1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | |
20 | #include "accessibility/extended/AccessibleBrowseBox.hxx" |
21 | #include "accessibility/extended/AccessibleBrowseBoxTable.hxx" |
22 | #include "accessibility/extended/AccessibleBrowseBoxHeaderBar.hxx" |
23 | #include <svtools/accessibletableprovider.hxx> |
24 | #include <comphelper/types.hxx> |
25 | #include <toolkit/helper/vclunohelper.hxx> |
26 | |
27 | // ============================================================================ |
28 | |
29 | namespace accessibility |
30 | { |
31 | |
32 | // ============================================================================ |
33 | |
34 | using namespace ::com::sun::star::uno; |
35 | using namespace ::com::sun::star; |
36 | using namespace ::com::sun::star::lang; |
37 | using namespace ::com::sun::star::accessibility; |
38 | using namespace ::svt; |
39 | |
40 | // ============================================================================ |
41 | class AccessibleBrowseBoxImpl |
42 | { |
43 | public: |
44 | /// the XAccessible which created the AccessibleBrowseBox |
45 | WeakReference< XAccessible > m_aCreator; |
46 | |
47 | /** The data table child. */ |
48 | Reference< |
49 | ::com::sun::star::accessibility::XAccessible > mxTable; |
50 | AccessibleBrowseBoxTable* m_pTable; |
51 | |
52 | /** The header bar for rows ("handle column"). */ |
53 | Reference< |
54 | ::com::sun::star::accessibility::XAccessible > ; |
55 | AccessibleBrowseBoxHeaderBar* ; |
56 | |
57 | /** The header bar for columns (first row of the table). */ |
58 | Reference< |
59 | ::com::sun::star::accessibility::XAccessible > mxColumnHeaderBar; |
60 | AccessibleBrowseBoxHeaderBar* m_pColumnHeaderBar; |
61 | }; |
62 | |
63 | // Ctor/Dtor/disposing -------------------------------------------------------- |
64 | |
65 | AccessibleBrowseBox::AccessibleBrowseBox( |
66 | const Reference< XAccessible >& _rxParent, const Reference< XAccessible >& _rxCreator, |
67 | IAccessibleTableProvider& _rBrowseBox ) |
68 | : AccessibleBrowseBoxBase( _rxParent, _rBrowseBox,NULL, BBTYPE_BROWSEBOX ) |
69 | { |
70 | m_pImpl.reset( new AccessibleBrowseBoxImpl() ); |
71 | m_pImpl->m_aCreator = _rxCreator; |
72 | |
73 | m_xFocusWindow = VCLUnoHelper::GetInterface(mpBrowseBox->GetWindowInstance()); |
74 | } |
75 | // ----------------------------------------------------------------------------- |
76 | void AccessibleBrowseBox::setCreator( const Reference< XAccessible >& _rxCreator ) |
77 | { |
78 | #if OSL_DEBUG_LEVEL > 0 |
79 | Reference< XAccessible > xCreator = (Reference< XAccessible >)m_pImpl->m_aCreator; |
80 | OSL_ENSURE( !xCreator.is(), "accessibility/extended/AccessibleBrowseBox::setCreator: creator already set!" ); |
81 | #endif |
82 | m_pImpl->m_aCreator = _rxCreator; |
83 | } |
84 | |
85 | // ----------------------------------------------------------------------------- |
86 | AccessibleBrowseBox::~AccessibleBrowseBox() |
87 | { |
88 | } |
89 | // ----------------------------------------------------------------------------- |
90 | |
91 | void SAL_CALL AccessibleBrowseBox::disposing() |
92 | { |
93 | ::osl::MutexGuard aGuard( getOslMutex() ); |
94 | |
95 | m_pImpl->m_pTable = NULL; |
96 | m_pImpl->m_pColumnHeaderBar = NULL; |
97 | m_pImpl->m_pRowHeaderBar = NULL; |
98 | m_pImpl->m_aCreator.clear(); |
99 | |
100 | Reference< XAccessible > xTable = m_pImpl->mxTable; |
101 | |
102 | Reference< XComponent > xComp( m_pImpl->mxTable, UNO_QUERY ); |
103 | if ( xComp.is() ) |
104 | { |
105 | xComp->dispose(); |
106 | |
107 | } |
108 | //! ::comphelper::disposeComponent(m_pImpl->mxTable); |
109 | ::comphelper::disposeComponent(m_pImpl->mxRowHeaderBar); |
110 | ::comphelper::disposeComponent(m_pImpl->mxColumnHeaderBar); |
111 | |
112 | AccessibleBrowseBoxBase::disposing(); |
113 | } |
114 | // ----------------------------------------------------------------------------- |
115 | |
116 | // XAccessibleContext --------------------------------------------------------- |
117 | |
118 | sal_Int32 SAL_CALL AccessibleBrowseBox::getAccessibleChildCount() |
119 | throw ( uno::RuntimeException ) |
120 | { |
121 | SolarMutexGuard aSolarGuard; |
122 | ::osl::MutexGuard aGuard( getOslMutex() ); |
123 | ensureIsAlive(); |
124 | return BBINDEX_FIRSTCONTROL + mpBrowseBox->GetAccessibleControlCount(); |
125 | } |
126 | // ----------------------------------------------------------------------------- |
127 | |
128 | Reference< XAccessible > SAL_CALL |
129 | AccessibleBrowseBox::getAccessibleChild( sal_Int32 nChildIndex ) |
130 | throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) |
131 | { |
132 | SolarMutexGuard aSolarGuard; |
133 | ::osl::MutexGuard aGuard( getOslMutex() ); |
134 | ensureIsAlive(); |
135 | |
136 | Reference< XAccessible > xRet; |
137 | if( nChildIndex >= 0 ) |
138 | { |
139 | if( nChildIndex < BBINDEX_FIRSTCONTROL ) |
140 | xRet = implGetFixedChild( nChildIndex ); |
141 | else |
142 | { |
143 | // additional controls |
144 | nChildIndex -= BBINDEX_FIRSTCONTROL; |
145 | if( nChildIndex < mpBrowseBox->GetAccessibleControlCount() ) |
146 | xRet = mpBrowseBox->CreateAccessibleControl( nChildIndex ); |
147 | } |
148 | } |
149 | |
150 | if( !xRet.is() ) |
151 | throw lang::IndexOutOfBoundsException(); |
152 | return xRet; |
153 | } |
154 | |
155 | // XAccessibleComponent ------------------------------------------------------- |
156 | |
157 | Reference< XAccessible > SAL_CALL |
158 | AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point& rPoint ) |
159 | throw ( uno::RuntimeException ) |
160 | { |
161 | SolarMutexGuard aSolarGuard; |
162 | ::osl::MutexGuard aGuard( getOslMutex() ); |
163 | ensureIsAlive(); |
164 | |
165 | Reference< XAccessible > xChild; |
166 | sal_Int32 nIndex = 0; |
167 | if( mpBrowseBox->ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) ) |
168 | xChild = mpBrowseBox->CreateAccessibleControl( nIndex ); |
169 | else |
170 | { |
171 | // try whether point is in one of the fixed children |
172 | // (table, header bars, corner control) |
173 | Point aPoint( VCLPoint( rPoint ) ); |
174 | for( nIndex = 0; (nIndex < BBINDEX_FIRSTCONTROL) && !xChild.is(); ++nIndex ) |
175 | { |
176 | Reference< XAccessible > xCurrChild( implGetFixedChild( nIndex ) ); |
177 | Reference< XAccessibleComponent > |
178 | xCurrChildComp( xCurrChild, uno::UNO_QUERY ); |
179 | |
180 | if( xCurrChildComp.is() && |
181 | VCLRectangle( xCurrChildComp->getBounds() ).IsInside( aPoint ) ) |
182 | xChild = xCurrChild; |
183 | } |
184 | } |
185 | return xChild; |
186 | } |
187 | // ----------------------------------------------------------------------------- |
188 | |
189 | void SAL_CALL AccessibleBrowseBox::grabFocus() |
190 | throw ( uno::RuntimeException ) |
191 | { |
192 | SolarMutexGuard aSolarGuard; |
193 | ::osl::MutexGuard aGuard( getOslMutex() ); |
194 | ensureIsAlive(); |
195 | mpBrowseBox->GrabFocus(); |
196 | } |
197 | // ----------------------------------------------------------------------------- |
198 | |
199 | Any SAL_CALL AccessibleBrowseBox::getAccessibleKeyBinding() |
200 | throw ( uno::RuntimeException ) |
201 | { |
202 | ensureIsAlive(); |
203 | return Any(); |
204 | } |
205 | // ----------------------------------------------------------------------------- |
206 | |
207 | // XServiceInfo --------------------------------------------------------------- |
208 | |
209 | OUString SAL_CALL AccessibleBrowseBox::getImplementationName() |
210 | throw ( uno::RuntimeException ) |
211 | { |
212 | return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBox" ); |
213 | } |
214 | // ----------------------------------------------------------------------------- |
215 | |
216 | // internal virtual methods --------------------------------------------------- |
217 | |
218 | Rectangle AccessibleBrowseBox::implGetBoundingBox() |
219 | { |
220 | Window* pParent = mpBrowseBox->GetAccessibleParentWindow(); |
221 | OSL_ENSURE( pParent, "implGetBoundingBox - missing parent window" ); |
222 | return mpBrowseBox->GetWindowExtentsRelative( pParent ); |
223 | } |
224 | // ----------------------------------------------------------------------------- |
225 | |
226 | Rectangle AccessibleBrowseBox::implGetBoundingBoxOnScreen() |
227 | { |
228 | return mpBrowseBox->GetWindowExtentsRelative( NULL ); |
229 | } |
230 | // ----------------------------------------------------------------------------- |
231 | |
232 | // internal helper methods ---------------------------------------------------- |
233 | |
234 | Reference< XAccessible > AccessibleBrowseBox::implGetTable() |
235 | { |
236 | if( !m_pImpl->mxTable.is() ) |
237 | { |
238 | m_pImpl->m_pTable = createAccessibleTable(); |
239 | m_pImpl->mxTable = m_pImpl->m_pTable; |
240 | |
241 | } |
242 | return m_pImpl->mxTable; |
243 | } |
244 | // ----------------------------------------------------------------------------- |
245 | |
246 | Reference< XAccessible > |
247 | AccessibleBrowseBox::( AccessibleBrowseBoxObjType eObjType ) |
248 | { |
249 | Reference< XAccessible > xRet; |
250 | Reference< XAccessible >* pxMember = NULL; |
251 | |
252 | if( eObjType == BBTYPE_ROWHEADERBAR ) |
253 | pxMember = &m_pImpl->mxRowHeaderBar; |
254 | else if( eObjType == BBTYPE_COLUMNHEADERBAR ) |
255 | pxMember = &m_pImpl->mxColumnHeaderBar; |
256 | |
257 | if( pxMember ) |
258 | { |
259 | if( !pxMember->is() ) |
260 | { |
261 | AccessibleBrowseBoxHeaderBar* = new AccessibleBrowseBoxHeaderBar( |
262 | (Reference< XAccessible >)m_pImpl->m_aCreator, *mpBrowseBox, eObjType ); |
263 | |
264 | if ( BBTYPE_COLUMNHEADERBAR == eObjType) |
265 | m_pImpl->m_pColumnHeaderBar = pHeaderBar; |
266 | else |
267 | m_pImpl->m_pRowHeaderBar = pHeaderBar; |
268 | |
269 | *pxMember = pHeaderBar; |
270 | } |
271 | xRet = *pxMember; |
272 | } |
273 | return xRet; |
274 | } |
275 | // ----------------------------------------------------------------------------- |
276 | |
277 | Reference< XAccessible > |
278 | AccessibleBrowseBox::implGetFixedChild( sal_Int32 nChildIndex ) |
279 | { |
280 | Reference< XAccessible > xRet; |
281 | switch( nChildIndex ) |
282 | { |
283 | case BBINDEX_COLUMNHEADERBAR: |
284 | xRet = implGetHeaderBar( BBTYPE_COLUMNHEADERBAR ); |
285 | break; |
286 | case BBINDEX_ROWHEADERBAR: |
287 | xRet = implGetHeaderBar( BBTYPE_ROWHEADERBAR ); |
288 | break; |
289 | case BBINDEX_TABLE: |
290 | xRet = implGetTable(); |
291 | break; |
292 | } |
293 | return xRet; |
294 | } |
295 | // ----------------------------------------------------------------------------- |
296 | AccessibleBrowseBoxTable* AccessibleBrowseBox::createAccessibleTable() |
297 | { |
298 | Reference< XAccessible > xCreator = (Reference< XAccessible >)m_pImpl->m_aCreator; |
299 | OSL_ENSURE( xCreator.is(), "accessibility/extended/AccessibleBrowseBox::createAccessibleTable: my creator died - how this?" ); |
300 | return new AccessibleBrowseBoxTable( xCreator, *mpBrowseBox ); |
301 | } |
302 | // ----------------------------------------------------------------------------- |
303 | void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue) |
304 | { |
305 | if ( m_pImpl->mxTable.is() ) |
306 | { |
307 | m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue); |
308 | } |
309 | } |
310 | // ----------------------------------------------------------------------------- |
311 | void AccessibleBrowseBox::( sal_Int16 _nEventId, |
312 | const Any& _rNewValue, |
313 | const Any& _rOldValue,sal_Bool _bColumnHeaderBar) |
314 | { |
315 | Reference< XAccessible > = _bColumnHeaderBar ? m_pImpl->mxColumnHeaderBar : m_pImpl->mxRowHeaderBar; |
316 | AccessibleBrowseBoxHeaderBar* = _bColumnHeaderBar ? m_pImpl->m_pColumnHeaderBar : m_pImpl->m_pRowHeaderBar; |
317 | if ( xHeaderBar.is() ) |
318 | pHeaderBar->commitEvent(_nEventId,_rNewValue,_rOldValue); |
319 | } |
320 | |
321 | // ============================================================================ |
322 | // = AccessibleBrowseBoxAccess |
323 | // ============================================================================ |
324 | AccessibleBrowseBoxAccess::AccessibleBrowseBoxAccess( const Reference< XAccessible >& _rxParent, IAccessibleTableProvider& _rBrowseBox ) |
325 | :m_xParent( _rxParent ) |
326 | ,m_rBrowseBox( _rBrowseBox ) |
327 | ,m_pContext( NULL ) |
328 | { |
329 | } |
330 | |
331 | // ----------------------------------------------------------------------------- |
332 | AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess() |
333 | { |
334 | } |
335 | |
336 | // ----------------------------------------------------------------------------- |
337 | void AccessibleBrowseBoxAccess::dispose() |
338 | { |
339 | ::osl::MutexGuard aGuard( m_aMutex ); |
340 | |
341 | m_pContext = NULL; |
342 | ::comphelper::disposeComponent( m_xContext ); |
343 | } |
344 | |
345 | // ----------------------------------------------------------------------------- |
346 | Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxAccess::getAccessibleContext() throw ( RuntimeException ) |
347 | { |
348 | ::osl::MutexGuard aGuard( m_aMutex ); |
349 | |
350 | OSL_ENSURE( ( m_pContext && m_xContext.is() ) || ( !m_pContext && !m_xContext.is() ), |
351 | "accessibility/extended/AccessibleBrowseBoxAccess::getAccessibleContext: inconsistency!" ); |
352 | |
353 | // if the context died meanwhile (there is no listener, so it won't tell us explicitily when this happens), |
354 | // then reset and re-create. |
355 | if ( m_pContext && !m_pContext->isAlive() ) |
356 | m_xContext = m_pContext = NULL; |
357 | |
358 | if ( !m_xContext.is() ) |
359 | m_xContext = m_pContext = new AccessibleBrowseBox( m_xParent, this, m_rBrowseBox ); |
360 | |
361 | return m_xContext; |
362 | } |
363 | |
364 | // ----------------------------------------------------------------------------- |
365 | bool AccessibleBrowseBoxAccess::isContextAlive() const |
366 | { |
367 | return ( NULL != m_pContext ) && m_pContext->isAlive(); |
368 | } |
369 | |
370 | // ============================================================================ |
371 | |
372 | } // namespace accessibility |
373 | |
374 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
375 | |