1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accmap.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <cppuhelper/weakref.hxx>
34 #include <com/sun/star/accessibility/XAccessible.hpp>
35 #include <vos/ref.hxx>
36 #include <vos/mutex.hxx>
37 #include <svx/IAccessibleViewForwarder.hxx>
38 #include <svx/IAccessibleParent.hxx>
40 #include <tools/debug.hxx>
41 #include <tools/fract.hxx>
48 class SwAccessibleContext
;
49 class SwAccessibleContextMap_Impl
;
50 class SwAccessibleEventList_Impl
;
51 class SwAccessibleEventMap_Impl
;
52 class SwShapeList_Impl
;
54 namespace accessibility
{ class AccessibleShape
; }
55 class SwAccessibleShapeMap_Impl
;
56 struct SwAccessibleEvent_Impl
;
57 // --> OD 2005-12-13 #i27301#
58 class SwAccessibleSelectedParas_Impl
;
62 class SwAccPreviewData
;
63 // OD 14.01.2003 #103492#
64 #ifndef _PREVWPAGE_HXX
65 #include <prevwpage.hxx>
68 // helper class that stores preview data
69 class SwAccPreviewData
71 typedef std::vector
<Rectangle
> Rectangles
;
72 Rectangles maPreviewRects
;
73 Rectangles maLogicRects
;
78 const SwPageFrm
*mpSelPage
;
80 /** adjust logic page retangle to its visible part
82 OD 17.01.2003 #103492#
86 @param _iorLogicPgSwRect
87 input/output parameter - reference to the logic page rectangle, which
90 @param _rPrevwPgSwRect
91 input parameter - constant reference to the corresponding preview page
92 rectangle; needed to determine the visible part of the logic page rectangle.
95 input paramter - constant reference to the preview window size in TWIP;
96 needed to determine the visible part of the logic page rectangle
98 void AdjustLogicPgRectToVisibleArea( SwRect
& _iorLogicPgSwRect
,
99 const SwRect
& _rPrevwPgSwRect
,
100 const Size
& _rPrevwWinSize
);
106 // OD 14.01.2003 #103492# - complete re-factoring of method due to new
107 // page/print preview functionality.
108 void Update( const std::vector
<PrevwPage
*>& _rPrevwPages
,
109 const Fraction
& _rScale
,
110 const SwPageFrm
* _pSelectedPageFrm
,
111 const Size
& _rPrevwWinSize
);
113 // OD 14.01.2003 #103492# - complete re-factoring of method due to new
114 // page/print preview functionality.
115 void InvalidateSelection( const SwPageFrm
* _pSelectedPageFrm
);
117 const SwRect
& GetVisArea() const;
119 MapMode
GetMapModeForPreview( ) const;
121 /** Adjust the MapMode so that the preview page appears at the
122 * proper position. rPoint identifies the page for which the
123 * MapMode should be adjusted. If bFromPreview is true, rPoint is
124 * a preview coordinate; else it's a document coordinate. */
125 // OD 17.01.2003 #103492# - delete unused 3rd parameter.
126 void AdjustMapMode( MapMode
& rMapMode
,
127 const Point
& rPoint
) const;
129 inline const SwPageFrm
*GetSelPage() const { return mpSelPage
; }
131 void DisposePage(const SwPageFrm
*pPageFrm
);
134 // real states for events
135 #define ACC_STATE_EDITABLE 0x01
136 #define ACC_STATE_OPAQUE 0x02
138 // pseudo states for events
139 // --> OD 2009-01-07 #i88069# - pseudo state for event TEXT_ATTRIBUTE_CHANGED
140 #define ACC_STATE_TEXT_ATTRIBUTE_CHANGED 0x0200
142 // --> OD 2005-12-12 #i27301# - pseudo state for event TEXT_SELECTION_CHANGED
143 #define ACC_STATE_TEXT_SELECTION_CHANGED 0x0100
145 #define ACC_STATE_CARET 0x80
146 #define ACC_STATE_RELATION_FROM 0x40
147 #define ACC_STATE_RELATION_TO 0x20
149 #define ACC_STATE_RELATION_MASK 0x60
151 #define ACC_STATE_MASK 0x1F
153 // --> OD 2005-12-12 #i27301# - introduce type definition of states
154 typedef sal_uInt16 tAccessibleStates
;
157 class SwAccessibleMap
: public accessibility::IAccessibleViewForwarder
,
158 public accessibility::IAccessibleParent
160 ::vos::OMutex maMutex
;
161 ::vos::OMutex maEventMutex
;
162 SwAccessibleContextMap_Impl
*mpFrmMap
;
163 SwAccessibleShapeMap_Impl
*mpShapeMap
;
164 SwShapeList_Impl
*mpShapes
;
165 SwAccessibleEventList_Impl
*mpEvents
;
166 SwAccessibleEventMap_Impl
*mpEventMap
;
167 // --> OD 2005-12-13 #i27301# - data structure to keep information about
168 // accessible paragraph, which have a selection.
169 SwAccessibleSelectedParas_Impl
* mpSelectedParas
;
172 /// for page preview: store preview data, VisArea, and mapping of
173 /// preview-to-display coordinates
174 SwAccPreviewData
* mpPreview
;
176 ::com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
> mxCursorContext
;
179 sal_Int32 mnFootnote
;
183 sal_Bool mbShapeSelected
;
185 void FireEvent( const SwAccessibleEvent_Impl
& rEvent
);
187 void AppendEvent( const SwAccessibleEvent_Impl
& rEvent
);
189 void InvalidateCursorPosition(
190 const ::com::sun::star::uno::Reference
<
191 ::com::sun::star::accessibility::XAccessible
>& rAcc
);
192 void DoInvalidateShapeSelection();
193 void DoInvalidateShapeFocus();
194 void InvalidateShapeSelection();
196 void _InvalidateRelationSet( const SwFrm
* pFrm
, sal_Bool bFrom
);
198 ::com::sun::star::uno::Reference
<
199 ::com::sun::star::accessibility::XAccessible
>
200 _GetDocumentView( sal_Bool bPagePreview
);
202 /** method to build up a new data structure of the accessible pararaphs,
203 which have a selection
205 OD 2005-12-13 #i27301#
206 Important note: method has to used inside a mutual exclusive section
210 SwAccessibleSelectedParas_Impl
* _BuildSelectedParas();
214 SwAccessibleMap( ViewShell
*pSh
);
217 ::com::sun::star::uno::Reference
<
218 ::com::sun::star::accessibility::XAccessible
> GetDocumentView();
220 // OD 15.01.2003 #103492# - complete re-factoring of method due to new
221 // page/print preview functionality.
222 ::com::sun::star::uno::Reference
<
223 ::com::sun::star::accessibility::XAccessible
> GetDocumentPreview(
224 const std::vector
<PrevwPage
*>& _rPrevwPages
,
225 const Fraction
& _rScale
,
226 const SwPageFrm
* _pSelectedPageFrm
,
227 const Size
& _rPrevwWinSize
);
229 ::vos::ORef
< SwAccessibleContext
> GetContextImpl(
231 sal_Bool bCreate
= sal_True
);
232 ::com::sun::star::uno::Reference
<
233 ::com::sun::star::accessibility::XAccessible
> GetContext(
235 sal_Bool bCreate
= sal_True
);
237 ::vos::ORef
< ::accessibility::AccessibleShape
> GetContextImpl(
238 const SdrObject
*pObj
,
239 SwAccessibleContext
*pParentImpl
,
240 sal_Bool bCreate
= sal_True
);
241 ::com::sun::star::uno::Reference
<
242 ::com::sun::star::accessibility::XAccessible
> GetContext(
243 const SdrObject
*pObj
,
244 SwAccessibleContext
*pParentImpl
,
245 sal_Bool bCreate
= sal_True
);
247 inline ViewShell
* GetShell() const
252 inline const SwRect
& GetVisArea() const
254 DBG_ASSERT( !GetShell()->IsPreView() || (mpPreview
!= NULL
),
255 "preview without preview data?" );
256 return GetShell()->IsPreView()
257 ? mpPreview
->GetVisArea()
258 : GetShell()->VisArea();
261 /** get size of a dedicated preview page
263 OD 15.01.2003 #103492#
264 complete re-factoring of previous method due to new page/print preview
269 @param _nPrevwPageNum
270 input parameter - physical page number of page visible in the page preview
272 @return an object of class <Size>
274 Size
GetPreViewPageSize( sal_uInt16 _nPrevwPageNum
) const;
276 void RemoveContext( const SwFrm
*pFrm
);
277 void RemoveContext( const SdrObject
*pObj
);
279 // Dispose frame and its children if bRecursive is set
280 void Dispose( const SwFrm
*pFrm
, const SdrObject
*pObj
,
281 sal_Bool bRecursive
=sal_False
);
283 void InvalidatePosOrSize( const SwFrm
*pFrm
, const SdrObject
*pObj
,
284 const SwRect
& rOldFrm
);
286 void InvalidateContent( const SwFrm
*pFrm
);
288 // --> OD 2009-01-06 #i88069#
289 void InvalidateAttr( const SwTxtFrm
& rTxtFrm
);
292 void InvalidateCursorPosition( const SwFrm
*pFrm
);
293 void InvalidateFocus();
295 void SetCursorContext(
296 const ::vos::ORef
< SwAccessibleContext
>& rCursorContext
);
298 // Invalidate state of whole tree. If an action is open, this call
299 // is processed when the last action ends.
300 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
301 void InvalidateStates( tAccessibleStates _nStates
,
302 const SwFrm
* _pFrm
= 0 );
304 void InvalidateRelationSet( const SwFrm
* pMaster
, const SwFrm
* pFollow
);
306 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
308 OD 2005-12-01 #i27138#
313 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
314 has to be invalidated.
317 input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
318 (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
320 void InvalidateParaFlowRelation( const SwTxtFrm
& _rTxtFrm
,
323 /** invalidation of text selection of a paragraph
325 OD 2005-12-12 #i27301#
329 void InvalidateParaTextSelection( const SwTxtFrm
& _rTxtFrm
);
331 /** invalidation of text selection of all paragraphs
333 OD 2005-12-13 #i27301#
337 void InvalidateTextSelectionOfAllParas();
339 // update preview data (and fire events if necessary)
340 // OD 15.01.2003 #103492# - complete re-factoring of method due to new
341 // page/print preview functionality.
342 void UpdatePreview( const std::vector
<PrevwPage
*>& _rPrevwPages
,
343 const Fraction
& _rScale
,
344 const SwPageFrm
* _pSelectedPageFrm
,
345 const Size
& _rPrevwWinSize
);
347 void InvalidatePreViewSelection( sal_uInt16 nSelPage
);
348 sal_Bool
IsPageSelected( const SwPageFrm
*pPageFrm
) const;
353 // IAccessibleViewForwarder
355 virtual sal_Bool
IsValid() const;
356 virtual Rectangle
GetVisibleArea() const;
357 virtual Point
LogicToPixel (const Point
& rPoint
) const;
358 virtual Size
LogicToPixel (const Size
& rSize
) const;
359 virtual Point
PixelToLogic (const Point
& rPoint
) const;
360 virtual Size
PixelToLogic (const Size
& rSize
) const;
363 virtual sal_Bool
ReplaceChild (
364 ::accessibility::AccessibleShape
* pCurrentChild
,
365 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>& _rxShape
,
367 const ::accessibility::AccessibleShapeTreeInfo
& _rShapeTreeInfo
368 ) throw (::com::sun::star::uno::RuntimeException
);
370 // additional Core/Pixel conversions for internal use; also works
372 Point
PixelToCore (const Point
& rPoint
) const;
373 Rectangle
CoreToPixel (const Rectangle
& rRect
) const;
376 /** get mapping mode for LogicToPixel and PixelToLogic conversions
378 OD 15.01.2003 #103492#
379 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
380 Method returns mapping mode of current output device and adjusts it,
381 if the shell is in page/print preview.
382 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
383 output device for mapping logic document positions to page preview window
384 positions and vice versa and doesn't take care to recover its changes.
389 input parameter - constant reference to point to determine the mapping
390 mode adjustments for page/print preview.
393 output parameter - reference to the mapping mode, which is determined
396 void GetMapMode( const Point
& _rPoint
,
397 MapMode
& _orMapMode
) const;