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::accessibility
;
51 using ::com::sun::star::uno::Reference
;
53 namespace accessibility
{
55 //===== internal ============================================================
57 AccessiblePageShape::AccessiblePageShape (
58 const uno::Reference
<drawing::XDrawPage
>& rxPage
,
59 const uno::Reference
<XAccessible
>& rxParent
,
60 const AccessibleShapeTreeInfo
& rShapeTreeInfo
,
62 : AccessibleShape (AccessibleShapeInfo (NULL
, rxParent
, nIndex
), rShapeTreeInfo
),
65 // The main part of the initialization is done in the init method which
66 // has to be called from this constructor's caller.
72 AccessiblePageShape::~AccessiblePageShape (void)
74 OSL_TRACE ("~AccessiblePageShape");
80 void AccessiblePageShape::Init (void)
82 AccessibleShape::Init ();
88 //===== XAccessibleContext ==================================================
91 AccessiblePageShape::getAccessibleChildCount (void)
100 /** Forward the request to the shape. Return the requested shape or throw
101 an exception for a wrong index.
103 uno::Reference
<XAccessible
> SAL_CALL
104 AccessiblePageShape::getAccessibleChild( sal_Int32
)
105 throw (::com::sun::star::uno::RuntimeException
)
107 throw lang::IndexOutOfBoundsException (
108 ::rtl::OUString::createFromAscii ("page shape has no children"),
109 static_cast<uno::XWeak
*>(this));
115 //===== XAccessibleComponent ================================================
117 awt::Rectangle SAL_CALL
AccessiblePageShape::getBounds (void)
118 throw (::com::sun::star::uno::RuntimeException
)
122 awt::Rectangle aBoundingBox
;
124 if (maShapeTreeInfo
.GetViewForwarder() != NULL
)
126 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
130 awt::Point aPosition
;
133 aValue
= xSet
->getPropertyValue (
134 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("BorderLeft")));
135 aValue
>>= aBoundingBox
.X
;
136 aValue
= xSet
->getPropertyValue (
137 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("BorderTop")));
138 aValue
>>= aBoundingBox
.Y
;
140 aValue
= xSet
->getPropertyValue (
141 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Width")));
142 aValue
>>= aBoundingBox
.Width
;
143 aValue
= xSet
->getPropertyValue (
144 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Height")));
145 aValue
>>= aBoundingBox
.Height
;
148 // Transform coordinates from internal to pixel.
149 ::Size aPixelSize
= maShapeTreeInfo
.GetViewForwarder()->LogicToPixel (
150 ::Size (aBoundingBox
.Width
, aBoundingBox
.Height
));
151 ::Point aPixelPosition
= maShapeTreeInfo
.GetViewForwarder()->LogicToPixel (
152 ::Point (aBoundingBox
.X
, aBoundingBox
.Y
));
154 // Clip the shape's bounding box with the bounding box of its parent.
155 Reference
<XAccessibleComponent
> xParentComponent (
156 getAccessibleParent(), uno::UNO_QUERY
);
157 if (xParentComponent
.is())
159 // Make the coordinates relative to the parent.
160 awt::Point
aParentLocation (xParentComponent
->getLocationOnScreen());
161 int x
= aPixelPosition
.getX() - aParentLocation
.X
;
162 int y
= aPixelPosition
.getY() - aParentLocation
.Y
;
165 // Clip with parent (with coordinates relative to itself).
167 x
, y
, x
+ aPixelSize
.getWidth(), y
+ aPixelSize
.getHeight());
168 awt::Size
aParentSize (xParentComponent
->getSize());
169 ::Rectangle
aParentBBox (0,0, aParentSize
.Width
, aParentSize
.Height
);
170 aBBox
= aBBox
.GetIntersection (aParentBBox
);
171 aBoundingBox
= awt::Rectangle (
178 aBoundingBox
= awt::Rectangle (
179 aPixelPosition
.getX(), aPixelPosition
.getY(),
180 aPixelSize
.getWidth(), aPixelSize
.getHeight());
189 sal_Int32 SAL_CALL
AccessiblePageShape::getForeground (void)
190 throw (::com::sun::star::uno::RuntimeException
)
193 sal_Int32
nColor (0x0ffffffL
);
197 uno::Reference
<beans::XPropertySet
> aSet (mxPage
, uno::UNO_QUERY
);
201 aColor
= aSet
->getPropertyValue (::rtl::OUString::createFromAscii ("LineColor"));
205 catch (::com::sun::star::beans::UnknownPropertyException
)
207 // Ignore exception and return default color.
215 /** Extract the background color from the Background property of eithe the
216 draw page or its master page.
218 sal_Int32 SAL_CALL
AccessiblePageShape::getBackground (void)
219 throw (::com::sun::star::uno::RuntimeException
)
222 sal_Int32
nColor (0x01020ffL
);
226 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
230 aBGSet
= xSet
->getPropertyValue (
231 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Background")));
232 Reference
<beans::XPropertySet
> xBGSet (aBGSet
, uno::UNO_QUERY
);
235 // Draw page has no Background property. Try the master
237 Reference
<drawing::XMasterPageTarget
> xTarget (mxPage
, uno::UNO_QUERY
);
240 xSet
= Reference
<beans::XPropertySet
> (xTarget
->getMasterPage(),
242 aBGSet
= xSet
->getPropertyValue (
243 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Background")));
244 xBGSet
= Reference
<beans::XPropertySet
> (aBGSet
, uno::UNO_QUERY
);
247 // Fetch the fill color. Has to be extended to cope with
248 // gradients, hashes, and bitmaps.
252 aColor
= xBGSet
->getPropertyValue (::rtl::OUString::createFromAscii ("FillColor"));
256 OSL_TRACE ("no Background property in page");
259 catch (::com::sun::star::beans::UnknownPropertyException
)
261 OSL_TRACE ("caught excption due to unknown property");
262 // Ignore exception and return default color.
270 //===== XServiceInfo ========================================================
272 ::rtl::OUString SAL_CALL
273 AccessiblePageShape::getImplementationName (void)
274 throw (::com::sun::star::uno::RuntimeException
)
277 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessiblePageShape"));
283 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
284 AccessiblePageShape::getSupportedServiceNames (void)
285 throw (::com::sun::star::uno::RuntimeException
)
288 return AccessibleShape::getSupportedServiceNames();
294 //===== lang::XEventListener ================================================
297 AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject
& aEvent
)
298 throw (::com::sun::star::uno::RuntimeException
)
301 AccessibleShape::disposing (aEvent
);
307 //===== XComponent ==========================================================
309 void AccessiblePageShape::dispose (void)
310 throw (::com::sun::star::uno::RuntimeException
)
312 OSL_TRACE ("AccessiblePageShape::dispose");
314 // Unregister listeners.
315 Reference
<lang::XComponent
> xComponent (mxShape
, uno::UNO_QUERY
);
317 xComponent
->removeEventListener (this);
322 // Call base classes.
323 AccessibleContextBase::dispose ();
329 //===== protected internal ==================================================
332 AccessiblePageShape::CreateAccessibleBaseName (void)
333 throw (::com::sun::star::uno::RuntimeException
)
335 return ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("PageShape"));
342 AccessiblePageShape::CreateAccessibleName (void)
343 throw (::com::sun::star::uno::RuntimeException
)
345 return CreateAccessibleBaseName();
352 AccessiblePageShape::CreateAccessibleDescription (void)
353 throw (::com::sun::star::uno::RuntimeException
)
355 return ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Page Shape"));
359 } // end of namespace accessibility