xref: /aoo42x/main/sw/inc/anchoredobject.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 #ifndef _ANCHOREDOBJECT_HXX
28 #define _ANCHOREDOBJECT_HXX
29 
30 #include <tools/rtti.hxx>
31 #include <swtypes.hxx>
32 #include <swrect.hxx>
33 
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;
46 
47 /** wrapper class for the positioning of Writer fly frames and drawing objects
48 
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>).
53 
54     @author OD
55 */
56 class SW_DLLPUBLIC SwAnchoredObject
57 {
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;
69 
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;
75 
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;
81 
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;
87 
88         // --> OD 2004-06-30 #i28701# - boolean, indicating that the object
89         // positioning algorithm is in progress.
90         bool mbPositioningInProgress;
91         // <--
92 
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         // <--
114 
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         // <--
126 
127         // --> OD 2006-06-21 #i68520#
128         mutable SwRect maObjRectWithSpaces;
129         mutable bool mbObjRectWithSpacesValid;
130         mutable SwRect maLastObjRect;
131         // <--
132 
133         /** method to indicate, that positioning of anchored object is in progress
134 
135             note: method is implemented empty
136 
137             @author OD
138         */
139         friend class SwObjPositioningInProgress;
140         inline void SetPositioningInProgress( const bool _bPosInProgress )
141         {
142             mbPositioningInProgress = _bPosInProgress;
143         }
144 
145 
146         /** check anchor character rectangle
147 
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>
155 
156             @author OD
157 
158             @param _rAnch
159             input parameter - reference to anchor position
160 
161             @param _rAnchorCharFrm
162             input parameter - reference to the text frame containing the anchor
163             character.
164         */
165         void _CheckCharRect( const SwFmtAnchor& _rAnch,
166                              const SwTxtFrm& _rAnchorCharFrm );
167 
168         /** check top of line
169 
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>
177 
178             @author OD
179 
180             @param _rAnch
181             input parameter - reference to anchor position
182 
183             @param _rAnchorCharFrm
184             input parameter - reference to the text frame containing the anchor
185             character.
186         */
187         void _CheckTopOfLine( const SwFmtAnchor& _rAnch,
188                               const SwTxtFrm& _rAnchorCharFrm );
189 
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();
200 
201         void SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm );
202 
203         /** method to assure that anchored object is registered at the correct
204             page frame
205 
206             OD 2004-07-02 #i28701#
207 
208             @author OD
209         */
210         virtual void RegisterAtCorrectPage() = 0;
211 
212         /** method to indicate, that anchored object is attached to a anchor frame
213 
214             @author OD
215         */
216         virtual void ObjectAttachedToAnchorFrame();
217 
218         /** method to determine, if other anchored objects, also attached at
219             to the anchor frame, have to consider its wrap influence.
220 
221             // --> OD 2005-02-22 #i43255#
222 
223             @author OD
224         */
225         bool ConsiderObjWrapInfluenceOfOtherObjs() const;
226 
227         /** method to apply temporary consideration of wrapping style influence
228             to the anchored objects, which are anchored at the same anchor frame
229 
230             OD 2006-07-24 #b6449874#
231 
232             @author OD
233         */
234         void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence );
235 
236         // --> OD 2006-08-10 #i68520#
237         virtual bool _SetObjTop( const SwTwips _nTop) = 0;
238         virtual bool _SetObjLeft( const SwTwips _nLeft) = 0;
239         // <--
240 
241         // --> OD 2006-10-05 #i70122#
242         virtual const SwRect GetObjBoundRect() const = 0;
243         // <--
244     public:
245         TYPEINFO();
246 
247         virtual ~SwAnchoredObject();
248 
249         // accessors to member <mpDrawObj>
250         void SetDrawObj( SdrObject& _rDrawObj );
251         const SdrObject* GetDrawObj() const;
252         SdrObject* DrawObj();
253 
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
259 
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.
265 
266             @author OD
267         */
268         SwFrm* GetAnchorFrmContainingAnchPos();
269 
270         // --> OD 2004-06-30 #i28701# - accessors to member <mpPageFrm>
271         SwPageFrm* GetPageFrm();
272         const SwPageFrm* GetPageFrm() const;
273         void SetPageFrm( SwPageFrm* _pNewPageFrm );
274         // <--
275 
276         /** method to determine the page frame, on which the 'anchor' of
277             the given anchored object is.
278 
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.
285 
286             @author OD
287 
288             @param _rAnchoredObj
289             input parameter - anchored object, for which the page frame of its
290             'anchor' has to be determined.
291 
292             @return SwPageFrm&
293             page frame, the 'anchor' of the given anchored object is on
294         */
295         SwPageFrm* FindPageFrmOfAnchor();
296 
297         /** get frame, which contains the anchor character, if the object
298             is anchored at-character or as-character.
299 
300             OD 2004-10-04 #i26945#
301 
302             @author OD
303 
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.
307         */
308         SwTxtFrm* FindAnchorCharFrm();
309 
310         // accessors to data of position calculation:
311         // frame vertical position is orient at
312         inline const SwLayoutFrm* GetVertPosOrientFrm() const
313         {
314             return mpVertPosOrientFrm;
315         }
316         // --> OD 2004-11-29 #115759# - method to clear member <mpVertPosOrientFrm>
317         inline void ClearVertPosOrientFrm()
318         {
319             mpVertPosOrientFrm = 0L;
320         }
321         // <--
322 
323         /** check anchor character rectangle and top of line
324 
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>
332 
333             @author OD
334 
335             @param _bCheckForParaPorInf
336             input parameter - boolean indicating, if check on paragraph portion
337             information has to be done.
338         */
339         void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf = true );
340 
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();
347 
348         // accessor to member <nmLastTopOfLine>
349         SwTwips GetLastTopOfLine() const;
350         // OD 2004-05-18 #i28701# - follow-up of #i22341#
351         void AddLastTopOfLineY( SwTwips _nDiff );
352 
353         /** reset members <maLastCharRect> and <mnLastTopOfLine>
354 
355             OD 2004-06-29 #i27801#
356 
357             @author OD
358         */
359         void ClearCharRectAndTopOfLine();
360 
361         /** method to determine position for the object and set the position
362             at the object
363 
364             @author OD
365         */
366         virtual void MakeObjPos() = 0;
367 
368         /** is positioning of anchored object in progress
369 
370             @author OD
371         */
372         inline bool IsPositioningInProgress() const
373         {
374             return mbPositioningInProgress;
375         }
376 
377         /** method to determine, if invalidation of position is allowed
378 
379             OD 2004-07-01 #i28701#
380 
381             @author OD
382         */
383         bool InvalidationOfPosAllowed() const;
384 
385         /** method to invalidate position of the anchored object
386 
387             @author OD
388         */
389         virtual void InvalidateObjPos() = 0;
390 
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.
394 
395             OD 2004-06-30 #i28701#
396 
397             @author OD
398         */
399         void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd );
400 
401         /** method to trigger notification of 'background'
402 
403             OD 2004-07-01 #i28701#
404 
405             @author OD
406         */
407         virtual void NotifyBackground( SwPageFrm* _pPageFrm,
408                                        const SwRect& _rRect,
409                                        PrepareHint _eHint ) = 0;
410 
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 );
415 
416         // accessors to the format
417         virtual SwFrmFmt& GetFrmFmt() = 0;
418         virtual const SwFrmFmt& GetFrmFmt() const = 0;
419 
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         // <--
426 
427         /** method update layout direction the layout direction, the anchored
428             object is assigned to
429 
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>
435 
436             @author OD
437         */
438         virtual void UpdateLayoutDir();
439 
440         /** method to determine object area inclusive its spacing
441 
442             OD 2004-06-30 #i28701#
443             OD 2006-08-10 #i68520# - return constant reference
444 
445             @author OD
446         */
447         const SwRect& GetObjRectWithSpaces() const;
448 
449         // --> OD 2006-08-10 #i68520#
450         inline void InvalidateObjRectWithSpaces() const
451         {
452             mbObjRectWithSpacesValid = false;
453         }
454         // <--
455 
456         /** method to determine, if wrapping style influence of the anchored
457             object has to be considered on the object positioning
458 
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.
462 
463             @author OD
464         */
465         bool ConsiderObjWrapInfluenceOnObjPos() const;
466 
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()
472         {
473             mbPositionLocked = true;
474         }
475         inline void UnlockPosition()
476         {
477             if ( !mbKeepPositionLockedForSection )
478             {
479                 mbPositionLocked = false;
480             }
481         }
482         // --> OD 2005-01-10 #i40147#
483         inline void SetKeepPosLocked( const bool _bKeepPosLocked )
484         {
485             mbKeepPositionLockedForSection = _bKeepPosLocked;
486         }
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()
496         {
497             mbPositioningInProgress = false;
498             mbConsiderForTextWrap = false;
499             mbPositionLocked = false;
500             mbKeepPositionLockedForSection = false;
501             mbRestartLayoutProcess = false;
502             mbClearedEnvironment = false;
503             mbTmpConsiderWrapInfluence = false;
504         }
505         // <--
506 
507         /** method to determine, if due to anchored object size and wrapping
508             style, its layout environment is cleared.
509 
510             OD 2004-10-22 #i35911#
511 
512             @author OD
513         */
514         bool HasClearedEnvironment() const;
515 
516         /** method to update anchored object in the <SwSortedObjs> lists
517 
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.
526 
527             @author OD
528         */
529         void UpdateObjInSortedList();
530 
531         /** method to determine, if a format on the anchored object is possible
532 
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.
536 
537             @author OD
538         */
539         virtual bool IsFormatPossible() const;
540 
541         // --> OD 2004-08-25 #i3317# - accessors to member <mbTmpConsiderWrapInfluence>
542         void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
543         bool IsTmpConsiderWrapInfluence() const;
544         // <--
545 
546         /** method to determine, if the anchored object is overlapping with a
547             previous column
548 
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.
554 
555             @author OD
556         */
557         bool OverlapsPrevColumn() const;
558 
559         /** method to determine position of anchored object relative to
560             anchor frame
561 
562             OD 2005-01-06 #i30669#
563             Usage: Needed layout information for WW8 export
564 
565             @author OD
566 
567             @return Point - determined relative position
568         */
569         Point GetRelPosToAnchorFrm() const;
570 
571         /** method to determine position of anchored object relative to
572             page frame
573 
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
581 
582             @author OD
583 
584             @param _bFollowTextFlow
585             input parameter - boolean indicating, if the anchored object has to
586             follow the text flow.
587 
588             @param _obRelToTableCell
589             output parameter - boolean indicating, the determine position is
590             relative to the table cell
591 
592             @return Point - determined relative position
593         */
594         Point GetRelPosToPageFrm( const bool _bFollowTextFlow,
595                                   bool& _obRelToTableCell ) const;
596 
597         /** method to determine position of anchored object relative to
598             anchor character
599 
600             OD 2005-01-06 #i30669#
601             Usage: Needed layout information for WW8 export
602 
603             @author OD
604 
605             @return Point - determined relative position
606         */
607         Point GetRelPosToChar() const;
608 
609         /** method to determine position of anchored object relative to
610             top of line
611 
612             OD 2005-01-06 #i30669#
613             Usage: Needed layout information for WW8 export
614 
615             @author OD
616 
617             @return Point - determined relative position
618         */
619         Point GetRelPosToLine() const;
620 };
621 
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
627 {
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         // <--
635 
636     public:
637         SwObjPositioningInProgress( SdrObject& _rSdrObj );
638         SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
639         ~SwObjPositioningInProgress();
640 };
641 
642 #endif
643