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
;
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
,
46 : AccessibleShape (AccessibleShapeInfo (NULL
, rxParent
, nIndex
), rShapeTreeInfo
),
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 ==================================================
66 AccessiblePageShape::getAccessibleChildCount()
67 throw (std::exception
)
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
)
90 awt::Rectangle aBoundingBox
;
92 if (maShapeTreeInfo
.GetViewForwarder() != NULL
)
94 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
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).
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 (
141 aBoundingBox
= awt::Rectangle (
142 aPixelPosition
.getX(), aPixelPosition
.getY(),
143 aPixelSize
.getWidth(), aPixelSize
.getHeight());
149 sal_Int32 SAL_CALL
AccessiblePageShape::getForeground()
150 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
153 sal_Int32
nColor (0x0ffffffL
);
157 uno::Reference
<beans::XPropertySet
> aSet (mxPage
, uno::UNO_QUERY
);
161 aColor
= aSet
->getPropertyValue ("LineColor");
165 catch (const ::com::sun::star::beans::UnknownPropertyException
&)
167 // Ignore exception and return default color.
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
)
179 sal_Int32
nColor (0x01020ffL
);
183 uno::Reference
<beans::XPropertySet
> xSet (mxPage
, uno::UNO_QUERY
);
187 aBGSet
= xSet
->getPropertyValue ("Background");
188 Reference
<beans::XPropertySet
> xBGSet (aBGSet
, uno::UNO_QUERY
);
191 // Draw page has no Background property. Try the master
193 Reference
<drawing::XMasterPageTarget
> xTarget (mxPage
, uno::UNO_QUERY
);
196 xSet
= Reference
<beans::XPropertySet
> (xTarget
->getMasterPage(),
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.
207 aColor
= xBGSet
->getPropertyValue ("FillColor");
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.
225 AccessiblePageShape::getImplementationName()
226 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
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
)
237 return AccessibleShape::getSupportedServiceNames();
240 //===== lang::XEventListener ================================================
243 AccessiblePageShape::disposing (const ::com::sun::star::lang::EventObject
& aEvent
)
244 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
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
);
260 xComponent
->removeEventListener (this);
265 // Call base classes.
266 AccessibleContextBase::dispose ();
269 //===== protected internal ==================================================
272 AccessiblePageShape::CreateAccessibleBaseName()
273 throw (::com::sun::star::uno::RuntimeException
)
275 return OUString ("PageShape");
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
;
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: */