xref: /aoo4110/main/sw/inc/anchoredobject.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ANCHOREDOBJECT_HXX
24 #define _ANCHOREDOBJECT_HXX
25 
26 #include <tools/rtti.hxx>
27 #include <swtypes.hxx>
28 #include <swrect.hxx>
29 
30 class SdrObject;
31 class SwFrm;
32 class SwLayoutFrm;
33 // --> OD 2004-07-14 #117380#
34 class SwTxtFrm;
35 // <--
36 // --> OD 2004-06-30 #i28701#
37 class SwPageFrm;
38 class SwObjPositioningInProgress;
39 // <--
40 class SwFrmFmt;
41 class SwFmtAnchor;
42 
43 /** wrapper class for the positioning of Writer fly frames and drawing objects
44 
45     OD 2004-03-22 #i26791#
46     Purpose of this class is to provide a unified interface for the positioning
47     of Writer fly frames (derived classes of <SwFlyFrm>) and of drawing objects
48     (derived classes of <SwDrawFrm>).
49 
50     @author OD
51 */
52 class SW_DLLPUBLIC SwAnchoredObject
53 {
54     private:
55         // drawing object representing the anchored object in the drawing layer
56         SdrObject* mpDrawObj;
57         // frame the object is anchored at
58         SwFrm* mpAnchorFrm;
59         // --> OD 2004-06-30 #i28701# - page frame the object is registered at
60         // note: no page frame for as-character anchored objects
61         SwPageFrm* mpPageFrm;
62         // <--
63         // current relative position (relative to anchor position of anchor frame)
64         Point maRelPos;
65 
66         // for to-character anchored objects:
67         // Last known anchor character retangle.
68         // Used to decide, if invalidation has to been performed, if anchor position
69         // has changed, and used to position object.
70         SwRect maLastCharRect;
71 
72         // for to-character anchored objects:
73         // Last known top of line, in which the anchor character is in.
74         // Used to decide, if invalidation has to been performed, if anchor position
75         // has changed, and used to position object.
76         SwTwips mnLastTopOfLine;
77 
78         // for to-paragraph and to-character anchored objects:
79         // Layout frame vertical position is orient at - typically its the upper
80         // of the anchor frame, but it could also by the upper of a follow or
81         // a following layout frame in the text flow.
82         const SwLayoutFrm* mpVertPosOrientFrm;
83 
84         // --> OD 2004-06-30 #i28701# - boolean, indicating that the object
85         // positioning algorithm is in progress.
86         bool mbPositioningInProgress;
87         // <--
88 
89         // --> OD 2004-06-29 #i28701# - Booleans needed for the layout process.
90         // Values only of relevance for to-paragraph and to-character anchored
91         // floating screen object, for whose the 'straight-forward positioning
92         // process are applied
93         // Otherwise value of <mbConsiderForTextWrap> is treated as <true>,
94         // value of <mbPositionLocked> is treated as <false> and
95         // value of <mbRestartLayoutProcess> is treated as <false>.
96         // --> OD 2004-10-22 #i35911# - add boolean <mbClearEnvironment>
97         // Indicates that due to its position and wrapping style its layout
98         // environment is cleared - all content is moved forward.
99         // Treated as <false>, if not the 'straight-forward positioning process"
100         // is applied.
101         bool mbConsiderForTextWrap;
102         bool mbPositionLocked;
103         // --> OD 2005-01-10 #i40147# - boolean needed to keep position of
104         // anchored object locked due to special object positioning for sections.
105         bool mbKeepPositionLockedForSection;
106         // <--
107         bool mbRestartLayoutProcess;
108         bool mbClearedEnvironment;
109         // <--
110 
111         // --> OD 2004-08-25 #i3317# - boolean, indicating that temporarly
112         // the wrapping style influence of the anchored object has to be
113         // considered during its positioning.
114         // This boolean is used, if compatibility option 'Consider wrapping style
115         // influence on object positioning' is OFF and a positioning loop is
116         // detected in method <SwFlyAtCntFrm::MakeAll()> or method
117         // <SwAnchoredDrawObject::_MakeObjPosAnchoredAtPara()>.
118         // The boolean is reset to <false>, when the layout process for a
119         // page frame starts - see class <NotifyLayoutOfPageInProgress>.
120         bool mbTmpConsiderWrapInfluence;
121         // <--
122 
123         // --> OD 2006-06-21 #i68520#
124         mutable SwRect maObjRectWithSpaces;
125         mutable bool mbObjRectWithSpacesValid;
126         mutable SwRect maLastObjRect;
127         // <--
128 
129         /** method to indicate, that positioning of anchored object is in progress
130 
131             note: method is implemented empty
132 
133             @author OD
134         */
135         friend class SwObjPositioningInProgress;
SetPositioningInProgress(const bool _bPosInProgress)136         inline void SetPositioningInProgress( const bool _bPosInProgress )
137         {
138             mbPositioningInProgress = _bPosInProgress;
139         }
140 
141 
142         /** check anchor character rectangle
143 
144             OD 2004-03-25 #i26791#
145             helper method for method <CheckCharRectAndTopOfLine()>
146             For to-character anchored Writer fly frames the member <maLastCharRect>
147             is updated. This is checked for change and depending on the applied
148             positioning, it's decided, if the Writer fly frame has to be invalidated.
149             OD 2004-07-14 #117380#
150             improvement - add second parameter <_rAnchorCharFrm>
151 
152             @author OD
153 
154             @param _rAnch
155             input parameter - reference to anchor position
156 
157             @param _rAnchorCharFrm
158             input parameter - reference to the text frame containing the anchor
159             character.
160         */
161         void _CheckCharRect( const SwFmtAnchor& _rAnch,
162                              const SwTxtFrm& _rAnchorCharFrm );
163 
164         /** check top of line
165 
166             OD 2004-03-25 #i26791#
167             helper method for method <CheckCharRectAndTopOfLine()>
168             For to-character anchored Writer fly frames the member <mnLastTopOfLine>
169             is updated. This is checked for change and depending on the applied
170             positioning, it's decided, if the Writer fly frame has to be invalidated.
171             OD 2004-07-14 #117380#
172             improvement - add second parameter <_rAnchorCharFrm>
173 
174             @author OD
175 
176             @param _rAnch
177             input parameter - reference to anchor position
178 
179             @param _rAnchorCharFrm
180             input parameter - reference to the text frame containing the anchor
181             character.
182         */
183         void _CheckTopOfLine( const SwFmtAnchor& _rAnch,
184                               const SwTxtFrm& _rAnchorCharFrm );
185 
186         // --> OD 2005-03-30 #120729# - needed for the hotfix
187         // method <lcl_HideObj(..)> sets needed data structure values for the
188         // object positioning
189         friend bool lcl_HideObj( const SwTxtFrm& _rFrm,
190                                  const RndStdIds _eAnchorType,
191                                  const xub_StrLen _nObjAnchorPos,
192                                  SwAnchoredObject* _pAnchoredObj );
193         // <--
194     protected:
195         SwAnchoredObject();
196 
197         void SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm );
198 
199         /** method to assure that anchored object is registered at the correct
200             page frame
201 
202             OD 2004-07-02 #i28701#
203 
204             @author OD
205         */
206         virtual void RegisterAtCorrectPage() = 0;
207 
208         /** method to indicate, that anchored object is attached to a anchor frame
209 
210             @author OD
211         */
212         virtual void ObjectAttachedToAnchorFrame();
213 
214         /** method to determine, if other anchored objects, also attached at
215             to the anchor frame, have to consider its wrap influence.
216 
217             // --> OD 2005-02-22 #i43255#
218 
219             @author OD
220         */
221         bool ConsiderObjWrapInfluenceOfOtherObjs() const;
222 
223         /** method to apply temporary consideration of wrapping style influence
224             to the anchored objects, which are anchored at the same anchor frame
225 
226             OD 2006-07-24 #b6449874#
227 
228             @author OD
229         */
230         void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence );
231 
232         // --> OD 2006-08-10 #i68520#
233         virtual bool _SetObjTop( const SwTwips _nTop) = 0;
234         virtual bool _SetObjLeft( const SwTwips _nLeft) = 0;
235         // <--
236 
237         // --> OD 2006-10-05 #i70122#
238         virtual const SwRect GetObjBoundRect() const = 0;
239         // <--
240     public:
241         TYPEINFO();
242 
243         virtual ~SwAnchoredObject();
244 
245         // accessors to member <mpDrawObj>
246         void SetDrawObj( SdrObject& _rDrawObj );
247         const SdrObject* GetDrawObj() const;
248         SdrObject* DrawObj();
249 
250         // accessors to member <mpAnchorFrm>
251         const SwFrm* GetAnchorFrm() const;
252         SwFrm* AnchorFrm();
253         void ChgAnchorFrm( SwFrm* _pNewAnchorFrm );
254         /** determine anchor frame containing the anchor position
255 
256             OD 2004-10-08 #i26945#
257             the anchor frame, which is determined, is <mpAnchorFrm>
258             for an at-page, at-frame or at-paragraph anchored object
259             and the anchor character frame for an at-character and as-character
260             anchored object.
261 
262             @author OD
263         */
264         SwFrm* GetAnchorFrmContainingAnchPos();
265 
266         // --> OD 2004-06-30 #i28701# - accessors to member <mpPageFrm>
267         SwPageFrm* GetPageFrm();
268         const SwPageFrm* GetPageFrm() const;
269         void SetPageFrm( SwPageFrm* _pNewPageFrm );
270         // <--
271 
272         /** method to determine the page frame, on which the 'anchor' of
273             the given anchored object is.
274 
275             OD 2004-07-02 #i28701#
276             OD 2004-09-23 #i33751#, #i34060#
277             Adjust meaning of method and thus its name: If the anchored object
278             or its anchor isn't correctly inserted in the layout, no page frame
279             can be found. Thus, the return type changed to be a pointer and can
280             be NULL.
281 
282             @author OD
283 
284             @param _rAnchoredObj
285             input parameter - anchored object, for which the page frame of its
286             'anchor' has to be determined.
287 
288             @return SwPageFrm&
289             page frame, the 'anchor' of the given anchored object is on
290         */
291         SwPageFrm* FindPageFrmOfAnchor();
292 
293         /** get frame, which contains the anchor character, if the object
294             is anchored at-character or as-character.
295 
296             OD 2004-10-04 #i26945#
297 
298             @author OD
299 
300             @return SwTxtFrm*
301             text frame containing the anchor character. It's NULL, if the object
302             isn't anchored at-character resp. as-character.
303         */
304         SwTxtFrm* FindAnchorCharFrm();
305 
306         // accessors to data of position calculation:
307         // frame vertical position is orient at
GetVertPosOrientFrm() const308         inline const SwLayoutFrm* GetVertPosOrientFrm() const
309         {
310             return mpVertPosOrientFrm;
311         }
312         // --> OD 2004-11-29 #115759# - method to clear member <mpVertPosOrientFrm>
ClearVertPosOrientFrm()313         inline void ClearVertPosOrientFrm()
314         {
315             mpVertPosOrientFrm = 0L;
316         }
317         // <--
318 
319         /** check anchor character rectangle and top of line
320 
321             OD 2004-03-25 #i26791#
322             For to-character anchored Writer fly frames the members <maLastCharRect>
323             and <maLastTopOfLine> are updated. These are checked for change and
324             depending on the applied positioning, it's decided, if the Writer fly
325             frame has to be invalidated.
326             OD 2004-07-15 #117380#
327             add parameter <_bCheckForParaPorInf>, default value <true>
328 
329             @author OD
330 
331             @param _bCheckForParaPorInf
332             input parameter - boolean indicating, if check on paragraph portion
333             information has to be done.
334         */
335         void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf = true );
336 
337         // accessors to member <maLastCharRect>
338         const SwRect& GetLastCharRect() const;
339         SwTwips GetRelCharX( const SwFrm* pFrm ) const;
340         SwTwips GetRelCharY( const SwFrm* pFrm ) const;
341         void AddLastCharY( long nDiff );
342         void ResetLastCharRectHeight();
343 
344         // accessor to member <nmLastTopOfLine>
345         SwTwips GetLastTopOfLine() const;
346         // OD 2004-05-18 #i28701# - follow-up of #i22341#
347         void AddLastTopOfLineY( SwTwips _nDiff );
348 
349         /** reset members <maLastCharRect> and <mnLastTopOfLine>
350 
351             OD 2004-06-29 #i27801#
352 
353             @author OD
354         */
355         void ClearCharRectAndTopOfLine();
356 
357         /** method to determine position for the object and set the position
358             at the object
359 
360             @author OD
361         */
362         virtual void MakeObjPos() = 0;
363 
364         /** is positioning of anchored object in progress
365 
366             @author OD
367         */
IsPositioningInProgress() const368         inline bool IsPositioningInProgress() const
369         {
370             return mbPositioningInProgress;
371         }
372 
373         /** method to determine, if invalidation of position is allowed
374 
375             OD 2004-07-01 #i28701#
376 
377             @author OD
378         */
379         bool InvalidationOfPosAllowed() const;
380 
381         /** method to invalidate position of the anchored object
382 
383             @author OD
384         */
385         virtual void InvalidateObjPos() = 0;
386 
387         /** method to perform necessary invalidations for the positioning of
388             objects, for whose the wrapping style influence has to be considered
389             on the object positioning.
390 
391             OD 2004-06-30 #i28701#
392 
393             @author OD
394         */
395         void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd );
396 
397         /** method to trigger notification of 'background'
398 
399             OD 2004-07-01 #i28701#
400 
401             @author OD
402         */
403         virtual void NotifyBackground( SwPageFrm* _pPageFrm,
404                                        const SwRect& _rRect,
405                                        PrepareHint _eHint ) = 0;
406 
407         // accessors to the current relative position (relative to anchor
408         // position of anchor frame)
409         const Point GetCurrRelPos() const;
410         void SetCurrRelPos( Point _aRelPos );
411 
412         // accessors to the format
413         virtual SwFrmFmt& GetFrmFmt() = 0;
414         virtual const SwFrmFmt& GetFrmFmt() const = 0;
415 
416         // accessors to the object area and its position
417         virtual const SwRect GetObjRect() const = 0;
418         // --> OD 2006-08-10 #i68520#
419         void SetObjTop( const SwTwips _nTop);
420         void SetObjLeft( const SwTwips _nLeft);
421         // <--
422 
423         /** method update layout direction the layout direction, the anchored
424             object is assigned to
425 
426             OD 2004-07-27 #i31698#
427             method has typically to be called, if the anchored object gets its
428             anchor frame assigned and if the anchor frame changes its layout direction
429             OD 2006-03-17 #i62875#
430             made virtual, because it's needed to be overloaded by <SwAnchoredDrawObject>
431 
432             @author OD
433         */
434         virtual void UpdateLayoutDir();
435 
436         /** method to determine object area inclusive its spacing
437 
438             OD 2004-06-30 #i28701#
439             OD 2006-08-10 #i68520# - return constant reference
440 
441             @author OD
442         */
443         const SwRect& GetObjRectWithSpaces() const;
444 
445         // --> OD 2006-08-10 #i68520#
InvalidateObjRectWithSpaces() const446         inline void InvalidateObjRectWithSpaces() const
447         {
448             mbObjRectWithSpacesValid = false;
449         }
450         // <--
451 
452         /** method to determine, if wrapping style influence of the anchored
453             object has to be considered on the object positioning
454 
455             OD 2004-06-30 #i28701#
456             Note: result of this method also decides, if the boolean for the
457             layout process are of relevance.
458 
459             @author OD
460         */
461         bool ConsiderObjWrapInfluenceOnObjPos() const;
462 
463         // --> OD 2004-06-29 #i28701# - accessors to booleans for layout process
464         bool ConsiderForTextWrap() const;
465         void SetConsiderForTextWrap( const bool _bConsiderForTextWrap );
466         bool PositionLocked() const;
LockPosition()467         inline void LockPosition()
468         {
469             mbPositionLocked = true;
470         }
UnlockPosition()471         inline void UnlockPosition()
472         {
473             if ( !mbKeepPositionLockedForSection )
474             {
475                 mbPositionLocked = false;
476             }
477         }
478         // --> OD 2005-01-10 #i40147#
SetKeepPosLocked(const bool _bKeepPosLocked)479         inline void SetKeepPosLocked( const bool _bKeepPosLocked )
480         {
481             mbKeepPositionLockedForSection = _bKeepPosLocked;
482         }
483         // <--
484         bool RestartLayoutProcess() const;
485         void SetRestartLayoutProcess( const bool _bRestartLayoutProcess );
486         // --> OD 2004-10-22 #i35911# - accessors for <mbClearedEnvironment>
487         bool ClearedEnvironment() const;
488         void SetClearedEnvironment( const bool _bClearedEnvironment );
489         // <--
490         // --> OD 2005-03-03 #i43913# - reset booleans for layout process
ResetLayoutProcessBools()491         inline void ResetLayoutProcessBools()
492         {
493             mbPositioningInProgress = false;
494             mbConsiderForTextWrap = false;
495             mbPositionLocked = false;
496             mbKeepPositionLockedForSection = false;
497             mbRestartLayoutProcess = false;
498             mbClearedEnvironment = false;
499             mbTmpConsiderWrapInfluence = false;
500         }
501         // <--
502 
503         /** method to determine, if due to anchored object size and wrapping
504             style, its layout environment is cleared.
505 
506             OD 2004-10-22 #i35911#
507 
508             @author OD
509         */
510         bool HasClearedEnvironment() const;
511 
512         /** method to update anchored object in the <SwSortedObjs> lists
513 
514             OD 2004-07-01 #i28701#
515             Method is not proposed to be called during a layout process is
516             running. It has been used on the change of the anchored object
517             attributes, which belongs the sort criteria of <SwSortedObjs>.
518             If document compatibility option 'Consider wrapping style influence
519             on object positioning' is ON, additionally all anchored objects
520             at the anchor frame and all following anchored objects on the page
521             frame are invalidated.
522 
523             @author OD
524         */
525         void UpdateObjInSortedList();
526 
527         /** method to determine, if a format on the anchored object is possible
528 
529             OD 2004-07-23 #i28701#
530             A format isn't possible, if anchored object is in an invisible layer.
531             Note: method is virtual to refine the conditions for the sub-classes.
532 
533             @author OD
534         */
535         virtual bool IsFormatPossible() const;
536 
537         // --> OD 2004-08-25 #i3317# - accessors to member <mbTmpConsiderWrapInfluence>
538         void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
539         bool IsTmpConsiderWrapInfluence() const;
540         // <--
541 
542         /** method to determine, if the anchored object is overlapping with a
543             previous column
544 
545             OD 2004-08-25 #i3317#
546             overlapping with a previous column means, that the object overlaps
547             with a column, which is a previous one of the column its anchor
548             frame is in.
549             Only applied for at-paragraph and at-character anchored objects.
550 
551             @author OD
552         */
553         bool OverlapsPrevColumn() const;
554 
555         /** method to determine position of anchored object relative to
556             anchor frame
557 
558             OD 2005-01-06 #i30669#
559             Usage: Needed layout information for WW8 export
560 
561             @author OD
562 
563             @return Point - determined relative position
564         */
565         Point GetRelPosToAnchorFrm() const;
566 
567         /** method to determine position of anchored object relative to
568             page frame
569 
570             OD 2005-01-06 #i30669#
571             Usage: Needed layout information for WW8 export
572             OD 2005-01-27 #i33818# - add parameters <_bFollowTextFlow> and
573             <_obRelToTableCell>
574             If <_bFollowTextFlow> is set and object is anchored inside table,
575             the position relative to the table cell is determined. Output
576             parameter <_obRelToTableCell> reflects this situation
577 
578             @author OD
579 
580             @param _bFollowTextFlow
581             input parameter - boolean indicating, if the anchored object has to
582             follow the text flow.
583 
584             @param _obRelToTableCell
585             output parameter - boolean indicating, the determine position is
586             relative to the table cell
587 
588             @return Point - determined relative position
589         */
590         Point GetRelPosToPageFrm( const bool _bFollowTextFlow,
591                                   bool& _obRelToTableCell ) const;
592 
593         /** method to determine position of anchored object relative to
594             anchor character
595 
596             OD 2005-01-06 #i30669#
597             Usage: Needed layout information for WW8 export
598 
599             @author OD
600 
601             @return Point - determined relative position
602         */
603         Point GetRelPosToChar() const;
604 
605         /** method to determine position of anchored object relative to
606             top of line
607 
608             OD 2005-01-06 #i30669#
609             Usage: Needed layout information for WW8 export
610 
611             @author OD
612 
613             @return Point - determined relative position
614         */
615         Point GetRelPosToLine() const;
616 };
617 
618 // ============================================================================
619 // OD 2004-04-13 #i26791#, #i28701#
620 // helper class for notify that positioning of an anchored object is in progress
621 // ============================================================================
622 class SwObjPositioningInProgress
623 {
624     private:
625         SwAnchoredObject* mpAnchoredObj;
626         // --> OD 2005-08-09 #i52904# - introduce boolean indicating old state
627         // of anchored object regarding positioning in progress in order to
628         // consider nested usage of class <SwObjPositioningInProgress>
629         bool mbOldObjPositioningInProgress;
630         // <--
631 
632     public:
633         SwObjPositioningInProgress( SdrObject& _rSdrObj );
634         SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
635         ~SwObjPositioningInProgress();
636 };
637 
638 #endif
639