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