bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / accessibility / svxpixelctlaccessiblecontext.cxx
blob4873b3cfe834c5019cf1a202710bf730a8d28ddb
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 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
114 if (mpPixelCtl)
116 const sal_Int16 aStandardStates[] =
118 AccessibleStateType::FOCUSABLE,
119 AccessibleStateType::SELECTABLE,
120 AccessibleStateType::SHOWING,
121 AccessibleStateType::VISIBLE,
122 AccessibleStateType::OPAQUE,
126 sal_Int16 nState = 0;
127 while (aStandardStates[nState])
129 pStateSetHelper->AddState(aStandardStates[nState++]);
131 if (mpPixelCtl->IsEnabled())
132 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
133 if (mpPixelCtl->HasFocus())
134 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
135 pStateSetHelper->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
138 return pStateSetHelper;
141 uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
142 const awt::Point& rPoint)
144 ::osl::MutexGuard aGuard( m_aMutex );
146 Reference< XAccessible > xRet;
148 if (mpPixelCtl)
150 tools::Long nIndex = mpPixelCtl->PointToIndex(Point(rPoint.X, rPoint.Y));
151 xRet = CreateChild(nIndex, mpPixelCtl->IndexToPoint(nIndex));
154 return xRet;
157 awt::Rectangle SvxPixelCtlAccessible::implGetBounds()
159 ::osl::MutexGuard aGuard( m_aMutex );
161 awt::Rectangle aRet;
163 if (mpPixelCtl)
165 const Point aOutPos;
166 Size aOutSize(mpPixelCtl->GetOutputSizePixel());
168 aRet.X = aOutPos.X();
169 aRet.Y = aOutPos.Y();
170 aRet.Width = aOutSize.Width();
171 aRet.Height = aOutSize.Height();
174 return aRet;
177 void SvxPixelCtlAccessible::grabFocus( )
179 ::osl::MutexGuard aGuard( m_aMutex );
180 if (mpPixelCtl)
181 mpPixelCtl->GrabFocus();
184 sal_Int32 SvxPixelCtlAccessible::getForeground( )
186 ::osl::MutexGuard aGuard( m_aMutex );
188 //see SvxPixelCtl::Paint
189 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
190 return sal_Int32(rStyles.GetLabelTextColor());
193 sal_Int32 SvxPixelCtlAccessible::getBackground( )
195 ::osl::MutexGuard aGuard( m_aMutex );
197 //see SvxPixelCtl::Paint
198 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
199 return sal_Int32(rStyles.GetDialogColor());
202 void SvxPixelCtlAccessible::implSelect(sal_Int32 nChildIndex, bool bSelect)
204 ::osl::MutexGuard aGuard( m_aMutex );
206 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
207 throw lang::IndexOutOfBoundsException();
209 if (!mpPixelCtl)
210 return;
212 tools::Long nIndex = mpPixelCtl->ShowPosition(mpPixelCtl->IndexToPoint(nChildIndex));
213 NotifyChild(nIndex, bSelect, false);
216 bool SvxPixelCtlAccessible::implIsSelected(sal_Int32 nChildIndex)
218 ::osl::MutexGuard aGuard( m_aMutex );
220 if (!mpPixelCtl)
221 return false;
223 return mpPixelCtl->GetFocusPosIndex() == nChildIndex;
226 void SAL_CALL SvxPixelCtlAccessible::disposing()
228 ::osl::MutexGuard aGuard(m_aMutex);
229 OAccessibleSelectionHelper::disposing();
230 m_xCurChild.clear();
231 mpPixelCtl = nullptr;
234 void SvxPixelCtlAccessible::NotifyChild(tools::Long nIndex,bool bSelect ,bool bCheck)
236 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
238 SvxPixelCtlAccessibleChild *pChild= nullptr;
240 if (m_xCurChild.is())
242 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
243 DBG_ASSERT(pChild,"Child Must be Valid");
244 if (pChild->getAccessibleIndexInParent() == nIndex )
246 if (bSelect)
248 pChild->SelectChild(true);
250 if (bCheck)
252 pChild->ChangePixelColorOrBG(mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0);
253 pChild->CheckChild();
255 return ;
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");
262 Any aNewValue,aOldValue;
263 aNewValue<<= xNewChild;
264 NotifyAccessibleEvent(AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue);
266 if (bSelect)
268 if (pChild)
270 pChild->SelectChild(false);
272 pNewChild->SelectChild(true);
274 if (bCheck)
276 pNewChild->CheckChild();
278 m_xCurChild= xNewChild;
281 uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (tools::Long nIndex,Point mPoint)
283 bool bPixelColorOrBG = mpPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)) != 0;
284 Size size(mpPixelCtl->GetWidth() / SvxPixelCtl::GetLineCount(), mpPixelCtl->GetHeight() / SvxPixelCtl::GetLineCount());
285 uno::Reference<XAccessible> xChild = new SvxPixelCtlAccessibleChild(*mpPixelCtl,
286 bPixelColorOrBG,
287 tools::Rectangle(mPoint,size),
288 this,
289 nIndex);
291 return xChild;
294 void SvxPixelCtlAccessibleChild::CheckChild()
296 Any aChecked;
297 aChecked <<= AccessibleStateType::CHECKED;
299 if (m_bPixelColorOrBG)//Current Child State
301 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aChecked);
303 else
305 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aChecked, Any());
309 void SvxPixelCtlAccessibleChild::SelectChild( bool bSelect)
311 Any aSelected;
312 aSelected <<= AccessibleStateType::SELECTED;
314 if (bSelect)
316 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, Any(), aSelected);
318 else
320 NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aSelected, Any());
324 SvxPixelCtlAccessibleChild::SvxPixelCtlAccessibleChild( SvxPixelCtl& rWindow, bool bPixelColorOrBG,
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 )
335 SvxPixelCtlAccessibleChild::~SvxPixelCtlAccessibleChild()
337 ensureDisposed();
340 IMPLEMENT_FORWARD_XINTERFACE2( SvxPixelCtlAccessibleChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
341 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SvxPixelCtlAccessibleChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
343 // XAccessible
344 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext()
346 return this;
349 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& )
351 return uno::Reference< XAccessible >();
354 void SAL_CALL SvxPixelCtlAccessibleChild::grabFocus()
358 sal_Int32 SvxPixelCtlAccessibleChild::getForeground()
360 ::osl::MutexGuard aGuard( m_aMutex );
361 return mxParent.is() ? mxParent->getForeground() : -1;
364 sal_Int32 SvxPixelCtlAccessibleChild::getBackground()
366 ::osl::MutexGuard aGuard( m_aMutex );
367 return mxParent.is() ? mxParent->getBackground() : -1;
370 // XAccessibleContext
371 sal_Int32 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChildCount()
373 return 0;
376 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 )
378 throw lang::IndexOutOfBoundsException();
381 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent()
383 return mxParent;
386 sal_Int16 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRole()
388 return AccessibleRole::CHECK_BOX;
391 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleDescription()
393 ::osl::MutexGuard aGuard( m_aMutex );
395 return GetName();
398 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleName()
400 ::osl::MutexGuard aGuard( m_aMutex );
401 return GetName();
404 /** Return empty uno::Reference to indicate that the relation set is not
405 supported.
407 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet()
409 return uno::Reference< XAccessibleRelationSet >();
412 uno::Reference< XAccessibleStateSet > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet()
414 ::osl::MutexGuard aGuard( m_aMutex );
415 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
417 if (!rBHelper.bDisposed)
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 );
427 tools::Long nIndex = mrParentWindow.GetFocusPosIndex();
428 if ( nIndex == mnIndexInParent)
430 pStateSetHelper->AddState( AccessibleStateType::SELECTED );
432 if (mrParentWindow.GetBitmapPixel(sal_uInt16(mnIndexInParent)))
434 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
437 else
438 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
440 return pStateSetHelper;
443 void SAL_CALL SvxPixelCtlAccessibleChild::disposing()
445 OAccessibleComponentHelper::disposing();
446 mxParent.clear();
449 awt::Rectangle SvxPixelCtlAccessibleChild::implGetBounds()
451 // no guard necessary, because no one changes maBoundingBox after creating it
452 return AWTRectangle(maBoundingBox);
455 OUString SvxPixelCtlAccessibleChild::GetName() const
457 sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
458 sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
460 OUString str = "("
461 + OUString::number(nXIndex)
462 + ","
463 + OUString::number(nYIndex)
464 + ")";
465 return str;
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */