LCOV - code coverage report
Current view: top level - toolkit/source/controls - accessiblecontrolcontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 136 27.2 %
Date: 2015-06-13 12:38:46 Functions: 11 28 39.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 <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          29 :     OAccessibleControlContext::OAccessibleControlContext()
      48          29 :         : OAccessibleControlContext_Base(new VCLExternalSolarLock)
      49             :     {
      50             :         // nothing to do here, we have a late ctor
      51          29 :     }
      52             : 
      53             : 
      54          87 :     OAccessibleControlContext::~OAccessibleControlContext()
      55             :     {
      56          29 :         ensureDisposed();
      57          58 :     }
      58             : 
      59             : 
      60        1073 :     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          29 :     void OAccessibleControlContext::Init( const Reference< XAccessible >& _rxCreator )
      66             :     {
      67          29 :         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          58 :         Reference< awt::XControl > xControl( _rxCreator, UNO_QUERY );
      73          29 :         if ( xControl.is() )
      74          29 :             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          29 :         if ( !m_xControlModel.is() )
      77           0 :             throw DisposedException();  // caught by the caller (the create method)
      78             : 
      79             :         // start listening at the model
      80          29 :         startModelListening();
      81             : 
      82             :         // announce the XAccessible to our base class
      83          58 :         OAccessibleControlContext_Base::lateInit( _rxCreator );
      84          29 :     }
      85             : 
      86             : 
      87          29 :     OAccessibleControlContext* OAccessibleControlContext::create( const Reference< XAccessible >& _rxCreator )
      88             :     {
      89          29 :         OAccessibleControlContext* pNew = NULL;
      90             :         try
      91             :         {
      92          29 :             pNew = new OAccessibleControlContext;
      93          29 :             pNew->Init( _rxCreator );
      94             :         }
      95           0 :         catch( const Exception& )
      96             :         {
      97             :             OSL_FAIL( "OAccessibleControlContext::create: caught an exception from the late ctor!" );
      98             :         }
      99          29 :         return pNew;
     100             :     }
     101             : 
     102             : 
     103          29 :     void OAccessibleControlContext::startModelListening( )
     104             :     {
     105          29 :         Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY );
     106             :         OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::startModelListening: invalid model!" );
     107          29 :         if ( xModelComp.is() )
     108          29 :             xModelComp->addEventListener( this );
     109          29 :     }
     110             : 
     111             : 
     112          29 :     void OAccessibleControlContext::stopModelListening( )
     113             :     {
     114          29 :         Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY );
     115             :         OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::stopModelListening: invalid model!" );
     116          29 :         if ( xModelComp.is() )
     117          29 :             xModelComp->removeEventListener( this );
     118          29 :     }
     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          29 :     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          29 :         stopModelListening( );
     201          29 :         m_xControlModel.clear();
     202          29 :         m_xModelPropsInfo.clear();
     203             : 
     204          29 :         OAccessibleControlContext_Base::disposing();
     205          29 :     }
     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 :     VclPtr< 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 :         VclPtr< vcl::Window > pWindow = xWindow.is() ? VCLUnoHelper::GetWindow( xWindow ) : VclPtr< vcl::Window >();
     236             : 
     237           0 :         if ( _pxUNOWindow )
     238           0 :             *_pxUNOWindow = xWindow;
     239             : 
     240           0 :         return pWindow;
     241             :     }
     242             : 
     243             : 
     244           0 :     awt::Rectangle OAccessibleControlContext::implGetBounds(  ) throw (RuntimeException)
     245             :     {
     246           0 :         SolarMutexGuard aSolarGuard;
     247             :             // want to do some VCL stuff here ...
     248           0 :         OContextEntryGuard aGuard( this );
     249             : 
     250             :         OSL_FAIL( "OAccessibleControlContext::implGetBounds: performance issue: forced to calc the size myself!" );
     251             :         // In design mode (and this is what this class is for), the surrounding shape (if any) should handle this call
     252             :         // The problem is that in design mode, our size may not be correct (in the drawing layer, controls are
     253             :         // positioned/sized for painting only), and that calculation of our position is expensive
     254             : 
     255             :         // what we know (or can obtain from somewhere):
     256             :         // * the PosSize of our peer, relative to its parent window
     257             :         // * the parent window which the PosSize is relative to
     258             :         // * our foreign controlled accessible parent
     259             :         // from this info, we can determine the position of our peer relative to the foreign parent
     260             : 
     261             :         // our control
     262           0 :         Reference< awt::XWindow > xWindow;
     263           0 :         VclPtr< vcl::Window > pVCLWindow = implGetWindow( &xWindow );
     264             : 
     265           0 :         awt::Rectangle aBounds( 0, 0, 0, 0 );
     266           0 :         if ( xWindow.is() )
     267             :         {
     268             :             // ugly, but .... though the XWindow has a getPosSize, it is impossible to determine the
     269             :             // parent which this position/size is relative to. This means we must tunnel UNO and ask the
     270             :             // implementation
     271           0 :             vcl::Window* pVCLParent = pVCLWindow ? pVCLWindow->GetParent() : NULL;
     272             : 
     273             :             // the relative location of the window
     274           0 :             ::Point aWindowRelativePos( 0, 0);
     275           0 :             if ( pVCLWindow )
     276           0 :                 aWindowRelativePos = pVCLWindow->GetPosPixel();
     277             : 
     278             :             // the screnn position of the "window parent" of the control
     279           0 :             ::Point aVCLParentScreenPos( 0, 0 );
     280           0 :             if ( pVCLParent )
     281           0 :                 aVCLParentScreenPos = pVCLParent->GetPosPixel();
     282             : 
     283             :             // the screen position of the "accessible parent" of the control
     284           0 :             Reference< XAccessible > xParentAcc( implGetForeignControlledParent() );
     285           0 :             Reference< XAccessibleComponent > xParentAccComponent;
     286           0 :             if ( xParentAcc.is() )
     287           0 :                 xParentAccComponent.set(xParentAcc->getAccessibleContext(), css::uno::UNO_QUERY);
     288           0 :             awt::Point aAccParentScreenPos( 0, 0 );
     289           0 :             if ( xParentAccComponent.is() )
     290           0 :                 aAccParentScreenPos = xParentAccComponent->getLocationOnScreen();
     291             : 
     292             :             // now the size of the control
     293           0 :             aBounds = xWindow->getPosSize();
     294             : 
     295             :             // correct the pos
     296           0 :             aBounds.X = aWindowRelativePos.X() + aVCLParentScreenPos.X() - aAccParentScreenPos.X;
     297           0 :             aBounds.Y = aWindowRelativePos.Y() + aVCLParentScreenPos.Y() - aAccParentScreenPos.Y;
     298             :         }
     299             : 
     300           0 :         return aBounds;
     301             :     }
     302             : 
     303             : 
     304           0 :     Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleAtPoint( const awt::Point& /* _rPoint */ ) throw (RuntimeException, std::exception)
     305             :     {
     306             :         // no children at all
     307           0 :         return NULL;
     308             :     }
     309             : 
     310             : 
     311           0 :     void SAL_CALL OAccessibleControlContext::grabFocus(  ) throw (RuntimeException, std::exception)
     312             :     {
     313             :         OSL_FAIL( "OAccessibleControlContext::grabFocus: !isFocusTraversable, but grabFocus!" );
     314           0 :     }
     315             : 
     316             : 
     317           0 :     sal_Int32 SAL_CALL OAccessibleControlContext::getForeground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     318             :     {
     319           0 :         SolarMutexGuard aSolarGuard;
     320             :             // want to do some VCL stuff here ...
     321           0 :         OContextEntryGuard aGuard( this );
     322             : 
     323           0 :         VclPtr< vcl::Window > pWindow = implGetWindow();
     324           0 :         sal_Int32 nColor = 0;
     325           0 :         if ( pWindow )
     326             :         {
     327           0 :             if ( pWindow->IsControlForeground() )
     328           0 :                 nColor = pWindow->GetControlForeground().GetColor();
     329             :             else
     330             :             {
     331           0 :                 vcl::Font aFont;
     332           0 :                 if ( pWindow->IsControlFont() )
     333           0 :                     aFont = pWindow->GetControlFont();
     334             :                 else
     335           0 :                     aFont = pWindow->GetFont();
     336           0 :                 nColor = aFont.GetColor().GetColor();
     337             :             }
     338             :         }
     339           0 :         return nColor;
     340             :     }
     341             : 
     342             : 
     343           0 :     sal_Int32 SAL_CALL OAccessibleControlContext::getBackground(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     344             :     {
     345           0 :         SolarMutexGuard aSolarGuard;
     346             :             // want to do some VCL stuff here ...
     347           0 :         OContextEntryGuard aGuard( this );
     348             : 
     349           0 :         VclPtr< vcl::Window > pWindow = implGetWindow();
     350           0 :         sal_Int32 nColor = 0;
     351           0 :         if ( pWindow )
     352             :         {
     353           0 :             if ( pWindow->IsControlBackground() )
     354           0 :                 nColor = pWindow->GetControlBackground().GetColor();
     355             :             else
     356           0 :                 nColor = pWindow->GetBackground().GetColor().GetColor();
     357             :         }
     358             : 
     359           0 :         return nColor;
     360             :     }
     361             : 
     362             : 
     363             : }   //namespace toolkit
     364             : 
     365             : 
     366             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11