LCOV - code coverage report
Current view: top level - sd/source/ui/accessibility - AccessiblePageShape.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 112 0.0 %
Date: 2014-04-14 Functions: 0 16 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 "AccessiblePageShape.hxx"
      21             : #include <svx/AccessibleShapeInfo.hxx>
      22             : 
      23             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      24             : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/container/XChild.hpp>
      27             : #include <com/sun/star/drawing/XShapes.hpp>
      28             : #include <com/sun/star/drawing/XShapeDescriptor.hpp>
      29             : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
      30             : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::accessibility;
      35             : using ::com::sun::star::uno::Reference;
      36             : 
      37             : 
      38             : namespace accessibility {
      39             : 
      40             : //=====  internal  ============================================================
      41             : 
      42           0 : AccessiblePageShape::AccessiblePageShape (
      43             :     const uno::Reference<drawing::XDrawPage>& rxPage,
      44             :     const uno::Reference<XAccessible>& rxParent,
      45             :     const AccessibleShapeTreeInfo& rShapeTreeInfo,
      46             :     long nIndex)
      47             :     : AccessibleShape (AccessibleShapeInfo (NULL, rxParent, nIndex), rShapeTreeInfo),
      48           0 :       mxPage (rxPage)
      49             : {
      50             :     // The main part of the initialization is done in the init method which
      51             :     // has to be called from this constructor's caller.
      52           0 : }
      53             : 
      54             : 
      55             : 
      56             : 
      57           0 : AccessiblePageShape::~AccessiblePageShape (void)
      58             : {
      59             :     OSL_TRACE ("~AccessiblePageShape");
      60           0 : }
      61             : 
      62             : 
      63             : 
      64             : 
      65           0 : void AccessiblePageShape::Init (void)
      66             : {
      67           0 :     AccessibleShape::Init ();
      68           0 : }
      69             : 
      70             : 
      71             : 
      72             : 
      73             : //=====  XAccessibleContext  ==================================================
      74             : 
      75             : sal_Int32 SAL_CALL
      76           0 :        AccessiblePageShape::getAccessibleChildCount (void)
      77             :     throw (std::exception)
      78             : {
      79           0 :     return 0;
      80             : }
      81             : 
      82             : 
      83             : 
      84             : 
      85             : /** Forward the request to the shape.  Return the requested shape or throw
      86             :     an exception for a wrong index.
      87             : */
      88             : uno::Reference<XAccessible> SAL_CALL
      89           0 :     AccessiblePageShape::getAccessibleChild( sal_Int32 )
      90             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
      91             : {
      92             :     throw lang::IndexOutOfBoundsException ("page shape has no children",
      93           0 :         static_cast<uno::XWeak*>(this));
      94             : }
      95             : 
      96             : 
      97             : 
      98             : 
      99             : //=====  XAccessibleComponent  ================================================
     100             : 
     101           0 : awt::Rectangle SAL_CALL AccessiblePageShape::getBounds (void)
     102             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     103             : {
     104           0 :     ThrowIfDisposed ();
     105             : 
     106           0 :     awt::Rectangle aBoundingBox;
     107             : 
     108           0 :     if (maShapeTreeInfo.GetViewForwarder() != NULL)
     109             :     {
     110           0 :         uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
     111           0 :         if (xSet.is())
     112             :         {
     113           0 :             uno::Any aValue;
     114           0 :             awt::Point aPosition;
     115           0 :             awt::Size aSize;
     116             : 
     117           0 :             aValue = xSet->getPropertyValue ("BorderLeft");
     118           0 :             aValue >>= aBoundingBox.X;
     119           0 :             aValue = xSet->getPropertyValue ("BorderTop");
     120           0 :             aValue >>= aBoundingBox.Y;
     121             : 
     122           0 :             aValue = xSet->getPropertyValue ("Width");
     123           0 :             aValue >>= aBoundingBox.Width;
     124           0 :             aValue = xSet->getPropertyValue ("Height");
     125           0 :             aValue >>= aBoundingBox.Height;
     126             :         }
     127             : 
     128             :         // Transform coordinates from internal to pixel.
     129           0 :         ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
     130           0 :             ::Size (aBoundingBox.Width, aBoundingBox.Height));
     131           0 :         ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
     132           0 :             ::Point (aBoundingBox.X, aBoundingBox.Y));
     133             : 
     134             :         // Clip the shape's bounding box with the bounding box of its parent.
     135             :         Reference<XAccessibleComponent> xParentComponent (
     136           0 :             getAccessibleParent(), uno::UNO_QUERY);
     137           0 :         if (xParentComponent.is())
     138             :         {
     139             :             // Make the coordinates relative to the parent.
     140           0 :             awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
     141           0 :             int x = aPixelPosition.getX() - aParentLocation.X;
     142           0 :             int y = aPixelPosition.getY() - aParentLocation.Y;
     143             : 
     144             : 
     145             :             // Clip with parent (with coordinates relative to itself).
     146             :             ::Rectangle aBBox (
     147           0 :                 x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
     148           0 :             awt::Size aParentSize (xParentComponent->getSize());
     149           0 :             ::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
     150           0 :             aBBox = aBBox.GetIntersection (aParentBBox);
     151             :             aBoundingBox = awt::Rectangle (
     152           0 :                 aBBox.getX(),
     153           0 :                 aBBox.getY(),
     154           0 :                 aBBox.getWidth(),
     155           0 :                 aBBox.getHeight());
     156             :         }
     157             :         else
     158             :             aBoundingBox = awt::Rectangle (
     159           0 :                 aPixelPosition.getX(), aPixelPosition.getY(),
     160           0 :                 aPixelSize.getWidth(), aPixelSize.getHeight());
     161             :     }
     162             : 
     163           0 :     return aBoundingBox;
     164             : }
     165             : 
     166             : 
     167             : 
     168             : 
     169           0 : sal_Int32 SAL_CALL AccessiblePageShape::getForeground (void)
     170             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     171             : {
     172           0 :     ThrowIfDisposed ();
     173           0 :     sal_Int32 nColor (0x0ffffffL);
     174             : 
     175             :     try
     176             :     {
     177           0 :         uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
     178           0 :         if (aSet.is())
     179             :         {
     180           0 :             uno::Any aColor;
     181           0 :             aColor = aSet->getPropertyValue ("LineColor");
     182           0 :             aColor >>= nColor;
     183           0 :         }
     184             :     }
     185           0 :     catch (const ::com::sun::star::beans::UnknownPropertyException&)
     186             :     {
     187             :         // Ignore exception and return default color.
     188             :     }
     189           0 :     return nColor;
     190             : }
     191             : 
     192             : 
     193             : 
     194             : 
     195             : /** Extract the background color from the Background property of eithe the
     196             :     draw page or its master page.
     197             : */
     198           0 : sal_Int32 SAL_CALL AccessiblePageShape::getBackground (void)
     199             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     200             : {
     201           0 :     ThrowIfDisposed ();
     202           0 :     sal_Int32 nColor (0x01020ffL);
     203             : 
     204             :     try
     205             :     {
     206           0 :         uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
     207           0 :         if (xSet.is())
     208             :         {
     209           0 :             uno::Any aBGSet;
     210           0 :             aBGSet = xSet->getPropertyValue ("Background");
     211           0 :             Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
     212           0 :             if ( ! xBGSet.is())
     213             :             {
     214             :                 // Draw page has no Background property.  Try the master
     215             :                 // page instead.
     216           0 :                 Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
     217           0 :                 if (xTarget.is())
     218             :                 {
     219           0 :                     xSet = Reference<beans::XPropertySet> (xTarget->getMasterPage(),
     220           0 :                         uno::UNO_QUERY);
     221           0 :                     aBGSet = xSet->getPropertyValue ("Background");
     222           0 :                     xBGSet = Reference<beans::XPropertySet> (aBGSet, uno::UNO_QUERY);
     223           0 :                 }
     224             :             }
     225             :             // Fetch the fill color.  Has to be extended to cope with
     226             :             // gradients, hashes, and bitmaps.
     227           0 :             if (xBGSet.is())
     228             :             {
     229           0 :                 uno::Any aColor;
     230           0 :                 aColor = xBGSet->getPropertyValue ("FillColor");
     231           0 :                 aColor >>= nColor;
     232             :             }
     233             :             else
     234           0 :                 OSL_TRACE ("no Background property in page");
     235           0 :         }
     236             :     }
     237           0 :     catch (const ::com::sun::star::beans::UnknownPropertyException&)
     238             :     {
     239             :         OSL_TRACE ("caught excption due to unknown property");
     240             :         // Ignore exception and return default color.
     241             :     }
     242           0 :     return nColor;
     243             : }
     244             : 
     245             : 
     246             : 
     247             : 
     248             : //=====  XServiceInfo  ========================================================
     249             : 
     250             : OUString SAL_CALL
     251           0 :     AccessiblePageShape::getImplementationName (void)
     252             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     253             : {
     254           0 :     ThrowIfDisposed ();
     255           0 :     return OUString("AccessiblePageShape");
     256             : }
     257             : 
     258             : 
     259             : 
     260             : 
     261             : ::com::sun::star::uno::Sequence< OUString> SAL_CALL
     262           0 :     AccessiblePageShape::getSupportedServiceNames (void)
     263             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     264             : {
     265           0 :     ThrowIfDisposed ();
     266           0 :     return AccessibleShape::getSupportedServiceNames();
     267             : }
     268             : 
     269             : 
     270             : 
     271             : 
     272             : //=====  lang::XEventListener  ================================================
     273             : 
     274             : void SAL_CALL
     275           0 :     AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject& aEvent)
     276             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     277             : {
     278           0 :     ThrowIfDisposed ();
     279           0 :     AccessibleShape::disposing (aEvent);
     280           0 : }
     281             : 
     282             : 
     283             : 
     284             : 
     285             : //=====  XComponent  ==========================================================
     286             : 
     287           0 : void AccessiblePageShape::dispose (void)
     288             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     289             : {
     290             :     OSL_TRACE ("AccessiblePageShape::dispose");
     291             : 
     292             :     // Unregister listeners.
     293           0 :     Reference<lang::XComponent> xComponent (mxShape, uno::UNO_QUERY);
     294           0 :     if (xComponent.is())
     295           0 :         xComponent->removeEventListener (this);
     296             : 
     297             :     // Cleanup.
     298           0 :     mxShape = NULL;
     299             : 
     300             :     // Call base classes.
     301           0 :     AccessibleContextBase::dispose ();
     302           0 : }
     303             : 
     304             : 
     305             : 
     306             : 
     307             : //=====  protected internal  ==================================================
     308             : 
     309             : OUString
     310           0 :     AccessiblePageShape::CreateAccessibleBaseName (void)
     311             :     throw (::com::sun::star::uno::RuntimeException)
     312             : {
     313           0 :     return OUString ("PageShape");
     314             : }
     315             : 
     316             : 
     317             : 
     318             : 
     319             : OUString
     320           0 :     AccessiblePageShape::CreateAccessibleName (void)
     321             :     throw (::com::sun::star::uno::RuntimeException)
     322             : {
     323           0 :     Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
     324             : 
     325             :     // Get name of the current slide.
     326           0 :     OUString sCurrentSlideName;
     327             :     try
     328             :     {
     329           0 :         if (xPageProperties.is())
     330             :         {
     331           0 :             xPageProperties->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName;
     332             :         }
     333             :     }
     334           0 :     catch (const beans::UnknownPropertyException&)
     335             :     {
     336             :     }
     337             : 
     338           0 :     return CreateAccessibleBaseName()+": "+sCurrentSlideName;
     339             : }
     340             : 
     341             : 
     342             : 
     343             : 
     344             : OUString
     345           0 :     AccessiblePageShape::CreateAccessibleDescription (void)
     346             :     throw (::com::sun::star::uno::RuntimeException)
     347             : {
     348           0 :     return OUString ("Page Shape");
     349             : }
     350             : 
     351             : 
     352             : } // end of namespace accessibility
     353             : 
     354             : 
     355             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10