LCOV - code coverage report
Current view: top level - sw/source/core/doc - doclay.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 543 1031 52.7 %
Date: 2012-08-25 Functions: 34 43 79.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 634 2198 28.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <unotools/linguprops.hxx>
      31                 :            : #include <unotools/lingucfg.hxx>
      32                 :            : #include <com/sun/star/embed/EmbedStates.hpp>
      33                 :            : #include <hintids.hxx>
      34                 :            : #include <com/sun/star/util/XCloseable.hpp>
      35                 :            : #include <sfx2/progress.hxx>
      36                 :            : #include <svx/svdmodel.hxx>
      37                 :            : #include <svx/svdpage.hxx>
      38                 :            : #include <editeng/keepitem.hxx>
      39                 :            : #include <editeng/ulspitem.hxx>
      40                 :            : #include <editeng/lrspitem.hxx>
      41                 :            : #include <editeng/boxitem.hxx>
      42                 :            : #include <editeng/shaditem.hxx>
      43                 :            : #include <editeng/protitem.hxx>
      44                 :            : #include <editeng/opaqitem.hxx>
      45                 :            : #include <editeng/prntitem.hxx>
      46                 :            : #include <svx/fmglob.hxx>
      47                 :            : #include <svx/svdouno.hxx>
      48                 :            : #include <svx/fmpage.hxx>
      49                 :            : #include <editeng/frmdiritem.hxx>
      50                 :            : 
      51                 :            : #include <swmodule.hxx>
      52                 :            : #include <modcfg.hxx>
      53                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      54                 :            : #include <rtl/logfile.hxx>
      55                 :            : #include <SwStyleNameMapper.hxx>
      56                 :            : #include <fchrfmt.hxx>
      57                 :            : #include <frmatr.hxx>
      58                 :            : #include <txatbase.hxx>
      59                 :            : #include <fmtfld.hxx>
      60                 :            : #include <fmtornt.hxx>
      61                 :            : #include <fmtcntnt.hxx>
      62                 :            : #include <fmtanchr.hxx>
      63                 :            : #include <fmtfsize.hxx>
      64                 :            : #include <fmtsrnd.hxx>
      65                 :            : #include <fmtflcnt.hxx>
      66                 :            : #include <fmtcnct.hxx>
      67                 :            : #include <frmfmt.hxx>
      68                 :            : #include <txtflcnt.hxx>
      69                 :            : #include <docfld.hxx>       // for ExpressionFields
      70                 :            : #include <pam.hxx>
      71                 :            : #include <ndtxt.hxx>
      72                 :            : #include <ndnotxt.hxx>
      73                 :            : #include <ndole.hxx>
      74                 :            : #include <doc.hxx>
      75                 :            : #include <IDocumentUndoRedo.hxx>
      76                 :            : #include <rootfrm.hxx>
      77                 :            : #include <pagefrm.hxx>
      78                 :            : #include <cntfrm.hxx>
      79                 :            : #include <flyfrm.hxx>
      80                 :            : #include <fesh.hxx>
      81                 :            : #include <docsh.hxx>
      82                 :            : #include <dflyobj.hxx>
      83                 :            : #include <dcontact.hxx>
      84                 :            : #include <swundo.hxx>
      85                 :            : #include <flypos.hxx>
      86                 :            : #include <UndoInsert.hxx>
      87                 :            : #include <expfld.hxx>       // InsertLabel
      88                 :            : #include <poolfmt.hxx>      // PoolTemplate Ids
      89                 :            : #include <docary.hxx>
      90                 :            : #include <swtable.hxx>
      91                 :            : #include <tblsel.hxx>
      92                 :            : #include <viewopt.hxx>
      93                 :            : #include <fldupde.hxx>
      94                 :            : #include <txtftn.hxx>
      95                 :            : #include <ftnidx.hxx>
      96                 :            : #include <ftninfo.hxx>
      97                 :            : #include <pagedesc.hxx>
      98                 :            : #include <PostItMgr.hxx>
      99                 :            : #include <comcore.hrc>      // STR ResIds
     100                 :            : 
     101                 :            : #include <unoframe.hxx>
     102                 :            : 
     103                 :            : #include <sortedobjs.hxx>
     104                 :            : 
     105                 :            : #include <vector>
     106                 :            : 
     107                 :            : using namespace ::com::sun::star;
     108                 :            : using ::rtl::OUString;
     109                 :            : 
     110                 :            : #define DEF_FLY_WIDTH    2268   // Default width for FlyFrms (2268 == 4cm)
     111                 :            : 
     112                 :            : 
     113                 :          0 : static bool lcl_IsItemSet(const SwCntntNode & rNode, sal_uInt16 which)
     114                 :            : {
     115                 :          0 :     bool bResult = false;
     116                 :            : 
     117         [ #  # ]:          0 :     if (SFX_ITEM_SET == rNode.GetSwAttrSet().GetItemState(which))
     118                 :          0 :         bResult = true;
     119                 :            : 
     120                 :          0 :     return bResult;
     121                 :            : }
     122                 :            : 
     123                 :            : /*************************************************************************
     124                 :            : |*
     125                 :            : |*  SwDoc::MakeLayoutFmt()
     126                 :            : |*
     127                 :            : |*  Description: Create a new format whose settings fit to the Request by
     128                 :            : |*  default.
     129                 :            : |*  The format is put into the respective format array.
     130                 :            : |*  If there already is a fitting format, it is returned instead.
     131                 :            : |*************************************************************************/
     132                 :        131 : SwFrmFmt *SwDoc::MakeLayoutFmt( RndStdIds eRequest, const SfxItemSet* pSet )
     133                 :            : {
     134                 :        131 :     SwFrmFmt *pFmt = 0;
     135                 :        131 :     const sal_Bool bMod = IsModified();
     136                 :        131 :     sal_Bool bHeader = sal_False;
     137                 :            : 
     138   [ +  +  -  - ]:        131 :     switch ( eRequest )
     139                 :            :     {
     140                 :            :     case RND_STD_HEADER:
     141                 :            :     case RND_STD_HEADERL:
     142                 :            :     case RND_STD_HEADERR:
     143                 :            :         {
     144                 :         65 :             bHeader = sal_True;
     145                 :            :             // no break, we continue further down
     146                 :            :         }
     147                 :            :     case RND_STD_FOOTER:
     148                 :            :     case RND_STD_FOOTERL:
     149                 :            :     case RND_STD_FOOTERR:
     150                 :            :         {
     151                 :            :             pFmt = new SwFrmFmt( GetAttrPool(),
     152                 :            :                                  (bHeader ? "Right header" : "Right footer"),
     153 [ +  - ][ +  + ]:        131 :                                  GetDfltFrmFmt() );
                 [ +  - ]
     154                 :            : 
     155 [ +  - ][ +  - ]:        131 :             SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() );
     156                 :            :             SwStartNode* pSttNd =
     157         [ +  - ]:        131 :                 GetNodes().MakeTextSection
     158                 :            :                 ( aTmpIdx,
     159                 :            :                   bHeader ? SwHeaderStartNode : SwFooterStartNode,
     160                 :            :                   GetTxtCollFromPool(static_cast<sal_uInt16>( bHeader
     161                 :            :                                      ? ( eRequest == RND_STD_HEADERL
     162                 :            :                                          ? RES_POOLCOLL_HEADERL
     163                 :            :                                          : eRequest == RND_STD_HEADERR
     164                 :            :                                          ? RES_POOLCOLL_HEADERR
     165                 :            :                                          : RES_POOLCOLL_HEADER )
     166                 :            :                                      : ( eRequest == RND_STD_FOOTERL
     167                 :            :                                          ? RES_POOLCOLL_FOOTERL
     168                 :            :                                          : eRequest == RND_STD_FOOTERR
     169                 :            :                                          ? RES_POOLCOLL_FOOTERR
     170                 :            :                                          : RES_POOLCOLL_FOOTER )
     171 [ +  + ][ +  - ]:        262 :                                      ) ) );
         [ -  + ][ +  - ]
         [ -  + ][ +  - ]
         [ +  + ][ +  - ]
     172 [ +  - ][ +  - ]:        131 :             pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ));
                 [ +  - ]
     173                 :            : 
     174         [ -  + ]:        131 :             if( pSet )      // Set a few more attributes
     175         [ #  # ]:          0 :                 pFmt->SetFmtAttr( *pSet );
     176                 :            : 
     177                 :            :             // Why set it back?  Doc has changed, or not?
     178                 :            :             // In any case, wrong for the FlyFrames!
     179         [ -  + ]:        131 :             if ( !bMod )
     180 [ #  # ][ +  - ]:        131 :                 ResetModified();
     181                 :            :         }
     182                 :        131 :         break;
     183                 :            : 
     184                 :            :     case RND_DRAW_OBJECT:
     185                 :            :         {
     186                 :          0 :             pFmt = MakeDrawFrmFmt( aEmptyStr, GetDfltFrmFmt() );
     187         [ #  # ]:          0 :             if( pSet )      // Set a few more attributes
     188                 :          0 :                 pFmt->SetFmtAttr( *pSet );
     189                 :            : 
     190         [ #  # ]:          0 :             if (GetIDocumentUndoRedo().DoesUndo())
     191                 :            :             {
     192                 :          0 :                 GetIDocumentUndoRedo().AppendUndo(
     193         [ #  # ]:          0 :                     new SwUndoInsLayFmt(pFmt, 0, 0));
     194                 :            :             }
     195                 :            :         }
     196                 :          0 :         break;
     197                 :            : 
     198                 :            : #if OSL_DEBUG_LEVEL > 0
     199                 :            :     case FLY_AT_PAGE:
     200                 :            :     case FLY_AT_CHAR:
     201                 :            :     case FLY_AT_FLY:
     202                 :            :     case FLY_AT_PARA:
     203                 :            :     case FLY_AS_CHAR:
     204                 :            :         OSL_FAIL( "use new interface instead: SwDoc::MakeFlySection!" );
     205                 :            :         break;
     206                 :            : #endif
     207                 :            : 
     208                 :            :     default:
     209                 :            :         OSL_ENSURE( !this,
     210                 :            :                 "LayoutFormat was requested with an invalid Request." );
     211                 :            : 
     212                 :            :     }
     213                 :        131 :     return pFmt;
     214                 :            : }
     215                 :            : 
     216                 :            : /*************************************************************************
     217                 :            : |*
     218                 :            : |*  SwDoc::DelLayoutFmt()
     219                 :            : |*
     220                 :            : |*  Description: Deletes the denoted format and its content.
     221                 :            : |*
     222                 :            : |*************************************************************************/
     223                 :        882 : void SwDoc::DelLayoutFmt( SwFrmFmt *pFmt )
     224                 :            : {
     225                 :            :     // A chain of frames needs to be merged, if necessary,
     226                 :            :     // so that the Frame's contents are adjusted accordingly before we destroy the Frames.
     227                 :        882 :     const SwFmtChain &rChain = pFmt->GetChain();
     228         [ -  + ]:        882 :     if ( rChain.GetPrev() )
     229                 :            :     {
     230 [ #  # ][ #  # ]:          0 :         SwFmtChain aChain( rChain.GetPrev()->GetChain() );
     231         [ #  # ]:          0 :         aChain.SetNext( rChain.GetNext() );
     232 [ #  # ][ #  # ]:          0 :         SetAttr( aChain, *rChain.GetPrev() );
     233                 :            :     }
     234         [ -  + ]:        882 :     if ( rChain.GetNext() )
     235                 :            :     {
     236 [ #  # ][ #  # ]:          0 :         SwFmtChain aChain( rChain.GetNext()->GetChain() );
     237         [ #  # ]:          0 :         aChain.SetPrev( rChain.GetPrev() );
     238 [ #  # ][ #  # ]:          0 :         SetAttr( aChain, *rChain.GetNext() );
     239                 :            :     }
     240                 :            : 
     241                 :        882 :     const SwNodeIndex* pCntIdx = pFmt->GetCntnt().GetCntntIdx();
     242 [ +  + ][ +  + ]:        882 :     if (pCntIdx && !GetIDocumentUndoRedo().DoesUndo())
                 [ +  + ]
     243                 :            :     {
     244                 :            :         // Disconnect if it's an OLE object
     245                 :          6 :         SwOLENode* pOLENd = GetNodes()[ pCntIdx->GetIndex()+1 ]->GetOLENode();
     246 [ #  # ][ -  + ]:          6 :         if( pOLENd && pOLENd->GetOLEObj().IsOleRef() )
                 [ -  + ]
     247                 :            :         {
     248                 :            : 
     249                 :            :             // TODO: the old object closed the object and cleared all references to it, but didn't remove it from the container.
     250                 :            :             // I have no idea, why, nobody could explain it - so I do my very best to mimic this behavior
     251                 :            :             //uno::Reference < util::XCloseable > xClose( pOLENd->GetOLEObj().GetOleRef(), uno::UNO_QUERY );
     252                 :            :             //if ( xClose.is() )
     253                 :            :             {
     254                 :            :                 try
     255                 :            :                 {
     256 [ #  # ][ #  # ]:          0 :                     pOLENd->GetOLEObj().GetOleRef()->changeState( embed::EmbedStates::LOADED );
         [ #  # ][ #  # ]
     257                 :            :                 }
     258                 :          0 :                 catch ( uno::Exception& )
     259                 :            :                 {
     260                 :            :                 }
     261                 :            :             }
     262                 :            : 
     263                 :            :         }
     264                 :            :     }
     265                 :            : 
     266                 :            :     // Destroy Frames
     267                 :        882 :     pFmt->DelFrms();
     268                 :            : 
     269                 :            :     // Only FlyFrames are undoable at first
     270                 :        882 :     const sal_uInt16 nWh = pFmt->Which();
     271 [ +  + ][ +  - ]:        882 :     if (GetIDocumentUndoRedo().DoesUndo() &&
         [ +  + ][ +  + ]
     272                 :            :         (RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh))
     273                 :            :     {
     274         [ +  - ]:         10 :         GetIDocumentUndoRedo().AppendUndo( new SwUndoDelLayFmt( pFmt ));
     275                 :            :     }
     276                 :            :     else
     277                 :            :     {
     278                 :            :         // #i32089# - delete at-frame anchored objects
     279         [ +  + ]:        872 :         if ( nWh == RES_FLYFRMFMT )
     280                 :            :         {
     281                 :            :             // determine frame formats of at-frame anchored objects
     282                 :        383 :             const SwNodeIndex* pCntntIdx = pFmt->GetCntnt().GetCntntIdx();
     283         [ +  + ]:        383 :             if ( pCntntIdx )
     284                 :            :             {
     285                 :          6 :                 const SwFrmFmts* pTbl = pFmt->GetDoc()->GetSpzFrmFmts();
     286         [ +  - ]:          6 :                 if ( pTbl )
     287                 :            :                 {
     288         [ +  - ]:          6 :                     std::vector<SwFrmFmt*> aToDeleteFrmFmts;
     289                 :          6 :                     const sal_uLong nNodeIdxOfFlyFmt( pCntntIdx->GetIndex() );
     290                 :            : 
     291         [ +  + ]:         18 :                     for ( sal_uInt16 i = 0; i < pTbl->size(); ++i )
     292                 :            :                     {
     293         [ +  - ]:         12 :                         SwFrmFmt* pTmpFmt = (*pTbl)[i];
     294         [ +  - ]:         12 :                         const SwFmtAnchor &rAnch = pTmpFmt->GetAnchor();
     295   [ -  +  #  # ]:         12 :                         if ( rAnch.GetAnchorId() == FLY_AT_FLY &&
                 [ -  + ]
     296         [ #  # ]:          0 :                              rAnch.GetCntntAnchor()->nNode.GetIndex() == nNodeIdxOfFlyFmt )
     297                 :            :                         {
     298         [ #  # ]:          0 :                             aToDeleteFrmFmts.push_back( pTmpFmt );
     299                 :            :                         }
     300                 :            :                     }
     301                 :            : 
     302                 :            :                     // delete found frame formats
     303         [ -  + ]:          6 :                     while ( !aToDeleteFrmFmts.empty() )
     304                 :            :                     {
     305         [ #  # ]:          0 :                         SwFrmFmt* pTmpFmt = aToDeleteFrmFmts.back();
     306         [ #  # ]:          0 :                         pFmt->GetDoc()->DelLayoutFmt( pTmpFmt );
     307                 :            : 
     308         [ #  # ]:          0 :                         aToDeleteFrmFmts.pop_back();
     309                 :          6 :                     }
     310                 :            :                 }
     311                 :            :             }
     312                 :            :         }
     313                 :            : 
     314                 :            :         // Delete content
     315         [ +  + ]:        872 :         if( pCntIdx )
     316                 :            :         {
     317                 :          6 :             SwNode *pNode = &pCntIdx->GetNode();
     318                 :          6 :             ((SwFmtCntnt&)pFmt->GetFmtAttr( RES_CNTNT )).SetNewCntntIdx( 0 );
     319                 :          6 :             DeleteSection( pNode );
     320                 :            :         }
     321                 :            : 
     322                 :            :         // Delete the character for FlyFrames anchored as char (if necessary)
     323                 :        872 :         const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
     324 [ +  + ][ +  + ]:        872 :         if ((FLY_AS_CHAR == rAnchor.GetAnchorId()) && rAnchor.GetCntntAnchor())
                 [ +  + ]
     325                 :            :         {
     326                 :          6 :             const SwPosition* pPos = rAnchor.GetCntntAnchor();
     327                 :          6 :             SwTxtNode *pTxtNd = pPos->nNode.GetNode().GetTxtNode();
     328                 :            : 
     329                 :            :             // attribute is still in text node, delete it
     330         [ +  + ]:          6 :             if ( pTxtNd )
     331                 :            :             {
     332                 :            :                 SwTxtFlyCnt* const pAttr = static_cast<SwTxtFlyCnt*>(
     333                 :          3 :                     pTxtNd->GetTxtAttrForCharAt( pPos->nContent.GetIndex(),
     334                 :          3 :                         RES_TXTATR_FLYCNT ));
     335 [ #  # ][ -  + ]:          3 :                 if ( pAttr && (pAttr->GetFlyCnt().GetFrmFmt() == pFmt) )
                 [ -  + ]
     336                 :            :                 {
     337                 :            :                     // dont delete, set pointer to 0
     338                 :          0 :                     const_cast<SwFmtFlyCnt&>(pAttr->GetFlyCnt()).SetFlyFmt();
     339         [ #  # ]:          0 :                     SwIndex aIdx( pPos->nContent );
     340 [ #  # ][ #  # ]:          0 :                     pTxtNd->EraseText( aIdx, 1 );
     341                 :            :                 }
     342                 :            :             }
     343                 :            :         }
     344                 :            : 
     345                 :        872 :         DelFrmFmt( pFmt );
     346                 :            :     }
     347                 :        882 :     SetModified();
     348                 :        882 : }
     349                 :            : 
     350                 :            : /*************************************************************************
     351                 :            : |*
     352                 :            : |*  SwDoc::CopyLayoutFmt()
     353                 :            : |*
     354                 :            : |*  Copies the stated format (pSrc) to pDest and returns pDest.
     355                 :            : |*  If there's no pDest, it is created.
     356                 :            : |*  If the source format is located in another document, also copy correctly
     357                 :            : |*  in this case.
     358                 :            : |*  The Anchor attribute's position is always set to 0!
     359                 :            : |*
     360                 :            : |*************************************************************************/
     361                 :          6 : SwFrmFmt *SwDoc::CopyLayoutFmt( const SwFrmFmt& rSource,
     362                 :            :                                 const SwFmtAnchor& rNewAnchor,
     363                 :            :                                 bool bSetTxtFlyAtt, bool bMakeFrms )
     364                 :            : {
     365                 :          6 :     const bool bFly = RES_FLYFRMFMT == rSource.Which();
     366                 :          6 :     const bool bDraw = RES_DRAWFRMFMT == rSource.Which();
     367                 :            :     OSL_ENSURE( bFly || bDraw, "this method only works for fly or draw" );
     368                 :            : 
     369                 :          6 :     SwDoc* pSrcDoc = (SwDoc*)rSource.GetDoc();
     370                 :            : 
     371                 :            :     // May we copy this object?
     372                 :            :     // We may, unless it's 1) it's a control (and therfore a draw)
     373                 :            :     //                     2) anchored in a header/footer
     374                 :            :     //                     3) anchored (to paragraph?)
     375                 :          6 :     bool bMayNotCopy = false;
     376         [ +  + ]:          6 :     if( bDraw )
     377                 :            :     {
     378                 :            :         const SwDrawContact* pDrawContact =
     379                 :          3 :             static_cast<const SwDrawContact*>( rSource.FindContactObj() );
     380                 :            : 
     381                 :            :         bMayNotCopy =
     382                 :          3 :             ((FLY_AT_PARA == rNewAnchor.GetAnchorId()) ||
     383                 :          0 :              (FLY_AT_FLY  == rNewAnchor.GetAnchorId()) ||
     384                 :          0 :              (FLY_AT_CHAR == rNewAnchor.GetAnchorId())) &&
     385                 :          3 :             rNewAnchor.GetCntntAnchor() &&
     386                 :          3 :             IsInHeaderFooter( rNewAnchor.GetCntntAnchor()->nNode ) &&
     387                 :            :             pDrawContact != NULL  &&
     388                 :          3 :             pDrawContact->GetMaster() != NULL  &&
     389   [ +  -  +  - ]:         12 :             CheckControlLayer( pDrawContact->GetMaster() );
         [ -  + ][ -  +  
          #  #  #  #  +  
                -  +  - ]
     390                 :            :     }
     391                 :            : 
     392                 :            :     // just return if we can't copy this
     393         [ -  + ]:          6 :     if( bMayNotCopy )
     394                 :          0 :         return NULL;
     395                 :            : 
     396                 :          6 :     SwFrmFmt* pDest = GetDfltFrmFmt();
     397         [ +  + ]:          6 :     if( rSource.GetRegisteredIn() != pSrcDoc->GetDfltFrmFmt() )
     398                 :          3 :         pDest = CopyFrmFmt( *(SwFrmFmt*)rSource.GetRegisteredIn() );
     399         [ +  + ]:          6 :     if( bFly )
     400                 :            :     {
     401                 :            :         // #i11176#
     402                 :            :         // To do a correct cloning concerning the ZOrder for all objects
     403                 :            :         // it is necessary to actually create a draw object for fly frames, too.
     404                 :            :         // These are then added to the DrawingLayer (which needs to exist).
     405                 :            :         // Together with correct sorting of all drawinglayer based objects
     406                 :            :         // before cloning ZOrder transfer works correctly then.
     407                 :          3 :         SwFlyFrmFmt *pFormat = MakeFlyFrmFmt( rSource.GetName(), pDest );
     408                 :          3 :         pDest = pFormat;
     409                 :            : 
     410                 :          3 :         SwXFrame::GetOrCreateSdrObject(pFormat);
     411                 :            :     }
     412                 :            :     else
     413                 :          3 :         pDest = MakeDrawFrmFmt( aEmptyStr, pDest );
     414                 :            : 
     415                 :            :     // Copy all other or new attributes
     416                 :          6 :     pDest->CopyAttrs( rSource );
     417                 :            : 
     418                 :            :     // Do not copy chains
     419                 :          6 :     pDest->ResetFmtAttr( RES_CHAIN );
     420                 :            : 
     421         [ +  + ]:          6 :     if( bFly )
     422                 :            :     {
     423                 :            :         // Duplicate the content.
     424         [ +  - ]:          3 :         const SwNode& rCSttNd = rSource.GetCntnt().GetCntntIdx()->GetNode();
     425         [ +  - ]:          3 :         SwNodeRange aRg( rCSttNd, 1, *rCSttNd.EndOfSectionNode() );
     426                 :            : 
     427 [ +  - ][ +  - ]:          3 :         SwNodeIndex aIdx( GetNodes().GetEndOfAutotext() );
     428 [ +  - ][ +  - ]:          3 :         SwStartNode* pSttNd = GetNodes().MakeEmptySection( aIdx, SwFlyStartNode );
     429                 :            : 
     430                 :            :         // Set the Anchor/CntntIndex first.
     431                 :            :         // Within the copying part, we can access the values (DrawFmt in Headers and Footers)
     432         [ +  - ]:          3 :         aIdx = *pSttNd;
     433 [ +  - ][ +  - ]:          3 :         SwFmtCntnt aAttr( rSource.GetCntnt() );
     434         [ +  - ]:          3 :         aAttr.SetNewCntntIdx( &aIdx );
     435         [ +  - ]:          3 :         pDest->SetFmtAttr( aAttr );
     436         [ +  - ]:          3 :         pDest->SetFmtAttr( rNewAnchor );
     437                 :            : 
     438 [ -  + ][ #  # ]:          3 :         if( !mbCopyIsMove || this != pSrcDoc )
     439                 :            :         {
     440         [ +  - ]:          3 :             if( mbInReading )
     441         [ +  - ]:          3 :                 pDest->SetName( aEmptyStr );
     442                 :            :             else
     443                 :            :             {
     444                 :            :                 // Test first if the name is already taken, if so generate a new one.
     445                 :          0 :                 sal_Int8 nNdTyp = aRg.aStart.GetNode().GetNodeType();
     446                 :            : 
     447         [ #  # ]:          0 :                 String sOld( pDest->GetName() );
     448         [ #  # ]:          0 :                 pDest->SetName( aEmptyStr );
     449 [ #  # ][ #  # ]:          0 :                 if( FindFlyByName( sOld, nNdTyp ) )     // found one
     450      [ #  #  # ]:          0 :                     switch( nNdTyp )
     451                 :            :                     {
     452 [ #  # ][ #  # ]:          0 :                     case ND_GRFNODE:    sOld = GetUniqueGrfName();      break;
                 [ #  # ]
     453 [ #  # ][ #  # ]:          0 :                     case ND_OLENODE:    sOld = GetUniqueOLEName();      break;
                 [ #  # ]
     454 [ #  # ][ #  # ]:          0 :                     default:            sOld = GetUniqueFrameName();    break;
                 [ #  # ]
     455                 :            :                     }
     456                 :            : 
     457 [ #  # ][ #  # ]:          0 :                 pDest->SetName( sOld );
     458                 :            :             }
     459                 :            :         }
     460                 :            : 
     461 [ +  - ][ +  - ]:          3 :         if (GetIDocumentUndoRedo().DoesUndo())
                 [ -  + ]
     462                 :            :         {
     463 [ #  # ][ #  # ]:          0 :             GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFmt(pDest,0,0));
         [ #  # ][ #  # ]
     464                 :            :         }
     465                 :            : 
     466                 :            :         // Make sure that FlyFrames in FlyFrames are copied
     467         [ +  - ]:          3 :         aIdx = *pSttNd->EndOfSectionNode();
     468                 :            : 
     469                 :            :         //fdo#36631 disable (scoped) any undo operations associated with the
     470                 :            :         //contact object itself. They should be managed by SwUndoInsLayFmt.
     471 [ +  - ][ +  - ]:          3 :         const ::sw::DrawUndoGuard drawUndoGuard(GetIDocumentUndoRedo());
     472                 :            : 
     473 [ +  - ][ +  - ]:          3 :         pSrcDoc->CopyWithFlyInFly( aRg, 0, aIdx, sal_False, sal_True, sal_True );
         [ +  - ][ +  - ]
                 [ +  - ]
     474                 :            :     }
     475                 :            :     else
     476                 :            :     {
     477                 :            :         OSL_ENSURE( RES_DRAWFRMFMT == rSource.Which(), "Neither Fly nor Draw." );
     478                 :            :         // #i52780# - Note: moving object to visible layer not needed.
     479                 :          3 :         SwDrawContact* pSourceContact = (SwDrawContact *)rSource.FindContactObj();
     480                 :            : 
     481                 :            :         SwDrawContact* pContact = new SwDrawContact( (SwDrawFrmFmt*)pDest,
     482                 :          3 :                                 CloneSdrObj( *pSourceContact->GetMaster(),
     483 [ #  # ][ +  - ]:          6 :                                         mbCopyIsMove && this == pSrcDoc ) );
                 [ -  + ]
     484                 :            :         // #i49730# - notify draw frame format that position attributes are
     485                 :            :         // already set, if the position attributes are already set at the
     486                 :            :         // source draw frame format.
     487   [ +  -  +  -  :          9 :         if ( pDest->ISA(SwDrawFrmFmt) &&
           -  + ][ -  + ]
     488                 :          3 :              rSource.ISA(SwDrawFrmFmt) &&
     489                 :          3 :              static_cast<const SwDrawFrmFmt&>(rSource).IsPosAttrSet() )
     490                 :            :         {
     491                 :          0 :             static_cast<SwDrawFrmFmt*>(pDest)->PosAttrSet();
     492                 :            :         }
     493                 :            : 
     494         [ -  + ]:          3 :         if( pDest->GetAnchor() == rNewAnchor )
     495                 :            :         {
     496                 :            :             // Do *not* connect to layout, if a <MakeFrms> will not be called.
     497         [ #  # ]:          0 :             if ( bMakeFrms )
     498                 :            :             {
     499                 :          0 :                 pContact->ConnectToLayout( &rNewAnchor );
     500                 :            :             }
     501                 :            :         }
     502                 :            :         else
     503                 :          3 :             pDest->SetFmtAttr( rNewAnchor );
     504                 :            : 
     505         [ -  + ]:          3 :         if (GetIDocumentUndoRedo().DoesUndo())
     506                 :            :         {
     507         [ #  # ]:          0 :             GetIDocumentUndoRedo().AppendUndo(new SwUndoInsLayFmt(pDest,0,0));
     508                 :            :         }
     509                 :            :     }
     510                 :            : 
     511 [ -  + ][ #  # ]:          6 :     if (bSetTxtFlyAtt && (FLY_AS_CHAR == rNewAnchor.GetAnchorId()))
                 [ -  + ]
     512                 :            :     {
     513         [ #  # ]:          0 :         const SwPosition* pPos = rNewAnchor.GetCntntAnchor();
     514         [ #  # ]:          0 :         SwFmtFlyCnt aFmt( pDest );
     515                 :          0 :         pPos->nNode.GetNode().GetTxtNode()->InsertItem(
     516 [ #  # ][ #  # ]:          0 :             aFmt, pPos->nContent.GetIndex(), 0 );
     517                 :            :     }
     518                 :            : 
     519         [ +  + ]:          6 :     if( bMakeFrms )
     520                 :          3 :         pDest->MakeFrms();
     521                 :            : 
     522                 :          6 :     return pDest;
     523                 :            : }
     524                 :            : 
     525                 :          3 : SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, sal_Bool bMoveWithinDoc,
     526                 :            :                                 sal_Bool bInsInPage )
     527                 :            : {
     528                 :            :     // #i52858# - method name changed
     529 [ +  - ][ +  - ]:          3 :     SdrPage *pPg = GetOrCreateDrawModel()->GetPage( 0 );
     530         [ -  + ]:          3 :     if( !pPg )
     531                 :            :     {
     532 [ #  # ][ #  # ]:          0 :         pPg = GetDrawModel()->AllocPage( sal_False );
     533 [ #  # ][ #  # ]:          0 :         GetDrawModel()->InsertPage( pPg );
     534                 :            :     }
     535                 :            : 
     536         [ +  - ]:          3 :     SdrObject *pObj = rObj.Clone();
     537 [ -  + ][ #  # ]:          3 :     if( bMoveWithinDoc && FmFormInventor == pObj->GetObjInventor() )
         [ #  # ][ -  + ]
     538                 :            :     {
     539                 :            :         // We need to preserve the Name for Controls
     540         [ #  # ]:          0 :         uno::Reference< awt::XControlModel >  xModel = ((SdrUnoObj*)pObj)->GetUnoControlModel();
     541                 :          0 :         uno::Any aVal;
     542         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet >  xSet(xModel, uno::UNO_QUERY);
     543         [ #  # ]:          0 :         OUString sName(RTL_CONSTASCII_USTRINGPARAM("Name"));
     544         [ #  # ]:          0 :         if( xSet.is() )
     545 [ #  # ][ #  # ]:          0 :             aVal = xSet->getPropertyValue( sName );
     546         [ #  # ]:          0 :         if( bInsInPage )
     547         [ #  # ]:          0 :             pPg->InsertObject( pObj );
     548         [ #  # ]:          0 :         if( xSet.is() )
     549 [ #  # ][ #  # ]:          0 :             xSet->setPropertyValue( sName, aVal );
     550                 :            :     }
     551         [ +  - ]:          3 :     else if( bInsInPage )
     552         [ +  - ]:          3 :         pPg->InsertObject( pObj );
     553                 :            : 
     554                 :            :     // For drawing objects: set layer of cloned object to invisible layer
     555         [ +  - ]:          3 :     SdrLayerID nLayerIdForClone = rObj.GetLayer();
     556 [ +  - ][ +  - ]:          9 :     if ( !pObj->ISA(SwFlyDrawObj) &&
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     557 [ +  - ][ +  - ]:          3 :          !pObj->ISA(SwVirtFlyDrawObj) &&
     558 [ +  - ][ +  - ]:          3 :          !IS_TYPE(SdrObject,pObj) )
                 [ +  - ]
     559                 :            :     {
     560 [ +  - ][ -  + ]:          3 :         if ( IsVisibleLayerId( nLayerIdForClone ) )
     561                 :            :         {
     562         [ #  # ]:          0 :             nLayerIdForClone = GetInvisibleLayerIdByVisibleOne( nLayerIdForClone );
     563                 :            :         }
     564                 :            :     }
     565         [ +  - ]:          3 :     pObj->SetLayer( nLayerIdForClone );
     566                 :            : 
     567                 :            : 
     568                 :          3 :     return pObj;
     569                 :            : }
     570                 :            : 
     571                 :        652 : SwFlyFrmFmt* SwDoc::_MakeFlySection( const SwPosition& rAnchPos,
     572                 :            :                                     const SwCntntNode& rNode,
     573                 :            :                                     RndStdIds eRequestId,
     574                 :            :                                     const SfxItemSet* pFlySet,
     575                 :            :                                     SwFrmFmt* pFrmFmt )
     576                 :            : {
     577         [ -  + ]:        652 :     if( !pFrmFmt )
     578         [ #  # ]:          0 :         pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_FRAME );
     579                 :            : 
     580         [ +  - ]:        652 :     String sName;
     581         [ +  + ]:        652 :     if( !mbInReading )
     582      [ +  +  + ]:        107 :         switch( rNode.GetNodeType() )
     583                 :            :         {
     584 [ +  - ][ +  - ]:         15 :         case ND_GRFNODE:        sName = GetUniqueGrfName();     break;
                 [ +  - ]
     585 [ +  - ][ +  - ]:          6 :         case ND_OLENODE:        sName = GetUniqueOLEName();     break;
                 [ +  - ]
     586 [ +  - ][ +  - ]:        107 :         default:                sName = GetUniqueFrameName();       break;
                 [ +  - ]
     587                 :            :         }
     588         [ +  - ]:        652 :     SwFlyFrmFmt* pFmt = MakeFlyFrmFmt( sName, pFrmFmt );
     589                 :            : 
     590                 :            :     // Create content and connect to the format.
     591                 :            :     // Create CntntNode and put it into the autotext selection.
     592         [ +  - ]:        652 :     SwNodeRange aRange( GetNodes().GetEndOfAutotext(), -1,
     593 [ +  - ][ +  - ]:       1304 :                         GetNodes().GetEndOfAutotext() );
     594 [ +  - ][ +  - ]:        652 :     GetNodes().SectionDown( &aRange, SwFlyStartNode );
     595                 :            : 
     596 [ +  - ][ +  - ]:        652 :     pFmt->SetFmtAttr( SwFmtCntnt( rNode.StartOfSectionNode() ));
                 [ +  - ]
     597                 :            : 
     598                 :            : 
     599                 :        652 :     const SwFmtAnchor* pAnchor = 0;
     600         [ +  - ]:        652 :     if( pFlySet )
     601                 :            :     {
     602                 :            :         pFlySet->GetItemState( RES_ANCHOR, sal_False,
     603         [ +  - ]:        652 :                                 (const SfxPoolItem**)&pAnchor );
     604 [ +  - ][ -  + ]:        652 :         if( SFX_ITEM_SET == pFlySet->GetItemState( RES_CNTNT, sal_False ))
     605                 :            :         {
     606         [ #  # ]:          0 :             SfxItemSet aTmpSet( *pFlySet );
     607         [ #  # ]:          0 :             aTmpSet.ClearItem( RES_CNTNT );
     608 [ #  # ][ #  # ]:          0 :             pFmt->SetFmtAttr( aTmpSet );
     609                 :            :         }
     610                 :            :         else
     611         [ +  - ]:        652 :             pFmt->SetFmtAttr( *pFlySet );
     612                 :            :     }
     613                 :            : 
     614                 :            :     // Anchor not yet set?
     615                 :        652 :     RndStdIds eAnchorId = pAnchor ? pAnchor->GetAnchorId()
     616 [ +  - ][ #  # ]:        652 :                                   : pFmt->GetAnchor().GetAnchorId();
     617                 :            :     // #i107811# Assure that at-page anchored fly frames have a page num or a
     618                 :            :     // content anchor set.
     619   [ +  -  +  + ]:       2055 :     if ( !pAnchor ||
           [ +  +  +  + ]
           [ +  +  -  + ]
                 [ +  + ]
     620                 :        652 :          ( FLY_AT_PAGE != pAnchor->GetAnchorId() &&
     621         [ +  - ]:        621 :            !pAnchor->GetCntntAnchor() ) ||
     622                 :         82 :          ( FLY_AT_PAGE == pAnchor->GetAnchorId() &&
     623         [ +  - ]:         31 :            !pAnchor->GetCntntAnchor() &&
     624                 :         17 :            pAnchor->GetPageNum() == 0 ) )
     625                 :            :     {
     626                 :            :         // set it again, needed for Undo
     627 [ +  - ][ +  - ]:        570 :         SwFmtAnchor aAnch( pFmt->GetAnchor() );
     628 [ +  - ][ -  + ]:        570 :         if (pAnchor && (FLY_AT_FLY == pAnchor->GetAnchorId()))
                 [ -  + ]
     629                 :            :         {
     630 [ #  # ][ #  # ]:          0 :             SwPosition aPos( *rAnchPos.nNode.GetNode().FindFlyStartNode() );
     631         [ #  # ]:          0 :             aAnch.SetAnchor( &aPos );
     632         [ #  # ]:          0 :             eAnchorId = FLY_AT_FLY;
     633                 :            :         }
     634                 :            :         else
     635                 :            :         {
     636 [ +  + ][ -  + ]:       1105 :             if( eRequestId != aAnch.GetAnchorId() &&
                 [ -  + ]
     637         [ +  - ]:        535 :                 SFX_ITEM_SET != pFmt->GetItemState( RES_ANCHOR, sal_True ) )
     638                 :            :             {
     639                 :          0 :                 aAnch.SetType( eRequestId );
     640                 :            :             }
     641                 :            : 
     642                 :        570 :             eAnchorId = aAnch.GetAnchorId();
     643         [ #  # ]:        570 :             if ( FLY_AT_PAGE != eAnchorId ||
           [ #  #  #  # ]
         [ +  - ][ -  + ]
     644                 :            :                  ( FLY_AT_PAGE == eAnchorId &&
     645                 :          0 :                    ( !pAnchor ||
     646                 :          0 :                      aAnch.GetPageNum() == 0 ) ) )
     647                 :            :             {
     648         [ +  - ]:        570 :                 aAnch.SetAnchor( &rAnchPos );
     649                 :            :             }
     650                 :            :         }
     651 [ +  - ][ +  - ]:        570 :         pFmt->SetFmtAttr( aAnch );
     652                 :            :     }
     653                 :            :     else
     654         [ +  - ]:         82 :         eAnchorId = pFmt->GetAnchor().GetAnchorId();
     655                 :            : 
     656         [ +  + ]:        652 :     if ( FLY_AS_CHAR == eAnchorId )
     657                 :            :     {
     658                 :        469 :         xub_StrLen nStt = rAnchPos.nContent.GetIndex();
     659                 :        469 :         SwTxtNode * pTxtNode = rAnchPos.nNode.GetNode().GetTxtNode();
     660                 :            : 
     661                 :            :         OSL_ENSURE(pTxtNode!= 0, "There should be a SwTxtNode!");
     662                 :            : 
     663         [ +  - ]:        469 :         if (pTxtNode != NULL)
     664                 :            :         {
     665         [ +  - ]:        469 :             SwFmtFlyCnt aFmt( pFmt );
     666 [ +  - ][ +  - ]:        469 :             pTxtNode->InsertItem( aFmt, nStt, nStt );
     667                 :            :         }
     668                 :            :     }
     669                 :            : 
     670 [ +  - ][ +  + ]:        652 :     if( SFX_ITEM_SET != pFmt->GetAttrSet().GetItemState( RES_FRM_SIZE ))
     671                 :            :     {
     672         [ +  - ]:          3 :         SwFmtFrmSize aFmtSize( ATT_VAR_SIZE, 0, DEF_FLY_WIDTH );
     673                 :          3 :         const SwNoTxtNode* pNoTxtNode = rNode.GetNoTxtNode();
     674         [ +  - ]:          3 :         if( pNoTxtNode )
     675                 :            :         {
     676                 :            :             // Set size
     677         [ +  - ]:          3 :              Size aSize( pNoTxtNode->GetTwipSize() );
     678         [ +  - ]:          3 :             if( MINFLY > aSize.Width() )
     679                 :          3 :                 aSize.Width() = DEF_FLY_WIDTH;
     680                 :          3 :             aFmtSize.SetWidth( aSize.Width() );
     681         [ -  + ]:          3 :             if( aSize.Height() )
     682                 :            :             {
     683                 :          0 :                 aFmtSize.SetHeight( aSize.Height() );
     684                 :          3 :                 aFmtSize.SetHeightSizeType( ATT_FIX_SIZE );
     685                 :            :             }
     686                 :            :         }
     687 [ +  - ][ +  - ]:          3 :         pFmt->SetFmtAttr( aFmtSize );
     688                 :            :     }
     689                 :            : 
     690                 :            :     // Set up frames
     691 [ +  - ][ +  + ]:        652 :     if( GetCurrentViewShell() )
     692         [ +  - ]:        104 :         pFmt->MakeFrms();           // ???  //swmod 071108//swmod 071225
     693                 :            : 
     694 [ +  - ][ +  - ]:        652 :     if (GetIDocumentUndoRedo().DoesUndo())
                 [ +  + ]
     695                 :            :     {
     696                 :        104 :         sal_uLong nNodeIdx = rAnchPos.nNode.GetIndex();
     697                 :        104 :         xub_StrLen nCntIdx = rAnchPos.nContent.GetIndex();
     698         [ +  - ]:        104 :         GetIDocumentUndoRedo().AppendUndo(
     699 [ +  - ][ +  - ]:        104 :             new SwUndoInsLayFmt( pFmt, nNodeIdx, nCntIdx ));
                 [ +  - ]
     700                 :            :     }
     701                 :            : 
     702         [ +  - ]:        652 :     SetModified();
     703 [ +  - ][ +  - ]:        652 :     return pFmt;
     704                 :            : }
     705                 :            : 
     706                 :        129 : SwFlyFrmFmt* SwDoc::MakeFlySection( RndStdIds eAnchorType,
     707                 :            :                                     const SwPosition* pAnchorPos,
     708                 :            :                                     const SfxItemSet* pFlySet,
     709                 :            :                                     SwFrmFmt* pFrmFmt, sal_Bool bCalledFromShell )
     710                 :            : {
     711                 :        129 :     SwFlyFrmFmt* pFmt = 0;
     712                 :        129 :     sal_Bool bCallMake = sal_True;
     713 [ -  + ][ #  # ]:        129 :     if ( !pAnchorPos && (FLY_AT_PAGE != eAnchorType) )
     714                 :            :     {
     715                 :            :         const SwFmtAnchor* pAnch;
     716 [ #  # ][ #  # ]:          0 :         if( (pFlySet && SFX_ITEM_SET == pFlySet->GetItemState(
         [ #  # ][ #  # ]
                 [ #  # ]
     717         [ #  # ]:          0 :                 RES_ANCHOR, sal_False, (const SfxPoolItem**)&pAnch )) ||
     718                 :            :             ( pFrmFmt && SFX_ITEM_SET == pFrmFmt->GetItemState(
     719         [ #  # ]:          0 :                 RES_ANCHOR, sal_True, (const SfxPoolItem**)&pAnch )) )
     720                 :            :         {
     721         [ #  # ]:          0 :             if ( (FLY_AT_PAGE != pAnch->GetAnchorId()) )
     722                 :            :             {
     723         [ #  # ]:          0 :                 pAnchorPos = pAnch->GetCntntAnchor();
     724         [ #  # ]:          0 :                 if (pAnchorPos)
     725                 :            :                 {
     726                 :          0 :                     bCallMake = sal_False;
     727                 :            :                 }
     728                 :            :             }
     729                 :            :         }
     730                 :            :     }
     731                 :            : 
     732         [ +  - ]:        129 :     if( bCallMake )
     733                 :            :     {
     734         [ +  + ]:        129 :         if( !pFrmFmt )
     735         [ +  - ]:        125 :             pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_FRAME );
     736                 :            : 
     737                 :            :         sal_uInt16 nCollId = static_cast<sal_uInt16>(
     738 [ +  - ][ -  + ]:        129 :             get(IDocumentSettingAccess::HTML_MODE) ? RES_POOLCOLL_TEXT : RES_POOLCOLL_FRAME );
     739                 :            : 
     740                 :            :         /* If there is no adjust item in the paragraph style for the content node of the new fly section
     741                 :            :            propagate an existing adjust item at the anchor to the new content node. */
     742         [ +  - ]:        129 :         SwCntntNode * pNewTxtNd = GetNodes().MakeTxtNode
     743         [ +  - ]:        129 :             (SwNodeIndex( GetNodes().GetEndOfAutotext()),
     744   [ +  -  +  - ]:        387 :              GetTxtCollFromPool( nCollId ));
         [ +  - ][ +  - ]
     745                 :        129 :         SwCntntNode * pAnchorNode = pAnchorPos->nNode.GetNode().GetCntntNode();
     746                 :            : 
     747                 :        129 :         const SfxPoolItem * pItem = NULL;
     748                 :            : 
     749 [ #  # ][ #  # ]:        129 :         if (bCalledFromShell && !lcl_IsItemSet(*pNewTxtNd, RES_PARATR_ADJUST) &&
         [ #  # ][ -  + ]
                 [ -  + ]
     750         [ #  # ]:          0 :             SFX_ITEM_SET == pAnchorNode->GetSwAttrSet().
     751         [ #  # ]:          0 :             GetItemState(RES_PARATR_ADJUST, sal_True, &pItem))
     752         [ #  # ]:          0 :             static_cast<SwCntntNode *>(pNewTxtNd)->SetAttr(*pItem);
     753                 :            : 
     754                 :            :          pFmt = _MakeFlySection( *pAnchorPos, *pNewTxtNd,
     755         [ +  - ]:        129 :                                 eAnchorType, pFlySet, pFrmFmt );
     756                 :            :     }
     757                 :        129 :     return pFmt;
     758                 :            : }
     759                 :            : 
     760                 :         15 : SwFlyFrmFmt* SwDoc::MakeFlyAndMove( const SwPaM& rPam, const SfxItemSet& rSet,
     761                 :            :                                     const SwSelBoxes* pSelBoxes,
     762                 :            :                                     SwFrmFmt *pParent )
     763                 :            : {
     764                 :         15 :     SwFmtAnchor& rAnch = (SwFmtAnchor&)rSet.Get( RES_ANCHOR );
     765                 :            : 
     766                 :         15 :     GetIDocumentUndoRedo().StartUndo( UNDO_INSLAYFMT, NULL );
     767                 :            : 
     768                 :            :     SwFlyFrmFmt* pFmt = MakeFlySection( rAnch.GetAnchorId(), rPam.GetPoint(),
     769                 :         15 :                                         &rSet, pParent );
     770                 :            : 
     771                 :            :     // If content is selected, it becomes the new frame's content.
     772                 :            :     // Namely, it is moved into the NodeArray's appropriate section.
     773                 :            : 
     774         [ +  - ]:         15 :     if( pFmt )
     775                 :            :     {
     776                 :            :         do {        // middle check loop
     777         [ +  - ]:         15 :             const SwFmtCntnt &rCntnt = pFmt->GetCntnt();
     778                 :            :             OSL_ENSURE( rCntnt.GetCntntIdx(), "No content prepared." );
     779         [ +  - ]:         15 :             SwNodeIndex aIndex( *(rCntnt.GetCntntIdx()), 1 );
     780                 :         15 :             SwCntntNode *pNode = aIndex.GetNode().GetCntntNode();
     781                 :            : 
     782                 :            :             // Attention: Do not create an index on the stack, or we
     783                 :            :             // cannot delete CntntNode in the end!
     784         [ +  - ]:         15 :             SwPosition aPos( aIndex );
     785 [ +  - ][ +  - ]:         15 :             aPos.nContent.Assign( pNode, 0 );
     786                 :            : 
     787 [ -  + ][ #  # ]:         15 :             if( pSelBoxes && !pSelBoxes->empty() )
                 [ -  + ]
     788                 :            :             {
     789                 :            :                 // Table selection
     790                 :            :                 // Copy parts of a table: create a table with the same width as the
     791                 :            :                 // original one and move (copy and delete) the selected boxes.
     792                 :            :                 // The size is corrected on a percentage basis.
     793                 :            : 
     794         [ #  # ]:          0 :                 SwTableNode* pTblNd = (SwTableNode*)(*pSelBoxes)[0]->
     795         [ #  # ]:          0 :                                                 GetSttNd()->FindTableNode();
     796         [ #  # ]:          0 :                 if( !pTblNd )
     797                 :            :                     break;
     798                 :            : 
     799                 :          0 :                 SwTable& rTbl = pTblNd->GetTable();
     800                 :            : 
     801                 :            :                 // Did we select the whole table?
     802         [ #  # ]:          0 :                 if( pSelBoxes->size() == rTbl.GetTabSortBoxes().size() )
     803                 :            :                 {
     804                 :            :                     // move the whole table
     805         [ #  # ]:          0 :                     SwNodeRange aRg( *pTblNd, 0, *pTblNd->EndOfSectionNode(), 1 );
     806                 :            : 
     807                 :            :                     // If we move the whole table and it is located within a
     808                 :            :                     // FlyFrame, the we create a TextNode after it.
     809                 :            :                     // So that this FlyFrame is preserved.
     810         [ #  # ]:          0 :                     if( aRg.aEnd.GetNode().IsEndNode() )
     811         [ #  # ]:          0 :                         GetNodes().MakeTxtNode( aRg.aStart,
     812         [ #  # ]:          0 :                                     (SwTxtFmtColl*)GetDfltTxtFmtColl() );
     813                 :            : 
     814 [ #  # ][ #  # ]:          0 :                     MoveNodeRange( aRg, aPos.nNode, DOC_MOVEDEFAULT );
     815                 :            :                 }
     816                 :            :                 else
     817                 :            :                 {
     818         [ #  # ]:          0 :                     rTbl.MakeCopy( this, aPos, *pSelBoxes );
     819                 :            :                     // Don't delete a part of a table with row span!!
     820                 :            :                     // You could delete the content instead -> ToDo
     821                 :            :                     //rTbl.DeleteSel( this, *pSelBoxes, 0, 0, sal_True, sal_True );
     822                 :            :                 }
     823                 :            : 
     824                 :            :                 // If the table is within the frame, then copy without the following TextNode
     825         [ #  # ]:          0 :                 aIndex = rCntnt.GetCntntIdx()->GetNode().EndOfSectionIndex() - 1;
     826                 :            :                 OSL_ENSURE( aIndex.GetNode().GetTxtNode(),
     827                 :            :                         "a TextNode should be here" );
     828         [ #  # ]:          0 :                 aPos.nContent.Assign( 0, 0 );       // Deregister index!
     829 [ #  # ][ #  # ]:          0 :                 GetNodes().Delete( aIndex, 1 );
     830                 :            : 
     831                 :            : // This is a hack: whilst FlyFrames/Headers/Footers are not undoable we delete all Undo objects
     832 [ #  # ][ #  # ]:          0 : if( GetIDocumentUndoRedo().DoesUndo() )
                 [ #  # ]
     833                 :            : {
     834 [ #  # ][ #  # ]:          0 :     GetIDocumentUndoRedo().DelAllUndoObj();
     835                 :            : }
     836                 :            : 
     837                 :            :             }
     838                 :            :             else
     839                 :            :             {
     840                 :            :                 // copy all Pams and then delete all
     841                 :         15 :                 SwPaM* pTmp = (SwPaM*)&rPam;
     842                 :         15 :                 sal_Bool bOldFlag = mbCopyIsMove;
     843 [ +  - ][ +  - ]:         15 :                 bool const bOldUndo = GetIDocumentUndoRedo().DoesUndo();
     844         [ +  - ]:         15 :                 bool const bOldRedlineMove(IsRedlineMove());
     845                 :         15 :                 mbCopyIsMove = sal_True;
     846 [ +  - ][ +  - ]:         15 :                 GetIDocumentUndoRedo().DoUndo(false);
     847         [ +  - ]:         15 :                 SetRedlineMove(true);
     848         [ -  + ]:         15 :                 do {
     849 [ +  - ][ +  - ]:         30 :                     if( pTmp->HasMark() &&
                 [ +  - ]
     850         [ +  - ]:         15 :                         *pTmp->GetPoint() != *pTmp->GetMark() )
     851                 :            :                     {
     852         [ +  - ]:         15 :                         CopyRange( *pTmp, aPos, false );
     853                 :            :                     }
     854                 :         15 :                     pTmp = static_cast<SwPaM*>(pTmp->GetNext());
     855                 :            :                 } while ( &rPam != pTmp );
     856         [ +  - ]:         15 :                 SetRedlineMove(bOldRedlineMove);
     857                 :         15 :                 mbCopyIsMove = bOldFlag;
     858 [ +  - ][ +  - ]:         15 :                 GetIDocumentUndoRedo().DoUndo(bOldUndo);
     859                 :            : 
     860                 :         15 :                 pTmp = (SwPaM*)&rPam;
     861         [ -  + ]:         15 :                 do {
     862 [ +  - ][ +  - ]:         30 :                     if( pTmp->HasMark() &&
                 [ +  - ]
     863         [ +  - ]:         15 :                         *pTmp->GetPoint() != *pTmp->GetMark() )
     864                 :            :                     {
     865         [ +  - ]:         15 :                         DeleteAndJoin( *pTmp );
     866                 :            :                     }
     867                 :         15 :                     pTmp = static_cast<SwPaM*>(pTmp->GetNext());
     868                 :            :                 } while ( &rPam != pTmp );
     869 [ +  - ][ -  + ]:         15 :             }
         [ +  - ][ +  - ]
     870                 :            :         } while( sal_False );
     871                 :            :     }
     872                 :            : 
     873                 :         15 :     SetModified();
     874                 :            : 
     875                 :         15 :     GetIDocumentUndoRedo().EndUndo( UNDO_INSLAYFMT, NULL );
     876                 :            : 
     877                 :         15 :     return pFmt;
     878                 :            : }
     879                 :            : 
     880                 :            : // Insert a DrawObject.
     881                 :            : // The Object has to be already registered in the DrawModel.
     882                 :        685 : SwDrawFrmFmt* SwDoc::Insert( const SwPaM &rRg,
     883                 :            :                              SdrObject& rDrawObj,
     884                 :            :                              const SfxItemSet* pFlyAttrSet,
     885                 :            :                              SwFrmFmt* pDefFmt )
     886                 :            : {
     887                 :            :     SwDrawFrmFmt *pFmt = MakeDrawFrmFmt( aEmptyStr,
     888 [ +  - ][ +  - ]:        685 :                                         pDefFmt ? pDefFmt : GetDfltFrmFmt() );
     889                 :            : 
     890                 :        685 :     const SwFmtAnchor* pAnchor = 0;
     891         [ +  - ]:        685 :     if( pFlyAttrSet )
     892                 :            :     {
     893                 :            :         pFlyAttrSet->GetItemState( RES_ANCHOR, sal_False,
     894         [ +  - ]:        685 :                                     (const SfxPoolItem**)&pAnchor );
     895         [ +  - ]:        685 :         pFmt->SetFmtAttr( *pFlyAttrSet );
     896                 :            :     }
     897                 :            : 
     898                 :        685 :     RndStdIds eAnchorId = pAnchor ? pAnchor->GetAnchorId()
     899 [ +  - ][ #  # ]:        685 :                                   : pFmt->GetAnchor().GetAnchorId();
     900                 :            : 
     901                 :            :     // Didn't set the Anchor yet?
     902                 :            :     // DrawObjecte must never end up in the Header/Footer!
     903                 :        685 :     const bool bIsAtCntnt = (FLY_AT_PAGE != eAnchorId);
     904                 :            : 
     905                 :        685 :     const SwNodeIndex* pChkIdx = 0;
     906         [ -  + ]:        685 :     if( !pAnchor )
     907                 :            :     {
     908                 :          0 :         pChkIdx = &rRg.GetPoint()->nNode;
     909                 :            :     }
     910         [ +  + ]:        685 :     else if( bIsAtCntnt )
     911                 :            :     {
     912         [ +  - ]:        578 :         pChkIdx = pAnchor->GetCntntAnchor()
     913         [ +  - ]:        572 :                     ? &pAnchor->GetCntntAnchor()->nNode
     914         [ +  + ]:       1150 :                     : &rRg.GetPoint()->nNode;
     915                 :            :     }
     916                 :            : 
     917                 :            :     // Allow drawing objects in header/footer, but control objects aren't
     918                 :            :     // allowed in header/footer.
     919 [ +  + ][ +  + ]:       1719 :     if( pChkIdx &&
         [ -  + ][ -  + ]
     920         [ +  - ]:        578 :         ::CheckControlLayer( &rDrawObj ) &&
     921         [ +  - ]:        456 :         IsInHeaderFooter( *pChkIdx ) )
     922                 :            :     {
     923 [ #  # ][ #  # ]:          0 :        pFmt->SetFmtAttr( SwFmtAnchor( eAnchorId = FLY_AT_PAGE ) );
                 [ #  # ]
     924                 :            :     }
     925 [ +  - ][ +  + ]:        685 :     else if( !pAnchor || (bIsAtCntnt && !pAnchor->GetCntntAnchor() ))
         [ +  - ][ +  + ]
                 [ +  + ]
     926                 :            :     {
     927                 :            :         // then set it, we need this in the Undo
     928 [ -  + ][ #  # ]:          6 :         SwFmtAnchor aAnch( pAnchor ? *pAnchor : pFmt->GetAnchor() );
                 [ +  - ]
     929                 :          6 :         eAnchorId = aAnch.GetAnchorId();
     930         [ -  + ]:          6 :         if( FLY_AT_FLY == eAnchorId )
     931                 :            :         {
     932 [ #  # ][ #  # ]:          0 :             SwPosition aPos( *rRg.GetNode()->FindFlyStartNode() );
     933 [ #  # ][ #  # ]:          0 :             aAnch.SetAnchor( &aPos );
     934                 :            :         }
     935                 :            :         else
     936                 :            :         {
     937         [ +  - ]:          6 :             aAnch.SetAnchor( rRg.GetPoint() );
     938         [ -  + ]:          6 :             if ( FLY_AT_PAGE == eAnchorId )
     939                 :            :             {
     940 [ #  # ][ #  # ]:          0 :                 eAnchorId = rDrawObj.ISA( SdrUnoObj )
     941         [ #  # ]:          0 :                                     ? FLY_AS_CHAR : FLY_AT_PARA;
     942                 :          0 :                 aAnch.SetType( eAnchorId );
     943                 :            :             }
     944                 :            :         }
     945 [ +  - ][ +  - ]:          6 :         pFmt->SetFmtAttr( aAnch );
     946                 :            :     }
     947                 :            : 
     948                 :            :     // For Draws anchored as character we set the attribute in the paragraph
     949         [ +  + ]:        685 :     if ( FLY_AS_CHAR == eAnchorId )
     950                 :            :     {
     951                 :        473 :         xub_StrLen nStt = rRg.GetPoint()->nContent.GetIndex();
     952         [ +  - ]:        473 :         SwFmtFlyCnt aFmt( pFmt );
     953                 :        473 :         rRg.GetPoint()->nNode.GetNode().GetTxtNode()->InsertItem(
     954 [ +  - ][ +  - ]:        473 :                 aFmt, nStt, nStt );
     955                 :            :     }
     956                 :            : 
     957 [ +  - ][ +  - ]:        685 :     SwDrawContact* pContact = new SwDrawContact( pFmt, &rDrawObj );
     958                 :            : 
     959                 :            :     // Create Frames if necessary
     960 [ +  - ][ +  + ]:        685 :     if( GetCurrentViewShell() )
     961                 :            :     {
     962         [ +  - ]:        458 :         pFmt->MakeFrms();
     963                 :            :         // #i42319# - follow-up of #i35635#
     964                 :            :         // move object to visible layer
     965                 :            :         // #i79391#
     966 [ +  - ][ +  - ]:        458 :         if ( pContact->GetAnchorFrm() )
     967                 :            :         {
     968         [ +  - ]:        458 :             pContact->MoveObjToVisibleLayer( &rDrawObj );
     969                 :            :         }
     970                 :            :     }
     971                 :            : 
     972 [ +  - ][ +  - ]:        685 :     if (GetIDocumentUndoRedo().DoesUndo())
                 [ +  + ]
     973                 :            :     {
     974 [ +  - ][ +  - ]:        458 :         GetIDocumentUndoRedo().AppendUndo( new SwUndoInsLayFmt(pFmt, 0, 0) );
         [ +  - ][ +  - ]
     975                 :            :     }
     976                 :            : 
     977         [ +  - ]:        685 :     SetModified();
     978                 :        685 :     return pFmt;
     979                 :            : }
     980                 :            : 
     981                 :            : /* ---------------------------------------------------------------------------
     982                 :            :     paragraph frames - o.k. if the PaM includes the paragraph from the beginning
     983                 :            :                        to the beginning of the next paragraph at least
     984                 :            :     frames at character - o.k. if the PaM starts at least at the same position
     985                 :            :                          as the frame
     986                 :            :  ---------------------------------------------------------------------------*/
     987                 :          0 : sal_Bool TstFlyRange( const SwPaM* pPam, const SwPosition* pFlyPos,
     988                 :            :                         RndStdIds nAnchorId )
     989                 :            : {
     990                 :          0 :     sal_Bool bOk = sal_False;
     991                 :          0 :     const SwPaM* pTmp = pPam;
     992 [ #  # ][ #  # ]:          0 :     do {
                 [ #  # ]
     993                 :          0 :         const sal_uInt32 nFlyIndex = pFlyPos->nNode.GetIndex();
     994                 :          0 :         const SwPosition* pPaMStart = pTmp->Start();
     995                 :          0 :         const SwPosition* pPaMEnd = pTmp->End();
     996                 :          0 :         const sal_uInt32 nPamStartIndex = pPaMStart->nNode.GetIndex();
     997                 :          0 :         const sal_uInt32 nPamEndIndex = pPaMEnd->nNode.GetIndex();
     998         [ #  # ]:          0 :         if (FLY_AT_PARA == nAnchorId)
     999                 :            :             bOk = (nPamStartIndex < nFlyIndex && nPamEndIndex > nFlyIndex) ||
    1000                 :          0 :                (((nPamStartIndex == nFlyIndex) && (pPaMStart->nContent.GetIndex() == 0)) &&
    1001 [ #  # ][ #  # ]:          0 :                (nPamEndIndex > nFlyIndex));
           [ #  #  #  # ]
                 [ #  # ]
    1002                 :            :         else
    1003                 :            :         {
    1004                 :          0 :             xub_StrLen nFlyContentIndex = pFlyPos->nContent.GetIndex();
    1005                 :          0 :             xub_StrLen nPamEndContentIndex = pPaMEnd->nContent.GetIndex();
    1006                 :            :             bOk = (nPamStartIndex < nFlyIndex &&
    1007                 :            :                 (( nPamEndIndex > nFlyIndex )||
    1008                 :            :                  ((nPamEndIndex == nFlyIndex) &&
    1009                 :            :                   (nPamEndContentIndex > nFlyContentIndex))) )
    1010                 :            :                 ||
    1011                 :            :                        (((nPamStartIndex == nFlyIndex) &&
    1012                 :          0 :                       (pPaMStart->nContent.GetIndex() <= nFlyContentIndex)) &&
    1013                 :            :                      ((nPamEndIndex > nFlyIndex) ||
    1014 [ #  # ][ #  # ]:          0 :                      (nPamEndContentIndex > nFlyContentIndex )));
                 [ #  # ]
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1015                 :            :         }
    1016                 :            : 
    1017                 :          0 :     } while( !bOk && pPam != ( pTmp = (const SwPaM*)pTmp->GetNext() ));
    1018                 :          0 :     return bOk;
    1019                 :            : }
    1020                 :            : 
    1021                 :        150 : void SwDoc::GetAllFlyFmts( SwPosFlyFrms& rPosFlyFmts,
    1022                 :            :                            const SwPaM* pCmpRange, sal_Bool bDrawAlso,
    1023                 :            :                            sal_Bool bAsCharAlso ) const
    1024                 :            : {
    1025                 :        150 :     SwPosFlyFrm *pFPos = 0;
    1026                 :            :     SwFrmFmt *pFly;
    1027                 :            : 
    1028                 :            :     // collect all anchored somehow to paragraphs
    1029         [ +  + ]:        372 :     for( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n )
    1030                 :            :     {
    1031         [ +  - ]:        222 :         pFly = (*GetSpzFrmFmts())[ n ];
    1032 [ +  - ][ +  + ]:        222 :         bool bDrawFmt = bDrawAlso ? RES_DRAWFRMFMT == pFly->Which() : false;
    1033                 :        222 :         bool bFlyFmt = RES_FLYFRMFMT == pFly->Which();
    1034 [ +  - ][ +  + ]:        222 :         if( bFlyFmt || bDrawFmt )
    1035                 :            :         {
    1036         [ +  - ]:        222 :             const SwFmtAnchor& rAnchor = pFly->GetAnchor();
    1037         [ +  - ]:        222 :             SwPosition const*const pAPos = rAnchor.GetCntntAnchor();
    1038   [ +  -  +  +  :       1089 :             if (pAPos &&
          +  -  +  +  +  
              - ][ -  + ]
                 [ +  + ]
    1039                 :        222 :                 ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
    1040                 :        216 :                  (FLY_AT_FLY  == rAnchor.GetAnchorId()) ||
    1041                 :        216 :                  (FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
    1042                 :        213 :                  ((FLY_AS_CHAR == rAnchor.GetAnchorId()) && bAsCharAlso)))
    1043                 :            :             {
    1044 [ -  + ][ #  # ]:          9 :                 if( pCmpRange &&
                 [ -  + ]
    1045         [ #  # ]:          0 :                     !TstFlyRange( pCmpRange, pAPos, rAnchor.GetAnchorId() ))
    1046                 :          0 :                         continue;       // not a valid FlyFrame
    1047 [ +  - ][ +  - ]:          9 :                 pFPos = new SwPosFlyFrm( pAPos->nNode, pFly, rPosFlyFmts.size() );
    1048         [ +  - ]:          9 :                 rPosFlyFmts.insert( pFPos );
    1049                 :            :             }
    1050                 :            :         }
    1051                 :            :     }
    1052                 :            : 
    1053                 :            :     // If we don't have a layout we can't get page anchored FlyFrames.
    1054                 :            :     // Also, page anchored FlyFrames are only returned if no range is specified.
    1055 [ +  - ][ +  - ]:        150 :     if( !GetCurrentViewShell() || pCmpRange )   //swmod 071108//swmod 071225
         [ +  + ][ +  + ]
    1056                 :        150 :         return;
    1057                 :            : 
    1058                 :        146 :     pFPos = 0;
    1059 [ +  - ][ +  - ]:        146 :     SwPageFrm *pPage = (SwPageFrm*)GetCurrentLayout()->GetLower();  //swmod 080218
    1060         [ +  + ]:        302 :     while( pPage )
    1061                 :            :     {
    1062         [ +  + ]:        152 :         if( pPage->GetSortedObjs() )
    1063                 :            :         {
    1064                 :          9 :             SwSortedObjs &rObjs = *pPage->GetSortedObjs();
    1065 [ +  - ][ +  + ]:         18 :             for( sal_uInt16 i = 0; i < rObjs.Count(); ++i)
    1066                 :            :             {
    1067         [ +  - ]:          9 :                 SwAnchoredObject* pAnchoredObj = rObjs[i];
    1068 [ +  - ][ +  - ]:          9 :                 if ( pAnchoredObj->ISA(SwFlyFrm) )
                 [ +  + ]
    1069         [ +  - ]:          3 :                     pFly = &(pAnchoredObj->GetFrmFmt());
    1070         [ +  - ]:          6 :                 else if ( bDrawAlso )
    1071         [ +  - ]:          6 :                     pFly = &(pAnchoredObj->GetFrmFmt());
    1072                 :            :                 else
    1073                 :          0 :                     continue;
    1074                 :            : 
    1075         [ +  - ]:          9 :                 const SwFmtAnchor& rAnchor = pFly->GetAnchor();
    1076   [ +  +  +  -  :         15 :                 if ((FLY_AT_PARA != rAnchor.GetAnchorId()) &&
           -  + ][ -  + ]
    1077                 :          3 :                     (FLY_AT_FLY  != rAnchor.GetAnchorId()) &&
    1078                 :          3 :                     (FLY_AT_CHAR != rAnchor.GetAnchorId()))
    1079                 :            :                 {
    1080         [ #  # ]:          0 :                     const SwCntntFrm * pCntntFrm = pPage->FindFirstBodyCntnt();
    1081         [ #  # ]:          0 :                     if ( !pCntntFrm )
    1082                 :            :                     {
    1083                 :            :                         // Oops! An empty page.
    1084                 :            :                         // In order not to loose the whole frame (RTF) we
    1085                 :            :                         // look for the last Cntnt before the page.
    1086                 :          0 :                         SwPageFrm *pPrv = (SwPageFrm*)pPage->GetPrev();
    1087 [ #  # ][ #  # ]:          0 :                         while ( !pCntntFrm && pPrv )
                 [ #  # ]
    1088                 :            :                         {
    1089         [ #  # ]:          0 :                             pCntntFrm = pPrv->FindFirstBodyCntnt();
    1090                 :          0 :                             pPrv = (SwPageFrm*)pPrv->GetPrev();
    1091                 :            :                         }
    1092                 :            :                     }
    1093         [ #  # ]:          0 :                     if ( pCntntFrm )
    1094                 :            :                     {
    1095         [ #  # ]:          0 :                         SwNodeIndex aIdx( *pCntntFrm->GetNode() );
    1096 [ #  # ][ #  # ]:          0 :                         pFPos = new SwPosFlyFrm( aIdx, pFly, rPosFlyFmts.size() );
                 [ #  # ]
    1097                 :            :                     }
    1098                 :            :                 }
    1099         [ -  + ]:          9 :                 if ( pFPos )
    1100                 :            :                 {
    1101         [ #  # ]:          0 :                     rPosFlyFmts.insert( pFPos );
    1102                 :          0 :                     pFPos = 0;
    1103                 :            :                 }
    1104                 :            :             }
    1105                 :            :         }
    1106                 :        152 :         pPage = (SwPageFrm*)pPage->GetNext();
    1107                 :            :     }
    1108                 :            : }
    1109                 :            : 
    1110                 :            : /*************************************************************************
    1111                 :            : |*
    1112                 :            : |*  SwDoc::InsertLabel()
    1113                 :            : |*
    1114                 :            : |*************************************************************************/
    1115                 :            : 
    1116                 :            : /* #i6447# changed behaviour if lcl_CpyAttr:
    1117                 :            : 
    1118                 :            :    If the old item set contains the item to set (no inheritance) copy the item
    1119                 :            :    into the new set.
    1120                 :            : 
    1121                 :            :    If the old item set contains the item by inheritance and the new set
    1122                 :            :    contains the item, too:
    1123                 :            :    If the two items differ copy the item from the old set to the new set.
    1124                 :            : 
    1125                 :            :    Otherwise the new set will not be changed.
    1126                 :            : */
    1127                 :          0 : void lcl_CpyAttr( SfxItemSet &rNewSet, const SfxItemSet &rOldSet, sal_uInt16 nWhich )
    1128                 :            : {
    1129                 :          0 :     const SfxPoolItem *pOldItem = NULL, *pNewItem = NULL;
    1130                 :            : 
    1131         [ #  # ]:          0 :     rOldSet.GetItemState( nWhich, sal_False, &pOldItem);
    1132         [ #  # ]:          0 :     if (pOldItem != NULL)
    1133         [ #  # ]:          0 :         rNewSet.Put( *pOldItem );
    1134                 :            :     else
    1135                 :            :     {
    1136         [ #  # ]:          0 :         pOldItem = rOldSet.GetItem( nWhich, sal_True);
    1137         [ #  # ]:          0 :         if (pOldItem != NULL)
    1138                 :            :         {
    1139         [ #  # ]:          0 :             pNewItem = rNewSet.GetItem( nWhich, sal_True);
    1140         [ #  # ]:          0 :             if (pNewItem != NULL)
    1141                 :            :             {
    1142 [ #  # ][ #  # ]:          0 :                 if (*pOldItem != *pNewItem)
    1143         [ #  # ]:          0 :                     rNewSet.Put( *pOldItem );
    1144                 :            :             }
    1145                 :            :             else {
    1146                 :            :                 OSL_FAIL("What am I doing here?");
    1147                 :            :             }
    1148                 :            :         }
    1149                 :            :         else {
    1150                 :            :             OSL_FAIL("What am I doing here?");
    1151                 :            :         }
    1152                 :            :     }
    1153                 :            : 
    1154                 :          0 : }
    1155                 :            : 
    1156                 :            : static SwFlyFrmFmt *
    1157                 :          0 : lcl_InsertLabel(SwDoc & rDoc, SwTxtFmtColls *const pTxtFmtCollTbl,
    1158                 :            :         SwUndoInsertLabel *const pUndo,
    1159                 :            :         SwLabelType const eType, String const& rTxt, String const& rSeparator,
    1160                 :            :             const String& rNumberingSeparator,
    1161                 :            :             const sal_Bool bBefore, const sal_uInt16 nId, const sal_uLong nNdIdx,
    1162                 :            :             const String& rCharacterStyle,
    1163                 :            :             const sal_Bool bCpyBrd )
    1164                 :            : {
    1165 [ #  # ][ #  # ]:          0 :     ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
    1166                 :            : 
    1167                 :          0 :     sal_Bool bTable = sal_False;    // To save some code.
    1168                 :            : 
    1169                 :            :     // Get the field first, beause we retrieve the TxtColl via the field's name
    1170                 :            :     OSL_ENSURE( nId == USHRT_MAX  || nId < rDoc.GetFldTypes()->size(),
    1171                 :            :             "FldType index out of bounds." );
    1172 [ #  # ][ #  # ]:          0 :     SwFieldType *pType = (nId != USHRT_MAX) ? (*rDoc.GetFldTypes())[nId] : NULL;
                 [ #  # ]
    1173                 :            :     OSL_ENSURE(!pType || pType->Which() == RES_SETEXPFLD, "wrong Id for Label");
    1174                 :            : 
    1175                 :          0 :     SwTxtFmtColl * pColl = NULL;
    1176         [ #  # ]:          0 :     if( pType )
    1177                 :            :     {
    1178         [ #  # ]:          0 :         for( sal_uInt16 i = pTxtFmtCollTbl->size(); i; )
    1179                 :            :         {
    1180 [ #  # ][ #  # ]:          0 :             if( (*pTxtFmtCollTbl)[ --i ]->GetName().Equals(pType->GetName()) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1181                 :            :             {
    1182         [ #  # ]:          0 :                 pColl = (*pTxtFmtCollTbl)[i];
    1183                 :          0 :                 break;
    1184                 :            :             }
    1185                 :            :         }
    1186                 :            :         OSL_ENSURE( pColl, "no text collection found" );
    1187                 :            :     }
    1188                 :            : 
    1189         [ #  # ]:          0 :     if( !pColl )
    1190                 :            :     {
    1191         [ #  # ]:          0 :         pColl = rDoc.GetTxtCollFromPool( RES_POOLCOLL_LABEL );
    1192                 :            :     }
    1193                 :            : 
    1194                 :          0 :     SwTxtNode *pNew = NULL;
    1195                 :          0 :     SwFlyFrmFmt* pNewFmt = NULL;
    1196                 :            : 
    1197   [ #  #  #  # ]:          0 :     switch ( eType )
    1198                 :            :     {
    1199                 :            :         case LTYPE_TABLE:
    1200                 :          0 :             bTable = sal_True;
    1201                 :            :             // no break here
    1202                 :            :         case LTYPE_FLY:
    1203                 :            :             // At the FlySection's Beginning/End insert the corresponding Node with it's Field.
    1204                 :            :             // The Frame is created automatically.
    1205                 :            :             {
    1206 [ #  # ][ #  # ]:          0 :                 SwStartNode *pSttNd = rDoc.GetNodes()[nNdIdx]->GetStartNode();
    1207                 :            :                 OSL_ENSURE( pSttNd, "No StartNode in InsertLabel." );
    1208                 :            :                 sal_uLong nNode;
    1209         [ #  # ]:          0 :                 if( bBefore )
    1210                 :            :                 {
    1211                 :          0 :                     nNode = pSttNd->GetIndex();
    1212         [ #  # ]:          0 :                     if( !bTable )
    1213                 :          0 :                         ++nNode;
    1214                 :            :                 }
    1215                 :            :                 else
    1216                 :            :                 {
    1217                 :          0 :                     nNode = pSttNd->EndOfSectionIndex();
    1218         [ #  # ]:          0 :                     if( bTable )
    1219                 :          0 :                         ++nNode;
    1220                 :            :                 }
    1221                 :            : 
    1222         [ #  # ]:          0 :                 if( pUndo )
    1223                 :          0 :                     pUndo->SetNodePos( nNode );
    1224                 :            : 
    1225                 :            :                 // Create Node for labeling paragraph.
    1226 [ #  # ][ #  # ]:          0 :                 SwNodeIndex aIdx( rDoc.GetNodes(), nNode );
    1227 [ #  # ][ #  # ]:          0 :                 pNew = rDoc.GetNodes().MakeTxtNode( aIdx, pColl );
                 [ #  # ]
    1228                 :            :             }
    1229                 :          0 :             break;
    1230                 :            : 
    1231                 :            :         case LTYPE_OBJECT:
    1232                 :            :             {
    1233                 :            :                 // Destroy Frame,
    1234                 :            :                 // insert new Frame,
    1235                 :            :                 // insert the corresponding Node with Field into the new Frame,
    1236                 :            :                 // insert the old Frame with the Object (Picture/OLE) paragraph-bound into the new Frame,
    1237                 :            :                 // create Frames.
    1238                 :            : 
    1239                 :            :                 // Get the FlyFrame's Format and decouple the Layout.
    1240 [ #  # ][ #  # ]:          0 :                 SwFrmFmt *pOldFmt = rDoc.GetNodes()[nNdIdx]->GetFlyFmt();
                 [ #  # ]
    1241                 :            :                 OSL_ENSURE( pOldFmt, "Couldn't find the Fly's Format." );
    1242                 :            :                 // #i115719#
    1243                 :            :                 // <title> and <description> attributes are lost when calling <DelFrms()>.
    1244                 :            :                 // Thus, keep them and restore them after the calling <MakeFrms()>
    1245 [ #  # ][ #  # ]:          0 :                 const bool bIsSwFlyFrmFmtInstance( dynamic_cast<SwFlyFrmFmt*>(pOldFmt) != 0 );
    1246                 :            :                 const String sTitle( bIsSwFlyFrmFmtInstance
    1247                 :            :                                      ? static_cast<SwFlyFrmFmt*>(pOldFmt)->GetObjTitle()
    1248 [ #  # ][ #  # ]:          0 :                                      : String() );
                 [ #  # ]
    1249                 :            :                 const String sDescription( bIsSwFlyFrmFmtInstance
    1250                 :            :                                            ? static_cast<SwFlyFrmFmt*>(pOldFmt)->GetObjDescription()
    1251 [ #  # ][ #  # ]:          0 :                                            : String() );
                 [ #  # ]
    1252         [ #  # ]:          0 :                 pOldFmt->DelFrms();
    1253                 :            : 
    1254                 :            :                 pNewFmt = rDoc.MakeFlyFrmFmt( rDoc.GetUniqueFrameName(),
    1255 [ #  # ][ #  # ]:          0 :                                 rDoc.GetFrmFmtFromPool(RES_POOLFRM_FRAME) );
         [ #  # ][ #  # ]
    1256                 :            : 
    1257                 :            :                 /* #i6447#: Only the selected items are copied from the old
    1258                 :            :                    format. */
    1259         [ #  # ]:          0 :                 SfxItemSet* pNewSet = pNewFmt->GetAttrSet().Clone( sal_True );
    1260                 :            : 
    1261                 :            : 
    1262                 :            :                 // Copy only the set attributes.
    1263                 :            :                 // The others should apply from the Templates.
    1264         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_PRINT );
    1265         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_OPAQUE );
    1266         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_PROTECT );
    1267         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_SURROUND );
    1268         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_VERT_ORIENT );
    1269         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_HORI_ORIENT );
    1270         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_LR_SPACE );
    1271         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_UL_SPACE );
    1272         [ #  # ]:          0 :                 lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_BACKGROUND );
    1273         [ #  # ]:          0 :                 if( bCpyBrd )
    1274                 :            :                 {
    1275                 :            :                     // If there's no BoxItem at graphic, but the new Format has one, then set the
    1276                 :            :                     // default item in the new Set. Because the graphic's size has never changed!
    1277                 :            :                     const SfxPoolItem *pItem;
    1278         [ #  # ]:          0 :                     if( SFX_ITEM_SET == pOldFmt->GetAttrSet().
    1279         [ #  # ]:          0 :                             GetItemState( RES_BOX, sal_True, &pItem ))
    1280         [ #  # ]:          0 :                         pNewSet->Put( *pItem );
    1281         [ #  # ]:          0 :                     else if( SFX_ITEM_SET == pNewFmt->GetAttrSet().
    1282         [ #  # ]:          0 :                             GetItemState( RES_BOX, sal_True ))
    1283 [ #  # ][ #  # ]:          0 :                         pNewSet->Put( *GetDfltAttr( RES_BOX ) );
    1284                 :            : 
    1285         [ #  # ]:          0 :                     if( SFX_ITEM_SET == pOldFmt->GetAttrSet().
    1286         [ #  # ]:          0 :                             GetItemState( RES_SHADOW, sal_True, &pItem ))
    1287         [ #  # ]:          0 :                         pNewSet->Put( *pItem );
    1288         [ #  # ]:          0 :                     else if( SFX_ITEM_SET == pNewFmt->GetAttrSet().
    1289         [ #  # ]:          0 :                             GetItemState( RES_SHADOW, sal_True ))
    1290 [ #  # ][ #  # ]:          0 :                         pNewSet->Put( *GetDfltAttr( RES_SHADOW ) );
    1291                 :            :                 }
    1292                 :            :                 else
    1293                 :            :                 {
    1294                 :            :                     // Hard-set the attributes, because they could come from the Template
    1295                 :            :                     // and then size calculations could not be correct anymore.
    1296 [ #  # ][ #  # ]:          0 :                     pNewSet->Put( SvxBoxItem(RES_BOX) );
                 [ #  # ]
    1297 [ #  # ][ #  # ]:          0 :                     pNewSet->Put( SvxShadowItem(RES_SHADOW) );
                 [ #  # ]
    1298                 :            : 
    1299                 :            :                 }
    1300                 :            : 
    1301                 :            :                 // Always transfer the anchor, which is a hard attribute anyways.
    1302 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( pOldFmt->GetAnchor() );
    1303                 :            : 
    1304                 :            :                 // The new one should be changeable in it's height.
    1305 [ #  # ][ #  # ]:          0 :                 SwFmtFrmSize aFrmSize( pOldFmt->GetFrmSize() );
    1306                 :          0 :                 aFrmSize.SetHeightSizeType( ATT_MIN_SIZE );
    1307         [ #  # ]:          0 :                 pNewSet->Put( aFrmSize );
    1308                 :            : 
    1309         [ #  # ]:          0 :                 SwStartNode* pSttNd = rDoc.GetNodes().MakeTextSection(
    1310         [ #  # ]:          0 :                             SwNodeIndex( rDoc.GetNodes().GetEndOfAutotext() ),
    1311 [ #  # ][ #  # ]:          0 :                             SwFlyStartNode, pColl );
                 [ #  # ]
    1312 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SwFmtCntnt( pSttNd ));
                 [ #  # ]
    1313                 :            : 
    1314         [ #  # ]:          0 :                 pNewFmt->SetFmtAttr( *pNewSet );
    1315                 :            : 
    1316                 :            :                 // InCntnts need to be treated in a special way:
    1317                 :            :                 // The TxtAttribute needs to be destroyed.
    1318                 :            :                 // Unfortunately, this also destroys the Format next to the Frames.
    1319                 :            :                 // To avoid this, we disconnect the attribute from the Format.
    1320                 :            : 
    1321         [ #  # ]:          0 :                 const SwFmtAnchor& rAnchor = pNewFmt->GetAnchor();
    1322         [ #  # ]:          0 :                 if ( FLY_AS_CHAR == rAnchor.GetAnchorId() )
    1323                 :            :                 {
    1324         [ #  # ]:          0 :                     const SwPosition *pPos = rAnchor.GetCntntAnchor();
    1325                 :          0 :                     SwTxtNode *pTxtNode = pPos->nNode.GetNode().GetTxtNode();
    1326                 :            :                     OSL_ENSURE( pTxtNode->HasHints(), "Missing FlyInCnt-Hint." );
    1327                 :          0 :                     const xub_StrLen nIdx = pPos->nContent.GetIndex();
    1328                 :            :                     SwTxtAttr * const pHnt =
    1329         [ #  # ]:          0 :                         pTxtNode->GetTxtAttrForCharAt(nIdx, RES_TXTATR_FLYCNT);
    1330                 :            : 
    1331                 :            :                     OSL_ENSURE( pHnt && pHnt->Which() == RES_TXTATR_FLYCNT,
    1332                 :            :                                 "Missing FlyInCnt-Hint." );
    1333                 :            :                     OSL_ENSURE( pHnt && pHnt->GetFlyCnt().GetFrmFmt() == pOldFmt,
    1334                 :            :                                 "Wrong TxtFlyCnt-Hint." );
    1335                 :            : 
    1336                 :          0 :                     const_cast<SwFmtFlyCnt&>(pHnt->GetFlyCnt()).SetFlyFmt(
    1337                 :          0 :                             pNewFmt );
    1338                 :            :                 }
    1339                 :            : 
    1340                 :            : 
    1341                 :            :                 // The old one should not have a flow and it should be adjusted to above and
    1342                 :            :                 // middle.
    1343                 :            :                 // Also, the width should be 100% and it should also adjust the hight, if changed.
    1344         [ #  # ]:          0 :                 pNewSet->ClearItem();
    1345                 :            : 
    1346 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SwFmtSurround( SURROUND_NONE ) );
                 [ #  # ]
    1347 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SvxOpaqueItem( RES_OPAQUE, sal_True ) );
                 [ #  # ]
    1348 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SwFmtVertOrient( text::VertOrientation::TOP ) );
                 [ #  # ]
    1349 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SwFmtHoriOrient( text::HoriOrientation::CENTER ) );
                 [ #  # ]
    1350                 :            : 
    1351 [ #  # ][ #  # ]:          0 :                 aFrmSize = pOldFmt->GetFrmSize();
    1352                 :          0 :                 aFrmSize.SetWidthPercent( 100 );
    1353                 :          0 :                 aFrmSize.SetHeightPercent( 255 );
    1354         [ #  # ]:          0 :                 pNewSet->Put( aFrmSize );
    1355                 :            : 
    1356                 :            :                 // Hard-set the attributes, because they could come from the Template
    1357                 :            :                 // and then size calculations could not be correct anymore.
    1358         [ #  # ]:          0 :                 if( bCpyBrd )
    1359                 :            :                 {
    1360 [ #  # ][ #  # ]:          0 :                     pNewSet->Put( SvxBoxItem(RES_BOX) );
                 [ #  # ]
    1361 [ #  # ][ #  # ]:          0 :                     pNewSet->Put( SvxShadowItem(RES_SHADOW) );
                 [ #  # ]
    1362                 :            :                 }
    1363 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SvxLRSpaceItem(RES_LR_SPACE) );
                 [ #  # ]
    1364 [ #  # ][ #  # ]:          0 :                 pNewSet->Put( SvxULSpaceItem(RES_UL_SPACE) );
                 [ #  # ]
    1365                 :            : 
    1366                 :            :                 // The old one is paragraph-bound to the paragraph in the new one.
    1367         [ #  # ]:          0 :                 SwFmtAnchor aAnch( FLY_AT_PARA );
    1368 [ #  # ][ #  # ]:          0 :                 SwNodeIndex aAnchIdx( *pNewFmt->GetCntnt().GetCntntIdx(), 1 );
    1369                 :          0 :                 pNew = aAnchIdx.GetNode().GetTxtNode();
    1370         [ #  # ]:          0 :                 SwPosition aPos( aAnchIdx );
    1371         [ #  # ]:          0 :                 aAnch.SetAnchor( &aPos );
    1372         [ #  # ]:          0 :                 pNewSet->Put( aAnch );
    1373                 :            : 
    1374         [ #  # ]:          0 :                 if( pUndo )
    1375         [ #  # ]:          0 :                     pUndo->SetFlys( *pOldFmt, *pNewSet, *pNewFmt );
    1376                 :            :                 else
    1377         [ #  # ]:          0 :                     pOldFmt->SetFmtAttr( *pNewSet );
    1378                 :            : 
    1379 [ #  # ][ #  # ]:          0 :                 delete pNewSet;
    1380                 :            : 
    1381                 :            :                 // Have only the FlyFrames created.
    1382                 :            :                 // We leave this to established methods (especially for InCntFlys).
    1383         [ #  # ]:          0 :                 pNewFmt->MakeFrms();
    1384                 :            :                 // #i115719#
    1385         [ #  # ]:          0 :                 if ( bIsSwFlyFrmFmtInstance )
    1386                 :            :                 {
    1387         [ #  # ]:          0 :                     static_cast<SwFlyFrmFmt*>(pOldFmt)->SetObjTitle( sTitle );
    1388         [ #  # ]:          0 :                     static_cast<SwFlyFrmFmt*>(pOldFmt)->SetObjDescription( sDescription );
    1389 [ #  # ][ #  # ]:          0 :                 }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1390                 :            :             }
    1391                 :          0 :             break;
    1392                 :            : 
    1393                 :            :         default:
    1394                 :            :             OSL_ENSURE(false, "unknown LabelType?");
    1395                 :            :     }
    1396                 :            :     OSL_ENSURE( pNew, "No Label inserted" );
    1397         [ #  # ]:          0 :     if( pNew )
    1398                 :            :     {
    1399                 :            :         // #i61007# order of captions
    1400         [ #  # ]:          0 :         sal_Bool bOrderNumberingFirst = SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst();
    1401                 :            :         // Work up string
    1402         [ #  # ]:          0 :         String aTxt;
    1403         [ #  # ]:          0 :         if( bOrderNumberingFirst )
    1404                 :            :         {
    1405         [ #  # ]:          0 :             aTxt = rNumberingSeparator;
    1406                 :            :         }
    1407         [ #  # ]:          0 :         if( pType)
    1408                 :            :         {
    1409 [ #  # ][ #  # ]:          0 :             aTxt += pType->GetName();
    1410         [ #  # ]:          0 :             if( !bOrderNumberingFirst )
    1411         [ #  # ]:          0 :                 aTxt += ' ';
    1412                 :            :         }
    1413                 :          0 :         xub_StrLen nIdx = aTxt.Len();
    1414         [ #  # ]:          0 :         if( rTxt.Len() > 0 )
    1415                 :            :         {
    1416         [ #  # ]:          0 :             aTxt += rSeparator;
    1417                 :            :         }
    1418                 :          0 :         xub_StrLen nSepIdx = aTxt.Len();
    1419         [ #  # ]:          0 :         aTxt += rTxt;
    1420                 :            : 
    1421                 :            :         // Insert string
    1422 [ #  # ][ #  # ]:          0 :         SwIndex aIdx( pNew, 0 );
    1423         [ #  # ]:          0 :         pNew->InsertText( aTxt, aIdx );
    1424                 :            : 
    1425                 :            :         // Insert field
    1426         [ #  # ]:          0 :         if(pType)
    1427                 :            :         {
    1428         [ #  # ]:          0 :             SwSetExpField aFld( (SwSetExpFieldType*)pType, aEmptyStr, SVX_NUM_ARABIC);
    1429         [ #  # ]:          0 :             if( bOrderNumberingFirst )
    1430                 :          0 :                 nIdx = 0;
    1431         [ #  # ]:          0 :             SwFmtFld aFmt( aFld );
    1432         [ #  # ]:          0 :             pNew->InsertItem( aFmt, nIdx, nIdx );
    1433         [ #  # ]:          0 :             if(rCharacterStyle.Len())
    1434                 :            :             {
    1435         [ #  # ]:          0 :                 SwCharFmt* pCharFmt = rDoc.FindCharFmtByName(rCharacterStyle);
    1436         [ #  # ]:          0 :                 if( !pCharFmt )
    1437                 :            :                 {
    1438         [ #  # ]:          0 :                     const sal_uInt16 nMyId = SwStyleNameMapper::GetPoolIdFromUIName(rCharacterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
    1439         [ #  # ]:          0 :                     pCharFmt = rDoc.GetCharFmtFromPool( nMyId );
    1440                 :            :                 }
    1441         [ #  # ]:          0 :                 if (pCharFmt)
    1442                 :            :                 {
    1443         [ #  # ]:          0 :                     SwFmtCharFmt aCharFmt( pCharFmt );
    1444                 :            :                     pNew->InsertItem( aCharFmt, 0,
    1445 [ #  # ][ #  # ]:          0 :                         nSepIdx + 1, nsSetAttrMode::SETATTR_DONTEXPAND );
    1446                 :            :                 }
    1447 [ #  # ][ #  # ]:          0 :             }
    1448                 :            :         }
    1449                 :            : 
    1450         [ #  # ]:          0 :         if ( bTable )
    1451                 :            :         {
    1452         [ #  # ]:          0 :             if ( bBefore )
    1453                 :            :             {
    1454 [ #  # ][ #  # ]:          0 :                 if ( !pNew->GetSwAttrSet().GetKeep().GetValue()  )
                 [ #  # ]
    1455 [ #  # ][ #  # ]:          0 :                     pNew->SetAttr( SvxFmtKeepItem( sal_True, RES_KEEP ) );
                 [ #  # ]
    1456                 :            :             }
    1457                 :            :             else
    1458                 :            :             {
    1459                 :            :                 SwTableNode *const pNd =
    1460 [ #  # ][ #  # ]:          0 :                     rDoc.GetNodes()[nNdIdx]->GetStartNode()->GetTableNode();
    1461                 :          0 :                 SwTable &rTbl = pNd->GetTable();
    1462 [ #  # ][ #  # ]:          0 :                 if ( !rTbl.GetFrmFmt()->GetKeep().GetValue() )
    1463 [ #  # ][ #  # ]:          0 :                     rTbl.GetFrmFmt()->SetFmtAttr( SvxFmtKeepItem( sal_True, RES_KEEP ) );
                 [ #  # ]
    1464         [ #  # ]:          0 :                 if ( pUndo )
    1465                 :          0 :                     pUndo->SetUndoKeep();
    1466                 :            :             }
    1467                 :            :         }
    1468 [ #  # ][ #  # ]:          0 :         rDoc.SetModified();
                 [ #  # ]
    1469                 :            :     }
    1470                 :            : 
    1471         [ #  # ]:          0 :     return pNewFmt;
    1472                 :            : }
    1473                 :            : 
    1474                 :            : SwFlyFrmFmt *
    1475                 :          0 : SwDoc::InsertLabel(
    1476                 :            :         SwLabelType const eType, String const& rTxt, String const& rSeparator,
    1477                 :            :         String const& rNumberingSeparator,
    1478                 :            :         sal_Bool const bBefore, sal_uInt16 const nId, sal_uLong const nNdIdx,
    1479                 :            :         String const& rCharacterStyle,
    1480                 :            :         sal_Bool const bCpyBrd )
    1481                 :            : {
    1482                 :          0 :     SwUndoInsertLabel * pUndo(0);
    1483         [ #  # ]:          0 :     if (GetIDocumentUndoRedo().DoesUndo())
    1484                 :            :     {
    1485                 :            :         pUndo = new SwUndoInsertLabel(
    1486                 :            :                         eType, rTxt, rSeparator, rNumberingSeparator,
    1487         [ #  # ]:          0 :                         bBefore, nId, rCharacterStyle, bCpyBrd );
    1488                 :            :     }
    1489                 :            : 
    1490                 :            :     SwFlyFrmFmt *const pNewFmt = lcl_InsertLabel(*this, pTxtFmtCollTbl, pUndo,
    1491                 :            :             eType, rTxt, rSeparator, rNumberingSeparator, bBefore,
    1492                 :          0 :             nId, nNdIdx, rCharacterStyle, bCpyBrd);
    1493                 :            : 
    1494         [ #  # ]:          0 :     if (pUndo)
    1495                 :            :     {
    1496                 :          0 :         GetIDocumentUndoRedo().AppendUndo(pUndo);
    1497                 :            :     }
    1498                 :            :     else
    1499                 :            :     {
    1500                 :          0 :         GetIDocumentUndoRedo().DelAllUndoObj();
    1501                 :            :     }
    1502                 :            : 
    1503                 :          0 :     return pNewFmt;
    1504                 :            : }
    1505                 :            : 
    1506                 :            : 
    1507                 :            : /*************************************************************************
    1508                 :            : |*
    1509                 :            : |*  SwDoc::InsertDrawLabel()
    1510                 :            : |*
    1511                 :            : |*************************************************************************/
    1512                 :            : static SwFlyFrmFmt *
    1513                 :          0 : lcl_InsertDrawLabel( SwDoc & rDoc, SwTxtFmtColls *const pTxtFmtCollTbl,
    1514                 :            :         SwUndoInsertLabel *const pUndo, SwDrawFrmFmt *const pOldFmt,
    1515                 :            :         String const& rTxt,
    1516                 :            :                                      const String& rSeparator,
    1517                 :            :                                      const String& rNumberSeparator,
    1518                 :            :                                      const sal_uInt16 nId,
    1519                 :            :                                      const String& rCharacterStyle,
    1520                 :            :                                      SdrObject& rSdrObj )
    1521                 :            : {
    1522 [ #  # ][ #  # ]:          0 :     ::sw::UndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
    1523 [ #  # ][ #  # ]:          0 :     ::sw::DrawUndoGuard const drawUndoGuard(rDoc.GetIDocumentUndoRedo());
    1524                 :            : 
    1525                 :            :     // Because we get by the TxtColl's name, we need to create the field first.
    1526                 :            :     OSL_ENSURE( nId == USHRT_MAX  || nId < rDoc.GetFldTypes()->size(),
    1527                 :            :             "FldType index out of bounds" );
    1528 [ #  # ][ #  # ]:          0 :     SwFieldType *pType = nId != USHRT_MAX ? (*rDoc.GetFldTypes())[nId] : 0;
                 [ #  # ]
    1529                 :            :     OSL_ENSURE( !pType || pType->Which() == RES_SETEXPFLD, "Wrong label id" );
    1530                 :            : 
    1531                 :          0 :     SwTxtFmtColl *pColl = NULL;
    1532         [ #  # ]:          0 :     if( pType )
    1533                 :            :     {
    1534         [ #  # ]:          0 :         for( sal_uInt16 i = pTxtFmtCollTbl->size(); i; )
    1535                 :            :         {
    1536 [ #  # ][ #  # ]:          0 :             if( (*pTxtFmtCollTbl)[ --i ]->GetName().Equals(pType->GetName()) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1537                 :            :             {
    1538         [ #  # ]:          0 :                 pColl = (*pTxtFmtCollTbl)[i];
    1539                 :          0 :                 break;
    1540                 :            :             }
    1541                 :            :         }
    1542                 :            :         OSL_ENSURE( pColl, "no text collection found" );
    1543                 :            :     }
    1544                 :            : 
    1545         [ #  # ]:          0 :     if( !pColl )
    1546                 :            :     {
    1547         [ #  # ]:          0 :         pColl = rDoc.GetTxtCollFromPool( RES_POOLCOLL_LABEL );
    1548                 :            :     }
    1549                 :            : 
    1550                 :          0 :     SwTxtNode* pNew = NULL;
    1551                 :          0 :     SwFlyFrmFmt* pNewFmt = NULL;
    1552                 :            : 
    1553                 :            :     // Destroy Frame,
    1554                 :            :     // insert new Frame,
    1555                 :            :     // insert the corresponding Node with Field into the new Frame,
    1556                 :            :     // insert the old Frame with the Object (Picture/OLE) paragraph-bound into the new Frame,
    1557                 :            :     // create Frames.
    1558                 :            : 
    1559                 :            :     // Keep layer ID of drawing object before removing
    1560                 :            :     // its frames.
    1561                 :            :     // Note: The layer ID is passed to the undo and have to be the correct value.
    1562                 :            :     //       Removing the frames of the drawing object changes its layer.
    1563         [ #  # ]:          0 :     const SdrLayerID nLayerId = rSdrObj.GetLayer();
    1564                 :            : 
    1565         [ #  # ]:          0 :     pOldFmt->DelFrms();
    1566                 :            : 
    1567                 :            :     // InCntnts need to be treated in a special way:
    1568                 :            :     // The TxtAttribute needs to be destroyed.
    1569                 :            :     // Unfortunately, this also destroys the Format next to the Frames.
    1570                 :            :     // To avoid this, we disconnect the attribute from the Format.
    1571         [ #  # ]:          0 :     SfxItemSet* pNewSet = pOldFmt->GetAttrSet().Clone( sal_False );
    1572                 :            : 
    1573                 :            :     // Protect the Frame's size and position
    1574 [ #  # ][ #  # ]:          0 :     if ( rSdrObj.IsMoveProtect() || rSdrObj.IsResizeProtect() )
         [ #  # ][ #  # ]
                 [ #  # ]
    1575                 :            :     {
    1576         [ #  # ]:          0 :         SvxProtectItem aProtect(RES_PROTECT);
    1577                 :          0 :         aProtect.SetCntntProtect( sal_False );
    1578         [ #  # ]:          0 :         aProtect.SetPosProtect( rSdrObj.IsMoveProtect() );
    1579         [ #  # ]:          0 :         aProtect.SetSizeProtect( rSdrObj.IsResizeProtect() );
    1580 [ #  # ][ #  # ]:          0 :         pNewSet->Put( aProtect );
    1581                 :            :     }
    1582                 :            : 
    1583                 :            :     // Take over the text wrap
    1584         [ #  # ]:          0 :     lcl_CpyAttr( *pNewSet, pOldFmt->GetAttrSet(), RES_SURROUND );
    1585                 :            : 
    1586                 :            :     // Send the frame to the back, if needed.
    1587                 :            :     // Consider the 'invisible' hell layer.
    1588 [ #  # ][ #  # ]:          0 :     if ( rDoc.GetHellId() != nLayerId &&
         [ #  # ][ #  # ]
    1589         [ #  # ]:          0 :          rDoc.GetInvisibleHellId() != nLayerId )
    1590                 :            :     {
    1591         [ #  # ]:          0 :         SvxOpaqueItem aOpaque( RES_OPAQUE );
    1592                 :          0 :         aOpaque.SetValue( sal_True );
    1593 [ #  # ][ #  # ]:          0 :         pNewSet->Put( aOpaque );
    1594                 :            :     }
    1595                 :            : 
    1596                 :            :     // Take over position
    1597                 :            :     // #i26791# - use directly drawing object's positioning attributes
    1598 [ #  # ][ #  # ]:          0 :     pNewSet->Put( pOldFmt->GetHoriOrient() );
    1599 [ #  # ][ #  # ]:          0 :     pNewSet->Put( pOldFmt->GetVertOrient() );
    1600                 :            : 
    1601 [ #  # ][ #  # ]:          0 :     pNewSet->Put( pOldFmt->GetAnchor() );
    1602                 :            : 
    1603                 :            :     // The new one should be variable in it's height!
    1604 [ #  # ][ #  # ]:          0 :      Size aSz( rSdrObj.GetCurrentBoundRect().GetSize() );
    1605         [ #  # ]:          0 :     SwFmtFrmSize aFrmSize( ATT_MIN_SIZE, aSz.Width(), aSz.Height() );
    1606         [ #  # ]:          0 :     pNewSet->Put( aFrmSize );
    1607                 :            : 
    1608                 :            :     // Apply the margin to the new Frame.
    1609                 :            :     // Don't set a border, use the one from the Template.
    1610 [ #  # ][ #  # ]:          0 :     pNewSet->Put( pOldFmt->GetLRSpace() );
    1611 [ #  # ][ #  # ]:          0 :     pNewSet->Put( pOldFmt->GetULSpace() );
    1612                 :            : 
    1613                 :            :     SwStartNode* pSttNd =
    1614         [ #  # ]:          0 :         rDoc.GetNodes().MakeTextSection(
    1615         [ #  # ]:          0 :             SwNodeIndex( rDoc.GetNodes().GetEndOfAutotext() ),
    1616 [ #  # ][ #  # ]:          0 :                                     SwFlyStartNode, pColl );
                 [ #  # ]
    1617                 :            : 
    1618                 :            :     pNewFmt = rDoc.MakeFlyFrmFmt( rDoc.GetUniqueFrameName(),
    1619 [ #  # ][ #  # ]:          0 :                  rDoc.GetFrmFmtFromPool( RES_POOLFRM_FRAME ) );
         [ #  # ][ #  # ]
    1620                 :            : 
    1621                 :            :     // Set border and shadow to default if the template contains any.
    1622 [ #  # ][ #  # ]:          0 :     if( SFX_ITEM_SET == pNewFmt->GetAttrSet().GetItemState( RES_BOX, sal_True ))
    1623 [ #  # ][ #  # ]:          0 :         pNewSet->Put( *GetDfltAttr( RES_BOX ) );
    1624                 :            : 
    1625 [ #  # ][ #  # ]:          0 :     if( SFX_ITEM_SET == pNewFmt->GetAttrSet().GetItemState(RES_SHADOW,sal_True))
    1626 [ #  # ][ #  # ]:          0 :         pNewSet->Put( *GetDfltAttr( RES_SHADOW ) );
    1627                 :            : 
    1628 [ #  # ][ #  # ]:          0 :     pNewFmt->SetFmtAttr( SwFmtCntnt( pSttNd ));
                 [ #  # ]
    1629         [ #  # ]:          0 :     pNewFmt->SetFmtAttr( *pNewSet );
    1630                 :            : 
    1631         [ #  # ]:          0 :     const SwFmtAnchor& rAnchor = pNewFmt->GetAnchor();
    1632         [ #  # ]:          0 :     if ( FLY_AS_CHAR == rAnchor.GetAnchorId() )
    1633                 :            :     {
    1634         [ #  # ]:          0 :         const SwPosition *pPos = rAnchor.GetCntntAnchor();
    1635                 :          0 :         SwTxtNode *pTxtNode = pPos->nNode.GetNode().GetTxtNode();
    1636                 :            :         OSL_ENSURE( pTxtNode->HasHints(), "Missing FlyInCnt-Hint." );
    1637                 :          0 :         const xub_StrLen nIdx = pPos->nContent.GetIndex();
    1638                 :            :         SwTxtAttr * const pHnt =
    1639         [ #  # ]:          0 :             pTxtNode->GetTxtAttrForCharAt( nIdx, RES_TXTATR_FLYCNT );
    1640                 :            : 
    1641                 :            : #if OSL_DEBUG_LEVEL > 0
    1642                 :            :         OSL_ENSURE( pHnt && pHnt->Which() == RES_TXTATR_FLYCNT,
    1643                 :            :                     "Missing FlyInCnt-Hint." );
    1644                 :            :         OSL_ENSURE( pHnt && ((SwFmtFlyCnt&)pHnt->GetFlyCnt()).
    1645                 :            :                     GetFrmFmt() == (SwFrmFmt*)pOldFmt,
    1646                 :            :                     "Wrong TxtFlyCnt-Hint." );
    1647                 :            : #endif
    1648                 :          0 :         const_cast<SwFmtFlyCnt&>(pHnt->GetFlyCnt()).SetFlyFmt( pNewFmt );
    1649                 :            :     }
    1650                 :            : 
    1651                 :            : 
    1652                 :            :     // The old one should not have a flow
    1653                 :            :     // and it should be adjusted to above and middle.
    1654         [ #  # ]:          0 :     pNewSet->ClearItem();
    1655                 :            : 
    1656 [ #  # ][ #  # ]:          0 :     pNewSet->Put( SwFmtSurround( SURROUND_NONE ) );
                 [ #  # ]
    1657 [ #  # ][ #  # ]:          0 :     if (nLayerId == rDoc.GetHellId())
    1658                 :            :     {
    1659                 :            :     // Consider drawing objects in the 'invisible' hell layer
    1660 [ #  # ][ #  # ]:          0 :         rSdrObj.SetLayer( rDoc.GetHeavenId() );
    1661                 :            :     }
    1662 [ #  # ][ #  # ]:          0 :     else if (nLayerId == rDoc.GetInvisibleHellId())
    1663                 :            :     {
    1664 [ #  # ][ #  # ]:          0 :         rSdrObj.SetLayer( rDoc.GetInvisibleHeavenId() );
    1665                 :            :     }
    1666 [ #  # ][ #  # ]:          0 :     pNewSet->Put( SvxLRSpaceItem( RES_LR_SPACE ) );
                 [ #  # ]
    1667 [ #  # ][ #  # ]:          0 :     pNewSet->Put( SvxULSpaceItem( RES_UL_SPACE ) );
                 [ #  # ]
    1668                 :            : 
    1669                 :            :     // #i26791# - set position of the drawing object, which is labeled.
    1670 [ #  # ][ #  # ]:          0 :     pNewSet->Put( SwFmtVertOrient( 0, text::VertOrientation::TOP, text::RelOrientation::FRAME ) );
                 [ #  # ]
    1671 [ #  # ][ #  # ]:          0 :     pNewSet->Put( SwFmtHoriOrient( 0, text::HoriOrientation::CENTER, text::RelOrientation::FRAME ) );
                 [ #  # ]
    1672                 :            : 
    1673                 :            :     // The old one is paragraph-bound to the new one's paragraph.
    1674         [ #  # ]:          0 :     SwFmtAnchor aAnch( FLY_AT_PARA );
    1675 [ #  # ][ #  # ]:          0 :     SwNodeIndex aAnchIdx( *pNewFmt->GetCntnt().GetCntntIdx(), 1 );
    1676                 :          0 :     pNew = aAnchIdx.GetNode().GetTxtNode();
    1677         [ #  # ]:          0 :     SwPosition aPos( aAnchIdx );
    1678         [ #  # ]:          0 :     aAnch.SetAnchor( &aPos );
    1679         [ #  # ]:          0 :     pNewSet->Put( aAnch );
    1680                 :            : 
    1681         [ #  # ]:          0 :     if( pUndo )
    1682                 :            :     {
    1683         [ #  # ]:          0 :         pUndo->SetFlys( *pOldFmt, *pNewSet, *pNewFmt );
    1684                 :            :         // #i26791# - position no longer needed
    1685         [ #  # ]:          0 :         pUndo->SetDrawObj( nLayerId );
    1686                 :            :     }
    1687                 :            :     else
    1688         [ #  # ]:          0 :         pOldFmt->SetFmtAttr( *pNewSet );
    1689                 :            : 
    1690 [ #  # ][ #  # ]:          0 :     delete pNewSet;
    1691                 :            : 
    1692                 :            :     // Have only the FlyFrames created.
    1693                 :            :     // We leave this to established methods (especially for InCntFlys).
    1694         [ #  # ]:          0 :     pNewFmt->MakeFrms();
    1695                 :            : 
    1696                 :            :     OSL_ENSURE( pNew, "No Label inserted" );
    1697                 :            : 
    1698         [ #  # ]:          0 :     if( pNew )
    1699                 :            :     {
    1700                 :            :         //#i61007# order of captions
    1701         [ #  # ]:          0 :         sal_Bool bOrderNumberingFirst = SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst();
    1702                 :            : 
    1703                 :            :         // prepare string
    1704         [ #  # ]:          0 :         String aTxt;
    1705         [ #  # ]:          0 :         if( bOrderNumberingFirst )
    1706                 :            :         {
    1707         [ #  # ]:          0 :             aTxt = rNumberSeparator;
    1708                 :            :         }
    1709         [ #  # ]:          0 :         if ( pType )
    1710                 :            :         {
    1711 [ #  # ][ #  # ]:          0 :             aTxt += pType->GetName();
    1712         [ #  # ]:          0 :             if( !bOrderNumberingFirst )
    1713         [ #  # ]:          0 :                 aTxt += ' ';
    1714                 :            :         }
    1715                 :          0 :         xub_StrLen nIdx = aTxt.Len();
    1716         [ #  # ]:          0 :         aTxt += rSeparator;
    1717                 :          0 :         xub_StrLen nSepIdx = aTxt.Len();
    1718         [ #  # ]:          0 :         aTxt += rTxt;
    1719                 :            : 
    1720                 :            :         // insert text
    1721 [ #  # ][ #  # ]:          0 :         SwIndex aIdx( pNew, 0 );
    1722         [ #  # ]:          0 :         pNew->InsertText( aTxt, aIdx );
    1723                 :            : 
    1724                 :            :         // insert field
    1725         [ #  # ]:          0 :         if ( pType )
    1726                 :            :         {
    1727         [ #  # ]:          0 :             SwSetExpField aFld( (SwSetExpFieldType*)pType, aEmptyStr, SVX_NUM_ARABIC );
    1728         [ #  # ]:          0 :             if( bOrderNumberingFirst )
    1729                 :          0 :                 nIdx = 0;
    1730         [ #  # ]:          0 :             SwFmtFld aFmt( aFld );
    1731         [ #  # ]:          0 :             pNew->InsertItem( aFmt, nIdx, nIdx );
    1732         [ #  # ]:          0 :             if ( rCharacterStyle.Len() )
    1733                 :            :             {
    1734         [ #  # ]:          0 :                 SwCharFmt * pCharFmt = rDoc.FindCharFmtByName(rCharacterStyle);
    1735         [ #  # ]:          0 :                 if ( !pCharFmt )
    1736                 :            :                 {
    1737         [ #  # ]:          0 :                     const sal_uInt16 nMyId = SwStyleNameMapper::GetPoolIdFromUIName( rCharacterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
    1738         [ #  # ]:          0 :                     pCharFmt = rDoc.GetCharFmtFromPool( nMyId );
    1739                 :            :                 }
    1740         [ #  # ]:          0 :                 if ( pCharFmt )
    1741                 :            :                 {
    1742         [ #  # ]:          0 :                     SwFmtCharFmt aCharFmt( pCharFmt );
    1743                 :            :                     pNew->InsertItem( aCharFmt, 0, nSepIdx + 1,
    1744 [ #  # ][ #  # ]:          0 :                             nsSetAttrMode::SETATTR_DONTEXPAND );
    1745                 :            :                 }
    1746 [ #  # ][ #  # ]:          0 :             }
    1747 [ #  # ][ #  # ]:          0 :         }
    1748                 :            :     }
    1749                 :            : 
    1750 [ #  # ][ #  # ]:          0 :     return pNewFmt;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1751                 :            : }
    1752                 :            : 
    1753                 :          0 : SwFlyFrmFmt* SwDoc::InsertDrawLabel(
    1754                 :            :         String const& rTxt,
    1755                 :            :         String const& rSeparator,
    1756                 :            :         String const& rNumberSeparator,
    1757                 :            :         sal_uInt16 const nId,
    1758                 :            :         String const& rCharacterStyle,
    1759                 :            :         SdrObject& rSdrObj )
    1760                 :            : {
    1761                 :            :     SwDrawContact *const pContact =
    1762                 :          0 :         static_cast<SwDrawContact*>(GetUserCall( &rSdrObj ));
    1763                 :            :     OSL_ENSURE( RES_DRAWFRMFMT == pContact->GetFmt()->Which(),
    1764                 :            :             "InsertDrawLabel(): not a DrawFrmFmt" );
    1765         [ #  # ]:          0 :     if (!pContact)
    1766                 :          0 :         return 0;
    1767                 :            : 
    1768                 :          0 :     SwDrawFrmFmt* pOldFmt = (SwDrawFrmFmt *)pContact->GetFmt();
    1769         [ #  # ]:          0 :     if (!pOldFmt)
    1770                 :          0 :         return 0;
    1771                 :            : 
    1772                 :          0 :     SwUndoInsertLabel * pUndo = 0;
    1773         [ #  # ]:          0 :     if (GetIDocumentUndoRedo().DoesUndo())
    1774                 :            :     {
    1775                 :          0 :         GetIDocumentUndoRedo().ClearRedo();
    1776                 :            :         pUndo = new SwUndoInsertLabel(
    1777                 :            :             LTYPE_DRAW, rTxt, rSeparator, rNumberSeparator, sal_False,
    1778         [ #  # ]:          0 :             nId, rCharacterStyle, sal_False );
    1779                 :            :     }
    1780                 :            : 
    1781                 :            :     SwFlyFrmFmt *const pNewFmt = lcl_InsertDrawLabel(
    1782                 :            :         *this, pTxtFmtCollTbl, pUndo, pOldFmt,
    1783                 :          0 :         rTxt, rSeparator, rNumberSeparator, nId, rCharacterStyle, rSdrObj);
    1784                 :            : 
    1785         [ #  # ]:          0 :     if (pUndo)
    1786                 :            :     {
    1787                 :          0 :         GetIDocumentUndoRedo().AppendUndo( pUndo );
    1788                 :            :     }
    1789                 :            :     else
    1790                 :            :     {
    1791                 :          0 :         GetIDocumentUndoRedo().DelAllUndoObj();
    1792                 :            :     }
    1793                 :            : 
    1794                 :          0 :     return pNewFmt;
    1795                 :            : }
    1796                 :            : 
    1797                 :            : 
    1798                 :            : /*************************************************************************
    1799                 :            : |*
    1800                 :            : |*  IDocumentTimerAccess methods
    1801                 :            : |*
    1802                 :            : |*************************************************************************/
    1803                 :       1318 : void SwDoc::StartIdling()
    1804                 :            : {
    1805                 :       1318 :     mbStartIdleTimer = sal_True;
    1806         [ +  - ]:       1318 :     if( !mIdleBlockCount )
    1807                 :       1318 :         aIdleTimer.Start();
    1808                 :       1318 : }
    1809                 :            : 
    1810                 :       2776 : void SwDoc::StopIdling()
    1811                 :            : {
    1812                 :       2776 :     mbStartIdleTimer = sal_False;
    1813                 :       2776 :     aIdleTimer.Stop();
    1814                 :       2776 : }
    1815                 :            : 
    1816                 :       4723 : void SwDoc::BlockIdling()
    1817                 :            : {
    1818                 :       4723 :     aIdleTimer.Stop();
    1819                 :       4723 :     ++mIdleBlockCount;
    1820                 :       4723 : }
    1821                 :            : 
    1822                 :       4723 : void SwDoc::UnblockIdling()
    1823                 :            : {
    1824                 :       4723 :     --mIdleBlockCount;
    1825 [ +  + ][ +  + ]:       4723 :     if( !mIdleBlockCount && mbStartIdleTimer && !aIdleTimer.IsActive() )
         [ +  - ][ +  + ]
    1826                 :       2321 :         aIdleTimer.Start();
    1827                 :       4723 : }
    1828                 :            : 
    1829                 :            : /*************************************************************************
    1830                 :            : |*
    1831                 :            : |*  SwDoc::DoIdleJobs()
    1832                 :            : |*
    1833                 :            : |*************************************************************************/
    1834                 :       8698 : IMPL_LINK( SwDoc, DoIdleJobs, Timer *, pTimer )
    1835                 :            : {
    1836                 :            : #ifdef TIMELOG
    1837                 :            :     static ::rtl::Logfile* pModLogFile = 0;
    1838                 :            :     if( !pModLogFile )
    1839                 :            :         pModLogFile = new ::rtl::Logfile( "First DoIdleJobs" );
    1840                 :            : #endif
    1841                 :            : 
    1842                 :       8698 :     SwRootFrm* pTmpRoot = GetCurrentLayout();//swmod 080219
    1843         [ +  - ]:      17396 :     if( pTmpRoot &&
           [ +  -  +  - ]
    1844                 :       8698 :         !SfxProgress::GetActiveProgress( pDocShell ) )
    1845                 :            :     {
    1846                 :            :         ViewShell *pSh, *pStartSh;
    1847         [ +  - ]:       8698 :         pSh = pStartSh = GetCurrentViewShell();
    1848         [ -  + ]:       8697 :         do {
    1849         [ +  + ]:       8698 :             if( pSh->ActionPend() )
    1850                 :            :             {
    1851         [ +  - ]:          1 :                 if( pTimer )
    1852         [ +  - ]:          1 :                     pTimer->Start();
    1853                 :          1 :                 return 0;
    1854                 :            :             }
    1855                 :       8697 :             pSh = (ViewShell*)pSh->GetNext();
    1856                 :            :         } while( pSh != pStartSh );
    1857                 :            : 
    1858         [ +  - ]:       8697 :         if( pTmpRoot->IsNeedGrammarCheck() )
    1859                 :            :         {
    1860                 :       8697 :             sal_Bool bIsOnlineSpell = pSh->GetViewOptions()->IsOnlineSpell();
    1861                 :       8697 :             sal_Bool bIsAutoGrammar = sal_False;
    1862                 :            :             SvtLinguConfig().GetProperty( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
    1863 [ +  - ][ +  - ]:       8697 :                         UPN_IS_GRAMMAR_AUTO )) ) >>= bIsAutoGrammar;
         [ +  - ][ +  - ]
    1864                 :            : 
    1865 [ +  - ][ +  + ]:       8697 :             if (bIsOnlineSpell && bIsAutoGrammar)
    1866         [ +  - ]:       8697 :                 StartGrammarChecking( *this );
    1867                 :            :         }
    1868                 :            :         SwFldUpdateFlags nFldUpdFlag;
    1869         [ +  - ]:       8697 :         std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();//swmod 080320
    1870                 :       8697 :         std::set<SwRootFrm*>::iterator pLayIter = aAllLayouts.begin();
    1871         [ +  + ]:      12904 :         for ( ;pLayIter != aAllLayouts.end();++pLayIter )
    1872                 :            :         {
    1873         [ +  + ]:       8697 :             if ((*pLayIter)->IsIdleFormat())
    1874                 :            :             {
    1875         [ +  - ]:       4490 :                 (*pLayIter)->GetCurrShell()->LayoutIdle();
    1876                 :       4490 :                 break;
    1877                 :            :             }
    1878                 :            :         }
    1879                 :       8697 :         bool bAllValid = pLayIter == aAllLayouts.end() ? 1 : 0;
    1880 [ +  - ][ +  - ]:      12912 :         if( bAllValid && ( AUTOUPD_FIELD_ONLY ==
           [ +  -  +  +  
           +  - ][ +  - ]
         [ +  + ][ +  + ]
    1881                 :       4207 :                  ( nFldUpdFlag = getFieldUpdateFlags(true) )
    1882                 :            :                     || AUTOUPD_FIELD_AND_CHARTS == nFldUpdFlag ) &&
    1883         [ +  - ]:       4207 :                 GetUpdtFlds().IsFieldsDirty() &&
    1884         [ +  - ]:          4 :                 !GetUpdtFlds().IsInUpdateFlds() &&
    1885         [ +  - ]:          4 :                 !IsExpFldsLocked()
    1886                 :            :                 // If we switch the field name the Fields are not updated.
    1887                 :            :                 // So the "backgorund update" should always be carried out
    1888                 :            :                 /* && !pStartSh->GetViewOptions()->IsFldName()*/ )
    1889                 :            :         {
    1890                 :            :             //  Action brackets!
    1891         [ +  - ]:          4 :             GetUpdtFlds().SetInUpdateFlds( sal_True );
    1892                 :            : 
    1893         [ +  - ]:          4 :             pTmpRoot->StartAllAction();
    1894                 :            : 
    1895                 :            :             // no jump on update of fields #i85168#
    1896                 :          4 :             const sal_Bool bOldLockView = pStartSh->IsViewLocked();
    1897                 :          4 :             pStartSh->LockView( sal_True );
    1898                 :            : 
    1899 [ +  - ][ +  - ]:          4 :             GetSysFldType( RES_CHAPTERFLD )->ModifyNotification( 0, 0 );    // ChapterField
    1900         [ +  - ]:          4 :             UpdateExpFlds( 0, sal_False );      // Updates ExpressionFields
    1901         [ +  - ]:          4 :             UpdateTblFlds(NULL);                // Tables
    1902         [ +  - ]:          4 :             UpdateRefFlds(NULL);                // References
    1903                 :            : 
    1904         [ +  - ]:          4 :             pTmpRoot->EndAllAction();
    1905                 :            : 
    1906                 :          4 :             pStartSh->LockView( bOldLockView );
    1907                 :            : 
    1908         [ +  - ]:          4 :             GetUpdtFlds().SetInUpdateFlds( sal_False );
    1909         [ +  - ]:          4 :             GetUpdtFlds().SetFieldsDirty( sal_False );
    1910                 :       8697 :         }
    1911                 :            :     }   //swmod 080219
    1912                 :            : #ifdef TIMELOG
    1913                 :            :     if( pModLogFile && 1 != (long)pModLogFile )
    1914                 :            :         delete pModLogFile, ((long&)pModLogFile) = 1;
    1915                 :            : #endif
    1916         [ +  - ]:       8697 :     if( pTimer )
    1917                 :       8697 :         pTimer->Start();
    1918                 :       8698 :     return 0;
    1919                 :            : }
    1920                 :            : 
    1921                 :          0 : IMPL_STATIC_LINK( SwDoc, BackgroundDone, SvxBrushItem*, EMPTYARG )
    1922                 :            : {
    1923                 :            :     ViewShell *pSh, *pStartSh;
    1924                 :          0 :     pSh = pStartSh = pThis->GetCurrentViewShell();  //swmod 071108//swmod 071225
    1925         [ #  # ]:          0 :     if( pStartSh )
    1926         [ #  # ]:          0 :         do {
    1927         [ #  # ]:          0 :             if( pSh->GetWin() )
    1928                 :            :             {
    1929                 :            :                 // Make sure to repaint with virtual device
    1930                 :          0 :                 pSh->LockPaint();
    1931                 :          0 :                 pSh->UnlockPaint( sal_True );
    1932                 :            :             }
    1933                 :          0 :             pSh = (ViewShell*)pSh->GetNext();
    1934                 :            :         } while( pSh != pStartSh );
    1935                 :          0 :     return 0;
    1936                 :            : }
    1937                 :            : 
    1938                 :        128 : static String lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId )
    1939                 :            : {
    1940                 :        128 :     ResId aId( nDefStrId, *pSwResMgr );
    1941         [ +  - ]:        128 :     String aName( aId );
    1942                 :        128 :     xub_StrLen nNmLen = aName.Len();
    1943                 :            : 
    1944                 :        128 :     const SwFrmFmts& rFmts = *pDoc->GetSpzFrmFmts();
    1945                 :            : 
    1946                 :        128 :     sal_uInt16 nNum, nTmp, nFlagSize = ( rFmts.size() / 8 ) +2;
    1947         [ +  - ]:        128 :     sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ];
    1948                 :            :     sal_uInt16 n;
    1949                 :            : 
    1950                 :        128 :     memset( pSetFlags, 0, nFlagSize );
    1951                 :            : 
    1952         [ +  + ]:        268 :     for( n = 0; n < rFmts.size(); ++n )
    1953                 :            :     {
    1954         [ +  - ]:        140 :         const SwFrmFmt* pFlyFmt = rFmts[ n ];
    1955 [ +  + ][ +  + ]:        244 :         if( RES_FLYFRMFMT == pFlyFmt->Which() &&
                 [ +  + ]
    1956         [ +  - ]:        104 :             pFlyFmt->GetName().Match( aName ) == nNmLen )
    1957                 :            :         {
    1958                 :            :             // Only get and set the Flag
    1959 [ +  - ][ +  - ]:         17 :             nNum = static_cast< sal_uInt16 >( pFlyFmt->GetName().Copy( nNmLen ).ToInt32() );
                 [ +  - ]
    1960 [ +  - ][ +  - ]:         17 :             if( nNum-- && nNum < rFmts.size() )
                 [ +  - ]
    1961                 :         17 :                 pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 ));
    1962                 :            :         }
    1963                 :            :     }
    1964                 :            : 
    1965                 :            :     // All numbers are flagged accordingly, so determine the right one
    1966                 :        128 :     nNum = rFmts.size();
    1967         [ +  - ]:        128 :     for( n = 0; n < nFlagSize; ++n )
    1968         [ +  - ]:        128 :         if( 0xff != ( nTmp = pSetFlags[ n ] ))
    1969                 :            :         {
    1970                 :            :             // so determine the number
    1971                 :        128 :             nNum = n * 8;
    1972         [ +  + ]:        145 :             while( nTmp & 1 )
    1973                 :         17 :                 ++nNum, nTmp >>= 1;
    1974                 :        128 :             break;
    1975                 :            :         }
    1976                 :            : 
    1977         [ +  - ]:        128 :     delete [] pSetFlags;
    1978 [ +  - ][ +  - ]:        128 :     return aName += String::CreateFromInt32( ++nNum );
         [ +  - ][ +  - ]
                 [ +  - ]
    1979                 :            : }
    1980                 :            : 
    1981                 :         15 : String SwDoc::GetUniqueGrfName() const
    1982                 :            : {
    1983                 :         15 :     return lcl_GetUniqueFlyName( this, STR_GRAPHIC_DEFNAME );
    1984                 :            : }
    1985                 :            : 
    1986                 :          6 : String SwDoc::GetUniqueOLEName() const
    1987                 :            : {
    1988                 :          6 :     return lcl_GetUniqueFlyName( this, STR_OBJECT_DEFNAME );
    1989                 :            : }
    1990                 :            : 
    1991                 :        101 : String SwDoc::GetUniqueFrameName() const
    1992                 :            : {
    1993                 :        101 :     return lcl_GetUniqueFlyName( this, STR_FRAME_DEFNAME );
    1994                 :            : }
    1995                 :            : 
    1996                 :        195 : const SwFlyFrmFmt* SwDoc::FindFlyByName( const String& rName, sal_Int8 nNdTyp ) const
    1997                 :            : {
    1998                 :        195 :     const SwFrmFmts& rFmts = *GetSpzFrmFmts();
    1999         [ +  + ]:        559 :     for( sal_uInt16 n = rFmts.size(); n; )
    2000                 :            :     {
    2001                 :        400 :         const SwFrmFmt* pFlyFmt = rFmts[ --n ];
    2002                 :            :         const SwNodeIndex* pIdx;
    2003   [ +  +  +  -  :        472 :         if( RES_FLYFRMFMT == pFlyFmt->Which() && pFlyFmt->GetName() == rName &&
           +  - ][ +  + ]
                 [ +  + ]
    2004                 :         36 :             0 != ( pIdx = pFlyFmt->GetCntnt().GetCntntIdx() ) &&
    2005                 :         36 :             pIdx->GetNode().GetNodes().IsDocNodes() )
    2006                 :            :         {
    2007         [ +  + ]:         36 :             if( nNdTyp )
    2008                 :            :             {
    2009                 :            :                 // query for the right NodeType
    2010                 :         30 :                 const SwNode* pNd = GetNodes()[ pIdx->GetIndex()+1 ];
    2011 [ +  - ][ +  + ]:         60 :                 if( nNdTyp == ND_TEXTNODE
    2012                 :         12 :                         ? !pNd->IsNoTxtNode()
    2013                 :         18 :                         : nNdTyp == pNd->GetNodeType() )
    2014                 :         30 :                     return (SwFlyFrmFmt*)pFlyFmt;
    2015                 :            :             }
    2016                 :            :             else
    2017                 :          6 :                 return (SwFlyFrmFmt*)pFlyFmt;
    2018                 :            :         }
    2019                 :            :     }
    2020                 :        195 :     return 0;
    2021                 :            : }
    2022                 :            : 
    2023                 :        117 : void SwDoc::SetFlyName( SwFlyFrmFmt& rFmt, const String& rName )
    2024                 :            : {
    2025         [ +  - ]:        117 :     String sName( rName );
    2026 [ +  - ][ +  - ]:        117 :     if( !rName.Len() || FindFlyByName( rName ) )
         [ +  + ][ +  + ]
    2027                 :            :     {
    2028                 :          6 :         sal_uInt16 nTyp = STR_FRAME_DEFNAME;
    2029         [ +  - ]:          6 :         const SwNodeIndex* pIdx = rFmt.GetCntnt().GetCntntIdx();
    2030 [ +  - ][ +  - ]:          6 :         if( pIdx && pIdx->GetNode().GetNodes().IsDocNodes() )
         [ +  - ][ +  - ]
    2031 [ +  - ][ +  - ]:          6 :             switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
              [ +  -  - ]
    2032                 :            :             {
    2033                 :          6 :             case ND_GRFNODE:    nTyp = STR_GRAPHIC_DEFNAME; break;
    2034                 :          6 :             case ND_OLENODE:    nTyp = STR_OBJECT_DEFNAME;  break;
    2035                 :            :             }
    2036 [ +  - ][ +  - ]:          6 :         sName = lcl_GetUniqueFlyName( this, nTyp );
                 [ +  - ]
    2037                 :            :     }
    2038         [ +  - ]:        117 :     rFmt.SetName( sName, sal_True );
    2039 [ +  - ][ +  - ]:        117 :     SetModified();
    2040                 :        117 : }
    2041                 :            : 
    2042                 :        188 : void SwDoc::SetAllUniqueFlyNames()
    2043                 :            : {
    2044                 :        188 :     sal_uInt16 n, nFlyNum = 0, nGrfNum = 0, nOLENum = 0;
    2045                 :            : 
    2046                 :        188 :     ResId nFrmId( STR_FRAME_DEFNAME, *pSwResMgr ),
    2047                 :        188 :           nGrfId( STR_GRAPHIC_DEFNAME, *pSwResMgr ),
    2048                 :        188 :           nOLEId( STR_OBJECT_DEFNAME, *pSwResMgr );
    2049         [ +  - ]:        188 :     String sFlyNm( nFrmId );
    2050         [ +  - ]:        188 :     String sGrfNm( nGrfId );
    2051         [ +  - ]:        188 :     String sOLENm( nOLEId );
    2052                 :            : 
    2053         [ -  + ]:        188 :     if( 255 < ( n = GetSpzFrmFmts()->size() ))
    2054                 :          0 :         n = 255;
    2055         [ +  - ]:        188 :     SwFrmFmts aArr;
    2056         [ +  - ]:        188 :     aArr.reserve( (sal_Int8)n );
    2057                 :            :     SwFrmFmt* pFlyFmt;
    2058                 :        188 :     sal_Bool bLoadedFlag = sal_True;            // something for the Layout
    2059                 :            : 
    2060         [ +  + ]:        387 :     for( n = GetSpzFrmFmts()->size(); n; )
    2061                 :            :     {
    2062 [ +  - ][ +  + ]:        199 :         if( RES_FLYFRMFMT == (pFlyFmt = (*GetSpzFrmFmts())[ --n ])->Which() )
    2063                 :            :         {
    2064                 :         65 :             sal_uInt16 *pNum = 0;
    2065                 :            :             xub_StrLen nLen;
    2066                 :         65 :             const String& rNm = pFlyFmt->GetName();
    2067         [ +  + ]:         65 :             if( rNm.Len() )
    2068                 :            :             {
    2069 [ +  - ][ +  + ]:          8 :                 if( rNm.Match( sGrfNm ) == ( nLen = sGrfNm.Len() ))
    2070                 :          2 :                     pNum = &nGrfNum;
    2071 [ +  - ][ +  + ]:          6 :                 else if( rNm.Match( sFlyNm ) == ( nLen = sFlyNm.Len() ))
    2072                 :          4 :                     pNum = &nFlyNum;
    2073 [ +  - ][ +  - ]:          2 :                 else if( rNm.Match( sOLENm ) == ( nLen = sOLENm.Len() ))
    2074                 :          2 :                     pNum = &nOLENum;
    2075                 :            : 
    2076 [ +  - ][ +  - ]:          8 :                 if ( pNum && *pNum < ( nLen = static_cast< xub_StrLen >( rNm.Copy( nLen ).ToInt32() ) ) )
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
           [ +  +  #  # ]
    2077                 :          6 :                     *pNum = nLen;
    2078                 :            :             }
    2079                 :            :             else
    2080                 :            :                 // we want to set that afterwards
    2081         [ +  - ]:         57 :                 aArr.push_back( pFlyFmt );
    2082                 :            : 
    2083                 :            :         }
    2084         [ +  + ]:        199 :         if( bLoadedFlag )
    2085                 :            :         {
    2086         [ +  - ]:         60 :             const SwFmtAnchor& rAnchor = pFlyFmt->GetAnchor();
    2087         [ +  + ]:        160 :             if (((FLY_AT_PAGE == rAnchor.GetAnchorId()) &&
           [ +  -  +  + ]
         [ -  + ][ #  # ]
                 [ +  + ]
    2088         [ +  - ]:          6 :                  rAnchor.GetCntntAnchor()) ||
    2089                 :            :                 // Or are DrawObjects adjusted relatively to something?
    2090                 :         60 :                 ( RES_DRAWFRMFMT == pFlyFmt->Which() && (
    2091                 :            :                     SFX_ITEM_SET == pFlyFmt->GetItemState(
    2092         [ +  - ]:         34 :                                         RES_VERT_ORIENT )||
    2093                 :            :                     SFX_ITEM_SET == pFlyFmt->GetItemState(
    2094         [ #  # ]:          0 :                                         RES_HORI_ORIENT ))) )
    2095                 :            :             {
    2096                 :         34 :                 bLoadedFlag = sal_False;
    2097                 :            :             }
    2098                 :            :         }
    2099                 :            :     }
    2100                 :            : 
    2101                 :            :     const SwNodeIndex* pIdx;
    2102                 :            : 
    2103         [ +  + ]:        245 :     for( n = aArr.size(); n; )
    2104 [ +  - ][ +  - ]:        114 :         if( 0 != ( pIdx = ( pFlyFmt = aArr[ --n ])->GetCntnt().GetCntntIdx() )
         [ +  - ][ +  - ]
                 [ +  - ]
    2105         [ +  - ]:         57 :             && pIdx->GetNode().GetNodes().IsDocNodes() )
    2106                 :            :         {
    2107                 :            :             sal_uInt16 nNum;
    2108         [ +  - ]:         57 :             String sNm;
    2109 [ +  - ][ +  - ]:         57 :             switch( GetNodes()[ pIdx->GetIndex() + 1 ]->GetNodeType() )
              [ +  -  + ]
    2110                 :            :             {
    2111                 :            :             case ND_GRFNODE:
    2112         [ +  - ]:         45 :                 sNm = sGrfNm;
    2113                 :         45 :                 nNum = ++nGrfNum;
    2114                 :         45 :                 break;
    2115                 :            :             case ND_OLENODE:
    2116         [ #  # ]:          0 :                 sNm = sOLENm;
    2117                 :          0 :                 nNum = ++nOLENum;
    2118                 :          0 :                 break;
    2119                 :            :             default:
    2120         [ +  - ]:         12 :                 sNm = sFlyNm;
    2121                 :         12 :                 nNum = ++nFlyNum;
    2122                 :         12 :                 break;
    2123                 :            :             }
    2124 [ +  - ][ +  - ]:         57 :             pFlyFmt->SetName( sNm += String::CreateFromInt32( nNum ));
         [ +  - ][ +  - ]
                 [ +  - ]
    2125                 :            :         }
    2126                 :        188 :     aArr.clear();
    2127                 :            : 
    2128         [ +  + ]:        188 :     if( !GetFtnIdxs().empty() )
    2129                 :            :     {
    2130         [ +  - ]:          6 :         SwTxtFtn::SetUniqueSeqRefNo( *this );
    2131                 :            :         // #i52775# Chapter footnotes did not get updated correctly.
    2132                 :            :         // Calling UpdateAllFtn() instead of UpdateFtn() solves this problem,
    2133                 :            :         // but I do not dare to call UpdateAllFtn() in all cases: Safety first.
    2134         [ -  + ]:          6 :         if ( FTNNUM_CHAPTER == GetFtnInfo().eNum )
    2135                 :            :         {
    2136         [ #  # ]:          0 :             GetFtnIdxs().UpdateAllFtn();
    2137                 :            :         }
    2138                 :            :         else
    2139                 :            :         {
    2140 [ +  - ][ +  - ]:          6 :             SwNodeIndex aTmp( GetNodes() );
    2141 [ +  - ][ +  - ]:          6 :             GetFtnIdxs().UpdateFtn( aTmp );
    2142                 :            :         }
    2143                 :            :     }
    2144                 :            : 
    2145                 :            :     // Found a new document, but not a page anchored Frame/DrawObjects
    2146                 :            :     // that are anchored to another Node.
    2147         [ +  + ]:        188 :     if( bLoadedFlag )
    2148 [ +  - ][ +  - ]:        188 :         SetLoaded( sal_True );
         [ +  - ][ +  - ]
                 [ +  - ]
    2149                 :        188 : }
    2150                 :            : 
    2151                 :       1450 : sal_Bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const
    2152                 :            : {
    2153                 :            :     // If there's a Layout, use it!
    2154                 :            :     // That can also be a Fly in a Fly in the Header.
    2155                 :            :     // Is also used by sw3io, to determine if a Redline object is
    2156                 :            :     // in the Header or Footer.
    2157                 :            :     // Because Redlines are also attached to Start and EndNoden,
    2158                 :            :     // the Index must not necessarily be from a ContentNode.
    2159                 :       1450 :     SwNode* pNd = &rIdx.GetNode();
    2160 [ +  + ][ +  + ]:       1450 :     if( pNd->IsCntntNode() && pCurrentView )//swmod 071029//swmod 071225
                 [ +  + ]
    2161                 :            :     {
    2162                 :       1122 :         const SwFrm *pFrm = pNd->GetCntntNode()->getLayoutFrm( GetCurrentLayout() );
    2163         [ +  - ]:       1122 :         if( pFrm )
    2164                 :            :         {
    2165                 :       1122 :             const SwFrm *pUp = pFrm->GetUpper();
    2166 [ +  + ][ +  + ]:       4461 :             while ( pUp && !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() )
         [ +  - ][ +  + ]
    2167                 :            :             {
    2168         [ -  + ]:       3339 :                 if ( pUp->IsFlyFrm() )
    2169                 :          0 :                     pUp = ((SwFlyFrm*)pUp)->GetAnchorFrm();
    2170                 :       3339 :                 pUp = pUp->GetUpper();
    2171                 :            :             }
    2172         [ +  + ]:       1122 :             if ( pUp )
    2173                 :          9 :                 return sal_True;
    2174                 :            : 
    2175                 :       1113 :             return sal_False;
    2176                 :            :         }
    2177                 :            :     }
    2178                 :            : 
    2179                 :            : 
    2180                 :        328 :     const SwNode* pFlyNd = pNd->FindFlyStartNode();
    2181         [ -  + ]:        328 :     while( pFlyNd )
    2182                 :            :     {
    2183                 :            :         // get up by using the Anchor
    2184                 :            :         sal_uInt16 n;
    2185         [ #  # ]:          0 :         for( n = 0; n < GetSpzFrmFmts()->size(); ++n )
    2186                 :            :         {
    2187                 :          0 :             const SwFrmFmt* pFmt = (*GetSpzFrmFmts())[ n ];
    2188                 :          0 :             const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
    2189 [ #  # ][ #  # ]:          0 :             if( pIdx && pFlyNd == &pIdx->GetNode() )
                 [ #  # ]
    2190                 :            :             {
    2191                 :          0 :                 const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
    2192         [ #  # ]:          0 :                 if ((FLY_AT_PAGE == rAnchor.GetAnchorId()) ||
           [ #  #  #  # ]
    2193                 :          0 :                     !rAnchor.GetCntntAnchor() )
    2194                 :            :                 {
    2195                 :          0 :                     return sal_False;
    2196                 :            :                 }
    2197                 :            : 
    2198                 :          0 :                 pNd = &rAnchor.GetCntntAnchor()->nNode.GetNode();
    2199                 :          0 :                 pFlyNd = pNd->FindFlyStartNode();
    2200                 :          0 :                 break;
    2201                 :            :             }
    2202                 :            :         }
    2203         [ #  # ]:          0 :         if( n >= GetSpzFrmFmts()->size() )
    2204                 :            :         {
    2205                 :            :             OSL_ENSURE( mbInReading, "Found a FlySection but not a Format!" );
    2206                 :          0 :             return sal_False;
    2207                 :            :         }
    2208                 :            :     }
    2209                 :            : 
    2210                 :        328 :     return 0 != pNd->FindHeaderStartNode() ||
    2211 [ -  + ][ +  + ]:       1450 :             0 != pNd->FindFooterStartNode();
    2212                 :            : }
    2213                 :            : 
    2214                 :      14298 : short SwDoc::GetTextDirection( const SwPosition& rPos,
    2215                 :            :                                const Point* pPt ) const
    2216                 :            : {
    2217                 :      14298 :     short nRet = -1;
    2218                 :            : 
    2219                 :      14298 :     SwCntntNode *pNd = rPos.nNode.GetNode().GetCntntNode();
    2220                 :            : 
    2221                 :            :     // #i42921# - use new method <SwCntntNode::GetTextDirection(..)>
    2222         [ +  - ]:      14298 :     if ( pNd )
    2223                 :            :     {
    2224                 :      14298 :         nRet = pNd->GetTextDirection( rPos, pPt );
    2225                 :            :     }
    2226         [ -  + ]:      14298 :     if ( nRet == -1 )
    2227                 :            :     {
    2228                 :          0 :         const SvxFrameDirectionItem* pItem = 0;
    2229         [ #  # ]:          0 :         if( pNd )
    2230                 :            :         {
    2231                 :            :             // Are we in a FlyFrame? Then look at that for the correct attribute
    2232                 :          0 :             const SwFrmFmt* pFlyFmt = pNd->GetFlyFmt();
    2233         [ #  # ]:          0 :             while( pFlyFmt )
    2234                 :            :             {
    2235                 :          0 :                 pItem = &pFlyFmt->GetFrmDir();
    2236         [ #  # ]:          0 :                 if( FRMDIR_ENVIRONMENT == pItem->GetValue() )
    2237                 :            :                 {
    2238                 :          0 :                     pItem = 0;
    2239                 :          0 :                     const SwFmtAnchor* pAnchor = &pFlyFmt->GetAnchor();
    2240         [ #  # ]:          0 :                     if ((FLY_AT_PAGE != pAnchor->GetAnchorId()) &&
           [ #  #  #  # ]
    2241                 :          0 :                         pAnchor->GetCntntAnchor())
    2242                 :            :                     {
    2243                 :          0 :                         pFlyFmt = pAnchor->GetCntntAnchor()->nNode.
    2244                 :          0 :                                             GetNode().GetFlyFmt();
    2245                 :            :                     }
    2246                 :            :                     else
    2247                 :          0 :                         pFlyFmt = 0;
    2248                 :            :                 }
    2249                 :            :                 else
    2250                 :          0 :                     pFlyFmt = 0;
    2251                 :            :             }
    2252                 :            : 
    2253         [ #  # ]:          0 :             if( !pItem )
    2254                 :            :             {
    2255                 :          0 :                 const SwPageDesc* pPgDsc = pNd->FindPageDesc( sal_False );
    2256         [ #  # ]:          0 :                 if( pPgDsc )
    2257                 :          0 :                     pItem = &pPgDsc->GetMaster().GetFrmDir();
    2258                 :            :             }
    2259                 :            :         }
    2260         [ #  # ]:          0 :         if( !pItem )
    2261                 :          0 :             pItem = (SvxFrameDirectionItem*)&GetAttrPool().GetDefaultItem(
    2262                 :          0 :                                                             RES_FRAMEDIR );
    2263                 :          0 :         nRet = pItem->GetValue();
    2264                 :            :     }
    2265                 :      14298 :     return nRet;
    2266                 :            : }
    2267                 :            : 
    2268                 :          0 : sal_Bool SwDoc::IsInVerticalText( const SwPosition& rPos, const Point* pPt ) const
    2269                 :            : {
    2270                 :          0 :     const short nDir = GetTextDirection( rPos, pPt );
    2271 [ #  # ][ #  # ]:          0 :     return FRMDIR_VERT_TOP_RIGHT == nDir || FRMDIR_VERT_TOP_LEFT == nDir;
    2272                 :            : }
    2273                 :            : 
    2274                 :       3688 : void SwDoc::SetCurrentViewShell( ViewShell* pNew )
    2275                 :            : {
    2276                 :       3688 :     pCurrentView = pNew;
    2277                 :       3688 : }
    2278                 :            : 
    2279                 :      73636 : SwLayouter* SwDoc::GetLayouter()
    2280                 :            : {
    2281                 :      73636 :     return pLayouter;
    2282                 :            : }
    2283                 :            : 
    2284                 :     870233 : const SwLayouter* SwDoc::GetLayouter() const
    2285                 :            : {
    2286                 :     870233 :     return pLayouter;
    2287                 :            : }
    2288                 :            : 
    2289                 :       1318 : void SwDoc::SetLayouter( SwLayouter* pNew )
    2290                 :            : {
    2291                 :       1318 :     pLayouter = pNew;
    2292                 :       1318 : }
    2293                 :            : 
    2294                 :     119432 : const ViewShell *SwDoc::GetCurrentViewShell() const
    2295                 :            : {
    2296                 :     119432 :     return pCurrentView;
    2297                 :            : }
    2298                 :            : 
    2299                 :     723984 : ViewShell *SwDoc::GetCurrentViewShell()
    2300                 :            : {
    2301                 :     723984 :     return pCurrentView;
    2302                 :            : }
    2303                 :            : 
    2304                 :            : //swmod 080219
    2305                 :            : // It must be able to communicate to a ViewShell. This is going to be removed later.
    2306                 :      59512 : const SwRootFrm *SwDoc::GetCurrentLayout() const
    2307                 :            : {
    2308         [ +  + ]:      59512 :     if(GetCurrentViewShell())
    2309                 :      59386 :         return GetCurrentViewShell()->GetLayout();
    2310                 :      59512 :     return 0;
    2311                 :            : }
    2312                 :            : 
    2313                 :     279659 : SwRootFrm *SwDoc::GetCurrentLayout()
    2314                 :            : {
    2315         [ +  + ]:     279659 :     if(GetCurrentViewShell())
    2316                 :     218529 :         return GetCurrentViewShell()->GetLayout();
    2317                 :     279659 :     return 0;
    2318                 :            : }
    2319                 :            : 
    2320                 :        993 : bool SwDoc::HasLayout() const
    2321                 :            : {
    2322                 :            :     // if there is a view, there is always a layout
    2323                 :        993 :     return (pCurrentView != 0);
    2324                 :            : }
    2325                 :            : 
    2326                 :       8769 : std::set<SwRootFrm*> SwDoc::GetAllLayouts()
    2327                 :            : {
    2328                 :       8769 :     std::set<SwRootFrm*> aAllLayouts;
    2329         [ +  - ]:       8769 :     ViewShell *pStart = GetCurrentViewShell();
    2330                 :       8769 :     ViewShell *pTemp = pStart;
    2331         [ +  - ]:       8769 :     if ( pTemp )
    2332                 :            :     {
    2333         [ -  + ]:       8769 :         do
    2334                 :            :         {
    2335 [ +  - ][ +  - ]:       8769 :             if (pTemp->GetLayout())
    2336                 :            :             {
    2337 [ +  - ][ +  - ]:       8769 :                 aAllLayouts.insert(pTemp->GetLayout());
    2338                 :       8769 :                 pTemp = (ViewShell*)pTemp->GetNext();
    2339                 :            :             }
    2340                 :            :         } while(pTemp!=pStart);
    2341                 :            :     }
    2342                 :            : 
    2343                 :       8769 :     return aAllLayouts;
    2344                 :            : }//swmod 070825
    2345                 :            : 
    2346                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10