LibreOffice Module svx (master) 1
svxpixelctlaccessiblecontext.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
20#include <com/sun/star/accessibility/AccessibleRole.hpp>
21#include <com/sun/star/accessibility/AccessibleEventId.hpp>
22#include <com/sun/star/accessibility/AccessibleStateType.hpp>
23#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25#include <utility>
26#include <vcl/svapp.hxx>
27#include <vcl/settings.hxx>
28#include <osl/mutex.hxx>
29#include <tools/debug.hxx>
30#include <tools/gen.hxx>
31
32#include <svx/dlgctrl.hxx>
33
35
36using namespace ::cppu;
37using namespace ::osl;
38using namespace ::com::sun::star;
39using namespace ::com::sun::star::uno;
40using namespace ::com::sun::star::accessibility;
41
43 : mpPixelCtl(pControl)
44{
45}
46
48{
49 ensureDisposed();
50}
51
52uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext( )
53{
54 return this;
55}
56
58{
60}
61uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int64 i )
62{
63 ::osl::MutexGuard aGuard( m_aMutex );
64 if ( i < 0 || i >= getAccessibleChildCount())
65 throw lang::IndexOutOfBoundsException();
66 Reference< XAccessible > xChild;
67 if (mpPixelCtl)
69 return xChild;
70}
71
72uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent( )
73{
74 ::osl::MutexGuard aGuard( m_aMutex );
75 if (mpPixelCtl)
77 return uno::Reference<css::accessibility::XAccessible>();
78}
79
81{
82 return AccessibleRole::LIST;
83}
84
86{
87
88 ::osl::MutexGuard aGuard( m_aMutex );
90}
91
93{
94 ::osl::MutexGuard aGuard( m_aMutex );
96}
97
98Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
99{
100 if (mpPixelCtl)
102 return uno::Reference<css::accessibility::XAccessibleRelationSet>();
103}
104
106{
107 ::osl::MutexGuard aGuard( m_aMutex );
108 sal_Int64 nStateSet = 0;
109
110 if (mpPixelCtl)
111 {
112 nStateSet |=
113 AccessibleStateType::FOCUSABLE |
114 AccessibleStateType::SELECTABLE |
115 AccessibleStateType::SHOWING |
116 AccessibleStateType::VISIBLE |
117 AccessibleStateType::OPAQUE;
118 if (mpPixelCtl->IsEnabled())
119 nStateSet |= AccessibleStateType::ENABLED;
120 if (mpPixelCtl->HasFocus())
121 nStateSet |= AccessibleStateType::FOCUSED;
122 nStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
123 }
124
125 return nStateSet;
126}
127
128uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
129 const awt::Point& rPoint)
130{
131 ::osl::MutexGuard aGuard( m_aMutex );
132
133 Reference< XAccessible > xRet;
134
135 if (mpPixelCtl)
136 {
137 tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
139 }
140
141 return xRet;
142}
143
145{
146 ::osl::MutexGuard aGuard( m_aMutex );
147
148 awt::Rectangle aRet;
149
150 if (mpPixelCtl)
151 {
152 const Point aOutPos;
154
155 aRet.X = aOutPos.X();
156 aRet.Y = aOutPos.Y();
157 aRet.Width = aOutSize.Width();
158 aRet.Height = aOutSize.Height();
159 }
160
161 return aRet;
162}
163
165{
166 ::osl::MutexGuard aGuard( m_aMutex );
167 if (mpPixelCtl)
169}
170
172{
173 ::osl::MutexGuard aGuard( m_aMutex );
174
175 //see SvxPixelCtl::Paint
177 return sal_Int32(rStyles.GetLabelTextColor());
178}
179
181{
182 ::osl::MutexGuard aGuard( m_aMutex );
183
184 //see SvxPixelCtl::Paint
186 return sal_Int32(rStyles.GetDialogColor());
187}
188
189void SvxPixelCtlAccessible::implSelect(sal_Int64 nChildIndex, bool bSelect)
190{
191 ::osl::MutexGuard aGuard( m_aMutex );
192
193 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
194 throw lang::IndexOutOfBoundsException();
195
196 if (!mpPixelCtl)
197 return;
198
200 NotifyChild(nIndex, bSelect, false);
201}
202
203bool SvxPixelCtlAccessible::implIsSelected(sal_Int64 nChildIndex)
204{
205 ::osl::MutexGuard aGuard( m_aMutex );
206
207 if (!mpPixelCtl)
208 return false;
209
210 return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
211}
212
214{
215 ::osl::MutexGuard aGuard(m_aMutex);
216 OAccessibleSelectionHelper::disposing();
217 m_xCurChild.clear();
218 mpPixelCtl = nullptr;
219}
220
221void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
222{
223 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
224
225 SvxPixelCtlAccessibleChild *pChild= nullptr;
226
227 if (m_xCurChild.is())
228 {
229 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
230 DBG_ASSERT(pChild,"Child Must be Valid");
231 if (pChild->getAccessibleIndexInParent() == nIndex )
232 {
233 if (bSelect)
234 {
235 pChild->SelectChild(true);
236 }
237 if (bCheck)
238 {
239 pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
240 pChild->CheckChild();
241 }
242 return ;
243 }
244 }
245 uno::Reference <XAccessible> xNewChild =CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
246 SvxPixelCtlAccessibleChild *pNewChild= static_cast<SvxPixelCtlAccessibleChild*>(xNewChild.get());
247 DBG_ASSERT(pNewChild,"Child Must be Valid");
248
249 Any aNewValue,aOldValue;
250 aNewValue<<= xNewChild;
251 NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
252
253 if (bSelect)
254 {
255 if (pChild)
256 {
257 pChild->SelectChild(false);
258 }
259 pNewChild->SelectChild(true);
260 }
261 if (bCheck)
262 {
263 pNewChild->CheckChild();
264 }
265 m_xCurChild= xNewChild;
266}
267
268uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
269{
270 bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
272 uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
273 bPixelColorOrBG,
274 tools::Rectangle(mPoint,size),
275 this,
276 nIndex);
277
278 return xChild;
279}
280
282{
283 Any aChecked;
284 aChecked <<= AccessibleStateType::CHECKED;
285
286 if (m_bPixelColorOrBG)//Current Child State
287 {
288 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
289 }
290 else
291 {
292 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
293 }
294}
295
297{
298 Any aSelected;
299 aSelected <<= AccessibleStateType::SELECTED;
300
301 if (bSelect)
302 {
303 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
304 }
305 else
306 {
307 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
308 }
309}
310
312 const tools::Rectangle& rBoundingBox, rtl::Reference<SvxPixelCtlAccessible> xParent,
313 tools::Long nIndexInParent)
314 : mrParentWindow( rWindow )
315 , mxParent(std::move(xParent))
316 , m_bPixelColorOrBG(bPixelColorOrBG)
317 , maBoundingBox( rBoundingBox )
318 , mnIndexInParent( nIndexInParent )
319{
320}
321
323{
324 ensureDisposed();
325}
326
327// XAccessible
328uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
329{
330 return this;
331}
332
333uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
334{
335 return uno::Reference< XAccessible >();
336}
337
339{
340}
341
343{
344 ::osl::MutexGuard aGuard( m_aMutex );
345 return mxParent.is() ? mxParent->getForeground() : -1;
346}
347
349{
350 ::osl::MutexGuard aGuard( m_aMutex );
351 return mxParent.is() ? mxParent->getBackground() : -1;
352}
353
354// XAccessibleContext
356{
357 return 0;
358}
359
360uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int64 )
361{
362 throw lang::IndexOutOfBoundsException();
363}
364
365uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
366{
367 return mxParent;
368}
369
371{
372 return AccessibleRole::CHECK_BOX;
373}
374
376{
377 ::osl::MutexGuard aGuard( m_aMutex );
378
379 return GetName();
380}
381
383{
384 ::osl::MutexGuard aGuard( m_aMutex );
385 return GetName();
386}
387
391uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
392{
393 return uno::Reference< XAccessibleRelationSet >();
394}
395
397{
398 ::osl::MutexGuard aGuard( m_aMutex );
399 sal_Int64 nStateSet = 0;
400
401 if (!rBHelper.bDisposed)
402 {
403 nStateSet |= AccessibleStateType::TRANSIENT;
404 nStateSet |= AccessibleStateType::ENABLED;
405 nStateSet |= AccessibleStateType::OPAQUE;
406 nStateSet |= AccessibleStateType::SELECTABLE;
407 nStateSet |= AccessibleStateType::SHOWING;
408 nStateSet |= AccessibleStateType::VISIBLE;
409
411 if ( nIndex == mnIndexInParent)
412 {
413 nStateSet |= AccessibleStateType::SELECTED;
414 }
416 {
417 nStateSet |= AccessibleStateType::CHECKED;
418 }
419 }
420 else
421 nStateSet |= AccessibleStateType::DEFUNC;
422
423 return nStateSet;
424}
425
427{
428 OAccessibleComponentHelper::disposing();
429 mxParent.clear();
430}
431
433{
434 // no guard necessary, because no one changes maBoundingBox after creating it
436}
437
439{
440 sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
441 sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
442
443 OUString str = "("
444 + OUString::number(nXIndex)
445 + ","
446 + OUString::number(nYIndex)
447 + ")";
448 return str;
449}
450
451/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unotools::WeakReference< AnimationNode > mxParent
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetLabelTextColor() const
const Color & GetDialogColor() const
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual void SAL_CALL grabFocus() override
tools::Long mnIndexInParent
index of child in parent
rtl::Reference< SvxPixelCtlAccessible > mxParent
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual OUString SAL_CALL getAccessibleDescription() override
SvxPixelCtlAccessibleChild(SvxPixelCtl &rWindow, bool bPixelColorOrBG, const tools::Rectangle &rBounds, rtl::Reference< SvxPixelCtlAccessible > xParent, tools::Long nIndexInParent)
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual void SAL_CALL disposing() override
void ChangePixelColorOrBG(bool bPixelColorOrBG)
virtual sal_Int32 SAL_CALL getBackground() override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
Return empty uno::Reference to indicate that the relation set is not supported.
virtual sal_Int32 SAL_CALL getForeground() override
virtual OUString SAL_CALL getAccessibleName() override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual css::awt::Rectangle implGetBounds() override
implements the calculation of the bounding rectangle
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual sal_Int32 SAL_CALL getForeground() override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual void SAL_CALL grabFocus() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual void SAL_CALL disposing() override
virtual css::awt::Rectangle implGetBounds() override
SvxPixelCtlAccessible(SvxPixelCtl *pPixelCtl)
virtual bool implIsSelected(sal_Int64 nAccessibleChildIndex) override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual void implSelect(sal_Int64 nAccessibleChildIndex, bool bSelect) override
css::uno::Reference< css::accessibility::XAccessible > CreateChild(tools::Long nIndex, Point mPoint)
css::uno::Reference< css::accessibility::XAccessible > m_xCurChild
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
void NotifyChild(tools::Long nIndex, bool bSelect, bool bCheck)
virtual OUString SAL_CALL getAccessibleName() override
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParent() const
Definition: dlgctrl.hxx:191
Point IndexToPoint(tools::Long nIndex) const
Definition: dlgctrl.cxx:600
a11yrelationset get_accessible_relation_set() const
Definition: dlgctrl.hxx:193
sal_uInt8 GetBitmapPixel(const sal_uInt16 nPixelNumber) const
Definition: dlgctrl.cxx:900
tools::Long ShowPosition(const Point &pt)
Definition: dlgctrl.cxx:619
tools::Long GetWidth() const
Definition: dlgctrl.hxx:196
static sal_uInt16 GetLineCount()
Definition: dlgctrl.hxx:183
tools::Long GetHeight() const
Definition: dlgctrl.hxx:197
tools::Long PointToIndex(const Point &pt) const
Definition: dlgctrl.cxx:592
tools::Long GetFocusPosIndex() const
Definition: dlgctrl.cxx:614
static tools::Long GetSquares()
Definition: dlgctrl.hxx:195
OUString GetAccessibleName() const
OUString GetAccessibleDescription() const
Size const & GetOutputSizePixel() const
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
#define DBG_ASSERT(sCon, aError)
std::mutex m_aMutex
sal_Int32 nIndex
size
int i
long Long