xref: /trunk/main/sd/source/ui/inc/AccessibleTreeNode.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 #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 
108 
109     //===== XAccessibleEventBroadcaster =======================================
110 
111     virtual void SAL_CALL
112         addEventListener(
113             const ::com::sun::star::uno::Reference<
114             ::com::sun::star::accessibility::XAccessibleEventListener >& rxListener);
115 
116     virtual void SAL_CALL
117         removeEventListener(
118             const ::com::sun::star::uno::Reference<
119             ::com::sun::star::accessibility::XAccessibleEventListener >& rxListener );
120 
121     using cppu::WeakComponentImplHelperBase::addEventListener;
122     using cppu::WeakComponentImplHelperBase::removeEventListener;
123 
124     //=====  XAccessibleContext  ==============================================
125 
126     /// Return the number of currently visible children.
127     virtual sal_Int32 SAL_CALL
128         getAccessibleChildCount (void);
129 
130     /// Return the specified child or throw exception.
131     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
132         getAccessibleChild (sal_Int32 nIndex);
133 
134     /// Return a reference to the parent.
135     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL
136         getAccessibleParent (void);
137 
138     /// Return this objects index among the parents children.
139     virtual sal_Int32 SAL_CALL
140         getAccessibleIndexInParent (void);
141 
142     /// Return this object's role.
143     virtual sal_Int16 SAL_CALL
144         getAccessibleRole (void);
145 
146     /// Return this object's description.
147     virtual ::rtl::OUString SAL_CALL
148         getAccessibleDescription (void);
149 
150     /// Return the object's current name.
151     virtual ::rtl::OUString SAL_CALL
152         getAccessibleName (void);
153 
154     /// Return NULL to indicate that an empty relation set.
155     virtual ::com::sun::star::uno::Reference<
156             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
157         getAccessibleRelationSet (void);
158 
159     /// Return the set of current states.
160     virtual ::com::sun::star::uno::Reference<
161             ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL
162         getAccessibleStateSet (void);
163 
164     /** Return the parents locale or throw exception if this object has no
165         parent yet/anymore.
166     */
167     virtual ::com::sun::star::lang::Locale SAL_CALL
168         getLocale (void);
169 
170     //=====  XAccessibleComponent  ================================================
171 
172     virtual sal_Bool SAL_CALL containsPoint (
173         const ::com::sun::star::awt::Point& aPoint);
174 
175     virtual ::com::sun::star::uno::Reference<
176         ::com::sun::star::accessibility::XAccessible > SAL_CALL
177         getAccessibleAtPoint (
178             const ::com::sun::star::awt::Point& aPoint);
179 
180     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds (void);
181 
182     virtual ::com::sun::star::awt::Point SAL_CALL getLocation (void);
183 
184     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen (void);
185 
186     virtual ::com::sun::star::awt::Size SAL_CALL getSize (void);
187 
188     virtual void SAL_CALL grabFocus (void);
189 
190     virtual sal_Int32 SAL_CALL getForeground (void);
191 
192     virtual sal_Int32 SAL_CALL getBackground (void);
193 
194 
195     //=====  XServiceInfo  ====================================================
196 
197     /** Returns an identifier for the implementation of this object.
198     */
199     virtual ::rtl::OUString SAL_CALL
200         getImplementationName (void);
201 
202     /** Return whether the specified service is supported by this class.
203     */
204     virtual sal_Bool SAL_CALL
205         supportsService (const ::rtl::OUString& sServiceName);
206 
207     /** Returns a list of all supported services.
208     */
209     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
210         getSupportedServiceNames (void);
211 
212 
213 protected:
214     ::com::sun::star::uno::Reference<
215         ::com::sun::star::accessibility::XAccessible> mxParent;
216     ::sd::toolpanel::TreeNode& mrTreeNode;
217     ::rtl::Reference< ::utl::AccessibleStateSetHelper> mrStateSet;
218 
219     const ::rtl::OUString msName;
220     const ::rtl::OUString msDescription;
221     const sal_Int16 meRole;
222 
223     virtual ~AccessibleTreeNode (void);
224 
225     /** Check whether or not the object has been disposed (or is in the
226         state of being disposed).  If that is the case then
227         DisposedException is thrown to inform the (indirect) caller of the
228         foul deed.
229     */
230     void ThrowIfDisposed (void);
231 
232     /** Check whether or not the object has been disposed (or is in the
233         state of being disposed).
234 
235         @return sal_True, if the object is disposed or in the course
236         of being disposed. Otherwise, sal_False is returned.
237     */
238     sal_Bool IsDisposed (void);
239 
240     /** Update the mpStateSet member to reflect the current state of the
241         TreeNode.  When one of the states has changed since the last call
242         then an appropriate event is sent.
243     */
244     virtual void UpdateStateSet (void);
245 
246     /** Update a single state and sent an event if its value changes.
247     */
248     void UpdateState(
249         sal_Int16 aState,
250         bool bValue);
251 
252     DECL_LINK(StateChangeListener, ::sd::toolpanel::TreeNodeStateChangeEvent*);
253     DECL_LINK(WindowEventListener, VclWindowEvent*);
254 
255 private:
256     sal_uInt32 mnClientId;
257 
258     /// The common part of the constructor.
259     void CommonConstructor (void);
260 };
261 
262 } // end of namespace ::accessibility
263 
264 #endif
265