1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePageShape.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include "AccessiblePageShape.hxx"
34 #include <svx/AccessibleShapeInfo.hxx>
36 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLE_ROLE_HPP_
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
39 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLE_STATE_TYPE_HPP_
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/container/XChild.hpp>
44 #include <com/sun/star/drawing/XShapes.hpp>
45 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
46 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
47 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::accessibility
;
52 using ::com::sun::star::uno::Reference
;
53 using ::rtl::OUString
;
55 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
57 namespace accessibility
{
59 //===== internal ============================================================
61 AccessiblePageShape::AccessiblePageShape (
62 const uno::Reference
<drawing::XDrawPage
>& rxPage
,
63 const uno::Reference
<XAccessible
>& rxParent
,
64 const AccessibleShapeTreeInfo
& rShapeTreeInfo
,
66 : AccessibleShape (AccessibleShapeInfo (NULL
, rxParent
, nIndex
), rShapeTreeInfo
),
69 // The main part of the initialization is done in the init method which
70 // has to be called from this constructor's caller.
76 AccessiblePageShape::~AccessiblePageShape (void)
78 OSL_TRACE ("~AccessiblePageShape");
84 void AccessiblePageShape::Init (void)
86 AccessibleShape::Init ();
92 //===== XAccessibleContext ==================================================
95 AccessiblePageShape::getAccessibleChildCount (void)
104 /** Forward the request to the shape. Return the requested shape or throw
105 an exception for a wrong index.
107 uno::Reference
<XAccessible
> SAL_CALL
108 AccessiblePageShape::getAccessibleChild( sal_Int32
)
109 throw (::com::sun::star::uno::RuntimeException
)
111 throw lang::IndexOutOfBoundsException (
112 ::rtl::OUString::createFromAscii ("page shape has no children"),
113 static_cast<uno::XWeak
*>(this));
119 //===== XAccessibleComponent ================================================
121 awt::Rectangle SAL_CALL
AccessiblePageShape::getBounds (void)
122 throw (::com::sun::star::uno::RuntimeException
)
126 awt::Rectangle aBoundingBox
;
128 if (maShapeTreeInfo
.GetViewForwarder() != NULL
)
130 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
134 awt::Point aPosition
;
137 aValue
= xSet
->getPropertyValue (
138 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("BorderLeft")));
139 aValue
>>= aBoundingBox
.X
;
140 aValue
= xSet
->getPropertyValue (
141 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("BorderTop")));
142 aValue
>>= aBoundingBox
.Y
;
144 aValue
= xSet
->getPropertyValue (
145 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Width")));
146 aValue
>>= aBoundingBox
.Width
;
147 aValue
= xSet
->getPropertyValue (
148 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Height")));
149 aValue
>>= aBoundingBox
.Height
;
152 // Transform coordinates from internal to pixel.
153 ::Size aPixelSize
= maShapeTreeInfo
.GetViewForwarder()->LogicToPixel (
154 ::Size (aBoundingBox
.Width
, aBoundingBox
.Height
));
155 ::Point aPixelPosition
= maShapeTreeInfo
.GetViewForwarder()->LogicToPixel (
156 ::Point (aBoundingBox
.X
, aBoundingBox
.Y
));
158 // Clip the shape's bounding box with the bounding box of its parent.
159 Reference
<XAccessibleComponent
> xParentComponent (
160 getAccessibleParent(), uno::UNO_QUERY
);
161 if (xParentComponent
.is())
163 // Make the coordinates relative to the parent.
164 awt::Point
aParentLocation (xParentComponent
->getLocationOnScreen());
165 int x
= aPixelPosition
.getX() - aParentLocation
.X
;
166 int y
= aPixelPosition
.getY() - aParentLocation
.Y
;
169 // Clip with parent (with coordinates relative to itself).
171 x
, y
, x
+ aPixelSize
.getWidth(), y
+ aPixelSize
.getHeight());
172 awt::Size
aParentSize (xParentComponent
->getSize());
173 ::Rectangle
aParentBBox (0,0, aParentSize
.Width
, aParentSize
.Height
);
174 aBBox
= aBBox
.GetIntersection (aParentBBox
);
175 aBoundingBox
= awt::Rectangle (
182 aBoundingBox
= awt::Rectangle (
183 aPixelPosition
.getX(), aPixelPosition
.getY(),
184 aPixelSize
.getWidth(), aPixelSize
.getHeight());
193 sal_Int32 SAL_CALL
AccessiblePageShape::getForeground (void)
194 throw (::com::sun::star::uno::RuntimeException
)
197 sal_Int32
nColor (0x0ffffffL
);
201 uno::Reference
<beans::XPropertySet
> aSet (mxPage
, uno::UNO_QUERY
);
205 aColor
= aSet
->getPropertyValue (::rtl::OUString::createFromAscii ("LineColor"));
209 catch (::com::sun::star::beans::UnknownPropertyException
)
211 // Ignore exception and return default color.
219 /** Extract the background color from the Background property of eithe the
220 draw page or its master page.
222 sal_Int32 SAL_CALL
AccessiblePageShape::getBackground (void)
223 throw (::com::sun::star::uno::RuntimeException
)
226 sal_Int32
nColor (0x01020ffL
);
230 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
234 aBGSet
= xSet
->getPropertyValue (
235 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Background")));
236 Reference
<beans::XPropertySet
> xBGSet (aBGSet
, uno::UNO_QUERY
);
239 // Draw page has no Background property. Try the master
241 Reference
<drawing::XMasterPageTarget
> xTarget (mxPage
, uno::UNO_QUERY
);
244 xSet
= Reference
<beans::XPropertySet
> (xTarget
->getMasterPage(),
246 aBGSet
= xSet
->getPropertyValue (
247 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Background")));
248 xBGSet
= Reference
<beans::XPropertySet
> (aBGSet
, uno::UNO_QUERY
);
251 // Fetch the fill color. Has to be extended to cope with
252 // gradients, hashes, and bitmaps.
256 aColor
= xBGSet
->getPropertyValue (::rtl::OUString::createFromAscii ("FillColor"));
260 OSL_TRACE ("no Background property in page");
263 catch (::com::sun::star::beans::UnknownPropertyException
)
265 OSL_TRACE ("caught excption due to unknown property");
266 // Ignore exception and return default color.
274 //===== XServiceInfo ========================================================
276 ::rtl::OUString SAL_CALL
277 AccessiblePageShape::getImplementationName (void)
278 throw (::com::sun::star::uno::RuntimeException
)
281 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessiblePageShape"));
287 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
288 AccessiblePageShape::getSupportedServiceNames (void)
289 throw (::com::sun::star::uno::RuntimeException
)
292 return AccessibleShape::getSupportedServiceNames();
298 //===== lang::XEventListener ================================================
301 AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject
& aEvent
)
302 throw (::com::sun::star::uno::RuntimeException
)
305 AccessibleShape::disposing (aEvent
);
311 //===== XComponent ==========================================================
313 void AccessiblePageShape::dispose (void)
314 throw (::com::sun::star::uno::RuntimeException
)
316 OSL_TRACE ("AccessiblePageShape::dispose");
318 // Unregister listeners.
319 Reference
<lang::XComponent
> xComponent (mxShape
, uno::UNO_QUERY
);
321 xComponent
->removeEventListener (this);
326 // Call base classes.
327 AccessibleContextBase::dispose ();
333 //===== protected internal ==================================================
336 AccessiblePageShape::CreateAccessibleBaseName (void)
337 throw (::com::sun::star::uno::RuntimeException
)
339 return ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("PageShape"));
346 AccessiblePageShape::CreateAccessibleName (void)
347 throw (::com::sun::star::uno::RuntimeException
)
349 Reference
<beans::XPropertySet
> xPageProperties (mxPage
, UNO_QUERY
);
351 // Get name of the current slide.
352 OUString sCurrentSlideName
;
355 if (xPageProperties
.is())
357 xPageProperties
->getPropertyValue(A2S("LinkDisplayName")) >>= sCurrentSlideName
;
360 catch (beans::UnknownPropertyException
&)
364 return CreateAccessibleBaseName()+A2S(": ")+sCurrentSlideName
;
371 AccessiblePageShape::CreateAccessibleDescription (void)
372 throw (::com::sun::star::uno::RuntimeException
)
374 return ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Page Shape"));
378 } // end of namespace accessibility