LCOV - code coverage report
Current view: top level - libreoffice/accessibility/source/standard - accessiblemenucomponent.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 171 0.0 %
Date: 2012-12-27 Functions: 0 35 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/accessiblemenucomponent.hxx>
      21             : 
      22             : #include <toolkit/awt/vclxfont.hxx>
      23             : #include <toolkit/helper/convert.hxx>
      24             : 
      25             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      27             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      28             : 
      29             : #include <unotools/accessiblestatesethelper.hxx>
      30             : #include <unotools/accessiblerelationsethelper.hxx>
      31             : #include <cppuhelper/typeprovider.hxx>
      32             : #include <comphelper/sequence.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : #include <vcl/window.hxx>
      35             : #include <vcl/menu.hxx>
      36             : #include <vcl/unohelp2.hxx>
      37             : 
      38             : 
      39             : using namespace ::com::sun::star::accessibility;
      40             : using namespace ::com::sun::star::uno;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::com::sun::star;
      43             : using namespace ::comphelper;
      44             : 
      45             : 
      46             : // -----------------------------------------------------------------------------
      47             : // class OAccessibleMenuComponent
      48             : // -----------------------------------------------------------------------------
      49             : 
      50           0 : OAccessibleMenuComponent::OAccessibleMenuComponent( Menu* pMenu )
      51           0 :     :OAccessibleMenuBaseComponent( pMenu )
      52             : {
      53           0 : }
      54             : 
      55             : // -----------------------------------------------------------------------------
      56             : 
      57           0 : OAccessibleMenuComponent::~OAccessibleMenuComponent()
      58             : {
      59           0 : }
      60             : 
      61             : // -----------------------------------------------------------------------------
      62             : 
      63           0 : sal_Bool OAccessibleMenuComponent::IsEnabled()
      64             : {
      65           0 :     return sal_True;
      66             : }
      67             : 
      68             : // -----------------------------------------------------------------------------
      69             : 
      70           0 : sal_Bool OAccessibleMenuComponent::IsVisible()
      71             : {
      72           0 :     sal_Bool bVisible = sal_False;
      73             : 
      74           0 :     if ( m_pMenu )
      75           0 :         bVisible = m_pMenu->IsMenuVisible();
      76             : 
      77           0 :     return bVisible;
      78             : }
      79             : 
      80             : // -----------------------------------------------------------------------------
      81             : 
      82           0 : void OAccessibleMenuComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
      83             : {
      84           0 :     if ( IsEnabled() )
      85             :     {
      86           0 :         rStateSet.AddState( AccessibleStateType::ENABLED );
      87           0 :         rStateSet.AddState( AccessibleStateType::SENSITIVE );
      88             :     }
      89             : 
      90           0 :     rStateSet.AddState( AccessibleStateType::FOCUSABLE );
      91             : 
      92           0 :     if ( IsFocused() )
      93           0 :         rStateSet.AddState( AccessibleStateType::FOCUSED );
      94             : 
      95           0 :     if ( IsVisible() )
      96             :     {
      97           0 :         rStateSet.AddState( AccessibleStateType::VISIBLE );
      98           0 :         rStateSet.AddState( AccessibleStateType::SHOWING );
      99             :     }
     100             : 
     101           0 :     rStateSet.AddState( AccessibleStateType::OPAQUE );
     102           0 : }
     103             : 
     104             : // -----------------------------------------------------------------------------
     105             : // OCommonAccessibleComponent
     106             : // -----------------------------------------------------------------------------
     107             : 
     108           0 : awt::Rectangle OAccessibleMenuComponent::implGetBounds() throw (RuntimeException)
     109             : {
     110           0 :     awt::Rectangle aBounds( 0, 0, 0, 0 );
     111             : 
     112           0 :     if ( m_pMenu )
     113             :     {
     114           0 :         Window* pWindow = m_pMenu->GetWindow();
     115           0 :         if ( pWindow )
     116             :         {
     117             :             // get bounding rectangle of the window in screen coordinates
     118           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
     119           0 :             aBounds = AWTRectangle( aRect );
     120             : 
     121             :             // get position of the accessible parent in screen coordinates
     122           0 :             Reference< XAccessible > xParent = getAccessibleParent();
     123           0 :             if ( xParent.is() )
     124             :             {
     125           0 :                 Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), UNO_QUERY );
     126           0 :                 if ( xParentComponent.is() )
     127             :                 {
     128           0 :                     awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
     129             : 
     130             :                     // calculate position of the window relative to the accessible parent
     131           0 :                     aBounds.X -= aParentScreenLoc.X;
     132           0 :                     aBounds.Y -= aParentScreenLoc.Y;
     133           0 :                 }
     134           0 :             }
     135             :         }
     136             :     }
     137             : 
     138           0 :     return aBounds;
     139             : }
     140             : 
     141             : // -----------------------------------------------------------------------------
     142             : // XInterface
     143             : // -----------------------------------------------------------------------------
     144             : 
     145           0 : IMPLEMENT_FORWARD_XINTERFACE2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
     146             : 
     147             : // -----------------------------------------------------------------------------
     148             : // XTypeProvider
     149             : // -----------------------------------------------------------------------------
     150             : 
     151           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( OAccessibleMenuComponent, OAccessibleMenuBaseComponent, OAccessibleMenuComponent_BASE )
     152             : 
     153             : // -----------------------------------------------------------------------------
     154             : // XAccessibleContext
     155             : // -----------------------------------------------------------------------------
     156             : 
     157           0 : sal_Int32 OAccessibleMenuComponent::getAccessibleChildCount() throw (RuntimeException)
     158             : {
     159           0 :     OExternalLockGuard aGuard( this );
     160             : 
     161           0 :     return GetChildCount();
     162             : }
     163             : 
     164             : // -----------------------------------------------------------------------------
     165             : 
     166           0 : Reference< XAccessible > OAccessibleMenuComponent::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
     167             : {
     168           0 :     OExternalLockGuard aGuard( this );
     169             : 
     170           0 :     if ( i < 0 || i >= GetChildCount() )
     171           0 :         throw IndexOutOfBoundsException();
     172             : 
     173           0 :     return GetChild( i );
     174             : }
     175             : 
     176             : // -----------------------------------------------------------------------------
     177             : 
     178           0 : Reference< XAccessible > OAccessibleMenuComponent::getAccessibleParent(  ) throw (RuntimeException)
     179             : {
     180           0 :     OExternalLockGuard aGuard( this );
     181             : 
     182           0 :     Reference< XAccessible > xParent;
     183             : 
     184           0 :     if ( m_pMenu )
     185             :     {
     186           0 :         Window* pWindow = m_pMenu->GetWindow();
     187           0 :         if ( pWindow )
     188             :         {
     189           0 :             Window* pParent = pWindow->GetAccessibleParentWindow();
     190           0 :             if ( pParent )
     191           0 :                 xParent = pParent->GetAccessible();
     192             :         }
     193             :     }
     194             : 
     195           0 :     return xParent;
     196             : }
     197             : 
     198             : // -----------------------------------------------------------------------------
     199             : 
     200           0 : sal_Int16 OAccessibleMenuComponent::getAccessibleRole(  ) throw (RuntimeException)
     201             : {
     202           0 :     OExternalLockGuard aGuard( this );
     203             : 
     204           0 :     return AccessibleRole::UNKNOWN;
     205             : }
     206             : 
     207             : // -----------------------------------------------------------------------------
     208             : 
     209           0 : OUString OAccessibleMenuComponent::getAccessibleDescription( ) throw (RuntimeException)
     210             : {
     211           0 :     OExternalLockGuard aGuard( this );
     212             : 
     213           0 :     OUString sDescription;
     214           0 :     if ( m_pMenu )
     215             :     {
     216           0 :         Window* pWindow = m_pMenu->GetWindow();
     217           0 :         if ( pWindow )
     218           0 :             sDescription = pWindow->GetAccessibleDescription();
     219             :     }
     220             : 
     221           0 :     return sDescription;
     222             : }
     223             : 
     224             : // -----------------------------------------------------------------------------
     225             : 
     226           0 : OUString OAccessibleMenuComponent::getAccessibleName(  ) throw (RuntimeException)
     227             : {
     228           0 :     OExternalLockGuard aGuard( this );
     229             : 
     230           0 :     return OUString();
     231             : }
     232             : 
     233             : // -----------------------------------------------------------------------------
     234             : 
     235           0 : Reference< XAccessibleRelationSet > OAccessibleMenuComponent::getAccessibleRelationSet(  ) throw (RuntimeException)
     236             : {
     237           0 :     OExternalLockGuard aGuard( this );
     238             : 
     239           0 :     utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
     240           0 :     Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
     241           0 :     return xSet;
     242             : }
     243             : 
     244             : // -----------------------------------------------------------------------------
     245             : 
     246           0 : Locale OAccessibleMenuComponent::getLocale(  ) throw (IllegalAccessibleComponentStateException, RuntimeException)
     247             : {
     248           0 :     OExternalLockGuard aGuard( this );
     249             : 
     250           0 :     return Application::GetSettings().GetLanguageTag().getLocale();
     251             : }
     252             : 
     253             : // -----------------------------------------------------------------------------
     254             : // XAccessibleComponent
     255             : // -----------------------------------------------------------------------------
     256             : 
     257           0 : Reference< XAccessible > OAccessibleMenuComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
     258             : {
     259           0 :     OExternalLockGuard aGuard( this );
     260             : 
     261           0 :     return GetChildAt( rPoint );
     262             : }
     263             : 
     264             : // -----------------------------------------------------------------------------
     265             : 
     266           0 : awt::Point OAccessibleMenuComponent::getLocationOnScreen(  ) throw (RuntimeException)
     267             : {
     268           0 :     OExternalLockGuard aGuard( this );
     269             : 
     270           0 :     awt::Point aPos;
     271             : 
     272           0 :     if ( m_pMenu )
     273             :     {
     274           0 :         Window* pWindow = m_pMenu->GetWindow();
     275           0 :         if ( pWindow )
     276             :         {
     277           0 :             Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
     278           0 :             aPos = AWTPoint( aRect.TopLeft() );
     279             :         }
     280             :     }
     281             : 
     282           0 :     return aPos;
     283             : }
     284             : 
     285             : // -----------------------------------------------------------------------------
     286             : 
     287           0 : void OAccessibleMenuComponent::grabFocus(  ) throw (RuntimeException)
     288             : {
     289           0 :     OExternalLockGuard aGuard( this );
     290             : 
     291           0 :     if ( m_pMenu )
     292             :     {
     293           0 :         Window* pWindow = m_pMenu->GetWindow();
     294           0 :         if ( pWindow )
     295           0 :             pWindow->GrabFocus();
     296           0 :     }
     297           0 : }
     298             : 
     299             : // -----------------------------------------------------------------------------
     300             : 
     301           0 : sal_Int32 OAccessibleMenuComponent::getForeground(  ) throw (RuntimeException)
     302             : {
     303           0 :     OExternalLockGuard aGuard( this );
     304             : 
     305           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     306           0 :     sal_Int32 nColor = rStyleSettings.GetMenuTextColor().GetColor();
     307             : 
     308           0 :     return nColor;
     309             : }
     310             : 
     311             : // -----------------------------------------------------------------------------
     312             : 
     313           0 : sal_Int32 OAccessibleMenuComponent::getBackground(  ) throw (RuntimeException)
     314             : {
     315           0 :     OExternalLockGuard aGuard( this );
     316             : 
     317           0 :     return 0;
     318             : }
     319             : 
     320             : // -----------------------------------------------------------------------------
     321             : // XAccessibleExtendedComponent
     322             : // -----------------------------------------------------------------------------
     323             : 
     324           0 : Reference< awt::XFont > OAccessibleMenuComponent::getFont(  ) throw (RuntimeException)
     325             : {
     326           0 :     OExternalLockGuard aGuard( this );
     327             : 
     328           0 :     Reference< awt::XFont > xFont;
     329             : 
     330           0 :     if ( m_pMenu )
     331             :     {
     332           0 :         Window* pWindow = m_pMenu->GetWindow();
     333           0 :         if ( pWindow )
     334             :         {
     335           0 :             Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
     336           0 :             if ( xDev.is() )
     337             :             {
     338           0 :                 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     339           0 :                 VCLXFont* pVCLXFont = new VCLXFont;
     340           0 :                 pVCLXFont->Init( *xDev.get(), rStyleSettings.GetMenuFont() );
     341           0 :                 xFont = pVCLXFont;
     342           0 :             }
     343             :         }
     344             :     }
     345             : 
     346           0 :     return xFont;
     347             : }
     348             : 
     349             : // -----------------------------------------------------------------------------
     350             : 
     351           0 : OUString OAccessibleMenuComponent::getTitledBorderText(  ) throw (RuntimeException)
     352             : {
     353           0 :     OExternalLockGuard aGuard( this );
     354             : 
     355           0 :     return OUString();
     356             : }
     357             : 
     358             : // -----------------------------------------------------------------------------
     359             : 
     360           0 : OUString OAccessibleMenuComponent::getToolTipText(  ) throw (RuntimeException)
     361             : {
     362           0 :     OExternalLockGuard aGuard( this );
     363             : 
     364           0 :     return OUString();
     365             : }
     366             : 
     367             : // -----------------------------------------------------------------------------
     368             : // XAccessibleSelection
     369             : // -----------------------------------------------------------------------------
     370             : 
     371           0 : void OAccessibleMenuComponent::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     372             : {
     373           0 :     OExternalLockGuard aGuard( this );
     374             : 
     375           0 :     if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
     376           0 :         throw IndexOutOfBoundsException();
     377             : 
     378           0 :     SelectChild( nChildIndex );
     379           0 : }
     380             : 
     381             : // -----------------------------------------------------------------------------
     382             : 
     383           0 : sal_Bool OAccessibleMenuComponent::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     384             : {
     385           0 :     OExternalLockGuard aGuard( this );
     386             : 
     387           0 :     if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
     388           0 :         throw IndexOutOfBoundsException();
     389             : 
     390           0 :     return IsChildSelected( nChildIndex );
     391             : }
     392             : 
     393             : // -----------------------------------------------------------------------------
     394             : 
     395           0 : void OAccessibleMenuComponent::clearAccessibleSelection(  ) throw (RuntimeException)
     396             : {
     397           0 :     OExternalLockGuard aGuard( this );
     398             : 
     399           0 :     DeSelectAll();
     400           0 : }
     401             : 
     402             : // -----------------------------------------------------------------------------
     403             : 
     404           0 : void OAccessibleMenuComponent::selectAllAccessibleChildren(  ) throw (RuntimeException)
     405             : {
     406             :     // This method makes no sense in a menu, and so does nothing.
     407           0 : }
     408             : 
     409             : // -----------------------------------------------------------------------------
     410             : 
     411           0 : sal_Int32 OAccessibleMenuComponent::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
     412             : {
     413           0 :     OExternalLockGuard aGuard( this );
     414             : 
     415           0 :     sal_Int32 nRet = 0;
     416             : 
     417           0 :     for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ )
     418             :     {
     419           0 :         if ( IsChildSelected( i ) )
     420           0 :             ++nRet;
     421             :     }
     422             : 
     423           0 :     return nRet;
     424             : }
     425             : 
     426             : // -----------------------------------------------------------------------------
     427             : 
     428           0 : Reference< XAccessible > OAccessibleMenuComponent::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     429             : {
     430           0 :     OExternalLockGuard aGuard( this );
     431             : 
     432           0 :     if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
     433           0 :         throw IndexOutOfBoundsException();
     434             : 
     435           0 :     Reference< XAccessible > xChild;
     436             : 
     437           0 :     for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ )
     438             :     {
     439           0 :         if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) )
     440             :         {
     441           0 :             xChild = GetChild( i );
     442           0 :             break;
     443             :         }
     444             :     }
     445             : 
     446           0 :     return xChild;
     447             : }
     448             : 
     449             : // -----------------------------------------------------------------------------
     450             : 
     451           0 : void OAccessibleMenuComponent::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException)
     452             : {
     453           0 :     OExternalLockGuard aGuard( this );
     454             : 
     455           0 :     if ( nChildIndex < 0 || nChildIndex >= GetChildCount() )
     456           0 :         throw IndexOutOfBoundsException();
     457             : 
     458           0 :     DeSelectAll();
     459           0 : }
     460             : 
     461             : // -----------------------------------------------------------------------------
     462             : 
     463             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10