LCOV - code coverage report
Current view: top level - sw/source/core/undo - unsort.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 113 27.4 %
Date: 2012-08-25 Functions: 7 10 70.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 242 9.9 %

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

Generated by: LCOV version 1.10