Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / accessibility / svxpixelctlaccessiblecontext.cxx
blobaf34fd21de72adf1d6679d164cfb3a053a12b250
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
24 #include <toolkit/helper/convert.hxx>
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>
32 #include <svx/dlgctrl.hxx>
34 #include <svxpixelctlaccessiblecontext.hxx>
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;
42 SvxPixelCtlAccessible::SvxPixelCtlAccessible(SvxPixelCtl* pControl)
43 : mpPixelCtl(pControl)
47 SvxPixelCtlAccessible::~SvxPixelCtlAccessible()
49 ensureDisposed();
52 uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext( )
54 return this;
57 sal_Int64 SvxPixelCtlAccessible::getAccessibleChildCount( )
59 return SvxPixelCtl::GetSquares();
61 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int64 i )
63 ::osl::MutexGuard aGuard( m_aMutex );
64 if ( i < 0 || i >= getAccessibleChildCount())
65 throw lang::IndexOutOfBoundsException();
66 Reference< XAccessible > xChild;
67 if (mpPixelCtl)
68 xChild = CreateChild(i, mpPixelCtl->IndexToPoint(i));
69 return xChild;
72 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent( )
74 ::osl::MutexGuard aGuard( m_aMutex );
75 if (mpPixelCtl)
76 return mpPixelCtl->getAccessibleParent();
77 return uno::Reference<css::accessibility::XAccessible>();
80 sal_Int16 SvxPixelCtlAccessible::getAccessibleRole( )
82 return AccessibleRole::LIST;
85 OUString SvxPixelCtlAccessible::getAccessibleDescription( )
88 ::osl::MutexGuard aGuard( m_aMutex );
89 return mpPixelCtl ? mpPixelCtl->GetAccessibleDescription() : "";
92 OUString SvxPixelCtlAccessible::getAccessibleName( )
94 ::osl::MutexGuard aGuard( m_aMutex );
95 return mpPixelCtl ? mpPixelCtl->GetAccessibleName() : "";
98 Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
100 if (mpPixelCtl)
101 return mpPixelCtl->get_accessible_relation_set();
102 return uno::Reference<css::accessibility::XAccessibleRelationSet>();
105 sal_Int64 SvxPixelCtlAccessible::getAccessibleStateSet( )
107 ::osl::MutexGuard aGuard( m_aMutex );
108 sal_Int64 nStateSet = 0;
110 if (mpPixelCtl)
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;
125 return nStateSet;
128 uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
129 const awt::Point& rPoint)
131 ::osl::MutexGuard aGuard( m_aMutex );
133 Reference< XAccessible > xRet;
135 if (mpPixelCtl)
137 tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
138 xRet = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
141 return xRet;
144 awt::Rectangle SvxPixelCtlAccessible::implGetBounds()
146 ::osl::MutexGuard aGuard( m_aMutex );
148 awt::Rectangle aRet;
150 if (mpPixelCtl)
152 const Point aOutPos;
153 Size aOutSize(mpPixelCtl->GetOutputSizePixel());
155 aRet.X = aOutPos.X();
156 aRet.Y = aOutPos.Y();
157 aRet.Width = aOutSize.Width();
158 aRet.Height = aOutSize.Height();
161 return aRet;
164 void SvxPixelCtlAccessible::grabFocus( )
166 ::osl::MutexGuard aGuard( m_aMutex );
167 if (mpPixelCtl)
168 mpPixelCtl->GrabFocus();
171 sal_Int32 SvxPixelCtlAccessible::getForeground( )
173 ::osl::MutexGuard aGuard( m_aMutex );
175 //see SvxPixelCtl::Paint
176 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
177 return sal_Int32(rStyles.GetLabelTextColor());
180 sal_Int32 SvxPixelCtlAccessible::getBackground( )
182 ::osl::MutexGuard aGuard( m_aMutex );
184 //see SvxPixelCtl::Paint
185 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
186 return sal_Int32(rStyles.GetDialogColor());
189 void SvxPixelCtlAccessible::implSelect(sal_Int64 nChildIndex, bool bSelect)
191 ::osl::MutexGuard aGuard( m_aMutex );
193 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
194 throw lang::IndexOutOfBoundsException();
196 if (!mpPixelCtl)
197 return;
199 tools::Long nIndex = mpPixelCtl->ShowPosition(mpPixelCtl->IndexToPoint(nChildIndex));
200 NotifyChild(nIndex, bSelect, false);
203 bool SvxPixelCtlAccessible::implIsSelected(sal_Int64 nChildIndex)
205 ::osl::MutexGuard aGuard( m_aMutex );
207 if (!mpPixelCtl)
208 return false;
210 return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
213 void SAL_CALL SvxPixelCtlAccessible::disposing()
215 ::osl::MutexGuard aGuard(m_aMutex);
216 OAccessibleSelectionHelper::disposing();
217 m_xCurChild.clear();
218 mpPixelCtl = nullptr;
221 void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
223 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
225 SvxPixelCtlAccessibleChild *pChild= nullptr;
227 if (m_xCurChild.is())
229 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
230 DBG_ASSERT(pChild,"Child Must be Valid");
231 if (pChild->getAccessibleIndexInParent() == nIndex )
233 if (bSelect)
235 pChild->SelectChild(true);
237 if (bCheck)
239 pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
240 pChild->CheckChild();
242 return ;
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");
249 Any aNewValue,aOldValue;
250 aNewValue<<= xNewChild;
251 NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
253 if (bSelect)
255 if (pChild)
257 pChild->SelectChild(false);
259 pNewChild->SelectChild(true);
261 if (bCheck)
263 pNewChild->CheckChild();
265 m_xCurChild= xNewChild;
268 uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
270 bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
271 Size size(mpPixelCtl->GetWidth() / SvxPixelCtl::GetLineCount(), mpPixelCtl->GetHeight() / SvxPixelCtl::GetLineCount());
272 uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
273 bPixelColorOrBG,
274 tools::Rectangle(mPoint,size),
275 this,
276 nIndex);
278 return xChild;
281 void SvxPixelCtlAccessibleChild::CheckChild()
283 Any aChecked;
284 aChecked <<= AccessibleStateType::CHECKED;
286 if (m_bPixelColorOrBG)//Current Child State
288 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
290 else
292 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
296 void SvxPixelCtlAccessibleChild::SelectChild( bool bSelect)
298 Any aSelected;
299 aSelected <<= AccessibleStateType::SELECTED;
301 if (bSelect)
303 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
305 else
307 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
311 SvxPixelCtlAccessibleChild::SvxPixelCtlAccessibleChild( SvxPixelCtl& rWindow, bool bPixelColorOrBG,
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 )
322 SvxPixelCtlAccessibleChild::~SvxPixelCtlAccessibleChild()
324 ensureDisposed();
327 // XAccessible
328 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
330 return this;
333 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
335 return uno::Reference< XAccessible >();
338 void SAL_CALL SvxPixelCtlAccessibleChild::grabFocus()
342 sal_Int32 SvxPixelCtlAccessibleChild::getForeground()
344 ::osl::MutexGuard aGuard( m_aMutex );
345 return mxParent.is() ? mxParent->getForeground() : -1;
348 sal_Int32 SvxPixelCtlAccessibleChild::getBackground()
350 ::osl::MutexGuard aGuard( m_aMutex );
351 return mxParent.is() ? mxParent->getBackground() : -1;
354 // XAccessibleContext
355 sal_Int64 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChildCount()
357 return 0;
360 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int64 )
362 throw lang::IndexOutOfBoundsException();
365 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
367 return mxParent;
370 sal_Int16 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRole()
372 return AccessibleRole::CHECK_BOX;
375 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleDescription()
377 ::osl::MutexGuard aGuard( m_aMutex );
379 return GetName();
382 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleName()
384 ::osl::MutexGuard aGuard( m_aMutex );
385 return GetName();
388 /** Return empty uno::Reference to indicate that the relation set is not
389 supported.
391 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
393 return uno::Reference< XAccessibleRelationSet >();
396 sal_Int64 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet()
398 ::osl::MutexGuard aGuard( m_aMutex );
399 sal_Int64 nStateSet = 0;
401 if (!rBHelper.bDisposed)
403 nStateSet |= AccessibleStateType::TRANSIENT;
404 nStateSet |= AccessibleStateType::ENABLED;
405 nStateSet |= AccessibleStateType::OPAQUE;
406 nStateSet |= AccessibleStateType::SELECTABLE;
407 nStateSet |= AccessibleStateType::SHOWING;
408 nStateSet |= AccessibleStateType::VISIBLE;
410 tools::Long nIndex = mrParentWindow.GetFocusPosIndex();
411 if ( nIndex == mnIndexInParent)
413 nStateSet |= AccessibleStateType::SELECTED;
415 if (mrParentWindow.GetBitmapPixel(sal_uInt16(mnIndexInParent)))
417 nStateSet |= AccessibleStateType::CHECKED;
420 else
421 nStateSet |= AccessibleStateType::DEFUNC;
423 return nStateSet;
426 void SAL_CALL SvxPixelCtlAccessibleChild::disposing()
428 OAccessibleComponentHelper::disposing();
429 mxParent.clear();
432 awt::Rectangle SvxPixelCtlAccessibleChild::implGetBounds()
434 // no guard necessary, because no one changes maBoundingBox after creating it
435 return AWTRectangle(maBoundingBox);
438 OUString SvxPixelCtlAccessibleChild::GetName() const
440 sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
441 sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
443 OUString str = "("
444 + OUString::number(nXIndex)
445 + ","
446 + OUString::number(nYIndex)
447 + ")";
448 return str;
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */