1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undocell.cxx,v $
10 * $Revision: 1.15.128.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "scitems.hxx"
35 #include <svx/eeitem.hxx>
37 #include <svx/editobj.hxx>
38 #include <svtools/zforlist.hxx>
39 #include <sfx2/app.hxx>
41 #include "undocell.hxx"
42 #include "document.hxx"
43 #include "docpool.hxx"
44 #include "patattr.hxx"
46 #include "tabvwsh.hxx"
47 #include "globstr.hrc"
51 #include "undoolk.hxx"
52 #include "detdata.hxx"
53 #include "stlpool.hxx"
54 #include "printfun.hxx"
55 #include "rangenam.hxx"
56 #include "chgtrack.hxx"
60 using ::boost::shared_ptr
;
62 // STATIC DATA -----------------------------------------------------------
64 TYPEINIT1(ScUndoCursorAttr
, ScSimpleUndo
);
65 TYPEINIT1(ScUndoEnterData
, ScSimpleUndo
);
66 TYPEINIT1(ScUndoEnterValue
, ScSimpleUndo
);
67 TYPEINIT1(ScUndoPutCell
, ScSimpleUndo
);
68 TYPEINIT1(ScUndoPageBreak
, ScSimpleUndo
);
69 TYPEINIT1(ScUndoPrintZoom
, ScSimpleUndo
);
70 TYPEINIT1(ScUndoThesaurus
, ScSimpleUndo
);
71 TYPEINIT1(ScUndoReplaceNote
, ScSimpleUndo
);
72 TYPEINIT1(ScUndoShowHideNote
, ScSimpleUndo
);
73 TYPEINIT1(ScUndoDetective
, ScSimpleUndo
);
74 TYPEINIT1(ScUndoRangeNames
, ScSimpleUndo
);
77 // -----------------------------------------------------------------------
79 // Attribute auf Cursor anwenden
82 ScUndoCursorAttr::ScUndoCursorAttr( ScDocShell
* pNewDocShell
,
83 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
84 const ScPatternAttr
* pOldPat
, const ScPatternAttr
* pNewPat
,
85 const ScPatternAttr
* pApplyPat
, BOOL bAutomatic
) :
86 ScSimpleUndo( pNewDocShell
),
90 pOldEditData( static_cast<EditTextObject
*>(NULL
) ),
91 pNewEditData( static_cast<EditTextObject
*>(NULL
) ),
92 bIsAutomatic( bAutomatic
)
94 ScDocumentPool
* pPool
= pDocShell
->GetDocument()->GetPool();
95 pNewPattern
= (ScPatternAttr
*) &pPool
->Put( *pNewPat
);
96 pOldPattern
= (ScPatternAttr
*) &pPool
->Put( *pOldPat
);
97 pApplyPattern
= (ScPatternAttr
*) &pPool
->Put( *pApplyPat
);
100 __EXPORT
ScUndoCursorAttr::~ScUndoCursorAttr()
102 ScDocumentPool
* pPool
= pDocShell
->GetDocument()->GetPool();
103 pPool
->Remove(*pNewPattern
);
104 pPool
->Remove(*pOldPattern
);
105 pPool
->Remove(*pApplyPattern
);
108 String __EXPORT
ScUndoCursorAttr::GetComment() const
110 //! eigener Text fuer automatische Attributierung
112 USHORT nId
= STR_UNDO_CURSORATTR
; // "Attribute"
113 return ScGlobal::GetRscString( nId
);
116 void ScUndoCursorAttr::SetEditData( EditTextObject
* pOld
, EditTextObject
* pNew
)
118 pOldEditData
.reset(pOld
);
119 pNewEditData
.reset(pNew
);
122 void ScUndoCursorAttr::DoChange( const ScPatternAttr
* pWhichPattern
, const shared_ptr
<EditTextObject
>& pEditData
) const
124 ScDocument
* pDoc
= pDocShell
->GetDocument();
125 pDoc
->SetPattern( nCol
, nRow
, nTab
, *pWhichPattern
, TRUE
);
128 pDoc
->GetCell(nCol
, nRow
, nTab
, pCell
);
129 if (pCell
&& pCell
->GetCellType() == CELLTYPE_EDIT
&& pEditData
.get())
130 static_cast<ScEditCell
*>(pCell
)->SetData(pEditData
.get(), NULL
);
132 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
135 pViewShell
->SetTabNo( nTab
);
136 pViewShell
->MoveCursorAbs( nCol
, nRow
, SC_FOLLOW_JUMP
, FALSE
, FALSE
);
137 pViewShell
->AdjustBlockHeight();
140 const SfxItemSet
& rApplySet
= pApplyPattern
->GetItemSet();
141 BOOL bPaintExt
= ( rApplySet
.GetItemState( ATTR_SHADOW
, TRUE
) != SFX_ITEM_DEFAULT
||
142 rApplySet
.GetItemState( ATTR_CONDITIONAL
, TRUE
) != SFX_ITEM_DEFAULT
);
143 BOOL bPaintRows
= ( rApplySet
.GetItemState( ATTR_HOR_JUSTIFY
, TRUE
) != SFX_ITEM_DEFAULT
);
145 USHORT nFlags
= SC_PF_TESTMERGE
;
147 nFlags
|= SC_PF_LINES
;
149 nFlags
|= SC_PF_WHOLEROWS
;
150 pDocShell
->PostPaint( nCol
,nRow
,nTab
, nCol
,nRow
,nTab
, PAINT_GRID
, nFlags
);
153 void __EXPORT
ScUndoCursorAttr::Undo()
156 DoChange(pOldPattern
, pOldEditData
);
160 // wenn automatische Formatierung rueckgaengig gemacht wird,
161 // soll auch nicht weiter automatisch formatiert werden:
163 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
165 pViewShell
->ForgetFormatArea();
171 void __EXPORT
ScUndoCursorAttr::Redo()
174 DoChange(pNewPattern
, pNewEditData
);
178 void __EXPORT
ScUndoCursorAttr::Repeat(SfxRepeatTarget
& rTarget
)
180 if (rTarget
.ISA(ScTabViewTarget
))
181 ((ScTabViewTarget
&)rTarget
).GetViewShell()->ApplySelectionPattern( *pApplyPattern
);
184 BOOL __EXPORT
ScUndoCursorAttr::CanRepeat(SfxRepeatTarget
& rTarget
) const
186 return (rTarget
.ISA(ScTabViewTarget
));
190 // -----------------------------------------------------------------------
195 ScUndoEnterData::ScUndoEnterData( ScDocShell
* pNewDocShell
,
196 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
197 SCTAB nNewCount
, SCTAB
* pNewTabs
, ScBaseCell
** ppOldData
,
198 BOOL
* pHasForm
, ULONG
* pOldForm
,
199 const String
& rNewStr
, EditTextObject
* pObj
) :
200 ScSimpleUndo( pNewDocShell
),
201 aNewString( rNewStr
),
203 ppOldCells( ppOldData
),
204 pHasFormat( pHasForm
),
205 pOldFormats( pOldForm
),
206 pNewEditData( pObj
),
215 __EXPORT
ScUndoEnterData::~ScUndoEnterData()
217 for (USHORT i
=0; i
<nCount
; i
++)
219 ppOldCells
[i
]->Delete();
223 delete[] pOldFormats
;
229 String __EXPORT
ScUndoEnterData::GetComment() const
231 return ScGlobal::GetRscString( STR_UNDO_ENTERDATA
); // "Eingabe"
234 void ScUndoEnterData::DoChange() const
236 // Zeilenhoehe anpassen
237 //! nur wenn noetig (alte oder neue EditZelle, oder Attribute) ??
238 for (USHORT i
=0; i
<nCount
; i
++)
239 pDocShell
->AdjustRowHeight( nRow
, nRow
, pTabs
[i
] );
241 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
244 pViewShell
->SetTabNo( nTab
);
245 pViewShell
->MoveCursorAbs( nCol
, nRow
, SC_FOLLOW_JUMP
, FALSE
, FALSE
);
248 pDocShell
->PostDataChanged();
251 void ScUndoEnterData::SetChangeTrack()
253 ScChangeTrack
* pChangeTrack
= pDocShell
->GetDocument()->GetChangeTrack();
256 nEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
257 ScAddress
aPos( nCol
, nRow
, nTab
);
258 for (USHORT i
=0; i
<nCount
; i
++)
260 aPos
.SetTab( pTabs
[i
] );
262 if ( pHasFormat
&& pOldFormats
)
265 nFormat
= pOldFormats
[i
];
267 pChangeTrack
->AppendContent( aPos
, ppOldCells
[i
], nFormat
);
269 if ( nEndChangeAction
> pChangeTrack
->GetActionMax() )
270 nEndChangeAction
= 0; // nichts appended
273 nEndChangeAction
= 0;
276 void __EXPORT
ScUndoEnterData::Undo()
280 ScDocument
* pDoc
= pDocShell
->GetDocument();
281 for (USHORT i
=0; i
<nCount
; i
++)
283 ScBaseCell
* pNewCell
= ppOldCells
[i
] ? ppOldCells
[i
]->CloneWithoutNote( *pDoc
, SC_CLONECELL_STARTLISTENING
) : 0;
284 pDoc
->PutCell( nCol
, nRow
, pTabs
[i
], pNewCell
);
286 if (pHasFormat
&& pOldFormats
)
289 pDoc
->ApplyAttr( nCol
, nRow
, pTabs
[i
],
290 SfxUInt32Item( ATTR_VALUE_FORMAT
, pOldFormats
[i
] ) );
293 ScPatternAttr
aPattern( *pDoc
->GetPattern( nCol
, nRow
, pTabs
[i
] ) );
294 aPattern
.GetItemSet().ClearItem( ATTR_VALUE_FORMAT
);
295 pDoc
->SetPattern( nCol
, nRow
, pTabs
[i
], aPattern
, TRUE
);
298 pDocShell
->PostPaintCell( nCol
, nRow
, pTabs
[i
] );
301 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
302 if ( pChangeTrack
&& nEndChangeAction
>= sal::static_int_cast
<ULONG
>(nCount
) )
303 pChangeTrack
->Undo( nEndChangeAction
- nCount
+ 1, nEndChangeAction
);
308 // #i97876# Spreadsheet data changes are not notified
309 ScModelObj
* pModelObj
= ScModelObj::getImplementation( pDocShell
->GetModel() );
310 if ( pModelObj
&& pModelObj
->HasChangesListeners() )
312 ScRangeList aChangeRanges
;
313 for ( USHORT i
= 0; i
< nCount
; ++i
)
315 aChangeRanges
.Append( ScRange( nCol
, nRow
, pTabs
[i
] ) );
317 pModelObj
->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges
);
321 void __EXPORT
ScUndoEnterData::Redo()
325 ScDocument
* pDoc
= pDocShell
->GetDocument();
326 for (USHORT i
=0; i
<nCount
; i
++)
329 pDoc
->PutCell( nCol
, nRow
, pTabs
[i
], new ScEditCell( pNewEditData
,
332 pDoc
->SetString( nCol
, nRow
, pTabs
[i
], aNewString
);
333 pDocShell
->PostPaintCell( nCol
, nRow
, pTabs
[i
] );
341 // #i97876# Spreadsheet data changes are not notified
342 ScModelObj
* pModelObj
= ScModelObj::getImplementation( pDocShell
->GetModel() );
343 if ( pModelObj
&& pModelObj
->HasChangesListeners() )
345 ScRangeList aChangeRanges
;
346 for ( USHORT i
= 0; i
< nCount
; ++i
)
348 aChangeRanges
.Append( ScRange( nCol
, nRow
, pTabs
[i
] ) );
350 pModelObj
->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges
);
354 void __EXPORT
ScUndoEnterData::Repeat(SfxRepeatTarget
& rTarget
)
356 if (rTarget
.ISA(ScTabViewTarget
))
358 String aTemp
= aNewString
;
359 ((ScTabViewTarget
&)rTarget
).GetViewShell()->EnterDataAtCursor( aTemp
);
363 BOOL __EXPORT
ScUndoEnterData::CanRepeat(SfxRepeatTarget
& rTarget
) const
365 return (rTarget
.ISA(ScTabViewTarget
));
369 // -----------------------------------------------------------------------
374 ScUndoEnterValue::ScUndoEnterValue( ScDocShell
* pNewDocShell
, const ScAddress
& rNewPos
,
375 ScBaseCell
* pUndoCell
, double nVal
, BOOL bHeight
) :
376 ScSimpleUndo( pNewDocShell
),
378 pOldCell ( pUndoCell
),
380 bNeedHeight ( bHeight
)
385 __EXPORT
ScUndoEnterValue::~ScUndoEnterValue()
391 String __EXPORT
ScUndoEnterValue::GetComment() const
393 return ScGlobal::GetRscString( STR_UNDO_ENTERDATA
); // "Eingabe"
396 void ScUndoEnterValue::SetChangeTrack()
398 ScDocument
* pDoc
= pDocShell
->GetDocument();
399 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
402 nEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
403 pChangeTrack
->AppendContent( aPos
, pOldCell
);
404 if ( nEndChangeAction
> pChangeTrack
->GetActionMax() )
405 nEndChangeAction
= 0; // nichts appended
408 nEndChangeAction
= 0;
411 void __EXPORT
ScUndoEnterValue::Undo()
415 ScDocument
* pDoc
= pDocShell
->GetDocument();
416 ScBaseCell
* pNewCell
= pOldCell
? pOldCell
->CloneWithoutNote( *pDoc
, SC_CLONECELL_STARTLISTENING
) : 0;
418 pDoc
->PutCell( aPos
, pNewCell
);
420 pDocShell
->PostPaintCell( aPos
);
422 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
424 pChangeTrack
->Undo( nEndChangeAction
, nEndChangeAction
);
429 void __EXPORT
ScUndoEnterValue::Redo()
433 ScDocument
* pDoc
= pDocShell
->GetDocument();
434 pDoc
->SetValue( aPos
.Col(), aPos
.Row(), aPos
.Tab(), nValue
);
435 pDocShell
->PostPaintCell( aPos
);
442 void __EXPORT
ScUndoEnterValue::Repeat(SfxRepeatTarget
& /* rTarget */)
447 BOOL __EXPORT
ScUndoEnterValue::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
453 // -----------------------------------------------------------------------
455 // Beliebige Zelle eingeben
458 ScUndoPutCell::ScUndoPutCell( ScDocShell
* pNewDocShell
, const ScAddress
& rNewPos
,
459 ScBaseCell
* pUndoCell
, ScBaseCell
* pRedoCell
, BOOL bHeight
) :
460 ScSimpleUndo( pNewDocShell
),
462 pOldCell ( pUndoCell
),
463 pEnteredCell( pRedoCell
),
464 bNeedHeight ( bHeight
)
469 __EXPORT
ScUndoPutCell::~ScUndoPutCell()
474 pEnteredCell
->Delete();
477 String __EXPORT
ScUndoPutCell::GetComment() const
479 return ScGlobal::GetRscString( STR_UNDO_ENTERDATA
); // "Eingabe"
482 void ScUndoPutCell::SetChangeTrack()
484 ScDocument
* pDoc
= pDocShell
->GetDocument();
485 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
488 nEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
489 pChangeTrack
->AppendContent( aPos
, pOldCell
);
490 if ( nEndChangeAction
> pChangeTrack
->GetActionMax() )
491 nEndChangeAction
= 0; // nichts appended
494 nEndChangeAction
= 0;
497 void __EXPORT
ScUndoPutCell::Undo()
501 ScDocument
* pDoc
= pDocShell
->GetDocument();
502 ScBaseCell
* pNewCell
= pOldCell
? pOldCell
->CloneWithoutNote( *pDoc
, aPos
, SC_CLONECELL_STARTLISTENING
) : 0;
504 pDoc
->PutCell( aPos
.Col(), aPos
.Row(), aPos
.Tab(), pNewCell
);
506 pDocShell
->PostPaintCell( aPos
);
508 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
510 pChangeTrack
->Undo( nEndChangeAction
, nEndChangeAction
);
515 void __EXPORT
ScUndoPutCell::Redo()
519 ScDocument
* pDoc
= pDocShell
->GetDocument();
520 ScBaseCell
* pNewCell
= pEnteredCell
? pEnteredCell
->CloneWithoutNote( *pDoc
, aPos
, SC_CLONECELL_STARTLISTENING
) : 0;
522 pDoc
->PutCell( aPos
.Col(), aPos
.Row(), aPos
.Tab(), pNewCell
);
524 pDocShell
->PostPaintCell( aPos
);
531 void __EXPORT
ScUndoPutCell::Repeat(SfxRepeatTarget
& /* rTarget */)
536 BOOL __EXPORT
ScUndoPutCell::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
542 // -----------------------------------------------------------------------
547 ScUndoPageBreak::ScUndoPageBreak( ScDocShell
* pNewDocShell
,
548 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
549 BOOL bNewColumn
, BOOL bNewInsert
) :
550 ScSimpleUndo( pNewDocShell
),
554 bColumn( bNewColumn
),
555 bInsert( bNewInsert
)
559 __EXPORT
ScUndoPageBreak::~ScUndoPageBreak()
563 String __EXPORT
ScUndoPageBreak::GetComment() const
565 //"Spaltenumbruch" | "Zeilenumbruch" "einfuegen" | "loeschen"
566 return String ( bColumn
?
568 ScGlobal::GetRscString( STR_UNDO_INSCOLBREAK
) :
569 ScGlobal::GetRscString( STR_UNDO_DELCOLBREAK
)
572 ScGlobal::GetRscString( STR_UNDO_INSROWBREAK
) :
573 ScGlobal::GetRscString( STR_UNDO_DELROWBREAK
)
577 void ScUndoPageBreak::DoChange( BOOL bInsertP
) const
579 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
583 pViewShell
->SetTabNo( nTab
);
584 pViewShell
->MoveCursorAbs( nCol
, nRow
, SC_FOLLOW_JUMP
, FALSE
, FALSE
);
587 pViewShell
->InsertPageBreak(bColumn
, FALSE
);
589 pViewShell
->DeletePageBreak(bColumn
, FALSE
);
591 pDocShell
->GetDocument()->InvalidatePageBreaks(nTab
);
595 void __EXPORT
ScUndoPageBreak::Undo()
602 void __EXPORT
ScUndoPageBreak::Redo()
609 void __EXPORT
ScUndoPageBreak::Repeat(SfxRepeatTarget
& rTarget
)
611 if (rTarget
.ISA(ScTabViewTarget
))
613 ScTabViewShell
& rViewShell
= *((ScTabViewTarget
&)rTarget
).GetViewShell();
616 rViewShell
.InsertPageBreak(bColumn
, TRUE
);
618 rViewShell
.DeletePageBreak(bColumn
, TRUE
);
622 BOOL __EXPORT
ScUndoPageBreak::CanRepeat(SfxRepeatTarget
& rTarget
) const
624 return (rTarget
.ISA(ScTabViewTarget
));
627 // -----------------------------------------------------------------------
632 ScUndoPrintZoom::ScUndoPrintZoom( ScDocShell
* pNewDocShell
,
633 SCTAB nT
, USHORT nOS
, USHORT nOP
, USHORT nNS
, USHORT nNP
) :
634 ScSimpleUndo( pNewDocShell
),
643 __EXPORT
ScUndoPrintZoom::~ScUndoPrintZoom()
647 String __EXPORT
ScUndoPrintZoom::GetComment() const
649 return ScGlobal::GetRscString( STR_UNDO_PRINTSCALE
);
652 void ScUndoPrintZoom::DoChange( BOOL bUndo
)
654 USHORT nScale
= bUndo
? nOldScale
: nNewScale
;
655 USHORT nPages
= bUndo
? nOldPages
: nNewPages
;
657 ScDocument
* pDoc
= pDocShell
->GetDocument();
658 String aStyleName
= pDoc
->GetPageStyle( nTab
);
659 ScStyleSheetPool
* pStylePool
= pDoc
->GetStyleSheetPool();
660 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aStyleName
, SFX_STYLE_FAMILY_PAGE
);
661 DBG_ASSERT( pStyleSheet
, "PageStyle not found" );
664 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
665 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALE
, nScale
) );
666 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES
, nPages
) );
668 ScPrintFunc
aPrintFunc( pDocShell
, pDocShell
->GetPrinter(), nTab
);
669 aPrintFunc
.UpdatePages();
673 void __EXPORT
ScUndoPrintZoom::Undo()
680 void __EXPORT
ScUndoPrintZoom::Redo()
687 void __EXPORT
ScUndoPrintZoom::Repeat(SfxRepeatTarget
& rTarget
)
689 if (rTarget
.ISA(ScTabViewTarget
))
691 ScTabViewShell
& rViewShell
= *((ScTabViewTarget
&)rTarget
).GetViewShell();
692 ScViewData
* pViewData
= rViewShell
.GetViewData();
693 pViewData
->GetDocShell()->SetPrintZoom( pViewData
->GetTabNo(), nNewScale
, nNewPages
);
697 BOOL __EXPORT
ScUndoPrintZoom::CanRepeat(SfxRepeatTarget
& rTarget
) const
699 return (rTarget
.ISA(ScTabViewTarget
));
703 // -----------------------------------------------------------------------
708 ScUndoThesaurus::ScUndoThesaurus( ScDocShell
* pNewDocShell
,
709 SCCOL nNewCol
, SCROW nNewRow
, SCTAB nNewTab
,
710 const String
& rNewUndoStr
, const EditTextObject
* pUndoTObj
,
711 const String
& rNewRedoStr
, const EditTextObject
* pRedoTObj
) :
712 ScSimpleUndo( pNewDocShell
),
716 aUndoStr( rNewUndoStr
),
717 aRedoStr( rNewRedoStr
)
719 pUndoTObject
= (pUndoTObj
) ? pUndoTObj
->Clone() : NULL
;
720 pRedoTObject
= (pRedoTObj
) ? pRedoTObj
->Clone() : NULL
;
722 ScBaseCell
* pOldCell
;
724 pOldCell
= new ScEditCell( pUndoTObject
, pDocShell
->GetDocument(), NULL
);
726 pOldCell
= new ScStringCell( aUndoStr
);
727 SetChangeTrack( pOldCell
);
731 __EXPORT
ScUndoThesaurus::~ScUndoThesaurus()
737 String __EXPORT
ScUndoThesaurus::GetComment() const
739 return ScGlobal::GetRscString( STR_UNDO_THESAURUS
); // "Thesaurus"
742 void ScUndoThesaurus::SetChangeTrack( ScBaseCell
* pOldCell
)
744 ScChangeTrack
* pChangeTrack
= pDocShell
->GetDocument()->GetChangeTrack();
747 nEndChangeAction
= pChangeTrack
->GetActionMax() + 1;
748 pChangeTrack
->AppendContent( ScAddress( nCol
, nRow
, nTab
), pOldCell
);
749 if ( nEndChangeAction
> pChangeTrack
->GetActionMax() )
750 nEndChangeAction
= 0; // nichts appended
753 nEndChangeAction
= 0;
756 void __EXPORT
ScUndoThesaurus::DoChange( BOOL bUndo
, const String
& rStr
,
757 const EditTextObject
* pTObj
)
759 ScDocument
* pDoc
= pDocShell
->GetDocument();
761 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
764 pViewShell
->SetTabNo( nTab
);
765 pViewShell
->MoveCursorAbs( nCol
, nRow
, SC_FOLLOW_JUMP
, FALSE
, FALSE
);
771 pDoc
->GetCell( nCol
, nRow
, nTab
, pCell
);
774 if (pCell
->GetCellType() == CELLTYPE_EDIT
)
776 ScEditCell
* pNewCell
= new ScEditCell( pTObj
, pDoc
, NULL
);
777 pDoc
->PutCell( nCol
, nRow
, nTab
, pNewCell
);
779 SetChangeTrack( pCell
);
783 DBG_ERROR("Nicht CELLTYPE_EDIT bei Un/RedoThesaurus");
789 ScBaseCell
* pCell
= NULL
;
791 pDoc
->GetCell( nCol
, nRow
, nTab
, pCell
);
792 pDoc
->SetString( nCol
, nRow
, nTab
, rStr
);
794 SetChangeTrack( pCell
);
797 pDocShell
->PostPaintCell( nCol
, nRow
, nTab
);
800 void __EXPORT
ScUndoThesaurus::Undo()
803 DoChange( TRUE
, aUndoStr
, pUndoTObject
);
804 ScChangeTrack
* pChangeTrack
= pDocShell
->GetDocument()->GetChangeTrack();
806 pChangeTrack
->Undo( nEndChangeAction
, nEndChangeAction
);
810 void __EXPORT
ScUndoThesaurus::Redo()
813 DoChange( FALSE
, aRedoStr
, pRedoTObject
);
817 void __EXPORT
ScUndoThesaurus::Repeat(SfxRepeatTarget
& rTarget
)
819 if (rTarget
.ISA(ScTabViewTarget
))
820 ((ScTabViewTarget
&)rTarget
).GetViewShell()->DoThesaurus( TRUE
);
823 BOOL __EXPORT
ScUndoThesaurus::CanRepeat(SfxRepeatTarget
& rTarget
) const
825 return (rTarget
.ISA(ScTabViewTarget
));
829 // ============================================================================
831 ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell
& rDocShell
, const ScAddress
& rPos
,
832 const ScNoteData
& rNoteData
, bool bInsert
, SdrUndoAction
* pDrawUndo
) :
833 ScSimpleUndo( &rDocShell
),
835 mpDrawUndo( pDrawUndo
)
837 DBG_ASSERT( rNoteData
.mpCaption
, "ScUndoReplaceNote::ScUndoReplaceNote - missing note caption" );
838 (bInsert
? maNewData
: maOldData
) = rNoteData
;
841 ScUndoReplaceNote::ScUndoReplaceNote( ScDocShell
& rDocShell
, const ScAddress
& rPos
,
842 const ScNoteData
& rOldData
, const ScNoteData
& rNewData
, SdrUndoAction
* pDrawUndo
) :
843 ScSimpleUndo( &rDocShell
),
845 maOldData( rOldData
),
846 maNewData( rNewData
),
847 mpDrawUndo( pDrawUndo
)
849 DBG_ASSERT( maOldData
.mpCaption
|| maNewData
.mpCaption
, "ScUndoReplaceNote::ScUndoReplaceNote - missing note captions" );
850 DBG_ASSERT( !maOldData
.mxInitData
.get() && !maNewData
.mxInitData
.get(), "ScUndoReplaceNote::ScUndoReplaceNote - unexpected unitialized note" );
853 ScUndoReplaceNote::~ScUndoReplaceNote()
855 DeleteSdrUndoAction( mpDrawUndo
);
858 void ScUndoReplaceNote::Undo()
861 DoSdrUndoAction( mpDrawUndo
, pDocShell
->GetDocument() );
862 /* Undo insert -> remove new note.
863 Undo remove -> insert old note.
864 Undo replace -> remove new note, insert old note. */
865 DoRemoveNote( maNewData
);
866 DoInsertNote( maOldData
);
867 pDocShell
->PostPaintCell( maPos
);
871 void ScUndoReplaceNote::Redo()
874 RedoSdrUndoAction( mpDrawUndo
);
875 /* Redo insert -> insert new note.
876 Redo remove -> remove old note.
877 Redo replace -> remove old note, insert new note. */
878 DoRemoveNote( maOldData
);
879 DoInsertNote( maNewData
);
880 pDocShell
->PostPaintCell( maPos
);
884 void ScUndoReplaceNote::Repeat( SfxRepeatTarget
& /*rTarget*/ )
888 BOOL
ScUndoReplaceNote::CanRepeat( SfxRepeatTarget
& /*rTarget*/ ) const
893 String
ScUndoReplaceNote::GetComment() const
895 return ScGlobal::GetRscString( maNewData
.mpCaption
?
896 (maOldData
.mpCaption
? STR_UNDO_EDITNOTE
: STR_UNDO_INSERTNOTE
) : STR_UNDO_DELETENOTE
);
899 void ScUndoReplaceNote::DoInsertNote( const ScNoteData
& rNoteData
)
901 if( rNoteData
.mpCaption
)
903 ScDocument
& rDoc
= *pDocShell
->GetDocument();
904 DBG_ASSERT( !rDoc
.GetNote( maPos
), "ScUndoReplaceNote::DoInsertNote - unexpected cell note" );
905 ScPostIt
* pNote
= new ScPostIt( rDoc
, maPos
, rNoteData
, false );
906 rDoc
.TakeNote( maPos
, pNote
);
910 void ScUndoReplaceNote::DoRemoveNote( const ScNoteData
& rNoteData
)
912 if( rNoteData
.mpCaption
)
914 ScDocument
& rDoc
= *pDocShell
->GetDocument();
915 DBG_ASSERT( rDoc
.GetNote( maPos
), "ScUndoReplaceNote::DoRemoveNote - missing cell note" );
916 if( ScPostIt
* pNote
= rDoc
.ReleaseNote( maPos
) )
918 /* Forget pointer to caption object to suppress removing the
919 caption object from the drawing layer while deleting pNote
920 (removing the caption is done by a drawing undo action). */
921 pNote
->ForgetCaption();
927 // ============================================================================
929 ScUndoShowHideNote::ScUndoShowHideNote( ScDocShell
& rDocShell
, const ScAddress
& rPos
, bool bShow
) :
930 ScSimpleUndo( &rDocShell
),
936 ScUndoShowHideNote::~ScUndoShowHideNote()
940 void ScUndoShowHideNote::Undo()
943 if( ScPostIt
* pNote
= pDocShell
->GetDocument()->GetNote( maPos
) )
944 pNote
->ShowCaption( maPos
, !mbShown
);
948 void ScUndoShowHideNote::Redo()
951 if( ScPostIt
* pNote
= pDocShell
->GetDocument()->GetNote( maPos
) )
952 pNote
->ShowCaption( maPos
, mbShown
);
956 void ScUndoShowHideNote::Repeat( SfxRepeatTarget
& /*rTarget*/ )
960 BOOL
ScUndoShowHideNote::CanRepeat( SfxRepeatTarget
& /*rTarget*/ ) const
965 String
ScUndoShowHideNote::GetComment() const
967 return ScGlobal::GetRscString( mbShown
? STR_UNDO_SHOWNOTE
: STR_UNDO_HIDENOTE
);
970 // ============================================================================
972 // -----------------------------------------------------------------------
977 ScUndoDetective::ScUndoDetective( ScDocShell
* pNewDocShell
,
978 SdrUndoAction
* pDraw
, const ScDetOpData
* pOperation
,
979 ScDetOpList
* pUndoList
) :
980 ScSimpleUndo( pNewDocShell
),
981 pOldList ( pUndoList
),
985 bIsDelete
= ( pOperation
== NULL
);
988 nAction
= (USHORT
) pOperation
->GetOperation();
989 aPos
= pOperation
->GetPos();
993 __EXPORT
ScUndoDetective::~ScUndoDetective()
995 DeleteSdrUndoAction( pDrawUndo
);
999 String __EXPORT
ScUndoDetective::GetComment() const
1001 USHORT nId
= STR_UNDO_DETDELALL
;
1003 switch ( (ScDetOpType
) nAction
)
1005 case SCDETOP_ADDSUCC
: nId
= STR_UNDO_DETADDSUCC
; break;
1006 case SCDETOP_DELSUCC
: nId
= STR_UNDO_DETDELSUCC
; break;
1007 case SCDETOP_ADDPRED
: nId
= STR_UNDO_DETADDPRED
; break;
1008 case SCDETOP_DELPRED
: nId
= STR_UNDO_DETDELPRED
; break;
1009 case SCDETOP_ADDERROR
: nId
= STR_UNDO_DETADDERROR
; break;
1012 return ScGlobal::GetRscString( nId
);
1016 void __EXPORT
ScUndoDetective::Undo()
1020 ScDocument
* pDoc
= pDocShell
->GetDocument();
1021 DoSdrUndoAction(pDrawUndo
, pDoc
);
1026 pDoc
->SetDetOpList( new ScDetOpList(*pOldList
) );
1030 // Eintrag aus der Liste loeschen
1032 ScDetOpList
* pList
= pDoc
->GetDetOpList();
1033 if (pList
&& pList
->Count())
1035 USHORT nPos
= pList
->Count() - 1;
1036 ScDetOpData
* pData
= (*pList
)[nPos
];
1037 if ( pData
->GetOperation() == (ScDetOpType
) nAction
&& pData
->GetPos() == aPos
)
1038 pList
->DeleteAndDestroy( nPos
, 1 );
1041 DBG_ERROR("Detektiv-Eintrag in der Liste nicht gefunden");
1046 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1048 pViewShell
->RecalcPPT(); //! use broadcast instead?
1053 void __EXPORT
ScUndoDetective::Redo()
1057 RedoSdrUndoAction(pDrawUndo
);
1059 ScDocument
* pDoc
= pDocShell
->GetDocument();
1062 pDoc
->ClearDetectiveOperations();
1064 pDoc
->AddDetectiveOperation( ScDetOpData( aPos
, (ScDetOpType
) nAction
) );
1066 ScTabViewShell
* pViewShell
= ScTabViewShell::GetActiveViewShell();
1068 pViewShell
->RecalcPPT(); //! use broadcast instead?
1073 void __EXPORT
ScUndoDetective::Repeat(SfxRepeatTarget
& /* rTarget */)
1078 BOOL __EXPORT
ScUndoDetective::CanRepeat(SfxRepeatTarget
& /* rTarget */) const
1083 // -----------------------------------------------------------------------
1085 // Benannte Bereiche
1088 ScUndoRangeNames::ScUndoRangeNames( ScDocShell
* pNewDocShell
,
1089 ScRangeName
* pOld
, ScRangeName
* pNew
) :
1090 ScSimpleUndo( pNewDocShell
),
1091 pOldRanges ( pOld
),
1096 __EXPORT
ScUndoRangeNames::~ScUndoRangeNames()
1102 String __EXPORT
ScUndoRangeNames::GetComment() const
1104 return ScGlobal::GetRscString( STR_UNDO_RANGENAMES
);
1107 void ScUndoRangeNames::DoChange( BOOL bUndo
)
1109 ScDocument
* pDoc
= pDocShell
->GetDocument();
1110 pDoc
->CompileNameFormula( TRUE
); // CreateFormulaString
1113 pDoc
->SetRangeName( new ScRangeName( *pOldRanges
) );
1115 pDoc
->SetRangeName( new ScRangeName( *pNewRanges
) );
1117 pDoc
->CompileNameFormula( FALSE
); // CompileFormulaString
1119 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED
) );
1122 void __EXPORT
ScUndoRangeNames::Undo()
1129 void __EXPORT
ScUndoRangeNames::Redo()
1136 void __EXPORT
ScUndoRangeNames::Repeat(SfxRepeatTarget
& /* rTarget */)
1141 BOOL __EXPORT
ScUndoRangeNames::CanRepeat(SfxRepeatTarget
& /* rTarget */) const