LCOV - code coverage report
Current view: top level - sd/source/ui/accessibility - AccessiblePageShape.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 63 112 56.2 %
Date: 2015-06-13 12:38:46 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           7 : 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           7 :       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           7 : }
      52             : 
      53          14 : AccessiblePageShape::~AccessiblePageShape()
      54             : {
      55             :     OSL_TRACE ("~AccessiblePageShape");
      56          14 : }
      57             : 
      58           7 : void AccessiblePageShape::Init()
      59             : {
      60           7 :     AccessibleShape::Init ();
      61           7 : }
      62             : 
      63             : //=====  XAccessibleContext  ==================================================
      64             : 
      65             : sal_Int32 SAL_CALL
      66           4 :        AccessiblePageShape::getAccessibleChildCount()
      67             :     throw (std::exception)
      68             : {
      69           4 :     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          16 : awt::Rectangle SAL_CALL AccessiblePageShape::getBounds()
      86             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
      87             : {
      88          16 :     ThrowIfDisposed ();
      89             : 
      90          16 :     awt::Rectangle aBoundingBox;
      91             : 
      92          16 :     if (maShapeTreeInfo.GetViewForwarder() != NULL)
      93             :     {
      94          16 :         uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
      95          16 :         if (xSet.is())
      96             :         {
      97          16 :             uno::Any aValue;
      98          16 :             awt::Point aPosition;
      99          16 :             awt::Size aSize;
     100             : 
     101          16 :             aValue = xSet->getPropertyValue ("BorderLeft");
     102          16 :             aValue >>= aBoundingBox.X;
     103          16 :             aValue = xSet->getPropertyValue ("BorderTop");
     104          16 :             aValue >>= aBoundingBox.Y;
     105             : 
     106          16 :             aValue = xSet->getPropertyValue ("Width");
     107          16 :             aValue >>= aBoundingBox.Width;
     108          16 :             aValue = xSet->getPropertyValue ("Height");
     109          16 :             aValue >>= aBoundingBox.Height;
     110             :         }
     111             : 
     112             :         // Transform coordinates from internal to pixel.
     113          16 :         ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
     114          16 :             ::Size (aBoundingBox.Width, aBoundingBox.Height));
     115          16 :         ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
     116          16 :             ::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          32 :             getAccessibleParent(), uno::UNO_QUERY);
     121          16 :         if (xParentComponent.is())
     122             :         {
     123             :             // Make the coordinates relative to the parent.
     124          16 :             awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
     125          16 :             int x = aPixelPosition.getX() - aParentLocation.X;
     126          16 :             int y = aPixelPosition.getY() - aParentLocation.Y;
     127             : 
     128             :             // Clip with parent (with coordinates relative to itself).
     129             :             ::Rectangle aBBox (
     130          16 :                 x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
     131          16 :             awt::Size aParentSize (xParentComponent->getSize());
     132          16 :             ::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
     133          16 :             aBBox = aBBox.GetIntersection (aParentBBox);
     134             :             aBoundingBox = awt::Rectangle (
     135          16 :                 aBBox.getX(),
     136          16 :                 aBBox.getY(),
     137          16 :                 aBBox.getWidth(),
     138          64 :                 aBBox.getHeight());
     139             :         }
     140             :         else
     141             :             aBoundingBox = awt::Rectangle (
     142           0 :                 aPixelPosition.getX(), aPixelPosition.getY(),
     143          16 :                 aPixelSize.getWidth(), aPixelSize.getHeight());
     144             :     }
     145             : 
     146          16 :     return aBoundingBox;
     147             : }
     148             : 
     149           0 : sal_Int32 SAL_CALL AccessiblePageShape::getForeground()
     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()
     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           1 :     AccessiblePageShape::getImplementationName()
     226             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     227             : {
     228           1 :     ThrowIfDisposed ();
     229           1 :     return OUString("AccessiblePageShape");
     230             : }
     231             : 
     232             : ::com::sun::star::uno::Sequence< OUString> SAL_CALL
     233           0 :     AccessiblePageShape::getSupportedServiceNames()
     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           7 : void AccessiblePageShape::dispose()
     253             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     254             : {
     255             :     OSL_TRACE ("AccessiblePageShape::dispose");
     256             : 
     257             :     // Unregister listeners.
     258           7 :     Reference<lang::XComponent> xComponent (mxShape, uno::UNO_QUERY);
     259           7 :     if (xComponent.is())
     260           0 :         xComponent->removeEventListener (this);
     261             : 
     262             :     // Cleanup.
     263           7 :     mxShape = NULL;
     264             : 
     265             :     // Call base classes.
     266           7 :     AccessibleContextBase::dispose ();
     267           7 : }
     268             : 
     269             : //=====  protected internal  ==================================================
     270             : 
     271             : OUString
     272           2 :     AccessiblePageShape::CreateAccessibleBaseName()
     273             :     throw (::com::sun::star::uno::RuntimeException)
     274             : {
     275           2 :     return OUString ("PageShape");
     276             : }
     277             : 
     278             : OUString
     279           2 :     AccessiblePageShape::CreateAccessibleName()
     280             :     throw (::com::sun::star::uno::RuntimeException)
     281             : {
     282           2 :     Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
     283             : 
     284             :     // Get name of the current slide.
     285           4 :     OUString sCurrentSlideName;
     286             :     try
     287             :     {
     288           2 :         if (xPageProperties.is())
     289             :         {
     290           2 :             xPageProperties->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName;
     291             :         }
     292             :     }
     293           0 :     catch (const beans::UnknownPropertyException&)
     294             :     {
     295             :     }
     296             : 
     297           4 :     return CreateAccessibleBaseName()+": "+sCurrentSlideName;
     298             : }
     299             : 
     300             : OUString
     301           0 :     AccessiblePageShape::CreateAccessibleDescription()
     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.11