Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 : : #include <com/sun/star/lang/DisposedException.hpp>
33 : : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
34 : : #include <com/sun/star/awt/XWindow.hpp>
35 : : #include <unotools/accessiblestatesethelper.hxx>
36 : : #include <cppuhelper/typeprovider.hxx>
37 : : #include <toolkit/helper/vclunohelper.hxx>
38 : : #include <vcl/svapp.hxx>
39 : : #include <osl/mutex.hxx>
40 : : #include <tools/gen.hxx>
41 : : #include <svl/smplhint.hxx>
42 : : #include <toolkit/helper/convert.hxx>
43 : : #include <svtools/colorcfg.hxx>
44 : : #include <comphelper/accessibleeventnotifier.hxx>
45 : : #include <svx/sdrpaintwindow.hxx>
46 : :
47 : : //===== local includes ========================================================
48 : : #include <svx/ShapeTypeHandler.hxx>
49 : : #include <svx/AccessibleShapeInfo.hxx>
50 : : #include "GraphCtlAccessibleContext.hxx"
51 : : #include <svx/graphctl.hxx>
52 : : #include <svx/dialogs.hrc>
53 : : #include "accessibility.hrc"
54 : : #include <svx/svdpage.hxx>
55 : : #include <svx/unomod.hxx>
56 : : #include <svx/dialmgr.hxx>
57 : : #include <svx/svdetc.hxx>
58 : : #include <svx/sdrhittesthelper.hxx>
59 : :
60 : : //===== namespaces ===========================================================
61 : :
62 : : using namespace ::cppu;
63 : : using namespace ::osl;
64 : : using ::rtl::OUString;
65 : : using namespace ::accessibility;
66 : : using namespace ::com::sun::star;
67 : : using namespace ::com::sun::star::uno;
68 : : using namespace ::com::sun::star::drawing;
69 : : using namespace ::com::sun::star::lang;
70 : : using namespace ::com::sun::star::accessibility;
71 : :
72 : : using rtl::OUString;
73 : :
74 : : //===== internal ============================================================
75 : :
76 : : /** initialize this component and set default values */
77 : 0 : SvxGraphCtrlAccessibleContext::SvxGraphCtrlAccessibleContext(
78 : : const Reference< XAccessible >& rxParent,
79 : : GraphCtrl& rRepr,
80 : : const OUString* pName,
81 : : const OUString* pDesc ) :
82 : :
83 : : SvxGraphCtrlAccessibleContext_Base( m_aMutex ),
84 : : mxParent( rxParent ),
85 : : mpControl( &rRepr ),
86 : : mpModel (NULL),
87 : : mpPage (NULL),
88 : : mpView (NULL),
89 : : mnClientId( 0 ),
90 [ # # ][ # # ]: 0 : mbDisposed( sal_False )
[ # # ][ # # ]
91 : : {
92 [ # # ]: 0 : if (mpControl != NULL)
93 : : {
94 : 0 : mpModel = mpControl->GetSdrModel();
95 [ # # ]: 0 : if (mpModel != NULL)
96 [ # # ]: 0 : mpPage = (SdrPage*)mpModel->GetPage( 0 );
97 : 0 : mpView = mpControl->GetSdrView();
98 : :
99 [ # # ][ # # ]: 0 : if( mpModel == NULL || mpPage == NULL || mpView == NULL )
[ # # ]
100 : : {
101 : 0 : mbDisposed = true;
102 : : // Set all the pointers to NULL just in case they are used as
103 : : // a disposed flag.
104 : 0 : mpModel = NULL;
105 : 0 : mpPage = NULL;
106 : 0 : mpView = NULL;
107 : : }
108 : : }
109 : :
110 [ # # ]: 0 : if( pName )
111 : : {
112 : 0 : msName = *pName;
113 : : }
114 : : else
115 : : {
116 [ # # ]: 0 : ::SolarMutexGuard aSolarGuard;
117 [ # # ][ # # ]: 0 : msName = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_NAME );
[ # # ]
118 : : }
119 : :
120 [ # # ]: 0 : if( pDesc )
121 : : {
122 : 0 : msDescription = *pDesc;
123 : : }
124 : : else
125 : : {
126 [ # # ]: 0 : ::SolarMutexGuard aSolarGuard;
127 [ # # ][ # # ]: 0 : msDescription = SVX_RESSTR( RID_SVXSTR_GRAPHCTRL_ACC_DESCRIPTION );
[ # # ]
128 : : }
129 : :
130 [ # # ]: 0 : maTreeInfo.SetSdrView( mpView );
131 [ # # ]: 0 : maTreeInfo.SetWindow( mpControl );
132 [ # # ]: 0 : maTreeInfo.SetViewForwarder( const_cast<SvxGraphCtrlAccessibleContext*>(this) );
133 : 0 : }
134 : :
135 : : //-----------------------------------------------------------------------------
136 : :
137 : : /** on destruction, this component is disposed and all dispose listeners
138 : : are called, except if this component was already disposed */
139 [ # # ][ # # ]: 0 : SvxGraphCtrlAccessibleContext::~SvxGraphCtrlAccessibleContext()
[ # # ]
140 : : {
141 [ # # ]: 0 : disposing();
142 [ # # ]: 0 : }
143 : :
144 : : //-----------------------------------------------------------------------------
145 : :
146 : : /** returns the XAccessible interface for a given SdrObject.
147 : : Multiple calls for the same SdrObject return the same XAccessible.
148 : : */
149 : 0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessible( const SdrObject* pObj )
150 : : {
151 : 0 : Reference<XAccessible> xAccessibleShape;
152 : :
153 [ # # ]: 0 : if( pObj )
154 : : {
155 : : // see if we already created an XAccessible for the given SdrObject
156 [ # # ]: 0 : ShapesMapType::iterator iter = mxShapes.find( pObj );
157 : :
158 [ # # ][ # # ]: 0 : if( iter != mxShapes.end() )
159 : : {
160 : : // if we already have one, return it
161 [ # # ][ # # ]: 0 : xAccessibleShape = (*iter).second;
[ # # ]
162 : : }
163 : : else
164 : : {
165 : : // create a new one and remember in our internal map
166 [ # # ][ # # ]: 0 : Reference< XShape > xShape( Reference< XShape >::query( (const_cast<SdrObject*>(pObj))->getUnoShape() ) );
167 : :
168 [ # # ]: 0 : AccessibleShapeInfo aShapeInfo (xShape,mxParent);
169 : : // Create accessible object that corresponds to the descriptor's shape.
170 [ # # ]: 0 : AccessibleShape* pAcc = ShapeTypeHandler::Instance().CreateAccessibleObject(
171 [ # # ]: 0 : aShapeInfo, maTreeInfo);
172 [ # # ][ # # ]: 0 : xAccessibleShape = pAcc;
173 [ # # ]: 0 : if (pAcc != NULL)
174 : : {
175 : 0 : pAcc->acquire();
176 : : // Now that we acquired the new accessible shape we can
177 : : // safely call its Init() method.
178 [ # # ]: 0 : pAcc->Init ();
179 : : }
180 [ # # ]: 0 : mxShapes[pObj] = pAcc;
181 : :
182 : : // Create event and inform listeners of the object creation.
183 [ # # ][ # # ]: 0 : CommitChange( AccessibleEventId::CHILD, makeAny( xAccessibleShape ), makeAny( Reference<XAccessible>() ) );
[ # # ][ # # ]
184 : : }
185 : : }
186 : :
187 : 0 : return xAccessibleShape;
188 : : }
189 : :
190 : : //===== XAccessible =========================================================
191 : :
192 : 0 : Reference< XAccessibleContext > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleContext( void ) throw( RuntimeException )
193 : : {
194 : 0 : return this;
195 : : }
196 : :
197 : : //===== XAccessibleComponent ================================================
198 : :
199 : 0 : sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::containsPoint( const awt::Point& rPoint ) throw( RuntimeException )
200 : : {
201 : : // no guard -> done in getSize()
202 [ # # ]: 0 : awt::Size aSize (getSize());
203 : : return (rPoint.X >= 0)
204 : : && (rPoint.X < aSize.Width)
205 : : && (rPoint.Y >= 0)
206 [ # # ][ # # ]: 0 : && (rPoint.Y < aSize.Height);
[ # # ][ # # ]
207 : : }
208 : :
209 : : //-----------------------------------------------------------------------------
210 : :
211 : 0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleAtPoint( const awt::Point& rPoint ) throw( RuntimeException )
212 : : {
213 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
214 : :
215 : 0 : Reference< XAccessible > xAccessible;
216 : :
217 [ # # ]: 0 : if( mpControl )
218 : : {
219 : 0 : Point aPnt( rPoint.X, rPoint.Y );
220 [ # # ]: 0 : mpControl->PixelToLogic( aPnt );
221 : :
222 : 0 : SdrObject* pObj = 0;
223 : :
224 [ # # ][ # # ]: 0 : if(mpView && mpView->GetSdrPageView())
[ # # ]
225 : : {
226 [ # # ]: 0 : pObj = SdrObjListPrimitiveHit(*mpPage, aPnt, 1, *mpView->GetSdrPageView(), 0, false);
227 : : }
228 : :
229 [ # # ]: 0 : if( pObj )
230 [ # # ][ # # ]: 0 : xAccessible = getAccessible( pObj );
231 : : }
232 : : else
233 : : {
234 [ # # ]: 0 : throw DisposedException();
235 : : }
236 : :
237 [ # # ]: 0 : return xAccessible;
238 : : }
239 : :
240 : : //-----------------------------------------------------------------------------
241 : :
242 : 0 : awt::Rectangle SAL_CALL SvxGraphCtrlAccessibleContext::getBounds() throw( RuntimeException )
243 : : {
244 : : // no guard -> done in GetBoundingBox()
245 [ # # ]: 0 : Rectangle aCoreBounds( GetBoundingBox() );
246 : 0 : awt::Rectangle aBounds;
247 : 0 : aBounds.X = aCoreBounds.getX();
248 : 0 : aBounds.Y = aCoreBounds.getY();
249 : 0 : aBounds.Width = aCoreBounds.getWidth();
250 : 0 : aBounds.Height = aCoreBounds.getHeight();
251 : 0 : return aBounds;
252 : : }
253 : :
254 : : //-----------------------------------------------------------------------------
255 : :
256 : 0 : awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocation() throw( RuntimeException )
257 : : {
258 : : // no guard -> done in GetBoundingBox()
259 [ # # ]: 0 : Rectangle aRect( GetBoundingBox() );
260 : 0 : return awt::Point( aRect.getX(), aRect.getY() );
261 : : }
262 : :
263 : : //-----------------------------------------------------------------------------
264 : :
265 : 0 : awt::Point SAL_CALL SvxGraphCtrlAccessibleContext::getLocationOnScreen() throw( RuntimeException )
266 : : {
267 : : // no guard -> done in GetBoundingBoxOnScreen()
268 [ # # ]: 0 : Rectangle aRect( GetBoundingBoxOnScreen() );
269 : 0 : return awt::Point( aRect.getX(), aRect.getY() );
270 : : }
271 : :
272 : : //-----------------------------------------------------------------------------
273 : :
274 : 0 : awt::Size SAL_CALL SvxGraphCtrlAccessibleContext::getSize() throw( RuntimeException )
275 : : {
276 : : // no guard -> done in GetBoundingBox()
277 [ # # ]: 0 : Rectangle aRect( GetBoundingBox() );
278 : 0 : return awt::Size( aRect.getWidth(), aRect.getHeight() );
279 : : }
280 : :
281 : :
282 : : //===== XAccessibleContext ==================================================
283 : :
284 : 0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChildCount( void ) throw( RuntimeException )
285 : : {
286 [ # # ]: 0 : ::SolarMutexGuard aGuard;
287 : :
288 [ # # ]: 0 : if( NULL == mpPage )
289 [ # # ]: 0 : throw DisposedException();
290 : :
291 [ # # ][ # # ]: 0 : return mpPage->GetObjCount();
292 : : }
293 : :
294 : : //-----------------------------------------------------------------------------
295 : :
296 : : /** returns the SdrObject at index nIndex from the model of this graph */
297 : 0 : SdrObject* SvxGraphCtrlAccessibleContext::getSdrObject( sal_Int32 nIndex )
298 : : throw( RuntimeException, lang::IndexOutOfBoundsException )
299 : : {
300 [ # # ]: 0 : ::SolarMutexGuard aGuard;
301 : :
302 [ # # ]: 0 : if( NULL == mpPage )
303 [ # # ]: 0 : throw DisposedException();
304 : :
305 [ # # ][ # # ]: 0 : if( (nIndex < 0) || ( static_cast<sal_uInt32>(nIndex) >= mpPage->GetObjCount() ) )
[ # # ][ # # ]
306 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
307 : :
308 [ # # ][ # # ]: 0 : return mpPage->GetObj( nIndex );
309 : : }
310 : :
311 : : //-----------------------------------------------------------------------------
312 : :
313 : : /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
314 : 0 : void SvxGraphCtrlAccessibleContext::CommitChange (
315 : : sal_Int16 nEventId,
316 : : const uno::Any& rNewValue,
317 : : const uno::Any& rOldValue)
318 : : {
319 : : AccessibleEventObject aEvent (
320 : : static_cast<uno::XWeak*>(this),
321 : : nEventId,
322 : : rNewValue,
323 [ # # ][ # # ]: 0 : rOldValue);
324 : :
325 [ # # ][ # # ]: 0 : FireEvent (aEvent);
326 : 0 : }
327 : :
328 : : /** sends an AccessibleEventObject to all added XAccessibleEventListeners */
329 : 0 : void SvxGraphCtrlAccessibleContext::FireEvent (const AccessibleEventObject& aEvent)
330 : : {
331 [ # # ]: 0 : if (mnClientId)
332 : 0 : comphelper::AccessibleEventNotifier::addEvent( mnClientId, aEvent );
333 : 0 : }
334 : :
335 : : //-----------------------------------------------------------------------------
336 : :
337 : 0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleChild( sal_Int32 nIndex )
338 : : throw( RuntimeException, lang::IndexOutOfBoundsException )
339 : : {
340 [ # # ]: 0 : ::SolarMutexGuard aGuard;
341 : :
342 [ # # ][ # # ]: 0 : return getAccessible( getSdrObject( nIndex ) );
[ # # ]
343 : : }
344 : :
345 : : //-----------------------------------------------------------------------------
346 : :
347 : 0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleParent( void ) throw( RuntimeException )
348 : : {
349 : 0 : return mxParent;
350 : : }
351 : :
352 : : //-----------------------------------------------------------------------------
353 : :
354 : 0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleIndexInParent( void ) throw( RuntimeException )
355 : : {
356 [ # # ]: 0 : ::SolarMutexGuard aGuard;
357 : : // Use a simple but slow solution for now. Optimize later.
358 : :
359 : : // Iterate over all the parent's children and search for this object.
360 [ # # ]: 0 : if( mxParent.is() )
361 : : {
362 [ # # ][ # # ]: 0 : Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
363 [ # # ]: 0 : if( xParentContext.is() )
364 : : {
365 [ # # ][ # # ]: 0 : sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
366 [ # # ]: 0 : for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
367 : : {
368 [ # # ][ # # ]: 0 : Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
369 [ # # ]: 0 : if( xChild.is() )
370 : : {
371 [ # # ][ # # ]: 0 : Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
372 [ # # ][ # # ]: 0 : if( xChildContext == ( XAccessibleContext* ) this )
373 [ # # ]: 0 : return i;
374 : : }
375 [ # # ]: 0 : }
376 [ # # ]: 0 : }
377 : : }
378 : :
379 : : // Return -1 to indicate that this object's parent does not know about the
380 : : // object.
381 [ # # ]: 0 : return -1;
382 : : }
383 : :
384 : : //-----------------------------------------------------------------------------
385 : :
386 : 0 : sal_Int16 SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRole( void ) throw( RuntimeException )
387 : : {
388 : 0 : return AccessibleRole::PANEL;
389 : : }
390 : :
391 : : //-----------------------------------------------------------------------------
392 : :
393 : 0 : OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleDescription( void ) throw( RuntimeException )
394 : : {
395 [ # # ]: 0 : ::SolarMutexGuard aGuard;
396 [ # # ]: 0 : return msDescription;
397 : : }
398 : :
399 : : //-----------------------------------------------------------------------------
400 : :
401 : 0 : OUString SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleName( void ) throw( RuntimeException )
402 : : {
403 [ # # ]: 0 : ::SolarMutexGuard aGuard;
404 [ # # ]: 0 : return msName;
405 : : }
406 : :
407 : : //-----------------------------------------------------------------------------
408 : :
409 : : /** Return empty reference to indicate that the relation set is not
410 : : supported.
411 : : */
412 : 0 : Reference< XAccessibleRelationSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleRelationSet( void ) throw( RuntimeException )
413 : : {
414 : 0 : return Reference< XAccessibleRelationSet >();
415 : : }
416 : :
417 : : //-----------------------------------------------------------------------------
418 : :
419 : 0 : Reference< XAccessibleStateSet > SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleStateSet( void ) throw( RuntimeException )
420 : : {
421 [ # # ]: 0 : ::SolarMutexGuard aGuard;
422 : :
423 [ # # ]: 0 : utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
424 : :
425 [ # # ][ # # ]: 0 : if ( rBHelper.bDisposed || mbDisposed )
426 : : {
427 [ # # ]: 0 : pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
428 : : }
429 : : else
430 : : {
431 [ # # ]: 0 : pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
432 [ # # ][ # # ]: 0 : if( mpControl->HasFocus() )
433 [ # # ]: 0 : pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
434 [ # # ]: 0 : pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
435 [ # # ]: 0 : pStateSetHelper->AddState( AccessibleStateType::SHOWING );
436 [ # # ]: 0 : pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
437 : : }
438 : :
439 [ # # ][ # # ]: 0 : return pStateSetHelper;
[ # # ]
440 : : }
441 : :
442 : : //-----------------------------------------------------------------------------
443 : :
444 : 0 : lang::Locale SAL_CALL SvxGraphCtrlAccessibleContext::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException )
445 : : {
446 [ # # ]: 0 : ::SolarMutexGuard aGuard;
447 : :
448 [ # # ]: 0 : if( mxParent.is() )
449 : : {
450 [ # # ][ # # ]: 0 : Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
451 [ # # ]: 0 : if( xParentContext.is() )
452 [ # # ][ # # ]: 0 : return xParentContext->getLocale();
[ # # ]
453 : : }
454 : :
455 : : // No parent. Therefore throw exception to indicate this cluelessness.
456 [ # # ][ # # ]: 0 : throw IllegalAccessibleComponentStateException();
457 : : }
458 : :
459 : : //===== XAccessibleEventListener ============================================
460 : :
461 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::addEventListener( const Reference< XAccessibleEventListener >& xListener )
462 : : throw( RuntimeException )
463 : : {
464 [ # # ]: 0 : if (xListener.is())
465 : : {
466 [ # # ]: 0 : ::SolarMutexGuard aGuard;
467 [ # # ]: 0 : if (!mnClientId)
468 [ # # ]: 0 : mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
469 [ # # ][ # # ]: 0 : comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
470 : : }
471 : 0 : }
472 : :
473 : : //-----------------------------------------------------------------------------
474 : :
475 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::removeEventListener( const Reference< XAccessibleEventListener >& xListener )
476 : : throw( RuntimeException )
477 : : {
478 [ # # ]: 0 : if (xListener.is())
479 : : {
480 [ # # ]: 0 : ::SolarMutexGuard aGuard;
481 : :
482 [ # # ]: 0 : sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
483 [ # # ]: 0 : if ( !nListenerCount )
484 : : {
485 : : // no listeners anymore
486 : : // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
487 : : // and at least to us not firing any events anymore, in case somebody calls
488 : : // NotifyAccessibleEvent, again
489 [ # # ]: 0 : comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
490 : 0 : mnClientId = 0;
491 [ # # ]: 0 : }
492 : : }
493 : 0 : }
494 : :
495 : : //-----------------------------------------------------------------------------
496 : :
497 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::addFocusListener( const Reference< awt::XFocusListener >& xListener )
498 : : throw( RuntimeException )
499 : : {
500 [ # # ]: 0 : ::SolarMutexGuard aGuard;
501 : :
502 [ # # ]: 0 : if( xListener.is() )
503 : : {
504 [ # # ]: 0 : Reference< ::com::sun::star::awt::XWindow > xWindow( VCLUnoHelper::GetInterface( mpControl ) );
505 [ # # ]: 0 : if( xWindow.is() )
506 [ # # ][ # # ]: 0 : xWindow->addFocusListener( xListener );
507 [ # # ]: 0 : }
508 : 0 : }
509 : :
510 : : //-----------------------------------------------------------------------------
511 : :
512 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::removeFocusListener( const Reference< awt::XFocusListener >& xListener )
513 : : throw (RuntimeException)
514 : : {
515 [ # # ]: 0 : ::SolarMutexGuard aGuard;
516 : :
517 [ # # ]: 0 : if( xListener.is() )
518 : : {
519 [ # # ]: 0 : Reference< ::com::sun::star::awt::XWindow > xWindow = VCLUnoHelper::GetInterface( mpControl );
520 [ # # ]: 0 : if( xWindow.is() )
521 [ # # ][ # # ]: 0 : xWindow->removeFocusListener( xListener );
522 [ # # ]: 0 : }
523 : 0 : }
524 : :
525 : : //-----------------------------------------------------------------------------
526 : :
527 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::grabFocus() throw( RuntimeException )
528 : : {
529 [ # # ]: 0 : ::SolarMutexGuard aGuard;
530 : :
531 [ # # ]: 0 : if( NULL == mpControl )
532 [ # # ]: 0 : throw DisposedException();
533 : :
534 [ # # ][ # # ]: 0 : mpControl->GrabFocus();
535 : 0 : }
536 : :
537 : : //-----------------------------------------------------------------------------
538 : :
539 : 0 : Any SAL_CALL SvxGraphCtrlAccessibleContext::getAccessibleKeyBinding() throw( RuntimeException )
540 : : {
541 : : // here is no implementation, because here are no KeyBindings for every object
542 : 0 : return Any();
543 : : }
544 : :
545 : :
546 : :
547 : :
548 : :
549 : 0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getForeground (void)
550 : : throw (::com::sun::star::uno::RuntimeException)
551 : : {
552 [ # # ]: 0 : svtools::ColorConfig aColorConfig;
553 [ # # ]: 0 : sal_uInt32 nColor = aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor;
554 [ # # ]: 0 : return static_cast<sal_Int32>(nColor);
555 : : }
556 : :
557 : :
558 : :
559 : :
560 : 0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getBackground (void)
561 : : throw (::com::sun::star::uno::RuntimeException)
562 : : {
563 : 0 : sal_uInt32 nColor = Application::GetSettings().GetStyleSettings().GetWindowColor().GetColor();
564 : 0 : return static_cast<sal_Int32>(nColor);
565 : : }
566 : :
567 : :
568 : : //===== XServiceInfo ========================================================
569 : :
570 : 0 : OUString SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationName( void ) throw( RuntimeException )
571 : : {
572 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.SvxGraphCtrlAccessibleContext" ) );
573 : : }
574 : :
575 : : //-----------------------------------------------------------------------------
576 : :
577 : 0 : sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::supportsService( const OUString& sServiceName ) throw( RuntimeException )
578 : : {
579 [ # # ]: 0 : ::SolarMutexGuard aGuard;
580 : : // Iterate over all supported service names and return true if on of them
581 : : // matches the given name.
582 [ # # ]: 0 : Sequence< OUString > aSupportedServices( getSupportedServiceNames() );
583 : 0 : int nLenght = aSupportedServices.getLength();
584 : :
585 [ # # ]: 0 : for( int i = 0 ; i < nLenght ; ++i )
586 : : {
587 [ # # ][ # # ]: 0 : if( sServiceName == aSupportedServices[ i ] )
588 : 0 : return sal_True;
589 : : }
590 : :
591 [ # # ][ # # ]: 0 : return sal_False;
592 : : }
593 : :
594 : : //-----------------------------------------------------------------------------
595 : :
596 : 0 : Sequence< OUString > SAL_CALL SvxGraphCtrlAccessibleContext::getSupportedServiceNames( void ) throw( RuntimeException )
597 : : {
598 : 0 : Sequence< OUString > aSNs( 3 );
599 : :
600 [ # # ][ # # ]: 0 : aSNs[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.Accessible" ) );
601 [ # # ][ # # ]: 0 : aSNs[1] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
602 [ # # ][ # # ]: 0 : aSNs[2] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.AccessibleGraphControl" ) );
603 : :
604 : 0 : return aSNs;
605 : : }
606 : :
607 : : //===== XTypeProvider =======================================================
608 : :
609 : 0 : Sequence<sal_Int8> SAL_CALL SvxGraphCtrlAccessibleContext::getImplementationId( void ) throw( RuntimeException )
610 : : {
611 [ # # ]: 0 : ::SolarMutexGuard aGuard;
612 [ # # ][ # # ]: 0 : return getUniqueId();
613 : : }
614 : :
615 : : //===== XServiceName ========================================================
616 : :
617 : 0 : OUString SvxGraphCtrlAccessibleContext::getServiceName( void ) throw( RuntimeException )
618 : : {
619 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
620 : : }
621 : :
622 : : //===== XAccessibleSelection =============================================
623 : :
624 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::selectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException )
625 : : {
626 [ # # ]: 0 : ::SolarMutexGuard aGuard;
627 : :
628 [ # # ]: 0 : if( NULL == mpView )
629 [ # # ]: 0 : throw DisposedException();
630 : :
631 [ # # ]: 0 : SdrObject* pObj = getSdrObject( nIndex );
632 : :
633 [ # # ]: 0 : if( pObj )
634 [ # # ][ # # ]: 0 : mpView->MarkObj( pObj, mpView->GetSdrPageView());
635 : 0 : }
636 : :
637 : : //-----------------------------------------------------------------------------
638 : :
639 : 0 : sal_Bool SAL_CALL SvxGraphCtrlAccessibleContext::isAccessibleChildSelected( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException )
640 : : {
641 [ # # ]: 0 : ::SolarMutexGuard aGuard;
642 : :
643 [ # # ]: 0 : if( NULL == mpView )
644 [ # # ]: 0 : throw DisposedException();
645 : :
646 [ # # ][ # # ]: 0 : return mpView->IsObjMarked( getSdrObject( nIndex ) );
[ # # ]
647 : : }
648 : :
649 : : //-----------------------------------------------------------------------------
650 : :
651 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::clearAccessibleSelection() throw( RuntimeException )
652 : : {
653 [ # # ]: 0 : ::SolarMutexGuard aGuard;
654 : :
655 [ # # ]: 0 : if( NULL == mpView )
656 [ # # ]: 0 : throw DisposedException();
657 : :
658 [ # # ][ # # ]: 0 : mpView->UnmarkAllObj();
659 : 0 : }
660 : :
661 : : //-----------------------------------------------------------------------------
662 : :
663 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::selectAllAccessibleChildren() throw( RuntimeException )
664 : : {
665 [ # # ]: 0 : ::SolarMutexGuard aGuard;
666 : :
667 [ # # ]: 0 : if( NULL == mpView )
668 [ # # ]: 0 : throw DisposedException();
669 : :
670 [ # # ][ # # ]: 0 : mpView->MarkAllObj();
671 : 0 : }
672 : :
673 : : //-----------------------------------------------------------------------------
674 : :
675 : 0 : sal_Int32 SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChildCount() throw( RuntimeException )
676 : : {
677 [ # # ]: 0 : ::SolarMutexGuard aGuard;
678 : :
679 [ # # ]: 0 : if( NULL == mpView )
680 [ # # ]: 0 : throw DisposedException();
681 : :
682 : 0 : const SdrMarkList& rList = mpView->GetMarkedObjectList();
683 [ # # ]: 0 : return rList.GetMarkCount();
684 : : }
685 : :
686 : : //-----------------------------------------------------------------------------
687 : :
688 : 0 : Reference< XAccessible > SAL_CALL SvxGraphCtrlAccessibleContext::getSelectedAccessibleChild( sal_Int32 nIndex )
689 : : throw( lang::IndexOutOfBoundsException, RuntimeException )
690 : : {
691 [ # # ]: 0 : ::SolarMutexGuard aGuard;
692 : :
693 [ # # ]: 0 : checkChildIndexOnSelection( nIndex );
694 : :
695 : 0 : Reference< XAccessible > xAccessible;
696 : :
697 : 0 : const SdrMarkList& rList = mpView->GetMarkedObjectList();
698 [ # # ][ # # ]: 0 : SdrObject* pObj = rList.GetMark(nIndex)->GetMarkedSdrObj();
699 [ # # ]: 0 : if( pObj )
700 [ # # ][ # # ]: 0 : xAccessible = getAccessible( pObj );
701 : :
702 [ # # ]: 0 : return xAccessible;
703 : : }
704 : :
705 : : //-----------------------------------------------------------------------------
706 : :
707 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::deselectAccessibleChild( sal_Int32 nIndex ) throw( lang::IndexOutOfBoundsException, RuntimeException )
708 : : {
709 [ # # ]: 0 : ::SolarMutexGuard aGuard;
710 : :
711 [ # # ]: 0 : checkChildIndexOnSelection( nIndex );
712 : :
713 [ # # ]: 0 : if( mpView )
714 : : {
715 : 0 : const SdrMarkList& rList = mpView->GetMarkedObjectList();
716 : :
717 [ # # ]: 0 : SdrObject* pObj = getSdrObject( nIndex );
718 [ # # ]: 0 : if( pObj )
719 : : {
720 [ # # ]: 0 : SdrMarkList aRefList( rList );
721 : :
722 : 0 : SdrPageView* pPV = mpView->GetSdrPageView();
723 [ # # ]: 0 : mpView->UnmarkAllObj( pPV );
724 : :
725 : 0 : sal_uInt32 nCount = aRefList.GetMarkCount();
726 : : sal_uInt32 nMark;
727 [ # # ]: 0 : for( nMark = 0; nMark < nCount; nMark++ )
728 : : {
729 [ # # ][ # # ]: 0 : if( aRefList.GetMark(nMark)->GetMarkedSdrObj() != pObj )
[ # # ]
730 [ # # ][ # # ]: 0 : mpView->MarkObj( aRefList.GetMark(nMark)->GetMarkedSdrObj(), pPV );
[ # # ]
731 [ # # ]: 0 : }
732 : : }
733 [ # # ]: 0 : }
734 : 0 : }
735 : :
736 : : //===== internals ========================================================
737 : :
738 : 0 : void SvxGraphCtrlAccessibleContext::checkChildIndexOnSelection( long nIndex ) throw( lang::IndexOutOfBoundsException )
739 : : {
740 [ # # ][ # # ]: 0 : if( nIndex < 0 || nIndex >= getSelectedAccessibleChildCount() )
[ # # ]
741 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
742 : 0 : }
743 : :
744 : :
745 : :
746 : : /** Replace the model, page, and view pointers by the ones provided
747 : : (explicitly and implicitly).
748 : : */
749 : 0 : void SvxGraphCtrlAccessibleContext::setModelAndView (
750 : : SdrModel* pModel,
751 : : SdrView* pView)
752 : : {
753 [ # # ]: 0 : ::SolarMutexGuard aGuard;
754 : :
755 : 0 : mpModel = pModel;
756 [ # # ]: 0 : if (mpModel != NULL)
757 [ # # ]: 0 : mpPage = (SdrPage*)mpModel->GetPage( 0 );
758 : 0 : mpView = pView;
759 : :
760 [ # # ][ # # ]: 0 : if (mpModel == NULL || mpPage == NULL || mpView == NULL)
[ # # ]
761 : : {
762 : 0 : mbDisposed = true;
763 : :
764 : : // Set all the pointers to NULL just in case they are used as
765 : : // a disposed flag.
766 : 0 : mpModel = NULL;
767 : 0 : mpPage = NULL;
768 : 0 : mpView = NULL;
769 : : }
770 : :
771 [ # # ][ # # ]: 0 : maTreeInfo.SetSdrView (mpView);
772 : 0 : }
773 : :
774 : :
775 : :
776 : : //-----------------------------------------------------------------------------
777 : :
778 : 0 : void SAL_CALL SvxGraphCtrlAccessibleContext::disposing()
779 : : {
780 [ # # ]: 0 : ::SolarMutexGuard aGuard;
781 : :
782 [ # # ]: 0 : if( mbDisposed )
783 : 0 : return;
784 : :
785 : 0 : mbDisposed = sal_True;
786 : :
787 : 0 : mpControl = NULL; // object dies with representation
788 : 0 : mpView = NULL;
789 : 0 : mpPage = NULL;
790 : :
791 : : {
792 [ # # ]: 0 : ShapesMapType::iterator I;
793 : :
794 [ # # ][ # # ]: 0 : for (I=mxShapes.begin(); I!=mxShapes.end(); ++I)
[ # # ]
795 : : {
796 [ # # ][ # # ]: 0 : XAccessible* pAcc = (*I).second;
797 [ # # ]: 0 : Reference< XComponent > xComp( pAcc, UNO_QUERY );
798 [ # # ]: 0 : if( xComp.is() )
799 [ # # ][ # # ]: 0 : xComp->dispose();
800 : :
801 [ # # ]: 0 : (*I).second->release();
802 : 0 : }
803 : :
804 : 0 : mxShapes.clear();
805 : : }
806 : :
807 : : // Send a disposing to all listeners.
808 [ # # ]: 0 : if ( mnClientId )
809 : : {
810 [ # # ][ # # ]: 0 : comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
811 : 0 : mnClientId = 0;
812 [ # # ][ # # ]: 0 : }
813 : : }
814 : :
815 : : //-----------------------------------------------------------------------------
816 : :
817 : 0 : Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
818 : : {
819 [ # # ]: 0 : ::SolarMutexGuard aGuard;
820 : :
821 [ # # ]: 0 : if( NULL == mpControl )
822 [ # # ]: 0 : throw DisposedException();
823 : :
824 : : return Rectangle(
825 : : mpControl->GetAccessibleParentWindow()->OutputToAbsoluteScreenPixel(
826 [ # # ][ # # ]: 0 : mpControl->GetPosPixel() ),
827 [ # # ][ # # ]: 0 : mpControl->GetSizePixel() );
[ # # ][ # # ]
828 : : }
829 : :
830 : : //-----------------------------------------------------------------------------
831 : :
832 : : /** Calculate the relative coordinates of the bounding box as difference
833 : : between the absolute coordinates of the bounding boxes of this control
834 : : and its parent in the accessibility tree.
835 : : */
836 : 0 : Rectangle SvxGraphCtrlAccessibleContext::GetBoundingBox( void ) throw( RuntimeException )
837 : : {
838 [ # # ]: 0 : ::SolarMutexGuard aGuard;
839 : :
840 [ # # ]: 0 : Rectangle aBounds ( 0, 0, 0, 0 );
841 : :
842 : 0 : Window* pWindow = mpControl;
843 [ # # ]: 0 : if (pWindow != NULL)
844 : : {
845 [ # # ]: 0 : aBounds = pWindow->GetWindowExtentsRelative (NULL);
846 [ # # ]: 0 : Window* pParent = pWindow->GetAccessibleParentWindow();
847 [ # # ]: 0 : if (pParent != NULL)
848 : : {
849 [ # # ]: 0 : Rectangle aParentRect = pParent->GetWindowExtentsRelative (NULL);
850 [ # # ]: 0 : aBounds -= aParentRect.TopLeft();
851 : : }
852 : : }
853 : : else
854 [ # # ]: 0 : throw DisposedException();
855 : :
856 [ # # ]: 0 : return aBounds;
857 : : }
858 : :
859 : : //-----------------------------------------------------------------------------
860 : :
861 : 0 : Sequence< sal_Int8 > SvxGraphCtrlAccessibleContext::getUniqueId( void )
862 : : {
863 : : // no guard because it's private -> has to guarded when using it!
864 : : static OImplementationId* pId = 0;
865 [ # # ]: 0 : if( !pId )
866 : : {
867 [ # # ]: 0 : ::SolarMutexGuard aGuard;
868 [ # # ]: 0 : if( !pId)
869 : : {
870 [ # # ][ # # ]: 0 : static OImplementationId aId;
871 : 0 : pId = &aId;
872 [ # # ]: 0 : }
873 : : }
874 : 0 : return pId->getImplementationId();
875 : : }
876 : :
877 : : //-----------------------------------------------------------------------------
878 : :
879 : 0 : void SvxGraphCtrlAccessibleContext::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
880 : : {
881 [ # # ][ # # ]: 0 : const SdrHint* pSdrHint = PTR_CAST( SdrHint, &rHint );
882 : :
883 [ # # ]: 0 : if( pSdrHint )
884 : : {
885 [ # # # # : 0 : switch( pSdrHint->GetKind() )
# ]
886 : : {
887 : : case HINT_OBJCHG:
888 : : {
889 [ # # ][ # # ]: 0 : ShapesMapType::iterator iter = mxShapes.find( pSdrHint->GetObject() );
890 : :
891 [ # # ][ # # ]: 0 : if( iter != mxShapes.end() )
892 : : {
893 : : // if we already have one, return it
894 [ # # ]: 0 : AccessibleShape* pShape = (*iter).second;
895 : :
896 [ # # ]: 0 : if( NULL != pShape )
897 [ # # ]: 0 : pShape->CommitChange( AccessibleEventId::VISIBLE_DATA_CHANGED, uno::Any(), uno::Any() );
898 : : }
899 : : }
900 : 0 : break;
901 : :
902 : : case HINT_OBJINSERTED:
903 [ # # ][ # # ]: 0 : CommitChange( AccessibleEventId::CHILD, makeAny( getAccessible( pSdrHint->GetObject() ) ) , uno::Any());
[ # # ][ # # ]
904 : 0 : break;
905 : : case HINT_OBJREMOVED:
906 [ # # ][ # # ]: 0 : CommitChange( AccessibleEventId::CHILD, uno::Any(), makeAny( getAccessible( pSdrHint->GetObject() ) ) );
907 : 0 : break;
908 : : case HINT_MODELCLEARED:
909 : 0 : dispose();
910 : 0 : break;
911 : : default:
912 : 0 : break;
913 : : }
914 : : }
915 : : else
916 : : {
917 [ # # ][ # # ]: 0 : const SfxSimpleHint* pSfxHint = PTR_CAST(SfxSimpleHint, &rHint );
918 : :
919 : : // Has our SdDrawDocument just died?
920 [ # # ][ # # ]: 0 : if(pSfxHint && pSfxHint->GetId() == SFX_HINT_DYING)
[ # # ]
921 : : {
922 : 0 : dispose();
923 : : }
924 : : }
925 : 0 : }
926 : :
927 : : //===== IAccessibleViewforwarder ========================================
928 : :
929 : 0 : sal_Bool SvxGraphCtrlAccessibleContext::IsValid (void) const
930 : : {
931 : 0 : return sal_True;
932 : : }
933 : :
934 : : //-----------------------------------------------------------------------------
935 : :
936 : 0 : Rectangle SvxGraphCtrlAccessibleContext::GetVisibleArea (void) const
937 : : {
938 : 0 : Rectangle aVisArea;
939 : :
940 [ # # ][ # # ]: 0 : if( mpView && mpView->PaintWindowCount())
[ # # ]
941 : : {
942 : 0 : SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(0L);
943 : 0 : aVisArea = pPaintWindow->GetVisibleArea();
944 : : }
945 : :
946 : 0 : return aVisArea;
947 : : }
948 : :
949 : : //-----------------------------------------------------------------------------
950 : :
951 : 0 : Point SvxGraphCtrlAccessibleContext::LogicToPixel (const Point& rPoint) const
952 : : {
953 [ # # ]: 0 : if( mpControl )
954 : : {
955 [ # # ]: 0 : Rectangle aBBox(mpControl->GetWindowExtentsRelative(NULL));
956 [ # # ]: 0 : return mpControl->LogicToPixel (rPoint) + aBBox.TopLeft();
957 : : }
958 : : else
959 : : {
960 : 0 : return rPoint;
961 : : }
962 : : }
963 : :
964 : : //-----------------------------------------------------------------------------
965 : :
966 : 0 : Size SvxGraphCtrlAccessibleContext::LogicToPixel (const Size& rSize) const
967 : : {
968 [ # # ]: 0 : if( mpControl )
969 : 0 : return mpControl->LogicToPixel (rSize);
970 : : else
971 : 0 : return rSize;
972 : : }
973 : :
974 : : //-----------------------------------------------------------------------------
975 : :
976 : 0 : Point SvxGraphCtrlAccessibleContext::PixelToLogic (const Point& rPoint) const
977 : : {
978 [ # # ]: 0 : if( mpControl )
979 : 0 : return mpControl->PixelToLogic (rPoint);
980 : : else
981 : 0 : return rPoint;
982 : : }
983 : :
984 : : //-----------------------------------------------------------------------------
985 : :
986 : 0 : Size SvxGraphCtrlAccessibleContext::PixelToLogic (const Size& rSize) const
987 : : {
988 [ # # ]: 0 : if( mpControl )
989 : 0 : return mpControl->PixelToLogic (rSize);
990 : : else
991 : 0 : return rSize;
992 : : }
993 : :
994 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|