update emoji autocorrect entries from po-files
[LibreOffice.git] / svtools / source / control / accessibleruler.cxx
blob942c7b3ab7dd76df63df028f1087d99b82b54812
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 .
19 #include <svtools/accessibleruler.hxx>
20 #include <com/sun/star/accessibility/AccessibleRole.hpp>
21 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
22 #include <unotools/accessiblestatesethelper.hxx>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
25 #include <com/sun/star/awt/XWindow.hpp>
26 #include <comphelper/accessibleeventnotifier.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <toolkit/helper/convert.hxx>
31 #include <vcl/svapp.hxx>
32 #include <osl/mutex.hxx>
33 #include <rtl/uuid.h>
34 #include <tools/gen.hxx>
36 #include <svtools/ruler.hxx>
38 using namespace ::cppu;
39 using namespace ::osl;
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::accessibility;
46 //===== internal ============================================================
48 SvtRulerAccessible::SvtRulerAccessible(
49 const uno::Reference< XAccessible >& rxParent, Ruler& rRepr, const OUString& rName ) :
51 SvtRulerAccessible_Base( m_aMutex ),
52 msName( rName ),
53 mxParent( rxParent ),
54 mpRepr( &rRepr ),
55 mnClientId( 0 )
59 SvtRulerAccessible::~SvtRulerAccessible()
62 if( IsAlive() )
64 osl_atomic_increment( &m_refCount );
65 dispose(); // set mpRepr = NULL & release all children
69 //===== XAccessible =========================================================
71 uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext() throw( RuntimeException, std::exception )
73 return this;
76 //===== XAccessibleComponent ================================================
78 sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint ) throw( RuntimeException, std::exception )
80 // no guard -> done in getBounds()
81 // return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
82 return Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
85 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& ) throw( RuntimeException, std::exception )
87 ::osl::MutexGuard aGuard( m_aMutex );
89 ThrowExceptionIfNotAlive();
91 uno::Reference< XAccessible > xRet;
94 return xRet;
97 awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds() throw( RuntimeException, std::exception )
99 // no guard -> done in GetBoundingBox()
100 return AWTRectangle( GetBoundingBox() );
103 awt::Point SAL_CALL SvtRulerAccessible::getLocation() throw( RuntimeException, std::exception )
105 // no guard -> done in GetBoundingBox()
106 return AWTPoint( GetBoundingBox().TopLeft() );
109 awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen() throw( RuntimeException, std::exception )
111 // no guard -> done in GetBoundingBoxOnScreen()
112 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
115 awt::Size SAL_CALL SvtRulerAccessible::getSize() throw( RuntimeException, std::exception )
117 // no guard -> done in GetBoundingBox()
118 return AWTSize( GetBoundingBox().GetSize() );
121 bool SAL_CALL SvtRulerAccessible::isVisible() throw( RuntimeException )
123 ::osl::MutexGuard aGuard( m_aMutex );
125 ThrowExceptionIfNotAlive();
127 return mpRepr->IsVisible();
130 //===== XAccessibleContext ==================================================
131 sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleChildCount() throw( RuntimeException, std::exception )
133 ::osl::MutexGuard aGuard( m_aMutex );
135 ThrowExceptionIfNotAlive();
137 return 0;
140 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int32 )
141 throw( RuntimeException, lang::IndexOutOfBoundsException, std::exception )
143 uno::Reference< XAccessible > xChild ;
145 return xChild;
148 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent() throw( RuntimeException, std::exception )
150 return mxParent;
153 sal_Int32 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent() throw( RuntimeException, std::exception )
155 ::osl::MutexGuard aGuard( m_aMutex );
156 // Use a simple but slow solution for now. Optimize later.
158 // Iterate over all the parent's children and search for this object.
159 if( mxParent.is() )
161 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
162 if( xParentContext.is() )
164 sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
165 for( sal_Int32 i = 0 ; i < nChildCount ; ++i )
167 uno::Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
168 if( xChild.get() == ( XAccessible* ) this )
169 return i;
174 // Return -1 to indicate that this object's parent does not know about the
175 // object.
176 return -1;
179 sal_Int16 SAL_CALL SvtRulerAccessible::getAccessibleRole() throw( RuntimeException, std::exception )
181 return AccessibleRole::RULER;
184 OUString SAL_CALL SvtRulerAccessible::getAccessibleDescription() throw( RuntimeException, std::exception )
186 ::osl::MutexGuard aGuard( m_aMutex );
187 return msDescription;
190 OUString SAL_CALL SvtRulerAccessible::getAccessibleName() throw( RuntimeException, std::exception )
192 ::osl::MutexGuard aGuard( m_aMutex );
193 return msName;
196 /** Return empty uno::Reference to indicate that the relation set is not
197 supported.
199 uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet() throw( RuntimeException, std::exception )
201 return uno::Reference< XAccessibleRelationSet >();
205 uno::Reference< XAccessibleStateSet > SAL_CALL SvtRulerAccessible::getAccessibleStateSet() throw( RuntimeException, std::exception )
207 ::osl::MutexGuard aGuard( m_aMutex );
208 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
210 if( IsAlive() )
212 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
214 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
216 if( isVisible() )
217 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
219 if ( mpRepr->GetStyle() & WB_HORZ )
220 pStateSetHelper->AddState( AccessibleStateType::HORIZONTAL );
221 else
222 pStateSetHelper->AddState( AccessibleStateType::VERTICAL );
224 if(pStateSetHelper->contains(AccessibleStateType::FOCUSABLE))
226 pStateSetHelper->RemoveState( AccessibleStateType::FOCUSABLE );
232 return pStateSetHelper;
235 lang::Locale SAL_CALL SvtRulerAccessible::getLocale() throw( IllegalAccessibleComponentStateException, RuntimeException, std::exception )
237 ::osl::MutexGuard aGuard( m_aMutex );
238 if( mxParent.is() )
240 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
241 if( xParentContext.is() )
242 return xParentContext->getLocale();
245 // No parent. Therefore throw exception to indicate this cluelessness.
246 throw IllegalAccessibleComponentStateException();
249 void SAL_CALL SvtRulerAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
250 throw( RuntimeException, std::exception )
252 if (xListener.is())
254 ::osl::MutexGuard aGuard( m_aMutex );
255 if (!mnClientId)
256 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
257 comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
261 void SAL_CALL SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
262 throw( RuntimeException, std::exception )
264 if (xListener.is())
266 ::osl::MutexGuard aGuard( m_aMutex );
268 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
269 if ( !nListenerCount )
271 // no listeners anymore
272 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
273 // and at least to us not firing any events anymore, in case somebody calls
274 // NotifyAccessibleEvent, again
275 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
276 mnClientId = 0;
281 void SAL_CALL SvtRulerAccessible::grabFocus() throw( RuntimeException, std::exception )
283 SolarMutexGuard aSolarGuard;
284 ::osl::MutexGuard aGuard( m_aMutex );
286 ThrowExceptionIfNotAlive();
288 mpRepr->GrabFocus();
291 sal_Int32 SvtRulerAccessible::getForeground( )
292 throw (::com::sun::star::uno::RuntimeException, std::exception)
294 SolarMutexGuard aSolarGuard;
295 ::osl::MutexGuard aGuard( m_aMutex );
296 ThrowExceptionIfNotAlive();
298 return mpRepr->GetControlForeground().GetColor();
300 sal_Int32 SvtRulerAccessible::getBackground( )
301 throw (::com::sun::star::uno::RuntimeException, std::exception)
303 SolarMutexGuard aSolarGuard;
304 ::osl::MutexGuard aGuard( m_aMutex );
305 ThrowExceptionIfNotAlive();
307 return mpRepr->GetControlBackground().GetColor();
310 // XServiceInfo
311 OUString SAL_CALL SvtRulerAccessible::getImplementationName() throw( RuntimeException, std::exception )
313 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.ui.SvtRulerAccessible" ) );
316 sal_Bool SAL_CALL SvtRulerAccessible::supportsService( const OUString& sServiceName ) throw( RuntimeException, std::exception )
318 return cppu::supportsService( this, sServiceName );
321 Sequence< OUString > SAL_CALL SvtRulerAccessible::getSupportedServiceNames() throw( RuntimeException, std::exception )
323 const OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleContext" ) );
324 return Sequence< OUString >( &sServiceName, 1 );
327 //===== XTypeProvider =======================================================
328 Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId() throw( RuntimeException, std::exception )
330 return css::uno::Sequence<sal_Int8>();
333 void SAL_CALL SvtRulerAccessible::disposing()
335 if( !rBHelper.bDisposed )
338 ::osl::MutexGuard aGuard( m_aMutex );
339 mpRepr = NULL; // object dies with representation
344 ::osl::MutexGuard aGuard( m_aMutex );
346 // Send a disposing to all listeners.
347 if ( mnClientId )
349 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
350 mnClientId = 0;
352 mxParent = uno::Reference< XAccessible >();
357 Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen() throw( RuntimeException )
359 SolarMutexGuard aSolarGuard;
360 ::osl::MutexGuard aGuard( m_aMutex );
362 ThrowExceptionIfNotAlive();
363 return Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
366 Rectangle SvtRulerAccessible::GetBoundingBox() throw( RuntimeException )
368 SolarMutexGuard aSolarGuard;
369 ::osl::MutexGuard aGuard( m_aMutex );
371 ThrowExceptionIfNotAlive();
373 return Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() );
376 void SvtRulerAccessible::ThrowExceptionIfNotAlive() throw( lang::DisposedException )
378 if( IsNotAlive() )
379 throw lang::DisposedException();
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */