LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - vclxaccessiblelist.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 411 0.0 %
Date: 2012-12-27 Functions: 0 42 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             : 
      20             : #include <accessibility/standard/vclxaccessiblelist.hxx>
      21             : #include <accessibility/standard/vclxaccessiblelistitem.hxx>
      22             : #include <accessibility/helper/listboxhelper.hxx>
      23             : 
      24             : #include <unotools/accessiblestatesethelper.hxx>
      25             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      27             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      28             : #include <vcl/svapp.hxx>
      29             : #include <vcl/combobox.hxx>
      30             : #include <vcl/lstbox.hxx>
      31             : #include <toolkit/helper/convert.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::lang;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::accessibility;
      38             : using namespace ::accessibility;
      39             : 
      40             : namespace
      41             : {
      42           0 :     void checkSelection_Impl( sal_Int32 _nIndex, const IComboListBoxHelper& _rListBox, sal_Bool bSelected )
      43             :         throw (::com::sun::star::lang::IndexOutOfBoundsException)
      44             :     {
      45           0 :         sal_Int32 nCount = bSelected ? (sal_Int32)_rListBox.GetSelectEntryCount()
      46           0 :                                      : (sal_Int32)_rListBox.GetEntryCount();
      47           0 :         if ( _nIndex < 0 || _nIndex >= nCount )
      48           0 :             throw ::com::sun::star::lang::IndexOutOfBoundsException();
      49           0 :     }
      50             : }
      51             : 
      52           0 : VCLXAccessibleList::VCLXAccessibleList (VCLXWindow* pVCLWindow, BoxType aBoxType,
      53             :                                         const Reference< XAccessible >& _xParent)
      54             :     : VCLXAccessibleComponent   (pVCLWindow),
      55             :       m_aBoxType                (aBoxType),
      56             :       m_nVisibleLineCount       (0),
      57             :       m_nIndexInParent          (DEFAULT_INDEX_IN_PARENT),
      58             :       m_nLastTopEntry           ( 0 ),
      59             :       m_nLastSelectedPos        ( LISTBOX_ENTRY_NOTFOUND ),
      60             :       m_bDisableProcessEvent    ( false ),
      61             :       m_bVisible                ( true ),
      62           0 :       m_xParent                 ( _xParent )
      63             : {
      64             :     // Because combo boxes and list boxes don't have a common interface for
      65             :     // methods with identical signature we have to write down twice the
      66             :     // same code.
      67           0 :     switch (m_aBoxType)
      68             :     {
      69             :         case COMBOBOX:
      70             :         {
      71           0 :             ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
      72           0 :             if ( pBox != NULL )
      73           0 :                 m_pListBoxHelper = new VCLListBoxHelper<ComboBox> (*pBox);
      74           0 :             break;
      75             :         }
      76             : 
      77             :         case LISTBOX:
      78             :         {
      79           0 :             ListBox* pBox = static_cast<ListBox*>(GetWindow());
      80           0 :             if ( pBox != NULL )
      81           0 :                 m_pListBoxHelper = new VCLListBoxHelper<ListBox> (*pBox);
      82           0 :             break;
      83             :         }
      84             :     }
      85           0 :     UpdateVisibleLineCount();
      86             : 
      87           0 :     sal_uInt16 nCount = static_cast<sal_uInt16>(getAccessibleChildCount());
      88           0 :     m_aAccessibleChildren.reserve(nCount);
      89           0 : }
      90             : // -----------------------------------------------------------------------------
      91             : 
      92           0 : VCLXAccessibleList::~VCLXAccessibleList (void)
      93             : {
      94           0 :     delete m_pListBoxHelper;
      95           0 : }
      96             : // -----------------------------------------------------------------------------
      97             : 
      98           0 : void VCLXAccessibleList::SetIndexInParent (sal_Int32 nIndex)
      99             : {
     100           0 :     m_nIndexInParent = nIndex;
     101           0 : }
     102             : // -----------------------------------------------------------------------------
     103             : 
     104           0 : void SAL_CALL VCLXAccessibleList::disposing (void)
     105             : {
     106           0 :     VCLXAccessibleComponent::disposing();
     107             : 
     108             :     // Dispose all items in the list.
     109           0 :     clearItems();
     110             : 
     111           0 :     delete m_pListBoxHelper;
     112           0 :     m_pListBoxHelper = NULL;
     113           0 : }
     114             : // -----------------------------------------------------------------------------
     115             : 
     116           0 : void VCLXAccessibleList::clearItems()
     117             : {
     118             :     // Clear the list itself and delete all the rest.
     119           0 :     ListItems().swap(m_aAccessibleChildren); // clear and minimize
     120           0 : }
     121             : // -----------------------------------------------------------------------------
     122             : 
     123           0 : void VCLXAccessibleList::FillAccessibleStateSet (utl::AccessibleStateSetHelper& rStateSet)
     124             : {
     125           0 :     SolarMutexGuard aSolarGuard;
     126             : 
     127           0 :     VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
     128             :     // check if our list should be visible
     129           0 :     if (    m_pListBoxHelper
     130           0 :         && (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN
     131           0 :         && !m_pListBoxHelper->IsInDropDown() )
     132             :     {
     133           0 :         rStateSet.RemoveState (AccessibleStateType::VISIBLE);
     134           0 :         rStateSet.RemoveState (AccessibleStateType::SHOWING);
     135           0 :         m_bVisible = false;
     136             :     }
     137             : 
     138             :     // Both the combo box and list box are handled identical in the
     139             :     // following but for some reason they don't have a common interface for
     140             :     // the methods used.
     141           0 :     if ( m_pListBoxHelper )
     142             :     {
     143           0 :         if ( m_pListBoxHelper->IsMultiSelectionEnabled() )
     144           0 :             rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE);
     145           0 :         rStateSet.AddState (AccessibleStateType::FOCUSABLE);
     146             :         // All children are transient.
     147           0 :         rStateSet.AddState (AccessibleStateType::MANAGES_DESCENDANTS);
     148           0 :     }
     149           0 : }
     150             : // -----------------------------------------------------------------------------
     151           0 : void VCLXAccessibleList::notifyVisibleStates(sal_Bool _bSetNew )
     152             : {
     153           0 :     m_bVisible = _bSetNew ? true : false;
     154           0 :     Any aOldValue, aNewValue;
     155           0 :     (_bSetNew ? aNewValue : aOldValue ) <<= AccessibleStateType::VISIBLE;
     156           0 :     NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
     157           0 :     (_bSetNew ? aNewValue : aOldValue ) <<= AccessibleStateType::SHOWING;
     158           0 :     NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
     159             : 
     160           0 :     ListItems::iterator aIter = m_aAccessibleChildren.begin();
     161           0 :     ListItems::iterator aEnd = m_aAccessibleChildren.end();
     162           0 :     UpdateVisibleLineCount();
     163             :     // adjust the index inside the VCLXAccessibleListItem
     164           0 :     for (;aIter != aEnd ; ++aIter)
     165             :     {
     166           0 :         Reference< XAccessible > xHold = *aIter;
     167           0 :         VCLXAccessibleListItem* pItem = static_cast<VCLXAccessibleListItem*>(xHold.get());
     168           0 :         if ( pItem )
     169             :         {
     170           0 :             sal_uInt16 nTopEntry = 0;
     171           0 :             if ( m_pListBoxHelper )
     172           0 :                 nTopEntry = m_pListBoxHelper->GetTopEntry();
     173           0 :             sal_uInt16 nPos = (sal_uInt16)(aIter - m_aAccessibleChildren.begin());
     174           0 :             sal_Bool bVisible = ( nPos>=nTopEntry && nPos<( nTopEntry + m_nVisibleLineCount ) );
     175           0 :             pItem->SetVisible( m_bVisible && bVisible );
     176             :         }
     177             : 
     178           0 :     }
     179           0 : }
     180             : // -----------------------------------------------------------------------------
     181           0 : void VCLXAccessibleList::ProcessWindowEvent (const VclWindowEvent& rVclWindowEvent)
     182             : {
     183             :     // Create a reference to this object to prevent an early release of the
     184             :     // listbox (VCLEVENT_OBJECT_DYING).
     185           0 :     Reference< XAccessible > xTemp = this;
     186             : 
     187           0 :     switch ( rVclWindowEvent.GetId() )
     188             :     {
     189             :         case VCLEVENT_DROPDOWN_OPEN:
     190           0 :             notifyVisibleStates(sal_True);
     191           0 :             break;
     192             :         case VCLEVENT_DROPDOWN_CLOSE:
     193           0 :             notifyVisibleStates(sal_False);
     194           0 :             break;
     195             :         case VCLEVENT_LISTBOX_SCROLLED:
     196             :         case VCLEVENT_COMBOBOX_SCROLLED:
     197           0 :             UpdateEntryRange_Impl();
     198           0 :             break;
     199             : 
     200             :         case VCLEVENT_LISTBOX_SELECT:
     201           0 :             if ( !m_bDisableProcessEvent )
     202           0 :                 UpdateSelection_Impl();
     203           0 :             break;
     204             :         // The selection events VCLEVENT_COMBOBOX_SELECT and
     205             :         // VCLEVENT_COMBOBOX_DESELECT are not handled here because here we
     206             :         // have no access to the edit field.  Its text is necessary to
     207             :         // identify the currently selected item.
     208             : 
     209             :         case VCLEVENT_OBJECT_DYING:
     210             :         {
     211           0 :             dispose();
     212             : 
     213           0 :             VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
     214           0 :             break;
     215             :         }
     216             : 
     217             :         case VCLEVENT_LISTBOX_ITEMREMOVED:
     218             :         case VCLEVENT_COMBOBOX_ITEMREMOVED:
     219             :             HandleChangedItemList (false, reinterpret_cast<sal_IntPtr>(
     220           0 :                 rVclWindowEvent.GetData()));
     221           0 :             break;
     222             : 
     223             :         case VCLEVENT_LISTBOX_ITEMADDED:
     224             :         case VCLEVENT_COMBOBOX_ITEMADDED:
     225             :             HandleChangedItemList (true, reinterpret_cast<sal_IntPtr>(
     226           0 :                 rVclWindowEvent.GetData()));
     227           0 :             break;
     228             :         case VCLEVENT_CONTROL_GETFOCUS:
     229           0 :             VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
     230           0 :             if ( m_pListBoxHelper )
     231             :             {
     232           0 :                 uno::Any    aOldValue,
     233           0 :                             aNewValue;
     234           0 :                 sal_uInt16 nPos = m_pListBoxHelper->GetSelectEntryPos();
     235           0 :                 if ( nPos == LISTBOX_ENTRY_NOTFOUND )
     236           0 :                     nPos = m_pListBoxHelper->GetTopEntry();
     237           0 :                 if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     238           0 :                     aNewValue <<= CreateChild(nPos);
     239             : 
     240             :                 NotifyAccessibleEvent(  AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
     241             :                                         aOldValue,
     242           0 :                                         aNewValue );
     243             :             }
     244           0 :             break;
     245             : 
     246             :         default:
     247           0 :             VCLXAccessibleComponent::ProcessWindowEvent (rVclWindowEvent);
     248           0 :     }
     249           0 : }
     250             : // -----------------------------------------------------------------------------
     251             : 
     252             : /** To find out which item is currently selected and to update the SELECTED
     253             :     state of the associated accessibility objects accordingly we exploit the
     254             :     fact that the
     255             : */
     256           0 : void VCLXAccessibleList::UpdateSelection (OUString sTextOfSelectedItem)
     257             : {
     258           0 :     if ( m_aBoxType == COMBOBOX )
     259             :     {
     260           0 :         ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
     261           0 :         if ( pBox != NULL )
     262             :         {
     263             :             // Find the index of the selected item inside the VCL control...
     264           0 :             sal_uInt16 nIndex = pBox->GetEntryPos(sTextOfSelectedItem);
     265             :             // ...and then find the associated accessibility object.
     266           0 :             if ( nIndex == LISTBOX_ENTRY_NOTFOUND )
     267           0 :                 nIndex = 0;
     268           0 :             UpdateSelection_Impl(nIndex);
     269             :         }
     270             :     }
     271           0 : }
     272             : // -----------------------------------------------------------------------------
     273             : 
     274           0 : void VCLXAccessibleList::adjustEntriesIndexInParent(ListItems::iterator& _aBegin,::std::mem_fun_t<bool,VCLXAccessibleListItem>& _rMemFun)
     275             : {
     276           0 :     ListItems::iterator aIter = _aBegin;
     277           0 :     ListItems::iterator aEnd = m_aAccessibleChildren.end();
     278             :     // adjust the index inside the VCLXAccessibleListItem
     279           0 :     for (;aIter != aEnd ; ++aIter)
     280             :     {
     281           0 :         Reference< XAccessible > xHold = *aIter;
     282           0 :         VCLXAccessibleListItem* pItem = static_cast<VCLXAccessibleListItem*>(xHold.get());
     283           0 :         if ( pItem )
     284           0 :             _rMemFun(pItem);
     285           0 :     }
     286           0 : }
     287             : // -----------------------------------------------------------------------------
     288             : 
     289           0 : Reference<XAccessible> VCLXAccessibleList::CreateChild (sal_Int32 i)
     290             : {
     291           0 :     Reference<XAccessible> xChild;
     292             : 
     293           0 :     sal_uInt16 nPos = static_cast<sal_uInt16>(i);
     294           0 :     if ( nPos >= m_aAccessibleChildren.size() )
     295             :     {
     296           0 :         m_aAccessibleChildren.resize(nPos + 1);
     297             : 
     298             :         // insert into the container
     299           0 :         xChild = new VCLXAccessibleListItem(m_pListBoxHelper, i, this);
     300           0 :         m_aAccessibleChildren[nPos] = xChild;
     301             :     }
     302             :     else
     303             :     {
     304           0 :         xChild = m_aAccessibleChildren[nPos];
     305             :         // check if position is empty and can be used else we have to adjust all entries behind this
     306           0 :         if ( xChild.is() )
     307             :         {
     308           0 :             ListItems::iterator aIter = m_aAccessibleChildren.begin() + nPos;
     309           0 :             ::std::mem_fun_t<bool, VCLXAccessibleListItem> aTemp(&VCLXAccessibleListItem::IncrementIndexInParent);
     310           0 :             adjustEntriesIndexInParent( aIter, aTemp);
     311             :         }
     312             :         else
     313             :         {
     314           0 :             xChild = new VCLXAccessibleListItem(m_pListBoxHelper, i, this);
     315           0 :             m_aAccessibleChildren[nPos] = xChild;
     316             :         }
     317             :     }
     318             : 
     319           0 :     if ( xChild.is() )
     320             :     {
     321             :         // Just add the SELECTED state.
     322           0 :         bool bNowSelected = false;
     323           0 :         if ( m_pListBoxHelper )
     324           0 :             bNowSelected = m_pListBoxHelper->IsEntryPosSelected ((sal_uInt16)i);
     325           0 :         VCLXAccessibleListItem* pItem = static_cast< VCLXAccessibleListItem* >(xChild.get());
     326           0 :         pItem->SetSelected( bNowSelected );
     327             : 
     328             :         // Set the child's VISIBLE state.
     329           0 :         UpdateVisibleLineCount();
     330           0 :         sal_uInt16 nTopEntry = 0;
     331           0 :         if ( m_pListBoxHelper )
     332           0 :             nTopEntry = m_pListBoxHelper->GetTopEntry();
     333           0 :         bool bVisible = ( nPos>=nTopEntry && nPos<( nTopEntry + m_nVisibleLineCount ) );
     334           0 :         pItem->SetVisible( m_bVisible && bVisible );
     335             :     }
     336             : 
     337           0 :     return xChild;
     338             : }
     339             : // -----------------------------------------------------------------------------
     340             : 
     341           0 : void VCLXAccessibleList::HandleChangedItemList (bool bItemInserted, sal_Int32 nIndex)
     342             : {
     343           0 :     if ( !bItemInserted )
     344             :     {
     345           0 :         if ( nIndex == -1 ) // special handling here
     346             :         {
     347           0 :             clearItems();
     348             :         }
     349             :         else
     350             :         {
     351           0 :             if ( nIndex >= 0 && static_cast<sal_uInt16>(nIndex) < m_aAccessibleChildren.size() )
     352             :             {
     353           0 :                 ListItems::iterator aIter = m_aAccessibleChildren.erase(m_aAccessibleChildren.begin()+nIndex);
     354           0 :             ::std::mem_fun_t<bool, VCLXAccessibleListItem> aTemp(&VCLXAccessibleListItem::DecrementIndexInParent);
     355           0 :                 adjustEntriesIndexInParent( aIter, aTemp );
     356             :             }
     357             :         }
     358             :     }
     359             :     else
     360           0 :         getAccessibleChild(nIndex);
     361             : 
     362             :     NotifyAccessibleEvent (
     363             :         AccessibleEventId::INVALIDATE_ALL_CHILDREN,
     364           0 :         Any(), Any());
     365           0 : }
     366             : // -----------------------------------------------------------------------------
     367             : 
     368           0 : IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleList, VCLXAccessibleComponent, VCLXAccessibleList_BASE)
     369           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleList, VCLXAccessibleComponent, VCLXAccessibleList_BASE)
     370             : 
     371             : //=====  XAccessible  =========================================================
     372             : 
     373             : Reference<XAccessibleContext> SAL_CALL
     374           0 :     VCLXAccessibleList::getAccessibleContext (void)
     375             :     throw (RuntimeException)
     376             : {
     377           0 :     return this;
     378             : }
     379             : // -----------------------------------------------------------------------------
     380             : 
     381             : //=====  XAccessibleContext  ==================================================
     382             : 
     383           0 : sal_Int32 SAL_CALL VCLXAccessibleList::getAccessibleChildCount (void)
     384             :     throw (RuntimeException)
     385             : {
     386           0 :     SolarMutexGuard aSolarGuard;
     387           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     388             : 
     389           0 :     sal_Int32 nCount = 0;
     390           0 :     if ( m_pListBoxHelper )
     391           0 :         nCount = m_pListBoxHelper->GetEntryCount();
     392             : 
     393           0 :     return nCount;
     394             : }
     395             : // -----------------------------------------------------------------------------
     396             : 
     397           0 : Reference<XAccessible> SAL_CALL VCLXAccessibleList::getAccessibleChild (sal_Int32 i)
     398             :     throw (IndexOutOfBoundsException, RuntimeException)
     399             : {
     400           0 :     SolarMutexGuard aSolarGuard;
     401           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     402             : 
     403           0 :     if ( i < 0 || i >= getAccessibleChildCount() )
     404           0 :         throw IndexOutOfBoundsException();
     405             : 
     406           0 :     Reference< XAccessible > xChild;
     407             :     // search for the child
     408           0 :     if ( static_cast<sal_uInt16>(i) >= m_aAccessibleChildren.size() )
     409           0 :         xChild = CreateChild (i);
     410             :     else
     411             :     {
     412           0 :         xChild = m_aAccessibleChildren[i];
     413           0 :         if ( !xChild.is() )
     414           0 :             xChild = CreateChild (i);
     415             :     }
     416             :     OSL_ENSURE( xChild.is(), "VCLXAccessibleList::getAccessibleChild: returning empty child!" );
     417           0 :     return xChild;
     418             : }
     419             : // -----------------------------------------------------------------------------
     420             : 
     421           0 : Reference< XAccessible > SAL_CALL VCLXAccessibleList::getAccessibleParent(  )
     422             :     throw (RuntimeException)
     423             : {
     424           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     425             : 
     426           0 :     return m_xParent;
     427             : }
     428             : // -----------------------------------------------------------------------------
     429             : 
     430           0 : sal_Int32 SAL_CALL VCLXAccessibleList::getAccessibleIndexInParent (void)
     431             :     throw (::com::sun::star::uno::RuntimeException)
     432             : {
     433           0 :     if (m_nIndexInParent != DEFAULT_INDEX_IN_PARENT)
     434           0 :         return m_nIndexInParent;
     435             :     else
     436           0 :         return VCLXAccessibleComponent::getAccessibleIndexInParent();
     437             : }
     438             : // -----------------------------------------------------------------------------
     439             : 
     440           0 : sal_Int16 SAL_CALL VCLXAccessibleList::getAccessibleRole (void)
     441             :     throw (RuntimeException)
     442             : {
     443           0 :     return AccessibleRole::LIST;
     444             : }
     445             : // -----------------------------------------------------------------------------
     446             : 
     447             : //=====  XAccessibleComponent  ================================================
     448             : 
     449           0 : sal_Bool SAL_CALL VCLXAccessibleList::contains( const awt::Point& rPoint ) throw (RuntimeException)
     450             : {
     451           0 :     SolarMutexGuard aSolarGuard;
     452           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     453             : 
     454           0 :     sal_Bool bInside = sal_False;
     455             : 
     456           0 :     Window* pListBox = GetWindow();
     457           0 :     if ( pListBox )
     458             :     {
     459           0 :         Rectangle aRect( Point(0,0), pListBox->GetSizePixel() );
     460           0 :         bInside = aRect.IsInside( VCLPoint( rPoint ) );
     461             :     }
     462             : 
     463           0 :     return bInside;
     464             : }
     465             : // -----------------------------------------------------------------------------
     466             : 
     467           0 : Reference< XAccessible > SAL_CALL VCLXAccessibleList::getAccessibleAt( const awt::Point& rPoint )
     468             :     throw (RuntimeException)
     469             : {
     470           0 :     SolarMutexGuard aSolarGuard;
     471           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     472             : 
     473           0 :     Reference< XAccessible > xChild;
     474           0 :     if ( m_pListBoxHelper )
     475             :     {
     476           0 :         UpdateVisibleLineCount();
     477           0 :         if ( contains( rPoint ) && m_nVisibleLineCount > 0 )
     478             :         {
     479           0 :             Point aPos = VCLPoint( rPoint );
     480           0 :             sal_uInt16 nEndPos = m_pListBoxHelper->GetTopEntry() + (sal_uInt16)m_nVisibleLineCount;
     481           0 :             for ( sal_uInt16 i = m_pListBoxHelper->GetTopEntry(); i < nEndPos; ++i )
     482             :             {
     483           0 :                 if ( m_pListBoxHelper->GetBoundingRectangle(i).IsInside( aPos ) )
     484             :                 {
     485           0 :                     xChild = getAccessibleChild(i);
     486           0 :                     break;
     487             :                 }
     488             :             }
     489             :         }
     490             :     }
     491             : 
     492           0 :     return xChild;
     493             : }
     494             : // -----------------------------------------------------------------------------
     495             : 
     496             : //===== XServiceInfo ==========================================================
     497             : 
     498           0 : OUString VCLXAccessibleList::getImplementationName (void)
     499             :     throw (RuntimeException)
     500             : {
     501           0 :     return OUString( "com.sun.star.comp.toolkit.AccessibleList" );
     502             : }
     503             : // -----------------------------------------------------------------------------
     504             : 
     505           0 : Sequence< OUString > VCLXAccessibleList::getSupportedServiceNames (void)
     506             :     throw (RuntimeException)
     507             : {
     508           0 :     Sequence< OUString > aNames = VCLXAccessibleComponent::getSupportedServiceNames();
     509           0 :     sal_Int32 nLength = aNames.getLength();
     510           0 :     aNames.realloc( nLength + 1 );
     511           0 :     aNames[nLength] = "com.sun.star.accessibility.AccessibleList";
     512           0 :     return aNames;
     513             : }
     514             : // -----------------------------------------------------------------------------
     515             : 
     516           0 : void VCLXAccessibleList::UpdateVisibleLineCount()
     517             : {
     518           0 :     if ( m_pListBoxHelper )
     519             :     {
     520           0 :         if ( (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
     521           0 :             m_nVisibleLineCount = m_pListBoxHelper->GetDisplayLineCount();
     522             :         else
     523             :         {
     524           0 :             sal_uInt16 nCols = 0,
     525           0 :                 nLines = 0;
     526           0 :             m_pListBoxHelper->GetMaxVisColumnsAndLines (nCols, nLines);
     527           0 :             m_nVisibleLineCount = nLines;
     528             :         }
     529             :     }
     530           0 : }
     531             : 
     532             : // -----------------------------------------------------------------------------
     533           0 : void VCLXAccessibleList::UpdateEntryRange_Impl()
     534             : {
     535           0 :     SolarMutexGuard aSolarGuard;
     536           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     537             : 
     538           0 :     sal_Int32 nTop = m_nLastTopEntry;
     539             : 
     540           0 :     if ( m_pListBoxHelper )
     541           0 :         nTop = m_pListBoxHelper->GetTopEntry();
     542           0 :     if ( nTop != m_nLastTopEntry )
     543             :     {
     544           0 :         UpdateVisibleLineCount();
     545           0 :         sal_Int32 nBegin = Min( m_nLastTopEntry, nTop );
     546           0 :         sal_Int32 nEnd = Max( m_nLastTopEntry + m_nVisibleLineCount, nTop + m_nVisibleLineCount );
     547           0 :         for (sal_uInt16 i = static_cast<sal_uInt16>(nBegin); (i <= static_cast<sal_uInt16>(nEnd)); ++i)
     548             :         {
     549           0 :             sal_Bool bVisible = ( i >= nTop && i < ( nTop + m_nVisibleLineCount ) );
     550           0 :             Reference< XAccessible > xHold;
     551           0 :             if ( i < m_aAccessibleChildren.size() )
     552           0 :                 xHold = m_aAccessibleChildren[i];
     553           0 :             else if ( bVisible )
     554           0 :                 xHold = CreateChild(i);
     555             : 
     556           0 :             if ( xHold.is() )
     557           0 :                 static_cast< VCLXAccessibleListItem* >( xHold.get() )->SetVisible( m_bVisible && bVisible );
     558           0 :         }
     559             :     }
     560             : 
     561           0 :     m_nLastTopEntry = nTop;
     562           0 : }
     563             : // -----------------------------------------------------------------------------
     564           0 : sal_Bool VCLXAccessibleList::checkEntrySelected(sal_uInt16 _nPos,Any& _rNewValue,Reference< XAccessible >& _rxNewAcc)
     565             : {
     566             :     OSL_ENSURE(m_pListBoxHelper,"Helper is not valid!");
     567           0 :     sal_Bool bNowSelected = sal_False;
     568           0 :     if ( m_pListBoxHelper )
     569             :     {
     570           0 :         bNowSelected = m_pListBoxHelper->IsEntryPosSelected (_nPos);
     571           0 :         if ( bNowSelected )
     572             :         {
     573           0 :             _rxNewAcc = CreateChild(_nPos);
     574           0 :             _rNewValue <<= _rxNewAcc;
     575             :         }
     576             :     }
     577           0 :     return bNowSelected;
     578             : }
     579             : // -----------------------------------------------------------------------------
     580             : 
     581           0 : void VCLXAccessibleList::UpdateSelection_Impl(sal_uInt16)
     582             : {
     583           0 :     uno::Any aOldValue, aNewValue;
     584             : 
     585             :     {
     586           0 :         SolarMutexGuard aSolarGuard;
     587           0 :         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     588           0 :         Reference< XAccessible > xNewAcc;
     589             : 
     590           0 :         if ( m_pListBoxHelper )
     591             :         {
     592           0 :             sal_uInt16 i=0;
     593           0 :             for ( ListItems::iterator aIter = m_aAccessibleChildren.begin();
     594           0 :                   aIter != m_aAccessibleChildren.end(); ++aIter,++i)
     595             :             {
     596           0 :                 Reference< XAccessible > xHold = *aIter;
     597           0 :                 if ( xHold.is() )
     598             :                 {
     599           0 :                     VCLXAccessibleListItem* pItem = static_cast< VCLXAccessibleListItem* >( xHold.get() );
     600             :                     // Retrieve the item's index from the list entry.
     601           0 :                     sal_Bool bNowSelected = m_pListBoxHelper->IsEntryPosSelected (i);
     602             : 
     603           0 :                     if ( bNowSelected && !pItem->IsSelected() )
     604             :                     {
     605           0 :                         xNewAcc = *aIter;
     606           0 :                         aNewValue <<= xNewAcc;
     607             :                     }
     608           0 :                     else if ( pItem->IsSelected() )
     609           0 :                         m_nLastSelectedPos = i;
     610             : 
     611           0 :                     pItem->SetSelected( bNowSelected );
     612             :                 }
     613             :                 else
     614             :                 { // it could happen that a child was not created before
     615           0 :                     checkEntrySelected(i,aNewValue,xNewAcc);
     616             :                 }
     617           0 :             }
     618           0 :             sal_uInt16 nCount = m_pListBoxHelper->GetEntryCount();
     619           0 :             if ( i < nCount ) // here we have to check the if any other listbox entry is selected
     620             :             {
     621           0 :                 for (; i < nCount && !checkEntrySelected(i,aNewValue,xNewAcc) ;++i )
     622             :                     ;
     623             :             }
     624           0 :             if ( xNewAcc.is() && GetWindow()->HasFocus() )
     625             :             {
     626           0 :                 if ( m_nLastSelectedPos != LISTBOX_ENTRY_NOTFOUND )
     627           0 :                     aOldValue <<= getAccessibleChild( (sal_Int32)m_nLastSelectedPos );
     628           0 :                 aNewValue <<= xNewAcc;
     629             :             }
     630           0 :         }
     631             :     }
     632             : 
     633           0 :     if ( aNewValue.hasValue() || aOldValue.hasValue() )
     634             :         NotifyAccessibleEvent(
     635             :             AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
     636             :             aOldValue,
     637           0 :             aNewValue );
     638             : 
     639           0 :     NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
     640           0 : }
     641             : 
     642             : // -----------------------------------------------------------------------------
     643             : // XAccessibleSelection
     644             : // -----------------------------------------------------------------------------
     645           0 : void SAL_CALL VCLXAccessibleList::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     646             : {
     647           0 :     sal_Bool bNotify = sal_False;
     648             : 
     649             :     {
     650           0 :         SolarMutexGuard aSolarGuard;
     651           0 :         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     652             : 
     653           0 :         if ( m_pListBoxHelper )
     654             :         {
     655           0 :             checkSelection_Impl(nChildIndex,*m_pListBoxHelper,sal_False);
     656             : 
     657           0 :             m_pListBoxHelper->SelectEntryPos( (sal_uInt16)nChildIndex, sal_True );
     658             :             // call the select handler, don't handle events in this time
     659           0 :             m_bDisableProcessEvent = true;
     660           0 :             m_pListBoxHelper->Select();
     661           0 :             m_bDisableProcessEvent = false;
     662           0 :             bNotify = sal_True;
     663           0 :         }
     664             :     }
     665             : 
     666           0 :     if ( bNotify )
     667           0 :         UpdateSelection_Impl();
     668           0 : }
     669             : // -----------------------------------------------------------------------------
     670           0 : sal_Bool SAL_CALL VCLXAccessibleList::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     671             : {
     672           0 :     SolarMutexGuard aSolarGuard;
     673           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     674             : 
     675           0 :     sal_Bool bRet = sal_False;
     676           0 :     if ( m_pListBoxHelper )
     677             :     {
     678           0 :         checkSelection_Impl(nChildIndex,*m_pListBoxHelper,sal_False);
     679             : 
     680           0 :         bRet = m_pListBoxHelper->IsEntryPosSelected( (sal_uInt16)nChildIndex );
     681             :     }
     682           0 :     return bRet;
     683             : }
     684             : // -----------------------------------------------------------------------------
     685           0 : void SAL_CALL VCLXAccessibleList::clearAccessibleSelection(  ) throw (RuntimeException)
     686             : {
     687           0 :     sal_Bool bNotify = sal_False;
     688             : 
     689             :     {
     690           0 :         SolarMutexGuard aSolarGuard;
     691           0 :         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     692             : 
     693           0 :         if ( m_pListBoxHelper )
     694             :         {
     695           0 :             m_pListBoxHelper->SetNoSelection();
     696           0 :             bNotify = sal_True;
     697           0 :         }
     698             :     }
     699             : 
     700           0 :     if ( bNotify )
     701           0 :         UpdateSelection_Impl();
     702           0 : }
     703             : // -----------------------------------------------------------------------------
     704           0 : void SAL_CALL VCLXAccessibleList::selectAllAccessibleChildren(  ) throw (RuntimeException)
     705             : {
     706           0 :     sal_Bool bNotify = sal_False;
     707             : 
     708             :     {
     709           0 :         SolarMutexGuard aSolarGuard;
     710           0 :         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     711             : 
     712           0 :         if ( m_pListBoxHelper )
     713             :         {
     714           0 :             sal_uInt16 nCount = m_pListBoxHelper->GetEntryCount();
     715           0 :             for ( sal_uInt16 i = 0; i < nCount; ++i )
     716           0 :                 m_pListBoxHelper->SelectEntryPos( i, sal_True );
     717             :             // call the select handler, don't handle events in this time
     718           0 :             m_bDisableProcessEvent = true;
     719           0 :             m_pListBoxHelper->Select();
     720           0 :             m_bDisableProcessEvent = false;
     721           0 :             bNotify = sal_True;
     722           0 :         }
     723             :     }
     724             : 
     725           0 :     if ( bNotify )
     726           0 :         UpdateSelection_Impl();
     727           0 : }
     728             : // -----------------------------------------------------------------------------
     729           0 : sal_Int32 SAL_CALL VCLXAccessibleList::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
     730             : {
     731           0 :     SolarMutexGuard aSolarGuard;
     732           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     733             : 
     734           0 :     sal_Int32 nCount = 0;
     735           0 :     if ( m_pListBoxHelper )
     736           0 :            nCount = m_pListBoxHelper->GetSelectEntryCount();
     737           0 :     return nCount;
     738             : }
     739             : // -----------------------------------------------------------------------------
     740           0 : Reference< XAccessible > SAL_CALL VCLXAccessibleList::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     741             : {
     742           0 :     SolarMutexGuard aSolarGuard;
     743           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     744             : 
     745           0 :     if ( m_pListBoxHelper )
     746             :     {
     747           0 :         checkSelection_Impl(nSelectedChildIndex,*m_pListBoxHelper,sal_True);
     748           0 :         return getAccessibleChild( (sal_Int32)m_pListBoxHelper->GetSelectEntryPos( (sal_uInt16)nSelectedChildIndex ) );
     749             :     }
     750             : 
     751           0 :     return NULL;
     752             : }
     753             : // -----------------------------------------------------------------------------
     754           0 : void SAL_CALL VCLXAccessibleList::deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     755             : {
     756           0 :     sal_Bool bNotify = sal_False;
     757             : 
     758             :     {
     759           0 :         SolarMutexGuard aSolarGuard;
     760           0 :         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     761             : 
     762           0 :         if ( m_pListBoxHelper )
     763             :         {
     764           0 :             checkSelection_Impl(nSelectedChildIndex,*m_pListBoxHelper,sal_False);
     765             : 
     766           0 :             m_pListBoxHelper->SelectEntryPos( (sal_uInt16)nSelectedChildIndex, sal_False );
     767             :             // call the select handler, don't handle events in this time
     768           0 :             m_bDisableProcessEvent = true;
     769           0 :             m_pListBoxHelper->Select();
     770           0 :             m_bDisableProcessEvent = false;
     771           0 :             bNotify = sal_True;
     772           0 :         }
     773             :     }
     774             : 
     775           0 :     if ( bNotify )
     776           0 :         UpdateSelection_Impl();
     777           0 : }
     778             : // -----------------------------------------------------------------------------
     779           0 : awt::Rectangle VCLXAccessibleList::implGetBounds() throw (uno::RuntimeException)
     780             : {
     781           0 :     awt::Rectangle aBounds ( 0, 0, 0, 0 );
     782           0 :     if ( m_pListBoxHelper
     783           0 :         && (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
     784             :     {
     785           0 :         if ( m_pListBoxHelper->IsInDropDown() )
     786           0 :             aBounds = AWTRectangle(m_pListBoxHelper->GetDropDownPosSizePixel());
     787             :     }
     788             :     else
     789             :     {
     790             :         // a list has the same bounds as his parent but starts at (0,0)
     791           0 :         aBounds = VCLXAccessibleComponent::implGetBounds();
     792           0 :         aBounds.X = 0;
     793           0 :         aBounds.Y = 0;
     794           0 :         if ( m_aBoxType == COMBOBOX )
     795             :         {
     796           0 :             ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
     797           0 :             if ( pBox )
     798             :             {
     799           0 :                 Size aSize = pBox->GetSubEdit()->GetSizePixel();
     800           0 :                 aBounds.X += aSize.Height();
     801           0 :                 aBounds.Y += aSize.Width();
     802           0 :                 aBounds.Height -= aSize.Height();
     803           0 :                 aBounds.Width  -= aSize.Width();
     804             :             }
     805             :         }
     806             :     }
     807           0 :     return aBounds;
     808             : }
     809             : // -----------------------------------------------------------------------------
     810             : 
     811           0 : awt::Point VCLXAccessibleList::getLocationOnScreen(  ) throw (uno::RuntimeException)
     812             : {
     813           0 :     SolarMutexGuard aSolarGuard;
     814           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     815             : 
     816           0 :     awt::Point aPos;
     817           0 :     if ( m_pListBoxHelper
     818           0 :         && (m_pListBoxHelper->GetStyle() & WB_DROPDOWN ) == WB_DROPDOWN )
     819             :     {
     820           0 :         if ( m_pListBoxHelper->IsInDropDown() )
     821           0 :             aPos = AWTPoint(m_pListBoxHelper->GetDropDownPosSizePixel().TopLeft());
     822             :     }
     823             :     else
     824             :     {
     825           0 :         aPos = VCLXAccessibleComponent::getLocationOnScreen();
     826           0 :         if ( m_aBoxType == COMBOBOX )
     827             :         {
     828           0 :             ComboBox* pBox = static_cast<ComboBox*>(GetWindow());
     829           0 :             if ( pBox )
     830             :             {
     831           0 :                 aPos.X += pBox->GetSubEdit()->GetSizePixel().Height();
     832           0 :                 aPos.Y += pBox->GetSubEdit()->GetSizePixel().Width();
     833             :             }
     834             :         }
     835             :     }
     836           0 :     return aPos;
     837             : }
     838             : // -----------------------------------------------------------------------------
     839             : 
     840             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10