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 #ifndef SD_ACCESSIBILITY_ACCESSIBLE_BASE_HXX
29 #define SD_ACCESSIBILITY_ACCESSIBLE_BASE_HXX
30 
31 #include "MutexOwner.hxx"
32 #include <cppuhelper/compbase5.hxx>
33 #include <com/sun/star/accessibility/XAccessible.hpp>
34 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
35 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
36 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
37 #include <com/sun/star/accessibility/AccessibleRole.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/awt/XFocusListener.hpp>
42 #include <com/sun/star/document/XEventListener.hpp>
43 #include <unotools/accessiblestatesethelper.hxx>
44 #include <tools/link.hxx>
45 #include <rtl/ref.hxx>
46 
47 class VclWindowEvent;
48 
49 namespace sd { namespace toolpanel {
50 class TreeNode;
51 class TreeNodeStateChangeEvent;
52 } }
53 
54 
55 namespace utl {
56 class AccessibleStateSetHelper;
57 }
58 
59 namespace accessibility {
60 
61 
62 class AccessibleSlideSorterObject;
63 
64 typedef ::cppu::WeakComponentImplHelper5<
65     ::com::sun::star::accessibility::XAccessible,
66     ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
67     ::com::sun::star::accessibility::XAccessibleContext,
68     ::com::sun::star::accessibility::XAccessibleComponent,
69     ::com::sun::star::lang::XServiceInfo
70     > AccessibleTreeNodeBase;
71 
72 /** This class makes objects based on the sd::toolpanel::TreeNode
73     accessible.
74 */
75 class AccessibleTreeNode
76     : public ::sd::MutexOwner,
77       public AccessibleTreeNodeBase
78 {
79 public:
80     /** Create a new object for the given tree node.  The accessible parent
81         is taken from the window returned by GetAccessibleParent() when
82         called at the window of the node.
83         @param rNode
84             The TreeNode to make accessible.
85         @param rsName
86             The accessible name that will be returned by getAccessibleName().
87         @param rsDescription
88             The accessible description that will be returned by
89             getAccessibleDescription().
90         @param eRole
91             The role that will be returned by getAccessibleRole().
92     */
93     AccessibleTreeNode(
94         ::sd::toolpanel::TreeNode& rNode,
95         const ::rtl::OUString& rsName,
96         const ::rtl::OUString& rsDescription,
97         sal_Int16 eRole);
98 
99     void FireAccessibleEvent (
100         short nEventId,
101         const ::com::sun::star::uno::Any& rOldValue,
102         const ::com::sun::star::uno::Any& rNewValue);
103 
104     virtual void SAL_CALL disposing (void);
105 
106     //===== XAccessible =======================================================
107 
108     virtual ::com::sun::star::uno::Reference<
109         ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL
110         getAccessibleContext (void)
111         throw (::com::sun::star::uno::RuntimeException);
112 
113 
114     //===== XAccessibleEventBroadcaster =======================================
115 
116     virtual void SAL_CALL
117         addEventListener(
118             const ::com::sun::star::uno::Reference<
119             ::com::sun::star::accessibility::XAccessibleEventListener >& rxListener)
120         throw (::com::sun::star::uno::RuntimeException);
121 
122     virtual void SAL_CALL
123         removeEventListener(
124             const ::com::sun::star::uno::Reference<
125             ::com::sun::star::accessibility::XAccessibleEventListener >& rxListener )
126         throw (::com::sun::star::uno::RuntimeException);
127 
128 	using cppu::WeakComponentImplHelperBase::addEventListener;
129 	using cppu::WeakComponentImplHelperBase::removeEventListener;
130 
131 	//=====  XAccessibleContext  ==============================================
132 
133     ///	Return the number of currently visible children.
134     virtual sal_Int32 SAL_CALL
135     	getAccessibleChildCount (void) throw (::com::sun::star::uno::RuntimeException);
136 
137     ///	Return the specified child or throw exception.
138     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
139     	getAccessibleChild (sal_Int32 nIndex)
140         throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
141 
142     ///	Return a reference to the parent.
143 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
144     	getAccessibleParent (void)
145         throw (::com::sun::star::uno::RuntimeException);
146 
147     ///	Return this objects index among the parents children.
148 	virtual	sal_Int32 SAL_CALL
149     	getAccessibleIndexInParent (void)
150         throw (::com::sun::star::uno::RuntimeException);
151 
152     ///	Return this object's role.
153 	virtual sal_Int16 SAL_CALL
154     	getAccessibleRole (void)
155         throw (::com::sun::star::uno::RuntimeException);
156 
157     ///	Return this object's description.
158 	virtual ::rtl::OUString SAL_CALL
159     	getAccessibleDescription (void)
160         throw (::com::sun::star::uno::RuntimeException);
161 
162     ///	Return the object's current name.
163 	virtual ::rtl::OUString SAL_CALL
164     	getAccessibleName (void)
165         throw (::com::sun::star::uno::RuntimeException);
166 
167 	///	Return NULL to indicate that an empty relation set.
168 	virtual ::com::sun::star::uno::Reference<
169             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
170     	getAccessibleRelationSet (void)
171         throw (::com::sun::star::uno::RuntimeException);
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         throw (::com::sun::star::uno::RuntimeException);
178 
179 	/**	Return the parents locale or throw exception if this object has no
180     	parent yet/anymore.
181     */
182 	virtual ::com::sun::star::lang::Locale SAL_CALL
183     	getLocale (void)
184 		throw (::com::sun::star::uno::RuntimeException,
185 			::com::sun::star::accessibility::IllegalAccessibleComponentStateException);
186 
187     //=====  XAccessibleComponent  ================================================
188 
189     virtual sal_Bool SAL_CALL containsPoint (
190         const ::com::sun::star::awt::Point& aPoint)
191         throw (::com::sun::star::uno::RuntimeException);
192 
193     virtual ::com::sun::star::uno::Reference<
194         ::com::sun::star::accessibility::XAccessible > SAL_CALL
195         getAccessibleAtPoint (
196             const ::com::sun::star::awt::Point& aPoint)
197         throw (::com::sun::star::uno::RuntimeException);
198 
199     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds (void)
200         throw (::com::sun::star::uno::RuntimeException);
201 
202     virtual ::com::sun::star::awt::Point SAL_CALL getLocation (void)
203         throw (::com::sun::star::uno::RuntimeException);
204 
205     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen (void)
206         throw (::com::sun::star::uno::RuntimeException);
207 
208     virtual ::com::sun::star::awt::Size SAL_CALL getSize (void)
209         throw (::com::sun::star::uno::RuntimeException);
210 
211     virtual void SAL_CALL grabFocus (void)
212         throw (::com::sun::star::uno::RuntimeException);
213 
214     virtual sal_Int32 SAL_CALL getForeground (void)
215         throw (::com::sun::star::uno::RuntimeException);
216 
217     virtual sal_Int32 SAL_CALL getBackground (void)
218         throw (::com::sun::star::uno::RuntimeException);
219 
220 
221 	//=====  XServiceInfo  ====================================================
222 
223     /**	Returns an identifier for the implementation of this object.
224     */
225 	virtual ::rtl::OUString SAL_CALL
226     	getImplementationName (void)
227         throw (::com::sun::star::uno::RuntimeException);
228 
229     /**	Return whether the specified service is supported by this class.
230     */
231     virtual sal_Bool SAL_CALL
232     	supportsService (const ::rtl::OUString& sServiceName)
233         throw (::com::sun::star::uno::RuntimeException);
234 
235     /** Returns a list of all supported services.
236     */
237 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
238     	getSupportedServiceNames (void)
239         throw (::com::sun::star::uno::RuntimeException);
240 
241 
242 protected:
243     ::com::sun::star::uno::Reference<
244         ::com::sun::star::accessibility::XAccessible> mxParent;
245     ::sd::toolpanel::TreeNode& mrTreeNode;
246     ::rtl::Reference< ::utl::AccessibleStateSetHelper> mrStateSet;
247 
248     const ::rtl::OUString msName;
249     const ::rtl::OUString msDescription;
250     const sal_Int16 meRole;
251 
252     virtual ~AccessibleTreeNode (void);
253 
254     /** Check whether or not the object has been disposed (or is in the
255         state of beeing disposed).  If that is the case then
256         DisposedException is thrown to inform the (indirect) caller of the
257         foul deed.
258     */
259     void ThrowIfDisposed (void)
260         throw (::com::sun::star::lang::DisposedException);
261 
262     /** Check whether or not the object has been disposed (or is in the
263         state of beeing disposed).
264 
265         @return sal_True, if the object is disposed or in the course
266         of being disposed. Otherwise, sal_False is returned.
267     */
268     sal_Bool IsDisposed (void);
269 
270     /** Update the mpStateSet member to reflect the current state of the
271         TreeNode.  When one of the states has changed since the last call
272         then an appropriate event is sent.
273     */
274     virtual void UpdateStateSet (void);
275 
276     /** Update a single state and sent an event if its value changes.
277     */
278     void UpdateState(
279         sal_Int16 aState,
280         bool bValue);
281 
282     DECL_LINK(StateChangeListener, ::sd::toolpanel::TreeNodeStateChangeEvent*);
283     DECL_LINK(WindowEventListener, VclWindowEvent*);
284 
285 private:
286     sal_uInt32 mnClientId;
287 
288     /// The common part of the constructor.
289     void CommonConstructor (void);
290 };
291 
292 } // end of namespace ::accessibility
293 
294 #endif
295