1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #ifndef _SC_ACCESSIBLECONTEXTBASE_HXX
30 #define _SC_ACCESSIBLECONTEXTBASE_HXX
31 
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
34 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
35 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
36 #ifndef _COM_SUN_STAR_ACCESSIBILITY_IllegalAccessibleComponentStateException_HPP_
37 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp>
38 #endif
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <com/sun/star/uno/Reference.hxx>
41 #include <cppuhelper/weak.hxx>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
43 #include <com/sun/star/lang/XTypeProvider.hpp>
44 #include <com/sun/star/lang/XServiceName.hpp>
45 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
46 #include <vos/mutex.hxx>
47 #include <cppuhelper/interfacecontainer.h>
48 
49 
50 #include <svl/lstner.hxx>
51 #include <cppuhelper/compbase5.hxx>
52 #include <cppuhelper/implbase1.hxx>
53 #include <comphelper/servicehelper.hxx>
54 #include <comphelper/broadcasthelper.hxx>
55 
56 class Rectangle;
57 
58 /**	@descr
59         This base class provides an implementation of the
60         <code>AccessibleContext</code> service.
61 */
62 
63 typedef cppu::WeakAggComponentImplHelper5<
64 				::com::sun::star::accessibility::XAccessible,
65 				::com::sun::star::accessibility::XAccessibleComponent,
66                 ::com::sun::star::accessibility::XAccessibleContext,
67 				::com::sun::star::accessibility::XAccessibleEventBroadcaster,
68                 ::com::sun::star::lang::XServiceInfo
69 				> ScAccessibleContextBaseWeakImpl;
70 
71 typedef cppu::ImplHelper1<
72 				::com::sun::star::accessibility::XAccessibleEventListener
73 				> ScAccessibleContextBaseImplEvent;
74 
75 class ScAccessibleContextBase
76 	:	public comphelper::OBaseMutex,
77 		public ScAccessibleContextBaseWeakImpl,
78 		public ScAccessibleContextBaseImplEvent,
79 		public SfxListener
80 {
81 public:
82 	//=====  internal  ========================================================
83 	ScAccessibleContextBase(
84         const ::com::sun::star::uno::Reference<
85         ::com::sun::star::accessibility::XAccessible>& rxParent,
86 		const sal_Int16 aRole);
87 
88 	virtual void Init();
89     virtual void SAL_CALL disposing();
90 protected:
91 	virtual ~ScAccessibleContextBase(void);
92 public:
93     using WeakAggComponentImplHelperBase::addEventListener;
94     using WeakAggComponentImplHelperBase::removeEventListener;
95 
96 	///=====  SfxListener  =====================================================
97 
98 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
99 
100 	///=====  XInterface  =====================================================
101 
102 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
103 		::com::sun::star::uno::Type const & rType )
104 		throw (::com::sun::star::uno::RuntimeException);
105 
106 	virtual void SAL_CALL acquire() throw ();
107 
108 	virtual void SAL_CALL release() throw ();
109 
110 	///=====  XAccessible  =====================================================
111 
112     ///	Return the XAccessibleContext.
113     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL
114     	getAccessibleContext(void) throw (::com::sun::star::uno::RuntimeException);
115 
116 	///=====  XAccessibleComponent  ============================================
117 
118     virtual sal_Bool SAL_CALL containsPoint(
119 		const ::com::sun::star::awt::Point& rPoint )
120 		throw (::com::sun::star::uno::RuntimeException);
121 
122     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
123 		SAL_CALL getAccessibleAtPoint(
124 		const ::com::sun::star::awt::Point& rPoint )
125 		throw (::com::sun::star::uno::RuntimeException);
126 
127     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds(  )
128 		throw (::com::sun::star::uno::RuntimeException);
129 
130     virtual ::com::sun::star::awt::Point SAL_CALL getLocation(  )
131 		throw (::com::sun::star::uno::RuntimeException);
132 
133     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen(  )
134 		throw (::com::sun::star::uno::RuntimeException);
135 
136     virtual ::com::sun::star::awt::Size SAL_CALL getSize(  )
137 		throw (::com::sun::star::uno::RuntimeException);
138 
139 	virtual sal_Bool SAL_CALL isShowing(  )
140 		throw (::com::sun::star::uno::RuntimeException);
141 
142     virtual sal_Bool SAL_CALL isVisible(  )
143 		throw (::com::sun::star::uno::RuntimeException);
144 
145     virtual void SAL_CALL grabFocus(  )
146 		throw (::com::sun::star::uno::RuntimeException);
147 
148     virtual sal_Int32 SAL_CALL getForeground(  )
149         throw (::com::sun::star::uno::RuntimeException);
150 
151     virtual sal_Int32 SAL_CALL getBackground(  )
152         throw (::com::sun::star::uno::RuntimeException);
153 
154     ///=====  XAccessibleContext  ==============================================
155 
156     ///	Return the number of currently visible children.
157     virtual sal_Int32 SAL_CALL
158     	getAccessibleChildCount(void) throw (::com::sun::star::uno::RuntimeException);
159 
160     ///	Return the specified child or NULL if index is invalid.
161     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
162     	getAccessibleChild(sal_Int32 nIndex)
163         throw (::com::sun::star::uno::RuntimeException,
164 				::com::sun::star::lang::IndexOutOfBoundsException);
165 
166     ///	Return a reference to the parent.
167 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
168     	getAccessibleParent(void)
169         throw (::com::sun::star::uno::RuntimeException);
170 
171     ///	Return this objects index among the parents children.
172 	virtual	sal_Int32 SAL_CALL
173     	getAccessibleIndexInParent(void)
174         throw (::com::sun::star::uno::RuntimeException);
175 
176     ///	Return this object's role.
177 	virtual sal_Int16 SAL_CALL
178     	getAccessibleRole(void)
179         throw (::com::sun::star::uno::RuntimeException);
180 
181     ///	Return this object's description.
182 	virtual ::rtl::OUString SAL_CALL
183     	getAccessibleDescription(void)
184         throw (::com::sun::star::uno::RuntimeException);
185 
186     ///	Return the object's current name.
187 	virtual ::rtl::OUString SAL_CALL
188     	getAccessibleName(void)
189         throw (::com::sun::star::uno::RuntimeException);
190 
191 	///	Return NULL to indicate that an empty relation set.
192 	virtual ::com::sun::star::uno::Reference<
193             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
194     	getAccessibleRelationSet(void)
195         throw (::com::sun::star::uno::RuntimeException);
196 
197     ///	Return the set of current states.
198 	virtual ::com::sun::star::uno::Reference<
199             ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL
200     	getAccessibleStateSet(void)
201         throw (::com::sun::star::uno::RuntimeException);
202 
203 	/**	Return the parents locale or throw exception if this object has no
204     	parent yet/anymore.
205     */
206 	virtual ::com::sun::star::lang::Locale SAL_CALL
207     	getLocale(void)
208 		throw (::com::sun::star::uno::RuntimeException,
209 			::com::sun::star::accessibility::IllegalAccessibleComponentStateException);
210 
211 	///=====  XAccessibleEventBroadcaster  =====================================
212 
213     /**	Add listener that is informed of future changes of name,
214       	description and so on events.
215     */
216 	virtual void SAL_CALL
217     	addEventListener(
218         	const ::com::sun::star::uno::Reference<
219                 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
220         throw (com::sun::star::uno::RuntimeException);
221 
222     //	Remove an existing event listener.
223 	virtual void SAL_CALL
224     	removeEventListener(
225 			const ::com::sun::star::uno::Reference<
226                 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
227         throw (com::sun::star::uno::RuntimeException);
228 
229 	///=====  XAccessibleEventListener  ========================================
230 
231     virtual void SAL_CALL
232 		disposing( const ::com::sun::star::lang::EventObject& Source )
233 		throw (::com::sun::star::uno::RuntimeException);
234 
235 	virtual void SAL_CALL
236 		notifyEvent(
237 		const ::com::sun::star::accessibility::AccessibleEventObject& aEvent )
238 		throw (::com::sun::star::uno::RuntimeException);
239 
240 	///=====  XServiceInfo  ====================================================
241 
242     /**	Returns an identifier for the implementation of this object.
243     */
244 	virtual ::rtl::OUString SAL_CALL
245     	getImplementationName(void)
246         throw (::com::sun::star::uno::RuntimeException);
247 
248     /**	Return whether the specified service is supported by this class.
249     */
250     virtual sal_Bool SAL_CALL
251     	supportsService(const ::rtl::OUString& sServiceName)
252         throw (::com::sun::star::uno::RuntimeException);
253 
254     /** Returns a list of all supported services.  In this case that is just
255     	the AccessibleContext and Accessible service.
256     */
257 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
258     	getSupportedServiceNames(void)
259         throw (::com::sun::star::uno::RuntimeException);
260 
261 	///=====  XTypeProvider  ===================================================
262 
263  	/// returns the possible types
264     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL
265 		getTypes()
266 		throw (::com::sun::star::uno::RuntimeException);
267 
268 	/**	Returns a implementation id.
269     */
270     virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL
271         getImplementationId(void)
272         throw (::com::sun::star::uno::RuntimeException);
273 
274 protected:
275     ///	Return this object's description.
276 	virtual ::rtl::OUString SAL_CALL
277     	createAccessibleDescription(void)
278         throw (::com::sun::star::uno::RuntimeException);
279 
280     ///	Return the object's current name.
281 	virtual ::rtl::OUString SAL_CALL
282     	createAccessibleName(void)
283         throw (::com::sun::star::uno::RuntimeException);
284 
285     ///	Return the object's current bounding box relative to the desktop.
286 	virtual Rectangle GetBoundingBoxOnScreen(void) const
287 		throw (::com::sun::star::uno::RuntimeException);
288 
289 	///	Return the object's current bounding box relative to the parent object.
290 	virtual Rectangle GetBoundingBox(void) const
291 		throw (::com::sun::star::uno::RuntimeException);
292 
293 public:
294     /// Calls all Listener to tell they the change.
295 	void
296 		CommitChange(const com::sun::star::accessibility::AccessibleEventObject& rEvent) const;
297 
298     /// change the name and call the listener to tell they the change
299     void
300         ChangeName();
301 
302 protected:
303 	/// Calls all FocusListener to tell they that the focus is gained.
304 	void CommitFocusGained() const;
305 
306 	/// Calls all FocusListener to tell they that the focus is lost.
307 	void CommitFocusLost() const;
308 
309 	sal_Bool IsDefunc() const { return rBHelper.bDisposed; }
310 
311     virtual void IsObjectValid() const
312         throw (::com::sun::star::lang::DisposedException);
313 
314     /// Use this method to set initial Name without notification
315     void SetName(const rtl::OUString& rName) { msName = rName; }
316     /// Use this method to set initial Description without notification
317     void SetDescription(const rtl::OUString& rDesc) { msDescription = rDesc; }
318 
319     ///	Reference to the parent object.
320     ::com::sun::star::uno::Reference<
321     	 ::com::sun::star::accessibility::XAccessible> mxParent;
322 
323 private:
324     /**	Description of this object.  This is not a constant because it can
325     	be set from the outside.  Furthermore, it changes according the the
326         draw page's display mode.
327     */
328     ::rtl::OUString msDescription;
329 
330     /**	Name of this object.  It changes according the the draw page's
331         display mode.
332     */
333     ::rtl::OUString msName;
334 
335     /// client id in the AccessibleEventNotifier queue
336     sal_uInt32 mnClientId;
337 
338 	/** This is the role of this object.
339 	*/
340 	sal_Int16 maRole;
341 };
342 
343 
344 #endif
345