xref: /trunk/main/accessibility/source/standard/vclxaccessibletoolbox.cxx (revision c82f28778d59b20a7e6c0f9982d1bc73807a432a)
1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c82f2877SAndrew Rist  * distributed with this work for additional information
6*c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c82f2877SAndrew Rist  * specific language governing permissions and limitations
18*c82f2877SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*c82f2877SAndrew Rist  *************************************************************/
21*c82f2877SAndrew Rist 
22*c82f2877SAndrew 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:
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     // -------------------------------------------------------------------------
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:
98cdf0e10cSrcweir         inline sal_Int32    getIndexInParent() const                    { return m_nIndexInParent; }
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:
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     // -------------------------------------------------------------------------
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     //--------------------------------------------------------------------
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     //--------------------------------------------------------------------
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     //--------------------------------------------------------------------
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 
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 // -----------------------------------------------------------------------------
198cdf0e10cSrcweir VCLXAccessibleToolBox::~VCLXAccessibleToolBox()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     DBG_DTOR(VCLXAccessibleToolBox,NULL);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir // -----------------------------------------------------------------------------
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
211cdf0e10cSrcweir         if ( aIter != m_aAccessibleChildren.end()  && !aIter->second.is())
212cdf0e10cSrcweir             pItem = static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     return pItem;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir // -----------------------------------------------------------------------------
218cdf0e10cSrcweir 
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 // -----------------------------------------------------------------------------
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 // -----------------------------------------------------------------------------
287cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateChecked_Impl( sal_Int32  )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
290cdf0e10cSrcweir     if ( pToolBox )
291cdf0e10cSrcweir     {
292cdf0e10cSrcweir         for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
293cdf0e10cSrcweir               aIter != m_aAccessibleChildren.end(); ++aIter )
294cdf0e10cSrcweir         {
295cdf0e10cSrcweir                 sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)aIter->first );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir                 VCLXAccessibleToolBoxItem* pItem =
298cdf0e10cSrcweir                     static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
299cdf0e10cSrcweir                 pItem->SetChecked( pToolBox->IsItemChecked( nItemId ) );
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir }
303cdf0e10cSrcweir // -----------------------------------------------------------------------------
304cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateIndeterminate_Impl( sal_Int32 _nPos )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
307cdf0e10cSrcweir     if ( pToolBox )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)_nPos );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir         ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find( _nPos );
312cdf0e10cSrcweir         if ( aIter != m_aAccessibleChildren.end() && aIter->second.is() )
313cdf0e10cSrcweir         {
314cdf0e10cSrcweir             VCLXAccessibleToolBoxItem* pItem =
315cdf0e10cSrcweir                 static_cast< VCLXAccessibleToolBoxItem* >( aIter->second.get() );
316cdf0e10cSrcweir             if ( pItem )
317cdf0e10cSrcweir                 pItem->SetIndeterminate( pToolBox->GetItemState( nItemId ) == STATE_DONTKNOW );
318cdf0e10cSrcweir         }
319cdf0e10cSrcweir     }
320cdf0e10cSrcweir }
321cdf0e10cSrcweir // -----------------------------------------------------------------------------
322cdf0e10cSrcweir void VCLXAccessibleToolBox::implReleaseToolboxItem( ToolBoxItemsMap::iterator& _rMapPos,
323cdf0e10cSrcweir         bool _bNotifyRemoval, bool _bDispose )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir     Reference< XAccessible > xItemAcc( _rMapPos->second );
326cdf0e10cSrcweir     if ( !xItemAcc.is() )
327cdf0e10cSrcweir         return;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     if ( _bNotifyRemoval )
330cdf0e10cSrcweir     {
331cdf0e10cSrcweir         NotifyAccessibleEvent( AccessibleEventId::CHILD, makeAny( xItemAcc ), Any() );
332cdf0e10cSrcweir     }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     OToolBoxWindowItem* pWindowItem = NULL;
335cdf0e10cSrcweir     if ( !OToolBoxWindowItem::isWindowItem( xItemAcc, &pWindowItem ) )
336cdf0e10cSrcweir     {
337cdf0e10cSrcweir         static_cast< VCLXAccessibleToolBoxItem* >( xItemAcc.get() )->ReleaseToolBox();
338cdf0e10cSrcweir         if ( _bDispose )
339cdf0e10cSrcweir             ::comphelper::disposeComponent( xItemAcc );
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir     else
342cdf0e10cSrcweir     {
343cdf0e10cSrcweir         if ( _bDispose )
344cdf0e10cSrcweir         {
345cdf0e10cSrcweir             if ( pWindowItem )
346cdf0e10cSrcweir             {
347cdf0e10cSrcweir                 Reference< XAccessibleContext > xContext( pWindowItem->getContextNoCreate() );
348cdf0e10cSrcweir                 ::comphelper::disposeComponent( xContext );
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir // -----------------------------------------------------------------------------
355cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateItem_Impl( sal_Int32 _nPos, sal_Bool _bItemAdded )
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     if ( _nPos < sal_Int32( m_aAccessibleChildren.size() ) )
358cdf0e10cSrcweir     {
359cdf0e10cSrcweir         UpdateAllItems_Impl();
360cdf0e10cSrcweir         return;
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
364cdf0e10cSrcweir     if ( pToolBox )
365cdf0e10cSrcweir     {
366cdf0e10cSrcweir         if ( !_bItemAdded )
367cdf0e10cSrcweir         {   // the item was removed
368cdf0e10cSrcweir             // -> destroy the old item
369cdf0e10cSrcweir             ToolBoxItemsMap::iterator aItemPos = m_aAccessibleChildren.find( _nPos );
370cdf0e10cSrcweir             if ( m_aAccessibleChildren.end() != aItemPos )
371cdf0e10cSrcweir             {
372cdf0e10cSrcweir                 implReleaseToolboxItem( aItemPos, true, true );
373cdf0e10cSrcweir                 m_aAccessibleChildren.erase( aItemPos );
374cdf0e10cSrcweir             }
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir         // adjust the "index-in-parent"s
378cdf0e10cSrcweir         ToolBoxItemsMap::iterator aIndexAdjust = m_aAccessibleChildren.upper_bound( _nPos );
379cdf0e10cSrcweir         while ( m_aAccessibleChildren.end() != aIndexAdjust )
380cdf0e10cSrcweir         {
381cdf0e10cSrcweir             Reference< XAccessible > xItemAcc( aIndexAdjust->second );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir             OToolBoxWindowItem* pWindowItem = NULL;
384cdf0e10cSrcweir             if ( !OToolBoxWindowItem::isWindowItem( xItemAcc, &pWindowItem ) )
385cdf0e10cSrcweir             {
386cdf0e10cSrcweir                 VCLXAccessibleToolBoxItem* pItem = static_cast< VCLXAccessibleToolBoxItem* >( xItemAcc.get() );
387cdf0e10cSrcweir                 if ( pItem )
388cdf0e10cSrcweir                 {
389cdf0e10cSrcweir                     sal_Int32 nIndex = pItem->getIndexInParent( );
390cdf0e10cSrcweir                     nIndex += _bItemAdded ? +1 : -1;
391cdf0e10cSrcweir                     pItem->setIndexInParent( nIndex );
392cdf0e10cSrcweir                 }
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir             else
395cdf0e10cSrcweir             {
396cdf0e10cSrcweir                 if ( pWindowItem )
397cdf0e10cSrcweir                 {
398cdf0e10cSrcweir                     sal_Int32 nIndex = pWindowItem->getIndexInParent( );
399cdf0e10cSrcweir                     nIndex += _bItemAdded ? +1 : -1;
400cdf0e10cSrcweir                     pWindowItem->setIndexInParent( nIndex );
401cdf0e10cSrcweir                 }
402cdf0e10cSrcweir             }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir             ++aIndexAdjust;
405cdf0e10cSrcweir         }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir         if ( _bItemAdded )
408cdf0e10cSrcweir         {
409cdf0e10cSrcweir             // TODO: we should make this dependent on the existence of event listeners
410cdf0e10cSrcweir             // with the current implementation, we always create accessible object
411cdf0e10cSrcweir             Any aNewChild = makeAny( getAccessibleChild( (sal_Int32)_nPos ) );
412cdf0e10cSrcweir             NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewChild );
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir }
416cdf0e10cSrcweir // -----------------------------------------------------------------------------
417cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateAllItems_Impl()
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
420cdf0e10cSrcweir     if ( pToolBox )
421cdf0e10cSrcweir     {
422cdf0e10cSrcweir         // deregister the old items
423cdf0e10cSrcweir         for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
424cdf0e10cSrcweir               aIter != m_aAccessibleChildren.end(); ++aIter )
425cdf0e10cSrcweir         {
426cdf0e10cSrcweir             implReleaseToolboxItem( aIter, true, true );
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir         m_aAccessibleChildren.clear();
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         // register the new items
431cdf0e10cSrcweir         sal_uInt16 i, nCount = pToolBox->GetItemCount();
432cdf0e10cSrcweir         for ( i = 0; i < nCount; ++i )
433cdf0e10cSrcweir         {
434cdf0e10cSrcweir             Any aNewValue;
435cdf0e10cSrcweir             aNewValue <<= getAccessibleChild( (sal_Int32)i );;
436cdf0e10cSrcweir             NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewValue );
437cdf0e10cSrcweir         }
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir // -----------------------------------------------------------------------------
442cdf0e10cSrcweir 
443cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateCustomPopupItemp_Impl( Window* pWindow, bool bOpen )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
446cdf0e10cSrcweir     if( pWindow && pToolBox )
447cdf0e10cSrcweir     {
448cdf0e10cSrcweir         Reference< XAccessible > xChild( pWindow->GetAccessible() );
449cdf0e10cSrcweir         if( xChild.is() )
450cdf0e10cSrcweir         {
451cdf0e10cSrcweir             Reference< XAccessible > xChildItem( getAccessibleChild( static_cast< sal_Int32 >( pToolBox->GetItemPos( pToolBox->GetDownItemId() ) ) ) );
452cdf0e10cSrcweir             VCLXAccessibleToolBoxItem* pItem = static_cast< VCLXAccessibleToolBoxItem* >( xChildItem.get() );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir             pItem->SetChild( xChild );
455cdf0e10cSrcweir             pItem->NotifyChildEvent( xChild, bOpen );
456cdf0e10cSrcweir         }
457cdf0e10cSrcweir     }
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir // -----------------------------------------------------------------------------
461cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateItemName_Impl( sal_Int32 _nPos )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     VCLXAccessibleToolBoxItem* pItem = GetItem_Impl( _nPos, false );
464cdf0e10cSrcweir     if ( pItem )
465cdf0e10cSrcweir         pItem->NameChanged();
466cdf0e10cSrcweir }
467cdf0e10cSrcweir // -----------------------------------------------------------------------------
468cdf0e10cSrcweir void VCLXAccessibleToolBox::UpdateItemEnabled_Impl( sal_Int32 _nPos )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     VCLXAccessibleToolBoxItem* pItem = GetItem_Impl( _nPos, false );
471cdf0e10cSrcweir     if ( pItem )
472cdf0e10cSrcweir         pItem->ToggleEnableState();
473cdf0e10cSrcweir }
474cdf0e10cSrcweir // -----------------------------------------------------------------------------
475cdf0e10cSrcweir void VCLXAccessibleToolBox::HandleSubToolBarEvent( const VclWindowEvent& rVclWindowEvent, bool _bShow )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
478cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
479cdf0e10cSrcweir     if ( pChildWindow
480cdf0e10cSrcweir         && pToolBox
481cdf0e10cSrcweir         && pToolBox == pChildWindow->GetParent()
482cdf0e10cSrcweir         && pChildWindow->GetType() == WINDOW_TOOLBOX )
483cdf0e10cSrcweir     {
484cdf0e10cSrcweir         sal_Int32 nIndex = pToolBox->GetItemPos( pToolBox->GetCurItemId() );
485cdf0e10cSrcweir         Reference< XAccessible > xItem = getAccessibleChild( nIndex );
486cdf0e10cSrcweir         if ( xItem.is() )
487cdf0e10cSrcweir         {
488cdf0e10cSrcweir             Reference< XAccessible > xChild = pChildWindow->GetAccessible();
489cdf0e10cSrcweir             VCLXAccessibleToolBoxItem* pItem =
490cdf0e10cSrcweir                 static_cast< VCLXAccessibleToolBoxItem* >( xItem.get() );
491cdf0e10cSrcweir             pItem->SetChild( xChild );
492cdf0e10cSrcweir             pItem->NotifyChildEvent( xChild, _bShow );
493cdf0e10cSrcweir         }
494cdf0e10cSrcweir     }
495cdf0e10cSrcweir }
496cdf0e10cSrcweir // -----------------------------------------------------------------------------
497cdf0e10cSrcweir void VCLXAccessibleToolBox::ReleaseSubToolBox( ToolBox* _pSubToolBox )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
500cdf0e10cSrcweir     if ( pToolBox )
501cdf0e10cSrcweir     {
502cdf0e10cSrcweir         sal_Int32 nIndex = pToolBox->GetItemPos( pToolBox->GetCurItemId() );
503cdf0e10cSrcweir         Reference< XAccessible > xItem = getAccessibleChild( nIndex );
504cdf0e10cSrcweir         if ( xItem.is() )
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             Reference< XAccessible > xChild = _pSubToolBox->GetAccessible();
507cdf0e10cSrcweir             VCLXAccessibleToolBoxItem* pItem =
508cdf0e10cSrcweir                 static_cast< VCLXAccessibleToolBoxItem* >( xItem.get() );
509cdf0e10cSrcweir             if ( pItem->GetChild() == xChild )
510cdf0e10cSrcweir             {
511cdf0e10cSrcweir                 pItem->SetChild( Reference< XAccessible >() );
512cdf0e10cSrcweir                 pItem->NotifyChildEvent( xChild, false );
513cdf0e10cSrcweir             }
514cdf0e10cSrcweir         }
515cdf0e10cSrcweir     }
516cdf0e10cSrcweir }
517cdf0e10cSrcweir // -----------------------------------------------------------------------------
518cdf0e10cSrcweir void VCLXAccessibleToolBox::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
523cdf0e10cSrcweir     if ( pToolBox )
524cdf0e10cSrcweir     {
525cdf0e10cSrcweir         rStateSet.AddState( AccessibleStateType::FOCUSABLE );
526cdf0e10cSrcweir         if ( pToolBox->IsHorizontal() )
527cdf0e10cSrcweir             rStateSet.AddState( AccessibleStateType::HORIZONTAL );
528cdf0e10cSrcweir         else
529cdf0e10cSrcweir             rStateSet.AddState( AccessibleStateType::VERTICAL );
530cdf0e10cSrcweir     }
531cdf0e10cSrcweir }
532cdf0e10cSrcweir // -----------------------------------------------------------------------------
533cdf0e10cSrcweir void VCLXAccessibleToolBox::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir     // to prevent an early release of the toolbox (VCLEVENT_OBJECT_DYING)
536cdf0e10cSrcweir     Reference< XAccessibleContext > xTemp = this;
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     switch ( rVclWindowEvent.GetId() )
539cdf0e10cSrcweir     {
540cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_CLICK:
541cdf0e10cSrcweir         {
542cdf0e10cSrcweir             if ( rVclWindowEvent.GetData() )
543cdf0e10cSrcweir             {
544cdf0e10cSrcweir                 UpdateChecked_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
545cdf0e10cSrcweir                 UpdateIndeterminate_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
546cdf0e10cSrcweir             }
547cdf0e10cSrcweir             break;
548cdf0e10cSrcweir         }
549cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_DOUBLECLICK:
550cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ACTIVATE:
551cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_DEACTIVATE:
552cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_SELECT:
553cdf0e10cSrcweir             break;
554cdf0e10cSrcweir 
555cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_HIGHLIGHT:
556cdf0e10cSrcweir             UpdateFocus_Impl();
557cdf0e10cSrcweir             break;
558cdf0e10cSrcweir 
559cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_HIGHLIGHTOFF:
560cdf0e10cSrcweir             ReleaseFocus_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
561cdf0e10cSrcweir             break;
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ITEMADDED :
564cdf0e10cSrcweir //            UpdateItem_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData(), VCLEVENT_TOOLBOX_ITEMADDED == rVclWindowEvent.GetId() );
565cdf0e10cSrcweir             UpdateItem_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData(), sal_True );
566cdf0e10cSrcweir             break;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ITEMREMOVED :
569cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ALLITEMSCHANGED :
570cdf0e10cSrcweir         {
571cdf0e10cSrcweir             UpdateAllItems_Impl();
572cdf0e10cSrcweir             break;
573cdf0e10cSrcweir         }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ITEMWINDOWCHANGED:
576cdf0e10cSrcweir         {
577cdf0e10cSrcweir             sal_Int32 nPos = (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData();
578cdf0e10cSrcweir             ToolBoxItemsMap::iterator aAccessiblePos( m_aAccessibleChildren.find( nPos ) );
579cdf0e10cSrcweir             if ( m_aAccessibleChildren.end() != aAccessiblePos )
580cdf0e10cSrcweir             {
581cdf0e10cSrcweir                 implReleaseToolboxItem( aAccessiblePos, false, true );
582cdf0e10cSrcweir                 m_aAccessibleChildren.erase (aAccessiblePos);
583cdf0e10cSrcweir             }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir             Any aNewValue;
586cdf0e10cSrcweir             aNewValue <<= getAccessibleChild(nPos);
587cdf0e10cSrcweir             NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), aNewValue );
588cdf0e10cSrcweir             break;
589cdf0e10cSrcweir         }
590cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ITEMTEXTCHANGED :
591cdf0e10cSrcweir             UpdateItemName_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
592cdf0e10cSrcweir             break;
593cdf0e10cSrcweir 
594cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ITEMENABLED :
595cdf0e10cSrcweir         case VCLEVENT_TOOLBOX_ITEMDISABLED :
596cdf0e10cSrcweir         {
597cdf0e10cSrcweir             UpdateItemEnabled_Impl( (sal_Int32)(sal_IntPtr)rVclWindowEvent.GetData() );
598cdf0e10cSrcweir             break;
599cdf0e10cSrcweir         }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir         case VCLEVENT_DROPDOWN_OPEN:
602cdf0e10cSrcweir         case VCLEVENT_DROPDOWN_CLOSE:
603cdf0e10cSrcweir         {
604cdf0e10cSrcweir             UpdateCustomPopupItemp_Impl( static_cast< Window* >( rVclWindowEvent.GetData() ), rVclWindowEvent.GetId() == VCLEVENT_DROPDOWN_OPEN );
605cdf0e10cSrcweir             break;
606cdf0e10cSrcweir         }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir         case VCLEVENT_OBJECT_DYING :
609cdf0e10cSrcweir         {
610cdf0e10cSrcweir             // if this toolbox is a subtoolbox, we have to relese it from its parent
611cdf0e10cSrcweir             ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
612cdf0e10cSrcweir             if ( pToolBox && pToolBox->GetParent() &&
613cdf0e10cSrcweir                  pToolBox->GetParent()->GetType() == WINDOW_TOOLBOX )
614cdf0e10cSrcweir             {
615cdf0e10cSrcweir                 VCLXAccessibleToolBox* pParent = static_cast< VCLXAccessibleToolBox* >(
616cdf0e10cSrcweir                     pToolBox->GetParent()->GetAccessible()->getAccessibleContext().get() );
617cdf0e10cSrcweir                 if ( pParent )
618cdf0e10cSrcweir                     pParent->ReleaseSubToolBox( pToolBox );
619cdf0e10cSrcweir             }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir             // dispose all items
622cdf0e10cSrcweir             for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
623cdf0e10cSrcweir                   aIter != m_aAccessibleChildren.end(); ++aIter )
624cdf0e10cSrcweir             {
625cdf0e10cSrcweir                 implReleaseToolboxItem( aIter, false, true );
626cdf0e10cSrcweir             }
627cdf0e10cSrcweir             m_aAccessibleChildren.clear();
628cdf0e10cSrcweir 
629cdf0e10cSrcweir             //!!! no break to call base class
630cdf0e10cSrcweir         }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir         default:
633cdf0e10cSrcweir             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
634cdf0e10cSrcweir     }
635cdf0e10cSrcweir }
636cdf0e10cSrcweir // -----------------------------------------------------------------------------
637cdf0e10cSrcweir void VCLXAccessibleToolBox::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
638cdf0e10cSrcweir {
639cdf0e10cSrcweir     switch ( rVclWindowEvent.GetId() )
640cdf0e10cSrcweir     {
641cdf0e10cSrcweir         case VCLEVENT_WINDOW_SHOW:  // send create on show for direct accessible children
642cdf0e10cSrcweir         {
643cdf0e10cSrcweir             Reference< XAccessible > xReturn = GetItemWindowAccessible(rVclWindowEvent);
644cdf0e10cSrcweir             if ( xReturn.is() )
645cdf0e10cSrcweir                 NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), makeAny(xReturn) );
646cdf0e10cSrcweir             else
647cdf0e10cSrcweir                 HandleSubToolBarEvent( rVclWindowEvent, true );
648cdf0e10cSrcweir         }
649cdf0e10cSrcweir         break;
650cdf0e10cSrcweir 
651cdf0e10cSrcweir         default:
652cdf0e10cSrcweir            VCLXAccessibleComponent::ProcessWindowChildEvent( rVclWindowEvent );
653cdf0e10cSrcweir 
654cdf0e10cSrcweir     }
655cdf0e10cSrcweir }
656cdf0e10cSrcweir // -----------------------------------------------------------------------------
657cdf0e10cSrcweir // XInterface
658cdf0e10cSrcweir // -----------------------------------------------------------------------------
659cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleToolBox, VCLXAccessibleComponent, VCLXAccessibleToolBox_BASE )
660cdf0e10cSrcweir // -----------------------------------------------------------------------------
661cdf0e10cSrcweir // XTypeProvider
662cdf0e10cSrcweir // -----------------------------------------------------------------------------
663cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBox, VCLXAccessibleComponent, VCLXAccessibleToolBox_BASE )
664cdf0e10cSrcweir // -----------------------------------------------------------------------------
665cdf0e10cSrcweir // XComponent
666cdf0e10cSrcweir // -----------------------------------------------------------------------------
667cdf0e10cSrcweir void SAL_CALL VCLXAccessibleToolBox::disposing()
668cdf0e10cSrcweir {
669cdf0e10cSrcweir     VCLXAccessibleComponent::disposing();
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     // release the items
672cdf0e10cSrcweir     for ( ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.begin();
673cdf0e10cSrcweir           aIter != m_aAccessibleChildren.end(); ++aIter )
674cdf0e10cSrcweir     {
675cdf0e10cSrcweir         implReleaseToolboxItem( aIter, false, true );
676cdf0e10cSrcweir     }
677cdf0e10cSrcweir     m_aAccessibleChildren.clear();
678cdf0e10cSrcweir }
679cdf0e10cSrcweir // -----------------------------------------------------------------------------
680cdf0e10cSrcweir // XServiceInfo
681cdf0e10cSrcweir // -----------------------------------------------------------------------------
682cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleToolBox::getImplementationName() throw (RuntimeException)
683cdf0e10cSrcweir {
684cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleToolBox" );
685cdf0e10cSrcweir }
686cdf0e10cSrcweir // -----------------------------------------------------------------------------
687cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleToolBox::getSupportedServiceNames() throw (RuntimeException)
688cdf0e10cSrcweir {
689cdf0e10cSrcweir     Sequence< ::rtl::OUString > aNames = VCLXAccessibleComponent::getSupportedServiceNames();
690cdf0e10cSrcweir     sal_Int32 nLength = aNames.getLength();
691cdf0e10cSrcweir     aNames.realloc( nLength + 1 );
692cdf0e10cSrcweir     aNames[nLength] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleToolBox" );
693cdf0e10cSrcweir     return aNames;
694cdf0e10cSrcweir }
695cdf0e10cSrcweir // -----------------------------------------------------------------------------
696cdf0e10cSrcweir // XAccessibleContext
697cdf0e10cSrcweir // -----------------------------------------------------------------------------
698cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleToolBox::getAccessibleChildCount(  ) throw (RuntimeException)
699cdf0e10cSrcweir {
700cdf0e10cSrcweir     comphelper::OExternalLockGuard aGuard( this );
701cdf0e10cSrcweir 
702cdf0e10cSrcweir     sal_Int32 nCount = 0;
703cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
704cdf0e10cSrcweir     if ( pToolBox )
705cdf0e10cSrcweir         nCount = pToolBox->GetItemCount();
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     return nCount;
708cdf0e10cSrcweir }
709cdf0e10cSrcweir // -----------------------------------------------------------------------------
710cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     if ( i < 0 || i >= getAccessibleChildCount() )
713cdf0e10cSrcweir         throw IndexOutOfBoundsException();
714cdf0e10cSrcweir 
715cdf0e10cSrcweir     comphelper::OExternalLockGuard aGuard( this );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
718cdf0e10cSrcweir     if ( pToolBox )
719cdf0e10cSrcweir     {
720cdf0e10cSrcweir         Reference< XAccessible > xChild;
721cdf0e10cSrcweir         // search for the child
722cdf0e10cSrcweir         ToolBoxItemsMap::iterator aIter = m_aAccessibleChildren.find(i);
723cdf0e10cSrcweir         if ( m_aAccessibleChildren.end() == aIter )
724cdf0e10cSrcweir         {
725cdf0e10cSrcweir             sal_uInt16 nItemId = pToolBox->GetItemId( (sal_uInt16)i );
726cdf0e10cSrcweir             sal_uInt16 nHighlightItemId = pToolBox->GetHighlightItemId();
727cdf0e10cSrcweir             Window* pItemWindow = pToolBox->GetItemWindow( nItemId );
728cdf0e10cSrcweir             // not found -> create a new child
729cdf0e10cSrcweir             VCLXAccessibleToolBoxItem* pChild = new VCLXAccessibleToolBoxItem( pToolBox, i );
730cdf0e10cSrcweir             Reference< XAccessible> xParent = pChild;
731cdf0e10cSrcweir             if ( pItemWindow )
732cdf0e10cSrcweir             {
733cdf0e10cSrcweir                 xChild = new OToolBoxWindowItem(0,::comphelper::getProcessServiceFactory(),pItemWindow->GetAccessible(),xParent);
734cdf0e10cSrcweir                 pItemWindow->SetAccessible(xChild);
735cdf0e10cSrcweir                 pChild->SetChild( xChild );
736cdf0e10cSrcweir             }
737cdf0e10cSrcweir             xChild = pChild;
738cdf0e10cSrcweir             if ( nHighlightItemId > 0 && nItemId == nHighlightItemId )
739cdf0e10cSrcweir                 pChild->SetFocus( sal_True );
740cdf0e10cSrcweir             if ( pToolBox->IsItemChecked( nItemId ) )
741cdf0e10cSrcweir                 pChild->SetChecked( sal_True );
742cdf0e10cSrcweir             if ( pToolBox->GetItemState( nItemId ) == STATE_DONTKNOW )
743cdf0e10cSrcweir                 pChild->SetIndeterminate( true );
744cdf0e10cSrcweir             m_aAccessibleChildren.insert( ToolBoxItemsMap::value_type( i, xChild ) );
745cdf0e10cSrcweir         }
746cdf0e10cSrcweir         else
747cdf0e10cSrcweir         {
748cdf0e10cSrcweir             // found it
749cdf0e10cSrcweir             xChild = aIter->second;
750cdf0e10cSrcweir         }
751cdf0e10cSrcweir         return xChild;
752cdf0e10cSrcweir     }
753cdf0e10cSrcweir 
754cdf0e10cSrcweir     return NULL;
755cdf0e10cSrcweir }
756cdf0e10cSrcweir // -----------------------------------------------------------------------------
757cdf0e10cSrcweir Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleAtPoint( const awt::Point& _rPoint ) throw (RuntimeException)
758cdf0e10cSrcweir {
759cdf0e10cSrcweir     comphelper::OExternalLockGuard aGuard( this );
760cdf0e10cSrcweir 
761cdf0e10cSrcweir     Reference< XAccessible > xAccessible;
762cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
763cdf0e10cSrcweir     if ( pToolBox )
764cdf0e10cSrcweir     {
765cdf0e10cSrcweir         sal_uInt16 nItemPos = pToolBox->GetItemPos( VCLPoint( _rPoint ) );
766cdf0e10cSrcweir         if ( nItemPos != TOOLBOX_ITEM_NOTFOUND )
767cdf0e10cSrcweir             xAccessible = getAccessibleChild( nItemPos );
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir     return xAccessible;
771cdf0e10cSrcweir }
772cdf0e10cSrcweir // -----------------------------------------------------------------------------
773cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleToolBox::GetItemWindowAccessible( const VclWindowEvent& rVclWindowEvent )
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     Reference< XAccessible > xReturn;
776cdf0e10cSrcweir     Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
777cdf0e10cSrcweir     ToolBox* pToolBox = static_cast< ToolBox* >( GetWindow() );
778cdf0e10cSrcweir     if ( pChildWindow && pToolBox )
779cdf0e10cSrcweir     {
780cdf0e10cSrcweir         sal_uInt16 nCount = pToolBox->GetItemCount();
781cdf0e10cSrcweir         for (sal_uInt16 i = 0 ; i < nCount && !xReturn.is() ; ++i)
782cdf0e10cSrcweir         {
783cdf0e10cSrcweir             sal_uInt16 nItemId = pToolBox->GetItemId( i );
784cdf0e10cSrcweir             Window* pItemWindow = pToolBox->GetItemWindow( nItemId );
785cdf0e10cSrcweir             if ( pItemWindow == pChildWindow )
786cdf0e10cSrcweir                 xReturn = getAccessibleChild(i);
787cdf0e10cSrcweir         }
788cdf0e10cSrcweir     }
789cdf0e10cSrcweir     return xReturn;
790cdf0e10cSrcweir }
791cdf0e10cSrcweir // -----------------------------------------------------------------------------
792cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleToolBox::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
793cdf0e10cSrcweir {
794cdf0e10cSrcweir     Reference< XAccessible > xReturn = GetItemWindowAccessible(rVclWindowEvent);
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     if ( !xReturn.is() )
797cdf0e10cSrcweir         xReturn = VCLXAccessibleComponent::GetChildAccessible(rVclWindowEvent);
798cdf0e10cSrcweir     return xReturn;
799cdf0e10cSrcweir }
800cdf0e10cSrcweir // -----------------------------------------------------------------------------
801cdf0e10cSrcweir // XAccessibleSelection
802cdf0e10cSrcweir // -----------------------------------------------------------------------------
803cdf0e10cSrcweir void VCLXAccessibleToolBox::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
804cdf0e10cSrcweir {
805cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
806cdf0e10cSrcweir     if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
807cdf0e10cSrcweir         throw IndexOutOfBoundsException();
808cdf0e10cSrcweir     ToolBox * pToolBox = static_cast < ToolBox * > ( GetWindow() );
809cdf0e10cSrcweir     sal_uInt16 nPos = static_cast < sal_uInt16 > (nChildIndex);
810cdf0e10cSrcweir     pToolBox->ChangeHighlight( nPos );
811cdf0e10cSrcweir }
812cdf0e10cSrcweir // -----------------------------------------------------------------------------
813cdf0e10cSrcweir sal_Bool VCLXAccessibleToolBox::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
814cdf0e10cSrcweir {
815cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
816cdf0e10cSrcweir     if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
817cdf0e10cSrcweir         throw IndexOutOfBoundsException();
818cdf0e10cSrcweir     ToolBox * pToolBox = static_cast < ToolBox * > ( GetWindow() );
819cdf0e10cSrcweir     sal_uInt16 nPos = static_cast < sal_uInt16 > (nChildIndex);
820cdf0e10cSrcweir     if ( pToolBox != NULL && pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nPos ) )
821cdf0e10cSrcweir         return sal_True;
822cdf0e10cSrcweir     else
823cdf0e10cSrcweir         return sal_False;
824cdf0e10cSrcweir }
825cdf0e10cSrcweir // -----------------------------------------------------------------------------
826cdf0e10cSrcweir void VCLXAccessibleToolBox::clearAccessibleSelection(  ) throw (RuntimeException)
827cdf0e10cSrcweir {
828cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
829cdf0e10cSrcweir     ToolBox * pToolBox = static_cast < ToolBox * > ( GetWindow() );
830cdf0e10cSrcweir     pToolBox -> LoseFocus();
831cdf0e10cSrcweir }
832cdf0e10cSrcweir // -----------------------------------------------------------------------------
833cdf0e10cSrcweir void VCLXAccessibleToolBox::selectAllAccessibleChildren(  ) throw (RuntimeException)
834cdf0e10cSrcweir {
835cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
836cdf0e10cSrcweir     // intentionally empty. makes no sense for a toolbox
837cdf0e10cSrcweir }
838cdf0e10cSrcweir // -----------------------------------------------------------------------------
839cdf0e10cSrcweir sal_Int32 VCLXAccessibleToolBox::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
840cdf0e10cSrcweir {
841cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
842cdf0e10cSrcweir     sal_Int32 nRet = 0;
843cdf0e10cSrcweir     for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; i++ )
844cdf0e10cSrcweir     {
845cdf0e10cSrcweir         if ( isAccessibleChildSelected( i ) )
846cdf0e10cSrcweir         {
847cdf0e10cSrcweir             nRet = 1;
848cdf0e10cSrcweir             break; // a toolbox can only have (n)one selected child
849cdf0e10cSrcweir         }
850cdf0e10cSrcweir     }
851cdf0e10cSrcweir     return nRet;
852cdf0e10cSrcweir }
853cdf0e10cSrcweir // -----------------------------------------------------------------------------
854cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleToolBox::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
855cdf0e10cSrcweir {
856cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
857cdf0e10cSrcweir     if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
858cdf0e10cSrcweir         throw IndexOutOfBoundsException();
859cdf0e10cSrcweir     Reference< XAccessible > xChild;
860cdf0e10cSrcweir     for ( sal_Int32 i = 0, j = 0, nCount = getAccessibleChildCount(); i < nCount; i++ )
861cdf0e10cSrcweir     {
862cdf0e10cSrcweir         if ( isAccessibleChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
863cdf0e10cSrcweir         {
864cdf0e10cSrcweir             xChild = getAccessibleChild( i );
865cdf0e10cSrcweir             break;
866cdf0e10cSrcweir         }
867cdf0e10cSrcweir     }
868cdf0e10cSrcweir     return xChild;
869cdf0e10cSrcweir }
870cdf0e10cSrcweir // -----------------------------------------------------------------------------
871cdf0e10cSrcweir void VCLXAccessibleToolBox::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
872cdf0e10cSrcweir {
873cdf0e10cSrcweir     OExternalLockGuard aGuard( this );
874cdf0e10cSrcweir     if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount() )
875cdf0e10cSrcweir         throw IndexOutOfBoundsException();
876cdf0e10cSrcweir     clearAccessibleSelection(); // a toolbox can only have (n)one selected child
877cdf0e10cSrcweir }
878cdf0e10cSrcweir // -----------------------------------------------------------------------------
879