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

Generated by: LCOV version 1.10