LCOV - code coverage report
Current view: top level - sd/source/ui/accessibility - AccessibleDrawDocumentView.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 201 484 41.5 %
Date: 2014-11-03 Functions: 22 32 68.8 %
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 "AccessibleDrawDocumentView.hxx"
      21             : #include <com/sun/star/drawing/ShapeCollection.hpp>
      22             : #include <com/sun/star/drawing/XDrawPage.hpp>
      23             : #include <com/sun/star/drawing/XDrawView.hpp>
      24             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      25             : #include <com/sun/star/drawing/XShapes.hpp>
      26             : #include <com/sun/star/container/XChild.hpp>
      27             : #include <com/sun/star/frame/XController.hpp>
      28             : #include <com/sun/star/frame/XFrame.hpp>
      29             : #include <com/sun/star/document/XEventBroadcaster.hpp>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      32             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      33             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <rtl/ustring.h>
      36             : #include <sfx2/viewfrm.hxx>
      37             : 
      38             : #include <svx/AccessibleShape.hxx>
      39             : 
      40             : #include <svx/svdobj.hxx>
      41             : #include <svx/svdmodel.hxx>
      42             : #include <svx/unoapi.hxx>
      43             : #include <toolkit/helper/vclunohelper.hxx>
      44             : #include "Window.hxx"
      45             : #include <vcl/svapp.hxx>
      46             : 
      47             : #include "ViewShell.hxx"
      48             : #include "View.hxx"
      49             : #include "DrawDocShell.hxx"
      50             : #include <drawdoc.hxx>
      51             : #include <algorithm>
      52             : #include "sdpage.hxx"
      53             : #include "slideshow.hxx"
      54             : #include "anminfo.hxx"
      55             : 
      56             : #include "accessibility.hrc"
      57             : #include "sdresid.hxx"
      58             : #include <osl/mutex.hxx>
      59             : 
      60             : using namespace ::com::sun::star;
      61             : using namespace ::com::sun::star::uno;
      62             : using namespace ::com::sun::star::accessibility;
      63             : 
      64             : namespace accessibility {
      65             : 
      66             : struct XShapePosCompareHelper
      67             : {
      68           0 :     bool operator() ( const uno::Reference<drawing::XShape>& xshape1,
      69             :         const uno::Reference<drawing::XShape>& xshape2 ) const
      70             :     {
      71             :         // modify the compare method to return the Z-Order, not layout order
      72           0 :         SdrObject* pObj1 = GetSdrObjectFromXShape(xshape1);
      73           0 :         SdrObject* pObj2 = GetSdrObjectFromXShape(xshape2);
      74           0 :         if(pObj1 && pObj2)
      75           0 :             return pObj1->GetOrdNum() < pObj2->GetOrdNum();
      76             :         else
      77           0 :             return false;
      78             :     }
      79             : };
      80             : //=====  internal  ============================================================
      81             : 
      82           6 : AccessibleDrawDocumentView::AccessibleDrawDocumentView (
      83             :     ::sd::Window* pSdWindow,
      84             :     ::sd::ViewShell* pViewShell,
      85             :     const uno::Reference<frame::XController>& rxController,
      86             :     const uno::Reference<XAccessible>& rxParent)
      87             :     : AccessibleDocumentViewBase (pSdWindow, pViewShell, rxController, rxParent),
      88             :       mpSdViewSh( pViewShell ),
      89           6 :       mpChildrenManager (NULL)
      90             : {
      91             :     OSL_TRACE ("AccessibleDrawDocumentView");
      92           6 :     UpdateAccessibleName();
      93           6 : }
      94             : 
      95          12 : AccessibleDrawDocumentView::~AccessibleDrawDocumentView (void)
      96             : {
      97             :     OSL_TRACE ("~AccessibleDrawDocumentView");
      98             :     DBG_ASSERT (rBHelper.bDisposed || rBHelper.bInDispose,
      99             :         "~AccessibleDrawDocumentView: object has not been disposed");
     100          12 : }
     101             : 
     102           6 : void AccessibleDrawDocumentView::Init (void)
     103             : {
     104           6 :     AccessibleDocumentViewBase::Init ();
     105             : 
     106             :     // Determine the list of shapes on the current page.
     107           6 :     uno::Reference<drawing::XShapes> xShapeList;
     108          12 :     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
     109           6 :     if (xView.is())
     110          12 :         xShapeList = uno::Reference<drawing::XShapes> (
     111          12 :             xView->getCurrentPage(), uno::UNO_QUERY);
     112             : 
     113             :     // Create the children manager.
     114           6 :     mpChildrenManager = new ChildrenManager(this, xShapeList, maShapeTreeInfo, *this);
     115           6 :     if (mpChildrenManager != NULL)
     116             :     {
     117           6 :         rtl::Reference<AccessiblePageShape> xPage(CreateDrawPageShape());
     118           6 :         if (xPage.is())
     119             :         {
     120           6 :             xPage->Init();
     121           6 :             mpChildrenManager->AddAccessibleShape (xPage.get());
     122           6 :             mpChildrenManager->Update ();
     123             :         }
     124           6 :         mpChildrenManager->UpdateSelection ();
     125           6 :     }
     126           6 : }
     127             : 
     128           4 : void AccessibleDrawDocumentView::ViewForwarderChanged (ChangeType aChangeType,
     129             :     const IAccessibleViewForwarder* pViewForwarder)
     130             : {
     131           4 :     AccessibleDocumentViewBase::ViewForwarderChanged (aChangeType, pViewForwarder);
     132           4 :     if (mpChildrenManager != NULL)
     133           4 :         mpChildrenManager->ViewForwarderChanged (aChangeType, pViewForwarder);
     134           4 : }
     135             : 
     136             : /**  The page shape is created on every call at the moment (provided that
     137             :      every thing goes well).
     138             : */
     139          14 : rtl::Reference<AccessiblePageShape> AccessibleDrawDocumentView::CreateDrawPageShape (void)
     140             : {
     141          14 :     rtl::Reference<AccessiblePageShape> xShape;
     142             : 
     143             :     // Create a shape that represents the actual draw page.
     144          28 :     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
     145          14 :     if (xView.is())
     146             :     {
     147             :         uno::Reference<beans::XPropertySet> xSet (
     148          14 :             uno::Reference<beans::XPropertySet> (xView->getCurrentPage(), uno::UNO_QUERY));
     149          14 :         if (xSet.is())
     150             :         {
     151             :             // Create a rectangle shape that will represent the draw page.
     152          14 :             uno::Reference<lang::XMultiServiceFactory> xFactory (mxModel, uno::UNO_QUERY);
     153          28 :             uno::Reference<drawing::XShape> xRectangle;
     154          14 :             if (xFactory.is())
     155          28 :                 xRectangle = uno::Reference<drawing::XShape>(xFactory->createInstance ("com.sun.star.drawing.RectangleShape"),
     156          14 :                     uno::UNO_QUERY);
     157             : 
     158             :             // Set the shape's size and position.
     159          14 :             if (xRectangle.is())
     160             :             {
     161          14 :                 uno::Any aValue;
     162          14 :                 awt::Point aPosition;
     163          14 :                 awt::Size aSize;
     164             : 
     165             :                 // Set size and position of the shape to those of the draw
     166             :                 // page.
     167          14 :                 aValue = xSet->getPropertyValue ("BorderLeft");
     168          14 :                 aValue >>= aPosition.X;
     169          14 :                 aValue = xSet->getPropertyValue ("BorderTop");
     170          14 :                 aValue >>= aPosition.Y;
     171          14 :                 xRectangle->setPosition (aPosition);
     172             : 
     173          14 :                 aValue = xSet->getPropertyValue ("Width");
     174          14 :                 aValue >>= aSize.Width;
     175          14 :                 aValue = xSet->getPropertyValue ("Height");
     176          14 :                 aValue >>= aSize.Height;
     177          14 :                 xRectangle->setSize (aSize);
     178             : 
     179             :                 // Create the accessible object for the shape and
     180             :                 // initialize it.
     181          28 :                 xShape = new AccessiblePageShape (
     182          42 :                     xView->getCurrentPage(), this, maShapeTreeInfo);
     183          14 :             }
     184          14 :         }
     185             :     }
     186          28 :     return xShape;
     187             : }
     188             : 
     189             : //=====  XAccessibleContext  ==================================================
     190             : 
     191             : sal_Int32 SAL_CALL
     192          34 :     AccessibleDrawDocumentView::getAccessibleChildCount (void)
     193             :     throw (uno::RuntimeException, std::exception)
     194             : {
     195          34 :     ThrowIfDisposed ();
     196             : 
     197          34 :     long mpChildCount = AccessibleDocumentViewBase::getAccessibleChildCount();
     198             : 
     199             :     // Forward request to children manager.
     200          34 :     if (mpChildrenManager != NULL)
     201          34 :         mpChildCount += mpChildrenManager->GetChildCount ();
     202             : 
     203          34 :     return mpChildCount;
     204             : }
     205             : 
     206             : uno::Reference<XAccessible> SAL_CALL
     207          14 :     AccessibleDrawDocumentView::getAccessibleChild (sal_Int32 nIndex)
     208             :     throw (uno::RuntimeException, lang::IndexOutOfBoundsException, std::exception)
     209             : {
     210          14 :     ThrowIfDisposed ();
     211             : 
     212          14 :     ::osl::ClearableMutexGuard aGuard (maMutex);
     213             : 
     214             :     // Take care of children of the base class.
     215          14 :     sal_Int32 nCount = AccessibleDocumentViewBase::getAccessibleChildCount();
     216          14 :     if (nCount > 0)
     217             :     {
     218           0 :         if (nIndex < nCount)
     219           0 :             return AccessibleDocumentViewBase::getAccessibleChild(nIndex);
     220             :         else
     221           0 :             nIndex -= nCount;
     222             :     }
     223             : 
     224             :     // Create a copy of the pointer to the children manager and release the
     225             :     // mutex before calling any of its methods.
     226          14 :     ChildrenManager* pChildrenManager = mpChildrenManager;
     227          14 :     aGuard.clear();
     228             : 
     229             :     // Forward request to children manager.
     230          14 :     if (pChildrenManager != NULL)
     231             :     {
     232          14 :         return pChildrenManager->GetChild (nIndex);
     233             :     }
     234             :     else
     235             :         throw lang::IndexOutOfBoundsException (
     236           0 :             "no accessible child with index " + OUString::number(nIndex),
     237           0 :             static_cast<uno::XWeak*>(this));
     238             : }
     239             : 
     240             : OUString SAL_CALL
     241          28 :     AccessibleDrawDocumentView::getAccessibleName(void)
     242             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     243             : {
     244          28 :     SolarMutexGuard g;
     245             : 
     246          28 :     OUString sName = SdResId(SID_SD_A11Y_D_PRESENTATION);
     247          28 :     ::sd::View* pSdView = static_cast< ::sd::View* >( maShapeTreeInfo.GetSdrView() );
     248          28 :     if ( pSdView )
     249             :     {
     250          28 :         SdDrawDocument& rDoc = pSdView->GetDoc();
     251          28 :         OUString sFileName = rDoc.getDocAccTitle();
     252          28 :         if ( !sFileName.getLength() )
     253             :         {
     254          28 :             ::sd::DrawDocShell* pDocSh = pSdView->GetDocSh();
     255          28 :             if ( pDocSh )
     256             :             {
     257          28 :                 sFileName = pDocSh->GetTitle( SFX_TITLE_APINAME );
     258             :             }
     259             :         }
     260             : 
     261          56 :         OUString sReadOnly;
     262          28 :         if(rDoc.getDocReadOnly())
     263             :         {
     264           0 :             sReadOnly = SdResId(SID_SD_A11Y_D_PRESENTATION_READONLY);
     265             :         }
     266             : 
     267          28 :         if ( sFileName.getLength() )
     268             :         {
     269          28 :             sName = sFileName + sReadOnly + " - " + sName;
     270          28 :         }
     271             :     }
     272             : 
     273          28 :     return sName;
     274             : }
     275             : 
     276             : //=====  XEventListener  ======================================================
     277             : 
     278             : void SAL_CALL
     279          18 :     AccessibleDrawDocumentView::disposing (const lang::EventObject& rEventObject)
     280             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     281             : {
     282          18 :     ThrowIfDisposed ();
     283             : 
     284          12 :     AccessibleDocumentViewBase::disposing (rEventObject);
     285          12 :     if (rEventObject.Source == mxModel)
     286             :     {
     287           0 :         ::osl::Guard< ::osl::Mutex> aGuard (::osl::Mutex::getGlobalMutex());
     288             :         // maShapeTreeInfo has been modified in base class.
     289           0 :         if (mpChildrenManager != NULL)
     290           0 :             mpChildrenManager->SetInfo (maShapeTreeInfo);
     291             :     }
     292          12 : }
     293             : 
     294             : //=====  XPropertyChangeListener  =============================================
     295             : 
     296             : void SAL_CALL
     297          32 :     AccessibleDrawDocumentView::propertyChange (const beans::PropertyChangeEvent& rEventObject)
     298             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     299             : {
     300          32 :     ThrowIfDisposed ();
     301             : 
     302          32 :     AccessibleDocumentViewBase::propertyChange (rEventObject);
     303             : 
     304             :     OSL_TRACE ("AccessibleDrawDocumentView::propertyChange");
     305             :     // add page switch event for slide show mode
     306          56 :     if (rEventObject.PropertyName == "CurrentPage" ||
     307          24 :         rEventObject.PropertyName == "PageChange")
     308             :     {
     309             :         OSL_TRACE ("    current page changed");
     310             : 
     311             :         // Update the accessible name to reflect the current slide.
     312           8 :         UpdateAccessibleName();
     313             : 
     314             :         // The current page changed.  Update the children manager accordingly.
     315           8 :         uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
     316           8 :         if (xView.is() && mpChildrenManager!=NULL)
     317             :         {
     318             :             // Inform the children manager to forget all children and give
     319             :             // him the new ones.
     320           8 :             mpChildrenManager->ClearAccessibleShapeList ();
     321             :             mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
     322           8 :                 xView->getCurrentPage(), uno::UNO_QUERY));
     323             : 
     324           8 :             rtl::Reference<AccessiblePageShape> xPage(CreateDrawPageShape ());
     325           8 :             if (xPage.is())
     326             :             {
     327           8 :                 xPage->Init();
     328           8 :                 mpChildrenManager->AddAccessibleShape (xPage.get());
     329           8 :                 mpChildrenManager->Update (false);
     330           8 :             }
     331             :         }
     332             :         else
     333             :             OSL_TRACE ("View invalid");
     334           8 :         CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
     335             :     }
     336          24 :     else if ( rEventObject.PropertyName == "VisibleArea" )
     337             :     {
     338             :         OSL_TRACE ("    visible area changed");
     339          24 :         if (mpChildrenManager != NULL)
     340             :             mpChildrenManager->ViewForwarderChanged (
     341             :                 IAccessibleViewForwarderListener::VISIBLE_AREA,
     342          24 :                 &maViewForwarder);
     343             :     }
     344           0 :     else if (rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("ActiveLayer")))
     345             :     {
     346           0 :         CommitChange(AccessibleEventId::PAGE_CHANGED,rEventObject.NewValue,rEventObject.OldValue);
     347             :     }
     348           0 :     else if (rEventObject.PropertyName == OUString (RTL_CONSTASCII_USTRINGPARAM("UpdateAcc")))
     349             :     {
     350             :         OSL_TRACE ("    acc on current page should be updated");
     351             : 
     352             :         // The current page changed.  Update the children manager accordingly.
     353           0 :         uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
     354           0 :         if (xView.is() && mpChildrenManager!=NULL)
     355             :         {
     356             :             // Inform the children manager to forget all children and give
     357             :             // him the new ones.
     358           0 :             mpChildrenManager->ClearAccessibleShapeList ();
     359             :             // update the slide show page's accessible info
     360             :             //mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
     361             :             //    xView->getCurrentPage(), uno::UNO_QUERY));
     362           0 :             rtl::Reference< sd::SlideShow > xSlideshow( sd::SlideShow::GetSlideShow( mpSdViewSh->GetViewShellBase() ) );
     363           0 :             if( xSlideshow.is() && xSlideshow->isRunning() && xSlideshow->isFullScreen() )
     364             :             {
     365           0 :                 ::com::sun::star::uno::Reference< drawing::XDrawPage > xSlide;
     366             :                 // MT IA2: Not used...
     367             :                 // sal_Int32 currentPageIndex = xSlideshow->getCurrentPageIndex();
     368           0 :                 ::com::sun::star::uno::Reference< ::com::sun::star::presentation::XSlideShowController > mpSlideController = xSlideshow->getController();
     369           0 :                 if( mpSlideController.is() )
     370             :                 {
     371           0 :                     xSlide = mpSlideController->getCurrentSlide();
     372           0 :                     if (xSlide.is())
     373             :                     {
     374             :                         mpChildrenManager->SetShapeList (uno::Reference<drawing::XShapes> (
     375           0 :                                     xSlide, uno::UNO_QUERY));
     376             :                     }
     377           0 :                 }
     378             :             }
     379           0 :             rtl::Reference<AccessiblePageShape> xPage(CreateDrawPageShape ());
     380           0 :             if (xPage.is())
     381             :             {
     382           0 :                 xPage->Init();
     383           0 :                 mpChildrenManager->AddAccessibleShape (xPage.get());
     384           0 :                 mpChildrenManager->Update (false);
     385           0 :             }
     386           0 :         }
     387             :     }
     388             :     else
     389             :     {
     390             :         OSL_TRACE ("  unhandled");
     391             :     }
     392             :     OSL_TRACE ("  done");
     393          32 : }
     394             : 
     395             : //=====  XServiceInfo  ========================================================
     396             : 
     397             : OUString SAL_CALL
     398           2 :     AccessibleDrawDocumentView::getImplementationName (void)
     399             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     400             : {
     401           2 :     return OUString("AccessibleDrawDocumentView");
     402             : }
     403             : 
     404             : ::com::sun::star::uno::Sequence< OUString> SAL_CALL
     405           0 :     AccessibleDrawDocumentView::getSupportedServiceNames (void)
     406             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     407             : {
     408           0 :     ThrowIfDisposed();
     409             :     // Get list of supported service names from base class...
     410             :     uno::Sequence<OUString> aServiceNames =
     411           0 :         AccessibleDocumentViewBase::getSupportedServiceNames();
     412           0 :     sal_Int32 nCount (aServiceNames.getLength());
     413             : 
     414             :     // ...and add additional names.
     415           0 :     aServiceNames.realloc (nCount + 1);
     416           0 :     static const OUString sAdditionalServiceName ("com.sun.star.drawing.AccessibleDrawDocumentView");
     417           0 :     aServiceNames[nCount] = sAdditionalServiceName;
     418             : 
     419           0 :     return aServiceNames;
     420             : }
     421             : 
     422             : //=====  XInterface  ==========================================================
     423             : 
     424             : uno::Any SAL_CALL
     425         580 :     AccessibleDrawDocumentView::queryInterface (const uno::Type & rType)
     426             :     throw (uno::RuntimeException, std::exception)
     427             : {
     428         580 :     uno::Any aReturn = AccessibleDocumentViewBase::queryInterface (rType);
     429         580 :     if ( ! aReturn.hasValue())
     430          24 :         aReturn = ::cppu::queryInterface (rType,
     431             :             static_cast<XAccessibleGroupPosition*>(this)
     432          12 :             );
     433         580 :     return aReturn;
     434             : }
     435             : 
     436             : void SAL_CALL
     437        2126 :     AccessibleDrawDocumentView::acquire (void)
     438             :     throw ()
     439             : {
     440        2126 :     AccessibleDocumentViewBase::acquire ();
     441        2126 : }
     442             : void SAL_CALL
     443        2126 :     AccessibleDrawDocumentView::release (void)
     444             :     throw ()
     445             : {
     446        2126 :     AccessibleDocumentViewBase::release ();
     447        2126 : }
     448             : //=====  XAccessibleGroupPosition  =========================================
     449             : uno::Sequence< sal_Int32 > SAL_CALL
     450           0 :     AccessibleDrawDocumentView::getGroupPosition( const uno::Any& rAny )
     451             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     452             : {
     453           0 :     SolarMutexGuard g;
     454             : 
     455             :     // we will return the:
     456             :     // [0] group level(always be 0 now)
     457             :     // [1] similar items counts in the group
     458             :     // [2] the position of the object in the group
     459           0 :     uno::Sequence< sal_Int32 > aRet( 3 );
     460             :     //get the xShape of the current selected drawing object
     461           0 :     uno::Reference<XAccessibleContext> xAccContent;
     462           0 :     rAny >>= xAccContent;
     463           0 :     if ( !xAccContent.is() )
     464             :     {
     465           0 :         return aRet;
     466             :     }
     467           0 :     AccessibleShape* pAcc = AccessibleShape::getImplementation( xAccContent );
     468           0 :     if ( !pAcc )
     469             :     {
     470           0 :         return aRet;
     471             :     }
     472           0 :     uno::Reference< drawing::XShape > xCurShape = pAcc->GetXShape();
     473           0 :     if ( !xCurShape.is() )
     474             :     {
     475           0 :         return aRet;
     476             :     }
     477             :     //find all the child in the page, insert them into a vector and sort
     478           0 :     if ( mpChildrenManager == NULL )
     479             :     {
     480           0 :         return aRet;
     481             :     }
     482           0 :     std::vector< uno::Reference<drawing::XShape> > vXShapes;
     483           0 :     sal_Int32 nCount = mpChildrenManager->GetChildCount();
     484             :     //get pointer of SdView & SdrPageView for further use.
     485           0 :     SdrPageView* pPV = NULL;
     486           0 :     ::sd::View* pSdView = NULL;
     487           0 :     if ( mpSdViewSh )
     488             :     {
     489           0 :         pSdView = mpSdViewSh->GetView();
     490           0 :         pPV = pSdView->GetSdrPageView();
     491             :     }
     492           0 :     for ( sal_Int32 i = 0; i < nCount; i++ )
     493             :     {
     494           0 :         uno::Reference< drawing::XShape > xShape = mpChildrenManager->GetChildShape(i);
     495           0 :         if ( xShape.is() )
     496             :         {
     497             :             //if the object is visible in the page, we add it into the group list.
     498           0 :             SdrObject* pObj = GetSdrObjectFromXShape(xShape);
     499           0 :             if ( pObj && pPV && pSdView && pSdView->IsObjMarkable( pObj, pPV ) )
     500             :             {
     501           0 :                 vXShapes.push_back( xShape );
     502             :             }
     503             :         }
     504           0 :     }
     505           0 :     std::sort( vXShapes.begin(), vXShapes.end(), XShapePosCompareHelper() );
     506             :     //get the the index of the selected object in the group
     507           0 :     std::vector< uno::Reference<drawing::XShape> >::iterator aIter;
     508             :     //we start counting position from 1
     509           0 :     sal_Int32 nPos = 1;
     510           0 :     for ( aIter = vXShapes.begin(); aIter != vXShapes.end(); ++aIter, nPos++ )
     511             :     {
     512           0 :         if ( (*aIter).get() == xCurShape.get() )
     513             :         {
     514           0 :             sal_Int32* pArray = aRet.getArray();
     515           0 :             pArray[0] = 1; //it should be 1 based, not 0 based.
     516           0 :             pArray[1] = vXShapes.size();
     517           0 :             pArray[2] = nPos;
     518           0 :             break;
     519             :         }
     520             :     }
     521           0 :     return aRet;
     522             : }
     523             : 
     524           0 : OUString AccessibleDrawDocumentView::getObjectLink( const uno::Any& rAny )
     525             :     throw (uno::RuntimeException, std::exception)
     526             : {
     527           0 :     SolarMutexGuard g;
     528             : 
     529           0 :     OUString aRet;
     530             :     //get the xShape of the current selected drawing object
     531           0 :     uno::Reference<XAccessibleContext> xAccContent;
     532           0 :     rAny >>= xAccContent;
     533           0 :     if ( !xAccContent.is() )
     534             :     {
     535           0 :         return aRet;
     536             :     }
     537           0 :     AccessibleShape* pAcc = AccessibleShape::getImplementation( xAccContent );
     538           0 :     if ( !pAcc )
     539             :     {
     540           0 :         return aRet;
     541             :     }
     542           0 :     uno::Reference< drawing::XShape > xCurShape = pAcc->GetXShape();
     543           0 :     if ( !xCurShape.is() )
     544             :     {
     545           0 :         return aRet;
     546             :     }
     547           0 :     SdrObject* pObj = GetSdrObjectFromXShape(xCurShape);
     548           0 :     if (pObj)
     549             :     {
     550           0 :         SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
     551           0 :         if( pInfo && (pInfo->meClickAction == presentation::ClickAction_DOCUMENT) )
     552           0 :             aRet = pInfo->GetBookmark();
     553             :     }
     554           0 :     return aRet;
     555             : }
     556             : 
     557             : /// Create a name for this view.
     558          14 : OUString AccessibleDrawDocumentView::CreateAccessibleName (void)
     559             :     throw (::com::sun::star::uno::RuntimeException)
     560             : {
     561          14 :     OUString sName;
     562             : 
     563          28 :     uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
     564          14 :     if (xInfo.is())
     565             :     {
     566          14 :         uno::Sequence< OUString > aServices( xInfo->getSupportedServiceNames() );
     567          28 :         OUString sFirstService = aServices[0];
     568          14 :         if ( sFirstService == "com.sun.star.drawing.DrawingDocumentDrawView" )
     569             :         {
     570          14 :             if( aServices.getLength() >= 2 && aServices[1] == "com.sun.star.presentation.PresentationView")
     571             :             {
     572           0 :                 SolarMutexGuard aGuard;
     573             : 
     574           0 :                 sName = SD_RESSTR(SID_SD_A11Y_I_DRAWVIEW_N);
     575             :             }
     576             :             else
     577             :             {
     578          14 :                 SolarMutexGuard aGuard;
     579             : 
     580          14 :                 sName = SD_RESSTR(SID_SD_A11Y_D_DRAWVIEW_N);
     581             :             }
     582             :         }
     583           0 :         else if ( sFirstService == "com.sun.star.presentation.NotesView" )
     584             :         {
     585           0 :             SolarMutexGuard aGuard;
     586             : 
     587           0 :             sName = SD_RESSTR(SID_SD_A11Y_I_NOTESVIEW_N);
     588             :         }
     589           0 :         else if ( sFirstService == "com.sun.star.presentation.HandoutView" )
     590             :         {
     591           0 :             SolarMutexGuard aGuard;
     592             : 
     593           0 :             sName = SD_RESSTR(SID_SD_A11Y_I_HANDOUTVIEW_N);
     594             :         }
     595             :         else
     596             :         {
     597           0 :             sName = sFirstService;
     598          14 :         }
     599             :     }
     600             :     else
     601             :     {
     602           0 :         sName = "AccessibleDrawDocumentView";
     603             :     }
     604          28 :     return sName;
     605             : }
     606             : 
     607             : /** Create a description for this view.  Use the model's description or URL
     608             :     if a description is not available.
     609             : */
     610             : OUString
     611           0 :     AccessibleDrawDocumentView::CreateAccessibleDescription (void)
     612             :     throw (::com::sun::star::uno::RuntimeException)
     613             : {
     614           0 :     OUString sDescription;
     615             : 
     616           0 :     uno::Reference<lang::XServiceInfo> xInfo (mxController, uno::UNO_QUERY);
     617           0 :     if (xInfo.is())
     618             :     {
     619           0 :         uno::Sequence< OUString > aServices( xInfo->getSupportedServiceNames() );
     620           0 :         OUString sFirstService = aServices[0];
     621           0 :         if ( sFirstService == "com.sun.star.drawing.DrawingDocumentDrawView" )
     622             :         {
     623           0 :             if( aServices.getLength() >= 2 && aServices[1] == "com.sun.star.presentation.PresentationView")
     624             :             {
     625           0 :                 SolarMutexGuard aGuard;
     626             : 
     627           0 :                 sDescription = SD_RESSTR(SID_SD_A11Y_I_DRAWVIEW_D);
     628             :             }
     629             :             else
     630             :             {
     631           0 :                 SolarMutexGuard aGuard;
     632             : 
     633           0 :                 sDescription = SD_RESSTR(SID_SD_A11Y_D_DRAWVIEW_D);
     634             :             }
     635             :         }
     636           0 :         else if ( sFirstService == "com.sun.star.presentation.NotesView" )
     637             :         {
     638           0 :             SolarMutexGuard aGuard;
     639             : 
     640           0 :             sDescription = SD_RESSTR(SID_SD_A11Y_I_NOTESVIEW_D);
     641             :         }
     642           0 :         else if ( sFirstService == "com.sun.star.presentation.HandoutView" )
     643             :         {
     644           0 :             SolarMutexGuard aGuard;
     645             : 
     646           0 :             sDescription = SD_RESSTR(SID_SD_A11Y_I_HANDOUTVIEW_D);
     647             :         }
     648             :         else
     649             :         {
     650           0 :             sDescription = sFirstService;
     651           0 :         }
     652             :     }
     653             :     else
     654             :     {
     655           0 :         sDescription = "Accessible Draw Document";
     656             :     }
     657           0 :     return sDescription;
     658             : }
     659             : 
     660             : /** Return selection state of specified child
     661             : */
     662             : bool
     663           0 :     AccessibleDrawDocumentView::implIsSelected( sal_Int32 nAccessibleChildIndex )
     664             :     throw (uno::RuntimeException)
     665             : {
     666           0 :     const SolarMutexGuard aSolarGuard;
     667           0 :     uno::Reference< view::XSelectionSupplier >  xSel( mxController, uno::UNO_QUERY );
     668           0 :     bool                                    bRet = false;
     669             : 
     670             :     OSL_ENSURE( 0 <= nAccessibleChildIndex, "AccessibleDrawDocumentView::implIsSelected: invalid index!" );
     671             : 
     672           0 :     if( xSel.is() && ( 0 <= nAccessibleChildIndex ) )
     673             :     {
     674           0 :         uno::Any                            aAny( xSel->getSelection() );
     675           0 :         uno::Reference< drawing::XShapes >  xShapes;
     676             : 
     677           0 :         aAny >>= xShapes;
     678             : 
     679           0 :         if( xShapes.is() )
     680             :         {
     681           0 :             AccessibleShape* pAcc = AccessibleShape::getImplementation( getAccessibleChild( nAccessibleChildIndex ) );
     682             : 
     683           0 :             if( pAcc )
     684             :             {
     685           0 :                 uno::Reference< drawing::XShape > xShape( pAcc->GetXShape() );
     686             : 
     687           0 :                 if( xShape.is() )
     688             :                 {
     689           0 :                     for( sal_Int32 i = 0, nCount = xShapes->getCount(); ( i < nCount ) && !bRet; ++i )
     690           0 :                         if( xShapes->getByIndex( i ) == xShape )
     691           0 :                             bRet = true;
     692           0 :                 }
     693             :             }
     694           0 :         }
     695             :     }
     696             : 
     697           0 :     return( bRet );
     698             : }
     699             : 
     700             : /** Select or delselect the specified shapes.  The corresponding accessible
     701             :     shapes are notified over the selection change listeners registered with
     702             :     the XSelectionSupplier of the controller.
     703             : */
     704             : void
     705           4 :     AccessibleDrawDocumentView::implSelect( sal_Int32 nAccessibleChildIndex, bool bSelect )
     706             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     707             : {
     708           4 :     const SolarMutexGuard aSolarGuard;
     709           8 :     uno::Reference< view::XSelectionSupplier >  xSel( mxController, uno::UNO_QUERY );
     710             : 
     711           4 :     if( xSel.is() )
     712             :     {
     713           4 :         uno::Any aAny;
     714             : 
     715           4 :         if( ACCESSIBLE_SELECTION_CHILD_ALL == nAccessibleChildIndex )
     716             :         {
     717             :             // Select or deselect all children.
     718             : 
     719           2 :             if( !bSelect )
     720           2 :                 xSel->select( aAny );
     721             :             else
     722             :             {
     723             :                 uno::Reference< drawing::XShapes > xShapes = drawing::ShapeCollection::create(
     724           0 :                         comphelper::getProcessComponentContext());
     725             : 
     726           0 :                 for(sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
     727             :                 {
     728           0 :                     AccessibleShape* pAcc = AccessibleShape::getImplementation( getAccessibleChild( i ) );
     729             : 
     730           0 :                     if( pAcc && pAcc->GetXShape().is() )
     731           0 :                         xShapes->add( pAcc->GetXShape() );
     732             :                 }
     733             : 
     734           0 :                 if( xShapes->getCount() )
     735             :                 {
     736           0 :                     aAny <<= xShapes;
     737           0 :                     xSel->select( aAny );
     738           0 :                 }
     739             :             }
     740             :         }
     741           2 :         else if( nAccessibleChildIndex >= 0 )
     742             :         {
     743             :             // Select or deselect only the child with index
     744             :             // nAccessibleChildIndex.
     745             : 
     746             :             AccessibleShape* pAcc = AccessibleShape::getImplementation(
     747           2 :                 getAccessibleChild( nAccessibleChildIndex ));
     748             : 
     749             :             // Add or remove the shape that is made accessible from the
     750             :             // selection of the controller.
     751           2 :             if( pAcc )
     752             :             {
     753           2 :                 uno::Reference< drawing::XShape > xShape( pAcc->GetXShape() );
     754             : 
     755           2 :                 if( xShape.is() )
     756             :                 {
     757           2 :                     uno::Reference< drawing::XShapes >  xShapes;
     758           2 :                     bool                            bFound = false;
     759             : 
     760           2 :                     aAny = xSel->getSelection();
     761           2 :                     aAny >>= xShapes;
     762             : 
     763             :                     // Search shape to be selected in current selection.
     764           2 :                     if (xShapes.is())
     765             :                     {
     766           0 :                         sal_Int32 nCount = xShapes->getCount();
     767           0 :                         for (sal_Int32 i=0; ( i < nCount ) && !bFound; ++i )
     768           0 :                             if( xShapes->getByIndex( i ) == xShape )
     769           0 :                                 bFound = true;
     770             :                     }
     771             :                     else
     772             :                         // Create an empty selection to add the shape to.
     773           4 :                         xShapes = drawing::ShapeCollection::create(
     774           2 :                                 comphelper::getProcessComponentContext());
     775             : 
     776             :                     // Update the selection.
     777           2 :                     if( !bFound && bSelect )
     778           2 :                         xShapes->add( xShape );
     779           0 :                     else if( bFound && !bSelect )
     780           0 :                         xShapes->remove( xShape );
     781             : 
     782           2 :                     aAny <<= xShapes;
     783           2 :                     xSel->select( aAny );
     784           2 :                 }
     785             :             }
     786           4 :         }
     787           4 :     }
     788           4 : }
     789             : 
     790           0 : void AccessibleDrawDocumentView::Activated (void)
     791             : {
     792           0 :     if (mpChildrenManager != NULL)
     793             :     {
     794           0 :         bool bChange = false;
     795             :         // When none of the children has the focus then claim it for the
     796             :         // view.
     797           0 :         if ( ! mpChildrenManager->HasFocus())
     798             :         {
     799           0 :             SetState (AccessibleStateType::FOCUSED);
     800           0 :             bChange = true;
     801             :         }
     802             :         else
     803           0 :             ResetState (AccessibleStateType::FOCUSED);
     804           0 :     mpChildrenManager->UpdateSelection();
     805             :     // if the child gets focus in UpdateSelection(), needs to reset the focus on document.
     806           0 :     if (mpChildrenManager->HasFocus() && bChange)
     807           0 :         ResetState (AccessibleStateType::FOCUSED);
     808             :     }
     809           0 : }
     810             : 
     811           0 : void AccessibleDrawDocumentView::Deactivated (void)
     812             : {
     813           0 :     if (mpChildrenManager != NULL)
     814           0 :         mpChildrenManager->RemoveFocus();
     815           0 :     ResetState (AccessibleStateType::FOCUSED);
     816           0 : }
     817             : 
     818           6 : void AccessibleDrawDocumentView::impl_dispose (void)
     819             : {
     820           6 :     if (mpChildrenManager != NULL)
     821             :     {
     822           0 :         delete mpChildrenManager;
     823           0 :         mpChildrenManager = NULL;
     824             :     }
     825             : 
     826           6 :     AccessibleDocumentViewBase::impl_dispose();
     827           6 : }
     828             : 
     829             : /** This method is called from the component helper base class while
     830             :     disposing.
     831             : */
     832           6 : void SAL_CALL AccessibleDrawDocumentView::disposing (void)
     833             : {
     834             : 
     835             :     // Release resources.
     836           6 :     if (mpChildrenManager != NULL)
     837             :     {
     838           6 :         delete mpChildrenManager;
     839           6 :         mpChildrenManager = NULL;
     840             :     }
     841             : 
     842             :     // Forward call to base classes.
     843           6 :     AccessibleDocumentViewBase::disposing ();
     844           6 : }
     845             : 
     846             : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
     847           0 :         SAL_CALL AccessibleDrawDocumentView::getAccFlowTo(const ::com::sun::star::uno::Any& rAny, sal_Int32 nType)
     848             :         throw ( ::com::sun::star::uno::RuntimeException, std::exception )
     849             : {
     850           0 :     SolarMutexGuard g;
     851             : 
     852           0 :     const sal_Int32 SPELLCHECKFLOWTO = 1;
     853           0 :     const sal_Int32 FINDREPLACEFLOWTO = 2;
     854           0 :     if ( nType == SPELLCHECKFLOWTO )
     855             :     {
     856           0 :         uno::Reference< ::com::sun::star::drawing::XShape > xShape;
     857           0 :         rAny >>= xShape;
     858           0 :         if ( mpChildrenManager && xShape.is() )
     859             :         {
     860           0 :             uno::Reference < XAccessible > xAcc = mpChildrenManager->GetChild(xShape);
     861           0 :             uno::Reference < XAccessibleSelection > xAccSelection( xAcc, uno::UNO_QUERY );
     862           0 :             if ( xAccSelection.is() )
     863             :             {
     864           0 :                 if ( xAccSelection->getSelectedAccessibleChildCount() )
     865             :                 {
     866           0 :                     uno::Reference < XAccessible > xSel = xAccSelection->getSelectedAccessibleChild( 0 );
     867           0 :                     if ( xSel.is() )
     868             :                     {
     869           0 :                         uno::Reference < XAccessibleContext > xSelContext( xSel->getAccessibleContext() );
     870           0 :                         if ( xSelContext.is() )
     871             :                         {
     872             :                             //if in sw we find the selected paragraph here
     873           0 :                             if ( xSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
     874             :                             {
     875           0 :                                 uno::Sequence<uno::Any> aRet( 1 );
     876           0 :                                 aRet[0] = uno::makeAny( xSel );
     877           0 :                                 return aRet;
     878             :                             }
     879           0 :                         }
     880           0 :                     }
     881             :                 }
     882             :             }
     883           0 :             uno::Reference<XAccessible> xPara = GetSelAccContextInTable();
     884           0 :             if ( xPara.is() )
     885             :             {
     886           0 :                 uno::Sequence<uno::Any> aRet( 1 );
     887           0 :                 aRet[0] = uno::makeAny( xPara );
     888           0 :                 return aRet;
     889           0 :             }
     890             :         }
     891             :         else
     892             :         {
     893           0 :             goto Rt;
     894           0 :         }
     895             :     }
     896           0 :     else if ( nType == FINDREPLACEFLOWTO )
     897             :     {
     898           0 :         sal_Int32 nChildCount = getSelectedAccessibleChildCount();
     899           0 :         if ( nChildCount )
     900             :         {
     901           0 :             uno::Reference < XAccessible > xSel = getSelectedAccessibleChild( 0 );
     902           0 :             if ( xSel.is() )
     903             :             {
     904           0 :                 uno::Reference < XAccessibleSelection > xAccChildSelection( xSel, uno::UNO_QUERY );
     905           0 :                 if ( xAccChildSelection.is() )
     906             :                 {
     907           0 :                     if ( xAccChildSelection->getSelectedAccessibleChildCount() )
     908             :                     {
     909           0 :                         uno::Reference < XAccessible > xChildSel = xAccChildSelection->getSelectedAccessibleChild( 0 );
     910           0 :                         if ( xChildSel.is() )
     911             :                         {
     912           0 :                             uno::Reference < XAccessibleContext > xChildSelContext( xChildSel->getAccessibleContext() );
     913           0 :                             if ( xChildSelContext.is() &&
     914           0 :                                 xChildSelContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
     915             :                             {
     916           0 :                                 uno::Sequence<uno::Any> aRet( 1 );
     917           0 :                                 aRet[0] = uno::makeAny( xChildSel );
     918           0 :                                 return aRet;
     919           0 :                             }
     920           0 :                         }
     921             :                     }
     922           0 :                 }
     923           0 :             }
     924             :         }
     925             :         else
     926             :         {
     927           0 :             uno::Reference<XAccessible> xPara = GetSelAccContextInTable();
     928           0 :             if ( xPara.is() )
     929             :             {
     930           0 :                 uno::Sequence<uno::Any> aRet( 1 );
     931           0 :                 aRet[0] = uno::makeAny( xPara );
     932           0 :                 return aRet;
     933           0 :             }
     934             :         }
     935             :     }
     936             : 
     937             : Rt:
     938           0 :     ::com::sun::star::uno::Sequence< uno::Any> aRet;
     939           0 :     return aRet;
     940             : }
     941           0 : uno::Reference<XAccessible> AccessibleDrawDocumentView::GetSelAccContextInTable()
     942             : {
     943           0 :     uno::Reference<XAccessible> xRet;
     944           0 :     sal_Int32 nCount = mpChildrenManager ? mpChildrenManager->GetChildCount() : 0;
     945           0 :     if ( nCount )
     946             :     {
     947           0 :         for ( sal_Int32 i = 0; i < nCount; i++ )
     948             :         {
     949             :             try
     950             :             {
     951           0 :                 uno::Reference<XAccessible> xObj = mpChildrenManager->GetChild(i);
     952           0 :                 if ( xObj.is() )
     953             :                 {
     954           0 :                     uno::Reference<XAccessibleContext> xObjContext( xObj, uno::UNO_QUERY );
     955           0 :                     if ( xObjContext.is() && xObjContext->getAccessibleRole() == AccessibleRole::TABLE )
     956             :                     {
     957           0 :                         uno::Reference<XAccessibleSelection> xObjSelection( xObj, uno::UNO_QUERY );
     958           0 :                         if ( xObjSelection.is() && xObjSelection->getSelectedAccessibleChildCount() )
     959             :                         {
     960           0 :                             uno::Reference<XAccessible> xCell = xObjSelection->getSelectedAccessibleChild(0);
     961           0 :                             if ( xCell.is() )
     962             :                             {
     963           0 :                                 uno::Reference<XAccessibleSelection> xCellSel( xCell, uno::UNO_QUERY );
     964           0 :                                 if ( xCellSel.is() && xCellSel->getSelectedAccessibleChildCount() )
     965             :                                 {
     966           0 :                                     uno::Reference<XAccessible> xPara = xCellSel->getSelectedAccessibleChild( 0 );
     967           0 :                                     if ( xPara.is() )
     968             :                                     {
     969           0 :                                         uno::Reference<XAccessibleContext> xParaContext( xPara, uno::UNO_QUERY );
     970           0 :                                         if ( xParaContext.is() &&
     971           0 :                                             xParaContext->getAccessibleRole() == AccessibleRole::PARAGRAPH )
     972             :                                         {
     973           0 :                                             xRet = xPara;
     974           0 :                                             return xRet;
     975           0 :                                         }
     976           0 :                                     }
     977           0 :                                 }
     978           0 :                             }
     979           0 :                         }
     980           0 :                     }
     981           0 :                 }
     982             :             }
     983           0 :             catch ( lang::IndexOutOfBoundsException )
     984             :             {
     985           0 :                 uno::Reference<XAccessible> xEmpty;
     986           0 :                 return xEmpty;
     987             :             }
     988           0 :             catch ( uno::RuntimeException )
     989             :             {
     990           0 :                 uno::Reference<XAccessible> xEmpty;
     991           0 :                 return xEmpty;
     992             :             }
     993             :         }
     994             :     }
     995             : 
     996           0 :     return xRet;
     997             : }
     998             : 
     999          14 : void AccessibleDrawDocumentView::UpdateAccessibleName (void)
    1000             : {
    1001          14 :     OUString sNewName (CreateAccessibleName());
    1002          14 :     sNewName += ": ";
    1003             : 
    1004             :     // Add the number of the current slide.
    1005          28 :     uno::Reference<drawing::XDrawView> xView (mxController, uno::UNO_QUERY);
    1006          14 :     if (xView.is())
    1007             :     {
    1008          14 :         uno::Reference<beans::XPropertySet> xProperties (xView->getCurrentPage(), UNO_QUERY);
    1009          14 :         if (xProperties.is())
    1010             :             try
    1011             :             {
    1012          14 :                 sal_Int16 nPageNumber (0);
    1013          14 :                 if (xProperties->getPropertyValue("Number") >>= nPageNumber)
    1014             :                 {
    1015          14 :                     sNewName += OUString::number(nPageNumber);
    1016             :                 }
    1017             :             }
    1018           0 :             catch (beans::UnknownPropertyException&)
    1019             :             {
    1020          14 :             }
    1021             :     }
    1022             : 
    1023             :     // Add the number of pages/slides.
    1024          28 :     Reference<drawing::XDrawPagesSupplier> xPagesSupplier (mxModel, UNO_QUERY);
    1025          14 :     if (xPagesSupplier.is())
    1026             :     {
    1027          14 :         Reference<container::XIndexAccess> xPages (xPagesSupplier->getDrawPages(), UNO_QUERY);
    1028          14 :         if (xPages.is())
    1029             :         {
    1030          14 :             sNewName += " / ";
    1031          14 :             sNewName += OUString::number(xPages->getCount());
    1032          14 :         }
    1033             :     }
    1034             : 
    1035          28 :     SetAccessibleName (sNewName, AutomaticallyCreated);
    1036          14 : }
    1037             : 
    1038         114 : } // end of namespace accessibility
    1039             : 
    1040             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10