1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
33 #include "tabvwsh.hxx"
34 #include "globstr.hrc"
36 #include "formulacell.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"
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
),
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();
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
;
145 nFlags
|= SC_PF_LINES
;
147 nFlags
|= SC_PF_WHOLEROWS
;
148 pDocShell
->PostPaint( nCol
,nRow
,nTab
, nCol
,nRow
,nTab
, PAINT_GRID
, nFlags
);
151 void ScUndoCursorAttr::Undo()
154 DoChange(pOldPattern
, pOldEditData
);
158 // if automatic formatting is reversed, then
159 // automatic formatting should also not continue to be done
161 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
163 pViewShell
->ForgetFormatArea();
169 void ScUndoCursorAttr::Redo()
172 DoChange(pNewPattern
, pNewEditData
);
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
),
195 mnEndChangeAction(0),
198 maOldValues
.swap(rOldValues
);
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();
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();
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
245 mnEndChangeAction
= 0;
248 void ScUndoEnterData::Undo()
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
));
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
);
282 HelperNotifyChanges::NotifyIfChangesListeners(*pDocShell
, maPos
, maOldValues
);
285 void ScUndoEnterData::Redo()
289 ScDocument
& rDoc
= pDocShell
->GetDocument();
290 for (size_t i
= 0, n
= maOldValues
.size(); i
< n
; ++i
)
292 SCTAB nTab
= maOldValues
[i
].mnTab
;
295 ScAddress aPos
= maPos
;
297 // edit text wil be cloned.
298 rDoc
.SetEditText(aPos
, *mpNewEditData
, NULL
);
301 rDoc
.SetString(maPos
.Col(), maPos
.Row(), nTab
, maNewString
);
303 pDocShell
->PostPaintCell(maPos
.Col(), maPos
.Row(), nTab
);
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
),
333 maOldCell(rUndoCell
),
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();
354 nEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
355 pChangeTrack
->AppendContent(aPos
, maOldCell
);
356 if ( nEndChangeAction
> pChangeTrack
->GetActionMax() )
357 nEndChangeAction
= 0; // nothing is appended
360 nEndChangeAction
= 0;
363 void ScUndoEnterValue::Undo()
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();
376 pChangeTrack
->Undo( nEndChangeAction
, nEndChangeAction
);
381 void ScUndoEnterValue::Redo()
385 ScDocument
& rDoc
= pDocShell
->GetDocument();
386 rDoc
.SetValue( aPos
.Col(), aPos
.Row(), aPos
.Tab(), nValue
);
387 pDocShell
->PostPaintCell( aPos
);
394 void ScUndoEnterValue::Repeat(SfxRepeatTarget
& /* rTarget */)
399 bool ScUndoEnterValue::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
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)
410 ScUndoSetCell::~ScUndoSetCell() {}
412 void ScUndoSetCell::Undo()
415 SetValue(maOldValue
);
416 pDocShell
->PostPaintCell(maPos
);
418 ScDocument
& rDoc
= pDocShell
->GetDocument();
419 ScChangeTrack
* pChangeTrack
= rDoc
.GetChangeTrack();
421 pChangeTrack
->Undo(mnEndChangeAction
, mnEndChangeAction
);
426 void ScUndoSetCell::Redo()
429 SetValue(maNewValue
);
430 pDocShell
->PostPaintCell(maPos
);
435 void ScUndoSetCell::Repeat( SfxRepeatTarget
& /*rTarget*/ )
440 bool ScUndoSetCell::CanRepeat( SfxRepeatTarget
& /*rTarget*/ ) const
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();
456 mnEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
458 pChangeTrack
->AppendContent(maPos
, maOldValue
);
460 if (mnEndChangeAction
> pChangeTrack
->GetActionMax())
461 mnEndChangeAction
= 0; // Nothing is appended
464 mnEndChangeAction
= 0;
467 void ScUndoSetCell::SetValue( const ScCellValue
& rVal
)
469 ScDocument
& rDoc
= pDocShell
->GetDocument();
475 rDoc
.SetEmptyCell(maPos
);
478 rDoc
.SetValue(maPos
, rVal
.mfValue
);
480 case CELLTYPE_STRING
:
482 ScSetStringParam aParam
;
483 aParam
.setTextInput();
484 rDoc
.SetString(maPos
, rVal
.mpString
->getString());
488 rDoc
.SetEditText(maPos
, rVal
.mpEditText
->Clone());
490 case CELLTYPE_FORMULA
:
491 rDoc
.SetFormulaCell(maPos
, rVal
.mpFormula
->Clone());
498 ScUndoPageBreak::ScUndoPageBreak( ScDocShell
* pNewDocShell
,
499 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
500 bool bNewColumn
, bool bNewInsert
) :
501 ScSimpleUndo( pNewDocShell
),
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
?
519 ScGlobal::GetRscString( STR_UNDO_INSCOLBREAK
) :
520 ScGlobal::GetRscString( STR_UNDO_DELCOLBREAK
)
523 ScGlobal::GetRscString( STR_UNDO_INSROWBREAK
) :
524 ScGlobal::GetRscString( STR_UNDO_DELROWBREAK
)
528 void ScUndoPageBreak::DoChange( bool bInsertP
) const
530 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
534 pViewShell
->SetTabNo( nTab
);
535 pViewShell
->MoveCursorAbs( nCol
, nRow
, SC_FOLLOW_JUMP
, false, false );
538 pViewShell
->InsertPageBreak(bColumn
, false);
540 pViewShell
->DeletePageBreak(bColumn
, false);
542 pDocShell
->GetDocument().InvalidatePageBreaks(nTab
);
546 void ScUndoPageBreak::Undo()
553 void ScUndoPageBreak::Redo()
560 void ScUndoPageBreak::Repeat(SfxRepeatTarget
& rTarget
)
562 if (rTarget
.ISA(ScTabViewTarget
))
564 ScTabViewShell
& rViewShell
= *static_cast<ScTabViewTarget
&>(rTarget
).GetViewShell();
567 rViewShell
.InsertPageBreak(bColumn
, true);
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
),
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" );
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()
626 void ScUndoPrintZoom::Redo()
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
),
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();
673 nEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
674 pChangeTrack
->AppendContent(ScAddress(nCol
, nRow
, nTab
), rOldCell
);
675 if ( nEndChangeAction
> pChangeTrack
->GetActionMax() )
676 nEndChangeAction
= 0; // nothing is appended
679 nEndChangeAction
= 0;
682 void ScUndoThesaurus::DoChange( bool bUndo
, const ScCellValue
& rText
)
684 ScDocument
& rDoc
= pDocShell
->GetDocument();
686 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
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
);
696 SetChangeTrack(maOldText
);
698 pDocShell
->PostPaintCell( nCol
, nRow
, nTab
);
701 void ScUndoThesaurus::Undo()
704 DoChange(true, maOldText
);
705 ScChangeTrack
* pChangeTrack
= pDocShell
->GetDocument().GetChangeTrack();
707 pChangeTrack
->Undo( nEndChangeAction
, nEndChangeAction
);
711 void ScUndoThesaurus::Redo()
714 DoChange(false, maNewText
);
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
),
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
),
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()
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
);
769 void ScUndoReplaceNote::Redo()
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
);
782 void ScUndoReplaceNote::Repeat( SfxRepeatTarget
& /*rTarget*/ )
786 bool ScUndoReplaceNote::CanRepeat( SfxRepeatTarget
& /*rTarget*/ ) const
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();
825 ScUndoShowHideNote::ScUndoShowHideNote( ScDocShell
& rDocShell
, const ScAddress
& rPos
, bool bShow
) :
826 ScSimpleUndo( &rDocShell
),
832 ScUndoShowHideNote::~ScUndoShowHideNote()
836 void ScUndoShowHideNote::Undo()
839 if( ScPostIt
* pNote
= pDocShell
->GetDocument().GetNote(maPos
) )
840 pNote
->ShowCaption( maPos
, !mbShown
);
844 void ScUndoShowHideNote::Redo()
847 if( ScPostIt
* pNote
= pDocShell
->GetDocument().GetNote(maPos
) )
848 pNote
->ShowCaption( maPos
, mbShown
);
852 void ScUndoShowHideNote::Repeat( SfxRepeatTarget
& /*rTarget*/ )
856 bool ScUndoShowHideNote::CanRepeat( SfxRepeatTarget
& /*rTarget*/ ) const
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
),
874 bIsDelete
= ( pOperation
== NULL
);
877 nAction
= (sal_uInt16
) pOperation
->GetOperation();
878 aPos
= pOperation
->GetPos();
882 ScUndoDetective::~ScUndoDetective()
884 DeleteSdrUndoAction( pDrawUndo
);
888 OUString
ScUndoDetective::GetComment() const
890 sal_uInt16 nId
= STR_UNDO_DETDELALL
;
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()
908 ScDocument
& rDoc
= pDocShell
->GetDocument();
909 DoSdrUndoAction(pDrawUndo
, &rDoc
);
914 rDoc
.SetDetOpList( new ScDetOpList(*pOldList
) );
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
)
929 OSL_FAIL("Detective entry could not be found in list");
934 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
936 pViewShell
->RecalcPPT(); //! use broadcast instead?
941 void ScUndoDetective::Redo()
945 RedoSdrUndoAction(pDrawUndo
);
947 ScDocument
& rDoc
= pDocShell
->GetDocument();
950 rDoc
.ClearDetectiveOperations();
952 rDoc
.AddDetectiveOperation( ScDetOpData( aPos
, (ScDetOpType
) nAction
) );
954 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
956 pViewShell
->RecalcPPT(); //! use broadcast instead?
961 void ScUndoDetective::Repeat(SfxRepeatTarget
& /* rTarget */)
966 bool ScUndoDetective::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
971 ScUndoRangeNames::ScUndoRangeNames( ScDocShell
* pNewDocShell
,
972 ScRangeName
* pOld
, ScRangeName
* pNew
, SCTAB nTab
) :
973 ScSimpleUndo( pNewDocShell
),
980 ScUndoRangeNames::~ScUndoRangeNames()
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();
999 rDoc
.SetRangeName( mnTab
, new ScRangeName( *pOldRanges
) );
1001 rDoc
.SetRangeName( new ScRangeName( *pOldRanges
) );
1006 rDoc
.SetRangeName( mnTab
, new ScRangeName( *pNewRanges
) );
1008 rDoc
.SetRangeName( new ScRangeName( *pNewRanges
) );
1011 rDoc
.CompileHybridFormula();
1013 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED
) );
1016 void ScUndoRangeNames::Undo()
1023 void ScUndoRangeNames::Redo()
1030 void ScUndoRangeNames::Repeat(SfxRepeatTarget
& /* rTarget */)
1035 bool ScUndoRangeNames::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
1040 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */