1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_ACCESSIBLECONTEXTBASE_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_ACCESSIBLECONTEXTBASE_HXX
22 
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/uno/Reference.hxx>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <cppuhelper/interfacecontainer.h>
30 
31 #include <svl/lstner.hxx>
32 #include <cppuhelper/basemutex.hxx>
33 #include <cppuhelper/compbase5.hxx>
34 #include <cppuhelper/implbase1.hxx>
35 
36 namespace tools { class Rectangle; }
37 
38 /** @descr
39         This base class provides an implementation of the
40         <code>AccessibleContext</code> service.
41 */
42 
43 typedef cppu::WeakAggComponentImplHelper5<
44                 css::accessibility::XAccessible,
45                 css::accessibility::XAccessibleComponent,
46                 css::accessibility::XAccessibleContext,
47                 css::accessibility::XAccessibleEventBroadcaster,
48                 css::lang::XServiceInfo
49                 > ScAccessibleContextBaseWeakImpl;
50 
51 typedef cppu::ImplHelper1<
52                 css::accessibility::XAccessibleEventListener
53                 > ScAccessibleContextBaseImplEvent;
54 
55 class ScAccessibleContextBase
56     :   public cppu::BaseMutex,
57         public ScAccessibleContextBaseWeakImpl,
58         public ScAccessibleContextBaseImplEvent,
59         public SfxListener
60 {
61 public:
62     //=====  internal  ========================================================
63     ScAccessibleContextBase(
64         const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
65         const sal_Int16 aRole);
66 
67     virtual void Init();
68     virtual void SAL_CALL disposing() override;
69 protected:
70     virtual ~ScAccessibleContextBase() override;
71 public:
72 
73     /// @throws css::uno::RuntimeException
74     bool isShowing();
75 
76     /// @throws css::uno::RuntimeException
77     virtual bool isVisible();
78 
79     ///=====  SfxListener  =====================================================
80 
81     virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
82 
83     ///=====  XInterface  =====================================================
84 
85     virtual css::uno::Any SAL_CALL queryInterface(
86         css::uno::Type const & rType ) override;
87 
88     virtual void SAL_CALL acquire() throw () override;
89 
90     virtual void SAL_CALL release() throw () override;
91 
92     ///=====  XAccessible  =====================================================
93 
94     /// Return the XAccessibleContext.
95     virtual css::uno::Reference< css::accessibility::XAccessibleContext> SAL_CALL
96         getAccessibleContext() override;
97 
98     ///=====  XAccessibleComponent  ============================================
99 
100     virtual sal_Bool SAL_CALL containsPoint(
101         const css::awt::Point& rPoint ) override;
102 
103     virtual css::uno::Reference< css::accessibility::XAccessible >
104         SAL_CALL getAccessibleAtPoint(
105         const css::awt::Point& rPoint ) override;
106 
107     virtual css::awt::Rectangle SAL_CALL getBounds(  ) override;
108 
109     virtual css::awt::Point SAL_CALL getLocation(  ) override;
110 
111     virtual css::awt::Point SAL_CALL getLocationOnScreen(  ) override;
112 
113     virtual css::awt::Size SAL_CALL getSize(  ) override;
114 
115     virtual void SAL_CALL grabFocus(  ) override;
116 
117     virtual sal_Int32 SAL_CALL getForeground(  ) override;
118 
119     virtual sal_Int32 SAL_CALL getBackground(  ) override;
120 
121     ///=====  XAccessibleContext  ==============================================
122 
123     /// Return the number of currently visible children.
124     virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
125 
126     /// Return the specified child or NULL if index is invalid.
127     virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
128         getAccessibleChild(sal_Int32 nIndex) override;
129 
130     /// Return a reference to the parent.
131     virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
132         getAccessibleParent() override;
133 
134     /// Return this objects index among the parents children.
135     virtual sal_Int32 SAL_CALL
136         getAccessibleIndexInParent() override;
137 
138     /// Return this object's role.
139     virtual sal_Int16 SAL_CALL
140         getAccessibleRole() override;
141 
142     /// Return this object's description.
143     virtual OUString SAL_CALL
144         getAccessibleDescription() override;
145 
146     /// Return the object's current name.
147     virtual OUString SAL_CALL
148         getAccessibleName() override;
149 
150     /// Return NULL to indicate that an empty relation set.
151     virtual css::uno::Reference<css::accessibility::XAccessibleRelationSet> SAL_CALL
152         getAccessibleRelationSet() override;
153 
154     /// Return the set of current states.
155     virtual css::uno::Reference<css::accessibility::XAccessibleStateSet> SAL_CALL
156         getAccessibleStateSet() override;
157 
158     /** Return the parents locale or throw exception if this object has no
159         parent yet/anymore.
160     */
161     virtual css::lang::Locale SAL_CALL
162         getLocale() override;
163 
164     ///=====  XAccessibleEventBroadcaster  =====================================
165 
166     /** Add listener that is informed of future changes of name,
167           description and so on events.
168     */
169     virtual void SAL_CALL
170         addAccessibleEventListener(
171             const css::uno::Reference<css::accessibility::XAccessibleEventListener>& xListener) override;
172 
173     //  Remove an existing event listener.
174     virtual void SAL_CALL
175         removeAccessibleEventListener(
176             const css::uno::Reference<css::accessibility::XAccessibleEventListener>& xListener) override;
177 
178     ///=====  XAccessibleEventListener  ========================================
179 
180     virtual void SAL_CALL
181         disposing( const css::lang::EventObject& Source ) override;
182 
183     virtual void SAL_CALL
184         notifyEvent(
185         const css::accessibility::AccessibleEventObject& aEvent ) override;
186 
187     ///=====  XServiceInfo  ====================================================
188 
189     /** Returns an identifier for the implementation of this object.
190     */
191     virtual OUString SAL_CALL
192         getImplementationName() override;
193 
194     /** Return whether the specified service is supported by this class.
195     */
196     virtual sal_Bool SAL_CALL
197         supportsService(const OUString& sServiceName) override;
198 
199     /** Returns a list of all supported services.  In this case that is just
200         the AccessibleContext and Accessible service.
201     */
202     virtual css::uno::Sequence< OUString> SAL_CALL
203         getSupportedServiceNames() override;
204 
205     ///=====  XTypeProvider  ===================================================
206 
207      /// returns the possible types
208     virtual css::uno::Sequence< css::uno::Type > SAL_CALL
209         getTypes() override;
210 
211     /** Returns an implementation id.
212     */
213     virtual css::uno::Sequence<sal_Int8> SAL_CALL
214         getImplementationId() override;
215 
216 protected:
217     /// Return this object's description.
218     ///
219     /// @throws css::uno::RuntimeException
220     virtual OUString
221         createAccessibleDescription();
222 
223     /// Return the object's current name.
224     ///
225     /// @throws css::uno::RuntimeException
226     virtual OUString
227         createAccessibleName();
228 
229     /// Return the object's current bounding box relative to the desktop.
230     ///
231     /// @throws css::uno::RuntimeException
232     virtual tools::Rectangle GetBoundingBoxOnScreen() const;
233 
234     /// Return the object's current bounding box relative to the parent object.
235     ///
236     /// @throws css::uno::RuntimeException
237     virtual tools::Rectangle GetBoundingBox() const;
238 
239 public:
240     /// Calls all Listener to tell they the change.
241     void
242         CommitChange(const css::accessibility::AccessibleEventObject& rEvent) const;
243 
244     /// Use this method to set initial Name without notification
SetName(const OUString & rName)245     void SetName(const OUString& rName) { msName = rName; }
246 
247     /// Use this method to set initial Description without notification
SetDescription(const OUString & rDesc)248     void SetDescription(const OUString& rDesc) { msDescription = rDesc; }
249 
SetParent(const css::uno::Reference<css::accessibility::XAccessible> & rParent)250     void SetParent(const css::uno::Reference<css::accessibility::XAccessible>& rParent) { mxParent = rParent; }
251 
252 protected:
253     /// Calls all FocusListener to tell they that the focus is gained.
254     void CommitFocusGained() const;
255 
256     /// Calls all FocusListener to tell they that the focus is lost.
257     void CommitFocusLost() const;
258 
IsDefunc() const259     bool IsDefunc() const { return rBHelper.bDisposed; }
260 
261     /// @throws css::lang::DisposedException
262     void IsObjectValid() const;
263 
264     /// Reference to the parent object.
265     css::uno::Reference<css::accessibility::XAccessible> mxParent;
266 
267 private:
268     /** Description of this object.  This is not a constant because it can
269         be set from the outside.  Furthermore, it changes according to the
270         draw page's display mode.
271     */
272     OUString msDescription;
273 
274     /** Name of this object.  It changes according the draw page's
275         display mode.
276     */
277     OUString msName;
278 
279     /// client id in the AccessibleEventNotifier queue
280     sal_uInt32 mnClientId;
281 
282     /** This is the role of this object.
283     */
284     sal_Int16 const maRole;
285 };
286 
287 #endif
288 
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
290