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_ANCHOREDOBJECT_HXX
20 #define INCLUDED_SW_INC_ANCHOREDOBJECT_HXX
22 #include <swtypes.hxx>
24 #include <libxml/xmlwriter.h>
32 class SwObjPositioningInProgress
;
37 /** wrapper class for the positioning of Writer fly frames and drawing objects
39 Purpose of this class is to provide a unified interface for the positioning
40 of Writer fly frames (derived classes of <SwFlyFrame>) and of drawing objects
41 (derived classes of <SwDrawFrame>).
45 class SW_DLLPUBLIC SwAnchoredObject
48 // drawing object representing the anchored object in the drawing layer
50 // frame the object is anchored at
51 SwFrame
* mpAnchorFrame
;
52 // #i28701 - page frame the object is registered at
53 // note: no page frame for as-character anchored objects
54 SwPageFrame
* mpPageFrame
;
55 // current relative position (relative to anchor position of anchor frame)
58 // for to-character anchored objects:
59 // Last known anchor character rectangle.
60 // Used to decide, if invalidation has to been performed, if anchor position
61 // has changed, and used to position object.
62 SwRect maLastCharRect
;
64 // for to-character anchored objects:
65 // Last known top of line, in which the anchor character is in.
66 // Used to decide, if invalidation has to been performed, if anchor position
67 // has changed, and used to position object.
68 SwTwips mnLastTopOfLine
;
70 // for to-paragraph and to-character anchored objects:
71 // Layout frame vertical position is orient at - typically it's the upper
72 // of the anchor frame, but it could also by the upper of a follow or
73 // a following layout frame in the text flow.
74 const SwLayoutFrame
* mpVertPosOrientFrame
;
76 // i#i28701 boolean, indicating that the object
77 // positioning algorithm is in progress.
78 bool mbPositioningInProgress
;
80 // Booleans needed for the layout process.
81 // Values only of relevance for to-paragraph and to-character anchored
82 // floating screen object, for whose the 'straight-forward positioning
83 // process are applied
84 // Otherwise value of <mbConsiderForTextWrap> is treated as <true>,
85 // value of <mbPositionLocked> is treated as <false> and
86 // value of <mbRestartLayoutProcess> is treated as <false>.
87 // i#35911 - add boolean <mbClearEnvironment>
88 // Indicates that due to its position and wrapping style its layout
89 // environment is cleared - all content is moved forward.
90 // Treated as <false>, if not the 'straight-forward positioning process"
92 bool mbConsiderForTextWrap
;
93 bool mbPositionLocked
;
94 // boolean needed to keep position of
95 // anchored object locked due to special object positioning for sections.
96 bool mbKeepPositionLockedForSection
;
98 bool mbRestartLayoutProcess
;
99 bool mbClearedEnvironment
;
101 // i#i3317 - boolean, indicating that temporarily
102 // the wrapping style influence of the anchored object has to be
103 // considered during its positioning.
104 // This boolean is used, if compatibility option 'Consider wrapping style
105 // influence on object positioning' is OFF and a positioning loop is
106 // detected in method <SwFlyAtContentFrame::MakeAll()> or method
107 // <SwAnchoredDrawObject::MakeObjPosAnchoredAtPara()>.
108 // The boolean is reset to <false>, when the layout process for a
109 // page frame starts.
110 bool mbTmpConsiderWrapInfluence
;
112 mutable SwRect maObjRectWithSpaces
;
113 mutable bool mbObjRectWithSpacesValid
;
114 mutable SwRect maLastObjRect
;
116 /** method to indicate, that positioning of anchored object is in progress
118 note: method is implemented empty
122 friend class SwObjPositioningInProgress
;
123 void SetPositioningInProgress( const bool _bPosInProgress
)
125 mbPositioningInProgress
= _bPosInProgress
;
128 /** check anchor character rectangle
130 helper method for method <CheckCharRectAndTopOfLine()>
131 For to-character anchored Writer fly frames the member <maLastCharRect>
132 is updated. This is checked for change and depending on the applied
133 positioning, it's decided, if the Writer fly frame has to be invalidated.
134 improvement - add second parameter <_rAnchorCharFrame>
139 input parameter - reference to anchor position
141 @param _rAnchorCharFrame
142 input parameter - reference to the text frame containing the anchor
145 void CheckCharRect( const SwFormatAnchor
& _rAnch
,
146 const SwTextFrame
& _rAnchorCharFrame
);
148 /** check top of line
150 helper method for method <CheckCharRectAndTopOfLine()>
151 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
152 is updated. This is checked for change and depending on the applied
153 positioning, it's decided, if the Writer fly frame has to be invalidated.
158 input parameter - reference to anchor position
160 @param _rAnchorCharFrame
161 input parameter - reference to the text frame containing the anchor
164 void CheckTopOfLine( const SwFormatAnchor
& _rAnch
,
165 const SwTextFrame
& _rAnchorCharFrame
);
167 // method <sw_HideObj(..)> sets needed data structure values for the
168 // object positioning
169 friend bool sw_HideObj( const SwTextFrame
& _rFrame
,
170 const RndStdIds _eAnchorType
,
171 const sal_Int32 _nObjAnchorPos
,
172 SwAnchoredObject
* _pAnchoredObj
);
176 void SetVertPosOrientFrame( const SwLayoutFrame
& _rVertPosOrientFrame
);
178 /** method to assure that anchored object is registered at the correct
183 virtual void RegisterAtCorrectPage() = 0;
185 /** method to indicate, that anchored object is attached to a anchor frame
189 virtual void ObjectAttachedToAnchorFrame();
191 /** method to determine, if other anchored objects, also attached at
192 to the anchor frame, have to consider its wrap influence.
196 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
198 /** method to apply temporary consideration of wrapping style influence
199 to the anchored objects, which are anchored at the same anchor frame
203 void SetTmpConsiderWrapInfluenceOfOtherObjs();
205 virtual bool SetObjTop_( const SwTwips _nTop
) = 0;
206 virtual bool SetObjLeft_( const SwTwips _nLeft
) = 0;
208 virtual const SwRect
GetObjBoundRect() const = 0;
211 virtual ~SwAnchoredObject();
213 // accessors to member <mpDrawObj>
214 void SetDrawObj( SdrObject
& _rDrawObj
);
215 const SdrObject
* GetDrawObj() const { return mpDrawObj
; }
216 SdrObject
* DrawObj() { return mpDrawObj
; }
218 // accessors to member <mpAnchorFrame>
219 const SwFrame
* GetAnchorFrame() const { return mpAnchorFrame
; }
220 SwFrame
* AnchorFrame() { return mpAnchorFrame
; }
221 void ChgAnchorFrame( SwFrame
* _pNewAnchorFrame
);
222 /** determine anchor frame containing the anchor position
224 the anchor frame, which is determined, is <mpAnchorFrame>
225 for an at-page, at-frame or at-paragraph anchored object
226 and the anchor character frame for an at-character and as-character
231 SwFrame
* GetAnchorFrameContainingAnchPos();
233 SwPageFrame
* GetPageFrame() { return mpPageFrame
; }
234 const SwPageFrame
* GetPageFrame() const { return mpPageFrame
; }
235 void SetPageFrame( SwPageFrame
* _pNewPageFrame
);
237 /** method to determine the page frame, on which the 'anchor' of
238 the given anchored object is.
240 Adjust meaning of method and thus its name: If the anchored object
241 or its anchor isn't correctly inserted in the layout, no page frame
242 can be found. Thus, the return type changed to be a pointer and can
248 input parameter - anchored object, for which the page frame of its
249 'anchor' has to be determined.
252 page frame, the 'anchor' of the given anchored object is on
254 SwPageFrame
* FindPageFrameOfAnchor();
256 /** get frame, which contains the anchor character, if the object
257 is anchored at-character or as-character.
262 text frame containing the anchor character. It's NULL, if the object
263 isn't anchored at-character resp. as-character.
265 SwTextFrame
* FindAnchorCharFrame();
267 // accessors to data of position calculation:
268 // frame vertical position is orient at
269 const SwLayoutFrame
* GetVertPosOrientFrame() const
271 return mpVertPosOrientFrame
;
273 // method to clear member <mpVertPosOrientFrame>
274 void ClearVertPosOrientFrame();
276 /** check anchor character rectangle and top of line
278 For to-character anchored Writer fly frames the members <maLastCharRect>
279 and <maLastTopOfLine> are updated. These are checked for change and
280 depending on the applied positioning, it's decided, if the Writer fly
281 frame has to be invalidated.
285 @param _bCheckForParaPorInf
286 input parameter - boolean indicating, if check on paragraph portion
287 information has to be done.
289 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf
);
291 // accessors to member <maLastCharRect>
292 const SwRect
& GetLastCharRect() const { return maLastCharRect
;}
293 SwTwips
GetRelCharX( const SwFrame
* pFrame
) const;
294 SwTwips
GetRelCharY( const SwFrame
* pFrame
) const;
295 void AddLastCharY( long nDiff
);
296 void ResetLastCharRectHeight();
298 // accessor to member <nmLastTopOfLine>
299 SwTwips
GetLastTopOfLine() const { return mnLastTopOfLine
;}
300 void AddLastTopOfLineY( SwTwips _nDiff
);
302 /** reset members <maLastCharRect> and <mnLastTopOfLine>
306 void ClearCharRectAndTopOfLine();
308 /** method to determine position for the object and set the position
313 virtual void MakeObjPos() = 0;
315 /** is positioning of anchored object in progress
319 bool IsPositioningInProgress() const
321 return mbPositioningInProgress
;
324 /** method to determine, if invalidation of position is allowed
328 bool InvalidationOfPosAllowed() const;
330 /** method to invalidate position of the anchored object
334 virtual void InvalidateObjPos() = 0;
336 /** method to perform necessary invalidations for the positioning of
337 objects, for whose the wrapping style influence has to be considered
338 on the object positioning.
342 void InvalidateObjPosForConsiderWrapInfluence();
344 /** method to trigger notification of 'background'
348 virtual void NotifyBackground( SwPageFrame
* _pPageFrame
,
349 const SwRect
& _rRect
,
350 PrepareHint _eHint
) = 0;
352 // accessors to the current relative position (relative to anchor
353 // position of anchor frame)
354 const Point
& GetCurrRelPos() const { return maRelPos
;}
355 void SetCurrRelPos( Point _aRelPos
);
357 // accessors to the format
358 virtual SwFrameFormat
& GetFrameFormat() = 0;
359 virtual const SwFrameFormat
& GetFrameFormat() const = 0;
361 // accessors to the object area and its position
362 virtual const SwRect
GetObjRect() const = 0;
364 void SetObjTop( const SwTwips _nTop
);
365 void SetObjLeft( const SwTwips _nLeft
);
367 /** method update layout direction the layout direction, the anchored
368 object is assigned to
370 method has typically to be called, if the anchored object gets its
371 anchor frame assigned and if the anchor frame changes its layout direction
375 virtual void UpdateLayoutDir();
377 /** method to determine object area inclusive its spacing
381 const SwRect
& GetObjRectWithSpaces() const;
383 void InvalidateObjRectWithSpaces() const
385 mbObjRectWithSpacesValid
= false;
388 /** method to determine, if wrapping style influence of the anchored
389 object has to be considered on the object positioning
391 Note: result of this method also decides, if the boolean for the
392 layout process are of relevance.
396 bool ConsiderObjWrapInfluenceOnObjPos() const;
398 // accessors to booleans for layout process
399 bool ConsiderForTextWrap() const;
400 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap
);
401 bool PositionLocked() const;
404 mbPositionLocked
= true;
406 void UnlockPosition()
408 if ( !mbKeepPositionLockedForSection
)
410 mbPositionLocked
= false;
414 void SetKeepPosLocked( const bool _bKeepPosLocked
)
416 mbKeepPositionLockedForSection
= _bKeepPosLocked
;
419 bool RestartLayoutProcess() const;
420 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess
);
421 // accessors for <mbClearedEnvironment>
422 bool ClearedEnvironment() const;
423 void SetClearedEnvironment( const bool _bClearedEnvironment
);
425 // reset booleans for layout process
426 void ResetLayoutProcessBools()
428 mbPositioningInProgress
= false;
429 mbConsiderForTextWrap
= false;
430 mbPositionLocked
= false;
431 mbKeepPositionLockedForSection
= false;
432 mbRestartLayoutProcess
= false;
433 mbClearedEnvironment
= false;
434 mbTmpConsiderWrapInfluence
= false;
437 /** method to determine, if due to anchored object size and wrapping
438 style, its layout environment is cleared.
442 bool HasClearedEnvironment() const;
444 /** method to update anchored object in the <SwSortedObjs> lists
446 Method is not proposed to be called during a layout process is
447 running. It has been used on the change of the anchored object
448 attributes, which belongs the sort criteria of <SwSortedObjs>.
449 If document compatibility option 'Consider wrapping style influence
450 on object positioning' is ON, additionally all anchored objects
451 at the anchor frame and all following anchored objects on the page
452 frame are invalidated.
456 void UpdateObjInSortedList();
458 /** method to determine, if a format on the anchored object is possible
460 A format isn't possible, if anchored object is in an invisible layer.
461 Note: method is virtual to refine the conditions for the sub-classes.
465 virtual bool IsFormatPossible() const;
467 // accessors to member <mbTmpConsiderWrapInfluence>
468 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence
);
469 bool IsTmpConsiderWrapInfluence() const { return mbTmpConsiderWrapInfluence
;}
471 /** method to determine, if the anchored object is overlapping with a
474 overlapping with a previous column means, that the object overlaps
475 with a column, which is a previous one of the column its anchor
477 Only applied for at-paragraph and at-character anchored objects.
481 bool OverlapsPrevColumn() const;
483 /** method to determine position of anchored object relative to
486 Usage: Needed layout information for WW8 export
490 @return Point - determined relative position
492 Point
GetRelPosToAnchorFrame() const;
494 /** method to determine position of anchored object relative to
497 Usage: Needed layout information for WW8 export
499 If <_bFollowTextFlow> is set and object is anchored inside table,
500 the position relative to the table cell is determined. Output
501 parameter <_obRelToTableCell> reflects this situation
505 @param _bFollowTextFlow
506 input parameter - boolean indicating, if the anchored object has to
507 follow the text flow.
509 @param _obRelToTableCell
510 output parameter - boolean indicating, the determine position is
511 relative to the table cell
513 @return Point - determined relative position
515 Point
GetRelPosToPageFrame( const bool _bFollowTextFlow
,
516 bool& _obRelToTableCell
) const;
518 /** method to determine position of anchored object relative to
521 Usage: Needed layout information for WW8 export
525 @return Point - determined relative position
527 Point
GetRelPosToChar() const;
529 /** method to determine position of anchored object relative to
532 Usage: Needed layout information for WW8 export
536 @return Point - determined relative position
538 Point
GetRelPosToLine() const;
540 /** Dump a bunch of useful data to an XML representation to ease
541 layout understanding, debugging and testing.
543 virtual void dumpAsXml( xmlTextWriterPtr pWriter
) const;
545 /** The element name to show in the XML dump.
547 virtual const char* getElementName( ) const { return "SwAnchoredObject"; }
550 /// Helper class for notify that positioning of an anchored object is in progress.
551 class SwObjPositioningInProgress
554 SwAnchoredObject
* mpAnchoredObj
;
555 // boolean indicating old state
556 // of anchored object regarding positioning in progress in order to
557 // consider nested usage of class <SwObjPositioningInProgress>
558 bool mbOldObjPositioningInProgress
;
561 SwObjPositioningInProgress( SdrObject
& _rSdrObj
);
562 SwObjPositioningInProgress( SwAnchoredObject
& _rAnchoredObj
);
563 ~SwObjPositioningInProgress();
568 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */