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