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