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::SwClientNotify. 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 ::osl::Mutex maEventMutex
;
93 std::unique_ptr
<SwAccessibleContextMap_Impl
> mpFrameMap
;
94 std::unique_ptr
<SwAccessibleShapeMap_Impl
> mpShapeMap
;
95 SwShapeList_Impl mvShapes
;
96 std::unique_ptr
<SwAccessibleEventList_Impl
> mpEvents
;
97 std::unique_ptr
<SwAccessibleEventMap_Impl
> mpEventMap
;
99 // Para Container for InvalidateCursorPosition
100 o3tl::sorted_vector
<SwAccessibleParagraph
*> m_setParaAdd
;
101 o3tl::sorted_vector
<SwAccessibleParagraph
*> m_setParaRemove
;
103 // #i27301 data structure to keep information about
104 // accessible paragraph, which have a selection.
105 std::unique_ptr
<SwAccessibleSelectedParas_Impl
> mpSelectedParas
;
107 /// for page preview: store preview data, VisArea, and mapping of
108 /// preview-to-display coordinates
109 std::unique_ptr
<SwAccPreviewData
> mpPreview
;
111 css::uno::WeakReference
< css::accessibility::XAccessible
> mxCursorContext
;
113 bool mbShapeSelected
;
115 void FireEvent( const SwAccessibleEvent_Impl
& rEvent
);
117 void AppendEvent( const SwAccessibleEvent_Impl
& rEvent
);
119 void InvalidateCursorPosition( const css::uno::Reference
<css::accessibility::XAccessible
>& rAcc
);
120 void DoInvalidateShapeSelection(bool bInvalidateFocusMode
= false);
122 void InvalidateShapeSelection();
124 //mpSelectedFrameMap contains the old selected objects.
125 std::unique_ptr
<SwAccessibleContextMap_Impl
> mpSelectedFrameMap
;
129 //InvalidateShapeInParaSelection() method is responsible for the updating the selected states of the objects.
130 void InvalidateShapeInParaSelection();
132 void InvalidateRelationSet_( const SwFrame
* pFrame
, bool bFrom
);
134 css::uno::Reference
<css::accessibility::XAccessible
>
135 GetDocumentView_( bool bPagePreview
);
137 /** method to build up a new data structure of the accessible paragraphs,
138 which have a selection
140 Important note: method has to used inside a mutual exclusive section
142 std::unique_ptr
<SwAccessibleSelectedParas_Impl
> BuildSelectedParas();
146 SwAccessibleMap( SwViewShell
*pSh
);
147 virtual ~SwAccessibleMap() override
;
149 css::uno::Reference
<css::accessibility::XAccessible
> GetDocumentView();
151 css::uno::Reference
<css::accessibility::XAccessible
> GetDocumentPreview(
152 const std::vector
<std::unique_ptr
<PreviewPage
>>& _rPreviewPages
,
153 const Fraction
& _rScale
,
154 const SwPageFrame
* _pSelectedPageFrame
,
155 const Size
& _rPreviewWinSize
);
157 ::rtl::Reference
< SwAccessibleContext
> GetContextImpl(
158 const SwFrame
*pFrame
,
159 bool bCreate
= true );
160 css::uno::Reference
<css::accessibility::XAccessible
> GetContext(
161 const SwFrame
*pFrame
,
162 bool bCreate
= true );
164 ::rtl::Reference
< ::accessibility::AccessibleShape
> GetContextImpl(
165 const SdrObject
*pObj
,
166 SwAccessibleContext
*pParentImpl
,
167 bool bCreate
= true );
168 css::uno::Reference
<css::accessibility::XAccessible
> GetContext(
169 const SdrObject
*pObj
,
170 SwAccessibleContext
*pParentImpl
,
171 bool bCreate
= true );
173 SwViewShell
* GetShell() const
177 static bool IsInSameLevel(const SdrObject
* pObj
, const SwFEShell
* pFESh
);
178 void AddShapeContext(const SdrObject
*pObj
,
179 css::uno::Reference
< css::accessibility::XAccessible
> const & xAccShape
);
181 void AddGroupContext(const SdrObject
*pParentObj
,
182 css::uno::Reference
< css::accessibility::XAccessible
> const & xAccParent
);
183 void RemoveGroupContext(const SdrObject
*pParentObj
);
185 const SwRect
& GetVisArea() const;
187 /** get size of a dedicated preview page
189 @param _nPreviewPageNum
190 input parameter - physical page number of page visible in the page preview
192 @return an object of class <Size>
194 Size
GetPreviewPageSize( sal_uInt16 _nPreviewPageNum
) const;
196 void RemoveContext( const SwFrame
*pFrame
);
197 void RemoveContext( const SdrObject
*pObj
);
199 // Dispose frame and its children if bRecursive is set
200 void A11yDispose( const SwFrame
* pFrame
,
201 const SdrObject
* pObj
,
202 vcl::Window
* pWindow
,
203 bool bRecursive
= false,
204 bool bCanSkipInvisible
= true );
206 void InvalidatePosOrSize( const SwFrame
* pFrame
,
207 const SdrObject
* pObj
,
208 vcl::Window
* pWindow
,
209 const SwRect
& rOldFrame
);
211 void InvalidateContent( const SwFrame
*pFrame
);
213 void InvalidateAttr( const SwTextFrame
& rTextFrame
);
215 void InvalidateCursorPosition( const SwFrame
*pFrame
);
216 void InvalidateFocus();
217 void SetCursorContext(
218 const ::rtl::Reference
< SwAccessibleContext
>& rCursorContext
);
220 // Invalidate state of whole tree. If an action is open, this call
221 // is processed when the last action ends.
222 void InvalidateEditableStates( const SwFrame
* _pFrame
);
224 void InvalidateRelationSet( const SwFrame
* pMaster
, const SwFrame
* pFollow
);
226 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
229 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
230 has to be invalidated.
233 input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
234 (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
236 void InvalidateParaFlowRelation( const SwTextFrame
& _rTextFrame
,
239 /** invalidation of text selection of a paragraph */
240 void InvalidateParaTextSelection( const SwTextFrame
& _rTextFrame
);
242 /** invalidation of text selection of all paragraphs */
243 void InvalidateTextSelectionOfAllParas();
245 sal_Int32
GetChildIndex( const SwFrame
& rParentFrame
,
246 vcl::Window
& rChild
) const;
248 // update preview data (and fire events if necessary)
249 void UpdatePreview( const std::vector
<std::unique_ptr
<PreviewPage
>>& _rPreviewPages
,
250 const Fraction
& _rScale
,
251 const SwPageFrame
* _pSelectedPageFrame
,
252 const Size
& _rPreviewWinSize
);
254 void InvalidatePreviewSelection( sal_uInt16 nSelPage
);
255 bool IsPageSelected( const SwPageFrame
*pPageFrame
) const;
259 const OUString
& GetDocName() const { return maDocName
; }
261 // IAccessibleViewForwarder
263 virtual tools::Rectangle
GetVisibleArea() const override
;
264 virtual Point
LogicToPixel (const Point
& rPoint
) const override
;
265 virtual Size
LogicToPixel (const Size
& rSize
) const override
;
268 virtual bool ReplaceChild (
269 ::accessibility::AccessibleShape
* pCurrentChild
,
270 const css::uno::Reference
< css::drawing::XShape
>& _rxShape
,
271 const tools::Long _nIndex
,
272 const ::accessibility::AccessibleShapeTreeInfo
& _rShapeTreeInfo
274 virtual ::accessibility::AccessibleControlShape
* GetAccControlShapeFromModel
275 (css::beans::XPropertySet
* pSet
) override
;
276 virtual css::uno::Reference
< css::accessibility::XAccessible
> GetAccessibleCaption (
277 const css::uno::Reference
< css::drawing::XShape
> & xShape
) override
;
279 // additional Core/Pixel conversions for internal use; also works
281 Point
PixelToCore (const Point
& rPoint
) const;
282 tools::Rectangle
CoreToPixel (const SwRect
& rRect
) const;
284 // is there a known accessibility impl cached for the frame
285 bool Contains(const SwFrame
*pFrame
) const;
288 /** get mapping mode for LogicToPixel and PixelToLogic conversions
290 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
291 Method returns mapping mode of current output device and adjusts it,
292 if the shell is in page/print preview.
293 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
294 output device for mapping logic document positions to page preview window
295 positions and vice versa and doesn't take care to recover its changes.
298 input parameter - constant reference to point to determine the mapping
299 mode adjustments for page/print preview.
302 output parameter - reference to the mapping mode, which is determined
305 void GetMapMode( const Point
& _rPoint
,
306 MapMode
& _orMapMode
) const;
308 virtual bool IsDocumentSelAll() override
;
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */