xref: /trunk/main/svtools/source/control/accessibleruler.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svtools.hxx"
24 
25 #ifndef _SVTRULERACCESSIBLE_HXX
26 #include <svtools/accessibleruler.hxx>
27 #endif
28 
29 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
30 #include <com/sun/star/accessibility/AccessibleRole.hpp>
31 #endif
32 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #endif
35 #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
36 #include <unotools/accessiblestatesethelper.hxx>
37 #endif
38 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
39 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
40 #endif
41 
42 #ifndef _COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_
43 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
44 #endif
45 
46 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
47 #include <com/sun/star/awt/XWindow.hpp>
48 #endif
49 
50 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
51 #include <cppuhelper/typeprovider.hxx>
52 #endif
53 
54 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
55 #include <toolkit/helper/vclunohelper.hxx>
56 #endif
57 #ifndef _TOOLKIT_HELPER_CONVERT_HXX_
58 #include <toolkit/helper/convert.hxx>
59 #endif
60 
61 #ifndef _SV_SVAPP_HXX
62 #include <vcl/svapp.hxx>
63 #endif
64 
65 #ifndef _OSL_MUTEX_HXX_
66 #include <osl/mutex.hxx>
67 #endif
68 #ifndef _RTL_UUID_H_
69 #include <rtl/uuid.h>
70 #endif
71 #ifndef _TOOLS_DEBUG_HXX
72 #include <tools/debug.hxx>
73 #endif
74 #ifndef _SV_GEN_HXX
75 #include <tools/gen.hxx>
76 #endif
77 
78 #include "ruler.hxx"
79 
80 #ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
81 #include <comphelper/accessibleeventnotifier.hxx>
82 #endif
83 
84 using namespace ::cppu;
85 using namespace ::osl;
86 using namespace ::rtl;
87 using namespace ::com::sun::star;
88 using namespace ::com::sun::star::uno;
89 using namespace ::com::sun::star::accessibility;
90 
DBG_NAME(SvtRulerAccessible)91 DBG_NAME( SvtRulerAccessible )
92 
93 
94 //=====  internal  ============================================================
95 
96 SvtRulerAccessible::SvtRulerAccessible(
97     const uno::Reference< XAccessible >& rxParent, Ruler& rRepr, const OUString& rName ) :
98 
99     SvtRulerAccessible_Base( m_aMutex ),
100     msName( rName ),
101     mxParent( rxParent ),
102     mpRepr( &rRepr ),
103     mnClientId( 0 )
104 {
105     DBG_CTOR( SvtRulerAccessible, NULL );
106 }
107 
~SvtRulerAccessible()108 SvtRulerAccessible::~SvtRulerAccessible()
109 {
110     DBG_DTOR( SvtRulerAccessible, NULL );
111 
112     if( IsAlive() )
113     {
114         osl_incrementInterlockedCount( &m_refCount );
115         dispose();      // set mpRepr = NULL & release all childs
116     }
117 }
118 
119 //=====  XAccessible  =========================================================
120 
getAccessibleContext(void)121 uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext( void )
122 {
123     return this;
124 }
125 
126 //=====  XAccessibleComponent  ================================================
127 
containsPoint(const awt::Point & rPoint)128 sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint )
129 {
130     // no guard -> done in getBounds()
131 //  return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
132     return Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
133 }
134 
getAccessibleAtPoint(const awt::Point &)135 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& )
136 {
137     ::osl::MutexGuard           aGuard( m_aMutex );
138 
139     ThrowExceptionIfNotAlive();
140 
141     uno::Reference< XAccessible >   xRet;
142 
143 
144     return xRet;
145 }
146 
getBounds()147 awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds()
148 {
149     // no guard -> done in GetBoundingBox()
150     return AWTRectangle( GetBoundingBox() );
151 }
152 
getLocation()153 awt::Point SAL_CALL SvtRulerAccessible::getLocation()
154 {
155     // no guard -> done in GetBoundingBox()
156     return AWTPoint( GetBoundingBox().TopLeft() );
157 }
158 
getLocationOnScreen()159 awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen()
160 {
161     // no guard -> done in GetBoundingBoxOnScreen()
162     return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
163 }
164 
getSize()165 awt::Size SAL_CALL SvtRulerAccessible::getSize()
166 {
167     // no guard -> done in GetBoundingBox()
168     return AWTSize( GetBoundingBox().GetSize() );
169 }
170 
isShowing()171 sal_Bool SAL_CALL SvtRulerAccessible::isShowing()
172 {
173     return sal_True;
174 }
175 
isVisible()176 sal_Bool SAL_CALL SvtRulerAccessible::isVisible()
177 {
178     ::osl::MutexGuard           aGuard( m_aMutex );
179 
180     ThrowExceptionIfNotAlive();
181 
182     return mpRepr->IsVisible();
183 }
184 
isFocusTraversable()185 sal_Bool SAL_CALL SvtRulerAccessible::isFocusTraversable()
186 {
187     return sal_True;
188 }
189 
190 //=====  XAccessibleContext  ==================================================
191 
getAccessibleChildCount(void)192 sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleChildCount( void )
193 {
194     ::osl::MutexGuard   aGuard( m_aMutex );
195 
196     ThrowExceptionIfNotAlive();
197 
198     return 0;
199 }
200 
getAccessibleChild(sal_Int32)201 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int32 )
202 {
203     uno::Reference< XAccessible >   xChild ;
204 
205     return xChild;
206 }
207 
getAccessibleParent(void)208 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent( void )
209 {
210     return mxParent;
211 }
212 
getAccessibleIndexInParent(void)213 sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent( void )
214 {
215     ::osl::MutexGuard   aGuard( m_aMutex );
216     //  Use a simple but slow solution for now.  Optimize later.
217 
218     //  Iterate over all the parent's children and search for this object.
219     if( mxParent.is() )
220     {
221         uno::Reference< XAccessibleContext >        xParentContext( mxParent->getAccessibleContext() );
222         if( xParentContext.is() )
223         {
224             sal_Int32                       nChildCount = xParentContext->getAccessibleChildCount();
225             for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
226             {
227                 uno::Reference< XAccessible >   xChild( xParentContext->getAccessibleChild( i ) );
228                 if( xChild.get() == ( XAccessible* ) this )
229                     return i;
230             }
231         }
232    }
233 
234    //   Return -1 to indicate that this object's parent does not know about the
235    //   object.
236    return -1;
237 }
238 
getAccessibleRole(void)239 sal_Int16 SAL_CALL SvtRulerAccessible::getAccessibleRole( void )
240 {
241     return AccessibleRole::RULER;
242 }
243 
getAccessibleDescription(void)244 OUString SAL_CALL SvtRulerAccessible::getAccessibleDescription( void )
245 {
246     ::osl::MutexGuard   aGuard( m_aMutex );
247     return msDescription;
248 }
249 
getAccessibleName(void)250 OUString SAL_CALL SvtRulerAccessible::getAccessibleName( void )
251 {
252     ::osl::MutexGuard   aGuard( m_aMutex );
253     return msName;
254 }
255 
256 /** Return empty uno::Reference to indicate that the relation set is not
257     supported.
258 */
getAccessibleRelationSet(void)259 uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet( void )
260 {
261     return uno::Reference< XAccessibleRelationSet >();
262 }
263 
264 
getAccessibleStateSet(void)265 uno::Reference< XAccessibleStateSet > SAL_CALL SvtRulerAccessible::getAccessibleStateSet( void )
266 {
267     ::osl::MutexGuard                       aGuard( m_aMutex );
268     utl::AccessibleStateSetHelper*          pStateSetHelper = new utl::AccessibleStateSetHelper;
269 
270     if( IsAlive() )
271     {
272         pStateSetHelper->AddState( AccessibleStateType::ENABLED );
273 
274         if( isShowing() )
275             pStateSetHelper->AddState( AccessibleStateType::SHOWING );
276 
277         if( isVisible() )
278             pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
279 
280 
281         if ( mpRepr )
282         {
283             if ( mpRepr->GetStyle() & WB_HORZ )
284                 pStateSetHelper->AddState( AccessibleStateType::HORIZONTAL );
285             else
286                 pStateSetHelper->AddState( AccessibleStateType::VERTICAL );
287         }
288         if(pStateSetHelper->contains(AccessibleStateType::FOCUSABLE))
289         {
290             pStateSetHelper->RemoveState( AccessibleStateType::FOCUSABLE );
291         }
292 
293     }
294 
295 
296     return pStateSetHelper;
297 }
298 
getLocale(void)299 lang::Locale SAL_CALL SvtRulerAccessible::getLocale( void )
300 {
301     ::osl::MutexGuard                           aGuard( m_aMutex );
302     if( mxParent.is() )
303     {
304         uno::Reference< XAccessibleContext >    xParentContext( mxParent->getAccessibleContext() );
305         if( xParentContext.is() )
306             return xParentContext->getLocale();
307     }
308 
309     //  No parent.  Therefore throw exception to indicate this cluelessness.
310     throw IllegalAccessibleComponentStateException();
311 }
312 
addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)313 void SAL_CALL SvtRulerAccessible::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
314 {
315     if (xListener.is())
316     {
317         ::osl::MutexGuard   aGuard( m_aMutex );
318         if (!mnClientId)
319             mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
320         comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
321     }
322 }
323 
removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)324 void SAL_CALL SvtRulerAccessible::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
325 {
326     if (xListener.is())
327     {
328         ::osl::MutexGuard   aGuard( m_aMutex );
329 
330         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
331         if ( !nListenerCount )
332         {
333             // no listeners anymore
334             // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
335             // and at least to us not firing any events anymore, in case somebody calls
336             // NotifyAccessibleEvent, again
337             comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
338             mnClientId = 0;
339         }
340     }
341 }
342 
addFocusListener(const uno::Reference<awt::XFocusListener> & xListener)343 void SAL_CALL SvtRulerAccessible::addFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
344 {
345     if( xListener.is() )
346     {
347         ::osl::MutexGuard   aGuard( m_aMutex );
348 
349         ThrowExceptionIfNotAlive();
350 
351         uno::Reference< awt::XWindow >  xWindow = VCLUnoHelper::GetInterface( mpRepr );
352         if( xWindow.is() )
353             xWindow->addFocusListener( xListener );
354     }
355 }
356 
removeFocusListener(const uno::Reference<awt::XFocusListener> & xListener)357 void SAL_CALL SvtRulerAccessible::removeFocusListener( const uno::Reference< awt::XFocusListener >& xListener )
358 {
359     if( xListener.is() )
360     {
361         ::osl::MutexGuard   aGuard( m_aMutex );
362 
363         ThrowExceptionIfNotAlive();
364 
365         uno::Reference< awt::XWindow >  xWindow = VCLUnoHelper::GetInterface( mpRepr );
366         if( xWindow.is() )
367             xWindow->removeFocusListener( xListener );
368     }
369 }
370 
grabFocus()371 void SAL_CALL SvtRulerAccessible::grabFocus()
372 {
373     ::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
374     ::osl::MutexGuard   aGuard( m_aMutex );
375 
376     ThrowExceptionIfNotAlive();
377 
378     mpRepr->GrabFocus();
379 }
380 
getAccessibleKeyBinding()381 Any SAL_CALL SvtRulerAccessible::getAccessibleKeyBinding()
382 {
383     // here is no implementation, because here are no KeyBindings for every object
384     return Any();
385 }
386 
getForeground()387 sal_Int32 SvtRulerAccessible::getForeground(  )
388 {
389     ::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
390     ::osl::MutexGuard   aGuard( m_aMutex );
391     ThrowExceptionIfNotAlive();
392 
393     return mpRepr->GetControlForeground().GetColor();
394 }
getBackground()395 sal_Int32 SvtRulerAccessible::getBackground(  )
396 {
397     ::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
398     ::osl::MutexGuard   aGuard( m_aMutex );
399     ThrowExceptionIfNotAlive();
400 
401     return mpRepr->GetControlBackground().GetColor();
402 }
403 
404 //=====  XServiceInfo  ========================================================
405 
getImplementationName(void)406 OUString SAL_CALL SvtRulerAccessible::getImplementationName( void )
407 {
408     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.SvtRulerAccessible" ) );
409 }
410 
supportsService(const OUString & sServiceName)411 sal_Bool SAL_CALL SvtRulerAccessible::supportsService( const OUString& sServiceName )
412 {
413     ::osl::MutexGuard   aGuard( m_aMutex );
414     //  Iterate over all supported service names and return true if on of them
415     //  matches the given name.
416     Sequence< OUString >    aSupportedServices( getSupportedServiceNames() );
417     int                     nLength = aSupportedServices.getLength();
418     const OUString*         pStr = aSupportedServices.getConstArray();
419 
420     for( int i = nLength ; i ; --i, ++pStr )
421     {
422         if( sServiceName == *pStr )
423             return sal_True;
424     }
425 
426     return sal_False;
427 }
428 
getSupportedServiceNames(void)429 Sequence< OUString > SAL_CALL SvtRulerAccessible::getSupportedServiceNames( void )
430 {
431     const OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
432     return Sequence< OUString >( &sServiceName, 1 );
433 }
434 
435 //=====  XTypeProvider  =======================================================
436 
getImplementationId(void)437 Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId( void )
438 {
439     return getUniqueId();
440 }
441 
442 
443 //=====  internals ========================================================
444 
setName(const OUString & rName)445 void SvtRulerAccessible::setName( const OUString& rName )
446 {
447         msName = rName;
448 
449 }
450 
setDescription(const OUString & rDescr)451 void SvtRulerAccessible::setDescription( const OUString& rDescr )
452 {
453 
454         msDescription = rDescr;
455 
456 }
457 
458 
459 
disposing()460 void SAL_CALL SvtRulerAccessible::disposing()
461 {
462     if( !rBHelper.bDisposed )
463     {
464         {
465             ::osl::MutexGuard   aGuard( m_aMutex );
466             mpRepr = NULL;      // object dies with representation
467 
468         }
469 
470         {
471             ::osl::MutexGuard   aGuard( m_aMutex );
472 
473             // Send a disposing to all listeners.
474             if ( mnClientId )
475             {
476                 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
477                 mnClientId =  0;
478             }
479             mxParent = uno::Reference< XAccessible >();
480         }
481     }
482 }
483 
GetBoundingBoxOnScreen(void)484 Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen( void )
485 {
486     ::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
487     ::osl::MutexGuard   aGuard( m_aMutex );
488 
489     ThrowExceptionIfNotAlive();
490     //the absolute on screen pixel is wrong
491     //return Rectangle( mpRepr->GetParent()->OutputToScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
492     return Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
493 }
494 
GetBoundingBox(void)495 Rectangle SvtRulerAccessible::GetBoundingBox( void )
496 {
497     ::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
498     ::osl::MutexGuard   aGuard( m_aMutex );
499 
500     ThrowExceptionIfNotAlive();
501 
502     return Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() );
503 }
504 
getUniqueId(void)505 Sequence< sal_Int8 > SvtRulerAccessible::getUniqueId( void )
506 {
507     static OImplementationId*   pId = 0;
508     if( !pId )
509     {
510         MutexGuard                      aGuard( Mutex::getGlobalMutex() );
511         if( !pId)
512         {
513             static OImplementationId    aId;
514             pId = &aId;
515         }
516     }
517     return pId->getImplementationId();
518 }
519 
ThrowExceptionIfNotAlive(void)520 void SvtRulerAccessible::ThrowExceptionIfNotAlive( void )
521 {
522     if( IsNotAlive() )
523         throw lang::DisposedException();
524 }
525 
addEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> & xListener)526 void SvtRulerAccessible::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener )
527 {
528     cppu::WeakAggComponentImplHelperBase::addEventListener( xListener );
529 }
530 
removeEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> & xListener)531 void SvtRulerAccessible::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener )
532 {
533     cppu::WeakAggComponentImplHelperBase::removeEventListener( xListener );
534 }
535 
536 
537 // -------------------------------------------------------------------------------------------------
538