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