Update ooo320-m1
[ooovba.git] / sc / source / ui / undo / undocell.cxx
blobc50211d9fd1211f11da9bc7c91e51a8d6c8c42be
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"
45 #include "docsh.hxx"
46 #include "tabvwsh.hxx"
47 #include "globstr.hrc"
48 #include "global.hxx"
49 #include "cell.hxx"
50 #include "target.hxx"
51 #include "undoolk.hxx"
52 #include "detdata.hxx"
53 #include "stlpool.hxx"
54 #include "printfun.hxx"
55 #include "rangenam.hxx"
56 #include "chgtrack.hxx"
57 #include "sc.hrc"
58 #include "docuno.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 ),
87 nCol( nNewCol ),
88 nRow( nNewRow ),
89 nTab( nNewTab ),
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 );
127 ScBaseCell* pCell;
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();
133 if (pViewShell)
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;
146 if (bPaintExt)
147 nFlags |= SC_PF_LINES;
148 if (bPaintRows)
149 nFlags |= SC_PF_WHOLEROWS;
150 pDocShell->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID, nFlags );
153 void __EXPORT ScUndoCursorAttr::Undo()
155 BeginUndo();
156 DoChange(pOldPattern, pOldEditData);
158 if ( bIsAutomatic )
160 // wenn automatische Formatierung rueckgaengig gemacht wird,
161 // soll auch nicht weiter automatisch formatiert werden:
163 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
164 if (pViewShell)
165 pViewShell->ForgetFormatArea();
168 EndUndo();
171 void __EXPORT ScUndoCursorAttr::Redo()
173 BeginRedo();
174 DoChange(pNewPattern, pNewEditData);
175 EndRedo();
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 // -----------------------------------------------------------------------
192 // Daten eingeben
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 ),
202 pTabs( pNewTabs ),
203 ppOldCells( ppOldData ),
204 pHasFormat( pHasForm ),
205 pOldFormats( pOldForm ),
206 pNewEditData( pObj ),
207 nCol( nNewCol ),
208 nRow( nNewRow ),
209 nTab( nNewTab ),
210 nCount( nNewCount )
212 SetChangeTrack();
215 __EXPORT ScUndoEnterData::~ScUndoEnterData()
217 for (USHORT i=0; i<nCount; i++)
218 if (ppOldCells[i])
219 ppOldCells[i]->Delete();
220 delete[] ppOldCells;
222 delete[] pHasFormat;
223 delete[] pOldFormats;
224 delete[] pTabs;
226 delete pNewEditData;
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();
242 if (pViewShell)
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();
254 if ( pChangeTrack )
256 nEndChangeAction = pChangeTrack->GetActionMax() + 1;
257 ScAddress aPos( nCol, nRow, nTab );
258 for (USHORT i=0; i<nCount; i++)
260 aPos.SetTab( pTabs[i] );
261 ULONG nFormat = 0;
262 if ( pHasFormat && pOldFormats )
264 if ( pHasFormat[i] )
265 nFormat = pOldFormats[i];
267 pChangeTrack->AppendContent( aPos, ppOldCells[i], nFormat );
269 if ( nEndChangeAction > pChangeTrack->GetActionMax() )
270 nEndChangeAction = 0; // nichts appended
272 else
273 nEndChangeAction = 0;
276 void __EXPORT ScUndoEnterData::Undo()
278 BeginUndo();
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)
288 if ( pHasFormat[i] )
289 pDoc->ApplyAttr( nCol, nRow, pTabs[i],
290 SfxUInt32Item( ATTR_VALUE_FORMAT, pOldFormats[i] ) );
291 else
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 );
305 DoChange();
306 EndUndo();
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()
323 BeginRedo();
325 ScDocument* pDoc = pDocShell->GetDocument();
326 for (USHORT i=0; i<nCount; i++)
328 if (pNewEditData)
329 pDoc->PutCell( nCol, nRow, pTabs[i], new ScEditCell( pNewEditData,
330 pDoc, NULL ) );
331 else
332 pDoc->SetString( nCol, nRow, pTabs[i], aNewString );
333 pDocShell->PostPaintCell( nCol, nRow, pTabs[i] );
336 SetChangeTrack();
338 DoChange();
339 EndRedo();
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 // -----------------------------------------------------------------------
371 // Wert aendern
374 ScUndoEnterValue::ScUndoEnterValue( ScDocShell* pNewDocShell, const ScAddress& rNewPos,
375 ScBaseCell* pUndoCell, double nVal, BOOL bHeight ) :
376 ScSimpleUndo( pNewDocShell ),
377 aPos ( rNewPos ),
378 pOldCell ( pUndoCell ),
379 nValue ( nVal ),
380 bNeedHeight ( bHeight )
382 SetChangeTrack();
385 __EXPORT ScUndoEnterValue::~ScUndoEnterValue()
387 if (pOldCell)
388 pOldCell->Delete();
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();
400 if ( pChangeTrack )
402 nEndChangeAction = pChangeTrack->GetActionMax() + 1;
403 pChangeTrack->AppendContent( aPos, pOldCell );
404 if ( nEndChangeAction > pChangeTrack->GetActionMax() )
405 nEndChangeAction = 0; // nichts appended
407 else
408 nEndChangeAction = 0;
411 void __EXPORT ScUndoEnterValue::Undo()
413 BeginUndo();
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();
423 if ( pChangeTrack )
424 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
426 EndUndo();
429 void __EXPORT ScUndoEnterValue::Redo()
431 BeginRedo();
433 ScDocument* pDoc = pDocShell->GetDocument();
434 pDoc->SetValue( aPos.Col(), aPos.Row(), aPos.Tab(), nValue );
435 pDocShell->PostPaintCell( aPos );
437 SetChangeTrack();
439 EndRedo();
442 void __EXPORT ScUndoEnterValue::Repeat(SfxRepeatTarget& /* rTarget */)
444 // gippsnich
447 BOOL __EXPORT ScUndoEnterValue::CanRepeat(SfxRepeatTarget& /* rTarget */) const
449 return FALSE;
453 // -----------------------------------------------------------------------
455 // Beliebige Zelle eingeben
458 ScUndoPutCell::ScUndoPutCell( ScDocShell* pNewDocShell, const ScAddress& rNewPos,
459 ScBaseCell* pUndoCell, ScBaseCell* pRedoCell, BOOL bHeight ) :
460 ScSimpleUndo( pNewDocShell ),
461 aPos ( rNewPos ),
462 pOldCell ( pUndoCell ),
463 pEnteredCell( pRedoCell ),
464 bNeedHeight ( bHeight )
466 SetChangeTrack();
469 __EXPORT ScUndoPutCell::~ScUndoPutCell()
471 if (pOldCell)
472 pOldCell->Delete();
473 if (pEnteredCell)
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();
486 if ( pChangeTrack )
488 nEndChangeAction = pChangeTrack->GetActionMax() + 1;
489 pChangeTrack->AppendContent( aPos, pOldCell );
490 if ( nEndChangeAction > pChangeTrack->GetActionMax() )
491 nEndChangeAction = 0; // nichts appended
493 else
494 nEndChangeAction = 0;
497 void __EXPORT ScUndoPutCell::Undo()
499 BeginUndo();
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();
509 if ( pChangeTrack )
510 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
512 EndUndo();
515 void __EXPORT ScUndoPutCell::Redo()
517 BeginRedo();
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 );
526 SetChangeTrack();
528 EndRedo();
531 void __EXPORT ScUndoPutCell::Repeat(SfxRepeatTarget& /* rTarget */)
533 // gippsnich
536 BOOL __EXPORT ScUndoPutCell::CanRepeat(SfxRepeatTarget& /* rTarget */) const
538 return FALSE;
542 // -----------------------------------------------------------------------
544 // Seitenumbrueche
547 ScUndoPageBreak::ScUndoPageBreak( ScDocShell* pNewDocShell,
548 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab,
549 BOOL bNewColumn, BOOL bNewInsert ) :
550 ScSimpleUndo( pNewDocShell ),
551 nCol( nNewCol ),
552 nRow( nNewRow ),
553 nTab( nNewTab ),
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 ?
567 ( bInsert ?
568 ScGlobal::GetRscString( STR_UNDO_INSCOLBREAK ) :
569 ScGlobal::GetRscString( STR_UNDO_DELCOLBREAK )
571 ( bInsert ?
572 ScGlobal::GetRscString( STR_UNDO_INSROWBREAK ) :
573 ScGlobal::GetRscString( STR_UNDO_DELROWBREAK )
574 ) );
577 void ScUndoPageBreak::DoChange( BOOL bInsertP ) const
579 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
581 if (pViewShell)
583 pViewShell->SetTabNo( nTab );
584 pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, FALSE, FALSE );
586 if (bInsertP)
587 pViewShell->InsertPageBreak(bColumn, FALSE);
588 else
589 pViewShell->DeletePageBreak(bColumn, FALSE);
591 pDocShell->GetDocument()->InvalidatePageBreaks(nTab);
595 void __EXPORT ScUndoPageBreak::Undo()
597 BeginUndo();
598 DoChange(!bInsert);
599 EndUndo();
602 void __EXPORT ScUndoPageBreak::Redo()
604 BeginRedo();
605 DoChange(bInsert);
606 EndRedo();
609 void __EXPORT ScUndoPageBreak::Repeat(SfxRepeatTarget& rTarget)
611 if (rTarget.ISA(ScTabViewTarget))
613 ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
615 if (bInsert)
616 rViewShell.InsertPageBreak(bColumn, TRUE);
617 else
618 rViewShell.DeletePageBreak(bColumn, TRUE);
622 BOOL __EXPORT ScUndoPageBreak::CanRepeat(SfxRepeatTarget& rTarget) const
624 return (rTarget.ISA(ScTabViewTarget));
627 // -----------------------------------------------------------------------
629 // Druck-Skalierung
632 ScUndoPrintZoom::ScUndoPrintZoom( ScDocShell* pNewDocShell,
633 SCTAB nT, USHORT nOS, USHORT nOP, USHORT nNS, USHORT nNP ) :
634 ScSimpleUndo( pNewDocShell ),
635 nTab( nT ),
636 nOldScale( nOS ),
637 nOldPages( nOP ),
638 nNewScale( nNS ),
639 nNewPages( nNP )
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" );
662 if ( pStyleSheet )
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()
675 BeginUndo();
676 DoChange(TRUE);
677 EndUndo();
680 void __EXPORT ScUndoPrintZoom::Redo()
682 BeginRedo();
683 DoChange(FALSE);
684 EndRedo();
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 // -----------------------------------------------------------------------
705 // Thesaurus
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 ),
713 nCol( nNewCol ),
714 nRow( nNewRow ),
715 nTab( nNewTab ),
716 aUndoStr( rNewUndoStr ),
717 aRedoStr( rNewRedoStr )
719 pUndoTObject = (pUndoTObj) ? pUndoTObj->Clone() : NULL;
720 pRedoTObject = (pRedoTObj) ? pRedoTObj->Clone() : NULL;
722 ScBaseCell* pOldCell;
723 if ( pUndoTObject )
724 pOldCell = new ScEditCell( pUndoTObject, pDocShell->GetDocument(), NULL );
725 else
726 pOldCell = new ScStringCell( aUndoStr );
727 SetChangeTrack( pOldCell );
728 pOldCell->Delete();
731 __EXPORT ScUndoThesaurus::~ScUndoThesaurus()
733 delete pUndoTObject;
734 delete pRedoTObject;
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();
745 if ( pChangeTrack )
747 nEndChangeAction = pChangeTrack->GetActionMax() + 1;
748 pChangeTrack->AppendContent( ScAddress( nCol, nRow, nTab ), pOldCell );
749 if ( nEndChangeAction > pChangeTrack->GetActionMax() )
750 nEndChangeAction = 0; // nichts appended
752 else
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();
762 if (pViewShell)
764 pViewShell->SetTabNo( nTab );
765 pViewShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_JUMP, FALSE, FALSE );
768 if (pTObj)
770 ScBaseCell* pCell;
771 pDoc->GetCell( nCol, nRow, nTab, pCell );
772 if (pCell)
774 if (pCell->GetCellType() == CELLTYPE_EDIT )
776 ScEditCell* pNewCell = new ScEditCell( pTObj, pDoc, NULL );
777 pDoc->PutCell( nCol, nRow, nTab, pNewCell );
778 if ( !bUndo )
779 SetChangeTrack( pCell );
781 else
783 DBG_ERROR("Nicht CELLTYPE_EDIT bei Un/RedoThesaurus");
787 else
789 ScBaseCell* pCell = NULL;
790 if ( !bUndo )
791 pDoc->GetCell( nCol, nRow, nTab, pCell );
792 pDoc->SetString( nCol, nRow, nTab, rStr );
793 if ( !bUndo )
794 SetChangeTrack( pCell );
797 pDocShell->PostPaintCell( nCol, nRow, nTab );
800 void __EXPORT ScUndoThesaurus::Undo()
802 BeginUndo();
803 DoChange( TRUE, aUndoStr, pUndoTObject );
804 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
805 if ( pChangeTrack )
806 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
807 EndUndo();
810 void __EXPORT ScUndoThesaurus::Redo()
812 BeginRedo();
813 DoChange( FALSE, aRedoStr, pRedoTObject );
814 EndRedo();
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 ),
834 maPos( rPos ),
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 ),
844 maPos( rPos ),
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()
860 BeginUndo();
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 );
868 EndUndo();
871 void ScUndoReplaceNote::Redo()
873 BeginRedo();
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 );
881 EndRedo();
884 void ScUndoReplaceNote::Repeat( SfxRepeatTarget& /*rTarget*/ )
888 BOOL ScUndoReplaceNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
890 return FALSE;
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();
922 delete pNote;
927 // ============================================================================
929 ScUndoShowHideNote::ScUndoShowHideNote( ScDocShell& rDocShell, const ScAddress& rPos, bool bShow ) :
930 ScSimpleUndo( &rDocShell ),
931 maPos( rPos ),
932 mbShown( bShow )
936 ScUndoShowHideNote::~ScUndoShowHideNote()
940 void ScUndoShowHideNote::Undo()
942 BeginUndo();
943 if( ScPostIt* pNote = pDocShell->GetDocument()->GetNote( maPos ) )
944 pNote->ShowCaption( maPos, !mbShown );
945 EndUndo();
948 void ScUndoShowHideNote::Redo()
950 BeginRedo();
951 if( ScPostIt* pNote = pDocShell->GetDocument()->GetNote( maPos ) )
952 pNote->ShowCaption( maPos, mbShown );
953 EndRedo();
956 void ScUndoShowHideNote::Repeat( SfxRepeatTarget& /*rTarget*/ )
960 BOOL ScUndoShowHideNote::CanRepeat( SfxRepeatTarget& /*rTarget*/ ) const
962 return FALSE;
965 String ScUndoShowHideNote::GetComment() const
967 return ScGlobal::GetRscString( mbShown ? STR_UNDO_SHOWNOTE : STR_UNDO_HIDENOTE );
970 // ============================================================================
972 // -----------------------------------------------------------------------
974 // Detektiv
977 ScUndoDetective::ScUndoDetective( ScDocShell* pNewDocShell,
978 SdrUndoAction* pDraw, const ScDetOpData* pOperation,
979 ScDetOpList* pUndoList ) :
980 ScSimpleUndo( pNewDocShell ),
981 pOldList ( pUndoList ),
982 nAction ( 0 ),
983 pDrawUndo ( pDraw )
985 bIsDelete = ( pOperation == NULL );
986 if (!bIsDelete)
988 nAction = (USHORT) pOperation->GetOperation();
989 aPos = pOperation->GetPos();
993 __EXPORT ScUndoDetective::~ScUndoDetective()
995 DeleteSdrUndoAction( pDrawUndo );
996 delete pOldList;
999 String __EXPORT ScUndoDetective::GetComment() const
1001 USHORT nId = STR_UNDO_DETDELALL;
1002 if ( !bIsDelete )
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()
1018 BeginUndo();
1020 ScDocument* pDoc = pDocShell->GetDocument();
1021 DoSdrUndoAction(pDrawUndo, pDoc);
1023 if (bIsDelete)
1025 if ( pOldList )
1026 pDoc->SetDetOpList( new ScDetOpList(*pOldList) );
1028 else
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 );
1039 else
1041 DBG_ERROR("Detektiv-Eintrag in der Liste nicht gefunden");
1046 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1047 if (pViewShell)
1048 pViewShell->RecalcPPT(); //! use broadcast instead?
1050 EndUndo();
1053 void __EXPORT ScUndoDetective::Redo()
1055 BeginRedo();
1057 RedoSdrUndoAction(pDrawUndo);
1059 ScDocument* pDoc = pDocShell->GetDocument();
1061 if (bIsDelete)
1062 pDoc->ClearDetectiveOperations();
1063 else
1064 pDoc->AddDetectiveOperation( ScDetOpData( aPos, (ScDetOpType) nAction ) );
1066 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1067 if (pViewShell)
1068 pViewShell->RecalcPPT(); //! use broadcast instead?
1070 EndRedo();
1073 void __EXPORT ScUndoDetective::Repeat(SfxRepeatTarget& /* rTarget */)
1075 // hammanich
1078 BOOL __EXPORT ScUndoDetective::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1080 return FALSE;
1083 // -----------------------------------------------------------------------
1085 // Benannte Bereiche
1088 ScUndoRangeNames::ScUndoRangeNames( ScDocShell* pNewDocShell,
1089 ScRangeName* pOld, ScRangeName* pNew ) :
1090 ScSimpleUndo( pNewDocShell ),
1091 pOldRanges ( pOld ),
1092 pNewRanges ( pNew )
1096 __EXPORT ScUndoRangeNames::~ScUndoRangeNames()
1098 delete pOldRanges;
1099 delete pNewRanges;
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
1112 if ( bUndo )
1113 pDoc->SetRangeName( new ScRangeName( *pOldRanges ) );
1114 else
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()
1124 BeginUndo();
1125 DoChange( TRUE );
1126 EndUndo();
1129 void __EXPORT ScUndoRangeNames::Redo()
1131 BeginRedo();
1132 DoChange( FALSE );
1133 EndRedo();
1136 void __EXPORT ScUndoRangeNames::Repeat(SfxRepeatTarget& /* rTarget */)
1138 // hammanich
1141 BOOL __EXPORT ScUndoRangeNames::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1143 return FALSE;