nss: upgrade to release 3.73
[LibreOffice.git] / svx / source / accessibility / svxpixelctlaccessiblecontext.cxx
blobaedb8d297bace6008bbd9bea8fad9636bfa61b47
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 <unotools/accessiblestatesethelper.hxx>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25 #include <toolkit/helper/convert.hxx>
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 IMPLEMENT_FORWARD_XINTERFACE2( SvxPixelCtlAccessible, OAccessibleSelectionHelper, OAccessibleHelper_Base )
53 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxPixelCtlAccessible, OAccessibleSelectionHelper, OAccessibleHelper_Base )
55 uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext( )
57 return this;
60 sal_Int32 SvxPixelCtlAccessible::getAccessibleChildCount( )
62 ::osl::MutexGuard aGuard( m_aMutex );
63 return SvxPixelCtl::GetSquares();
65 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int32 i )
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;
76 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent( )
78 ::osl::MutexGuard aGuard( m_aMutex );
79 if (mpPixelCtl)
80 return mpPixelCtl->getAccessibleParent();
81 return uno::Reference<css::accessibility::XAccessible>();
84 sal_Int16 SvxPixelCtlAccessible::getAccessibleRole( )
86 return AccessibleRole::LIST;
89 OUString SvxPixelCtlAccessible::getAccessibleDescription( )
92 ::osl::MutexGuard aGuard( m_aMutex );
93 return mpPixelCtl ? mpPixelCtl->GetAccessibleDescription() : "";
96 OUString SvxPixelCtlAccessible::getAccessibleName( )
98 ::osl::MutexGuard aGuard( m_aMutex );
99 return mpPixelCtl ? mpPixelCtl->GetAccessibleName() : "";
102 Reference< XAccessibleRelationSet > SAL_CALL SvxPixelCtlAccessible::getAccessibleRelationSet()
104 if (mpPixelCtl)
105 return mpPixelCtl->get_accessible_relation_set();
106 return uno::Reference<css::accessibility::XAccessibleRelationSet>();
109 uno::Reference< XAccessibleStateSet > SvxPixelCtlAccessible::getAccessibleStateSet( )
111 ::osl::MutexGuard aGuard( m_aMutex );
112 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
113 uno::Reference< XAccessibleStateSet > xRet = pStateSetHelper;
115 if (mpPixelCtl)
117 const sal_Int16 aStandardStates[] =
119 AccessibleStateType::FOCUSABLE,
120 AccessibleStateType::SELECTABLE,
121 AccessibleStateType::SHOWING,
122 AccessibleStateType::VISIBLE,
123 AccessibleStateType::OPAQUE,
127 sal_Int16 nState = 0;
128 while (aStandardStates[nState])
130 pStateSetHelper->AddState(aStandardStates[nState++]);
132 if (mpPixelCtl->IsEnabled())
133 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
134 if (mpPixelCtl->HasFocus())
135 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
136 pStateSetHelper->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
139 return xRet;
142 uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
143 const awt::Point& rPoint)
145 ::osl::MutexGuard aGuard( m_aMutex );
147 Reference< XAccessible > xRet;
149 if (mpPixelCtl)
151 tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
152 xRet = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
155 return xRet;
158 awt::Rectangle SvxPixelCtlAccessible::implGetBounds()
160 ::osl::MutexGuard aGuard( m_aMutex );
162 awt::Rectangle aRet;
164 if (mpPixelCtl)
166 const Point aOutPos;
167 Size aOutSize(mpPixelCtl->GetOutputSizePixel());
169 aRet.X = aOutPos.X();
170 aRet.Y = aOutPos.Y();
171 aRet.Width = aOutSize.Width();
172 aRet.Height = aOutSize.Height();
175 return aRet;
178 void SvxPixelCtlAccessible::grabFocus( )
180 ::osl::MutexGuard aGuard( m_aMutex );
181 if (mpPixelCtl)
182 mpPixelCtl->GrabFocus();
185 sal_Int32 SvxPixelCtlAccessible::getForeground( )
187 ::osl::MutexGuard aGuard( m_aMutex );
189 //see SvxPixelCtl::Paint
190 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
191 return sal_Int32(rStyles.GetLabelTextColor());
194 sal_Int32 SvxPixelCtlAccessible::getBackground( )
196 ::osl::MutexGuard aGuard( m_aMutex );
198 //see SvxPixelCtl::Paint
199 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
200 return sal_Int32(rStyles.GetDialogColor());
203 void SvxPixelCtlAccessible::implSelect(sal_Int32 nChildIndex, bool bSelect)
205 ::osl::MutexGuard aGuard( m_aMutex );
207 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
208 throw lang::IndexOutOfBoundsException();
210 if (!mpPixelCtl)
211 return;
213 tools::Long nIndex = mpPixelCtl->ShowPosition(mpPixelCtl->IndexToPoint(nChildIndex));
214 NotifyChild(nIndex, bSelect, false);
217 bool SvxPixelCtlAccessible::implIsSelected(sal_Int32 nChildIndex)
219 ::osl::MutexGuard aGuard( m_aMutex );
221 if (!mpPixelCtl)
222 return false;
224 return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
227 void SAL_CALL SvxPixelCtlAccessible::disposing()
229 ::osl::MutexGuard aGuard(m_aMutex);
230 OAccessibleSelectionHelper::disposing();
231 m_xCurChild.clear();
232 mpPixelCtl = nullptr;
235 void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
237 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
239 SvxPixelCtlAccessibleChild *pChild= nullptr;
241 if (m_xCurChild.is())
243 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
244 DBG_ASSERT(pChild,"Child Must be Valid");
245 if (pChild->getAccessibleIndexInParent() == nIndex )
247 if (bSelect)
249 pChild->SelectChild(true);
251 if (bCheck)
253 pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
254 pChild->CheckChild();
256 return ;
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");
263 Any aNewValue,aOldValue;
264 aNewValue<<= xNewChild;
265 NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
267 if (bSelect)
269 if (pChild)
271 pChild->SelectChild(false);
273 pNewChild->SelectChild(true);
275 if (bCheck)
277 pNewChild->CheckChild();
279 m_xCurChild= xNewChild;
282 uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
284 bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
285 Size size(mpPixelCtl->GetWidth() / SvxPixelCtl::GetLineCount(), mpPixelCtl->GetHeight() / SvxPixelCtl::GetLineCount());
286 uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
287 bPixelColorOrBG,
288 tools::Rectangle(mPoint,size),
289 this,
290 nIndex);
292 return xChild;
295 void SvxPixelCtlAccessibleChild::CheckChild()
297 Any aChecked;
298 aChecked <<= AccessibleStateType::CHECKED;
300 if (m_bPixelColorOrBG)//Current Child State
302 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
304 else
306 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
310 void SvxPixelCtlAccessibleChild::SelectChild( bool bSelect)
312 Any aSelected;
313 aSelected <<= AccessibleStateType::SELECTED;
315 if (bSelect)
317 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
319 else
321 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
325 SvxPixelCtlAccessibleChild::SvxPixelCtlAccessibleChild( SvxPixelCtl& rWindow, bool bPixelColorOrBG,
326 const tools::Rectangle& rBoundingBox, const rtl::Reference<SvxPixelCtlAccessible>& rxParent,
327 tools::Long nIndexInParent)
328 : mrParentWindow( rWindow )
329 , mxParent(rxParent)
330 , m_bPixelColorOrBG(bPixelColorOrBG)
331 , maBoundingBox( rBoundingBox )
332 , mnIndexInParent( nIndexInParent )
336 SvxPixelCtlAccessibleChild::~SvxPixelCtlAccessibleChild()
338 ensureDisposed();
341 IMPLEMENT_FORWARD_XINTERFACE2( SvxPixelCtlAccessibleChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
342 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxPixelCtlAccessibleChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
344 // XAccessible
345 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
347 return this;
350 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
352 return uno::Reference< XAccessible >();
355 void SAL_CALL SvxPixelCtlAccessibleChild::grabFocus()
359 sal_Int32 SvxPixelCtlAccessibleChild::getForeground()
361 ::osl::MutexGuard aGuard( m_aMutex );
362 return mxParent.is() ? mxParent->getForeground() : -1;
365 sal_Int32 SvxPixelCtlAccessibleChild::getBackground()
367 ::osl::MutexGuard aGuard( m_aMutex );
368 return mxParent.is() ? mxParent->getBackground() : -1;
371 // XAccessibleContext
372 sal_Int32 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChildCount()
374 return 0;
377 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 )
379 throw lang::IndexOutOfBoundsException();
382 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
384 return mxParent.get();
387 sal_Int16 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRole()
389 return AccessibleRole::CHECK_BOX;
392 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleDescription()
394 ::osl::MutexGuard aGuard( m_aMutex );
396 return GetName();
399 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleName()
401 ::osl::MutexGuard aGuard( m_aMutex );
402 return GetName();
405 /** Return empty uno::Reference to indicate that the relation set is not
406 supported.
408 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
410 return uno::Reference< XAccessibleRelationSet >();
413 uno::Reference< XAccessibleStateSet > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet()
415 ::osl::MutexGuard aGuard( m_aMutex );
416 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
418 if (!rBHelper.bDisposed)
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 );
428 tools::Long nIndex = mrParentWindow.GetFocusPosIndex();
429 if ( nIndex == mnIndexInParent)
431 pStateSetHelper->AddState( AccessibleStateType::SELECTED );
433 if (mrParentWindow.GetBitmapPixel(sal_uInt16(mnIndexInParent)))
435 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
438 else
439 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
441 return pStateSetHelper;
444 void SAL_CALL SvxPixelCtlAccessibleChild::disposing()
446 OAccessibleComponentHelper::disposing();
447 mxParent.clear();
450 awt::Rectangle SvxPixelCtlAccessibleChild::implGetBounds()
452 // no guard necessary, because no one changes maBoundingBox after creating it
453 return AWTRectangle(maBoundingBox);
456 OUString SvxPixelCtlAccessibleChild::GetName() const
458 sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
459 sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
461 OUString str = "("
462 + OUString::number(nXIndex)
463 + ","
464 + OUString::number(nYIndex)
465 + ")";
466 return str;
469 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */