bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / anchoredobject.hxx
blobff4b88ada6440022c10de532e2a04b809c39f2cc
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 _ANCHOREDOBJECT_HXX
20 #define _ANCHOREDOBJECT_HXX
22 #include <tools/rtti.hxx>
23 #include <swtypes.hxx>
24 #include <swrect.hxx>
25 #include <libxml/xmlwriter.h>
27 class SdrObject;
28 class SwFrm;
29 class SwLayoutFrm;
30 class SwTxtFrm;
32 class SwPageFrm;
33 class SwObjPositioningInProgress;
35 class SwFrmFmt;
36 class SwFmtAnchor;
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>).
44 @author OD
46 class SW_DLLPUBLIC SwAnchoredObject
48 private:
49 // drawing object representing the anchored object in the drawing layer
50 SdrObject* mpDrawObj;
51 // frame the object is anchored at
52 SwFrm* mpAnchorFrm;
53 // #i28701 - page frame the object is registered at
54 // note: no page frame for as-character anchored objects
55 SwPageFrm* mpPageFrm;
56 // current relative position (relative to anchor position of anchor frame)
57 Point maRelPos;
59 // for to-character anchored objects:
60 // Last known anchor character retangle.
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"
92 // is applied.
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
121 @author OD
123 friend class SwObjPositioningInProgress;
124 inline void SetPositioningInProgress( const bool _bPosInProgress )
126 mbPositioningInProgress = _bPosInProgress;
130 /** check anchor character rectangle
132 helper method for method <CheckCharRectAndTopOfLine()>
133 For to-character anchored Writer fly frames the member <maLastCharRect>
134 is updated. This is checked for change and depending on the applied
135 positioning, it's decided, if the Writer fly frame has to be invalidated.
136 improvement - add second parameter <_rAnchorCharFrm>
138 @author OD
140 @param _rAnch
141 input parameter - reference to anchor position
143 @param _rAnchorCharFrm
144 input parameter - reference to the text frame containing the anchor
145 character.
147 void _CheckCharRect( const SwFmtAnchor& _rAnch,
148 const SwTxtFrm& _rAnchorCharFrm );
150 /** check top of line
152 helper method for method <CheckCharRectAndTopOfLine()>
153 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
154 is updated. This is checked for change and depending on the applied
155 positioning, it's decided, if the Writer fly frame has to be invalidated.
157 @author OD
159 @param _rAnch
160 input parameter - reference to anchor position
162 @param _rAnchorCharFrm
163 input parameter - reference to the text frame containing the anchor
164 character.
166 void _CheckTopOfLine( const SwFmtAnchor& _rAnch,
167 const SwTxtFrm& _rAnchorCharFrm );
169 // method <sw_HideObj(..)> sets needed data structure values for the
170 // object positioning
171 friend bool sw_HideObj( const SwTxtFrm& _rFrm,
172 const RndStdIds _eAnchorType,
173 const xub_StrLen _nObjAnchorPos,
174 SwAnchoredObject* _pAnchoredObj );
175 protected:
176 SwAnchoredObject();
178 void SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm );
180 /** method to assure that anchored object is registered at the correct
181 page frame
183 @author OD
185 virtual void RegisterAtCorrectPage() = 0;
187 /** method to indicate, that anchored object is attached to a anchor frame
189 @author OD
191 virtual void ObjectAttachedToAnchorFrame();
193 /** method to determine, if other anchored objects, also attached at
194 to the anchor frame, have to consider its wrap influence.
196 @author OD
198 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
200 /** method to apply temporary consideration of wrapping style influence
201 to the anchored objects, which are anchored at the same anchor frame
203 @author OD
205 void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence );
207 virtual bool _SetObjTop( const SwTwips _nTop) = 0;
208 virtual bool _SetObjLeft( const SwTwips _nLeft) = 0;
210 virtual const SwRect GetObjBoundRect() const = 0;
211 public:
212 TYPEINFO();
214 virtual ~SwAnchoredObject();
216 // accessors to member <mpDrawObj>
217 void SetDrawObj( SdrObject& _rDrawObj );
218 const SdrObject* GetDrawObj() const;
219 SdrObject* DrawObj();
221 // accessors to member <mpAnchorFrm>
222 const SwFrm* GetAnchorFrm() const;
223 SwFrm* AnchorFrm();
224 void ChgAnchorFrm( SwFrm* _pNewAnchorFrm );
225 /** determine anchor frame containing the anchor position
227 the anchor frame, which is determined, is <mpAnchorFrm>
228 for an at-page, at-frame or at-paragraph anchored object
229 and the anchor character frame for an at-character and as-character
230 anchored object.
232 @author OD
234 SwFrm* GetAnchorFrmContainingAnchPos();
236 SwPageFrm* GetPageFrm();
237 const SwPageFrm* GetPageFrm() const;
238 void SetPageFrm( SwPageFrm* _pNewPageFrm );
240 /** method to determine the page frame, on which the 'anchor' of
241 the given anchored object is.
243 Adjust meaning of method and thus its name: If the anchored object
244 or its anchor isn't correctly inserted in the layout, no page frame
245 can be found. Thus, the return type changed to be a pointer and can
246 be NULL.
248 @author OD
250 @param _rAnchoredObj
251 input parameter - anchored object, for which the page frame of its
252 'anchor' has to be determined.
254 @return SwPageFrm&
255 page frame, the 'anchor' of the given anchored object is on
257 SwPageFrm* FindPageFrmOfAnchor();
259 /** get frame, which contains the anchor character, if the object
260 is anchored at-character or as-character.
262 @author OD
264 @return SwTxtFrm*
265 text frame containing the anchor character. It's NULL, if the object
266 isn't anchored at-character resp. as-character.
268 SwTxtFrm* FindAnchorCharFrm();
270 // accessors to data of position calculation:
271 // frame vertical position is orient at
272 const SwLayoutFrm* GetVertPosOrientFrm() const
274 return mpVertPosOrientFrm;
276 // method to clear member <mpVertPosOrientFrm>
277 void ClearVertPosOrientFrm();
279 /** check anchor character rectangle and top of line
281 For to-character anchored Writer fly frames the members <maLastCharRect>
282 and <maLastTopOfLine> are updated. These are checked for change and
283 depending on the applied positioning, it's decided, if the Writer fly
284 frame has to be invalidated.
286 @author OD
288 @param _bCheckForParaPorInf
289 input parameter - boolean indicating, if check on paragraph portion
290 information has to be done.
292 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf = true );
294 // accessors to member <maLastCharRect>
295 const SwRect& GetLastCharRect() const;
296 SwTwips GetRelCharX( const SwFrm* pFrm ) const;
297 SwTwips GetRelCharY( const SwFrm* pFrm ) const;
298 void AddLastCharY( long nDiff );
299 void ResetLastCharRectHeight();
301 // accessor to member <nmLastTopOfLine>
302 SwTwips GetLastTopOfLine() const;
303 void AddLastTopOfLineY( SwTwips _nDiff );
305 /** reset members <maLastCharRect> and <mnLastTopOfLine>
307 @author OD
309 void ClearCharRectAndTopOfLine();
311 /** method to determine position for the object and set the position
312 at the object
314 @author OD
316 virtual void MakeObjPos() = 0;
318 /** is positioning of anchored object in progress
320 @author OD
322 inline bool IsPositioningInProgress() const
324 return mbPositioningInProgress;
327 /** method to determine, if invalidation of position is allowed
329 @author OD
331 bool InvalidationOfPosAllowed() const;
333 /** method to invalidate position of the anchored object
335 @author OD
337 virtual void InvalidateObjPos() = 0;
339 /** method to perform necessary invalidations for the positioning of
340 objects, for whose the wrapping style influence has to be considered
341 on the object positioning.
343 @author OD
345 void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd );
347 /** method to trigger notification of 'background'
349 @author OD
351 virtual void NotifyBackground( SwPageFrm* _pPageFrm,
352 const SwRect& _rRect,
353 PrepareHint _eHint ) = 0;
355 // accessors to the current relative position (relative to anchor
356 // position of anchor frame)
357 const Point GetCurrRelPos() const;
358 void SetCurrRelPos( Point _aRelPos );
360 // accessors to the format
361 virtual SwFrmFmt& GetFrmFmt() = 0;
362 virtual const SwFrmFmt& GetFrmFmt() const = 0;
364 // accessors to the object area and its position
365 virtual const SwRect GetObjRect() const = 0;
367 void SetObjTop( const SwTwips _nTop);
368 void SetObjLeft( const SwTwips _nLeft);
370 /** method update layout direction the layout direction, the anchored
371 object is assigned to
373 method has typically to be called, if the anchored object gets its
374 anchor frame assigned and if the anchor frame changes its layout direction
376 @author OD
378 virtual void UpdateLayoutDir();
380 /** method to determine object area inclusive its spacing
382 @author OD
384 const SwRect& GetObjRectWithSpaces() const;
386 inline void InvalidateObjRectWithSpaces() const
388 mbObjRectWithSpacesValid = false;
391 /** method to determine, if wrapping style influence of the anchored
392 object has to be considered on the object positioning
394 Note: result of this method also decides, if the boolean for the
395 layout process are of relevance.
397 @author OD
399 bool ConsiderObjWrapInfluenceOnObjPos() const;
401 // accessors to booleans for layout process
402 bool ConsiderForTextWrap() const;
403 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap );
404 bool PositionLocked() const;
405 inline void LockPosition()
407 mbPositionLocked = true;
409 inline void UnlockPosition()
411 if ( !mbKeepPositionLockedForSection )
413 mbPositionLocked = false;
417 inline void SetKeepPosLocked( const bool _bKeepPosLocked )
419 mbKeepPositionLockedForSection = _bKeepPosLocked;
422 bool RestartLayoutProcess() const;
423 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess );
424 // accessors for <mbClearedEnvironment>
425 bool ClearedEnvironment() const;
426 void SetClearedEnvironment( const bool _bClearedEnvironment );
428 // reset booleans for layout process
429 inline void ResetLayoutProcessBools()
431 mbPositioningInProgress = false;
432 mbConsiderForTextWrap = false;
433 mbPositionLocked = false;
434 mbKeepPositionLockedForSection = false;
435 mbRestartLayoutProcess = false;
436 mbClearedEnvironment = false;
437 mbTmpConsiderWrapInfluence = false;
440 /** method to determine, if due to anchored object size and wrapping
441 style, its layout environment is cleared.
443 @author OD
445 bool HasClearedEnvironment() const;
447 /** method to update anchored object in the <SwSortedObjs> lists
449 Method is not proposed to be called during a layout process is
450 running. It has been used on the change of the anchored object
451 attributes, which belongs the sort criteria of <SwSortedObjs>.
452 If document compatibility option 'Consider wrapping style influence
453 on object positioning' is ON, additionally all anchored objects
454 at the anchor frame and all following anchored objects on the page
455 frame are invalidated.
457 @author OD
459 void UpdateObjInSortedList();
461 /** method to determine, if a format on the anchored object is possible
463 A format isn't possible, if anchored object is in an invisible layer.
464 Note: method is virtual to refine the conditions for the sub-classes.
466 @author OD
468 virtual bool IsFormatPossible() const;
470 // accessors to member <mbTmpConsiderWrapInfluence>
471 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
472 bool IsTmpConsiderWrapInfluence() const;
474 /** method to determine, if the anchored object is overlapping with a
475 previous column
477 overlapping with a previous column means, that the object overlaps
478 with a column, which is a previous one of the column its anchor
479 frame is in.
480 Only applied for at-paragraph and at-character anchored objects.
482 @author OD
484 bool OverlapsPrevColumn() const;
486 /** method to determine position of anchored object relative to
487 anchor frame
489 Usage: Needed layout information for WW8 export
491 @author OD
493 @return Point - determined relative position
495 Point GetRelPosToAnchorFrm() const;
497 /** method to determine position of anchored object relative to
498 page frame
500 Usage: Needed layout information for WW8 export
502 If <_bFollowTextFlow> is set and object is anchored inside table,
503 the position relative to the table cell is determined. Output
504 parameter <_obRelToTableCell> reflects this situation
506 @author OD
508 @param _bFollowTextFlow
509 input parameter - boolean indicating, if the anchored object has to
510 follow the text flow.
512 @param _obRelToTableCell
513 output parameter - boolean indicating, the determine position is
514 relative to the table cell
516 @return Point - determined relative position
518 Point GetRelPosToPageFrm( const bool _bFollowTextFlow,
519 bool& _obRelToTableCell ) const;
521 /** method to determine position of anchored object relative to
522 anchor character
524 Usage: Needed layout information for WW8 export
526 @author OD
528 @return Point - determined relative position
530 Point GetRelPosToChar() const;
532 /** method to determine position of anchored object relative to
533 top of line
535 Usage: Needed layout information for WW8 export
537 @author OD
539 @return Point - determined relative position
541 Point GetRelPosToLine() const;
543 /** Dump a bunch of useful data to an XML representation to ease
544 layout understanding, debugging and testing.
546 virtual void dumpAsXml( xmlTextWriterPtr pWriter );
548 /** The element name to show in the XML dump.
550 virtual const char* getElementName( ) { return "SwAnchoredObject"; }
553 // ============================================================================
554 // helper class for notify that positioning of an anchored object is in progress
555 // ============================================================================
556 class SwObjPositioningInProgress
558 private:
559 SwAnchoredObject* mpAnchoredObj;
560 // boolean indicating old state
561 // of anchored object regarding positioning in progress in order to
562 // consider nested usage of class <SwObjPositioningInProgress>
563 bool mbOldObjPositioningInProgress;
565 public:
566 SwObjPositioningInProgress( SdrObject& _rSdrObj );
567 SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
568 ~SwObjPositioningInProgress();
571 #endif
573 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */