LCOV - code coverage report
Current view: top level - accessibility/source/standard - vclxaccessiblemenubar.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 55 64 85.9 %
Date: 2015-06-13 12:38:46 Functions: 12 13 92.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          25 : VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu* pMenu )
      39          25 :     :OAccessibleMenuComponent( pMenu )
      40             : {
      41          25 :     if ( pMenu )
      42             :     {
      43          25 :         m_pWindow = pMenu->GetWindow();
      44             : 
      45          25 :         if ( m_pWindow )
      46          25 :             m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
      47             :     }
      48             :     else
      49             :     {
      50           0 :         m_pWindow = 0;
      51             :     }
      52          25 : }
      53             : 
      54             : 
      55             : 
      56          75 : VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
      57             : {
      58          25 :     if ( m_pWindow )
      59           0 :         m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
      60          50 : }
      61             : 
      62             : 
      63             : 
      64          36 : bool VCLXAccessibleMenuBar::IsFocused()
      65             : {
      66          36 :     bool bFocused = false;
      67             : 
      68          36 :     if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
      69           0 :         bFocused = true;
      70             : 
      71          36 :     return bFocused;
      72             : }
      73             : 
      74             : 
      75             : 
      76         196 : IMPL_LINK( VCLXAccessibleMenuBar, WindowEventListener, VclSimpleEvent*, pEvent )
      77             : {
      78             :     OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "VCLXAccessibleMenuBar::WindowEventListener: unknown window event!" );
      79          98 :     if ( pEvent && pEvent->ISA( VclWindowEvent ) )
      80             :     {
      81             :         OSL_ENSURE( static_cast<VclWindowEvent*>(pEvent)->GetWindow(), "VCLXAccessibleMenuBar::WindowEventListener: no window!" );
      82          98 :         if ( !static_cast<VclWindowEvent*>(pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
      83             :         {
      84          98 :             ProcessWindowEvent( *static_cast<VclWindowEvent*>(pEvent) );
      85             :         }
      86             :     }
      87          98 :     return 0;
      88             : }
      89             : 
      90             : 
      91             : 
      92          98 : void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
      93             : {
      94          98 :     switch ( rVclWindowEvent.GetId() )
      95             :     {
      96             :         case VCLEVENT_WINDOW_GETFOCUS:
      97             :         case VCLEVENT_WINDOW_LOSEFOCUS:
      98             :         {
      99          16 :             SetFocused( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS );
     100             :         }
     101          16 :         break;
     102             :         case VCLEVENT_OBJECT_DYING:
     103             :         {
     104          25 :             if ( m_pWindow )
     105             :             {
     106          25 :                 m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
     107          25 :                 m_pWindow = NULL;
     108             :             }
     109             :         }
     110          25 :         break;
     111             :         default:
     112             :         {
     113             :         }
     114          57 :         break;
     115             :     }
     116          98 : }
     117             : 
     118             : 
     119             : // XComponent
     120             : 
     121             : 
     122          25 : void VCLXAccessibleMenuBar::disposing()
     123             : {
     124          25 :     OAccessibleMenuComponent::disposing();
     125             : 
     126          25 :     if ( m_pWindow )
     127             :     {
     128           0 :         m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
     129           0 :         m_pWindow = NULL;
     130             :     }
     131          25 : }
     132             : 
     133             : 
     134             : // XServiceInfo
     135             : 
     136             : 
     137           1 : OUString VCLXAccessibleMenuBar::getImplementationName() throw (RuntimeException, std::exception)
     138             : {
     139           1 :     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           1 : sal_Int32 VCLXAccessibleMenuBar::getAccessibleIndexInParent(  ) throw (RuntimeException, std::exception)
     156             : {
     157           1 :     OExternalLockGuard aGuard( this );
     158             : 
     159           1 :     sal_Int32 nIndexInParent = -1;
     160             : 
     161           1 :     if ( m_pMenu )
     162             :     {
     163           1 :         vcl::Window* pWindow = m_pMenu->GetWindow();
     164           1 :         if ( pWindow )
     165             :         {
     166           1 :             vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
     167           1 :             if ( pParent )
     168             :             {
     169           8 :                 for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
     170             :                 {
     171           7 :                     vcl::Window* pChild = pParent->GetAccessibleChildWindow( --n );
     172           7 :                     if ( pChild == pWindow )
     173             :                     {
     174           1 :                         nIndexInParent = n;
     175           1 :                         break;
     176             :                     }
     177             :                 }
     178             :             }
     179             :         }
     180             :     }
     181             : 
     182           1 :     return nIndexInParent;
     183             : }
     184             : 
     185             : 
     186             : 
     187         157 : sal_Int16 VCLXAccessibleMenuBar::getAccessibleRole(  ) throw (RuntimeException, std::exception)
     188             : {
     189         157 :     OExternalLockGuard aGuard( this );
     190             : 
     191         157 :     return AccessibleRole::MENU_BAR;
     192             : }
     193             : 
     194             : 
     195             : // XAccessibleExtendedComponent
     196             : 
     197             : 
     198           1 : sal_Int32 VCLXAccessibleMenuBar::getBackground(  ) throw (RuntimeException, std::exception)
     199             : {
     200           1 :     OExternalLockGuard aGuard( this );
     201             : 
     202           1 :     return Application::GetSettings().GetStyleSettings().GetMenuBarColor().GetColor();
     203             : }
     204             : 
     205             : 
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11