bump product version to 4.1.6.2
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBox.cxx
blobbd56b697ba7bb89c3e8a83a58398fc8e7b1ed68d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 // ============================================================================
29 namespace accessibility
32 // ============================================================================
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;
40 // ============================================================================
41 class AccessibleBrowseBoxImpl
43 public:
44 /// the XAccessible which created the AccessibleBrowseBox
45 WeakReference< XAccessible > m_aCreator;
47 /** The data table child. */
48 Reference<
49 ::com::sun::star::accessibility::XAccessible > mxTable;
50 AccessibleBrowseBoxTable* m_pTable;
52 /** The header bar for rows ("handle column"). */
53 Reference<
54 ::com::sun::star::accessibility::XAccessible > mxRowHeaderBar;
55 AccessibleBrowseBoxHeaderBar* m_pRowHeaderBar;
57 /** The header bar for columns (first row of the table). */
58 Reference<
59 ::com::sun::star::accessibility::XAccessible > mxColumnHeaderBar;
60 AccessibleBrowseBoxHeaderBar* m_pColumnHeaderBar;
63 // Ctor/Dtor/disposing --------------------------------------------------------
65 AccessibleBrowseBox::AccessibleBrowseBox(
66 const Reference< XAccessible >& _rxParent, const Reference< XAccessible >& _rxCreator,
67 IAccessibleTableProvider& _rBrowseBox )
68 : AccessibleBrowseBoxBase( _rxParent, _rBrowseBox,NULL, BBTYPE_BROWSEBOX )
70 m_pImpl.reset( new AccessibleBrowseBoxImpl() );
71 m_pImpl->m_aCreator = _rxCreator;
73 m_xFocusWindow = VCLUnoHelper::GetInterface(mpBrowseBox->GetWindowInstance());
75 // -----------------------------------------------------------------------------
76 void AccessibleBrowseBox::setCreator( const Reference< XAccessible >& _rxCreator )
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;
85 // -----------------------------------------------------------------------------
86 AccessibleBrowseBox::~AccessibleBrowseBox()
89 // -----------------------------------------------------------------------------
91 void SAL_CALL AccessibleBrowseBox::disposing()
93 ::osl::MutexGuard aGuard( getOslMutex() );
95 m_pImpl->m_pTable = NULL;
96 m_pImpl->m_pColumnHeaderBar = NULL;
97 m_pImpl->m_pRowHeaderBar = NULL;
98 m_pImpl->m_aCreator = Reference< XAccessible >();
100 Reference< XAccessible > xTable = m_pImpl->mxTable;
102 Reference< XComponent > xComp( m_pImpl->mxTable, UNO_QUERY );
103 if ( xComp.is() )
105 xComp->dispose();
108 //! ::comphelper::disposeComponent(m_pImpl->mxTable);
109 ::comphelper::disposeComponent(m_pImpl->mxRowHeaderBar);
110 ::comphelper::disposeComponent(m_pImpl->mxColumnHeaderBar);
112 AccessibleBrowseBoxBase::disposing();
114 // -----------------------------------------------------------------------------
116 // XAccessibleContext ---------------------------------------------------------
118 sal_Int32 SAL_CALL AccessibleBrowseBox::getAccessibleChildCount()
119 throw ( uno::RuntimeException )
121 SolarMutexGuard aSolarGuard;
122 ::osl::MutexGuard aGuard( getOslMutex() );
123 ensureIsAlive();
124 return BBINDEX_FIRSTCONTROL + mpBrowseBox->GetAccessibleControlCount();
126 // -----------------------------------------------------------------------------
128 Reference< XAccessible > SAL_CALL
129 AccessibleBrowseBox::getAccessibleChild( sal_Int32 nChildIndex )
130 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
132 SolarMutexGuard aSolarGuard;
133 ::osl::MutexGuard aGuard( getOslMutex() );
134 ensureIsAlive();
136 Reference< XAccessible > xRet;
137 if( nChildIndex >= 0 )
139 if( nChildIndex < BBINDEX_FIRSTCONTROL )
140 xRet = implGetFixedChild( nChildIndex );
141 else
143 // additional controls
144 nChildIndex -= BBINDEX_FIRSTCONTROL;
145 if( nChildIndex < mpBrowseBox->GetAccessibleControlCount() )
146 xRet = mpBrowseBox->CreateAccessibleControl( nChildIndex );
150 if( !xRet.is() )
151 throw lang::IndexOutOfBoundsException();
152 return xRet;
155 // XAccessibleComponent -------------------------------------------------------
157 Reference< XAccessible > SAL_CALL
158 AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point& rPoint )
159 throw ( uno::RuntimeException )
161 SolarMutexGuard aSolarGuard;
162 ::osl::MutexGuard aGuard( getOslMutex() );
163 ensureIsAlive();
165 Reference< XAccessible > xChild;
166 sal_Int32 nIndex = 0;
167 if( mpBrowseBox->ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) )
168 xChild = mpBrowseBox->CreateAccessibleControl( nIndex );
169 else
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 )
176 Reference< XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
177 Reference< XAccessibleComponent >
178 xCurrChildComp( xCurrChild, uno::UNO_QUERY );
180 if( xCurrChildComp.is() &&
181 VCLRectangle( xCurrChildComp->getBounds() ).IsInside( aPoint ) )
182 xChild = xCurrChild;
185 return xChild;
187 // -----------------------------------------------------------------------------
189 void SAL_CALL AccessibleBrowseBox::grabFocus()
190 throw ( uno::RuntimeException )
192 SolarMutexGuard aSolarGuard;
193 ::osl::MutexGuard aGuard( getOslMutex() );
194 ensureIsAlive();
195 mpBrowseBox->GrabFocus();
197 // -----------------------------------------------------------------------------
199 Any SAL_CALL AccessibleBrowseBox::getAccessibleKeyBinding()
200 throw ( uno::RuntimeException )
202 ensureIsAlive();
203 return Any();
205 // -----------------------------------------------------------------------------
207 // XServiceInfo ---------------------------------------------------------------
209 OUString SAL_CALL AccessibleBrowseBox::getImplementationName()
210 throw ( uno::RuntimeException )
212 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBox" );
214 // -----------------------------------------------------------------------------
216 // internal virtual methods ---------------------------------------------------
218 Rectangle AccessibleBrowseBox::implGetBoundingBox()
220 Window* pParent = mpBrowseBox->GetAccessibleParentWindow();
221 OSL_ENSURE( pParent, "implGetBoundingBox - missing parent window" );
222 return mpBrowseBox->GetWindowExtentsRelative( pParent );
224 // -----------------------------------------------------------------------------
226 Rectangle AccessibleBrowseBox::implGetBoundingBoxOnScreen()
228 return mpBrowseBox->GetWindowExtentsRelative( NULL );
230 // -----------------------------------------------------------------------------
232 // internal helper methods ----------------------------------------------------
234 Reference< XAccessible > AccessibleBrowseBox::implGetTable()
236 if( !m_pImpl->mxTable.is() )
238 m_pImpl->m_pTable = createAccessibleTable();
239 m_pImpl->mxTable = m_pImpl->m_pTable;
242 return m_pImpl->mxTable;
244 // -----------------------------------------------------------------------------
246 Reference< XAccessible >
247 AccessibleBrowseBox::implGetHeaderBar( AccessibleBrowseBoxObjType eObjType )
249 Reference< XAccessible > xRet;
250 Reference< XAccessible >* pxMember = NULL;
252 if( eObjType == BBTYPE_ROWHEADERBAR )
253 pxMember = &m_pImpl->mxRowHeaderBar;
254 else if( eObjType == BBTYPE_COLUMNHEADERBAR )
255 pxMember = &m_pImpl->mxColumnHeaderBar;
257 if( pxMember )
259 if( !pxMember->is() )
261 AccessibleBrowseBoxHeaderBar* pHeaderBar = new AccessibleBrowseBoxHeaderBar(
262 (Reference< XAccessible >)m_pImpl->m_aCreator, *mpBrowseBox, eObjType );
264 if ( BBTYPE_COLUMNHEADERBAR == eObjType)
265 m_pImpl->m_pColumnHeaderBar = pHeaderBar;
266 else
267 m_pImpl->m_pRowHeaderBar = pHeaderBar;
269 *pxMember = pHeaderBar;
271 xRet = *pxMember;
273 return xRet;
275 // -----------------------------------------------------------------------------
277 Reference< XAccessible >
278 AccessibleBrowseBox::implGetFixedChild( sal_Int32 nChildIndex )
280 Reference< XAccessible > xRet;
281 switch( nChildIndex )
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;
293 return xRet;
295 // -----------------------------------------------------------------------------
296 AccessibleBrowseBoxTable* AccessibleBrowseBox::createAccessibleTable()
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 );
302 // -----------------------------------------------------------------------------
303 void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
305 if ( m_pImpl->mxTable.is() )
307 m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
310 // -----------------------------------------------------------------------------
311 void AccessibleBrowseBox::commitHeaderBarEvent( sal_Int16 _nEventId,
312 const Any& _rNewValue,
313 const Any& _rOldValue,sal_Bool _bColumnHeaderBar)
315 Reference< XAccessible > xHeaderBar = _bColumnHeaderBar ? m_pImpl->mxColumnHeaderBar : m_pImpl->mxRowHeaderBar;
316 AccessibleBrowseBoxHeaderBar* pHeaderBar = _bColumnHeaderBar ? m_pImpl->m_pColumnHeaderBar : m_pImpl->m_pRowHeaderBar;
317 if ( xHeaderBar.is() )
318 pHeaderBar->commitEvent(_nEventId,_rNewValue,_rOldValue);
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 )
331 // -----------------------------------------------------------------------------
332 AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess()
336 // -----------------------------------------------------------------------------
337 void AccessibleBrowseBoxAccess::dispose()
339 ::osl::MutexGuard aGuard( m_aMutex );
341 m_pContext = NULL;
342 ::comphelper::disposeComponent( m_xContext );
345 // -----------------------------------------------------------------------------
346 Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxAccess::getAccessibleContext() throw ( RuntimeException )
348 ::osl::MutexGuard aGuard( m_aMutex );
350 OSL_ENSURE( ( m_pContext && m_xContext.is() ) || ( !m_pContext && !m_xContext.is() ),
351 "accessibility/extended/AccessibleBrowseBoxAccess::getAccessibleContext: inconsistency!" );
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;
358 if ( !m_xContext.is() )
359 m_xContext = m_pContext = new AccessibleBrowseBox( m_xParent, this, m_rBrowseBox );
361 return m_xContext;
364 // -----------------------------------------------------------------------------
365 bool AccessibleBrowseBoxAccess::isContextAlive() const
367 return ( NULL != m_pContext ) && m_pContext->isAlive();
370 // ============================================================================
372 } // namespace accessibility
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */