1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_SC_SOURCE_UI_INC_ACCESSIBLECONTEXTBASE_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_ACCESSIBLECONTEXTBASE_HXX
23 #include <com/sun/star/accessibility/XAccessible.hpp>
24 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
25 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
26 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
27 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <cppuhelper/weak.hxx>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XTypeProvider.hpp>
33 #include <com/sun/star/lang/XServiceName.hpp>
34 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
35 #include <osl/mutex.hxx>
36 #include <cppuhelper/interfacecontainer.h>
38 #include <svl/lstner.hxx>
39 #include <cppuhelper/compbase5.hxx>
40 #include <cppuhelper/implbase1.hxx>
41 #include <comphelper/servicehelper.hxx>
42 #include <comphelper/broadcasthelper.hxx>
47 This base class provides an implementation of the
48 <code>AccessibleContext</code> service.
51 typedef cppu::WeakAggComponentImplHelper5
<
52 css::accessibility::XAccessible
,
53 css::accessibility::XAccessibleComponent
,
54 css::accessibility::XAccessibleContext
,
55 css::accessibility::XAccessibleEventBroadcaster
,
56 css::lang::XServiceInfo
57 > ScAccessibleContextBaseWeakImpl
;
59 typedef cppu::ImplHelper1
<
60 css::accessibility::XAccessibleEventListener
61 > ScAccessibleContextBaseImplEvent
;
63 class ScAccessibleContextBase
64 : public comphelper::OBaseMutex
,
65 public ScAccessibleContextBaseWeakImpl
,
66 public ScAccessibleContextBaseImplEvent
,
70 //===== internal ========================================================
71 ScAccessibleContextBase(
72 const css::uno::Reference
<css::accessibility::XAccessible
>& rxParent
,
73 const sal_Int16 aRole
);
76 virtual void SAL_CALL
disposing() override
;
78 virtual ~ScAccessibleContextBase();
81 bool SAL_CALL
isShowing( )
82 throw (css::uno::RuntimeException
);
84 virtual bool SAL_CALL
isVisible()
85 throw (css::uno::RuntimeException
, std::exception
);
87 ///===== SfxListener =====================================================
89 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
91 ///===== XInterface =====================================================
93 virtual css::uno::Any SAL_CALL
queryInterface(
94 css::uno::Type
const & rType
)
95 throw (css::uno::RuntimeException
, std::exception
) override
;
97 virtual void SAL_CALL
acquire() throw () override
;
99 virtual void SAL_CALL
release() throw () override
;
101 ///===== XAccessible =====================================================
103 /// Return the XAccessibleContext.
104 virtual css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
105 getAccessibleContext() throw (css::uno::RuntimeException
, std::exception
) override
;
107 ///===== XAccessibleComponent ============================================
109 virtual sal_Bool SAL_CALL
containsPoint(
110 const css::awt::Point
& rPoint
)
111 throw (css::uno::RuntimeException
, std::exception
) override
;
113 virtual css::uno::Reference
< css::accessibility::XAccessible
>
114 SAL_CALL
getAccessibleAtPoint(
115 const css::awt::Point
& rPoint
)
116 throw (css::uno::RuntimeException
, std::exception
) override
;
118 virtual css::awt::Rectangle SAL_CALL
getBounds( )
119 throw (css::uno::RuntimeException
, std::exception
) override
;
121 virtual css::awt::Point SAL_CALL
getLocation( )
122 throw (css::uno::RuntimeException
, std::exception
) override
;
124 virtual css::awt::Point SAL_CALL
getLocationOnScreen( )
125 throw (css::uno::RuntimeException
, std::exception
) override
;
127 virtual css::awt::Size SAL_CALL
getSize( )
128 throw (css::uno::RuntimeException
, std::exception
) override
;
130 virtual void SAL_CALL
grabFocus( )
131 throw (css::uno::RuntimeException
, std::exception
) override
;
133 virtual sal_Int32 SAL_CALL
getForeground( )
134 throw (css::uno::RuntimeException
, std::exception
) override
;
136 virtual sal_Int32 SAL_CALL
getBackground( )
137 throw (css::uno::RuntimeException
, std::exception
) override
;
139 ///===== XAccessibleContext ==============================================
141 /// Return the number of currently visible children.
142 virtual sal_Int32 SAL_CALL
getAccessibleChildCount()
143 throw (css::uno::RuntimeException
, std::exception
) override
;
145 /// Return the specified child or NULL if index is invalid.
146 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
147 getAccessibleChild(sal_Int32 nIndex
)
148 throw (css::uno::RuntimeException
,
149 css::lang::IndexOutOfBoundsException
,
150 std::exception
) override
;
152 /// Return a reference to the parent.
153 virtual css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
154 getAccessibleParent()
155 throw (css::uno::RuntimeException
, std::exception
) override
;
157 /// Return this objects index among the parents children.
158 virtual sal_Int32 SAL_CALL
159 getAccessibleIndexInParent()
160 throw (css::uno::RuntimeException
, std::exception
) override
;
162 /// Return this object's role.
163 virtual sal_Int16 SAL_CALL
165 throw (css::uno::RuntimeException
, std::exception
) override
;
167 /// Return this object's description.
168 virtual OUString SAL_CALL
169 getAccessibleDescription()
170 throw (css::uno::RuntimeException
, std::exception
) override
;
172 /// Return the object's current name.
173 virtual OUString SAL_CALL
175 throw (css::uno::RuntimeException
, std::exception
) override
;
177 /// Return NULL to indicate that an empty relation set.
178 virtual css::uno::Reference
<css::accessibility::XAccessibleRelationSet
> SAL_CALL
179 getAccessibleRelationSet()
180 throw (css::uno::RuntimeException
, std::exception
) override
;
182 /// Return the set of current states.
183 virtual css::uno::Reference
<css::accessibility::XAccessibleStateSet
> SAL_CALL
184 getAccessibleStateSet()
185 throw (css::uno::RuntimeException
, std::exception
) override
;
187 /** Return the parents locale or throw exception if this object has no
190 virtual css::lang::Locale SAL_CALL
192 throw (css::uno::RuntimeException
,
193 css::accessibility::IllegalAccessibleComponentStateException
, std::exception
) override
;
195 ///===== XAccessibleEventBroadcaster =====================================
197 /** Add listener that is informed of future changes of name,
198 description and so on events.
200 virtual void SAL_CALL
201 addAccessibleEventListener(
202 const css::uno::Reference
<css::accessibility::XAccessibleEventListener
>& xListener
)
203 throw (css::uno::RuntimeException
, std::exception
) override
;
205 // Remove an existing event listener.
206 virtual void SAL_CALL
207 removeAccessibleEventListener(
208 const css::uno::Reference
<css::accessibility::XAccessibleEventListener
>& xListener
)
209 throw (css::uno::RuntimeException
, std::exception
) override
;
211 ///===== XAccessibleEventListener ========================================
213 virtual void SAL_CALL
214 disposing( const css::lang::EventObject
& Source
)
215 throw (css::uno::RuntimeException
, std::exception
) override
;
217 virtual void SAL_CALL
219 const css::accessibility::AccessibleEventObject
& aEvent
)
220 throw (css::uno::RuntimeException
, std::exception
) override
;
222 ///===== XServiceInfo ====================================================
224 /** Returns an identifier for the implementation of this object.
226 virtual OUString SAL_CALL
227 getImplementationName()
228 throw (css::uno::RuntimeException
, std::exception
) override
;
230 /** Return whether the specified service is supported by this class.
232 virtual sal_Bool SAL_CALL
233 supportsService(const OUString
& sServiceName
)
234 throw (css::uno::RuntimeException
, std::exception
) override
;
236 /** Returns a list of all supported services. In this case that is just
237 the AccessibleContext and Accessible service.
239 virtual css::uno::Sequence
< OUString
> SAL_CALL
240 getSupportedServiceNames()
241 throw (css::uno::RuntimeException
, std::exception
) override
;
243 ///===== XTypeProvider ===================================================
245 /// returns the possible types
246 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
248 throw (css::uno::RuntimeException
, std::exception
) override
;
250 /** Returns a implementation id.
252 virtual css::uno::Sequence
<sal_Int8
> SAL_CALL
253 getImplementationId()
254 throw (css::uno::RuntimeException
, std::exception
) override
;
257 /// Return this object's description.
258 virtual OUString SAL_CALL
259 createAccessibleDescription()
260 throw (css::uno::RuntimeException
, std::exception
);
262 /// Return the object's current name.
263 virtual OUString SAL_CALL
264 createAccessibleName()
265 throw (css::uno::RuntimeException
,
268 /// Return the object's current bounding box relative to the desktop.
269 virtual Rectangle
GetBoundingBoxOnScreen() const
270 throw (css::uno::RuntimeException
, std::exception
);
272 /// Return the object's current bounding box relative to the parent object.
273 virtual Rectangle
GetBoundingBox() const
274 throw (css::uno::RuntimeException
, std::exception
);
277 /// Calls all Listener to tell they the change.
279 CommitChange(const css::accessibility::AccessibleEventObject
& rEvent
) const;
282 /// Calls all FocusListener to tell they that the focus is gained.
283 void CommitFocusGained() const;
285 /// Calls all FocusListener to tell they that the focus is lost.
286 void CommitFocusLost() const;
288 bool IsDefunc() const { return rBHelper
.bDisposed
; }
290 void IsObjectValid() const
291 throw (css::lang::DisposedException
);
293 /// Use this method to set initial Name without notification
294 void SetName(const OUString
& rName
) { msName
= rName
; }
295 /// Use this method to set initial Description without notification
296 void SetDescription(const OUString
& rDesc
) { msDescription
= rDesc
; }
298 /// Reference to the parent object.
299 css::uno::Reference
<css::accessibility::XAccessible
> mxParent
;
302 /** Description of this object. This is not a constant because it can
303 be set from the outside. Furthermore, it changes according to the
304 draw page's display mode.
306 OUString msDescription
;
308 /** Name of this object. It changes according the draw page's
313 /// client id in the AccessibleEventNotifier queue
314 sal_uInt32 mnClientId
;
316 /** This is the role of this object.
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */