LibreOffice Module sd (master) 1
AccessiblePageShape.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
24#include <tools/gen.hxx>
25#include <sal/log.hxx>
26
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/drawing/XMasterPageTarget.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30#include <utility>
31
32using namespace ::com::sun::star;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::accessibility;
35using ::com::sun::star::uno::Reference;
36
37namespace accessibility {
38
39//===== internal ============================================================
40
42 uno::Reference<drawing::XDrawPage> xPage,
43 const uno::Reference<XAccessible>& rxParent,
44 const AccessibleShapeTreeInfo& rShapeTreeInfo)
45 : AccessibleShape (AccessibleShapeInfo (nullptr, rxParent), rShapeTreeInfo),
46 mxPage (std::move(xPage))
47{
48 // The main part of the initialization is done in the init method which
49 // has to be called from this constructor's caller.
50}
51
52AccessiblePageShape::~AccessiblePageShape()
53{
54}
55
56//===== XAccessibleContext ==================================================
57
58sal_Int64 SAL_CALL
59 AccessiblePageShape::getAccessibleChildCount()
60{
61 return 0;
62}
63
67uno::Reference<XAccessible> SAL_CALL
68 AccessiblePageShape::getAccessibleChild( sal_Int64 )
69{
70 throw lang::IndexOutOfBoundsException ("page shape has no children",
71 static_cast<uno::XWeak*>(this));
72}
73
74//===== XAccessibleComponent ================================================
75
76awt::Rectangle SAL_CALL AccessiblePageShape::getBounds()
77{
78 ThrowIfDisposed ();
79
80 awt::Rectangle aBoundingBox;
81
82 if (maShapeTreeInfo.GetViewForwarder() != nullptr)
83 {
84 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
85 if (xSet.is())
86 {
87 uno::Any aValue;
88
89 aValue = xSet->getPropertyValue ("BorderLeft");
90 aValue >>= aBoundingBox.X;
91 aValue = xSet->getPropertyValue ("BorderTop");
92 aValue >>= aBoundingBox.Y;
93
94 aValue = xSet->getPropertyValue ("Width");
95 aValue >>= aBoundingBox.Width;
96 aValue = xSet->getPropertyValue ("Height");
97 aValue >>= aBoundingBox.Height;
98 }
99
100 // Transform coordinates from internal to pixel.
101 ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
102 ::Size (aBoundingBox.Width, aBoundingBox.Height));
103 ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
104 ::Point (aBoundingBox.X, aBoundingBox.Y));
105
106 // Clip the shape's bounding box with the bounding box of its parent.
107 Reference<XAccessibleComponent> xParentComponent (
108 getAccessibleParent(), uno::UNO_QUERY);
109 if (xParentComponent.is())
110 {
111 // Make the coordinates relative to the parent.
112 awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
113 int x = aPixelPosition.getX() - aParentLocation.X;
114 int y = aPixelPosition.getY() - aParentLocation.Y;
115
116 // Clip with parent (with coordinates relative to itself).
117 ::tools::Rectangle aBBox (
118 x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
119 awt::Size aParentSize (xParentComponent->getSize());
120 ::tools::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
121 aBBox = aBBox.GetIntersection (aParentBBox);
122 aBoundingBox = awt::Rectangle (
123 aBBox.Left(),
124 aBBox.Top(),
125 aBBox.getOpenWidth(),
126 aBBox.getOpenHeight());
127 }
128 else
129 aBoundingBox = awt::Rectangle (
130 aPixelPosition.getX(), aPixelPosition.getY(),
131 aPixelSize.getWidth(), aPixelSize.getHeight());
132 }
133
134 return aBoundingBox;
135}
136
137sal_Int32 SAL_CALL AccessiblePageShape::getForeground()
138{
139 ThrowIfDisposed ();
140 sal_Int32 nColor (0x0ffffffL);
141
142 try
143 {
144 uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
145 if (aSet.is())
146 {
147 uno::Any aColor = aSet->getPropertyValue ("LineColor");
148 aColor >>= nColor;
149 }
150 }
151 catch (const css::beans::UnknownPropertyException&)
152 {
153 // Ignore exception and return default color.
154 }
155 return nColor;
156}
157
161sal_Int32 SAL_CALL AccessiblePageShape::getBackground()
162{
163 ThrowIfDisposed ();
164 sal_Int32 nColor (0x01020ffL);
165
166 try
167 {
168 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
169 if (xSet.is())
170 {
171 uno::Any aBGSet = xSet->getPropertyValue ("Background");
172 Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
173 if ( ! xBGSet.is())
174 {
175 // Draw page has no Background property. Try the master
176 // page instead.
177 Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
178 if (xTarget.is())
179 {
180 xSet.set(xTarget->getMasterPage(), uno::UNO_QUERY);
181 aBGSet = xSet->getPropertyValue ("Background");
182 xBGSet.set(aBGSet, uno::UNO_QUERY);
183 }
184 }
185 // Fetch the fill color. Has to be extended to cope with
186 // gradients, hashes, and bitmaps.
187 if (xBGSet.is())
188 {
189 uno::Any aColor = xBGSet->getPropertyValue ("FillColor");
190 aColor >>= nColor;
191 }
192 else
193 SAL_WARN("sd", "no Background property in page");
194 }
195 }
196 catch (const css::beans::UnknownPropertyException&)
197 {
198 TOOLS_WARN_EXCEPTION("sd", "caught exception due to unknown property");
199 // Ignore exception and return default color.
200 }
201 return nColor;
202}
203
204// XServiceInfo
205
206OUString SAL_CALL
207 AccessiblePageShape::getImplementationName()
208{
209 ThrowIfDisposed ();
210 return "AccessiblePageShape";
211}
212
213css::uno::Sequence< OUString> SAL_CALL
214 AccessiblePageShape::getSupportedServiceNames()
215{
216 ThrowIfDisposed ();
217 return AccessibleShape::getSupportedServiceNames();
218}
219
220//===== XComponent ==========================================================
221
222void AccessiblePageShape::dispose()
223{
224 // Cleanup.
225 mxShape = nullptr;
226
227 // Call base classes.
228 AccessibleContextBase::dispose ();
229}
230
231//===== protected internal ==================================================
232
233OUString
234 AccessiblePageShape::CreateAccessibleBaseName()
235{
236 return "PageShape";
237}
238
239OUString
240 AccessiblePageShape::CreateAccessibleName()
241{
242 Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
243
244 // Get name of the current slide.
245 OUString sCurrentSlideName;
246 try
247 {
248 if (xPageProperties.is())
249 {
250 xPageProperties->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName;
251 }
252 }
253 catch (const beans::UnknownPropertyException&)
254 {
255 }
256
257 return CreateAccessibleBaseName()+": "+sCurrentSlideName;
258}
259
260} // end of namespace accessibility
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long getX() const
constexpr tools::Long getY() const
constexpr tools::Long getHeight() const
constexpr tools::Long getWidth() const
AccessiblePageShape(css::uno::Reference< css::drawing::XDrawPage > xPage, const css::uno::Reference< css::accessibility::XAccessible > &rxParent, const AccessibleShapeTreeInfo &rShapeTreeInfo)
Create a new accessible object that makes the given shape accessible.
tools::Rectangle GetIntersection(const tools::Rectangle &rRect) const
constexpr tools::Long Top() const
tools::Long getOpenHeight() const
tools::Long getOpenWidth() const
constexpr tools::Long Left() const
#define TOOLS_WARN_EXCEPTION(area, stream)
float y
float x
Reference< XInterface > xTarget
#define SAL_WARN(area, stream)
uno::Reference< drawing::XShape > const mxShape