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  uno::Reference< XAccessibleStateSet > xRet = pStateSetHelper;
114 
115  if (mpPixelCtl)
116  {
117  const sal_Int16 aStandardStates[] =
118  {
119  AccessibleStateType::FOCUSABLE,
120  AccessibleStateType::SELECTABLE,
121  AccessibleStateType::SHOWING,
122  AccessibleStateType::VISIBLE,
123  AccessibleStateType::OPAQUE,
124  0
125  };
126 
127  sal_Int16 nState = 0;
128  while (aStandardStates[nState])
129  {
130  pStateSetHelper->AddState(aStandardStates[nState++]);
131  }
132  if (mpPixelCtl->IsEnabled())
133  pStateSetHelper->AddState(AccessibleStateType::ENABLED);
134  if (mpPixelCtl->HasFocus())
135  pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
136  pStateSetHelper->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
137  }
138 
139  return xRet;
140 }
141 
142 uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
143  const awt::Point& rPoint)
144 {
145  ::osl::MutexGuard aGuard( m_aMutex );
146 
147  Reference< XAccessible > xRet;
148 
149  if (mpPixelCtl)
150  {
151  long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
152  xRet = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
153  }
154 
155  return xRet;
156 }
157 
159 {
160  ::osl::MutexGuard aGuard( m_aMutex );
161 
162  awt::Rectangle aRet;
163 
164  if (mpPixelCtl)
165  {
166  const Point aOutPos;
167  Size aOutSize(mpPixelCtl->GetOutputSizePixel());
168 
169  aRet.X = aOutPos.X();
170  aRet.Y = aOutPos.Y();
171  aRet.Width = aOutSize.Width();
172  aRet.Height = aOutSize.Height();
173  }
174 
175  return aRet;
176 }
177 
179 {
180  ::osl::MutexGuard aGuard( m_aMutex );
181  if (mpPixelCtl)
183 }
184 
186 {
187  ::osl::MutexGuard aGuard( m_aMutex );
188 
189  //see SvxPixelCtl::Paint
191  return sal_Int32(rStyles.GetLabelTextColor());
192 }
193 
195 {
196  ::osl::MutexGuard aGuard( m_aMutex );
197 
198  //see SvxPixelCtl::Paint
200  return sal_Int32(rStyles.GetDialogColor());
201 }
202 
203 void SvxPixelCtlAccessible::implSelect(sal_Int32 nChildIndex, bool bSelect)
204 {
205  ::osl::MutexGuard aGuard( m_aMutex );
206 
207  if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
208  throw lang::IndexOutOfBoundsException();
209 
210  if (!mpPixelCtl)
211  return;
212 
213  long nIndex = mpPixelCtl->ShowPosition(mpPixelCtl->IndexToPoint(nChildIndex));
214  NotifyChild(nIndex, bSelect, false);
215 }
216 
217 bool SvxPixelCtlAccessible::implIsSelected(sal_Int32 nChildIndex)
218 {
219  ::osl::MutexGuard aGuard( m_aMutex );
220 
221  if (!mpPixelCtl)
222  return false;
223 
224  return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
225 }
226 
228 {
229  ::osl::MutexGuard aGuard(m_aMutex);
230  OAccessibleSelectionHelper::disposing();
231  m_xCurChild.clear();
232  mpPixelCtl = nullptr;
233 }
234 
235 void SvxPixelCtlAccessible::NotifyChild(long nIndex,bool bSelect ,bool bCheck)
236 {
237  DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
238 
239  SvxPixelCtlAccessibleChild *pChild= nullptr;
240 
241  if (m_xCurChild.is())
242  {
243  pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
244  DBG_ASSERT(pChild,"Child Must be Valid");
245  if (pChild->getAccessibleIndexInParent() == nIndex )
246  {
247  if (bSelect)
248  {
249  pChild->SelectChild(true);
250  }
251  if (bCheck)
252  {
253  pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
254  pChild->CheckChild();
255  }
256  return ;
257  }
258  }
259  uno::Reference <XAccessible> xNewChild =CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
260  SvxPixelCtlAccessibleChild *pNewChild= static_cast<SvxPixelCtlAccessibleChild*>(xNewChild.get());
261  DBG_ASSERT(pNewChild,"Child Must be Valid");
262 
263  Any aNewValue,aOldValue;
264  aNewValue<<= xNewChild;
265  NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
266 
267  if (bSelect)
268  {
269  if (pChild)
270  {
271  pChild->SelectChild(false);
272  }
273  pNewChild->SelectChild(true);
274  }
275  if (bCheck)
276  {
277  pNewChild->CheckChild();
278  }
279  m_xCurChild= xNewChild;
280 }
281 
282 uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (long nIndex,Point mPoint)
283 {
284  bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
286  uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
287  bPixelColorOrBG,
288  tools::Rectangle(mPoint,size),
289  this,
290  nIndex);
291 
292  return xChild;
293 }
294 
296 {
297  Any aChecked;
298  aChecked <<= AccessibleStateType::CHECKED;
299 
300  if (m_bPixelColorOrBG)//Current Child State
301  {
302  NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
303  }
304  else
305  {
306  NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
307  }
308 }
309 
311 {
312  Any aSelected;
313  aSelected <<= AccessibleStateType::SELECTED;
314 
315  if (bSelect)
316  {
317  NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
318  }
319  else
320  {
321  NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
322  }
323 }
324 
326  const tools::Rectangle& rBoundingBox, const rtl::Reference<SvxPixelCtlAccessible>& rxParent,
327  long nIndexInParent)
328  : mrParentWindow( rWindow )
329  , mxParent(rxParent)
330  , m_bPixelColorOrBG(bPixelColorOrBG)
331  , maBoundingBox( rBoundingBox )
332  , mnIndexInParent( nIndexInParent )
333 {
334 }
335 
337 {
338  ensureDisposed();
339 }
340 
342 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxPixelCtlAccessibleChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
343 
344 // XAccessible
345 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
346 {
347  return this;
348 }
349 
350 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
351 {
352  return uno::Reference< XAccessible >();
353 }
354 
356 {
357 }
358 
360 {
361  ::osl::MutexGuard aGuard( m_aMutex );
362  return mxParent.is() ? mxParent->getForeground() : -1;
363 }
364 
366 {
367  ::osl::MutexGuard aGuard( m_aMutex );
368  return mxParent.is() ? mxParent->getBackground() : -1;
369 }
370 
371 // XAccessibleContext
373 {
374  return 0;
375 }
376 
377 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 )
378 {
379  throw lang::IndexOutOfBoundsException();
380 }
381 
382 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
383 {
384  return mxParent.get();
385 }
386 
388 {
389  return AccessibleRole::CHECK_BOX;
390 }
391 
393 {
394  ::osl::MutexGuard aGuard( m_aMutex );
395 
396  return GetName();
397 }
398 
400 {
401  ::osl::MutexGuard aGuard( m_aMutex );
402  return GetName();
403 }
404 
408 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
409 {
410  return uno::Reference< XAccessibleRelationSet >();
411 }
412 
413 uno::Reference< XAccessibleStateSet > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet()
414 {
415  ::osl::MutexGuard aGuard( m_aMutex );
417 
418  if (!rBHelper.bDisposed)
419  {
420 
421  pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
422  pStateSetHelper->AddState( AccessibleStateType::ENABLED );
423  pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
424  pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
425  pStateSetHelper->AddState( AccessibleStateType::SHOWING );
426  pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
427 
429  if ( nIndex == mnIndexInParent)
430  {
431  pStateSetHelper->AddState( AccessibleStateType::SELECTED );
432  }
434  {
435  pStateSetHelper->AddState( AccessibleStateType::CHECKED );
436  }
437  }
438  else
439  pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
440 
441  return pStateSetHelper;
442 }
443 
445 {
446  OAccessibleComponentHelper::disposing();
447  mxParent.clear();
448 }
449 
451 {
452  // no guard necessary, because no one changes maBoundingBox after creating it
453  return AWTRectangle(maBoundingBox);
454 }
455 
457 {
458  sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
459  sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
460 
461  OUString str = "("
462  + OUString::number(nXIndex)
463  + ","
464  + OUString::number(nYIndex)
465  + ")";
466  return str;
467 }
468 
469 /* 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
long mnIndexInParent
index of child in parent
virtual OUString SAL_CALL getAccessibleName() override
virtual bool implIsSelected(sal_Int32 nAccessibleChildIndex) override
virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() override
const StyleSettings & GetStyleSettings() const
WeakReference< XInterface > mxParent
static const AllSettings & GetSettings()
OUString GetAccessibleDescription() const
virtual sal_Int16 SAL_CALL getAccessibleRole() override
css::uno::Reference< css::accessibility::XAccessible > CreateChild(long nIndex, Point mPoint)
long GetHeight() const
Definition: dlgctrl.hxx:199
long ShowPosition(const Point &pt)
Definition: dlgctrl.cxx:609
virtual OUString SAL_CALL getAccessibleName() override
const Color & GetLabelTextColor() const
a11yrelationset get_accessible_relation_set() const
Definition: dlgctrl.hxx:195
virtual css::uno::Reference< css::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet() override
rtl::Reference< SvxPixelCtlAccessible > mxParent
virtual void SAL_CALL disposing() override
long GetFocusPosIndex() const
Definition: dlgctrl.cxx:604
Size const & GetOutputSizePixel() const
Point IndexToPoint(long nIndex) const
Definition: dlgctrl.cxx:590
virtual OUString SAL_CALL getAccessibleDescription() override
void ChangePixelColorOrBG(bool bPixelColorOrBG)
#define DBG_ASSERT(sCon, aError)
sal_uInt8 GetBitmapPixel(const sal_uInt16 nPixelNumber) const
Definition: dlgctrl.cxx:880
OUString GetAccessibleName() const
void NotifyChild(long nIndex, bool bSelect, bool bCheck)
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int32 i) override
static sal_uInt16 GetLineCount()
Definition: dlgctrl.hxx:185
tools::Long Width() const
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
SvxPixelCtlAccessibleChild(SvxPixelCtl &rWindow, bool bPixelColorOrBG, const tools::Rectangle &rBounds, const rtl::Reference< SvxPixelCtlAccessible > &xParent, long nIndexInParent)
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
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
static long GetSquares()
Definition: dlgctrl.hxx:197
virtual sal_Int32 SAL_CALL getForeground() override
long PointToIndex(const Point &pt) const
Definition: dlgctrl.cxx:582
void AddState(sal_Int16 aState)
sal_Int32 nState
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
long GetWidth() const
Definition: dlgctrl.hxx:198
virtual void SAL_CALL grabFocus() override
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