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 .
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>
37 class SwAccessibleContext
;
38 class SwAccessibleContextMap_Impl
;
39 class SwAccessibleEventList_Impl
;
40 class SwAccessibleEventMap_Impl
;
41 class SwShapeList_Impl
;
43 namespace accessibility
{
44 class AccessibleShape
;
46 class SwAccessibleShapeMap_Impl
;
47 struct SwAccessibleEvent_Impl
;
48 class SwAccessibleSelectedParas_Impl
;
51 class SwAccPreviewData
;
55 // real states for events
56 #define ACC_STATE_EDITABLE 0x01
57 #define ACC_STATE_OPAQUE 0x02
59 // pseudo states for events
60 #define ACC_STATE_TEXT_ATTRIBUTE_CHANGED 0x0200
61 #define ACC_STATE_TEXT_SELECTION_CHANGED 0x0100
62 #define ACC_STATE_CARET 0x80
63 #define ACC_STATE_RELATION_FROM 0x40
64 #define ACC_STATE_RELATION_TO 0x20
66 #define ACC_STATE_RELATION_MASK 0x60
68 #define ACC_STATE_MASK 0x1F
70 typedef sal_uInt16 tAccessibleStates
;
72 class SwAccessibleMap
: public accessibility::IAccessibleViewForwarder
,
73 public accessibility::IAccessibleParent
75 mutable ::osl::Mutex maMutex
;
76 ::osl::Mutex maEventMutex
;
77 SwAccessibleContextMap_Impl
*mpFrmMap
;
78 SwAccessibleShapeMap_Impl
*mpShapeMap
;
79 SwShapeList_Impl
*mpShapes
;
80 SwAccessibleEventList_Impl
*mpEvents
;
81 SwAccessibleEventMap_Impl
*mpEventMap
;
82 // #i27301 data structure to keep information about
83 // accessible paragraph, which have a selection.
84 SwAccessibleSelectedParas_Impl
* mpSelectedParas
;
86 /// for page preview: store preview data, VisArea, and mapping of
87 /// preview-to-display coordinates
88 SwAccPreviewData
* mpPreview
;
90 ::com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
> mxCursorContext
;
99 void FireEvent( const SwAccessibleEvent_Impl
& rEvent
);
101 void AppendEvent( const SwAccessibleEvent_Impl
& rEvent
);
103 void InvalidateCursorPosition(
104 const ::com::sun::star::uno::Reference
<
105 ::com::sun::star::accessibility::XAccessible
>& rAcc
);
106 void DoInvalidateShapeSelection();
107 void DoInvalidateShapeFocus();
108 void InvalidateShapeSelection();
110 void _InvalidateRelationSet( const SwFrm
* pFrm
, bool bFrom
);
112 ::com::sun::star::uno::Reference
<
113 ::com::sun::star::accessibility::XAccessible
>
114 _GetDocumentView( bool bPagePreview
);
116 /** method to build up a new data structure of the accessible pararaphs,
117 which have a selection
119 Important note: method has to used inside a mutual exclusive section
123 SwAccessibleSelectedParas_Impl
* _BuildSelectedParas();
127 SwAccessibleMap( ViewShell
*pSh
);
130 ::com::sun::star::uno::Reference
<
131 ::com::sun::star::accessibility::XAccessible
> GetDocumentView();
133 ::com::sun::star::uno::Reference
<
134 ::com::sun::star::accessibility::XAccessible
> GetDocumentPreview(
135 const std::vector
<PrevwPage
*>& _rPrevwPages
,
136 const Fraction
& _rScale
,
137 const SwPageFrm
* _pSelectedPageFrm
,
138 const Size
& _rPrevwWinSize
);
140 ::rtl::Reference
< SwAccessibleContext
> GetContextImpl(
142 sal_Bool bCreate
= sal_True
);
143 ::com::sun::star::uno::Reference
<
144 ::com::sun::star::accessibility::XAccessible
> GetContext(
146 sal_Bool bCreate
= sal_True
);
148 ::rtl::Reference
< ::accessibility::AccessibleShape
> GetContextImpl(
149 const SdrObject
*pObj
,
150 SwAccessibleContext
*pParentImpl
,
151 sal_Bool bCreate
= sal_True
);
152 ::com::sun::star::uno::Reference
<
153 ::com::sun::star::accessibility::XAccessible
> GetContext(
154 const SdrObject
*pObj
,
155 SwAccessibleContext
*pParentImpl
,
156 sal_Bool bCreate
= sal_True
);
158 inline ViewShell
* GetShell() const
163 const SwRect
& GetVisArea() const;
165 /** get size of a dedicated preview page
169 @param _nPrevwPageNum
170 input parameter - physical page number of page visible in the page preview
172 @return an object of class <Size>
174 Size
GetPreViewPageSize( sal_uInt16 _nPrevwPageNum
) const;
176 void RemoveContext( const SwFrm
*pFrm
);
177 void RemoveContext( const SdrObject
*pObj
);
179 // Dispose frame and its children if bRecursive is set
180 void Dispose( const SwFrm
* pFrm
,
181 const SdrObject
* pObj
,
183 sal_Bool bRecursive
= sal_False
);
185 void InvalidatePosOrSize( const SwFrm
* pFrm
,
186 const SdrObject
* pObj
,
188 const SwRect
& rOldFrm
);
190 void InvalidateContent( const SwFrm
*pFrm
);
192 void InvalidateAttr( const SwTxtFrm
& rTxtFrm
);
194 void InvalidateCursorPosition( const SwFrm
*pFrm
);
195 void InvalidateFocus();
197 void SetCursorContext(
198 const ::rtl::Reference
< SwAccessibleContext
>& rCursorContext
);
200 // Invalidate state of whole tree. If an action is open, this call
201 // is processed when the last action ends.
202 void InvalidateStates( tAccessibleStates _nStates
,
203 const SwFrm
* _pFrm
= 0 );
205 void InvalidateRelationSet( const SwFrm
* pMaster
, const SwFrm
* pFollow
);
207 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
212 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
213 has to be invalidated.
216 input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
217 (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
219 void InvalidateParaFlowRelation( const SwTxtFrm
& _rTxtFrm
,
222 /** invalidation of text selection of a paragraph
226 void InvalidateParaTextSelection( const SwTxtFrm
& _rTxtFrm
);
228 /** invalidation of text selection of all paragraphs
232 void InvalidateTextSelectionOfAllParas();
234 sal_Int32
GetChildIndex( const SwFrm
& rParentFrm
,
235 Window
& rChild
) const;
237 // update preview data (and fire events if necessary)
238 void UpdatePreview( const std::vector
<PrevwPage
*>& _rPrevwPages
,
239 const Fraction
& _rScale
,
240 const SwPageFrm
* _pSelectedPageFrm
,
241 const Size
& _rPrevwWinSize
);
243 void InvalidatePreViewSelection( sal_uInt16 nSelPage
);
244 bool IsPageSelected( const SwPageFrm
*pPageFrm
) const;
249 // IAccessibleViewForwarder
251 virtual sal_Bool
IsValid() const;
252 virtual Rectangle
GetVisibleArea() const;
253 virtual Point
LogicToPixel (const Point
& rPoint
) const;
254 virtual Size
LogicToPixel (const Size
& rSize
) const;
255 virtual Point
PixelToLogic (const Point
& rPoint
) const;
256 virtual Size
PixelToLogic (const Size
& rSize
) const;
259 virtual sal_Bool
ReplaceChild (
260 ::accessibility::AccessibleShape
* pCurrentChild
,
261 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>& _rxShape
,
263 const ::accessibility::AccessibleShapeTreeInfo
& _rShapeTreeInfo
264 ) throw (::com::sun::star::uno::RuntimeException
);
266 // additional Core/Pixel conversions for internal use; also works
268 Point
PixelToCore (const Point
& rPoint
) const;
269 Rectangle
CoreToPixel (const Rectangle
& rRect
) const;
272 /** get mapping mode for LogicToPixel and PixelToLogic conversions
274 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
275 Method returns mapping mode of current output device and adjusts it,
276 if the shell is in page/print preview.
277 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
278 output device for mapping logic document positions to page preview window
279 positions and vice versa and doesn't take care to recover its changes.
284 input parameter - constant reference to point to determine the mapping
285 mode adjustments for page/print preview.
288 output parameter - reference to the mapping mode, which is determined
291 void GetMapMode( const Point
& _rPoint
,
292 MapMode
& _orMapMode
) const;
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */