merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / undo / unspnd.cxx
blob0e39363c67fe9082c9b8ce84ccda3cee09f36123
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unspnd.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include "doc.hxx"
36 #include "pam.hxx"
37 #include "swtable.hxx"
38 #include "ndtxt.hxx"
39 #include "swundo.hxx" // fuer die UndoIds
40 #include <svx/brkitem.hxx>
41 #include <fmtpdsc.hxx>
42 #include <frmfmt.hxx>
43 #include "undobj.hxx"
44 #include "rolbck.hxx"
45 #include "redline.hxx"
46 #include "docary.hxx"
49 inline SwDoc& SwUndoIter::GetDoc() const { return *pAktPam->GetDoc(); }
52 //------------------------------------------------------------------
54 // SPLITNODE
57 SwUndoSplitNode::SwUndoSplitNode( SwDoc* pDoc, const SwPosition& rPos,
58 BOOL bChkTable )
59 : SwUndo( UNDO_SPLITNODE ), pHistory( 0 ), pRedlData( 0 ), nNode( rPos.nNode.GetIndex() ),
60 nCntnt( rPos.nContent.GetIndex() ),
61 bTblFlag( FALSE ), bChkTblStt( bChkTable )
63 SwTxtNode* pTxtNd = pDoc->GetNodes()[ rPos.nNode ]->GetTxtNode();
64 ASSERT( pTxtNd, "nur beim TextNode rufen!" );
65 if( pTxtNd->GetpSwpHints() )
67 pHistory = new SwHistory;
68 pHistory->CopyAttr( pTxtNd->GetpSwpHints(), nNode, 0,
69 pTxtNd->GetTxt().Len(), false );
70 if( !pHistory->Count() )
71 DELETEZ( pHistory );
73 // Redline beachten
74 if( pDoc->IsRedlineOn() )
76 pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, pDoc->GetRedlineAuthor() );
77 SetRedlineMode( pDoc->GetRedlineMode() );
84 SwUndoSplitNode::~SwUndoSplitNode()
86 delete pHistory;
87 delete pRedlData;
92 void SwUndoSplitNode::Undo( SwUndoIter& rUndoIter )
94 SwDoc* pDoc = &rUndoIter.GetDoc();
95 SwPaM& rPam = *rUndoIter.pAktPam;
96 rPam.DeleteMark();
97 if( bTblFlag )
99 // dann wurde direkt vor der akt. Tabelle ein TextNode eingefuegt.
100 SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
101 rIdx = nNode;
102 SwTxtNode* pTNd;
103 SwNode* pCurrNd = pDoc->GetNodes()[ nNode + 1 ];
104 SwTableNode* pTblNd = pCurrNd->FindTableNode();
105 if( pCurrNd->IsCntntNode() && pTblNd &&
106 0 != ( pTNd = pDoc->GetNodes()[ pTblNd->GetIndex()-1 ]->GetTxtNode() ))
108 // verschiebe die BreakAttribute noch
109 SwFrmFmt* pTableFmt = pTblNd->GetTable().GetFrmFmt();
110 const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
111 if( pNdSet )
113 const SfxPoolItem *pItem;
114 if( SFX_ITEM_SET == pNdSet->GetItemState( RES_PAGEDESC, FALSE,
115 &pItem ) )
116 pTableFmt->SetFmtAttr( *pItem );
118 if( SFX_ITEM_SET == pNdSet->GetItemState( RES_BREAK, FALSE,
119 &pItem ) )
120 pTableFmt->SetFmtAttr( *pItem );
123 // dann loesche den wieder
124 SwNodeIndex aDelNd( *pTblNd, -1 );
125 rPam.GetPoint()->nContent.Assign( (SwCntntNode*)pCurrNd, 0 );
126 RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
127 pDoc->GetNodes().Delete( aDelNd );
130 else
132 SwTxtNode * pTNd = pDoc->GetNodes()[ nNode ]->GetTxtNode();
133 if( pTNd )
135 rPam.GetPoint()->nNode = *pTNd;
136 rPam.GetPoint()->nContent.Assign( pTNd, pTNd->GetTxt().Len() );
138 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
140 rPam.SetMark();
141 rPam.GetMark()->nNode++;
142 rPam.GetMark()->nContent.Assign( rPam.GetMark()->
143 nNode.GetNode().GetCntntNode(), 0 );
144 pDoc->DeleteRedline( rPam, true, USHRT_MAX );
145 rPam.DeleteMark();
148 RemoveIdxRel( nNode+1, *rPam.GetPoint() );
150 pTNd->JoinNext();
151 if( pHistory )
153 rPam.GetPoint()->nContent = 0;
154 rPam.SetMark();
155 rPam.GetPoint()->nContent = pTNd->GetTxt().Len();
157 pDoc->RstTxtAttrs( rPam, TRUE );
158 pHistory->TmpRollback( pDoc, 0, false );
163 // setze noch den Cursor auf den Undo-Bereich
164 rPam.DeleteMark();
165 rPam.GetPoint()->nNode = nNode;
166 rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), nCntnt );
170 void SwUndoSplitNode::Repeat( SwUndoIter& rUndoIter )
172 if( UNDO_SPLITNODE == rUndoIter.GetLastUndoId() )
173 return;
174 rUndoIter.GetDoc().SplitNode( *rUndoIter.pAktPam->GetPoint(), bChkTblStt );
175 rUndoIter.pLastUndoObj = this;
179 void SwUndoSplitNode::Redo( SwUndoIter& rUndoIter )
181 SwPaM& rPam = *rUndoIter.pAktPam;
182 ULONG nOldNode = rPam.GetPoint()->nNode.GetIndex();
183 rPam.GetPoint()->nNode = nNode;
184 SwTxtNode * pTNd = rPam.GetNode()->GetTxtNode();
185 if( pTNd ) // sollte eigentlich immer ein TextNode sein !!
187 rPam.GetPoint()->nContent.Assign( pTNd, nCntnt );
189 SwDoc* pDoc = rPam.GetDoc();
190 pDoc->SplitNode( *rPam.GetPoint(), bChkTblStt );
192 if( pHistory )
193 pHistory->SetTmpEnd( pHistory->Count() );
195 if( ( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
196 ( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
197 pDoc->GetRedlineTbl().Count() ))
199 rPam.SetMark();
200 if( rPam.Move( fnMoveBackward ))
202 if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
204 RedlineMode_t eOld = pDoc->GetRedlineMode();
205 pDoc->SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
206 pDoc->AppendRedline( new SwRedline( *pRedlData, rPam ), true);
207 pDoc->SetRedlineMode_intern( eOld );
209 else
210 pDoc->SplitRedline( rPam );
211 rPam.Exchange();
213 rPam.DeleteMark();
216 else
217 rPam.GetPoint()->nNode = nOldNode;