LCOV - code coverage report
Current view: top level - chart2/source/controller/accessibility - AccessibleChartView.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 183 0.0 %
Date: 2014-04-14 Functions: 0 17 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 "AccessibleChartView.hxx"
      21             : #include "chartview/ExplicitValueProvider.hxx"
      22             : #include "servicenames.hxx"
      23             : #include "macros.hxx"
      24             : #include "ObjectHierarchy.hxx"
      25             : #include "ObjectIdentifier.hxx"
      26             : #include "ResId.hxx"
      27             : #include "Strings.hrc"
      28             : #include "AccessibleViewForwarder.hxx"
      29             : 
      30             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      31             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      32             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      33             : 
      34             : #include <rtl/ustring.hxx>
      35             : #include <vcl/window.hxx>
      36             : #include <toolkit/helper/vclunohelper.hxx>
      37             : // for SolarMutex
      38             : #include <vcl/svapp.hxx>
      39             : 
      40             : // header for typedef MutexGuard
      41             : #include <osl/mutex.hxx>
      42             : 
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::accessibility;
      45             : 
      46             : using ::com::sun::star::uno::Sequence;
      47             : using ::com::sun::star::uno::Reference;
      48             : using ::com::sun::star::uno::WeakReference;
      49             : using ::com::sun::star::uno::Any;
      50             : using osl::MutexGuard;
      51             : 
      52             : namespace chart
      53             : {
      54             : 
      55           0 : AccessibleChartView::AccessibleChartView(
      56             :     const Reference< uno::XComponentContext >& xContext, SdrView* pView ) :
      57             :         impl::AccessibleChartView_Base(
      58             :             AccessibleElementInfo(), // empty for now
      59             :             true, // has children
      60             :             true  // always transparent
      61             :             ),
      62             :         m_xContext( xContext ),
      63             :         m_pSdrView( pView ),
      64           0 :         m_pViewForwarder( NULL )
      65             : {
      66           0 :     AddState( AccessibleStateType::OPAQUE );
      67           0 : }
      68             : 
      69           0 : AccessibleChartView::~AccessibleChartView()
      70             : {
      71           0 :     delete m_pViewForwarder;
      72           0 : }
      73             : 
      74           0 : awt::Rectangle AccessibleChartView::GetWindowPosSize() const
      75             : {
      76           0 :     Reference< awt::XWindow > xWindow( GetInfo().m_xWindow );
      77           0 :     if( ! xWindow.is())
      78           0 :         return awt::Rectangle();
      79             : 
      80           0 :     awt::Rectangle aBBox( xWindow->getPosSize() );
      81             : 
      82           0 :     Window* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow ));
      83           0 :     if( pWindow )
      84             :     {
      85           0 :         SolarMutexGuard aSolarGuard;
      86           0 :         Point aVCLPoint( pWindow->OutputToAbsoluteScreenPixel( Point( 0, 0 ) ));
      87           0 :         aBBox.X = aVCLPoint.getX();
      88           0 :         aBBox.Y = aVCLPoint.getY();
      89             :     }
      90             : 
      91           0 :     return aBBox;
      92             : }
      93             : 
      94           0 : awt::Point AccessibleChartView::GetUpperLeftOnScreen() const
      95             : {
      96           0 :     awt::Point aParentPosition;
      97             : 
      98           0 :     awt::Rectangle aBBox( GetWindowPosSize() );
      99           0 :     aParentPosition.X = aBBox.X;
     100           0 :     aParentPosition.Y = aBBox.Y;
     101             : 
     102           0 :     return aParentPosition;
     103             : }
     104             : 
     105             : // ________ XAccessibleContext ________
     106           0 : OUString SAL_CALL AccessibleChartView::getAccessibleName()
     107             :     throw (uno::RuntimeException, std::exception)
     108             : {
     109           0 :     return SCH_RESSTR(STR_OBJECT_DIAGRAM);
     110             : }
     111             : 
     112           0 : OUString SAL_CALL AccessibleChartView::getAccessibleDescription()
     113             :     throw (uno::RuntimeException, std::exception)
     114             : {
     115           0 :     return getAccessibleName();
     116             : }
     117             : 
     118           0 : Reference< XAccessible > SAL_CALL AccessibleChartView::getAccessibleParent()
     119             :     throw (uno::RuntimeException, std::exception)
     120             : {
     121           0 :     return Reference< XAccessible >( m_xParent );
     122             : }
     123             : 
     124           0 : sal_Int32 SAL_CALL AccessibleChartView::getAccessibleIndexInParent()
     125             :     throw (uno::RuntimeException, std::exception)
     126             : {
     127             :     // the document is always the only child of the window
     128           0 :     return 0;
     129             : }
     130             : 
     131           0 : sal_Int16 SAL_CALL AccessibleChartView::getAccessibleRole()
     132             :     throw (uno::RuntimeException, std::exception)
     133             : {
     134           0 :     return AccessibleRole::DOCUMENT;
     135             : }
     136             : 
     137             : // ________ XAccessibleComponent ________
     138           0 : awt::Rectangle SAL_CALL AccessibleChartView::getBounds()
     139             :     throw (uno::RuntimeException, std::exception)
     140             : {
     141           0 :     awt::Rectangle aResult( GetWindowPosSize());
     142           0 :     Reference< XAccessible > xParent( m_xParent );
     143           0 :     if( xParent.is())
     144             :     {
     145           0 :         Reference< XAccessibleComponent > xContext( xParent->getAccessibleContext(), uno::UNO_QUERY );
     146           0 :         if( xContext.is())
     147             :         {
     148           0 :             awt::Point aParentPosition = xContext->getLocationOnScreen();
     149           0 :             aResult.X -= aParentPosition.X;
     150           0 :             aResult.Y -= aParentPosition.Y;
     151           0 :         }
     152             :     }
     153           0 :     return aResult;
     154             : }
     155             : 
     156           0 : awt::Point SAL_CALL AccessibleChartView::getLocationOnScreen()
     157             :     throw (uno::RuntimeException, std::exception)
     158             : {
     159           0 :     awt::Rectangle aBounds( getBounds());
     160           0 :     awt::Point aResult;
     161           0 :     Reference< XAccessible > xParent( m_xParent );
     162           0 :     if( xParent.is())
     163             :     {
     164             :         Reference< XAccessibleComponent > xAccComp(
     165           0 :             xParent->getAccessibleContext(), uno::UNO_QUERY );
     166           0 :         aResult = xAccComp->getLocationOnScreen();
     167           0 :         aResult.X += aBounds.X;
     168           0 :         aResult.Y += aBounds.Y;
     169             :     }
     170           0 :     return aResult;
     171             : }
     172             : 
     173             : // lang::XInitialization
     174             : 
     175           0 : void SAL_CALL AccessibleChartView::initialize( const Sequence< Any >& rArguments )
     176             :                 throw (uno::Exception, uno::RuntimeException, std::exception)
     177             : {
     178             :     //0: view::XSelectionSupplier offers notifications for selection changes and access to the selection itself
     179             :     //1: frame::XModel representing the chart model - offers access to object data
     180             :     //2: lang::XInterface representing the normal chart view - offers access to some extra object data
     181             : 
     182             :     //all arguments are only valid until next initialization
     183           0 :     bool bChanged = false;
     184           0 :     bool bOldInvalid = false;
     185           0 :     bool bNewInvalid = false;
     186             : 
     187           0 :     Reference< view::XSelectionSupplier > xSelectionSupplier;
     188           0 :     Reference< frame::XModel > xChartModel;
     189           0 :     Reference< uno::XInterface > xChartView;
     190           0 :     Reference< XAccessible > xParent;
     191           0 :     Reference< awt::XWindow > xWindow;
     192             :     {
     193           0 :         MutexGuard aGuard( GetMutex());
     194           0 :         xSelectionSupplier.set( m_xSelectionSupplier );
     195           0 :         xChartModel.set( m_xChartModel );
     196           0 :         xChartView.set( m_xChartView );
     197           0 :         xParent.set( m_xParent );
     198           0 :         xWindow.set( m_xWindow );
     199             :     }
     200             : 
     201           0 :     if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
     202             :     {
     203           0 :         bOldInvalid = true;
     204             :     }
     205             : 
     206           0 :     if( rArguments.getLength() > 1 )
     207             :     {
     208           0 :         Reference< frame::XModel > xNewChartModel;
     209           0 :         rArguments[1] >>= xNewChartModel;
     210           0 :         if( xNewChartModel != xChartModel )
     211             :         {
     212           0 :             xChartModel = xNewChartModel;
     213           0 :             bChanged = true;
     214           0 :         }
     215             :     }
     216           0 :     else if( xChartModel.is() )
     217             :     {
     218           0 :         bChanged = true;
     219           0 :         xChartModel = 0;
     220             :     }
     221             : 
     222           0 :     if( rArguments.getLength() > 2 )
     223             :     {
     224           0 :         Reference< uno::XInterface > xNewChartView;
     225           0 :         rArguments[2] >>= xNewChartView;
     226           0 :         if( xNewChartView != xChartView )
     227             :         {
     228           0 :             xChartView = xNewChartView;
     229           0 :             bChanged = true;
     230           0 :         }
     231             :     }
     232           0 :     else if( xChartView.is() )
     233             :     {
     234           0 :         bChanged = true;
     235           0 :         xChartView = 0;
     236             :     }
     237             : 
     238           0 :     if( rArguments.getLength() > 3 )
     239             :     {
     240           0 :         Reference< XAccessible > xNewParent;
     241           0 :         rArguments[3] >>= xNewParent;
     242           0 :         if( xNewParent != xParent )
     243             :         {
     244           0 :             xParent = xNewParent;
     245           0 :             bChanged = true;
     246           0 :         }
     247             :     }
     248             : 
     249           0 :     if( rArguments.getLength() > 4 )
     250             :     {
     251           0 :         Reference< awt::XWindow > xNewWindow;
     252           0 :         rArguments[4] >>= xNewWindow;
     253           0 :         if( xNewWindow != xWindow )
     254             :         {
     255           0 :             xWindow.set( xNewWindow );
     256           0 :             bChanged = true;
     257           0 :         }
     258             :     }
     259             : 
     260           0 :     if( rArguments.getLength() > 0 && xChartModel.is() && xChartView.is() )
     261             :     {
     262           0 :         Reference< view::XSelectionSupplier > xNewSelectionSupplier;
     263           0 :         rArguments[0] >>= xNewSelectionSupplier;
     264           0 :         if(xSelectionSupplier!=xNewSelectionSupplier)
     265             :         {
     266           0 :             bChanged = true;
     267           0 :             if(xSelectionSupplier.is())
     268           0 :                 xSelectionSupplier->removeSelectionChangeListener(this);
     269           0 :             if(xNewSelectionSupplier.is())
     270           0 :                 xNewSelectionSupplier->addSelectionChangeListener(this);
     271           0 :             xSelectionSupplier = xNewSelectionSupplier;
     272           0 :         }
     273             :     }
     274           0 :     else if( xSelectionSupplier.is() )
     275             :     {
     276           0 :         bChanged = true;
     277           0 :         xSelectionSupplier->removeSelectionChangeListener(this);
     278           0 :         xSelectionSupplier = 0;
     279             :     }
     280             : 
     281           0 :     if( !xSelectionSupplier.is() || !xChartModel.is() || !xChartView.is() )
     282             :     {
     283           0 :         if(xSelectionSupplier.is())
     284           0 :             xSelectionSupplier->removeSelectionChangeListener(this);
     285           0 :         xSelectionSupplier = 0;
     286           0 :         xChartModel.clear();
     287           0 :         xChartView.clear();
     288           0 :         xParent.clear();
     289           0 :         xWindow.clear();
     290             : 
     291           0 :         bNewInvalid = true;
     292             :     }
     293             : 
     294             :     {
     295           0 :         MutexGuard aGuard( GetMutex());
     296           0 :         m_xSelectionSupplier = WeakReference< view::XSelectionSupplier >(xSelectionSupplier);
     297           0 :         m_xChartModel = WeakReference< frame::XModel >(xChartModel);
     298           0 :         m_xChartView = WeakReference< uno::XInterface >(xChartView);
     299           0 :         m_xParent = WeakReference< XAccessible >(xParent);
     300           0 :         m_xWindow = WeakReference< awt::XWindow >(xWindow);
     301             :     }
     302             : 
     303           0 :     if( bOldInvalid && bNewInvalid )
     304           0 :         bChanged = false;
     305             : 
     306           0 :     if( bChanged )
     307             :     {
     308             :         {
     309             :             //before notification we prepare for creation of new context
     310             :             //the old context will be deleted after notification than
     311           0 :             MutexGuard aGuard( GetMutex());
     312           0 :             Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
     313           0 :             if( xChartDoc.is())
     314           0 :                 m_spObjectHierarchy.reset( new ObjectHierarchy( xChartDoc, getExplicitValueProvider() ));
     315             :             else
     316           0 :                 m_spObjectHierarchy.reset();
     317             :         }
     318             : 
     319             :         {
     320           0 :             AccessibleElementInfo aAccInfo;
     321           0 :             aAccInfo.m_aOID = ObjectIdentifier("ROOT");
     322           0 :             aAccInfo.m_xChartDocument = uno::WeakReference< chart2::XChartDocument >(
     323           0 :                 uno::Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY ));
     324           0 :             aAccInfo.m_xSelectionSupplier = m_xSelectionSupplier;
     325           0 :             aAccInfo.m_xView = m_xChartView;
     326           0 :             aAccInfo.m_xWindow = m_xWindow;
     327           0 :             aAccInfo.m_pParent = 0;
     328           0 :             aAccInfo.m_spObjectHierarchy = m_spObjectHierarchy;
     329           0 :             aAccInfo.m_pSdrView = m_pSdrView;
     330           0 :             Window* pWindow = VCLUnoHelper::GetWindow( m_xWindow );
     331           0 :             if ( m_pViewForwarder )
     332             :             {
     333           0 :                 delete m_pViewForwarder;
     334             :             }
     335           0 :             m_pViewForwarder = new AccessibleViewForwarder( this, pWindow );
     336           0 :             aAccInfo.m_pViewForwarder = m_pViewForwarder;
     337             :             // broadcasts an INVALIDATE_ALL_CHILDREN event globally
     338           0 :             SetInfo( aAccInfo );
     339             :         }
     340           0 :     }
     341           0 : }
     342             : 
     343           0 : ExplicitValueProvider* AccessibleChartView::getExplicitValueProvider()
     344             : {
     345           0 :     return ExplicitValueProvider::getExplicitValueProvider(m_xChartView);
     346             : }
     347             : 
     348             : // view::XSelectionChangeListener
     349             : 
     350           0 : void SAL_CALL AccessibleChartView::selectionChanged( const lang::EventObject& /*rEvent*/ )
     351             :                 throw (uno::RuntimeException, std::exception)
     352             : {
     353           0 :     Reference< view::XSelectionSupplier > xSelectionSupplier;
     354             :     {
     355           0 :         MutexGuard aGuard( GetMutex());
     356           0 :         xSelectionSupplier = Reference< view::XSelectionSupplier >(m_xSelectionSupplier);
     357             :     }
     358             : 
     359           0 :     if( xSelectionSupplier.is() )
     360             :     {
     361           0 :         ObjectIdentifier aSelectedOID( xSelectionSupplier->getSelection() );
     362           0 :         if ( m_aCurrentSelectionOID.isValid() )
     363             :         {
     364           0 :             NotifyEvent( LOST_SELECTION, m_aCurrentSelectionOID );
     365             :         }
     366           0 :         if( aSelectedOID.isValid() )
     367             :         {
     368           0 :             NotifyEvent( GOT_SELECTION, aSelectedOID );
     369             :         }
     370           0 :         m_aCurrentSelectionOID = aSelectedOID;
     371           0 :     }
     372           0 : }
     373             : 
     374             : // lang::XComponent::dispose()
     375           0 : void SAL_CALL AccessibleChartView::disposing()
     376             : {
     377           0 :     AccessibleBase::disposing();
     378           0 : }
     379             : 
     380             : // XEventListener
     381           0 : void SAL_CALL AccessibleChartView::disposing( const lang::EventObject& /*Source*/ )
     382             :     throw (uno::RuntimeException, std::exception)
     383             : {
     384           0 : }
     385             : 
     386             : } //namespace chart
     387             : 
     388             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10