LCOV - code coverage report
Current view: top level - sw/source/core/undo - untbl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 245 1573 15.6 %
Date: 2012-08-25 Functions: 35 128 27.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 203 2723 7.5 %

           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                 :            : #include <vector>
      30                 :            : 
      31                 :            : #include <boost/shared_ptr.hpp>
      32                 :            : 
      33                 :            : #include <UndoTable.hxx>
      34                 :            : #include <UndoRedline.hxx>
      35                 :            : #include <UndoDelete.hxx>
      36                 :            : #include <UndoSplitMove.hxx>
      37                 :            : #include <UndoCore.hxx>
      38                 :            : #include <hintids.hxx>
      39                 :            : #include <hints.hxx>
      40                 :            : #include <editeng/brkitem.hxx>
      41                 :            : #include <fmtornt.hxx>
      42                 :            : #include <fmtpdsc.hxx>
      43                 :            : #include <doc.hxx>
      44                 :            : #include <IDocumentUndoRedo.hxx>
      45                 :            : #include <editsh.hxx>
      46                 :            : #include <docary.hxx>
      47                 :            : #include <ndtxt.hxx>
      48                 :            : #include <swtable.hxx>
      49                 :            : #include <pam.hxx>
      50                 :            : #include <cntfrm.hxx>
      51                 :            : #include <tblsel.hxx>
      52                 :            : #include <swundo.hxx>
      53                 :            : #include <rolbck.hxx>
      54                 :            : #include <ddefld.hxx>
      55                 :            : #include <tabcol.hxx>
      56                 :            : #include <tabfrm.hxx>
      57                 :            : #include <rowfrm.hxx>
      58                 :            : #include <cellfrm.hxx>
      59                 :            : #include <swcache.hxx>
      60                 :            : #include <tblafmt.hxx>
      61                 :            : #include <poolfmt.hxx>
      62                 :            : #include <mvsave.hxx>
      63                 :            : #include <cellatr.hxx>
      64                 :            : #include <swtblfmt.hxx>
      65                 :            : #include <swddetbl.hxx>
      66                 :            : #include <redline.hxx>
      67                 :            : #include <node2lay.hxx>
      68                 :            : #include <tblrwcl.hxx>
      69                 :            : #include <fmtanchr.hxx>
      70                 :            : #include <comcore.hrc>
      71                 :            : #include <unochart.hxx>
      72                 :            : #include <switerator.hxx>
      73                 :            : 
      74                 :            : #ifdef DBG_UTIL
      75                 :            : #define CHECK_TABLE(t) (t).CheckConsistency();
      76                 :            : #else
      77                 :            : #define CHECK_TABLE(t)
      78                 :            : #endif
      79                 :            : 
      80                 :            : #ifdef DBG_UTIL
      81                 :            :     void lcl_DebugRedline( const SwDoc* pDoc ); // docredln.cxx
      82                 :            :     #define _DEBUG_REDLINE( pDoc ) lcl_DebugRedline( pDoc );
      83                 :            : #else
      84                 :            :     #define _DEBUG_REDLINE( pDoc )
      85                 :            : #endif
      86                 :            : 
      87                 :            : extern void ClearFEShellTabCols();
      88                 :            : 
      89                 :            : typedef std::vector<boost::shared_ptr<SfxItemSet> > SfxItemSets;
      90                 :            : 
      91                 :          2 : class SwUndoSaveSections : public boost::ptr_vector<SwUndoSaveSection> {
      92                 :            : public:
      93         [ +  - ]:          2 :     SwUndoSaveSections(size_type n) : boost::ptr_vector<SwUndoSaveSection>(n) {}
      94                 :            : };
      95                 :            : 
      96                 :          4 : class SwUndoMoves : public boost::ptr_vector<SwUndoMove> {};
      97                 :            : 
      98                 :            : struct SwTblToTxtSave;
      99                 :          0 : class SwTblToTxtSaves : public boost::ptr_vector<SwTblToTxtSave> {
     100                 :            : public:
     101         [ #  # ]:          0 :     SwTblToTxtSaves(size_type n) : boost::ptr_vector<SwTblToTxtSave>(n) {}
     102                 :            : };
     103                 :            : 
     104                 :            : struct _UndoTblCpyTbl_Entry
     105                 :            : {
     106                 :            :     sal_uLong nBoxIdx, nOffset;
     107                 :            :     SfxItemSet* pBoxNumAttr;
     108                 :            :     SwUndo* pUndo;
     109                 :            : 
     110                 :            :     // Was the last paragraph of the new and the first paragraph of the old content joined?
     111                 :            :     bool bJoin; // For redlining only
     112                 :            : 
     113                 :            :     _UndoTblCpyTbl_Entry( const SwTableBox& rBox );
     114                 :            :     ~_UndoTblCpyTbl_Entry();
     115                 :            : };
     116                 :          0 : class _UndoTblCpyTbl_Entries : public boost::ptr_vector<_UndoTblCpyTbl_Entry> {};
     117                 :            : 
     118                 :            : class _SaveBox;
     119                 :            : class _SaveLine;
     120                 :            : 
     121                 :            : class _SaveTable
     122                 :            : {
     123                 :            :     friend class _SaveBox;
     124                 :            :     friend class _SaveLine;
     125                 :            :     SfxItemSet aTblSet;
     126                 :            :     _SaveLine* pLine;
     127                 :            :     const SwTable* pSwTable;
     128                 :            :     SfxItemSets aSets;
     129                 :            :     SwFrmFmts aFrmFmts;
     130                 :            :     sal_uInt16 nLineCount;
     131                 :            :     sal_Bool bModifyBox : 1;
     132                 :            :     sal_Bool bSaveFormula : 1;
     133                 :            :     sal_Bool bNewModel : 1;
     134                 :            : 
     135                 :            : public:
     136                 :            :     _SaveTable( const SwTable& rTbl, sal_uInt16 nLnCnt = USHRT_MAX,
     137                 :            :                 sal_Bool bSaveFml = sal_True );
     138                 :            :     ~_SaveTable();
     139                 :            : 
     140                 :            :     sal_uInt16 AddFmt( SwFrmFmt* pFmt, bool bIsLine );
     141                 :            :     void NewFrmFmt( const SwTableLine* , const SwTableBox*, sal_uInt16 nFmtPos,
     142                 :            :                     SwFrmFmt* pOldFmt );
     143                 :            : 
     144                 :            :     void RestoreAttr( SwTable& rTbl, sal_Bool bModifyBox = sal_False );
     145                 :            :     void SaveCntntAttrs( SwDoc* pDoc );
     146                 :            :     void CreateNew( SwTable& rTbl, sal_Bool bCreateFrms = sal_True,
     147                 :            :                     sal_Bool bRestoreChart = sal_True );
     148                 :          0 :     sal_Bool IsNewModel() const { return bNewModel; }
     149                 :            : };
     150                 :            : 
     151                 :            : class _SaveLine
     152                 :            : {
     153                 :            :     friend class _SaveTable;
     154                 :            :     friend class _SaveBox;
     155                 :            : 
     156                 :            :     _SaveLine* pNext;
     157                 :            :     _SaveBox* pBox;
     158                 :            :     sal_uInt16 nItemSet;
     159                 :            : 
     160                 :            : public:
     161                 :            :     _SaveLine( _SaveLine* pPrev, const SwTableLine& rLine, _SaveTable& rSTbl );
     162                 :            :     ~_SaveLine();
     163                 :            : 
     164                 :            :     void RestoreAttr( SwTableLine& rLine, _SaveTable& rSTbl );
     165                 :            :     void SaveCntntAttrs( SwDoc* pDoc );
     166                 :            : 
     167                 :            :     void CreateNew( SwTable& rTbl, SwTableBox& rParent, _SaveTable& rSTbl  );
     168                 :            : };
     169                 :            : 
     170                 :            : class _SaveBox
     171                 :            : {
     172                 :            :     friend class _SaveLine;
     173                 :            : 
     174                 :            :     _SaveBox* pNext;
     175                 :            :     sal_uLong nSttNode;
     176                 :            :     long nRowSpan;
     177                 :            :     sal_uInt16 nItemSet;
     178                 :            :     union
     179                 :            :     {
     180                 :            :         SfxItemSets* pCntntAttrs;
     181                 :            :         _SaveLine* pLine;
     182                 :            :     } Ptrs;
     183                 :            : 
     184                 :            : public:
     185                 :            :     _SaveBox( _SaveBox* pPrev, const SwTableBox& rBox, _SaveTable& rSTbl );
     186                 :            :     ~_SaveBox();
     187                 :            : 
     188                 :            :     void RestoreAttr( SwTableBox& rBox, _SaveTable& rSTbl );
     189                 :            :     void SaveCntntAttrs( SwDoc* pDoc );
     190                 :            : 
     191                 :            :     void CreateNew( SwTable& rTbl, SwTableLine& rParent, _SaveTable& rSTbl );
     192                 :            : };
     193                 :            : 
     194                 :            : void InsertSort( std::vector<sal_uInt16>& rArr, sal_uInt16 nIdx, sal_uInt16* pInsPos = 0 );
     195                 :            : 
     196                 :            : #if OSL_DEBUG_LEVEL > 0
     197                 :            : #include "shellio.hxx"
     198                 :            : void CheckTable( const SwTable& );
     199                 :            : #define CHECKTABLE(t) CheckTable( t );
     200                 :            : #else
     201                 :            : #define CHECKTABLE(t)
     202                 :            : #endif
     203                 :            : 
     204                 :            : /* #130880: Crash in undo of table to text when the table has (freshly) merged cells
     205                 :            : The order of cell content nodes in the nodes array is not given by the recursive table structure.
     206                 :            : The algorithmn must not rely on this even it holds for a fresh loaded table in odt file format.
     207                 :            : So we need to remember not only the start node position but the end node position as well.
     208                 :            : */
     209                 :            : 
     210                 :            : struct SwTblToTxtSave
     211                 :            : {
     212                 :            :     sal_uLong m_nSttNd;
     213                 :            :     sal_uLong m_nEndNd;
     214                 :            :     xub_StrLen m_nCntnt;
     215                 :            :     SwHistory* m_pHstry;
     216                 :            :     // metadata references for first and last paragraph in cell
     217                 :            :     ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoStart;
     218                 :            :     ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoEnd;
     219                 :            : 
     220                 :            :     SwTblToTxtSave( SwDoc& rDoc, sal_uLong nNd, sal_uLong nEndIdx, xub_StrLen nCntnt );
     221 [ #  # ][ #  # ]:          0 :     ~SwTblToTxtSave() { delete m_pHstry; }
                 [ #  # ]
     222                 :            : };
     223                 :            : 
     224                 :            : sal_uInt16 aSave_BoxCntntSet[] = {
     225                 :            :     RES_CHRATR_COLOR, RES_CHRATR_CROSSEDOUT,
     226                 :            :     RES_CHRATR_FONT, RES_CHRATR_FONTSIZE,
     227                 :            :     RES_CHRATR_POSTURE, RES_CHRATR_POSTURE,
     228                 :            :     RES_CHRATR_SHADOWED, RES_CHRATR_WEIGHT,
     229                 :            :     RES_PARATR_ADJUST, RES_PARATR_ADJUST,
     230                 :            :     0 };
     231                 :            : 
     232                 :         64 : SwUndoInsTbl::SwUndoInsTbl( const SwPosition& rPos, sal_uInt16 nCl, sal_uInt16 nRw,
     233                 :            :                             sal_uInt16 nAdj, const SwInsertTableOptions& rInsTblOpts,
     234                 :            :                             const SwTableAutoFmt* pTAFmt,
     235                 :            :                             const std::vector<sal_uInt16> *pColArr,
     236                 :            :                             const String & rName)
     237                 :            :     : SwUndo( UNDO_INSTABLE ),
     238                 :            :     aInsTblOpts( rInsTblOpts ), pDDEFldType( 0 ), pColWidth( 0 ), pRedlData( 0 ), pAutoFmt( 0 ),
     239         [ +  - ]:         64 :     nSttNode( rPos.nNode.GetIndex() ), nRows( nRw ), nCols( nCl ), nAdjust( nAdj )
     240                 :            : {
     241         [ -  + ]:         64 :     if( pColArr )
     242                 :            :     {
     243 [ #  # ][ #  # ]:          0 :         pColWidth = new std::vector<sal_uInt16>(*pColArr);
     244                 :            :     }
     245         [ -  + ]:         64 :     if( pTAFmt )
     246 [ #  # ][ #  # ]:          0 :         pAutoFmt = new SwTableAutoFmt( *pTAFmt );
     247                 :            : 
     248                 :            :     // consider redline
     249                 :         64 :     SwDoc& rDoc = *rPos.nNode.GetNode().GetDoc();
     250 [ -  + ][ +  - ]:         64 :     if( rDoc.IsRedlineOn() )
     251                 :            :     {
     252 [ #  # ][ #  # ]:          0 :         pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, rDoc.GetRedlineAuthor() );
                 [ #  # ]
     253         [ #  # ]:          0 :         SetRedlineMode( rDoc.GetRedlineMode() );
     254                 :            :     }
     255                 :            : 
     256         [ +  - ]:         64 :     sTblNm = rName;
     257                 :         64 : }
     258                 :            : 
     259         [ +  - ]:         64 : SwUndoInsTbl::~SwUndoInsTbl()
     260                 :            : {
     261 [ -  + ][ #  # ]:         64 :     delete pDDEFldType;
     262         [ -  + ]:         64 :     delete pColWidth;
     263 [ -  + ][ #  # ]:         64 :     delete pRedlData;
     264 [ -  + ][ #  # ]:         64 :     delete pAutoFmt;
     265         [ -  + ]:        128 : }
     266                 :            : 
     267                 :          2 : void SwUndoInsTbl::UndoImpl(::sw::UndoRedoContext & rContext)
     268                 :            : {
     269                 :          2 :     SwDoc & rDoc = rContext.GetDoc();
     270 [ +  - ][ +  - ]:          2 :     SwNodeIndex aIdx( rDoc.GetNodes(), nSttNode );
     271                 :            : 
     272                 :          2 :     SwTableNode* pTblNd = aIdx.GetNode().GetTableNode();
     273                 :            :     OSL_ENSURE( pTblNd, "no TableNode" );
     274         [ +  - ]:          2 :     pTblNd->DelFrms();
     275                 :            : 
     276         [ -  + ]:          2 :     if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     277         [ #  # ]:          0 :         rDoc.DeleteRedline( *pTblNd, true, USHRT_MAX );
     278         [ +  - ]:          2 :     RemoveIdxFromSection( rDoc, nSttNode );
     279                 :            : 
     280                 :            :     // move hard page breaks into next node
     281 [ +  - ][ +  - ]:          2 :     SwCntntNode* pNextNd = rDoc.GetNodes()[ pTblNd->EndOfSectionIndex()+1 ]->GetCntntNode();
     282         [ +  - ]:          2 :     if( pNextNd )
     283                 :            :     {
     284                 :          2 :         SwFrmFmt* pTableFmt = pTblNd->GetTable().GetFrmFmt();
     285                 :            :         const SfxPoolItem *pItem;
     286                 :            : 
     287         [ -  + ]:          2 :         if( SFX_ITEM_SET == pTableFmt->GetItemState( RES_PAGEDESC,
     288         [ +  - ]:          2 :             sal_False, &pItem ) )
     289         [ #  # ]:          0 :             pNextNd->SetAttr( *pItem );
     290                 :            : 
     291         [ -  + ]:          2 :         if( SFX_ITEM_SET == pTableFmt->GetItemState( RES_BREAK,
     292         [ +  - ]:          2 :             sal_False, &pItem ) )
     293         [ #  # ]:          2 :             pNextNd->SetAttr( *pItem );
     294                 :            :     }
     295                 :            : 
     296                 :            : 
     297         [ +  - ]:          2 :     sTblNm = pTblNd->GetTable().GetFrmFmt()->GetName();
     298 [ +  - ][ +  - ]:          2 :     if( pTblNd->GetTable().IsA( TYPE( SwDDETable )) )
                 [ -  + ]
     299                 :          0 :         pDDEFldType = (SwDDEFieldType*)((SwDDETable&)pTblNd->GetTable()).
     300 [ #  # ][ #  # ]:          0 :                                         GetDDEFldType()->Copy();
     301                 :            : 
     302         [ +  - ]:          4 :     rDoc.GetNodes().Delete( aIdx, pTblNd->EndOfSectionIndex() -
     303         [ +  - ]:          4 :                                 aIdx.GetIndex() + 1 );
     304                 :            : 
     305         [ +  - ]:          2 :     SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
     306         [ +  - ]:          2 :     rPam.DeleteMark();
     307         [ +  - ]:          2 :     rPam.GetPoint()->nNode = aIdx;
     308 [ +  - ][ +  - ]:          2 :     rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
                 [ +  - ]
     309                 :          2 : }
     310                 :            : 
     311                 :          0 : void SwUndoInsTbl::RedoImpl(::sw::UndoRedoContext & rContext)
     312                 :            : {
     313                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     314                 :            : 
     315 [ #  # ][ #  # ]:          0 :     SwPosition const aPos(SwNodeIndex(rDoc.GetNodes(), nSttNode));
         [ #  # ][ #  # ]
     316                 :            :     const SwTable* pTbl = rDoc.InsertTable( aInsTblOpts, aPos, nRows, nCols,
     317                 :            :                                             nAdjust,
     318         [ #  # ]:          0 :                                             pAutoFmt, pColWidth );
     319         [ #  # ]:          0 :     ((SwFrmFmt*)pTbl->GetFrmFmt())->SetName( sTblNm );
     320 [ #  # ][ #  # ]:          0 :     SwTableNode* pTblNode = (SwTableNode*)rDoc.GetNodes()[nSttNode]->GetTableNode();
     321                 :            : 
     322         [ #  # ]:          0 :     if( pDDEFldType )
     323                 :            :     {
     324                 :            :         SwDDEFieldType* pNewType = (SwDDEFieldType*)rDoc.InsertFldType(
     325         [ #  # ]:          0 :                                                             *pDDEFldType);
     326 [ #  # ][ #  # ]:          0 :         SwDDETable* pDDETbl = new SwDDETable( pTblNode->GetTable(), pNewType );
     327         [ #  # ]:          0 :         pTblNode->SetNewTable( pDDETbl );
     328 [ #  # ][ #  # ]:          0 :         delete pDDEFldType, pDDEFldType = 0;
     329                 :            :     }
     330                 :            : 
     331 [ #  # ][ #  #  :          0 :     if( (pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
             #  #  #  # ]
                 [ #  # ]
     332                 :          0 :         ( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
     333         [ #  # ]:          0 :             !rDoc.GetRedlineTbl().empty() ))
     334                 :            :     {
     335         [ #  # ]:          0 :         SwPaM aPam( *pTblNode->EndOfSectionNode(), *pTblNode, 1 );
     336                 :          0 :         SwCntntNode* pCNd = aPam.GetCntntNode( sal_False );
     337         [ #  # ]:          0 :         if( pCNd )
     338 [ #  # ][ #  # ]:          0 :             aPam.GetMark()->nContent.Assign( pCNd, 0 );
     339                 :            : 
     340 [ #  # ][ #  # ]:          0 :         if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ) )
                 [ #  # ]
     341                 :            :         {
     342         [ #  # ]:          0 :             RedlineMode_t eOld = rDoc.GetRedlineMode();
     343         [ #  # ]:          0 :             rDoc.SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
     344                 :            : 
     345 [ #  # ][ #  # ]:          0 :             rDoc.AppendRedline( new SwRedline( *pRedlData, aPam ), true);
                 [ #  # ]
     346         [ #  # ]:          0 :             rDoc.SetRedlineMode_intern( eOld );
     347                 :            :         }
     348                 :            :         else
     349 [ #  # ][ #  # ]:          0 :             rDoc.SplitRedline( aPam );
     350         [ #  # ]:          0 :     }
     351                 :          0 : }
     352                 :            : 
     353                 :          0 : void SwUndoInsTbl::RepeatImpl(::sw::RepeatContext & rContext)
     354                 :            : {
     355                 :          0 :     rContext.GetDoc().InsertTable(
     356                 :          0 :             aInsTblOpts, *rContext.GetRepeatPaM().GetPoint(),
     357                 :          0 :             nRows, nCols, nAdjust, pAutoFmt, pColWidth );
     358                 :          0 : }
     359                 :            : 
     360                 :         64 : SwRewriter SwUndoInsTbl::GetRewriter() const
     361                 :            : {
     362                 :         64 :     SwRewriter aRewriter;
     363                 :            : 
     364 [ +  - ][ +  - ]:         64 :     aRewriter.AddRule(UndoArg1, SW_RES(STR_START_QUOTE));
                 [ +  - ]
     365         [ +  - ]:         64 :     aRewriter.AddRule(UndoArg2, sTblNm);
     366 [ +  - ][ +  - ]:         64 :     aRewriter.AddRule(UndoArg3, SW_RES(STR_END_QUOTE));
                 [ +  - ]
     367                 :            : 
     368                 :         64 :     return aRewriter;
     369                 :            : }
     370                 :            : 
     371                 :          0 : SwTblToTxtSave::SwTblToTxtSave( SwDoc& rDoc, sal_uLong nNd, sal_uLong nEndIdx, xub_StrLen nCnt )
     372         [ #  # ]:          0 :     : m_nSttNd( nNd ), m_nEndNd( nEndIdx), m_nCntnt( nCnt ), m_pHstry( 0 )
     373                 :            : {
     374                 :            :     // keep attributes of the joined node
     375 [ #  # ][ #  # ]:          0 :     SwTxtNode* pNd = rDoc.GetNodes()[ nNd ]->GetTxtNode();
     376         [ #  # ]:          0 :     if( pNd )
     377                 :            :     {
     378 [ #  # ][ #  # ]:          0 :         m_pHstry = new SwHistory;
     379                 :            : 
     380         [ #  # ]:          0 :         m_pHstry->Add( pNd->GetTxtColl(), nNd, ND_TEXTNODE );
     381         [ #  # ]:          0 :         if ( pNd->GetpSwpHints() )
     382                 :            :         {
     383                 :            :             m_pHstry->CopyAttr( pNd->GetpSwpHints(), nNd, 0,
     384         [ #  # ]:          0 :                         pNd->GetTxt().Len(), false );
     385                 :            :         }
     386 [ #  # ][ #  # ]:          0 :         if( pNd->HasSwAttrSet() )
     387 [ #  # ][ #  # ]:          0 :             m_pHstry->CopyFmtAttr( *pNd->GetpSwAttrSet(), nNd );
     388                 :            : 
     389         [ #  # ]:          0 :         if( !m_pHstry->Count() )
     390 [ #  # ][ #  # ]:          0 :             delete m_pHstry, m_pHstry = 0;
     391                 :            : 
     392                 :            :         // METADATA: store
     393 [ #  # ][ #  # ]:          0 :         m_pMetadataUndoStart = pNd->CreateUndo();
                 [ #  # ]
     394                 :            :     }
     395                 :            : 
     396                 :            :     // we also need to store the metadata reference of the _last_ paragraph
     397                 :            :     // we subtract 1 to account for the removed cell start/end node pair
     398                 :            :     // (after SectionUp, the end of the range points to the node after the cell)
     399         [ #  # ]:          0 :     if ( nEndIdx - 1 > nNd )
     400                 :            :     {
     401 [ #  # ][ #  # ]:          0 :         SwTxtNode* pLastNode( rDoc.GetNodes()[ nEndIdx - 1 ]->GetTxtNode() );
     402         [ #  # ]:          0 :         if( pLastNode )
     403                 :            :         {
     404                 :            :             // METADATA: store
     405 [ #  # ][ #  # ]:          0 :             m_pMetadataUndoEnd = pLastNode->CreateUndo();
                 [ #  # ]
     406                 :            :         }
     407                 :            :     }
     408                 :          0 : }
     409                 :            : 
     410                 :          0 : SwUndoTblToTxt::SwUndoTblToTxt( const SwTable& rTbl, sal_Unicode cCh )
     411                 :            :     : SwUndo( UNDO_TABLETOTEXT ),
     412                 :          0 :     sTblNm( rTbl.GetFrmFmt()->GetName() ), pDDEFldType( 0 ), pHistory( 0 ),
     413                 :            :     nSttNd( 0 ), nEndNd( 0 ),
     414         [ #  # ]:          0 :     nAdjust( static_cast<sal_uInt16>(rTbl.GetFrmFmt()->GetHoriOrient().GetHoriOrient()) ),
     415   [ #  #  #  # ]:          0 :     cTrenner( cCh ), nHdlnRpt( rTbl.GetRowsToRepeat() )
     416                 :            : {
     417 [ #  # ][ #  # ]:          0 :     pTblSave = new _SaveTable( rTbl );
     418 [ #  # ][ #  # ]:          0 :     pBoxSaves = new SwTblToTxtSaves( (SwTblToTxtSaves::size_type)rTbl.GetTabSortBoxes().size() );
     419                 :            : 
     420 [ #  # ][ #  # ]:          0 :     if( rTbl.IsA( TYPE( SwDDETable ) ) )
                 [ #  # ]
     421 [ #  # ][ #  # ]:          0 :         pDDEFldType = (SwDDEFieldType*)((SwDDETable&)rTbl).GetDDEFldType()->Copy();
     422                 :            : 
     423         [ #  # ]:          0 :     bCheckNumFmt = rTbl.GetFrmFmt()->GetDoc()->IsInsTblFormatNum();
     424                 :            : 
     425 [ #  # ][ #  # ]:          0 :     pHistory = new SwHistory;
     426         [ #  # ]:          0 :     const SwTableNode* pTblNd = rTbl.GetTableNode();
     427                 :          0 :     sal_uLong nTblStt = pTblNd->GetIndex(), nTblEnd = pTblNd->EndOfSectionIndex();
     428                 :            : 
     429                 :          0 :     const SwFrmFmts& rFrmFmtTbl = *pTblNd->GetDoc()->GetSpzFrmFmts();
     430         [ #  # ]:          0 :     for( sal_uInt16 n = 0; n < rFrmFmtTbl.size(); ++n )
     431                 :            :     {
     432                 :          0 :         SwFrmFmt* pFmt = rFrmFmtTbl[ n ];
     433         [ #  # ]:          0 :         SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
     434         [ #  # ]:          0 :         SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
     435   [ #  #  #  #  :          0 :         if (pAPos &&
          #  #  #  #  #  
              # ][ #  # ]
     436                 :          0 :             ((FLY_AT_CHAR == pAnchor->GetAnchorId()) ||
     437                 :          0 :              (FLY_AT_PARA == pAnchor->GetAnchorId())) &&
     438                 :          0 :             nTblStt <= pAPos->nNode.GetIndex() &&
     439                 :          0 :             pAPos->nNode.GetIndex() < nTblEnd )
     440                 :            :         {
     441         [ #  # ]:          0 :             pHistory->Add( *pFmt );
     442                 :            :         }
     443                 :            :     }
     444                 :            : 
     445         [ #  # ]:          0 :     if( !pHistory->Count() )
     446 [ #  # ][ #  # ]:          0 :         delete pHistory, pHistory = 0;
     447                 :          0 : }
     448                 :            : 
     449         [ #  # ]:          0 : SwUndoTblToTxt::~SwUndoTblToTxt()
     450                 :            : {
     451 [ #  # ][ #  # ]:          0 :     delete pDDEFldType;
     452 [ #  # ][ #  # ]:          0 :     delete pTblSave;
     453 [ #  # ][ #  # ]:          0 :     delete pBoxSaves;
     454 [ #  # ][ #  # ]:          0 :     delete pHistory;
     455         [ #  # ]:          0 : }
     456                 :            : 
     457                 :          0 : void SwUndoTblToTxt::UndoImpl(::sw::UndoRedoContext & rContext)
     458                 :            : {
     459                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     460         [ #  # ]:          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
     461                 :            : 
     462 [ #  # ][ #  # ]:          0 :     SwNodeIndex aFrmIdx( rDoc.GetNodes(), nSttNd );
     463 [ #  # ][ #  # ]:          0 :     SwNodeIndex aEndIdx( rDoc.GetNodes(), nEndNd );
     464                 :            : 
     465         [ #  # ]:          0 :     pPam->GetPoint()->nNode = aFrmIdx;
     466         [ #  # ]:          0 :     pPam->SetMark();
     467         [ #  # ]:          0 :     pPam->GetPoint()->nNode = aEndIdx;
     468         [ #  # ]:          0 :     rDoc.DelNumRules( *pPam );
     469         [ #  # ]:          0 :     pPam->DeleteMark();
     470                 :            : 
     471                 :            :     // now collect all Uppers
     472         [ #  # ]:          0 :     SwNode2Layout aNode2Layout( aFrmIdx.GetNode() );
     473                 :            : 
     474                 :            :     // create TableNode structure
     475 [ #  # ][ #  # ]:          0 :     SwTableNode* pTblNd = rDoc.GetNodes().UndoTableToText( nSttNd, nEndNd, *pBoxSaves );
     476                 :          0 :     pTblNd->GetTable().SetTableModel( pTblSave->IsNewModel() );
     477         [ #  # ]:          0 :     SwTableFmt* pTableFmt = rDoc.MakeTblFrmFmt( sTblNm, rDoc.GetDfltFrmFmt() );
     478         [ #  # ]:          0 :     pTblNd->GetTable().RegisterToFormat( *pTableFmt );
     479                 :          0 :     pTblNd->GetTable().SetRowsToRepeat( nHdlnRpt );
     480                 :            : 
     481                 :            :     // create old table structure
     482         [ #  # ]:          0 :     pTblSave->CreateNew( pTblNd->GetTable() );
     483                 :            : 
     484         [ #  # ]:          0 :     if( pDDEFldType )
     485                 :            :     {
     486                 :            :         SwDDEFieldType* pNewType = (SwDDEFieldType*)rDoc.InsertFldType(
     487         [ #  # ]:          0 :                                                             *pDDEFldType);
     488 [ #  # ][ #  # ]:          0 :         SwDDETable* pDDETbl = new SwDDETable( pTblNd->GetTable(), pNewType );
     489         [ #  # ]:          0 :         pTblNd->SetNewTable( pDDETbl, sal_False );
     490 [ #  # ][ #  # ]:          0 :         delete pDDEFldType, pDDEFldType = 0;
     491                 :            :     }
     492                 :            : 
     493         [ #  # ]:          0 :     if( bCheckNumFmt )
     494                 :            :     {
     495                 :          0 :         SwTableSortBoxes& rBxs = pTblNd->GetTable().GetTabSortBoxes();
     496         [ #  # ]:          0 :         for( sal_uInt16 nBoxes = rBxs.size(); nBoxes; )
     497         [ #  # ]:          0 :             rDoc.ChkBoxNumFmt( *rBxs[ --nBoxes ], sal_False );
     498                 :            :     }
     499                 :            : 
     500         [ #  # ]:          0 :     if( pHistory )
     501                 :            :     {
     502                 :          0 :         sal_uInt16 nTmpEnd = pHistory->GetTmpEnd();
     503         [ #  # ]:          0 :         pHistory->TmpRollback( &rDoc, 0 );
     504         [ #  # ]:          0 :         pHistory->SetTmpEnd( nTmpEnd );
     505                 :            :     }
     506                 :            : 
     507         [ #  # ]:          0 :     aNode2Layout.RestoreUpperFrms( rDoc.GetNodes(),
     508         [ #  # ]:          0 :                                    pTblNd->GetIndex(), pTblNd->GetIndex()+1 );
     509                 :            : 
     510                 :            :     // Is a table selection requested?
     511         [ #  # ]:          0 :     pPam->DeleteMark();
     512         [ #  # ]:          0 :     pPam->GetPoint()->nNode = *pTblNd->EndOfSectionNode();
     513         [ #  # ]:          0 :     pPam->SetMark();
     514         [ #  # ]:          0 :     pPam->GetPoint()->nNode = *pPam->GetNode()->StartOfSectionNode();
     515         [ #  # ]:          0 :     pPam->Move( fnMoveForward, fnGoCntnt );
     516                 :          0 :     pPam->Exchange();
     517         [ #  # ]:          0 :     pPam->Move( fnMoveBackward, fnGoCntnt );
     518                 :            : 
     519 [ #  # ][ #  # ]:          0 :     ClearFEShellTabCols();
         [ #  # ][ #  # ]
     520                 :          0 : }
     521                 :            : 
     522                 :            : // located in untbl.cxx and only an Undo object is allowed to call it
     523                 :          0 : SwTableNode* SwNodes::UndoTableToText( sal_uLong nSttNd, sal_uLong nEndNd,
     524                 :            :                                 const SwTblToTxtSaves& rSavedData )
     525                 :            : {
     526         [ #  # ]:          0 :     SwNodeIndex aSttIdx( *this, nSttNd );
     527         [ #  # ]:          0 :     SwNodeIndex aEndIdx( *this, nEndNd+1 );
     528                 :            : 
     529 [ #  # ][ #  # ]:          0 :     SwTableNode * pTblNd = new SwTableNode( aSttIdx );
     530 [ #  # ][ #  # ]:          0 :     SwEndNode* pEndNd = new SwEndNode( aEndIdx, *pTblNd  );
     531                 :            : 
     532         [ #  # ]:          0 :     aEndIdx = *pEndNd;
     533                 :            : 
     534                 :            :     /* Set pTblNd as start of section for all nodes in [nSttNd, nEndNd].
     535                 :            :        Delete all Frames attached to the nodes in that range. */
     536                 :            :     SwNode* pNd;
     537                 :            :     {
     538                 :          0 :         sal_uLong n, nTmpEnd = aEndIdx.GetIndex();
     539         [ #  # ]:          0 :         for( n = pTblNd->GetIndex() + 1; n < nTmpEnd; ++n )
     540                 :            :         {
     541 [ #  # ][ #  # ]:          0 :             if( ( pNd = (*this)[ n ] )->IsCntntNode() )
     542 [ #  # ][ #  # ]:          0 :                 ((SwCntntNode*)pNd)->DelFrms();
     543                 :          0 :             pNd->pStartOfSection = pTblNd;
     544                 :            :         }
     545                 :            :     }
     546                 :            : 
     547                 :            :     // than create table structure partially. First a single line that contains
     548                 :            :     // all boxes. The correct structure is than taken from SaveStruct.
     549         [ #  # ]:          0 :     SwTableBoxFmt* pBoxFmt = GetDoc()->MakeTableBoxFmt();
     550         [ #  # ]:          0 :     SwTableLineFmt* pLineFmt = GetDoc()->MakeTableLineFmt();
     551 [ #  # ][ #  # ]:          0 :     SwTableLine* pLine = new SwTableLine( pLineFmt, rSavedData.size(), 0 );
     552         [ #  # ]:          0 :     pTblNd->GetTable().GetTabLines().insert( pTblNd->GetTable().GetTabLines().begin(), pLine );
     553                 :            : 
     554         [ #  # ]:          0 :     std::vector<sal_uLong> aBkmkArr;
     555         [ #  # ]:          0 :     for( sal_uInt16 n = rSavedData.size(); n; )
     556                 :            :     {
     557         [ #  # ]:          0 :         const SwTblToTxtSave* pSave = &rSavedData[ --n ];
     558                 :            :         // if the start node was merged with last from prev. cell,
     559                 :            :         // subtract 1 from index to get the merged paragraph, and split that
     560 [ #  # ][ #  # ]:          0 :         aSttIdx = pSave->m_nSttNd - ( ( USHRT_MAX != pSave->m_nCntnt ) ? 1 : 0);
     561                 :          0 :         SwTxtNode* pTxtNd = aSttIdx.GetNode().GetTxtNode();
     562                 :            : 
     563         [ #  # ]:          0 :         if( USHRT_MAX != pSave->m_nCntnt )
     564                 :            :         {
     565                 :            :             // split at ContentPosition, delete previous char (= seperator)
     566                 :            :             OSL_ENSURE( pTxtNd, "Where is my TextNode?" );
     567 [ #  # ][ #  # ]:          0 :             SwIndex aCntPos( pTxtNd, pSave->m_nCntnt - 1 );
     568                 :            : 
     569         [ #  # ]:          0 :             pTxtNd->EraseText( aCntPos, 1 );
     570                 :            :             SwCntntNode* pNewNd = pTxtNd->SplitCntntNode(
     571 [ #  # ][ #  # ]:          0 :                                         SwPosition( aSttIdx, aCntPos ));
                 [ #  # ]
     572         [ #  # ]:          0 :             if( !aBkmkArr.empty() )
     573                 :            :                 _RestoreCntntIdx( aBkmkArr, *pNewNd, pSave->m_nCntnt,
     574 [ #  # ][ #  # ]:          0 :                                                      pSave->m_nCntnt + 1 );
     575                 :            :         }
     576                 :            :         else
     577                 :            :         {
     578                 :          0 :             aBkmkArr.clear();
     579         [ #  # ]:          0 :             if( pTxtNd )
     580                 :            :                 _SaveCntntIdx( GetDoc(), aSttIdx.GetIndex(),
     581         [ #  # ]:          0 :                                 pTxtNd->GetTxt().Len(), aBkmkArr );
     582                 :            :         }
     583                 :            : 
     584         [ #  # ]:          0 :         if( pTxtNd )
     585                 :            :         {
     586                 :            :             // METADATA: restore
     587         [ #  # ]:          0 :             pTxtNd->GetTxtNode()->RestoreMetadata(pSave->m_pMetadataUndoStart);
     588 [ #  # ][ #  # ]:          0 :             if( pTxtNd->HasSwAttrSet() )
     589         [ #  # ]:          0 :                 pTxtNd->ResetAllAttr();
     590                 :            : 
     591         [ #  # ]:          0 :             if( pTxtNd->GetpSwpHints() )
     592         [ #  # ]:          0 :                 pTxtNd->ClearSwpHintsArr( false );
     593                 :            :         }
     594                 :            : 
     595         [ #  # ]:          0 :         if( pSave->m_pHstry )
     596                 :            :         {
     597                 :          0 :             sal_uInt16 nTmpEnd = pSave->m_pHstry->GetTmpEnd();
     598         [ #  # ]:          0 :             pSave->m_pHstry->TmpRollback( GetDoc(), 0 );
     599         [ #  # ]:          0 :             pSave->m_pHstry->SetTmpEnd( nTmpEnd );
     600                 :            :         }
     601                 :            : 
     602                 :            :         // METADATA: restore
     603                 :            :         // end points to node after cell
     604         [ #  # ]:          0 :         if ( pSave->m_nEndNd - 1 > pSave->m_nSttNd )
     605                 :            :         {
     606         [ #  # ]:          0 :             SwTxtNode* pLastNode = (*this)[ pSave->m_nEndNd - 1 ]->GetTxtNode();
     607         [ #  # ]:          0 :             if (pLastNode)
     608                 :            :             {
     609         [ #  # ]:          0 :                 pLastNode->RestoreMetadata(pSave->m_pMetadataUndoEnd);
     610                 :            :             }
     611                 :            :         }
     612                 :            : 
     613         [ #  # ]:          0 :         aEndIdx = pSave->m_nEndNd;
     614                 :            :         SwStartNode* pSttNd = new SwStartNode( aSttIdx, ND_STARTNODE,
     615 [ #  # ][ #  # ]:          0 :                                                 SwTableBoxStartNode );
     616                 :          0 :         pSttNd->pStartOfSection = pTblNd;
     617 [ #  # ][ #  # ]:          0 :         new SwEndNode( aEndIdx, *pSttNd );
     618                 :            : 
     619         [ #  # ]:          0 :         for( sal_uLong i = aSttIdx.GetIndex(); i < aEndIdx.GetIndex()-1; ++i )
     620                 :            :         {
     621         [ #  # ]:          0 :             pNd = (*this)[ i ];
     622                 :          0 :             pNd->pStartOfSection = pSttNd;
     623         [ #  # ]:          0 :             if( pNd->IsStartNode() )
     624                 :          0 :                 i = pNd->EndOfSectionIndex();
     625                 :            :         }
     626                 :            : 
     627 [ #  # ][ #  # ]:          0 :         SwTableBox* pBox = new SwTableBox( pBoxFmt, *pSttNd, pLine );
     628         [ #  # ]:          0 :         pLine->GetTabBoxes().insert( pLine->GetTabBoxes().begin(), pBox );
     629                 :            :     }
     630 [ #  # ][ #  # ]:          0 :     return pTblNd;
     631                 :            : }
     632                 :            : 
     633                 :          0 : void SwUndoTblToTxt::RedoImpl(::sw::UndoRedoContext & rContext)
     634                 :            : {
     635                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     636         [ #  # ]:          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
     637                 :            : 
     638         [ #  # ]:          0 :     pPam->GetPoint()->nNode = nSttNd;
     639         [ #  # ]:          0 :     pPam->GetPoint()->nContent.Assign( 0, 0 );
     640         [ #  # ]:          0 :     SwNodeIndex aSaveIdx( pPam->GetPoint()->nNode, -1 );
     641                 :            : 
     642         [ #  # ]:          0 :     pPam->SetMark();            // log off all indices
     643         [ #  # ]:          0 :     pPam->DeleteMark();
     644                 :            : 
     645                 :          0 :     SwTableNode* pTblNd = pPam->GetNode()->GetTableNode();
     646                 :            :     OSL_ENSURE( pTblNd, "Could not find any TableNode" );
     647                 :            : 
     648 [ #  # ][ #  # ]:          0 :     if( pTblNd->GetTable().IsA( TYPE( SwDDETable )) )
                 [ #  # ]
     649                 :          0 :         pDDEFldType = (SwDDEFieldType*)((SwDDETable&)pTblNd->GetTable()).
     650 [ #  # ][ #  # ]:          0 :                                                 GetDDEFldType()->Copy();
     651                 :            : 
     652         [ #  # ]:          0 :     rDoc.TableToText( pTblNd, cTrenner );
     653                 :            : 
     654         [ #  # ]:          0 :     aSaveIdx++;
     655                 :          0 :     SwCntntNode* pCNd = aSaveIdx.GetNode().GetCntntNode();
     656 [ #  # ][ #  # ]:          0 :     if( !pCNd && 0 == ( pCNd = rDoc.GetNodes().GoNext( &aSaveIdx ) ) &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     657         [ #  # ]:          0 :         0 == ( pCNd = rDoc.GetNodes().GoPrevious( &aSaveIdx )) )
     658                 :            :     {
     659                 :            :         OSL_FAIL( "Where is the TextNode now?" );
     660                 :            :     }
     661                 :            : 
     662         [ #  # ]:          0 :     pPam->GetPoint()->nNode = aSaveIdx;
     663 [ #  # ][ #  # ]:          0 :     pPam->GetPoint()->nContent.Assign( pCNd, 0 );
     664                 :            : 
     665         [ #  # ]:          0 :     pPam->SetMark();            // log off all indices
     666 [ #  # ][ #  # ]:          0 :     pPam->DeleteMark();
     667                 :          0 : }
     668                 :            : 
     669                 :          0 : void SwUndoTblToTxt::RepeatImpl(::sw::RepeatContext & rContext)
     670                 :            : {
     671                 :          0 :     SwPaM *const pPam = & rContext.GetRepeatPaM();
     672                 :          0 :     SwTableNode *const pTblNd = pPam->GetNode()->FindTableNode();
     673         [ #  # ]:          0 :     if( pTblNd )
     674                 :            :     {
     675                 :            :         // move cursor out of table
     676                 :          0 :         pPam->GetPoint()->nNode = *pTblNd->EndOfSectionNode();
     677                 :          0 :         pPam->Move( fnMoveForward, fnGoCntnt );
     678                 :          0 :         pPam->SetMark();
     679                 :          0 :         pPam->DeleteMark();
     680                 :            : 
     681                 :          0 :         rContext.GetDoc().TableToText( pTblNd, cTrenner );
     682                 :            :     }
     683                 :          0 : }
     684                 :            : 
     685                 :          0 : void SwUndoTblToTxt::SetRange( const SwNodeRange& rRg )
     686                 :            : {
     687                 :          0 :     nSttNd = rRg.aStart.GetIndex();
     688                 :          0 :     nEndNd = rRg.aEnd.GetIndex();
     689                 :          0 : }
     690                 :            : 
     691                 :          0 : void SwUndoTblToTxt::AddBoxPos( SwDoc& rDoc, sal_uLong nNdIdx, sal_uLong nEndIdx, xub_StrLen nCntntIdx )
     692                 :            : {
     693         [ #  # ]:          0 :     SwTblToTxtSave* pNew = new SwTblToTxtSave( rDoc, nNdIdx, nEndIdx, nCntntIdx );
     694                 :          0 :     pBoxSaves->push_back( pNew );
     695                 :          0 : }
     696                 :            : 
     697                 :          0 : SwUndoTxtToTbl::SwUndoTxtToTbl( const SwPaM& rRg,
     698                 :            :                                 const SwInsertTableOptions& rInsTblOpts,
     699                 :            :                                 sal_Unicode cCh, sal_uInt16 nAdj,
     700                 :            :                                 const SwTableAutoFmt* pAFmt )
     701                 :            :     : SwUndo( UNDO_TEXTTOTABLE ), SwUndRng( rRg ), aInsTblOpts( rInsTblOpts ),
     702                 :            :       pDelBoxes( 0 ), pAutoFmt( 0 ),
     703 [ #  # ][ #  # ]:          0 :       pHistory( 0 ), cTrenner( cCh ), nAdjust( nAdj )
     704                 :            : {
     705         [ #  # ]:          0 :     if( pAFmt )
     706 [ #  # ][ #  # ]:          0 :         pAutoFmt = new SwTableAutoFmt( *pAFmt );
     707                 :            : 
     708         [ #  # ]:          0 :     const SwPosition* pEnd = rRg.End();
     709         [ #  # ]:          0 :     SwNodes& rNds = rRg.GetDoc()->GetNodes();
     710                 :          0 :     bSplitEnd = pEnd->nContent.GetIndex() && ( pEnd->nContent.GetIndex()
     711         [ #  # ]:          0 :                         != pEnd->nNode.GetNode().GetCntntNode()->Len() ||
     712 [ #  # ][ #  # ]:          0 :                 pEnd->nNode.GetIndex() >= rNds.GetEndOfContent().GetIndex()-1 );
                 [ #  # ]
     713                 :          0 : }
     714                 :            : 
     715         [ #  # ]:          0 : SwUndoTxtToTbl::~SwUndoTxtToTbl()
     716                 :            : {
     717         [ #  # ]:          0 :     delete pDelBoxes;
     718 [ #  # ][ #  # ]:          0 :     delete pAutoFmt;
     719         [ #  # ]:          0 : }
     720                 :            : 
     721                 :          0 : void SwUndoTxtToTbl::UndoImpl(::sw::UndoRedoContext & rContext)
     722                 :            : {
     723                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     724                 :            : 
     725                 :          0 :     sal_uLong nTblNd = nSttNode;
     726         [ #  # ]:          0 :     if( nSttCntnt )
     727                 :          0 :         ++nTblNd;       // Node was splitted previously
     728 [ #  # ][ #  # ]:          0 :     SwNodeIndex aIdx( rDoc.GetNodes(), nTblNd );
     729                 :          0 :     SwTableNode *const pTNd = aIdx.GetNode().GetTableNode();
     730                 :            :     OSL_ENSURE( pTNd, "Could not find a TableNode" );
     731                 :            : 
     732         [ #  # ]:          0 :     RemoveIdxFromSection( rDoc, nTblNd );
     733                 :            : 
     734         [ #  # ]:          0 :     sTblNm = pTNd->GetTable().GetFrmFmt()->GetName();
     735                 :            : 
     736         [ #  # ]:          0 :     if( pHistory )
     737                 :            :     {
     738         [ #  # ]:          0 :         pHistory->TmpRollback( &rDoc, 0 );
     739         [ #  # ]:          0 :         pHistory->SetTmpEnd( pHistory->Count() );
     740                 :            :     }
     741                 :            : 
     742         [ #  # ]:          0 :     if( pDelBoxes )
     743                 :            :     {
     744                 :          0 :         SwTable& rTbl = pTNd->GetTable();
     745         [ #  # ]:          0 :         for( sal_uInt16 n = pDelBoxes->size(); n; )
     746                 :            :         {
     747 [ #  # ][ #  # ]:          0 :             SwTableBox* pBox = rTbl.GetTblBox( (*pDelBoxes)[ --n ] );
     748         [ #  # ]:          0 :             if( pBox )
     749         [ #  # ]:          0 :                 ::_DeleteBox( rTbl, pBox, 0, sal_False, sal_False );
     750                 :            :             else {
     751                 :            :                 OSL_ENSURE( !this, "Where is my box?" );
     752                 :            :             }
     753                 :            :         }
     754                 :            :     }
     755                 :            : 
     756         [ #  # ]:          0 :     SwNodeIndex aEndIdx( *pTNd->EndOfSectionNode() );
     757 [ #  # ][ #  # ]:          0 :     rDoc.TableToText( pTNd, 0x0b == cTrenner ? 0x09 : cTrenner );
     758                 :            : 
     759                 :            :     // join again at start?
     760 [ #  # ][ #  # ]:          0 :     SwPaM aPam(rDoc.GetNodes().GetEndOfContent());
     761                 :          0 :     SwPosition *const pPos = aPam.GetPoint();
     762         [ #  # ]:          0 :     if( nSttCntnt )
     763                 :            :     {
     764         [ #  # ]:          0 :         pPos->nNode = nTblNd;
     765 [ #  # ][ #  # ]:          0 :         pPos->nContent.Assign(pPos->nNode.GetNode().GetCntntNode(), 0);
     766 [ #  # ][ #  # ]:          0 :         if (aPam.Move(fnMoveBackward, fnGoCntnt))
     767                 :            :         {
     768                 :          0 :             SwNodeIndex & rIdx = aPam.GetPoint()->nNode;
     769                 :            : 
     770                 :            :             // than move, relatively, the Crsr/etc. again
     771         [ #  # ]:          0 :             RemoveIdxRel( rIdx.GetIndex()+1, *pPos );
     772                 :            : 
     773         [ #  # ]:          0 :             rIdx.GetNode().GetCntntNode()->JoinNext();
     774                 :            :         }
     775                 :            :     }
     776                 :            : 
     777                 :            :     // join again at end?
     778         [ #  # ]:          0 :     if( bSplitEnd )
     779                 :            :     {
     780                 :          0 :         SwNodeIndex& rIdx = pPos->nNode;
     781         [ #  # ]:          0 :         rIdx = nEndNode;
     782                 :          0 :         SwTxtNode* pTxtNd = rIdx.GetNode().GetTxtNode();
     783 [ #  # ][ #  # ]:          0 :         if( pTxtNd && pTxtNd->CanJoinNext() )
         [ #  # ][ #  # ]
     784                 :            :         {
     785         [ #  # ]:          0 :             aPam.GetMark()->nContent.Assign( 0, 0 );
     786         [ #  # ]:          0 :             aPam.GetPoint()->nContent.Assign( 0, 0 );
     787                 :            : 
     788                 :            :             // than move, relatively, the Crsr/etc. again
     789 [ #  # ][ #  # ]:          0 :             pPos->nContent.Assign( pTxtNd, pTxtNd->GetTxt().Len() );
     790         [ #  # ]:          0 :             RemoveIdxRel( nEndNode + 1, *pPos );
     791                 :            : 
     792         [ #  # ]:          0 :             pTxtNd->JoinNext();
     793                 :            :         }
     794                 :            :     }
     795                 :            : 
     796 [ #  # ][ #  # ]:          0 :     AddUndoRedoPaM(rContext);
         [ #  # ][ #  # ]
     797                 :          0 : }
     798                 :            : 
     799                 :          0 : void SwUndoTxtToTbl::RedoImpl(::sw::UndoRedoContext & rContext)
     800                 :            : {
     801                 :          0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     802                 :          0 :     RemoveIdxFromRange(rPam, false);
     803                 :          0 :     SetPaM(rPam);
     804                 :            : 
     805                 :          0 :     SwTable const*const pTable = rContext.GetDoc().TextToTable(
     806                 :          0 :                 aInsTblOpts, rPam, cTrenner, nAdjust, pAutoFmt );
     807                 :          0 :     ((SwFrmFmt*)pTable->GetFrmFmt())->SetName( sTblNm );
     808                 :          0 : }
     809                 :            : 
     810                 :          0 : void SwUndoTxtToTbl::RepeatImpl(::sw::RepeatContext & rContext)
     811                 :            : {
     812                 :            :     // no Table In Table
     813         [ #  # ]:          0 :     if (!rContext.GetRepeatPaM().GetNode()->FindTableNode())
     814                 :            :     {
     815                 :          0 :         rContext.GetDoc().TextToTable( aInsTblOpts, rContext.GetRepeatPaM(),
     816                 :            :                                         cTrenner, nAdjust,
     817                 :          0 :                                         pAutoFmt );
     818                 :            :     }
     819                 :          0 : }
     820                 :            : 
     821                 :          0 : void SwUndoTxtToTbl::AddFillBox( const SwTableBox& rBox )
     822                 :            : {
     823         [ #  # ]:          0 :     if( !pDelBoxes )
     824         [ #  # ]:          0 :         pDelBoxes = new std::vector<sal_uLong>;
     825         [ #  # ]:          0 :     pDelBoxes->push_back( rBox.GetSttIdx() );
     826                 :          0 : }
     827                 :            : 
     828                 :          0 : SwHistory& SwUndoTxtToTbl::GetHistory()
     829                 :            : {
     830         [ #  # ]:          0 :     if( !pHistory )
     831         [ #  # ]:          0 :         pHistory = new SwHistory;
     832                 :          0 :     return *pHistory;
     833                 :            : }
     834                 :            : 
     835                 :          2 : SwUndoTblHeadline::SwUndoTblHeadline( const SwTable& rTbl, sal_uInt16 nOldHdl,
     836                 :            :                                       sal_uInt16 nNewHdl )
     837                 :            :     : SwUndo( UNDO_TABLEHEADLINE ),
     838                 :            :     nOldHeadline( nOldHdl ),
     839                 :          2 :     nNewHeadline( nNewHdl )
     840                 :            : {
     841                 :            :     OSL_ENSURE( !rTbl.GetTabSortBoxes().empty(), "Table without content" );
     842                 :          2 :     const SwStartNode *pSttNd = rTbl.GetTabSortBoxes()[ 0 ]->GetSttNd();
     843                 :            :     OSL_ENSURE( pSttNd, "Box without content" );
     844                 :            : 
     845                 :          2 :     nTblNd = pSttNd->StartOfSectionIndex();
     846                 :          2 : }
     847                 :            : 
     848                 :          0 : void SwUndoTblHeadline::UndoImpl(::sw::UndoRedoContext & rContext)
     849                 :            : {
     850                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     851                 :          0 :     SwTableNode* pTNd = rDoc.GetNodes()[ nTblNd ]->GetTableNode();
     852                 :            :     OSL_ENSURE( pTNd, "could not find any TableNode" );
     853                 :            : 
     854                 :          0 :     rDoc.SetRowsToRepeat( pTNd->GetTable(), nOldHeadline );
     855                 :          0 : }
     856                 :            : 
     857                 :          0 : void SwUndoTblHeadline::RedoImpl(::sw::UndoRedoContext & rContext)
     858                 :            : {
     859                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     860                 :            : 
     861                 :          0 :     SwTableNode* pTNd = rDoc.GetNodes()[ nTblNd ]->GetTableNode();
     862                 :            :     OSL_ENSURE( pTNd, "could not find any TableNode" );
     863                 :            : 
     864                 :          0 :     rDoc.SetRowsToRepeat( pTNd->GetTable(), nNewHeadline );
     865                 :          0 : }
     866                 :            : 
     867                 :          0 : void SwUndoTblHeadline::RepeatImpl(::sw::RepeatContext & rContext)
     868                 :            : {
     869                 :            :     SwTableNode *const pTblNd =
     870                 :          0 :         rContext.GetRepeatPaM().GetNode()->FindTableNode();
     871         [ #  # ]:          0 :     if( pTblNd )
     872                 :            :     {
     873                 :          0 :         rContext.GetDoc().SetRowsToRepeat( pTblNd->GetTable(), nNewHeadline );
     874                 :            :     }
     875                 :          0 : }
     876                 :            : 
     877                 :         22 : _SaveTable::_SaveTable( const SwTable& rTbl, sal_uInt16 nLnCnt, sal_Bool bSaveFml )
     878                 :         22 :     : aTblSet( *rTbl.GetFrmFmt()->GetAttrSet().GetPool(), aTableSetRange ),
     879 [ +  - ][ +  - ]:         22 :     pSwTable( &rTbl ), nLineCount( nLnCnt ), bSaveFormula( bSaveFml )
     880                 :            : {
     881                 :         22 :     bModifyBox = sal_False;
     882                 :         22 :     bNewModel = rTbl.IsNewModel();
     883         [ +  - ]:         22 :     aTblSet.Put( rTbl.GetFrmFmt()->GetAttrSet() );
     884 [ +  - ][ +  - ]:         22 :     pLine = new _SaveLine( 0, *rTbl.GetTabLines()[ 0 ], *this );
     885                 :            : 
     886                 :         22 :     _SaveLine* pLn = pLine;
     887         [ +  - ]:         22 :     if( USHRT_MAX == nLnCnt )
     888                 :         22 :         nLnCnt = rTbl.GetTabLines().size();
     889         [ +  + ]:         76 :     for( sal_uInt16 n = 1; n < nLnCnt; ++n )
     890 [ +  - ][ +  - ]:         54 :         pLn = new _SaveLine( pLn, *rTbl.GetTabLines()[ n ], *this );
     891                 :            : 
     892                 :         22 :     aFrmFmts.clear();
     893                 :         22 :     pSwTable = 0;
     894                 :         22 : }
     895                 :            : 
     896         [ +  - ]:         22 : _SaveTable::~_SaveTable()
     897                 :            : {
     898 [ +  - ][ +  - ]:         22 :     delete pLine;
     899                 :         22 : }
     900                 :            : 
     901                 :        234 : sal_uInt16 _SaveTable::AddFmt( SwFrmFmt* pFmt, bool bIsLine )
     902                 :            : {
     903                 :        234 :     sal_uInt16 nRet = aFrmFmts.GetPos( pFmt );
     904         [ +  + ]:        234 :     if( USHRT_MAX == nRet )
     905                 :            :     {
     906                 :            :         // Create copy of ItemSet
     907                 :        138 :         boost::shared_ptr<SfxItemSet> pSet( new SfxItemSet( *pFmt->GetAttrSet().GetPool(),
     908 [ +  + ][ +  - ]:        138 :             bIsLine ? aTableLineSetRange : aTableBoxSetRange ) );
         [ +  - ][ +  - ]
     909         [ +  - ]:        138 :         pSet->Put( pFmt->GetAttrSet() );
     910                 :            :         // When a formula is set, never save the value. It possibly must be
     911                 :            :         // recalculated.
     912                 :            :         // Save formulas always in plain text.
     913                 :            :         const SfxPoolItem* pItem;
     914 [ +  - ][ -  + ]:        138 :         if( SFX_ITEM_SET == pSet->GetItemState( RES_BOXATR_FORMULA, sal_True, &pItem ))
     915                 :            :         {
     916         [ #  # ]:          0 :             pSet->ClearItem( RES_BOXATR_VALUE );
     917 [ #  # ][ #  # ]:          0 :             if( pSwTable && bSaveFormula )
     918                 :            :             {
     919         [ #  # ]:          0 :                 SwTableFmlUpdate aMsgHnt( pSwTable );
     920                 :          0 :                 aMsgHnt.eFlags = TBL_BOXNAME;
     921                 :          0 :                 ((SwTblBoxFormula*)pItem)->ChgDefinedIn( pFmt );
     922         [ #  # ]:          0 :                 ((SwTblBoxFormula*)pItem)->ChangeState( &aMsgHnt );
     923         [ #  # ]:          0 :                 ((SwTblBoxFormula*)pItem)->ChgDefinedIn( 0 );
     924                 :            :             }
     925                 :            :         }
     926                 :        138 :         nRet = aSets.size();
     927         [ +  - ]:        138 :         aSets.push_back( pSet );
     928 [ +  - ][ +  - ]:        138 :         aFrmFmts.insert( aFrmFmts.begin() + nRet, pFmt );
                 [ +  - ]
     929                 :            :     }
     930                 :        234 :     return nRet;
     931                 :            : }
     932                 :            : 
     933                 :          0 : void _SaveTable::RestoreAttr( SwTable& rTbl, sal_Bool bMdfyBox )
     934                 :            : {
     935                 :            :     sal_uInt16 n;
     936                 :            : 
     937                 :          0 :     bModifyBox = bMdfyBox;
     938                 :            : 
     939                 :            :     // first, get back attributes of TableFrmFormat
     940                 :          0 :     SwFrmFmt* pFmt = rTbl.GetFrmFmt();
     941                 :          0 :     SfxItemSet& rFmtSet  = (SfxItemSet&)pFmt->GetAttrSet();
     942         [ #  # ]:          0 :     rFmtSet.ClearItem();
     943         [ #  # ]:          0 :     rFmtSet.Put( aTblSet );
     944                 :            : 
     945         [ #  # ]:          0 :     if( pFmt->IsInCache() )
     946                 :            :     {
     947         [ #  # ]:          0 :         SwFrm::GetCache().Delete( pFmt );
     948                 :          0 :         pFmt->SetInCache( sal_False );
     949                 :            :     }
     950                 :            : 
     951                 :            :     // for safety, invalidate all TableFrames
     952         [ #  # ]:          0 :     SwIterator<SwTabFrm,SwFmt> aIter( *pFmt );
     953 [ #  # ][ #  # ]:          0 :     for( SwTabFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
                 [ #  # ]
     954         [ #  # ]:          0 :         if( pLast->GetTable() == &rTbl )
     955                 :            :         {
     956         [ #  # ]:          0 :             pLast->InvalidateAll();
     957                 :          0 :             pLast->SetCompletePaint();
     958                 :            :         }
     959                 :            : 
     960                 :            :     // fill FrmFmts with defaults (0)
     961                 :          0 :     pFmt = 0;
     962         [ #  # ]:          0 :     for( n = aSets.size(); n; --n )
     963         [ #  # ]:          0 :         aFrmFmts.push_back( pFmt );
     964                 :            : 
     965                 :          0 :     sal_uInt16 nLnCnt = nLineCount;
     966         [ #  # ]:          0 :     if( USHRT_MAX == nLnCnt )
     967                 :          0 :         nLnCnt = rTbl.GetTabLines().size();
     968                 :            : 
     969                 :          0 :     _SaveLine* pLn = pLine;
     970         [ #  # ]:          0 :     for( n = 0; n < nLnCnt; ++n, pLn = pLn->pNext )
     971                 :            :     {
     972         [ #  # ]:          0 :         if( !pLn )
     973                 :            :         {
     974                 :            :             OSL_ENSURE( !this, "Number of lines changed" );
     975                 :          0 :             break;
     976                 :            :         }
     977                 :            : 
     978         [ #  # ]:          0 :         pLn->RestoreAttr( *rTbl.GetTabLines()[ n ], *this );
     979                 :            :     }
     980                 :            : 
     981                 :          0 :     aFrmFmts.clear();
     982         [ #  # ]:          0 :     bModifyBox = sal_False;
     983                 :          0 : }
     984                 :            : 
     985                 :          0 : void _SaveTable::SaveCntntAttrs( SwDoc* pDoc )
     986                 :            : {
     987                 :          0 :     pLine->SaveCntntAttrs( pDoc );
     988                 :          0 : }
     989                 :            : 
     990                 :          0 : void _SaveTable::CreateNew( SwTable& rTbl, sal_Bool bCreateFrms,
     991                 :            :                             sal_Bool bRestoreChart )
     992                 :            : {
     993                 :            :     sal_uInt16 n;
     994                 :            : 
     995         [ #  # ]:          0 :     _FndBox aTmpBox( 0, 0 );
     996         [ #  # ]:          0 :     aTmpBox.DelFrms( rTbl );
     997                 :            : 
     998                 :            :     // first, get back attributes of TableFrmFormat
     999                 :          0 :     SwFrmFmt* pFmt = rTbl.GetFrmFmt();
    1000                 :          0 :     SfxItemSet& rFmtSet  = (SfxItemSet&)pFmt->GetAttrSet();
    1001         [ #  # ]:          0 :     rFmtSet.ClearItem();
    1002         [ #  # ]:          0 :     rFmtSet.Put( aTblSet );
    1003                 :            : 
    1004         [ #  # ]:          0 :     if( pFmt->IsInCache() )
    1005                 :            :     {
    1006         [ #  # ]:          0 :         SwFrm::GetCache().Delete( pFmt );
    1007                 :          0 :         pFmt->SetInCache( sal_False );
    1008                 :            :     }
    1009                 :            : 
    1010                 :            :     // SwTableBox must have a format
    1011         [ #  # ]:          0 :     SwTableBox aParent( (SwTableBoxFmt*)pFmt, rTbl.GetTabLines().size(), 0 );
    1012                 :            : 
    1013                 :            :     // fill FrmFmts with defaults (0)
    1014                 :          0 :     pFmt = 0;
    1015         [ #  # ]:          0 :     for( n = aSets.size(); n; --n )
    1016         [ #  # ]:          0 :         aFrmFmts.push_back( pFmt );
    1017                 :            : 
    1018         [ #  # ]:          0 :     pLine->CreateNew( rTbl, aParent, *this );
    1019                 :          0 :     aFrmFmts.clear();
    1020                 :            : 
    1021                 :            :     // add new lines, delete old ones
    1022                 :          0 :     sal_uInt16 nOldLines = nLineCount;
    1023         [ #  # ]:          0 :     if( USHRT_MAX == nLineCount )
    1024                 :          0 :         nOldLines = rTbl.GetTabLines().size();
    1025                 :            : 
    1026                 :          0 :     SwDoc *pDoc = rTbl.GetFrmFmt()->GetDoc();
    1027         [ #  # ]:          0 :     SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
    1028         [ #  # ]:          0 :     for( n = 0; n < aParent.GetTabLines().size(); ++n )
    1029                 :            :     {
    1030                 :          0 :         SwTableLine* pLn = aParent.GetTabLines()[ n ];
    1031                 :          0 :         pLn->SetUpper( 0 );
    1032         [ #  # ]:          0 :         if( n < nOldLines )
    1033                 :            :         {
    1034                 :          0 :             SwTableLine* pOld = rTbl.GetTabLines()[ n ];
    1035                 :            : 
    1036                 :            :             // TL_CHART2: notify chart about boxes to be removed
    1037                 :          0 :             const SwTableBoxes &rBoxes = pOld->GetTabBoxes();
    1038                 :          0 :             sal_uInt16 nBoxes = rBoxes.size();
    1039         [ #  # ]:          0 :             for (sal_uInt16 k = 0;  k < nBoxes;  ++k)
    1040                 :            :             {
    1041                 :          0 :                 SwTableBox *pBox = rBoxes[k];
    1042         [ #  # ]:          0 :                 if (pPCD)
    1043         [ #  # ]:          0 :                     pPCD->DeleteBox( &rTbl, *pBox );
    1044                 :            :             }
    1045                 :            : 
    1046                 :          0 :             rTbl.GetTabLines()[n] = pLn;
    1047 [ #  # ][ #  # ]:          0 :             delete pOld;
    1048                 :            :         }
    1049                 :            :         else
    1050 [ #  # ][ #  # ]:          0 :             rTbl.GetTabLines().insert( rTbl.GetTabLines().begin() + n, pLn );
    1051                 :            :     }
    1052                 :            : 
    1053         [ #  # ]:          0 :     if( n < nOldLines )
    1054                 :            :     {
    1055                 :            :         // remove remaining lines...
    1056         [ #  # ]:          0 :         for (sal_uInt16 k1 = 0; k1 < nOldLines - n;  ++k1)
    1057                 :            :         {
    1058                 :          0 :             const SwTableBoxes &rBoxes = rTbl.GetTabLines()[n + k1]->GetTabBoxes();
    1059                 :          0 :             sal_uInt16 nBoxes = rBoxes.size();
    1060         [ #  # ]:          0 :             for (sal_uInt16 k2 = 0;  k2 < nBoxes;  ++k2)
    1061                 :            :             {
    1062                 :          0 :                 SwTableBox *pBox = rBoxes[k2];
    1063                 :            :                 // TL_CHART2: notify chart about boxes to be removed
    1064         [ #  # ]:          0 :                 if (pPCD)
    1065         [ #  # ]:          0 :                     pPCD->DeleteBox( &rTbl, *pBox );
    1066                 :            :             }
    1067                 :            :         }
    1068                 :            : 
    1069 [ #  # ][ #  # ]:          0 :         for( SwTableLines::const_iterator it = rTbl.GetTabLines().begin() + n;
         [ #  # ][ #  # ]
    1070         [ #  # ]:          0 :              it != rTbl.GetTabLines().begin() + nOldLines; ++it )
    1071 [ #  # ][ #  # ]:          0 :             delete *it;
    1072 [ #  # ][ #  # ]:          0 :         rTbl.GetTabLines().erase( rTbl.GetTabLines().begin() + n, rTbl.GetTabLines().begin() + nOldLines );
                 [ #  # ]
    1073                 :            :     }
    1074                 :            : 
    1075 [ #  # ][ #  # ]:          0 :     aParent.GetTabLines().erase( aParent.GetTabLines().begin(), aParent.GetTabLines().begin() + n );
    1076                 :            : 
    1077         [ #  # ]:          0 :     if( bCreateFrms )
    1078         [ #  # ]:          0 :         aTmpBox.MakeFrms( rTbl );
    1079         [ #  # ]:          0 :     if( bRestoreChart )
    1080                 :            :     {
    1081                 :            :         // TL_CHART2: need to inform chart of probably changed cell names
    1082         [ #  # ]:          0 :         pDoc->UpdateCharts( rTbl.GetFrmFmt()->GetName() );
    1083 [ #  # ][ #  # ]:          0 :     }
    1084                 :          0 : }
    1085                 :            : 
    1086                 :          0 : void _SaveTable::NewFrmFmt( const SwTableLine* pTblLn, const SwTableBox* pTblBx,
    1087                 :            :                             sal_uInt16 nFmtPos, SwFrmFmt* pOldFmt )
    1088                 :            : {
    1089                 :          0 :     SwDoc* pDoc = pOldFmt->GetDoc();
    1090                 :            : 
    1091                 :          0 :     SwFrmFmt* pFmt = aFrmFmts[ nFmtPos ];
    1092         [ #  # ]:          0 :     if( !pFmt )
    1093                 :            :     {
    1094         [ #  # ]:          0 :         if( pTblLn )
    1095         [ #  # ]:          0 :             pFmt = pDoc->MakeTableLineFmt();
    1096                 :            :         else
    1097         [ #  # ]:          0 :             pFmt = pDoc->MakeTableBoxFmt();
    1098         [ #  # ]:          0 :         pFmt->SetFmtAttr( *aSets[ nFmtPos ] );
    1099                 :          0 :         aFrmFmts[nFmtPos] = pFmt;
    1100                 :            :     }
    1101                 :            : 
    1102                 :            :     // first re-assign Frms
    1103         [ #  # ]:          0 :     SwIterator<SwTabFrm,SwFmt> aIter( *pOldFmt );
    1104 [ #  # ][ #  # ]:          0 :     for( SwFrm* pLast = aIter.First(); pLast; pLast = aIter.Next() )
                 [ #  # ]
    1105                 :            :     {
    1106 [ #  # ][ #  # ]:          0 :         if( pTblLn ? ((SwRowFrm*)pLast)->GetTabLine() == pTblLn
    1107                 :          0 :                     : ((SwCellFrm*)pLast)->GetTabBox() == pTblBx )
    1108                 :            :         {
    1109         [ #  # ]:          0 :             pLast->RegisterToFormat(*pFmt);
    1110         [ #  # ]:          0 :             pLast->InvalidateAll();
    1111         [ #  # ]:          0 :             pLast->ReinitializeFrmSizeAttrFlags();
    1112         [ #  # ]:          0 :             if ( !pTblLn )
    1113                 :            :             {
    1114                 :          0 :                 ((SwCellFrm*)pLast)->SetDerivedVert( sal_False );
    1115         [ #  # ]:          0 :                 ((SwCellFrm*)pLast)->CheckDirChange();
    1116                 :            :             }
    1117                 :            :         }
    1118                 :            :     }
    1119                 :            : 
    1120                 :            :     // than re-assign myself
    1121         [ #  # ]:          0 :     if ( pTblLn )
    1122         [ #  # ]:          0 :         const_cast<SwTableLine*>(pTblLn)->RegisterToFormat( *pFmt );
    1123         [ #  # ]:          0 :     else if ( pTblBx )
    1124         [ #  # ]:          0 :         const_cast<SwTableBox*>(pTblBx)->RegisterToFormat( *pFmt );
    1125                 :            : 
    1126 [ #  # ][ #  # ]:          0 :     if( bModifyBox && !pTblLn )
    1127                 :            :     {
    1128         [ #  # ]:          0 :         const SfxPoolItem& rOld = pOldFmt->GetFmtAttr( RES_BOXATR_FORMAT ),
    1129         [ #  # ]:          0 :                          & rNew = pFmt->GetFmtAttr( RES_BOXATR_FORMAT );
    1130 [ #  # ][ #  # ]:          0 :         if( rOld != rNew )
    1131         [ #  # ]:          0 :             pFmt->ModifyNotification( (SfxPoolItem*)&rOld, (SfxPoolItem*)&rNew );
    1132                 :            :     }
    1133                 :            : 
    1134         [ #  # ]:          0 :     if( !pOldFmt->GetDepends() )
    1135 [ #  # ][ #  # ]:          0 :         delete pOldFmt;
                 [ #  # ]
    1136                 :          0 : }
    1137                 :            : 
    1138                 :         76 : _SaveLine::_SaveLine( _SaveLine* pPrev, const SwTableLine& rLine, _SaveTable& rSTbl )
    1139                 :         76 :     : pNext( 0 )
    1140                 :            : {
    1141         [ +  + ]:         76 :     if( pPrev )
    1142                 :         54 :         pPrev->pNext = this;
    1143                 :            : 
    1144                 :         76 :     nItemSet = rSTbl.AddFmt( rLine.GetFrmFmt(), true );
    1145                 :            : 
    1146         [ +  - ]:         76 :     pBox = new _SaveBox( 0, *rLine.GetTabBoxes()[ 0 ], rSTbl );
    1147                 :         76 :     _SaveBox* pBx = pBox;
    1148         [ +  + ]:        158 :     for( sal_uInt16 n = 1; n < rLine.GetTabBoxes().size(); ++n )
    1149         [ +  - ]:         82 :         pBx = new _SaveBox( pBx, *rLine.GetTabBoxes()[ n ], rSTbl );
    1150                 :         76 : }
    1151                 :            : 
    1152                 :         76 : _SaveLine::~_SaveLine()
    1153                 :            : {
    1154         [ +  - ]:         76 :     delete pBox;
    1155         [ +  + ]:         76 :     delete pNext;
    1156                 :         76 : }
    1157                 :            : 
    1158                 :          0 : void _SaveLine::RestoreAttr( SwTableLine& rLine, _SaveTable& rSTbl )
    1159                 :            : {
    1160                 :          0 :     rSTbl.NewFrmFmt( &rLine, 0, nItemSet, rLine.GetFrmFmt() );
    1161                 :            : 
    1162                 :          0 :     _SaveBox* pBx = pBox;
    1163         [ #  # ]:          0 :     for( sal_uInt16 n = 0; n < rLine.GetTabBoxes().size(); ++n, pBx = pBx->pNext )
    1164                 :            :     {
    1165         [ #  # ]:          0 :         if( !pBx )
    1166                 :            :         {
    1167                 :            :             OSL_ENSURE( !this, "Number of boxes changed" );
    1168                 :          0 :             break;
    1169                 :            :         }
    1170                 :          0 :         pBx->RestoreAttr( *rLine.GetTabBoxes()[ n ], rSTbl );
    1171                 :            :     }
    1172                 :          0 : }
    1173                 :            : 
    1174                 :          0 : void _SaveLine::SaveCntntAttrs( SwDoc* pDoc )
    1175                 :            : {
    1176                 :          0 :     pBox->SaveCntntAttrs( pDoc );
    1177         [ #  # ]:          0 :     if( pNext )
    1178                 :          0 :         pNext->SaveCntntAttrs( pDoc );
    1179                 :          0 : }
    1180                 :            : 
    1181                 :          0 : void _SaveLine::CreateNew( SwTable& rTbl, SwTableBox& rParent, _SaveTable& rSTbl )
    1182                 :            : {
    1183                 :          0 :     SwTableLineFmt* pFmt = (SwTableLineFmt*)rSTbl.aFrmFmts[ nItemSet ];
    1184         [ #  # ]:          0 :     if( !pFmt )
    1185                 :            :     {
    1186                 :          0 :         SwDoc* pDoc = rTbl.GetFrmFmt()->GetDoc();
    1187         [ #  # ]:          0 :         pFmt = pDoc->MakeTableLineFmt();
    1188         [ #  # ]:          0 :         pFmt->SetFmtAttr( *rSTbl.aSets[ nItemSet ] );
    1189                 :          0 :         rSTbl.aFrmFmts[ nItemSet ] = pFmt;
    1190                 :            :     }
    1191 [ #  # ][ #  # ]:          0 :     SwTableLine* pNew = new SwTableLine( pFmt, 1, &rParent );
    1192                 :            : 
    1193         [ #  # ]:          0 :     rParent.GetTabLines().push_back( pNew );
    1194                 :            : 
    1195                 :            :     // HB, #127868# robustness: in some cases - which I
    1196                 :            :     // cannot reproduce nor see from the code - pNew seems
    1197                 :            :     // to be set to NULL in C40_INSERT.
    1198                 :            :     OSL_ENSURE(pNew, "Table line just created set to NULL in C40_INSERT");
    1199                 :            : 
    1200         [ #  # ]:          0 :     if (pNew)
    1201                 :            :     {
    1202         [ #  # ]:          0 :         pBox->CreateNew( rTbl, *pNew, rSTbl );
    1203                 :            :     }
    1204                 :            : 
    1205         [ #  # ]:          0 :     if( pNext )
    1206         [ #  # ]:          0 :         pNext->CreateNew( rTbl, rParent, rSTbl );
    1207                 :          0 : }
    1208                 :            : 
    1209                 :        158 : _SaveBox::_SaveBox( _SaveBox* pPrev, const SwTableBox& rBox, _SaveTable& rSTbl )
    1210                 :        158 :     : pNext( 0 ), nSttNode( ULONG_MAX ), nRowSpan(0)
    1211                 :            : {
    1212                 :        158 :     Ptrs.pLine = 0;
    1213                 :            : 
    1214         [ +  + ]:        158 :     if( pPrev )
    1215                 :         82 :         pPrev->pNext = this;
    1216                 :            : 
    1217                 :        158 :     nItemSet = rSTbl.AddFmt( rBox.GetFrmFmt(), false );
    1218                 :            : 
    1219         [ +  - ]:        158 :     if( rBox.GetSttNd() )
    1220                 :            :     {
    1221                 :        158 :         nSttNode = rBox.GetSttIdx();
    1222                 :        158 :         nRowSpan = rBox.getRowSpan();
    1223                 :            :     }
    1224                 :            :     else
    1225                 :            :     {
    1226         [ #  # ]:          0 :         Ptrs.pLine = new _SaveLine( 0, *rBox.GetTabLines()[ 0 ], rSTbl );
    1227                 :            : 
    1228                 :          0 :         _SaveLine* pLn = Ptrs.pLine;
    1229         [ #  # ]:          0 :         for( sal_uInt16 n = 1; n < rBox.GetTabLines().size(); ++n )
    1230         [ #  # ]:          0 :             pLn = new _SaveLine( pLn, *rBox.GetTabLines()[ n ], rSTbl );
    1231                 :            :     }
    1232                 :        158 : }
    1233                 :            : 
    1234                 :        158 : _SaveBox::~_SaveBox()
    1235                 :            : {
    1236         [ -  + ]:        158 :     if( ULONG_MAX == nSttNode )     // no EndBox
    1237         [ #  # ]:          0 :         delete Ptrs.pLine;
    1238                 :            :     else
    1239         [ -  + ]:        158 :         delete Ptrs.pCntntAttrs;
    1240         [ +  + ]:        158 :     delete pNext;
    1241                 :        158 : }
    1242                 :            : 
    1243                 :          0 : void _SaveBox::RestoreAttr( SwTableBox& rBox, _SaveTable& rSTbl )
    1244                 :            : {
    1245                 :          0 :     rSTbl.NewFrmFmt( 0, &rBox, nItemSet, rBox.GetFrmFmt() );
    1246                 :            : 
    1247         [ #  # ]:          0 :     if( ULONG_MAX == nSttNode )     // no EndBox
    1248                 :            :     {
    1249         [ #  # ]:          0 :         if( !rBox.GetTabLines().size() )
    1250                 :            :         {
    1251                 :            :             OSL_ENSURE( !this, "Number of lines changed" );
    1252                 :            :         }
    1253                 :            :         else
    1254                 :            :         {
    1255                 :          0 :             _SaveLine* pLn = Ptrs.pLine;
    1256         [ #  # ]:          0 :             for( sal_uInt16 n = 0; n < rBox.GetTabLines().size(); ++n, pLn = pLn->pNext )
    1257                 :            :             {
    1258         [ #  # ]:          0 :                 if( !pLn )
    1259                 :            :                 {
    1260                 :            :                     OSL_ENSURE( !this, "Number of lines changed" );
    1261                 :          0 :                     break;
    1262                 :            :                 }
    1263                 :            : 
    1264                 :          0 :                 pLn->RestoreAttr( *rBox.GetTabLines()[ n ], rSTbl );
    1265                 :            :             }
    1266                 :            :         }
    1267                 :            :     }
    1268 [ #  # ][ #  # ]:          0 :     else if( rBox.GetSttNd() && rBox.GetSttIdx() == nSttNode )
                 [ #  # ]
    1269                 :            :     {
    1270         [ #  # ]:          0 :         if( Ptrs.pCntntAttrs )
    1271                 :            :         {
    1272                 :          0 :             SwNodes& rNds = rBox.GetFrmFmt()->GetDoc()->GetNodes();
    1273                 :          0 :             sal_uInt16 nSet = 0;
    1274                 :          0 :             sal_uLong nEnd = rBox.GetSttNd()->EndOfSectionIndex();
    1275         [ #  # ]:          0 :             for( sal_uLong n = nSttNode + 1; n < nEnd; ++n )
    1276                 :            :             {
    1277                 :          0 :                 SwCntntNode* pCNd = rNds[ n ]->GetCntntNode();
    1278         [ #  # ]:          0 :                 if( pCNd )
    1279                 :            :                 {
    1280         [ #  # ]:          0 :                     boost::shared_ptr<SfxItemSet> pSet( (*Ptrs.pCntntAttrs)[ nSet++ ] );
    1281         [ #  # ]:          0 :                     if( pSet )
    1282                 :            :                     {
    1283                 :          0 :                         sal_uInt16 *pRstAttr = aSave_BoxCntntSet;
    1284         [ #  # ]:          0 :                         while( *pRstAttr )
    1285                 :            :                         {
    1286         [ #  # ]:          0 :                             pCNd->ResetAttr( *pRstAttr, *(pRstAttr+1) );
    1287                 :          0 :                             pRstAttr += 2;
    1288                 :            :                         }
    1289         [ #  # ]:          0 :                         pCNd->SetAttr( *pSet );
    1290                 :            :                     }
    1291                 :            :                     else
    1292 [ #  # ][ #  # ]:          0 :                         pCNd->ResetAllAttr();
    1293                 :            :                 }
    1294                 :            :             }
    1295                 :            :         }
    1296                 :            :     }
    1297                 :            :     else
    1298                 :            :     {
    1299                 :            :         OSL_ENSURE( !this, "Box not anymore at the same node" );
    1300                 :            :     }
    1301                 :          0 : }
    1302                 :            : 
    1303                 :          0 : void _SaveBox::SaveCntntAttrs( SwDoc* pDoc )
    1304                 :            : {
    1305         [ #  # ]:          0 :     if( ULONG_MAX == nSttNode )     // no EndBox
    1306                 :            :     {
    1307                 :            :         // continue in current line
    1308                 :          0 :         Ptrs.pLine->SaveCntntAttrs( pDoc );
    1309                 :            :     }
    1310                 :            :     else
    1311                 :            :     {
    1312                 :          0 :         sal_uLong nEnd = pDoc->GetNodes()[ nSttNode ]->EndOfSectionIndex();
    1313         [ #  # ]:          0 :         Ptrs.pCntntAttrs = new SfxItemSets( (sal_uInt8)(nEnd - nSttNode - 1 ) );
    1314         [ #  # ]:          0 :         for( sal_uLong n = nSttNode + 1; n < nEnd; ++n )
    1315                 :            :         {
    1316                 :          0 :             SwCntntNode* pCNd = pDoc->GetNodes()[ n ]->GetCntntNode();
    1317         [ #  # ]:          0 :             if( pCNd )
    1318                 :            :             {
    1319         [ #  # ]:          0 :                 boost::shared_ptr<SfxItemSet> pSet;
    1320 [ #  # ][ #  # ]:          0 :                 if( pCNd->HasSwAttrSet() )
    1321                 :            :                 {
    1322                 :          0 :                     pSet.reset( new SfxItemSet( pDoc->GetAttrPool(),
    1323 [ #  # ][ #  # ]:          0 :                                             aSave_BoxCntntSet ) );
                 [ #  # ]
    1324 [ #  # ][ #  # ]:          0 :                     pSet->Put( *pCNd->GetpSwAttrSet() );
    1325                 :            :                 }
    1326                 :            : 
    1327 [ #  # ][ #  # ]:          0 :                 Ptrs.pCntntAttrs->push_back( pSet );
    1328                 :            :             }
    1329                 :            :         }
    1330                 :            :     }
    1331         [ #  # ]:          0 :     if( pNext )
    1332                 :          0 :         pNext->SaveCntntAttrs( pDoc );
    1333                 :          0 : }
    1334                 :            : 
    1335                 :          0 : void _SaveBox::CreateNew( SwTable& rTbl, SwTableLine& rParent, _SaveTable& rSTbl )
    1336                 :            : {
    1337                 :          0 :     SwTableBoxFmt* pFmt = (SwTableBoxFmt*)rSTbl.aFrmFmts[ nItemSet ];
    1338         [ #  # ]:          0 :     if( !pFmt )
    1339                 :            :     {
    1340                 :          0 :         SwDoc* pDoc = rTbl.GetFrmFmt()->GetDoc();
    1341                 :          0 :         pFmt = pDoc->MakeTableBoxFmt();
    1342                 :          0 :         pFmt->SetFmtAttr( *rSTbl.aSets[ nItemSet ] );
    1343                 :          0 :         rSTbl.aFrmFmts[nItemSet] = pFmt;
    1344                 :            :     }
    1345                 :            : 
    1346         [ #  # ]:          0 :     if( ULONG_MAX == nSttNode )     // no EndBox
    1347                 :            :     {
    1348 [ #  # ][ #  # ]:          0 :         SwTableBox* pNew = new SwTableBox( pFmt, 1, &rParent );
    1349         [ #  # ]:          0 :         rParent.GetTabBoxes().push_back( pNew );
    1350                 :            : 
    1351         [ #  # ]:          0 :         Ptrs.pLine->CreateNew( rTbl, *pNew, rSTbl );
    1352                 :            :     }
    1353                 :            :     else
    1354                 :            :     {
    1355                 :            :         // search box for StartNode in old table
    1356         [ #  # ]:          0 :         SwTableBox* pBox = rTbl.GetTblBox( nSttNode );
    1357                 :            :         OSL_ENSURE( pBox, "Where is my TableBox?" );
    1358                 :            : 
    1359                 :          0 :         SwFrmFmt* pOld = pBox->GetFrmFmt();
    1360         [ #  # ]:          0 :         pBox->RegisterToFormat( *pFmt );
    1361         [ #  # ]:          0 :         if( !pOld->GetDepends() )
    1362 [ #  # ][ #  # ]:          0 :             delete pOld;
    1363                 :            : 
    1364         [ #  # ]:          0 :         pBox->setRowSpan( nRowSpan );
    1365                 :            : 
    1366                 :          0 :         SwTableBoxes* pTBoxes = &pBox->GetUpper()->GetTabBoxes();
    1367 [ #  # ][ #  # ]:          0 :         pTBoxes->erase( std::find( pTBoxes->begin(), pTBoxes->end(), pBox ) );
    1368                 :            : 
    1369                 :          0 :         pBox->SetUpper( &rParent );
    1370                 :          0 :         pTBoxes = &rParent.GetTabBoxes();
    1371         [ #  # ]:          0 :         pTBoxes->push_back( pBox );
    1372                 :            :     }
    1373                 :            : 
    1374         [ #  # ]:          0 :     if( pNext )
    1375                 :          0 :         pNext->CreateNew( rTbl, rParent, rSTbl );
    1376                 :          0 : }
    1377                 :            : 
    1378                 :            : // UndoObject for attribute changes on table
    1379                 :         12 : SwUndoAttrTbl::SwUndoAttrTbl( const SwTableNode& rTblNd, sal_Bool bClearTabCols )
    1380                 :            :     : SwUndo( UNDO_TABLE_ATTR ),
    1381                 :         12 :     nSttNode( rTblNd.GetIndex() )
    1382                 :            : {
    1383                 :         12 :     bClearTabCol = bClearTabCols;
    1384 [ +  - ][ +  - ]:         12 :     pSaveTbl = new _SaveTable( rTblNd.GetTable() );
    1385                 :         12 : }
    1386                 :            : 
    1387                 :         12 : SwUndoAttrTbl::~SwUndoAttrTbl()
    1388                 :            : {
    1389 [ +  - ][ +  - ]:         12 :     delete pSaveTbl;
    1390         [ -  + ]:         24 : }
    1391                 :            : 
    1392                 :          0 : void SwUndoAttrTbl::UndoImpl(::sw::UndoRedoContext & rContext)
    1393                 :            : {
    1394                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    1395                 :          0 :     SwTableNode* pTblNd = rDoc.GetNodes()[ nSttNode ]->GetTableNode();
    1396                 :            :     OSL_ENSURE( pTblNd, "no TableNode" );
    1397                 :            : 
    1398         [ #  # ]:          0 :     if (pTblNd)
    1399                 :            :     {
    1400         [ #  # ]:          0 :         _SaveTable* pOrig = new _SaveTable( pTblNd->GetTable() );
    1401                 :          0 :         pSaveTbl->RestoreAttr( pTblNd->GetTable() );
    1402         [ #  # ]:          0 :         delete pSaveTbl;
    1403                 :          0 :         pSaveTbl = pOrig;
    1404                 :            :     }
    1405                 :            : 
    1406         [ #  # ]:          0 :     if( bClearTabCol )
    1407                 :          0 :         ClearFEShellTabCols();
    1408                 :          0 : }
    1409                 :            : 
    1410                 :          0 : void SwUndoAttrTbl::RedoImpl(::sw::UndoRedoContext & rContext)
    1411                 :            : {
    1412                 :          0 :     UndoImpl(rContext);
    1413                 :          0 : }
    1414                 :            : 
    1415                 :            : // UndoObject for AutoFormat on Table
    1416                 :          0 : SwUndoTblAutoFmt::SwUndoTblAutoFmt( const SwTableNode& rTblNd,
    1417                 :            :                                     const SwTableAutoFmt& rAFmt )
    1418                 :            :     : SwUndo( UNDO_TABLE_AUTOFMT ),
    1419                 :          0 :     nSttNode( rTblNd.GetIndex() ),
    1420                 :            :     bSaveCntntAttr( sal_False )
    1421 [ #  # ][ #  # ]:          0 :     , m_nRepeatHeading(rTblNd.GetTable().GetRowsToRepeat())
    1422                 :            : {
    1423 [ #  # ][ #  # ]:          0 :     pSaveTbl = new _SaveTable( rTblNd.GetTable() );
    1424                 :            : 
    1425 [ #  # ][ #  # ]:          0 :     if( rAFmt.IsFont() || rAFmt.IsJustify() )
                 [ #  # ]
    1426                 :            :     {
    1427                 :            :         // than also go over the ContentNodes of the EndBoxes and collect
    1428                 :            :         // all paragraph attributes
    1429         [ #  # ]:          0 :         pSaveTbl->SaveCntntAttrs( (SwDoc*)rTblNd.GetDoc() );
    1430                 :          0 :         bSaveCntntAttr = sal_True;
    1431                 :            :     }
    1432                 :          0 : }
    1433                 :            : 
    1434                 :          0 : SwUndoTblAutoFmt::~SwUndoTblAutoFmt()
    1435                 :            : {
    1436 [ #  # ][ #  # ]:          0 :     delete pSaveTbl;
    1437         [ #  # ]:          0 : }
    1438                 :            : 
    1439                 :          0 : void SwUndoTblAutoFmt::SaveBoxCntnt( const SwTableBox& rBox )
    1440                 :            : {
    1441 [ #  # ][ #  # ]:          0 :     ::boost::shared_ptr<SwUndoTblNumFmt> const p(new SwUndoTblNumFmt(rBox));
                 [ #  # ]
    1442 [ #  # ][ #  # ]:          0 :     m_Undos.push_back(p);
    1443                 :          0 : }
    1444                 :            : 
    1445                 :            : void
    1446                 :          0 : SwUndoTblAutoFmt::UndoRedo(bool const bUndo, ::sw::UndoRedoContext & rContext)
    1447                 :            : {
    1448                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    1449                 :          0 :     SwTableNode* pTblNd = rDoc.GetNodes()[ nSttNode ]->GetTableNode();
    1450                 :            :     OSL_ENSURE( pTblNd, "no TableNode" );
    1451                 :            : 
    1452                 :          0 :     SwTable& table = pTblNd->GetTable();
    1453         [ #  # ]:          0 :     _SaveTable* pOrig = new _SaveTable( table );
    1454                 :            :     // than go also over the ContentNodes of the EndBoxes and collect
    1455                 :            :     // all paragraph attributes
    1456         [ #  # ]:          0 :     if( bSaveCntntAttr )
    1457                 :          0 :         pOrig->SaveCntntAttrs( &rDoc );
    1458                 :            : 
    1459         [ #  # ]:          0 :     if (bUndo)
    1460                 :            :     {
    1461         [ #  # ]:          0 :         for (size_t n = m_Undos.size(); 0 < n; --n)
    1462                 :            :         {
    1463                 :          0 :             m_Undos.at(n-1)->UndoImpl(rContext);
    1464                 :            :         }
    1465                 :            : 
    1466                 :          0 :         table.SetRowsToRepeat(m_nRepeatHeading);
    1467                 :            :     }
    1468                 :            : 
    1469                 :          0 :     pSaveTbl->RestoreAttr( pTblNd->GetTable(), !bUndo );
    1470         [ #  # ]:          0 :     delete pSaveTbl;
    1471                 :          0 :     pSaveTbl = pOrig;
    1472                 :          0 : }
    1473                 :            : 
    1474                 :          0 : void SwUndoTblAutoFmt::UndoImpl(::sw::UndoRedoContext & rContext)
    1475                 :            : {
    1476                 :          0 :     UndoRedo(true, rContext);
    1477                 :          0 : }
    1478                 :            : 
    1479                 :          0 : void SwUndoTblAutoFmt::RedoImpl(::sw::UndoRedoContext & rContext)
    1480                 :            : {
    1481                 :          0 :     UndoRedo(false, rContext);
    1482                 :          0 : }
    1483                 :            : 
    1484                 :          8 : SwUndoTblNdsChg::SwUndoTblNdsChg( SwUndoId nAction,
    1485                 :            :                                     const SwSelBoxes& rBoxes,
    1486                 :            :                                     const SwTableNode& rTblNd,
    1487                 :            :                                     long nMn, long nMx,
    1488                 :            :                                     sal_uInt16 nCnt, sal_Bool bFlg, sal_Bool bSmHght )
    1489                 :            :     : SwUndo( nAction ),
    1490                 :            :     nMin( nMn ), nMax( nMx ),
    1491                 :          8 :     nSttNode( rTblNd.GetIndex() ), nCurrBox( 0 ),
    1492                 :            :     nCount( nCnt ), nRelDiff( 0 ), nAbsDiff( 0 ),
    1493                 :            :     nSetColType( USHRT_MAX ),
    1494                 :            :     bFlag( bFlg ),
    1495         [ +  - ]:          8 :     bSameHeight( bSmHght )
    1496                 :            : {
    1497                 :          8 :     const SwTable& rTbl = rTblNd.GetTable();
    1498 [ +  - ][ +  - ]:          8 :     pSaveTbl = new _SaveTable( rTbl );
    1499                 :            : 
    1500                 :            :     // and remember selection
    1501         [ +  - ]:          8 :     ReNewBoxes( rBoxes );
    1502                 :          8 : }
    1503                 :            : 
    1504                 :          0 : SwUndoTblNdsChg::SwUndoTblNdsChg( SwUndoId nAction,
    1505                 :            :                                     const SwSelBoxes& rBoxes,
    1506                 :            :                                     const SwTableNode& rTblNd )
    1507                 :            :     : SwUndo( nAction ),
    1508                 :            :     nMin( 0 ), nMax( 0 ),
    1509                 :          0 :     nSttNode( rTblNd.GetIndex() ), nCurrBox( 0 ),
    1510                 :            :     nCount( 0 ), nRelDiff( 0 ), nAbsDiff( 0 ),
    1511                 :            :     nSetColType( USHRT_MAX ),
    1512                 :            :     bFlag( sal_False ),
    1513         [ #  # ]:          0 :     bSameHeight( sal_False )
    1514                 :            : {
    1515                 :          0 :     const SwTable& rTbl = rTblNd.GetTable();
    1516 [ #  # ][ #  # ]:          0 :     pSaveTbl = new _SaveTable( rTbl );
    1517                 :            : 
    1518                 :            :     // and remember selection
    1519         [ #  # ]:          0 :     ReNewBoxes( rBoxes );
    1520                 :          0 : }
    1521                 :            : 
    1522                 :         10 : void SwUndoTblNdsChg::ReNewBoxes( const SwSelBoxes& rBoxes )
    1523                 :            : {
    1524         [ +  + ]:         10 :     if( rBoxes.size() != aBoxes.size() )
    1525                 :            :     {
    1526                 :          8 :         aBoxes.clear();
    1527         [ +  + ]:         22 :         for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
    1528         [ +  - ]:         14 :             aBoxes.insert( rBoxes[n]->GetSttIdx() );
    1529                 :            :     }
    1530                 :         10 : }
    1531                 :            : 
    1532 [ +  - ][ +  - ]:          8 : SwUndoTblNdsChg::~SwUndoTblNdsChg()
    1533                 :            : {
    1534 [ +  - ][ +  - ]:          8 :     delete pSaveTbl;
    1535         [ -  + ]:         16 : }
    1536                 :            : 
    1537                 :          4 : void SwUndoTblNdsChg::SaveNewBoxes( const SwTableNode& rTblNd,
    1538                 :            :                                     const SwTableSortBoxes& rOld )
    1539                 :            : {
    1540                 :          4 :     const SwTable& rTbl = rTblNd.GetTable();
    1541                 :          4 :     const SwTableSortBoxes& rTblBoxes = rTbl.GetTabSortBoxes();
    1542                 :            :     sal_uInt16 n;
    1543                 :            :     sal_uInt16 i;
    1544                 :            : 
    1545                 :            :     OSL_ENSURE( ! IsDelBox(), "wrong Action" );
    1546         [ +  - ]:          4 :     pNewSttNds.reset( new std::set<_BoxMove> );
    1547                 :            : 
    1548         [ +  + ]:         15 :     for( n = 0, i = 0; n < rOld.size(); ++i )
    1549                 :            :     {
    1550         [ +  + ]:         11 :         if( rOld[ n ] == rTblBoxes[ i ] )
    1551                 :          8 :             ++n;
    1552                 :            :         else
    1553                 :            :             // new box: insert sorted
    1554         [ +  - ]:          3 :             pNewSttNds->insert( _BoxMove(rTblBoxes[ i ]->GetSttIdx()) );
    1555                 :            :     }
    1556                 :            : 
    1557         [ +  + ]:          9 :     for( ; i < rTblBoxes.size(); ++i )
    1558                 :            :         // new box: insert sorted
    1559         [ +  - ]:          5 :         pNewSttNds->insert( _BoxMove(rTblBoxes[ i ]->GetSttIdx()) );
    1560                 :          4 : }
    1561                 :            : 
    1562                 :          0 : SwTableLine* lcl_FindTableLine( const SwTable& rTable,
    1563                 :            :                                 const SwTableBox& rBox )
    1564                 :            : {
    1565                 :          0 :     SwTableLine* pRet = NULL;
    1566                 :            :     // i63949: For nested cells we have to take nLineNo - 1, too, not 0!
    1567                 :          0 :     const SwTableLines &rTableLines = ( rBox.GetUpper()->GetUpper() != NULL ) ?
    1568                 :          0 :                                   rBox.GetUpper()->GetUpper()->GetTabLines()
    1569         [ #  # ]:          0 :                                 : rTable.GetTabLines();
    1570                 :          0 :     const SwTableLine* pLine = rBox.GetUpper();
    1571                 :          0 :     sal_uInt16 nLineNo = rTableLines.GetPos( pLine );
    1572                 :          0 :     pRet = rTableLines[nLineNo - 1];
    1573                 :            : 
    1574                 :          0 :     return pRet;
    1575                 :            : }
    1576                 :            : 
    1577                 :          4 : const SwTableLines& lcl_FindParentLines( const SwTable& rTable,
    1578                 :            :                                        const SwTableBox& rBox )
    1579                 :            : {
    1580                 :            :     const SwTableLines& rRet =
    1581                 :          4 :         ( rBox.GetUpper()->GetUpper() != NULL ) ?
    1582                 :          0 :             rBox.GetUpper()->GetUpper()->GetTabLines() :
    1583         [ -  + ]:          4 :             rTable.GetTabLines();
    1584                 :            : 
    1585                 :          4 :     return rRet;
    1586                 :            : }
    1587                 :            : 
    1588                 :          2 : void SwUndoTblNdsChg::SaveNewBoxes( const SwTableNode& rTblNd,
    1589                 :            :                                     const SwTableSortBoxes& rOld,
    1590                 :            :                                     const SwSelBoxes& rBoxes,
    1591                 :            :                                     const std::vector<sal_uLong> &rNodeCnts )
    1592                 :            : {
    1593                 :          2 :     const SwTable& rTbl = rTblNd.GetTable();
    1594                 :          2 :     const SwTableSortBoxes& rTblBoxes = rTbl.GetTabSortBoxes();
    1595                 :            : 
    1596                 :            :     OSL_ENSURE( ! IsDelBox(), "wrong Action" );
    1597         [ +  - ]:          2 :     pNewSttNds.reset( new std::set<_BoxMove> );
    1598                 :            : 
    1599                 :            :     OSL_ENSURE( rTbl.IsNewModel() || rOld.size() + nCount * rBoxes.size() == rTblBoxes.size(),
    1600                 :            :         "unexpected boxes" );
    1601                 :            :     OSL_ENSURE( rOld.size() <= rTblBoxes.size(), "more unexpected boxes" );
    1602         [ +  + ]:          6 :     for( sal_uInt16 n = 0, i = 0; i < rTblBoxes.size(); ++i )
    1603                 :            :     {
    1604   [ +  -  +  + ]:          8 :         if( ( n < rOld.size() ) &&
                 [ +  + ]
    1605                 :          4 :             ( rOld[ n ] == rTblBoxes[ i ] ) )
    1606                 :            :         {
    1607                 :            :             // box already known? Then nothing to be done.
    1608                 :          2 :             ++n;
    1609                 :            :         }
    1610                 :            :         else
    1611                 :            :         {
    1612                 :            :             // new box found: insert (obey sort order)
    1613                 :          2 :             const SwTableBox* pBox = rTblBoxes[ i ];
    1614                 :            : 
    1615                 :            :             // find the source box. It must be one in rBoxes.
    1616                 :            :             // We found the right one if it's in the same column as pBox.
    1617                 :            :             // No, if more than one selected cell in the same column has been splitted,
    1618                 :            :             // we have to look for the nearest one (i65201)!
    1619                 :          2 :             const SwTableBox* pSourceBox = NULL;
    1620                 :          2 :             const SwTableBox* pCheckBox = NULL;
    1621                 :          2 :             const SwTableLine* pBoxLine = pBox->GetUpper();
    1622                 :          2 :             sal_uInt16 nLineDiff = lcl_FindParentLines(rTbl,*pBox).GetPos(pBoxLine);
    1623                 :          2 :             sal_uInt16 nLineNo = 0;
    1624         [ +  + ]:          4 :             for( sal_uInt16 j = 0; j < rBoxes.size(); ++j )
    1625                 :            :             {
    1626                 :          2 :                 pCheckBox = rBoxes[j];
    1627         [ +  - ]:          2 :                 if( pCheckBox->GetUpper()->GetUpper() == pBox->GetUpper()->GetUpper() )
    1628                 :            :                 {
    1629                 :          2 :                     const SwTableLine* pCheckLine = pCheckBox->GetUpper();
    1630                 :          2 :                     sal_uInt16 nCheckLine = lcl_FindParentLines( rTbl, *pCheckBox ).
    1631                 :          2 :                     GetPos( pCheckLine );
    1632 [ #  # ][ +  - ]:          2 :                     if( ( !pSourceBox || nCheckLine > nLineNo ) && nCheckLine < nLineDiff )
                 [ -  + ]
    1633                 :            :                     {
    1634                 :          2 :                         nLineNo = nCheckLine;
    1635                 :          2 :                         pSourceBox = pCheckBox;
    1636                 :            :                     }
    1637                 :            :                 }
    1638                 :            :             }
    1639                 :            : 
    1640                 :            :             // find the line number difference
    1641                 :            :             // (to help determine bNodesMoved flag below)
    1642                 :          2 :             nLineDiff = nLineDiff - nLineNo;
    1643                 :            :             OSL_ENSURE( pSourceBox, "Splitted source box not found!" );
    1644                 :            :             // find out how many nodes the source box used to have
    1645                 :            :             // (to help determine bNodesMoved flag below)
    1646                 :          2 :             sal_uInt16 nNdsPos = 0;
    1647         [ -  + ]:          2 :             while( rBoxes[ nNdsPos ] != pSourceBox )
    1648                 :          0 :                 ++nNdsPos;
    1649                 :          2 :             sal_uLong nNodes = rNodeCnts[ nNdsPos ];
    1650                 :            : 
    1651                 :            :             // When a new table cell is created, it either gets a new
    1652                 :            :             // node, or it gets node(s) from elsewhere. The undo must
    1653                 :            :             // know, of course, and thus we must determine here just
    1654                 :            :             // where pBox's nodes are from:
    1655                 :            :             // If 1) the source box has lost nodes, and
    1656                 :            :             //    2) we're in the node range that got nodes
    1657                 :            :             // then pBox received nodes from elsewhere.
    1658                 :            :             // If bNodesMoved is set for pBox the undo must move the
    1659                 :            :             // boxes back, otherwise it must delete them.
    1660                 :            :             sal_Bool bNodesMoved =
    1661                 :          2 :                 ( nNodes != ( pSourceBox->GetSttNd()->EndOfSectionIndex() -
    1662                 :          2 :                               pSourceBox->GetSttIdx() ) )
    1663 [ #  # ][ -  + ]:          2 :                 && ( nNodes - 1 > nLineDiff );
    1664         [ +  - ]:          2 :             pNewSttNds->insert( _BoxMove(pBox->GetSttIdx(), bNodesMoved) );
    1665                 :            :         }
    1666                 :            :     }
    1667                 :          2 : }
    1668                 :            : 
    1669                 :          4 : void SwUndoTblNdsChg::SaveSection( SwStartNode* pSttNd )
    1670                 :            : {
    1671                 :            :     OSL_ENSURE( IsDelBox(), "wrong Action" );
    1672         [ +  + ]:          4 :     if( pDelSects.get() == NULL )
    1673         [ +  - ]:          2 :         pDelSects.reset( new SwUndoSaveSections( 10 ) );
    1674                 :            : 
    1675                 :          4 :     SwTableNode* pTblNd = pSttNd->FindTableNode();
    1676         [ +  - ]:          4 :     SwUndoSaveSection* pSave = new SwUndoSaveSection;
    1677         [ +  - ]:          4 :     pSave->SaveSection( pSttNd->GetDoc(), SwNodeIndex( *pSttNd ));
    1678                 :            : 
    1679                 :          4 :     pDelSects->push_back( pSave );
    1680                 :          4 :     nSttNode = pTblNd->GetIndex();
    1681                 :          4 : }
    1682                 :            : 
    1683                 :          0 : void SwUndoTblNdsChg::UndoImpl(::sw::UndoRedoContext & rContext)
    1684                 :            : {
    1685                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    1686 [ #  # ][ #  # ]:          0 :     SwNodeIndex aIdx( rDoc.GetNodes(), nSttNode );
    1687                 :            : 
    1688                 :          0 :     SwTableNode *const pTblNd = aIdx.GetNode().GetTableNode();
    1689                 :            :     OSL_ENSURE( pTblNd, "no TableNode" );
    1690                 :            : 
    1691         [ #  # ]:          0 :     SwTableFmlUpdate aMsgHnt( &pTblNd->GetTable() );
    1692                 :          0 :     aMsgHnt.eFlags = TBL_BOXPTR;
    1693         [ #  # ]:          0 :     rDoc.UpdateTblFlds( &aMsgHnt );
    1694                 :            : 
    1695                 :            :     CHECK_TABLE( pTblNd->GetTable() )
    1696                 :            : 
    1697         [ #  # ]:          0 :     _FndBox aTmpBox( 0, 0 );
    1698                 :            :     // ? TL_CHART2: notification or locking of controller required ?
    1699                 :            : 
    1700         [ #  # ]:          0 :     SwChartDataProvider *pPCD = rDoc.GetChartDataProvider();
    1701         [ #  # ]:          0 :     std::vector< SwTableBox* > aDelBoxes;
    1702 [ #  # ][ #  # ]:          0 :     if( IsDelBox() )
    1703                 :            :     {
    1704                 :            :         // Trick: add missing boxes in any line, they will be connected
    1705                 :            :         // correctly when calling CreateNew
    1706                 :          0 :         SwTableBox* pCpyBox = pTblNd->GetTable().GetTabSortBoxes()[0];
    1707                 :          0 :         SwTableBoxes& rLnBoxes = pCpyBox->GetUpper()->GetTabBoxes();
    1708                 :            : 
    1709                 :            :         // restore sections
    1710         [ #  # ]:          0 :         for( sal_uInt16 n = pDelSects->size(); n; )
    1711                 :            :         {
    1712         [ #  # ]:          0 :             SwUndoSaveSection* pSave = &(*pDelSects)[ --n ];
    1713         [ #  # ]:          0 :             pSave->RestoreSection( &rDoc, &aIdx, SwTableBoxStartNode );
    1714         [ #  # ]:          0 :             if( pSave->GetHistory() )
    1715         [ #  # ]:          0 :                 pSave->GetHistory()->Rollback( &rDoc );
    1716                 :            :             SwTableBox* pBox = new SwTableBox( (SwTableBoxFmt*)pCpyBox->GetFrmFmt(), aIdx,
    1717 [ #  # ][ #  # ]:          0 :                                                 pCpyBox->GetUpper() );
    1718         [ #  # ]:          0 :             rLnBoxes.push_back( pBox );
    1719                 :            :         }
    1720         [ #  # ]:          0 :         pDelSects->clear();
    1721                 :            :     }
    1722         [ #  # ]:          0 :     else if( !pNewSttNds->empty() )
    1723                 :            :     {
    1724                 :            :         // Than the nodes have be moved and not deleted!
    1725                 :            :         // But for that we need a temp array.
    1726         [ #  # ]:          0 :         std::vector<_BoxMove> aTmp( pNewSttNds->begin(), pNewSttNds->end() );
    1727                 :            : 
    1728                 :            :         // backwards
    1729         [ #  # ]:          0 :         for( int n = aTmp.size() - 1; n >= 0 ; --n)
    1730                 :            :         {
    1731                 :            :             // delete box from table structure
    1732                 :          0 :             sal_uLong nIdx = aTmp[n].index;
    1733         [ #  # ]:          0 :             SwTableBox* pBox = pTblNd->GetTable().GetTblBox( nIdx );
    1734                 :            :             OSL_ENSURE( pBox, "Where is my TableBox?" );
    1735                 :            : 
    1736                 :            :             // TL_CHART2: notify chart about box to be removed
    1737         [ #  # ]:          0 :             if (pPCD)
    1738         [ #  # ]:          0 :                 pPCD->DeleteBox( &pTblNd->GetTable(), *pBox );
    1739                 :            : 
    1740         [ #  # ]:          0 :             if( aTmp[n].hasMoved )
    1741                 :            :             {
    1742                 :          0 :                 SwNodeRange aRg( *pBox->GetSttNd(), 1,
    1743         [ #  # ]:          0 :                             *pBox->GetSttNd()->EndOfSectionNode() );
    1744                 :            : 
    1745         [ #  # ]:          0 :                 SwTableLine* pLine = lcl_FindTableLine( pTblNd->GetTable(), *pBox );
    1746         [ #  # ]:          0 :                 SwNodeIndex aInsPos( *(pLine->GetTabBoxes()[0]->GetSttNd()), 2 );
    1747                 :            : 
    1748                 :            :                 // adjust all StartNode indices
    1749                 :          0 :                 sal_uInt16 i = n;
    1750                 :          0 :                 sal_uLong nSttIdx = aInsPos.GetIndex() - 2,
    1751                 :          0 :                        nNdCnt = aRg.aEnd.GetIndex() - aRg.aStart.GetIndex();
    1752 [ #  # ][ #  # ]:          0 :                 while( i && aTmp[ --i ].index > nSttIdx )
                 [ #  # ]
    1753                 :          0 :                     aTmp[ i ].index += nNdCnt;
    1754                 :            : 
    1755                 :            :                 // first delete box
    1756 [ #  # ][ #  # ]:          0 :                 delete pBox;
    1757                 :            :                 // than move nodes
    1758 [ #  # ][ #  # ]:          0 :                 rDoc.GetNodes()._MoveNodes( aRg, rDoc.GetNodes(), aInsPos, sal_False );
         [ #  # ][ #  # ]
                 [ #  # ]
    1759                 :            :             }
    1760                 :            :             else
    1761 [ #  # ][ #  # ]:          0 :                 rDoc.DeleteSection( rDoc.GetNodes()[ nIdx ] );
                 [ #  # ]
    1762         [ #  # ]:          0 :             aDelBoxes.insert( aDelBoxes.end(), pBox );
    1763                 :          0 :         }
    1764                 :            :     }
    1765                 :            :     else
    1766                 :            :     {
    1767                 :            :         // Remove nodes from nodes array (backwards!)
    1768         [ #  # ]:          0 :         std::set<_BoxMove>::reverse_iterator it;
    1769 [ #  # ][ #  # ]:          0 :         for( it = pNewSttNds->rbegin(); it != pNewSttNds->rend(); ++it )
                 [ #  # ]
    1770                 :            :         {
    1771         [ #  # ]:          0 :             sal_uLong nIdx = (*it).index;
    1772         [ #  # ]:          0 :             SwTableBox* pBox = pTblNd->GetTable().GetTblBox( nIdx );
    1773                 :            :             OSL_ENSURE( pBox, "Where's my table box?" );
    1774                 :            :             // TL_CHART2: notify chart about box to be removed
    1775         [ #  # ]:          0 :             if (pPCD)
    1776         [ #  # ]:          0 :                 pPCD->DeleteBox( &pTblNd->GetTable(), *pBox );
    1777         [ #  # ]:          0 :             aDelBoxes.insert( aDelBoxes.end(), pBox );
    1778 [ #  # ][ #  # ]:          0 :             rDoc.DeleteSection( rDoc.GetNodes()[ nIdx ] );
                 [ #  # ]
    1779                 :            :         }
    1780                 :            :     }
    1781                 :            :     // Remove boxes from table structure
    1782         [ #  # ]:          0 :     for( sal_uInt16 n = 0; n < aDelBoxes.size(); ++n )
    1783                 :            :     {
    1784                 :          0 :         SwTableBox* pCurrBox = aDelBoxes[n];
    1785                 :          0 :         SwTableBoxes* pTBoxes = &pCurrBox->GetUpper()->GetTabBoxes();
    1786 [ #  # ][ #  # ]:          0 :         pTBoxes->erase( std::find( pTBoxes->begin(), pTBoxes->end(), pCurrBox ) );
    1787 [ #  # ][ #  # ]:          0 :         delete pCurrBox;
    1788                 :            :     }
    1789                 :            : 
    1790         [ #  # ]:          0 :     pSaveTbl->CreateNew( pTblNd->GetTable(), sal_True, sal_False );
    1791                 :            : 
    1792                 :            :     // TL_CHART2: need to inform chart of probably changed cell names
    1793         [ #  # ]:          0 :     rDoc.UpdateCharts( pTblNd->GetTable().GetFrmFmt()->GetName() );
    1794                 :            : 
    1795 [ #  # ][ #  # ]:          0 :     if( IsDelBox() )
    1796                 :          0 :         nSttNode = pTblNd->GetIndex();
    1797 [ #  # ][ #  # ]:          0 :     ClearFEShellTabCols();
         [ #  # ][ #  # ]
    1798                 :            :     CHECK_TABLE( pTblNd->GetTable() )
    1799                 :          0 : }
    1800                 :            : 
    1801                 :          0 : void SwUndoTblNdsChg::RedoImpl(::sw::UndoRedoContext & rContext)
    1802                 :            : {
    1803                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    1804                 :            : 
    1805 [ #  # ][ #  # ]:          0 :     SwTableNode* pTblNd = rDoc.GetNodes()[ nSttNode ]->GetTableNode();
    1806                 :            :     OSL_ENSURE( pTblNd, "no TableNode" );
    1807                 :            :     CHECK_TABLE( pTblNd->GetTable() )
    1808                 :            : 
    1809         [ #  # ]:          0 :     SwSelBoxes aSelBoxes;
    1810 [ #  # ][ #  # ]:          0 :     for( std::set<sal_uLong>::iterator it = aBoxes.begin(); it != aBoxes.end(); ++it )
                 [ #  # ]
    1811                 :            :     {
    1812 [ #  # ][ #  # ]:          0 :         SwTableBox* pBox = pTblNd->GetTable().GetTblBox( *it );
    1813         [ #  # ]:          0 :         aSelBoxes.insert( pBox );
    1814                 :            :     }
    1815                 :            : 
    1816                 :            :     // create SelBoxes and call InsertCell/-Row/SplitTbl
    1817 [ #  # ][ #  #  :          0 :     switch( GetId() )
                #  #  # ]
    1818                 :            :     {
    1819                 :            :     case UNDO_TABLE_INSCOL:
    1820         [ #  # ]:          0 :         if( USHRT_MAX == nSetColType )
    1821         [ #  # ]:          0 :             rDoc.InsertCol( aSelBoxes, nCount, bFlag );
    1822                 :            :         else
    1823                 :            :         {
    1824         [ #  # ]:          0 :             SwTableBox* pBox = pTblNd->GetTable().GetTblBox( nCurrBox );
    1825                 :            :             rDoc.SetColRowWidthHeight( *pBox, nSetColType, nAbsDiff,
    1826         [ #  # ]:          0 :                                         nRelDiff );
    1827                 :            :         }
    1828                 :          0 :         break;
    1829                 :            : 
    1830                 :            :     case UNDO_TABLE_INSROW:
    1831         [ #  # ]:          0 :         if( USHRT_MAX == nSetColType )
    1832         [ #  # ]:          0 :             rDoc.InsertRow( aSelBoxes, nCount, bFlag );
    1833                 :            :         else
    1834                 :            :         {
    1835                 :          0 :             SwTable& rTbl = pTblNd->GetTable();
    1836         [ #  # ]:          0 :             SwTableBox* pBox = rTbl.GetTblBox( nCurrBox );
    1837                 :          0 :             TblChgMode eOldMode = rTbl.GetTblChgMode();
    1838                 :          0 :             rTbl.SetTblChgMode( (TblChgMode)nCount );
    1839         [ #  # ]:          0 :             rDoc.SetColRowWidthHeight( *pBox, nSetColType, nAbsDiff, nRelDiff );
    1840                 :          0 :             rTbl.SetTblChgMode( eOldMode );
    1841                 :            :         }
    1842                 :          0 :         break;
    1843                 :            : 
    1844                 :            :     case UNDO_TABLE_SPLIT:
    1845         [ #  # ]:          0 :         rDoc.SplitTbl( aSelBoxes, bFlag, nCount, bSameHeight );
    1846                 :          0 :         break;
    1847                 :            :     case UNDO_TABLE_DELBOX:
    1848                 :            :     case UNDO_ROW_DELETE:
    1849                 :            :     case UNDO_COL_DELETE:
    1850         [ #  # ]:          0 :         if( USHRT_MAX == nSetColType )
    1851                 :            :         {
    1852         [ #  # ]:          0 :             SwTableFmlUpdate aMsgHnt( &pTblNd->GetTable() );
    1853                 :          0 :             aMsgHnt.eFlags = TBL_BOXPTR;
    1854         [ #  # ]:          0 :             rDoc.UpdateTblFlds( &aMsgHnt );
    1855                 :          0 :             SwTable &rTable = pTblNd->GetTable();
    1856 [ #  # ][ #  # ]:          0 :             if( nMax > nMin && rTable.IsNewModel() )
                 [ #  # ]
    1857         [ #  # ]:          0 :                 rTable.PrepareDeleteCol( nMin, nMax );
    1858 [ #  # ][ #  # ]:          0 :             rTable.DeleteSel( &rDoc, aSelBoxes, 0, this, sal_True, sal_True );
    1859                 :            :         }
    1860                 :            :         else
    1861                 :            :         {
    1862                 :          0 :             SwTable& rTbl = pTblNd->GetTable();
    1863                 :            : 
    1864         [ #  # ]:          0 :             SwTableFmlUpdate aMsgHnt( &rTbl );
    1865                 :          0 :             aMsgHnt.eFlags = TBL_BOXPTR;
    1866         [ #  # ]:          0 :             rDoc.UpdateTblFlds( &aMsgHnt );
    1867                 :            : 
    1868         [ #  # ]:          0 :             SwTableBox* pBox = rTbl.GetTblBox( nCurrBox );
    1869                 :          0 :             TblChgMode eOldMode = rTbl.GetTblChgMode();
    1870                 :          0 :             rTbl.SetTblChgMode( (TblChgMode)nCount );
    1871                 :            : 
    1872                 :            :             // need the SaveSections!
    1873 [ #  # ][ #  # ]:          0 :             rDoc.GetIDocumentUndoRedo().DoUndo( true );
    1874                 :          0 :             SwUndoTblNdsChg* pUndo = 0;
    1875                 :            : 
    1876      [ #  #  # ]:          0 :             switch( nSetColType & 0xff )
    1877                 :            :             {
    1878                 :            :             case nsTblChgWidthHeightType::WH_COL_LEFT:
    1879                 :            :             case nsTblChgWidthHeightType::WH_COL_RIGHT:
    1880                 :            :             case nsTblChgWidthHeightType::WH_CELL_LEFT:
    1881                 :            :             case nsTblChgWidthHeightType::WH_CELL_RIGHT:
    1882                 :            :                  rTbl.SetColWidth( *pBox, nSetColType, nAbsDiff,
    1883         [ #  # ]:          0 :                                     nRelDiff, (SwUndo**)&pUndo );
    1884                 :          0 :                 break;
    1885                 :            :             case nsTblChgWidthHeightType::WH_ROW_TOP:
    1886                 :            :             case nsTblChgWidthHeightType::WH_ROW_BOTTOM:
    1887                 :            :             case nsTblChgWidthHeightType::WH_CELL_TOP:
    1888                 :            :             case nsTblChgWidthHeightType::WH_CELL_BOTTOM:
    1889                 :            :                 rTbl.SetRowHeight( *pBox, nSetColType, nAbsDiff,
    1890         [ #  # ]:          0 :                                     nRelDiff, (SwUndo**)&pUndo );
    1891                 :          0 :                 break;
    1892                 :            :             }
    1893                 :            : 
    1894         [ #  # ]:          0 :             if( pUndo )
    1895                 :            :             {
    1896 [ #  # ][ #  # ]:          0 :                 pDelSects->transfer( pDelSects->begin(), *pUndo->pDelSects.get() );
    1897 [ #  # ][ #  # ]:          0 :                 delete pUndo;
    1898                 :            :             }
    1899 [ #  # ][ #  # ]:          0 :             rDoc.GetIDocumentUndoRedo().DoUndo( false );
    1900                 :            : 
    1901         [ #  # ]:          0 :             rTbl.SetTblChgMode( eOldMode );
    1902                 :            :         }
    1903                 :          0 :         nSttNode = pTblNd->GetIndex();
    1904                 :          0 :         break;
    1905                 :            :     default:
    1906                 :            :         ;
    1907                 :            :     }
    1908         [ #  # ]:          0 :     ClearFEShellTabCols();
    1909                 :            :     CHECK_TABLE( pTblNd->GetTable() )
    1910                 :          0 : }
    1911                 :            : 
    1912                 :          2 : SwUndoTblMerge::SwUndoTblMerge( const SwPaM& rTblSel )
    1913 [ +  - ][ +  - ]:          2 :     : SwUndo( UNDO_TABLE_MERGE ), SwUndRng( rTblSel ), pHistory( 0 )
                 [ +  - ]
    1914                 :            : {
    1915         [ +  - ]:          2 :     const SwTableNode* pTblNd = rTblSel.GetNode()->FindTableNode();
    1916                 :            :     OSL_ENSURE( pTblNd, "Where is the TableNode?" );
    1917 [ +  - ][ +  - ]:          2 :     pSaveTbl = new _SaveTable( pTblNd->GetTable() );
    1918 [ +  - ][ +  - ]:          2 :     pMoves = new SwUndoMoves;
    1919                 :          2 :     nTblNode = pTblNd->GetIndex();
    1920                 :          2 : }
    1921                 :            : 
    1922                 :          2 : SwUndoTblMerge::~SwUndoTblMerge()
    1923                 :            : {
    1924 [ +  - ][ +  - ]:          2 :     delete pSaveTbl;
    1925 [ +  - ][ +  - ]:          2 :     delete pMoves;
    1926 [ -  + ][ #  # ]:          2 :     delete pHistory;
    1927         [ -  + ]:          4 : }
    1928                 :            : 
    1929                 :          0 : void SwUndoTblMerge::UndoImpl(::sw::UndoRedoContext & rContext)
    1930                 :            : {
    1931                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    1932 [ #  # ][ #  # ]:          0 :     SwNodeIndex aIdx( rDoc.GetNodes(), nTblNode );
    1933                 :            : 
    1934                 :          0 :     SwTableNode *const pTblNd = aIdx.GetNode().GetTableNode();
    1935                 :            :     OSL_ENSURE( pTblNd, "no TableNode" );
    1936                 :            : 
    1937         [ #  # ]:          0 :     SwTableFmlUpdate aMsgHnt( &pTblNd->GetTable() );
    1938                 :          0 :     aMsgHnt.eFlags = TBL_BOXPTR;
    1939         [ #  # ]:          0 :     rDoc.UpdateTblFlds( &aMsgHnt );
    1940                 :            : 
    1941         [ #  # ]:          0 :     _FndBox aTmpBox( 0, 0 );
    1942                 :            :     // ? TL_CHART2: notification or locking of controller required ?
    1943                 :            : 
    1944                 :            :     // 1. restore deleted boxes:
    1945                 :            :     // Trick: add missing boxes in any line, they will be connected
    1946                 :            :     // correctly when calling CreateNew
    1947                 :          0 :     SwTableBox *pBox, *pCpyBox = pTblNd->GetTable().GetTabSortBoxes()[0];
    1948                 :          0 :     SwTableBoxes& rLnBoxes = pCpyBox->GetUpper()->GetTabBoxes();
    1949                 :            : 
    1950                 :            : CHECKTABLE(pTblNd->GetTable())
    1951                 :            : 
    1952         [ #  # ]:          0 :     SwSelBoxes aSelBoxes;
    1953         [ #  # ]:          0 :     SwTxtFmtColl* pColl = rDoc.GetTxtCollFromPool( RES_POOLCOLL_STANDARD );
    1954                 :            :     sal_uInt16 n;
    1955                 :            : 
    1956         [ #  # ]:          0 :     std::set<sal_uLong>::iterator it;
    1957 [ #  # ][ #  # ]:          0 :     for( it = aBoxes.begin(); it != aBoxes.end(); ++it )
                 [ #  # ]
    1958                 :            :     {
    1959 [ #  # ][ #  # ]:          0 :         aIdx = *it;
    1960         [ #  # ]:          0 :         SwStartNode* pSttNd = rDoc.GetNodes().MakeTextSection( aIdx,
    1961         [ #  # ]:          0 :                                             SwTableBoxStartNode, pColl );
    1962                 :            :         pBox = new SwTableBox( (SwTableBoxFmt*)pCpyBox->GetFrmFmt(), *pSttNd,
    1963 [ #  # ][ #  # ]:          0 :                                 pCpyBox->GetUpper() );
    1964         [ #  # ]:          0 :         rLnBoxes.push_back( pBox );
    1965                 :            : 
    1966         [ #  # ]:          0 :         aSelBoxes.insert( pBox );
    1967                 :            :     }
    1968                 :            : 
    1969                 :            : CHECKTABLE(pTblNd->GetTable())
    1970                 :            : 
    1971         [ #  # ]:          0 :     SwChartDataProvider *pPCD = rDoc.GetChartDataProvider();
    1972                 :            :     // 2. deleted the inserted boxes
    1973                 :            :     // delete nodes (from last to first)
    1974         [ #  # ]:          0 :     for( n = aNewSttNds.size(); n; )
    1975                 :            :     {
    1976                 :            :         // remove box from table structure
    1977         [ #  # ]:          0 :         sal_uLong nIdx = aNewSttNds[ --n ];
    1978                 :            : 
    1979 [ #  # ][ #  # ]:          0 :         if( !nIdx && n )
    1980                 :            :         {
    1981         [ #  # ]:          0 :             nIdx = aNewSttNds[ --n ];
    1982         [ #  # ]:          0 :             pBox = pTblNd->GetTable().GetTblBox( nIdx );
    1983                 :            :             OSL_ENSURE( pBox, "Where is my TableBox?" );
    1984                 :            : 
    1985         [ #  # ]:          0 :             if( !pSaveTbl->IsNewModel() )
    1986         [ #  # ]:          0 :                 rDoc.GetNodes().MakeTxtNode( SwNodeIndex(
    1987 [ #  # ][ #  # ]:          0 :                     *pBox->GetSttNd()->EndOfSectionNode() ), pColl );
                 [ #  # ]
    1988                 :            : 
    1989                 :            :             // this was the separator -> restore moved ones
    1990         [ #  # ]:          0 :             for( sal_uInt16 i = pMoves->size(); i; )
    1991                 :            :             {
    1992                 :          0 :                 SwTxtNode* pTxtNd = 0;
    1993                 :          0 :                 sal_uInt16 nDelPos = 0;
    1994         [ #  # ]:          0 :                 SwUndoMove* pUndo = &(*pMoves)[ --i ];
    1995         [ #  # ]:          0 :                 if( !pUndo->IsMoveRange() )
    1996                 :            :                 {
    1997 [ #  # ][ #  # ]:          0 :                     pTxtNd = rDoc.GetNodes()[ pUndo->GetDestSttNode() ]->GetTxtNode();
    1998                 :          0 :                     nDelPos = pUndo->GetDestSttCntnt() - 1;
    1999                 :            :                 }
    2000         [ #  # ]:          0 :                 pUndo->UndoImpl(rContext);
    2001         [ #  # ]:          0 :                 if( pUndo->IsMoveRange() )
    2002                 :            :                 {
    2003                 :            :                     // delete the unnecessary node
    2004         [ #  # ]:          0 :                     aIdx = pUndo->GetEndNode();
    2005                 :          0 :                     SwCntntNode *pCNd = aIdx.GetNode().GetCntntNode();
    2006         [ #  # ]:          0 :                     if( pCNd )
    2007                 :            :                     {
    2008         [ #  # ]:          0 :                         SwNodeIndex aTmp( aIdx, -1 );
    2009                 :          0 :                         SwCntntNode *pMove = aTmp.GetNode().GetCntntNode();
    2010         [ #  # ]:          0 :                         if( pMove )
    2011 [ #  # ][ #  # ]:          0 :                             pCNd->MoveTo( *pMove );
    2012                 :            :                     }
    2013 [ #  # ][ #  # ]:          0 :                     rDoc.GetNodes().Delete( aIdx, 1 );
    2014                 :            :                 }
    2015         [ #  # ]:          0 :                 else if( pTxtNd )
    2016                 :            :                 {
    2017                 :            :                     // also delete not needed attributes
    2018 [ #  # ][ #  # ]:          0 :                     SwIndex aTmpIdx( pTxtNd, nDelPos );
    2019 [ #  # ][ #  # ]:          0 :                     if( pTxtNd->GetpSwpHints() && pTxtNd->GetpSwpHints()->Count() )
                 [ #  # ]
    2020                 :          0 :                         pTxtNd->RstAttr( aTmpIdx, pTxtNd->GetTxt().Len() -
    2021         [ #  # ]:          0 :                                                             nDelPos + 1 );
    2022                 :            :                     // delete separator
    2023 [ #  # ][ #  # ]:          0 :                     pTxtNd->EraseText( aTmpIdx, 1 );
    2024                 :            :                 }
    2025                 :            :             }
    2026         [ #  # ]:          0 :             nIdx = pBox->GetSttIdx();
    2027                 :            :         }
    2028                 :            :         else
    2029         [ #  # ]:          0 :             pBox = pTblNd->GetTable().GetTblBox( nIdx );
    2030                 :            : 
    2031         [ #  # ]:          0 :         if( !pSaveTbl->IsNewModel() )
    2032                 :            :         {
    2033                 :            :             // TL_CHART2: notify chart about box to be removed
    2034         [ #  # ]:          0 :             if (pPCD)
    2035         [ #  # ]:          0 :                 pPCD->DeleteBox( &pTblNd->GetTable(), *pBox );
    2036                 :            : 
    2037                 :          0 :             SwTableBoxes* pTBoxes = &pBox->GetUpper()->GetTabBoxes();
    2038 [ #  # ][ #  # ]:          0 :             pTBoxes->erase( std::find(pTBoxes->begin(), pTBoxes->end(), pBox ) );
    2039                 :            : 
    2040                 :            :             // delete indices from section
    2041                 :            :             {
    2042         [ #  # ]:          0 :                 SwNodeIndex aTmpIdx( *pBox->GetSttNd() );
    2043                 :            :                 rDoc.CorrAbs( SwNodeIndex( aTmpIdx, 1 ),
    2044                 :          0 :                             SwNodeIndex( *aTmpIdx.GetNode().EndOfSectionNode() ),
    2045         [ #  # ]:          0 :                             SwPosition( aTmpIdx, SwIndex( 0, 0 )), sal_True );
           [ #  #  #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    2046                 :            :             }
    2047                 :            : 
    2048 [ #  # ][ #  # ]:          0 :             delete pBox;
    2049 [ #  # ][ #  # ]:          0 :             rDoc.DeleteSection( rDoc.GetNodes()[ nIdx ] );
                 [ #  # ]
    2050                 :            :         }
    2051                 :            :     }
    2052                 :            : CHECKTABLE(pTblNd->GetTable())
    2053                 :            : 
    2054         [ #  # ]:          0 :     pSaveTbl->CreateNew( pTblNd->GetTable(), sal_True, sal_False );
    2055                 :            : 
    2056                 :            :     // TL_CHART2: need to inform chart of probably changed cell names
    2057         [ #  # ]:          0 :     rDoc.UpdateCharts( pTblNd->GetTable().GetFrmFmt()->GetName() );
    2058                 :            : 
    2059         [ #  # ]:          0 :     if( pHistory )
    2060                 :            :     {
    2061         [ #  # ]:          0 :         pHistory->TmpRollback( &rDoc, 0 );
    2062         [ #  # ]:          0 :         pHistory->SetTmpEnd( pHistory->Count() );
    2063                 :            :     }
    2064         [ #  # ]:          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    2065         [ #  # ]:          0 :     pPam->DeleteMark();
    2066         [ #  # ]:          0 :     pPam->GetPoint()->nNode = nSttNode;
    2067 [ #  # ][ #  # ]:          0 :     pPam->GetPoint()->nContent.Assign( pPam->GetCntntNode(), nSttCntnt );
    2068         [ #  # ]:          0 :     pPam->SetMark();
    2069         [ #  # ]:          0 :     pPam->DeleteMark();
    2070                 :            : 
    2071                 :            : CHECKTABLE(pTblNd->GetTable())
    2072 [ #  # ][ #  # ]:          0 :     ClearFEShellTabCols();
         [ #  # ][ #  # ]
    2073                 :          0 : }
    2074                 :            : 
    2075                 :          0 : void SwUndoTblMerge::RedoImpl(::sw::UndoRedoContext & rContext)
    2076                 :            : {
    2077                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    2078                 :          0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
    2079                 :          0 :     rDoc.MergeTbl(rPam);
    2080                 :          0 : }
    2081                 :            : 
    2082                 :          0 : void SwUndoTblMerge::MoveBoxCntnt( SwDoc* pDoc, SwNodeRange& rRg, SwNodeIndex& rPos )
    2083                 :            : {
    2084 [ #  # ][ #  # ]:          0 :     SwNodeIndex aTmp( rRg.aStart, -1 ), aTmp2( rPos, -1 );
    2085 [ #  # ][ #  # ]:          0 :     SwUndoMove* pUndo = new SwUndoMove( pDoc, rRg, rPos );
    2086 [ #  # ][ #  # ]:          0 :     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
    2087                 :          0 :     pDoc->MoveNodeRange( rRg, rPos, (pSaveTbl->IsNewModel()) ?
    2088                 :            :         IDocumentContentOperations::DOC_NO_DELFRMS :
    2089 [ #  # ][ #  # ]:          0 :         IDocumentContentOperations::DOC_MOVEDEFAULT );
    2090         [ #  # ]:          0 :     aTmp++;
    2091         [ #  # ]:          0 :     aTmp2++;
    2092         [ #  # ]:          0 :     pUndo->SetDestRange( aTmp2, rPos, aTmp );
    2093                 :            : 
    2094 [ #  # ][ #  # ]:          0 :     pMoves->push_back( pUndo );
         [ #  # ][ #  # ]
    2095                 :          0 : }
    2096                 :            : 
    2097                 :          2 : void SwUndoTblMerge::SetSelBoxes( const SwSelBoxes& rBoxes )
    2098                 :            : {
    2099                 :            :     // memorize selection
    2100         [ +  + ]:          8 :     for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
    2101         [ +  - ]:          6 :         aBoxes.insert( rBoxes[n]->GetSttIdx() );
    2102                 :            : 
    2103                 :            :     // as separator for inserts of new boxes after shifting
    2104         [ +  - ]:          2 :     aNewSttNds.push_back( (sal_uLong)0 );
    2105                 :            : 
    2106                 :            :     // The new table model does not delete overlapped cells (by row span),
    2107                 :            :     // so the rBoxes array might be empty even some cells have been merged.
    2108         [ +  - ]:          2 :     if( !rBoxes.empty() )
    2109                 :          2 :         nTblNode = rBoxes[ 0 ]->GetSttNd()->FindTableNode()->GetIndex();
    2110                 :          2 : }
    2111                 :            : 
    2112                 :          0 : void SwUndoTblMerge::SaveCollection( const SwTableBox& rBox )
    2113                 :            : {
    2114         [ #  # ]:          0 :     if( !pHistory )
    2115 [ #  # ][ #  # ]:          0 :         pHistory = new SwHistory;
    2116                 :            : 
    2117         [ #  # ]:          0 :     SwNodeIndex aIdx( *rBox.GetSttNd(), 1 );
    2118                 :          0 :     SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
    2119         [ #  # ]:          0 :     if( !pCNd )
    2120         [ #  # ]:          0 :         pCNd = aIdx.GetNodes().GoNext( &aIdx );
    2121                 :            : 
    2122         [ #  # ]:          0 :     pHistory->Add( pCNd->GetFmtColl(), aIdx.GetIndex(), pCNd->GetNodeType());
    2123 [ #  # ][ #  # ]:          0 :     if( pCNd->HasSwAttrSet() )
    2124 [ #  # ][ #  # ]:          0 :         pHistory->CopyFmtAttr( *pCNd->GetpSwAttrSet(), aIdx.GetIndex() );
                 [ #  # ]
    2125                 :          0 : }
    2126                 :            : 
    2127                 :        146 : SwUndoTblNumFmt::SwUndoTblNumFmt( const SwTableBox& rBox,
    2128                 :            :                                     const SfxItemSet* pNewSet )
    2129                 :            :     : SwUndo( UNDO_TBLNUMFMT ),
    2130 [ +  - ][ +  - ]:        146 :     pBoxSet( 0 ), pHistory( 0 ), nFmtIdx( NUMBERFORMAT_TEXT )
    2131                 :            : {
    2132                 :        146 :     bNewFmt = bNewFml = bNewValue = sal_False;
    2133         [ +  - ]:        146 :     nNode = rBox.GetSttIdx();
    2134                 :            : 
    2135         [ +  - ]:        146 :     nNdPos = rBox.IsValidNumTxtNd( 0 == pNewSet );
    2136                 :        146 :     SwDoc* pDoc = rBox.GetFrmFmt()->GetDoc();
    2137                 :            : 
    2138         [ +  - ]:        146 :     if( ULONG_MAX != nNdPos )
    2139                 :            :     {
    2140 [ +  - ][ +  - ]:        146 :         SwTxtNode* pTNd = pDoc->GetNodes()[ nNdPos ]->GetTxtNode();
    2141                 :            : 
    2142 [ +  - ][ +  - ]:        146 :         pHistory = new SwHistory;
    2143         [ +  - ]:        146 :         SwRegHistory aRHst( *rBox.GetSttNd(), pHistory );
    2144                 :            :         // always save all text atttibutes because of possibly overlapping
    2145                 :            :         // areas of on/off
    2146                 :            :         pHistory->CopyAttr( pTNd->GetpSwpHints(), nNdPos, 0,
    2147         [ +  - ]:        146 :                             pTNd->GetTxt().Len(), true );
    2148                 :            : 
    2149 [ +  - ][ +  + ]:        146 :         if( pTNd->HasSwAttrSet() )
    2150 [ +  - ][ +  - ]:         80 :             pHistory->CopyFmtAttr( *pTNd->GetpSwAttrSet(), nNdPos );
    2151                 :            : 
    2152         [ +  - ]:        146 :         aStr = pTNd->GetTxt();
    2153         [ +  + ]:        146 :         if( pTNd->GetpSwpHints() )
    2154         [ +  - ]:        146 :             pTNd->GetpSwpHints()->DeRegister();
    2155                 :            :     }
    2156                 :            : 
    2157 [ +  - ][ +  - ]:        146 :     pBoxSet = new SfxItemSet( pDoc->GetAttrPool(), aTableBoxSetRange );
    2158         [ +  - ]:        146 :     pBoxSet->Put( rBox.GetFrmFmt()->GetAttrSet() );
    2159                 :            : 
    2160         [ +  + ]:        146 :     if( pNewSet )
    2161                 :            :     {
    2162                 :            :         const SfxPoolItem* pItem;
    2163         [ +  + ]:        144 :         if( SFX_ITEM_SET == pNewSet->GetItemState( RES_BOXATR_FORMAT,
    2164         [ +  - ]:        144 :                 sal_False, &pItem ))
    2165                 :            :         {
    2166                 :        134 :             bNewFmt = sal_True;
    2167                 :        134 :             nNewFmtIdx = ((SwTblBoxNumFormat*)pItem)->GetValue();
    2168                 :            :         }
    2169         [ -  + ]:        144 :         if( SFX_ITEM_SET == pNewSet->GetItemState( RES_BOXATR_FORMULA,
    2170         [ +  - ]:        144 :                 sal_False, &pItem ))
    2171                 :            :         {
    2172                 :          0 :             bNewFml = sal_True;
    2173         [ #  # ]:          0 :             aNewFml = ((SwTblBoxFormula*)pItem)->GetFormula();
    2174                 :            :         }
    2175         [ +  - ]:        144 :         if( SFX_ITEM_SET == pNewSet->GetItemState( RES_BOXATR_VALUE,
    2176         [ +  - ]:        144 :                 sal_False, &pItem ))
    2177                 :            :         {
    2178                 :        144 :             bNewValue = sal_True;
    2179                 :        144 :             fNewNum = ((SwTblBoxValue*)pItem)->GetValue();
    2180                 :            :         }
    2181                 :            :     }
    2182                 :            : 
    2183                 :            :     // is a history needed at all?
    2184 [ +  - ][ +  + ]:        146 :     if( pHistory && !pHistory->Count() )
                 [ +  + ]
    2185 [ +  - ][ +  - ]:         66 :         DELETEZ( pHistory );
    2186                 :        146 : }
    2187                 :            : 
    2188 [ +  - ][ +  - ]:        146 : SwUndoTblNumFmt::~SwUndoTblNumFmt()
    2189                 :            : {
    2190 [ +  + ][ +  - ]:        146 :     delete pHistory;
    2191 [ +  - ][ +  - ]:        146 :     delete pBoxSet;
    2192         [ -  + ]:        292 : }
    2193                 :            : 
    2194                 :          0 : void SwUndoTblNumFmt::UndoImpl(::sw::UndoRedoContext & rContext)
    2195                 :            : {
    2196                 :            :     OSL_ENSURE( pBoxSet, "Where's the stored item set?" );
    2197                 :            : 
    2198                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    2199                 :          0 :     SwStartNode* pSttNd = rDoc.GetNodes()[ nNode ]->
    2200                 :          0 :                             FindSttNodeByType( SwTableBoxStartNode );
    2201                 :            :     OSL_ENSURE( pSttNd, "without StartNode no TableBox" );
    2202                 :          0 :     SwTableBox* pBox = pSttNd->FindTableNode()->GetTable().GetTblBox(
    2203                 :          0 :                                     pSttNd->GetIndex() );
    2204                 :            :     OSL_ENSURE( pBox, "found no TableBox" );
    2205                 :            : 
    2206                 :          0 :     SwTableBoxFmt* pFmt = rDoc.MakeTableBoxFmt();
    2207                 :          0 :     pFmt->SetFmtAttr( *pBoxSet );
    2208                 :          0 :     pBox->ChgFrmFmt( pFmt );
    2209                 :            : 
    2210         [ #  # ]:          0 :     if( ULONG_MAX == nNdPos )
    2211                 :          0 :         return;
    2212                 :            : 
    2213                 :          0 :     SwTxtNode* pTxtNd = rDoc.GetNodes()[ nNdPos ]->GetTxtNode();
    2214                 :            :     // If more than one node was deleted than all "node" attributes were also
    2215                 :            :     // saved
    2216         [ #  # ]:          0 :     if( pTxtNd->HasSwAttrSet() )
    2217                 :          0 :         pTxtNd->ResetAllAttr();
    2218                 :            : 
    2219 [ #  # ][ #  # ]:          0 :     if( pTxtNd->GetpSwpHints() && aStr.Len() )
                 [ #  # ]
    2220                 :          0 :         pTxtNd->ClearSwpHintsArr( true );
    2221                 :            : 
    2222                 :            :     // ChgTextToNum(..) only acts when the strings are different. We need to do
    2223                 :            :     // the same here.
    2224         [ #  # ]:          0 :     if( pTxtNd->GetTxt() != aStr )
    2225                 :            :     {
    2226         [ #  # ]:          0 :         rDoc.DeleteRedline( *( pBox->GetSttNd() ), false, USHRT_MAX );
    2227                 :            : 
    2228 [ #  # ][ #  # ]:          0 :         SwIndex aIdx( pTxtNd, 0 );
    2229         [ #  # ]:          0 :         if( aStr.Len() )
    2230                 :            :         {
    2231         [ #  # ]:          0 :             pTxtNd->EraseText( aIdx );
    2232                 :            :             pTxtNd->InsertText( aStr, aIdx,
    2233         [ #  # ]:          0 :                 IDocumentContentOperations::INS_NOHINTEXPAND );
    2234         [ #  # ]:          0 :         }
    2235                 :            :     }
    2236                 :            : 
    2237         [ #  # ]:          0 :     if( pHistory )
    2238                 :            :     {
    2239                 :          0 :         sal_uInt16 nTmpEnd = pHistory->GetTmpEnd();
    2240                 :          0 :         pHistory->TmpRollback( &rDoc, 0 );
    2241                 :          0 :         pHistory->SetTmpEnd( nTmpEnd );
    2242                 :            :     }
    2243                 :            : 
    2244                 :          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    2245                 :          0 :     pPam->DeleteMark();
    2246                 :          0 :     pPam->GetPoint()->nNode = nNode + 1;
    2247         [ #  # ]:          0 :     pPam->GetPoint()->nContent.Assign( pTxtNd, 0 );
    2248                 :            : }
    2249                 :            : 
    2250                 :            : /** switch the RedlineMode on the given document, using
    2251                 :            :  * SetRedlineMode_intern. This class set the mode in the constructor,
    2252                 :            :  * and changes it back in the destructor, i.e. it uses the
    2253                 :            :  * initialization-is-resource-acquisition idiom.
    2254                 :            :  */
    2255                 :            : class RedlineModeInternGuard
    2256                 :            : {
    2257                 :            :     SwDoc& mrDoc;
    2258                 :            :     RedlineMode_t meOldRedlineMode;
    2259                 :            : 
    2260                 :            : public:
    2261                 :            :     RedlineModeInternGuard(
    2262                 :            :         SwDoc& rDoc,                      // change mode of this document
    2263                 :            :         RedlineMode_t eNewRedlineMode,    // new redline mode
    2264                 :            :         RedlineMode_t eRedlineModeMask  = (RedlineMode_t)(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_IGNORE /*change only bits set in this mask*/));
    2265                 :            : 
    2266                 :            :     ~RedlineModeInternGuard();
    2267                 :            : };
    2268                 :            : 
    2269                 :          0 : RedlineModeInternGuard::RedlineModeInternGuard(
    2270                 :            :     SwDoc& rDoc,
    2271                 :            :     RedlineMode_t eNewRedlineMode,
    2272                 :            :     RedlineMode_t eRedlineModeMask )
    2273                 :            :     : mrDoc( rDoc ),
    2274                 :          0 :       meOldRedlineMode( rDoc.GetRedlineMode() )
    2275                 :            : {
    2276                 :            :     mrDoc.SetRedlineMode_intern((RedlineMode_t)( ( meOldRedlineMode & ~eRedlineModeMask ) |
    2277                 :          0 :                                      ( eNewRedlineMode & eRedlineModeMask ) ));
    2278                 :          0 : }
    2279                 :            : 
    2280                 :          0 : RedlineModeInternGuard::~RedlineModeInternGuard()
    2281                 :            : {
    2282                 :          0 :     mrDoc.SetRedlineMode_intern( meOldRedlineMode );
    2283                 :          0 : }
    2284                 :            : 
    2285                 :          0 : void SwUndoTblNumFmt::RedoImpl(::sw::UndoRedoContext & rContext)
    2286                 :            : {
    2287                 :            :     // Could the box be changed?
    2288         [ #  # ]:          0 :     if( !pBoxSet )
    2289                 :          0 :         return ;
    2290                 :            : 
    2291                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    2292                 :          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    2293                 :            : 
    2294                 :          0 :     pPam->DeleteMark();
    2295                 :          0 :     pPam->GetPoint()->nNode = nNode;
    2296                 :            : 
    2297                 :          0 :     SwNode * pNd = & pPam->GetPoint()->nNode.GetNode();
    2298                 :          0 :     SwStartNode* pSttNd = pNd->FindSttNodeByType( SwTableBoxStartNode );
    2299                 :            :     OSL_ENSURE( pSttNd, "without StartNode no TableBox" );
    2300                 :          0 :     SwTableBox* pBox = pSttNd->FindTableNode()->GetTable().GetTblBox(
    2301                 :          0 :                                     pSttNd->GetIndex() );
    2302                 :            :     OSL_ENSURE( pBox, "found no TableBox" );
    2303                 :            : 
    2304                 :          0 :     SwFrmFmt* pBoxFmt = pBox->ClaimFrmFmt();
    2305 [ #  # ][ #  # ]:          0 :     if( bNewFmt || bNewFml || bNewValue )
                 [ #  # ]
    2306                 :            :     {
    2307                 :          0 :         SfxItemSet aBoxSet( rDoc.GetAttrPool(),
    2308         [ #  # ]:          0 :                                 RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
    2309                 :            : 
    2310                 :            :         // Resetting attributes is not enough. In addition, take care that the
    2311                 :            :         // text will be also formatted correctly.
    2312                 :          0 :         pBoxFmt->LockModify();
    2313                 :            : 
    2314         [ #  # ]:          0 :         if( bNewFml )
    2315 [ #  # ][ #  # ]:          0 :             aBoxSet.Put( SwTblBoxFormula( aNewFml ));
                 [ #  # ]
    2316                 :            :         else
    2317         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMULA );
    2318         [ #  # ]:          0 :         if( bNewFmt )
    2319 [ #  # ][ #  # ]:          0 :             aBoxSet.Put( SwTblBoxNumFormat( nNewFmtIdx ));
                 [ #  # ]
    2320                 :            :         else
    2321         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMAT );
    2322         [ #  # ]:          0 :         if( bNewValue )
    2323 [ #  # ][ #  # ]:          0 :             aBoxSet.Put( SwTblBoxValue( fNewNum ));
                 [ #  # ]
    2324                 :            :         else
    2325         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
    2326                 :          0 :         pBoxFmt->UnlockModify();
    2327                 :            : 
    2328                 :            :         // dvo: When redlining is (was) enabled, setting the attribute
    2329                 :            :         // will also change the cell content. To allow this, the
    2330                 :            :         // REDLINE_IGNORE flag must be removed during Redo. #108450#
    2331         [ #  # ]:          0 :         RedlineModeInternGuard aGuard( rDoc, nsRedlineMode_t::REDLINE_NONE, nsRedlineMode_t::REDLINE_IGNORE );
    2332 [ #  # ][ #  # ]:          0 :         pBoxFmt->SetFmtAttr( aBoxSet );
                 [ #  # ]
    2333                 :            :     }
    2334         [ #  # ]:          0 :     else if( NUMBERFORMAT_TEXT != nFmtIdx )
    2335                 :            :     {
    2336                 :          0 :         SfxItemSet aBoxSet( rDoc.GetAttrPool(),
    2337         [ #  # ]:          0 :                             RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
    2338                 :            : 
    2339 [ #  # ][ #  # ]:          0 :         aBoxSet.Put( SwTblBoxNumFormat( nFmtIdx ));
                 [ #  # ]
    2340 [ #  # ][ #  # ]:          0 :         aBoxSet.Put( SwTblBoxValue( fNum ));
                 [ #  # ]
    2341                 :            : 
    2342                 :            :         // Resetting attributes is not enough. In addition, take care that the
    2343                 :            :         // text will be also formatted correctly.
    2344                 :          0 :         pBoxFmt->LockModify();
    2345         [ #  # ]:          0 :         pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMULA );
    2346                 :          0 :         pBoxFmt->UnlockModify();
    2347                 :            : 
    2348                 :            :         // dvo: When redlining is (was) enabled, setting the attribute
    2349                 :            :         // will also change the cell content. To allow this, the
    2350                 :            :         // REDLINE_IGNORE flag must be removed during Redo. #108450#
    2351         [ #  # ]:          0 :         RedlineModeInternGuard aGuard( rDoc, nsRedlineMode_t::REDLINE_NONE, nsRedlineMode_t::REDLINE_IGNORE );
    2352 [ #  # ][ #  # ]:          0 :         pBoxFmt->SetFmtAttr( aBoxSet );
                 [ #  # ]
    2353                 :            :     }
    2354                 :            :     else
    2355                 :            :     {
    2356                 :            :         // it's no number
    2357                 :            : 
    2358                 :            :         // Resetting attributes is not enough. In addition, take care that the
    2359                 :            :         // text will be also formatted correctly.
    2360                 :          0 :         pBoxFmt->SetFmtAttr( *GetDfltAttr( RES_BOXATR_FORMAT ));
    2361                 :            : 
    2362                 :          0 :         pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
    2363                 :            :     }
    2364                 :            : 
    2365         [ #  # ]:          0 :     if( bNewFml )
    2366                 :            :     {
    2367                 :            :         // No matter what was set, an update of the table is always a good idea
    2368 [ #  # ][ #  # ]:          0 :         SwTableFmlUpdate aTblUpdate( &pSttNd->FindTableNode()->GetTable() );
    2369 [ #  # ][ #  # ]:          0 :         rDoc.UpdateTblFlds( &aTblUpdate );
    2370                 :            :     }
    2371                 :            : 
    2372         [ #  # ]:          0 :     if( !pNd->IsCntntNode() )
    2373         [ #  # ]:          0 :         pNd = rDoc.GetNodes().GoNext( &pPam->GetPoint()->nNode );
    2374 [ #  # ][ #  # ]:          0 :     pPam->GetPoint()->nContent.Assign( (SwCntntNode*)pNd, 0 );
                 [ #  # ]
    2375                 :            : }
    2376                 :            : 
    2377                 :          0 : void SwUndoTblNumFmt::SetBox( const SwTableBox& rBox )
    2378                 :            : {
    2379                 :          0 :     nNode = rBox.GetSttIdx();
    2380                 :          0 : }
    2381                 :            : 
    2382                 :          0 : _UndoTblCpyTbl_Entry::_UndoTblCpyTbl_Entry( const SwTableBox& rBox )
    2383                 :          0 :     : nBoxIdx( rBox.GetSttIdx() ), nOffset( 0 ),
    2384                 :          0 :     pBoxNumAttr( 0 ), pUndo( 0 ), bJoin( false )
    2385                 :            : {
    2386                 :          0 : }
    2387                 :            : 
    2388                 :          0 : _UndoTblCpyTbl_Entry::~_UndoTblCpyTbl_Entry()
    2389                 :            : {
    2390         [ #  # ]:          0 :     delete pUndo;
    2391         [ #  # ]:          0 :     delete pBoxNumAttr;
    2392                 :          0 : }
    2393                 :            : 
    2394                 :          0 : SwUndoTblCpyTbl::SwUndoTblCpyTbl()
    2395                 :          0 :     : SwUndo( UNDO_TBLCPYTBL ), pInsRowUndo( 0 )
    2396                 :            : {
    2397 [ #  # ][ #  # ]:          0 :     pArr = new _UndoTblCpyTbl_Entries;
    2398                 :          0 : }
    2399                 :            : 
    2400                 :          0 : SwUndoTblCpyTbl::~SwUndoTblCpyTbl()
    2401                 :            : {
    2402 [ #  # ][ #  # ]:          0 :     delete pArr;
    2403 [ #  # ][ #  # ]:          0 :     delete pInsRowUndo;
    2404         [ #  # ]:          0 : }
    2405                 :            : 
    2406                 :          0 : void SwUndoTblCpyTbl::UndoImpl(::sw::UndoRedoContext & rContext)
    2407                 :            : {
    2408                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    2409                 :            :     _DEBUG_REDLINE( &rDoc )
    2410                 :            : 
    2411                 :          0 :     SwTableNode* pTblNd = 0;
    2412         [ #  # ]:          0 :     for( sal_uInt16 n = pArr->size(); n; )
    2413                 :            :     {
    2414         [ #  # ]:          0 :         _UndoTblCpyTbl_Entry* pEntry = &(*pArr)[ --n ];
    2415                 :          0 :         sal_uLong nSttPos = pEntry->nBoxIdx + pEntry->nOffset;
    2416 [ #  # ][ #  # ]:          0 :         SwStartNode* pSNd = rDoc.GetNodes()[ nSttPos ]->StartOfSectionNode();
    2417         [ #  # ]:          0 :         if( !pTblNd )
    2418         [ #  # ]:          0 :             pTblNd = pSNd->FindTableNode();
    2419                 :            : 
    2420         [ #  # ]:          0 :         SwTableBox& rBox = *pTblNd->GetTable().GetTblBox( nSttPos );
    2421                 :            : 
    2422         [ #  # ]:          0 :         SwNodeIndex aInsIdx( *rBox.GetSttNd(), 1 );
    2423 [ #  # ][ #  # ]:          0 :         rDoc.GetNodes().MakeTxtNode( aInsIdx, (SwTxtFmtColl*)rDoc.GetDfltTxtFmtColl() );
    2424                 :            : 
    2425                 :            :         // b62341295: Redline for copying tables
    2426                 :          0 :         const SwNode *pEndNode = rBox.GetSttNd()->EndOfSectionNode();
    2427         [ #  # ]:          0 :         SwPaM aPam( aInsIdx.GetNode(), *pEndNode );
    2428                 :          0 :         SwUndoDelete* pUndo = 0;
    2429                 :            : 
    2430         [ #  # ]:          0 :         if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ) )
    2431                 :            :         {
    2432                 :          0 :             bool bDeleteCompleteParagraph = false;
    2433                 :          0 :             bool bShiftPam = false;
    2434                 :            :             // There are a couple of different situations to consider during redlining
    2435         [ #  # ]:          0 :             if( pEntry->pUndo )
    2436                 :            :             {
    2437                 :            :                 SwUndoDelete *const pUndoDelete =
    2438         [ #  # ]:          0 :                     dynamic_cast<SwUndoDelete*>(pEntry->pUndo);
    2439                 :            :                 SwUndoRedlineDelete *const pUndoRedlineDelete =
    2440         [ #  # ]:          0 :                     dynamic_cast<SwUndoRedlineDelete*>(pEntry->pUndo);
    2441                 :            :                 OSL_ASSERT(pUndoDelete || pUndoRedlineDelete);
    2442         [ #  # ]:          0 :                 if (pUndoRedlineDelete)
    2443                 :            :                 {
    2444                 :            :                     // The old content was not empty or he has been merged with the new content
    2445                 :          0 :                     bDeleteCompleteParagraph = !pEntry->bJoin; // bJoin is set when merged
    2446                 :            :                     // Set aTmpIdx to the beginning fo the old content
    2447                 :            :                     SwNodeIndex aTmpIdx( *pEndNode,
    2448         [ #  # ]:          0 :                             pUndoRedlineDelete->NodeDiff()-1 );
    2449                 :          0 :                     SwTxtNode *pTxt = aTmpIdx.GetNode().GetTxtNode();
    2450         [ #  # ]:          0 :                     if( pTxt )
    2451                 :            :                     {
    2452         [ #  # ]:          0 :                         aPam.GetPoint()->nNode = *pTxt;
    2453                 :          0 :                         aPam.GetPoint()->nContent.Assign( pTxt,
    2454 [ #  # ][ #  # ]:          0 :                                 pUndoRedlineDelete->ContentStart() );
    2455                 :            :                     }
    2456                 :            :                     else
    2457 [ #  # ][ #  # ]:          0 :                         *aPam.GetPoint() = SwPosition( aTmpIdx );
         [ #  # ][ #  # ]
    2458                 :            :                 }
    2459 [ #  # ][ #  # ]:          0 :                 else if (pUndoDelete && pUndoDelete->IsDelFullPara())
                 [ #  # ]
    2460                 :            :                 {
    2461                 :            :                     // When the old content was an empty paragraph, but could not be joined
    2462                 :            :                     // with the new content (e.g. because of a section or table)
    2463                 :            :                     // We "save" the aPam.Point, we go one step backwards (because later on the
    2464                 :            :                     // empty paragraph will be inserted by the undo) and set the "ShiftPam-flag
    2465                 :            :                     // for step forward later on.
    2466                 :          0 :                     bDeleteCompleteParagraph = true;
    2467                 :          0 :                     bShiftPam = true;
    2468         [ #  # ]:          0 :                     SwNodeIndex aTmpIdx( *pEndNode, -1 );
    2469                 :          0 :                     SwTxtNode *pTxt = aTmpIdx.GetNode().GetTxtNode();
    2470         [ #  # ]:          0 :                     if( pTxt )
    2471                 :            :                     {
    2472         [ #  # ]:          0 :                         aPam.GetPoint()->nNode = *pTxt;
    2473 [ #  # ][ #  # ]:          0 :                         aPam.GetPoint()->nContent.Assign( pTxt, 0 );
    2474                 :            :                     }
    2475                 :            :                     else
    2476 [ #  # ][ #  # ]:          0 :                         *aPam.GetPoint() = SwPosition( aTmpIdx );
         [ #  # ][ #  # ]
    2477                 :            :                 }
    2478                 :            :             }
    2479         [ #  # ]:          0 :             rDoc.DeleteRedline( aPam, true, USHRT_MAX );
    2480                 :            : 
    2481         [ #  # ]:          0 :             if( pEntry->pUndo )
    2482                 :            :             {
    2483         [ #  # ]:          0 :                 pEntry->pUndo->UndoImpl(rContext);
    2484 [ #  # ][ #  # ]:          0 :                 delete pEntry->pUndo;
    2485                 :          0 :                 pEntry->pUndo = 0;
    2486                 :            :             }
    2487         [ #  # ]:          0 :             if( bShiftPam )
    2488                 :            :             {
    2489                 :            :                 // The aPam.Point is at the moment at the last position of the new content and has to be
    2490                 :            :                 // moved to the first postion of the old content for the SwUndoDelete operation
    2491         [ #  # ]:          0 :                 SwNodeIndex aTmpIdx( aPam.GetPoint()->nNode, 1 );
    2492                 :          0 :                 SwTxtNode *pTxt = aTmpIdx.GetNode().GetTxtNode();
    2493         [ #  # ]:          0 :                 if( pTxt )
    2494                 :            :                 {
    2495         [ #  # ]:          0 :                     aPam.GetPoint()->nNode = *pTxt;
    2496 [ #  # ][ #  # ]:          0 :                     aPam.GetPoint()->nContent.Assign( pTxt, 0 );
    2497                 :            :                 }
    2498                 :            :                 else
    2499 [ #  # ][ #  # ]:          0 :                     *aPam.GetPoint() = SwPosition( aTmpIdx );
         [ #  # ][ #  # ]
    2500                 :            :             }
    2501 [ #  # ][ #  # ]:          0 :             pUndo = new SwUndoDelete( aPam, bDeleteCompleteParagraph, sal_True );
    2502                 :            :         }
    2503                 :            :         else
    2504                 :            :         {
    2505 [ #  # ][ #  # ]:          0 :             pUndo = new SwUndoDelete( aPam, true );
    2506         [ #  # ]:          0 :             if( pEntry->pUndo )
    2507                 :            :             {
    2508         [ #  # ]:          0 :                 pEntry->pUndo->UndoImpl(rContext);
    2509 [ #  # ][ #  # ]:          0 :                 delete pEntry->pUndo;
    2510                 :          0 :                 pEntry->pUndo = 0;
    2511                 :            :             }
    2512                 :            :         }
    2513                 :          0 :         pEntry->pUndo = pUndo;
    2514                 :            : 
    2515 [ #  # ][ #  # ]:          0 :         aInsIdx = rBox.GetSttIdx() + 1;
    2516 [ #  # ][ #  # ]:          0 :         rDoc.GetNodes().Delete( aInsIdx, 1 );
    2517                 :            : 
    2518                 :          0 :         SfxItemSet aTmpSet( rDoc.GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
    2519         [ #  # ]:          0 :                                                 RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
    2520         [ #  # ]:          0 :         aTmpSet.Put( rBox.GetFrmFmt()->GetAttrSet() );
    2521         [ #  # ]:          0 :         if( aTmpSet.Count() )
    2522                 :            :         {
    2523         [ #  # ]:          0 :             SwFrmFmt* pBoxFmt = rBox.ClaimFrmFmt();
    2524         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
    2525         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_VERT_ORIENT );
    2526                 :            :         }
    2527                 :            : 
    2528         [ #  # ]:          0 :         if( pEntry->pBoxNumAttr )
    2529                 :            :         {
    2530 [ #  # ][ #  # ]:          0 :             rBox.ClaimFrmFmt()->SetFmtAttr( *pEntry->pBoxNumAttr );
    2531 [ #  # ][ #  # ]:          0 :             delete pEntry->pBoxNumAttr, pEntry->pBoxNumAttr = 0;
    2532                 :            :         }
    2533                 :            : 
    2534         [ #  # ]:          0 :         if( aTmpSet.Count() )
    2535                 :            :         {
    2536                 :          0 :             pEntry->pBoxNumAttr = new SfxItemSet( rDoc.GetAttrPool(),
    2537                 :            :                                     RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
    2538 [ #  # ][ #  # ]:          0 :                                     RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
    2539         [ #  # ]:          0 :             pEntry->pBoxNumAttr->Put( aTmpSet );
    2540                 :            :         }
    2541                 :            : 
    2542         [ #  # ]:          0 :         pEntry->nOffset = rBox.GetSttIdx() - pEntry->nBoxIdx;
    2543 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    2544                 :            : 
    2545         [ #  # ]:          0 :     if( pInsRowUndo )
    2546                 :            :     {
    2547                 :          0 :         pInsRowUndo->UndoImpl(rContext);
    2548                 :            :     }
    2549                 :            :     _DEBUG_REDLINE( &rDoc )
    2550                 :          0 : }
    2551                 :            : 
    2552                 :          0 : void SwUndoTblCpyTbl::RedoImpl(::sw::UndoRedoContext & rContext)
    2553                 :            : {
    2554                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    2555                 :            :     _DEBUG_REDLINE( &rDoc )
    2556                 :            : 
    2557         [ #  # ]:          0 :     if( pInsRowUndo )
    2558                 :            :     {
    2559                 :          0 :         pInsRowUndo->RedoImpl(rContext);
    2560                 :            :     }
    2561                 :            : 
    2562                 :          0 :     SwTableNode* pTblNd = 0;
    2563         [ #  # ]:          0 :     for( sal_uInt16 n = 0; n < pArr->size(); ++n )
    2564                 :            :     {
    2565         [ #  # ]:          0 :         _UndoTblCpyTbl_Entry* pEntry = &(*pArr)[ n ];
    2566                 :          0 :         sal_uLong nSttPos = pEntry->nBoxIdx + pEntry->nOffset;
    2567 [ #  # ][ #  # ]:          0 :         SwStartNode* pSNd = rDoc.GetNodes()[ nSttPos ]->StartOfSectionNode();
    2568         [ #  # ]:          0 :         if( !pTblNd )
    2569         [ #  # ]:          0 :             pTblNd = pSNd->FindTableNode();
    2570                 :            : 
    2571         [ #  # ]:          0 :         SwTableBox& rBox = *pTblNd->GetTable().GetTblBox( nSttPos );
    2572                 :            : 
    2573         [ #  # ]:          0 :         SwNodeIndex aInsIdx( *rBox.GetSttNd(), 1 );
    2574                 :            : 
    2575                 :            :         // b62341295: Redline for copying tables - Start.
    2576 [ #  # ][ #  # ]:          0 :         rDoc.GetNodes().MakeTxtNode( aInsIdx, (SwTxtFmtColl*)rDoc.GetDfltTxtFmtColl() );
    2577         [ #  # ]:          0 :         SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode());
    2578 [ #  # ][ #  # ]:          0 :         SwUndo* pUndo = IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ) ? 0 : new SwUndoDelete( aPam, sal_True );
                 [ #  # ]
    2579         [ #  # ]:          0 :         if( pEntry->pUndo )
    2580                 :            :         {
    2581         [ #  # ]:          0 :             pEntry->pUndo->UndoImpl(rContext);
    2582         [ #  # ]:          0 :             if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ) )
    2583                 :            :             {
    2584                 :            :                 // PrepareRedline has to be called with the beginning of the old content
    2585                 :            :                 // When new and old content has been joined, the rIter.pAktPam has been set
    2586                 :            :                 // by the Undo operation to this point.
    2587                 :            :                 // Otherwise aInsIdx has been moved during the Undo operation
    2588         [ #  # ]:          0 :                 if( pEntry->bJoin )
    2589                 :            :                 {
    2590                 :            :                     SwPaM const& rLastPam =
    2591         [ #  # ]:          0 :                         rContext.GetCursorSupplier().GetCurrentShellCursor();
    2592                 :          0 :                     pUndo = PrepareRedline( &rDoc, rBox, *rLastPam.GetPoint(),
    2593         [ #  # ]:          0 :                                             pEntry->bJoin, true );
    2594                 :            :                 }
    2595                 :            :                 else
    2596                 :            :                 {
    2597         [ #  # ]:          0 :                     SwPosition aTmpPos( aInsIdx );
    2598 [ #  # ][ #  # ]:          0 :                     pUndo = PrepareRedline( &rDoc, rBox, aTmpPos, pEntry->bJoin, true );
    2599                 :            :                 }
    2600                 :            :             }
    2601 [ #  # ][ #  # ]:          0 :             delete pEntry->pUndo;
    2602                 :          0 :             pEntry->pUndo = 0;
    2603                 :            :         }
    2604                 :          0 :         pEntry->pUndo = pUndo;
    2605                 :            :         // b62341295: Redline for copying tables - End.
    2606                 :            : 
    2607 [ #  # ][ #  # ]:          0 :         aInsIdx = rBox.GetSttIdx() + 1;
    2608 [ #  # ][ #  # ]:          0 :         rDoc.GetNodes().Delete( aInsIdx, 1 );
    2609                 :            : 
    2610                 :          0 :         SfxItemSet aTmpSet( rDoc.GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
    2611         [ #  # ]:          0 :                                                 RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
    2612         [ #  # ]:          0 :         aTmpSet.Put( rBox.GetFrmFmt()->GetAttrSet() );
    2613         [ #  # ]:          0 :         if( aTmpSet.Count() )
    2614                 :            :         {
    2615         [ #  # ]:          0 :             SwFrmFmt* pBoxFmt = rBox.ClaimFrmFmt();
    2616         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
    2617         [ #  # ]:          0 :             pBoxFmt->ResetFmtAttr( RES_VERT_ORIENT );
    2618                 :            :         }
    2619         [ #  # ]:          0 :         if( pEntry->pBoxNumAttr )
    2620                 :            :         {
    2621 [ #  # ][ #  # ]:          0 :             rBox.ClaimFrmFmt()->SetFmtAttr( *pEntry->pBoxNumAttr );
    2622 [ #  # ][ #  # ]:          0 :             delete pEntry->pBoxNumAttr, pEntry->pBoxNumAttr = 0;
    2623                 :            :         }
    2624                 :            : 
    2625         [ #  # ]:          0 :         if( aTmpSet.Count() )
    2626                 :            :         {
    2627                 :          0 :             pEntry->pBoxNumAttr = new SfxItemSet( rDoc.GetAttrPool(),
    2628                 :            :                                     RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
    2629 [ #  # ][ #  # ]:          0 :                                     RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
    2630         [ #  # ]:          0 :             pEntry->pBoxNumAttr->Put( aTmpSet );
    2631                 :            :         }
    2632                 :            : 
    2633         [ #  # ]:          0 :         pEntry->nOffset = rBox.GetSttIdx() - pEntry->nBoxIdx;
    2634 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    2635                 :            :     _DEBUG_REDLINE( &rDoc )
    2636                 :          0 : }
    2637                 :            : 
    2638                 :          0 : void SwUndoTblCpyTbl::AddBoxBefore( const SwTableBox& rBox, sal_Bool bDelCntnt )
    2639                 :            : {
    2640 [ #  # ][ #  # ]:          0 :     if( !pArr->empty() && !bDelCntnt )
                 [ #  # ]
    2641                 :          0 :         return;
    2642                 :            : 
    2643         [ #  # ]:          0 :     _UndoTblCpyTbl_Entry* pEntry = new _UndoTblCpyTbl_Entry( rBox );
    2644                 :          0 :     pArr->push_back( pEntry );
    2645                 :            : 
    2646                 :          0 :     SwDoc* pDoc = rBox.GetFrmFmt()->GetDoc();
    2647                 :            :     _DEBUG_REDLINE( pDoc )
    2648         [ #  # ]:          0 :     if( bDelCntnt )
    2649                 :            :     {
    2650         [ #  # ]:          0 :         SwNodeIndex aInsIdx( *rBox.GetSttNd(), 1 );
    2651 [ #  # ][ #  # ]:          0 :         pDoc->GetNodes().MakeTxtNode( aInsIdx, (SwTxtFmtColl*)pDoc->GetDfltTxtFmtColl() );
    2652         [ #  # ]:          0 :         SwPaM aPam( aInsIdx.GetNode(), *rBox.GetSttNd()->EndOfSectionNode() );
    2653                 :            : 
    2654 [ #  # ][ #  # ]:          0 :         if( !pDoc->IsRedlineOn() )
    2655 [ #  # ][ #  # ]:          0 :             pEntry->pUndo = new SwUndoDelete( aPam, sal_True );
         [ #  # ][ #  # ]
    2656                 :            :     }
    2657                 :            : 
    2658                 :          0 :     pEntry->pBoxNumAttr = new SfxItemSet( pDoc->GetAttrPool(),
    2659                 :            :                                     RES_BOXATR_FORMAT, RES_BOXATR_VALUE,
    2660         [ #  # ]:          0 :                                     RES_VERT_ORIENT, RES_VERT_ORIENT, 0 );
    2661                 :          0 :     pEntry->pBoxNumAttr->Put( rBox.GetFrmFmt()->GetAttrSet() );
    2662         [ #  # ]:          0 :     if( !pEntry->pBoxNumAttr->Count() )
    2663         [ #  # ]:          0 :         delete pEntry->pBoxNumAttr, pEntry->pBoxNumAttr = 0;
    2664                 :            :     _DEBUG_REDLINE( pDoc )
    2665                 :            : }
    2666                 :            : 
    2667                 :          0 : void SwUndoTblCpyTbl::AddBoxAfter( const SwTableBox& rBox, const SwNodeIndex& rIdx, sal_Bool bDelCntnt )
    2668                 :            : {
    2669                 :          0 :     _UndoTblCpyTbl_Entry* pEntry = &(*pArr).back();
    2670                 :            : 
    2671                 :            :     // If the content was deleted than remove also the temporarily created node
    2672         [ #  # ]:          0 :     if( bDelCntnt )
    2673                 :            :     {
    2674                 :          0 :         SwDoc* pDoc = rBox.GetFrmFmt()->GetDoc();
    2675                 :            :         _DEBUG_REDLINE( pDoc )
    2676                 :            : 
    2677 [ #  # ][ #  # ]:          0 :         if( pDoc->IsRedlineOn() )
    2678                 :            :         {
    2679         [ #  # ]:          0 :             SwPosition aTmpPos( rIdx );
    2680 [ #  # ][ #  # ]:          0 :             pEntry->pUndo = PrepareRedline( pDoc, rBox, aTmpPos, pEntry->bJoin, false );
    2681                 :            :         }
    2682         [ #  # ]:          0 :         SwNodeIndex aDelIdx( *rBox.GetSttNd(), 1 );
    2683 [ #  # ][ #  # ]:          0 :         rBox.GetFrmFmt()->GetDoc()->GetNodes().Delete( aDelIdx, 1 );
                 [ #  # ]
    2684                 :            :         _DEBUG_REDLINE( pDoc )
    2685                 :            :     }
    2686                 :            : 
    2687                 :          0 :     pEntry->nOffset = rBox.GetSttIdx() - pEntry->nBoxIdx;
    2688                 :          0 : }
    2689                 :            : 
    2690                 :            : // PrepareRedline is called from AddBoxAfter() and from Redo() in slightly different situations.
    2691                 :            : // bRedo is set by calling from Redo()
    2692                 :            : // rJoin is false by calling from AddBoxAfter() and will be set if the old and new content has
    2693                 :            : // been merged.
    2694                 :            : // rJoin is true if Redo() is calling and the content has already been merged
    2695                 :            : 
    2696                 :          0 : SwUndo* SwUndoTblCpyTbl::PrepareRedline( SwDoc* pDoc, const SwTableBox& rBox,
    2697                 :            :     const SwPosition& rPos, bool& rJoin, bool bRedo )
    2698                 :            : {
    2699                 :          0 :     SwUndo *pUndo = 0;
    2700                 :            :     // b62341295: Redline for copying tables
    2701                 :            :     // What's to do?
    2702                 :            :     // Mark the cell content before rIdx as insertion,
    2703                 :            :     // mark the cell content behind rIdx as deletion
    2704                 :            :     // merge text nodes at rIdx if possible
    2705         [ #  # ]:          0 :     RedlineMode_t eOld = pDoc->GetRedlineMode();
    2706                 :            :     pDoc->SetRedlineMode_intern((RedlineMode_t)( ( eOld | nsRedlineMode_t::REDLINE_DONTCOMBINE_REDLINES ) &
    2707         [ #  # ]:          0 :                                      ~nsRedlineMode_t::REDLINE_IGNORE ));
    2708         [ #  # ]:          0 :     SwPosition aInsertEnd( rPos );
    2709                 :            :     SwTxtNode* pTxt;
    2710         [ #  # ]:          0 :     if( !rJoin )
    2711                 :            :     {
    2712                 :            :         // If the content is not merged, the end of the insertion is at the end of the node
    2713                 :            :         // _before_ the given position rPos
    2714         [ #  # ]:          0 :         --aInsertEnd.nNode;
    2715                 :          0 :         pTxt = aInsertEnd.nNode.GetNode().GetTxtNode();
    2716         [ #  # ]:          0 :         if( pTxt )
    2717                 :            :         {
    2718 [ #  # ][ #  # ]:          0 :             aInsertEnd.nContent.Assign( pTxt, pTxt->GetTxt().Len() );
    2719 [ #  # ][ #  # ]:          0 :             if( !bRedo && rPos.nNode.GetNode().GetTxtNode() )
                 [ #  # ]
    2720                 :            :             {   // Try to merge, if not called by Redo()
    2721                 :          0 :                 rJoin = true;
    2722         [ #  # ]:          0 :                 pTxt->JoinNext();
    2723                 :            :             }
    2724                 :            :         }
    2725                 :            :         else
    2726 [ #  # ][ #  # ]:          0 :             aInsertEnd.nContent = SwIndex( 0 );
                 [ #  # ]
    2727                 :            :     }
    2728                 :            :     // For joined (merged) contents the start of deletion and end of insertion are identical
    2729                 :            :     // otherwise adjacent nodes.
    2730 [ #  # ][ #  # ]:          0 :     SwPosition aDeleteStart( rJoin ? aInsertEnd : rPos );
    2731         [ #  # ]:          0 :     if( !rJoin )
    2732                 :            :     {
    2733                 :          0 :         pTxt = aDeleteStart.nNode.GetNode().GetTxtNode();
    2734         [ #  # ]:          0 :         if( pTxt )
    2735 [ #  # ][ #  # ]:          0 :             aDeleteStart.nContent.Assign( pTxt, 0 );
    2736                 :            :     }
    2737 [ #  # ][ #  # ]:          0 :     SwPosition aCellEnd( SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode(), -1 ) );
                 [ #  # ]
    2738                 :          0 :     pTxt = aCellEnd.nNode.GetNode().GetTxtNode();
    2739         [ #  # ]:          0 :     if( pTxt )
    2740 [ #  # ][ #  # ]:          0 :         aCellEnd.nContent.Assign( pTxt, pTxt->GetTxt().Len() );
    2741 [ #  # ][ #  # ]:          0 :     if( aDeleteStart != aCellEnd )
    2742                 :            :     {   // If the old (deleted) part is not empty, here we are...
    2743         [ #  # ]:          0 :         SwPaM aDeletePam( aDeleteStart, aCellEnd );
    2744 [ #  # ][ #  # ]:          0 :         pUndo = new SwUndoRedlineDelete( aDeletePam, UNDO_DELETE );
    2745 [ #  # ][ #  # ]:          0 :         pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_DELETE, aDeletePam ), true );
         [ #  # ][ #  # ]
    2746                 :            :     }
    2747         [ #  # ]:          0 :     else if( !rJoin ) // If the old part is empty and joined, we are finished
    2748                 :            :     {   // if it is not joined, we have to delete this empty paragraph
    2749                 :            :         aCellEnd = SwPosition(
    2750 [ #  # ][ #  # ]:          0 :             SwNodeIndex( *rBox.GetSttNd()->EndOfSectionNode() ));
         [ #  # ][ #  # ]
                 [ #  # ]
    2751         [ #  # ]:          0 :         SwPaM aTmpPam( aDeleteStart, aCellEnd );
    2752 [ #  # ][ #  # ]:          0 :         pUndo = new SwUndoDelete( aTmpPam, sal_True );
                 [ #  # ]
    2753                 :            :     }
    2754 [ #  # ][ #  # ]:          0 :     SwPosition aCellStart( SwNodeIndex( *rBox.GetSttNd(), 2 ) );
                 [ #  # ]
    2755                 :          0 :     pTxt = aCellStart.nNode.GetNode().GetTxtNode();
    2756         [ #  # ]:          0 :     if( pTxt )
    2757 [ #  # ][ #  # ]:          0 :         aCellStart.nContent.Assign( pTxt, 0 );
    2758 [ #  # ][ #  # ]:          0 :     if( aCellStart != aInsertEnd ) // An empty insertion will not been marked
    2759                 :            :     {
    2760         [ #  # ]:          0 :         SwPaM aTmpPam( aCellStart, aInsertEnd );
    2761 [ #  # ][ #  # ]:          0 :         pDoc->AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, aTmpPam ), true );
         [ #  # ][ #  # ]
    2762                 :            :     }
    2763                 :            : 
    2764         [ #  # ]:          0 :     pDoc->SetRedlineMode_intern( eOld );
    2765 [ #  # ][ #  # ]:          0 :     return pUndo;
         [ #  # ][ #  # ]
    2766                 :            : }
    2767                 :            : 
    2768                 :          0 : sal_Bool SwUndoTblCpyTbl::InsertRow( SwTable& rTbl, const SwSelBoxes& rBoxes,
    2769                 :            :                                 sal_uInt16 nCnt )
    2770                 :            : {
    2771                 :          0 :     SwTableNode* pTblNd = (SwTableNode*)rTbl.GetTabSortBoxes()[0]->
    2772         [ #  # ]:          0 :                                 GetSttNd()->FindTableNode();
    2773                 :            : 
    2774                 :            :     pInsRowUndo = new SwUndoTblNdsChg( UNDO_TABLE_INSROW, rBoxes, *pTblNd,
    2775 [ #  # ][ #  # ]:          0 :                                        0, 0, nCnt, sal_True, sal_False );
    2776         [ #  # ]:          0 :     SwTableSortBoxes aTmpLst( rTbl.GetTabSortBoxes() );
    2777                 :            : 
    2778         [ #  # ]:          0 :     sal_Bool bRet = rTbl.InsertRow( rTbl.GetFrmFmt()->GetDoc(), rBoxes, nCnt, sal_True );
    2779         [ #  # ]:          0 :     if( bRet )
    2780         [ #  # ]:          0 :         pInsRowUndo->SaveNewBoxes( *pTblNd, aTmpLst );
    2781                 :            :     else
    2782 [ #  # ][ #  # ]:          0 :         delete pInsRowUndo, pInsRowUndo = 0;
    2783                 :          0 :     return bRet;
    2784                 :            : }
    2785                 :            : 
    2786                 :          0 : sal_Bool SwUndoTblCpyTbl::IsEmpty() const
    2787                 :            : {
    2788 [ #  # ][ #  # ]:          0 :     return !pInsRowUndo && pArr->empty();
    2789                 :            : }
    2790                 :            : 
    2791                 :          0 : SwUndoCpyTbl::SwUndoCpyTbl()
    2792                 :          0 :     : SwUndo( UNDO_CPYTBL ), pDel( 0 ), nTblNode( 0 )
    2793                 :            : {
    2794                 :          0 : }
    2795                 :            : 
    2796                 :          0 : SwUndoCpyTbl::~SwUndoCpyTbl()
    2797                 :            : {
    2798 [ #  # ][ #  # ]:          0 :     delete pDel;
    2799         [ #  # ]:          0 : }
    2800                 :            : 
    2801                 :          0 : void SwUndoCpyTbl::UndoImpl(::sw::UndoRedoContext & rContext)
    2802                 :            : {
    2803                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
    2804 [ #  # ][ #  # ]:          0 :     SwTableNode* pTNd = rDoc.GetNodes()[ nTblNode ]->GetTableNode();
    2805                 :            : 
    2806                 :            :     // move hard page breaks into next node
    2807 [ #  # ][ #  # ]:          0 :     SwCntntNode* pNextNd = rDoc.GetNodes()[ pTNd->EndOfSectionIndex()+1 ]->GetCntntNode();
    2808         [ #  # ]:          0 :     if( pNextNd )
    2809                 :            :     {
    2810                 :          0 :         SwFrmFmt* pTableFmt = pTNd->GetTable().GetFrmFmt();
    2811                 :            :         const SfxPoolItem *pItem;
    2812                 :            : 
    2813         [ #  # ]:          0 :         if( SFX_ITEM_SET == pTableFmt->GetItemState( RES_PAGEDESC,
    2814         [ #  # ]:          0 :             sal_False, &pItem ) )
    2815         [ #  # ]:          0 :             pNextNd->SetAttr( *pItem );
    2816                 :            : 
    2817         [ #  # ]:          0 :         if( SFX_ITEM_SET == pTableFmt->GetItemState( RES_BREAK,
    2818         [ #  # ]:          0 :             sal_False, &pItem ) )
    2819         [ #  # ]:          0 :             pNextNd->SetAttr( *pItem );
    2820                 :            :     }
    2821                 :            : 
    2822         [ #  # ]:          0 :     SwPaM aPam( *pTNd, *pTNd->EndOfSectionNode(), 0 , 1 );
    2823 [ #  # ][ #  # ]:          0 :     pDel = new SwUndoDelete( aPam, sal_True );
                 [ #  # ]
    2824                 :          0 : }
    2825                 :            : 
    2826                 :          0 : void SwUndoCpyTbl::RedoImpl(::sw::UndoRedoContext & rContext)
    2827                 :            : {
    2828                 :          0 :     pDel->UndoImpl(rContext);
    2829         [ #  # ]:          0 :     delete pDel, pDel = 0;
    2830                 :          0 : }
    2831                 :            : 
    2832                 :          0 : SwUndoSplitTbl::SwUndoSplitTbl( const SwTableNode& rTblNd,
    2833                 :            :     SwSaveRowSpan* pRowSp, sal_uInt16 eMode, sal_Bool bNewSize )
    2834                 :            :     : SwUndo( UNDO_SPLIT_TABLE ),
    2835                 :          0 :     nTblNode( rTblNd.GetIndex() ), nOffset( 0 ), mpSaveRowSpan( pRowSp ), pSavTbl( 0 ),
    2836                 :          0 :     pHistory( 0 ), nMode( eMode ), nFmlEnd( 0 ), bCalcNewSize( bNewSize )
    2837                 :            : {
    2838      [ #  #  # ]:          0 :     switch( nMode )
    2839                 :            :     {
    2840                 :            :     case HEADLINE_BOXATRCOLLCOPY:
    2841 [ #  # ][ #  # ]:          0 :             pHistory = new SwHistory;
    2842                 :            :             // no break
    2843                 :            :     case HEADLINE_BORDERCOPY:
    2844                 :            :     case HEADLINE_BOXATTRCOPY:
    2845 [ #  # ][ #  # ]:          0 :         pSavTbl = new _SaveTable( rTblNd.GetTable(), 1, sal_False );
    2846                 :          0 :         break;
    2847                 :            :     }
    2848                 :          0 : }
    2849                 :            : 
    2850                 :          0 : SwUndoSplitTbl::~SwUndoSplitTbl()
    2851                 :            : {
    2852 [ #  # ][ #  # ]:          0 :     delete pSavTbl;
    2853 [ #  # ][ #  # ]:          0 :     delete pHistory;
    2854         [ #  # ]:          0 :     delete mpSaveRowSpan;
    2855         [ #  # ]:          0 : }
    2856                 :            : 
    2857                 :          0 : void SwUndoSplitTbl::UndoImpl(::sw::UndoRedoContext & rContext)
    2858                 :            : {
    2859                 :          0 :     SwDoc *const pDoc = & rContext.GetDoc();
    2860         [ #  # ]:          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    2861                 :            : 
    2862         [ #  # ]:          0 :     pPam->DeleteMark();
    2863                 :          0 :     SwNodeIndex& rIdx = pPam->GetPoint()->nNode;
    2864         [ #  # ]:          0 :     rIdx = nTblNode + nOffset;
    2865                 :            : 
    2866                 :            :     // remove implicitly created paragraph again
    2867 [ #  # ][ #  # ]:          0 :     pDoc->GetNodes().Delete( rIdx, 1 );
    2868                 :            : 
    2869         [ #  # ]:          0 :     rIdx = nTblNode + nOffset;
    2870                 :          0 :     SwTableNode* pTblNd = rIdx.GetNode().GetTableNode();
    2871                 :          0 :     SwTable& rTbl = pTblNd->GetTable();
    2872                 :            : 
    2873         [ #  # ]:          0 :     SwTableFmlUpdate aMsgHnt( &rTbl );
    2874                 :          0 :     aMsgHnt.eFlags = TBL_BOXPTR;
    2875         [ #  # ]:          0 :     pDoc->UpdateTblFlds( &aMsgHnt );
    2876                 :            : 
    2877   [ #  #  #  # ]:          0 :     switch( nMode )
    2878                 :            :     {
    2879                 :            :     case HEADLINE_BOXATRCOLLCOPY:
    2880         [ #  # ]:          0 :         if( pHistory )
    2881         [ #  # ]:          0 :             pHistory->TmpRollback( pDoc, nFmlEnd );
    2882                 :            :         // no break
    2883                 :            :     case HEADLINE_BOXATTRCOPY:
    2884                 :            :     case HEADLINE_BORDERCOPY:
    2885                 :            :         {
    2886         [ #  # ]:          0 :             pSavTbl->CreateNew( rTbl, sal_False );
    2887         [ #  # ]:          0 :             pSavTbl->RestoreAttr( rTbl );
    2888                 :            :         }
    2889                 :          0 :         break;
    2890                 :            : 
    2891                 :            :     case HEADLINE_CNTNTCOPY:
    2892                 :            :         // the created first line has to be removed again
    2893                 :            :         {
    2894         [ #  # ]:          0 :             SwSelBoxes aSelBoxes;
    2895         [ #  # ]:          0 :             SwTableBox* pBox = rTbl.GetTblBox( nTblNode + nOffset + 1 );
    2896         [ #  # ]:          0 :             rTbl.SelLineFromBox( pBox, aSelBoxes, sal_True );
    2897         [ #  # ]:          0 :             _FndBox aTmpBox( 0, 0 );
    2898         [ #  # ]:          0 :             aTmpBox.SetTableLines( aSelBoxes, rTbl );
    2899         [ #  # ]:          0 :             aTmpBox.DelFrms( rTbl );
    2900 [ #  # ][ #  # ]:          0 :             rTbl.DeleteSel( pDoc, aSelBoxes, 0, 0, sal_False, sal_False );
    2901                 :            :         }
    2902                 :          0 :         break;
    2903                 :            :     }
    2904                 :            : 
    2905 [ #  # ][ #  # ]:          0 :     pDoc->GetNodes().MergeTable( rIdx );
    2906                 :            : 
    2907         [ #  # ]:          0 :     if( pHistory )
    2908                 :            :     {
    2909         [ #  # ]:          0 :         pHistory->TmpRollback( pDoc, 0 );
    2910         [ #  # ]:          0 :         pHistory->SetTmpEnd( pHistory->Count() );
    2911                 :            :     }
    2912         [ #  # ]:          0 :     if( mpSaveRowSpan )
    2913                 :            :     {
    2914         [ #  # ]:          0 :         pTblNd = rIdx.GetNode().FindTableNode();
    2915         [ #  # ]:          0 :         if( pTblNd )
    2916         [ #  # ]:          0 :             pTblNd->GetTable().RestoreRowSpan( *mpSaveRowSpan );
    2917                 :            :     }
    2918 [ #  # ][ #  # ]:          0 :     ClearFEShellTabCols();
    2919                 :          0 : }
    2920                 :            : 
    2921                 :          0 : void SwUndoSplitTbl::RedoImpl(::sw::UndoRedoContext & rContext)
    2922                 :            : {
    2923                 :          0 :     SwDoc *const pDoc = & rContext.GetDoc();
    2924                 :          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    2925                 :            : 
    2926                 :          0 :     pPam->DeleteMark();
    2927                 :          0 :     pPam->GetPoint()->nNode = nTblNode;
    2928                 :          0 :     pDoc->SplitTable( *pPam->GetPoint(), nMode, bCalcNewSize );
    2929                 :            : 
    2930                 :          0 :     ClearFEShellTabCols();
    2931                 :          0 : }
    2932                 :            : 
    2933                 :          0 : void SwUndoSplitTbl::RepeatImpl(::sw::RepeatContext & rContext)
    2934                 :            : {
    2935                 :          0 :     SwPaM *const pPam = & rContext.GetRepeatPaM();
    2936                 :          0 :     SwDoc *const pDoc = & rContext.GetDoc();
    2937                 :            : 
    2938                 :          0 :     pDoc->SplitTable( *pPam->GetPoint(), nMode, bCalcNewSize );
    2939                 :          0 :     ClearFEShellTabCols();
    2940                 :          0 : }
    2941                 :            : 
    2942                 :          0 : void SwUndoSplitTbl::SaveFormula( SwHistory& rHistory )
    2943                 :            : {
    2944         [ #  # ]:          0 :     if( !pHistory )
    2945         [ #  # ]:          0 :         pHistory = new SwHistory;
    2946                 :            : 
    2947                 :          0 :     nFmlEnd = rHistory.Count();
    2948                 :          0 :     pHistory->Move( 0, &rHistory );
    2949                 :          0 : }
    2950                 :            : 
    2951                 :          0 : SwUndoMergeTbl::SwUndoMergeTbl( const SwTableNode& rTblNd,
    2952                 :            :                                 const SwTableNode& rDelTblNd,
    2953                 :            :                                 sal_Bool bWithPrv, sal_uInt16 nMd )
    2954                 :            :     : SwUndo( UNDO_MERGE_TABLE ), pSavTbl( 0 ),
    2955         [ #  # ]:          0 :     pHistory( 0 ), nMode( nMd ), bWithPrev( bWithPrv )
    2956                 :            : {
    2957                 :            :     // memorize end node of the last table cell that'll stay in position
    2958         [ #  # ]:          0 :     if( bWithPrev )
    2959                 :          0 :         nTblNode = rDelTblNd.EndOfSectionIndex() - 1;
    2960                 :            :     else
    2961                 :          0 :         nTblNode = rTblNd.EndOfSectionIndex() - 1;
    2962                 :            : 
    2963         [ #  # ]:          0 :     aName = rDelTblNd.GetTable().GetFrmFmt()->GetName();
    2964 [ #  # ][ #  # ]:          0 :     pSavTbl = new _SaveTable( rDelTblNd.GetTable() );
    2965                 :            : 
    2966 [ #  # ][ #  # ]:          0 :     pSavHdl = bWithPrev ? new _SaveTable( rTblNd.GetTable(), 1 ) : 0;
                 [ #  # ]
    2967                 :          0 : }
    2968                 :            : 
    2969         [ #  # ]:          0 : SwUndoMergeTbl::~SwUndoMergeTbl()
    2970                 :            : {
    2971 [ #  # ][ #  # ]:          0 :     delete pSavTbl;
    2972 [ #  # ][ #  # ]:          0 :     delete pSavHdl;
    2973 [ #  # ][ #  # ]:          0 :     delete pHistory;
    2974         [ #  # ]:          0 : }
    2975                 :            : 
    2976                 :          0 : void SwUndoMergeTbl::UndoImpl(::sw::UndoRedoContext & rContext)
    2977                 :            : {
    2978                 :          0 :     SwDoc *const pDoc = & rContext.GetDoc();
    2979         [ #  # ]:          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    2980                 :            : 
    2981         [ #  # ]:          0 :     pPam->DeleteMark();
    2982                 :          0 :     SwNodeIndex& rIdx = pPam->GetPoint()->nNode;
    2983         [ #  # ]:          0 :     rIdx = nTblNode;
    2984                 :            : 
    2985         [ #  # ]:          0 :     SwTableNode* pTblNd = rIdx.GetNode().FindTableNode();
    2986                 :          0 :     SwTable* pTbl = &pTblNd->GetTable();
    2987                 :            : 
    2988         [ #  # ]:          0 :     SwTableFmlUpdate aMsgHnt( pTbl );
    2989                 :          0 :     aMsgHnt.eFlags = TBL_BOXPTR;
    2990         [ #  # ]:          0 :     pDoc->UpdateTblFlds( &aMsgHnt );
    2991                 :            : 
    2992                 :            :     // get lines for layout update
    2993         [ #  # ]:          0 :     _FndBox aFndBox( 0, 0 );
    2994         [ #  # ]:          0 :     aFndBox.SetTableLines( *pTbl );
    2995         [ #  # ]:          0 :     aFndBox.DelFrms( *pTbl );
    2996                 :            :     // ? TL_CHART2: notification or locking of controller required ?
    2997                 :            : 
    2998 [ #  # ][ #  # ]:          0 :     SwTableNode* pNew = pDoc->GetNodes().SplitTable( rIdx, sal_True, sal_False );
    2999                 :            : 
    3000                 :            :     // update layout
    3001         [ #  # ]:          0 :     aFndBox.MakeFrms( *pTbl );
    3002                 :            :     // ? TL_CHART2: notification or locking of controller required ?
    3003                 :            : 
    3004         [ #  # ]:          0 :     if( bWithPrev )
    3005                 :            :     {
    3006                 :            :         // move name
    3007         [ #  # ]:          0 :         pNew->GetTable().GetFrmFmt()->SetName( pTbl->GetFrmFmt()->GetName() );
    3008         [ #  # ]:          0 :         pSavHdl->RestoreAttr( pNew->GetTable() );
    3009                 :            :     }
    3010                 :            :     else
    3011                 :          0 :         pTbl = &pNew->GetTable();
    3012                 :            : 
    3013         [ #  # ]:          0 :     pTbl->GetFrmFmt()->SetName( aName );
    3014         [ #  # ]:          0 :     pSavTbl->RestoreAttr( *pTbl );
    3015                 :            : 
    3016         [ #  # ]:          0 :     if( pHistory )
    3017                 :            :     {
    3018         [ #  # ]:          0 :         pHistory->TmpRollback( pDoc, 0 );
    3019         [ #  # ]:          0 :         pHistory->SetTmpEnd( pHistory->Count() );
    3020                 :            :     }
    3021                 :            : 
    3022                 :            :     // create frames for the new table
    3023         [ #  # ]:          0 :     SwNodeIndex aTmpIdx( *pNew );
    3024         [ #  # ]:          0 :     pNew->MakeFrms( &aTmpIdx );
    3025                 :            : 
    3026                 :            :     // position cursor somewhere in content
    3027 [ #  # ][ #  # ]:          0 :     SwCntntNode* pCNd = pDoc->GetNodes().GoNext( &rIdx );
    3028 [ #  # ][ #  # ]:          0 :     pPam->GetPoint()->nContent.Assign( pCNd, 0 );
    3029                 :            : 
    3030         [ #  # ]:          0 :     ClearFEShellTabCols();
    3031                 :            : 
    3032                 :            :     // TL_CHART2: need to inform chart of probably changed cell names
    3033         [ #  # ]:          0 :     SwChartDataProvider *pPCD = pDoc->GetChartDataProvider();
    3034         [ #  # ]:          0 :     if (pPCD)
    3035                 :            :     {
    3036         [ #  # ]:          0 :         pDoc->UpdateCharts( pTbl->GetFrmFmt()->GetName() );
    3037         [ #  # ]:          0 :         pDoc->UpdateCharts( pNew->GetTable().GetFrmFmt()->GetName() );
    3038 [ #  # ][ #  # ]:          0 :     }
                 [ #  # ]
    3039                 :          0 : }
    3040                 :            : 
    3041                 :          0 : void SwUndoMergeTbl::RedoImpl(::sw::UndoRedoContext & rContext)
    3042                 :            : {
    3043                 :          0 :     SwDoc *const pDoc = & rContext.GetDoc();
    3044                 :          0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
    3045                 :            : 
    3046                 :          0 :     pPam->DeleteMark();
    3047                 :          0 :     pPam->GetPoint()->nNode = nTblNode;
    3048         [ #  # ]:          0 :     if( bWithPrev )
    3049                 :          0 :         pPam->GetPoint()->nNode = nTblNode + 3;
    3050                 :            :     else
    3051                 :          0 :         pPam->GetPoint()->nNode = nTblNode;
    3052                 :            : 
    3053                 :          0 :     pDoc->MergeTable( *pPam->GetPoint(), bWithPrev, nMode );
    3054                 :            : 
    3055                 :          0 :     ClearFEShellTabCols();
    3056                 :          0 : }
    3057                 :            : 
    3058                 :          0 : void SwUndoMergeTbl::RepeatImpl(::sw::RepeatContext & rContext)
    3059                 :            : {
    3060                 :          0 :     SwDoc *const pDoc = & rContext.GetDoc();
    3061                 :          0 :     SwPaM *const pPam = & rContext.GetRepeatPaM();
    3062                 :            : 
    3063                 :          0 :     pDoc->MergeTable( *pPam->GetPoint(), bWithPrev, nMode );
    3064                 :          0 :     ClearFEShellTabCols();
    3065                 :          0 : }
    3066                 :            : 
    3067                 :          0 : void SwUndoMergeTbl::SaveFormula( SwHistory& rHistory )
    3068                 :            : {
    3069         [ #  # ]:          0 :     if( !pHistory )
    3070         [ #  # ]:          0 :         pHistory = new SwHistory;
    3071                 :          0 :     pHistory->Move( 0, &rHistory );
    3072                 :          0 : }
    3073                 :            : 
    3074                 :          0 : void InsertSort( std::vector<sal_uInt16>& rArr, sal_uInt16 nIdx, sal_uInt16* pInsPos )
    3075                 :            : {
    3076                 :          0 :     sal_uInt16 nO   = rArr.size(), nM, nU = 0;
    3077         [ #  # ]:          0 :     if( nO > 0 )
    3078                 :            :     {
    3079                 :          0 :         nO--;
    3080         [ #  # ]:          0 :         while( nU <= nO )
    3081                 :            :         {
    3082                 :          0 :             nM = nU + ( nO - nU ) / 2;
    3083         [ #  # ]:          0 :             if ( rArr[nM] == nIdx )
    3084                 :            :             {
    3085                 :            :                 OSL_FAIL( "Index already exists. This should never happen." );
    3086                 :          0 :                 return;
    3087                 :            :             }
    3088         [ #  # ]:          0 :             if( rArr[nM] < nIdx )
    3089                 :          0 :                 nU = nM + 1;
    3090         [ #  # ]:          0 :             else if( nM == 0 )
    3091                 :          0 :                 break;
    3092                 :            :             else
    3093                 :          0 :                 nO = nM - 1;
    3094                 :            :         }
    3095                 :            :     }
    3096 [ #  # ][ #  # ]:          0 :     rArr.insert( rArr.begin() + nU, nIdx );
    3097         [ #  # ]:          0 :     if( pInsPos )
    3098                 :          0 :         *pInsPos = nU;
    3099                 :            : }
    3100                 :            : 
    3101                 :            : #if OSL_DEBUG_LEVEL > 0
    3102                 :            : void CheckTable( const SwTable& rTbl )
    3103                 :            : {
    3104                 :            :     const SwNodes& rNds = rTbl.GetFrmFmt()->GetDoc()->GetNodes();
    3105                 :            :     const SwTableSortBoxes& rSrtArr = rTbl.GetTabSortBoxes();
    3106                 :            :     for( sal_uInt16 n = 0; n < rSrtArr.size(); ++n )
    3107                 :            :     {
    3108                 :            :         const SwTableBox* pBox = rSrtArr[ n ];
    3109                 :            :         const SwNode* pNd = pBox->GetSttNd();
    3110                 :            :         OSL_ENSURE( rNds[ pBox->GetSttIdx() ] == pNd, "Box with wrong StartNode"  );
    3111                 :            :     }
    3112                 :            : }
    3113                 :            : #endif
    3114                 :            : 
    3115                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10