1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleBrowseBox.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include "accessibility/extended/AccessibleBrowseBox.hxx"
34 #include "accessibility/extended/AccessibleBrowseBoxTable.hxx"
35 #include "accessibility/extended/AccessibleBrowseBoxHeaderBar.hxx"
36 #include <svtools/accessibletableprovider.hxx>
37 #include <comphelper/types.hxx>
38 #include <toolkit/helper/vclunohelper.hxx>
40 // ============================================================================
42 namespace accessibility
45 // ============================================================================
47 using ::rtl::OUString
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::lang
;
52 using namespace ::com::sun::star::accessibility
;
53 using namespace ::svt
;
55 // ============================================================================
56 class AccessibleBrowseBoxImpl
59 /// the XAccessible which created the AccessibleBrowseBox
60 WeakReference
< XAccessible
> m_aCreator
;
62 /** The data table child. */
64 ::com::sun::star::accessibility::XAccessible
> mxTable
;
65 AccessibleBrowseBoxTable
* m_pTable
;
67 /** The header bar for rows ("handle column"). */
69 ::com::sun::star::accessibility::XAccessible
> mxRowHeaderBar
;
70 AccessibleBrowseBoxHeaderBar
* m_pRowHeaderBar
;
72 /** The header bar for columns (first row of the table). */
74 ::com::sun::star::accessibility::XAccessible
> mxColumnHeaderBar
;
75 AccessibleBrowseBoxHeaderBar
* m_pColumnHeaderBar
;
78 // Ctor/Dtor/disposing --------------------------------------------------------
80 DBG_NAME( AccessibleBrowseBox
)
82 AccessibleBrowseBox::AccessibleBrowseBox(
83 const Reference
< XAccessible
>& _rxParent
, const Reference
< XAccessible
>& _rxCreator
,
84 IAccessibleTableProvider
& _rBrowseBox
)
85 : AccessibleBrowseBoxBase( _rxParent
, _rBrowseBox
,NULL
, BBTYPE_BROWSEBOX
)
87 DBG_CTOR( AccessibleBrowseBox
, NULL
);
88 m_pImpl
.reset( new AccessibleBrowseBoxImpl() );
89 m_pImpl
->m_aCreator
= _rxCreator
;
91 m_xFocusWindow
= VCLUnoHelper::GetInterface(mpBrowseBox
->GetWindowInstance());
93 // -----------------------------------------------------------------------------
94 void AccessibleBrowseBox::setCreator( const Reference
< XAccessible
>& _rxCreator
)
96 #if OSL_DEBUG_LEVEL > 0
97 Reference
< XAccessible
> xCreator
= (Reference
< XAccessible
>)m_pImpl
->m_aCreator
;
98 DBG_ASSERT( !xCreator
.is(), "accessibility/extended/AccessibleBrowseBox::setCreator: creator already set!" );
100 m_pImpl
->m_aCreator
= _rxCreator
;
103 // -----------------------------------------------------------------------------
104 AccessibleBrowseBox::~AccessibleBrowseBox()
106 DBG_DTOR( AccessibleBrowseBox
, NULL
);
108 // -----------------------------------------------------------------------------
110 void SAL_CALL
AccessibleBrowseBox::disposing()
112 ::osl::MutexGuard
aGuard( getOslMutex() );
114 m_pImpl
->m_pTable
= NULL
;
115 m_pImpl
->m_pColumnHeaderBar
= NULL
;
116 m_pImpl
->m_pRowHeaderBar
= NULL
;
117 m_pImpl
->m_aCreator
= Reference
< XAccessible
>();
119 Reference
< XAccessible
> xTable
= m_pImpl
->mxTable
;
121 Reference
< XComponent
> xComp( m_pImpl
->mxTable
, UNO_QUERY
);
127 //! ::comphelper::disposeComponent(m_pImpl->mxTable);
128 ::comphelper::disposeComponent(m_pImpl
->mxRowHeaderBar
);
129 ::comphelper::disposeComponent(m_pImpl
->mxColumnHeaderBar
);
131 AccessibleBrowseBoxBase::disposing();
133 // -----------------------------------------------------------------------------
135 // XAccessibleContext ---------------------------------------------------------
137 sal_Int32 SAL_CALL
AccessibleBrowseBox::getAccessibleChildCount()
138 throw ( uno::RuntimeException
)
140 BBSolarGuard aSolarGuard
;
141 ::osl::MutexGuard
aGuard( getOslMutex() );
143 return BBINDEX_FIRSTCONTROL
+ mpBrowseBox
->GetAccessibleControlCount();
145 // -----------------------------------------------------------------------------
147 Reference
< XAccessible
> SAL_CALL
148 AccessibleBrowseBox::getAccessibleChild( sal_Int32 nChildIndex
)
149 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
151 BBSolarGuard aSolarGuard
;
152 ::osl::MutexGuard
aGuard( getOslMutex() );
155 Reference
< XAccessible
> xRet
;
156 if( nChildIndex
>= 0 )
158 if( nChildIndex
< BBINDEX_FIRSTCONTROL
)
159 xRet
= implGetFixedChild( nChildIndex
);
162 // additional controls
163 nChildIndex
-= BBINDEX_FIRSTCONTROL
;
164 if( nChildIndex
< mpBrowseBox
->GetAccessibleControlCount() )
165 xRet
= mpBrowseBox
->CreateAccessibleControl( nChildIndex
);
170 throw lang::IndexOutOfBoundsException();
173 // -----------------------------------------------------------------------------
175 //sal_Int16 SAL_CALL AccessibleBrowseBox::getAccessibleRole()
176 // throw ( uno::RuntimeException )
179 // return AccessibleRole::PANEL;
181 // -----------------------------------------------------------------------------
183 // XAccessibleComponent -------------------------------------------------------
185 Reference
< XAccessible
> SAL_CALL
186 AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point
& rPoint
)
187 throw ( uno::RuntimeException
)
189 BBSolarGuard aSolarGuard
;
190 ::osl::MutexGuard
aGuard( getOslMutex() );
193 Reference
< XAccessible
> xChild
;
194 sal_Int32 nIndex
= 0;
195 if( mpBrowseBox
->ConvertPointToControlIndex( nIndex
, VCLPoint( rPoint
) ) )
196 xChild
= mpBrowseBox
->CreateAccessibleControl( nIndex
);
199 // try whether point is in one of the fixed children
200 // (table, header bars, corner control)
201 Point
aPoint( VCLPoint( rPoint
) );
202 for( nIndex
= 0; (nIndex
< BBINDEX_FIRSTCONTROL
) && !xChild
.is(); ++nIndex
)
204 Reference
< XAccessible
> xCurrChild( implGetFixedChild( nIndex
) );
205 Reference
< XAccessibleComponent
>
206 xCurrChildComp( xCurrChild
, uno::UNO_QUERY
);
208 if( xCurrChildComp
.is() &&
209 VCLRectangle( xCurrChildComp
->getBounds() ).IsInside( aPoint
) )
215 // -----------------------------------------------------------------------------
217 void SAL_CALL
AccessibleBrowseBox::grabFocus()
218 throw ( uno::RuntimeException
)
220 BBSolarGuard aSolarGuard
;
221 ::osl::MutexGuard
aGuard( getOslMutex() );
223 mpBrowseBox
->GrabFocus();
225 // -----------------------------------------------------------------------------
227 Any SAL_CALL
AccessibleBrowseBox::getAccessibleKeyBinding()
228 throw ( uno::RuntimeException
)
233 // -----------------------------------------------------------------------------
235 // XServiceInfo ---------------------------------------------------------------
237 OUString SAL_CALL
AccessibleBrowseBox::getImplementationName()
238 throw ( uno::RuntimeException
)
240 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBox" ) );
242 // -----------------------------------------------------------------------------
244 // internal virtual methods ---------------------------------------------------
246 Rectangle
AccessibleBrowseBox::implGetBoundingBox()
248 Window
* pParent
= mpBrowseBox
->GetAccessibleParentWindow();
249 DBG_ASSERT( pParent
, "implGetBoundingBox - missing parent window" );
250 return mpBrowseBox
->GetWindowExtentsRelative( pParent
);
252 // -----------------------------------------------------------------------------
254 Rectangle
AccessibleBrowseBox::implGetBoundingBoxOnScreen()
256 return mpBrowseBox
->GetWindowExtentsRelative( NULL
);
258 // -----------------------------------------------------------------------------
260 // internal helper methods ----------------------------------------------------
262 Reference
< XAccessible
> AccessibleBrowseBox::implGetTable()
264 if( !m_pImpl
->mxTable
.is() )
266 m_pImpl
->m_pTable
= createAccessibleTable();
267 m_pImpl
->mxTable
= m_pImpl
->m_pTable
;
270 return m_pImpl
->mxTable
;
272 // -----------------------------------------------------------------------------
274 Reference
< XAccessible
>
275 AccessibleBrowseBox::implGetHeaderBar( AccessibleBrowseBoxObjType eObjType
)
277 Reference
< XAccessible
> xRet
;
278 Reference
< XAccessible
>* pxMember
= NULL
;
280 if( eObjType
== BBTYPE_ROWHEADERBAR
)
281 pxMember
= &m_pImpl
->mxRowHeaderBar
;
282 else if( eObjType
== BBTYPE_COLUMNHEADERBAR
)
283 pxMember
= &m_pImpl
->mxColumnHeaderBar
;
287 if( !pxMember
->is() )
289 AccessibleBrowseBoxHeaderBar
* pHeaderBar
= new AccessibleBrowseBoxHeaderBar(
290 (Reference
< XAccessible
>)m_pImpl
->m_aCreator
, *mpBrowseBox
, eObjType
);
292 if ( BBTYPE_COLUMNHEADERBAR
== eObjType
)
293 m_pImpl
->m_pColumnHeaderBar
= pHeaderBar
;
295 m_pImpl
->m_pRowHeaderBar
= pHeaderBar
;
297 *pxMember
= pHeaderBar
;
303 // -----------------------------------------------------------------------------
305 Reference
< XAccessible
>
306 AccessibleBrowseBox::implGetFixedChild( sal_Int32 nChildIndex
)
308 Reference
< XAccessible
> xRet
;
309 switch( nChildIndex
)
311 case BBINDEX_COLUMNHEADERBAR
:
312 xRet
= implGetHeaderBar( BBTYPE_COLUMNHEADERBAR
);
314 case BBINDEX_ROWHEADERBAR
:
315 xRet
= implGetHeaderBar( BBTYPE_ROWHEADERBAR
);
318 xRet
= implGetTable();
323 // -----------------------------------------------------------------------------
324 AccessibleBrowseBoxTable
* AccessibleBrowseBox::createAccessibleTable()
326 Reference
< XAccessible
> xCreator
= (Reference
< XAccessible
>)m_pImpl
->m_aCreator
;
327 DBG_ASSERT( xCreator
.is(), "accessibility/extended/AccessibleBrowseBox::createAccessibleTable: my creator died - how this?" );
328 return new AccessibleBrowseBoxTable( xCreator
, *mpBrowseBox
);
330 // -----------------------------------------------------------------------------
331 void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId
,const Any
& _rNewValue
,const Any
& _rOldValue
)
333 if ( m_pImpl
->mxTable
.is() )
335 m_pImpl
->m_pTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
338 // -----------------------------------------------------------------------------
339 void AccessibleBrowseBox::commitHeaderBarEvent( sal_Int16 _nEventId
,
340 const Any
& _rNewValue
,
341 const Any
& _rOldValue
,sal_Bool _bColumnHeaderBar
)
343 Reference
< XAccessible
> xHeaderBar
= _bColumnHeaderBar
? m_pImpl
->mxColumnHeaderBar
: m_pImpl
->mxRowHeaderBar
;
344 AccessibleBrowseBoxHeaderBar
* pHeaderBar
= _bColumnHeaderBar
? m_pImpl
->m_pColumnHeaderBar
: m_pImpl
->m_pRowHeaderBar
;
345 if ( xHeaderBar
.is() )
346 pHeaderBar
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
349 // ============================================================================
350 // = AccessibleBrowseBoxAccess
351 // ============================================================================
352 DBG_NAME( AccessibleBrowseBoxAccess
)
353 // -----------------------------------------------------------------------------
354 AccessibleBrowseBoxAccess::AccessibleBrowseBoxAccess( const Reference
< XAccessible
>& _rxParent
, IAccessibleTableProvider
& _rBrowseBox
)
355 :m_xParent( _rxParent
)
356 ,m_rBrowseBox( _rBrowseBox
)
359 DBG_CTOR( AccessibleBrowseBoxAccess
, NULL
);
362 // -----------------------------------------------------------------------------
363 AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess()
365 DBG_DTOR( AccessibleBrowseBoxAccess
, NULL
);
368 // -----------------------------------------------------------------------------
369 void AccessibleBrowseBoxAccess::dispose()
371 ::osl::MutexGuard
aGuard( m_aMutex
);
374 ::comphelper::disposeComponent( m_xContext
);
377 // -----------------------------------------------------------------------------
378 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxAccess::getAccessibleContext() throw ( RuntimeException
)
380 ::osl::MutexGuard
aGuard( m_aMutex
);
382 DBG_ASSERT( ( m_pContext
&& m_xContext
.is() ) || ( !m_pContext
&& !m_xContext
.is() ),
383 "accessibility/extended/AccessibleBrowseBoxAccess::getAccessibleContext: inconsistency!" );
385 // if the context died meanwhile (we're no listener, so it won't tell us explicitily when this happens),
386 // then reset an re-create.
387 if ( m_pContext
&& !m_pContext
->isAlive() )
388 m_xContext
= m_pContext
= NULL
;
390 if ( !m_xContext
.is() )
391 m_xContext
= m_pContext
= new AccessibleBrowseBox( m_xParent
, this, m_rBrowseBox
);
396 // -----------------------------------------------------------------------------
397 bool AccessibleBrowseBoxAccess::isContextAlive() const
399 return ( NULL
!= m_pContext
) && m_pContext
->isAlive();
402 // ============================================================================
404 } // namespace accessibility