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