Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / anchoredobject.hxx
blob1db20eaf494c6d827cd64496310dc17779f22b2f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include "swrect.hxx"
24 #include <libxml/xmlwriter.h>
26 struct SwPosition;
27 class SdrObject;
28 class SwFrame;
29 class SwLayoutFrame;
30 class SwTextFrame;
32 class SwPageFrame;
34 class SwFrameFormat;
35 class SwFormatAnchor;
36 enum class RndStdIds;
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
46 private:
47 // drawing object representing the anchored object in the drawing layer
48 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)
56 Point maRelPos;
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"
91 // is applied.
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
120 friend class SwObjPositioningInProgress;
121 void SetPositioningInProgress( const bool _bPosInProgress )
123 mbPositioningInProgress = _bPosInProgress;
126 /** check anchor character rectangle
128 helper method for method <CheckCharRectAndTopOfLine()>
129 For to-character anchored Writer fly frames the member <maLastCharRect>
130 is updated. This is checked for change and depending on the applied
131 positioning, it's decided, if the Writer fly frame has to be invalidated.
132 improvement - add second parameter <_rAnchorCharFrame>
134 @param _rAnch
135 input parameter - reference to anchor position
137 @param _rAnchorCharFrame
138 input parameter - reference to the text frame containing the anchor
139 character.
141 void CheckCharRect( const SwFormatAnchor& _rAnch,
142 const SwTextFrame& _rAnchorCharFrame );
144 /** check top of line
146 helper method for method <CheckCharRectAndTopOfLine()>
147 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
148 is updated. This is checked for change and depending on the applied
149 positioning, it's decided, if the Writer fly frame has to be invalidated.
151 @param _rAnch
152 input parameter - reference to anchor position
154 @param _rAnchorCharFrame
155 input parameter - reference to the text frame containing the anchor
156 character.
158 void CheckTopOfLine( const SwFormatAnchor& _rAnch,
159 const SwTextFrame& _rAnchorCharFrame );
161 // method <sw_HideObj(..)> sets needed data structure values for the
162 // object positioning
163 friend bool sw_HideObj( const SwTextFrame& _rFrame,
164 const RndStdIds _eAnchorType,
165 SwPosition const& rAnchorPos,
166 SwAnchoredObject* _pAnchoredObj );
167 protected:
168 SwAnchoredObject();
170 void SetVertPosOrientFrame( const SwLayoutFrame& _rVertPosOrientFrame );
172 /** method to assure that anchored object is registered at the correct
173 page frame
175 virtual void RegisterAtCorrectPage() = 0;
177 /** method to indicate, that anchored object is attached to an anchor frame */
178 virtual void ObjectAttachedToAnchorFrame();
180 /** method to determine, if other anchored objects, also attached at
181 to the anchor frame, have to consider its wrap influence.
183 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
185 /** method to apply temporary consideration of wrapping style influence
186 to the anchored objects, which are anchored at the same anchor frame
188 void SetTmpConsiderWrapInfluenceOfOtherObjs();
190 virtual bool SetObjTop_( const SwTwips _nTop) = 0;
191 virtual bool SetObjLeft_( const SwTwips _nLeft) = 0;
193 virtual SwRect GetObjBoundRect() const = 0;
194 public:
196 virtual ~SwAnchoredObject();
198 // accessors to member <mpDrawObj>
199 void SetDrawObj( SdrObject& _rDrawObj );
200 const SdrObject* GetDrawObj() const { return mpDrawObj; }
201 SdrObject* DrawObj() { return mpDrawObj; }
203 // accessors to member <mpAnchorFrame>
204 const SwFrame* GetAnchorFrame() const { return mpAnchorFrame; }
205 SwFrame* AnchorFrame() { return mpAnchorFrame; }
206 void ChgAnchorFrame( SwFrame* _pNewAnchorFrame );
207 /** determine anchor frame containing the anchor position
209 the anchor frame, which is determined, is <mpAnchorFrame>
210 for an at-page, at-frame or at-paragraph anchored object
211 and the anchor character frame for an at-character and as-character
212 anchored object.
214 SwFrame* GetAnchorFrameContainingAnchPos();
216 SwPageFrame* GetPageFrame() { return mpPageFrame; }
217 const SwPageFrame* GetPageFrame() const { return mpPageFrame; }
218 void SetPageFrame( SwPageFrame* _pNewPageFrame );
220 /** method to determine the page frame, on which the 'anchor' of
221 the given anchored object is.
223 Adjust meaning of method and thus its name: If the anchored object
224 or its anchor isn't correctly inserted in the layout, no page frame
225 can be found. Thus, the return type changed to be a pointer and can
226 be NULL.
228 @param _rAnchoredObj
229 input parameter - anchored object, for which the page frame of its
230 'anchor' has to be determined.
232 @return SwPageFrame&
233 page frame, the 'anchor' of the given anchored object is on
235 SwPageFrame* FindPageFrameOfAnchor();
237 /** get frame, which contains the anchor character, if the object
238 is anchored at-character or as-character.
240 @return SwTextFrame*
241 text frame containing the anchor character. It's NULL, if the object
242 isn't anchored at-character resp. as-character.
244 SwTextFrame* FindAnchorCharFrame();
246 // accessors to data of position calculation:
247 // frame vertical position is orient at
248 const SwLayoutFrame* GetVertPosOrientFrame() const
250 return mpVertPosOrientFrame;
252 // method to clear member <mpVertPosOrientFrame>
253 void ClearVertPosOrientFrame();
255 /** check anchor character rectangle and top of line
257 For to-character anchored Writer fly frames the members <maLastCharRect>
258 and <maLastTopOfLine> are updated. These are checked for change and
259 depending on the applied positioning, it's decided, if the Writer fly
260 frame has to be invalidated.
262 @param _bCheckForParaPorInf
263 input parameter - boolean indicating, if check on paragraph portion
264 information has to be done.
266 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf );
268 // accessors to member <maLastCharRect>
269 const SwRect& GetLastCharRect() const { return maLastCharRect;}
270 SwTwips GetRelCharX( const SwFrame* pFrame ) const;
271 SwTwips GetRelCharY( const SwFrame* pFrame ) const;
272 void AddLastCharY( tools::Long nDiff );
273 void ResetLastCharRectHeight();
275 // accessor to member <nmLastTopOfLine>
276 SwTwips GetLastTopOfLine() const { return mnLastTopOfLine;}
277 void AddLastTopOfLineY( SwTwips _nDiff );
279 /** reset members <maLastCharRect> and <mnLastTopOfLine> */
280 void ClearCharRectAndTopOfLine();
282 /** method to determine position for the object and set the position
283 at the object
285 virtual void MakeObjPos() = 0;
287 /** is positioning of anchored object in progress */
288 bool IsPositioningInProgress() const
290 return mbPositioningInProgress;
293 /** method to determine, if invalidation of position is allowed */
294 bool InvalidationOfPosAllowed() const;
296 /** method to invalidate position of the anchored object */
297 virtual void InvalidateObjPos() = 0;
299 virtual void RegisterAtPage(SwPageFrame &) = 0;
301 /** method to perform necessary invalidations for the positioning of
302 objects, for whose the wrapping style influence has to be considered
303 on the object positioning.
305 void InvalidateObjPosForConsiderWrapInfluence();
307 /** method to trigger notification of 'background' */
308 virtual void NotifyBackground( SwPageFrame* _pPageFrame,
309 const SwRect& _rRect,
310 PrepareHint _eHint ) = 0;
312 // accessors to the current relative position (relative to anchor
313 // position of anchor frame)
314 const Point& GetCurrRelPos() const { return maRelPos;}
315 void SetCurrRelPos( Point _aRelPos );
317 // accessors to the format
318 virtual SwFrameFormat& GetFrameFormat() = 0;
319 virtual const SwFrameFormat& GetFrameFormat() const = 0;
321 // accessors to the object area and its position
322 virtual SwRect GetObjRect() const = 0;
324 void SetObjTop( const SwTwips _nTop);
325 void SetObjLeft( const SwTwips _nLeft);
327 /** method update layout direction the layout direction, the anchored
328 object is assigned to
330 method has typically to be called, if the anchored object gets its
331 anchor frame assigned and if the anchor frame changes its layout direction
333 virtual void UpdateLayoutDir();
335 /** method to determine object area inclusive its spacing */
336 const SwRect& GetObjRectWithSpaces() const;
338 void InvalidateObjRectWithSpaces() const
340 mbObjRectWithSpacesValid = false;
343 /** method to determine, if wrapping style influence of the anchored
344 object has to be considered on the object positioning
346 Note: result of this method also decides, if the boolean for the
347 layout process are of relevance.
349 bool ConsiderObjWrapInfluenceOnObjPos() const;
351 // accessors to booleans for layout process
352 bool ConsiderForTextWrap() const;
353 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap );
354 bool PositionLocked() const;
355 void LockPosition()
357 mbPositionLocked = true;
359 void UnlockPosition()
361 if ( !mbKeepPositionLockedForSection )
363 mbPositionLocked = false;
367 void SetKeepPosLocked( const bool _bKeepPosLocked )
369 mbKeepPositionLockedForSection = _bKeepPosLocked;
372 bool RestartLayoutProcess() const;
373 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess );
374 // accessors for <mbClearedEnvironment>
375 bool ClearedEnvironment() const;
376 void SetClearedEnvironment( const bool _bClearedEnvironment );
378 // reset booleans for layout process
379 void ResetLayoutProcessBools()
381 mbPositioningInProgress = false;
382 mbConsiderForTextWrap = false;
383 mbPositionLocked = false;
384 mbKeepPositionLockedForSection = false;
385 mbRestartLayoutProcess = false;
386 mbClearedEnvironment = false;
387 mbTmpConsiderWrapInfluence = false;
390 /** method to determine, if due to anchored object size and wrapping
391 style, its layout environment is cleared.
393 bool HasClearedEnvironment() const;
395 /** method to update anchored object in the <SwSortedObjs> lists
397 Method is not proposed to be called during a layout process is
398 running. It has been used on the change of the anchored object
399 attributes, which belongs the sort criteria of <SwSortedObjs>.
400 If document compatibility option 'Consider wrapping style influence
401 on object positioning' is ON, additionally all anchored objects
402 at the anchor frame and all following anchored objects on the page
403 frame are invalidated.
405 void UpdateObjInSortedList();
407 /** method to determine, if a format on the anchored object is possible
409 A format isn't possible, if anchored object is in an invisible layer.
410 Note: method is virtual to refine the conditions for the sub-classes.
412 virtual bool IsFormatPossible() const;
414 /** method to determine if dragging objects off page is allowed
416 Returns true if editor objects can be dragged off page, false otherwise
418 static bool IsDraggingOffPageAllowed(const SwFrameFormat*);
420 // accessors to member <mbTmpConsiderWrapInfluence>
421 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
422 bool IsTmpConsiderWrapInfluence() const { return mbTmpConsiderWrapInfluence;}
423 void ClearTmpConsiderWrapInfluence();
425 /** method to determine, if the anchored object is overlapping with a
426 previous column
428 overlapping with a previous column means, that the object overlaps
429 with a column, which is a previous one of the column its anchor
430 frame is in.
431 Only applied for at-paragraph and at-character anchored objects.
433 bool OverlapsPrevColumn() const;
435 /** method to determine position of anchored object relative to
436 anchor frame
438 Usage: Needed layout information for WW8 export
440 @return Point - determined relative position
442 Point GetRelPosToAnchorFrame() const;
444 /** method to determine position of anchored object relative to
445 page frame
447 Usage: Needed layout information for WW8 export
449 If <_bFollowTextFlow> is set and object is anchored inside table,
450 the position relative to the table cell is determined. Output
451 parameter <_obRelToTableCell> reflects this situation
453 @param _bFollowTextFlow
454 input parameter - boolean indicating, if the anchored object has to
455 follow the text flow.
457 @param _obRelToTableCell
458 output parameter - boolean indicating, the determine position is
459 relative to the table cell
461 @return Point - determined relative position
463 Point GetRelPosToPageFrame( const bool _bFollowTextFlow,
464 bool& _obRelToTableCell ) const;
466 /** method to determine position of anchored object relative to
467 anchor character
469 Usage: Needed layout information for WW8 export
471 @return Point - determined relative position
473 Point GetRelPosToChar() const;
475 /** method to determine position of anchored object relative to
476 top of line
478 Usage: Needed layout information for WW8 export
480 @return Point - determined relative position
482 Point GetRelPosToLine() const;
484 /** Dump a bunch of useful data to an XML representation to ease
485 layout understanding, debugging and testing.
487 virtual void dumpAsXml( xmlTextWriterPtr pWriter ) const;
489 /** The element name to show in the XML dump. */
490 virtual const char* getElementName( ) const { return "SwAnchoredObject"; }
493 /// Helper class for notify that positioning of an anchored object is in progress.
494 class SwObjPositioningInProgress
496 private:
497 SwAnchoredObject* mpAnchoredObj;
498 // boolean indicating old state
499 // of anchored object regarding positioning in progress in order to
500 // consider nested usage of class <SwObjPositioningInProgress>
501 bool mbOldObjPositioningInProgress;
503 public:
504 SwObjPositioningInProgress( SdrObject& _rSdrObj );
505 SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
506 ~SwObjPositioningInProgress();
509 #endif
511 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */