LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/undo - unsort.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 113 0.0 %
Date: 2012-12-17 Functions: 0 10 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 <UndoSort.hxx>
      21             : #include <doc.hxx>
      22             : #include <swundo.hxx>
      23             : #include <pam.hxx>
      24             : #include <swtable.hxx>
      25             : #include <ndtxt.hxx>
      26             : #include <UndoCore.hxx>
      27             : #include <UndoTable.hxx>
      28             : #include <sortopt.hxx>
      29             : #include <docsort.hxx>
      30             : #include <redline.hxx>
      31             : #include <node2lay.hxx>
      32             : 
      33             : /*--------------------------------------------------------------------
      34             :     Description:   Undo for Sorting
      35             :  --------------------------------------------------------------------*/
      36             : 
      37           0 : SwSortUndoElement::~SwSortUndoElement()
      38             : {
      39             :     // are there string pointers saved?
      40           0 :     if( 0xffffffff != SORT_TXT_TBL.TXT.nKenn ) // Kenn(ung) = identifier
      41             :     {
      42           0 :         delete SORT_TXT_TBL.TBL.pSource;
      43           0 :         delete SORT_TXT_TBL.TBL.pTarget;
      44             :     }
      45           0 : }
      46             : 
      47           0 : SwUndoSort::SwUndoSort(const SwPaM& rRg, const SwSortOptions& rOpt)
      48             :     : SwUndo(UNDO_SORT_TXT), SwUndRng(rRg), pUndoTblAttr( 0 ),
      49           0 :     pRedlData( 0 )
      50             : {
      51           0 :     pSortOpt = new SwSortOptions(rOpt);
      52           0 : }
      53             : 
      54           0 : SwUndoSort::SwUndoSort( sal_uLong nStt, sal_uLong nEnd, const SwTableNode& rTblNd,
      55             :                         const SwSortOptions& rOpt, bool bSaveTable )
      56           0 :     : SwUndo(UNDO_SORT_TBL), pUndoTblAttr( 0 ), pRedlData( 0 )
      57             : {
      58           0 :     nSttNode = nStt;
      59           0 :     nEndNode = nEnd;
      60           0 :     nTblNd   = rTblNd.GetIndex();
      61             : 
      62           0 :     pSortOpt = new SwSortOptions(rOpt);
      63           0 :     if( bSaveTable )
      64           0 :         pUndoTblAttr = new SwUndoAttrTbl( rTblNd );
      65           0 : }
      66             : 
      67           0 : SwUndoSort::~SwUndoSort()
      68             : {
      69           0 :     delete pSortOpt;
      70           0 :     delete pUndoTblAttr;
      71           0 :     delete pRedlData;
      72           0 : }
      73             : 
      74           0 : void SwUndoSort::UndoImpl(::sw::UndoRedoContext & rContext)
      75             : {
      76           0 :     SwDoc & rDoc = rContext.GetDoc();
      77           0 :     if(pSortOpt->bTable)
      78             :     {
      79             :         // Undo for Table
      80           0 :         RemoveIdxFromSection( rDoc, nSttNode, &nEndNode );
      81             : 
      82           0 :         if( pUndoTblAttr )
      83             :         {
      84           0 :             pUndoTblAttr->UndoImpl(rContext);
      85             :         }
      86             : 
      87           0 :         SwTableNode* pTblNd = rDoc.GetNodes()[ nTblNd ]->GetTableNode();
      88             : 
      89             :         // #i37739# A simple 'MakeFrms' after the node sorting
      90             :         // does not work if the table is inside a frame and has no prev/next.
      91           0 :         SwNode2Layout aNode2Layout( *pTblNd );
      92             : 
      93           0 :         pTblNd->DelFrms();
      94           0 :         const SwTable& rTbl = pTblNd->GetTable();
      95             : 
      96           0 :         SwMovedBoxes aMovedList;
      97           0 :         for( sal_uInt16 i=0; i < aSortList.size(); i++)
      98             :         {
      99             :             const SwTableBox* pSource = rTbl.GetTblBox(
     100           0 :                     *aSortList[i].SORT_TXT_TBL.TBL.pSource );
     101             :             const SwTableBox* pTarget = rTbl.GetTblBox(
     102           0 :                     *aSortList[i].SORT_TXT_TBL.TBL.pTarget );
     103             : 
     104             :             // move back
     105             :             MoveCell(&rDoc, pTarget, pSource,
     106           0 :                      USHRT_MAX != aMovedList.GetPos(pSource) );
     107             : 
     108             :             // store moved entry in list
     109           0 :             aMovedList.push_back(pTarget);
     110             :         }
     111             : 
     112             :         // Restore table frames:
     113             :         // #i37739# A simple 'MakeFrms' after the node sorting
     114             :         // does not work if the table is inside a frame and has no prev/next.
     115           0 :         const sal_uLong nIdx = pTblNd->GetIndex();
     116           0 :         aNode2Layout.RestoreUpperFrms( rDoc.GetNodes(), nIdx, nIdx + 1 );
     117             :     }
     118             :     else
     119             :     {
     120             :         // Undo for Text
     121           0 :         SwPaM & rPam( AddUndoRedoPaM(rContext) );
     122           0 :         RemoveIdxFromRange(rPam, true);
     123             : 
     124             :         // create index for (sorted) positions
     125             :         // The IndexList must be created based on (asc.) sorted SourcePosition.
     126           0 :         SwUndoSortList aIdxList;
     127             :         sal_uInt16 i;
     128             : 
     129           0 :         for( i = 0; i < aSortList.size(); ++i)
     130           0 :             for( sal_uInt16 ii=0; ii < aSortList.size(); ++ii )
     131           0 :                 if( aSortList[ii].SORT_TXT_TBL.TXT.nSource == nSttNode + i )
     132             :                 {
     133             :                     SwNodeIndex* pIdx = new SwNodeIndex( rDoc.GetNodes(),
     134           0 :                         aSortList[ii].SORT_TXT_TBL.TXT.nTarget );
     135           0 :                     aIdxList.insert( aIdxList.begin() + i, pIdx );
     136             :                     break;
     137             :                 }
     138             : 
     139           0 :         for(i=0; i < aSortList.size(); ++i)
     140             :         {
     141           0 :             SwNodeIndex aIdx( rDoc.GetNodes(), nSttNode + i );
     142           0 :             SwNodeRange aRg( *aIdxList[i], 0, *aIdxList[i], 1 );
     143             :             rDoc.MoveNodeRange(aRg, aIdx,
     144           0 :                 IDocumentContentOperations::DOC_MOVEDEFAULT);
     145           0 :         }
     146             :         // delete indices
     147           0 :         for(SwUndoSortList::const_iterator it = aIdxList.begin(); it != aIdxList.end(); ++it)
     148           0 :             delete *it;
     149           0 :         aIdxList.clear();
     150           0 :         SetPaM(rPam, true);
     151             :     }
     152           0 : }
     153             : 
     154           0 : void SwUndoSort::RedoImpl(::sw::UndoRedoContext & rContext)
     155             : {
     156           0 :     SwDoc & rDoc = rContext.GetDoc();
     157             : 
     158           0 :     if(pSortOpt->bTable)
     159             :     {
     160             :         // Redo for Table
     161           0 :         RemoveIdxFromSection( rDoc, nSttNode, &nEndNode );
     162             : 
     163           0 :         SwTableNode* pTblNd = rDoc.GetNodes()[ nTblNd ]->GetTableNode();
     164             : 
     165             :         // #i37739# A simple 'MakeFrms' after the node sorting
     166             :         // does not work if the table is inside a frame and has no prev/next.
     167           0 :         SwNode2Layout aNode2Layout( *pTblNd );
     168             : 
     169           0 :         pTblNd->DelFrms();
     170           0 :         const SwTable& rTbl = pTblNd->GetTable();
     171             : 
     172           0 :         SwMovedBoxes aMovedList;
     173           0 :         for(sal_uInt16 i=0; i < aSortList.size(); ++i)
     174             :         {
     175             :             const SwTableBox* pSource = rTbl.GetTblBox(
     176           0 :                     (const String&) *aSortList[i].SORT_TXT_TBL.TBL.pSource );
     177             :             const SwTableBox* pTarget = rTbl.GetTblBox(
     178           0 :                     (const String&) *aSortList[i].SORT_TXT_TBL.TBL.pTarget );
     179             : 
     180             :             // move back
     181             :             MoveCell(&rDoc, pSource, pTarget,
     182           0 :                      USHRT_MAX != aMovedList.GetPos( pTarget ) );
     183             :             // store moved entry in list
     184           0 :             aMovedList.push_back( pSource );
     185             :         }
     186             : 
     187           0 :         if( pUndoTblAttr )
     188             :         {
     189           0 :             pUndoTblAttr->RedoImpl(rContext);
     190             :         }
     191             : 
     192             :         // Restore table frames:
     193             :         // #i37739# A simple 'MakeFrms' after the node sorting
     194             :         // does not work if the table is inside a frame and has no prev/next.
     195           0 :         const sal_uLong nIdx = pTblNd->GetIndex();
     196           0 :         aNode2Layout.RestoreUpperFrms( rDoc.GetNodes(), nIdx, nIdx + 1 );
     197             :     }
     198             :     else
     199             :     {
     200             :         // Redo for Text
     201           0 :         SwPaM & rPam( AddUndoRedoPaM(rContext) );
     202           0 :         SetPaM(rPam);
     203           0 :         RemoveIdxFromRange(rPam, true);
     204             : 
     205           0 :         SwUndoSortList aIdxList;
     206             :         sal_uInt16 i;
     207             : 
     208           0 :         for( i = 0; i < aSortList.size(); ++i)
     209             :         {   // current position is starting point
     210             :             SwNodeIndex* pIdx = new SwNodeIndex( rDoc.GetNodes(),
     211           0 :                     aSortList[i].SORT_TXT_TBL.TXT.nSource);
     212           0 :             aIdxList.insert( aIdxList.begin() + i, pIdx );
     213             :         }
     214             : 
     215           0 :         for(i=0; i < aSortList.size(); ++i)
     216             :         {
     217           0 :             SwNodeIndex aIdx( rDoc.GetNodes(), nSttNode + i);
     218           0 :             SwNodeRange aRg( *aIdxList[i], 0, *aIdxList[i], 1 );
     219             :             rDoc.MoveNodeRange(aRg, aIdx,
     220           0 :                 IDocumentContentOperations::DOC_MOVEDEFAULT);
     221           0 :         }
     222             :         // delete indices
     223           0 :         for(SwUndoSortList::const_iterator it = aIdxList.begin(); it != aIdxList.end(); ++it)
     224           0 :             delete *it;
     225           0 :         aIdxList.clear();
     226           0 :         SetPaM(rPam, true);
     227           0 :         SwTxtNode const*const pTNd = rPam.GetNode()->GetTxtNode();
     228           0 :         if( pTNd )
     229             :         {
     230           0 :             rPam.GetPoint()->nContent = pTNd->GetTxt().Len();
     231           0 :         }
     232             :     }
     233           0 : }
     234             : 
     235           0 : void SwUndoSort::RepeatImpl(::sw::RepeatContext & rContext)
     236             : {
     237             :     // table not repeat capable
     238           0 :     if(!pSortOpt->bTable)
     239             :     {
     240           0 :         SwPaM *const pPam = & rContext.GetRepeatPaM();
     241           0 :         SwDoc& rDoc = *pPam->GetDoc();
     242             : 
     243           0 :         if( !rDoc.IsIdxInTbl( pPam->Start()->nNode ) )
     244           0 :             rDoc.SortText(*pPam, *pSortOpt);
     245             :     }
     246           0 : }
     247             : 
     248           0 : void SwUndoSort::Insert( const String& rOrgPos, const String& rNewPos)
     249             : {
     250           0 :     SwSortUndoElement* pEle = new SwSortUndoElement(rOrgPos, rNewPos);
     251           0 :     aSortList.push_back( pEle );
     252           0 : }
     253             : 
     254           0 : void SwUndoSort::Insert( sal_uLong nOrgPos, sal_uLong nNewPos)
     255             : {
     256           0 :     SwSortUndoElement* pEle = new SwSortUndoElement(nOrgPos, nNewPos);
     257           0 :     aSortList.push_back( pEle );
     258           0 : }
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10