Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / accessibility / GraphCtlAccessibleContext.cxx
blob74ffcab8b5f96f216734d75cb51daa4f1a0b2159
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/DisposedException.hpp>
24 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
25 #include <com/sun/star/awt/XWindow.hpp>
26 #include <unotools/accessiblestatesethelper.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
32 #include <osl/mutex.hxx>
33 #include <tools/gen.hxx>
34 #include <svl/smplhint.hxx>
35 #include <toolkit/helper/convert.hxx>
36 #include <svtools/colorcfg.hxx>
37 #include <comphelper/accessibleeventnotifier.hxx>
38 #include <svx/sdrpaintwindow.hxx>
40 //===== local includes ========================================================
41 #include <svx/ShapeTypeHandler.hxx>
42 #include <svx/AccessibleShapeInfo.hxx>
43 #include "GraphCtlAccessibleContext.hxx"
44 #include <svx/graphctl.hxx>
45 #include <svx/dialogs.hrc>
46 #include "accessibility.hrc"
47 #include <svx/svdpage.hxx>
48 #include <svx/unomod.hxx>
49 #include <svx/dialmgr.hxx>
50 #include <svx/svdetc.hxx>
51 #include <svx/sdrhittesthelper.hxx>
53 //===== namespaces ===========================================================
55 using namespace ::cppu;
56 using namespace ::osl;
57 using namespace ::accessibility;
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::drawing;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::accessibility;
65 //===== internal ============================================================
67 /** initialize this component and set default values */
68 SvxGraphCtrlAccessibleContext::SvxGraphCtrlAccessibleContext(
69 const Reference< XAccessible >& rxParent,
70 GraphCtrl& rRepr,
71 const OUString* pName,
72 const OUString* pDesc ) :
74 SvxGraphCtrlAccessibleContext_Base( m_aMutex ),
75 mxParent( rxParent ),
76 mpControl( &rRepr ),
77 mpModel (NULL),
78 mpPage (NULL),
79 mpView (NULL),
80 mnClientId( 0 ),
81 mbDisposed( false )
83 if (mpControl != NULL)
85 mpModel = mpControl->GetSdrModel();
86 if (mpModel != NULL)
87 mpPage = (SdrPage*)mpModel->GetPage( 0 );
88 mpView = mpControl->GetSdrView();
90 if( mpModel == NULL || mpPage == NULL || mpView == NULL )
92 mbDisposed = true;
93 // Set all the pointers to NULL just in case they are used as
94 // a disposed flag.
95 mpModel = NULL;
96 mpPage = NULL;
97 mpView = NULL;
101 if( pName )
103 msName = *pName;
105 else
107 ::SolarMutexGuard aSolarGuard;
108 msName = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_NAME );
111 if( pDesc )
113 msDescription = *pDesc;
115 else
117 ::SolarMutexGuard aSolarGuard;
118 msDescription = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_DESCRIPTION );
121 maTreeInfo.SetSdrView( mpView );
122 maTreeInfo.SetWindow( mpControl );
123 maTreeInfo.SetViewForwarder( const_cast<SvxGraphCtrlAccessibleContext*>(this) );
128 /** on destruction, this component is disposed and all dispose listeners
129 are called, except if this component was already disposed */
130 SvxGraphCtrlAccessibleContext::~SvxGraphCtrlAccessibleContext()
132 disposing();
137 /** returns the XAccessible interface for a given SdrObject.
138 Multiple calls for the same SdrObject return the same XAccessible.
140 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessible( const SdrObject* pObj )
142 Reference<XAccessible> xAccessibleShape;
144 if( pObj )
146 // see if we already created an XAccessible for the given SdrObject
147 ShapesMapType::iterator iter = mxShapes.find( pObj );
149 if( iter != mxShapes.end() )
151 // if we already have one, return it
152 xAccessibleShape = (*iter).second;
154 else
156 // create a new one and remember in our internal map
157 Reference< XShape > xShape( Reference< XShape >::query( (const_cast<SdrObject*>(pObj))->getUnoShape() ) );
159 AccessibleShapeInfo aShapeInfo (xShape,mxParent);
160 // Create accessible object that corresponds to the descriptor's shape.
161 AccessibleShape* pAcc = ShapeTypeHandler::Instance().CreateAccessibleObject(
162 aShapeInfo, maTreeInfo);
163 xAccessibleShape = pAcc;
164 if (pAcc != NULL)
166 pAcc->acquire();
167 // Now that we acquired the new accessible shape we can
168 // safely call its Init() method.
169 pAcc->Init ();
171 mxShapes[pObj] = pAcc;
173 // Create event and inform listeners of the object creation.
174 CommitChange( AccessibleEventId::CHILD, makeAny( xAccessibleShape ), makeAny( Reference<XAccessible>() ) );
178 return xAccessibleShape;
181 //===== XAccessible =========================================================
183 Reference< XAccessibleContext > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleContext( void ) throw( RuntimeException, std::exception )
185 return this;
188 //===== XAccessibleComponent ================================================
190 sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::containsPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
192 // no guard -> done in getSize()
193 awt::Size aSize (getSize());
194 return (rPoint.X >= 0)
195 && (rPoint.X < aSize.Width)
196 && (rPoint.Y >= 0)
197 && (rPoint.Y < aSize.Height);
202 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleAtPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
204 ::osl::MutexGuard aGuard( m_aMutex );
206 Reference< XAccessible > xAccessible;
208 if( mpControl )
210 Point aPnt( rPoint.X, rPoint.Y );
211 mpControl->PixelToLogic( aPnt );
213 SdrObject* pObj = 0;
215 if(mpView && mpView->GetSdrPageView())
217 pObj = SdrObjListPrimitiveHit(*mpPage, aPnt, 1, *mpView->GetSdrPageView(), 0, false);
220 if( pObj )
221 xAccessible = getAccessible( pObj );
223 else
225 throw DisposedException();
228 return xAccessible;
233 awt::Rectangle SAL_CALL SvxGraphCtrlAccessibleContext::getBounds() throw( RuntimeException, std::exception )
235 // no guard -> done in GetBoundingBox()
236 Rectangle aCoreBounds( GetBoundingBox() );
237 awt::Rectangle aBounds;
238 aBounds.X = aCoreBounds.getX();
239 aBounds.Y = aCoreBounds.getY();
240 aBounds.Width = aCoreBounds.getWidth();
241 aBounds.Height = aCoreBounds.getHeight();
242 return aBounds;
247 awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocation() throw( RuntimeException, std::exception )
249 // no guard -> done in GetBoundingBox()
250 Rectangle aRect( GetBoundingBox() );
251 return awt::Point( aRect.getX(), aRect.getY() );
256 awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocationOnScreen() throw( RuntimeException, std::exception )
258 // no guard -> done in GetBoundingBoxOnScreen()
259 Rectangle aRect( GetBoundingBoxOnScreen() );
260 return awt::Point( aRect.getX(), aRect.getY() );
265 awt::Size SAL_CALL SvxGraphCtrlAccessibleContext::getSize() throw( RuntimeException, std::exception )
267 // no guard -> done in GetBoundingBox()
268 Rectangle aRect( GetBoundingBox() );
269 return awt::Size( aRect.getWidth(), aRect.getHeight() );
273 //===== XAccessibleContext ==================================================
275 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChildCount( void ) throw( RuntimeException, std::exception )
277 ::SolarMutexGuard aGuard;
279 if( NULL == mpPage )
280 throw DisposedException();
282 return mpPage->GetObjCount();
287 /** returns the SdrObject at index nIndex from the model of this graph */
288 SdrObject* SvxGraphCtrlAccessibleContext::getSdrObject( sal_Int32 nIndex )
289 throw( RuntimeException, lang::IndexOutOfBoundsException )
291 ::SolarMutexGuard aGuard;
293 if( NULL == mpPage )
294 throw DisposedException();
296 if( (nIndex < 0) || ( static_cast<sal_uInt32>(nIndex) >= mpPage->GetObjCount() ) )
297 throw lang::IndexOutOfBoundsException();
299 return mpPage->GetObj( nIndex );
304 /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
305 void SvxGraphCtrlAccessibleContext::CommitChange (
306 sal_Int16 nEventId,
307 const uno::Any& rNewValue,
308 const uno::Any& rOldValue)
310 AccessibleEventObject aEvent (
311 static_cast<uno::XWeak*>(this),
312 nEventId,
313 rNewValue,
314 rOldValue);
316 FireEvent (aEvent);
319 /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
320 void SvxGraphCtrlAccessibleContext::FireEvent (const AccessibleEventObject& aEvent)
322 if (mnClientId)
323 comphelper::AccessibleEventNotifier::addEvent( mnClientId, aEvent );
328 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChild( sal_Int32 nIndex )
329 throw( RuntimeException, lang::IndexOutOfBoundsException, std::exception )
331 ::SolarMutexGuard aGuard;
333 return getAccessible( getSdrObject( nIndex ) );
338 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleParent( void ) throw( RuntimeException, std::exception )
340 return mxParent;
345 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleIndexInParent( void ) throw( RuntimeException, std::exception )
347 ::SolarMutexGuard aGuard;
348 // Use a simple but slow solution for now. Optimize later.
350 // Iterate over all the parent's children and search for this object.
351 if( mxParent.is() )
353 Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
354 if( xParentContext.is() )
356 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
357 for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
359 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
360 if( xChild.is() )
362 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
363 if( xChildContext == ( XAccessibleContext* ) this )
364 return i;
370 // Return -1 to indicate that this object's parent does not know about the
371 // object.
372 return -1;
377 sal_Int16 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRole( void ) throw( RuntimeException, std::exception )
379 return AccessibleRole::PANEL;
384 OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleDescription( void ) throw( RuntimeException, std::exception )
386 ::SolarMutexGuard aGuard;
387 return msDescription;
392 OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleName( void ) throw( RuntimeException, std::exception )
394 ::SolarMutexGuard aGuard;
395 return msName;
400 /** Return empty reference to indicate that the relation set is not
401 supported.
403 Reference< XAccessibleRelationSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRelationSet( void ) throw( RuntimeException, std::exception )
405 return Reference< XAccessibleRelationSet >();
410 Reference< XAccessibleStateSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleStateSet( void ) throw( RuntimeException, std::exception )
412 ::SolarMutexGuard aGuard;
414 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
416 if ( rBHelper.bDisposed || mbDisposed )
418 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
420 else
422 pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
423 if( mpControl->HasFocus() )
424 pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
425 pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
426 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
427 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
430 return pStateSetHelper;
435 lang::Locale SAL_CALL SvxGraphCtrlAccessibleContext::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException, std::exception )
437 ::SolarMutexGuard aGuard;
439 if( mxParent.is() )
441 Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
442 if( xParentContext.is() )
443 return xParentContext->getLocale();
446 // No parent. Therefore throw exception to indicate this cluelessness.
447 throw IllegalAccessibleComponentStateException();
450 //===== XAccessibleEventListener ============================================
452 void SAL_CALL SvxGraphCtrlAccessibleContext::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
453 throw( RuntimeException, std::exception )
455 if (xListener.is())
457 ::SolarMutexGuard aGuard;
458 if (!mnClientId)
459 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
460 comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
466 void SAL_CALL SvxGraphCtrlAccessibleContext::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
467 throw( RuntimeException, std::exception )
469 if (xListener.is())
471 ::SolarMutexGuard aGuard;
473 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
474 if ( !nListenerCount )
476 // no listeners anymore
477 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
478 // and at least to us not firing any events anymore, in case somebody calls
479 // NotifyAccessibleEvent, again
480 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
481 mnClientId = 0;
488 void SAL_CALL SvxGraphCtrlAccessibleContext::addFocusListener( const Reference< awt::XFocusListener >& xListener )
489 throw( RuntimeException )
491 ::SolarMutexGuard aGuard;
493 if( xListener.is() )
495 Reference< ::com::sun::star::awt::XWindow > xWindow( VCLUnoHelper::GetInterface( mpControl ) );
496 if( xWindow.is() )
497 xWindow->addFocusListener( xListener );
503 void SAL_CALL SvxGraphCtrlAccessibleContext::removeFocusListener( const Reference< awt::XFocusListener >& xListener )
504 throw (RuntimeException)
506 ::SolarMutexGuard aGuard;
508 if( xListener.is() )
510 Reference< ::com::sun::star::awt::XWindow > xWindow = VCLUnoHelper::GetInterface( mpControl );
511 if( xWindow.is() )
512 xWindow->removeFocusListener( xListener );
518 void SAL_CALL SvxGraphCtrlAccessibleContext::grabFocus() throw( RuntimeException, std::exception )
520 ::SolarMutexGuard aGuard;
522 if( NULL == mpControl )
523 throw DisposedException();
525 mpControl->GrabFocus();
530 Any SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleKeyBinding() throw( RuntimeException )
532 // here is no implementation, because here are no KeyBindings for every object
533 return Any();
540 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getForeground (void)
541 throw (::com::sun::star::uno::RuntimeException, std::exception)
543 svtools::ColorConfig aColorConfig;
544 sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
545 return static_cast<sal_Int32>(nColor);
551 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getBackground (void)
552 throw (::com::sun::star::uno::RuntimeException, std::exception)
554 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
555 return static_cast<sal_Int32>(nColor);
559 //===== XServiceInfo ========================================================
560 OUString SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationName( void ) throw( RuntimeException, std::exception )
562 return OUString( "com.sun.star.comp.ui.SvxGraphCtrlAccessibleContext" );
565 sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::supportsService( const OUString& sServiceName ) throw( RuntimeException, std::exception )
567 return cppu::supportsService(this, sServiceName);
570 Sequence< OUString > SAL_CALL SvxGraphCtrlAccessibleContext::getSupportedServiceNames( void ) throw( RuntimeException, std::exception )
572 Sequence< OUString > aSNs( 3 );
574 aSNs[0] = "com.sun.star.accessibility.Accessible";
575 aSNs[1] = "com.sun.star.accessibility.AccessibleContext";
576 aSNs[2] = "com.sun.star.drawing.AccessibleGraphControl";
578 return aSNs;
581 //===== XTypeProvider =======================================================
582 Sequence<sal_Int8> SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationId( void ) throw( RuntimeException, std::exception )
584 return css::uno::Sequence<sal_Int8>();
587 //===== XServiceName ========================================================
589 OUString SvxGraphCtrlAccessibleContext::getServiceName( void ) throw( RuntimeException, std::exception )
591 return OUString( "com.sun.star.accessibility.AccessibleContext" );
594 //===== XAccessibleSelection =============================================
596 void SAL_CALL SvxGraphCtrlAccessibleContext::selectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
598 ::SolarMutexGuard aGuard;
600 if( NULL == mpView )
601 throw DisposedException();
603 SdrObject* pObj = getSdrObject( nIndex );
605 if( pObj )
606 mpView->MarkObj( pObj, mpView->GetSdrPageView());
611 sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::isAccessibleChildSelected( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
613 ::SolarMutexGuard aGuard;
615 if( NULL == mpView )
616 throw DisposedException();
618 return mpView->IsObjMarked( getSdrObject( nIndex ) );
623 void SAL_CALL SvxGraphCtrlAccessibleContext::clearAccessibleSelection() throw( RuntimeException, std::exception )
625 ::SolarMutexGuard aGuard;
627 if( NULL == mpView )
628 throw DisposedException();
630 mpView->UnmarkAllObj();
635 void SAL_CALL SvxGraphCtrlAccessibleContext::selectAllAccessibleChildren() throw( RuntimeException, std::exception )
637 ::SolarMutexGuard aGuard;
639 if( NULL == mpView )
640 throw DisposedException();
642 mpView->MarkAllObj();
647 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChildCount() throw( RuntimeException, std::exception )
649 ::SolarMutexGuard aGuard;
651 if( NULL == mpView )
652 throw DisposedException();
654 const SdrMarkList& rList = mpView->GetMarkedObjectList();
655 return rList.GetMarkCount();
660 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChild( sal_Int32 nIndex )
661 throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
663 ::SolarMutexGuard aGuard;
665 checkChildIndexOnSelection( nIndex );
667 Reference< XAccessible > xAccessible;
669 const SdrMarkList& rList = mpView->GetMarkedObjectList();
670 SdrObject* pObj = rList.GetMark(nIndex)->GetMarkedSdrObj();
671 if( pObj )
672 xAccessible = getAccessible( pObj );
674 return xAccessible;
679 void SAL_CALL SvxGraphCtrlAccessibleContext::deselectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException, std::exception )
681 ::SolarMutexGuard aGuard;
683 checkChildIndexOnSelection( nIndex );
685 if( mpView )
687 const SdrMarkList& rList = mpView->GetMarkedObjectList();
689 SdrObject* pObj = getSdrObject( nIndex );
690 if( pObj )
692 SdrMarkList aRefList( rList );
694 SdrPageView* pPV = mpView->GetSdrPageView();
695 mpView->UnmarkAllObj( pPV );
697 sal_uInt32 nCount = aRefList.GetMarkCount();
698 sal_uInt32 nMark;
699 for( nMark = 0; nMark < nCount; nMark++ )
701 if( aRefList.GetMark(nMark)->GetMarkedSdrObj() != pObj )
702 mpView->MarkObj( aRefList.GetMark(nMark)->GetMarkedSdrObj(), pPV );
708 //===== internals ========================================================
710 void SvxGraphCtrlAccessibleContext::checkChildIndexOnSelection( long nIndex ) throw( lang::IndexOutOfBoundsException )
712 if( nIndex < 0 || nIndex >= getSelectedAccessibleChildCount() )
713 throw lang::IndexOutOfBoundsException();
718 /** Replace the model, page, and view pointers by the ones provided
719 (explicitly and implicitly).
721 void SvxGraphCtrlAccessibleContext::setModelAndView (
722 SdrModel* pModel,
723 SdrView* pView)
725 ::SolarMutexGuard aGuard;
727 mpModel = pModel;
728 if (mpModel != NULL)
729 mpPage = (SdrPage*)mpModel->GetPage( 0 );
730 mpView = pView;
732 if (mpModel == NULL || mpPage == NULL || mpView == NULL)
734 mbDisposed = true;
736 // Set all the pointers to NULL just in case they are used as
737 // a disposed flag.
738 mpModel = NULL;
739 mpPage = NULL;
740 mpView = NULL;
743 maTreeInfo.SetSdrView (mpView);
750 void SAL_CALL SvxGraphCtrlAccessibleContext::disposing()
752 ::SolarMutexGuard aGuard;
754 if( mbDisposed )
755 return;
757 mbDisposed = true;
759 mpControl = NULL; // object dies with representation
760 mpView = NULL;
761 mpPage = NULL;
764 ShapesMapType::iterator I;
766 for (I=mxShapes.begin(); I!=mxShapes.end(); ++I)
768 XAccessible* pAcc = (*I).second;
769 Reference< XComponent > xComp( pAcc, UNO_QUERY );
770 if( xComp.is() )
771 xComp->dispose();
773 (*I).second->release();
776 mxShapes.clear();
779 // Send a disposing to all listeners.
780 if ( mnClientId )
782 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
783 mnClientId = 0;
789 Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
791 ::SolarMutexGuard aGuard;
793 if( NULL == mpControl )
794 throw DisposedException();
796 return Rectangle(
797 mpControl->GetAccessibleParentWindow()->OutputToAbsoluteScreenPixel(
798 mpControl->GetPosPixel() ),
799 mpControl->GetSizePixel() );
804 /** Calculate the relative coordinates of the bounding box as difference
805 between the absolute coordinates of the bounding boxes of this control
806 and its parent in the accessibility tree.
808 Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBox( void ) throw( RuntimeException )
810 ::SolarMutexGuard aGuard;
812 Rectangle aBounds ( 0, 0, 0, 0 );
814 Window* pWindow = mpControl;
815 if (pWindow != NULL)
817 aBounds = pWindow->GetWindowExtentsRelative (NULL);
818 Window* pParent = pWindow->GetAccessibleParentWindow();
819 if (pParent != NULL)
821 Rectangle aParentRect = pParent->GetWindowExtentsRelative (NULL);
822 aBounds -= aParentRect.TopLeft();
825 else
826 throw DisposedException();
828 return aBounds;
831 void SvxGraphCtrlAccessibleContext::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
833 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
835 if( pSdrHint )
837 switch( pSdrHint->GetKind() )
839 case HINT_OBJCHG:
841 ShapesMapType::iterator iter = mxShapes.find( pSdrHint->GetObject() );
843 if( iter != mxShapes.end() )
845 // if we already have one, return it
846 AccessibleShape* pShape = (*iter).second;
848 if( NULL != pShape )
849 pShape->CommitChange( AccessibleEventId::VISIBLE_DATA_CHANGED, uno::Any(), uno::Any() );
852 break;
854 case HINT_OBJINSERTED:
855 CommitChange( AccessibleEventId::CHILD, makeAny( getAccessible( pSdrHint->GetObject() ) ) , uno::Any());
856 break;
857 case HINT_OBJREMOVED:
858 CommitChange( AccessibleEventId::CHILD, uno::Any(), makeAny( getAccessible( pSdrHint->GetObject() ) ) );
859 break;
860 case HINT_MODELCLEARED:
861 dispose();
862 break;
863 default:
864 break;
867 else
869 const SfxSimpleHint* pSfxHint = PTR_CAST(SfxSimpleHint, &rHint );
871 // Has our SdDrawDocument just died?
872 if(pSfxHint && pSfxHint->GetId() == SFX_HINT_DYING)
874 dispose();
879 //===== IAccessibleViewforwarder ========================================
881 bool SvxGraphCtrlAccessibleContext::IsValid (void) const
883 return true;
888 Rectangle SvxGraphCtrlAccessibleContext::GetVisibleArea (void) const
890 Rectangle aVisArea;
892 if( mpView && mpView->PaintWindowCount())
894 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(0L);
895 aVisArea = pPaintWindow->GetVisibleArea();
898 return aVisArea;
903 Point SvxGraphCtrlAccessibleContext::LogicToPixel (const Point& rPoint) const
905 if( mpControl )
907 Rectangle aBBox(mpControl->GetWindowExtentsRelative(NULL));
908 return mpControl->LogicToPixel (rPoint) + aBBox.TopLeft();
910 else
912 return rPoint;
918 Size SvxGraphCtrlAccessibleContext::LogicToPixel (const Size& rSize) const
920 if( mpControl )
921 return mpControl->LogicToPixel (rSize);
922 else
923 return rSize;
928 Point SvxGraphCtrlAccessibleContext::PixelToLogic (const Point& rPoint) const
930 if( mpControl )
931 return mpControl->PixelToLogic (rPoint);
932 else
933 return rPoint;
938 Size SvxGraphCtrlAccessibleContext::PixelToLogic (const Size& rSize) const
940 if( mpControl )
941 return mpControl->PixelToLogic (rSize);
942 else
943 return rSize;
946 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */