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 <UndoAttribute.hxx>
21 : #include <svl/itemiter.hxx>
22 : #include <editeng/tstpitem.hxx>
23 : #include <svx/svdmodel.hxx>
24 : #include <svx/svdpage.hxx>
25 : #include <hintids.hxx>
26 : #include <fmtflcnt.hxx>
27 : #include <txtftn.hxx>
28 : #include <fmtornt.hxx>
29 : #include <fmtanchr.hxx>
30 : #include <fmtfsize.hxx>
31 : #include <frmfmt.hxx>
32 : #include <fmtcntnt.hxx>
33 : #include <ftnidx.hxx>
34 : #include <doc.hxx>
35 : #include <IDocumentUndoRedo.hxx>
36 : #include <IShellCursorSupplier.hxx>
37 : #include <docary.hxx>
38 : #include <swundo.hxx>
39 : #include <pam.hxx>
40 : #include <ndtxt.hxx>
41 : #include <swtable.hxx>
42 : #include <swtblfmt.hxx>
43 : #include <UndoCore.hxx>
44 : #include <hints.hxx>
45 : #include <rolbck.hxx>
46 : #include <ndnotxt.hxx>
47 : #include <dcontact.hxx>
48 : #include <ftninfo.hxx>
49 : #include <redline.hxx>
50 : #include <section.hxx>
51 : #include <charfmt.hxx>
52 : #include <switerator.hxx>
53 :
54 0 : SwUndoFmtAttrHelper::SwUndoFmtAttrHelper( SwFmt& rFmt, bool bSvDrwPt )
55 : : SwClient( &rFmt )
56 : , m_pUndo( 0 )
57 0 : , m_bSaveDrawPt( bSvDrwPt )
58 : {
59 0 : }
60 :
61 0 : void SwUndoFmtAttrHelper::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
62 : {
63 0 : if( pOld )
64 : {
65 0 : if ( pOld->Which() == RES_OBJECTDYING )
66 : {
67 0 : CheckRegistration( pOld, pNew );
68 : }
69 0 : else if ( pNew )
70 : {
71 0 : if( POOLATTR_END >= pOld->Which() )
72 : {
73 0 : if ( GetUndo() )
74 : {
75 0 : m_pUndo->PutAttr( *pOld );
76 : }
77 : else
78 : {
79 : m_pUndo.reset( new SwUndoFmtAttr( *pOld,
80 0 : *static_cast<SwFmt*>(GetRegisteredInNonConst()), m_bSaveDrawPt ) );
81 : }
82 : }
83 0 : else if ( RES_ATTRSET_CHG == pOld->Which() )
84 : {
85 0 : if ( GetUndo() )
86 : {
87 : SfxItemIter aIter(
88 0 : *(static_cast<const SwAttrSetChg*>(pOld))->GetChgSet() );
89 0 : const SfxPoolItem* pItem = aIter.GetCurItem();
90 0 : while ( pItem )
91 : {
92 0 : m_pUndo->PutAttr( *pItem );
93 0 : if( aIter.IsAtEnd() )
94 0 : break;
95 0 : pItem = aIter.NextItem();
96 0 : }
97 : }
98 : else
99 : {
100 : m_pUndo.reset( new SwUndoFmtAttr(
101 0 : *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet(),
102 0 : *static_cast<SwFmt*>(GetRegisteredInNonConst()), m_bSaveDrawPt ) );
103 : }
104 : }
105 : }
106 : }
107 0 : }
108 :
109 0 : SwUndoFmtAttr::SwUndoFmtAttr( const SfxItemSet& rOldSet,
110 : SwFmt& rChgFmt,
111 : bool bSaveDrawPt )
112 : : SwUndo( UNDO_INSFMTATTR )
113 : , m_pFmt( &rChgFmt )
114 : // #i56253#
115 0 : , m_pOldSet( new SfxItemSet( rOldSet ) )
116 : , m_nNodeIndex( 0 )
117 0 : , m_nFmtWhich( rChgFmt.Which() )
118 0 : , m_bSaveDrawPt( bSaveDrawPt )
119 : {
120 0 : Init();
121 0 : }
122 :
123 0 : SwUndoFmtAttr::SwUndoFmtAttr( const SfxPoolItem& rItem, SwFmt& rChgFmt,
124 : bool bSaveDrawPt )
125 : : SwUndo( UNDO_INSFMTATTR )
126 : , m_pFmt( &rChgFmt )
127 0 : , m_pOldSet( m_pFmt->GetAttrSet().Clone( sal_False ) )
128 : , m_nNodeIndex( 0 )
129 0 : , m_nFmtWhich( rChgFmt.Which() )
130 0 : , m_bSaveDrawPt( bSaveDrawPt )
131 : {
132 0 : m_pOldSet->Put( rItem );
133 0 : Init();
134 0 : }
135 :
136 0 : void SwUndoFmtAttr::Init()
137 : {
138 : // treat change of anchor specially
139 0 : if ( SFX_ITEM_SET == m_pOldSet->GetItemState( RES_ANCHOR, sal_False ))
140 : {
141 0 : SaveFlyAnchor( m_bSaveDrawPt );
142 : }
143 0 : else if ( RES_FRMFMT == m_nFmtWhich )
144 : {
145 0 : SwDoc* pDoc = m_pFmt->GetDoc();
146 0 : if ( pDoc->GetTblFrmFmts()->Contains(static_cast<const SwFrmFmt*>(m_pFmt)))
147 : {
148 : // Table Format: save table position, table formats are volatile!
149 0 : SwTable * pTbl = SwIterator<SwTable,SwFmt>::FirstElement( *m_pFmt );
150 0 : if ( pTbl )
151 : {
152 0 : m_nNodeIndex = pTbl->GetTabSortBoxes()[ 0 ]->GetSttNd()
153 0 : ->FindTableNode()->GetIndex();
154 : }
155 : }
156 0 : else if ( pDoc->GetSections().Contains(static_cast<const SwSectionFmt*>(m_pFmt)))
157 : {
158 0 : m_nNodeIndex = m_pFmt->GetCntnt().GetCntntIdx()->GetIndex();
159 : }
160 0 : else if ( 0 != dynamic_cast< SwTableBoxFmt* >( m_pFmt ) )
161 : {
162 0 : SwTableBox * pTblBox = SwIterator<SwTableBox,SwFmt>::FirstElement( *m_pFmt );
163 0 : if ( pTblBox )
164 : {
165 0 : m_nNodeIndex = pTblBox->GetSttIdx();
166 : }
167 : }
168 : }
169 0 : }
170 :
171 0 : SwUndoFmtAttr::~SwUndoFmtAttr()
172 : {
173 0 : }
174 :
175 0 : void SwUndoFmtAttr::UndoImpl(::sw::UndoRedoContext & rContext)
176 : {
177 : // OD 2004-10-26 #i35443#
178 : // Important note: <Undo(..)> also called by <ReDo(..)>
179 :
180 0 : if ( !m_pOldSet.get() || !m_pFmt || !IsFmtInDoc( &rContext.GetDoc() ))
181 0 : return;
182 :
183 : // #i35443# - If anchor attribute has been successfull
184 : // restored, all other attributes are also restored.
185 : // Thus, keep track of its restoration
186 0 : bool bAnchorAttrRestored( false );
187 0 : if ( SFX_ITEM_SET == m_pOldSet->GetItemState( RES_ANCHOR, sal_False ))
188 : {
189 0 : bAnchorAttrRestored = RestoreFlyAnchor(rContext);
190 0 : if ( bAnchorAttrRestored )
191 : {
192 : // Anchor attribute successfull restored.
193 : // Thus, keep anchor position for redo
194 0 : SaveFlyAnchor();
195 : }
196 : else
197 : {
198 : // Anchor attribute not restored due to invalid anchor position.
199 : // Thus, delete anchor attribute.
200 0 : m_pOldSet->ClearItem( RES_ANCHOR );
201 : }
202 : }
203 :
204 0 : if ( !bAnchorAttrRestored )
205 : {
206 0 : SwUndoFmtAttrHelper aTmp( *m_pFmt, m_bSaveDrawPt );
207 0 : m_pFmt->SetFmtAttr( *m_pOldSet );
208 0 : if ( aTmp.GetUndo() )
209 : {
210 : // transfer ownership of helper object's old set
211 0 : m_pOldSet = aTmp.GetUndo()->m_pOldSet;
212 : }
213 : else
214 : {
215 0 : m_pOldSet->ClearItem();
216 : }
217 :
218 0 : if ( RES_FLYFRMFMT == m_nFmtWhich || RES_DRAWFRMFMT == m_nFmtWhich )
219 : {
220 0 : rContext.SetSelections(static_cast<SwFrmFmt*>(m_pFmt), 0);
221 0 : }
222 : }
223 : }
224 :
225 0 : bool SwUndoFmtAttr::IsFmtInDoc( SwDoc* pDoc )
226 : {
227 : // search for the Format in the Document; if it does not exist any more,
228 : // the attribute is not restored!
229 0 : sal_uInt16 nPos = USHRT_MAX;
230 0 : switch ( m_nFmtWhich )
231 : {
232 : case RES_TXTFMTCOLL:
233 : nPos = pDoc->GetTxtFmtColls()->GetPos(
234 0 : static_cast<const SwTxtFmtColl*>(m_pFmt) );
235 0 : break;
236 :
237 : case RES_GRFFMTCOLL:
238 : nPos = pDoc->GetGrfFmtColls()->GetPos(
239 0 : static_cast<const SwGrfFmtColl*>(m_pFmt) );
240 0 : break;
241 :
242 : case RES_CHRFMT:
243 : nPos = pDoc->GetCharFmts()->GetPos(
244 0 : static_cast<SwCharFmt*>(m_pFmt) );
245 0 : break;
246 :
247 : case RES_FRMFMT:
248 0 : if ( m_nNodeIndex && (m_nNodeIndex < pDoc->GetNodes().Count()) )
249 : {
250 0 : SwNode* pNd = pDoc->GetNodes()[ m_nNodeIndex ];
251 0 : if ( pNd->IsTableNode() )
252 : {
253 : m_pFmt =
254 0 : static_cast<SwTableNode*>(pNd)->GetTable().GetFrmFmt();
255 0 : nPos = 0;
256 0 : break;
257 : }
258 0 : else if ( pNd->IsSectionNode() )
259 : {
260 : m_pFmt =
261 0 : static_cast<SwSectionNode*>(pNd)->GetSection().GetFmt();
262 0 : nPos = 0;
263 0 : break;
264 : }
265 0 : else if ( pNd->IsStartNode() && (SwTableBoxStartNode ==
266 0 : static_cast< SwStartNode* >(pNd)->GetStartNodeType()) )
267 : {
268 0 : SwTableNode* pTblNode = pNd->FindTableNode();
269 0 : if ( pTblNode )
270 : {
271 : SwTableBox* pBox =
272 0 : pTblNode->GetTable().GetTblBox( m_nNodeIndex );
273 0 : if ( pBox )
274 : {
275 0 : m_pFmt = pBox->GetFrmFmt();
276 0 : nPos = 0;
277 0 : break;
278 : }
279 : }
280 : }
281 : }
282 : // no break!
283 : case RES_DRAWFRMFMT:
284 : case RES_FLYFRMFMT:
285 : nPos = pDoc->GetSpzFrmFmts()->GetPos(
286 0 : static_cast<const SwFrmFmt*>(m_pFmt) );
287 0 : if ( USHRT_MAX == nPos )
288 : {
289 : nPos = pDoc->GetFrmFmts()->GetPos(
290 0 : static_cast<const SwFrmFmt*>(m_pFmt) );
291 : }
292 0 : break;
293 : }
294 :
295 0 : if ( USHRT_MAX == nPos )
296 : {
297 : // Format does not exist; reset
298 0 : m_pFmt = 0;
299 : }
300 :
301 0 : return 0 != m_pFmt;
302 : }
303 :
304 : // Check if it is still in Doc
305 0 : SwFmt* SwUndoFmtAttr::GetFmt( SwDoc& rDoc )
306 : {
307 0 : return m_pFmt && IsFmtInDoc( &rDoc ) ? m_pFmt : 0;
308 : }
309 :
310 0 : void SwUndoFmtAttr::RedoImpl(::sw::UndoRedoContext & rContext)
311 : {
312 : // #i35443# - Because the undo stores the attributes for
313 : // redo, the same code as for <Undo(..)> can be applied for <Redo(..)>
314 0 : UndoImpl(rContext);
315 0 : }
316 :
317 0 : void SwUndoFmtAttr::RepeatImpl(::sw::RepeatContext & rContext)
318 : {
319 0 : if ( !m_pOldSet.get() )
320 0 : return;
321 :
322 0 : SwDoc & rDoc(rContext.GetDoc());
323 :
324 0 : switch ( m_nFmtWhich )
325 : {
326 : case RES_GRFFMTCOLL:
327 : {
328 : SwNoTxtNode *const pNd =
329 0 : rContext.GetRepeatPaM().GetNode()->GetNoTxtNode();
330 0 : if( pNd )
331 : {
332 0 : rDoc.SetAttr( m_pFmt->GetAttrSet(), *pNd->GetFmtColl() );
333 : }
334 : }
335 0 : break;
336 :
337 : case RES_TXTFMTCOLL:
338 : {
339 : SwTxtNode *const pNd =
340 0 : rContext.GetRepeatPaM().GetNode()->GetTxtNode();
341 0 : if( pNd )
342 : {
343 0 : rDoc.SetAttr( m_pFmt->GetAttrSet(), *pNd->GetFmtColl() );
344 : }
345 : }
346 0 : break;
347 :
348 : case RES_FLYFRMFMT:
349 : {
350 : // Check if the cursor is in a flying frame
351 : // Steps: search in all FlyFrmFormats for the FlyCntnt attribute
352 : // and validate if the cursor is in the respective section
353 : SwFrmFmt *const pFly =
354 0 : rContext.GetRepeatPaM().GetNode()->GetFlyFmt();
355 0 : if( pFly )
356 : {
357 : // Bug 43672: do not set all attributes!
358 0 : if (SFX_ITEM_SET ==
359 0 : m_pFmt->GetAttrSet().GetItemState( RES_CNTNT ))
360 : {
361 0 : SfxItemSet aTmpSet( m_pFmt->GetAttrSet() );
362 0 : aTmpSet.ClearItem( RES_CNTNT );
363 0 : if( aTmpSet.Count() )
364 : {
365 0 : rDoc.SetAttr( aTmpSet, *pFly );
366 0 : }
367 : }
368 : else
369 : {
370 0 : rDoc.SetAttr( m_pFmt->GetAttrSet(), *pFly );
371 : }
372 : }
373 0 : break;
374 : }
375 : }
376 : }
377 :
378 0 : SwRewriter SwUndoFmtAttr::GetRewriter() const
379 : {
380 0 : SwRewriter aRewriter;
381 :
382 0 : if (m_pFmt)
383 : {
384 0 : aRewriter.AddRule(UndoArg1, m_pFmt->GetName());
385 : }
386 :
387 0 : return aRewriter;
388 : }
389 :
390 0 : void SwUndoFmtAttr::PutAttr( const SfxPoolItem& rItem )
391 : {
392 0 : m_pOldSet->Put( rItem );
393 0 : if ( RES_ANCHOR == rItem.Which() )
394 : {
395 0 : SaveFlyAnchor( m_bSaveDrawPt );
396 : }
397 0 : }
398 :
399 0 : void SwUndoFmtAttr::SaveFlyAnchor( bool bSvDrwPt )
400 : {
401 : // Format is valid, otherwise you would not reach this point here
402 0 : if( bSvDrwPt )
403 : {
404 0 : if ( RES_DRAWFRMFMT == m_pFmt->Which() )
405 : {
406 0 : Point aPt( static_cast<SwFrmFmt*>(m_pFmt)->FindSdrObject()
407 0 : ->GetRelativePos() );
408 : // store old value as attribute, to keep SwUndoFmtAttr small
409 0 : m_pOldSet->Put( SwFmtFrmSize( ATT_VAR_SIZE, aPt.X(), aPt.Y() ) );
410 : }
411 : }
412 :
413 : const SwFmtAnchor& rAnchor =
414 0 : static_cast<const SwFmtAnchor&>( m_pOldSet->Get( RES_ANCHOR, sal_False ) );
415 0 : if( !rAnchor.GetCntntAnchor() )
416 : return;
417 :
418 0 : xub_StrLen nCntnt = 0;
419 0 : switch( rAnchor.GetAnchorId() )
420 : {
421 : case FLY_AS_CHAR:
422 : case FLY_AT_CHAR:
423 0 : nCntnt = rAnchor.GetCntntAnchor()->nContent.GetIndex();
424 : case FLY_AT_PARA:
425 : case FLY_AT_FLY:
426 0 : m_nNodeIndex = rAnchor.GetCntntAnchor()->nNode.GetIndex();
427 0 : break;
428 : default:
429 : return;
430 : }
431 :
432 0 : SwFmtAnchor aAnchor( rAnchor.GetAnchorId(), nCntnt );
433 0 : m_pOldSet->Put( aAnchor );
434 : }
435 :
436 : // #i35443# - Add return value, type <bool>.
437 : // Return value indicates, if anchor attribute is restored.
438 : // Note: If anchor attribute is restored, all other existing attributes
439 : // are also restored.
440 0 : bool SwUndoFmtAttr::RestoreFlyAnchor(::sw::UndoRedoContext & rContext)
441 : {
442 0 : SwDoc *const pDoc = & rContext.GetDoc();
443 0 : SwFlyFrmFmt* pFrmFmt = static_cast<SwFlyFrmFmt*>(m_pFmt);
444 : const SwFmtAnchor& rAnchor =
445 0 : static_cast<const SwFmtAnchor&>( m_pOldSet->Get( RES_ANCHOR, sal_False ) );
446 :
447 0 : SwFmtAnchor aNewAnchor( rAnchor.GetAnchorId() );
448 0 : if (FLY_AT_PAGE != rAnchor.GetAnchorId())
449 : {
450 0 : SwNode* pNd = pDoc->GetNodes()[ m_nNodeIndex ];
451 :
452 0 : if ( (FLY_AT_FLY == rAnchor.GetAnchorId())
453 0 : ? ( !pNd->IsStartNode() || (SwFlyStartNode !=
454 0 : static_cast<SwStartNode*>(pNd)->GetStartNodeType()) )
455 0 : : !pNd->IsTxtNode() )
456 : {
457 : // #i35443# - invalid position.
458 : // Thus, anchor attribute not restored
459 0 : return false;
460 : }
461 :
462 0 : SwPosition aPos( *pNd );
463 0 : if ((FLY_AS_CHAR == rAnchor.GetAnchorId()) ||
464 0 : (FLY_AT_CHAR == rAnchor.GetAnchorId()))
465 : {
466 0 : aPos.nContent.Assign( (SwTxtNode*)pNd, rAnchor.GetPageNum() );
467 0 : if ( aPos.nContent.GetIndex() >
468 0 : static_cast<SwTxtNode*>(pNd)->GetTxt().Len() )
469 : {
470 : // #i35443# - invalid position.
471 : // Thus, anchor attribute not restored
472 0 : return false;
473 : }
474 : }
475 0 : aNewAnchor.SetAnchor( &aPos );
476 : }
477 : else
478 0 : aNewAnchor.SetPageNum( rAnchor.GetPageNum() );
479 :
480 0 : Point aDrawSavePt, aDrawOldPt;
481 0 : if( pDoc->GetCurrentViewShell() ) //swmod 071108//swmod 071225
482 : {
483 0 : if( RES_DRAWFRMFMT == pFrmFmt->Which() )
484 : {
485 : // get the old cached value
486 : const SwFmtFrmSize& rOldSize = static_cast<const SwFmtFrmSize&>(
487 0 : m_pOldSet->Get( RES_FRM_SIZE ) );
488 0 : aDrawSavePt.X() = rOldSize.GetWidth();
489 0 : aDrawSavePt.Y() = rOldSize.GetHeight();
490 0 : m_pOldSet->ClearItem( RES_FRM_SIZE );
491 :
492 : // write the current value into cache
493 0 : aDrawOldPt = pFrmFmt->FindSdrObject()->GetRelativePos();
494 : }
495 : else
496 : {
497 0 : pFrmFmt->DelFrms(); // delete Frms
498 : }
499 : }
500 :
501 0 : const SwFmtAnchor &rOldAnch = pFrmFmt->GetAnchor();
502 : // #i54336#
503 : // Consider case, that as-character anchored object has moved its anchor position.
504 0 : if (FLY_AS_CHAR == rOldAnch.GetAnchorId())
505 : {
506 : // With InCntnts it's tricky: the text attribute needs to be deleted.
507 : // Unfortunately, this not only destroys the Frms but also the format.
508 : // To prevent that, first detach the connection between attribute and
509 : // format.
510 0 : const SwPosition *pPos = rOldAnch.GetCntntAnchor();
511 0 : SwTxtNode *pTxtNode = (SwTxtNode*)&pPos->nNode.GetNode();
512 : OSL_ENSURE( pTxtNode->HasHints(), "Missing FlyInCnt-Hint." );
513 0 : const xub_StrLen nIdx = pPos->nContent.GetIndex();
514 : SwTxtAttr * const pHnt =
515 0 : pTxtNode->GetTxtAttrForCharAt( nIdx, RES_TXTATR_FLYCNT );
516 : OSL_ENSURE( pHnt && pHnt->Which() == RES_TXTATR_FLYCNT,
517 : "Missing FlyInCnt-Hint." );
518 : OSL_ENSURE( pHnt && pHnt->GetFlyCnt().GetFrmFmt() == pFrmFmt,
519 : "Wrong TxtFlyCnt-Hint." );
520 0 : const_cast<SwFmtFlyCnt&>(pHnt->GetFlyCnt()).SetFlyFmt();
521 :
522 : // Connection is now detached, therefore the attribute can be deleted
523 0 : pTxtNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx );
524 : }
525 :
526 : {
527 0 : m_pOldSet->Put( aNewAnchor );
528 0 : SwUndoFmtAttrHelper aTmp( *m_pFmt, m_bSaveDrawPt );
529 0 : m_pFmt->SetFmtAttr( *m_pOldSet );
530 0 : if ( aTmp.GetUndo() )
531 : {
532 0 : m_nNodeIndex = aTmp.GetUndo()->m_nNodeIndex;
533 : // transfer ownership of helper object's old set
534 0 : m_pOldSet = aTmp.GetUndo()->m_pOldSet;
535 : }
536 : else
537 : {
538 0 : m_pOldSet->ClearItem();
539 0 : }
540 : }
541 :
542 0 : if ( RES_DRAWFRMFMT == pFrmFmt->Which() )
543 : {
544 : SwDrawContact *pCont =
545 0 : static_cast<SwDrawContact*>(pFrmFmt->FindContactObj());
546 : // The Draw model also prepared an Undo object for its right positioning
547 : // which unfortunately is relative. Therefore block here a position
548 : // change of the Contact object by setting the anchor.
549 0 : SdrObject* pObj = pCont->GetMaster();
550 :
551 0 : if( pCont->GetAnchorFrm() && !pObj->IsInserted() )
552 : {
553 : OSL_ENSURE( pDoc->GetDrawModel(), "RestoreFlyAnchor without DrawModel" );
554 0 : pDoc->GetDrawModel()->GetPage( 0 )->InsertObject( pObj );
555 : }
556 0 : pObj->SetRelativePos( aDrawSavePt );
557 :
558 : // cache the old value again
559 : m_pOldSet->Put(
560 0 : SwFmtFrmSize( ATT_VAR_SIZE, aDrawOldPt.X(), aDrawOldPt.Y() ) );
561 : }
562 :
563 0 : if (FLY_AS_CHAR == aNewAnchor.GetAnchorId())
564 : {
565 0 : const SwPosition* pPos = aNewAnchor.GetCntntAnchor();
566 0 : SwTxtNode* pTxtNd = pPos->nNode.GetNode().GetTxtNode();
567 : OSL_ENSURE( pTxtNd, "no Text Node at position." );
568 0 : SwFmtFlyCnt aFmt( pFrmFmt );
569 0 : pTxtNd->InsertItem( aFmt, pPos->nContent.GetIndex(), 0 );
570 : }
571 :
572 :
573 0 : if( RES_DRAWFRMFMT != pFrmFmt->Which() )
574 0 : pFrmFmt->MakeFrms();
575 :
576 0 : rContext.SetSelections(pFrmFmt, 0);
577 :
578 : // #i35443# - anchor attribute restored.
579 0 : return true;
580 : }
581 :
582 0 : SwUndoFmtResetAttr::SwUndoFmtResetAttr( SwFmt& rChangedFormat,
583 : const sal_uInt16 nWhichId )
584 : : SwUndo( UNDO_RESETATTR )
585 : , m_pChangedFormat( &rChangedFormat )
586 : , m_nWhichId( nWhichId )
587 0 : , m_pOldItem( 0 )
588 : {
589 0 : const SfxPoolItem* pItem = 0;
590 0 : if (rChangedFormat.GetItemState( nWhichId, sal_False, &pItem ) == SFX_ITEM_SET)
591 : {
592 0 : m_pOldItem.reset( pItem->Clone() );
593 : }
594 0 : }
595 :
596 0 : SwUndoFmtResetAttr::~SwUndoFmtResetAttr()
597 : {
598 0 : }
599 :
600 0 : void SwUndoFmtResetAttr::UndoImpl(::sw::UndoRedoContext &)
601 : {
602 0 : if ( m_pOldItem.get() )
603 : {
604 0 : m_pChangedFormat->SetFmtAttr( *m_pOldItem );
605 : }
606 0 : }
607 :
608 0 : void SwUndoFmtResetAttr::RedoImpl(::sw::UndoRedoContext &)
609 : {
610 0 : if ( m_pOldItem.get() )
611 : {
612 0 : m_pChangedFormat->ResetFmtAttr( m_nWhichId );
613 : }
614 0 : }
615 :
616 0 : SwUndoResetAttr::SwUndoResetAttr( const SwPaM& rRange, sal_uInt16 nFmtId )
617 : : SwUndo( UNDO_RESETATTR ), SwUndRng( rRange )
618 0 : , m_pHistory( new SwHistory )
619 0 : , m_nFormatId( nFmtId )
620 : {
621 0 : }
622 :
623 0 : SwUndoResetAttr::SwUndoResetAttr( const SwPosition& rPos, sal_uInt16 nFmtId )
624 : : SwUndo( UNDO_RESETATTR )
625 0 : , m_pHistory( new SwHistory )
626 0 : , m_nFormatId( nFmtId )
627 : {
628 0 : nSttNode = nEndNode = rPos.nNode.GetIndex();
629 0 : nSttCntnt = nEndCntnt = rPos.nContent.GetIndex();
630 0 : }
631 :
632 0 : SwUndoResetAttr::~SwUndoResetAttr()
633 : {
634 0 : }
635 :
636 0 : void SwUndoResetAttr::UndoImpl(::sw::UndoRedoContext & rContext)
637 : {
638 : // reset old values
639 0 : SwDoc & rDoc = rContext.GetDoc();
640 0 : m_pHistory->TmpRollback( &rDoc, 0 );
641 0 : m_pHistory->SetTmpEnd( m_pHistory->Count() );
642 :
643 0 : if ((RES_CONDTXTFMTCOLL == m_nFormatId) &&
644 : (nSttNode == nEndNode) && (nSttCntnt == nEndCntnt))
645 : {
646 0 : SwTxtNode* pTNd = rDoc.GetNodes()[ nSttNode ]->GetTxtNode();
647 0 : if( pTNd )
648 : {
649 0 : SwIndex aIdx( pTNd, nSttCntnt );
650 0 : pTNd->DontExpandFmt( aIdx, false );
651 : }
652 : }
653 :
654 0 : AddUndoRedoPaM(rContext);
655 0 : }
656 :
657 0 : void SwUndoResetAttr::RedoImpl(::sw::UndoRedoContext & rContext)
658 : {
659 0 : SwDoc & rDoc = rContext.GetDoc();
660 0 : SwPaM & rPam = AddUndoRedoPaM(rContext);
661 :
662 0 : switch ( m_nFormatId )
663 : {
664 : case RES_CHRFMT:
665 0 : rDoc.RstTxtAttrs(rPam);
666 0 : break;
667 : case RES_TXTFMTCOLL:
668 0 : rDoc.ResetAttrs(rPam, false, m_Ids );
669 0 : break;
670 : case RES_CONDTXTFMTCOLL:
671 0 : rDoc.ResetAttrs(rPam, true, m_Ids );
672 :
673 0 : break;
674 : case RES_TXTATR_TOXMARK:
675 : // special treatment for TOXMarks
676 : {
677 0 : SwTOXMarks aArr;
678 0 : SwNodeIndex aIdx( rDoc.GetNodes(), nSttNode );
679 0 : SwPosition aPos( aIdx, SwIndex( aIdx.GetNode().GetCntntNode(),
680 0 : nSttCntnt ));
681 :
682 0 : sal_uInt16 nCnt = rDoc.GetCurTOXMark( aPos, aArr );
683 0 : if( nCnt )
684 : {
685 0 : if( 1 < nCnt )
686 : {
687 : // search for the right one
688 0 : SwHistoryHint* pHHint = (GetHistory())[ 0 ];
689 0 : if( pHHint && HSTRY_SETTOXMARKHNT == pHHint->Which() )
690 : {
691 0 : while( nCnt )
692 : {
693 0 : if ( static_cast<SwHistorySetTOXMark*>(pHHint)
694 0 : ->IsEqual( *aArr[ --nCnt ] ) )
695 : {
696 0 : ++nCnt;
697 0 : break;
698 : }
699 : }
700 : }
701 : else
702 0 : nCnt = 0;
703 : }
704 : // found one, thus delete it
705 0 : if( nCnt-- )
706 : {
707 0 : rDoc.DeleteTOXMark( aArr[ nCnt ] );
708 : }
709 0 : }
710 : }
711 0 : break;
712 : }
713 0 : }
714 :
715 0 : void SwUndoResetAttr::RepeatImpl(::sw::RepeatContext & rContext)
716 : {
717 0 : if (m_nFormatId < RES_FMT_BEGIN)
718 : {
719 0 : return;
720 : }
721 :
722 0 : switch ( m_nFormatId )
723 : {
724 : case RES_CHRFMT:
725 0 : rContext.GetDoc().RstTxtAttrs(rContext.GetRepeatPaM());
726 0 : break;
727 : case RES_TXTFMTCOLL:
728 0 : rContext.GetDoc().ResetAttrs(rContext.GetRepeatPaM(), false, m_Ids);
729 0 : break;
730 : case RES_CONDTXTFMTCOLL:
731 0 : rContext.GetDoc().ResetAttrs(rContext.GetRepeatPaM(), true, m_Ids);
732 0 : break;
733 : }
734 : }
735 :
736 :
737 0 : void SwUndoResetAttr::SetAttrs( const std::set<sal_uInt16> &rAttrs )
738 : {
739 0 : m_Ids.clear();
740 0 : m_Ids.insert( rAttrs.begin(), rAttrs.end() );
741 0 : }
742 :
743 0 : SwUndoAttr::SwUndoAttr( const SwPaM& rRange, const SfxPoolItem& rAttr,
744 : const SetAttrMode nFlags )
745 : : SwUndo( UNDO_INSATTR ), SwUndRng( rRange )
746 0 : , m_AttrSet( rRange.GetDoc()->GetAttrPool(), rAttr.Which(), rAttr.Which() )
747 0 : , m_pHistory( new SwHistory )
748 : , m_pRedlineData( 0 )
749 : , m_pRedlineSaveData( 0 )
750 : , m_nNodeIndex( ULONG_MAX )
751 0 : , m_nInsertFlags( nFlags )
752 : {
753 0 : m_AttrSet.Put( rAttr );
754 0 : }
755 :
756 0 : SwUndoAttr::SwUndoAttr( const SwPaM& rRange, const SfxItemSet& rSet,
757 : const SetAttrMode nFlags )
758 : : SwUndo( UNDO_INSATTR ), SwUndRng( rRange )
759 : , m_AttrSet( rSet )
760 0 : , m_pHistory( new SwHistory )
761 : , m_pRedlineData( 0 )
762 : , m_pRedlineSaveData( 0 )
763 : , m_nNodeIndex( ULONG_MAX )
764 0 : , m_nInsertFlags( nFlags )
765 : {
766 0 : }
767 :
768 0 : SwUndoAttr::~SwUndoAttr()
769 : {
770 0 : }
771 :
772 0 : void SwUndoAttr::SaveRedlineData( const SwPaM& rPam, sal_Bool bIsCntnt )
773 : {
774 0 : SwDoc* pDoc = rPam.GetDoc();
775 0 : if ( pDoc->IsRedlineOn() )
776 : {
777 : m_pRedlineData.reset( new SwRedlineData( bIsCntnt
778 : ? nsRedlineType_t::REDLINE_INSERT
779 : : nsRedlineType_t::REDLINE_FORMAT,
780 0 : pDoc->GetRedlineAuthor() ) );
781 : }
782 :
783 0 : m_pRedlineSaveData.reset( new SwRedlineSaveDatas );
784 0 : if ( !FillSaveDataForFmt( rPam, *m_pRedlineSaveData ))
785 : {
786 0 : m_pRedlineSaveData.reset(0);
787 : }
788 :
789 0 : SetRedlineMode( pDoc->GetRedlineMode() );
790 0 : if ( bIsCntnt )
791 : {
792 0 : m_nNodeIndex = rPam.GetPoint()->nNode.GetIndex();
793 : }
794 0 : }
795 :
796 0 : void SwUndoAttr::UndoImpl(::sw::UndoRedoContext & rContext)
797 : {
798 0 : SwDoc *const pDoc = & rContext.GetDoc();
799 :
800 0 : RemoveIdx( *pDoc );
801 :
802 0 : if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ) )
803 : {
804 0 : SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
805 0 : if ( ULONG_MAX != m_nNodeIndex )
806 : {
807 0 : aPam.DeleteMark();
808 0 : aPam.GetPoint()->nNode = m_nNodeIndex;
809 0 : aPam.GetPoint()->nContent.Assign( aPam.GetCntntNode(), nSttCntnt );
810 0 : aPam.SetMark();
811 0 : aPam.GetPoint()->nContent++;
812 0 : pDoc->DeleteRedline(aPam, false, USHRT_MAX);
813 : }
814 : else
815 : {
816 : // remove all format redlines, will be recreated if needed
817 0 : SetPaM(aPam);
818 0 : pDoc->DeleteRedline(aPam, false, nsRedlineType_t::REDLINE_FORMAT);
819 0 : if ( m_pRedlineSaveData.get() )
820 : {
821 0 : SetSaveData( *pDoc, *m_pRedlineSaveData );
822 : }
823 0 : }
824 : }
825 :
826 0 : const bool bToLast = (1 == m_AttrSet.Count())
827 0 : && (RES_TXTATR_FIELD <= *m_AttrSet.GetRanges())
828 0 : && (*m_AttrSet.GetRanges() <= RES_TXTATR_FTN);
829 :
830 : // restore old values
831 0 : m_pHistory->TmpRollback( pDoc, 0, !bToLast );
832 0 : m_pHistory->SetTmpEnd( m_pHistory->Count() );
833 :
834 : // set cursor onto Undo area
835 0 : AddUndoRedoPaM(rContext);
836 0 : }
837 :
838 0 : void SwUndoAttr::RepeatImpl(::sw::RepeatContext & rContext)
839 : {
840 : // RefMarks are not repeat capable
841 0 : if ( SFX_ITEM_SET != m_AttrSet.GetItemState( RES_TXTATR_REFMARK, sal_False ) )
842 : {
843 0 : rContext.GetDoc().InsertItemSet( rContext.GetRepeatPaM(),
844 0 : m_AttrSet, m_nInsertFlags );
845 : }
846 0 : else if ( 1 < m_AttrSet.Count() )
847 : {
848 0 : SfxItemSet aTmpSet( m_AttrSet );
849 0 : aTmpSet.ClearItem( RES_TXTATR_REFMARK );
850 0 : rContext.GetDoc().InsertItemSet( rContext.GetRepeatPaM(),
851 0 : aTmpSet, m_nInsertFlags );
852 : }
853 0 : }
854 :
855 0 : void SwUndoAttr::RedoImpl(::sw::UndoRedoContext & rContext)
856 : {
857 0 : SwDoc & rDoc = rContext.GetDoc();
858 0 : SwPaM & rPam = AddUndoRedoPaM(rContext);
859 :
860 0 : if ( m_pRedlineData.get() &&
861 0 : IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ) )
862 : {
863 0 : RedlineMode_t eOld = rDoc.GetRedlineMode();
864 : rDoc.SetRedlineMode_intern(static_cast<RedlineMode_t>(
865 0 : eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
866 0 : rDoc.InsertItemSet( rPam, m_AttrSet, m_nInsertFlags );
867 :
868 0 : if ( ULONG_MAX != m_nNodeIndex )
869 : {
870 0 : rPam.SetMark();
871 0 : if ( rPam.Move( fnMoveBackward ) )
872 : {
873 0 : rDoc.AppendRedline( new SwRedline( *m_pRedlineData, rPam ),
874 0 : true);
875 : }
876 0 : rPam.DeleteMark();
877 : }
878 : else
879 : {
880 0 : rDoc.AppendRedline( new SwRedline( *m_pRedlineData, rPam ), true);
881 : }
882 :
883 0 : rDoc.SetRedlineMode_intern( eOld );
884 : }
885 : else
886 : {
887 0 : rDoc.InsertItemSet( rPam, m_AttrSet, m_nInsertFlags );
888 : }
889 0 : }
890 :
891 0 : void SwUndoAttr::RemoveIdx( SwDoc& rDoc )
892 : {
893 0 : if ( SFX_ITEM_SET != m_AttrSet.GetItemState( RES_TXTATR_FTN, sal_False ))
894 0 : return ;
895 :
896 : SwHistoryHint* pHstHnt;
897 0 : SwNodes& rNds = rDoc.GetNodes();
898 0 : for ( sal_uInt16 n = 0; n < m_pHistory->Count(); ++n )
899 : {
900 0 : xub_StrLen nCntnt = 0;
901 0 : sal_uLong nNode = 0;
902 0 : pHstHnt = (*m_pHistory)[ n ];
903 0 : switch ( pHstHnt->Which() )
904 : {
905 : case HSTRY_RESETTXTHNT:
906 : {
907 : SwHistoryResetTxt * pHistoryHint
908 0 : = static_cast<SwHistoryResetTxt*>(pHstHnt);
909 0 : if ( RES_TXTATR_FTN == pHistoryHint->GetWhich() )
910 : {
911 0 : nNode = pHistoryHint->GetNode();
912 0 : nCntnt = pHistoryHint->GetCntnt();
913 : }
914 : }
915 0 : break;
916 :
917 : case HSTRY_RESETATTRSET:
918 : {
919 : SwHistoryResetAttrSet * pHistoryHint
920 0 : = static_cast<SwHistoryResetAttrSet*>(pHstHnt);
921 0 : nCntnt = pHistoryHint->GetCntnt();
922 0 : if ( STRING_MAXLEN != nCntnt )
923 : {
924 0 : const std::vector<sal_uInt16>& rArr = pHistoryHint->GetArr();
925 0 : for ( sal_uInt16 i = rArr.size(); i; )
926 : {
927 0 : if ( RES_TXTATR_FTN == rArr[ --i ] )
928 : {
929 0 : nNode = pHistoryHint->GetNode();
930 0 : break;
931 : }
932 : }
933 : }
934 : }
935 0 : break;
936 :
937 : default:
938 0 : break;
939 : }
940 :
941 0 : if( nNode )
942 : {
943 0 : SwTxtNode* pTxtNd = rNds[ nNode ]->GetTxtNode();
944 0 : if( pTxtNd )
945 : {
946 : SwTxtAttr *const pTxtHt =
947 0 : pTxtNd->GetTxtAttrForCharAt(nCntnt, RES_TXTATR_FTN);
948 0 : if( pTxtHt )
949 : {
950 : // ok, so get values
951 0 : SwTxtFtn* pFtn = static_cast<SwTxtFtn*>(pTxtHt);
952 0 : RemoveIdxFromSection( rDoc, pFtn->GetStartNode()->GetIndex() );
953 0 : return ;
954 : }
955 : }
956 : }
957 : }
958 : }
959 :
960 0 : SwUndoDefaultAttr::SwUndoDefaultAttr( const SfxItemSet& rSet )
961 : : SwUndo( UNDO_SETDEFTATTR )
962 : , m_pOldSet( 0 )
963 0 : , m_pTabStop( 0 )
964 : {
965 : const SfxPoolItem* pItem;
966 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_PARATR_TABSTOP, sal_False, &pItem ) )
967 : {
968 : // store separately, because it may change!
969 0 : m_pTabStop.reset( static_cast<SvxTabStopItem*>(pItem->Clone()) );
970 0 : if ( 1 != rSet.Count() ) // are there more attributes?
971 : {
972 0 : m_pOldSet.reset( new SfxItemSet( rSet ) );
973 : }
974 : }
975 : else
976 : {
977 0 : m_pOldSet.reset( new SfxItemSet( rSet ) );
978 : }
979 0 : }
980 :
981 0 : SwUndoDefaultAttr::~SwUndoDefaultAttr()
982 : {
983 0 : }
984 :
985 0 : void SwUndoDefaultAttr::UndoImpl(::sw::UndoRedoContext & rContext)
986 : {
987 0 : SwDoc & rDoc = rContext.GetDoc();
988 0 : if ( m_pOldSet.get() )
989 : {
990 : SwUndoFmtAttrHelper aTmp(
991 0 : *const_cast<SwTxtFmtColl*>(rDoc.GetDfltTxtFmtColl()) );
992 0 : rDoc.SetDefault( *m_pOldSet );
993 0 : m_pOldSet.reset( 0 );
994 0 : if ( aTmp.GetUndo() )
995 : {
996 : // transfer ownership of helper object's old set
997 0 : m_pOldSet = aTmp.GetUndo()->m_pOldSet;
998 0 : }
999 : }
1000 0 : if ( m_pTabStop.get() )
1001 : {
1002 : SvxTabStopItem* pOld = static_cast<SvxTabStopItem*>(
1003 0 : rDoc.GetDefault( RES_PARATR_TABSTOP ).Clone() );
1004 0 : rDoc.SetDefault( *m_pTabStop );
1005 0 : m_pTabStop.reset( pOld );
1006 : }
1007 0 : }
1008 :
1009 0 : void SwUndoDefaultAttr::RedoImpl(::sw::UndoRedoContext & rContext)
1010 : {
1011 0 : UndoImpl(rContext);
1012 0 : }
1013 :
1014 0 : SwUndoMoveLeftMargin::SwUndoMoveLeftMargin(
1015 : const SwPaM& rPam, sal_Bool bFlag, bool bMod )
1016 : : SwUndo( bFlag ? UNDO_INC_LEFTMARGIN : UNDO_DEC_LEFTMARGIN )
1017 : , SwUndRng( rPam )
1018 0 : , m_pHistory( new SwHistory )
1019 0 : , m_bModulus( bMod )
1020 : {
1021 0 : }
1022 :
1023 0 : SwUndoMoveLeftMargin::~SwUndoMoveLeftMargin()
1024 : {
1025 0 : }
1026 :
1027 0 : void SwUndoMoveLeftMargin::UndoImpl(::sw::UndoRedoContext & rContext)
1028 : {
1029 0 : SwDoc & rDoc = rContext.GetDoc();
1030 :
1031 : // restore old values
1032 0 : m_pHistory->TmpRollback( & rDoc, 0 );
1033 0 : m_pHistory->SetTmpEnd( m_pHistory->Count() );
1034 :
1035 0 : AddUndoRedoPaM(rContext);
1036 0 : }
1037 :
1038 0 : void SwUndoMoveLeftMargin::RedoImpl(::sw::UndoRedoContext & rContext)
1039 : {
1040 0 : SwDoc & rDoc = rContext.GetDoc();
1041 0 : SwPaM & rPam = AddUndoRedoPaM(rContext);
1042 :
1043 : rDoc.MoveLeftMargin( rPam,
1044 0 : GetId() == UNDO_INC_LEFTMARGIN, m_bModulus );
1045 0 : }
1046 :
1047 0 : void SwUndoMoveLeftMargin::RepeatImpl(::sw::RepeatContext & rContext)
1048 : {
1049 0 : SwDoc & rDoc = rContext.GetDoc();
1050 0 : rDoc.MoveLeftMargin(rContext.GetRepeatPaM(), GetId() == UNDO_INC_LEFTMARGIN,
1051 0 : m_bModulus );
1052 0 : }
1053 :
1054 0 : SwUndoChangeFootNote::SwUndoChangeFootNote(
1055 : const SwPaM& rRange, const String& rTxt,
1056 : sal_uInt16 nNum, bool bIsEndNote )
1057 : : SwUndo( UNDO_CHGFTN ), SwUndRng( rRange )
1058 0 : , m_pHistory( new SwHistory() )
1059 : , m_Text( rTxt )
1060 : , m_nNumber( nNum )
1061 0 : , m_bEndNote( bIsEndNote )
1062 : {
1063 0 : }
1064 :
1065 0 : SwUndoChangeFootNote::~SwUndoChangeFootNote()
1066 : {
1067 0 : }
1068 :
1069 0 : void SwUndoChangeFootNote::UndoImpl(::sw::UndoRedoContext & rContext)
1070 : {
1071 0 : SwDoc & rDoc = rContext.GetDoc();
1072 :
1073 0 : m_pHistory->TmpRollback( &rDoc, 0 );
1074 0 : m_pHistory->SetTmpEnd( m_pHistory->Count() );
1075 :
1076 0 : rDoc.GetFtnIdxs().UpdateAllFtn();
1077 :
1078 0 : AddUndoRedoPaM(rContext);
1079 0 : }
1080 :
1081 0 : void SwUndoChangeFootNote::RedoImpl(::sw::UndoRedoContext & rContext)
1082 : {
1083 0 : SwDoc & rDoc( rContext.GetDoc() );
1084 0 : SwPaM & rPaM = AddUndoRedoPaM(rContext);
1085 0 : rDoc.SetCurFtn(rPaM, m_Text, m_nNumber, m_bEndNote);
1086 0 : SetPaM(rPaM);
1087 0 : }
1088 :
1089 0 : void SwUndoChangeFootNote::RepeatImpl(::sw::RepeatContext & rContext)
1090 : {
1091 0 : SwDoc & rDoc = rContext.GetDoc();
1092 0 : rDoc.SetCurFtn( rContext.GetRepeatPaM(), m_Text, m_nNumber, m_bEndNote );
1093 0 : }
1094 :
1095 0 : SwUndoFootNoteInfo::SwUndoFootNoteInfo( const SwFtnInfo &rInfo )
1096 : : SwUndo( UNDO_FTNINFO )
1097 0 : , m_pFootNoteInfo( new SwFtnInfo( rInfo ) )
1098 : {
1099 0 : }
1100 :
1101 0 : SwUndoFootNoteInfo::~SwUndoFootNoteInfo()
1102 : {
1103 0 : }
1104 :
1105 0 : void SwUndoFootNoteInfo::UndoImpl(::sw::UndoRedoContext & rContext)
1106 : {
1107 0 : SwDoc & rDoc = rContext.GetDoc();
1108 0 : SwFtnInfo *pInf = new SwFtnInfo( rDoc.GetFtnInfo() );
1109 0 : rDoc.SetFtnInfo( *m_pFootNoteInfo );
1110 0 : m_pFootNoteInfo.reset( pInf );
1111 0 : }
1112 :
1113 0 : void SwUndoFootNoteInfo::RedoImpl(::sw::UndoRedoContext & rContext)
1114 : {
1115 0 : SwDoc & rDoc = rContext.GetDoc();
1116 0 : SwFtnInfo *pInf = new SwFtnInfo( rDoc.GetFtnInfo() );
1117 0 : rDoc.SetFtnInfo( *m_pFootNoteInfo );
1118 0 : m_pFootNoteInfo.reset( pInf );
1119 0 : }
1120 :
1121 0 : SwUndoEndNoteInfo::SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo )
1122 : : SwUndo( UNDO_FTNINFO )
1123 0 : , m_pEndNoteInfo( new SwEndNoteInfo( rInfo ) )
1124 : {
1125 0 : }
1126 :
1127 0 : SwUndoEndNoteInfo::~SwUndoEndNoteInfo()
1128 : {
1129 0 : }
1130 :
1131 0 : void SwUndoEndNoteInfo::UndoImpl(::sw::UndoRedoContext & rContext)
1132 : {
1133 0 : SwDoc & rDoc = rContext.GetDoc();
1134 0 : SwEndNoteInfo *pInf = new SwEndNoteInfo( rDoc.GetEndNoteInfo() );
1135 0 : rDoc.SetEndNoteInfo( *m_pEndNoteInfo );
1136 0 : m_pEndNoteInfo.reset( pInf );
1137 0 : }
1138 :
1139 0 : void SwUndoEndNoteInfo::RedoImpl(::sw::UndoRedoContext & rContext)
1140 : {
1141 0 : SwDoc & rDoc = rContext.GetDoc();
1142 0 : SwEndNoteInfo *pInf = new SwEndNoteInfo( rDoc.GetEndNoteInfo() );
1143 0 : rDoc.SetEndNoteInfo( *m_pEndNoteInfo );
1144 0 : m_pEndNoteInfo.reset( pInf );
1145 0 : }
1146 :
1147 0 : SwUndoDontExpandFmt::SwUndoDontExpandFmt( const SwPosition& rPos )
1148 : : SwUndo( UNDO_DONTEXPAND )
1149 0 : , m_nNodeIndex( rPos.nNode.GetIndex() )
1150 0 : , m_nContentIndex( rPos.nContent.GetIndex() )
1151 : {
1152 0 : }
1153 :
1154 0 : void SwUndoDontExpandFmt::UndoImpl(::sw::UndoRedoContext & rContext)
1155 : {
1156 0 : SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
1157 0 : SwDoc *const pDoc = & rContext.GetDoc();
1158 :
1159 0 : SwPosition& rPos = *pPam->GetPoint();
1160 0 : rPos.nNode = m_nNodeIndex;
1161 0 : rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(), m_nContentIndex);
1162 0 : pDoc->DontExpandFmt( rPos, false );
1163 0 : }
1164 :
1165 0 : void SwUndoDontExpandFmt::RedoImpl(::sw::UndoRedoContext & rContext)
1166 : {
1167 0 : SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
1168 0 : SwDoc *const pDoc = & rContext.GetDoc();
1169 :
1170 0 : SwPosition& rPos = *pPam->GetPoint();
1171 0 : rPos.nNode = m_nNodeIndex;
1172 0 : rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(), m_nContentIndex);
1173 0 : pDoc->DontExpandFmt( rPos );
1174 0 : }
1175 :
1176 0 : void SwUndoDontExpandFmt::RepeatImpl(::sw::RepeatContext & rContext)
1177 : {
1178 0 : SwPaM & rPam = rContext.GetRepeatPaM();
1179 0 : SwDoc & rDoc = rContext.GetDoc();
1180 0 : rDoc.DontExpandFmt( *rPam.GetPoint() );
1181 0 : }
1182 :
1183 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|