bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / ui / accessibility / AccessiblePageShape.cxx
blob6390ce18e3b58023e641f9de99ef27630b3cba3d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <svx/IAccessibleViewForwarder.hxx>
23 #include <tools/diagnose_ex.h>
24 #include <tools/gen.hxx>
25 #include <sal/log.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
29 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::accessibility;
34 using ::com::sun::star::uno::Reference;
36 namespace accessibility {
38 //===== internal ============================================================
40 AccessiblePageShape::AccessiblePageShape (
41 const uno::Reference<drawing::XDrawPage>& rxPage,
42 const uno::Reference<XAccessible>& rxParent,
43 const AccessibleShapeTreeInfo& rShapeTreeInfo)
44 : AccessibleShape (AccessibleShapeInfo (nullptr, rxParent), rShapeTreeInfo),
45 mxPage (rxPage)
47 // The main part of the initialization is done in the init method which
48 // has to be called from this constructor's caller.
51 AccessiblePageShape::~AccessiblePageShape()
55 //===== XAccessibleContext ==================================================
57 sal_Int32 SAL_CALL
58 AccessiblePageShape::getAccessibleChildCount()
60 return 0;
63 /** Forward the request to the shape. Return the requested shape or throw
64 an exception for a wrong index.
66 uno::Reference<XAccessible> SAL_CALL
67 AccessiblePageShape::getAccessibleChild( sal_Int32 )
69 throw lang::IndexOutOfBoundsException ("page shape has no children",
70 static_cast<uno::XWeak*>(this));
73 //===== XAccessibleComponent ================================================
75 awt::Rectangle SAL_CALL AccessiblePageShape::getBounds()
77 ThrowIfDisposed ();
79 awt::Rectangle aBoundingBox;
81 if (maShapeTreeInfo.GetViewForwarder() != nullptr)
83 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
84 if (xSet.is())
86 uno::Any aValue;
88 aValue = xSet->getPropertyValue ("BorderLeft");
89 aValue >>= aBoundingBox.X;
90 aValue = xSet->getPropertyValue ("BorderTop");
91 aValue >>= aBoundingBox.Y;
93 aValue = xSet->getPropertyValue ("Width");
94 aValue >>= aBoundingBox.Width;
95 aValue = xSet->getPropertyValue ("Height");
96 aValue >>= aBoundingBox.Height;
99 // Transform coordinates from internal to pixel.
100 ::Size aPixelSize = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
101 ::Size (aBoundingBox.Width, aBoundingBox.Height));
102 ::Point aPixelPosition = maShapeTreeInfo.GetViewForwarder()->LogicToPixel (
103 ::Point (aBoundingBox.X, aBoundingBox.Y));
105 // Clip the shape's bounding box with the bounding box of its parent.
106 Reference<XAccessibleComponent> xParentComponent (
107 getAccessibleParent(), uno::UNO_QUERY);
108 if (xParentComponent.is())
110 // Make the coordinates relative to the parent.
111 awt::Point aParentLocation (xParentComponent->getLocationOnScreen());
112 int x = aPixelPosition.getX() - aParentLocation.X;
113 int y = aPixelPosition.getY() - aParentLocation.Y;
115 // Clip with parent (with coordinates relative to itself).
116 ::tools::Rectangle aBBox (
117 x, y, x + aPixelSize.getWidth(), y + aPixelSize.getHeight());
118 awt::Size aParentSize (xParentComponent->getSize());
119 ::tools::Rectangle aParentBBox (0,0, aParentSize.Width, aParentSize.Height);
120 aBBox = aBBox.GetIntersection (aParentBBox);
121 aBoundingBox = awt::Rectangle (
122 aBBox.getX(),
123 aBBox.getY(),
124 aBBox.getWidth(),
125 aBBox.getHeight());
127 else
128 aBoundingBox = awt::Rectangle (
129 aPixelPosition.getX(), aPixelPosition.getY(),
130 aPixelSize.getWidth(), aPixelSize.getHeight());
133 return aBoundingBox;
136 sal_Int32 SAL_CALL AccessiblePageShape::getForeground()
138 ThrowIfDisposed ();
139 sal_Int32 nColor (0x0ffffffL);
143 uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
144 if (aSet.is())
146 uno::Any aColor = aSet->getPropertyValue ("LineColor");
147 aColor >>= nColor;
150 catch (const css::beans::UnknownPropertyException&)
152 // Ignore exception and return default color.
154 return nColor;
157 /** Extract the background color from the Background property of the
158 draw page or its master page.
160 sal_Int32 SAL_CALL AccessiblePageShape::getBackground()
162 ThrowIfDisposed ();
163 sal_Int32 nColor (0x01020ffL);
167 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
168 if (xSet.is())
170 uno::Any aBGSet = xSet->getPropertyValue ("Background");
171 Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
172 if ( ! xBGSet.is())
174 // Draw page has no Background property. Try the master
175 // page instead.
176 Reference<drawing::XMasterPageTarget> xTarget (mxPage, uno::UNO_QUERY);
177 if (xTarget.is())
179 xSet.set(xTarget->getMasterPage(), uno::UNO_QUERY);
180 aBGSet = xSet->getPropertyValue ("Background");
181 xBGSet.set(aBGSet, uno::UNO_QUERY);
184 // Fetch the fill color. Has to be extended to cope with
185 // gradients, hashes, and bitmaps.
186 if (xBGSet.is())
188 uno::Any aColor = xBGSet->getPropertyValue ("FillColor");
189 aColor >>= nColor;
191 else
192 SAL_WARN("sd", "no Background property in page");
195 catch (const css::beans::UnknownPropertyException&)
197 TOOLS_WARN_EXCEPTION("sd", "caught exception due to unknown property");
198 // Ignore exception and return default color.
200 return nColor;
203 // XServiceInfo
205 OUString SAL_CALL
206 AccessiblePageShape::getImplementationName()
208 ThrowIfDisposed ();
209 return "AccessiblePageShape";
212 css::uno::Sequence< OUString> SAL_CALL
213 AccessiblePageShape::getSupportedServiceNames()
215 ThrowIfDisposed ();
216 return AccessibleShape::getSupportedServiceNames();
219 //===== XComponent ==========================================================
221 void AccessiblePageShape::dispose()
223 // Cleanup.
224 mxShape = nullptr;
226 // Call base classes.
227 AccessibleContextBase::dispose ();
230 //===== protected internal ==================================================
232 OUString
233 AccessiblePageShape::CreateAccessibleBaseName()
235 return "PageShape";
238 OUString
239 AccessiblePageShape::CreateAccessibleName()
241 Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
243 // Get name of the current slide.
244 OUString sCurrentSlideName;
247 if (xPageProperties.is())
249 xPageProperties->getPropertyValue( "LinkDisplayName" ) >>= sCurrentSlideName;
252 catch (const beans::UnknownPropertyException&)
256 return CreateAccessibleBaseName()+": "+sCurrentSlideName;
259 } // end of namespace accessibility
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */