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_DOCUMENT_VIEW_BASE_HXX
25 #define SD_ACCESSIBILITY_ACCESSIBLE_DOCUMENT_VIEW_BASE_HXX
26 
27 #include <editeng/AccessibleContextBase.hxx>
28 #include <editeng/AccessibleComponentBase.hxx>
29 #include <editeng/AccessibleSelectionBase.hxx>
30 #include "AccessibleViewForwarder.hxx"
31 #include "AccessiblePageShape.hxx"
32 #include <svx/ChildrenManager.hxx>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/awt/XWindowListener.hpp>
35 #include <com/sun/star/awt/XFocusListener.hpp>
36 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
37 #include <com/sun/star/accessibility/XAccessible.hpp>
38 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
39 #include <tools/link.hxx>
40 
41 namespace sd {
42 class ViewShell;
43 class Window;
44 }
45 
46 class VclSimpleEvent;
47 
48 namespace accessibility {
49 
50 
51 /** Base class for the various document views of the Draw and
52     Impress applications.
53 
54 	<p>The different view modes of the Draw and Impress applications
55 	are made accessible by derived classes.  When the view mode is
56 	changed than the object representing the document view is
57 	disposed and replaced by a new instance of the then appropriate
58 	derived class.</p>
59 
60     <p>This base class also manages an optionally active accessible OLE
61     object.  If you overwrite the <member>getAccessibleChildCount</member>
62     and <member>getAccessibleChild</member> methods then make sure to first
63     call the corresponding method of this class and adapt your child count
64     and indices accordingly.  Only one active OLE object is allowed at a
65     time.  This class does not listen for disposing calls at the moment
66     because it does not use the accessible OLE object directly and trusts on
67     getting informed through VCL window events.</p>
68 
69     <p>This class implements three kinds of listeners:
70     <ol><li>The property change listener is not used directly but exists as
71     convenience for derived classes.  May be moved to those classes
72     instead.</li>
73     <li>As window listener it waits for changes of the window geometry and
74     forwards those as view forwarder changes.</li>
75     <li>As focus listener it keeps track of the focus to give this class and
76     derived classes the oportunity to set and remove the focus to/from
77     shapes.</li>
78     </ol>
79     </p>
80 */
81 class AccessibleDocumentViewBase
82 	:	public AccessibleContextBase,
83         public AccessibleComponentBase,
84         public AccessibleSelectionBase,
85         public IAccessibleViewForwarderListener,
86         public ::com::sun::star::beans::XPropertyChangeListener,
87         public ::com::sun::star::awt::XWindowListener,
88         public ::com::sun::star::awt::XFocusListener
89 {
90 public:
91     //=====  internal  ========================================================
92 
93     /** Create a new object.  Note that the caller has to call the
94         Init method directly after this constructor has finished.
95 	@param pSdWindow
96 	    The window whose content is to be made accessible.
97 	@param pViewShell
98 	    The view shell associated with the given window.
99     @param rxController
100         The controller from which to get the model.
101     @param rxParent
102         The accessible parent of the new object.  Note that this parent does
103         not necessarily correspond with the parent of the given window.
104      */
105     AccessibleDocumentViewBase (
106         ::sd::Window* pSdWindow,
107         ::sd::ViewShell* pViewShell,
108         const ::com::sun::star::uno::Reference<
109             ::com::sun::star::frame::XController>& rxController,
110         const ::com::sun::star::uno::Reference<
111             ::com::sun::star::accessibility::XAccessible>& rxParent);
112 
113     virtual ~AccessibleDocumentViewBase	(void);
114 
115     /** Initialize a new object.  Call this method directly after creating a
116         new object.  It finished the initialization begun in the constructor
117         but which needs a fully created object.
118      */
119     virtual void Init (void);
120 
121     /** Define callback for listening to window child events of VCL.
122         Listen for creation or destruction of OLE objects.
123     */
124 	DECL_LINK (WindowChildEventListener, VclSimpleEvent*);
125 
126     //=====  IAccessibleViewForwarderListener  ================================
127 
128     /** A view forwarder change is signalled for instance when any of the
129         window events is recieved.  Thus, instead of overloading the four
130         windowResized... methods it will be sufficient in most cases just to
131         overload this method.
132      */
133     virtual void ViewForwarderChanged (ChangeType aChangeType,
134         const IAccessibleViewForwarder* pViewForwarder);
135 
136     //=====  XAccessibleContext  ==============================================
137 
138     virtual ::com::sun::star::uno::Reference<
139         ::com::sun::star::accessibility::XAccessible> SAL_CALL
140         getAccessibleParent (void)
141         throw (::com::sun::star::uno::RuntimeException);
142 
143     /** This implementation returns either 1 or 0 depending on whether there
144         is an active accessible OLE object or not.
145     */
146     virtual sal_Int32 SAL_CALL
147         getAccessibleChildCount (void)
148         throw (::com::sun::star::uno::RuntimeException);
149 
150     /** This implementation either returns the active accessible OLE object
151         if it exists and the given index is 0 or throws an exception.
152     */
153     virtual ::com::sun::star::uno::Reference<
154         ::com::sun::star::accessibility::XAccessible> SAL_CALL
155         getAccessibleChild (sal_Int32 nIndex)
156         throw (::com::sun::star::uno::RuntimeException,
157             ::com::sun::star::lang::IndexOutOfBoundsException);
158 
159 
160     //=====  XAccessibleComponent  ============================================
161 
162     virtual ::com::sun::star::uno::Reference<
163         ::com::sun::star::accessibility::XAccessible > SAL_CALL
164         getAccessibleAtPoint (const ::com::sun::star::awt::Point& aPoint)
165         throw (::com::sun::star::uno::RuntimeException);
166 
167     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds (void)
168         throw (::com::sun::star::uno::RuntimeException);
169 
170     virtual ::com::sun::star::awt::Point SAL_CALL getLocation (void)
171         throw (::com::sun::star::uno::RuntimeException);
172 
173     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen (void)
174         throw (::com::sun::star::uno::RuntimeException);
175 
176     virtual ::com::sun::star::awt::Size SAL_CALL getSize (void)
177         throw (::com::sun::star::uno::RuntimeException);
178 
179 
180     //=====  XInterface  ======================================================
181 
182     virtual com::sun::star::uno::Any SAL_CALL
183         queryInterface (const com::sun::star::uno::Type & rType)
184         throw (::com::sun::star::uno::RuntimeException);
185 
186     virtual void SAL_CALL
187         acquire (void)
188         throw ();
189 
190     virtual void SAL_CALL
191         release (void)
192         throw ();
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 	    throw (::com::sun::star::uno::RuntimeException);
202 
203     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
204         getSupportedServiceNames (void)
205         throw (::com::sun::star::uno::RuntimeException);
206 
207 
208     //=====  XTypeProvider  ===================================================
209 
210     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL
211         getTypes (void)
212         throw (::com::sun::star::uno::RuntimeException);
213 
214 
215     //=====  lang::XEventListener  ============================================
216 
217     virtual void SAL_CALL
218         disposing (const ::com::sun::star::lang::EventObject& rEventObject)
219         throw (::com::sun::star::uno::RuntimeException);
220 
221 
222     //=====  XPropertyChangeListener  =========================================
223 
224 	virtual void SAL_CALL
225 		propertyChange (const ::com::sun::star::beans::PropertyChangeEvent& rEventObject)
226         throw (::com::sun::star::uno::RuntimeException);
227 
228 
229     //=====  XWindowListener  =================================================
230 
231     virtual void SAL_CALL
232         windowResized (const ::com::sun::star::awt::WindowEvent& e)
233         throw (::com::sun::star::uno::RuntimeException);
234 
235     virtual void SAL_CALL
236         windowMoved (const ::com::sun::star::awt::WindowEvent& e)
237         throw (::com::sun::star::uno::RuntimeException);
238 
239     virtual void SAL_CALL
240         windowShown (const ::com::sun::star::lang::EventObject& e)
241         throw (::com::sun::star::uno::RuntimeException);
242 
243     virtual void SAL_CALL
244         windowHidden (const ::com::sun::star::lang::EventObject& e)
245         throw (::com::sun::star::uno::RuntimeException);
246 
247     //=====  XFocusListener  =================================================
248 
249 	virtual void SAL_CALL focusGained (const ::com::sun::star::awt::FocusEvent& e)
250         throw (::com::sun::star::uno::RuntimeException);
251 	virtual void SAL_CALL focusLost (const ::com::sun::star::awt::FocusEvent& e)
252         throw (::com::sun::star::uno::RuntimeException);
253 
254 private:
255 
256     // return the member maMutex;
257     virtual ::osl::Mutex&
258         implGetMutex();
259 
260 	// return ourself as context in default case
261     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >
262         implGetAccessibleContext()
263         throw ( ::com::sun::star::uno::RuntimeException );
264 
265     // return sal_False in default case
266 	virtual sal_Bool
267         implIsSelected( sal_Int32 nAccessibleChildIndex )
268         throw (::com::sun::star::uno::RuntimeException);
269 
270     // return nothing in default case
271     virtual void
272         implSelect( sal_Int32 nAccessibleChildIndex, sal_Bool bSelect )
273         throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
274 
275 protected:
276     /// The core window that is made accessible.
277     ::sd::Window* mpWindow;
278 
279     /// The API window that is made accessible.
280     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow>
281          mxWindow;
282 
283     /// The controller of the window in which this view is displayed.
284     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController>
285          mxController;
286 
287     /// Model of the document.
288     ::com::sun::star::uno::Reference < ::com::sun::star::frame::XModel>
289         mxModel;
290 
291     // Bundle of information that is passed down the shape tree.
292     AccessibleShapeTreeInfo maShapeTreeInfo;
293 
294     /// The view forwarder passed to the children manager.
295     AccessibleViewForwarder maViewForwarder;
296 
297     /** Accessible OLE object.  Set or removed by the
298         <member>SetAccessibleOLEObject</member> method.
299     */
300     ::com::sun::star::uno::Reference <
301         ::com::sun::star::accessibility::XAccessible>
302         mxAccessibleOLEObject;
303 
304     Link maWindowLink;
305 
306     // This method is called from the component helper base class while
307     // disposing.
308     virtual void SAL_CALL disposing (void);
309 
310     /**	Create a name string.  The current name is not modified and,
311         therefore, no events are send.  This method is usually called once
312         by the <member>getAccessibleName</member> method of the base class.
313         @return
314            A name string.
315     */
316     virtual ::rtl::OUString
317     	CreateAccessibleName ()
318         throw (::com::sun::star::uno::RuntimeException);
319 
320     /**	Create a description string.  The current description is not
321         modified and, therefore, no events are send.  This method is usually
322         called once by the <member>getAccessibleDescription</member> method
323         of the base class.
324         @return
325            A description string.
326     */
327     virtual ::rtl::OUString
328     	CreateAccessibleDescription ()
329         throw (::com::sun::star::uno::RuntimeException);
330 
331     /** This method is called when (after) the frame containing this
332         document has been activated.  Can be used to send FOCUSED state
333         changes for the currently selected element.
334 
335         Note: Currently used as a substitute for FocusGained.  Should be
336         renamed in the future.
337     */
338     virtual void Activated (void);
339 
340     /** This method is called when (before or after?) the frame containing
341         this document has been deactivated.  Can be used to send FOCUSED
342         state changes for the currently selected element.
343 
344         Note: Currently used as a substitute for FocusLost.  Should be
345         renamed in the future.
346     */
347     virtual void Deactivated (void);
348 
349     /** Set or remove the currently active accessible OLE object.
350         @param xOLEObject
351             If this is a valid reference then a child event is send that
352             informs the listeners of a new child.  If there has already been
353             an active accessible OLE object then this is removed first and
354             appropriate events are send.
355 
356             If this is an empty reference then the currently active
357             accessible OLE object (if there is one) is removed.
358     */
359     virtual void SetAccessibleOLEObject (
360         const ::com::sun::star::uno::Reference <
361         ::com::sun::star::accessibility::XAccessible>& xOLEObject);
362 
363     virtual void impl_dispose (void);
364 };
365 
366 } // end of namespace accessibility
367 
368 #endif
369