1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unspnd.cxx,v $
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"
37 #include "swtable.hxx"
39 #include "swundo.hxx" // fuer die UndoIds
40 #include <svx/brkitem.hxx>
41 #include <fmtpdsc.hxx>
45 #include "redline.hxx"
49 inline SwDoc
& SwUndoIter::GetDoc() const { return *pAktPam
->GetDoc(); }
52 //------------------------------------------------------------------
57 SwUndoSplitNode::SwUndoSplitNode( SwDoc
* pDoc
, const SwPosition
& rPos
,
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() )
74 if( pDoc
->IsRedlineOn() )
76 pRedlData
= new SwRedlineData( nsRedlineType_t::REDLINE_INSERT
, pDoc
->GetRedlineAuthor() );
77 SetRedlineMode( pDoc
->GetRedlineMode() );
84 SwUndoSplitNode::~SwUndoSplitNode()
92 void SwUndoSplitNode::Undo( SwUndoIter
& rUndoIter
)
94 SwDoc
* pDoc
= &rUndoIter
.GetDoc();
95 SwPaM
& rPam
= *rUndoIter
.pAktPam
;
99 // dann wurde direkt vor der akt. Tabelle ein TextNode eingefuegt.
100 SwNodeIndex
& rIdx
= rPam
.GetPoint()->nNode
;
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();
113 const SfxPoolItem
*pItem
;
114 if( SFX_ITEM_SET
== pNdSet
->GetItemState( RES_PAGEDESC
, FALSE
,
116 pTableFmt
->SetFmtAttr( *pItem
);
118 if( SFX_ITEM_SET
== pNdSet
->GetItemState( RES_BREAK
, FALSE
,
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
);
132 SwTxtNode
* pTNd
= pDoc
->GetNodes()[ nNode
]->GetTxtNode();
135 rPam
.GetPoint()->nNode
= *pTNd
;
136 rPam
.GetPoint()->nContent
.Assign( pTNd
, pTNd
->GetTxt().Len() );
138 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
141 rPam
.GetMark()->nNode
++;
142 rPam
.GetMark()->nContent
.Assign( rPam
.GetMark()->
143 nNode
.GetNode().GetCntntNode(), 0 );
144 pDoc
->DeleteRedline( rPam
, true, USHRT_MAX
);
148 RemoveIdxRel( nNode
+1, *rPam
.GetPoint() );
153 rPam
.GetPoint()->nContent
= 0;
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
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() )
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
);
193 pHistory
->SetTmpEnd( pHistory
->Count() );
195 if( ( pRedlData
&& IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
196 ( !( nsRedlineMode_t::REDLINE_IGNORE
& GetRedlineMode() ) &&
197 pDoc
->GetRedlineTbl().Count() ))
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
);
210 pDoc
->SplitRedline( rPam
);
217 rPam
.GetPoint()->nNode
= nOldNode
;