LCOV - code coverage report
Current view: top level - svx/source/accessibility - GraphCtlAccessibleContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 372 0.3 %
Date: 2014-11-03 Functions: 2 58 3.4 %
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 <com/sun/star/accessibility/AccessibleRole.hpp>
      21             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      22             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      23             : #include <com/sun/star/lang/DisposedException.hpp>
      24             : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
      25             : #include <com/sun/star/awt/XWindow.hpp>
      26             : #include <unotools/accessiblestatesethelper.hxx>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : #include <cppuhelper/typeprovider.hxx>
      29             : #include <toolkit/helper/vclunohelper.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : #include <vcl/settings.hxx>
      32             : #include <osl/mutex.hxx>
      33             : #include <tools/gen.hxx>
      34             : #include <svl/smplhint.hxx>
      35             : #include <toolkit/helper/convert.hxx>
      36             : #include <svtools/colorcfg.hxx>
      37             : #include <comphelper/accessibleeventnotifier.hxx>
      38             : #include <svx/sdrpaintwindow.hxx>
      39             : 
      40             : #include <svx/ShapeTypeHandler.hxx>
      41             : #include <svx/AccessibleShapeInfo.hxx>
      42             : #include "GraphCtlAccessibleContext.hxx"
      43             : #include <svx/graphctl.hxx>
      44             : #include <svx/dialogs.hrc>
      45             : #include "accessibility.hrc"
      46             : #include <svx/svdpage.hxx>
      47             : #include <svx/unomod.hxx>
      48             : #include <svx/dialmgr.hxx>
      49             : #include <svx/svdetc.hxx>
      50             : #include <svx/sdrhittesthelper.hxx>
      51             : 
      52             : // namespaces
      53             : using namespace ::cppu;
      54             : using namespace ::osl;
      55             : using namespace ::accessibility;
      56             : using namespace ::com::sun::star;
      57             : using namespace ::com::sun::star::uno;
      58             : using namespace ::com::sun::star::drawing;
      59             : using namespace ::com::sun::star::lang;
      60             : using namespace ::com::sun::star::accessibility;
      61             : 
      62             : // internal
      63             : /** initialize this component and set default values */
      64           0 : SvxGraphCtrlAccessibleContext::SvxGraphCtrlAccessibleContext(
      65             :     const Reference< XAccessible >& rxParent,
      66             :     GraphCtrl&                              rRepr,
      67             :     const OUString*                         pName,
      68             :     const OUString*                         pDesc ) :
      69             : 
      70             :     SvxGraphCtrlAccessibleContext_Base( m_aMutex ),
      71             :     mxParent( rxParent ),
      72             :     mpControl( &rRepr ),
      73             :     mpModel (NULL),
      74             :     mpPage (NULL),
      75             :     mpView (NULL),
      76             :     mnClientId( 0 ),
      77           0 :     mbDisposed( false )
      78             : {
      79           0 :     if (mpControl != NULL)
      80             :     {
      81           0 :         mpModel = mpControl->GetSdrModel();
      82           0 :         if (mpModel != NULL)
      83           0 :             mpPage = (SdrPage*)mpModel->GetPage( 0 );
      84           0 :         mpView = mpControl->GetSdrView();
      85             : 
      86           0 :         if( mpModel == NULL || mpPage == NULL || mpView == NULL )
      87             :         {
      88           0 :             mbDisposed = true;
      89             :             // Set all the pointers to NULL just in case they are used as
      90             :             // a disposed flag.
      91           0 :             mpModel = NULL;
      92           0 :             mpPage = NULL;
      93           0 :             mpView = NULL;
      94             :         }
      95             :     }
      96             : 
      97           0 :     if( pName )
      98             :     {
      99           0 :         msName = *pName;
     100             :     }
     101             :     else
     102             :     {
     103           0 :         ::SolarMutexGuard aSolarGuard;
     104           0 :         msName = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_NAME );
     105             :     }
     106             : 
     107           0 :     if( pDesc )
     108             :     {
     109           0 :         msDescription = *pDesc;
     110             :     }
     111             :     else
     112             :     {
     113           0 :         ::SolarMutexGuard aSolarGuard;
     114           0 :         msDescription = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_DESCRIPTION );
     115             :     }
     116             : 
     117           0 :     maTreeInfo.SetSdrView( mpView );
     118           0 :     maTreeInfo.SetWindow( mpControl );
     119           0 :     maTreeInfo.SetViewForwarder( const_cast<SvxGraphCtrlAccessibleContext*>(this) );
     120           0 : }
     121             : 
     122             : 
     123             : 
     124             : /** on destruction, this component is disposed and all dispose listeners
     125             :     are called, except if this component was already disposed */
     126           0 : SvxGraphCtrlAccessibleContext::~SvxGraphCtrlAccessibleContext()
     127             : {
     128           0 :     disposing();
     129           0 : }
     130             : 
     131             : 
     132             : 
     133             : /** returns the XAccessible interface for a given SdrObject.
     134             :     Multiple calls for the same SdrObject return the same XAccessible.
     135             : */
     136           0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessible( const SdrObject* pObj )
     137             : {
     138           0 :     Reference<XAccessible> xAccessibleShape;
     139             : 
     140           0 :     if( pObj )
     141             :     {
     142             :         // see if we already created an XAccessible for the given SdrObject
     143           0 :         ShapesMapType::iterator iter = mxShapes.find( pObj );
     144             : 
     145           0 :         if( iter != mxShapes.end() )
     146             :         {
     147             :             // if we already have one, return it
     148           0 :             xAccessibleShape = (*iter).second;
     149             :         }
     150             :         else
     151             :         {
     152             :             // create a new one and remember in our internal map
     153           0 :             Reference< XShape > xShape( Reference< XShape >::query( (const_cast<SdrObject*>(pObj))->getUnoShape() ) );
     154             : 
     155           0 :             AccessibleShapeInfo aShapeInfo (xShape,mxParent);
     156             :             // Create accessible object that corresponds to the descriptor's shape.
     157           0 :             AccessibleShape* pAcc = ShapeTypeHandler::Instance().CreateAccessibleObject(
     158           0 :                 aShapeInfo, maTreeInfo);
     159           0 :             xAccessibleShape = pAcc;
     160           0 :             if (pAcc != NULL)
     161             :             {
     162           0 :                 pAcc->acquire();
     163             :                 // Now that we acquired the new accessible shape we can
     164             :                 // safely call its Init() method.
     165           0 :                 pAcc->Init ();
     166             :             }
     167           0 :             mxShapes[pObj] = pAcc;
     168             : 
     169             :             // Create event and inform listeners of the object creation.
     170           0 :             CommitChange( AccessibleEventId::CHILD, makeAny( xAccessibleShape ), makeAny( Reference<XAccessible>() ) );
     171             :         }
     172             :     }
     173             : 
     174           0 :     return xAccessibleShape;
     175             : }
     176             : 
     177             : // XAccessible
     178           0 : Reference< XAccessibleContext > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleContext( void ) throw( RuntimeException, std::exception )
     179             : {
     180           0 :     return this;
     181             : }
     182             : 
     183             : // XAccessibleComponent
     184           0 : sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::containsPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
     185             : {
     186             :     // no guard -> done in getSize()
     187           0 :     awt::Size aSize (getSize());
     188           0 :     return (rPoint.X >= 0)
     189           0 :         && (rPoint.X < aSize.Width)
     190           0 :         && (rPoint.Y >= 0)
     191           0 :         && (rPoint.Y < aSize.Height);
     192             : }
     193             : 
     194             : 
     195             : 
     196           0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleAtPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
     197             : {
     198           0 :     ::osl::MutexGuard   aGuard( m_aMutex );
     199             : 
     200           0 :     Reference< XAccessible > xAccessible;
     201             : 
     202           0 :     if( mpControl )
     203             :     {
     204           0 :         Point aPnt( rPoint.X, rPoint.Y );
     205           0 :         mpControl->PixelToLogic( aPnt );
     206             : 
     207           0 :         SdrObject* pObj = 0;
     208             : 
     209           0 :         if(mpView && mpView->GetSdrPageView())
     210             :         {
     211           0 :             pObj = SdrObjListPrimitiveHit(*mpPage, aPnt, 1, *mpView->GetSdrPageView(), 0, false);
     212             :         }
     213             : 
     214           0 :         if( pObj )
     215           0 :             xAccessible = getAccessible( pObj );
     216             :     }
     217             :     else
     218             :     {
     219           0 :         throw DisposedException();
     220             :     }
     221             : 
     222           0 :     return xAccessible;
     223             : }
     224             : 
     225             : 
     226             : 
     227           0 : awt::Rectangle SAL_CALL SvxGraphCtrlAccessibleContext::getBounds() throw( RuntimeException, std::exception )
     228             : {
     229             :     // no guard -> done in GetBoundingBox()
     230           0 :     Rectangle           aCoreBounds( GetBoundingBox() );
     231           0 :     awt::Rectangle      aBounds;
     232           0 :     aBounds.X = aCoreBounds.getX();
     233           0 :     aBounds.Y = aCoreBounds.getY();
     234           0 :     aBounds.Width = aCoreBounds.getWidth();
     235           0 :     aBounds.Height = aCoreBounds.getHeight();
     236           0 :     return aBounds;
     237             : }
     238             : 
     239             : 
     240             : 
     241           0 : awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocation() throw( RuntimeException, std::exception )
     242             : {
     243             :     // no guard -> done in GetBoundingBox()
     244           0 :     Rectangle   aRect( GetBoundingBox() );
     245           0 :     return awt::Point( aRect.getX(), aRect.getY() );
     246             : }
     247             : 
     248             : 
     249             : 
     250           0 : awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocationOnScreen() throw( RuntimeException, std::exception )
     251             : {
     252             :     // no guard -> done in GetBoundingBoxOnScreen()
     253           0 :     Rectangle   aRect( GetBoundingBoxOnScreen() );
     254           0 :     return awt::Point( aRect.getX(), aRect.getY() );
     255             : }
     256             : 
     257             : 
     258             : 
     259           0 : awt::Size SAL_CALL SvxGraphCtrlAccessibleContext::getSize() throw( RuntimeException, std::exception )
     260             : {
     261             :     // no guard -> done in GetBoundingBox()
     262           0 :     Rectangle   aRect( GetBoundingBox() );
     263           0 :     return awt::Size( aRect.getWidth(), aRect.getHeight() );
     264             : }
     265             : 
     266             : // XAccessibleContext
     267           0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChildCount( void ) throw( RuntimeException, std::exception )
     268             : {
     269           0 :     ::SolarMutexGuard aGuard;
     270             : 
     271           0 :     if( NULL == mpPage )
     272           0 :         throw DisposedException();
     273             : 
     274           0 :     return mpPage->GetObjCount();
     275             : }
     276             : 
     277             : 
     278             : 
     279             : /** returns the SdrObject at index nIndex from the model of this graph */
     280           0 : SdrObject* SvxGraphCtrlAccessibleContext::getSdrObject( sal_Int32 nIndex )
     281             :     throw( RuntimeException, lang::IndexOutOfBoundsException )
     282             : {
     283           0 :     ::SolarMutexGuard aGuard;
     284             : 
     285           0 :     if( NULL == mpPage )
     286           0 :         throw DisposedException();
     287             : 
     288           0 :     if( (nIndex < 0) || ( static_cast<size_t>(nIndex) >= mpPage->GetObjCount() ) )
     289           0 :         throw lang::IndexOutOfBoundsException();
     290             : 
     291           0 :     return mpPage->GetObj( nIndex );
     292             : }
     293             : 
     294             : 
     295             : 
     296             : /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
     297           0 : void SvxGraphCtrlAccessibleContext::CommitChange (
     298             :     sal_Int16 nEventId,
     299             :     const uno::Any& rNewValue,
     300             :     const uno::Any& rOldValue)
     301             : {
     302             :     AccessibleEventObject aEvent (
     303             :         static_cast<uno::XWeak*>(this),
     304             :         nEventId,
     305             :         rNewValue,
     306           0 :         rOldValue);
     307             : 
     308           0 :     FireEvent (aEvent);
     309           0 : }
     310             : 
     311             : /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
     312           0 : void SvxGraphCtrlAccessibleContext::FireEvent (const AccessibleEventObject& aEvent)
     313             : {
     314           0 :     if (mnClientId)
     315           0 :         comphelper::AccessibleEventNotifier::addEvent( mnClientId, aEvent );
     316           0 : }
     317             : 
     318             : 
     319             : 
     320           0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChild( sal_Int32 nIndex )
     321             :     throw( RuntimeException, lang::IndexOutOfBoundsException, std::exception )
     322             : {
     323           0 :     ::SolarMutexGuard aGuard;
     324             : 
     325           0 :     return getAccessible( getSdrObject( nIndex ) );
     326             : }
     327             : 
     328             : 
     329             : 
     330           0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleParent( void ) throw( RuntimeException, std::exception )
     331             : {
     332           0 :     return mxParent;
     333             : }
     334             : 
     335             : 
     336             : 
     337           0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleIndexInParent( void ) throw( RuntimeException, std::exception )
     338             : {
     339           0 :     ::SolarMutexGuard aGuard;
     340             :     //  Use a simple but slow solution for now.  Optimize later.
     341             : 
     342             :     //  Iterate over all the parent's children and search for this object.
     343           0 :     if( mxParent.is() )
     344             :     {
     345           0 :         Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
     346           0 :         if( xParentContext.is() )
     347             :         {
     348           0 :             sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
     349           0 :             for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
     350             :             {
     351           0 :                 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
     352           0 :                 if( xChild.is() )
     353             :                 {
     354           0 :                     Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
     355           0 :                     if( xChildContext == ( XAccessibleContext* ) this )
     356           0 :                         return i;
     357             :                 }
     358           0 :             }
     359           0 :         }
     360             :    }
     361             : 
     362             :    //   Return -1 to indicate that this object's parent does not know about the
     363             :    //   object.
     364           0 :    return -1;
     365             : }
     366             : 
     367             : 
     368             : 
     369           0 : sal_Int16 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRole( void ) throw( RuntimeException, std::exception )
     370             : {
     371           0 :     return AccessibleRole::PANEL;
     372             : }
     373             : 
     374             : 
     375             : 
     376           0 : OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleDescription( void ) throw( RuntimeException, std::exception )
     377             : {
     378           0 :     ::SolarMutexGuard aGuard;
     379           0 :     return msDescription;
     380             : }
     381             : 
     382             : 
     383             : 
     384           0 : OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleName( void ) throw( RuntimeException, std::exception )
     385             : {
     386           0 :     ::SolarMutexGuard aGuard;
     387           0 :     return msName;
     388             : }
     389             : 
     390             : 
     391             : 
     392             : /** Return empty reference to indicate that the relation set is not
     393             :     supported.
     394             : */
     395           0 : Reference< XAccessibleRelationSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRelationSet( void ) throw( RuntimeException, std::exception )
     396             : {
     397           0 :     return Reference< XAccessibleRelationSet >();
     398             : }
     399             : 
     400             : 
     401             : 
     402           0 : Reference< XAccessibleStateSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleStateSet( void ) throw( RuntimeException, std::exception )
     403             : {
     404           0 :     ::SolarMutexGuard aGuard;
     405             : 
     406           0 :     utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
     407             : 
     408           0 :     if ( rBHelper.bDisposed || mbDisposed )
     409             :     {
     410           0 :         pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
     411             :     }
     412             :     else
     413             :     {
     414           0 :         pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
     415           0 :         if( mpControl->HasFocus() )
     416           0 :             pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
     417           0 :         pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
     418           0 :         pStateSetHelper->AddState( AccessibleStateType::SHOWING );
     419           0 :         pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
     420             :     }
     421             : 
     422           0 :     return pStateSetHelper;
     423             : }
     424             : 
     425             : 
     426             : 
     427           0 : lang::Locale SAL_CALL SvxGraphCtrlAccessibleContext::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException, std::exception )
     428             : {
     429           0 :     ::SolarMutexGuard aGuard;
     430             : 
     431           0 :     if( mxParent.is() )
     432             :     {
     433           0 :         Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
     434           0 :         if( xParentContext.is() )
     435           0 :             return xParentContext->getLocale();
     436             :     }
     437             : 
     438             :     //  No parent.  Therefore throw exception to indicate this cluelessness.
     439           0 :     throw IllegalAccessibleComponentStateException();
     440             : }
     441             : 
     442             : // XAccessibleEventListener
     443           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
     444             :     throw( RuntimeException, std::exception )
     445             : {
     446           0 :     if (xListener.is())
     447             :     {
     448           0 :         ::SolarMutexGuard aGuard;
     449           0 :         if (!mnClientId)
     450           0 :             mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
     451           0 :         comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
     452             :     }
     453           0 : }
     454             : 
     455             : 
     456             : 
     457           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
     458             :     throw( RuntimeException, std::exception )
     459             : {
     460           0 :     if (xListener.is())
     461             :     {
     462           0 :         ::SolarMutexGuard aGuard;
     463             : 
     464           0 :         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
     465           0 :         if ( !nListenerCount )
     466             :         {
     467             :             // no listeners anymore
     468             :             // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
     469             :             // and at least to us not firing any events anymore, in case somebody calls
     470             :             // NotifyAccessibleEvent, again
     471           0 :             comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
     472           0 :             mnClientId = 0;
     473           0 :         }
     474             :     }
     475           0 : }
     476             : 
     477             : 
     478             : 
     479           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::addFocusListener( const Reference< awt::XFocusListener >& xListener )
     480             :     throw( RuntimeException )
     481             : {
     482           0 :     ::SolarMutexGuard aGuard;
     483             : 
     484           0 :     if( xListener.is() )
     485             :     {
     486           0 :         Reference< ::com::sun::star::awt::XWindow > xWindow( VCLUnoHelper::GetInterface( mpControl ) );
     487           0 :         if( xWindow.is() )
     488           0 :             xWindow->addFocusListener( xListener );
     489           0 :     }
     490           0 : }
     491             : 
     492             : 
     493             : 
     494           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::removeFocusListener( const Reference< awt::XFocusListener >& xListener )
     495             :     throw (RuntimeException)
     496             : {
     497           0 :     ::SolarMutexGuard aGuard;
     498             : 
     499           0 :     if( xListener.is() )
     500             :     {
     501           0 :         Reference< ::com::sun::star::awt::XWindow > xWindow = VCLUnoHelper::GetInterface( mpControl );
     502           0 :         if( xWindow.is() )
     503           0 :             xWindow->removeFocusListener( xListener );
     504           0 :     }
     505           0 : }
     506             : 
     507             : 
     508             : 
     509           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::grabFocus() throw( RuntimeException, std::exception )
     510             : {
     511           0 :     ::SolarMutexGuard aGuard;
     512             : 
     513           0 :     if( NULL == mpControl )
     514           0 :         throw DisposedException();
     515             : 
     516           0 :     mpControl->GrabFocus();
     517           0 : }
     518             : 
     519             : 
     520             : 
     521           0 : Any SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleKeyBinding() throw( RuntimeException )
     522             : {
     523             :     // here is no implementation, because here are no KeyBindings for every object
     524           0 :     return Any();
     525             : }
     526             : 
     527             : 
     528             : 
     529             : 
     530             : 
     531           0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getForeground (void)
     532             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     533             : {
     534           0 :     svtools::ColorConfig aColorConfig;
     535           0 :     sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
     536           0 :     return static_cast<sal_Int32>(nColor);
     537             : }
     538             : 
     539             : 
     540             : 
     541             : 
     542           0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getBackground (void)
     543             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     544             : {
     545           0 :     sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
     546           0 :     return static_cast<sal_Int32>(nColor);
     547             : }
     548             : 
     549             : // XServiceInfo
     550           0 : OUString SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationName( void ) throw( RuntimeException, std::exception )
     551             : {
     552           0 :     return OUString( "com.sun.star.comp.ui.SvxGraphCtrlAccessibleContext" );
     553             : }
     554             : 
     555           0 : sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::supportsService( const OUString& sServiceName ) throw( RuntimeException, std::exception )
     556             : {
     557           0 :     return cppu::supportsService(this, sServiceName);
     558             : }
     559             : 
     560           0 : Sequence< OUString > SAL_CALL SvxGraphCtrlAccessibleContext::getSupportedServiceNames( void ) throw( RuntimeException, std::exception )
     561             : {
     562           0 :     Sequence< OUString > aSNs( 3 );
     563             : 
     564           0 :     aSNs[0] = "com.sun.star.accessibility.Accessible";
     565           0 :     aSNs[1] = "com.sun.star.accessibility.AccessibleContext";
     566           0 :     aSNs[2] = "com.sun.star.drawing.AccessibleGraphControl";
     567             : 
     568           0 :     return aSNs;
     569             : }
     570             : 
     571             : // XTypeProvider
     572           0 : Sequence<sal_Int8> SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationId( void ) throw( RuntimeException, std::exception )
     573             : {
     574           0 :     return css::uno::Sequence<sal_Int8>();
     575             : }
     576             : 
     577             : // XServiceName
     578           0 : OUString SvxGraphCtrlAccessibleContext::getServiceName( void ) throw( RuntimeException, std::exception )
     579             : {
     580           0 :     return OUString( "com.sun.star.accessibility.AccessibleContext" );
     581             : }
     582             : 
     583             : // XAccessibleSelection
     584           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::selectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
     585             : {
     586           0 :     ::SolarMutexGuard aGuard;
     587             : 
     588           0 :     if( NULL == mpView )
     589           0 :         throw DisposedException();
     590             : 
     591           0 :     SdrObject* pObj = getSdrObject( nIndex );
     592             : 
     593           0 :     if( pObj )
     594           0 :         mpView->MarkObj( pObj, mpView->GetSdrPageView());
     595           0 : }
     596             : 
     597             : 
     598             : 
     599           0 : sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::isAccessibleChildSelected( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
     600             : {
     601           0 :     ::SolarMutexGuard aGuard;
     602             : 
     603           0 :     if( NULL == mpView )
     604           0 :         throw DisposedException();
     605             : 
     606           0 :     return mpView->IsObjMarked( getSdrObject( nIndex ) );
     607             : }
     608             : 
     609             : 
     610             : 
     611           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::clearAccessibleSelection() throw( RuntimeException, std::exception )
     612             : {
     613           0 :     ::SolarMutexGuard aGuard;
     614             : 
     615           0 :     if( NULL == mpView )
     616           0 :         throw DisposedException();
     617             : 
     618           0 :     mpView->UnmarkAllObj();
     619           0 : }
     620             : 
     621             : 
     622             : 
     623           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::selectAllAccessibleChildren() throw( RuntimeException, std::exception )
     624             : {
     625           0 :     ::SolarMutexGuard aGuard;
     626             : 
     627           0 :     if( NULL == mpView )
     628           0 :         throw DisposedException();
     629             : 
     630           0 :     mpView->MarkAllObj();
     631           0 : }
     632             : 
     633             : 
     634             : 
     635           0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChildCount() throw( RuntimeException, std::exception )
     636             : {
     637           0 :     ::SolarMutexGuard aGuard;
     638             : 
     639           0 :     if( NULL == mpView )
     640           0 :         throw DisposedException();
     641             : 
     642           0 :     const SdrMarkList& rList = mpView->GetMarkedObjectList();
     643           0 :     return static_cast<sal_Int32>(rList.GetMarkCount());
     644             : }
     645             : 
     646             : 
     647             : 
     648           0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChild( sal_Int32 nIndex )
     649             :     throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
     650             : {
     651           0 :     ::SolarMutexGuard aGuard;
     652             : 
     653           0 :     checkChildIndexOnSelection( nIndex );
     654             : 
     655           0 :     Reference< XAccessible > xAccessible;
     656             : 
     657           0 :     const SdrMarkList& rList = mpView->GetMarkedObjectList();
     658           0 :     SdrObject* pObj = rList.GetMark(static_cast<size_t>(nIndex))->GetMarkedSdrObj();
     659           0 :     if( pObj )
     660           0 :         xAccessible = getAccessible( pObj );
     661             : 
     662           0 :     return xAccessible;
     663             : }
     664             : 
     665             : 
     666             : 
     667           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::deselectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
     668             : {
     669           0 :     ::SolarMutexGuard aGuard;
     670             : 
     671           0 :     checkChildIndexOnSelection( nIndex );
     672             : 
     673           0 :     if( mpView )
     674             :     {
     675           0 :         const SdrMarkList& rList = mpView->GetMarkedObjectList();
     676             : 
     677           0 :         SdrObject* pObj = getSdrObject( nIndex );
     678           0 :         if( pObj )
     679             :         {
     680           0 :             SdrMarkList aRefList( rList );
     681             : 
     682           0 :             SdrPageView* pPV = mpView->GetSdrPageView();
     683           0 :             mpView->UnmarkAllObj( pPV );
     684             : 
     685           0 :             const size_t nCount = aRefList.GetMarkCount();
     686           0 :             for( size_t nMark = 0; nMark < nCount; ++nMark )
     687             :             {
     688           0 :                 if( aRefList.GetMark(nMark)->GetMarkedSdrObj() != pObj )
     689           0 :                     mpView->MarkObj( aRefList.GetMark(nMark)->GetMarkedSdrObj(), pPV );
     690           0 :             }
     691             :         }
     692           0 :     }
     693           0 : }
     694             : 
     695             : // internals
     696           0 : void SvxGraphCtrlAccessibleContext::checkChildIndexOnSelection( long nIndex ) throw( lang::IndexOutOfBoundsException )
     697             : {
     698           0 :     if( nIndex < 0 || nIndex >= getSelectedAccessibleChildCount() )
     699           0 :         throw lang::IndexOutOfBoundsException();
     700           0 : }
     701             : 
     702             : 
     703             : 
     704             : /** Replace the model, page, and view pointers by the ones provided
     705             :     (explicitly and implicitly).
     706             : */
     707           0 : void SvxGraphCtrlAccessibleContext::setModelAndView (
     708             :     SdrModel* pModel,
     709             :     SdrView* pView)
     710             : {
     711           0 :     ::SolarMutexGuard aGuard;
     712             : 
     713           0 :     mpModel = pModel;
     714           0 :     if (mpModel != NULL)
     715           0 :         mpPage = (SdrPage*)mpModel->GetPage( 0 );
     716           0 :     mpView = pView;
     717             : 
     718           0 :     if (mpModel == NULL || mpPage == NULL || mpView == NULL)
     719             :     {
     720           0 :         mbDisposed = true;
     721             : 
     722             :         // Set all the pointers to NULL just in case they are used as
     723             :         // a disposed flag.
     724           0 :         mpModel = NULL;
     725           0 :         mpPage = NULL;
     726           0 :         mpView = NULL;
     727             :     }
     728             : 
     729           0 :     maTreeInfo.SetSdrView (mpView);
     730           0 : }
     731             : 
     732             : 
     733             : 
     734             : 
     735             : 
     736           0 : void SAL_CALL SvxGraphCtrlAccessibleContext::disposing()
     737             : {
     738           0 :     ::SolarMutexGuard aGuard;
     739             : 
     740           0 :     if( mbDisposed )
     741           0 :         return;
     742             : 
     743           0 :     mbDisposed = true;
     744             : 
     745           0 :     mpControl = NULL;       // object dies with representation
     746           0 :     mpView = NULL;
     747           0 :     mpPage = NULL;
     748             : 
     749             :     {
     750           0 :         ShapesMapType::iterator I;
     751             : 
     752           0 :         for (I=mxShapes.begin(); I!=mxShapes.end(); ++I)
     753             :         {
     754           0 :             XAccessible* pAcc = (*I).second;
     755           0 :             Reference< XComponent > xComp( pAcc, UNO_QUERY );
     756           0 :             if( xComp.is() )
     757           0 :                 xComp->dispose();
     758             : 
     759           0 :             (*I).second->release();
     760           0 :         }
     761             : 
     762           0 :         mxShapes.clear();
     763             :     }
     764             : 
     765             :     // Send a disposing to all listeners.
     766           0 :     if ( mnClientId )
     767             :     {
     768           0 :         comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
     769           0 :         mnClientId =  0;
     770           0 :     }
     771             : }
     772             : 
     773             : 
     774             : 
     775           0 : Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
     776             : {
     777           0 :     ::SolarMutexGuard aGuard;
     778             : 
     779           0 :     if( NULL == mpControl )
     780           0 :         throw DisposedException();
     781             : 
     782             :     return Rectangle(
     783             :         mpControl->GetAccessibleParentWindow()->OutputToAbsoluteScreenPixel(
     784           0 :             mpControl->GetPosPixel() ),
     785           0 :         mpControl->GetSizePixel() );
     786             : }
     787             : 
     788             : 
     789             : 
     790             : /** Calculate the relative coordinates of the bounding box as difference
     791             :     between the absolute coordinates of the bounding boxes of this control
     792             :     and its parent in the accessibility tree.
     793             : */
     794           0 : Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBox( void ) throw( RuntimeException )
     795             : {
     796           0 :     ::SolarMutexGuard aGuard;
     797             : 
     798           0 :     Rectangle aBounds ( 0, 0, 0, 0 );
     799             : 
     800           0 :     vcl::Window* pWindow = mpControl;
     801           0 :     if (pWindow != NULL)
     802             :     {
     803           0 :         aBounds = pWindow->GetWindowExtentsRelative (NULL);
     804           0 :         vcl::Window* pParent = pWindow->GetAccessibleParentWindow();
     805           0 :         if (pParent != NULL)
     806             :         {
     807           0 :             Rectangle aParentRect = pParent->GetWindowExtentsRelative (NULL);
     808           0 :             aBounds -= aParentRect.TopLeft();
     809             :         }
     810             :     }
     811             :     else
     812           0 :         throw DisposedException();
     813             : 
     814           0 :     return aBounds;
     815             : }
     816             : 
     817           0 : void SvxGraphCtrlAccessibleContext::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
     818             : {
     819           0 :     const SdrHint* pSdrHint = dynamic_cast<const SdrHint*>( &rHint );
     820             : 
     821           0 :     if( pSdrHint )
     822             :     {
     823           0 :         switch( pSdrHint->GetKind() )
     824             :         {
     825             :             case HINT_OBJCHG:
     826             :                 {
     827           0 :                     ShapesMapType::iterator iter = mxShapes.find( pSdrHint->GetObject() );
     828             : 
     829           0 :                     if( iter != mxShapes.end() )
     830             :                     {
     831             :                         // if we already have one, return it
     832           0 :                         AccessibleShape* pShape = (*iter).second;
     833             : 
     834           0 :                         if( NULL != pShape )
     835           0 :                             pShape->CommitChange( AccessibleEventId::VISIBLE_DATA_CHANGED, uno::Any(), uno::Any() );
     836             :                     }
     837             :                 }
     838           0 :                 break;
     839             : 
     840             :             case HINT_OBJINSERTED:
     841           0 :                 CommitChange( AccessibleEventId::CHILD, makeAny( getAccessible( pSdrHint->GetObject() ) ) , uno::Any());
     842           0 :                 break;
     843             :             case HINT_OBJREMOVED:
     844           0 :                 CommitChange( AccessibleEventId::CHILD, uno::Any(), makeAny( getAccessible( pSdrHint->GetObject() ) )  );
     845           0 :                 break;
     846             :             case HINT_MODELCLEARED:
     847           0 :                 dispose();
     848           0 :                 break;
     849             :             default:
     850           0 :                 break;
     851             :         }
     852             :     }
     853             :     else
     854             :     {
     855           0 :         const SfxSimpleHint* pSfxHint = dynamic_cast<const SfxSimpleHint*>( &rHint );
     856             : 
     857             :         // Has our SdDrawDocument just died?
     858           0 :         if(pSfxHint && pSfxHint->GetId() == SFX_HINT_DYING)
     859             :         {
     860           0 :             dispose();
     861             :         }
     862             :     }
     863           0 : }
     864             : 
     865             : // IAccessibleViewforwarder
     866           0 : bool SvxGraphCtrlAccessibleContext::IsValid (void) const
     867             : {
     868           0 :     return true;
     869             : }
     870             : 
     871             : 
     872             : 
     873           0 : Rectangle SvxGraphCtrlAccessibleContext::GetVisibleArea (void) const
     874             : {
     875           0 :     Rectangle aVisArea;
     876             : 
     877           0 :     if( mpView && mpView->PaintWindowCount())
     878             :     {
     879           0 :         SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(0L);
     880           0 :         aVisArea = pPaintWindow->GetVisibleArea();
     881             :     }
     882             : 
     883           0 :     return aVisArea;
     884             : }
     885             : 
     886             : 
     887             : 
     888           0 : Point SvxGraphCtrlAccessibleContext::LogicToPixel (const Point& rPoint) const
     889             : {
     890           0 :     if( mpControl )
     891             :     {
     892           0 :         Rectangle aBBox(mpControl->GetWindowExtentsRelative(NULL));
     893           0 :         return mpControl->LogicToPixel (rPoint) + aBBox.TopLeft();
     894             :     }
     895             :     else
     896             :     {
     897           0 :         return rPoint;
     898             :     }
     899             : }
     900             : 
     901             : 
     902             : 
     903           0 : Size SvxGraphCtrlAccessibleContext::LogicToPixel (const Size& rSize) const
     904             : {
     905           0 :     if( mpControl )
     906           0 :         return mpControl->LogicToPixel (rSize);
     907             :     else
     908           0 :         return rSize;
     909             : }
     910             : 
     911             : 
     912             : 
     913           0 : Point SvxGraphCtrlAccessibleContext::PixelToLogic (const Point& rPoint) const
     914             : {
     915           0 :     if( mpControl )
     916           0 :         return mpControl->PixelToLogic (rPoint);
     917             :     else
     918           0 :         return rPoint;
     919             : }
     920             : 
     921             : 
     922             : 
     923           0 : Size SvxGraphCtrlAccessibleContext::PixelToLogic (const Size& rSize) const
     924             : {
     925           0 :     if( mpControl )
     926           0 :         return mpControl->PixelToLogic (rSize);
     927             :     else
     928           0 :         return rSize;
     929         594 : }
     930             : 
     931             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10