LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessibletoolbox.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 418 0.0 %
Date: 2014-04-14 Functions: 0 57 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10