Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / accessibility / svxpixelctlaccessiblecontext.cxx
blob1d45757fb26f2e478e3fc97b2bb6da92f6137ae9
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/beans/PropertyChangeEvent.hpp>
25 #include <com/sun/star/awt/XWindow.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <toolkit/helper/convert.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <osl/mutex.hxx>
33 #include <rtl/uuid.h>
34 #include <tools/debug.hxx>
35 #include <tools/gen.hxx>
37 #include <svx/dialogs.hrc>
38 #include "accessibility.hrc"
39 #include <svx/dlgctrl.hxx>
41 #include <svx/dialmgr.hxx>
42 #include <comphelper/accessibleeventnotifier.hxx>
44 #include <unotools/accessiblerelationsethelper.hxx>
46 #include "svxpixelctlaccessiblecontext.hxx"
47 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
49 using namespace ::cppu;
50 using namespace ::osl;
51 using namespace ::rtl;
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::accessibility;
56 SvxPixelCtlAccessible::SvxPixelCtlAccessible( SvxPixelCtl& rControl) :
57 SvxPixelCtlAccessible_BASE(m_aMutex),
58 mrPixelCtl(rControl),
59 mnClientId(0)
63 SvxPixelCtlAccessible::~SvxPixelCtlAccessible()
65 if( IsAlive() )
67 osl_atomic_increment( &m_refCount );
68 dispose(); // set mpRepr = NULL & release all childs
71 /*-- 04.02.2002 14:11:55---------------------------------------------------
73 -----------------------------------------------------------------------*/
74 uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext( )
75 throw (uno::RuntimeException, std::exception)
77 return this;
80 sal_Int32 SvxPixelCtlAccessible::getAccessibleChildCount( ) throw (uno::RuntimeException, std::exception)
82 ::osl::MutexGuard aGuard( m_aMutex );
83 return mrPixelCtl.GetSquares();
85 /*-- 04.02.2002 14:11:56---------------------------------------------------
87 -----------------------------------------------------------------------*/
88 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int32 i )
89 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
91 ::osl::MutexGuard aGuard( m_aMutex );
92 if ( i < 0 || i >= getAccessibleChildCount())
93 throw lang::IndexOutOfBoundsException();
94 uno::Reference <XAccessible> xAcc;
95 return CreateChild(i, mrPixelCtl.IndexToPoint(i));
100 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent( )
101 throw (uno::RuntimeException, std::exception)
103 ::osl::MutexGuard aGuard( m_aMutex );
104 Window *pTabPage = getNonLayoutParent(&mrPixelCtl);
105 assert(pTabPage && WINDOW_TABPAGE == pTabPage->GetType());
106 return pTabPage->GetAccessible( true );
109 sal_Int32 SvxPixelCtlAccessible::getAccessibleIndexInParent( )
110 throw (uno::RuntimeException, std::exception)
112 ::osl::MutexGuard aGuard( m_aMutex );
113 sal_uInt16 nIdx = 0;
114 Window *pTabPage = getNonLayoutParent(&mrPixelCtl);
115 assert(pTabPage && WINDOW_TABPAGE == pTabPage->GetType());
116 sal_uInt16 nChildren = pTabPage->GetChildCount();
117 for(nIdx = 0; nIdx < nChildren; nIdx++)
118 if(pTabPage->GetChild( nIdx ) == &mrPixelCtl)
119 break;
120 return nIdx;
122 /*-- 04.02.2002 14:11:57---------------------------------------------------
124 -----------------------------------------------------------------------*/
125 sal_Int16 SvxPixelCtlAccessible::getAccessibleRole( ) throw (uno::RuntimeException, std::exception)
127 return AccessibleRole::LIST;
130 OUString SvxPixelCtlAccessible::getAccessibleDescription( )
131 throw (uno::RuntimeException, std::exception)
134 ::osl::MutexGuard aGuard( m_aMutex );
135 return mrPixelCtl.GetAccessibleDescription();
138 OUString SvxPixelCtlAccessible::getAccessibleName( )
139 throw (uno::RuntimeException, std::exception)
142 ::osl::MutexGuard aGuard( m_aMutex );
143 return mrPixelCtl.GetAccessibleName();
146 uno::Reference< XAccessibleRelationSet > SvxPixelCtlAccessible::getAccessibleRelationSet( )
147 throw (uno::RuntimeException, std::exception)
149 ::osl::MutexGuard aGuard( m_aMutex );
150 utl::AccessibleRelationSetHelper* rRelationSet = new utl::AccessibleRelationSetHelper;
151 uno::Reference< css::accessibility::XAccessibleRelationSet > rSet = rRelationSet;
152 Window *pLabeledBy = mrPixelCtl.GetAccessibleRelationLabeledBy();
153 if ( pLabeledBy && pLabeledBy != &mrPixelCtl )
155 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
156 aSequence[0] = pLabeledBy->GetAccessible();
157 rRelationSet->AddRelation( css::accessibility::AccessibleRelation( css::accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
160 Window* pMemberOf = mrPixelCtl.GetAccessibleRelationMemberOf();
161 if ( pMemberOf && pMemberOf != &mrPixelCtl )
163 uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
164 aSequence[0] = pMemberOf->GetAccessible();
165 rRelationSet->AddRelation( css::accessibility::AccessibleRelation( css::accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
167 return rSet;
171 uno::Reference< XAccessibleStateSet > SvxPixelCtlAccessible::getAccessibleStateSet( )
172 throw (uno::RuntimeException, std::exception)
174 ::osl::MutexGuard aGuard( m_aMutex );
175 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
176 uno::Reference< XAccessibleStateSet > xRet = pStateSetHelper;
178 const sal_Int16 aStandardStates[] =
180 AccessibleStateType::FOCUSABLE,
181 AccessibleStateType::SELECTABLE,
182 AccessibleStateType::SHOWING,
183 AccessibleStateType::VISIBLE,
184 AccessibleStateType::OPAQUE,
188 sal_Int16 nState = 0;
189 while(aStandardStates[nState])
191 pStateSetHelper->AddState(aStandardStates[nState++]);
193 if(mrPixelCtl.IsEnabled())
194 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
195 if(mrPixelCtl.HasFocus())
196 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
197 pStateSetHelper->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
199 return xRet;
203 com::sun::star::lang::Locale SvxPixelCtlAccessible::getLocale( )
204 throw (IllegalAccessibleComponentStateException, uno::RuntimeException, std::exception)
206 ::osl::MutexGuard aGuard( m_aMutex );
207 if( getAccessibleParent().is() )
209 uno::Reference< XAccessibleContext > xParentContext( getAccessibleParent()->getAccessibleContext() );
210 if( xParentContext.is() )
211 return xParentContext->getLocale();
214 // No locale and no parent. Therefore throw exception to indicate this
215 // cluelessness.
216 throw IllegalAccessibleComponentStateException();
220 sal_Bool SvxPixelCtlAccessible::containsPoint( const awt::Point& aPt )
221 throw (uno::RuntimeException, std::exception)
223 ::osl::MutexGuard aGuard( m_aMutex );
224 Point aPoint(aPt.X, aPt.Y);
225 return (aPoint.X() >= 0)
226 && (aPoint.X() < mrPixelCtl.GetSizePixel().getWidth())
227 && (aPoint.Y() >= 0)
228 && (aPoint.Y() < mrPixelCtl.GetSizePixel().getHeight());
230 uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
231 const awt::Point& aPoint)
232 throw (uno::RuntimeException, std::exception)
234 ::osl::MutexGuard aGuard( m_aMutex );
235 ensureIsAlive();
236 uno::Reference <XAccessible> xAcc;
238 Point childPoint;
239 childPoint.X() = aPoint.X;
240 childPoint.Y() = aPoint.Y;
242 Point pt= mrPixelCtl.PixelToLogic(childPoint);
243 long nIndex = mrPixelCtl.PointToIndex(pt);
244 return CreateChild(nIndex, mrPixelCtl.IndexToPoint(nIndex));
247 awt::Rectangle SvxPixelCtlAccessible::getBounds( ) throw (uno::RuntimeException, std::exception)
249 ::osl::MutexGuard aGuard( m_aMutex );
250 awt::Rectangle aRet;
251 Size aSz = mrPixelCtl.GetSizePixel();
252 Point aPos = mrPixelCtl.GetPosPixel();
253 aRet.X = aPos.X();
254 aRet.Y = aPos.Y();
255 aRet.Width = aSz.Width();
256 aRet.Height = aSz.Height();
257 return aRet;
260 awt::Point SvxPixelCtlAccessible::getLocation( ) throw (uno::RuntimeException, std::exception)
262 ::osl::MutexGuard aGuard( m_aMutex );
263 Point aPos;
264 aPos = mrPixelCtl.GetPosPixel();
265 awt::Point aRet(aPos.X(), aPos.Y());
266 return aRet;
269 awt::Point SvxPixelCtlAccessible::getLocationOnScreen( ) throw (uno::RuntimeException, std::exception)
271 ::osl::MutexGuard aGuard( m_aMutex );
272 Rectangle rect = mrPixelCtl.GetWindowExtentsRelative(NULL);
273 return awt::Point(rect.Left(),rect.Top() );
276 awt::Size SvxPixelCtlAccessible::getSize( ) throw (uno::RuntimeException, std::exception)
278 ::osl::MutexGuard aGuard( m_aMutex );
279 Size aSz = mrPixelCtl.GetSizePixel();
280 return awt::Size(aSz.Width(),aSz.Height());
282 void SvxPixelCtlAccessible::grabFocus( ) throw (uno::RuntimeException, std::exception)
284 ::osl::MutexGuard aGuard( m_aMutex );
285 mrPixelCtl.GrabFocus();
288 sal_Int32 SvxPixelCtlAccessible::getForeground( )
289 throw (::com::sun::star::uno::RuntimeException, std::exception)
291 ::osl::MutexGuard aGuard( m_aMutex );
292 return mrPixelCtl.GetControlForeground().GetColor();
295 sal_Int32 SvxPixelCtlAccessible::getBackground( )
296 throw (::com::sun::star::uno::RuntimeException, std::exception)
298 ::osl::MutexGuard aGuard( m_aMutex );
299 return mrPixelCtl.GetControlBackground().GetColor();
302 OUString SvxPixelCtlAccessible::getImplementationName( ) throw (uno::RuntimeException, std::exception)
304 return OUString("SvxPixelCtlAccessible");
307 sal_Bool SvxPixelCtlAccessible::supportsService( const OUString& rServiceName )
308 throw (uno::RuntimeException, std::exception)
310 return cppu::supportsService( this, rServiceName );
313 uno::Sequence< OUString > SvxPixelCtlAccessible::getSupportedServiceNames( )
314 throw (uno::RuntimeException, std::exception)
316 uno::Sequence< OUString > aRet(2);
317 OUString* pArray = aRet.getArray();
318 pArray[0] = "Accessible";
319 pArray[1] = "AccessibleContext";
320 pArray[2] = "AccessibleComponent";
321 return aRet;
325 // XAccessibleSelection
327 void SAL_CALL SvxPixelCtlAccessible::selectAccessibleChild( sal_Int32 nChildIndex ) throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
329 ::osl::MutexGuard aGuard( m_aMutex );
331 if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
332 throw lang::IndexOutOfBoundsException();
334 long nIndex = mrPixelCtl.ShowPosition(mrPixelCtl.IndexToPoint(nChildIndex));
335 NotifyChild(nIndex,true,false);
338 sal_Bool SAL_CALL SvxPixelCtlAccessible::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
340 ::osl::MutexGuard aGuard( m_aMutex );
342 return mrPixelCtl.GetFoucsPosIndex() == nChildIndex;
345 void SAL_CALL SvxPixelCtlAccessible::clearAccessibleSelection( ) throw (RuntimeException, std::exception)
349 void SAL_CALL SvxPixelCtlAccessible::selectAllAccessibleChildren( ) throw (RuntimeException, std::exception)
353 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getSelectedAccessibleChildCount( ) throw (RuntimeException, std::exception)
355 return 1;
358 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessible::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
360 ::osl::MutexGuard aGuard( m_aMutex );
362 if ( nSelectedChildIndex >= 1)
363 throw lang::IndexOutOfBoundsException();
365 uno::Reference< XAccessible > xChild;
366 if(m_xCurChild.is())
368 xChild = m_xCurChild;
370 return xChild;
373 void SAL_CALL SvxPixelCtlAccessible::deselectAccessibleChild( sal_Int32 ) throw (lang::IndexOutOfBoundsException, RuntimeException, std::exception)
377 // Added by lq
378 void SvxPixelCtlAccessible::ensureIsAlive() const
379 throw ( lang::DisposedException )
381 if( !IsAlive() )
382 throw lang::DisposedException();
385 //XAccessibleEventBroadcaster
386 void SAL_CALL SvxPixelCtlAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener ) throw( RuntimeException, std::exception )
388 if (xListener.is())
390 ::osl::MutexGuard aGuard( m_aMutex );
391 if (!mnClientId)
392 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
393 comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
397 void SAL_CALL SvxPixelCtlAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
398 throw( RuntimeException, std::exception )
400 if (xListener.is())
402 ::osl::MutexGuard aGuard( m_aMutex );
404 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
405 if ( !nListenerCount )
407 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
408 mnClientId = 0;
412 void SvxPixelCtlAccessible::CommitChange( const AccessibleEventObject& rEvent )
414 if (mnClientId)
415 comphelper::AccessibleEventNotifier::addEvent( mnClientId, rEvent );
418 //Solution:Add the event handling method
419 void SvxPixelCtlAccessible::FireAccessibleEvent (short nEventId, const ::com::sun::star::uno::Any& rOld, const ::com::sun::star::uno::Any& rNew)
421 const uno::Reference< XInterface > xSource( *this );
422 CommitChange( AccessibleEventObject( xSource, nEventId, rNew,rOld ) );
425 void SAL_CALL SvxPixelCtlAccessible::disposing()
427 if( !rBHelper.bDisposed )
430 ::osl::MutexGuard aGuard( m_aMutex );
431 if ( mnClientId )
433 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
434 mnClientId = 0;
437 //mxParent = uno::Reference< XAccessible >();
442 void SvxPixelCtlAccessible::NotifyChild(long nIndex,bool bSelect ,bool bCheck)
444 DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
446 SvxPixelCtlAccessibleChild *pChild= NULL;
448 if (m_xCurChild.is())
450 pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
451 DBG_ASSERT(pChild,"Child Must be Valid");
452 if (pChild->getAccessibleIndexInParent() == nIndex )
454 if (bSelect)
456 pChild->SelectChild(true);
458 if (bCheck)
460 pChild->ChangePixelColorOrBG( mrPixelCtl.GetBitmapPixel(sal_uInt16(nIndex)) != 0);
461 pChild->CheckChild();
463 return ;
466 uno::Reference <XAccessible> xNewChild =CreateChild(nIndex, mrPixelCtl.IndexToPoint(nIndex));
467 SvxPixelCtlAccessibleChild *pNewChild= static_cast<SvxPixelCtlAccessibleChild*>(xNewChild.get());
468 DBG_ASSERT(pNewChild,"Child Must be Valid");
470 Any aNewValue,aOldValue;
471 aNewValue<<= xNewChild;
472 FireAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
473 aOldValue,
474 aNewValue );
476 if (bSelect)
478 if (pChild)
480 pChild->SelectChild(false);
482 pNewChild->SelectChild(true);
484 if (bCheck)
486 pNewChild->CheckChild();
488 m_xCurChild= xNewChild;
493 uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (long nIndex,Point mPoint)
495 long nX = mPoint.X();
496 long nY = mPoint.Y();
497 if( Application::GetSettings().GetLayoutRTL())
499 nX = (sal_uInt16) mrPixelCtl.GetWidth() - 1 - nX;
502 bool bPixelColorOrBG = mrPixelCtl.GetBitmapPixel(sal_uInt16(nIndex)) != 0;
503 Size size(mrPixelCtl.GetWidth() / mrPixelCtl.GetLineCount(),mrPixelCtl.GetHeight() / mrPixelCtl.GetLineCount());
504 uno::Reference<XAccessible> xChild;
505 xChild = new SvxPixelCtlAccessibleChild(mrPixelCtl,
506 bPixelColorOrBG,
507 Point(nX,nY),
508 Rectangle(mPoint,size),
509 this,
510 nIndex);
512 return xChild;
516 void SvxPixelCtlAccessible::LoseFocus()
518 m_xCurChild = uno::Reference< XAccessible >() ;
521 void SvxPixelCtlAccessibleChild::CheckChild()
523 Any aChecked;
524 aChecked <<= AccessibleStateType::CHECKED;
526 if (m_bPixelColorOrBG)//Current Child State
528 FireAccessibleEvent( AccessibleEventId::STATE_CHANGED,
529 Any(),
530 aChecked);
532 else
534 FireAccessibleEvent( AccessibleEventId::STATE_CHANGED,
535 aChecked,
536 Any() );
540 void SvxPixelCtlAccessibleChild::SelectChild( bool bSelect)
542 Any aSelected;
543 aSelected <<= AccessibleStateType::SELECTED;
545 if (bSelect)
547 FireAccessibleEvent( AccessibleEventId::STATE_CHANGED,
548 Any(),
549 aSelected);
551 else
553 FireAccessibleEvent( AccessibleEventId::STATE_CHANGED,
554 aSelected,
555 Any());
558 void SvxPixelCtlAccessibleChild::FireAccessibleEvent (
559 short nEventId,
560 const ::com::sun::star::uno::Any& rOld,
561 const ::com::sun::star::uno::Any& rNew)
563 const uno::Reference< XInterface > xSource( *this );
564 CommitChange( AccessibleEventObject( xSource, nEventId, rNew,rOld ) );
567 SvxPixelCtlAccessibleChild::SvxPixelCtlAccessibleChild(
568 SvxPixelCtl& rWindow,
569 bool bPixelColorOrBG,
570 const Point &aPoint,
571 const Rectangle& rBoundingBox,
572 const uno::Reference<XAccessible>& rxParent,
573 long nIndexInParent ) :
574 SvxPixelCtlAccessibleChild_BASE( m_aMutex ),
575 mrParentWindow( rWindow ),
576 mxParent(rxParent),
577 m_bPixelColorOrBG(bPixelColorOrBG),
578 maPoint(aPoint),
579 mpBoundingBox( new Rectangle( rBoundingBox ) ),
580 mnIndexInParent( nIndexInParent ),
581 mnClientId( 0 )
586 SvxPixelCtlAccessibleChild::~SvxPixelCtlAccessibleChild()
588 if( IsAlive() )
590 osl_atomic_increment( &m_refCount );
591 dispose(); // set mpRepr = NULL & release all childs
595 //===== XAccessible =========================================================
597 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext( void ) throw( RuntimeException, std::exception )
599 return this;
602 //===== XAccessibleComponent ================================================
604 sal_Bool SAL_CALL SvxPixelCtlAccessibleChild::containsPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
606 // no guard -> done in getBounds()
607 // return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
608 return Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
611 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& ) throw( RuntimeException, std::exception )
613 return uno::Reference< XAccessible >();
616 awt::Rectangle SAL_CALL SvxPixelCtlAccessibleChild::getBounds() throw( RuntimeException, std::exception )
618 // no guard -> done in getBoundingBox()
619 //Modified by lq, 09/26
620 //return AWTRectangle( GetBoundingBox() );
621 awt::Rectangle rect = AWTRectangle( GetBoundingBox() );
622 rect.X = rect.X + mrParentWindow.GetClientWindowExtentsRelative(NULL).Left()-mrParentWindow.GetWindowExtentsRelative(NULL).Left();
623 rect.Y = rect.Y + mrParentWindow.GetClientWindowExtentsRelative(NULL).Top()-mrParentWindow.GetWindowExtentsRelative(NULL).Top();
624 return rect;
625 // End
628 awt::Point SAL_CALL SvxPixelCtlAccessibleChild::getLocation() throw( RuntimeException, std::exception )
630 // no guard -> done in getBoundingBox()
631 return AWTPoint( GetBoundingBox().TopLeft() );
634 awt::Point SAL_CALL SvxPixelCtlAccessibleChild::getLocationOnScreen() throw( RuntimeException, std::exception )
636 // no guard -> done in getBoundingBoxOnScreen()
637 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
640 awt::Size SAL_CALL SvxPixelCtlAccessibleChild::getSize() throw( RuntimeException, std::exception )
642 // no guard -> done in getBoundingBox()
643 return AWTSize( GetBoundingBox().GetSize() );
646 void SAL_CALL SvxPixelCtlAccessibleChild::grabFocus() throw( RuntimeException, std::exception )
650 sal_Int32 SvxPixelCtlAccessibleChild::getForeground( )
651 throw (::com::sun::star::uno::RuntimeException, std::exception)
653 //::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
654 ::osl::MutexGuard aGuard( m_aMutex );
655 ThrowExceptionIfNotAlive();
656 return mrParentWindow.GetControlForeground().GetColor();
658 sal_Int32 SvxPixelCtlAccessibleChild::getBackground( )
659 throw (::com::sun::star::uno::RuntimeException, std::exception)
661 //::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
662 ::osl::MutexGuard aGuard( m_aMutex );
664 ThrowExceptionIfNotAlive();
665 return mrParentWindow.GetControlBackground().GetColor();
668 //===== XAccessibleContext ==================================================
670 sal_Int32 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChildCount( void ) throw( RuntimeException, std::exception )
672 return 0;
675 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 )
676 throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
678 throw lang::IndexOutOfBoundsException();
681 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent( void ) throw( RuntimeException, std::exception )
683 return mxParent;
686 sal_Int32 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleIndexInParent( void ) throw( RuntimeException, std::exception )
688 return mnIndexInParent;
691 sal_Int16 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRole( void ) throw( RuntimeException, std::exception )
693 return AccessibleRole::CHECK_BOX;
696 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleDescription( void ) throw( RuntimeException, std::exception )
698 ::osl::MutexGuard aGuard( m_aMutex );
700 return GetName();
703 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleName( void ) throw( RuntimeException, std::exception )
705 ::osl::MutexGuard aGuard( m_aMutex );
706 return GetName();
709 /** Return empty uno::Reference to indicate that the relation set is not
710 supported.
712 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet( void ) throw( RuntimeException, std::exception )
714 return uno::Reference< XAccessibleRelationSet >();
717 uno::Reference< XAccessibleStateSet > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet( void ) throw( RuntimeException, std::exception )
719 ::osl::MutexGuard aGuard( m_aMutex );
720 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
722 if( IsAlive() )
725 pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
726 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
727 pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
728 pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
729 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
730 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
732 long nIndex = mrParentWindow.GetFoucsPosIndex();
733 if ( nIndex == mnIndexInParent)
735 pStateSetHelper->AddState( AccessibleStateType::SELECTED );
737 if (mrParentWindow.GetBitmapPixel(sal_uInt16(mnIndexInParent)))
739 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
742 else
743 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
745 return pStateSetHelper;
748 lang::Locale SAL_CALL SvxPixelCtlAccessibleChild::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException, std::exception )
750 ::osl::MutexGuard aGuard( m_aMutex );
751 if( mxParent.is() )
753 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
754 if( xParentContext.is() )
755 return xParentContext->getLocale();
758 // No locale and no parent. Therefore throw exception to indicate this
759 // cluelessness.
760 throw IllegalAccessibleComponentStateException();
763 void SAL_CALL SvxPixelCtlAccessibleChild::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
764 throw( RuntimeException, std::exception )
766 if (xListener.is())
768 ::osl::MutexGuard aGuard( m_aMutex );
769 if (!mnClientId)
770 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
771 comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
775 void SAL_CALL SvxPixelCtlAccessibleChild::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
776 throw( RuntimeException, std::exception )
778 if (xListener.is())
780 ::osl::MutexGuard aGuard( m_aMutex );
782 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
783 if ( !nListenerCount )
785 // no listeners anymore
786 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
787 // and at least to us not firing any events anymore, in case somebody calls
788 // NotifyAccessibleEvent, again
789 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
790 mnClientId = 0;
796 //===== XServiceInfo ========================================================
797 OUString SAL_CALL SvxPixelCtlAccessibleChild::getImplementationName( void ) throw( RuntimeException, std::exception )
799 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxPixelCtlAccessibleChild" ) );
802 sal_Bool SAL_CALL SvxPixelCtlAccessibleChild::supportsService( const OUString& rServiceName ) throw( RuntimeException, std::exception )
804 return cppu::supportsService( this, rServiceName );
807 Sequence< OUString > SAL_CALL SvxPixelCtlAccessibleChild::getSupportedServiceNames( void ) throw( RuntimeException, std::exception )
809 uno::Sequence< OUString > aRet(3);
810 OUString* pArray = aRet.getArray();
811 pArray[0] = "Accessible";
812 pArray[1] = "AccessibleContext";
813 pArray[2] = "AccessibleComponent";
814 return aRet;
817 //===== internal ============================================================
819 void SvxPixelCtlAccessibleChild::CommitChange( const AccessibleEventObject& rEvent )
821 if (mnClientId)
822 comphelper::AccessibleEventNotifier::addEvent( mnClientId, rEvent );
825 void SAL_CALL SvxPixelCtlAccessibleChild::disposing()
827 if( !rBHelper.bDisposed )
829 ::osl::MutexGuard aGuard( m_aMutex );
831 // Send a disposing to all listeners.
832 if ( mnClientId )
834 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
835 mnClientId = 0;
838 mxParent = uno::Reference< XAccessible >();
840 delete mpBoundingBox;
844 void SvxPixelCtlAccessibleChild::ThrowExceptionIfNotAlive( void ) throw( lang::DisposedException )
846 if( IsNotAlive() )
847 throw lang::DisposedException();
850 Rectangle SvxPixelCtlAccessibleChild::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
852 ::osl::MutexGuard aGuard( m_aMutex );
854 // no ThrowExceptionIfNotAlive() because its done in GetBoundingBox()
855 Rectangle aRect( GetBoundingBox() );
857 return Rectangle( mrParentWindow.OutputToAbsoluteScreenPixel( aRect.TopLeft() ), aRect.GetSize() );
860 Rectangle SvxPixelCtlAccessibleChild::GetBoundingBox( void ) throw( RuntimeException )
862 // no guard necessary, because no one changes mpBoundingBox after creating it
863 ThrowExceptionIfNotAlive();
865 return *mpBoundingBox;
868 OUString SvxPixelCtlAccessibleChild::GetName()
870 sal_Int32 nXIndex = mnIndexInParent % mrParentWindow.GetLineCount();
871 sal_Int32 nYIndex = mnIndexInParent / mrParentWindow.GetLineCount();
873 OUString str;
874 str += "(";
875 str += OUString::number(nXIndex);
876 str += ",";
877 str += OUString::number(nYIndex);
878 str += ")";
879 return str;
882 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */