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