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

Generated by: LCOV version 1.10