LCOV - code coverage report
Current view: top level - toolkit/source/controls - accessiblecontrolcontext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 38 139 27.3 %
Date: 2014-11-03 Functions: 13 31 41.9 %
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 <toolkit/controls/accessiblecontrolcontext.hxx>
      21             : #include <unotools/accessiblestatesethelper.hxx>
      22             : #include <com/sun/star/awt/XControl.hpp>
      23             : #include <com/sun/star/awt/XWindow.hpp>
      24             : #include <vcl/svapp.hxx>
      25             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      26             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      27             : #include <toolkit/helper/vclunohelper.hxx>
      28             : #include <toolkit/helper/externallock.hxx>
      29             : #include <vcl/window.hxx>
      30             : 
      31             : 
      32             : namespace toolkit
      33             : {
      34             : 
      35             : 
      36             :     using ::comphelper::OContextEntryGuard;
      37             :     using namespace ::com::sun::star;
      38             :     using namespace ::com::sun::star::uno;
      39             :     using namespace ::com::sun::star::lang;
      40             :     using namespace ::com::sun::star::beans;
      41             :     using namespace ::com::sun::star::accessibility;
      42             : 
      43             : 
      44             :     //= OAccessibleControlContext
      45             : 
      46             : 
      47          58 :     OAccessibleControlContext::OAccessibleControlContext()
      48          58 :         : OAccessibleControlContext_Base(new VCLExternalSolarLock)
      49             :     {
      50             :         // nothing to do here, we have a late ctor
      51          58 :     }
      52             : 
      53             : 
      54         174 :     OAccessibleControlContext::~OAccessibleControlContext()
      55             :     {
      56          58 :         ensureDisposed();
      57         116 :     }
      58             : 
      59             : 
      60        2146 :     IMPLEMENT_FORWARD_XINTERFACE3( OAccessibleControlContext, OAccessibleControlContext_Base, OAccessibleImplementationAccess, OAccessibleControlContext_IBase )
      61           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER3( OAccessibleControlContext, OAccessibleControlContext_Base, OAccessibleImplementationAccess, OAccessibleControlContext_IBase )
      62             :         // (order matters: the first is the class name, the second is the class doing the ref counting)
      63             : 
      64             : 
      65          58 :     void OAccessibleControlContext::Init( const Reference< XAccessible >& _rxCreator )
      66             :     {
      67          58 :         OContextEntryGuard aGuard( this );
      68             : 
      69             :         // retrieve the model of the control
      70             :         OSL_ENSURE( !m_xControlModel.is(), "OAccessibleControlContext::Init: already know a control model....!???" );
      71             : 
      72         116 :         Reference< awt::XControl > xControl( _rxCreator, UNO_QUERY );
      73          58 :         if ( xControl.is() )
      74          58 :             m_xControlModel.set(xControl->getModel(), css::uno::UNO_QUERY);
      75             :         OSL_ENSURE( m_xControlModel.is(), "OAccessibleControlContext::Init: invalid creator (no control, or control without model!" );
      76          58 :         if ( !m_xControlModel.is() )
      77           0 :             throw DisposedException();  // caught by the caller (the create method)
      78             : 
      79             :         // start listening at the model
      80          58 :         startModelListening();
      81             : 
      82             :         // announce the XAccessible to our base class
      83         116 :         OAccessibleControlContext_Base::lateInit( _rxCreator );
      84          58 :     }
      85             : 
      86             : 
      87          58 :     OAccessibleControlContext* OAccessibleControlContext::create( const Reference< XAccessible >& _rxCreator )
      88             :     {
      89          58 :         OAccessibleControlContext* pNew = NULL;
      90             :         try
      91             :         {
      92          58 :             pNew = new OAccessibleControlContext;
      93          58 :             pNew->Init( _rxCreator );
      94             :         }
      95           0 :         catch( const Exception& )
      96             :         {
      97             :             OSL_FAIL( "OAccessibleControlContext::create: caught an exception from the late ctor!" );
      98             :         }
      99          58 :         return pNew;
     100             :     }
     101             : 
     102             : 
     103          58 :     void OAccessibleControlContext::startModelListening( )
     104             :     {
     105          58 :         Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY );
     106             :         OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::startModelListening: invalid model!" );
     107          58 :         if ( xModelComp.is() )
     108          58 :             xModelComp->addEventListener( this );
     109          58 :     }
     110             : 
     111             : 
     112          58 :     void OAccessibleControlContext::stopModelListening( )
     113             :     {
     114          58 :         Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY );
     115             :         OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::stopModelListening: invalid model!" );
     116          58 :         if ( xModelComp.is() )
     117          58 :             xModelComp->removeEventListener( this );
     118          58 :     }
     119             : 
     120             : 
     121           0 :     sal_Int32 SAL_CALL OAccessibleControlContext::getAccessibleChildCount(  ) throw (RuntimeException, std::exception)
     122             :     {
     123             :         // we do not have children
     124           0 :         return 0;
     125             :     }
     126             : 
     127             : 
     128           0 :     Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleChild( sal_Int32 ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
     129             :     {
     130             :         // we do not have children
     131           0 :         throw IndexOutOfBoundsException();
     132             :     }
     133             : 
     134             : 
     135           0 :     Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleParent(  ) throw (RuntimeException, std::exception)
     136             :     {
     137           0 :         OContextEntryGuard aGuard( this );
     138             :         OSL_ENSURE( implGetForeignControlledParent().is(), "OAccessibleControlContext::getAccessibleParent: somebody forgot to set a parent!" );
     139             :             // this parent of us is foreign controlled - somebody has to set it using the OAccessibleImplementationAccess
     140             :             // class, before integrating our instance into an AccessibleDocumentModel
     141           0 :         return implGetForeignControlledParent();
     142             :     }
     143             : 
     144             : 
     145           0 :     sal_Int16 SAL_CALL OAccessibleControlContext::getAccessibleRole(  ) throw (RuntimeException, std::exception)
     146             :     {
     147           0 :         return AccessibleRole::SHAPE;
     148             :     }
     149             : 
     150             : 
     151           0 :     OUString SAL_CALL OAccessibleControlContext::getAccessibleDescription(  ) throw (RuntimeException, std::exception)
     152             :     {
     153           0 :         OContextEntryGuard aGuard( this );
     154           0 :         return getModelStringProperty( "HelpText" );
     155             :     }
     156             : 
     157             : 
     158           0 :     OUString SAL_CALL OAccessibleControlContext::getAccessibleName(  ) throw (RuntimeException, std::exception)
     159             :     {
     160           0 :         OContextEntryGuard aGuard( this );
     161           0 :         return getModelStringProperty( "Name" );
     162             :     }
     163             : 
     164             : 
     165           0 :     Reference< XAccessibleRelationSet > SAL_CALL OAccessibleControlContext::getAccessibleRelationSet(  ) throw (RuntimeException, std::exception)
     166             :     {
     167           0 :         return NULL;
     168             :     }
     169             : 
     170             : 
     171           0 :     Reference< XAccessibleStateSet > SAL_CALL OAccessibleControlContext::getAccessibleStateSet(  ) throw (RuntimeException, std::exception)
     172             :     {
     173           0 :         ::osl::MutexGuard aGuard( GetMutex() );
     174             :             // no OContextEntryGuard here, as we do not want to throw an exception in case we're not alive anymore
     175             : 
     176           0 :         ::utl::AccessibleStateSetHelper* pStateSet = NULL;
     177           0 :         if ( isAlive() )
     178             :         {
     179             :             // no own states, only the ones which are foreign controlled
     180           0 :             pStateSet = new ::utl::AccessibleStateSetHelper( implGetForeignControlledStates() );
     181             :         }
     182             :         else
     183             :         {   // only the DEFUNC state if we're already disposed
     184           0 :             pStateSet = new ::utl::AccessibleStateSetHelper;
     185           0 :             pStateSet->AddState( AccessibleStateType::DEFUNC );
     186             :         }
     187           0 :         return pStateSet;
     188             :     }
     189             : 
     190             : 
     191          58 :     void SAL_CALL OAccessibleControlContext::disposing( const EventObject&
     192             :     #if OSL_DEBUG_LEVEL > 0
     193             :     _rSource
     194             :     #endif
     195             :     ) throw ( RuntimeException, std::exception )
     196             :     {
     197             :         OSL_ENSURE( Reference< XPropertySet >( _rSource.Source, UNO_QUERY ).get() == m_xControlModel.get(),
     198             :             "OAccessibleControlContext::disposing: where did this come from?" );
     199             : 
     200          58 :         stopModelListening( );
     201          58 :         m_xControlModel.clear();
     202          58 :         m_xModelPropsInfo.clear();
     203             : 
     204          58 :         OAccessibleControlContext_Base::disposing();
     205          58 :     }
     206             : 
     207             : 
     208           0 :     OUString OAccessibleControlContext::getModelStringProperty( const sal_Char* _pPropertyName )
     209             :     {
     210           0 :         OUString sReturn;
     211             :         try
     212             :         {
     213           0 :             if ( !m_xModelPropsInfo.is() && m_xControlModel.is() )
     214           0 :                 m_xModelPropsInfo = m_xControlModel->getPropertySetInfo();
     215             : 
     216           0 :             OUString sPropertyName( OUString::createFromAscii( _pPropertyName ) );
     217           0 :             if ( m_xModelPropsInfo.is() && m_xModelPropsInfo->hasPropertyByName( sPropertyName ) )
     218           0 :                 m_xControlModel->getPropertyValue( sPropertyName ) >>= sReturn;
     219             :         }
     220           0 :         catch( const Exception& )
     221             :         {
     222             :             OSL_FAIL( "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
     223             :         }
     224           0 :         return sReturn;
     225             :     }
     226             : 
     227             : 
     228           0 :     vcl::Window* OAccessibleControlContext::implGetWindow( Reference< awt::XWindow >* _pxUNOWindow ) const
     229             :     {
     230           0 :         Reference< awt::XControl > xControl( getAccessibleCreator(), UNO_QUERY );
     231           0 :         Reference< awt::XWindow > xWindow;
     232           0 :         if ( xControl.is() )
     233           0 :             xWindow.set(xControl->getPeer(), css::uno::UNO_QUERY);
     234             : 
     235           0 :         vcl::Window* pWindow = xWindow.is() ? VCLUnoHelper::GetWindow( xWindow ) : NULL;
     236             : 
     237           0 :         if ( _pxUNOWindow )
     238           0 :             *_pxUNOWindow = xWindow;
     239           0 :         return pWindow;
     240             :     }
     241             : 
     242             : 
     243           0 :     awt::Rectangle OAccessibleControlContext::implGetBounds(  ) throw (RuntimeException)
     244             :     {
     245           0 :         SolarMutexGuard aSolarGuard;
     246             :             // want to do some VCL stuff here ...
     247           0 :         OContextEntryGuard aGuard( this );
     248             : 
     249             :         OSL_FAIL( "OAccessibleControlContext::implGetBounds: performance issue: forced to calc the size myself!" );
     250             :         // In design mode (and this is what this class is for), the surrounding shape (if any) should handle this call
     251             :         // The problem is that in design mode, our size may not be correct (in the drawing layer, controls are
     252             :         // positioned/sized for painting only), and that calculation of our position is expensive
     253             : 
     254             :         // what we know (or can obtain from somewhere):
     255             :         // * the PosSize of our peer, relative to its parent window
     256             :         // * the parent window which the PosSize is relative to
     257             :         // * our foreign controlled accessible parent
     258             :         // from this info, we can determine the position of our peer relative to the foreign parent
     259             : 
     260             :         // our control
     261           0 :         Reference< awt::XWindow > xWindow;
     262           0 :         vcl::Window* pVCLWindow = implGetWindow( &xWindow );
     263             : 
     264           0 :         awt::Rectangle aBounds( 0, 0, 0, 0 );
     265           0 :         if ( xWindow.is() )
     266             :         {
     267             :             // ugly, but .... though the XWindow has a getPosSize, it is impossible to determine the
     268             :             // parent which this position/size is relative to. This means we must tunnel UNO and ask the
     269             :             // implementation
     270           0 :             vcl::Window* pVCLParent = pVCLWindow ? pVCLWindow->GetParent() : NULL;
     271             : 
     272             :             // the relative location of the window
     273           0 :             ::Point aWindowRelativePos( 0, 0);
     274           0 :             if ( pVCLWindow )
     275           0 :                 aWindowRelativePos = pVCLWindow->GetPosPixel();
     276             : 
     277             :             // the screnn position of the "window parent" of the control
     278           0 :             ::Point aVCLParentScreenPos( 0, 0 );
     279           0 :             if ( pVCLParent )
     280           0 :                 aVCLParentScreenPos = pVCLParent->GetPosPixel();
     281             : 
     282             :             // the screen position of the "accessible parent" of the control
     283           0 :             Reference< XAccessible > xParentAcc( implGetForeignControlledParent() );
     284           0 :             Reference< XAccessibleComponent > xParentAccComponent;
     285           0 :             if ( xParentAcc.is() )
     286           0 :                 xParentAccComponent.set(xParentAcc->getAccessibleContext(), css::uno::UNO_QUERY);
     287           0 :             awt::Point aAccParentScreenPos( 0, 0 );
     288           0 :             if ( xParentAccComponent.is() )
     289           0 :                 aAccParentScreenPos = xParentAccComponent->getLocationOnScreen();
     290             : 
     291             :             // now the size of the control
     292           0 :             aBounds = xWindow->getPosSize();
     293             : 
     294             :             // correct the pos
     295           0 :             aBounds.X = aWindowRelativePos.X() + aVCLParentScreenPos.X() - aAccParentScreenPos.X;
     296           0 :             aBounds.Y = aWindowRelativePos.Y() + aVCLParentScreenPos.Y() - aAccParentScreenPos.Y;
     297             :         }
     298             : 
     299           0 :         return aBounds;
     300             :     }
     301             : 
     302             : 
     303           0 :     Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleAtPoint( const awt::Point& /* _rPoint */ ) throw (RuntimeException, std::exception)
     304             :     {
     305             :         // no children at all
     306           0 :         return NULL;
     307             :     }
     308             : 
     309             : 
     310           0 :     void SAL_CALL OAccessibleControlContext::grabFocus(  ) throw (RuntimeException, std::exception)
     311             :     {
     312             :         OSL_FAIL( "OAccessibleControlContext::grabFocus: !isFocusTraversable, but grabFocus!" );
     313           0 :     }
     314             : 
     315             : 
     316           0 :     Any SAL_CALL OAccessibleControlContext::getAccessibleKeyBinding(  ) throw (RuntimeException)
     317             :     {
     318             :         // we do not have any key bindings to activate a UNO control in design mode
     319           0 :         return Any();
     320             :     }
     321             : 
     322             : 
     323           0 :     sal_Int32 SAL_CALL OAccessibleControlContext::getForeground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     324             :     {
     325           0 :         SolarMutexGuard aSolarGuard;
     326             :             // want to do some VCL stuff here ...
     327           0 :         OContextEntryGuard aGuard( this );
     328             : 
     329           0 :         vcl::Window* pWindow = implGetWindow( );
     330           0 :         sal_Int32 nColor = 0;
     331           0 :         if ( pWindow )
     332             :         {
     333           0 :             if ( pWindow->IsControlForeground() )
     334           0 :                 nColor = pWindow->GetControlForeground().GetColor();
     335             :             else
     336             :             {
     337           0 :                 vcl::Font aFont;
     338           0 :                 if ( pWindow->IsControlFont() )
     339           0 :                     aFont = pWindow->GetControlFont();
     340             :                 else
     341           0 :                     aFont = pWindow->GetFont();
     342           0 :                 nColor = aFont.GetColor().GetColor();
     343             :             }
     344             :         }
     345           0 :         return nColor;
     346             :     }
     347             : 
     348             : 
     349           0 :     sal_Int32 SAL_CALL OAccessibleControlContext::getBackground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     350             :     {
     351           0 :         SolarMutexGuard aSolarGuard;
     352             :             // want to do some VCL stuff here ...
     353           0 :         OContextEntryGuard aGuard( this );
     354             : 
     355           0 :         vcl::Window* pWindow = implGetWindow( );
     356           0 :         sal_Int32 nColor = 0;
     357           0 :         if ( pWindow )
     358             :         {
     359           0 :             if ( pWindow->IsControlBackground() )
     360           0 :                 nColor = pWindow->GetControlBackground().GetColor();
     361             :             else
     362           0 :                 nColor = pWindow->GetBackground().GetColor().GetColor();
     363             :         }
     364             : 
     365           0 :         return nColor;
     366             :     }
     367             : 
     368             : 
     369        1227 : }   //namespace toolkit
     370             : 
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10