android: Update app-specific/MIME type icons
[LibreOffice.git] / svtools / source / control / accessibleruler.cxx
blob6bb9b63e4b07bd82526a68ae0201e7f628f5ea77
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 <com/sun/star/accessibility/AccessibleRole.hpp>
20 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <comphelper/accessibleeventnotifier.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <toolkit/helper/convert.hxx>
25 #include <utility>
26 #include <vcl/svapp.hxx>
27 #include <osl/mutex.hxx>
28 #include <tools/gen.hxx>
30 #include <svtools/ruler.hxx>
31 #include "accessibleruler.hxx"
33 using namespace ::cppu;
34 using namespace ::osl;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::accessibility;
40 //===== internal ============================================================
42 SvtRulerAccessible::SvtRulerAccessible(
43 uno::Reference< XAccessible > xParent, Ruler& rRepr, OUString aName ) :
45 SvtRulerAccessible_Base( m_aMutex ),
46 msName(std::move( aName )),
47 mxParent(std::move( xParent )),
48 mpRepr( &rRepr ),
49 mnClientId( 0 )
53 SvtRulerAccessible::~SvtRulerAccessible()
56 if( IsAlive() )
58 osl_atomic_increment( &m_refCount );
59 dispose(); // set mpRepr = NULL & release all children
63 //===== XAccessible =========================================================
65 uno::Reference< XAccessibleContext > SAL_CALL SvtRulerAccessible::getAccessibleContext()
67 return this;
70 //===== XAccessibleComponent ================================================
72 sal_Bool SAL_CALL SvtRulerAccessible::containsPoint( const awt::Point& rPoint )
74 // no guard -> done in getBounds()
75 // return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
76 return tools::Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).Contains( VCLPoint( rPoint ) );
79 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleAtPoint( const awt::Point& )
81 ::osl::MutexGuard aGuard( m_aMutex );
83 ThrowExceptionIfNotAlive();
85 uno::Reference< XAccessible > xRet;
88 return xRet;
91 awt::Rectangle SAL_CALL SvtRulerAccessible::getBounds()
93 // no guard -> done in GetBoundingBox()
94 return AWTRectangle( GetBoundingBox() );
97 awt::Point SAL_CALL SvtRulerAccessible::getLocation()
99 // no guard -> done in GetBoundingBox()
100 return AWTPoint( GetBoundingBox().TopLeft() );
103 awt::Point SAL_CALL SvtRulerAccessible::getLocationOnScreen()
105 // no guard -> done in GetBoundingBoxOnScreen()
106 return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
109 awt::Size SAL_CALL SvtRulerAccessible::getSize()
111 // no guard -> done in GetBoundingBox()
112 return AWTSize( GetBoundingBox().GetSize() );
115 bool SvtRulerAccessible::isVisible()
117 ::osl::MutexGuard aGuard( m_aMutex );
119 ThrowExceptionIfNotAlive();
121 return mpRepr->IsVisible();
124 //===== XAccessibleContext ==================================================
125 sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleChildCount()
127 ::osl::MutexGuard aGuard( m_aMutex );
129 ThrowExceptionIfNotAlive();
131 return 0;
134 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleChild( sal_Int64 )
136 uno::Reference< XAccessible > xChild ;
138 return xChild;
141 uno::Reference< XAccessible > SAL_CALL SvtRulerAccessible::getAccessibleParent()
143 return mxParent;
146 sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleIndexInParent()
148 ::osl::MutexGuard aGuard( m_aMutex );
149 // Use a simple but slow solution for now. Optimize later.
151 // Iterate over all the parent's children and search for this object.
152 if( mxParent.is() )
154 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
155 if( xParentContext.is() )
157 sal_Int64 nChildCount = xParentContext->getAccessibleChildCount();
158 for( sal_Int64 i = 0 ; i < nChildCount ; ++i )
160 uno::Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
161 if( xChild.get() == static_cast<XAccessible*>(this) )
162 return i;
167 // Return -1 to indicate that this object's parent does not know about the
168 // object.
169 return -1;
172 sal_Int16 SAL_CALL SvtRulerAccessible::getAccessibleRole()
174 return AccessibleRole::RULER;
177 OUString SAL_CALL SvtRulerAccessible::getAccessibleDescription()
179 return OUString();
182 OUString SAL_CALL SvtRulerAccessible::getAccessibleName()
184 ::osl::MutexGuard aGuard( m_aMutex );
185 return msName;
188 /** Return empty uno::Reference to indicate that the relation set is not
189 supported.
191 uno::Reference< XAccessibleRelationSet > SAL_CALL SvtRulerAccessible::getAccessibleRelationSet()
193 return uno::Reference< XAccessibleRelationSet >();
197 sal_Int64 SAL_CALL SvtRulerAccessible::getAccessibleStateSet()
199 ::osl::MutexGuard aGuard( m_aMutex );
200 sal_Int64 nStateSet = 0;
202 if( IsAlive() )
204 nStateSet |= AccessibleStateType::ENABLED;
206 nStateSet |= AccessibleStateType::SHOWING;
208 if( isVisible() )
209 nStateSet |= AccessibleStateType::VISIBLE;
211 if ( mpRepr->GetStyle() & WB_HORZ )
212 nStateSet |= AccessibleStateType::HORIZONTAL;
213 else
214 nStateSet |= AccessibleStateType::VERTICAL;
217 return nStateSet;
220 lang::Locale SAL_CALL SvtRulerAccessible::getLocale()
222 ::osl::MutexGuard aGuard( m_aMutex );
223 if( mxParent.is() )
225 uno::Reference< XAccessibleContext > xParentContext( mxParent->getAccessibleContext() );
226 if( xParentContext.is() )
227 return xParentContext->getLocale();
230 // No parent. Therefore throw exception to indicate this cluelessness.
231 throw IllegalAccessibleComponentStateException();
234 void SAL_CALL SvtRulerAccessible::addAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
236 if (xListener.is())
238 ::osl::MutexGuard aGuard( m_aMutex );
239 if (!mnClientId)
240 mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
241 comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
245 void SAL_CALL SvtRulerAccessible::removeAccessibleEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
247 if (!(xListener.is() && mnClientId))
248 return;
250 ::osl::MutexGuard aGuard( m_aMutex );
252 sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
253 if ( !nListenerCount )
255 // no listeners anymore
256 // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
257 // and at least to us not firing any events anymore, in case somebody calls
258 // NotifyAccessibleEvent, again
259 comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
260 mnClientId = 0;
264 void SAL_CALL SvtRulerAccessible::grabFocus()
266 SolarMutexGuard aSolarGuard;
267 ::osl::MutexGuard aGuard( m_aMutex );
269 ThrowExceptionIfNotAlive();
271 mpRepr->GrabFocus();
274 sal_Int32 SvtRulerAccessible::getForeground( )
276 SolarMutexGuard aSolarGuard;
277 ::osl::MutexGuard aGuard( m_aMutex );
278 ThrowExceptionIfNotAlive();
280 return sal_Int32(mpRepr->GetControlForeground());
282 sal_Int32 SvtRulerAccessible::getBackground( )
284 SolarMutexGuard aSolarGuard;
285 ::osl::MutexGuard aGuard( m_aMutex );
286 ThrowExceptionIfNotAlive();
288 return sal_Int32(mpRepr->GetControlBackground());
291 // XServiceInfo
292 OUString SAL_CALL SvtRulerAccessible::getImplementationName()
294 return "com.sun.star.comp.ui.SvtRulerAccessible";
297 sal_Bool SAL_CALL SvtRulerAccessible::supportsService( const OUString& sServiceName )
299 return cppu::supportsService( this, sServiceName );
302 Sequence< OUString > SAL_CALL SvtRulerAccessible::getSupportedServiceNames()
304 return { "com.sun.star.accessibility.AccessibleContext" };
307 //===== XTypeProvider =======================================================
308 Sequence< sal_Int8 > SAL_CALL SvtRulerAccessible::getImplementationId()
310 return css::uno::Sequence<sal_Int8>();
313 void SAL_CALL SvtRulerAccessible::disposing()
315 if( rBHelper.bDisposed )
316 return;
318 ::osl::MutexGuard aGuard( m_aMutex );
319 mpRepr = nullptr; // object dies with representation
321 // Send a disposing to all listeners.
322 if ( mnClientId )
324 comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
325 mnClientId = 0;
327 mxParent.clear();
330 tools::Rectangle SvtRulerAccessible::GetBoundingBoxOnScreen()
332 SolarMutexGuard aSolarGuard;
333 ::osl::MutexGuard aGuard( m_aMutex );
335 ThrowExceptionIfNotAlive();
336 return tools::Rectangle( mpRepr->GetParent()->OutputToAbsoluteScreenPixel( mpRepr->GetPosPixel() ), mpRepr->GetSizePixel() );
339 tools::Rectangle SvtRulerAccessible::GetBoundingBox()
341 SolarMutexGuard aSolarGuard;
342 ::osl::MutexGuard aGuard( m_aMutex );
344 ThrowExceptionIfNotAlive();
346 return tools::Rectangle( mpRepr->GetPosPixel(), mpRepr->GetSizePixel() );
349 void SvtRulerAccessible::ThrowExceptionIfNotAlive()
351 if( rBHelper.bDisposed || rBHelper.bInDispose )
352 throw lang::DisposedException();
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */