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