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 <tools/rtti.hxx>
23 #include <swtypes.hxx>
25 #include <libxml/xmlwriter.h>
33 class SwObjPositioningInProgress
;
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 <SwFlyFrm>) and of drawing objects
42 (derived classes of <SwDrawFrm>).
46 class SW_DLLPUBLIC SwAnchoredObject
49 // drawing object representing the anchored object in the drawing layer
51 // frame the object is anchored at
53 // #i28701 - page frame the object is registered at
54 // note: no page frame for as-character anchored objects
56 // current relative position (relative to anchor position of anchor frame)
59 // for to-character anchored objects:
60 // Last known anchor character rectangle.
61 // Used to decide, if invalidation has to been performed, if anchor position
62 // has changed, and used to position object.
63 SwRect maLastCharRect
;
65 // for to-character anchored objects:
66 // Last known top of line, in which the anchor character is in.
67 // Used to decide, if invalidation has to been performed, if anchor position
68 // has changed, and used to position object.
69 SwTwips mnLastTopOfLine
;
71 // for to-paragraph and to-character anchored objects:
72 // Layout frame vertical position is orient at - typically its the upper
73 // of the anchor frame, but it could also by the upper of a follow or
74 // a following layout frame in the text flow.
75 const SwLayoutFrm
* mpVertPosOrientFrm
;
77 // i#i28701 boolean, indicating that the object
78 // positioning algorithm is in progress.
79 bool mbPositioningInProgress
;
81 // Booleans needed for the layout process.
82 // Values only of relevance for to-paragraph and to-character anchored
83 // floating screen object, for whose the 'straight-forward positioning
84 // process are applied
85 // Otherwise value of <mbConsiderForTextWrap> is treated as <true>,
86 // value of <mbPositionLocked> is treated as <false> and
87 // value of <mbRestartLayoutProcess> is treated as <false>.
88 // i#35911 - add boolean <mbClearEnvironment>
89 // Indicates that due to its position and wrapping style its layout
90 // environment is cleared - all content is moved forward.
91 // Treated as <false>, if not the 'straight-forward positioning process"
93 bool mbConsiderForTextWrap
;
94 bool mbPositionLocked
;
95 // boolean needed to keep position of
96 // anchored object locked due to special object positioning for sections.
97 bool mbKeepPositionLockedForSection
;
99 bool mbRestartLayoutProcess
;
100 bool mbClearedEnvironment
;
102 // i#i3317 - boolean, indicating that temporarly
103 // the wrapping style influence of the anchored object has to be
104 // considered during its positioning.
105 // This boolean is used, if compatibility option 'Consider wrapping style
106 // influence on object positioning' is OFF and a positioning loop is
107 // detected in method <SwFlyAtCntFrm::MakeAll()> or method
108 // <SwAnchoredDrawObject::_MakeObjPosAnchoredAtPara()>.
109 // The boolean is reset to <false>, when the layout process for a
110 // page frame starts.
111 bool mbTmpConsiderWrapInfluence
;
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
123 friend class SwObjPositioningInProgress
;
124 inline void SetPositioningInProgress( const bool _bPosInProgress
)
126 mbPositioningInProgress
= _bPosInProgress
;
129 /** check anchor character rectangle
131 helper method for method <CheckCharRectAndTopOfLine()>
132 For to-character anchored Writer fly frames the member <maLastCharRect>
133 is updated. This is checked for change and depending on the applied
134 positioning, it's decided, if the Writer fly frame has to be invalidated.
135 improvement - add second parameter <_rAnchorCharFrm>
140 input parameter - reference to anchor position
142 @param _rAnchorCharFrm
143 input parameter - reference to the text frame containing the anchor
146 void _CheckCharRect( const SwFormatAnchor
& _rAnch
,
147 const SwTextFrm
& _rAnchorCharFrm
);
149 /** check top of line
151 helper method for method <CheckCharRectAndTopOfLine()>
152 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
153 is updated. This is checked for change and depending on the applied
154 positioning, it's decided, if the Writer fly frame has to be invalidated.
159 input parameter - reference to anchor position
161 @param _rAnchorCharFrm
162 input parameter - reference to the text frame containing the anchor
165 void _CheckTopOfLine( const SwFormatAnchor
& _rAnch
,
166 const SwTextFrm
& _rAnchorCharFrm
);
168 // method <sw_HideObj(..)> sets needed data structure values for the
169 // object positioning
170 friend bool sw_HideObj( const SwTextFrm
& _rFrm
,
171 const RndStdIds _eAnchorType
,
172 const sal_Int32 _nObjAnchorPos
,
173 SwAnchoredObject
* _pAnchoredObj
);
177 void SetVertPosOrientFrm( const SwLayoutFrm
& _rVertPosOrientFrm
);
179 /** method to assure that anchored object is registered at the correct
184 virtual void RegisterAtCorrectPage() = 0;
186 /** method to indicate, that anchored object is attached to a anchor frame
190 virtual void ObjectAttachedToAnchorFrame();
192 /** method to determine, if other anchored objects, also attached at
193 to the anchor frame, have to consider its wrap influence.
197 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
199 /** method to apply temporary consideration of wrapping style influence
200 to the anchored objects, which are anchored at the same anchor frame
204 void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence
);
206 virtual bool _SetObjTop( const SwTwips _nTop
) = 0;
207 virtual bool _SetObjLeft( const SwTwips _nLeft
) = 0;
209 virtual const SwRect
GetObjBoundRect() const = 0;
213 virtual ~SwAnchoredObject();
215 // accessors to member <mpDrawObj>
216 void SetDrawObj( SdrObject
& _rDrawObj
);
217 const SdrObject
* GetDrawObj() const { return mpDrawObj
;}
218 SdrObject
* DrawObj() { return mpDrawObj
;}
220 // accessors to member <mpAnchorFrm>
221 const SwFrm
* GetAnchorFrm() const { return mpAnchorFrm
;}
222 SwFrm
* AnchorFrm() { return mpAnchorFrm
;}
223 void ChgAnchorFrm( SwFrm
* _pNewAnchorFrm
);
224 /** determine anchor frame containing the anchor position
226 the anchor frame, which is determined, is <mpAnchorFrm>
227 for an at-page, at-frame or at-paragraph anchored object
228 and the anchor character frame for an at-character and as-character
233 SwFrm
* GetAnchorFrmContainingAnchPos();
235 SwPageFrm
* GetPageFrm() { return mpPageFrm
;}
236 const SwPageFrm
* GetPageFrm() const { return mpPageFrm
;}
237 void SetPageFrm( SwPageFrm
* _pNewPageFrm
);
239 /** method to determine the page frame, on which the 'anchor' of
240 the given anchored object is.
242 Adjust meaning of method and thus its name: If the anchored object
243 or its anchor isn't correctly inserted in the layout, no page frame
244 can be found. Thus, the return type changed to be a pointer and can
250 input parameter - anchored object, for which the page frame of its
251 'anchor' has to be determined.
254 page frame, the 'anchor' of the given anchored object is on
256 SwPageFrm
* FindPageFrmOfAnchor();
258 /** get frame, which contains the anchor character, if the object
259 is anchored at-character or as-character.
264 text frame containing the anchor character. It's NULL, if the object
265 isn't anchored at-character resp. as-character.
267 SwTextFrm
* FindAnchorCharFrm();
269 // accessors to data of position calculation:
270 // frame vertical position is orient at
271 const SwLayoutFrm
* GetVertPosOrientFrm() const
273 return mpVertPosOrientFrm
;
275 // method to clear member <mpVertPosOrientFrm>
276 void ClearVertPosOrientFrm();
278 /** check anchor character rectangle and top of line
280 For to-character anchored Writer fly frames the members <maLastCharRect>
281 and <maLastTopOfLine> are updated. These are checked for change and
282 depending on the applied positioning, it's decided, if the Writer fly
283 frame has to be invalidated.
287 @param _bCheckForParaPorInf
288 input parameter - boolean indicating, if check on paragraph portion
289 information has to be done.
291 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf
= true );
293 // accessors to member <maLastCharRect>
294 const SwRect
& GetLastCharRect() const { return maLastCharRect
;}
295 SwTwips
GetRelCharX( const SwFrm
* pFrm
) const;
296 SwTwips
GetRelCharY( const SwFrm
* pFrm
) const;
297 void AddLastCharY( long nDiff
);
298 void ResetLastCharRectHeight();
300 // accessor to member <nmLastTopOfLine>
301 SwTwips
GetLastTopOfLine() const { return mnLastTopOfLine
;}
302 void AddLastTopOfLineY( SwTwips _nDiff
);
304 /** reset members <maLastCharRect> and <mnLastTopOfLine>
308 void ClearCharRectAndTopOfLine();
310 /** method to determine position for the object and set the position
315 virtual void MakeObjPos() = 0;
317 /** is positioning of anchored object in progress
321 inline bool IsPositioningInProgress() const
323 return mbPositioningInProgress
;
326 /** method to determine, if invalidation of position is allowed
330 bool InvalidationOfPosAllowed() const;
332 /** method to invalidate position of the anchored object
336 virtual void InvalidateObjPos() = 0;
338 /** method to perform necessary invalidations for the positioning of
339 objects, for whose the wrapping style influence has to be considered
340 on the object positioning.
344 void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd
);
346 /** method to trigger notification of 'background'
350 virtual void NotifyBackground( SwPageFrm
* _pPageFrm
,
351 const SwRect
& _rRect
,
352 PrepareHint _eHint
) = 0;
354 // accessors to the current relative position (relative to anchor
355 // position of anchor frame)
356 const Point
GetCurrRelPos() const { return maRelPos
;}
357 void SetCurrRelPos( Point _aRelPos
);
359 // accessors to the format
360 virtual SwFrameFormat
& GetFrameFormat() = 0;
361 virtual const SwFrameFormat
& GetFrameFormat() const = 0;
363 // accessors to the object area and its position
364 virtual const SwRect
GetObjRect() const = 0;
366 void SetObjTop( const SwTwips _nTop
);
367 void SetObjLeft( const SwTwips _nLeft
);
369 /** method update layout direction the layout direction, the anchored
370 object is assigned to
372 method has typically to be called, if the anchored object gets its
373 anchor frame assigned and if the anchor frame changes its layout direction
377 virtual void UpdateLayoutDir();
379 /** method to determine object area inclusive its spacing
383 const SwRect
& GetObjRectWithSpaces() const;
385 inline void InvalidateObjRectWithSpaces() const
387 mbObjRectWithSpacesValid
= false;
390 /** method to determine, if wrapping style influence of the anchored
391 object has to be considered on the object positioning
393 Note: result of this method also decides, if the boolean for the
394 layout process are of relevance.
398 bool ConsiderObjWrapInfluenceOnObjPos() const;
400 // accessors to booleans for layout process
401 bool ConsiderForTextWrap() const;
402 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap
);
403 bool PositionLocked() const;
404 inline void LockPosition()
406 mbPositionLocked
= true;
408 inline void UnlockPosition()
410 if ( !mbKeepPositionLockedForSection
)
412 mbPositionLocked
= false;
416 inline void SetKeepPosLocked( const bool _bKeepPosLocked
)
418 mbKeepPositionLockedForSection
= _bKeepPosLocked
;
421 bool RestartLayoutProcess() const;
422 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess
);
423 // accessors for <mbClearedEnvironment>
424 bool ClearedEnvironment() const;
425 void SetClearedEnvironment( const bool _bClearedEnvironment
);
427 // reset booleans for layout process
428 inline void ResetLayoutProcessBools()
430 mbPositioningInProgress
= false;
431 mbConsiderForTextWrap
= false;
432 mbPositionLocked
= false;
433 mbKeepPositionLockedForSection
= false;
434 mbRestartLayoutProcess
= false;
435 mbClearedEnvironment
= false;
436 mbTmpConsiderWrapInfluence
= false;
439 /** method to determine, if due to anchored object size and wrapping
440 style, its layout environment is cleared.
444 bool HasClearedEnvironment() const;
446 /** method to update anchored object in the <SwSortedObjs> lists
448 Method is not proposed to be called during a layout process is
449 running. It has been used on the change of the anchored object
450 attributes, which belongs the sort criteria of <SwSortedObjs>.
451 If document compatibility option 'Consider wrapping style influence
452 on object positioning' is ON, additionally all anchored objects
453 at the anchor frame and all following anchored objects on the page
454 frame are invalidated.
458 void UpdateObjInSortedList();
460 /** method to determine, if a format on the anchored object is possible
462 A format isn't possible, if anchored object is in an invisible layer.
463 Note: method is virtual to refine the conditions for the sub-classes.
467 virtual bool IsFormatPossible() const;
469 // accessors to member <mbTmpConsiderWrapInfluence>
470 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence
);
471 bool IsTmpConsiderWrapInfluence() const { return mbTmpConsiderWrapInfluence
;}
473 /** method to determine, if the anchored object is overlapping with a
476 overlapping with a previous column means, that the object overlaps
477 with a column, which is a previous one of the column its anchor
479 Only applied for at-paragraph and at-character anchored objects.
483 bool OverlapsPrevColumn() const;
485 /** method to determine position of anchored object relative to
488 Usage: Needed layout information for WW8 export
492 @return Point - determined relative position
494 Point
GetRelPosToAnchorFrm() const;
496 /** method to determine position of anchored object relative to
499 Usage: Needed layout information for WW8 export
501 If <_bFollowTextFlow> is set and object is anchored inside table,
502 the position relative to the table cell is determined. Output
503 parameter <_obRelToTableCell> reflects this situation
507 @param _bFollowTextFlow
508 input parameter - boolean indicating, if the anchored object has to
509 follow the text flow.
511 @param _obRelToTableCell
512 output parameter - boolean indicating, the determine position is
513 relative to the table cell
515 @return Point - determined relative position
517 Point
GetRelPosToPageFrm( const bool _bFollowTextFlow
,
518 bool& _obRelToTableCell
) const;
520 /** method to determine position of anchored object relative to
523 Usage: Needed layout information for WW8 export
527 @return Point - determined relative position
529 Point
GetRelPosToChar() const;
531 /** method to determine position of anchored object relative to
534 Usage: Needed layout information for WW8 export
538 @return Point - determined relative position
540 Point
GetRelPosToLine() const;
542 /** Dump a bunch of useful data to an XML representation to ease
543 layout understanding, debugging and testing.
545 virtual void dumpAsXml( xmlTextWriterPtr pWriter
) const;
547 /** The element name to show in the XML dump.
549 virtual const char* getElementName( ) const { return "SwAnchoredObject"; }
552 /// Helper class for notify that positioning of an anchored object is in progress.
553 class SwObjPositioningInProgress
556 SwAnchoredObject
* mpAnchoredObj
;
557 // boolean indicating old state
558 // of anchored object regarding positioning in progress in order to
559 // consider nested usage of class <SwObjPositioningInProgress>
560 bool mbOldObjPositioningInProgress
;
563 SwObjPositioningInProgress( SdrObject
& _rSdrObj
);
564 SwObjPositioningInProgress( SwAnchoredObject
& _rAnchoredObj
);
565 ~SwObjPositioningInProgress();
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */