fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / accessibility / GraphCtlAccessibleContext.cxx
blobdf0d9f8104a72783364aac3a1ece5342aab7a908
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/typeprovider.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <osl/mutex.hxx>
31 #include <tools/gen.hxx>
32 #include <svl/smplhint.hxx>
33 #include <toolkit/helper/convert.hxx>
34 #include <svtools/colorcfg.hxx>
35 #include <comphelper/accessibleeventnotifier.hxx>
36 #include <svx/sdrpaintwindow.hxx>
38 //===== local includes ========================================================
39 #include <svx/ShapeTypeHandler.hxx>
40 #include <svx/AccessibleShapeInfo.hxx>
41 #include "GraphCtlAccessibleContext.hxx"
42 #include <svx/graphctl.hxx>
43 #include <svx/dialogs.hrc>
44 #include "accessibility.hrc"
45 #include <svx/svdpage.hxx>
46 #include <svx/unomod.hxx>
47 #include <svx/dialmgr.hxx>
48 #include <svx/svdetc.hxx>
49 #include <svx/sdrhittesthelper.hxx>
51 //===== namespaces ===========================================================
53 using namespace ::cppu;
54 using namespace ::osl;
55 using namespace ::accessibility;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::drawing;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::accessibility;
63 //===== internal ============================================================
65 /** initialize this component and set default values */
66 SvxGraphCtrlAccessibleContext::SvxGraphCtrlAccessibleContext(
67 const Reference< XAccessible >& rxParent,
68 GraphCtrl& rRepr,
69 const OUString* pName,
70 const OUString* pDesc ) :
72 SvxGraphCtrlAccessibleContext_Base( m_aMutex ),
73 mxParent( rxParent ),
74 mpControl( &rRepr ),
75 mpModel (NULL),
76 mpPage (NULL),
77 mpView (NULL),
78 mnClientId( 0 ),
79 mbDisposed( sal_False )
81 if (mpControl != NULL)
83 mpModel = mpControl->GetSdrModel();
84 if (mpModel != NULL)
85 mpPage = (SdrPage*)mpModel->GetPage( 0 );
86 mpView = mpControl->GetSdrView();
88 if( mpModel == NULL || mpPage == NULL || mpView == NULL )
90 mbDisposed = true;
91 // Set all the pointers to NULL just in case they are used as
92 // a disposed flag.
93 mpModel = NULL;
94 mpPage = NULL;
95 mpView = NULL;
99 if( pName )
101 msName = *pName;
103 else
105 ::SolarMutexGuard aSolarGuard;
106 msName = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_NAME );
109 if( pDesc )
111 msDescription = *pDesc;
113 else
115 ::SolarMutexGuard aSolarGuard;
116 msDescription = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_DESCRIPTION );
119 maTreeInfo.SetSdrView( mpView );
120 maTreeInfo.SetWindow( mpControl );
121 maTreeInfo.SetViewForwarder( const_cast<SvxGraphCtrlAccessibleContext*>(this) );
124 //-----------------------------------------------------------------------------
126 /** on destruction, this component is disposed and all dispose listeners
127 are called, except if this component was already disposed */
128 SvxGraphCtrlAccessibleContext::~SvxGraphCtrlAccessibleContext()
130 disposing();
133 //-----------------------------------------------------------------------------
135 /** returns the XAccessible interface for a given SdrObject.
136 Multiple calls for the same SdrObject return the same XAccessible.
138 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessible( const SdrObject* pObj )
140 Reference<XAccessible> xAccessibleShape;
142 if( pObj )
144 // see if we already created an XAccessible for the given SdrObject
145 ShapesMapType::iterator iter = mxShapes.find( pObj );
147 if( iter != mxShapes.end() )
149 // if we already have one, return it
150 xAccessibleShape = (*iter).second;
152 else
154 // create a new one and remember in our internal map
155 Reference< XShape > xShape( Reference< XShape >::query( (const_cast<SdrObject*>(pObj))->getUnoShape() ) );
157 AccessibleShapeInfo aShapeInfo (xShape,mxParent);
158 // Create accessible object that corresponds to the descriptor's shape.
159 AccessibleShape* pAcc = ShapeTypeHandler::Instance().CreateAccessibleObject(
160 aShapeInfo, maTreeInfo);
161 xAccessibleShape = pAcc;
162 if (pAcc != NULL)
164 pAcc->acquire();
165 // Now that we acquired the new accessible shape we can
166 // safely call its Init() method.
167 pAcc->Init ();
169 mxShapes[pObj] = pAcc;
171 // Create event and inform listeners of the object creation.
172 CommitChange( AccessibleEventId::CHILD, makeAny( xAccessibleShape ), makeAny( Reference<XAccessible>() ) );
176 return xAccessibleShape;
179 //===== XAccessible =========================================================
181 Reference< XAccessibleContext > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleContext( void ) throw( RuntimeException )
183 return this;
186 //===== XAccessibleComponent ================================================
188 sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::containsPoint( const awt::Point& rPoint ) throw( RuntimeException )
190 // no guard -> done in getSize()
191 awt::Size aSize (getSize());
192 return (rPoint.X >= 0)
193 && (rPoint.X < aSize.Width)
194 && (rPoint.Y >= 0)
195 && (rPoint.Y < aSize.Height);
198 //-----------------------------------------------------------------------------
200 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleAtPoint( const awt::Point& rPoint ) throw( RuntimeException )
202 ::osl::MutexGuard aGuard( m_aMutex );
204 Reference< XAccessible > xAccessible;
206 if( mpControl )
208 Point aPnt( rPoint.X, rPoint.Y );
209 mpControl->PixelToLogic( aPnt );
211 SdrObject* pObj = 0;
213 if(mpView && mpView->GetSdrPageView())
215 pObj = SdrObjListPrimitiveHit(*mpPage, aPnt, 1, *mpView->GetSdrPageView(), 0, false);
218 if( pObj )
219 xAccessible = getAccessible( pObj );
221 else
223 throw DisposedException();
226 return xAccessible;
229 //-----------------------------------------------------------------------------
231 awt::Rectangle SAL_CALL SvxGraphCtrlAccessibleContext::getBounds() throw( RuntimeException )
233 // no guard -> done in GetBoundingBox()
234 Rectangle aCoreBounds( GetBoundingBox() );
235 awt::Rectangle aBounds;
236 aBounds.X = aCoreBounds.getX();
237 aBounds.Y = aCoreBounds.getY();
238 aBounds.Width = aCoreBounds.getWidth();
239 aBounds.Height = aCoreBounds.getHeight();
240 return aBounds;
243 //-----------------------------------------------------------------------------
245 awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocation() throw( RuntimeException )
247 // no guard -> done in GetBoundingBox()
248 Rectangle aRect( GetBoundingBox() );
249 return awt::Point( aRect.getX(), aRect.getY() );
252 //-----------------------------------------------------------------------------
254 awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocationOnScreen() throw( RuntimeException )
256 // no guard -> done in GetBoundingBoxOnScreen()
257 Rectangle aRect( GetBoundingBoxOnScreen() );
258 return awt::Point( aRect.getX(), aRect.getY() );
261 //-----------------------------------------------------------------------------
263 awt::Size SAL_CALL SvxGraphCtrlAccessibleContext::getSize() throw( RuntimeException )
265 // no guard -> done in GetBoundingBox()
266 Rectangle aRect( GetBoundingBox() );
267 return awt::Size( aRect.getWidth(), aRect.getHeight() );
271 //===== XAccessibleContext ==================================================
273 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChildCount( void ) throw( RuntimeException )
275 ::SolarMutexGuard aGuard;
277 if( NULL == mpPage )
278 throw DisposedException();
280 return mpPage->GetObjCount();
283 //-----------------------------------------------------------------------------
285 /** returns the SdrObject at index nIndex from the model of this graph */
286 SdrObject* SvxGraphCtrlAccessibleContext::getSdrObject( sal_Int32 nIndex )
287 throw( RuntimeException, lang::IndexOutOfBoundsException )
289 ::SolarMutexGuard aGuard;
291 if( NULL == mpPage )
292 throw DisposedException();
294 if( (nIndex < 0) || ( static_cast<sal_uInt32>(nIndex) >= mpPage->GetObjCount() ) )
295 throw lang::IndexOutOfBoundsException();
297 return mpPage->GetObj( nIndex );
300 //-----------------------------------------------------------------------------
302 /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
303 void SvxGraphCtrlAccessibleContext::CommitChange (
304 sal_Int16 nEventId,
305 const uno::Any& rNewValue,
306 const uno::Any& rOldValue)
308 AccessibleEventObject aEvent (
309 static_cast<uno::XWeak*>(this),
310 nEventId,
311 rNewValue,
312 rOldValue);
314 FireEvent (aEvent);
317 /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
318 void SvxGraphCtrlAccessibleContext::FireEvent (const AccessibleEventObject& aEvent)
320 if (mnClientId)
321 comphelper::AccessibleEventNotifier::addEvent( mnClientId, aEvent );
324 //-----------------------------------------------------------------------------
326 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChild( sal_Int32 nIndex )
327 throw( RuntimeException, lang::IndexOutOfBoundsException )
329 ::SolarMutexGuard aGuard;
331 return getAccessible( getSdrObject( nIndex ) );
334 //-----------------------------------------------------------------------------
336 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleParent( void ) throw( RuntimeException )
338 return mxParent;
341 //-----------------------------------------------------------------------------
343 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleIndexInParent( void ) throw( RuntimeException )
345 ::SolarMutexGuard aGuard;
346 // Use a simple but slow solution for now. Optimize later.
348 // Iterate over all the parent's children and search for this object.
349 if( mxParent.is() )
351 Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
352 if( xParentContext.is() )
354 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
355 for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
357 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
358 if( xChild.is() )
360 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
361 if( xChildContext == ( XAccessibleContext* ) this )
362 return i;
368 // Return -1 to indicate that this object's parent does not know about the
369 // object.
370 return -1;
373 //-----------------------------------------------------------------------------
375 sal_Int16 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRole( void ) throw( RuntimeException )
377 return AccessibleRole::PANEL;
380 //-----------------------------------------------------------------------------
382 OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleDescription( void ) throw( RuntimeException )
384 ::SolarMutexGuard aGuard;
385 return msDescription;
388 //-----------------------------------------------------------------------------
390 OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleName( void ) throw( RuntimeException )
392 ::SolarMutexGuard aGuard;
393 return msName;
396 //-----------------------------------------------------------------------------
398 /** Return empty reference to indicate that the relation set is not
399 supported.
401 Reference< XAccessibleRelationSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRelationSet( void ) throw( RuntimeException )
403 return Reference< XAccessibleRelationSet >();
406 //-----------------------------------------------------------------------------
408 Reference< XAccessibleStateSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleStateSet( void ) throw( RuntimeException )
410 ::SolarMutexGuard aGuard;
412 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
414 if ( rBHelper.bDisposed || mbDisposed )
416 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
418 else
420 pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
421 if( mpControl->HasFocus() )
422 pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
423 pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
424 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
425 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
428 return pStateSetHelper;
431 //-----------------------------------------------------------------------------
433 lang::Locale SAL_CALL SvxGraphCtrlAccessibleContext::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException )
435 ::SolarMutexGuard aGuard;
437 if( mxParent.is() )
439 Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
440 if( xParentContext.is() )
441 return xParentContext->getLocale();
444 // No parent. Therefore throw exception to indicate this cluelessness.
445 throw IllegalAccessibleComponentStateException();
448 //===== XAccessibleEventListener ============================================
450 void SAL_CALL SvxGraphCtrlAccessibleContext::addAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
451 throw( RuntimeException )
453 if (xListener.is())
455 ::SolarMutexGuard aGuard;
456 if (!mnClientId)
457 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
458 comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
462 //-----------------------------------------------------------------------------
464 void SAL_CALL SvxGraphCtrlAccessibleContext::removeAccessibleEventListener( const Reference< XAccessibleEventListener >& xListener )
465 throw( RuntimeException )
467 if (xListener.is())
469 ::SolarMutexGuard aGuard;
471 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
472 if ( !nListenerCount )
474 // no listeners anymore
475 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
476 // and at least to us not firing any events anymore, in case somebody calls
477 // NotifyAccessibleEvent, again
478 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
479 mnClientId = 0;
484 //-----------------------------------------------------------------------------
486 void SAL_CALL SvxGraphCtrlAccessibleContext::addFocusListener( const Reference< awt::XFocusListener >& xListener )
487 throw( RuntimeException )
489 ::SolarMutexGuard aGuard;
491 if( xListener.is() )
493 Reference< ::com::sun::star::awt::XWindow > xWindow( VCLUnoHelper::GetInterface( mpControl ) );
494 if( xWindow.is() )
495 xWindow->addFocusListener( xListener );
499 //-----------------------------------------------------------------------------
501 void SAL_CALL SvxGraphCtrlAccessibleContext::removeFocusListener( const Reference< awt::XFocusListener >& xListener )
502 throw (RuntimeException)
504 ::SolarMutexGuard aGuard;
506 if( xListener.is() )
508 Reference< ::com::sun::star::awt::XWindow > xWindow = VCLUnoHelper::GetInterface( mpControl );
509 if( xWindow.is() )
510 xWindow->removeFocusListener( xListener );
514 //-----------------------------------------------------------------------------
516 void SAL_CALL SvxGraphCtrlAccessibleContext::grabFocus() throw( RuntimeException )
518 ::SolarMutexGuard aGuard;
520 if( NULL == mpControl )
521 throw DisposedException();
523 mpControl->GrabFocus();
526 //-----------------------------------------------------------------------------
528 Any SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleKeyBinding() throw( RuntimeException )
530 // here is no implementation, because here are no KeyBindings for every object
531 return Any();
538 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getForeground (void)
539 throw (::com::sun::star::uno::RuntimeException)
541 svtools::ColorConfig aColorConfig;
542 sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
543 return static_cast<sal_Int32>(nColor);
549 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getBackground (void)
550 throw (::com::sun::star::uno::RuntimeException)
552 sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
553 return static_cast<sal_Int32>(nColor);
557 //===== XServiceInfo ========================================================
559 OUString SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationName( void ) throw( RuntimeException )
561 return OUString( "com.sun.star.comp.ui.SvxGraphCtrlAccessibleContext" );
564 //-----------------------------------------------------------------------------
566 sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::supportsService( const OUString& sServiceName ) throw( RuntimeException )
568 ::SolarMutexGuard aGuard;
569 // Iterate over all supported service names and return true if on of them
570 // matches the given name.
571 Sequence< OUString > aSupportedServices( getSupportedServiceNames() );
572 int nLenght = aSupportedServices.getLength();
574 for( int i = 0 ; i < nLenght ; ++i )
576 if( sServiceName == aSupportedServices[ i ] )
577 return sal_True;
580 return sal_False;
583 //-----------------------------------------------------------------------------
585 Sequence< OUString > SAL_CALL SvxGraphCtrlAccessibleContext::getSupportedServiceNames( void ) throw( RuntimeException )
587 Sequence< OUString > aSNs( 3 );
589 aSNs[0] = "com.sun.star.accessibility.Accessible";
590 aSNs[1] = "com.sun.star.accessibility.AccessibleContext";
591 aSNs[2] = "com.sun.star.drawing.AccessibleGraphControl";
593 return aSNs;
596 //===== XTypeProvider =======================================================
598 Sequence<sal_Int8> SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationId( void ) throw( RuntimeException )
600 ::SolarMutexGuard aGuard;
601 return getUniqueId();
604 //===== XServiceName ========================================================
606 OUString SvxGraphCtrlAccessibleContext::getServiceName( void ) throw( RuntimeException )
608 return OUString( "com.sun.star.accessibility.AccessibleContext" );
611 //===== XAccessibleSelection =============================================
613 void SAL_CALL SvxGraphCtrlAccessibleContext::selectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException )
615 ::SolarMutexGuard aGuard;
617 if( NULL == mpView )
618 throw DisposedException();
620 SdrObject* pObj = getSdrObject( nIndex );
622 if( pObj )
623 mpView->MarkObj( pObj, mpView->GetSdrPageView());
626 //-----------------------------------------------------------------------------
628 sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::isAccessibleChildSelected( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException )
630 ::SolarMutexGuard aGuard;
632 if( NULL == mpView )
633 throw DisposedException();
635 return mpView->IsObjMarked( getSdrObject( nIndex ) );
638 //-----------------------------------------------------------------------------
640 void SAL_CALL SvxGraphCtrlAccessibleContext::clearAccessibleSelection() throw( RuntimeException )
642 ::SolarMutexGuard aGuard;
644 if( NULL == mpView )
645 throw DisposedException();
647 mpView->UnmarkAllObj();
650 //-----------------------------------------------------------------------------
652 void SAL_CALL SvxGraphCtrlAccessibleContext::selectAllAccessibleChildren() throw( RuntimeException )
654 ::SolarMutexGuard aGuard;
656 if( NULL == mpView )
657 throw DisposedException();
659 mpView->MarkAllObj();
662 //-----------------------------------------------------------------------------
664 sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChildCount() throw( RuntimeException )
666 ::SolarMutexGuard aGuard;
668 if( NULL == mpView )
669 throw DisposedException();
671 const SdrMarkList& rList = mpView->GetMarkedObjectList();
672 return rList.GetMarkCount();
675 //-----------------------------------------------------------------------------
677 Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChild( sal_Int32 nIndex )
678 throw( lang::IndexOutOfBoundsException, RuntimeException )
680 ::SolarMutexGuard aGuard;
682 checkChildIndexOnSelection( nIndex );
684 Reference< XAccessible > xAccessible;
686 const SdrMarkList& rList = mpView->GetMarkedObjectList();
687 SdrObject* pObj = rList.GetMark(nIndex)->GetMarkedSdrObj();
688 if( pObj )
689 xAccessible = getAccessible( pObj );
691 return xAccessible;
694 //-----------------------------------------------------------------------------
696 void SAL_CALL SvxGraphCtrlAccessibleContext::deselectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException )
698 ::SolarMutexGuard aGuard;
700 checkChildIndexOnSelection( nIndex );
702 if( mpView )
704 const SdrMarkList& rList = mpView->GetMarkedObjectList();
706 SdrObject* pObj = getSdrObject( nIndex );
707 if( pObj )
709 SdrMarkList aRefList( rList );
711 SdrPageView* pPV = mpView->GetSdrPageView();
712 mpView->UnmarkAllObj( pPV );
714 sal_uInt32 nCount = aRefList.GetMarkCount();
715 sal_uInt32 nMark;
716 for( nMark = 0; nMark < nCount; nMark++ )
718 if( aRefList.GetMark(nMark)->GetMarkedSdrObj() != pObj )
719 mpView->MarkObj( aRefList.GetMark(nMark)->GetMarkedSdrObj(), pPV );
725 //===== internals ========================================================
727 void SvxGraphCtrlAccessibleContext::checkChildIndexOnSelection( long nIndex ) throw( lang::IndexOutOfBoundsException )
729 if( nIndex < 0 || nIndex >= getSelectedAccessibleChildCount() )
730 throw lang::IndexOutOfBoundsException();
735 /** Replace the model, page, and view pointers by the ones provided
736 (explicitly and implicitly).
738 void SvxGraphCtrlAccessibleContext::setModelAndView (
739 SdrModel* pModel,
740 SdrView* pView)
742 ::SolarMutexGuard aGuard;
744 mpModel = pModel;
745 if (mpModel != NULL)
746 mpPage = (SdrPage*)mpModel->GetPage( 0 );
747 mpView = pView;
749 if (mpModel == NULL || mpPage == NULL || mpView == NULL)
751 mbDisposed = true;
753 // Set all the pointers to NULL just in case they are used as
754 // a disposed flag.
755 mpModel = NULL;
756 mpPage = NULL;
757 mpView = NULL;
760 maTreeInfo.SetSdrView (mpView);
765 //-----------------------------------------------------------------------------
767 void SAL_CALL SvxGraphCtrlAccessibleContext::disposing()
769 ::SolarMutexGuard aGuard;
771 if( mbDisposed )
772 return;
774 mbDisposed = sal_True;
776 mpControl = NULL; // object dies with representation
777 mpView = NULL;
778 mpPage = NULL;
781 ShapesMapType::iterator I;
783 for (I=mxShapes.begin(); I!=mxShapes.end(); ++I)
785 XAccessible* pAcc = (*I).second;
786 Reference< XComponent > xComp( pAcc, UNO_QUERY );
787 if( xComp.is() )
788 xComp->dispose();
790 (*I).second->release();
793 mxShapes.clear();
796 // Send a disposing to all listeners.
797 if ( mnClientId )
799 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
800 mnClientId = 0;
804 //-----------------------------------------------------------------------------
806 Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
808 ::SolarMutexGuard aGuard;
810 if( NULL == mpControl )
811 throw DisposedException();
813 return Rectangle(
814 mpControl->GetAccessibleParentWindow()->OutputToAbsoluteScreenPixel(
815 mpControl->GetPosPixel() ),
816 mpControl->GetSizePixel() );
819 //-----------------------------------------------------------------------------
821 /** Calculate the relative coordinates of the bounding box as difference
822 between the absolute coordinates of the bounding boxes of this control
823 and its parent in the accessibility tree.
825 Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBox( void ) throw( RuntimeException )
827 ::SolarMutexGuard aGuard;
829 Rectangle aBounds ( 0, 0, 0, 0 );
831 Window* pWindow = mpControl;
832 if (pWindow != NULL)
834 aBounds = pWindow->GetWindowExtentsRelative (NULL);
835 Window* pParent = pWindow->GetAccessibleParentWindow();
836 if (pParent != NULL)
838 Rectangle aParentRect = pParent->GetWindowExtentsRelative (NULL);
839 aBounds -= aParentRect.TopLeft();
842 else
843 throw DisposedException();
845 return aBounds;
848 //-----------------------------------------------------------------------------
850 Sequence< sal_Int8 > SvxGraphCtrlAccessibleContext::getUniqueId( void )
852 // no guard because it's private -> has to guarded when using it!
853 static OImplementationId* pId = 0;
854 if( !pId )
856 ::SolarMutexGuard aGuard;
857 if( !pId)
859 static OImplementationId aId;
860 pId = &aId;
863 return pId->getImplementationId();
866 //-----------------------------------------------------------------------------
868 void SvxGraphCtrlAccessibleContext::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
870 const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
872 if( pSdrHint )
874 switch( pSdrHint->GetKind() )
876 case HINT_OBJCHG:
878 ShapesMapType::iterator iter = mxShapes.find( pSdrHint->GetObject() );
880 if( iter != mxShapes.end() )
882 // if we already have one, return it
883 AccessibleShape* pShape = (*iter).second;
885 if( NULL != pShape )
886 pShape->CommitChange( AccessibleEventId::VISIBLE_DATA_CHANGED, uno::Any(), uno::Any() );
889 break;
891 case HINT_OBJINSERTED:
892 CommitChange( AccessibleEventId::CHILD, makeAny( getAccessible( pSdrHint->GetObject() ) ) , uno::Any());
893 break;
894 case HINT_OBJREMOVED:
895 CommitChange( AccessibleEventId::CHILD, uno::Any(), makeAny( getAccessible( pSdrHint->GetObject() ) ) );
896 break;
897 case HINT_MODELCLEARED:
898 dispose();
899 break;
900 default:
901 break;
904 else
906 const SfxSimpleHint* pSfxHint = PTR_CAST(SfxSimpleHint, &rHint );
908 // Has our SdDrawDocument just died?
909 if(pSfxHint && pSfxHint->GetId() == SFX_HINT_DYING)
911 dispose();
916 //===== IAccessibleViewforwarder ========================================
918 sal_Bool SvxGraphCtrlAccessibleContext::IsValid (void) const
920 return sal_True;
923 //-----------------------------------------------------------------------------
925 Rectangle SvxGraphCtrlAccessibleContext::GetVisibleArea (void) const
927 Rectangle aVisArea;
929 if( mpView && mpView->PaintWindowCount())
931 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(0L);
932 aVisArea = pPaintWindow->GetVisibleArea();
935 return aVisArea;
938 //-----------------------------------------------------------------------------
940 Point SvxGraphCtrlAccessibleContext::LogicToPixel (const Point& rPoint) const
942 if( mpControl )
944 Rectangle aBBox(mpControl->GetWindowExtentsRelative(NULL));
945 return mpControl->LogicToPixel (rPoint) + aBBox.TopLeft();
947 else
949 return rPoint;
953 //-----------------------------------------------------------------------------
955 Size SvxGraphCtrlAccessibleContext::LogicToPixel (const Size& rSize) const
957 if( mpControl )
958 return mpControl->LogicToPixel (rSize);
959 else
960 return rSize;
963 //-----------------------------------------------------------------------------
965 Point SvxGraphCtrlAccessibleContext::PixelToLogic (const Point& rPoint) const
967 if( mpControl )
968 return mpControl->PixelToLogic (rPoint);
969 else
970 return rPoint;
973 //-----------------------------------------------------------------------------
975 Size SvxGraphCtrlAccessibleContext::PixelToLogic (const Size& rSize) const
977 if( mpControl )
978 return mpControl->PixelToLogic (rSize);
979 else
980 return rSize;
983 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */