LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - accessiblemenuitemcomponent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 197 0.0 %
Date: 2012-12-17 Functions: 0 32 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/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           0 : OAccessibleMenuItemComponent::OAccessibleMenuItemComponent( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu )
      59             :     :OAccessibleMenuBaseComponent( pMenu )
      60             :     ,m_pParent( pParent )
      61           0 :     ,m_nItemPos( nItemPos )
      62             : {
      63           0 :     m_sAccessibleName = GetAccessibleName();
      64           0 :     m_sItemText = GetItemText();
      65           0 : }
      66             : 
      67             : // -----------------------------------------------------------------------------
      68             : 
      69           0 : OAccessibleMenuItemComponent::~OAccessibleMenuItemComponent()
      70             : {
      71           0 : }
      72             : 
      73             : // -----------------------------------------------------------------------------
      74             : 
      75           0 : sal_Bool OAccessibleMenuItemComponent::IsEnabled()
      76             : {
      77           0 :     OExternalLockGuard aGuard( this );
      78             : 
      79           0 :     sal_Bool bEnabled = sal_False;
      80           0 :     if ( m_pParent )
      81           0 :         bEnabled = m_pParent->IsItemEnabled( m_pParent->GetItemId( m_nItemPos ) );
      82             : 
      83           0 :     return bEnabled;
      84             : }
      85             : 
      86             : // -----------------------------------------------------------------------------
      87             : 
      88           0 : sal_Bool OAccessibleMenuItemComponent::IsVisible()
      89             : {
      90           0 :     sal_Bool bVisible = sal_False;
      91             : 
      92           0 :     if ( m_pParent )
      93           0 :         bVisible = m_pParent->IsItemPosVisible( m_nItemPos );
      94             : 
      95           0 :     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           0 : void OAccessibleMenuItemComponent::Click()
     127             : {
     128             :     // open the parent menu
     129           0 :     Reference< XAccessible > xParent( getAccessibleParent() );
     130           0 :     if ( xParent.is() )
     131             :     {
     132           0 :         OAccessibleMenuBaseComponent* pComp = static_cast< OAccessibleMenuBaseComponent* >( xParent.get() );
     133           0 :         if ( pComp && pComp->getAccessibleRole() == AccessibleRole::MENU && !pComp->IsPopupMenuOpen() )
     134           0 :             pComp->Click();
     135             :     }
     136             : 
     137             :     // click the menu item
     138           0 :     if ( m_pParent )
     139             :     {
     140           0 :         Window* pWindow = m_pParent->GetWindow();
     141           0 :         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           0 :             AllSettings aSettings = pWindow->GetSettings();
     149           0 :             MouseSettings aMouseSettings = aSettings.GetMouseSettings();
     150           0 :             sal_uLong nDelay = aMouseSettings.GetMenuDelay();
     151           0 :             aMouseSettings.SetMenuDelay( 0 );
     152           0 :             aSettings.SetMouseSettings( aMouseSettings );
     153           0 :             pWindow->SetSettings( aSettings );
     154             : 
     155           0 :             m_pParent->SelectItem( m_pParent->GetItemId( m_nItemPos ) );
     156             : 
     157             :             // meanwhile the window pointer may be invalid
     158           0 :             pWindow = m_pParent->GetWindow();
     159           0 :             if ( pWindow )
     160             :             {
     161             :                 // set the menu delay back to the old value
     162           0 :                 aSettings = pWindow->GetSettings();
     163           0 :                 aMouseSettings = aSettings.GetMouseSettings();
     164           0 :                 aMouseSettings.SetMenuDelay( nDelay );
     165           0 :                 aSettings.SetMouseSettings( aMouseSettings );
     166           0 :                 pWindow->SetSettings( aSettings );
     167           0 :             }
     168             :         }
     169           0 :     }
     170           0 : }
     171             : 
     172             : // -----------------------------------------------------------------------------
     173             : 
     174           0 : void OAccessibleMenuItemComponent::SetItemPos( sal_uInt16 nItemPos )
     175             : {
     176           0 :     m_nItemPos = nItemPos;
     177           0 : }
     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           0 : OUString OAccessibleMenuItemComponent::GetAccessibleName()
     196             : {
     197           0 :     OUString sName;
     198           0 :     if ( m_pParent )
     199             :     {
     200           0 :         sal_uInt16 nItemId = m_pParent->GetItemId( m_nItemPos );
     201           0 :         sName = m_pParent->GetAccessibleName( nItemId );
     202           0 :         if ( sName.isEmpty() )
     203           0 :             sName = m_pParent->GetItemText( nItemId );
     204           0 :         sName = OutputDevice::GetNonMnemonicString( sName );
     205             :     }
     206             : 
     207           0 :     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           0 : OUString OAccessibleMenuItemComponent::GetItemText()
     225             : {
     226           0 :     OUString sText;
     227           0 :     if ( m_pParent )
     228           0 :         sText = OutputDevice::GetNonMnemonicString( m_pParent->GetItemText( m_pParent->GetItemId( m_nItemPos ) ) );
     229             : 
     230           0 :     return sText;
     231             : }
     232             : 
     233             : // -----------------------------------------------------------------------------
     234             : 
     235           0 : void OAccessibleMenuItemComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
     236             : {
     237           0 :     if ( IsEnabled() )
     238             :     {
     239           0 :         rStateSet.AddState( AccessibleStateType::ENABLED );
     240           0 :         rStateSet.AddState( AccessibleStateType::SENSITIVE );
     241             :     }
     242             : 
     243           0 :     if ( IsVisible() )
     244             :     {
     245           0 :         rStateSet.AddState( AccessibleStateType::VISIBLE );
     246           0 :         rStateSet.AddState( AccessibleStateType::SHOWING );
     247             :     }
     248             : 
     249           0 :     rStateSet.AddState( AccessibleStateType::OPAQUE );
     250           0 : }
     251             : 
     252             : // -----------------------------------------------------------------------------
     253             : // OCommonAccessibleComponent
     254             : // -----------------------------------------------------------------------------
     255             : 
     256           0 : awt::Rectangle OAccessibleMenuItemComponent::implGetBounds() throw (RuntimeException)
     257             : {
     258           0 :     awt::Rectangle aBounds( 0, 0, 0, 0 );
     259             : 
     260           0 :     if ( m_pParent )
     261             :     {
     262             :         // get bounding rectangle of the item relative to the containing window
     263           0 :         aBounds = AWTRectangle( m_pParent->GetBoundingRectangle( m_nItemPos ) );
     264             : 
     265             :         // get position of containing window in screen coordinates
     266           0 :         Window* pWindow = m_pParent->GetWindow();
     267           0 :         if ( pWindow )
     268             :         {
     269           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
     270           0 :             awt::Point aWindowScreenLoc = AWTPoint( aRect.TopLeft() );
     271             : 
     272             :             // get position of accessible parent in screen coordinates
     273           0 :             Reference< XAccessible > xParent = getAccessibleParent();
     274           0 :             if ( xParent.is() )
     275             :             {
     276           0 :                 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
     277           0 :                 if ( xParentComponent.is() )
     278             :                 {
     279           0 :                     awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
     280             : 
     281             :                     // calculate bounding rectangle of the item relative to the accessible parent
     282           0 :                     aBounds.X += aWindowScreenLoc.X - aParentScreenLoc.X;
     283           0 :                     aBounds.Y += aWindowScreenLoc.Y - aParentScreenLoc.Y;
     284           0 :                 }
     285           0 :             }
     286             :         }
     287             :     }
     288             : 
     289           0 :     return aBounds;
     290             : }
     291             : 
     292             : // -----------------------------------------------------------------------------
     293             : // XComponent
     294             : // -----------------------------------------------------------------------------
     295             : 
     296           0 : void SAL_CALL OAccessibleMenuItemComponent::disposing()
     297             : {
     298           0 :     OAccessibleMenuBaseComponent::disposing();
     299             : 
     300           0 :     m_pParent = NULL;
     301           0 :     m_sAccessibleName = OUString();
     302           0 :     m_sItemText = OUString();
     303           0 : }
     304             : 
     305             : // -----------------------------------------------------------------------------
     306             : // XAccessibleContext
     307             : // -----------------------------------------------------------------------------
     308             : 
     309           0 : sal_Int32 OAccessibleMenuItemComponent::getAccessibleChildCount() throw (RuntimeException)
     310             : {
     311           0 :     OExternalLockGuard aGuard( this );
     312             : 
     313           0 :     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           0 : Reference< XAccessible > OAccessibleMenuItemComponent::getAccessibleParent(  ) throw (RuntimeException)
     331             : {
     332           0 :     OExternalLockGuard aGuard( this );
     333             : 
     334           0 :     return m_pParent->GetAccessible();
     335             : }
     336             : 
     337             : // -----------------------------------------------------------------------------
     338             : 
     339           0 : sal_Int32 OAccessibleMenuItemComponent::getAccessibleIndexInParent(  ) throw (RuntimeException)
     340             : {
     341           0 :     OExternalLockGuard aGuard( this );
     342             : 
     343           0 :     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           0 : OUString OAccessibleMenuItemComponent::getAccessibleDescription( ) throw (RuntimeException)
     358             : {
     359           0 :     OExternalLockGuard aGuard( this );
     360             : 
     361           0 :     OUString sDescription;
     362           0 :     if ( m_pParent )
     363           0 :         sDescription = m_pParent->GetHelpText( m_pParent->GetItemId( m_nItemPos ) );
     364             : 
     365           0 :     return sDescription;
     366             : }
     367             : 
     368             : // -----------------------------------------------------------------------------
     369             : 
     370           0 : OUString OAccessibleMenuItemComponent::getAccessibleName(  ) throw (RuntimeException)
     371             : {
     372           0 :     OExternalLockGuard aGuard( this );
     373             : 
     374           0 :     return m_sAccessibleName;
     375             : }
     376             : 
     377             : // -----------------------------------------------------------------------------
     378             : 
     379           0 : Reference< XAccessibleRelationSet > OAccessibleMenuItemComponent::getAccessibleRelationSet(  ) throw (RuntimeException)
     380             : {
     381           0 :     OExternalLockGuard aGuard( this );
     382             : 
     383           0 :     utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
     384           0 :     Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
     385           0 :     return xSet;
     386             : }
     387             : 
     388             : // -----------------------------------------------------------------------------
     389             : 
     390           0 : Locale OAccessibleMenuItemComponent::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
     391             : {
     392           0 :     OExternalLockGuard aGuard( this );
     393             : 
     394           0 :     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           0 : void OAccessibleMenuItemComponent::grabFocus(  ) throw (RuntimeException)
     411             : {
     412             :     // no focus for items
     413           0 : }
     414             : 
     415             : // -----------------------------------------------------------------------------
     416             : 
     417           0 : sal_Int32 OAccessibleMenuItemComponent::getForeground(  ) throw (RuntimeException)
     418             : {
     419           0 :     OExternalLockGuard aGuard( this );
     420             : 
     421           0 :     sal_Int32 nColor = 0;
     422           0 :     Reference< XAccessible > xParent = getAccessibleParent();
     423           0 :     if ( xParent.is() )
     424             :     {
     425           0 :         Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
     426           0 :         if ( xParentComp.is() )
     427           0 :             nColor = xParentComp->getForeground();
     428             :     }
     429             : 
     430           0 :     return nColor;
     431             : }
     432             : 
     433             : // -----------------------------------------------------------------------------
     434             : 
     435           0 : sal_Int32 OAccessibleMenuItemComponent::getBackground(  ) throw (RuntimeException)
     436             : {
     437           0 :     OExternalLockGuard aGuard( this );
     438             : 
     439           0 :     sal_Int32 nColor = 0;
     440           0 :     Reference< XAccessible > xParent = getAccessibleParent();
     441           0 :     if ( xParent.is() )
     442             :     {
     443           0 :         Reference< XAccessibleComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
     444           0 :         if ( xParentComp.is() )
     445           0 :             nColor = xParentComp->getBackground();
     446             :     }
     447             : 
     448           0 :     return nColor;
     449             : }
     450             : 
     451             : // -----------------------------------------------------------------------------
     452             : // XAccessibleExtendedComponent
     453             : // -----------------------------------------------------------------------------
     454             : 
     455           0 : Reference< awt::XFont > OAccessibleMenuItemComponent::getFont(  ) throw (RuntimeException)
     456             : {
     457           0 :     OExternalLockGuard aGuard( this );
     458             : 
     459           0 :     Reference< awt::XFont > xFont;
     460           0 :     Reference< XAccessible > xParent = getAccessibleParent();
     461           0 :     if ( xParent.is() )
     462             :     {
     463           0 :         Reference< XAccessibleExtendedComponent > xParentComp( xParent->getAccessibleContext(), UNO_QUERY );
     464           0 :         if ( xParentComp.is() )
     465           0 :             xFont = xParentComp->getFont();
     466             :     }
     467             : 
     468           0 :     return xFont;
     469             : }
     470             : 
     471             : // -----------------------------------------------------------------------------
     472             : 
     473           0 : OUString OAccessibleMenuItemComponent::getTitledBorderText(  ) throw (RuntimeException)
     474             : {
     475           0 :     OExternalLockGuard aGuard( this );
     476             : 
     477           0 :     return OUString();
     478             : }
     479             : 
     480             : // -----------------------------------------------------------------------------
     481             : 
     482           0 : OUString OAccessibleMenuItemComponent::getToolTipText(  ) throw (RuntimeException)
     483             : {
     484           0 :     OExternalLockGuard aGuard( this );
     485             : 
     486           0 :     OUString sRet;
     487           0 :     if ( m_pParent )
     488           0 :         sRet = m_pParent->GetTipHelpText( m_pParent->GetItemId( m_nItemPos ) );
     489             : 
     490           0 :     return sRet;
     491             : }
     492             : 
     493             : // -----------------------------------------------------------------------------
     494             : 
     495             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10