tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / accessibility / AccessiblePageShape.cxx
blob22721bc3b3d508a477bf7927c499006b63e6bdbb
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 <comphelper/diagnose_ex.hxx>
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>
30 #include <utility>
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 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))
48 // The main part of the initialization is done in the init method which
49 // has to be called from this constructor's caller.
52 AccessiblePageShape::~AccessiblePageShape()
56 //===== XAccessibleContext ==================================================
58 sal_Int64 SAL_CALL
59 AccessiblePageShape::getAccessibleChildCount()
61 return 0;
64 /** Forward the request to the shape. Return the requested shape or throw
65 an exception for a wrong index.
67 uno::Reference<XAccessible> SAL_CALL
68 AccessiblePageShape::getAccessibleChild( sal_Int64 )
70 throw lang::IndexOutOfBoundsException (u"page shape has no children"_ustr,
71 static_cast<uno::XWeak*>(this));
74 //===== XAccessibleComponent ================================================
76 awt::Rectangle SAL_CALL AccessiblePageShape::getBounds()
78 ThrowIfDisposed ();
80 awt::Rectangle aBoundingBox;
82 if (maShapeTreeInfo.GetViewForwarder() != nullptr)
84 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
85 if (xSet.is())
87 uno::Any aValue;
89 aValue = xSet->getPropertyValue (u"BorderLeft"_ustr);
90 aValue >>= aBoundingBox.X;
91 aValue = xSet->getPropertyValue (u"BorderTop"_ustr);
92 aValue >>= aBoundingBox.Y;
94 aValue = xSet->getPropertyValue (u"Width"_ustr);
95 aValue >>= aBoundingBox.Width;
96 aValue = xSet->getPropertyValue (u"Height"_ustr);
97 aValue >>= aBoundingBox.Height;
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));
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())
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;
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());
128 else
129 aBoundingBox = awt::Rectangle (
130 aPixelPosition.getX(), aPixelPosition.getY(),
131 aPixelSize.getWidth(), aPixelSize.getHeight());
134 return aBoundingBox;
137 sal_Int32 SAL_CALL AccessiblePageShape::getForeground()
139 ThrowIfDisposed ();
140 sal_Int32 nColor (0x0ffffffL);
144 uno::Reference<beans::XPropertySet> aSet (mxPage, uno::UNO_QUERY);
145 if (aSet.is())
147 uno::Any aColor = aSet->getPropertyValue (u"LineColor"_ustr);
148 aColor >>= nColor;
151 catch (const css::beans::UnknownPropertyException&)
153 // Ignore exception and return default color.
155 return nColor;
158 /** Extract the background color from the Background property of the
159 draw page or its master page.
161 sal_Int32 SAL_CALL AccessiblePageShape::getBackground()
163 ThrowIfDisposed ();
164 sal_Int32 nColor (0x01020ffL);
168 uno::Reference<beans::XPropertySet> xSet (mxPage, uno::UNO_QUERY);
169 if (xSet.is())
171 uno::Any aBGSet = xSet->getPropertyValue (u"Background"_ustr);
172 Reference<beans::XPropertySet> xBGSet (aBGSet, uno::UNO_QUERY);
173 if ( ! xBGSet.is())
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())
180 xSet.set(xTarget->getMasterPage(), uno::UNO_QUERY);
181 aBGSet = xSet->getPropertyValue (u"Background"_ustr);
182 xBGSet.set(aBGSet, uno::UNO_QUERY);
185 // Fetch the fill color. Has to be extended to cope with
186 // gradients, hashes, and bitmaps.
187 if (xBGSet.is())
189 uno::Any aColor = xBGSet->getPropertyValue (u"FillColor"_ustr);
190 aColor >>= nColor;
192 else
193 SAL_WARN("sd", "no Background property in page");
196 catch (const css::beans::UnknownPropertyException&)
198 TOOLS_WARN_EXCEPTION("sd", "caught exception due to unknown property");
199 // Ignore exception and return default color.
201 return nColor;
204 // XServiceInfo
206 OUString SAL_CALL
207 AccessiblePageShape::getImplementationName()
209 ThrowIfDisposed ();
210 return u"AccessiblePageShape"_ustr;
213 css::uno::Sequence< OUString> SAL_CALL
214 AccessiblePageShape::getSupportedServiceNames()
216 ThrowIfDisposed ();
217 return AccessibleShape::getSupportedServiceNames();
220 //===== XComponent ==========================================================
222 void AccessiblePageShape::dispose()
224 // Cleanup.
225 mxShape = nullptr;
227 // Call base classes.
228 AccessibleContextBase::dispose ();
231 //===== protected internal ==================================================
233 OUString
234 AccessiblePageShape::CreateAccessibleBaseName()
236 return u"PageShape"_ustr;
239 OUString
240 AccessiblePageShape::CreateAccessibleName()
242 Reference<beans::XPropertySet> xPageProperties (mxPage, UNO_QUERY);
244 // Get name of the current slide.
245 OUString sCurrentSlideName;
248 if (xPageProperties.is())
250 xPageProperties->getPropertyValue( u"LinkDisplayName"_ustr ) >>= sCurrentSlideName;
253 catch (const beans::UnknownPropertyException&)
257 return CreateAccessibleBaseName()+": "+sCurrentSlideName;
260 } // end of namespace accessibility
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */