1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <rtl/ref.hxx>
24 #include <osl/mutex.hxx>
25 #include <svx/IAccessibleViewForwarder.hxx>
26 #include <svx/IAccessibleParent.hxx>
28 #include <svx/AccessibleControlShape.hxx>
29 #include <o3tl/typed_flags_set.hxx>
33 #include <o3tl/sorted_vector.hxx>
35 class SwAccessibleParagraph
;
40 class SwAccessibleContext
;
41 class SwAccessibleContextMap_Impl
;
42 class SwAccessibleEventList_Impl
;
43 class SwAccessibleEventMap_Impl
;
45 namespace accessibility
{ class AccessibleShape
; }
46 class SwAccessibleShapeMap_Impl
;
47 struct SwAccessibleEvent_Impl
;
48 class SwAccessibleSelectedParas_Impl
;
51 class SwAccPreviewData
;
55 namespace vcl
{ class Window
; }
56 namespace com::sun::star::accessibility
{ class XAccessible
; }
58 // The shape list is filled if an accessible shape is destroyed. It
59 // simply keeps a reference to the accessible shape's XShape. These
60 // references are destroyed within the EndAction when firing events.
61 // There are two reason for this. First of all, a new accessible shape
62 // for the XShape might be created soon. It's then cheaper if the XShape
63 // still exists. The other reason are situations where an accessible shape
64 // is destroyed within an SwFrameFormat::Modify. In this case, destroying
65 // the XShape at the same time (indirectly by destroying the accessible
66 // shape) leads to an assert, because a client of the Modify is destroyed
67 // within a Modify call.
68 using SwShapeList_Impl
= std::vector
<css::uno::Reference
<css::drawing::XShape
>>;
70 enum class AccessibleStates
73 // real states for events
76 // pseudo states for events
77 TEXT_ATTRIBUTE_CHANGED
= 0x0200,
78 TEXT_SELECTION_CHANGED
= 0x0100,
80 RELATION_FROM
= 0x0040,
85 template<> struct typed_flags
<AccessibleStates
> : is_typed_flags
<AccessibleStates
, 0x3e3> {};
88 class SwAccessibleMap final
: public ::accessibility::IAccessibleViewForwarder
,
89 public ::accessibility::IAccessibleParent
90 , public std::enable_shared_from_this
<SwAccessibleMap
>
92 mutable ::osl::Mutex maMutex
;
93 ::osl::Mutex maEventMutex
;
94 std::unique_ptr
<SwAccessibleContextMap_Impl
> mpFrameMap
;
95 std::unique_ptr
<SwAccessibleShapeMap_Impl
> mpShapeMap
;
96 SwShapeList_Impl mvShapes
;
97 std::unique_ptr
<SwAccessibleEventList_Impl
> mpEvents
;
98 std::unique_ptr
<SwAccessibleEventMap_Impl
> mpEventMap
;
99 // #i27301 data structure to keep information about
100 // accessible paragraph, which have a selection.
101 std::unique_ptr
<SwAccessibleSelectedParas_Impl
> mpSelectedParas
;
103 /// for page preview: store preview data, VisArea, and mapping of
104 /// preview-to-display coordinates
105 std::unique_ptr
<SwAccPreviewData
> mpPreview
;
107 css::uno::WeakReference
< css::accessibility::XAccessible
> mxCursorContext
;
109 bool mbShapeSelected
;
111 void FireEvent( const SwAccessibleEvent_Impl
& rEvent
);
113 void AppendEvent( const SwAccessibleEvent_Impl
& rEvent
);
115 void InvalidateCursorPosition( const css::uno::Reference
<css::accessibility::XAccessible
>& rAcc
);
116 void DoInvalidateShapeSelection(bool bInvalidateFocusMode
= false);
118 void InvalidateShapeSelection();
120 //mpSelectedFrameMap contains the old selected objects.
121 std::unique_ptr
<SwAccessibleContextMap_Impl
> mpSeletedFrameMap
;
125 //InvalidateShapeInParaSelection() method is responsible for the updating the selected states of the objects.
126 void InvalidateShapeInParaSelection();
128 void InvalidateRelationSet_( const SwFrame
* pFrame
, bool bFrom
);
130 css::uno::Reference
<css::accessibility::XAccessible
>
131 GetDocumentView_( bool bPagePreview
);
133 /** method to build up a new data structure of the accessible paragraphs,
134 which have a selection
136 Important note: method has to used inside a mutual exclusive section
138 std::unique_ptr
<SwAccessibleSelectedParas_Impl
> BuildSelectedParas();
142 SwAccessibleMap( SwViewShell
*pSh
);
143 virtual ~SwAccessibleMap() override
;
145 css::uno::Reference
<css::accessibility::XAccessible
> GetDocumentView();
147 css::uno::Reference
<css::accessibility::XAccessible
> GetDocumentPreview(
148 const std::vector
<std::unique_ptr
<PreviewPage
>>& _rPreviewPages
,
149 const Fraction
& _rScale
,
150 const SwPageFrame
* _pSelectedPageFrame
,
151 const Size
& _rPreviewWinSize
);
153 ::rtl::Reference
< SwAccessibleContext
> GetContextImpl(
154 const SwFrame
*pFrame
,
155 bool bCreate
= true );
156 css::uno::Reference
<css::accessibility::XAccessible
> GetContext(
157 const SwFrame
*pFrame
,
158 bool bCreate
= true );
160 ::rtl::Reference
< ::accessibility::AccessibleShape
> GetContextImpl(
161 const SdrObject
*pObj
,
162 SwAccessibleContext
*pParentImpl
,
163 bool bCreate
= true );
164 css::uno::Reference
<css::accessibility::XAccessible
> GetContext(
165 const SdrObject
*pObj
,
166 SwAccessibleContext
*pParentImpl
,
167 bool bCreate
= true );
169 SwViewShell
* GetShell() const
173 static bool IsInSameLevel(const SdrObject
* pObj
, const SwFEShell
* pFESh
);
174 void AddShapeContext(const SdrObject
*pObj
,
175 css::uno::Reference
< css::accessibility::XAccessible
> const & xAccShape
);
177 void AddGroupContext(const SdrObject
*pParentObj
,
178 css::uno::Reference
< css::accessibility::XAccessible
> const & xAccParent
);
179 void RemoveGroupContext(const SdrObject
*pParentObj
);
181 const SwRect
& GetVisArea() const;
183 /** get size of a dedicated preview page
185 @param _nPreviewPageNum
186 input parameter - physical page number of page visible in the page preview
188 @return an object of class <Size>
190 Size
GetPreviewPageSize( sal_uInt16 _nPreviewPageNum
) const;
192 void RemoveContext( const SwFrame
*pFrame
);
193 void RemoveContext( const SdrObject
*pObj
);
195 // Dispose frame and its children if bRecursive is set
196 void A11yDispose( const SwFrame
* pFrame
,
197 const SdrObject
* pObj
,
198 vcl::Window
* pWindow
,
199 bool bRecursive
= false,
200 bool bCanSkipInvisible
= true );
202 void InvalidatePosOrSize( const SwFrame
* pFrame
,
203 const SdrObject
* pObj
,
204 vcl::Window
* pWindow
,
205 const SwRect
& rOldFrame
);
207 void InvalidateContent( const SwFrame
*pFrame
);
209 void InvalidateAttr( const SwTextFrame
& rTextFrame
);
211 void InvalidateCursorPosition( const SwFrame
*pFrame
);
212 void InvalidateFocus();
213 void SetCursorContext(
214 const ::rtl::Reference
< SwAccessibleContext
>& rCursorContext
);
216 // Invalidate state of whole tree. If an action is open, this call
217 // is processed when the last action ends.
218 void InvalidateEditableStates( const SwFrame
* _pFrame
);
220 void InvalidateRelationSet( const SwFrame
* pMaster
, const SwFrame
* pFollow
);
222 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
225 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
226 has to be invalidated.
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 SwTextFrame
& _rTextFrame
,
235 /** invalidation of text selection of a paragraph */
236 void InvalidateParaTextSelection( const SwTextFrame
& _rTextFrame
);
238 /** invalidation of text selection of all paragraphs */
239 void InvalidateTextSelectionOfAllParas();
241 sal_Int32
GetChildIndex( const SwFrame
& rParentFrame
,
242 vcl::Window
& rChild
) const;
244 // update preview data (and fire events if necessary)
245 void UpdatePreview( const std::vector
<std::unique_ptr
<PreviewPage
>>& _rPreviewPages
,
246 const Fraction
& _rScale
,
247 const SwPageFrame
* _pSelectedPageFrame
,
248 const Size
& _rPreviewWinSize
);
250 void InvalidatePreviewSelection( sal_uInt16 nSelPage
);
251 bool IsPageSelected( const SwPageFrame
*pPageFrame
) const;
255 const OUString
& GetDocName() const { return maDocName
; }
257 // IAccessibleViewForwarder
259 virtual tools::Rectangle
GetVisibleArea() const override
;
260 virtual Point
LogicToPixel (const Point
& rPoint
) const override
;
261 virtual Size
LogicToPixel (const Size
& rSize
) const override
;
264 virtual bool ReplaceChild (
265 ::accessibility::AccessibleShape
* pCurrentChild
,
266 const css::uno::Reference
< css::drawing::XShape
>& _rxShape
,
267 const tools::Long _nIndex
,
268 const ::accessibility::AccessibleShapeTreeInfo
& _rShapeTreeInfo
270 virtual ::accessibility::AccessibleControlShape
* GetAccControlShapeFromModel
271 (css::beans::XPropertySet
* pSet
) override
;
272 virtual css::uno::Reference
< css::accessibility::XAccessible
> GetAccessibleCaption (
273 const css::uno::Reference
< css::drawing::XShape
> & xShape
) override
;
275 // additional Core/Pixel conversions for internal use; also works
277 Point
PixelToCore (const Point
& rPoint
) const;
278 tools::Rectangle
CoreToPixel (const tools::Rectangle
& rRect
) const;
280 // is there a known accessibility impl cached for the frame
281 bool Contains(const SwFrame
*pFrame
) const;
284 /** get mapping mode for LogicToPixel and PixelToLogic conversions
286 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
287 Method returns mapping mode of current output device and adjusts it,
288 if the shell is in page/print preview.
289 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
290 output device for mapping logic document positions to page preview window
291 positions and vice versa and doesn't take care to recover its changes.
294 input parameter - constant reference to point to determine the mapping
295 mode adjustments for page/print preview.
298 output parameter - reference to the mapping mode, which is determined
301 void GetMapMode( const Point
& _rPoint
,
302 MapMode
& _orMapMode
) const;
304 virtual bool IsDocumentSelAll() override
;
306 //Para Container for InvalidateCursorPosition
307 typedef o3tl::sorted_vector
< SwAccessibleParagraph
* > SET_PARA
;
308 SET_PARA m_setParaAdd
;
309 SET_PARA m_setParaRemove
;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */