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