LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessiblemenubar.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 56 65 86.2 %
Date: 2014-11-03 Functions: 14 15 93.3 %
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/vclxaccessiblemenubar.hxx>
      21             : 
      22             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/window.hxx>
      25             : #include <vcl/menu.hxx>
      26             : #include <vcl/settings.hxx>
      27             : 
      28             : using namespace ::com::sun::star::accessibility;
      29             : using namespace ::com::sun::star::uno;
      30             : using namespace ::com::sun::star;
      31             : using namespace ::comphelper;
      32             : 
      33             : 
      34             : 
      35             : // class VCLXAccessibleMenuBar
      36             : 
      37             : 
      38          50 : VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu* pMenu )
      39          50 :     :OAccessibleMenuComponent( pMenu )
      40             : {
      41          50 :     if ( pMenu )
      42             :     {
      43          50 :         m_pWindow = pMenu->GetWindow();
      44             : 
      45          50 :         if ( m_pWindow )
      46          50 :             m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
      47             :     }
      48             :     else
      49             :     {
      50           0 :         m_pWindow = 0;
      51             :     }
      52          50 : }
      53             : 
      54             : 
      55             : 
      56         150 : VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
      57             : {
      58          50 :     if ( m_pWindow )
      59           0 :         m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
      60         100 : }
      61             : 
      62             : 
      63             : 
      64          72 : bool VCLXAccessibleMenuBar::IsFocused()
      65             : {
      66          72 :     bool bFocused = false;
      67             : 
      68          72 :     if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
      69           0 :         bFocused = true;
      70             : 
      71          72 :     return bFocused;
      72             : }
      73             : 
      74             : 
      75             : 
      76         392 : IMPL_LINK( VCLXAccessibleMenuBar, WindowEventListener, VclSimpleEvent*, pEvent )
      77             : {
      78             :     OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "VCLXAccessibleMenuBar::WindowEventListener: unknown window event!" );
      79         196 :     if ( pEvent && pEvent->ISA( VclWindowEvent ) )
      80             :     {
      81             :         OSL_ENSURE( static_cast<VclWindowEvent*>(pEvent)->GetWindow(), "VCLXAccessibleMenuBar::WindowEventListener: no window!" );
      82         196 :         if ( !static_cast<VclWindowEvent*>(pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
      83             :         {
      84         196 :             ProcessWindowEvent( *static_cast<VclWindowEvent*>(pEvent) );
      85             :         }
      86             :     }
      87         196 :     return 0;
      88             : }
      89             : 
      90             : 
      91             : 
      92         196 : void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      93             : {
      94         196 :     switch ( rVclWindowEvent.GetId() )
      95             :     {
      96             :         case VCLEVENT_WINDOW_GETFOCUS:
      97             :         case VCLEVENT_WINDOW_LOSEFOCUS:
      98             :         {
      99          32 :             SetFocused( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS );
     100             :         }
     101          32 :         break;
     102             :         case VCLEVENT_OBJECT_DYING:
     103             :         {
     104          50 :             if ( m_pWindow )
     105             :             {
     106          50 :                 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
     107          50 :                 m_pWindow = NULL;
     108             :             }
     109             :         }
     110          50 :         break;
     111             :         default:
     112             :         {
     113             :         }
     114         114 :         break;
     115             :     }
     116         196 : }
     117             : 
     118             : 
     119             : // XComponent
     120             : 
     121             : 
     122          50 : void VCLXAccessibleMenuBar::disposing()
     123             : {
     124          50 :     OAccessibleMenuComponent::disposing();
     125             : 
     126          50 :     if ( m_pWindow )
     127             :     {
     128           0 :         m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
     129           0 :         m_pWindow = NULL;
     130             :     }
     131          50 : }
     132             : 
     133             : 
     134             : // XServiceInfo
     135             : 
     136             : 
     137           2 : OUString VCLXAccessibleMenuBar::getImplementationName() throw (RuntimeException, std::exception)
     138             : {
     139           2 :     return OUString( "com.sun.star.comp.toolkit.AccessibleMenuBar" );
     140             : }
     141             : 
     142             : 
     143             : 
     144           0 : Sequence< OUString > VCLXAccessibleMenuBar::getSupportedServiceNames() throw (RuntimeException, std::exception)
     145             : {
     146           0 :     Sequence< OUString > aNames(1);
     147           0 :     aNames[0] = "com.sun.star.awt.AccessibleMenuBar";
     148           0 :     return aNames;
     149             : }
     150             : 
     151             : 
     152             : // XAccessibleContext
     153             : 
     154             : 
     155           2 : sal_Int32 VCLXAccessibleMenuBar::getAccessibleIndexInParent(  ) throw (RuntimeException, std::exception)
     156             : {
     157           2 :     OExternalLockGuard aGuard( this );
     158             : 
     159           2 :     sal_Int32 nIndexInParent = -1;
     160             : 
     161           2 :     if ( m_pMenu )
     162             :     {
     163           2 :         vcl::Window* pWindow = m_pMenu->GetWindow();
     164           2 :         if ( pWindow )
     165             :         {
     166           2 :             vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
     167           2 :             if ( pParent )
     168             :             {
     169          16 :                 for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
     170             :                 {
     171          14 :                     vcl::Window* pChild = pParent->GetAccessibleChildWindow( --n );
     172          14 :                     if ( pChild == pWindow )
     173             :                     {
     174           2 :                         nIndexInParent = n;
     175           2 :                         break;
     176             :                     }
     177             :                 }
     178             :             }
     179             :         }
     180             :     }
     181             : 
     182           2 :     return nIndexInParent;
     183             : }
     184             : 
     185             : 
     186             : 
     187         258 : sal_Int16 VCLXAccessibleMenuBar::getAccessibleRole(  ) throw (RuntimeException, std::exception)
     188             : {
     189         258 :     OExternalLockGuard aGuard( this );
     190             : 
     191         258 :     return AccessibleRole::MENU_BAR;
     192             : }
     193             : 
     194             : 
     195             : // XAccessibleExtendedComponent
     196             : 
     197             : 
     198           2 : sal_Int32 VCLXAccessibleMenuBar::getBackground(  ) throw (RuntimeException, std::exception)
     199             : {
     200           2 :     OExternalLockGuard aGuard( this );
     201             : 
     202           2 :     return Application::GetSettings().GetStyleSettings().GetMenuBarColor().GetColor();
     203          60 : }
     204             : 
     205             : 
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10