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 <svx/svdobj.hxx>
25 #include <libxml/xmlwriter.h>
38 /** wrapper class for the positioning of Writer fly frames and drawing objects
40 Purpose of this class is to provide a unified interface for the positioning
41 of Writer fly frames (derived classes of <SwFlyFrame>) and of drawing objects
42 (derived classes of <SwAnchoredDrawObject>).
44 class SW_DLLPUBLIC SwAnchoredObject
47 // drawing object representing the anchored object in the drawing layer
48 rtl::Reference
<SdrObject
> mpDrawObj
;
49 /// Frame the object is anchored at.
50 /// For at-char/at-para anchor, this is always the master SwTextFrame.
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 bool mbForceNotifyNewBackground
= false;
114 mutable SwRect maObjRectWithSpaces
;
115 mutable bool mbObjRectWithSpacesValid
;
116 mutable SwRect maLastObjRect
;
118 /** method to indicate, that positioning of anchored object is in progress
120 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>
137 input parameter - reference to anchor position
139 @param _rAnchorCharFrame
140 input parameter - reference to the text frame containing the anchor
143 void CheckCharRect( const SwFormatAnchor
& _rAnch
,
144 const SwTextFrame
& _rAnchorCharFrame
);
146 /** check top of line
148 helper method for method <CheckCharRectAndTopOfLine()>
149 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
150 is updated. This is checked for change and depending on the applied
151 positioning, it's decided, if the Writer fly frame has to be invalidated.
154 input parameter - reference to anchor position
156 @param _rAnchorCharFrame
157 input parameter - reference to the text frame containing the anchor
160 void CheckTopOfLine( const SwFormatAnchor
& _rAnch
,
161 const SwTextFrame
& _rAnchorCharFrame
);
163 // method <sw_HideObj(..)> sets needed data structure values for the
164 // object positioning
165 friend bool sw_HideObj( const SwTextFrame
& _rFrame
,
166 const RndStdIds _eAnchorType
,
167 SwFormatAnchor
const& rFormatAnchor
,
168 SwAnchoredObject
* _pAnchoredObj
);
172 void SetVertPosOrientFrame( const SwLayoutFrame
& _rVertPosOrientFrame
);
174 /** method to assure that anchored object is registered at the correct
177 virtual void RegisterAtCorrectPage() = 0;
179 /** method to indicate, that anchored object is attached to an anchor frame */
180 virtual void ObjectAttachedToAnchorFrame();
182 /** method to determine, if other anchored objects, also attached at
183 to the anchor frame, have to consider its wrap influence.
185 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
187 /** method to apply temporary consideration of wrapping style influence
188 to the anchored objects, which are anchored at the same anchor frame
190 void SetTmpConsiderWrapInfluenceOfOtherObjs();
192 virtual bool SetObjTop_( const SwTwips _nTop
) = 0;
193 virtual bool SetObjLeft_( const SwTwips _nLeft
) = 0;
195 virtual SwRect
GetObjBoundRect() const = 0;
198 virtual ~SwAnchoredObject();
200 // accessors to member <mpDrawObj>
201 void SetDrawObj( SdrObject
& _rDrawObj
);
202 const SdrObject
* GetDrawObj() const { return mpDrawObj
.get(); }
203 SdrObject
* DrawObj() { return mpDrawObj
.get(); }
204 void ClearDrawObj() { mpDrawObj
.clear(); }
206 // accessors to member <mpAnchorFrame>
207 const SwFrame
* GetAnchorFrame() const { return mpAnchorFrame
; }
208 SwFrame
* AnchorFrame() { return mpAnchorFrame
; }
209 void ChgAnchorFrame( SwFrame
* _pNewAnchorFrame
);
210 /** determine anchor frame containing the anchor position
212 the anchor frame, which is determined, is <mpAnchorFrame>
213 for an at-page, at-frame or at-paragraph anchored object
214 and the anchor character frame for an at-character and as-character
217 SwFrame
* GetAnchorFrameContainingAnchPos();
219 SwPageFrame
* GetPageFrame() { return mpPageFrame
; }
220 const SwPageFrame
* GetPageFrame() const { return mpPageFrame
; }
221 void SetPageFrame( SwPageFrame
* _pNewPageFrame
);
223 /** method to determine the page frame, on which the 'anchor' of
224 the given anchored object is.
226 Adjust meaning of method and thus its name: If the anchored object
227 or its anchor isn't correctly inserted in the layout, no page frame
228 can be found. Thus, the return type changed to be a pointer and can
232 input parameter - anchored object, for which the page frame of its
233 'anchor' has to be determined.
236 page frame, the 'anchor' of the given anchored object is on
238 SwPageFrame
* FindPageFrameOfAnchor();
240 /** get frame, which contains the anchor character, if the object
241 is anchored at-character or as-character.
244 text frame containing the anchor character. It's NULL, if the object
245 isn't anchored at-character resp. as-character.
247 SwTextFrame
* FindAnchorCharFrame();
249 // accessors to data of position calculation:
250 // frame vertical position is orient at
251 const SwLayoutFrame
* GetVertPosOrientFrame() const
253 return mpVertPosOrientFrame
;
255 // method to clear member <mpVertPosOrientFrame>
256 void ClearVertPosOrientFrame();
258 /** check anchor character rectangle and top of line
260 For to-character anchored Writer fly frames the members <maLastCharRect>
261 and <maLastTopOfLine> are updated. These are checked for change and
262 depending on the applied positioning, it's decided, if the Writer fly
263 frame has to be invalidated.
265 @param _bCheckForParaPorInf
266 input parameter - boolean indicating, if check on paragraph portion
267 information has to be done.
269 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf
);
271 // accessors to member <maLastCharRect>
272 const SwRect
& GetLastCharRect() const { return maLastCharRect
;}
273 SwTwips
GetRelCharX( const SwFrame
* pFrame
) const;
274 SwTwips
GetRelCharY( const SwFrame
* pFrame
) const;
275 void AddLastCharY( tools::Long nDiff
);
276 void ResetLastCharRectHeight();
278 // accessor to member <nmLastTopOfLine>
279 SwTwips
GetLastTopOfLine() const { return mnLastTopOfLine
;}
280 void AddLastTopOfLineY( SwTwips _nDiff
);
282 /** reset members <maLastCharRect> and <mnLastTopOfLine> */
283 void ClearCharRectAndTopOfLine();
285 /** method to determine position for the object and set the position
288 virtual void MakeObjPos() = 0;
290 /** is positioning of anchored object in progress */
291 bool IsPositioningInProgress() const
293 return mbPositioningInProgress
;
296 /** method to determine, if invalidation of position is allowed */
297 bool InvalidationOfPosAllowed() const;
299 /** method to invalidate position of the anchored object */
300 virtual void InvalidateObjPos() = 0;
302 virtual void RegisterAtPage(SwPageFrame
&) = 0;
304 /** method to perform necessary invalidations for the positioning of
305 objects, for whose the wrapping style influence has to be considered
306 on the object positioning.
308 void InvalidateObjPosForConsiderWrapInfluence();
310 /** method to trigger notification of 'background' */
311 virtual void NotifyBackground( SwPageFrame
* _pPageFrame
,
312 const SwRect
& _rRect
,
313 PrepareHint _eHint
) = 0;
315 // accessors to the current relative position (relative to anchor
316 // position of anchor frame)
317 const Point
& GetCurrRelPos() const { return maRelPos
;}
318 void SetCurrRelPos( Point _aRelPos
);
320 // accessors to the format
321 virtual SwFrameFormat
& GetFrameFormat() = 0;
322 virtual const SwFrameFormat
& GetFrameFormat() const = 0;
324 // accessors to the object area and its position
325 virtual SwRect
GetObjRect() const = 0;
327 void SetObjTop( const SwTwips _nTop
);
328 void SetObjLeft( const SwTwips _nLeft
);
330 /** method update layout direction the layout direction, the anchored
331 object is assigned to
333 method has typically to be called, if the anchored object gets its
334 anchor frame assigned and if the anchor frame changes its layout direction
336 virtual void UpdateLayoutDir();
338 /** method to determine object area inclusive its spacing */
339 const SwRect
& GetObjRectWithSpaces() const;
341 void InvalidateObjRectWithSpaces() const
343 mbObjRectWithSpacesValid
= false;
346 /** method to determine, if wrapping style influence of the anchored
347 object has to be considered on the object positioning
349 Note: result of this method also decides, if the boolean for the
350 layout process are of relevance.
352 bool ConsiderObjWrapInfluenceOnObjPos() const;
354 // accessors to booleans for layout process
355 bool ConsiderForTextWrap() const;
356 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap
);
357 bool PositionLocked() const;
360 mbPositionLocked
= true;
362 void UnlockPosition()
364 if ( !mbKeepPositionLockedForSection
)
366 mbPositionLocked
= false;
370 void SetKeepPosLocked( const bool _bKeepPosLocked
)
372 mbKeepPositionLockedForSection
= _bKeepPosLocked
;
375 bool RestartLayoutProcess() const;
376 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess
);
377 // accessors for <mbClearedEnvironment>
378 bool ClearedEnvironment() const;
379 void SetClearedEnvironment( const bool _bClearedEnvironment
);
381 // reset booleans for layout process
382 void ResetLayoutProcessBools()
384 mbPositioningInProgress
= false;
385 mbConsiderForTextWrap
= false;
386 mbPositionLocked
= false;
387 mbKeepPositionLockedForSection
= false;
388 mbRestartLayoutProcess
= false;
389 mbClearedEnvironment
= false;
390 mbTmpConsiderWrapInfluence
= false;
393 /** method to determine, if due to anchored object size and wrapping
394 style, its layout environment is cleared.
396 bool HasClearedEnvironment() const;
398 /** method to update anchored object in the <SwSortedObjs> lists
400 Method is not proposed to be called during a layout process is
401 running. It has been used on the change of the anchored object
402 attributes, which belongs the sort criteria of <SwSortedObjs>.
403 If document compatibility option 'Consider wrapping style influence
404 on object positioning' is ON, additionally all anchored objects
405 at the anchor frame and all following anchored objects on the page
406 frame are invalidated.
408 void UpdateObjInSortedList();
410 /** method to determine, if a format on the anchored object is possible
412 A format isn't possible, if anchored object is in an invisible layer.
413 Note: method is virtual to refine the conditions for the sub-classes.
415 virtual bool IsFormatPossible() const;
417 /** method to determine if dragging objects off page is allowed
419 Returns true if editor objects can be dragged off page, false otherwise
421 static bool IsDraggingOffPageAllowed(const SwFrameFormat
*);
423 // accessors to member <mbTmpConsiderWrapInfluence>
424 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence
);
425 bool IsTmpConsiderWrapInfluence() const { return mbTmpConsiderWrapInfluence
;}
426 void ClearTmpConsiderWrapInfluence();
428 bool IsForceNotifyNewBackground() { return mbForceNotifyNewBackground
; }
429 void SetForceNotifyNewBackground(bool const b
) { mbForceNotifyNewBackground
= b
; }
431 /** method to determine, if the anchored object is overlapping with a
434 overlapping with a previous column means, that the object overlaps
435 with a column, which is a previous one of the column its anchor
437 Only applied for at-paragraph and at-character anchored objects.
439 bool OverlapsPrevColumn() const;
441 /** method to determine position of anchored object relative to
444 Usage: Needed layout information for WW8 export
446 @return Point - determined relative position
448 Point
GetRelPosToAnchorFrame() const;
450 /** method to determine position of anchored object relative to
453 Usage: Needed layout information for WW8 export
455 If <_bFollowTextFlow> is set and object is anchored inside table,
456 the position relative to the table cell is determined. Output
457 parameter <_obRelToTableCell> reflects this situation
459 @param _bFollowTextFlow
460 input parameter - boolean indicating, if the anchored object has to
461 follow the text flow.
463 @param _obRelToTableCell
464 output parameter - boolean indicating, the determine position is
465 relative to the table cell
467 @return Point - determined relative position
469 Point
GetRelPosToPageFrame( const bool _bFollowTextFlow
,
470 bool& _obRelToTableCell
) const;
472 /** method to determine position of anchored object relative to
475 Usage: Needed layout information for WW8 export
477 @return Point - determined relative position
479 Point
GetRelPosToChar() const;
481 /** method to determine position of anchored object relative to
484 Usage: Needed layout information for WW8 export
486 @return Point - determined relative position
488 Point
GetRelPosToLine() const;
490 /** Dump a bunch of useful data to an XML representation to ease
491 layout understanding, debugging and testing.
493 virtual void dumpAsXml( xmlTextWriterPtr pWriter
= nullptr ) const;
495 /** The element name to show in the XML dump. */
496 virtual const char* getElementName( ) const { return "SwAnchoredObject"; }
498 virtual const SwFlyFrame
* DynCastFlyFrame() const;
499 virtual SwFlyFrame
* DynCastFlyFrame();
502 /// Helper class for notify that positioning of an anchored object is in progress.
503 class SwObjPositioningInProgress
506 SwAnchoredObject
* mpAnchoredObj
;
507 // boolean indicating old state
508 // of anchored object regarding positioning in progress in order to
509 // consider nested usage of class <SwObjPositioningInProgress>
510 bool mbOldObjPositioningInProgress
;
513 SwObjPositioningInProgress( SdrObject
& _rSdrObj
);
514 SwObjPositioningInProgress( SwAnchoredObject
& _rAnchoredObj
);
515 ~SwObjPositioningInProgress();
520 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */