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

Generated by: LCOV version 1.10