1c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file
5c82f2877SAndrew Rist * distributed with this work for additional information
6c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the
8c82f2877SAndrew Rist * "License"); you may not use this file except in compliance
9c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing,
14c82f2877SAndrew Rist * software distributed under the License is distributed on an
15c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c82f2877SAndrew Rist * KIND, either express or implied. See the License for the
17c82f2877SAndrew Rist * specific language governing permissions and limitations
18c82f2877SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20c82f2877SAndrew Rist *************************************************************/
21c82f2877SAndrew Rist
22c82f2877SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // includes --------------------------------------------------------------
28cdf0e10cSrcweir #include <accessibility/standard/vclxaccessibletoolbox.hxx>
29cdf0e10cSrcweir #include <accessibility/standard/vclxaccessibletoolboxitem.hxx>
30cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
33cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include <vcl/toolbox.hxx>
39cdf0e10cSrcweir #include <comphelper/accessiblewrapper.hxx>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace ::comphelper;
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir using namespace ::com::sun::star::lang;
46cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
47cdf0e10cSrcweir
48cdf0e10cSrcweir namespace
49cdf0e10cSrcweir {
50cdf0e10cSrcweir // =========================================================================
51cdf0e10cSrcweir // = OToolBoxWindowItemContext
52cdf0e10cSrcweir // =========================================================================
53cdf0e10cSrcweir /** XAccessibleContext implementation for a toolbox item which is represented by a VCL Window
54cdf0e10cSrcweir */
55cdf0e10cSrcweir class OToolBoxWindowItemContext : public OAccessibleContextWrapper
56cdf0e10cSrcweir {
57cdf0e10cSrcweir sal_Int32 m_nIndexInParent;
58cdf0e10cSrcweir public:
OToolBoxWindowItemContext(sal_Int32 _nIndexInParent,const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxORB,const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessibleContext> & _rxInnerAccessibleContext,const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & _rxOwningAccessible,const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & _rxParentAccessible)59cdf0e10cSrcweir OToolBoxWindowItemContext(sal_Int32 _nIndexInParent,
60cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
61cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerAccessibleContext,
62cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxOwningAccessible,
63cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible
64cdf0e10cSrcweir ) : OAccessibleContextWrapper(
65cdf0e10cSrcweir _rxORB,
66cdf0e10cSrcweir _rxInnerAccessibleContext,
67cdf0e10cSrcweir _rxOwningAccessible,
68cdf0e10cSrcweir _rxParentAccessible)
69cdf0e10cSrcweir ,m_nIndexInParent(_nIndexInParent)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException);
73cdf0e10cSrcweir };
74cdf0e10cSrcweir
75cdf0e10cSrcweir // -------------------------------------------------------------------------
getAccessibleIndexInParent()76cdf0e10cSrcweir sal_Int32 SAL_CALL OToolBoxWindowItemContext::getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
79cdf0e10cSrcweir return m_nIndexInParent;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir // =========================================================================
83cdf0e10cSrcweir // = OToolBoxWindowItem
84cdf0e10cSrcweir // =========================================================================
85cdf0e10cSrcweir typedef ::cppu::ImplHelper1 < XUnoTunnel
86cdf0e10cSrcweir > OToolBoxWindowItem_Base;
87cdf0e10cSrcweir
88cdf0e10cSrcweir /** XAccessible implementation for a toolbox item which is represented by a VCL Window
89cdf0e10cSrcweir */
90cdf0e10cSrcweir class OToolBoxWindowItem
91cdf0e10cSrcweir :public OAccessibleWrapper
92cdf0e10cSrcweir ,public OToolBoxWindowItem_Base
93cdf0e10cSrcweir {
94cdf0e10cSrcweir private:
95cdf0e10cSrcweir sal_Int32 m_nIndexInParent;
96cdf0e10cSrcweir
97cdf0e10cSrcweir public:
getIndexInParent() const98cdf0e10cSrcweir inline sal_Int32 getIndexInParent() const { return m_nIndexInParent; }
setIndexInParent(sal_Int32 _nNewIndex)99cdf0e10cSrcweir inline void setIndexInParent( sal_Int32 _nNewIndex ) { m_nIndexInParent = _nNewIndex; }
100cdf0e10cSrcweir
101cdf0e10cSrcweir static sal_Bool isWindowItem( const Reference< XAccessible >& _rxAcc, OToolBoxWindowItem** /* [out] */ _ppImplementation = NULL );
102cdf0e10cSrcweir
103cdf0e10cSrcweir public:
OToolBoxWindowItem(sal_Int32 _nIndexInParent,const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxORB,const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & _rxInnerAccessible,const::com::sun::star::uno::Reference<::com::sun::star::accessibility::XAccessible> & _rxParentAccessible)104cdf0e10cSrcweir OToolBoxWindowItem(sal_Int32 _nIndexInParent,
105cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
106cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxInnerAccessible,
107cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParentAccessible
108cdf0e10cSrcweir ) : OAccessibleWrapper(
109cdf0e10cSrcweir _rxORB,
110cdf0e10cSrcweir _rxInnerAccessible,
111cdf0e10cSrcweir _rxParentAccessible)
112cdf0e10cSrcweir ,m_nIndexInParent(_nIndexInParent)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir protected:
117cdf0e10cSrcweir // XInterface
118cdf0e10cSrcweir DECLARE_XINTERFACE( )
119cdf0e10cSrcweir DECLARE_XTYPEPROVIDER( )
120cdf0e10cSrcweir
121cdf0e10cSrcweir // OAccessibleWrapper
122cdf0e10cSrcweir virtual OAccessibleContextWrapper* createAccessibleContext(
123cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& _rxInnerContext
124cdf0e10cSrcweir );
125cdf0e10cSrcweir
126cdf0e10cSrcweir // XUnoTunnel
127cdf0e10cSrcweir virtual sal_Int64 SAL_CALL getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException);
128cdf0e10cSrcweir static Sequence< sal_Int8 > getUnoTunnelImplementationId();
129cdf0e10cSrcweir };
130cdf0e10cSrcweir
131cdf0e10cSrcweir // -------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(OToolBoxWindowItem,OAccessibleWrapper,OToolBoxWindowItem_Base)132cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( OToolBoxWindowItem, OAccessibleWrapper, OToolBoxWindowItem_Base )
133cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( OToolBoxWindowItem, OAccessibleWrapper, OToolBoxWindowItem_Base )
134cdf0e10cSrcweir
135cdf0e10cSrcweir // -------------------------------------------------------------------------
136cdf0e10cSrcweir OAccessibleContextWrapper* OToolBoxWindowItem::createAccessibleContext(
137cdf0e10cSrcweir const Reference< XAccessibleContext >& _rxInnerContext )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir return new OToolBoxWindowItemContext( m_nIndexInParent,getORB(), _rxInnerContext, this, getParent() );
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir //--------------------------------------------------------------------
isWindowItem(const Reference<XAccessible> & _rxAcc,OToolBoxWindowItem ** _ppImplementation)143cdf0e10cSrcweir sal_Bool OToolBoxWindowItem::isWindowItem( const Reference< XAccessible >& _rxAcc, OToolBoxWindowItem** /* [out] */ _ppImplementation )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir OToolBoxWindowItem* pImplementation = NULL;
146cdf0e10cSrcweir
147cdf0e10cSrcweir Reference< XUnoTunnel > xTunnel( _rxAcc, UNO_QUERY );
148cdf0e10cSrcweir if ( xTunnel.is() )
149cdf0e10cSrcweir pImplementation = reinterpret_cast< OToolBoxWindowItem* >( xTunnel->getSomething( getUnoTunnelImplementationId() ) );
150cdf0e10cSrcweir
151cdf0e10cSrcweir if ( _ppImplementation )
152cdf0e10cSrcweir *_ppImplementation = pImplementation;
153cdf0e10cSrcweir
154cdf0e10cSrcweir return NULL != pImplementation;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157cdf0e10cSrcweir //--------------------------------------------------------------------
getUnoTunnelImplementationId()158cdf0e10cSrcweir Sequence< sal_Int8 > OToolBoxWindowItem::getUnoTunnelImplementationId()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0;
161cdf0e10cSrcweir if (! pId)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
164cdf0e10cSrcweir if (! pId)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir static ::cppu::OImplementationId aId;
167cdf0e10cSrcweir pId = &aId;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir return pId->getImplementationId();
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir //--------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & _rId)174cdf0e10cSrcweir sal_Int64 SAL_CALL OToolBoxWindowItem::getSomething( const Sequence< sal_Int8 >& _rId ) throw (RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir if ( ( 16 == _rId.getLength() )
177cdf0e10cSrcweir && ( 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(), _rId.getConstArray(), 16 ) )
178cdf0e10cSrcweir )
179cdf0e10cSrcweir return reinterpret_cast< sal_Int64>( this );
180cdf0e10cSrcweir
181cdf0e10cSrcweir return 0;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir }
184cdf0e10cSrcweir
DBG_NAME(VCLXAccessibleToolBox)185cdf0e10cSrcweir DBG_NAME(VCLXAccessibleToolBox)
186cdf0e10cSrcweir
187cdf0e10cSrcweir // -----------------------------------------------------------------------------
188cdf0e10cSrcweir // VCLXAccessibleToolBox
189cdf0e10cSrcweir // -----------------------------------------------------------------------------
190cdf0e10cSrcweir VCLXAccessibleToolBox::VCLXAccessibleToolBox( VCLXWindow* pVCLXWindow ) :
191cdf0e10cSrcweir
192cdf0e10cSrcweir VCLXAccessibleComponent( pVCLXWindow )
193cdf0e10cSrcweir
194cdf0e10cSrcweir {
195cdf0e10cSrcweir DBG_CTOR(VCLXAccessibleToolBox,NULL);
196cdf0e10cSrcweir }
197cdf0e10cSrcweir // -----------------------------------------------------------------------------
~VCLXAccessibleToolBox()198cdf0e10cSrcweir VCLXAccessibleToolBox::~VCLXAccessibleToolBox()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir DBG_DTOR(VCLXAccessibleToolBox,NULL);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetItem_Impl(sal_Int32 _nPos,bool _bMustHaveFocus)203cdf0e10cSrcweir VCLXAccessibleToolBoxItem* VCLXAccessibleToolBox::GetItem_Impl( sal_Int32 _nPos, bool _bMustHaveFocus )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem = NULL;
206cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
207cdf0e10cSrcweir if ( pToolBox && ( !_bMustHaveFocus || pToolBox->HasFocus() ) )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
210cdf0e10cSrcweir // returns only toolbox buttons, not windows
21121075d77SSteve Yin if ( aIter != m_aAccessibleChildren.end() && aIter->second.is())
212cdf0e10cSrcweir pItem = static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir return pItem;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir // -----------------------------------------------------------------------------
218cdf0e10cSrcweir
UpdateFocus_Impl()219cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateFocus_Impl()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
222cdf0e10cSrcweir if( !pToolBox )
223cdf0e10cSrcweir return;
224cdf0e10cSrcweir
225cdf0e10cSrcweir // submit events only if toolbox has the focus to avoid sending events due to mouse move
226cdf0e10cSrcweir sal_Bool bHasFocus = sal_False;
227cdf0e10cSrcweir if ( pToolBox->HasFocus() )
228cdf0e10cSrcweir bHasFocus = sal_True;
229cdf0e10cSrcweir else
230cdf0e10cSrcweir {
231cdf0e10cSrcweir // check for subtoolbar, i.e. check if our parent is a toolbar
232cdf0e10cSrcweir ToolBox* pToolBoxParent = dynamic_cast< ToolBox* >( pToolBox->GetParent() );
233cdf0e10cSrcweir // subtoolbars never get the focus as key input is just forwarded, so check if the parent toolbar has it
234cdf0e10cSrcweir if ( pToolBoxParent && pToolBoxParent->HasFocus() )
235cdf0e10cSrcweir bHasFocus = sal_True;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir if ( bHasFocus )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId();
241cdf0e10cSrcweir sal_uInt16 nFocusCount = 0;
242cdf0e10cSrcweir for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
243cdf0e10cSrcweir aIter != m_aAccessibleChildren.end(); ++aIter )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)aIter->first );
246cdf0e10cSrcweir
247cdf0e10cSrcweir if ( aIter->second.is() )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem =
250cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
251cdf0e10cSrcweir if ( pItem->HasFocus() && nItemId != nHighlightItemId )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir // reset the old focused item
254cdf0e10cSrcweir pItem->SetFocus( sal_False );
255cdf0e10cSrcweir nFocusCount++;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir if ( nItemId == nHighlightItemId )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir // set the new focused item
260cdf0e10cSrcweir pItem->SetFocus( sal_True );
261cdf0e10cSrcweir nFocusCount++;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir // both items changed?
265cdf0e10cSrcweir if ( nFocusCount > 1 )
266cdf0e10cSrcweir break;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir }
269cdf0e10cSrcweir }
270cdf0e10cSrcweir // -----------------------------------------------------------------------------
ReleaseFocus_Impl(sal_Int32 _nPos)271cdf0e10cSrcweir void VCLXAccessibleToolBox::ReleaseFocus_Impl( sal_Int32 _nPos )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
274cdf0e10cSrcweir if ( pToolBox ) // #107124#, do not check for focus because this message is also handled in losefocus
275cdf0e10cSrcweir {
276cdf0e10cSrcweir ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
277cdf0e10cSrcweir if ( aIter != m_aAccessibleChildren.end() && aIter->second.is() )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem =
280cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
281cdf0e10cSrcweir if ( pItem->HasFocus() )
282cdf0e10cSrcweir pItem->SetFocus( sal_False );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir }
285cdf0e10cSrcweir }
286cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateChecked_Impl(sal_Int32 _nPos)28721075d77SSteve Yin void VCLXAccessibleToolBox::UpdateChecked_Impl( sal_Int32 _nPos )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
290cdf0e10cSrcweir if ( pToolBox )
291cdf0e10cSrcweir {
29221075d77SSteve Yin sal_uInt16 nFocusId = pToolBox->GetItemId( (sal_uInt16)_nPos );
29321075d77SSteve Yin VCLXAccessibleToolBoxItem* pFocusItem = NULL;
29421075d77SSteve Yin
295cdf0e10cSrcweir for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
296cdf0e10cSrcweir aIter != m_aAccessibleChildren.end(); ++aIter )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)aIter->first );
299cdf0e10cSrcweir
300cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem =
301cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
302cdf0e10cSrcweir pItem->SetChecked( pToolBox->IsItemChecked( nItemId ) );
30321075d77SSteve Yin if ( nItemId == nFocusId )
30421075d77SSteve Yin pFocusItem = pItem;
305cdf0e10cSrcweir }
30621075d77SSteve Yin // Solution: If the position is not a child item, the focus should not be called
30721075d77SSteve Yin if ( pFocusItem && (sal_uInt16)_nPos != TOOLBOX_ITEM_NOTFOUND )
30821075d77SSteve Yin pFocusItem->SetFocus( sal_True );
309cdf0e10cSrcweir }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateIndeterminate_Impl(sal_Int32 _nPos)312cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateIndeterminate_Impl( sal_Int32 _nPos )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
315cdf0e10cSrcweir if ( pToolBox )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)_nPos );
318cdf0e10cSrcweir
319cdf0e10cSrcweir ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
320cdf0e10cSrcweir if ( aIter != m_aAccessibleChildren.end() && aIter->second.is() )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem =
323cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
324cdf0e10cSrcweir if ( pItem )
325cdf0e10cSrcweir pItem->SetIndeterminate( pToolBox->GetItemState( nItemId ) == STATE_DONTKNOW );
326cdf0e10cSrcweir }
327cdf0e10cSrcweir }
328cdf0e10cSrcweir }
329cdf0e10cSrcweir // -----------------------------------------------------------------------------
implReleaseToolboxItem(ToolBoxItemsMap::iterator & _rMapPos,bool _bNotifyRemoval,bool _bDispose)330cdf0e10cSrcweir void VCLXAccessibleToolBox::implReleaseToolboxItem( ToolBoxItemsMap::iterator& _rMapPos,
331cdf0e10cSrcweir bool _bNotifyRemoval, bool _bDispose )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir Reference< XAccessible > xItemAcc( _rMapPos->second );
334cdf0e10cSrcweir if ( !xItemAcc.is() )
335cdf0e10cSrcweir return;
336cdf0e10cSrcweir
337cdf0e10cSrcweir if ( _bNotifyRemoval )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, makeAny( xItemAcc ), Any() );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
342cdf0e10cSrcweir OToolBoxWindowItem* pWindowItem = NULL;
343cdf0e10cSrcweir if ( !OToolBoxWindowItem::isWindowItem( xItemAcc, &pWindowItem ) )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( xItemAcc.get() )->ReleaseToolBox();
346cdf0e10cSrcweir if ( _bDispose )
347cdf0e10cSrcweir ::comphelper::disposeComponent( xItemAcc );
348cdf0e10cSrcweir }
349cdf0e10cSrcweir else
350cdf0e10cSrcweir {
351cdf0e10cSrcweir if ( _bDispose )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir if ( pWindowItem )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir Reference< XAccessibleContext > xContext( pWindowItem->getContextNoCreate() );
356cdf0e10cSrcweir ::comphelper::disposeComponent( xContext );
357cdf0e10cSrcweir }
358cdf0e10cSrcweir }
359cdf0e10cSrcweir }
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
362cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateItem_Impl(sal_Int32 _nPos,sal_Bool _bItemAdded)363cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateItem_Impl( sal_Int32 _nPos, sal_Bool _bItemAdded )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir if ( _nPos < sal_Int32( m_aAccessibleChildren.size() ) )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir UpdateAllItems_Impl();
368cdf0e10cSrcweir return;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
372cdf0e10cSrcweir if ( pToolBox )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir if ( !_bItemAdded )
375cdf0e10cSrcweir { // the item was removed
376cdf0e10cSrcweir // -> destroy the old item
377cdf0e10cSrcweir ToolBoxItemsMap::iterator aItemPos = m_aAccessibleChildren.find( _nPos );
378cdf0e10cSrcweir if ( m_aAccessibleChildren.end() != aItemPos )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir implReleaseToolboxItem( aItemPos, true, true );
381cdf0e10cSrcweir m_aAccessibleChildren.erase( aItemPos );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
385cdf0e10cSrcweir // adjust the "index-in-parent"s
386cdf0e10cSrcweir ToolBoxItemsMap::iterator aIndexAdjust = m_aAccessibleChildren.upper_bound( _nPos );
387cdf0e10cSrcweir while ( m_aAccessibleChildren.end() != aIndexAdjust )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir Reference< XAccessible > xItemAcc( aIndexAdjust->second );
390cdf0e10cSrcweir
391cdf0e10cSrcweir OToolBoxWindowItem* pWindowItem = NULL;
392cdf0e10cSrcweir if ( !OToolBoxWindowItem::isWindowItem( xItemAcc, &pWindowItem ) )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem = static_cast< VCLXAccessibleToolBoxItem* >( xItemAcc.get() );
395cdf0e10cSrcweir if ( pItem )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir sal_Int32 nIndex = pItem->getIndexInParent( );
398cdf0e10cSrcweir nIndex += _bItemAdded ? +1 : -1;
399cdf0e10cSrcweir pItem->setIndexInParent( nIndex );
400cdf0e10cSrcweir }
401cdf0e10cSrcweir }
402cdf0e10cSrcweir else
403cdf0e10cSrcweir {
404cdf0e10cSrcweir if ( pWindowItem )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir sal_Int32 nIndex = pWindowItem->getIndexInParent( );
407cdf0e10cSrcweir nIndex += _bItemAdded ? +1 : -1;
408cdf0e10cSrcweir pWindowItem->setIndexInParent( nIndex );
409cdf0e10cSrcweir }
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
412cdf0e10cSrcweir ++aIndexAdjust;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
415cdf0e10cSrcweir if ( _bItemAdded )
416cdf0e10cSrcweir {
417cdf0e10cSrcweir // TODO: we should make this dependent on the existence of event listeners
418cdf0e10cSrcweir // with the current implementation, we always create accessible object
419cdf0e10cSrcweir Any aNewChild = makeAny( getAccessibleChild( (sal_Int32)_nPos ) );
420cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewChild );
421cdf0e10cSrcweir }
422cdf0e10cSrcweir }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateAllItems_Impl()425cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateAllItems_Impl()
426cdf0e10cSrcweir {
427cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
428cdf0e10cSrcweir if ( pToolBox )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir // deregister the old items
431cdf0e10cSrcweir for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
432cdf0e10cSrcweir aIter != m_aAccessibleChildren.end(); ++aIter )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir implReleaseToolboxItem( aIter, true, true );
435cdf0e10cSrcweir }
436cdf0e10cSrcweir m_aAccessibleChildren.clear();
437cdf0e10cSrcweir
438cdf0e10cSrcweir // register the new items
439cdf0e10cSrcweir sal_uInt16 i, nCount = pToolBox->GetItemCount();
440cdf0e10cSrcweir for ( i = 0; i < nCount; ++i )
441cdf0e10cSrcweir {
442cdf0e10cSrcweir Any aNewValue;
443*6bcc9fe0Smseidel aNewValue <<= getAccessibleChild( (sal_Int32)i );
444cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewValue );
445cdf0e10cSrcweir }
446cdf0e10cSrcweir }
447cdf0e10cSrcweir }
448cdf0e10cSrcweir
449cdf0e10cSrcweir // -----------------------------------------------------------------------------
450cdf0e10cSrcweir
UpdateCustomPopupItemp_Impl(Window * pWindow,bool bOpen)451cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateCustomPopupItemp_Impl( Window* pWindow, bool bOpen )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
454cdf0e10cSrcweir if( pWindow && pToolBox )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir Reference< XAccessible > xChild( pWindow->GetAccessible() );
457cdf0e10cSrcweir if( xChild.is() )
458cdf0e10cSrcweir {
459cdf0e10cSrcweir Reference< XAccessible > xChildItem( getAccessibleChild( static_cast< sal_Int32 >( pToolBox->GetItemPos( pToolBox->GetDownItemId() ) ) ) );
460cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem = static_cast< VCLXAccessibleToolBoxItem* >( xChildItem.get() );
461cdf0e10cSrcweir
462cdf0e10cSrcweir pItem->SetChild( xChild );
463cdf0e10cSrcweir pItem->NotifyChildEvent( xChild, bOpen );
464cdf0e10cSrcweir }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
468cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateItemName_Impl(sal_Int32 _nPos)469cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateItemName_Impl( sal_Int32 _nPos )
470cdf0e10cSrcweir {
471cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem = GetItem_Impl( _nPos, false );
472cdf0e10cSrcweir if ( pItem )
473cdf0e10cSrcweir pItem->NameChanged();
474cdf0e10cSrcweir }
475cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateItemEnabled_Impl(sal_Int32 _nPos)476cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateItemEnabled_Impl( sal_Int32 _nPos )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem = GetItem_Impl( _nPos, false );
479cdf0e10cSrcweir if ( pItem )
480cdf0e10cSrcweir pItem->ToggleEnableState();
481cdf0e10cSrcweir }
482cdf0e10cSrcweir // -----------------------------------------------------------------------------
HandleSubToolBarEvent(const VclWindowEvent & rVclWindowEvent,bool _bShow)483cdf0e10cSrcweir void VCLXAccessibleToolBox::HandleSubToolBarEvent( const VclWindowEvent& rVclWindowEvent, bool _bShow )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
486cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
487cdf0e10cSrcweir if ( pChildWindow
488cdf0e10cSrcweir && pToolBox
489cdf0e10cSrcweir && pToolBox == pChildWindow->GetParent()
490cdf0e10cSrcweir && pChildWindow->GetType() == WINDOW_TOOLBOX )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir sal_Int32 nIndex = pToolBox->GetItemPos( pToolBox->GetCurItemId() );
493cdf0e10cSrcweir Reference< XAccessible > xItem = getAccessibleChild( nIndex );
494cdf0e10cSrcweir if ( xItem.is() )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir Reference< XAccessible > xChild = pChildWindow->GetAccessible();
497cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem =
498cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( xItem.get() );
499cdf0e10cSrcweir pItem->SetChild( xChild );
500cdf0e10cSrcweir pItem->NotifyChildEvent( xChild, _bShow );
501cdf0e10cSrcweir }
502cdf0e10cSrcweir }
503cdf0e10cSrcweir }
504cdf0e10cSrcweir // -----------------------------------------------------------------------------
ReleaseSubToolBox(ToolBox * _pSubToolBox)505cdf0e10cSrcweir void VCLXAccessibleToolBox::ReleaseSubToolBox( ToolBox* _pSubToolBox )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
508cdf0e10cSrcweir if ( pToolBox )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir sal_Int32 nIndex = pToolBox->GetItemPos( pToolBox->GetCurItemId() );
511cdf0e10cSrcweir Reference< XAccessible > xItem = getAccessibleChild( nIndex );
512cdf0e10cSrcweir if ( xItem.is() )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir Reference< XAccessible > xChild = _pSubToolBox->GetAccessible();
515cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pItem =
516cdf0e10cSrcweir static_cast< VCLXAccessibleToolBoxItem* >( xItem.get() );
517cdf0e10cSrcweir if ( pItem->GetChild() == xChild )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir pItem->SetChild( Reference< XAccessible >() );
520cdf0e10cSrcweir pItem->NotifyChildEvent( xChild, false );
521cdf0e10cSrcweir }
522cdf0e10cSrcweir }
523cdf0e10cSrcweir }
524cdf0e10cSrcweir }
525cdf0e10cSrcweir // -----------------------------------------------------------------------------
FillAccessibleStateSet(utl::AccessibleStateSetHelper & rStateSet)526cdf0e10cSrcweir void VCLXAccessibleToolBox::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
529cdf0e10cSrcweir
530cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
531cdf0e10cSrcweir if ( pToolBox )
532cdf0e10cSrcweir {
533cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSABLE );
534cdf0e10cSrcweir if ( pToolBox->IsHorizontal() )
535cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::HORIZONTAL );
536cdf0e10cSrcweir else
537cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::VERTICAL );
538cdf0e10cSrcweir }
539cdf0e10cSrcweir }
540cdf0e10cSrcweir // -----------------------------------------------------------------------------
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)541cdf0e10cSrcweir void VCLXAccessibleToolBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir // to prevent an early release of the toolbox (VCLEVENT_OBJECT_DYING)
544cdf0e10cSrcweir Reference< XAccessibleContext > xTemp = this;
545cdf0e10cSrcweir
54621075d77SSteve Yin ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
547cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() )
548cdf0e10cSrcweir {
549cdf0e10cSrcweir case VCLEVENT_TOOLBOX_CLICK:
55021075d77SSteve Yin case VCLEVENT_TOOLBOX_SELECT:
551cdf0e10cSrcweir {
552cdf0e10cSrcweir if ( rVclWindowEvent.GetData() )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir UpdateChecked_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
555cdf0e10cSrcweir UpdateIndeterminate_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
556cdf0e10cSrcweir }
55721075d77SSteve Yin else if( pToolBox->GetItemPos(pToolBox->GetCurItemId()) != TOOLBOX_ITEM_NOTFOUND )
55821075d77SSteve Yin {
55921075d77SSteve Yin UpdateChecked_Impl( pToolBox->GetItemPos(pToolBox->GetCurItemId()) );
56021075d77SSteve Yin UpdateIndeterminate_Impl( pToolBox->GetItemPos(pToolBox->GetCurItemId()) );
56121075d77SSteve Yin }
562cdf0e10cSrcweir break;
563cdf0e10cSrcweir }
564cdf0e10cSrcweir case VCLEVENT_TOOLBOX_DOUBLECLICK:
565cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ACTIVATE:
566cdf0e10cSrcweir case VCLEVENT_TOOLBOX_DEACTIVATE:
56721075d77SSteve Yin //case VCLEVENT_TOOLBOX_SELECT:
568cdf0e10cSrcweir break;
56921075d77SSteve Yin // IA2 CWS. MT: Still using VCLEVENT_TOOLBOX_CLICK, see comment in vcl/source/window/toolbox2.cxx
57021075d77SSteve Yin /*
57121075d77SSteve Yin case VCLEVENT_TOOLBOX_ITEMUPDATED:
57221075d77SSteve Yin {
57321075d77SSteve Yin if ( rVclWindowEvent.GetData() )
57421075d77SSteve Yin {
57521075d77SSteve Yin UpdateChecked_Impl( TOOLBOX_ITEM_NOTFOUND );
57621075d77SSteve Yin UpdateIndeterminate_Impl( (sal_Int32)rVclWindowEvent.GetData() );
57721075d77SSteve Yin }
57821075d77SSteve Yin break;
57921075d77SSteve Yin }
58021075d77SSteve Yin */
581cdf0e10cSrcweir case VCLEVENT_TOOLBOX_HIGHLIGHT:
582cdf0e10cSrcweir UpdateFocus_Impl();
583cdf0e10cSrcweir break;
584cdf0e10cSrcweir
585cdf0e10cSrcweir case VCLEVENT_TOOLBOX_HIGHLIGHTOFF:
586cdf0e10cSrcweir ReleaseFocus_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
587cdf0e10cSrcweir break;
588cdf0e10cSrcweir
589cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ITEMADDED :
590cdf0e10cSrcweir // UpdateItem_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData(), VCLEVENT_TOOLBOX_ITEMADDED == rVclWindowEvent.GetId() );
591cdf0e10cSrcweir UpdateItem_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData(), sal_True );
592cdf0e10cSrcweir break;
593cdf0e10cSrcweir
594cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ITEMREMOVED :
595cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ALLITEMSCHANGED :
596cdf0e10cSrcweir {
597cdf0e10cSrcweir UpdateAllItems_Impl();
598cdf0e10cSrcweir break;
599cdf0e10cSrcweir }
600cdf0e10cSrcweir
601cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ITEMWINDOWCHANGED:
602cdf0e10cSrcweir {
603cdf0e10cSrcweir sal_Int32 nPos = (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData();
604cdf0e10cSrcweir ToolBoxItemsMap::iterator aAccessiblePos( m_aAccessibleChildren.find( nPos ) );
605cdf0e10cSrcweir if ( m_aAccessibleChildren.end() != aAccessiblePos )
606cdf0e10cSrcweir {
607cdf0e10cSrcweir implReleaseToolboxItem( aAccessiblePos, false, true );
608cdf0e10cSrcweir m_aAccessibleChildren.erase (aAccessiblePos);
609cdf0e10cSrcweir }
610cdf0e10cSrcweir
611cdf0e10cSrcweir Any aNewValue;
612cdf0e10cSrcweir aNewValue <<= getAccessibleChild(nPos);
613cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewValue );
614cdf0e10cSrcweir break;
615cdf0e10cSrcweir }
616cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ITEMTEXTCHANGED :
617cdf0e10cSrcweir UpdateItemName_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
618cdf0e10cSrcweir break;
619cdf0e10cSrcweir
620cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ITEMENABLED :
621cdf0e10cSrcweir case VCLEVENT_TOOLBOX_ITEMDISABLED :
622cdf0e10cSrcweir {
623cdf0e10cSrcweir UpdateItemEnabled_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
624cdf0e10cSrcweir break;
625cdf0e10cSrcweir }
626cdf0e10cSrcweir
627cdf0e10cSrcweir case VCLEVENT_DROPDOWN_OPEN:
628cdf0e10cSrcweir case VCLEVENT_DROPDOWN_CLOSE:
629cdf0e10cSrcweir {
630cdf0e10cSrcweir UpdateCustomPopupItemp_Impl( static_cast< Window* >( rVclWindowEvent.GetData() ), rVclWindowEvent.GetId() == VCLEVENT_DROPDOWN_OPEN );
631cdf0e10cSrcweir break;
632cdf0e10cSrcweir }
633cdf0e10cSrcweir
634cdf0e10cSrcweir case VCLEVENT_OBJECT_DYING :
635cdf0e10cSrcweir {
63625e2a94aSMatthias Seidel // if this toolbox is a subtoolbox, we have to release it from its parent
637cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
638cdf0e10cSrcweir if ( pToolBox && pToolBox->GetParent() &&
639cdf0e10cSrcweir pToolBox->GetParent()->GetType() == WINDOW_TOOLBOX )
640cdf0e10cSrcweir {
641cdf0e10cSrcweir VCLXAccessibleToolBox* pParent = static_cast< VCLXAccessibleToolBox* >(
642cdf0e10cSrcweir pToolBox->GetParent()->GetAccessible()->getAccessibleContext().get() );
643cdf0e10cSrcweir if ( pParent )
644cdf0e10cSrcweir pParent->ReleaseSubToolBox( pToolBox );
645cdf0e10cSrcweir }
646cdf0e10cSrcweir
647cdf0e10cSrcweir // dispose all items
648cdf0e10cSrcweir for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
649cdf0e10cSrcweir aIter != m_aAccessibleChildren.end(); ++aIter )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir implReleaseToolboxItem( aIter, false, true );
652cdf0e10cSrcweir }
653cdf0e10cSrcweir m_aAccessibleChildren.clear();
654cdf0e10cSrcweir
655cdf0e10cSrcweir // !!! no break to call base class
656cdf0e10cSrcweir }
657cdf0e10cSrcweir
658cdf0e10cSrcweir default:
659cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
660cdf0e10cSrcweir }
661cdf0e10cSrcweir }
662cdf0e10cSrcweir // -----------------------------------------------------------------------------
ProcessWindowChildEvent(const VclWindowEvent & rVclWindowEvent)663cdf0e10cSrcweir void VCLXAccessibleToolBox::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() )
666cdf0e10cSrcweir {
667cdf0e10cSrcweir case VCLEVENT_WINDOW_SHOW: // send create on show for direct accessible children
668cdf0e10cSrcweir {
669cdf0e10cSrcweir Reference< XAccessible > xReturn = GetItemWindowAccessible(rVclWindowEvent);
670cdf0e10cSrcweir if ( xReturn.is() )
671cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), makeAny(xReturn) );
672cdf0e10cSrcweir else
673cdf0e10cSrcweir HandleSubToolBarEvent( rVclWindowEvent, true );
674cdf0e10cSrcweir }
675cdf0e10cSrcweir break;
676cdf0e10cSrcweir
677cdf0e10cSrcweir default:
678cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowChildEvent( rVclWindowEvent );
679cdf0e10cSrcweir
680cdf0e10cSrcweir }
681cdf0e10cSrcweir }
682cdf0e10cSrcweir // -----------------------------------------------------------------------------
683cdf0e10cSrcweir // XInterface
684cdf0e10cSrcweir // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleToolBox,VCLXAccessibleComponent,VCLXAccessibleToolBox_BASE)685cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleToolBox, VCLXAccessibleComponent, VCLXAccessibleToolBox_BASE )
686cdf0e10cSrcweir // -----------------------------------------------------------------------------
687cdf0e10cSrcweir // XTypeProvider
688cdf0e10cSrcweir // -----------------------------------------------------------------------------
689cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBox, VCLXAccessibleComponent, VCLXAccessibleToolBox_BASE )
690cdf0e10cSrcweir // -----------------------------------------------------------------------------
691cdf0e10cSrcweir // XComponent
692cdf0e10cSrcweir // -----------------------------------------------------------------------------
693cdf0e10cSrcweir void SAL_CALL VCLXAccessibleToolBox::disposing()
694cdf0e10cSrcweir {
695cdf0e10cSrcweir VCLXAccessibleComponent::disposing();
696cdf0e10cSrcweir
697cdf0e10cSrcweir // release the items
698cdf0e10cSrcweir for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
699cdf0e10cSrcweir aIter != m_aAccessibleChildren.end(); ++aIter )
700cdf0e10cSrcweir {
701cdf0e10cSrcweir implReleaseToolboxItem( aIter, false, true );
702cdf0e10cSrcweir }
703cdf0e10cSrcweir m_aAccessibleChildren.clear();
704cdf0e10cSrcweir }
705cdf0e10cSrcweir // -----------------------------------------------------------------------------
706cdf0e10cSrcweir // XServiceInfo
707cdf0e10cSrcweir // -----------------------------------------------------------------------------
getImplementationName()708cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleToolBox::getImplementationName() throw (RuntimeException)
709cdf0e10cSrcweir {
710cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleToolBox" );
711cdf0e10cSrcweir }
712cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSupportedServiceNames()713cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleToolBox::getSupportedServiceNames() throw (RuntimeException)
714cdf0e10cSrcweir {
715cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames = VCLXAccessibleComponent::getSupportedServiceNames();
716cdf0e10cSrcweir sal_Int32 nLength = aNames.getLength();
717cdf0e10cSrcweir aNames.realloc( nLength + 1 );
718cdf0e10cSrcweir aNames[nLength] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleToolBox" );
719cdf0e10cSrcweir return aNames;
720cdf0e10cSrcweir }
721cdf0e10cSrcweir // -----------------------------------------------------------------------------
722cdf0e10cSrcweir // XAccessibleContext
723cdf0e10cSrcweir // -----------------------------------------------------------------------------
getAccessibleChildCount()724cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount( ) throw (RuntimeException)
725cdf0e10cSrcweir {
726cdf0e10cSrcweir comphelper::OExternalLockGuard aGuard( this );
727cdf0e10cSrcweir
728cdf0e10cSrcweir sal_Int32 nCount = 0;
729cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
730cdf0e10cSrcweir if ( pToolBox )
731cdf0e10cSrcweir nCount = pToolBox->GetItemCount();
732cdf0e10cSrcweir
733cdf0e10cSrcweir return nCount;
734cdf0e10cSrcweir }
735cdf0e10cSrcweir // -----------------------------------------------------------------------------
getAccessibleChild(sal_Int32 i)736cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
737cdf0e10cSrcweir {
738cdf0e10cSrcweir if ( i < 0 || i >= getAccessibleChildCount() )
739cdf0e10cSrcweir throw IndexOutOfBoundsException();
740cdf0e10cSrcweir
741cdf0e10cSrcweir comphelper::OExternalLockGuard aGuard( this );
742cdf0e10cSrcweir
743cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
744cdf0e10cSrcweir if ( pToolBox )
745cdf0e10cSrcweir {
746cdf0e10cSrcweir Reference< XAccessible > xChild;
747cdf0e10cSrcweir // search for the child
748cdf0e10cSrcweir ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i);
749cdf0e10cSrcweir if ( m_aAccessibleChildren.end() == aIter )
750cdf0e10cSrcweir {
751cdf0e10cSrcweir sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)i );
752cdf0e10cSrcweir sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId();
753cdf0e10cSrcweir Window* pItemWindow = pToolBox->GetItemWindow( nItemId );
754cdf0e10cSrcweir // not found -> create a new child
755cdf0e10cSrcweir VCLXAccessibleToolBoxItem* pChild = new VCLXAccessibleToolBoxItem( pToolBox, i );
756cdf0e10cSrcweir Reference< XAccessible> xParent = pChild;
757cdf0e10cSrcweir if ( pItemWindow )
758cdf0e10cSrcweir {
759cdf0e10cSrcweir xChild = new OToolBoxWindowItem(0,::comphelper::getProcessServiceFactory(),pItemWindow->GetAccessible(),xParent);
760cdf0e10cSrcweir pItemWindow->SetAccessible(xChild);
761cdf0e10cSrcweir pChild->SetChild( xChild );
762cdf0e10cSrcweir }
763cdf0e10cSrcweir xChild = pChild;
764cdf0e10cSrcweir if ( nHighlightItemId > 0 && nItemId == nHighlightItemId )
765cdf0e10cSrcweir pChild->SetFocus( sal_True );
766cdf0e10cSrcweir if ( pToolBox->IsItemChecked( nItemId ) )
767cdf0e10cSrcweir pChild->SetChecked( sal_True );
768cdf0e10cSrcweir if ( pToolBox->GetItemState( nItemId ) == STATE_DONTKNOW )
769cdf0e10cSrcweir pChild->SetIndeterminate( true );
770cdf0e10cSrcweir m_aAccessibleChildren.insert( ToolBoxItemsMap::value_type( i, xChild ) );
771cdf0e10cSrcweir }
772cdf0e10cSrcweir else
773cdf0e10cSrcweir {
774cdf0e10cSrcweir // found it
775cdf0e10cSrcweir xChild = aIter->second;
776cdf0e10cSrcweir }
777cdf0e10cSrcweir return xChild;
778cdf0e10cSrcweir }
779cdf0e10cSrcweir
780cdf0e10cSrcweir return NULL;
781cdf0e10cSrcweir }
782cdf0e10cSrcweir // -----------------------------------------------------------------------------
getAccessibleAtPoint(const awt::Point & _rPoint)783cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleAtPoint( const awt::Point& _rPoint ) throw (RuntimeException)
784cdf0e10cSrcweir {
785cdf0e10cSrcweir comphelper::OExternalLockGuard aGuard( this );
786cdf0e10cSrcweir
787cdf0e10cSrcweir Reference< XAccessible > xAccessible;
788cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
789cdf0e10cSrcweir if ( pToolBox )
790cdf0e10cSrcweir {
791cdf0e10cSrcweir sal_uInt16 nItemPos = pToolBox->GetItemPos( VCLPoint( _rPoint ) );
792cdf0e10cSrcweir if ( nItemPos != TOOLBOX_ITEM_NOTFOUND )
793cdf0e10cSrcweir xAccessible = getAccessibleChild( nItemPos );
794cdf0e10cSrcweir }
795cdf0e10cSrcweir
796cdf0e10cSrcweir return xAccessible;
797cdf0e10cSrcweir }
798cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetItemWindowAccessible(const VclWindowEvent & rVclWindowEvent)799cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleToolBox::GetItemWindowAccessible( const VclWindowEvent& rVclWindowEvent )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir Reference< XAccessible > xReturn;
802cdf0e10cSrcweir Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
803cdf0e10cSrcweir ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
804cdf0e10cSrcweir if ( pChildWindow && pToolBox )
805cdf0e10cSrcweir {
806cdf0e10cSrcweir sal_uInt16 nCount = pToolBox->GetItemCount();
807cdf0e10cSrcweir for (sal_uInt16 i = 0 ; i < nCount && !xReturn.is() ; ++i)
808cdf0e10cSrcweir {
809cdf0e10cSrcweir sal_uInt16 nItemId = pToolBox->GetItemId( i );
810cdf0e10cSrcweir Window* pItemWindow = pToolBox->GetItemWindow( nItemId );
811cdf0e10cSrcweir if ( pItemWindow == pChildWindow )
812cdf0e10cSrcweir xReturn = getAccessibleChild(i);
813cdf0e10cSrcweir }
814cdf0e10cSrcweir }
815cdf0e10cSrcweir return xReturn;
816cdf0e10cSrcweir }
817cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetChildAccessible(const VclWindowEvent & rVclWindowEvent)818cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleToolBox::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
819cdf0e10cSrcweir {
820cdf0e10cSrcweir Reference< XAccessible > xReturn = GetItemWindowAccessible(rVclWindowEvent);
821cdf0e10cSrcweir
822cdf0e10cSrcweir if ( !xReturn.is() )
823cdf0e10cSrcweir xReturn = VCLXAccessibleComponent::GetChildAccessible(rVclWindowEvent);
824cdf0e10cSrcweir return xReturn;
825cdf0e10cSrcweir }
826cdf0e10cSrcweir // -----------------------------------------------------------------------------
827cdf0e10cSrcweir // XAccessibleSelection
828cdf0e10cSrcweir // -----------------------------------------------------------------------------
selectAccessibleChild(sal_Int32 nChildIndex)829cdf0e10cSrcweir void VCLXAccessibleToolBox::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
830cdf0e10cSrcweir {
831cdf0e10cSrcweir OExternalLockGuard aGuard( this );
832cdf0e10cSrcweir if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
833cdf0e10cSrcweir throw IndexOutOfBoundsException();
834cdf0e10cSrcweir ToolBox * pToolBox = static_cast < ToolBox * > ( GetWindow() );
835cdf0e10cSrcweir sal_uInt16 nPos = static_cast < sal_uInt16 > (nChildIndex);
836cdf0e10cSrcweir pToolBox->ChangeHighlight( nPos );
837cdf0e10cSrcweir }
838cdf0e10cSrcweir // -----------------------------------------------------------------------------
isAccessibleChildSelected(sal_Int32 nChildIndex)839cdf0e10cSrcweir sal_Bool VCLXAccessibleToolBox::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
840cdf0e10cSrcweir {
841cdf0e10cSrcweir OExternalLockGuard aGuard( this );
842cdf0e10cSrcweir if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
843cdf0e10cSrcweir throw IndexOutOfBoundsException();
844cdf0e10cSrcweir ToolBox * pToolBox = static_cast < ToolBox * > ( GetWindow() );
845cdf0e10cSrcweir sal_uInt16 nPos = static_cast < sal_uInt16 > (nChildIndex);
846cdf0e10cSrcweir if ( pToolBox != NULL && pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nPos ) )
847cdf0e10cSrcweir return sal_True;
848cdf0e10cSrcweir else
849cdf0e10cSrcweir return sal_False;
850cdf0e10cSrcweir }
851cdf0e10cSrcweir // -----------------------------------------------------------------------------
clearAccessibleSelection()852cdf0e10cSrcweir void VCLXAccessibleToolBox::clearAccessibleSelection( ) throw (RuntimeException)
853cdf0e10cSrcweir {
854cdf0e10cSrcweir OExternalLockGuard aGuard( this );
855cdf0e10cSrcweir ToolBox * pToolBox = static_cast < ToolBox * > ( GetWindow() );
856cdf0e10cSrcweir pToolBox -> LoseFocus();
857cdf0e10cSrcweir }
858cdf0e10cSrcweir // -----------------------------------------------------------------------------
selectAllAccessibleChildren()859cdf0e10cSrcweir void VCLXAccessibleToolBox::selectAllAccessibleChildren( ) throw (RuntimeException)
860cdf0e10cSrcweir {
861cdf0e10cSrcweir OExternalLockGuard aGuard( this );
862cdf0e10cSrcweir // intentionally empty. makes no sense for a toolbox
863cdf0e10cSrcweir }
864cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSelectedAccessibleChildCount()865cdf0e10cSrcweir sal_Int32 VCLXAccessibleToolBox::getSelectedAccessibleChildCount( ) throw (RuntimeException)
866cdf0e10cSrcweir {
867cdf0e10cSrcweir OExternalLockGuard aGuard( this );
868cdf0e10cSrcweir sal_Int32 nRet = 0;
869cdf0e10cSrcweir for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; i++ )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir if ( isAccessibleChildSelected( i ) )
872cdf0e10cSrcweir {
873cdf0e10cSrcweir nRet = 1;
874cdf0e10cSrcweir break; // a toolbox can only have (n)one selected child
875cdf0e10cSrcweir }
876cdf0e10cSrcweir }
877cdf0e10cSrcweir return nRet;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)880cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleToolBox::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
881cdf0e10cSrcweir {
882cdf0e10cSrcweir OExternalLockGuard aGuard( this );
883cdf0e10cSrcweir if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
884cdf0e10cSrcweir throw IndexOutOfBoundsException();
885cdf0e10cSrcweir Reference< XAccessible > xChild;
886cdf0e10cSrcweir for ( sal_Int32 i = 0, j = 0, nCount = getAccessibleChildCount(); i < nCount; i++ )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir if ( isAccessibleChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir xChild = getAccessibleChild( i );
891cdf0e10cSrcweir break;
892cdf0e10cSrcweir }
893cdf0e10cSrcweir }
894cdf0e10cSrcweir return xChild;
895cdf0e10cSrcweir }
896cdf0e10cSrcweir // -----------------------------------------------------------------------------
deselectAccessibleChild(sal_Int32 nChildIndex)897cdf0e10cSrcweir void VCLXAccessibleToolBox::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
898cdf0e10cSrcweir {
899cdf0e10cSrcweir OExternalLockGuard aGuard( this );
900cdf0e10cSrcweir if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
901cdf0e10cSrcweir throw IndexOutOfBoundsException();
902cdf0e10cSrcweir clearAccessibleSelection(); // a toolbox can only have (n)one selected child
903cdf0e10cSrcweir }
904cdf0e10cSrcweir // -----------------------------------------------------------------------------
905