Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / accmap.hxx
blobbf9dcd1c613aa59f2e0063beae0bbb4ff7c587cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SW_INC_ACCMAP_HXX
20 #define INCLUDED_SW_INC_ACCMAP_HXX
22 #include <cppuhelper/weakref.hxx>
23 #include <com/sun/star/accessibility/XAccessible.hpp>
24 #include <rtl/ref.hxx>
25 #include <osl/mutex.hxx>
26 #include <svx/IAccessibleViewForwarder.hxx>
27 #include <svx/IAccessibleParent.hxx>
28 #include <tools/fract.hxx>
30 #include <svx/AccessibleControlShape.hxx>
31 #include <svx/AccessibleShape.hxx>
32 #include "fesh.hxx"
33 #include <vector>
34 #include <set>
35 #include <o3tl/typed_flags_set.hxx>
37 class SwAccessibleParagraph;
38 class SwViewShell;
39 class Rectangle;
40 class SwFrm;
41 class SwTextFrm;
42 class SwPageFrm;
43 class SwAccessibleContext;
44 class SwAccessibleContextMap_Impl;
45 class SwAccessibleEventList_Impl;
46 class SwAccessibleEventMap_Impl;
47 class SwShapeList_Impl;
48 class SdrObject;
49 namespace accessibility { class AccessibleShape; }
50 class SwAccessibleShapeMap_Impl;
51 struct SwAccessibleEvent_Impl;
52 class SwAccessibleSelectedParas_Impl;
53 class SwRect;
54 class MapMode;
55 class SwAccPreviewData;
56 struct PreviewPage;
57 namespace vcl { class Window; }
59 enum class AccessibleStates
61 NONE = 0x0000,
62 // real states for events
63 EDITABLE = 0x0001,
64 OPAQUE = 0x0002,
65 // pseudo states for events
66 TEXT_ATTRIBUTE_CHANGED = 0x0200,
67 TEXT_SELECTION_CHANGED = 0x0100,
68 CARET = 0x0080,
69 RELATION_FROM = 0x0040,
70 RELATION_TO = 0x0020,
72 namespace o3tl
74 template<> struct typed_flags<AccessibleStates> : is_typed_flags<AccessibleStates, 0x3e3> {};
77 class SwAccessibleMap : public ::accessibility::IAccessibleViewForwarder,
78 public ::accessibility::IAccessibleParent
80 mutable ::osl::Mutex maMutex;
81 ::osl::Mutex maEventMutex;
82 SwAccessibleContextMap_Impl *mpFrmMap;
83 SwAccessibleShapeMap_Impl *mpShapeMap;
84 SwShapeList_Impl *mpShapes;
85 SwAccessibleEventList_Impl *mpEvents;
86 SwAccessibleEventMap_Impl *mpEventMap;
87 // #i27301 data structure to keep information about
88 // accessible paragraph, which have a selection.
89 SwAccessibleSelectedParas_Impl* mpSelectedParas;
90 SwViewShell *mpVSh;
91 /// for page preview: store preview data, VisArea, and mapping of
92 /// preview-to-display coordinates
93 SwAccPreviewData* mpPreview;
95 ::com::sun::star::uno::WeakReference < ::com::sun::star::accessibility::XAccessible > mxCursorContext;
97 sal_Int32 mnPara;
99 bool mbShapeSelected;
101 void FireEvent( const SwAccessibleEvent_Impl& rEvent );
103 void AppendEvent( const SwAccessibleEvent_Impl& rEvent );
105 void InvalidateCursorPosition(
106 const ::com::sun::star::uno::Reference<
107 ::com::sun::star::accessibility::XAccessible>& rAcc );
108 void DoInvalidateShapeSelection(bool bInvalidateFocusMode = false);
110 void InvalidateShapeSelection();
112 //mpSelectedFrmMap contains the old selected objects.
113 SwAccessibleContextMap_Impl *mpSeletedFrmMap;
114 //IvalidateShapeInParaSelection() method is responsible for the updating the selected states of the objects.
115 void InvalidateShapeInParaSelection();
117 void _InvalidateRelationSet( const SwFrm* pFrm, bool bFrom );
119 ::com::sun::star::uno::Reference<
120 ::com::sun::star::accessibility::XAccessible>
121 _GetDocumentView( bool bPagePreview );
123 /** method to build up a new data structure of the accessible paragraphs,
124 which have a selection
126 Important note: method has to used inside a mutual exclusive section
128 @author OD
130 SwAccessibleSelectedParas_Impl* _BuildSelectedParas();
132 public:
134 SwAccessibleMap( SwViewShell *pSh );
135 virtual ~SwAccessibleMap();
137 ::com::sun::star::uno::Reference<
138 ::com::sun::star::accessibility::XAccessible> GetDocumentView();
140 ::com::sun::star::uno::Reference<
141 ::com::sun::star::accessibility::XAccessible> GetDocumentPreview(
142 const std::vector<PreviewPage*>& _rPreviewPages,
143 const Fraction& _rScale,
144 const SwPageFrm* _pSelectedPageFrm,
145 const Size& _rPreviewWinSize );
147 ::rtl::Reference < SwAccessibleContext > GetContextImpl(
148 const SwFrm *pFrm,
149 bool bCreate = true );
150 ::com::sun::star::uno::Reference<
151 ::com::sun::star::accessibility::XAccessible> GetContext(
152 const SwFrm *pFrm,
153 bool bCreate = true );
155 ::rtl::Reference < ::accessibility::AccessibleShape > GetContextImpl(
156 const SdrObject *pObj,
157 SwAccessibleContext *pParentImpl,
158 bool bCreate = true );
159 ::com::sun::star::uno::Reference<
160 ::com::sun::star::accessibility::XAccessible> GetContext(
161 const SdrObject *pObj,
162 SwAccessibleContext *pParentImpl,
163 bool bCreate = true );
165 inline SwViewShell* GetShell() const
167 return mpVSh;
169 static bool IsInSameLevel(const SdrObject* pObj, const SwFEShell* pFESh);
170 void AddShapeContext(const SdrObject *pObj,
171 ::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xAccShape);
173 void AddGroupContext(const SdrObject *pParentObj,
174 ::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xAccParent);
175 void RemoveGroupContext(const SdrObject *pParentObj, ::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > xAccParent);
177 const SwRect& GetVisArea() const;
179 /** get size of a dedicated preview page
181 @author OD
183 @param _nPreviewPageNum
184 input parameter - physical page number of page visible in the page preview
186 @return an object of class <Size>
188 Size GetPreviewPageSize( sal_uInt16 _nPreviewPageNum ) const;
190 void RemoveContext( const SwFrm *pFrm );
191 void RemoveContext( const SdrObject *pObj );
193 // Dispose frame and its children if bRecursive is set
194 void Dispose( const SwFrm* pFrm,
195 const SdrObject* pObj,
196 vcl::Window* pWindow,
197 bool bRecursive = false );
199 void InvalidatePosOrSize( const SwFrm* pFrm,
200 const SdrObject* pObj,
201 vcl::Window* pWindow,
202 const SwRect& rOldFrm );
204 void InvalidateContent( const SwFrm *pFrm );
206 void InvalidateAttr( const SwTextFrm& rTextFrm );
208 void InvalidateCursorPosition( const SwFrm *pFrm );
209 void InvalidateFocus();
210 void SetCursorContext(
211 const ::rtl::Reference < SwAccessibleContext >& rCursorContext );
213 // Invalidate state of whole tree. If an action is open, this call
214 // is processed when the last action ends.
215 void InvalidateStates( AccessibleStates _nStates,
216 const SwFrm* _pFrm = 0 );
218 void InvalidateRelationSet( const SwFrm* pMaster, const SwFrm* pFollow );
220 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
222 @author OD
224 @param _rTextFrm
225 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
226 has to be invalidated.
228 @param _bFrom
229 input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
230 (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
232 void InvalidateParaFlowRelation( const SwTextFrm& _rTextFrm,
233 const bool _bFrom );
235 /** invalidation of text selection of a paragraph
237 @author OD
239 void InvalidateParaTextSelection( const SwTextFrm& _rTextFrm );
241 /** invalidation of text selection of all paragraphs
243 @author OD
245 void InvalidateTextSelectionOfAllParas();
247 sal_Int32 GetChildIndex( const SwFrm& rParentFrm,
248 vcl::Window& rChild ) const;
250 // update preview data (and fire events if necessary)
251 void UpdatePreview( const std::vector<PreviewPage*>& _rPreviewPages,
252 const Fraction& _rScale,
253 const SwPageFrm* _pSelectedPageFrm,
254 const Size& _rPreviewWinSize );
256 void InvalidatePreviewSelection( sal_uInt16 nSelPage );
257 bool IsPageSelected( const SwPageFrm *pPageFrm ) const;
259 void FireEvents();
261 // IAccessibleViewForwarder
263 virtual bool IsValid() const SAL_OVERRIDE;
264 virtual Rectangle GetVisibleArea() const SAL_OVERRIDE;
265 virtual Point LogicToPixel (const Point& rPoint) const SAL_OVERRIDE;
266 virtual Size LogicToPixel (const Size& rSize) const SAL_OVERRIDE;
267 virtual Point PixelToLogic (const Point& rPoint) const SAL_OVERRIDE;
268 virtual Size PixelToLogic (const Size& rSize) const SAL_OVERRIDE;
270 // IAccessibleParent
271 virtual bool ReplaceChild (
272 ::accessibility::AccessibleShape* pCurrentChild,
273 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& _rxShape,
274 const long _nIndex,
275 const ::accessibility::AccessibleShapeTreeInfo& _rShapeTreeInfo
276 ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
277 virtual ::accessibility::AccessibleControlShape* GetAccControlShapeFromModel
278 (::com::sun::star::beans::XPropertySet* pSet)
279 throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
280 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > GetAccessibleCaption (
281 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & xShape)
282 throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
284 // additional Core/Pixel conversions for internal use; also works
285 // for preview
286 Point PixelToCore (const Point& rPoint) const;
287 Rectangle CoreToPixel (const Rectangle& rRect) const;
289 private:
290 /** get mapping mode for LogicToPixel and PixelToLogic conversions
292 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
293 Method returns mapping mode of current output device and adjusts it,
294 if the shell is in page/print preview.
295 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
296 output device for mapping logic document positions to page preview window
297 positions and vice versa and doesn't take care to recover its changes.
299 @author OD
301 @param _rPoint
302 input parameter - constant reference to point to determine the mapping
303 mode adjustments for page/print preview.
305 @param _orMapMode
306 output parameter - reference to the mapping mode, which is determined
307 by the method
309 void GetMapMode( const Point& _rPoint,
310 MapMode& _orMapMode ) const;
311 public:
312 virtual bool IsDocumentSelAll() SAL_OVERRIDE;
314 ::com::sun::star::uno::WeakReference < ::com::sun::star::accessibility::XAccessible >
315 GetCursorContext() const { return mxCursorContext; }
317 //Para Container for InvalidateCursorPosition
318 typedef std::set< SwAccessibleParagraph* > SET_PARA;
319 SET_PARA m_setParaAdd;
320 SET_PARA m_setParaRemove;
322 #endif
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */