LCOV - code coverage report
Current view: top level - sd/source/ui/accessibility - AccessiblePageShape.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 63 112 56.2 %
Date: 2012-08-25 Functions: 10 16 62.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 38 148 25.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "AccessiblePageShape.hxx"
      30                 :            : #include <svx/AccessibleShapeInfo.hxx>
      31                 :            : 
      32                 :            : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      33                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      34                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      35                 :            : #include <com/sun/star/container/XChild.hpp>
      36                 :            : #include <com/sun/star/drawing/XShapes.hpp>
      37                 :            : #include <com/sun/star/drawing/XShapeDescriptor.hpp>
      38                 :            : #include <com/sun/star/drawing/XMasterPageTarget.hpp>
      39                 :            : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
      40                 :            : 
      41                 :            : using namespace ::com::sun::star;
      42                 :            : using namespace ::com::sun::star::uno;
      43                 :            : using namespace ::com::sun::star::accessibility;
      44                 :            : using ::com::sun::star::uno::Reference;
      45                 :            : using ::rtl::OUString;
      46                 :            : 
      47                 :            : 
      48                 :            : namespace accessibility {
      49                 :            : 
      50                 :            : //=====  internal  ============================================================
      51                 :            : 
      52                 :         14 : AccessiblePageShape::AccessiblePageShape (
      53                 :            :     const uno::Reference<drawing::XDrawPage>& rxPage,
      54                 :            :     const uno::Reference<XAccessible>& rxParent,
      55                 :            :     const AccessibleShapeTreeInfo& rShapeTreeInfo,
      56                 :            :     long nIndex)
      57                 :            :     : AccessibleShape (AccessibleShapeInfo (NULL, rxParent, nIndex), rShapeTreeInfo),
      58 [ +  - ][ +  - ]:         14 :       mxPage (rxPage)
                 [ +  - ]
      59                 :            : {
      60                 :            :     // The main part of the initialization is done in the init method which
      61                 :            :     // has to be called from this constructor's caller.
      62                 :         14 : }
      63                 :            : 
      64                 :            : 
      65                 :            : 
      66                 :            : 
      67                 :         14 : AccessiblePageShape::~AccessiblePageShape (void)
      68                 :            : {
      69                 :            :     OSL_TRACE ("~AccessiblePageShape");
      70         [ -  + ]:         28 : }
      71                 :            : 
      72                 :            : 
      73                 :            : 
      74                 :            : 
      75                 :         14 : void AccessiblePageShape::Init (void)
      76                 :            : {
      77                 :         14 :     AccessibleShape::Init ();
      78                 :         14 : }
      79                 :            : 
      80                 :            : 
      81                 :            : 
      82                 :            : 
      83                 :            : //=====  XAccessibleContext  ==================================================
      84                 :            : 
      85                 :            : sal_Int32 SAL_CALL
      86                 :          8 :        AccessiblePageShape::getAccessibleChildCount (void)
      87                 :            :     throw ()
      88                 :            : {
      89                 :          8 :     return 0;
      90                 :            : }
      91                 :            : 
      92                 :            : 
      93                 :            : 
      94                 :            : 
      95                 :            : /** Forward the request to the shape.  Return the requested shape or throw
      96                 :            :     an exception for a wrong index.
      97                 :            : */
      98                 :            : uno::Reference<XAccessible> SAL_CALL
      99                 :          0 :     AccessiblePageShape::getAccessibleChild( sal_Int32 )
     100                 :            :     throw (::com::sun::star::uno::RuntimeException)
     101                 :            : {
     102                 :            :     throw lang::IndexOutOfBoundsException ("page shape has no children",
     103 [ #  # ][ #  # ]:          0 :         static_cast<uno::XWeak*>(this));
     104                 :            : }
     105                 :            : 
     106                 :            : 
     107                 :            : 
     108                 :            : 
     109                 :            : //=====  XAccessibleComponent  ================================================
     110                 :            : 
     111                 :         34 : awt::Rectangle SAL_CALL AccessiblePageShape::getBounds (void)
     112                 :            :     throw (::com::sun::star::uno::RuntimeException)
     113                 :            : {
     114                 :         34 :     ThrowIfDisposed ();
     115                 :            : 
     116                 :         34 :     awt::Rectangle aBoundingBox;
     117                 :            : 
     118         [ +  - ]:         34 :     if (maShapeTreeInfo.GetViewForwarder() != NULL)
     119                 :            :     {
     120         [ +  - ]:         34 :         uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
     121         [ +  - ]:         34 :         if (xSet.is())
     122                 :            :         {
     123                 :         34 :             uno::Any aValue;
     124                 :         34 :             awt::Point aPosition;
     125                 :         34 :             awt::Size aSize;
     126                 :            : 
     127 [ +  - ][ +  - ]:         34 :             aValue = xSet->getPropertyValue ("BorderLeft");
     128                 :         34 :             aValue >>= aBoundingBox.X;
     129 [ +  - ][ +  - ]:         34 :             aValue = xSet->getPropertyValue ("BorderTop");
     130                 :         34 :             aValue >>= aBoundingBox.Y;
     131                 :            : 
     132 [ +  - ][ +  - ]:         34 :             aValue = xSet->getPropertyValue ("Width");
     133                 :         34 :             aValue >>= aBoundingBox.Width;
     134 [ +  - ][ +  - ]:         34 :             aValue = xSet->getPropertyValue ("Height");
     135                 :         34 :             aValue >>= aBoundingBox.Height;
     136                 :            :         }
     137                 :            : 
     138                 :            :         // Transform coordinates from internal to pixel.
     139         [ +  - ]:         34 :         ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
     140         [ +  - ]:         34 :             ::Size (aBoundingBox.Width, aBoundingBox.Height));
     141         [ +  - ]:         34 :         ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
     142         [ +  - ]:         34 :             ::Point (aBoundingBox.X, aBoundingBox.Y));
     143                 :            : 
     144                 :            :         // Clip the shape's bounding box with the bounding box of its parent.
     145                 :            :         Reference<XAccessibleComponent> xParentComponent (
     146 [ +  - ][ +  - ]:         34 :             getAccessibleParent(), uno::UNO_QUERY);
     147         [ +  - ]:         34 :         if (xParentComponent.is())
     148                 :            :         {
     149                 :            :             // Make the coordinates relative to the parent.
     150 [ +  - ][ +  - ]:         34 :             awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
     151                 :         34 :             int x = aPixelPosition.getX() - aParentLocation.X;
     152                 :         34 :             int y = aPixelPosition.getY() - aParentLocation.Y;
     153                 :            : 
     154                 :            : 
     155                 :            :             // Clip with parent (with coordinates relative to itself).
     156                 :            :             ::Rectangle aBBox (
     157         [ +  - ]:         34 :                 x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
     158 [ +  - ][ +  - ]:         34 :             awt::Size aParentSize (xParentComponent->getSize());
     159         [ +  - ]:         34 :             ::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
     160         [ +  - ]:         34 :             aBBox = aBBox.GetIntersection (aParentBBox);
     161                 :            :             aBoundingBox = awt::Rectangle (
     162                 :         34 :                 aBBox.getX(),
     163                 :         34 :                 aBBox.getY(),
     164                 :         34 :                 aBBox.getWidth(),
     165                 :         68 :                 aBBox.getHeight());
     166                 :            :         }
     167                 :            :         else
     168                 :            :             aBoundingBox = awt::Rectangle (
     169                 :          0 :                 aPixelPosition.getX(), aPixelPosition.getY(),
     170                 :         34 :                 aPixelSize.getWidth(), aPixelSize.getHeight());
     171                 :            :     }
     172                 :            : 
     173                 :         34 :     return aBoundingBox;
     174                 :            : }
     175                 :            : 
     176                 :            : 
     177                 :            : 
     178                 :            : 
     179                 :          0 : sal_Int32 SAL_CALL AccessiblePageShape::getForeground (void)
     180                 :            :     throw (::com::sun::star::uno::RuntimeException)
     181                 :            : {
     182         [ #  # ]:          0 :     ThrowIfDisposed ();
     183                 :          0 :     sal_Int32 nColor (0x0ffffffL);
     184                 :            : 
     185                 :            :     try
     186                 :            :     {
     187         [ #  # ]:          0 :         uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
     188         [ #  # ]:          0 :         if (aSet.is())
     189                 :            :         {
     190                 :          0 :             uno::Any aColor;
     191 [ #  # ][ #  # ]:          0 :             aColor = aSet->getPropertyValue ("LineColor");
     192                 :          0 :             aColor >>= nColor;
     193         [ #  # ]:          0 :         }
     194                 :            :     }
     195         [ #  # ]:          0 :     catch (const ::com::sun::star::beans::UnknownPropertyException&)
     196                 :            :     {
     197                 :            :         // Ignore exception and return default color.
     198                 :            :     }
     199                 :          0 :     return nColor;
     200                 :            : }
     201                 :            : 
     202                 :            : 
     203                 :            : 
     204                 :            : 
     205                 :            : /** Extract the background color from the Background property of eithe the
     206                 :            :     draw page or its master page.
     207                 :            : */
     208                 :          0 : sal_Int32 SAL_CALL AccessiblePageShape::getBackground (void)
     209                 :            :     throw (::com::sun::star::uno::RuntimeException)
     210                 :            : {
     211         [ #  # ]:          0 :     ThrowIfDisposed ();
     212                 :          0 :     sal_Int32 nColor (0x01020ffL);
     213                 :            : 
     214                 :            :     try
     215                 :            :     {
     216         [ #  # ]:          0 :         uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
     217         [ #  # ]:          0 :         if (xSet.is())
     218                 :            :         {
     219                 :          0 :             uno::Any aBGSet;
     220 [ #  # ][ #  # ]:          0 :             aBGSet = xSet->getPropertyValue ("Background");
     221         [ #  # ]:          0 :             Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
     222         [ #  # ]:          0 :             if ( ! xBGSet.is())
     223                 :            :             {
     224                 :            :                 // Draw page has no Background property.  Try the master
     225                 :            :                 // page instead.
     226         [ #  # ]:          0 :                 Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
     227         [ #  # ]:          0 :                 if (xTarget.is())
     228                 :            :                 {
     229         [ #  # ]:          0 :                     xSet = Reference<beans::XPropertySet> (xTarget->getMasterPage(),
     230 [ #  # ][ #  # ]:          0 :                         uno::UNO_QUERY);
                 [ #  # ]
     231 [ #  # ][ #  # ]:          0 :                     aBGSet = xSet->getPropertyValue ("Background");
     232 [ #  # ][ #  # ]:          0 :                     xBGSet = Reference<beans::XPropertySet> (aBGSet, uno::UNO_QUERY);
     233                 :          0 :                 }
     234                 :            :             }
     235                 :            :             // Fetch the fill color.  Has to be extended to cope with
     236                 :            :             // gradients, hashes, and bitmaps.
     237         [ #  # ]:          0 :             if (xBGSet.is())
     238                 :            :             {
     239                 :          0 :                 uno::Any aColor;
     240 [ #  # ][ #  # ]:          0 :                 aColor = xBGSet->getPropertyValue ("FillColor");
     241                 :          0 :                 aColor >>= nColor;
     242                 :            :             }
     243                 :            :             else
     244                 :          0 :                 OSL_TRACE ("no Background property in page");
     245         [ #  # ]:          0 :         }
     246                 :            :     }
     247         [ #  # ]:          0 :     catch (const ::com::sun::star::beans::UnknownPropertyException&)
     248                 :            :     {
     249                 :            :         OSL_TRACE ("caught excption due to unknown property");
     250                 :            :         // Ignore exception and return default color.
     251                 :            :     }
     252                 :          0 :     return nColor;
     253                 :            : }
     254                 :            : 
     255                 :            : 
     256                 :            : 
     257                 :            : 
     258                 :            : //=====  XServiceInfo  ========================================================
     259                 :            : 
     260                 :            : ::rtl::OUString SAL_CALL
     261                 :          2 :     AccessiblePageShape::getImplementationName (void)
     262                 :            :     throw (::com::sun::star::uno::RuntimeException)
     263                 :            : {
     264                 :          2 :     ThrowIfDisposed ();
     265                 :          2 :     return ::rtl::OUString("AccessiblePageShape");
     266                 :            : }
     267                 :            : 
     268                 :            : 
     269                 :            : 
     270                 :            : 
     271                 :            : ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
     272                 :          0 :     AccessiblePageShape::getSupportedServiceNames (void)
     273                 :            :     throw (::com::sun::star::uno::RuntimeException)
     274                 :            : {
     275                 :          0 :     ThrowIfDisposed ();
     276                 :          0 :     return AccessibleShape::getSupportedServiceNames();
     277                 :            : }
     278                 :            : 
     279                 :            : 
     280                 :            : 
     281                 :            : 
     282                 :            : //=====  lang::XEventListener  ================================================
     283                 :            : 
     284                 :            : void SAL_CALL
     285                 :          0 :     AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject& aEvent)
     286                 :            :     throw (::com::sun::star::uno::RuntimeException)
     287                 :            : {
     288                 :          0 :     ThrowIfDisposed ();
     289                 :          0 :     AccessibleShape::disposing (aEvent);
     290                 :          0 : }
     291                 :            : 
     292                 :            : 
     293                 :            : 
     294                 :            : 
     295                 :            : //=====  XComponent  ==========================================================
     296                 :            : 
     297                 :         14 : void AccessiblePageShape::dispose (void)
     298                 :            :     throw (::com::sun::star::uno::RuntimeException)
     299                 :            : {
     300                 :            :     OSL_TRACE ("AccessiblePageShape::dispose");
     301                 :            : 
     302                 :            :     // Unregister listeners.
     303         [ +  - ]:         14 :     Reference<lang::XComponent> xComponent (mxShape, uno::UNO_QUERY);
     304         [ -  + ]:         14 :     if (xComponent.is())
     305 [ #  # ][ #  # ]:          0 :         xComponent->removeEventListener (this);
                 [ #  # ]
     306                 :            : 
     307                 :            :     // Cleanup.
     308         [ +  - ]:         14 :     mxShape = NULL;
     309                 :            : 
     310                 :            :     // Call base classes.
     311         [ +  - ]:         14 :     AccessibleContextBase::dispose ();
     312                 :         14 : }
     313                 :            : 
     314                 :            : 
     315                 :            : 
     316                 :            : 
     317                 :            : //=====  protected internal  ==================================================
     318                 :            : 
     319                 :            : ::rtl::OUString
     320                 :          4 :     AccessiblePageShape::CreateAccessibleBaseName (void)
     321                 :            :     throw (::com::sun::star::uno::RuntimeException)
     322                 :            : {
     323                 :          4 :     return ::rtl::OUString ("PageShape");
     324                 :            : }
     325                 :            : 
     326                 :            : 
     327                 :            : 
     328                 :            : 
     329                 :            : ::rtl::OUString
     330                 :          4 :     AccessiblePageShape::CreateAccessibleName (void)
     331                 :            :     throw (::com::sun::star::uno::RuntimeException)
     332                 :            : {
     333         [ +  - ]:          4 :     Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
     334                 :            : 
     335                 :            :     // Get name of the current slide.
     336                 :          4 :     OUString sCurrentSlideName;
     337                 :            :     try
     338                 :            :     {
     339         [ +  - ]:          4 :         if (xPageProperties.is())
     340                 :            :         {
     341 [ +  - ][ +  - ]:          4 :             xPageProperties->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName;
                 [ #  # ]
     342                 :            :         }
     343                 :            :     }
     344         [ #  # ]:          0 :     catch (const beans::UnknownPropertyException&)
     345                 :            :     {
     346                 :            :     }
     347                 :            : 
     348         [ +  - ]:          4 :     return CreateAccessibleBaseName()+": "+sCurrentSlideName;
     349                 :            : }
     350                 :            : 
     351                 :            : 
     352                 :            : 
     353                 :            : 
     354                 :            : ::rtl::OUString
     355                 :          0 :     AccessiblePageShape::CreateAccessibleDescription (void)
     356                 :            :     throw (::com::sun::star::uno::RuntimeException)
     357                 :            : {
     358                 :          0 :     return ::rtl::OUString ("Page Shape");
     359                 :            : }
     360                 :            : 
     361                 :            : 
     362                 :            : } // end of namespace accessibility
     363                 :            : 
     364                 :            : 
     365                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10