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{
59 ::osl::MutexGuard aGuard( m_aMutex );
61}
62uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int64 i )
63{
64 ::osl::MutexGuard aGuard( m_aMutex );
65 if ( i < 0 || i >= getAccessibleChildCount())
66 throw lang::IndexOutOfBoundsException();
67 Reference< XAccessible > xChild;
68 if (mpPixelCtl)
70 return xChild;
71}
72
73uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent( )
74{
75 ::osl::MutexGuard aGuard( m_aMutex );
76 if (mpPixelCtl)
78 return uno::Reference<css::accessibility::XAccessible>();
79}
80
82{
83 return AccessibleRole::LIST;
84}
85
87{
88
89 ::osl::MutexGuard aGuard( m_aMutex );
91}
92
94{
95 ::osl::MutexGuard aGuard( m_aMutex );
97}
98
99Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
100{
101 if (mpPixelCtl)
103 return uno::Reference<css::accessibility::XAccessibleRelationSet>();
104}
105
107{
108 ::osl::MutexGuard aGuard( m_aMutex );
109 sal_Int64 nStateSet = 0;
110
111 if (mpPixelCtl)
112 {
113 nStateSet |=
114 AccessibleStateType::FOCUSABLE |
115 AccessibleStateType::SELECTABLE |
116 AccessibleStateType::SHOWING |
117 AccessibleStateType::VISIBLE |
118 AccessibleStateType::OPAQUE;
119 if (mpPixelCtl->IsEnabled())
120 nStateSet |= AccessibleStateType::ENABLED;
121 if (mpPixelCtl->HasFocus())
122 nStateSet |= AccessibleStateType::FOCUSED;
123 nStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
124 }
125
126 return nStateSet;
127}
128
129uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
130 const awt::Point& rPoint)
131{
132 ::osl::MutexGuard aGuard( m_aMutex );
133
134 Reference< XAccessible > xRet;
135
136 if (mpPixelCtl)
137 {
138 tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
140 }
141
142 return xRet;
143}
144
146{
147 ::osl::MutexGuard aGuard( m_aMutex );
148
149 awt::Rectangle aRet;
150
151 if (mpPixelCtl)
152 {
153 const Point aOutPos;
155
156 aRet.X = aOutPos.X();
157 aRet.Y = aOutPos.Y();
158 aRet.Width = aOutSize.Width();
159 aRet.Height = aOutSize.Height();
160 }
161
162 return aRet;
163}
164
166{
167 ::osl::MutexGuard aGuard( m_aMutex );
168 if (mpPixelCtl)
170}
171
173{
174 ::osl::MutexGuard aGuard( m_aMutex );
175
176 //see SvxPixelCtl::Paint
178 return sal_Int32(rStyles.GetLabelTextColor());
179}
180
182{
183 ::osl::MutexGuard aGuard( m_aMutex );
184
185 //see SvxPixelCtl::Paint
187 return sal_Int32(rStyles.GetDialogColor());
188}
189
190void SvxPixelCtlAccessible::implSelect(sal_Int64 nChildIndex, bool bSelect)
191{
192 ::osl::MutexGuard aGuard( m_aMutex );
193
194 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
195 throw lang::IndexOutOfBoundsException();
196
197 if (!mpPixelCtl)
198 return;
199
201 NotifyChild(nIndex, bSelect, false);
202}
203
204bool SvxPixelCtlAccessible::implIsSelected(sal_Int64 nChildIndex)
205{
206 ::osl::MutexGuard aGuard( m_aMutex );
207
208 if (!mpPixelCtl)
209 return false;
210
211 return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
212}
213
215{
216 ::osl::MutexGuard aGuard(m_aMutex);
217 OAccessibleSelectionHelper::disposing();
218 m_xCurChild.clear();
219 mpPixelCtl = nullptr;
220}
221
222void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
223{
224 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
225
226 SvxPixelCtlAccessibleChild *pChild= nullptr;
227
228 if (m_xCurChild.is())
229 {
230 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
231 DBG_ASSERT(pChild,"Child Must be Valid");
232 if (pChild->getAccessibleIndexInParent() == nIndex )
233 {
234 if (bSelect)
235 {
236 pChild->SelectChild(true);
237 }
238 if (bCheck)
239 {
240 pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
241 pChild->CheckChild();
242 }
243 return ;
244 }
245 }
246 uno::Reference <XAccessible> xNewChild =CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
247 SvxPixelCtlAccessibleChild *pNewChild= static_cast<SvxPixelCtlAccessibleChild*>(xNewChild.get());
248 DBG_ASSERT(pNewChild,"Child Must be Valid");
249
250 Any aNewValue,aOldValue;
251 aNewValue<<= xNewChild;
252 NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
253
254 if (bSelect)
255 {
256 if (pChild)
257 {
258 pChild->SelectChild(false);
259 }
260 pNewChild->SelectChild(true);
261 }
262 if (bCheck)
263 {
264 pNewChild->CheckChild();
265 }
266 m_xCurChild= xNewChild;
267}
268
269uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
270{
271 bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
273 uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
274 bPixelColorOrBG,
275 tools::Rectangle(mPoint,size),
276 this,
277 nIndex);
278
279 return xChild;
280}
281
283{
284 Any aChecked;
285 aChecked <<= AccessibleStateType::CHECKED;
286
287 if (m_bPixelColorOrBG)//Current Child State
288 {
289 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
290 }
291 else
292 {
293 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
294 }
295}
296
298{
299 Any aSelected;
300 aSelected <<= AccessibleStateType::SELECTED;
301
302 if (bSelect)
303 {
304 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
305 }
306 else
307 {
308 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
309 }
310}
311
313 const tools::Rectangle& rBoundingBox, rtl::Reference<SvxPixelCtlAccessible> xParent,
314 tools::Long nIndexInParent)
315 : mrParentWindow( rWindow )
316 , mxParent(std::move(xParent))
317 , m_bPixelColorOrBG(bPixelColorOrBG)
318 , maBoundingBox( rBoundingBox )
319 , mnIndexInParent( nIndexInParent )
320{
321}
322
324{
325 ensureDisposed();
326}
327
328// XAccessible
329uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
330{
331 return this;
332}
333
334uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
335{
336 return uno::Reference< XAccessible >();
337}
338
340{
341}
342
344{
345 ::osl::MutexGuard aGuard( m_aMutex );
346 return mxParent.is() ? mxParent->getForeground() : -1;
347}
348
350{
351 ::osl::MutexGuard aGuard( m_aMutex );
352 return mxParent.is() ? mxParent->getBackground() : -1;
353}
354
355// XAccessibleContext
357{
358 return 0;
359}
360
361uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int64 )
362{
363 throw lang::IndexOutOfBoundsException();
364}
365
366uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
367{
368 return mxParent;
369}
370
372{
373 return AccessibleRole::CHECK_BOX;
374}
375
377{
378 ::osl::MutexGuard aGuard( m_aMutex );
379
380 return GetName();
381}
382
384{
385 ::osl::MutexGuard aGuard( m_aMutex );
386 return GetName();
387}
388
392uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
393{
394 return uno::Reference< XAccessibleRelationSet >();
395}
396
398{
399 ::osl::MutexGuard aGuard( m_aMutex );
400 sal_Int64 nStateSet = 0;
401
402 if (!rBHelper.bDisposed)
403 {
404 nStateSet |= AccessibleStateType::TRANSIENT;
405 nStateSet |= AccessibleStateType::ENABLED;
406 nStateSet |= AccessibleStateType::OPAQUE;
407 nStateSet |= AccessibleStateType::SELECTABLE;
408 nStateSet |= AccessibleStateType::SHOWING;
409 nStateSet |= AccessibleStateType::VISIBLE;
410
412 if ( nIndex == mnIndexInParent)
413 {
414 nStateSet |= AccessibleStateType::SELECTED;
415 }
417 {
418 nStateSet |= AccessibleStateType::CHECKED;
419 }
420 }
421 else
422 nStateSet |= AccessibleStateType::DEFUNC;
423
424 return nStateSet;
425}
426
428{
429 OAccessibleComponentHelper::disposing();
430 mxParent.clear();
431}
432
434{
435 // no guard necessary, because no one changes maBoundingBox after creating it
437}
438
440{
441 sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
442 sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
443
444 OUString str = "("
445 + OUString::number(nXIndex)
446 + ","
447 + OUString::number(nYIndex)
448 + ")";
449 return str;
450}
451
452/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unotools::WeakReference< AnimationNode > mxParent
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
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