LCOV - code coverage report
Current view: top level - sw/inc - anchoredobject.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 40 97.5 %
Date: 2015-06-13 12:38:46 Functions: 18 19 94.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #ifndef INCLUDED_SW_INC_ANCHOREDOBJECT_HXX
      20             : #define INCLUDED_SW_INC_ANCHOREDOBJECT_HXX
      21             : 
      22             : #include <tools/rtti.hxx>
      23             : #include <swtypes.hxx>
      24             : #include <swrect.hxx>
      25             : #include <libxml/xmlwriter.h>
      26             : 
      27             : class SdrObject;
      28             : class SwFrm;
      29             : class SwLayoutFrm;
      30             : class SwTextFrm;
      31             : 
      32             : class SwPageFrm;
      33             : class SwObjPositioningInProgress;
      34             : 
      35             : class SwFrameFormat;
      36             : class SwFormatAnchor;
      37             : 
      38             : /** wrapper class for the positioning of Writer fly frames and drawing objects
      39             : 
      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>).
      43             : 
      44             :     @author OD
      45             : */
      46             : class SW_DLLPUBLIC SwAnchoredObject
      47             : {
      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;
      58             : 
      59             :         // for to-character anchored objects:
      60             :         // Last known anchor character rectangle.
      61             :         // Used to decide, if invalidation has to been performed, if anchor position
      62             :         // has changed, and used to position object.
      63             :         SwRect maLastCharRect;
      64             : 
      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;
      70             : 
      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;
      76             : 
      77             :         // i#i28701 boolean, indicating that the object
      78             :         // positioning algorithm is in progress.
      79             :         bool mbPositioningInProgress;
      80             : 
      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;
      98             : 
      99             :         bool mbRestartLayoutProcess;
     100             :         bool mbClearedEnvironment;
     101             : 
     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;
     112             : 
     113             :         mutable SwRect maObjRectWithSpaces;
     114             :         mutable bool mbObjRectWithSpacesValid;
     115             :         mutable SwRect maLastObjRect;
     116             : 
     117             :         /** method to indicate, that positioning of anchored object is in progress
     118             : 
     119             :             note: method is implemented empty
     120             : 
     121             :             @author OD
     122             :         */
     123             :         friend class SwObjPositioningInProgress;
     124       21652 :         inline void SetPositioningInProgress( const bool _bPosInProgress )
     125             :         {
     126       21652 :             mbPositioningInProgress = _bPosInProgress;
     127       21652 :         }
     128             : 
     129             :         /** check anchor character rectangle
     130             : 
     131             :             helper method for method <CheckCharRectAndTopOfLine()>
     132             :             For to-character anchored Writer fly frames the member <maLastCharRect>
     133             :             is updated. This is checked for change and depending on the applied
     134             :             positioning, it's decided, if the Writer fly frame has to be invalidated.
     135             :             improvement - add second parameter <_rAnchorCharFrm>
     136             : 
     137             :             @author OD
     138             : 
     139             :             @param _rAnch
     140             :             input parameter - reference to anchor position
     141             : 
     142             :             @param _rAnchorCharFrm
     143             :             input parameter - reference to the text frame containing the anchor
     144             :             character.
     145             :         */
     146             :         void _CheckCharRect( const SwFormatAnchor& _rAnch,
     147             :                              const SwTextFrm& _rAnchorCharFrm );
     148             : 
     149             :         /** check top of line
     150             : 
     151             :             helper method for method <CheckCharRectAndTopOfLine()>
     152             :             For to-character anchored Writer fly frames the member <mnLastTopOfLine>
     153             :             is updated. This is checked for change and depending on the applied
     154             :             positioning, it's decided, if the Writer fly frame has to be invalidated.
     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 _CheckTopOfLine( const SwFormatAnchor& _rAnch,
     166             :                               const SwTextFrm& _rAnchorCharFrm );
     167             : 
     168             :         // method <sw_HideObj(..)> sets needed data structure values for the
     169             :         // object positioning
     170             :         friend bool sw_HideObj( const SwTextFrm& _rFrm,
     171             :                                  const RndStdIds _eAnchorType,
     172             :                                  const sal_Int32 _nObjAnchorPos,
     173             :                                  SwAnchoredObject* _pAnchoredObj );
     174             :     protected:
     175             :         SwAnchoredObject();
     176             : 
     177             :         void SetVertPosOrientFrm( const SwLayoutFrm& _rVertPosOrientFrm );
     178             : 
     179             :         /** method to assure that anchored object is registered at the correct
     180             :             page frame
     181             : 
     182             :             @author OD
     183             :         */
     184             :         virtual void RegisterAtCorrectPage() = 0;
     185             : 
     186             :         /** method to indicate, that anchored object is attached to a anchor frame
     187             : 
     188             :             @author OD
     189             :         */
     190             :         virtual void ObjectAttachedToAnchorFrame();
     191             : 
     192             :         /** method to determine, if other anchored objects, also attached at
     193             :             to the anchor frame, have to consider its wrap influence.
     194             : 
     195             :             @author OD
     196             :         */
     197             :         bool ConsiderObjWrapInfluenceOfOtherObjs() const;
     198             : 
     199             :         /** method to apply temporary consideration of wrapping style influence
     200             :             to the anchored objects, which are anchored at the same anchor frame
     201             : 
     202             :             @author OD
     203             :         */
     204             :         void SetTmpConsiderWrapInfluenceOfOtherObjs( const bool bTmpConsiderWrapInfluence );
     205             : 
     206             :         virtual bool _SetObjTop( const SwTwips _nTop) = 0;
     207             :         virtual bool _SetObjLeft( const SwTwips _nLeft) = 0;
     208             : 
     209             :         virtual const SwRect GetObjBoundRect() const = 0;
     210             :     public:
     211             :         TYPEINFO();
     212             : 
     213             :         virtual ~SwAnchoredObject();
     214             : 
     215             :         // accessors to member <mpDrawObj>
     216             :         void SetDrawObj( SdrObject& _rDrawObj );
     217     3285376 :         const SdrObject* GetDrawObj() const { return mpDrawObj;}
     218      296707 :         SdrObject* DrawObj() { return mpDrawObj;}
     219             : 
     220             :         // accessors to member <mpAnchorFrm>
     221      580413 :         const SwFrm* GetAnchorFrm() const { return mpAnchorFrm;}
     222      249941 :         SwFrm* AnchorFrm() { return mpAnchorFrm;}
     223             :         void ChgAnchorFrm( SwFrm* _pNewAnchorFrm );
     224             :         /** determine anchor frame containing the anchor position
     225             : 
     226             :             the anchor frame, which is determined, is <mpAnchorFrm>
     227             :             for an at-page, at-frame or at-paragraph anchored object
     228             :             and the anchor character frame for an at-character and as-character
     229             :             anchored object.
     230             : 
     231             :             @author OD
     232             :         */
     233             :         SwFrm* GetAnchorFrmContainingAnchPos();
     234             : 
     235      278707 :         SwPageFrm* GetPageFrm() { return mpPageFrm;}
     236       14666 :         const SwPageFrm* GetPageFrm() const { return mpPageFrm;}
     237             :         void SetPageFrm( SwPageFrm* _pNewPageFrm );
     238             : 
     239             :         /** method to determine the page frame, on which the 'anchor' of
     240             :             the given anchored object is.
     241             : 
     242             :             Adjust meaning of method and thus its name: If the anchored object
     243             :             or its anchor isn't correctly inserted in the layout, no page frame
     244             :             can be found. Thus, the return type changed to be a pointer and can
     245             :             be NULL.
     246             : 
     247             :             @author OD
     248             : 
     249             :             @param _rAnchoredObj
     250             :             input parameter - anchored object, for which the page frame of its
     251             :             'anchor' has to be determined.
     252             : 
     253             :             @return SwPageFrm&
     254             :             page frame, the 'anchor' of the given anchored object is on
     255             :         */
     256             :         SwPageFrm* FindPageFrmOfAnchor();
     257             : 
     258             :         /** get frame, which contains the anchor character, if the object
     259             :             is anchored at-character or as-character.
     260             : 
     261             :             @author OD
     262             : 
     263             :             @return SwTextFrm*
     264             :             text frame containing the anchor character. It's NULL, if the object
     265             :             isn't anchored at-character resp. as-character.
     266             :         */
     267             :         SwTextFrm* FindAnchorCharFrm();
     268             : 
     269             :         // accessors to data of position calculation:
     270             :         // frame vertical position is orient at
     271       38446 :         const SwLayoutFrm* GetVertPosOrientFrm() const
     272             :         {
     273       38446 :             return mpVertPosOrientFrm;
     274             :         }
     275             :         // method to clear member <mpVertPosOrientFrm>
     276             :         void ClearVertPosOrientFrm();
     277             : 
     278             :         /** check anchor character rectangle and top of line
     279             : 
     280             :             For to-character anchored Writer fly frames the members <maLastCharRect>
     281             :             and <maLastTopOfLine> are updated. These are checked for change and
     282             :             depending on the applied positioning, it's decided, if the Writer fly
     283             :             frame has to be invalidated.
     284             : 
     285             :             @author OD
     286             : 
     287             :             @param _bCheckForParaPorInf
     288             :             input parameter - boolean indicating, if check on paragraph portion
     289             :             information has to be done.
     290             :         */
     291             :         void CheckCharRectAndTopOfLine( const bool _bCheckForParaPorInf = true );
     292             : 
     293             :         // accessors to member <maLastCharRect>
     294        2166 :         const SwRect& GetLastCharRect() const { return maLastCharRect;}
     295             :         SwTwips GetRelCharX( const SwFrm* pFrm ) const;
     296             :         SwTwips GetRelCharY( const SwFrm* pFrm ) const;
     297             :         void AddLastCharY( long nDiff );
     298             :         void ResetLastCharRectHeight();
     299             : 
     300             :         // accessor to member <nmLastTopOfLine>
     301        2120 :         SwTwips GetLastTopOfLine() const { return mnLastTopOfLine;}
     302             :         void AddLastTopOfLineY( SwTwips _nDiff );
     303             : 
     304             :         /** reset members <maLastCharRect> and <mnLastTopOfLine>
     305             : 
     306             :             @author OD
     307             :         */
     308             :         void ClearCharRectAndTopOfLine();
     309             : 
     310             :         /** method to determine position for the object and set the position
     311             :             at the object
     312             : 
     313             :             @author OD
     314             :         */
     315             :         virtual void MakeObjPos() = 0;
     316             : 
     317             :         /** is positioning of anchored object in progress
     318             : 
     319             :             @author OD
     320             :         */
     321       45176 :         inline bool IsPositioningInProgress() const
     322             :         {
     323       45176 :             return mbPositioningInProgress;
     324             :         }
     325             : 
     326             :         /** method to determine, if invalidation of position is allowed
     327             : 
     328             :             @author OD
     329             :         */
     330             :         bool InvalidationOfPosAllowed() const;
     331             : 
     332             :         /** method to invalidate position of the anchored object
     333             : 
     334             :             @author OD
     335             :         */
     336             :         virtual void InvalidateObjPos() = 0;
     337             : 
     338             :         /** method to perform necessary invalidations for the positioning of
     339             :             objects, for whose the wrapping style influence has to be considered
     340             :             on the object positioning.
     341             : 
     342             :             @author OD
     343             :         */
     344             :         void InvalidateObjPosForConsiderWrapInfluence( const bool _bNotifyBackgrd );
     345             : 
     346             :         /** method to trigger notification of 'background'
     347             : 
     348             :             @author OD
     349             :         */
     350             :         virtual void NotifyBackground( SwPageFrm* _pPageFrm,
     351             :                                        const SwRect& _rRect,
     352             :                                        PrepareHint _eHint ) = 0;
     353             : 
     354             :         // accessors to the current relative position (relative to anchor
     355             :         // position of anchor frame)
     356       10581 :         const Point GetCurrRelPos() const { return maRelPos;}
     357             :         void SetCurrRelPos( Point _aRelPos );
     358             : 
     359             :         // accessors to the format
     360             :         virtual SwFrameFormat& GetFrameFormat() = 0;
     361             :         virtual const SwFrameFormat& GetFrameFormat() const = 0;
     362             : 
     363             :         // accessors to the object area and its position
     364             :         virtual const SwRect GetObjRect() const = 0;
     365             : 
     366             :         void SetObjTop( const SwTwips _nTop);
     367             :         void SetObjLeft( const SwTwips _nLeft);
     368             : 
     369             :         /** method update layout direction the layout direction, the anchored
     370             :             object is assigned to
     371             : 
     372             :             method has typically to be called, if the anchored object gets its
     373             :             anchor frame assigned and if the anchor frame changes its layout direction
     374             : 
     375             :             @author OD
     376             :         */
     377             :         virtual void UpdateLayoutDir();
     378             : 
     379             :         /** method to determine object area inclusive its spacing
     380             : 
     381             :             @author OD
     382             :         */
     383             :         const SwRect& GetObjRectWithSpaces() const;
     384             : 
     385       11658 :         inline void InvalidateObjRectWithSpaces() const
     386             :         {
     387       11658 :             mbObjRectWithSpacesValid = false;
     388       11658 :         }
     389             : 
     390             :         /** method to determine, if wrapping style influence of the anchored
     391             :             object has to be considered on the object positioning
     392             : 
     393             :             Note: result of this method also decides, if the boolean for the
     394             :             layout process are of relevance.
     395             : 
     396             :             @author OD
     397             :         */
     398             :         bool ConsiderObjWrapInfluenceOnObjPos() const;
     399             : 
     400             :         // accessors to booleans for layout process
     401             :         bool ConsiderForTextWrap() const;
     402             :         void SetConsiderForTextWrap( const bool _bConsiderForTextWrap );
     403             :         bool PositionLocked() const;
     404        1005 :         inline void LockPosition()
     405             :         {
     406        1005 :             mbPositionLocked = true;
     407        1005 :         }
     408       12736 :         inline void UnlockPosition()
     409             :         {
     410       12736 :             if ( !mbKeepPositionLockedForSection )
     411             :             {
     412       12735 :                 mbPositionLocked = false;
     413             :             }
     414       12736 :         }
     415             : 
     416           4 :         inline void SetKeepPosLocked( const bool _bKeepPosLocked )
     417             :         {
     418           4 :             mbKeepPositionLockedForSection = _bKeepPosLocked;
     419           4 :         }
     420             : 
     421             :         bool RestartLayoutProcess() const;
     422             :         void SetRestartLayoutProcess( const bool _bRestartLayoutProcess );
     423             :         // accessors for <mbClearedEnvironment>
     424             :         bool ClearedEnvironment() const;
     425             :         void SetClearedEnvironment( const bool _bClearedEnvironment );
     426             : 
     427             :         // reset booleans for layout process
     428       15722 :         inline void ResetLayoutProcessBools()
     429             :         {
     430       15722 :             mbPositioningInProgress = false;
     431       15722 :             mbConsiderForTextWrap = false;
     432       15722 :             mbPositionLocked = false;
     433       15722 :             mbKeepPositionLockedForSection = false;
     434       15722 :             mbRestartLayoutProcess = false;
     435       15722 :             mbClearedEnvironment = false;
     436       15722 :             mbTmpConsiderWrapInfluence = false;
     437       15722 :         }
     438             : 
     439             :         /** method to determine, if due to anchored object size and wrapping
     440             :             style, its layout environment is cleared.
     441             : 
     442             :             @author OD
     443             :         */
     444             :         bool HasClearedEnvironment() const;
     445             : 
     446             :         /** method to update anchored object in the <SwSortedObjs> lists
     447             : 
     448             :             Method is not proposed to be called during a layout process is
     449             :             running. It has been used on the change of the anchored object
     450             :             attributes, which belongs the sort criteria of <SwSortedObjs>.
     451             :             If document compatibility option 'Consider wrapping style influence
     452             :             on object positioning' is ON, additionally all anchored objects
     453             :             at the anchor frame and all following anchored objects on the page
     454             :             frame are invalidated.
     455             : 
     456             :             @author OD
     457             :         */
     458             :         void UpdateObjInSortedList();
     459             : 
     460             :         /** method to determine, if a format on the anchored object is possible
     461             : 
     462             :             A format isn't possible, if anchored object is in an invisible layer.
     463             :             Note: method is virtual to refine the conditions for the sub-classes.
     464             : 
     465             :             @author OD
     466             :         */
     467             :         virtual bool IsFormatPossible() const;
     468             : 
     469             :         // accessors to member <mbTmpConsiderWrapInfluence>
     470             :         void SetTmpConsiderWrapInfluence( const bool _bTmpConsiderWrapInfluence );
     471      539261 :         bool IsTmpConsiderWrapInfluence() const { return mbTmpConsiderWrapInfluence;}
     472             : 
     473             :         /** method to determine, if the anchored object is overlapping with a
     474             :             previous column
     475             : 
     476             :             overlapping with a previous column means, that the object overlaps
     477             :             with a column, which is a previous one of the column its anchor
     478             :             frame is in.
     479             :             Only applied for at-paragraph and at-character anchored objects.
     480             : 
     481             :             @author OD
     482             :         */
     483             :         bool OverlapsPrevColumn() const;
     484             : 
     485             :         /** method to determine position of anchored object relative to
     486             :             anchor frame
     487             : 
     488             :             Usage: Needed layout information for WW8 export
     489             : 
     490             :             @author OD
     491             : 
     492             :             @return Point - determined relative position
     493             :         */
     494             :         Point GetRelPosToAnchorFrm() const;
     495             : 
     496             :         /** method to determine position of anchored object relative to
     497             :             page frame
     498             : 
     499             :             Usage: Needed layout information for WW8 export
     500             : 
     501             :             If <_bFollowTextFlow> is set and object is anchored inside table,
     502             :             the position relative to the table cell is determined. Output
     503             :             parameter <_obRelToTableCell> reflects this situation
     504             : 
     505             :             @author OD
     506             : 
     507             :             @param _bFollowTextFlow
     508             :             input parameter - boolean indicating, if the anchored object has to
     509             :             follow the text flow.
     510             : 
     511             :             @param _obRelToTableCell
     512             :             output parameter - boolean indicating, the determine position is
     513             :             relative to the table cell
     514             : 
     515             :             @return Point - determined relative position
     516             :         */
     517             :         Point GetRelPosToPageFrm( const bool _bFollowTextFlow,
     518             :                                   bool& _obRelToTableCell ) const;
     519             : 
     520             :         /** method to determine position of anchored object relative to
     521             :             anchor character
     522             : 
     523             :             Usage: Needed layout information for WW8 export
     524             : 
     525             :             @author OD
     526             : 
     527             :             @return Point - determined relative position
     528             :         */
     529             :         Point GetRelPosToChar() const;
     530             : 
     531             :         /** method to determine position of anchored object relative to
     532             :             top of line
     533             : 
     534             :             Usage: Needed layout information for WW8 export
     535             : 
     536             :             @author OD
     537             : 
     538             :             @return Point - determined relative position
     539             :         */
     540             :         Point GetRelPosToLine() const;
     541             : 
     542             :         /** Dump a bunch of useful data to an XML representation to ease
     543             :             layout understanding, debugging and testing.
     544             :           */
     545             :         virtual void dumpAsXml( xmlTextWriterPtr pWriter ) const;
     546             : 
     547             :         /** The element name to show in the XML dump.
     548             :           */
     549           0 :         virtual const char* getElementName( ) const { return "SwAnchoredObject"; }
     550             : };
     551             : 
     552             : /// Helper class for notify that positioning of an anchored object is in progress.
     553             : class SwObjPositioningInProgress
     554             : {
     555             :     private:
     556             :         SwAnchoredObject* mpAnchoredObj;
     557             :         // boolean indicating old state
     558             :         // of anchored object regarding positioning in progress in order to
     559             :         // consider nested usage of class <SwObjPositioningInProgress>
     560             :         bool mbOldObjPositioningInProgress;
     561             : 
     562             :     public:
     563             :         SwObjPositioningInProgress( SdrObject& _rSdrObj );
     564             :         SwObjPositioningInProgress( SwAnchoredObject& _rAnchoredObj );
     565             :         ~SwObjPositioningInProgress();
     566             : };
     567             : 
     568             : #endif
     569             : 
     570             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11