1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
29 namespace accessibility
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
;
41 class AccessibleBrowseBoxImpl
44 /// the XAccessible which created the AccessibleBrowseBox
45 WeakReference
< XAccessible
> m_aCreator
;
47 /** The data table child. */
49 ::com::sun::star::accessibility::XAccessible
> mxTable
;
50 AccessibleBrowseBoxTable
* m_pTable
;
52 /** The header bar for rows ("handle column"). */
54 ::com::sun::star::accessibility::XAccessible
> mxRowHeaderBar
;
55 AccessibleBrowseBoxHeaderBar
* m_pRowHeaderBar
;
57 /** The header bar for columns (first row of the table). */
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_xImpl
.reset( new AccessibleBrowseBoxImpl() );
71 m_xImpl
->m_aCreator
= _rxCreator
;
73 m_xFocusWindow
= VCLUnoHelper::GetInterface(mpBrowseBox
->GetWindowInstance());
76 void AccessibleBrowseBox::setCreator( const Reference
< XAccessible
>& _rxCreator
)
78 #if OSL_DEBUG_LEVEL > 0
79 Reference
< XAccessible
> xCreator(m_xImpl
->m_aCreator
);
80 OSL_ENSURE( !xCreator
.is(), "accessibility/extended/AccessibleBrowseBox::setCreator: creator already set!" );
82 m_xImpl
->m_aCreator
= _rxCreator
;
86 AccessibleBrowseBox::~AccessibleBrowseBox()
91 void SAL_CALL
AccessibleBrowseBox::disposing()
93 ::osl::MutexGuard
aGuard( getOslMutex() );
95 m_xImpl
->m_pTable
= NULL
;
96 m_xImpl
->m_pColumnHeaderBar
= NULL
;
97 m_xImpl
->m_pRowHeaderBar
= NULL
;
98 m_xImpl
->m_aCreator
.clear();
100 Reference
< XAccessible
> xTable
= m_xImpl
->mxTable
;
102 Reference
< XComponent
> xComp( m_xImpl
->mxTable
, UNO_QUERY
);
108 //! ::comphelper::disposeComponent(m_xImpl->mxTable);
109 ::comphelper::disposeComponent(m_xImpl
->mxRowHeaderBar
);
110 ::comphelper::disposeComponent(m_xImpl
->mxColumnHeaderBar
);
112 AccessibleBrowseBoxBase::disposing();
116 // XAccessibleContext ---------------------------------------------------------
118 sal_Int32 SAL_CALL
AccessibleBrowseBox::getAccessibleChildCount()
119 throw ( uno::RuntimeException
, std::exception
)
121 SolarMutexGuard aSolarGuard
;
122 ::osl::MutexGuard
aGuard( getOslMutex() );
124 return BBINDEX_FIRSTCONTROL
+ mpBrowseBox
->GetAccessibleControlCount();
128 Reference
< XAccessible
> SAL_CALL
129 AccessibleBrowseBox::getAccessibleChild( sal_Int32 nChildIndex
)
130 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
132 SolarMutexGuard aSolarGuard
;
133 ::osl::MutexGuard
aGuard( getOslMutex() );
136 Reference
< XAccessible
> xRet
;
137 if( nChildIndex
>= 0 )
139 if( nChildIndex
< BBINDEX_FIRSTCONTROL
)
140 xRet
= implGetFixedChild( nChildIndex
);
143 // additional controls
144 nChildIndex
-= BBINDEX_FIRSTCONTROL
;
145 if( nChildIndex
< mpBrowseBox
->GetAccessibleControlCount() )
146 xRet
= mpBrowseBox
->CreateAccessibleControl( nChildIndex
);
151 throw lang::IndexOutOfBoundsException();
155 // XAccessibleComponent -------------------------------------------------------
157 Reference
< XAccessible
> SAL_CALL
158 AccessibleBrowseBox::getAccessibleAtPoint( const awt::Point
& rPoint
)
159 throw ( uno::RuntimeException
, std::exception
)
161 SolarMutexGuard aSolarGuard
;
162 ::osl::MutexGuard
aGuard( getOslMutex() );
165 Reference
< XAccessible
> xChild
;
166 sal_Int32 nIndex
= 0;
167 if( mpBrowseBox
->ConvertPointToControlIndex( nIndex
, VCLPoint( rPoint
) ) )
168 xChild
= mpBrowseBox
->CreateAccessibleControl( nIndex
);
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
) )
189 void SAL_CALL
AccessibleBrowseBox::grabFocus()
190 throw ( uno::RuntimeException
, std::exception
)
192 SolarMutexGuard aSolarGuard
;
193 ::osl::MutexGuard
aGuard( getOslMutex() );
195 mpBrowseBox
->GrabFocus();
198 // XServiceInfo ---------------------------------------------------------------
200 OUString SAL_CALL
AccessibleBrowseBox::getImplementationName()
201 throw ( uno::RuntimeException
, std::exception
)
203 return OUString( "com.sun.star.comp.svtools.AccessibleBrowseBox" );
207 // internal virtual methods ---------------------------------------------------
209 Rectangle
AccessibleBrowseBox::implGetBoundingBox()
211 vcl::Window
* pParent
= mpBrowseBox
->GetAccessibleParentWindow();
212 OSL_ENSURE( pParent
, "implGetBoundingBox - missing parent window" );
213 return mpBrowseBox
->GetWindowExtentsRelative( pParent
);
217 Rectangle
AccessibleBrowseBox::implGetBoundingBoxOnScreen()
219 return mpBrowseBox
->GetWindowExtentsRelative( NULL
);
223 // internal helper methods ----------------------------------------------------
225 Reference
< XAccessible
> AccessibleBrowseBox::implGetTable()
227 if( !m_xImpl
->mxTable
.is() )
229 m_xImpl
->m_pTable
= createAccessibleTable();
230 m_xImpl
->mxTable
= m_xImpl
->m_pTable
;
233 return m_xImpl
->mxTable
;
237 Reference
< XAccessible
>
238 AccessibleBrowseBox::implGetHeaderBar( AccessibleBrowseBoxObjType eObjType
)
240 Reference
< XAccessible
> xRet
;
241 Reference
< XAccessible
>* pxMember
= NULL
;
243 if( eObjType
== BBTYPE_ROWHEADERBAR
)
244 pxMember
= &m_xImpl
->mxRowHeaderBar
;
245 else if( eObjType
== BBTYPE_COLUMNHEADERBAR
)
246 pxMember
= &m_xImpl
->mxColumnHeaderBar
;
250 if( !pxMember
->is() )
252 AccessibleBrowseBoxHeaderBar
* pHeaderBar
= new AccessibleBrowseBoxHeaderBar(
253 m_xImpl
->m_aCreator
, *mpBrowseBox
, eObjType
);
255 if ( BBTYPE_COLUMNHEADERBAR
== eObjType
)
256 m_xImpl
->m_pColumnHeaderBar
= pHeaderBar
;
258 m_xImpl
->m_pRowHeaderBar
= pHeaderBar
;
260 *pxMember
= pHeaderBar
;
268 Reference
< XAccessible
>
269 AccessibleBrowseBox::implGetFixedChild( sal_Int32 nChildIndex
)
271 Reference
< XAccessible
> xRet
;
272 switch( nChildIndex
)
274 case BBINDEX_COLUMNHEADERBAR
:
275 xRet
= implGetHeaderBar( BBTYPE_COLUMNHEADERBAR
);
277 case BBINDEX_ROWHEADERBAR
:
278 xRet
= implGetHeaderBar( BBTYPE_ROWHEADERBAR
);
281 xRet
= implGetTable();
287 AccessibleBrowseBoxTable
* AccessibleBrowseBox::createAccessibleTable()
289 Reference
< XAccessible
> xCreator(m_xImpl
->m_aCreator
);
290 OSL_ENSURE( xCreator
.is(), "accessibility/extended/AccessibleBrowseBox::createAccessibleTable: my creator died - how this?" );
291 return new AccessibleBrowseBoxTable( xCreator
, *mpBrowseBox
);
294 void AccessibleBrowseBox::commitTableEvent(sal_Int16 _nEventId
,const Any
& _rNewValue
,const Any
& _rOldValue
)
296 if ( m_xImpl
->mxTable
.is() )
298 m_xImpl
->m_pTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
302 void AccessibleBrowseBox::commitHeaderBarEvent( sal_Int16 _nEventId
,
303 const Any
& _rNewValue
,
304 const Any
& _rOldValue
,bool _bColumnHeaderBar
)
306 Reference
< XAccessible
> xHeaderBar
= _bColumnHeaderBar
? m_xImpl
->mxColumnHeaderBar
: m_xImpl
->mxRowHeaderBar
;
307 AccessibleBrowseBoxHeaderBar
* pHeaderBar
= _bColumnHeaderBar
? m_xImpl
->m_pColumnHeaderBar
: m_xImpl
->m_pRowHeaderBar
;
308 if ( xHeaderBar
.is() )
309 pHeaderBar
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
313 // = AccessibleBrowseBoxAccess
315 AccessibleBrowseBoxAccess::AccessibleBrowseBoxAccess( const Reference
< XAccessible
>& _rxParent
, IAccessibleTableProvider
& _rBrowseBox
)
316 :m_xParent( _rxParent
)
317 ,m_rBrowseBox( _rBrowseBox
)
323 AccessibleBrowseBoxAccess::~AccessibleBrowseBoxAccess()
328 void AccessibleBrowseBoxAccess::dispose()
330 ::osl::MutexGuard
aGuard( m_aMutex
);
333 ::comphelper::disposeComponent( m_xContext
);
337 Reference
< XAccessibleContext
> SAL_CALL
AccessibleBrowseBoxAccess::getAccessibleContext() throw ( RuntimeException
, std::exception
)
339 ::osl::MutexGuard
aGuard( m_aMutex
);
341 OSL_ENSURE( ( m_pContext
&& m_xContext
.is() ) || ( !m_pContext
&& !m_xContext
.is() ),
342 "accessibility/extended/AccessibleBrowseBoxAccess::getAccessibleContext: inconsistency!" );
344 // if the context died meanwhile (there is no listener, so it won't tell us explicitily when this happens),
345 // then reset and re-create.
346 if ( m_pContext
&& !m_pContext
->isAlive() )
347 m_xContext
= m_pContext
= NULL
;
349 if ( !m_xContext
.is() )
350 m_xContext
= m_pContext
= new AccessibleBrowseBox( m_xParent
, this, m_rBrowseBox
);
356 bool AccessibleBrowseBoxAccess::isContextAlive() const
358 return ( NULL
!= m_pContext
) && m_pContext
->isAlive();
363 } // namespace accessibility
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */