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 
36 using namespace ::cppu;
37 using namespace ::osl;
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::accessibility;
41 
43  : mpPixelCtl(pControl)
44 {
45 }
46 
48 {
49  ensureDisposed();
50 }
51 
53 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxPixelCtlAccessible, OAccessibleSelectionHelper, OAccessibleHelper_Base )
54 
55 uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext( )
56 {
57  return this;
58 }
59 
61 {
62  ::osl::MutexGuard aGuard( m_aMutex );
63  return SvxPixelCtl::GetSquares();
64 }
65 uno::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)
72  xChild = CreateChild(i, mpPixelCtl->IndexToPoint(i));
73  return xChild;
74 }
75 
76 uno::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 );
99  return mpPixelCtl ? mpPixelCtl->GetAccessibleName() : "";
100 }
101 
102 Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
103 {
104  if (mpPixelCtl)
106  return uno::Reference<css::accessibility::XAccessibleRelationSet>();
107 }
108 
109 uno::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 
141 uno::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));
151  xRet = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
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;
166  Size aOutSize(mpPixelCtl->GetOutputSizePixel());
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 
202 void 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 
216 bool 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 
234 void 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 
281 uno::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 {
337  ensureDisposed();
338 }
339 
341 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxPixelCtlAccessibleChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
342 
343 // XAccessible
344 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
345 {
346  return this;
347 }
348 
349 uno::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 
376 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 )
377 {
378  throw lang::IndexOutOfBoundsException();
379 }
380 
381 uno::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 
407 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
408 {
409  return uno::Reference< XAccessibleRelationSet >();
410 }
411 
412 uno::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
452  return AWTRectangle(maBoundingBox);
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: */
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
css::uno::Reference< css::accessibility::XAccessible > m_xCurChild
virtual sal_Int32 SAL_CALL getForeground() override
virtual void SAL_CALL grabFocus() override
sal_Int32 nIndex
const Color & GetDialogColor() const
osl::Mutex m_aMutex
static tools::Long GetSquares()
Definition: dlgctrl.hxx:197
virtual OUString SAL_CALL getAccessibleName() override
tools::Long PointToIndex(const Point &pt) const
Definition: dlgctrl.cxx:580
virtual bool implIsSelected(sal_Int32 nAccessibleChildIndex) override
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
long Long
const StyleSettings & GetStyleSettings() const
WeakReference< XInterface > mxParent
static const AllSettings & GetSettings()
OUString GetAccessibleDescription() const
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual OUString SAL_CALL getAccessibleName() override
const Color & GetLabelTextColor() const
a11yrelationset get_accessible_relation_set() const
Definition: dlgctrl.hxx:195
tools::Long GetWidth() const
Definition: dlgctrl.hxx:198
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
rtl::Reference< SvxPixelCtlAccessible > mxParent
tools::Long ShowPosition(const Point &pt)
Definition: dlgctrl.cxx:607
virtual void SAL_CALL disposing() override
Size const & GetOutputSizePixel() const
Point IndexToPoint(tools::Long nIndex) const
Definition: dlgctrl.cxx:588
constexpr tools::Long Width() const
virtual OUString SAL_CALL getAccessibleDescription() override
tools::Long GetFocusPosIndex() const
Definition: dlgctrl.cxx:602
void ChangePixelColorOrBG(bool bPixelColorOrBG)
SvxPixelCtlAccessibleChild(SvxPixelCtl &rWindow, bool bPixelColorOrBG, const tools::Rectangle &rBounds, const rtl::Reference< SvxPixelCtlAccessible > &xParent, tools::Long nIndexInParent)
#define DBG_ASSERT(sCon, aError)
tools::Long GetHeight() const
Definition: dlgctrl.hxx:199
sal_uInt8 GetBitmapPixel(const sal_uInt16 nPixelNumber) const
Definition: dlgctrl.cxx:878
OUString GetAccessibleName() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
static sal_uInt16 GetLineCount()
Definition: dlgctrl.hxx:185
virtual OUString SAL_CALL getAccessibleDescription() override
size
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
virtual void SAL_CALL disposing() override
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 css::awt::Rectangle implGetBounds() override
implements the calculation of the bounding rectangle
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
SvxPixelCtlAccessible(SvxPixelCtl *pPixelCtl)
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override
tools::Long mnIndexInParent
index of child in parent
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual css::awt::Rectangle implGetBounds() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
css::uno::Reference< css::accessibility::XAccessible > getAccessibleParent() const
Definition: dlgctrl.hxx:193
virtual sal_Int32 SAL_CALL getForeground() override
sal_Int32 nState
css::uno::Reference< css::accessibility::XAccessible > CreateChild(tools::Long nIndex, Point mPoint)
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
virtual void SAL_CALL grabFocus() override
void NotifyChild(tools::Long nIndex, bool bSelect, bool bCheck)
void NotifyAccessibleEvent(const sal_Int16 _nEventId, const css::uno::Any &_rOldValue, const css::uno::Any &_rNewValue)
virtual void implSelect(sal_Int32 nAccessibleChildIndex, bool bSelect) override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override