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>
23#include <com/sun/star/accessibility/AccessibleStateType.hpp>
24#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
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
54
55uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext( )
56{
57 return this;
58}
59
61{
62 ::osl::MutexGuard aGuard( m_aMutex );
64}
65uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int32 i )
66{
67 ::osl::MutexGuard aGuard( m_aMutex );
68 if ( i < 0 || i >= getAccessibleChildCount())
69 throw lang::IndexOutOfBoundsException();
70 Reference< XAccessible > xChild;
71 if (mpPixelCtl)
73 return xChild;
74}
75
76uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent( )
77{
78 ::osl::MutexGuard aGuard( m_aMutex );
79 if (mpPixelCtl)
81 return uno::Reference<css::accessibility::XAccessible>();
82}
83
85{
86 return AccessibleRole::LIST;
87}
88
90{
91
92 ::osl::MutexGuard aGuard( m_aMutex );
94}
95
97{
98 ::osl::MutexGuard aGuard( m_aMutex );
100}
101
102Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
103{
104 if (mpPixelCtl)
106 return uno::Reference<css::accessibility::XAccessibleRelationSet>();
107}
108
109uno::Reference< XAccessibleStateSet > SvxPixelCtlAccessible::getAccessibleStateSet( )
110{
111 ::osl::MutexGuard aGuard( m_aMutex );
113
114 if (mpPixelCtl)
115 {
116 const sal_Int16 aStandardStates[] =
117 {
118 AccessibleStateType::FOCUSABLE,
119 AccessibleStateType::SELECTABLE,
120 AccessibleStateType::SHOWING,
121 AccessibleStateType::VISIBLE,
122 AccessibleStateType::OPAQUE,
123 0
124 };
125
126 sal_Int16 nState = 0;
127 while (aStandardStates[nState])
128 {
129 pStateSetHelper->AddState(aStandardStates[nState++]);
130 }
131 if (mpPixelCtl->IsEnabled())
132 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
133 if (mpPixelCtl->HasFocus())
134 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
135 pStateSetHelper->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
136 }
137
138 return pStateSetHelper;
139}
140
141uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
142 const awt::Point& rPoint)
143{
144 ::osl::MutexGuard aGuard( m_aMutex );
145
146 Reference< XAccessible > xRet;
147
148 if (mpPixelCtl)
149 {
150 tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
152 }
153
154 return xRet;
155}
156
158{
159 ::osl::MutexGuard aGuard( m_aMutex );
160
161 awt::Rectangle aRet;
162
163 if (mpPixelCtl)
164 {
165 const Point aOutPos;
167
168 aRet.X = aOutPos.X();
169 aRet.Y = aOutPos.Y();
170 aRet.Width = aOutSize.Width();
171 aRet.Height = aOutSize.Height();
172 }
173
174 return aRet;
175}
176
178{
179 ::osl::MutexGuard aGuard( m_aMutex );
180 if (mpPixelCtl)
182}
183
185{
186 ::osl::MutexGuard aGuard( m_aMutex );
187
188 //see SvxPixelCtl::Paint
190 return sal_Int32(rStyles.GetLabelTextColor());
191}
192
194{
195 ::osl::MutexGuard aGuard( m_aMutex );
196
197 //see SvxPixelCtl::Paint
199 return sal_Int32(rStyles.GetDialogColor());
200}
201
202void SvxPixelCtlAccessible::implSelect(sal_Int32 nChildIndex, bool bSelect)
203{
204 ::osl::MutexGuard aGuard( m_aMutex );
205
206 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
207 throw lang::IndexOutOfBoundsException();
208
209 if (!mpPixelCtl)
210 return;
211
213 NotifyChild(nIndex, bSelect, false);
214}
215
216bool SvxPixelCtlAccessible::implIsSelected(sal_Int32 nChildIndex)
217{
218 ::osl::MutexGuard aGuard( m_aMutex );
219
220 if (!mpPixelCtl)
221 return false;
222
223 return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
224}
225
227{
228 ::osl::MutexGuard aGuard(m_aMutex);
229 OAccessibleSelectionHelper::disposing();
230 m_xCurChild.clear();
231 mpPixelCtl = nullptr;
232}
233
234void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
235{
236 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
237
238 SvxPixelCtlAccessibleChild *pChild= nullptr;
239
240 if (m_xCurChild.is())
241 {
242 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
243 DBG_ASSERT(pChild,"Child Must be Valid");
244 if (pChild->getAccessibleIndexInParent() == nIndex )
245 {
246 if (bSelect)
247 {
248 pChild->SelectChild(true);
249 }
250 if (bCheck)
251 {
252 pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
253 pChild->CheckChild();
254 }
255 return ;
256 }
257 }
258 uno::Reference <XAccessible> xNewChild =CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
259 SvxPixelCtlAccessibleChild *pNewChild= static_cast<SvxPixelCtlAccessibleChild*>(xNewChild.get());
260 DBG_ASSERT(pNewChild,"Child Must be Valid");
261
262 Any aNewValue,aOldValue;
263 aNewValue<<= xNewChild;
264 NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
265
266 if (bSelect)
267 {
268 if (pChild)
269 {
270 pChild->SelectChild(false);
271 }
272 pNewChild->SelectChild(true);
273 }
274 if (bCheck)
275 {
276 pNewChild->CheckChild();
277 }
278 m_xCurChild= xNewChild;
279}
280
281uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
282{
283 bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
285 uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
286 bPixelColorOrBG,
287 tools::Rectangle(mPoint,size),
288 this,
289 nIndex);
290
291 return xChild;
292}
293
295{
296 Any aChecked;
297 aChecked <<= AccessibleStateType::CHECKED;
298
299 if (m_bPixelColorOrBG)//Current Child State
300 {
301 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
302 }
303 else
304 {
305 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
306 }
307}
308
310{
311 Any aSelected;
312 aSelected <<= AccessibleStateType::SELECTED;
313
314 if (bSelect)
315 {
316 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
317 }
318 else
319 {
320 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
321 }
322}
323
325 const tools::Rectangle& rBoundingBox, const rtl::Reference<SvxPixelCtlAccessible>& rxParent,
326 tools::Long nIndexInParent)
327 : mrParentWindow( rWindow )
328 , mxParent(rxParent)
329 , m_bPixelColorOrBG(bPixelColorOrBG)
330 , maBoundingBox( rBoundingBox )
331 , mnIndexInParent( nIndexInParent )
332{
333}
334
336{
338}
339
342
343// XAccessible
344uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
345{
346 return this;
347}
348
349uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
350{
351 return uno::Reference< XAccessible >();
352}
353
355{
356}
357
359{
360 ::osl::MutexGuard aGuard( m_aMutex );
361 return mxParent.is() ? mxParent->getForeground() : -1;
362}
363
365{
366 ::osl::MutexGuard aGuard( m_aMutex );
367 return mxParent.is() ? mxParent->getBackground() : -1;
368}
369
370// XAccessibleContext
372{
373 return 0;
374}
375
376uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 )
377{
378 throw lang::IndexOutOfBoundsException();
379}
380
381uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
382{
383 return mxParent;
384}
385
387{
388 return AccessibleRole::CHECK_BOX;
389}
390
392{
393 ::osl::MutexGuard aGuard( m_aMutex );
394
395 return GetName();
396}
397
399{
400 ::osl::MutexGuard aGuard( m_aMutex );
401 return GetName();
402}
403
407uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
408{
409 return uno::Reference< XAccessibleRelationSet >();
410}
411
412uno::Reference< XAccessibleStateSet > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet()
413{
414 ::osl::MutexGuard aGuard( m_aMutex );
416
417 if (!rBHelper.bDisposed)
418 {
419
420 pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
421 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
422 pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
423 pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
424 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
425 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
426
428 if ( nIndex == mnIndexInParent)
429 {
430 pStateSetHelper->AddState( AccessibleStateType::SELECTED );
431 }
433 {
434 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
435 }
436 }
437 else
438 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
439
440 return pStateSetHelper;
441}
442
444{
445 OAccessibleComponentHelper::disposing();
446 mxParent.clear();
447}
448
450{
451 // no guard necessary, because no one changes maBoundingBox after creating it
453}
454
456{
457 sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
458 sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
459
460 OUString str = "("
461 + OUString::number(nXIndex)
462 + ","
463 + OUString::number(nYIndex)
464 + ")";
465 return str;
466}
467
468/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
WeakReference< XInterface > 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 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
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 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 css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
virtual OUString SAL_CALL getAccessibleName() 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 getAccessibleChildCount() override
SvxPixelCtlAccessibleChild(SvxPixelCtl &rWindow, bool bPixelColorOrBG, const tools::Rectangle &rBounds, const rtl::Reference< SvxPixelCtlAccessible > &xParent, tools::Long nIndexInParent)
virtual sal_Int32 SAL_CALL getForeground() override
virtual sal_Int32 SAL_CALL getAccessibleChildCount() 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 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 sal_Int16 SAL_CALL getAccessibleRole() override
css::uno::Reference< css::accessibility::XAccessible > CreateChild(tools::Long nIndex, Point mPoint)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
css::uno::Reference< css::accessibility::XAccessible > m_xCurChild
virtual bool implIsSelected(sal_Int32 nAccessibleChildIndex) override
void NotifyChild(tools::Long nIndex, bool bSelect, bool bCheck)
virtual OUString SAL_CALL getAccessibleName() override
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
virtual void implSelect(sal_Int32 nAccessibleChildIndex, bool bSelect) override
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParent() const
Definition: dlgctrl.hxx:193
Point IndexToPoint(tools::Long nIndex) const
Definition: dlgctrl.cxx:600
a11yrelationset get_accessible_relation_set() const
Definition: dlgctrl.hxx:195
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:198
static sal_uInt16 GetLineCount()
Definition: dlgctrl.hxx:185
tools::Long GetHeight() const
Definition: dlgctrl.hxx:199
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:197
void NotifyAccessibleEvent(const sal_Int16 _nEventId, const css::uno::Any &_rOldValue, const css::uno::Any &_rNewValue)
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
OUString GetAccessibleName() const
OUString GetAccessibleDescription() const
Size const & GetOutputSizePixel() const
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
#define DBG_ASSERT(sCon, aError)
sal_Int32 nState
std::mutex m_aMutex
sal_Int32 nIndex
size
int i
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
long Long