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

Generated by: LCOV version 1.10