1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
38 namespace accessibility
{
40 //===== internal ============================================================
42 AccessiblePageShape::AccessiblePageShape (
43 const uno::Reference
<drawing::XDrawPage
>& rxPage
,
44 const uno::Reference
<XAccessible
>& rxParent
,
45 const AccessibleShapeTreeInfo
& rShapeTreeInfo
,
47 : AccessibleShape (AccessibleShapeInfo (NULL
, rxParent
, nIndex
), rShapeTreeInfo
),
50 // The main part of the initialization is done in the init method which
51 // has to be called from this constructor's caller.
57 AccessiblePageShape::~AccessiblePageShape (void)
59 OSL_TRACE ("~AccessiblePageShape");
65 void AccessiblePageShape::Init (void)
67 AccessibleShape::Init ();
73 //===== XAccessibleContext ==================================================
76 AccessiblePageShape::getAccessibleChildCount (void)
85 /** Forward the request to the shape. Return the requested shape or throw
86 an exception for a wrong index.
88 uno::Reference
<XAccessible
> SAL_CALL
89 AccessiblePageShape::getAccessibleChild( sal_Int32
)
90 throw (::com::sun::star::uno::RuntimeException
)
92 throw lang::IndexOutOfBoundsException ("page shape has no children",
93 static_cast<uno::XWeak
*>(this));
99 //===== XAccessibleComponent ================================================
101 awt::Rectangle SAL_CALL
AccessiblePageShape::getBounds (void)
102 throw (::com::sun::star::uno::RuntimeException
)
106 awt::Rectangle aBoundingBox
;
108 if (maShapeTreeInfo
.GetViewForwarder() != NULL
)
110 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
114 awt::Point aPosition
;
117 aValue
= xSet
->getPropertyValue ("BorderLeft");
118 aValue
>>= aBoundingBox
.X
;
119 aValue
= xSet
->getPropertyValue ("BorderTop");
120 aValue
>>= aBoundingBox
.Y
;
122 aValue
= xSet
->getPropertyValue ("Width");
123 aValue
>>= aBoundingBox
.Width
;
124 aValue
= xSet
->getPropertyValue ("Height");
125 aValue
>>= aBoundingBox
.Height
;
128 // Transform coordinates from internal to pixel.
129 ::Size aPixelSize
= maShapeTreeInfo
.GetViewForwarder()->LogicToPixel (
130 ::Size (aBoundingBox
.Width
, aBoundingBox
.Height
));
131 ::Point aPixelPosition
= maShapeTreeInfo
.GetViewForwarder()->LogicToPixel (
132 ::Point (aBoundingBox
.X
, aBoundingBox
.Y
));
134 // Clip the shape's bounding box with the bounding box of its parent.
135 Reference
<XAccessibleComponent
> xParentComponent (
136 getAccessibleParent(), uno::UNO_QUERY
);
137 if (xParentComponent
.is())
139 // Make the coordinates relative to the parent.
140 awt::Point
aParentLocation (xParentComponent
->getLocationOnScreen());
141 int x
= aPixelPosition
.getX() - aParentLocation
.X
;
142 int y
= aPixelPosition
.getY() - aParentLocation
.Y
;
145 // Clip with parent (with coordinates relative to itself).
147 x
, y
, x
+ aPixelSize
.getWidth(), y
+ aPixelSize
.getHeight());
148 awt::Size
aParentSize (xParentComponent
->getSize());
149 ::Rectangle
aParentBBox (0,0, aParentSize
.Width
, aParentSize
.Height
);
150 aBBox
= aBBox
.GetIntersection (aParentBBox
);
151 aBoundingBox
= awt::Rectangle (
158 aBoundingBox
= awt::Rectangle (
159 aPixelPosition
.getX(), aPixelPosition
.getY(),
160 aPixelSize
.getWidth(), aPixelSize
.getHeight());
169 sal_Int32 SAL_CALL
AccessiblePageShape::getForeground (void)
170 throw (::com::sun::star::uno::RuntimeException
)
173 sal_Int32
nColor (0x0ffffffL
);
177 uno::Reference
<beans::XPropertySet
> aSet (mxPage
, uno::UNO_QUERY
);
181 aColor
= aSet
->getPropertyValue ("LineColor");
185 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
187 // Ignore exception and return default color.
195 /** Extract the background color from the Background property of eithe the
196 draw page or its master page.
198 sal_Int32 SAL_CALL
AccessiblePageShape::getBackground (void)
199 throw (::com::sun::star::uno::RuntimeException
)
202 sal_Int32
nColor (0x01020ffL
);
206 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
210 aBGSet
= xSet
->getPropertyValue ("Background");
211 Reference
<beans::XPropertySet
> xBGSet (aBGSet
, uno::UNO_QUERY
);
214 // Draw page has no Background property. Try the master
216 Reference
<drawing::XMasterPageTarget
> xTarget (mxPage
, uno::UNO_QUERY
);
219 xSet
= Reference
<beans::XPropertySet
> (xTarget
->getMasterPage(),
221 aBGSet
= xSet
->getPropertyValue ("Background");
222 xBGSet
= Reference
<beans::XPropertySet
> (aBGSet
, uno::UNO_QUERY
);
225 // Fetch the fill color. Has to be extended to cope with
226 // gradients, hashes, and bitmaps.
230 aColor
= xBGSet
->getPropertyValue ("FillColor");
234 OSL_TRACE ("no Background property in page");
237 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
239 OSL_TRACE ("caught excption due to unknown property");
240 // Ignore exception and return default color.
248 //===== XServiceInfo ========================================================
251 AccessiblePageShape::getImplementationName (void)
252 throw (::com::sun::star::uno::RuntimeException
)
255 return OUString("AccessiblePageShape");
261 ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
262 AccessiblePageShape::getSupportedServiceNames (void)
263 throw (::com::sun::star::uno::RuntimeException
)
266 return AccessibleShape::getSupportedServiceNames();
272 //===== lang::XEventListener ================================================
275 AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject
& aEvent
)
276 throw (::com::sun::star::uno::RuntimeException
)
279 AccessibleShape::disposing (aEvent
);
285 //===== XComponent ==========================================================
287 void AccessiblePageShape::dispose (void)
288 throw (::com::sun::star::uno::RuntimeException
)
290 OSL_TRACE ("AccessiblePageShape::dispose");
292 // Unregister listeners.
293 Reference
<lang::XComponent
> xComponent (mxShape
, uno::UNO_QUERY
);
295 xComponent
->removeEventListener (this);
300 // Call base classes.
301 AccessibleContextBase::dispose ();
307 //===== protected internal ==================================================
310 AccessiblePageShape::CreateAccessibleBaseName (void)
311 throw (::com::sun::star::uno::RuntimeException
)
313 return OUString ("PageShape");
320 AccessiblePageShape::CreateAccessibleName (void)
321 throw (::com::sun::star::uno::RuntimeException
)
323 Reference
<beans::XPropertySet
> xPageProperties (mxPage
, UNO_QUERY
);
325 // Get name of the current slide.
326 OUString sCurrentSlideName
;
329 if (xPageProperties
.is())
331 xPageProperties
->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName
;
334 catch (const beans::UnknownPropertyException
&)
338 return CreateAccessibleBaseName()+": "+sCurrentSlideName
;
345 AccessiblePageShape::CreateAccessibleDescription (void)
346 throw (::com::sun::star::uno::RuntimeException
)
348 return OUString ("Page Shape");
352 } // end of namespace accessibility
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */