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 <UndoNumbering.hxx>
30 : : #include <hintids.hxx>
31 : : #include <editeng/lrspitem.hxx>
32 : : #include <doc.hxx>
33 : : #include <IDocumentUndoRedo.hxx>
34 : : #include <swundo.hxx>
35 : : #include <pam.hxx>
36 : : #include <ndtxt.hxx>
37 : : #include <UndoCore.hxx>
38 : : #include <rolbck.hxx>
39 : :
40 : 0 : SwUndoInsNum::SwUndoInsNum( const SwNumRule& rOldRule,
41 : : const SwNumRule& rNewRule,
42 : : SwUndoId nUndoId )
43 : : : SwUndo( nUndoId ),
44 : : aNumRule( rNewRule ), pHistory( 0 ), nSttSet( ULONG_MAX ),
45 [ # # ][ # # ]: 0 : pOldNumRule( new SwNumRule( rOldRule )), nLRSavePos( 0 )
[ # # ][ # # ]
[ # # ]
46 : : {
47 : 0 : }
48 : :
49 : 0 : SwUndoInsNum::SwUndoInsNum( const SwPaM& rPam, const SwNumRule& rRule )
50 : : : SwUndo( UNDO_INSNUM ), SwUndRng( rPam ),
51 : : aNumRule( rRule ), pHistory( 0 ),
52 [ # # ][ # # ]: 0 : nSttSet( ULONG_MAX ), pOldNumRule( 0 ), nLRSavePos( 0 )
[ # # ]
53 : : {
54 : 0 : }
55 : :
56 : 0 : SwUndoInsNum::SwUndoInsNum( const SwPosition& rPos, const SwNumRule& rRule,
57 : : const String& rReplaceRule )
58 : : : SwUndo( UNDO_INSNUM ),
59 : : aNumRule( rRule ), pHistory( 0 ),
60 : : nSttSet( ULONG_MAX ), pOldNumRule( 0 ),
61 [ # # ][ # # ]: 0 : sReplaceRule( rReplaceRule ), nLRSavePos( 0 )
[ # # ]
62 : : {
63 : : // No selection!
64 : 0 : nEndNode = 0, nEndCntnt = USHRT_MAX;
65 : 0 : nSttNode = rPos.nNode.GetIndex();
66 : 0 : nSttCntnt = rPos.nContent.GetIndex();
67 : 0 : }
68 : :
69 [ # # ][ # # ]: 0 : SwUndoInsNum::~SwUndoInsNum()
70 : : {
71 [ # # ][ # # ]: 0 : delete pHistory;
72 [ # # ][ # # ]: 0 : delete pOldNumRule;
73 [ # # ]: 0 : }
74 : :
75 : 0 : SwRewriter SwUndoInsNum::GetRewriter() const
76 : : {
77 : 0 : SwRewriter aResult;
78 [ # # ][ # # ]: 0 : if( UNDO_INSFMTATTR == GetId() )
79 [ # # ]: 0 : aResult.AddRule(UndoArg1, aNumRule.GetName());
80 : 0 : return aResult;
81 : : }
82 : :
83 : 0 : void SwUndoInsNum::UndoImpl(::sw::UndoRedoContext & rContext)
84 : : {
85 : 0 : SwDoc & rDoc = rContext.GetDoc();
86 : :
87 [ # # ]: 0 : if( pOldNumRule )
88 : 0 : rDoc.ChgNumRuleFmts( *pOldNumRule );
89 : :
90 [ # # ]: 0 : if( pHistory )
91 : : {
92 : : SwTxtNode* pNd;
93 [ # # # # ]: 0 : if( ULONG_MAX != nSttSet &&
[ # # ]
94 : 0 : 0 != ( pNd = rDoc.GetNodes()[ nSttSet ]->GetTxtNode() ))
95 : 0 : pNd->SetListRestart( sal_True );
96 : : else
97 : 0 : pNd = 0;
98 : :
99 : :
100 [ # # ]: 0 : if( nLRSavePos )
101 : : {
102 : : // Update immediately so that potential "old" LRSpaces will be valid again.
103 : : // For that search firstly the correct NumRule names!
104 [ # # ][ # # ]: 0 : if( !pNd && nSttNode )
105 : 0 : pNd = rDoc.GetNodes()[ nSttNode ]->GetTxtNode();
106 : :
107 : 0 : pHistory->TmpRollback( &rDoc, nLRSavePos );
108 : :
109 : : }
110 : 0 : pHistory->TmpRollback( &rDoc, 0 );
111 : 0 : pHistory->SetTmpEnd( pHistory->Count() );
112 : : }
113 : :
114 [ # # ]: 0 : if (nSttNode)
115 : : {
116 : 0 : AddUndoRedoPaM(rContext);
117 : : }
118 : 0 : }
119 : :
120 : 0 : void SwUndoInsNum::RedoImpl(::sw::UndoRedoContext & rContext)
121 : : {
122 : 0 : SwDoc & rDoc = rContext.GetDoc();
123 : :
124 [ # # ]: 0 : if( pOldNumRule )
125 : 0 : rDoc.ChgNumRuleFmts( aNumRule );
126 [ # # ]: 0 : else if( pHistory )
127 : : {
128 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
129 [ # # ]: 0 : if( sReplaceRule.Len() )
130 : : {
131 : 0 : rDoc.ReplaceNumRule(*rPam.GetPoint(),
132 : 0 : sReplaceRule, aNumRule.GetName() );
133 : : }
134 : : else
135 : : {
136 : : // #i42921# - adapt to changed signature
137 [ # # ]: 0 : rDoc.SetNumRule(rPam, aNumRule, false);
138 : : }
139 : : }
140 : 0 : }
141 : :
142 : 0 : void SwUndoInsNum::SetLRSpaceEndPos()
143 : : {
144 [ # # ]: 0 : if( pHistory )
145 : 0 : nLRSavePos = pHistory->Count();
146 : 0 : }
147 : :
148 : 0 : void SwUndoInsNum::RepeatImpl(::sw::RepeatContext & rContext)
149 : : {
150 : 0 : SwDoc & rDoc(rContext.GetDoc());
151 [ # # ]: 0 : if( nSttNode )
152 : : {
153 [ # # ]: 0 : if( !sReplaceRule.Len() )
154 : : {
155 : : // #i42921# - adapt to changed signature
156 [ # # ]: 0 : rDoc.SetNumRule(rContext.GetRepeatPaM(), aNumRule, false);
157 : : }
158 : : }
159 : : else
160 : : {
161 : 0 : rDoc.ChgNumRuleFmts( aNumRule );
162 : : }
163 : 0 : }
164 : :
165 : 0 : SwHistory* SwUndoInsNum::GetHistory()
166 : : {
167 [ # # ]: 0 : if( !pHistory )
168 [ # # ]: 0 : pHistory = new SwHistory;
169 : 0 : return pHistory;
170 : : }
171 : :
172 : 0 : void SwUndoInsNum::SaveOldNumRule( const SwNumRule& rOld )
173 : : {
174 [ # # ]: 0 : if( !pOldNumRule )
175 [ # # ]: 0 : pOldNumRule = new SwNumRule( rOld );
176 : 0 : }
177 : :
178 : 0 : SwUndoDelNum::SwUndoDelNum( const SwPaM& rPam )
179 [ # # ][ # # ]: 0 : : SwUndo( UNDO_DELNUM ), SwUndRng( rPam )
180 : : {
181 [ # # ]: 0 : aNodes.reserve( nEndNode - nSttNode > 255 ? 255 : nEndNode - nSttNode );
182 [ # # ][ # # ]: 0 : pHistory = new SwHistory;
183 : 0 : }
184 : :
185 : 0 : SwUndoDelNum::~SwUndoDelNum()
186 : : {
187 [ # # ][ # # ]: 0 : delete pHistory;
188 [ # # ]: 0 : }
189 : :
190 : 0 : void SwUndoDelNum::UndoImpl(::sw::UndoRedoContext & rContext)
191 : : {
192 : 0 : SwDoc & rDoc = rContext.GetDoc();
193 : :
194 : 0 : pHistory->TmpRollback( &rDoc, 0 );
195 : 0 : pHistory->SetTmpEnd( pHistory->Count() );
196 : :
197 [ # # ][ # # ]: 0 : for( std::vector<NodeLevel>::const_iterator i = aNodes.begin(); i != aNodes.end(); ++i )
[ # # ]
198 : : {
199 [ # # ][ # # ]: 0 : SwTxtNode* pNd = rDoc.GetNodes()[ i->index ]->GetTxtNode();
200 : : OSL_ENSURE( pNd, "Where has the TextNode gone?" );
201 [ # # ]: 0 : pNd->SetAttrListLevel( i->level );
202 : :
203 [ # # ]: 0 : if( pNd->GetCondFmtColl() )
204 [ # # ]: 0 : pNd->ChkCondColl();
205 : : }
206 : :
207 : 0 : AddUndoRedoPaM(rContext);
208 : 0 : }
209 : :
210 : 0 : void SwUndoDelNum::RedoImpl(::sw::UndoRedoContext & rContext)
211 : : {
212 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
213 : 0 : rContext.GetDoc().DelNumRules(rPam);
214 : 0 : }
215 : :
216 : 0 : void SwUndoDelNum::RepeatImpl(::sw::RepeatContext & rContext)
217 : : {
218 : 0 : rContext.GetDoc().DelNumRules(rContext.GetRepeatPaM());
219 : 0 : }
220 : :
221 : 0 : void SwUndoDelNum::AddNode( const SwTxtNode& rNd, sal_Bool )
222 : : {
223 [ # # ]: 0 : if( rNd.GetNumRule() )
224 : : {
225 [ # # ]: 0 : aNodes.push_back( NodeLevel( rNd.GetIndex(), rNd.GetActualListLevel() ) );
226 : : }
227 : 0 : }
228 : :
229 : 0 : SwUndoMoveNum::SwUndoMoveNum( const SwPaM& rPam, long nOff, sal_Bool bIsOutlMv )
230 : : : SwUndo( bIsOutlMv ? UNDO_OUTLINE_UD : UNDO_MOVENUM ),
231 : : SwUndRng( rPam ),
232 [ # # ][ # # ]: 0 : nNewStt( 0 ), nOffset( nOff )
233 : : {
234 : : // nOffset: Down => 1
235 : : // Up => -1
236 : 0 : }
237 : :
238 : 0 : void SwUndoMoveNum::UndoImpl(::sw::UndoRedoContext & rContext)
239 : : {
240 : 0 : sal_uLong nTmpStt = nSttNode, nTmpEnd = nEndNode;
241 : :
242 [ # # ][ # # ]: 0 : if( nEndNode || USHRT_MAX != nEndCntnt ) // section?
243 : : {
244 [ # # ]: 0 : if( nNewStt < nSttNode ) // moved forwards
245 : 0 : nEndNode = nEndNode - ( nSttNode - nNewStt );
246 : : else
247 : 0 : nEndNode = nEndNode + ( nNewStt - nSttNode );
248 : : }
249 : 0 : nSttNode = nNewStt;
250 : :
251 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
252 : 0 : rContext.GetDoc().MoveParagraph( rPam, -nOffset,
253 : 0 : UNDO_OUTLINE_UD == GetId() );
254 : 0 : nSttNode = nTmpStt;
255 : 0 : nEndNode = nTmpEnd;
256 : 0 : }
257 : :
258 : 0 : void SwUndoMoveNum::RedoImpl(::sw::UndoRedoContext & rContext)
259 : : {
260 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
261 : 0 : rContext.GetDoc().MoveParagraph(rPam, nOffset, UNDO_OUTLINE_UD == GetId());
262 : 0 : }
263 : :
264 : 0 : void SwUndoMoveNum::RepeatImpl(::sw::RepeatContext & rContext)
265 : : {
266 : 0 : SwDoc & rDoc = rContext.GetDoc();
267 [ # # ]: 0 : if( UNDO_OUTLINE_UD == GetId() )
268 : : {
269 : 0 : rDoc.MoveOutlinePara(rContext.GetRepeatPaM(),
270 [ # # ]: 0 : 0 < nOffset ? 1 : -1 );
271 : : }
272 : : else
273 : : {
274 : 0 : rDoc.MoveParagraph(rContext.GetRepeatPaM(), nOffset, sal_False);
275 : : }
276 : 0 : }
277 : :
278 : 0 : SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM& rPam, short nOff )
279 : : : SwUndo( nOff > 0 ? UNDO_NUMUP : UNDO_NUMDOWN ), SwUndRng( rPam ),
280 [ # # ][ # # ]: 0 : nOffset( nOff )
281 : : {
282 : : // nOffset: Down => 1
283 : : // Up => -1
284 : 0 : }
285 : :
286 : 0 : void SwUndoNumUpDown::UndoImpl(::sw::UndoRedoContext & rContext)
287 : : {
288 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
289 : 0 : rContext.GetDoc().NumUpDown(rPam, 1 != nOffset );
290 : 0 : }
291 : :
292 : 0 : void SwUndoNumUpDown::RedoImpl(::sw::UndoRedoContext & rContext)
293 : : {
294 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
295 : 0 : rContext.GetDoc().NumUpDown(rPam, 1 == nOffset);
296 : 0 : }
297 : :
298 : 0 : void SwUndoNumUpDown::RepeatImpl(::sw::RepeatContext & rContext)
299 : : {
300 : 0 : rContext.GetDoc().NumUpDown(rContext.GetRepeatPaM(), 1 == nOffset);
301 : 0 : }
302 : :
303 : : // #115901#
304 : 0 : SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex& rIdx, sal_Bool bOldNum,
305 : : sal_Bool bNewNum)
306 : 0 : : SwUndo( UNDO_NUMORNONUM ), nIdx( rIdx.GetIndex() ), mbNewNum(bNewNum),
307 : 0 : mbOldNum(bOldNum)
308 : : {
309 : 0 : }
310 : :
311 : : // #115901#, #i40034#
312 : 0 : void SwUndoNumOrNoNum::UndoImpl(::sw::UndoRedoContext & rContext)
313 : : {
314 [ # # ][ # # ]: 0 : SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
315 : 0 : SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
316 : :
317 [ # # ]: 0 : if (NULL != pTxtNd)
318 : : {
319 [ # # ]: 0 : pTxtNd->SetCountedInList(mbOldNum);
320 [ # # ]: 0 : }
321 : 0 : }
322 : :
323 : : // #115901#, #i40034#
324 : 0 : void SwUndoNumOrNoNum::RedoImpl(::sw::UndoRedoContext & rContext)
325 : : {
326 [ # # ][ # # ]: 0 : SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
327 : 0 : SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
328 : :
329 [ # # ]: 0 : if (NULL != pTxtNd)
330 : : {
331 [ # # ]: 0 : pTxtNd->SetCountedInList(mbNewNum);
332 [ # # ]: 0 : }
333 : 0 : }
334 : :
335 : : // #115901#
336 : 0 : void SwUndoNumOrNoNum::RepeatImpl(::sw::RepeatContext & rContext)
337 : : {
338 : 0 : SwDoc & rDoc = rContext.GetDoc();
339 [ # # ][ # # ]: 0 : if (mbOldNum && ! mbNewNum)
340 : : {
341 : 0 : rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, sal_False);
342 : : }
343 [ # # ][ # # ]: 0 : else if ( ! mbOldNum && mbNewNum )
344 : : {
345 : 0 : rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, sal_True);
346 : : }
347 : 0 : }
348 : :
349 : 0 : SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_Bool bFlg )
350 : : : SwUndo( UNDO_SETNUMRULESTART ),
351 : 0 : nIdx( rPos.nNode.GetIndex() ), nOldStt( USHRT_MAX ),
352 : 0 : nNewStt( USHRT_MAX ), bSetSttValue( sal_False ), bFlag( bFlg )
353 : : {
354 : 0 : }
355 : :
356 : 2 : SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_uInt16 nStt )
357 : : : SwUndo( UNDO_SETNUMRULESTART ),
358 : 2 : nIdx( rPos.nNode.GetIndex() ),
359 : 2 : nOldStt( USHRT_MAX ), nNewStt( nStt ), bSetSttValue( sal_True )
360 : : {
361 : 2 : SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
362 [ + - ]: 2 : if ( pTxtNd )
363 : : {
364 [ + - ][ - + ]: 2 : if ( pTxtNd->HasAttrListRestartValue() )
365 : : {
366 [ # # ]: 0 : nOldStt = static_cast<sal_uInt16>(pTxtNd->GetAttrListRestartValue());
367 : : }
368 : : else
369 : : {
370 : 2 : nOldStt = USHRT_MAX; // indicating, that the list restart value is not set
371 : : }
372 : : }
373 : 2 : }
374 : :
375 : 0 : void SwUndoNumRuleStart::UndoImpl(::sw::UndoRedoContext & rContext)
376 : : {
377 : 0 : SwDoc & rDoc = rContext.GetDoc();
378 [ # # ][ # # ]: 0 : SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
[ # # ]
379 [ # # ]: 0 : if( bSetSttValue )
380 : : {
381 [ # # ]: 0 : rDoc.SetNodeNumStart( aPos, nOldStt );
382 : : }
383 : : else
384 : : {
385 [ # # ]: 0 : rDoc.SetNumRuleStart( aPos, !bFlag );
386 [ # # ]: 0 : }
387 : 0 : }
388 : :
389 : 0 : void SwUndoNumRuleStart::RedoImpl(::sw::UndoRedoContext & rContext)
390 : : {
391 : 0 : SwDoc & rDoc = rContext.GetDoc();
392 [ # # ][ # # ]: 0 : SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
[ # # ]
393 [ # # ]: 0 : if( bSetSttValue )
394 : : {
395 [ # # ]: 0 : rDoc.SetNodeNumStart( aPos, nNewStt );
396 : : }
397 : : else
398 : : {
399 [ # # ]: 0 : rDoc.SetNumRuleStart( aPos, bFlag );
400 [ # # ]: 0 : }
401 : 0 : }
402 : :
403 : 0 : void SwUndoNumRuleStart::RepeatImpl(::sw::RepeatContext & rContext)
404 : : {
405 : 0 : SwDoc & rDoc = rContext.GetDoc();
406 [ # # ]: 0 : if( bSetSttValue )
407 : : {
408 : 0 : rDoc.SetNodeNumStart(*rContext.GetRepeatPaM().GetPoint(), nNewStt);
409 : : }
410 : : else
411 : : {
412 : 0 : rDoc.SetNumRuleStart(*rContext.GetRepeatPaM().GetPoint(), bFlag);
413 : : }
414 : 0 : }
415 : :
416 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|