xref: /aoo41x/main/sw/inc/accmap.hxx (revision cdf0e10c)
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 #ifndef _ACCMAP_HXX
28 #define _ACCMAP_HXX
29 
30 #include <cppuhelper/weakref.hxx>
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 #include <vos/ref.hxx>
33 #include <vos/mutex.hxx>
34 #include <svx/IAccessibleViewForwarder.hxx>
35 #include <svx/IAccessibleParent.hxx>
36 #include <tools/debug.hxx>
37 #include <tools/fract.hxx>
38 
39 #include <vector>
40 
41 class ViewShell;
42 class Rectangle;
43 class SwFrm;
44 class SwTxtFrm;
45 class SwPageFrm;
46 class SwAccessibleContext;
47 class SwAccessibleContextMap_Impl;
48 class SwAccessibleEventList_Impl;
49 class SwAccessibleEventMap_Impl;
50 class SwShapeList_Impl;
51 class SdrObject;
52 namespace accessibility {
53     class AccessibleShape;
54 }
55 class SwAccessibleShapeMap_Impl;
56 struct SwAccessibleEvent_Impl;
57 class SwAccessibleSelectedParas_Impl;
58 class SwRect;
59 class MapMode;
60 class SwAccPreviewData;
61 struct PrevwPage;
62 class Window;
63 
64 // real states for events
65 #define ACC_STATE_EDITABLE 0x01
66 #define ACC_STATE_OPAQUE 0x02
67 
68 // pseudo states for events
69 // --> OD 2009-01-07 #i88069# - pseudo state for event TEXT_ATTRIBUTE_CHANGED
70 #define ACC_STATE_TEXT_ATTRIBUTE_CHANGED 0x0200
71 // <--
72 // --> OD 2005-12-12 #i27301# - pseudo state for event TEXT_SELECTION_CHANGED
73 #define ACC_STATE_TEXT_SELECTION_CHANGED 0x0100
74 // <--
75 #define ACC_STATE_CARET 0x80
76 #define ACC_STATE_RELATION_FROM 0x40
77 #define ACC_STATE_RELATION_TO 0x20
78 
79 #define ACC_STATE_RELATION_MASK 0x60
80 
81 #define ACC_STATE_MASK 0x1F
82 
83 // --> OD 2005-12-12 #i27301# - introduce type definition of states
84 typedef sal_uInt16 tAccessibleStates;
85 // <--
86 
87 class SwAccessibleMap : public accessibility::IAccessibleViewForwarder,
88 						public accessibility::IAccessibleParent
89 {
90     mutable ::vos::OMutex maMutex;
91 	::vos::OMutex maEventMutex;
92 	SwAccessibleContextMap_Impl *mpFrmMap;
93 	SwAccessibleShapeMap_Impl *mpShapeMap;
94 	SwShapeList_Impl *mpShapes;
95 	SwAccessibleEventList_Impl *mpEvents;
96 	SwAccessibleEventMap_Impl *mpEventMap;
97     // --> OD 2005-12-13 #i27301# - data structure to keep information about
98     // accessible paragraph, which have a selection.
99     SwAccessibleSelectedParas_Impl* mpSelectedParas;
100     // <--
101     ViewShell *mpVSh;
102     /// for page preview: store preview data, VisArea, and mapping of
103     /// preview-to-display coordinates
104     SwAccPreviewData* mpPreview;
105 
106 	::com::sun::star::uno::WeakReference < ::com::sun::star::accessibility::XAccessible > mxCursorContext;
107 
108 	sal_Int32 mnPara;
109 	sal_Int32 mnFootnote;
110 	sal_Int32 mnEndnote;
111 
112 
113 	sal_Bool mbShapeSelected;
114 
115 	void FireEvent( const SwAccessibleEvent_Impl& rEvent );
116 
117 	void AppendEvent( const SwAccessibleEvent_Impl& rEvent );
118 
119 	void InvalidateCursorPosition(
120 		const ::com::sun::star::uno::Reference<
121 			::com::sun::star::accessibility::XAccessible>& rAcc );
122 	void DoInvalidateShapeSelection();
123 	void DoInvalidateShapeFocus();
124 	void InvalidateShapeSelection();
125 
126     void _InvalidateRelationSet( const SwFrm* pFrm, sal_Bool bFrom );
127 
128 	::com::sun::star::uno::Reference<
129 		::com::sun::star::accessibility::XAccessible>
130             _GetDocumentView( sal_Bool bPagePreview );
131 
132     /** method to build up a new data structure of the accessible pararaphs,
133         which have a selection
134 
135         OD 2005-12-13 #i27301#
136         Important note: method has to used inside a mutual exclusive section
137 
138         @author OD
139     */
140     SwAccessibleSelectedParas_Impl* _BuildSelectedParas();
141 
142 public:
143 
144 	SwAccessibleMap( ViewShell *pSh );
145 	~SwAccessibleMap();
146 
147 	::com::sun::star::uno::Reference<
148 		::com::sun::star::accessibility::XAccessible> GetDocumentView();
149 
150     // OD 15.01.2003 #103492# - complete re-factoring of method due to new
151     // page/print preview functionality.
152     ::com::sun::star::uno::Reference<
153         ::com::sun::star::accessibility::XAccessible> GetDocumentPreview(
154                             const std::vector<PrevwPage*>& _rPrevwPages,
155                             const Fraction&  _rScale,
156                             const SwPageFrm* _pSelectedPageFrm,
157                             const Size&      _rPrevwWinSize );
158 
159 	::vos::ORef < SwAccessibleContext > GetContextImpl(
160 									 			const SwFrm *pFrm,
161 												sal_Bool bCreate = sal_True );
162 	::com::sun::star::uno::Reference<
163 		::com::sun::star::accessibility::XAccessible> GetContext(
164 									 			const SwFrm *pFrm,
165 												sal_Bool bCreate = sal_True );
166 
167 	::vos::ORef < ::accessibility::AccessibleShape > GetContextImpl(
168 										const SdrObject *pObj,
169 										SwAccessibleContext *pParentImpl,
170 										sal_Bool bCreate = sal_True );
171 	::com::sun::star::uno::Reference<
172 		::com::sun::star::accessibility::XAccessible> GetContext(
173 										const SdrObject *pObj,
174 										SwAccessibleContext *pParentImpl,
175 										sal_Bool bCreate = sal_True );
176 
177     inline ViewShell* GetShell() const
178     {
179         return mpVSh;
180     }
181 
182     const SwRect& GetVisArea() const;
183 
184     /** get size of a dedicated preview page
185 
186         OD 15.01.2003 #103492#
187         complete re-factoring of previous method due to new page/print preview
188         functionality.
189 
190         @author OD
191 
192         @param _nPrevwPageNum
193         input parameter - physical page number of page visible in the page preview
194 
195         @return an object of class <Size>
196     */
197     Size GetPreViewPageSize( sal_uInt16 _nPrevwPageNum ) const;
198 
199 	void RemoveContext( const SwFrm *pFrm );
200 	void RemoveContext( const SdrObject *pObj );
201 
202 	// Dispose frame and its children if bRecursive is set
203     void Dispose( const SwFrm* pFrm,
204                   const SdrObject* pObj,
205                   Window* pWindow,
206                   sal_Bool bRecursive = sal_False );
207 
208     void InvalidatePosOrSize( const SwFrm* pFrm,
209                               const SdrObject* pObj,
210                               Window* pWindow,
211 							  const SwRect& rOldFrm );
212 
213 	void InvalidateContent( const SwFrm *pFrm );
214 
215     // --> OD 2009-01-06 #i88069#
216     void InvalidateAttr( const SwTxtFrm& rTxtFrm );
217     // <--
218 
219 	void InvalidateCursorPosition( const SwFrm *pFrm );
220 	void InvalidateFocus();
221 
222 	void SetCursorContext(
223 		const ::vos::ORef < SwAccessibleContext >& rCursorContext );
224 
225 	// Invalidate state of whole tree. If an action is open, this call
226 	// is processed when the last action ends.
227     // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
228     void InvalidateStates( tAccessibleStates _nStates,
229                            const SwFrm* _pFrm = 0 );
230 
231     void InvalidateRelationSet( const SwFrm* pMaster, const SwFrm* pFollow );
232 
233     /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
234 
235         OD 2005-12-01 #i27138#
236 
237         @author OD
238 
239         @param _rTxtFrm
240         input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
241         has to be invalidated.
242 
243         @param _bFrom
244         input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
245         (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
246     */
247     void InvalidateParaFlowRelation( const SwTxtFrm& _rTxtFrm,
248                                      const bool _bFrom );
249 
250     /** invalidation of text selection of a paragraph
251 
252         OD 2005-12-12 #i27301#
253 
254         @author OD
255     */
256     void InvalidateParaTextSelection( const SwTxtFrm& _rTxtFrm );
257 
258     /** invalidation of text selection of all paragraphs
259 
260         OD 2005-12-13 #i27301#
261 
262         @author OD
263     */
264     void InvalidateTextSelectionOfAllParas();
265 
266     sal_Int32 GetChildIndex( const SwFrm& rParentFrm,
267                              Window& rChild ) const;
268 
269     // update preview data (and fire events if necessary)
270     // OD 15.01.2003 #103492# - complete re-factoring of method due to new
271     // page/print preview functionality.
272     void UpdatePreview( const std::vector<PrevwPage*>& _rPrevwPages,
273                         const Fraction&  _rScale,
274                         const SwPageFrm* _pSelectedPageFrm,
275                         const Size&      _rPrevwWinSize );
276 
277     void InvalidatePreViewSelection( sal_uInt16 nSelPage );
278 	sal_Bool IsPageSelected( const SwPageFrm *pPageFrm ) const;
279 
280 	void FireEvents();
281 
282 
283 	// IAccessibleViewForwarder
284 
285 	virtual sal_Bool IsValid() const;
286     virtual Rectangle GetVisibleArea() const;
287     virtual Point LogicToPixel (const Point& rPoint) const;
288     virtual Size LogicToPixel (const Size& rSize) const;
289     virtual Point PixelToLogic (const Point& rPoint) const;
290     virtual Size PixelToLogic (const Size& rSize) const;
291 
292 	// IAccessibleParent
293     virtual sal_Bool ReplaceChild (
294         ::accessibility::AccessibleShape* pCurrentChild,
295 		const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
296 		const long _nIndex,
297 		const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo
298 	)	throw (::com::sun::star::uno::RuntimeException);
299 
300     // additional Core/Pixel conversions for internal use; also works
301     // for preview
302     Point PixelToCore (const Point& rPoint) const;
303     Rectangle CoreToPixel (const Rectangle& rRect) const;
304 
305 private:
306     /** get mapping mode for LogicToPixel and PixelToLogic conversions
307 
308         OD 15.01.2003 #103492#
309         Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
310         Method returns mapping mode of current output device and adjusts it,
311         if the shell is in page/print preview.
312         Necessary, because <PreviewAdjust(..)> changes mapping mode at current
313         output device for mapping logic document positions to page preview window
314         positions and vice versa and doesn't take care to recover its changes.
315 
316         @author OD
317 
318         @param _rPoint
319         input parameter - constant reference to point to determine the mapping
320         mode adjustments for page/print preview.
321 
322         @param _orMapMode
323         output parameter - reference to the mapping mode, which is determined
324         by the method
325     */
326     void GetMapMode( const Point& _rPoint,
327                      MapMode&     _orMapMode ) const;
328 };
329 #endif
330