LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/accessibility/source/standard - accessiblemenuitemcomponent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 158 198 79.8 %
Date: 2013-07-09 Functions: 26 34 76.5 %
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/accessiblemenuitemcomponent.hxx>
      21             : 
      22             : 
      23             : #include <accessibility/helper/accresmgr.hxx>
      24             : #include <accessibility/helper/accessiblestrings.hrc>
      25             : #include <toolkit/awt/vclxwindows.hxx>
      26             : #include <toolkit/helper/externallock.hxx>
      27             : #include <toolkit/helper/convert.hxx>
      28             : 
      29             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      30             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      31             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      32             : #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
      33             : #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
      34             : 
      35             : #include <unotools/accessiblestatesethelper.hxx>
      36             : #include <unotools/accessiblerelationsethelper.hxx>
      37             : #include <cppuhelper/typeprovider.hxx>
      38             : #include <comphelper/sequence.hxx>
      39             : #include <comphelper/accessibletexthelper.hxx>
      40             : #include <vcl/svapp.hxx>
      41             : #include <vcl/window.hxx>
      42             : #include <vcl/menu.hxx>
      43             : #include <vcl/unohelp2.hxx>
      44             : 
      45             : 
      46             : using namespace ::com::sun::star::accessibility;
      47             : using namespace ::com::sun::star::uno;
      48             : using namespace ::com::sun::star::beans;
      49             : using namespace ::com::sun::star::lang;
      50             : using namespace ::com::sun::star;
      51             : using namespace ::comphelper;
      52             : 
      53             : 
      54             : // -----------------------------------------------------------------------------
      55             : // class OAccessibleMenuItemComponent
      56             : // -----------------------------------------------------------------------------
      57             : 
      58        1924 : OAccessibleMenuItemComponent::OAccessibleMenuItemComponent( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu )
      59             :     :OAccessibleMenuBaseComponent( pMenu )
      60             :     ,m_pParent( pParent )
      61        1924 :     ,m_nItemPos( nItemPos )
      62             : {
      63        1924 :     m_sAccessibleName = GetAccessibleName();
      64        1924 :     m_sItemText = GetItemText();
      65        1924 : }
      66             : 
      67             : // -----------------------------------------------------------------------------
      68             : 
      69        1924 : OAccessibleMenuItemComponent::~OAccessibleMenuItemComponent()
      70             : {
      71        1924 : }
      72             : 
      73             : // -----------------------------------------------------------------------------
      74             : 
      75        4112 : sal_Bool OAccessibleMenuItemComponent::IsEnabled()
      76             : {
      77        4112 :     OExternalLockGuard aGuard( this );
      78             : 
      79        4112 :     sal_Bool bEnabled = sal_False;
      80        4112 :     if ( m_pParent )
      81        4112 :         bEnabled = m_pParent->IsItemEnabled( m_pParent->GetItemId( m_nItemPos ) );
      82             : 
      83        4112 :     return bEnabled;
      84             : }
      85             : 
      86             : // -----------------------------------------------------------------------------
      87             : 
      88        4280 : sal_Bool OAccessibleMenuItemComponent::IsVisible()
      89             : {
      90        4280 :     sal_Bool bVisible = sal_False;
      91             : 
      92        4280 :     if ( m_pParent )
      93        4280 :         bVisible = m_pParent->IsItemPosVisible( m_nItemPos );
      94             : 
      95        4280 :     return bVisible;
      96             : }
      97             : 
      98             : // -----------------------------------------------------------------------------
      99             : 
     100           0 : void OAccessibleMenuItemComponent::Select()
     101             : {
     102             :     // open the parent menu
     103           0 :     Reference< XAccessible > xParent( getAccessibleParent() );
     104           0 :     if ( xParent.is() )
     105             :     {
     106           0 :         OAccessibleMenuBaseComponent* pComp = static_cast< OAccessibleMenuBaseComponent* >( xParent.get() );
     107           0 :         if ( pComp && pComp->getAccessibleRole() == AccessibleRole::MENU && !pComp->IsPopupMenuOpen() )
     108           0 :             pComp->Click();
     109             :     }
     110             : 
     111             :     // highlight the menu item
     112           0 :     if ( m_pParent )
     113           0 :         m_pParent->HighlightItem( m_nItemPos );
     114           0 : }
     115             : 
     116             : // -----------------------------------------------------------------------------
     117             : 
     118           0 : void OAccessibleMenuItemComponent::DeSelect()
     119             : {
     120           0 :     if ( m_pParent && IsSelected() )
     121           0 :         m_pParent->DeHighlight();
     122           0 : }
     123             : 
     124             : // -----------------------------------------------------------------------------
     125             : 
     126           8 : void OAccessibleMenuItemComponent::Click()
     127             : {
     128             :     // open the parent menu
     129           8 :     Reference< XAccessible > xParent( getAccessibleParent() );
     130           8 :     if ( xParent.is() )
     131             :     {
     132           8 :         OAccessibleMenuBaseComponent* pComp = static_cast< OAccessibleMenuBaseComponent* >( xParent.get() );
     133           8 :         if ( pComp && pComp->getAccessibleRole() == AccessibleRole::MENU && !pComp->IsPopupMenuOpen() )
     134           0 :             pComp->Click();
     135             :     }
     136             : 
     137             :     // click the menu item
     138           8 :     if ( m_pParent )
     139             :     {
     140           8 :         Window* pWindow = m_pParent->GetWindow();
     141           8 :         if ( pWindow )
     142             :         {
     143             :             // #102438# Menu items are not selectable
     144             :             // Popup menus are executed asynchronously, triggered by a timer.
     145             :             // As Menu::SelectItem only works, if the corresponding menu window is
     146             :             // already created, we have to set the menu delay to 0, so
     147             :             // that the popup menus are executed synchronously.
     148           8 :             AllSettings aSettings = pWindow->GetSettings();
     149          16 :             MouseSettings aMouseSettings = aSettings.GetMouseSettings();
     150           8 :             sal_uLong nDelay = aMouseSettings.GetMenuDelay();
     151           8 :             aMouseSettings.SetMenuDelay( 0 );
     152           8 :             aSettings.SetMouseSettings( aMouseSettings );
     153           8 :             pWindow->SetSettings( aSettings );
     154             : 
     155           8 :             m_pParent->SelectItem( m_pParent->GetItemId( m_nItemPos ) );
     156             : 
     157             :             // meanwhile the window pointer may be invalid
     158           8 :             pWindow = m_pParent->GetWindow();
     159           8 :             if ( pWindow )
     160             :             {
     161             :                 // set the menu delay back to the old value
     162           8 :                 aSettings = pWindow->GetSettings();
     163           8 :                 aMouseSettings = aSettings.GetMouseSettings();
     164           8 :                 aMouseSettings.SetMenuDelay( nDelay );
     165           8 :                 aSettings.SetMouseSettings( aMouseSettings );
     166           8 :                 pWindow->SetSettings( aSettings );
     167           8 :             }
     168             :         }
     169           8 :     }
     170           8 : }
     171             : 
     172             : // -----------------------------------------------------------------------------
     173             : 
     174        1506 : void OAccessibleMenuItemComponent::SetItemPos( sal_uInt16 nItemPos )
     175             : {
     176        1506 :     m_nItemPos = nItemPos;
     177        1506 : }
     178             : 
     179             : // -----------------------------------------------------------------------------
     180             : 
     181           0 : void OAccessibleMenuItemComponent::SetAccessibleName( const OUString& sAccessibleName )
     182             : {
     183           0 :     if ( !m_sAccessibleName.equals( sAccessibleName ) )
     184             :     {
     185           0 :         Any aOldValue, aNewValue;
     186           0 :         aOldValue <<= m_sAccessibleName;
     187           0 :         aNewValue <<= sAccessibleName;
     188           0 :         m_sAccessibleName = sAccessibleName;
     189           0 :         NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
     190             :     }
     191           0 : }
     192             : 
     193             : // -----------------------------------------------------------------------------
     194             : 
     195        1924 : OUString OAccessibleMenuItemComponent::GetAccessibleName()
     196             : {
     197        1924 :     OUString sName;
     198        1924 :     if ( m_pParent )
     199             :     {
     200        1924 :         sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos );
     201        1924 :         sName = m_pParent->GetAccessibleName( nItemId );
     202        1924 :         if ( sName.isEmpty() )
     203        1924 :             sName = m_pParent->GetItemText( nItemId );
     204        1924 :         sName = OutputDevice::GetNonMnemonicString( sName );
     205             :     }
     206             : 
     207        1924 :     return sName;
     208             : }
     209             : 
     210             : // -----------------------------------------------------------------------------
     211             : 
     212           0 : void OAccessibleMenuItemComponent::SetItemText( const OUString& sItemText )
     213             : {
     214           0 :     Any aOldValue, aNewValue;
     215           0 :     if ( OCommonAccessibleText::implInitTextChangedEvent( m_sItemText, sItemText, aOldValue, aNewValue ) )
     216             :     {
     217           0 :         m_sItemText = sItemText;
     218           0 :         NotifyAccessibleEvent( AccessibleEventId::TEXT_CHANGED, aOldValue, aNewValue );
     219           0 :     }
     220           0 : }
     221             : 
     222             : // -----------------------------------------------------------------------------
     223             : 
     224        1924 : OUString OAccessibleMenuItemComponent::GetItemText()
     225             : {
     226        1924 :     OUString sText;
     227        1924 :     if ( m_pParent )
     228        1924 :         sText = OutputDevice::GetNonMnemonicString( m_pParent->GetItemText( m_pParent->GetItemId( m_nItemPos ) ) );
     229             : 
     230        1924 :     return sText;
     231             : }
     232             : 
     233             : // -----------------------------------------------------------------------------
     234             : 
     235        2188 : void OAccessibleMenuItemComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
     236             : {
     237        2188 :     if ( IsEnabled() )
     238             :     {
     239        2134 :         rStateSet.AddState( AccessibleStateType::ENABLED );
     240        2134 :         rStateSet.AddState( AccessibleStateType::SENSITIVE );
     241             :     }
     242             : 
     243        2188 :     if ( IsVisible() )
     244             :     {
     245          78 :         rStateSet.AddState( AccessibleStateType::VISIBLE );
     246          78 :         rStateSet.AddState( AccessibleStateType::SHOWING );
     247             :     }
     248             : 
     249        2188 :     rStateSet.AddState( AccessibleStateType::OPAQUE );
     250        2188 : }
     251             : 
     252             : // -----------------------------------------------------------------------------
     253             : // OCommonAccessibleComponent
     254             : // -----------------------------------------------------------------------------
     255             : 
     256        1472 : awt::Rectangle OAccessibleMenuItemComponent::implGetBounds() throw (RuntimeException)
     257             : {
     258        1472 :     awt::Rectangle aBounds( 0, 0, 0, 0 );
     259             : 
     260        1472 :     if ( m_pParent )
     261             :     {
     262             :         // get bounding rectangle of the item relative to the containing window
     263        1472 :         aBounds = AWTRectangle( m_pParent->GetBoundingRectangle( m_nItemPos ) );
     264             : 
     265             :         // get position of containing window in screen coordinates
     266        1472 :         Window* pWindow = m_pParent->GetWindow();
     267        1472 :         if ( pWindow )
     268             :         {
     269        1472 :             Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
     270        1472 :             awt::Point aWindowScreenLoc = AWTPoint( aRect.TopLeft() );
     271             : 
     272             :             // get position of accessible parent in screen coordinates
     273        1472 :             Reference< XAccessible > xParent = getAccessibleParent();
     274        1472 :             if ( xParent.is() )
     275             :             {
     276        1472 :                 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
     277        1472 :                 if ( xParentComponent.is() )
     278             :                 {
     279        1472 :                     awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
     280             : 
     281             :                     // calculate bounding rectangle of the item relative to the accessible parent
     282        1472 :                     aBounds.X += aWindowScreenLoc.X - aParentScreenLoc.X;
     283        1472 :                     aBounds.Y += aWindowScreenLoc.Y - aParentScreenLoc.Y;
     284        1472 :                 }
     285        1472 :             }
     286             :         }
     287             :     }
     288             : 
     289        1472 :     return aBounds;
     290             : }
     291             : 
     292             : // -----------------------------------------------------------------------------
     293             : // XComponent
     294             : // -----------------------------------------------------------------------------
     295             : 
     296        1924 : void SAL_CALL OAccessibleMenuItemComponent::disposing()
     297             : {
     298        1924 :     OAccessibleMenuBaseComponent::disposing();
     299             : 
     300        1924 :     m_pParent = NULL;
     301        1924 :     m_sAccessibleName = OUString();
     302        1924 :     m_sItemText = OUString();
     303        1924 : }
     304             : 
     305             : // -----------------------------------------------------------------------------
     306             : // XAccessibleContext
     307             : // -----------------------------------------------------------------------------
     308             : 
     309        3795 : sal_Int32 OAccessibleMenuItemComponent::getAccessibleChildCount() throw (RuntimeException)
     310             : {
     311        3795 :     OExternalLockGuard aGuard( this );
     312             : 
     313        3795 :     return 0;
     314             : }
     315             : 
     316             : // -----------------------------------------------------------------------------
     317             : 
     318           0 : Reference< XAccessible > OAccessibleMenuItemComponent::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
     319             : {
     320           0 :     OExternalLockGuard aGuard( this );
     321             : 
     322           0 :     if ( i < 0 || i >= getAccessibleChildCount() )
     323           0 :         throw IndexOutOfBoundsException();
     324             : 
     325           0 :     return Reference< XAccessible >();
     326             : }
     327             : 
     328             : // -----------------------------------------------------------------------------
     329             : 
     330        2322 : Reference< XAccessible > OAccessibleMenuItemComponent::getAccessibleParent(  ) throw (RuntimeException)
     331             : {
     332        2322 :     OExternalLockGuard aGuard( this );
     333             : 
     334        2322 :     return m_pParent->GetAccessible();
     335             : }
     336             : 
     337             : // -----------------------------------------------------------------------------
     338             : 
     339          52 : sal_Int32 OAccessibleMenuItemComponent::getAccessibleIndexInParent(  ) throw (RuntimeException)
     340             : {
     341          52 :     OExternalLockGuard aGuard( this );
     342             : 
     343          52 :     return m_nItemPos;
     344             : }
     345             : 
     346             : // -----------------------------------------------------------------------------
     347             : 
     348           0 : sal_Int16 OAccessibleMenuItemComponent::getAccessibleRole(  ) throw (RuntimeException)
     349             : {
     350           0 :     OExternalLockGuard aGuard( this );
     351             : 
     352           0 :     return AccessibleRole::UNKNOWN;
     353             : }
     354             : 
     355             : // -----------------------------------------------------------------------------
     356             : 
     357         201 : OUString OAccessibleMenuItemComponent::getAccessibleDescription( ) throw (RuntimeException)
     358             : {
     359         201 :     OExternalLockGuard aGuard( this );
     360             : 
     361         201 :     OUString sDescription;
     362         201 :     if ( m_pParent )
     363         201 :         sDescription = m_pParent->GetHelpText( m_pParent->GetItemId( m_nItemPos ) );
     364             : 
     365         201 :     return sDescription;
     366             : }
     367             : 
     368             : // -----------------------------------------------------------------------------
     369             : 
     370         201 : OUString OAccessibleMenuItemComponent::getAccessibleName(  ) throw (RuntimeException)
     371             : {
     372         201 :     OExternalLockGuard aGuard( this );
     373             : 
     374         201 :     return m_sAccessibleName;
     375             : }
     376             : 
     377             : // -----------------------------------------------------------------------------
     378             : 
     379           2 : Reference< XAccessibleRelationSet > OAccessibleMenuItemComponent::getAccessibleRelationSet(  ) throw (RuntimeException)
     380             : {
     381           2 :     OExternalLockGuard aGuard( this );
     382             : 
     383           2 :     utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
     384           2 :     Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
     385           2 :     return xSet;
     386             : }
     387             : 
     388             : // -----------------------------------------------------------------------------
     389             : 
     390           2 : Locale OAccessibleMenuItemComponent::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
     391             : {
     392           2 :     OExternalLockGuard aGuard( this );
     393             : 
     394           2 :     return Application::GetSettings().GetLanguageTag().getLocale();
     395             : }
     396             : 
     397             : // -----------------------------------------------------------------------------
     398             : // XAccessibleComponent
     399             : // -----------------------------------------------------------------------------
     400             : 
     401           0 : Reference< XAccessible > OAccessibleMenuItemComponent::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
     402             : {
     403           0 :     OExternalLockGuard aGuard( this );
     404             : 
     405           0 :     return Reference< XAccessible >();
     406             : }
     407             : 
     408             : // -----------------------------------------------------------------------------
     409             : 
     410           1 : void OAccessibleMenuItemComponent::grabFocus(  ) throw (RuntimeException)
     411             : {
     412             :     // no focus for items
     413           1 : }
     414             : 
     415             : // -----------------------------------------------------------------------------
     416             : 
     417           1 : sal_Int32 OAccessibleMenuItemComponent::getForeground(  ) throw (RuntimeException)
     418             : {
     419           1 :     OExternalLockGuard aGuard( this );
     420             : 
     421           1 :     sal_Int32 nColor = 0;
     422           2 :     Reference< XAccessible > xParent = getAccessibleParent();
     423           1 :     if ( xParent.is() )
     424             :     {
     425           1 :         Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
     426           1 :         if ( xParentComp.is() )
     427           1 :             nColor = xParentComp->getForeground();
     428             :     }
     429             : 
     430           2 :     return nColor;
     431             : }
     432             : 
     433             : // -----------------------------------------------------------------------------
     434             : 
     435           1 : sal_Int32 OAccessibleMenuItemComponent::getBackground(  ) throw (RuntimeException)
     436             : {
     437           1 :     OExternalLockGuard aGuard( this );
     438             : 
     439           1 :     sal_Int32 nColor = 0;
     440           2 :     Reference< XAccessible > xParent = getAccessibleParent();
     441           1 :     if ( xParent.is() )
     442             :     {
     443           1 :         Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
     444           1 :         if ( xParentComp.is() )
     445           1 :             nColor = xParentComp->getBackground();
     446             :     }
     447             : 
     448           2 :     return nColor;
     449             : }
     450             : 
     451             : // -----------------------------------------------------------------------------
     452             : // XAccessibleExtendedComponent
     453             : // -----------------------------------------------------------------------------
     454             : 
     455           3 : Reference< awt::XFont > OAccessibleMenuItemComponent::getFont(  ) throw (RuntimeException)
     456             : {
     457           3 :     OExternalLockGuard aGuard( this );
     458             : 
     459           3 :     Reference< awt::XFont > xFont;
     460           6 :     Reference< XAccessible > xParent = getAccessibleParent();
     461           3 :     if ( xParent.is() )
     462             :     {
     463           3 :         Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
     464           3 :         if ( xParentComp.is() )
     465           3 :             xFont = xParentComp->getFont();
     466             :     }
     467             : 
     468           6 :     return xFont;
     469             : }
     470             : 
     471             : // -----------------------------------------------------------------------------
     472             : 
     473           2 : OUString OAccessibleMenuItemComponent::getTitledBorderText(  ) throw (RuntimeException)
     474             : {
     475           2 :     OExternalLockGuard aGuard( this );
     476             : 
     477           2 :     return OUString();
     478             : }
     479             : 
     480             : // -----------------------------------------------------------------------------
     481             : 
     482           2 : OUString OAccessibleMenuItemComponent::getToolTipText(  ) throw (RuntimeException)
     483             : {
     484           2 :     OExternalLockGuard aGuard( this );
     485             : 
     486           2 :     OUString sRet;
     487           2 :     if ( m_pParent )
     488           2 :         sRet = m_pParent->GetTipHelpText( m_pParent->GetItemId( m_nItemPos ) );
     489             : 
     490           2 :     return sRet;
     491          30 : }
     492             : 
     493             : // -----------------------------------------------------------------------------
     494             : 
     495             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10