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