fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / undocell.cxx
blobc239686cc030b352587463f7b846712758ef9d27
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "undocell.hxx"
22 #include "scitems.hxx"
23 #include <editeng/eeitem.hxx>
24 #include <editeng/editobj.hxx>
25 #include <svl/zforlist.hxx>
26 #include <svl/sharedstringpool.hxx>
27 #include <sfx2/app.hxx>
29 #include "document.hxx"
30 #include "docpool.hxx"
31 #include "patattr.hxx"
32 #include "docsh.hxx"
33 #include "tabvwsh.hxx"
34 #include "globstr.hrc"
35 #include "global.hxx"
36 #include "formulacell.hxx"
37 #include "target.hxx"
38 #include "undoolk.hxx"
39 #include "detdata.hxx"
40 #include "stlpool.hxx"
41 #include "printfun.hxx"
42 #include "rangenam.hxx"
43 #include "chgtrack.hxx"
44 #include "sc.hrc"
45 #include "docuno.hxx"
46 #include "stringutil.hxx"
48 using ::boost::shared_ptr;
50 namespace HelperNotifyChanges
52 void NotifyIfChangesListeners(ScDocShell& rDocShell, const ScAddress &rPos,
53 const ScUndoEnterData::ValuesType &rOldValues, const OUString &rType = OUString("cell-change"))
55 if (ScModelObj* pModelObj = getMustPropagateChangesModel(rDocShell))
57 ScRangeList aChangeRanges;
59 for (size_t i = 0, n = rOldValues.size(); i < n; ++i)
61 aChangeRanges.Append( ScRange(rPos.Col(), rPos.Row(), rOldValues[i].mnTab));
64 Notify(*pModelObj, aChangeRanges, rType);
69 TYPEINIT1(ScUndoCursorAttr, ScSimpleUndo);
70 TYPEINIT1(ScUndoEnterData, ScSimpleUndo);
71 TYPEINIT1(ScUndoEnterValue, ScSimpleUndo);
72 TYPEINIT1(ScUndoSetCell, ScSimpleUndo);
73 TYPEINIT1(ScUndoPageBreak, ScSimpleUndo);
74 TYPEINIT1(ScUndoPrintZoom, ScSimpleUndo);
75 TYPEINIT1(ScUndoThesaurus, ScSimpleUndo);
76 TYPEINIT1(ScUndoReplaceNote, ScSimpleUndo);
77 TYPEINIT1(ScUndoShowHideNote, ScSimpleUndo);
78 TYPEINIT1(ScUndoDetective, ScSimpleUndo);
79 TYPEINIT1(ScUndoRangeNames, ScSimpleUndo);
81 ScUndoCursorAttr::ScUndoCursorAttr( ScDocShell* pNewDocShell,
82 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
83 const ScPatternAttr* pOldPat, const ScPatternAttr* pNewPat,
84 const ScPatternAttr* pApplyPat, bool bAutomatic ) :
85 ScSimpleUndo( pNewDocShell ),
86 nCol( nNewCol ),
87 nRow( nNewRow ),
88 nTab( nNewTab ),
89 pOldEditData( static_cast<EditTextObject*>(NULL) ),
90 pNewEditData( static_cast<EditTextObject*>(NULL) ),
91 bIsAutomatic( bAutomatic )
93 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
94 pNewPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pNewPat ) ));
95 pOldPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pOldPat ) ));
96 pApplyPattern = const_cast<ScPatternAttr*>(static_cast<const ScPatternAttr*>( &pPool->Put( *pApplyPat ) ));
99 ScUndoCursorAttr::~ScUndoCursorAttr()
101 ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
102 pPool->Remove(*pNewPattern);
103 pPool->Remove(*pOldPattern);
104 pPool->Remove(*pApplyPattern);
107 OUString ScUndoCursorAttr::GetComment() const
109 //! own text for automatic attribution
111 sal_uInt16 nId = STR_UNDO_CURSORATTR; // "Attribute"
112 return ScGlobal::GetRscString( nId );
115 void ScUndoCursorAttr::SetEditData( EditTextObject* pOld, EditTextObject* pNew )
117 pOldEditData.reset(pOld);
118 pNewEditData.reset(pNew);
121 void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const shared_ptr<EditTextObject>& pEditData ) const
123 ScDocument& rDoc = pDocShell->GetDocument();
124 ScAddress aPos(nCol, nRow, nTab);
125 rDoc.SetPattern( nCol, nRow, nTab, *pWhichPattern, true );
127 if (rDoc.GetCellType(aPos) == CELLTYPE_EDIT && pEditData)
128 rDoc.SetEditText(aPos, *pEditData, NULL);
130 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
131 if (pViewShell)
133 pViewShell->SetTabNo( nTab );
134 pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, false, false );
135 pViewShell->AdjustBlockHeight();
138 const SfxItemSet& rApplySet = pApplyPattern->GetItemSet();
139 bool bPaintExt = ( rApplySet.GetItemState( ATTR_SHADOW, true ) != SfxItemState::DEFAULT ||
140 rApplySet.GetItemState( ATTR_CONDITIONAL, true ) != SfxItemState::DEFAULT );
141 bool bPaintRows = ( rApplySet.GetItemState( ATTR_HOR_JUSTIFY, true ) != SfxItemState::DEFAULT );
143 sal_uInt16 nFlags = SC_PF_TESTMERGE;
144 if (bPaintExt)
145 nFlags |= SC_PF_LINES;
146 if (bPaintRows)
147 nFlags |= SC_PF_WHOLEROWS;
148 pDocShell->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID, nFlags );
151 void ScUndoCursorAttr::Undo()
153 BeginUndo();
154 DoChange(pOldPattern, pOldEditData);
156 if ( bIsAutomatic )
158 // if automatic formatting is reversed, then
159 // automatic formatting should also not continue to be done
161 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
162 if (pViewShell)
163 pViewShell->ForgetFormatArea();
166 EndUndo();
169 void ScUndoCursorAttr::Redo()
171 BeginRedo();
172 DoChange(pNewPattern, pNewEditData);
173 EndRedo();
176 void ScUndoCursorAttr::Repeat(SfxRepeatTarget& rTarget)
178 if (rTarget.ISA(ScTabViewTarget))
179 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->ApplySelectionPattern( *pApplyPattern );
182 bool ScUndoCursorAttr::CanRepeat(SfxRepeatTarget& rTarget) const
184 return rTarget.ISA(ScTabViewTarget);
187 ScUndoEnterData::Value::Value() : mnTab(-1), mbHasFormat(false), mnFormat(0) {}
189 ScUndoEnterData::ScUndoEnterData(
190 ScDocShell* pNewDocShell, const ScAddress& rPos, ValuesType& rOldValues,
191 const OUString& rNewStr, EditTextObject* pObj ) :
192 ScSimpleUndo( pNewDocShell ),
193 maNewString(rNewStr),
194 mpNewEditData(pObj),
195 mnEndChangeAction(0),
196 maPos(rPos)
198 maOldValues.swap(rOldValues);
200 SetChangeTrack();
203 ScUndoEnterData::~ScUndoEnterData() {}
205 OUString ScUndoEnterData::GetComment() const
207 return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
210 void ScUndoEnterData::DoChange() const
212 // only when needed (old or new Edit cell, or Attribute)?
213 for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
214 pDocShell->AdjustRowHeight(maPos.Row(), maPos.Row(), maOldValues[i].mnTab);
216 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
217 if (pViewShell)
219 pViewShell->SetTabNo(maPos.Tab());
220 pViewShell->MoveCursorAbs(maPos.Col(), maPos.Row(), SC_FOLLOW_JUMP, false, false);
223 pDocShell->PostDataChanged();
226 void ScUndoEnterData::SetChangeTrack()
228 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
229 if ( pChangeTrack )
231 mnEndChangeAction = pChangeTrack->GetActionMax() + 1;
232 ScAddress aPos(maPos);
233 for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
235 aPos.SetTab(maOldValues[i].mnTab);
236 sal_uLong nFormat = 0;
237 if (maOldValues[i].mbHasFormat)
238 nFormat = maOldValues[i].mnFormat;
239 pChangeTrack->AppendContent(aPos, maOldValues[i].maCell, nFormat);
241 if ( mnEndChangeAction > pChangeTrack->GetActionMax() )
242 mnEndChangeAction = 0; // nothing is appended
244 else
245 mnEndChangeAction = 0;
248 void ScUndoEnterData::Undo()
250 BeginUndo();
252 ScDocument& rDoc = pDocShell->GetDocument();
253 for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
255 Value& rVal = maOldValues[i];
256 ScCellValue aNewCell;
257 aNewCell.assign(rVal.maCell, rDoc, SC_CLONECELL_STARTLISTENING);
258 ScAddress aPos = maPos;
259 aPos.SetTab(rVal.mnTab);
260 aNewCell.release(rDoc, aPos);
262 if (rVal.mbHasFormat)
263 rDoc.ApplyAttr(maPos.Col(), maPos.Row(), rVal.mnTab,
264 SfxUInt32Item(ATTR_VALUE_FORMAT, rVal.mnFormat));
265 else
267 ScPatternAttr aPattern(*rDoc.GetPattern(maPos.Col(), maPos.Row(), rVal.mnTab));
268 aPattern.GetItemSet().ClearItem( ATTR_VALUE_FORMAT );
269 rDoc.SetPattern(maPos.Col(), maPos.Row(), rVal.mnTab, aPattern, true);
271 pDocShell->PostPaintCell(maPos.Col(), maPos.Row(), rVal.mnTab);
274 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
275 size_t nCount = maOldValues.size();
276 if ( pChangeTrack && mnEndChangeAction >= sal::static_int_cast<sal_uLong>(nCount) )
277 pChangeTrack->Undo( mnEndChangeAction - nCount + 1, mnEndChangeAction );
279 DoChange();
280 EndUndo();
282 HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, maPos, maOldValues);
285 void ScUndoEnterData::Redo()
287 BeginRedo();
289 ScDocument& rDoc = pDocShell->GetDocument();
290 for (size_t i = 0, n = maOldValues.size(); i < n; ++i)
292 SCTAB nTab = maOldValues[i].mnTab;
293 if (mpNewEditData)
295 ScAddress aPos = maPos;
296 aPos.SetTab(nTab);
297 // edit text wil be cloned.
298 rDoc.SetEditText(aPos, *mpNewEditData, NULL);
300 else
301 rDoc.SetString(maPos.Col(), maPos.Row(), nTab, maNewString);
303 pDocShell->PostPaintCell(maPos.Col(), maPos.Row(), nTab);
306 SetChangeTrack();
308 DoChange();
309 EndRedo();
311 HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell, maPos, maOldValues);
314 void ScUndoEnterData::Repeat(SfxRepeatTarget& rTarget)
316 if (rTarget.ISA(ScTabViewTarget))
318 OUString aTemp = maNewString;
319 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->EnterDataAtCursor( aTemp );
323 bool ScUndoEnterData::CanRepeat(SfxRepeatTarget& rTarget) const
325 return rTarget.ISA(ScTabViewTarget);
328 ScUndoEnterValue::ScUndoEnterValue(
329 ScDocShell* pNewDocShell, const ScAddress& rNewPos,
330 const ScCellValue& rUndoCell, double nVal ) :
331 ScSimpleUndo( pNewDocShell ),
332 aPos ( rNewPos ),
333 maOldCell(rUndoCell),
334 nValue ( nVal )
336 SetChangeTrack();
339 ScUndoEnterValue::~ScUndoEnterValue()
343 OUString ScUndoEnterValue::GetComment() const
345 return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Input"
348 void ScUndoEnterValue::SetChangeTrack()
350 ScDocument& rDoc = pDocShell->GetDocument();
351 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
352 if ( pChangeTrack )
354 nEndChangeAction = pChangeTrack->GetActionMax() + 1;
355 pChangeTrack->AppendContent(aPos, maOldCell);
356 if ( nEndChangeAction > pChangeTrack->GetActionMax() )
357 nEndChangeAction = 0; // nothing is appended
359 else
360 nEndChangeAction = 0;
363 void ScUndoEnterValue::Undo()
365 BeginUndo();
367 ScDocument& rDoc = pDocShell->GetDocument();
368 ScCellValue aNewCell;
369 aNewCell.assign(maOldCell, rDoc, SC_CLONECELL_STARTLISTENING);
370 aNewCell.release(rDoc, aPos);
372 pDocShell->PostPaintCell( aPos );
374 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
375 if ( pChangeTrack )
376 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
378 EndUndo();
381 void ScUndoEnterValue::Redo()
383 BeginRedo();
385 ScDocument& rDoc = pDocShell->GetDocument();
386 rDoc.SetValue( aPos.Col(), aPos.Row(), aPos.Tab(), nValue );
387 pDocShell->PostPaintCell( aPos );
389 SetChangeTrack();
391 EndRedo();
394 void ScUndoEnterValue::Repeat(SfxRepeatTarget& /* rTarget */)
396 // makes no sense
399 bool ScUndoEnterValue::CanRepeat(SfxRepeatTarget& /* rTarget */) const
401 return false;
404 ScUndoSetCell::ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal ) :
405 ScSimpleUndo(pDocSh), maPos(rPos), maOldValue(rOldVal), maNewValue(rNewVal), mnEndChangeAction(0)
407 SetChangeTrack();
410 ScUndoSetCell::~ScUndoSetCell() {}
412 void ScUndoSetCell::Undo()
414 BeginUndo();
415 SetValue(maOldValue);
416 pDocShell->PostPaintCell(maPos);
418 ScDocument& rDoc = pDocShell->GetDocument();
419 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
420 if (pChangeTrack)
421 pChangeTrack->Undo(mnEndChangeAction, mnEndChangeAction);
423 EndUndo();
426 void ScUndoSetCell::Redo()
428 BeginRedo();
429 SetValue(maNewValue);
430 pDocShell->PostPaintCell(maPos);
431 SetChangeTrack();
432 EndRedo();
435 void ScUndoSetCell::Repeat( SfxRepeatTarget& /*rTarget*/ )
437 // Makes no sense.
440 bool ScUndoSetCell::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
442 return false;
445 OUString ScUndoSetCell::GetComment() const
447 return ScGlobal::GetRscString(STR_UNDO_ENTERDATA); // "Input"
450 void ScUndoSetCell::SetChangeTrack()
452 ScDocument& rDoc = pDocShell->GetDocument();
453 ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
454 if (pChangeTrack)
456 mnEndChangeAction = pChangeTrack->GetActionMax() + 1;
458 pChangeTrack->AppendContent(maPos, maOldValue);
460 if (mnEndChangeAction > pChangeTrack->GetActionMax())
461 mnEndChangeAction = 0; // Nothing is appended
463 else
464 mnEndChangeAction = 0;
467 void ScUndoSetCell::SetValue( const ScCellValue& rVal )
469 ScDocument& rDoc = pDocShell->GetDocument();
471 switch (rVal.meType)
473 case CELLTYPE_NONE:
474 // empty cell
475 rDoc.SetEmptyCell(maPos);
476 break;
477 case CELLTYPE_VALUE:
478 rDoc.SetValue(maPos, rVal.mfValue);
479 break;
480 case CELLTYPE_STRING:
482 ScSetStringParam aParam;
483 aParam.setTextInput();
484 rDoc.SetString(maPos, rVal.mpString->getString());
486 break;
487 case CELLTYPE_EDIT:
488 rDoc.SetEditText(maPos, rVal.mpEditText->Clone());
489 break;
490 case CELLTYPE_FORMULA:
491 rDoc.SetFormulaCell(maPos, rVal.mpFormula->Clone());
492 break;
493 default:
498 ScUndoPageBreak::ScUndoPageBreak( ScDocShell* pNewDocShell,
499 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
500 bool bNewColumn, bool bNewInsert ) :
501 ScSimpleUndo( pNewDocShell ),
502 nCol( nNewCol ),
503 nRow( nNewRow ),
504 nTab( nNewTab ),
505 bColumn( bNewColumn ),
506 bInsert( bNewInsert )
510 ScUndoPageBreak::~ScUndoPageBreak()
514 OUString ScUndoPageBreak::GetComment() const
516 //"Column break" | "Row break" "insert" | "delete"
517 return OUString ( bColumn ?
518 ( bInsert ?
519 ScGlobal::GetRscString( STR_UNDO_INSCOLBREAK ) :
520 ScGlobal::GetRscString( STR_UNDO_DELCOLBREAK )
522 ( bInsert ?
523 ScGlobal::GetRscString( STR_UNDO_INSROWBREAK ) :
524 ScGlobal::GetRscString( STR_UNDO_DELROWBREAK )
525 ) );
528 void ScUndoPageBreak::DoChange( bool bInsertP ) const
530 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
532 if (pViewShell)
534 pViewShell->SetTabNo( nTab );
535 pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, false, false );
537 if (bInsertP)
538 pViewShell->InsertPageBreak(bColumn, false);
539 else
540 pViewShell->DeletePageBreak(bColumn, false);
542 pDocShell->GetDocument().InvalidatePageBreaks(nTab);
546 void ScUndoPageBreak::Undo()
548 BeginUndo();
549 DoChange(!bInsert);
550 EndUndo();
553 void ScUndoPageBreak::Redo()
555 BeginRedo();
556 DoChange(bInsert);
557 EndRedo();
560 void ScUndoPageBreak::Repeat(SfxRepeatTarget& rTarget)
562 if (rTarget.ISA(ScTabViewTarget))
564 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
566 if (bInsert)
567 rViewShell.InsertPageBreak(bColumn, true);
568 else
569 rViewShell.DeletePageBreak(bColumn, true);
573 bool ScUndoPageBreak::CanRepeat(SfxRepeatTarget& rTarget) const
575 return rTarget.ISA(ScTabViewTarget);
578 ScUndoPrintZoom::ScUndoPrintZoom( ScDocShell* pNewDocShell,
579 SCTAB nT, sal_uInt16 nOS, sal_uInt16 nOP, sal_uInt16 nNS, sal_uInt16 nNP ) :
580 ScSimpleUndo( pNewDocShell ),
581 nTab( nT ),
582 nOldScale( nOS ),
583 nOldPages( nOP ),
584 nNewScale( nNS ),
585 nNewPages( nNP )
589 ScUndoPrintZoom::~ScUndoPrintZoom()
593 OUString ScUndoPrintZoom::GetComment() const
595 return ScGlobal::GetRscString( STR_UNDO_PRINTSCALE );
598 void ScUndoPrintZoom::DoChange( bool bUndo )
600 sal_uInt16 nScale = bUndo ? nOldScale : nNewScale;
601 sal_uInt16 nPages = bUndo ? nOldPages : nNewPages;
603 ScDocument& rDoc = pDocShell->GetDocument();
604 OUString aStyleName = rDoc.GetPageStyle( nTab );
605 ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
606 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
607 OSL_ENSURE( pStyleSheet, "PageStyle not found" );
608 if ( pStyleSheet )
610 SfxItemSet& rSet = pStyleSheet->GetItemSet();
611 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
612 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
614 ScPrintFunc aPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab );
615 aPrintFunc.UpdatePages();
619 void ScUndoPrintZoom::Undo()
621 BeginUndo();
622 DoChange(true);
623 EndUndo();
626 void ScUndoPrintZoom::Redo()
628 BeginRedo();
629 DoChange(false);
630 EndRedo();
633 void ScUndoPrintZoom::Repeat(SfxRepeatTarget& rTarget)
635 if (rTarget.ISA(ScTabViewTarget))
637 ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
638 ScViewData& rViewData = rViewShell.GetViewData();
639 rViewData.GetDocShell()->SetPrintZoom( rViewData.GetTabNo(), nNewScale, nNewPages );
643 bool ScUndoPrintZoom::CanRepeat(SfxRepeatTarget& rTarget) const
645 return rTarget.ISA(ScTabViewTarget);
648 ScUndoThesaurus::ScUndoThesaurus(
649 ScDocShell* pNewDocShell, SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
650 const ScCellValue& rOldText, const ScCellValue& rNewText ) :
651 ScSimpleUndo( pNewDocShell ),
652 nCol( nNewCol ),
653 nRow( nNewRow ),
654 nTab( nNewTab ),
655 maOldText(rOldText),
656 maNewText(rNewText)
658 SetChangeTrack(maOldText);
661 ScUndoThesaurus::~ScUndoThesaurus() {}
663 OUString ScUndoThesaurus::GetComment() const
665 return ScGlobal::GetRscString( STR_UNDO_THESAURUS ); // "Thesaurus"
668 void ScUndoThesaurus::SetChangeTrack( const ScCellValue& rOldCell )
670 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
671 if ( pChangeTrack )
673 nEndChangeAction = pChangeTrack->GetActionMax() + 1;
674 pChangeTrack->AppendContent(ScAddress(nCol, nRow, nTab), rOldCell);
675 if ( nEndChangeAction > pChangeTrack->GetActionMax() )
676 nEndChangeAction = 0; // nothing is appended
678 else
679 nEndChangeAction = 0;
682 void ScUndoThesaurus::DoChange( bool bUndo, const ScCellValue& rText )
684 ScDocument& rDoc = pDocShell->GetDocument();
686 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
687 if (pViewShell)
689 pViewShell->SetTabNo( nTab );
690 pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, false, false );
693 ScAddress aPos(nCol, nRow, nTab);
694 rText.commit(rDoc, aPos);
695 if (!bUndo)
696 SetChangeTrack(maOldText);
698 pDocShell->PostPaintCell( nCol, nRow, nTab );
701 void ScUndoThesaurus::Undo()
703 BeginUndo();
704 DoChange(true, maOldText);
705 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
706 if ( pChangeTrack )
707 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
708 EndUndo();
711 void ScUndoThesaurus::Redo()
713 BeginRedo();
714 DoChange(false, maNewText);
715 EndRedo();
718 void ScUndoThesaurus::Repeat(SfxRepeatTarget& rTarget)
720 if (rTarget.ISA(ScTabViewTarget))
721 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DoThesaurus( true );
724 bool ScUndoThesaurus::CanRepeat(SfxRepeatTarget& rTarget) const
726 return rTarget.ISA(ScTabViewTarget);
729 ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell& rDocShell, const ScAddress& rPos,
730 const ScNoteData& rNoteData, bool bInsert, SdrUndoAction* pDrawUndo ) :
731 ScSimpleUndo( &rDocShell ),
732 maPos( rPos ),
733 mpDrawUndo( pDrawUndo )
735 OSL_ENSURE( rNoteData.mpCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note caption" );
736 (bInsert ? maNewData : maOldData) = rNoteData;
739 ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell& rDocShell, const ScAddress& rPos,
740 const ScNoteData& rOldData, const ScNoteData& rNewData, SdrUndoAction* pDrawUndo ) :
741 ScSimpleUndo( &rDocShell ),
742 maPos( rPos ),
743 maOldData( rOldData ),
744 maNewData( rNewData ),
745 mpDrawUndo( pDrawUndo )
747 OSL_ENSURE( maOldData.mpCaption || maNewData.mpCaption, "ScUndoReplaceNote::ScUndoReplaceNote - missing note captions" );
748 OSL_ENSURE( !maOldData.mxInitData.get() && !maNewData.mxInitData.get(), "ScUndoReplaceNote::ScUndoReplaceNote - unexpected unitialized note" );
751 ScUndoReplaceNote::~ScUndoReplaceNote()
753 DeleteSdrUndoAction( mpDrawUndo );
756 void ScUndoReplaceNote::Undo()
758 BeginUndo();
759 DoSdrUndoAction( mpDrawUndo, &pDocShell->GetDocument() );
760 /* Undo insert -> remove new note.
761 Undo remove -> insert old note.
762 Undo replace -> remove new note, insert old note. */
763 DoRemoveNote( maNewData );
764 DoInsertNote( maOldData );
765 pDocShell->PostPaintCell( maPos );
766 EndUndo();
769 void ScUndoReplaceNote::Redo()
771 BeginRedo();
772 RedoSdrUndoAction( mpDrawUndo );
773 /* Redo insert -> insert new note.
774 Redo remove -> remove old note.
775 Redo replace -> remove old note, insert new note. */
776 DoRemoveNote( maOldData );
777 DoInsertNote( maNewData );
778 pDocShell->PostPaintCell( maPos );
779 EndRedo();
782 void ScUndoReplaceNote::Repeat( SfxRepeatTarget& /*rTarget*/ )
786 bool ScUndoReplaceNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
788 return false;
791 OUString ScUndoReplaceNote::GetComment() const
793 return ScGlobal::GetRscString( maNewData.mpCaption ?
794 (maOldData.mpCaption ? STR_UNDO_EDITNOTE : STR_UNDO_INSERTNOTE) : STR_UNDO_DELETENOTE );
797 void ScUndoReplaceNote::DoInsertNote( const ScNoteData& rNoteData )
799 if( rNoteData.mpCaption )
801 ScDocument& rDoc = pDocShell->GetDocument();
802 OSL_ENSURE( !rDoc.GetNote(maPos), "ScUndoReplaceNote::DoInsertNote - unexpected cell note" );
803 ScPostIt* pNote = new ScPostIt( rDoc, maPos, rNoteData, false );
804 rDoc.SetNote( maPos, pNote );
808 void ScUndoReplaceNote::DoRemoveNote( const ScNoteData& rNoteData )
810 if( rNoteData.mpCaption )
812 ScDocument& rDoc = pDocShell->GetDocument();
813 OSL_ENSURE( rDoc.GetNote(maPos), "ScUndoReplaceNote::DoRemoveNote - missing cell note" );
814 if( ScPostIt* pNote = rDoc.ReleaseNote( maPos ) )
816 /* Forget pointer to caption object to suppress removing the
817 caption object from the drawing layer while deleting pNote
818 (removing the caption is done by a drawing undo action). */
819 pNote->ForgetCaption();
820 delete pNote;
825 ScUndoShowHideNote::ScUndoShowHideNote( ScDocShell& rDocShell, const ScAddress& rPos, bool bShow ) :
826 ScSimpleUndo( &rDocShell ),
827 maPos( rPos ),
828 mbShown( bShow )
832 ScUndoShowHideNote::~ScUndoShowHideNote()
836 void ScUndoShowHideNote::Undo()
838 BeginUndo();
839 if( ScPostIt* pNote = pDocShell->GetDocument().GetNote(maPos) )
840 pNote->ShowCaption( maPos, !mbShown );
841 EndUndo();
844 void ScUndoShowHideNote::Redo()
846 BeginRedo();
847 if( ScPostIt* pNote = pDocShell->GetDocument().GetNote(maPos) )
848 pNote->ShowCaption( maPos, mbShown );
849 EndRedo();
852 void ScUndoShowHideNote::Repeat( SfxRepeatTarget& /*rTarget*/ )
856 bool ScUndoShowHideNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
858 return false;
861 OUString ScUndoShowHideNote::GetComment() const
863 return ScGlobal::GetRscString( mbShown ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
866 ScUndoDetective::ScUndoDetective( ScDocShell* pNewDocShell,
867 SdrUndoAction* pDraw, const ScDetOpData* pOperation,
868 ScDetOpList* pUndoList ) :
869 ScSimpleUndo( pNewDocShell ),
870 pOldList ( pUndoList ),
871 nAction ( 0 ),
872 pDrawUndo ( pDraw )
874 bIsDelete = ( pOperation == NULL );
875 if (!bIsDelete)
877 nAction = (sal_uInt16) pOperation->GetOperation();
878 aPos = pOperation->GetPos();
882 ScUndoDetective::~ScUndoDetective()
884 DeleteSdrUndoAction( pDrawUndo );
885 delete pOldList;
888 OUString ScUndoDetective::GetComment() const
890 sal_uInt16 nId = STR_UNDO_DETDELALL;
891 if ( !bIsDelete )
892 switch ( (ScDetOpType) nAction )
894 case SCDETOP_ADDSUCC: nId = STR_UNDO_DETADDSUCC; break;
895 case SCDETOP_DELSUCC: nId = STR_UNDO_DETDELSUCC; break;
896 case SCDETOP_ADDPRED: nId = STR_UNDO_DETADDPRED; break;
897 case SCDETOP_DELPRED: nId = STR_UNDO_DETDELPRED; break;
898 case SCDETOP_ADDERROR: nId = STR_UNDO_DETADDERROR; break;
901 return ScGlobal::GetRscString( nId );
904 void ScUndoDetective::Undo()
906 BeginUndo();
908 ScDocument& rDoc = pDocShell->GetDocument();
909 DoSdrUndoAction(pDrawUndo, &rDoc);
911 if (bIsDelete)
913 if ( pOldList )
914 rDoc.SetDetOpList( new ScDetOpList(*pOldList) );
916 else
918 // Remove entry from list
920 ScDetOpList* pList = rDoc.GetDetOpList();
921 if (pList && pList->Count())
923 ScDetOpDataVector& rVec = pList->GetDataVector();
924 ScDetOpDataVector::iterator it = rVec.begin() + rVec.size() - 1;
925 if ( it->GetOperation() == (ScDetOpType) nAction && it->GetPos() == aPos )
926 rVec.erase( it);
927 else
929 OSL_FAIL("Detective entry could not be found in list");
934 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
935 if (pViewShell)
936 pViewShell->RecalcPPT(); //! use broadcast instead?
938 EndUndo();
941 void ScUndoDetective::Redo()
943 BeginRedo();
945 RedoSdrUndoAction(pDrawUndo);
947 ScDocument& rDoc = pDocShell->GetDocument();
949 if (bIsDelete)
950 rDoc.ClearDetectiveOperations();
951 else
952 rDoc.AddDetectiveOperation( ScDetOpData( aPos, (ScDetOpType) nAction ) );
954 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
955 if (pViewShell)
956 pViewShell->RecalcPPT(); //! use broadcast instead?
958 EndRedo();
961 void ScUndoDetective::Repeat(SfxRepeatTarget& /* rTarget */)
963 // makes no sense
966 bool ScUndoDetective::CanRepeat(SfxRepeatTarget& /* rTarget */) const
968 return false;
971 ScUndoRangeNames::ScUndoRangeNames( ScDocShell* pNewDocShell,
972 ScRangeName* pOld, ScRangeName* pNew, SCTAB nTab ) :
973 ScSimpleUndo( pNewDocShell ),
974 pOldRanges ( pOld ),
975 pNewRanges ( pNew ),
976 mnTab ( nTab )
980 ScUndoRangeNames::~ScUndoRangeNames()
982 delete pOldRanges;
983 delete pNewRanges;
986 OUString ScUndoRangeNames::GetComment() const
988 return ScGlobal::GetRscString( STR_UNDO_RANGENAMES );
991 void ScUndoRangeNames::DoChange( bool bUndo )
993 ScDocument& rDoc = pDocShell->GetDocument();
994 rDoc.PreprocessRangeNameUpdate();
996 if ( bUndo )
998 if (mnTab >= 0)
999 rDoc.SetRangeName( mnTab, new ScRangeName( *pOldRanges ) );
1000 else
1001 rDoc.SetRangeName( new ScRangeName( *pOldRanges ) );
1003 else
1005 if (mnTab >= 0)
1006 rDoc.SetRangeName( mnTab, new ScRangeName( *pNewRanges ) );
1007 else
1008 rDoc.SetRangeName( new ScRangeName( *pNewRanges ) );
1011 rDoc.CompileHybridFormula();
1013 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
1016 void ScUndoRangeNames::Undo()
1018 BeginUndo();
1019 DoChange( true );
1020 EndUndo();
1023 void ScUndoRangeNames::Redo()
1025 BeginRedo();
1026 DoChange( false );
1027 EndRedo();
1030 void ScUndoRangeNames::Repeat(SfxRepeatTarget& /* rTarget */)
1032 // makes no sense
1035 bool ScUndoRangeNames::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1037 return false;
1040 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */