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 2005-12-12 #i27301# - pseudo state for event TEXT_SELECTION_CHANGED
140 #define ACC_STATE_TEXT_SELECTION_CHANGED 0x0100
142 #define ACC_STATE_CARET 0x80
143 #define ACC_STATE_RELATION_FROM 0x40
144 #define ACC_STATE_RELATION_TO 0x20
146 #define ACC_STATE_RELATION_MASK 0x60
148 #define ACC_STATE_MASK 0x1F
150 // --> OD 2005-12-12 #i27301# - introduce type definition of states
151 typedef sal_uInt16 tAccessibleStates
;
154 class SwAccessibleMap
: public accessibility::IAccessibleViewForwarder
,
155 public accessibility::IAccessibleParent
157 ::vos::OMutex maMutex
;
158 ::vos::OMutex maEventMutex
;
159 SwAccessibleContextMap_Impl
*mpFrmMap
;
160 SwAccessibleShapeMap_Impl
*mpShapeMap
;
161 SwShapeList_Impl
*mpShapes
;
162 SwAccessibleEventList_Impl
*mpEvents
;
163 SwAccessibleEventMap_Impl
*mpEventMap
;
164 // --> OD 2005-12-13 #i27301# - data structure to keep information about
165 // accessible paragraph, which have a selection.
166 SwAccessibleSelectedParas_Impl
* mpSelectedParas
;
169 /// for page preview: store preview data, VisArea, and mapping of
170 /// preview-to-display coordinates
171 SwAccPreviewData
* mpPreview
;
173 ::com::sun::star::uno::WeakReference
< ::com::sun::star::accessibility::XAccessible
> mxCursorContext
;
176 sal_Int32 mnFootnote
;
180 sal_Bool mbShapeSelected
;
182 void FireEvent( const SwAccessibleEvent_Impl
& rEvent
);
184 void AppendEvent( const SwAccessibleEvent_Impl
& rEvent
);
186 void InvalidateCursorPosition(
187 const ::com::sun::star::uno::Reference
<
188 ::com::sun::star::accessibility::XAccessible
>& rAcc
);
189 void DoInvalidateShapeSelection();
190 void DoInvalidateShapeFocus();
191 void InvalidateShapeSelection();
193 void _InvalidateRelationSet( const SwFrm
* pFrm
, sal_Bool bFrom
);
195 ::com::sun::star::uno::Reference
<
196 ::com::sun::star::accessibility::XAccessible
>
197 _GetDocumentView( sal_Bool bPagePreview
);
199 /** method to build up a new data structure of the accessible pararaphs,
200 which have a selection
202 OD 2005-12-13 #i27301#
203 Important note: method has to used inside a mutual exclusive section
207 SwAccessibleSelectedParas_Impl
* _BuildSelectedParas();
211 SwAccessibleMap( ViewShell
*pSh
);
214 ::com::sun::star::uno::Reference
<
215 ::com::sun::star::accessibility::XAccessible
> GetDocumentView();
217 // OD 15.01.2003 #103492# - complete re-factoring of method due to new
218 // page/print preview functionality.
219 ::com::sun::star::uno::Reference
<
220 ::com::sun::star::accessibility::XAccessible
> GetDocumentPreview(
221 const std::vector
<PrevwPage
*>& _rPrevwPages
,
222 const Fraction
& _rScale
,
223 const SwPageFrm
* _pSelectedPageFrm
,
224 const Size
& _rPrevwWinSize
);
226 ::vos::ORef
< SwAccessibleContext
> GetContextImpl(
228 sal_Bool bCreate
= sal_True
);
229 ::com::sun::star::uno::Reference
<
230 ::com::sun::star::accessibility::XAccessible
> GetContext(
232 sal_Bool bCreate
= sal_True
);
234 ::vos::ORef
< ::accessibility::AccessibleShape
> GetContextImpl(
235 const SdrObject
*pObj
,
236 SwAccessibleContext
*pParentImpl
,
237 sal_Bool bCreate
= sal_True
);
238 ::com::sun::star::uno::Reference
<
239 ::com::sun::star::accessibility::XAccessible
> GetContext(
240 const SdrObject
*pObj
,
241 SwAccessibleContext
*pParentImpl
,
242 sal_Bool bCreate
= sal_True
);
244 inline ViewShell
* GetShell() const
249 inline const SwRect
& GetVisArea() const
251 DBG_ASSERT( !GetShell()->IsPreView() || (mpPreview
!= NULL
),
252 "preview without preview data?" );
253 return GetShell()->IsPreView()
254 ? mpPreview
->GetVisArea()
255 : GetShell()->VisArea();
258 /** get size of a dedicated preview page
260 OD 15.01.2003 #103492#
261 complete re-factoring of previous method due to new page/print preview
266 @param _nPrevwPageNum
267 input parameter - physical page number of page visible in the page preview
269 @return an object of class <Size>
271 Size
GetPreViewPageSize( sal_uInt16 _nPrevwPageNum
) const;
273 void RemoveContext( const SwFrm
*pFrm
);
274 void RemoveContext( const SdrObject
*pObj
);
276 // Dispose frame and its children if bRecursive is set
277 void Dispose( const SwFrm
*pFrm
, const SdrObject
*pObj
,
278 sal_Bool bRecursive
=sal_False
);
280 void InvalidatePosOrSize( const SwFrm
*pFrm
, const SdrObject
*pObj
,
281 const SwRect
& rOldFrm
);
283 void InvalidateContent( const SwFrm
*pFrm
);
285 void InvalidateCursorPosition( const SwFrm
*pFrm
);
286 void InvalidateFocus();
288 void SetCursorContext(
289 const ::vos::ORef
< SwAccessibleContext
>& rCursorContext
);
291 // Invalidate state of whole tree. If an action is open, this call
292 // is processed when the last action ends.
293 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates>
294 void InvalidateStates( tAccessibleStates _nStates
,
295 const SwFrm
* _pFrm
= 0 );
297 void InvalidateRelationSet( const SwFrm
* pMaster
, const SwFrm
* pFollow
);
299 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
301 OD 2005-12-01 #i27138#
306 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
307 has to be invalidated.
310 input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
311 (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
313 void InvalidateParaFlowRelation( const SwTxtFrm
& _rTxtFrm
,
316 /** invalidation of text selection of a paragraph
318 OD 2005-12-12 #i27301#
322 void InvalidateParaTextSelection( const SwTxtFrm
& _rTxtFrm
);
324 /** invalidation of text selection of all paragraphs
326 OD 2005-12-13 #i27301#
330 void InvalidateTextSelectionOfAllParas();
332 // update preview data (and fire events if necessary)
333 // OD 15.01.2003 #103492# - complete re-factoring of method due to new
334 // page/print preview functionality.
335 void UpdatePreview( const std::vector
<PrevwPage
*>& _rPrevwPages
,
336 const Fraction
& _rScale
,
337 const SwPageFrm
* _pSelectedPageFrm
,
338 const Size
& _rPrevwWinSize
);
340 void InvalidatePreViewSelection( sal_uInt16 nSelPage
);
341 sal_Bool
IsPageSelected( const SwPageFrm
*pPageFrm
) const;
346 // IAccessibleViewForwarder
348 virtual sal_Bool
IsValid() const;
349 virtual Rectangle
GetVisibleArea() const;
350 virtual Point
LogicToPixel (const Point
& rPoint
) const;
351 virtual Size
LogicToPixel (const Size
& rSize
) const;
352 virtual Point
PixelToLogic (const Point
& rPoint
) const;
353 virtual Size
PixelToLogic (const Size
& rSize
) const;
356 virtual sal_Bool
ReplaceChild (
357 ::accessibility::AccessibleShape
* pCurrentChild
,
358 const ::com::sun::star::uno::Reference
< ::com::sun::star::drawing::XShape
>& _rxShape
,
360 const ::accessibility::AccessibleShapeTreeInfo
& _rShapeTreeInfo
361 ) throw (::com::sun::star::uno::RuntimeException
);
363 // additional Core/Pixel conversions for internal use; also works
365 Point
PixelToCore (const Point
& rPoint
) const;
366 Rectangle
CoreToPixel (const Rectangle
& rRect
) const;
369 /** get mapping mode for LogicToPixel and PixelToLogic conversions
371 OD 15.01.2003 #103492#
372 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
373 Method returns mapping mode of current output device and adjusts it,
374 if the shell is in page/print preview.
375 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
376 output device for mapping logic document positions to page preview window
377 positions and vice versa and doesn't take care to recover its changes.
382 input parameter - constant reference to point to determine the mapping
383 mode adjustments for page/print preview.
386 output parameter - reference to the mapping mode, which is determined
389 void GetMapMode( const Point
& _rPoint
,
390 MapMode
& _orMapMode
) const;