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 .
21 #include "swtypes.hxx"
23 #include <svx/svdobj.hxx>
24 #include <libxml/xmlwriter.h>
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 <SwAnchoredDrawObject>).
43 class SAL_DLLPUBLIC_RTTI SwAnchoredObject
46 // drawing object representing the anchored object in the drawing layer
47 rtl::Reference
<SdrObject
> mpDrawObj
;
48 /// Frame the object is anchored at.
49 /// For at-char/at-para anchor, this is always the master SwTextFrame.
50 SwFrame
* mpAnchorFrame
;
51 // #i28701 - page frame the object is registered at
52 // note: no page frame for as-character anchored objects
53 SwPageFrame
* mpPageFrame
;
54 // current relative position (relative to anchor position of anchor frame)
57 // for to-character anchored objects:
58 // Last known anchor character rectangle.
59 // Used to decide, if invalidation has to been performed, if anchor position
60 // has changed, and used to position object.
61 SwRect maLastCharRect
;
63 // for to-character anchored objects:
64 // Last known top of line, in which the anchor character is in.
65 // Used to decide, if invalidation has to been performed, if anchor position
66 // has changed, and used to position object.
67 SwTwips mnLastTopOfLine
;
69 // for to-paragraph and to-character anchored objects:
70 // Layout frame vertical position is orient at - typically it's the upper
71 // of the anchor frame, but it could also by the upper of a follow or
72 // a following layout frame in the text flow.
73 const SwLayoutFrame
* mpVertPosOrientFrame
;
75 // i#i28701 boolean, indicating that the object
76 // positioning algorithm is in progress.
77 bool mbPositioningInProgress
;
79 // Booleans needed for the layout process.
80 // Values only of relevance for to-paragraph and to-character anchored
81 // floating screen object, for whose the 'straight-forward positioning
82 // process are applied
83 // Otherwise value of <mbConsiderForTextWrap> is treated as <true>,
84 // value of <mbPositionLocked> is treated as <false> and
85 // value of <mbRestartLayoutProcess> is treated as <false>.
86 // i#35911 - add boolean <mbClearEnvironment>
87 // Indicates that due to its position and wrapping style its layout
88 // environment is cleared - all content is moved forward.
89 // Treated as <false>, if not the 'straight-forward positioning process"
91 bool mbConsiderForTextWrap
;
92 bool mbPositionLocked
;
93 // boolean needed to keep position of
94 // anchored object locked due to special object positioning for sections.
95 bool mbKeepPositionLockedForSection
;
97 bool mbRestartLayoutProcess
;
98 bool mbClearedEnvironment
;
100 // i#i3317 - boolean, indicating that temporarily
101 // the wrapping style influence of the anchored object has to be
102 // considered during its positioning.
103 // This boolean is used, if compatibility option 'Consider wrapping style
104 // influence on object positioning' is OFF and a positioning loop is
105 // detected in method <SwFlyAtContentFrame::MakeAll()> or method
106 // <SwAnchoredDrawObject::MakeObjPosAnchoredAtPara()>.
107 // The boolean is reset to <false>, when the layout process for a
108 // page frame starts.
109 bool mbTmpConsiderWrapInfluence
;
111 bool mbForceNotifyNewBackground
= false;
113 mutable SwRect maObjRectWithSpaces
;
114 mutable bool mbObjRectWithSpacesValid
;
115 mutable SwRect maLastObjRect
;
117 /** method to indicate, that positioning of anchored object is in progress
119 note: method is implemented empty
121 friend class SwObjPositioningInProgress
;
122 void SetPositioningInProgress( const bool _bPosInProgress
)
124 mbPositioningInProgress
= _bPosInProgress
;
127 /** check anchor character rectangle
129 helper method for method <CheckCharRectAndTopOfLine()>
130 For to-character anchored Writer fly frames the member <maLastCharRect>
131 is updated. This is checked for change and depending on the applied
132 positioning, it's decided, if the Writer fly frame has to be invalidated.
133 improvement - add second parameter <_rAnchorCharFrame>
136 input parameter - reference to anchor position
138 @param _rAnchorCharFrame
139 input parameter - reference to the text frame containing the anchor
142 void CheckCharRect( const SwFormatAnchor
& _rAnch
,
143 const SwTextFrame
& _rAnchorCharFrame
);
145 /** check top of line
147 helper method for method <CheckCharRectAndTopOfLine()>
148 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
149 is updated. This is checked for change and depending on the applied
150 positioning, it's decided, if the Writer fly frame has to be invalidated.
153 input parameter - reference to anchor position
155 @param _rAnchorCharFrame
156 input parameter - reference to the text frame containing the anchor
159 void CheckTopOfLine( const SwFormatAnchor
& _rAnch
,
160 const SwTextFrame
& _rAnchorCharFrame
);
162 // method <sw_HideObj(..)> sets needed data structure values for the
163 // object positioning
164 friend bool sw_HideObj( const SwTextFrame
& _rFrame
,
165 const RndStdIds _eAnchorType
,
166 SwFormatAnchor
const& rFormatAnchor
,
167 SwAnchoredObject
* _pAnchoredObj
);
171 void SetVertPosOrientFrame( const SwLayoutFrame
& _rVertPosOrientFrame
);
173 /** method to assure that anchored object is registered at the correct
176 virtual void RegisterAtCorrectPage() = 0;
178 /** method to indicate, that anchored object is attached to an anchor frame */
179 virtual void ObjectAttachedToAnchorFrame();
181 /** method to determine, if other anchored objects, also attached at
182 to the anchor frame, have to consider its wrap influence.
184 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
186 /** method to apply temporary consideration of wrapping style influence
187 to the anchored objects, which are anchored at the same anchor frame
189 void SetTmpConsiderWrapInfluenceOfOtherObjs();
191 virtual bool SetObjTop_( const SwTwips _nTop
) = 0;
192 virtual bool SetObjLeft_( const SwTwips _nLeft
) = 0;
194 virtual SwRect
GetObjBoundRect() const = 0;
197 virtual ~SwAnchoredObject();
199 // accessors to member <mpDrawObj>
200 void SetDrawObj( SdrObject
& _rDrawObj
);
201 const SdrObject
* GetDrawObj() const { return mpDrawObj
.get(); }
202 SdrObject
* DrawObj() { return mpDrawObj
.get(); }
203 void ClearDrawObj() { mpDrawObj
.clear(); }
205 // accessors to member <mpAnchorFrame>
206 const SwFrame
* GetAnchorFrame() const { return mpAnchorFrame
; }
207 SwFrame
* AnchorFrame() { return mpAnchorFrame
; }
208 void ChgAnchorFrame( SwFrame
* _pNewAnchorFrame
);
209 /** determine anchor frame containing the anchor position
211 the anchor frame, which is determined, is <mpAnchorFrame>
212 for an at-page, at-frame or at-paragraph anchored object
213 and the anchor character frame for an at-character and as-character
216 SW_DLLPUBLIC SwFrame
* GetAnchorFrameContainingAnchPos();
218 SwPageFrame
* GetPageFrame() { return mpPageFrame
; }
219 const SwPageFrame
* GetPageFrame() const { return mpPageFrame
; }
220 void SetPageFrame( SwPageFrame
* _pNewPageFrame
);
222 /** method to determine the page frame, on which the 'anchor' of
223 the given anchored object is.
225 Adjust meaning of method and thus its name: If the anchored object
226 or its anchor isn't correctly inserted in the layout, no page frame
227 can be found. Thus, the return type changed to be a pointer and can
231 input parameter - anchored object, for which the page frame of its
232 'anchor' has to be determined.
235 page frame, the 'anchor' of the given anchored object is on
237 SwPageFrame
* FindPageFrameOfAnchor();
239 /** get frame, which contains the anchor character, if the object
240 is anchored at-character or as-character.
243 text frame containing the anchor character. It's NULL, if the object
244 isn't anchored at-character resp. as-character.
246 SwTextFrame
* FindAnchorCharFrame();
248 // accessors to data of position calculation:
249 // frame vertical position is orient at
250 const SwLayoutFrame
* GetVertPosOrientFrame() const
252 return mpVertPosOrientFrame
;
254 // method to clear member <mpVertPosOrientFrame>
255 void ClearVertPosOrientFrame();
257 /** check anchor character rectangle and top of line
259 For to-character anchored Writer fly frames the members <maLastCharRect>
260 and <maLastTopOfLine> are updated. These are checked for change and
261 depending on the applied positioning, it's decided, if the Writer fly
262 frame has to be invalidated.
264 @param _bCheckForParaPorInf
265 input parameter - boolean indicating, if check on paragraph portion
266 information has to be done.
268 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf
);
270 // accessors to member <maLastCharRect>
271 const SwRect
& GetLastCharRect() const { return maLastCharRect
;}
272 SwTwips
GetRelCharX( const SwFrame
* pFrame
) const;
273 SwTwips
GetRelCharY( const SwFrame
* pFrame
) const;
274 void AddLastCharY( tools::Long nDiff
);
275 void ResetLastCharRectHeight();
277 // accessor to member <nmLastTopOfLine>
278 SwTwips
GetLastTopOfLine() const { return mnLastTopOfLine
;}
279 void AddLastTopOfLineY( SwTwips _nDiff
);
281 /** reset members <maLastCharRect> and <mnLastTopOfLine> */
282 void ClearCharRectAndTopOfLine();
284 /** method to determine position for the object and set the position
287 virtual void MakeObjPos() = 0;
289 /** is positioning of anchored object in progress */
290 bool IsPositioningInProgress() const
292 return mbPositioningInProgress
;
295 /** method to determine, if invalidation of position is allowed */
296 bool InvalidationOfPosAllowed() const;
298 /** method to invalidate position of the anchored object */
299 virtual void InvalidateObjPos() = 0;
301 virtual void RegisterAtPage(SwPageFrame
&) = 0;
303 /** method to perform necessary invalidations for the positioning of
304 objects, for whose the wrapping style influence has to be considered
305 on the object positioning.
307 void InvalidateObjPosForConsiderWrapInfluence();
309 /** method to trigger notification of 'background' */
310 virtual void NotifyBackground( SwPageFrame
* _pPageFrame
,
311 const SwRect
& _rRect
,
312 PrepareHint _eHint
) = 0;
314 // accessors to the current relative position (relative to anchor
315 // position of anchor frame)
316 const Point
& GetCurrRelPos() const { return maRelPos
;}
317 void SetCurrRelPos( Point _aRelPos
);
319 // accessors to the format
320 virtual SwFrameFormat
* GetFrameFormat() = 0;
321 virtual const SwFrameFormat
* GetFrameFormat() const = 0;
323 // accessors to the object area and its position
324 virtual SwRect
GetObjRect() const = 0;
326 void SetObjTop( const SwTwips _nTop
);
327 void SetObjLeft( const SwTwips _nLeft
);
329 /** method update layout direction the layout direction, the anchored
330 object is assigned to
332 method has typically to be called, if the anchored object gets its
333 anchor frame assigned and if the anchor frame changes its layout direction
335 virtual void UpdateLayoutDir();
337 /** method to determine object area inclusive its spacing */
338 SW_DLLPUBLIC
const SwRect
& GetObjRectWithSpaces() const;
340 void InvalidateObjRectWithSpaces() const
342 mbObjRectWithSpacesValid
= false;
345 /** method to determine, if wrapping style influence of the anchored
346 object has to be considered on the object positioning
348 Note: result of this method also decides, if the boolean for the
349 layout process are of relevance.
351 bool ConsiderObjWrapInfluenceOnObjPos() const;
353 // accessors to booleans for layout process
354 bool ConsiderForTextWrap() const;
355 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap
);
356 bool PositionLocked() const;
359 mbPositionLocked
= true;
361 void UnlockPosition()
363 if ( !mbKeepPositionLockedForSection
)
365 mbPositionLocked
= false;
369 void SetKeepPosLocked( const bool _bKeepPosLocked
)
371 mbKeepPositionLockedForSection
= _bKeepPosLocked
;
374 bool RestartLayoutProcess() const;
375 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess
);
376 // accessors for <mbClearedEnvironment>
377 bool ClearedEnvironment() const;
378 void SetClearedEnvironment( const bool _bClearedEnvironment
);
380 // reset booleans for layout process
381 void ResetLayoutProcessBools()
383 mbPositioningInProgress
= false;
384 mbConsiderForTextWrap
= false;
385 mbPositionLocked
= false;
386 mbKeepPositionLockedForSection
= false;
387 mbRestartLayoutProcess
= false;
388 mbClearedEnvironment
= false;
389 mbTmpConsiderWrapInfluence
= false;
392 /** method to determine, if due to anchored object size and wrapping
393 style, its layout environment is cleared.
395 bool HasClearedEnvironment() const;
397 /** method to update anchored object in the <SwSortedObjs> lists
399 Method is not proposed to be called during a layout process is
400 running. It has been used on the change of the anchored object
401 attributes, which belongs the sort criteria of <SwSortedObjs>.
402 If document compatibility option 'Consider wrapping style influence
403 on object positioning' is ON, additionally all anchored objects
404 at the anchor frame and all following anchored objects on the page
405 frame are invalidated.
407 void UpdateObjInSortedList();
409 /** method to determine, if a format on the anchored object is possible
411 A format isn't possible, if anchored object is in an invisible layer.
412 Note: method is virtual to refine the conditions for the sub-classes.
414 virtual bool IsFormatPossible() const;
416 /** method to determine if dragging objects off page is allowed
418 Returns true if editor objects can be dragged off page, false otherwise
420 static bool IsDraggingOffPageAllowed(const SwFrameFormat
*);
422 // accessors to member <mbTmpConsiderWrapInfluence>
423 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence
);
424 bool IsTmpConsiderWrapInfluence() const { return mbTmpConsiderWrapInfluence
;}
425 void ClearTmpConsiderWrapInfluence();
427 bool IsForceNotifyNewBackground() { return mbForceNotifyNewBackground
; }
428 void SetForceNotifyNewBackground(bool const b
) { mbForceNotifyNewBackground
= b
; }
430 /** method to determine, if the anchored object is overlapping with a
433 overlapping with a previous column means, that the object overlaps
434 with a column, which is a previous one of the column its anchor
436 Only applied for at-paragraph and at-character anchored objects.
438 bool OverlapsPrevColumn() const;
440 /** method to determine position of anchored object relative to
443 Usage: Needed layout information for WW8 export
445 @return Point - determined relative position
447 Point
GetRelPosToAnchorFrame() const;
449 /** method to determine position of anchored object relative to
452 Usage: Needed layout information for WW8 export
454 If <_bFollowTextFlow> is set and object is anchored inside table,
455 the position relative to the table cell is determined. Output
456 parameter <_obRelToTableCell> reflects this situation
458 @param _bFollowTextFlow
459 input parameter - boolean indicating, if the anchored object has to
460 follow the text flow.
462 @param _obRelToTableCell
463 output parameter - boolean indicating, the determine position is
464 relative to the table cell
466 @return Point - determined relative position
468 Point
GetRelPosToPageFrame( const bool _bFollowTextFlow
,
469 bool& _obRelToTableCell
) const;
471 /** method to determine position of anchored object relative to
474 Usage: Needed layout information for WW8 export
476 @return Point - determined relative position
478 Point
GetRelPosToChar() const;
480 /** method to determine position of anchored object relative to
483 Usage: Needed layout information for WW8 export
485 @return Point - determined relative position
487 Point
GetRelPosToLine() const;
489 /** Dump a bunch of useful data to an XML representation to ease
490 layout understanding, debugging and testing.
492 virtual void dumpAsXml( xmlTextWriterPtr pWriter
= nullptr ) const;
494 /** The element name to show in the XML dump. */
495 virtual const char* getElementName( ) const { return "SwAnchoredObject"; }
497 virtual const SwFlyFrame
* DynCastFlyFrame() const;
498 virtual SwFlyFrame
* DynCastFlyFrame();
501 /// Helper class for notify that positioning of an anchored object is in progress.
502 class SwObjPositioningInProgress
505 SwAnchoredObject
* mpAnchoredObj
;
506 // boolean indicating old state
507 // of anchored object regarding positioning in progress in order to
508 // consider nested usage of class <SwObjPositioningInProgress>
509 bool mbOldObjPositioningInProgress
;
512 SwObjPositioningInProgress( SdrObject
& _rSdrObj
);
513 SwObjPositioningInProgress( SwAnchoredObject
& _rAnchoredObj
);
514 ~SwObjPositioningInProgress();
517 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */