LCOV - code coverage report
Current view: top level - sw/source/core/doc - tblcpy.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 547 0.0 %
Date: 2014-04-14 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : 
      22             : #include <svl/zforlist.hxx>
      23             : #include <frmfmt.hxx>
      24             : #include <doc.hxx>
      25             : #include <IDocumentUndoRedo.hxx>
      26             : #include <cntfrm.hxx>
      27             : #include <pam.hxx>
      28             : #include <swtable.hxx>
      29             : #include <ndtxt.hxx>
      30             : #include <fldbas.hxx>
      31             : #include <tblsel.hxx>
      32             : #include <tabfrm.hxx>
      33             : #include <poolfmt.hxx>
      34             : #include <cellatr.hxx>
      35             : #include <mvsave.hxx>
      36             : #include <docary.hxx>
      37             : #include <fmtanchr.hxx>
      38             : #include <hints.hxx>
      39             : #include <UndoTable.hxx>
      40             : #include <redline.hxx>
      41             : #include <fmtfsize.hxx>
      42             : #include <list>
      43             : #include <boost/foreach.hpp>
      44             : #include <boost/scoped_ptr.hpp>
      45             : 
      46             : static void lcl_CpyBox( const SwTable& rCpyTbl, const SwTableBox* pCpyBox,
      47             :                     SwTable& rDstTbl, SwTableBox* pDstBox,
      48             :                     bool bDelCntnt, SwUndoTblCpyTbl* pUndo );
      49             : 
      50             : // The following type will be used by table copy functions to describe
      51             : // the structure of tables (or parts of tables).
      52             : // It's for new table model only.
      53             : 
      54             : namespace
      55             : {
      56             :     struct BoxSpanInfo
      57             :     {
      58             :         SwTableBox* mpBox;
      59             :         SwTableBox* mpCopy;
      60             :         sal_uInt16 mnColSpan;
      61             :         bool mbSelected;
      62             :     };
      63             : 
      64             :     typedef std::vector< BoxSpanInfo > BoxStructure;
      65             :     typedef std::vector< BoxStructure > LineStructure;
      66             :     typedef std::list< sal_uLong > ColumnStructure;
      67             : 
      68             :     struct SubBox
      69             :     {
      70             :         SwTableBox *mpBox;
      71             :         bool mbCovered;
      72             :     };
      73             : 
      74             :     typedef std::list< SubBox > SubLine;
      75             :     typedef std::list< SubLine > SubTable;
      76             : 
      77           0 :     class TableStructure
      78             :     {
      79             :     public:
      80             :         LineStructure maLines;
      81             :         ColumnStructure maCols;
      82             :         sal_uInt16 mnStartCol;
      83             :         sal_uInt16 mnAddLine;
      84             :         void addLine( sal_uInt16 &rLine, const SwTableBoxes&, const SwSelBoxes*,
      85             :                       bool bNewModel );
      86             :         void addBox( sal_uInt16 nLine, const SwSelBoxes*, SwTableBox *pBox,
      87             :                      sal_uLong &rnB, sal_uInt16 &rnC, ColumnStructure::iterator& rpCl,
      88             :                      BoxStructure::iterator& rpSel, bool &rbSel, bool bCover );
      89             :         void incColSpan( sal_uInt16 nLine, sal_uInt16 nCol );
      90             :         TableStructure( const SwTable& rTable );
      91             :         TableStructure( const SwTable& rTable, _FndBox &rFndBox,
      92             :                         const SwSelBoxes& rSelBoxes,
      93             :                         LineStructure::size_type nMinSize );
      94           0 :         LineStructure::size_type getLineCount() const
      95           0 :             { return maLines.size(); }
      96             :         void moreLines( const SwTable& rTable );
      97             :         void assignBoxes( const TableStructure &rSource );
      98             :         void copyBoxes( const SwTable& rSource, SwTable& rDstTbl,
      99             :                         SwUndoTblCpyTbl* pUndo ) const;
     100             :     };
     101             : 
     102             :     SubTable::iterator insertSubLine( SubTable& rSubTable, SwTableLine& rLine,
     103             :         SubTable::iterator pStartLn );
     104             : 
     105           0 :     SubTable::iterator insertSubBox( SubTable& rSubTable, SwTableBox& rBox,
     106             :         SubTable::iterator pStartLn, SubTable::iterator pEndLn )
     107             :     {
     108           0 :         if( !rBox.GetTabLines().empty() )
     109             :         {
     110           0 :             SubTable::difference_type nSize = std::distance( pStartLn, pEndLn );
     111           0 :             if( nSize < (sal_uInt16)rBox.GetTabLines().size() )
     112             :             {
     113           0 :                 SubLine aSubLine;
     114           0 :                 SubLine::iterator pBox = pStartLn->begin();
     115           0 :                 SubLine::iterator pEnd = pStartLn->end();
     116           0 :                 while( pBox != pEnd )
     117             :                 {
     118             :                     SubBox aSub;
     119           0 :                     aSub.mpBox = pBox->mpBox;
     120           0 :                     aSub.mbCovered = true;
     121           0 :                     aSubLine.push_back( aSub );
     122           0 :                     ++pBox;
     123             :                 }
     124           0 :                 do
     125             :                 {
     126           0 :                     rSubTable.insert( pEndLn, aSubLine );
     127           0 :                 } while( ++nSize < (sal_uInt16)rBox.GetTabLines().size() );
     128             :             }
     129           0 :             for( sal_uInt16 nLine = 0; nLine < rBox.GetTabLines().size(); ++nLine )
     130           0 :                 pStartLn = insertSubLine( rSubTable, *rBox.GetTabLines()[nLine],
     131           0 :                            pStartLn );
     132             :             OSL_ENSURE( pStartLn == pEndLn, "Sub line confusion" );
     133             :         }
     134             :         else
     135             :         {
     136             :             SubBox aSub;
     137           0 :             aSub.mpBox = &rBox;
     138           0 :             aSub.mbCovered = false;
     139           0 :             while( pStartLn != pEndLn )
     140             :             {
     141           0 :                 pStartLn->push_back( aSub );
     142           0 :                 aSub.mbCovered = true;
     143           0 :                 ++pStartLn;
     144             :             }
     145             :         }
     146           0 :         return pStartLn;
     147             :     }
     148             : 
     149           0 :     SubTable::iterator insertSubLine( SubTable& rSubTable, SwTableLine& rLine,
     150             :         SubTable::iterator pStartLn )
     151             :     {
     152           0 :         SubTable::iterator pMax = pStartLn;
     153           0 :         ++pMax;
     154           0 :         SubTable::difference_type nMax = 1;
     155           0 :         for( sal_uInt16 nBox = 0; nBox < rLine.GetTabBoxes().size(); ++nBox )
     156             :         {
     157             :             SubTable::iterator pTmp = insertSubBox( rSubTable,
     158           0 :                 *rLine.GetTabBoxes()[nBox], pStartLn, pMax );
     159           0 :             SubTable::difference_type nTmp = std::distance( pStartLn, pTmp );
     160           0 :             if( nTmp > nMax )
     161             :             {
     162           0 :                 pMax = pTmp;
     163           0 :                 nMax = nTmp;
     164             :             }
     165             :         }
     166           0 :         return pMax;
     167             :     }
     168             : 
     169           0 :     TableStructure::TableStructure( const SwTable& rTable ) :
     170           0 :         maLines( rTable.GetTabLines().size() ), mnStartCol(USHRT_MAX),
     171           0 :         mnAddLine(0)
     172             :     {
     173           0 :         maCols.push_front(0);
     174           0 :         const SwTableLines &rLines = rTable.GetTabLines();
     175           0 :         sal_uInt16 nCnt = 0;
     176           0 :         for( sal_uInt16 nLine = 0; nLine < rLines.size(); ++nLine )
     177           0 :             addLine( nCnt, rLines[nLine]->GetTabBoxes(), 0, rTable.IsNewModel() );
     178           0 :     }
     179             : 
     180           0 :     TableStructure::TableStructure( const SwTable& rTable,
     181             :         _FndBox &rFndBox, const SwSelBoxes& rSelBoxes,
     182             :         LineStructure::size_type nMinSize )
     183           0 :         : mnStartCol(USHRT_MAX), mnAddLine(0)
     184             :     {
     185           0 :         if( !rFndBox.GetLines().empty() )
     186             :         {
     187           0 :             bool bNoSelection = rSelBoxes.size() < 2;
     188           0 :             _FndLines &rFndLines = rFndBox.GetLines();
     189           0 :             maCols.push_front(0);
     190           0 :             const SwTableLine* pLine = rFndLines.front().GetLine();
     191           0 :             sal_uInt16 nStartLn = rTable.GetTabLines().GetPos( pLine );
     192           0 :             sal_uInt16 nEndLn = nStartLn;
     193           0 :             if( rFndLines.size() > 1 )
     194             :             {
     195           0 :                 pLine = rFndLines.back().GetLine();
     196           0 :                 nEndLn = rTable.GetTabLines().GetPos( pLine );
     197             :             }
     198           0 :             if( nStartLn < USHRT_MAX && nEndLn < USHRT_MAX )
     199             :             {
     200           0 :                 const SwTableLines &rLines = rTable.GetTabLines();
     201           0 :                 if( bNoSelection &&
     202           0 :                     (sal_uInt16)nMinSize > nEndLn - nStartLn + 1 )
     203             :                 {
     204           0 :                     sal_uInt16 nNewEndLn = nStartLn + (sal_uInt16)nMinSize - 1;
     205           0 :                     if( nNewEndLn >= rLines.size() )
     206             :                     {
     207           0 :                         mnAddLine = nNewEndLn - rLines.size() + 1;
     208           0 :                         nNewEndLn = rLines.size() - 1;
     209             :                     }
     210           0 :                     while( nEndLn < nNewEndLn )
     211             :                     {
     212           0 :                         SwTableLine *pLine2 = rLines[ ++nEndLn ];
     213           0 :                         SwTableBox *pTmpBox = pLine2->GetTabBoxes()[0];
     214           0 :                         _FndLine *pInsLine = new _FndLine( pLine2, &rFndBox );
     215           0 :                         _FndBox *pFndBox = new _FndBox( pTmpBox, pInsLine );
     216           0 :                         pInsLine->GetBoxes().insert(pInsLine->GetBoxes().begin(), pFndBox);
     217           0 :                         rFndLines.push_back( pInsLine );
     218             :                     }
     219             :                 }
     220           0 :                 maLines.resize( nEndLn - nStartLn + 1 );
     221           0 :                 const SwSelBoxes* pSelBoxes = &rSelBoxes;
     222           0 :                 sal_uInt16 nCnt = 0;
     223           0 :                 for( sal_uInt16 nLine = nStartLn; nLine <= nEndLn; ++nLine )
     224             :                 {
     225           0 :                     addLine( nCnt, rLines[nLine]->GetTabBoxes(),
     226           0 :                              pSelBoxes, rTable.IsNewModel() );
     227           0 :                     if( bNoSelection )
     228           0 :                         pSelBoxes = 0;
     229             :                 }
     230             :             }
     231           0 :             if( bNoSelection && mnStartCol < USHRT_MAX )
     232             :             {
     233           0 :                 BoxStructure::iterator pC = maLines[0].begin();
     234           0 :                 BoxStructure::iterator pEnd = maLines[0].end();
     235           0 :                 sal_uInt16 nIdx = mnStartCol;
     236           0 :                 mnStartCol = 0;
     237           0 :                 while( nIdx && pC != pEnd )
     238             :                 {
     239           0 :                     mnStartCol = mnStartCol + pC->mnColSpan;
     240           0 :                     --nIdx;
     241           0 :                     ++pC;
     242           0 :                 }
     243             :             }
     244             :             else
     245           0 :                 mnStartCol = USHRT_MAX;
     246             :         }
     247           0 :     }
     248             : 
     249           0 :     void TableStructure::addLine( sal_uInt16 &rLine, const SwTableBoxes& rBoxes,
     250             :         const SwSelBoxes* pSelBoxes, bool bNewModel )
     251             :     {
     252           0 :         bool bComplex = false;
     253           0 :         if( !bNewModel )
     254           0 :             for( sal_uInt16 nBox = 0; !bComplex && nBox < rBoxes.size(); ++nBox )
     255           0 :                 bComplex = !rBoxes[nBox]->GetTabLines().empty();
     256           0 :         if( bComplex )
     257             :         {
     258           0 :             SubTable aSubTable;
     259           0 :             SubLine aSubLine;
     260           0 :             aSubTable.push_back( aSubLine );
     261           0 :             SubTable::iterator pStartLn = aSubTable.begin();
     262           0 :             SubTable::iterator pEndLn = aSubTable.end();
     263           0 :             for( sal_uInt16 nBox = 0; nBox < rBoxes.size(); ++nBox )
     264           0 :                 insertSubBox( aSubTable, *rBoxes[nBox], pStartLn, pEndLn );
     265           0 :             SubTable::size_type nSize = aSubTable.size();
     266           0 :             if( nSize )
     267             :             {
     268           0 :                 maLines.resize( maLines.size() + nSize - 1 );
     269           0 :                 while( pStartLn != pEndLn )
     270             :                 {
     271           0 :                     bool bSelected = false;
     272           0 :                     sal_uLong nBorder = 0;
     273           0 :                     sal_uInt16 nCol = 0;
     274           0 :                     maLines[rLine].reserve( pStartLn->size() );
     275           0 :                     BoxStructure::iterator pSel = maLines[rLine].end();
     276           0 :                     ColumnStructure::iterator pCol = maCols.begin();
     277           0 :                     SubLine::iterator pBox = pStartLn->begin();
     278           0 :                     SubLine::iterator pEnd = pStartLn->end();
     279           0 :                     while( pBox != pEnd )
     280             :                     {
     281           0 :                         addBox( rLine, pSelBoxes, pBox->mpBox, nBorder, nCol,
     282           0 :                             pCol, pSel, bSelected, pBox->mbCovered );
     283           0 :                         ++pBox;
     284             :                     }
     285           0 :                     ++rLine;
     286           0 :                     ++pStartLn;
     287             :                 }
     288           0 :             }
     289             :         }
     290             :         else
     291             :         {
     292           0 :             bool bSelected = false;
     293           0 :             sal_uLong nBorder = 0;
     294           0 :             sal_uInt16 nCol = 0;
     295           0 :             maLines[rLine].reserve( rBoxes.size() );
     296           0 :             ColumnStructure::iterator pCol = maCols.begin();
     297           0 :             BoxStructure::iterator pSel = maLines[rLine].end();
     298           0 :             for( sal_uInt16 nBox = 0; nBox < rBoxes.size(); ++nBox )
     299           0 :                 addBox( rLine, pSelBoxes, rBoxes[nBox], nBorder, nCol,
     300           0 :                         pCol, pSel, bSelected, false );
     301           0 :             ++rLine;
     302             :         }
     303           0 :     }
     304             : 
     305           0 :     void TableStructure::addBox( sal_uInt16 nLine, const SwSelBoxes* pSelBoxes,
     306             :         SwTableBox *pBox, sal_uLong &rnBorder, sal_uInt16 &rnCol,
     307             :         ColumnStructure::iterator& rpCol, BoxStructure::iterator& rpSel,
     308             :         bool &rbSelected, bool bCovered )
     309             :     {
     310             :         BoxSpanInfo aInfo;
     311           0 :         if( pSelBoxes &&
     312           0 :             pSelBoxes->end() != pSelBoxes->find( pBox ) )
     313             :         {
     314           0 :             aInfo.mbSelected = true;
     315           0 :             if( mnStartCol == USHRT_MAX )
     316             :             {
     317           0 :                 mnStartCol = (sal_uInt16)maLines[nLine].size();
     318           0 :                 if( pSelBoxes->size() < 2 )
     319             :                 {
     320           0 :                     pSelBoxes = 0;
     321           0 :                     aInfo.mbSelected = false;
     322             :                 }
     323             :             }
     324             :         }
     325             :         else
     326           0 :             aInfo.mbSelected = false;
     327           0 :         rnBorder += pBox->GetFrmFmt()->GetFrmSize().GetWidth();
     328           0 :         sal_uInt16 nLeftCol = rnCol;
     329           0 :         while( rpCol != maCols.end() && *rpCol < rnBorder )
     330             :         {
     331           0 :             ++rnCol;
     332           0 :             ++rpCol;
     333             :         }
     334           0 :         if( rpCol == maCols.end() || *rpCol > rnBorder )
     335             :         {
     336           0 :             maCols.insert( rpCol, rnBorder );
     337           0 :             --rpCol;
     338           0 :             incColSpan( nLine, rnCol );
     339             :         }
     340           0 :         aInfo.mnColSpan = rnCol - nLeftCol;
     341           0 :         aInfo.mpCopy = 0;
     342           0 :         aInfo.mpBox = bCovered ? 0 : pBox;
     343           0 :         maLines[nLine].push_back( aInfo );
     344           0 :         if( aInfo.mbSelected )
     345             :         {
     346           0 :             if( rbSelected )
     347             :             {
     348           0 :                 while( rpSel != maLines[nLine].end() )
     349             :                 {
     350           0 :                     rpSel->mbSelected = true;
     351           0 :                     ++rpSel;
     352             :                 }
     353             :             }
     354             :             else
     355             :             {
     356           0 :                 rpSel = maLines[nLine].end();
     357           0 :                 rbSelected = true;
     358             :             }
     359           0 :             --rpSel;
     360             :         }
     361           0 :     }
     362             : 
     363           0 :     void TableStructure::moreLines( const SwTable& rTable )
     364             :     {
     365           0 :         if( mnAddLine )
     366             :         {
     367           0 :             const SwTableLines &rLines = rTable.GetTabLines();
     368           0 :             sal_uInt16 nLineCount = rLines.size();
     369           0 :             if( nLineCount < mnAddLine )
     370           0 :                 mnAddLine = nLineCount;
     371           0 :             sal_uInt16 nLine = (sal_uInt16)maLines.size();
     372           0 :             maLines.resize( nLine + mnAddLine );
     373           0 :             while( mnAddLine )
     374             :             {
     375           0 :                 SwTableLine *pLine = rLines[ nLineCount - mnAddLine ];
     376           0 :                 addLine( nLine, pLine->GetTabBoxes(), 0, rTable.IsNewModel() );
     377           0 :                 --mnAddLine;
     378             :             }
     379             :         }
     380           0 :     }
     381             : 
     382           0 :     void TableStructure::incColSpan( sal_uInt16 nLineMax, sal_uInt16 nNewCol )
     383             :     {
     384           0 :         for( sal_uInt16 nLine = 0; nLine < nLineMax; ++nLine )
     385             :         {
     386           0 :             BoxStructure::iterator pInfo = maLines[nLine].begin();
     387           0 :             BoxStructure::iterator pEnd = maLines[nLine].end();
     388           0 :             long nCol = pInfo->mnColSpan;
     389           0 :             while( nNewCol > nCol && ++pInfo != pEnd )
     390           0 :                 nCol += pInfo->mnColSpan;
     391           0 :             if( pInfo != pEnd )
     392           0 :                 ++(pInfo->mnColSpan);
     393             :         }
     394           0 :     }
     395             : 
     396           0 :     void TableStructure::assignBoxes( const TableStructure &rSource )
     397             :     {
     398           0 :         LineStructure::const_iterator pFirstLine = rSource.maLines.begin();
     399           0 :         LineStructure::const_iterator pLastLine = rSource.maLines.end();
     400           0 :         if( pFirstLine == pLastLine )
     401           0 :             return;
     402           0 :         LineStructure::const_iterator pCurrLine = pFirstLine;
     403           0 :         LineStructure::size_type nLineCount = maLines.size();
     404           0 :         sal_uInt16 nFirstStartCol = 0;
     405             :         {
     406           0 :             BoxStructure::const_iterator pFirstBox = pFirstLine->begin();
     407           0 :             if( pFirstBox != pFirstLine->end() && pFirstBox->mpBox &&
     408           0 :                 pFirstBox->mpBox->getDummyFlag() )
     409           0 :                 nFirstStartCol = pFirstBox->mnColSpan;
     410             :         }
     411           0 :         for( LineStructure::size_type nLine = 0; nLine < nLineCount; ++nLine )
     412             :         {
     413           0 :             BoxStructure::const_iterator pFirstBox = pCurrLine->begin();
     414           0 :             BoxStructure::const_iterator pLastBox = pCurrLine->end();
     415           0 :             sal_uInt16 nCurrStartCol = mnStartCol;
     416           0 :             if( pFirstBox != pLastBox )
     417             :             {
     418           0 :                 BoxStructure::const_iterator pTmpBox = pLastBox;
     419           0 :                 --pTmpBox;
     420           0 :                 if( pTmpBox->mpBox && pTmpBox->mpBox->getDummyFlag() )
     421           0 :                     --pLastBox;
     422           0 :                 if( pFirstBox != pLastBox && pFirstBox->mpBox &&
     423           0 :                     pFirstBox->mpBox->getDummyFlag() )
     424             :                 {
     425           0 :                     if( nCurrStartCol < USHRT_MAX )
     426             :                     {
     427           0 :                         if( pFirstBox->mnColSpan > nFirstStartCol )
     428           0 :                             nCurrStartCol = pFirstBox->mnColSpan - nFirstStartCol
     429           0 :                                             + nCurrStartCol;
     430             :                     }
     431           0 :                     ++pFirstBox;
     432             :                 }
     433             :             }
     434           0 :             if( pFirstBox != pLastBox )
     435             :             {
     436           0 :                 BoxStructure::const_iterator pCurrBox = pFirstBox;
     437           0 :                 BoxStructure &rBox = maLines[nLine];
     438           0 :                 BoxStructure::size_type nBoxCount = rBox.size();
     439           0 :                 sal_uInt16 nCol = 0;
     440           0 :                 for( BoxStructure::size_type nBox = 0; nBox < nBoxCount; ++nBox )
     441             :                 {
     442           0 :                     BoxSpanInfo& rInfo = rBox[nBox];
     443           0 :                     nCol = nCol + rInfo.mnColSpan;
     444           0 :                     if( rInfo.mbSelected || nCol > nCurrStartCol )
     445             :                     {
     446           0 :                         rInfo.mpCopy = pCurrBox->mpBox;
     447           0 :                         if( rInfo.mbSelected && rInfo.mpCopy->getDummyFlag() )
     448             :                         {
     449           0 :                             ++pCurrBox;
     450           0 :                             if( pCurrBox == pLastBox )
     451             :                             {
     452           0 :                                 pCurrBox = pFirstBox;
     453           0 :                                 if( pCurrBox->mpBox->getDummyFlag() )
     454           0 :                                     ++pCurrBox;
     455             :                             }
     456           0 :                             rInfo.mpCopy = pCurrBox->mpBox;
     457             :                         }
     458           0 :                         ++pCurrBox;
     459           0 :                         if( pCurrBox == pLastBox )
     460             :                         {
     461           0 :                             if( rInfo.mbSelected )
     462           0 :                                 pCurrBox = pFirstBox;
     463             :                             else
     464             :                             {
     465           0 :                                 rInfo.mbSelected = rInfo.mpCopy == 0;
     466           0 :                                 break;
     467             :                             }
     468             :                         }
     469           0 :                         rInfo.mbSelected = rInfo.mpCopy == 0;
     470             :                     }
     471             :                 }
     472             :             }
     473           0 :             ++pCurrLine;
     474           0 :             if( pCurrLine == pLastLine )
     475           0 :                 pCurrLine = pFirstLine;
     476             :         }
     477             :     }
     478             : 
     479           0 :     void TableStructure::copyBoxes( const SwTable& rSource, SwTable& rDstTbl,
     480             :                                     SwUndoTblCpyTbl* pUndo ) const
     481             :     {
     482           0 :         LineStructure::size_type nLineCount = maLines.size();
     483           0 :         for( LineStructure::size_type nLine = 0; nLine < nLineCount; ++nLine )
     484             :         {
     485           0 :             const BoxStructure &rBox = maLines[nLine];
     486           0 :             BoxStructure::size_type nBoxCount = rBox.size();
     487           0 :             for( BoxStructure::size_type nBox = 0; nBox < nBoxCount; ++nBox )
     488             :             {
     489           0 :                 const BoxSpanInfo& rInfo = rBox[nBox];
     490           0 :                 if( ( rInfo.mpCopy && !rInfo.mpCopy->getDummyFlag() )
     491           0 :                     || rInfo.mbSelected )
     492             :                 {
     493           0 :                     SwTableBox *pBox = rInfo.mpBox;
     494           0 :                     if( pBox && pBox->getRowSpan() > 0 )
     495             :                         lcl_CpyBox( rSource, rInfo.mpCopy, rDstTbl, pBox,
     496           0 :                                     true, pUndo );
     497             :                 }
     498             :             }
     499             :         }
     500           0 :     }
     501             : }
     502             : 
     503             : /** Copy Table into this Box.
     504             :     Copy all Boxes of a Line into the corresponding Boxes. The old content
     505             :     is deleted by doing this.
     506             :     If no Box is left the remaining content goes to the Box of a "BaseLine".
     507             :     If there's no Line anymore, put it also into the last Box of a "BaseLine". */
     508           0 : static void lcl_CpyBox( const SwTable& rCpyTbl, const SwTableBox* pCpyBox,
     509             :                     SwTable& rDstTbl, SwTableBox* pDstBox,
     510             :                     bool bDelCntnt, SwUndoTblCpyTbl* pUndo )
     511             : {
     512             :     OSL_ENSURE( ( !pCpyBox || pCpyBox->GetSttNd() ) && pDstBox->GetSttNd(),
     513             :             "No content in this Box" );
     514             : 
     515           0 :     SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
     516           0 :     SwDoc* pDoc = rDstTbl.GetFrmFmt()->GetDoc();
     517             : 
     518             :     // First copy the new content and then delete the old one.
     519             :     // Do not create empty Sections, otherwise they will be deleted!
     520             :     boost::scoped_ptr< SwNodeRange > pRg( pCpyBox ?
     521           0 :         new SwNodeRange ( *pCpyBox->GetSttNd(), 1,
     522           0 :         *pCpyBox->GetSttNd()->EndOfSectionNode() ) : 0 );
     523             : 
     524           0 :     SwNodeIndex aInsIdx( *pDstBox->GetSttNd(), bDelCntnt ? 1 :
     525           0 :                         pDstBox->GetSttNd()->EndOfSectionIndex() -
     526           0 :                         pDstBox->GetSttIdx() );
     527             : 
     528           0 :     if( pUndo )
     529           0 :         pUndo->AddBoxBefore( *pDstBox, bDelCntnt );
     530             : 
     531           0 :     bool bUndoRedline = pUndo && pDoc->IsRedlineOn();
     532           0 :     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
     533             : 
     534           0 :     SwNodeIndex aSavePos( aInsIdx, -1 );
     535           0 :     if( pRg.get() )
     536           0 :         pCpyDoc->CopyWithFlyInFly( *pRg, 0, aInsIdx, NULL, sal_False );
     537             :     else
     538           0 :         pDoc->GetNodes().MakeTxtNode( aInsIdx, (SwTxtFmtColl*)pDoc->GetDfltTxtFmtColl() );
     539           0 :     ++aSavePos;
     540             : 
     541           0 :     SwTableLine* pLine = pDstBox->GetUpper();
     542           0 :     while( pLine->GetUpper() )
     543           0 :         pLine = pLine->GetUpper()->GetUpper();
     544             : 
     545           0 :     bool bReplaceColl = true;
     546           0 :     if( bDelCntnt && !bUndoRedline )
     547             :     {
     548             :         // Delete the Fly first, then the corresponding Nodes
     549           0 :         SwNodeIndex aEndNdIdx( *aInsIdx.GetNode().EndOfSectionNode() );
     550             : 
     551             :         // Move Bookmarks
     552             :         {
     553           0 :             SwPosition aMvPos( aInsIdx );
     554           0 :             SwCntntNode* pCNd = pDoc->GetNodes().GoPrevious( &aMvPos.nNode );
     555           0 :             aMvPos.nContent.Assign( pCNd, pCNd->Len() );
     556           0 :             pDoc->CorrAbs( aInsIdx, aEndNdIdx, aMvPos, /*sal_True*/sal_False );
     557             :         }
     558             : 
     559             :         // If we still have FlyFrames hanging around, delete them too
     560           0 :         for( sal_uInt16 n = 0; n < pDoc->GetSpzFrmFmts()->size(); ++n )
     561             :         {
     562           0 :             SwFrmFmt *const pFly = (*pDoc->GetSpzFrmFmts())[n];
     563           0 :             SwFmtAnchor const*const pAnchor = &pFly->GetAnchor();
     564           0 :             SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
     565           0 :             if (pAPos &&
     566           0 :                 ((FLY_AT_PARA == pAnchor->GetAnchorId()) ||
     567           0 :                  (FLY_AT_CHAR == pAnchor->GetAnchorId())) &&
     568           0 :                 aInsIdx <= pAPos->nNode && pAPos->nNode <= aEndNdIdx )
     569             :             {
     570           0 :                 pDoc->DelLayoutFmt( pFly );
     571             :             }
     572             :         }
     573             : 
     574             :         // If DestBox is a Headline Box and has Table style set, then
     575             :         // DO NOT automatically set the TableHeadline style!
     576           0 :         if( 1 < rDstTbl.GetTabLines().size() &&
     577           0 :             pLine == rDstTbl.GetTabLines().front() )
     578             :         {
     579           0 :             SwCntntNode* pCNd = aInsIdx.GetNode().GetCntntNode();
     580           0 :             if( !pCNd )
     581             :             {
     582           0 :                 SwNodeIndex aTmp( aInsIdx );
     583           0 :                 pCNd = pDoc->GetNodes().GoNext( &aTmp );
     584             :             }
     585             : 
     586           0 :             if( pCNd &&
     587             :                 RES_POOLCOLL_TABLE_HDLN !=
     588           0 :                     pCNd->GetFmtColl()->GetPoolFmtId() )
     589           0 :                 bReplaceColl = false;
     590             :         }
     591             : 
     592           0 :         pDoc->GetNodes().Delete( aInsIdx, aEndNdIdx.GetIndex() - aInsIdx.GetIndex() );
     593             :     }
     594             : 
     595             :     //b6341295: Table copy redlining will be managed by AddBoxAfter()
     596           0 :     if( pUndo )
     597           0 :         pUndo->AddBoxAfter( *pDstBox, aInsIdx, bDelCntnt );
     598             : 
     599             :     // heading
     600           0 :     SwTxtNode *const pTxtNd = aSavePos.GetNode().GetTxtNode();
     601           0 :     if( pTxtNd )
     602             :     {
     603           0 :         sal_uInt16 nPoolId = pTxtNd->GetTxtColl()->GetPoolFmtId();
     604           0 :         if( bReplaceColl &&
     605           0 :             (( 1 < rDstTbl.GetTabLines().size() &&
     606           0 :                 pLine == rDstTbl.GetTabLines().front() )
     607             :                 // Is the Table's content sill valid?
     608             :                 ? RES_POOLCOLL_TABLE == nPoolId
     609             :                 : RES_POOLCOLL_TABLE_HDLN == nPoolId ) )
     610             :         {
     611             :             SwTxtFmtColl* pColl = pDoc->GetTxtCollFromPool(
     612             :                 static_cast<sal_uInt16>(
     613             :                                     RES_POOLCOLL_TABLE == nPoolId
     614             :                                         ? RES_POOLCOLL_TABLE_HDLN
     615           0 :                                         : RES_POOLCOLL_TABLE ) );
     616           0 :             if( pColl )         // Apply style
     617             :             {
     618           0 :                 SwPaM aPam( aSavePos );
     619           0 :                 aPam.SetMark();
     620           0 :                 aPam.Move( fnMoveForward, fnGoSection );
     621           0 :                 pDoc->SetTxtFmtColl( aPam, pColl );
     622             :             }
     623             :         }
     624             : 
     625             :         // Delete the current Formula/Format/Value values
     626           0 :         if( SFX_ITEM_SET == pDstBox->GetFrmFmt()->GetItemState( RES_BOXATR_FORMAT ) ||
     627           0 :             SFX_ITEM_SET == pDstBox->GetFrmFmt()->GetItemState( RES_BOXATR_FORMULA ) ||
     628           0 :             SFX_ITEM_SET == pDstBox->GetFrmFmt()->GetItemState( RES_BOXATR_VALUE ) )
     629             :         {
     630           0 :             pDstBox->ClaimFrmFmt()->ResetFmtAttr( RES_BOXATR_FORMAT,
     631           0 :                                                  RES_BOXATR_VALUE );
     632             :         }
     633             : 
     634             :         // Copy the TableBoxAttributes - Formula/Format/Value
     635           0 :         if( pCpyBox )
     636             :         {
     637           0 :             SfxItemSet aBoxAttrSet( pCpyDoc->GetAttrPool(), RES_BOXATR_FORMAT,
     638           0 :                                                             RES_BOXATR_VALUE );
     639           0 :             aBoxAttrSet.Put( pCpyBox->GetFrmFmt()->GetAttrSet() );
     640           0 :             if( aBoxAttrSet.Count() )
     641             :             {
     642             :                 const SfxPoolItem* pItem;
     643           0 :                 SvNumberFormatter* pN = pDoc->GetNumberFormatter( sal_False );
     644           0 :                 if( pN && pN->HasMergeFmtTbl() && SFX_ITEM_SET == aBoxAttrSet.
     645           0 :                     GetItemState( RES_BOXATR_FORMAT, false, &pItem ) )
     646             :                 {
     647           0 :                     sal_uLong nOldIdx = ((SwTblBoxNumFormat*)pItem)->GetValue();
     648           0 :                     sal_uLong nNewIdx = pN->GetMergeFmtIndex( nOldIdx );
     649           0 :                     if( nNewIdx != nOldIdx )
     650           0 :                         aBoxAttrSet.Put( SwTblBoxNumFormat( nNewIdx ));
     651             :                 }
     652           0 :                 pDstBox->ClaimFrmFmt()->SetFmtAttr( aBoxAttrSet );
     653           0 :             }
     654             :         }
     655           0 :     }
     656           0 : }
     657             : 
     658           0 : sal_Bool SwTable::InsNewTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
     659             :                         SwUndoTblCpyTbl* pUndo )
     660             : {
     661           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     662           0 :     SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
     663             : 
     664           0 :     SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
     665             : 
     666             :     // Analyze source structure
     667           0 :     TableStructure aCopyStruct( rCpyTbl );
     668             : 
     669             :     // Analyze target structure (from start box) and selected substructure
     670           0 :     _FndBox aFndBox( 0, 0 );
     671             :     {   // get all boxes/lines
     672           0 :         _FndPara aPara( rSelBoxes, &aFndBox );
     673           0 :         ForEach_FndLineCopyCol( GetTabLines(), &aPara );
     674             :     }
     675           0 :     TableStructure aTarget( *this, aFndBox, rSelBoxes, aCopyStruct.getLineCount() );
     676             : 
     677           0 :     bool bClear = false;
     678           0 :     if( aTarget.mnAddLine && IsNewModel() )
     679             :     {
     680           0 :         SwSelBoxes aBoxes;
     681           0 :         aBoxes.insert( GetTabLines().back()->GetTabBoxes().front() );
     682           0 :         if( pUndo )
     683           0 :             pUndo->InsertRow( *this, aBoxes, aTarget.mnAddLine );
     684             :         else
     685           0 :             InsertRow( pDoc, aBoxes, aTarget.mnAddLine, true );
     686             : 
     687           0 :         aTarget.moreLines( *this );
     688           0 :         bClear = true;
     689             :     }
     690             : 
     691             :     // Find mapping, if needed extend target table and/or selection
     692           0 :     aTarget.assignBoxes( aCopyStruct );
     693             : 
     694             :     {
     695             :         // Change table formulas into relative representation
     696           0 :         SwTableFmlUpdate aMsgHnt( &rCpyTbl );
     697           0 :         aMsgHnt.eFlags = TBL_RELBOXNAME;
     698           0 :         pCpyDoc->UpdateTblFlds( &aMsgHnt );
     699             :     }
     700             : 
     701             :     // delete frames
     702           0 :     aFndBox.SetTableLines( *this );
     703           0 :     if( bClear )
     704           0 :         aFndBox.ClearLineBehind();
     705           0 :     aFndBox.DelFrms( *this );
     706             : 
     707             :     // copy boxes
     708           0 :     aTarget.copyBoxes( rCpyTbl, *this, pUndo );
     709             : 
     710             :     // adjust row span attributes accordingly
     711             : 
     712             :     // make frames
     713           0 :     aFndBox.MakeFrms( *this );
     714             : 
     715           0 :     return sal_True;
     716             : }
     717             : 
     718             : /** Copy Table into this Box.
     719             :     Copy all Boxes of a Line into the corresponding Boxes. The old content is
     720             :     deleted by doing this.
     721             :     If no Box is left the remaining content goes to the Box of a "BaseLine".
     722             :     If there's no Line anymore, put it also into the last Box of a "BaseLine". */
     723           0 : sal_Bool SwTable::InsTable( const SwTable& rCpyTbl, const SwNodeIndex& rSttBox,
     724             :                         SwUndoTblCpyTbl* pUndo )
     725             : {
     726           0 :     SetHTMLTableLayout( 0 );    // Delete HTML Layout
     727             : 
     728           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     729             : 
     730           0 :     SwTableNode* pTblNd = pDoc->IsIdxInTbl( rSttBox );
     731             : 
     732             :     // Find the Box, to which should be copied:
     733             :     SwTableBox* pMyBox = (SwTableBox*)GetTblBox(
     734           0 :             rSttBox.GetNode().FindTableBoxStartNode()->GetIndex() );
     735             : 
     736             :     OSL_ENSURE( pMyBox, "Index is not in a Box in this Table" );
     737             : 
     738             :     // First delete the Table's Frames
     739           0 :     _FndBox aFndBox( 0, 0 );
     740           0 :     aFndBox.DelFrms( pTblNd->GetTable() );
     741             : 
     742           0 :     SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
     743             : 
     744             :     {
     745             :         // Convert Table formulas to their relative representation
     746           0 :         SwTableFmlUpdate aMsgHnt( &rCpyTbl );
     747           0 :         aMsgHnt.eFlags = TBL_RELBOXNAME;
     748           0 :         pCpyDoc->UpdateTblFlds( &aMsgHnt );
     749             :     }
     750             : 
     751           0 :     SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
     752             : 
     753           0 :     bool bDelCntnt = true;
     754             :     const SwTableBox* pTmp;
     755             : 
     756           0 :     for( sal_uInt16 nLines = 0; nLines < rCpyTbl.GetTabLines().size(); ++nLines )
     757             :     {
     758             :         // Get the first from the CopyLine
     759           0 :         const SwTableBox* pCpyBox = rCpyTbl.GetTabLines()[nLines]
     760           0 :                                     ->GetTabBoxes().front();
     761           0 :         while( !pCpyBox->GetTabLines().empty() )
     762           0 :             pCpyBox = pCpyBox->GetTabLines().front()->GetTabBoxes().front();
     763             : 
     764             :         do {
     765             :             // First copy the new content and then delete the old one.
     766             :             // Do not create empty Sections, otherwise they will be deleted!
     767           0 :             lcl_CpyBox( rCpyTbl, pCpyBox, *this, pMyBox, bDelCntnt, pUndo );
     768             : 
     769           0 :             if( 0 == (pTmp = pCpyBox->FindNextBox( rCpyTbl, pCpyBox, false )))
     770           0 :                 break;      // no more Boxes
     771           0 :             pCpyBox = pTmp;
     772             : 
     773           0 :             if( 0 == ( pTmp = pMyBox->FindNextBox( *this, pMyBox, false )))
     774           0 :                 bDelCntnt = false;  // No space left?
     775             :             else
     776           0 :                 pMyBox = (SwTableBox*)pTmp;
     777             : 
     778             :         } while( true );
     779             : 
     780             :         // Find the topmost Line
     781           0 :         SwTableLine* pNxtLine = pMyBox->GetUpper();
     782           0 :         while( pNxtLine->GetUpper() )
     783           0 :             pNxtLine = pNxtLine->GetUpper()->GetUpper();
     784           0 :         sal_uInt16 nPos = GetTabLines().GetPos( pNxtLine );
     785             :         // Is there a next?
     786           0 :         if( nPos + 1 >= (sal_uInt16)GetTabLines().size() )
     787           0 :             bDelCntnt = false;      // there is none, all goes into the last Box
     788             :         else
     789             :         {
     790             :             // Find the next Box with content
     791           0 :             pNxtLine = GetTabLines()[ nPos+1 ];
     792           0 :             pMyBox = pNxtLine->GetTabBoxes().front();
     793           0 :             while( !pMyBox->GetTabLines().empty() )
     794           0 :                 pMyBox = pMyBox->GetTabLines().front()->GetTabBoxes().front();
     795           0 :             bDelCntnt = true;
     796             :         }
     797           0 :     }
     798             : 
     799           0 :     aFndBox.MakeFrms( pTblNd->GetTable() );     // Create the Frames anew
     800           0 :     return sal_True;
     801             : }
     802             : 
     803           0 : sal_Bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
     804             :                         SwUndoTblCpyTbl* pUndo )
     805             : {
     806             :     OSL_ENSURE( !rSelBoxes.empty(), "Missing selection" );
     807             : 
     808           0 :     SetHTMLTableLayout( 0 );    // Delete HTML Layout
     809             : 
     810           0 :     if( IsNewModel() || rCpyTbl.IsNewModel() )
     811           0 :         return InsNewTable( rCpyTbl, rSelBoxes, pUndo );
     812             : 
     813             :     OSL_ENSURE( !rCpyTbl.IsTblComplex(), "Table too complex" );
     814             : 
     815           0 :     SwDoc* pDoc = GetFrmFmt()->GetDoc();
     816           0 :     SwDoc* pCpyDoc = rCpyTbl.GetFrmFmt()->GetDoc();
     817             : 
     818           0 :     SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
     819             : 
     820           0 :     SwTableBox *pTmpBox, *pSttBox = (SwTableBox*)rSelBoxes[0];
     821             : 
     822             :     sal_uInt16 nLn, nBx;
     823           0 :     _FndLine *pFLine, *pInsFLine = 0;
     824           0 :     _FndBox aFndBox( 0, 0 );
     825             :     // Find all Boxes/Lines
     826             :     {
     827           0 :         _FndPara aPara( rSelBoxes, &aFndBox );
     828           0 :         ForEach_FndLineCopyCol( GetTabLines(), &aPara );
     829             :     }
     830             : 
     831             :     // Special case: If a Box is located in a Table, copy it to all selected
     832             :     // Boxes!
     833           0 :     if( 1 != rCpyTbl.GetTabSortBoxes().size() )
     834             :     {
     835           0 :         SwTableLine* pSttLine = pSttBox->GetUpper();
     836           0 :         sal_uInt16 nSttLine = GetTabLines().GetPos( pSttLine );
     837             :         _FndBox* pFndBox;
     838             : 
     839           0 :         sal_uInt16 nFndCnt = aFndBox.GetLines().size();
     840           0 :         if( !nFndCnt )
     841           0 :             return sal_False;
     842             : 
     843             :         // Check if we have enough space for all Lines and Boxes
     844           0 :         sal_uInt16 nTstLns = 0;
     845           0 :         pFLine = &aFndBox.GetLines().front();
     846           0 :         pSttLine = pFLine->GetLine();
     847           0 :         nSttLine = GetTabLines().GetPos( pSttLine );
     848             :         // Do we have as many rows, actually?
     849           0 :         if( 1 == nFndCnt )
     850             :         {
     851             :             // Is there still enough space in the Table?
     852           0 :             if( (GetTabLines().size() - nSttLine ) <
     853           0 :                 rCpyTbl.GetTabLines().size() )
     854             :             {
     855             :                 // If we don't have enough Lines, then see if we can insert
     856             :                 // new ones to reach our goal. But only if the SSelection
     857             :                 // contains a Box!
     858           0 :                 if( 1 < rSelBoxes.size() )
     859           0 :                     return sal_False;
     860             : 
     861           0 :                 sal_uInt16 nNewLns = rCpyTbl.GetTabLines().size() -
     862           0 :                                 (GetTabLines().size() - nSttLine );
     863             : 
     864             :                 // See if the Box count is high enough for the Lines
     865           0 :                 SwTableLine* pLastLn = GetTabLines().back();
     866             : 
     867           0 :                 pSttBox = pFLine->GetBoxes()[0].GetBox();
     868           0 :                 sal_uInt16 nSttBox = pFLine->GetLine()->GetTabBoxes().GetPos( pSttBox );
     869           0 :                 for( sal_uInt16 n = rCpyTbl.GetTabLines().size() - nNewLns;
     870           0 :                         n < rCpyTbl.GetTabLines().size(); ++n )
     871             :                 {
     872           0 :                     SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[ n ];
     873             : 
     874           0 :                     if( pLastLn->GetTabBoxes().size() < nSttBox ||
     875           0 :                         ( pLastLn->GetTabBoxes().size() - nSttBox ) <
     876           0 :                             pCpyLn->GetTabBoxes().size() )
     877           0 :                         return sal_False;
     878             : 
     879             :                     // Test for nesting
     880           0 :                     for( nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
     881           0 :                         if( !( pTmpBox = pLastLn->GetTabBoxes()[ nSttBox + nBx ])
     882           0 :                                     ->GetSttNd() )
     883           0 :                             return sal_False;
     884             :                 }
     885             :                 // We have enough space for the to-be-copied, so insert new
     886             :                 // rows accordingly.
     887           0 :                 SwTableBox* pInsBox = pLastLn->GetTabBoxes()[ nSttBox ];
     888             :                 OSL_ENSURE( pInsBox && pInsBox->GetSttNd(),
     889             :                     "no CntntBox or it's not in this Table" );
     890           0 :                 SwSelBoxes aBoxes;
     891             : 
     892           0 :                 if( pUndo
     893             :                     ? !pUndo->InsertRow( *this, SelLineFromBox( pInsBox,
     894           0 :                                 aBoxes, true ), nNewLns )
     895             :                     : !InsertRow( pDoc, SelLineFromBox( pInsBox,
     896           0 :                                 aBoxes, true ), nNewLns, true ) )
     897           0 :                     return sal_False;
     898             :             }
     899             : 
     900           0 :             nTstLns = rCpyTbl.GetTabLines().size();        // copy this many
     901             :         }
     902           0 :         else if( 0 == (nFndCnt % rCpyTbl.GetTabLines().size()) )
     903           0 :             nTstLns = nFndCnt;
     904             :         else
     905           0 :             return sal_False;       // not enough space for the rows
     906             : 
     907           0 :         for( nLn = 0; nLn < nTstLns; ++nLn )
     908             :         {
     909             :             // We have enough rows, so check the Boxes per row
     910           0 :             pFLine = &aFndBox.GetLines()[ nLn % nFndCnt ];
     911           0 :             SwTableLine* pLine = pFLine->GetLine();
     912           0 :             pSttBox = pFLine->GetBoxes()[0].GetBox();
     913           0 :             sal_uInt16 nSttBox = pLine->GetTabBoxes().GetPos( pSttBox );
     914           0 :             if( nLn >= nFndCnt )
     915             :             {
     916             :                 // We have more rows in the ClipBoard than we have selected
     917           0 :                 pInsFLine = new _FndLine( GetTabLines()[ nSttLine + nLn ],
     918           0 :                                         &aFndBox );
     919           0 :                 pLine = pInsFLine->GetLine();
     920             :             }
     921           0 :             SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[ nLn %
     922           0 :                                         rCpyTbl.GetTabLines().size() ];
     923             : 
     924             :             // Selected too few rows?
     925           0 :             if( pInsFLine )
     926             :             {
     927             :                 // We insert a new row into the FndBox
     928           0 :                 if( pLine->GetTabBoxes().size() < nSttBox ||
     929             :                     sal::static_int_cast< sal_uInt16 >(
     930           0 :                         pLine->GetTabBoxes().size() - nSttBox ) <
     931           0 :                     pFLine->GetBoxes().size() )
     932             :                 {
     933           0 :                     delete pInsFLine;
     934           0 :                     return sal_False;
     935             :                 }
     936             : 
     937             :                 // Test for nesting
     938           0 :                 for( nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
     939             :                 {
     940           0 :                     if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
     941           0 :                         ->GetSttNd() )
     942             :                     {
     943           0 :                         delete pInsFLine;
     944           0 :                         return sal_False;
     945             :                     }
     946             :                     // if Ok, insert the Box into the FndLine
     947           0 :                     pFndBox = new _FndBox( pTmpBox, pInsFLine );
     948           0 :                     pInsFLine->GetBoxes().insert( pInsFLine->GetBoxes().begin() + nBx, pFndBox );
     949             :                 }
     950           0 :                 aFndBox.GetLines().insert( aFndBox.GetLines().begin() + nLn, pInsFLine );
     951             :             }
     952           0 :             else if( pFLine->GetBoxes().size() == 1 )
     953             :             {
     954           0 :                 if( pLine->GetTabBoxes().size() < nSttBox  ||
     955           0 :                     ( pLine->GetTabBoxes().size() - nSttBox ) <
     956           0 :                     pCpyLn->GetTabBoxes().size() )
     957           0 :                     return sal_False;
     958             : 
     959             :                 // Test for nesting
     960           0 :                 for( nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
     961             :                 {
     962           0 :                     if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
     963           0 :                         ->GetSttNd() )
     964           0 :                         return sal_False;
     965             :                     // if Ok, insert the Box into the FndLine
     966           0 :                     if( nBx == pFLine->GetBoxes().size() )
     967             :                     {
     968           0 :                         pFndBox = new _FndBox( pTmpBox, pFLine );
     969           0 :                         pFLine->GetBoxes().insert( pFLine->GetBoxes().begin() + nBx, pFndBox );
     970             :                     }
     971             :                 }
     972             :             }
     973             :             else
     974             :             {
     975             :                 // Match the selected Boxes with the ones in the Clipboard
     976             :                 // (n times)
     977           0 :                 if( 0 != ( pFLine->GetBoxes().size() %
     978           0 :                             pCpyLn->GetTabBoxes().size() ))
     979           0 :                     return sal_False;
     980             : 
     981             :                 // Test for nesting
     982           0 :                 for( nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
     983           0 :                     if (!pFLine->GetBoxes()[nBx].GetBox()->GetSttNd())
     984           0 :                         return sal_False;
     985             :             }
     986             :         }
     987             : 
     988           0 :         if( aFndBox.GetLines().empty() )
     989           0 :             return sal_False;
     990             :     }
     991             : 
     992             :     {
     993             :         // Convert Table formulas to their relative representation
     994           0 :         SwTableFmlUpdate aMsgHnt( &rCpyTbl );
     995           0 :         aMsgHnt.eFlags = TBL_RELBOXNAME;
     996           0 :         pCpyDoc->UpdateTblFlds( &aMsgHnt );
     997             :     }
     998             : 
     999             :     // Delete the Frames
    1000           0 :     aFndBox.SetTableLines( *this );
    1001             :     //Not dispose accessible table
    1002           0 :     aFndBox.DelFrms( *this,sal_False );
    1003             : 
    1004           0 :     if( 1 == rCpyTbl.GetTabSortBoxes().size() )
    1005             :     {
    1006           0 :         SwTableBox *pTmpBx = rCpyTbl.GetTabSortBoxes()[0];
    1007           0 :         for (size_t n = 0; n < rSelBoxes.size(); ++n)
    1008             :         {
    1009             :             lcl_CpyBox( rCpyTbl, pTmpBx, *this,
    1010           0 :                         (SwTableBox*)rSelBoxes[n], true, pUndo );
    1011             :         }
    1012             :     }
    1013             :     else
    1014           0 :         for( nLn = 0; nLn < aFndBox.GetLines().size(); ++nLn )
    1015             :         {
    1016           0 :             pFLine = &aFndBox.GetLines()[ nLn ];
    1017           0 :             SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[
    1018           0 :                                 nLn % rCpyTbl.GetTabLines().size() ];
    1019           0 :             for( nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
    1020             :             {
    1021             :                 // Copy the pCpyBox into pMyBox
    1022           0 :                 lcl_CpyBox( rCpyTbl, pCpyLn->GetTabBoxes()[
    1023           0 :                             nBx % pCpyLn->GetTabBoxes().size() ],
    1024           0 :                     *this, pFLine->GetBoxes()[nBx].GetBox(), true, pUndo );
    1025             :             }
    1026             :         }
    1027             : 
    1028           0 :     aFndBox.MakeFrms( *this );
    1029           0 :     return sal_True;
    1030             : }
    1031             : 
    1032             : static void _FndCntntLine( const SwTableLine* pLine, SwSelBoxes* pPara );
    1033             : 
    1034           0 : static void _FndCntntBox( const SwTableBox* pBox, SwSelBoxes* pPara )
    1035             : {
    1036           0 :     if( !pBox->GetTabLines().empty() )
    1037             :     {
    1038           0 :         BOOST_FOREACH( const SwTableLine* pLine, pBox->GetTabLines() )
    1039           0 :             _FndCntntLine( pLine, pPara );
    1040             :     }
    1041             :     else
    1042           0 :         pPara->insert( (SwTableBox*)pBox );
    1043           0 : }
    1044             : 
    1045           0 : static void _FndCntntLine( const SwTableLine* pLine, SwSelBoxes* pPara )
    1046             : {
    1047           0 :     BOOST_FOREACH( const SwTableBox* pBox, pLine->GetTabBoxes() )
    1048           0 :         _FndCntntBox(pBox, pPara );
    1049           0 : }
    1050             : 
    1051             : // Find all Boxes with content in this Box
    1052           0 : SwSelBoxes& SwTable::SelLineFromBox( const SwTableBox* pBox,
    1053             :                                     SwSelBoxes& rBoxes, bool bToTop ) const
    1054             : {
    1055           0 :     SwTableLine* pLine = (SwTableLine*)pBox->GetUpper();
    1056           0 :     if( bToTop )
    1057           0 :         while( pLine->GetUpper() )
    1058           0 :             pLine = pLine->GetUpper()->GetUpper();
    1059             : 
    1060             :     // Delete all old ones
    1061           0 :     rBoxes.clear();
    1062           0 :     for( SwTableBoxes::iterator it = pLine->GetTabBoxes().begin();
    1063           0 :              it != pLine->GetTabBoxes().end(); ++it)
    1064           0 :         _FndCntntBox(*it, &rBoxes );
    1065           0 :     return rBoxes;
    1066             : }
    1067             : 
    1068             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10