LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - vclxaccessiblebox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 139 0.0 %
Date: 2012-12-27 Functions: 0 20 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/vclxaccessiblebox.hxx>
      21             : #include <accessibility/standard/vclxaccessibletextfield.hxx>
      22             : #include <accessibility/standard/vclxaccessibleedit.hxx>
      23             : #include <accessibility/standard/vclxaccessiblelist.hxx>
      24             : #include <accessibility/helper/listboxhelper.hxx>
      25             : 
      26             : #include <unotools/accessiblestatesethelper.hxx>
      27             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      28             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      29             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      30             : #include <vcl/svapp.hxx>
      31             : #include <vcl/combobox.hxx>
      32             : #include <vcl/lstbox.hxx>
      33             : #include <accessibility/helper/accresmgr.hxx>
      34             : #include <accessibility/helper/accessiblestrings.hrc>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::lang;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::accessibility;
      41             : 
      42           0 : VCLXAccessibleBox::VCLXAccessibleBox (VCLXWindow* pVCLWindow, BoxType aType, bool bIsDropDownBox)
      43             :     : VCLXAccessibleComponent (pVCLWindow),
      44             :       m_aBoxType (aType),
      45             :       m_bIsDropDownBox (bIsDropDownBox),
      46           0 :       m_nIndexInParent (DEFAULT_INDEX_IN_PARENT)
      47             : {
      48             :     // Set up the flags that indicate which children this object has.
      49           0 :     m_bHasListChild = true;
      50             : 
      51             :     // A text field is not present for non drop down list boxes.
      52           0 :     if ((m_aBoxType==LISTBOX) && ! m_bIsDropDownBox)
      53           0 :         m_bHasTextChild = false;
      54             :     else
      55           0 :         m_bHasTextChild = true;
      56           0 : }
      57             : 
      58           0 : VCLXAccessibleBox::~VCLXAccessibleBox (void)
      59             : {
      60           0 : }
      61             : 
      62           0 : void VCLXAccessibleBox::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
      63             : {
      64           0 :        uno::Any aOldValue, aNewValue;
      65           0 :     uno::Reference<XAccessible> xAcc;
      66             : 
      67           0 :     switch ( rVclWindowEvent.GetId() )
      68             :     {
      69             :         case VCLEVENT_WINDOW_SHOW:
      70             :         case VCLEVENT_WINDOW_HIDE:
      71             :         {
      72           0 :             Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
      73             :             // Just compare to the combo box text field.  All other children
      74             :             // are identical to this object in which case this object will
      75             :             // be removed in a short time.
      76           0 :             if (m_aBoxType==COMBOBOX)
      77             :             {
      78           0 :                 ComboBox* pComboBox = static_cast<ComboBox*>(GetWindow());
      79           0 :                 if ( ( pComboBox != NULL ) && ( pChildWindow != NULL ) )
      80           0 :                     if (pChildWindow == pComboBox->GetSubEdit())
      81             :                     {
      82           0 :                         if (rVclWindowEvent.GetId() == VCLEVENT_WINDOW_SHOW)
      83             :                         {
      84             :                             // Instantiate text field.
      85           0 :                             getAccessibleChild (0);
      86           0 :                             aNewValue <<= m_xText;
      87             :                         }
      88             :                         else
      89             :                         {
      90             :                             // Release text field.
      91           0 :                             aOldValue <<= m_xText;
      92           0 :                             m_xText = NULL;
      93             :                         }
      94             :                         // Tell the listeners about the new/removed child.
      95             :                         NotifyAccessibleEvent (
      96             :                             AccessibleEventId::CHILD,
      97           0 :                             aOldValue, aNewValue);
      98             :                     }
      99             : 
     100             :             }
     101             :         }
     102           0 :         break;
     103             : 
     104             :         default:
     105           0 :             VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
     106           0 :     }
     107           0 : }
     108             : 
     109           0 : void VCLXAccessibleBox::ProcessWindowEvent (const VclWindowEvent& rVclWindowEvent)
     110             : {
     111           0 :     switch ( rVclWindowEvent.GetId() )
     112             :     {
     113             :         case VCLEVENT_DROPDOWN_OPEN:
     114             :         case VCLEVENT_DROPDOWN_CLOSE:
     115             :         case VCLEVENT_LISTBOX_DOUBLECLICK:
     116             :         case VCLEVENT_LISTBOX_SCROLLED:
     117             :         case VCLEVENT_LISTBOX_SELECT:
     118             :         case VCLEVENT_LISTBOX_ITEMADDED:
     119             :         case VCLEVENT_LISTBOX_ITEMREMOVED:
     120             :         case VCLEVENT_COMBOBOX_ITEMADDED:
     121             :         case VCLEVENT_COMBOBOX_ITEMREMOVED:
     122             :         case VCLEVENT_COMBOBOX_SCROLLED:
     123             :         {
     124             :             // Forward the call to the list child.
     125           0 :             VCLXAccessibleList* pList = static_cast<VCLXAccessibleList*>(m_xList.get());
     126           0 :             if ( pList == NULL )
     127             :             {
     128           0 :                 getAccessibleChild ( m_bHasTextChild ? 1 : 0 );
     129           0 :                 pList = static_cast<VCLXAccessibleList*>(m_xList.get());
     130             :             }
     131           0 :             if ( pList != NULL )
     132           0 :                 pList->ProcessWindowEvent (rVclWindowEvent);
     133           0 :             break;
     134             :         }
     135             : 
     136             :         case VCLEVENT_COMBOBOX_SELECT:
     137             :         case VCLEVENT_COMBOBOX_DESELECT:
     138             :         {
     139             :             // Selection is handled by VCLXAccessibleList which operates on
     140             :             // the same VCL object as this box does.  In case of the
     141             :             // combobox, however, we have to help by providing the list with
     142             :             // the text of the currently selected item.
     143           0 :             VCLXAccessibleList* pList = static_cast<VCLXAccessibleList*>(m_xList.get());
     144           0 :             if (pList != NULL && m_xText.is())
     145             :             {
     146           0 :                 Reference<XAccessibleText> xText (m_xText->getAccessibleContext(), UNO_QUERY);
     147           0 :                 if ( xText.is() )
     148             :                 {
     149           0 :                     OUString sText = xText->getSelectedText();
     150           0 :                     if ( sText.isEmpty() )
     151           0 :                         sText = xText->getText();
     152           0 :                     pList->UpdateSelection (sText);
     153           0 :                 }
     154             :             }
     155           0 :             break;
     156             :         }
     157             : 
     158             :         case VCLEVENT_EDIT_MODIFY:
     159             :         case VCLEVENT_EDIT_SELECTIONCHANGED:
     160             :             // Modify/Selection events are handled by the combo box instead of
     161             :             // directly by the edit field (Why?).  Therefore, delegate this
     162             :             // call to the edit field.
     163           0 :             if (m_aBoxType==COMBOBOX)
     164             :             {
     165           0 :                 if (m_xText.is())
     166             :                 {
     167           0 :                     Reference<XAccessibleContext> xContext = m_xText->getAccessibleContext();
     168           0 :                     VCLXAccessibleEdit* pEdit = static_cast<VCLXAccessibleEdit*>(xContext.get());
     169           0 :                     if (pEdit != NULL)
     170           0 :                         pEdit->ProcessWindowEvent (rVclWindowEvent);
     171             :                 }
     172             :             }
     173           0 :             break;
     174             : 
     175             :         default:
     176           0 :             VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
     177             :     }
     178           0 : }
     179             : 
     180           0 : IMPLEMENT_FORWARD_XINTERFACE2(VCLXAccessibleBox, VCLXAccessibleComponent, VCLXAccessibleBox_BASE)
     181           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleBox, VCLXAccessibleComponent, VCLXAccessibleBox_BASE)
     182             : 
     183             : //=====  XAccessible  =========================================================
     184             : 
     185           0 : Reference< XAccessibleContext > SAL_CALL VCLXAccessibleBox::getAccessibleContext(  )
     186             :     throw (RuntimeException)
     187             : {
     188           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     189             : 
     190           0 :     return this;
     191             : }
     192             : 
     193             : //=====  XAccessibleContext  ==================================================
     194             : 
     195           0 : sal_Int32 SAL_CALL VCLXAccessibleBox::getAccessibleChildCount (void)
     196             :     throw (RuntimeException)
     197             : {
     198           0 :     SolarMutexGuard aSolarGuard;
     199           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     200             : 
     201             :     // Usually a box has a text field and a list of items as its children.
     202             :     // Non drop down list boxes have no text field.  Additionally check
     203             :     // whether the object is valid.
     204           0 :     sal_Int32 nCount = 0;
     205           0 :     if (IsValid())
     206           0 :         nCount += (m_bHasTextChild?1:0) + (m_bHasListChild?1:0);
     207             :     else
     208             :     {
     209             :         // Object not valid anymore.  Release references to children.
     210           0 :         m_bHasTextChild = false;
     211           0 :         m_xText = NULL;
     212           0 :         m_bHasListChild = false;
     213           0 :         m_xList = NULL;
     214             :     }
     215             : 
     216           0 :     return nCount;
     217             : }
     218             : 
     219           0 : Reference<XAccessible> SAL_CALL VCLXAccessibleBox::getAccessibleChild (sal_Int32 i)
     220             :     throw (IndexOutOfBoundsException, RuntimeException)
     221             : {
     222           0 :     SolarMutexGuard aSolarGuard;
     223           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     224             : 
     225           0 :     if (i<0 || i>=getAccessibleChildCount())
     226           0 :         throw IndexOutOfBoundsException();
     227             : 
     228           0 :     Reference< XAccessible > xChild;
     229           0 :     if (IsValid())
     230             :     {
     231           0 :         if (i==1 || ! m_bHasTextChild)
     232             :         {
     233             :             // List.
     234           0 :             if ( ! m_xList.is())
     235             :             {
     236           0 :                 VCLXAccessibleList* pList = new VCLXAccessibleList ( GetVCLXWindow(),
     237             :                     (m_aBoxType == LISTBOX ? VCLXAccessibleList::LISTBOX : VCLXAccessibleList::COMBOBOX),
     238           0 :                                                                     this);
     239           0 :                 pList->SetIndexInParent (i);
     240           0 :                 m_xList = pList;
     241             :             }
     242           0 :             xChild = m_xList;
     243             :         }
     244             :         else
     245             :         {
     246             :             // Text Field.
     247           0 :             if ( ! m_xText.is())
     248             :             {
     249           0 :                 if (m_aBoxType==COMBOBOX)
     250             :                 {
     251           0 :                     ComboBox* pComboBox = static_cast<ComboBox*>(GetWindow());
     252           0 :                     if (pComboBox!=NULL && pComboBox->GetSubEdit()!=NULL)
     253           0 :                         m_xText = pComboBox->GetSubEdit()->GetAccessible();
     254             :                 }
     255           0 :                 else if (m_bIsDropDownBox)
     256           0 :                     m_xText = new VCLXAccessibleTextField (GetVCLXWindow(),this);
     257             :             }
     258           0 :             xChild = m_xText;
     259             :         }
     260             :     }
     261             : 
     262           0 :     return xChild;
     263             : }
     264             : 
     265           0 : sal_Int16 SAL_CALL VCLXAccessibleBox::getAccessibleRole (void) throw (RuntimeException)
     266             : {
     267           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     268             : 
     269             :     // Return the role <const>COMBO_BOX</const> for both VCL combo boxes and
     270             :     // VCL list boxes in DropDown-Mode else <const>PANEL</const>.
     271             :     // This way the Java bridge has not to handle both independently.
     272           0 :     return m_bIsDropDownBox ? AccessibleRole::COMBO_BOX : AccessibleRole::PANEL;
     273             : }
     274             : 
     275           0 : sal_Int32 SAL_CALL VCLXAccessibleBox::getAccessibleIndexInParent (void)
     276             :     throw (::com::sun::star::uno::RuntimeException)
     277             : {
     278           0 :     if (m_nIndexInParent != DEFAULT_INDEX_IN_PARENT)
     279           0 :         return m_nIndexInParent;
     280             :     else
     281           0 :         return VCLXAccessibleComponent::getAccessibleIndexInParent();
     282             : }
     283             : 
     284             : //=====  XAccessibleAction  ===================================================
     285             : 
     286           0 : sal_Int32 SAL_CALL VCLXAccessibleBox::getAccessibleActionCount (void)
     287             :     throw (RuntimeException)
     288             : {
     289           0 :     ::osl::Guard< ::osl::Mutex> aGuard (GetMutex());
     290             : 
     291             :     // There is one action for drop down boxes (toggle popup) and none for
     292             :     // the other boxes.
     293           0 :     return m_bIsDropDownBox ? 1 : 0;
     294             : }
     295             : 
     296           0 : sal_Bool SAL_CALL VCLXAccessibleBox::doAccessibleAction (sal_Int32 nIndex)
     297             :     throw (IndexOutOfBoundsException, RuntimeException)
     298             : {
     299           0 :     sal_Bool bNotify = sal_False;
     300             : 
     301             :     {
     302           0 :         SolarMutexGuard aSolarGuard;
     303           0 :         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     304             : 
     305           0 :         if (nIndex<0 || nIndex>=getAccessibleActionCount())
     306           0 :             throw ::com::sun::star::lang::IndexOutOfBoundsException();
     307             : 
     308           0 :         if (m_aBoxType == COMBOBOX)
     309             :         {
     310           0 :             ComboBox* pComboBox = static_cast< ComboBox* >( GetWindow() );
     311           0 :             if (pComboBox != NULL)
     312             :             {
     313           0 :                 pComboBox->ToggleDropDown();
     314           0 :                 bNotify = sal_True;
     315             :             }
     316             :         }
     317           0 :         else if (m_aBoxType == LISTBOX)
     318             :         {
     319           0 :             ListBox* pListBox = static_cast< ListBox* >( GetWindow() );
     320           0 :             if (pListBox != NULL)
     321             :             {
     322           0 :                 pListBox->ToggleDropDown();
     323           0 :                 bNotify = sal_True;
     324             :             }
     325           0 :         }
     326             :     }
     327             : 
     328           0 :     if (bNotify)
     329           0 :         NotifyAccessibleEvent (AccessibleEventId::ACTION_CHANGED, Any(), Any());
     330             : 
     331           0 :     return bNotify;
     332             : }
     333             : 
     334           0 : OUString SAL_CALL VCLXAccessibleBox::getAccessibleActionDescription (sal_Int32 nIndex)
     335             :     throw (IndexOutOfBoundsException, RuntimeException)
     336             : {
     337           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     338           0 :     if (nIndex<0 || nIndex>=getAccessibleActionCount())
     339           0 :         throw ::com::sun::star::lang::IndexOutOfBoundsException();
     340           0 :     return TK_RES_STRING( RID_STR_ACC_ACTION_TOGGLEPOPUP);
     341             : }
     342             : 
     343           0 : Reference< XAccessibleKeyBinding > VCLXAccessibleBox::getAccessibleActionKeyBinding( sal_Int32 nIndex )
     344             :     throw (IndexOutOfBoundsException, RuntimeException)
     345             : {
     346           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     347             : 
     348           0 :     Reference< XAccessibleKeyBinding > xRet;
     349             : 
     350           0 :     if (nIndex<0 || nIndex>=getAccessibleActionCount())
     351           0 :         throw ::com::sun::star::lang::IndexOutOfBoundsException();
     352             : 
     353             :     // ... which key?
     354           0 :     return xRet;
     355             : }
     356             : 
     357             : //=====  XComponent  ==========================================================
     358             : 
     359           0 : void SAL_CALL VCLXAccessibleBox::disposing (void)
     360             : {
     361           0 :     VCLXAccessibleComponent::disposing();
     362           0 : }
     363             : 
     364             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10