bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / accessibility / AccessiblePageShape.cxx
blob9254f3babd1b4020f3929bd8c9d7df00b1258463
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "AccessiblePageShape.hxx"
21 #include <svx/AccessibleShapeInfo.hxx>
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/container/XChild.hpp>
27 #include <com/sun/star/drawing/XShapes.hpp>
28 #include <com/sun/star/drawing/XShapeDescriptor.hpp>
29 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
30 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::accessibility;
35 using ::com::sun::star::uno::Reference;
37 namespace accessibility {
39 //===== internal ============================================================
41 AccessiblePageShape::AccessiblePageShape (
42 const uno::Reference<drawing::XDrawPage>& rxPage,
43 const uno::Reference<XAccessible>& rxParent,
44 const AccessibleShapeTreeInfo& rShapeTreeInfo,
45 long nIndex)
46 : AccessibleShape (AccessibleShapeInfo (NULL, rxParent, nIndex), rShapeTreeInfo),
47 mxPage (rxPage)
49 // The main part of the initialization is done in the init method which
50 // has to be called from this constructor's caller.
53 AccessiblePageShape::~AccessiblePageShape()
55 OSL_TRACE ("~AccessiblePageShape");
58 void AccessiblePageShape::Init()
60 AccessibleShape::Init ();
63 //===== XAccessibleContext ==================================================
65 sal_Int32 SAL_CALL
66 AccessiblePageShape::getAccessibleChildCount()
67 throw (std::exception)
69 return 0;
72 /** Forward the request to the shape. Return the requested shape or throw
73 an exception for a wrong index.
75 uno::Reference<XAccessible> SAL_CALL
76 AccessiblePageShape::getAccessibleChild( sal_Int32 )
77 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
79 throw lang::IndexOutOfBoundsException ("page shape has no children",
80 static_cast<uno::XWeak*>(this));
83 //===== XAccessibleComponent ================================================
85 awt::Rectangle SAL_CALL AccessiblePageShape::getBounds()
86 throw (::com::sun::star::uno::RuntimeException, std::exception)
88 ThrowIfDisposed ();
90 awt::Rectangle aBoundingBox;
92 if (maShapeTreeInfo.GetViewForwarder() != NULL)
94 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
95 if (xSet.is())
97 uno::Any aValue;
98 awt::Point aPosition;
99 awt::Size aSize;
101 aValue = xSet->getPropertyValue ("BorderLeft");
102 aValue >>= aBoundingBox.X;
103 aValue = xSet->getPropertyValue ("BorderTop");
104 aValue >>= aBoundingBox.Y;
106 aValue = xSet->getPropertyValue ("Width");
107 aValue >>= aBoundingBox.Width;
108 aValue = xSet->getPropertyValue ("Height");
109 aValue >>= aBoundingBox.Height;
112 // Transform coordinates from internal to pixel.
113 ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
114 ::Size (aBoundingBox.Width, aBoundingBox.Height));
115 ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
116 ::Point (aBoundingBox.X, aBoundingBox.Y));
118 // Clip the shape's bounding box with the bounding box of its parent.
119 Reference<XAccessibleComponent> xParentComponent (
120 getAccessibleParent(), uno::UNO_QUERY);
121 if (xParentComponent.is())
123 // Make the coordinates relative to the parent.
124 awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
125 int x = aPixelPosition.getX() - aParentLocation.X;
126 int y = aPixelPosition.getY() - aParentLocation.Y;
128 // Clip with parent (with coordinates relative to itself).
129 ::Rectangle aBBox (
130 x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
131 awt::Size aParentSize (xParentComponent->getSize());
132 ::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
133 aBBox = aBBox.GetIntersection (aParentBBox);
134 aBoundingBox = awt::Rectangle (
135 aBBox.getX(),
136 aBBox.getY(),
137 aBBox.getWidth(),
138 aBBox.getHeight());
140 else
141 aBoundingBox = awt::Rectangle (
142 aPixelPosition.getX(), aPixelPosition.getY(),
143 aPixelSize.getWidth(), aPixelSize.getHeight());
146 return aBoundingBox;
149 sal_Int32 SAL_CALL AccessiblePageShape::getForeground()
150 throw (::com::sun::star::uno::RuntimeException, std::exception)
152 ThrowIfDisposed ();
153 sal_Int32 nColor (0x0ffffffL);
157 uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
158 if (aSet.is())
160 uno::Any aColor;
161 aColor = aSet->getPropertyValue ("LineColor");
162 aColor >>= nColor;
165 catch (const ::com::sun::star::beans::UnknownPropertyException&)
167 // Ignore exception and return default color.
169 return nColor;
172 /** Extract the background color from the Background property of eithe the
173 draw page or its master page.
175 sal_Int32 SAL_CALL AccessiblePageShape::getBackground()
176 throw (::com::sun::star::uno::RuntimeException, std::exception)
178 ThrowIfDisposed ();
179 sal_Int32 nColor (0x01020ffL);
183 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
184 if (xSet.is())
186 uno::Any aBGSet;
187 aBGSet = xSet->getPropertyValue ("Background");
188 Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
189 if ( ! xBGSet.is())
191 // Draw page has no Background property. Try the master
192 // page instead.
193 Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
194 if (xTarget.is())
196 xSet = Reference<beans::XPropertySet> (xTarget->getMasterPage(),
197 uno::UNO_QUERY);
198 aBGSet = xSet->getPropertyValue ("Background");
199 xBGSet = Reference<beans::XPropertySet> (aBGSet, uno::UNO_QUERY);
202 // Fetch the fill color. Has to be extended to cope with
203 // gradients, hashes, and bitmaps.
204 if (xBGSet.is())
206 uno::Any aColor;
207 aColor = xBGSet->getPropertyValue ("FillColor");
208 aColor >>= nColor;
210 else
211 OSL_TRACE ("no Background property in page");
214 catch (const ::com::sun::star::beans::UnknownPropertyException&)
216 OSL_TRACE ("caught exception due to unknown property");
217 // Ignore exception and return default color.
219 return nColor;
222 // XServiceInfo
224 OUString SAL_CALL
225 AccessiblePageShape::getImplementationName()
226 throw (::com::sun::star::uno::RuntimeException, std::exception)
228 ThrowIfDisposed ();
229 return OUString("AccessiblePageShape");
232 ::com::sun::star::uno::Sequence< OUString> SAL_CALL
233 AccessiblePageShape::getSupportedServiceNames()
234 throw (::com::sun::star::uno::RuntimeException, std::exception)
236 ThrowIfDisposed ();
237 return AccessibleShape::getSupportedServiceNames();
240 //===== lang::XEventListener ================================================
242 void SAL_CALL
243 AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject& aEvent)
244 throw (::com::sun::star::uno::RuntimeException, std::exception)
246 ThrowIfDisposed ();
247 AccessibleShape::disposing (aEvent);
250 //===== XComponent ==========================================================
252 void AccessiblePageShape::dispose()
253 throw (::com::sun::star::uno::RuntimeException, std::exception)
255 OSL_TRACE ("AccessiblePageShape::dispose");
257 // Unregister listeners.
258 Reference<lang::XComponent> xComponent (mxShape, uno::UNO_QUERY);
259 if (xComponent.is())
260 xComponent->removeEventListener (this);
262 // Cleanup.
263 mxShape = NULL;
265 // Call base classes.
266 AccessibleContextBase::dispose ();
269 //===== protected internal ==================================================
271 OUString
272 AccessiblePageShape::CreateAccessibleBaseName()
273 throw (::com::sun::star::uno::RuntimeException)
275 return OUString ("PageShape");
278 OUString
279 AccessiblePageShape::CreateAccessibleName()
280 throw (::com::sun::star::uno::RuntimeException)
282 Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
284 // Get name of the current slide.
285 OUString sCurrentSlideName;
288 if (xPageProperties.is())
290 xPageProperties->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName;
293 catch (const beans::UnknownPropertyException&)
297 return CreateAccessibleBaseName()+": "+sCurrentSlideName;
300 OUString
301 AccessiblePageShape::CreateAccessibleDescription()
302 throw (::com::sun::star::uno::RuntimeException)
304 return OUString ("Page Shape");
307 } // end of namespace accessibility
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */