merged tag ooo/OOO330_m14
[LibreOffice.git] / sw / inc / anchoredobject.hxx
blobc9f53e51f069e4247d215e15477d415eee8ef0ae
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef _ANCHOREDOBJECT_HXX
28 #define _ANCHOREDOBJECT_HXX
30 #include <tools/rtti.hxx>
31 #include <swtypes.hxx>
32 #include <swrect.hxx>
34 class SdrObject;
35 class SwFrm;
36 class SwLayoutFrm;
37 // --> OD 2004-07-14 #117380#
38 class SwTxtFrm;
39 // <--
40 // --> OD 2004-06-30 #i28701#
41 class SwPageFrm;
42 class SwObjPositioningInProgress;
43 // <--
44 class SwFrmFmt;
45 class SwFmtAnchor;
47 /** wrapper class for the positioning of Writer fly frames and drawing objects
49 OD 2004-03-22 #i26791#
50 Purpose of this class is to provide a unified interface for the positioning
51 of Writer fly frames (derived classes of <SwFlyFrm>) and of drawing objects
52 (derived classes of <SwDrawFrm>).
54 @author OD
56 class SW_DLLPUBLIC SwAnchoredObject
58 private:
59 // drawing object representing the anchored object in the drawing layer
60 SdrObject* mpDrawObj;
61 // frame the object is anchored at
62 SwFrm* mpAnchorFrm;
63 // --> OD 2004-06-30 #i28701# - page frame the object is registered at
64 // note: no page frame for as-character anchored objects
65 SwPageFrm* mpPageFrm;
66 // <--
67 // current relative position (relative to anchor position of anchor frame)
68 Point maRelPos;
70 // for to-character anchored objects:
71 // Last known anchor character retangle.
72 // Used to decide, if invalidation has to been performed, if anchor position
73 // has changed, and used to position object.
74 SwRect maLastCharRect;
76 // for to-character anchored objects:
77 // Last known top of line, in which the anchor character is in.
78 // Used to decide, if invalidation has to been performed, if anchor position
79 // has changed, and used to position object.
80 SwTwips mnLastTopOfLine;
82 // for to-paragraph and to-character anchored objects:
83 // Layout frame vertical position is orient at - typically its the upper
84 // of the anchor frame, but it could also by the upper of a follow or
85 // a following layout frame in the text flow.
86 const SwLayoutFrm* mpVertPosOrientFrm;
88 // --> OD 2004-06-30 #i28701# - boolean, indicating that the object
89 // positioning algorithm is in progress.
90 bool mbPositioningInProgress;
91 // <--
93 // --> OD 2004-06-29 #i28701# - Booleans needed for the layout process.
94 // Values only of relevance for to-paragraph and to-character anchored
95 // floating screen object, for whose the 'straight-forward positioning
96 // process are applied
97 // Otherwise value of <mbConsiderForTextWrap> is treated as <true>,
98 // value of <mbPositionLocked> is treated as <false> and
99 // value of <mbRestartLayoutProcess> is treated as <false>.
100 // --> OD 2004-10-22 #i35911# - add boolean <mbClearEnvironment>
101 // Indicates that due to its position and wrapping style its layout
102 // environment is cleared - all content is moved forward.
103 // Treated as <false>, if not the 'straight-forward positioning process"
104 // is applied.
105 bool mbConsiderForTextWrap;
106 bool mbPositionLocked;
107 // --> OD 2005-01-10 #i40147# - boolean needed to keep position of
108 // anchored object locked due to special object positioning for sections.
109 bool mbKeepPositionLockedForSection;
110 // <--
111 bool mbRestartLayoutProcess;
112 bool mbClearedEnvironment;
113 // <--
115 // --> OD 2004-08-25 #i3317# - boolean, indicating that temporarly
116 // the wrapping style influence of the anchored object has to be
117 // considered during its positioning.
118 // This boolean is used, if compatibility option 'Consider wrapping style
119 // influence on object positioning' is OFF and a positioning loop is
120 // detected in method <SwFlyAtCntFrm::MakeAll()> or method
121 // <SwAnchoredDrawObject::_MakeObjPosAnchoredAtPara()>.
122 // The boolean is reset to <false>, when the layout process for a
123 // page frame starts - see class <NotifyLayoutOfPageInProgress>.
124 bool mbTmpConsiderWrapInfluence;
125 // <--
127 // --> OD 2006-06-21 #i68520#
128 mutable SwRect maObjRectWithSpaces;
129 mutable bool mbObjRectWithSpacesValid;
130 mutable SwRect maLastObjRect;
131 // <--
133 /** method to indicate, that positioning of anchored object is in progress
135 note: method is implemented empty
137 @author OD
139 friend class SwObjPositioningInProgress;
140 inline void SetPositioningInProgress( const bool _bPosInProgress )
142 mbPositioningInProgress = _bPosInProgress;
146 /** check anchor character rectangle
148 OD 2004-03-25 #i26791#
149 helper method for method <CheckCharRectAndTopOfLine()>
150 For to-character anchored Writer fly frames the member <maLastCharRect>
151 is updated. This is checked for change and depending on the applied
152 positioning, it's decided, if the Writer fly frame has to be invalidated.
153 OD 2004-07-14 #117380#
154 improvement - add second parameter <_rAnchorCharFrm>
156 @author OD
158 @param _rAnch
159 input parameter - reference to anchor position
161 @param _rAnchorCharFrm
162 input parameter - reference to the text frame containing the anchor
163 character.
165 void _CheckCharRect( const SwFmtAnchor& _rAnch,
166 const SwTxtFrm& _rAnchorCharFrm );
168 /** check top of line
170 OD 2004-03-25 #i26791#
171 helper method for method <CheckCharRectAndTopOfLine()>
172 For to-character anchored Writer fly frames the member <mnLastTopOfLine>
173 is updated. This is checked for change and depending on the applied
174 positioning, it's decided, if the Writer fly frame has to be invalidated.
175 OD 2004-07-14 #117380#
176 improvement - add second parameter <_rAnchorCharFrm>
178 @author OD
180 @param _rAnch
181 input parameter - reference to anchor position
183 @param _rAnchorCharFrm
184 input parameter - reference to the text frame containing the anchor
185 character.
187 void _CheckTopOfLine( const SwFmtAnchor& _rAnch,
188 const SwTxtFrm& _rAnchorCharFrm );
190 // --> OD 2005-03-30 #120729# - needed for the hotfix
191 // method <lcl_HideObj(..)> sets needed data structure values for the
192 // object positioning
193 friend bool lcl_HideObj( const SwTxtFrm& _rFrm,
194 const RndStdIds _eAnchorType,
195 const xub_StrLen _nObjAnchorPos,
196 SwAnchoredObject* _pAnchoredObj );
197 // <--
198 protected:
199 SwAnchoredObject();
201 void SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm );
203 /** method to assure that anchored object is registered at the correct
204 page frame
206 OD 2004-07-02 #i28701#
208 @author OD
210 virtual void RegisterAtCorrectPage() = 0;
212 /** method to indicate, that anchored object is attached to a anchor frame
214 @author OD
216 virtual void ObjectAttachedToAnchorFrame();
218 /** method to determine, if other anchored objects, also attached at
219 to the anchor frame, have to consider its wrap influence.
221 // --> OD 2005-02-22 #i43255#
223 @author OD
225 bool ConsiderObjWrapInfluenceOfOtherObjs() const;
227 /** method to apply temporary consideration of wrapping style influence
228 to the anchored objects, which are anchored at the same anchor frame
230 OD 2006-07-24 #b6449874#
232 @author OD
234 void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence );
236 // --> OD 2006-08-10 #i68520#
237 virtual bool _SetObjTop( const SwTwips _nTop) = 0;
238 virtual bool _SetObjLeft( const SwTwips _nLeft) = 0;
239 // <--
241 // --> OD 2006-10-05 #i70122#
242 virtual const SwRect GetObjBoundRect() const = 0;
243 // <--
244 public:
245 TYPEINFO();
247 virtual ~SwAnchoredObject();
249 // accessors to member <mpDrawObj>
250 void SetDrawObj( SdrObject& _rDrawObj );
251 const SdrObject* GetDrawObj() const;
252 SdrObject* DrawObj();
254 // accessors to member <mpAnchorFrm>
255 const SwFrm* GetAnchorFrm() const;
256 SwFrm* AnchorFrm();
257 void ChgAnchorFrm( SwFrm* _pNewAnchorFrm );
258 /** determine anchor frame containing the anchor position
260 OD 2004-10-08 #i26945#
261 the anchor frame, which is determined, is <mpAnchorFrm>
262 for an at-page, at-frame or at-paragraph anchored object
263 and the anchor character frame for an at-character and as-character
264 anchored object.
266 @author OD
268 SwFrm* GetAnchorFrmContainingAnchPos();
270 // --> OD 2004-06-30 #i28701# - accessors to member <mpPageFrm>
271 SwPageFrm* GetPageFrm();
272 const SwPageFrm* GetPageFrm() const;
273 void SetPageFrm( SwPageFrm* _pNewPageFrm );
274 // <--
276 /** method to determine the page frame, on which the 'anchor' of
277 the given anchored object is.
279 OD 2004-07-02 #i28701#
280 OD 2004-09-23 #i33751#, #i34060#
281 Adjust meaning of method and thus its name: If the anchored object
282 or its anchor isn't correctly inserted in the layout, no page frame
283 can be found. Thus, the return type changed to be a pointer and can
284 be NULL.
286 @author OD
288 @param _rAnchoredObj
289 input parameter - anchored object, for which the page frame of its
290 'anchor' has to be determined.
292 @return SwPageFrm&
293 page frame, the 'anchor' of the given anchored object is on
295 SwPageFrm* FindPageFrmOfAnchor();
297 /** get frame, which contains the anchor character, if the object
298 is anchored at-character or as-character.
300 OD 2004-10-04 #i26945#
302 @author OD
304 @return SwTxtFrm*
305 text frame containing the anchor character. It's NULL, if the object
306 isn't anchored at-character resp. as-character.
308 SwTxtFrm* FindAnchorCharFrm();
310 // accessors to data of position calculation:
311 // frame vertical position is orient at
312 inline const SwLayoutFrm* GetVertPosOrientFrm() const
314 return mpVertPosOrientFrm;
316 // --> OD 2004-11-29 #115759# - method to clear member <mpVertPosOrientFrm>
317 inline void ClearVertPosOrientFrm()
319 mpVertPosOrientFrm = 0L;
321 // <--
323 /** check anchor character rectangle and top of line
325 OD 2004-03-25 #i26791#
326 For to-character anchored Writer fly frames the members <maLastCharRect>
327 and <maLastTopOfLine> are updated. These are checked for change and
328 depending on the applied positioning, it's decided, if the Writer fly
329 frame has to be invalidated.
330 OD 2004-07-15 #117380#
331 add parameter <_bCheckForParaPorInf>, default value <true>
333 @author OD
335 @param _bCheckForParaPorInf
336 input parameter - boolean indicating, if check on paragraph portion
337 information has to be done.
339 void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf = true );
341 // accessors to member <maLastCharRect>
342 const SwRect& GetLastCharRect() const;
343 SwTwips GetRelCharX( const SwFrm* pFrm ) const;
344 SwTwips GetRelCharY( const SwFrm* pFrm ) const;
345 void AddLastCharY( long nDiff );
346 void ResetLastCharRectHeight();
348 // accessor to member <nmLastTopOfLine>
349 SwTwips GetLastTopOfLine() const;
350 // OD 2004-05-18 #i28701# - follow-up of #i22341#
351 void AddLastTopOfLineY( SwTwips _nDiff );
353 /** reset members <maLastCharRect> and <mnLastTopOfLine>
355 OD 2004-06-29 #i27801#
357 @author OD
359 void ClearCharRectAndTopOfLine();
361 /** method to determine position for the object and set the position
362 at the object
364 @author OD
366 virtual void MakeObjPos() = 0;
368 /** is positioning of anchored object in progress
370 @author OD
372 inline bool IsPositioningInProgress() const
374 return mbPositioningInProgress;
377 /** method to determine, if invalidation of position is allowed
379 OD 2004-07-01 #i28701#
381 @author OD
383 bool InvalidationOfPosAllowed() const;
385 /** method to invalidate position of the anchored object
387 @author OD
389 virtual void InvalidateObjPos() = 0;
391 /** method to perform necessary invalidations for the positioning of
392 objects, for whose the wrapping style influence has to be considered
393 on the object positioning.
395 OD 2004-06-30 #i28701#
397 @author OD
399 void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd );
401 /** method to trigger notification of 'background'
403 OD 2004-07-01 #i28701#
405 @author OD
407 virtual void NotifyBackground( SwPageFrm* _pPageFrm,
408 const SwRect& _rRect,
409 PrepareHint _eHint ) = 0;
411 // accessors to the current relative position (relative to anchor
412 // position of anchor frame)
413 const Point GetCurrRelPos() const;
414 void SetCurrRelPos( Point _aRelPos );
416 // accessors to the format
417 virtual SwFrmFmt& GetFrmFmt() = 0;
418 virtual const SwFrmFmt& GetFrmFmt() const = 0;
420 // accessors to the object area and its position
421 virtual const SwRect GetObjRect() const = 0;
422 // --> OD 2006-08-10 #i68520#
423 void SetObjTop( const SwTwips _nTop);
424 void SetObjLeft( const SwTwips _nLeft);
425 // <--
427 /** method update layout direction the layout direction, the anchored
428 object is assigned to
430 OD 2004-07-27 #i31698#
431 method has typically to be called, if the anchored object gets its
432 anchor frame assigned and if the anchor frame changes its layout direction
433 OD 2006-03-17 #i62875#
434 made virtual, because it's needed to be overloaded by <SwAnchoredDrawObject>
436 @author OD
438 virtual void UpdateLayoutDir();
440 /** method to determine object area inclusive its spacing
442 OD 2004-06-30 #i28701#
443 OD 2006-08-10 #i68520# - return constant reference
445 @author OD
447 const SwRect& GetObjRectWithSpaces() const;
449 // --> OD 2006-08-10 #i68520#
450 inline void InvalidateObjRectWithSpaces() const
452 mbObjRectWithSpacesValid = false;
454 // <--
456 /** method to determine, if wrapping style influence of the anchored
457 object has to be considered on the object positioning
459 OD 2004-06-30 #i28701#
460 Note: result of this method also decides, if the boolean for the
461 layout process are of relevance.
463 @author OD
465 bool ConsiderObjWrapInfluenceOnObjPos() const;
467 // --> OD 2004-06-29 #i28701# - accessors to booleans for layout process
468 bool ConsiderForTextWrap() const;
469 void SetConsiderForTextWrap( const bool _bConsiderForTextWrap );
470 bool PositionLocked() const;
471 inline void LockPosition()
473 mbPositionLocked = true;
475 inline void UnlockPosition()
477 if ( !mbKeepPositionLockedForSection )
479 mbPositionLocked = false;
482 // --> OD 2005-01-10 #i40147#
483 inline void SetKeepPosLocked( const bool _bKeepPosLocked )
485 mbKeepPositionLockedForSection = _bKeepPosLocked;
487 // <--
488 bool RestartLayoutProcess() const;
489 void SetRestartLayoutProcess( const bool _bRestartLayoutProcess );
490 // --> OD 2004-10-22 #i35911# - accessors for <mbClearedEnvironment>
491 bool ClearedEnvironment() const;
492 void SetClearedEnvironment( const bool _bClearedEnvironment );
493 // <--
494 // --> OD 2005-03-03 #i43913# - reset booleans for layout process
495 inline void ResetLayoutProcessBools()
497 mbPositioningInProgress = false;
498 mbConsiderForTextWrap = false;
499 mbPositionLocked = false;
500 mbKeepPositionLockedForSection = false;
501 mbRestartLayoutProcess = false;
502 mbClearedEnvironment = false;
503 mbTmpConsiderWrapInfluence = false;
505 // <--
507 /** method to determine, if due to anchored object size and wrapping
508 style, its layout environment is cleared.
510 OD 2004-10-22 #i35911#
512 @author OD
514 bool HasClearedEnvironment() const;
516 /** method to update anchored object in the <SwSortedObjs> lists
518 OD 2004-07-01 #i28701#
519 Method is not proposed to be called during a layout process is
520 running. It has been used on the change of the anchored object
521 attributes, which belongs the sort criteria of <SwSortedObjs>.
522 If document compatibility option 'Consider wrapping style influence
523 on object positioning' is ON, additionally all anchored objects
524 at the anchor frame and all following anchored objects on the page
525 frame are invalidated.
527 @author OD
529 void UpdateObjInSortedList();
531 /** method to determine, if a format on the anchored object is possible
533 OD 2004-07-23 #i28701#
534 A format isn't possible, if anchored object is in an invisible layer.
535 Note: method is virtual to refine the conditions for the sub-classes.
537 @author OD
539 virtual bool IsFormatPossible() const;
541 // --> OD 2004-08-25 #i3317# - accessors to member <mbTmpConsiderWrapInfluence>
542 void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
543 bool IsTmpConsiderWrapInfluence() const;
544 // <--
546 /** method to determine, if the anchored object is overlapping with a
547 previous column
549 OD 2004-08-25 #i3317#
550 overlapping with a previous column means, that the object overlaps
551 with a column, which is a previous one of the column its anchor
552 frame is in.
553 Only applied for at-paragraph and at-character anchored objects.
555 @author OD
557 bool OverlapsPrevColumn() const;
559 /** method to determine position of anchored object relative to
560 anchor frame
562 OD 2005-01-06 #i30669#
563 Usage: Needed layout information for WW8 export
565 @author OD
567 @return Point - determined relative position
569 Point GetRelPosToAnchorFrm() const;
571 /** method to determine position of anchored object relative to
572 page frame
574 OD 2005-01-06 #i30669#
575 Usage: Needed layout information for WW8 export
576 OD 2005-01-27 #i33818# - add parameters <_bFollowTextFlow> and
577 <_obRelToTableCell>
578 If <_bFollowTextFlow> is set and object is anchored inside table,
579 the position relative to the table cell is determined. Output
580 parameter <_obRelToTableCell> reflects this situation
582 @author OD
584 @param _bFollowTextFlow
585 input parameter - boolean indicating, if the anchored object has to
586 follow the text flow.
588 @param _obRelToTableCell
589 output parameter - boolean indicating, the determine position is
590 relative to the table cell
592 @return Point - determined relative position
594 Point GetRelPosToPageFrm( const bool _bFollowTextFlow,
595 bool& _obRelToTableCell ) const;
597 /** method to determine position of anchored object relative to
598 anchor character
600 OD 2005-01-06 #i30669#
601 Usage: Needed layout information for WW8 export
603 @author OD
605 @return Point - determined relative position
607 Point GetRelPosToChar() const;
609 /** method to determine position of anchored object relative to
610 top of line
612 OD 2005-01-06 #i30669#
613 Usage: Needed layout information for WW8 export
615 @author OD
617 @return Point - determined relative position
619 Point GetRelPosToLine() const;
622 // ============================================================================
623 // OD 2004-04-13 #i26791#, #i28701#
624 // helper class for notify that positioning of an anchored object is in progress
625 // ============================================================================
626 class SwObjPositioningInProgress
628 private:
629 SwAnchoredObject* mpAnchoredObj;
630 // --> OD 2005-08-09 #i52904# - introduce boolean indicating old state
631 // of anchored object regarding positioning in progress in order to
632 // consider nested usage of class <SwObjPositioningInProgress>
633 bool mbOldObjPositioningInProgress;
634 // <--
636 public:
637 SwObjPositioningInProgress( SdrObject& _rSdrObj );
638 SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
639 ~SwObjPositioningInProgress();
642 #endif