update dev300-m58
[ooovba.git] / sd / source / ui / accessibility / AccessiblePageShape.cxx
blob6aff48bfb11213104b3a44d67a53524dc92ec722
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 $
10 * $Revision: 1.18 $
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>
38 #endif
39 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLE_STATE_TYPE_HPP_
40 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
41 #endif
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,
61 long nIndex)
62 : AccessibleShape (AccessibleShapeInfo (NULL, rxParent, nIndex), rShapeTreeInfo),
63 mxPage (rxPage)
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 ==================================================
90 sal_Int32 SAL_CALL
91 AccessiblePageShape::getAccessibleChildCount (void)
92 throw ()
94 return 0;
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)
120 ThrowIfDisposed ();
122 awt::Rectangle aBoundingBox;
124 if (maShapeTreeInfo.GetViewForwarder() != NULL)
126 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
127 if (xSet.is())
129 uno::Any aValue;
130 awt::Point aPosition;
131 awt::Size aSize;
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).
166 ::Rectangle aBBox (
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 (
172 aBBox.getX(),
173 aBBox.getY(),
174 aBBox.getWidth(),
175 aBBox.getHeight());
177 else
178 aBoundingBox = awt::Rectangle (
179 aPixelPosition.getX(), aPixelPosition.getY(),
180 aPixelSize.getWidth(), aPixelSize.getHeight());
183 return aBoundingBox;
189 sal_Int32 SAL_CALL AccessiblePageShape::getForeground (void)
190 throw (::com::sun::star::uno::RuntimeException)
192 ThrowIfDisposed ();
193 sal_Int32 nColor (0x0ffffffL);
197 uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
198 if (aSet.is())
200 uno::Any aColor;
201 aColor = aSet->getPropertyValue (::rtl::OUString::createFromAscii ("LineColor"));
202 aColor >>= nColor;
205 catch (::com::sun::star::beans::UnknownPropertyException)
207 // Ignore exception and return default color.
209 return nColor;
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)
221 ThrowIfDisposed ();
222 sal_Int32 nColor (0x01020ffL);
226 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
227 if (xSet.is())
229 uno::Any aBGSet;
230 aBGSet = xSet->getPropertyValue (
231 ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("Background")));
232 Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
233 if ( ! xBGSet.is())
235 // Draw page has no Background property. Try the master
236 // page instead.
237 Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
238 if (xTarget.is())
240 xSet = Reference<beans::XPropertySet> (xTarget->getMasterPage(),
241 uno::UNO_QUERY);
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.
249 if (xBGSet.is())
251 uno::Any aColor;
252 aColor = xBGSet->getPropertyValue (::rtl::OUString::createFromAscii ("FillColor"));
253 aColor >>= nColor;
255 else
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.
264 return nColor;
270 //===== XServiceInfo ========================================================
272 ::rtl::OUString SAL_CALL
273 AccessiblePageShape::getImplementationName (void)
274 throw (::com::sun::star::uno::RuntimeException)
276 ThrowIfDisposed ();
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)
287 ThrowIfDisposed ();
288 return AccessibleShape::getSupportedServiceNames();
294 //===== lang::XEventListener ================================================
296 void SAL_CALL
297 AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject& aEvent)
298 throw (::com::sun::star::uno::RuntimeException)
300 ThrowIfDisposed ();
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);
316 if (xComponent.is())
317 xComponent->removeEventListener (this);
319 // Cleanup.
320 mxShape = NULL;
322 // Call base classes.
323 AccessibleContextBase::dispose ();
329 //===== protected internal ==================================================
331 ::rtl::OUString
332 AccessiblePageShape::CreateAccessibleBaseName (void)
333 throw (::com::sun::star::uno::RuntimeException)
335 return ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("PageShape"));
341 ::rtl::OUString
342 AccessiblePageShape::CreateAccessibleName (void)
343 throw (::com::sun::star::uno::RuntimeException)
345 return CreateAccessibleBaseName();
351 ::rtl::OUString
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