Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / undo / undotab.cxx
blobf4fce0f7e0c616fa3fb6fdb57bc363956a1c3380
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 <sfx2/app.hxx>
21 #include <sfx2/bindings.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <svl/smplhint.hxx>
25 #include "undotab.hxx"
26 #include "document.hxx"
27 #include "docsh.hxx"
28 #include "tabvwsh.hxx"
29 #include "globstr.hrc"
30 #include "global.hxx"
31 #include "sc.hrc"
32 #include "undoolk.hxx"
33 #include "target.hxx"
34 #include "uiitems.hxx"
35 #include "prnsave.hxx"
36 #include "printfun.hxx"
37 #include "chgtrack.hxx"
38 #include "tabprotection.hxx"
39 #include "viewdata.hxx"
40 #include "progress.hxx"
41 #include "markdata.hxx"
43 // for ScUndoRenameObject - might me moved to another file later
44 #include <svx/svditer.hxx>
45 #include <svx/svdoole2.hxx>
46 #include <svx/svdpage.hxx>
47 #include "drwlayer.hxx"
48 #include "scresid.hxx"
50 #include <vector>
52 extern sal_Bool bDrawIsInUndo; // somewhere as member!
54 using namespace com::sun::star;
55 using ::com::sun::star::uno::Sequence;
56 using ::std::auto_ptr;
57 using ::std::vector;
58 using ::boost::shared_ptr;
60 TYPEINIT1(ScUndoInsertTab, SfxUndoAction);
61 TYPEINIT1(ScUndoInsertTables, SfxUndoAction);
62 TYPEINIT1(ScUndoDeleteTab, SfxUndoAction);
63 TYPEINIT1(ScUndoRenameTab, SfxUndoAction);
64 TYPEINIT1(ScUndoMoveTab, SfxUndoAction);
65 TYPEINIT1(ScUndoCopyTab, SfxUndoAction);
66 TYPEINIT1(ScUndoMakeScenario, SfxUndoAction);
67 TYPEINIT1(ScUndoImportTab, SfxUndoAction);
68 TYPEINIT1(ScUndoRemoveLink, SfxUndoAction);
69 TYPEINIT1(ScUndoShowHideTab, SfxUndoAction);
70 TYPEINIT1(ScUndoPrintRange, SfxUndoAction);
71 TYPEINIT1(ScUndoScenarioFlags, SfxUndoAction);
72 TYPEINIT1(ScUndoRenameObject, SfxUndoAction);
73 TYPEINIT1(ScUndoLayoutRTL, SfxUndoAction);
74 TYPEINIT1(ScUndoTabColor, SfxUndoAction);
76 ScUndoInsertTab::ScUndoInsertTab( ScDocShell* pNewDocShell,
77 SCTAB nTabNum,
78 sal_Bool bApp,
79 const OUString& rNewName) :
80 ScSimpleUndo( pNewDocShell ),
81 sNewName( rNewName ),
82 pDrawUndo( NULL ),
83 nTab( nTabNum ),
84 bAppend( bApp )
86 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
87 SetChangeTrack();
90 ScUndoInsertTab::~ScUndoInsertTab()
92 DeleteSdrUndoAction( pDrawUndo );
95 OUString ScUndoInsertTab::GetComment() const
97 if (bAppend)
98 return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
99 else
100 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
103 void ScUndoInsertTab::SetChangeTrack()
105 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
106 if ( pChangeTrack )
108 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
109 pChangeTrack->AppendInsert( aRange );
110 nEndChangeAction = pChangeTrack->GetActionMax();
112 else
113 nEndChangeAction = 0;
116 void ScUndoInsertTab::Undo()
118 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
119 pViewShell->SetTabNo(nTab);
121 pDocShell->SetInUndo( sal_True ); //! BeginUndo
122 bDrawIsInUndo = sal_True;
123 pViewShell->DeleteTable( nTab, false );
124 bDrawIsInUndo = false;
125 pDocShell->SetInUndo( false ); //! EndUndo
127 DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
129 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
130 if ( pChangeTrack )
131 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
133 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
134 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
137 void ScUndoInsertTab::Redo()
139 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
141 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
143 pDocShell->SetInUndo( sal_True ); //! BeginRedo
144 bDrawIsInUndo = sal_True;
145 if (bAppend)
146 pViewShell->AppendTable( sNewName, false );
147 else
149 pViewShell->SetTabNo(nTab);
150 pViewShell->InsertTable( sNewName, nTab, false );
152 bDrawIsInUndo = false;
153 pDocShell->SetInUndo( false ); //! EndRedo
155 SetChangeTrack();
158 void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
160 if (rTarget.ISA(ScTabViewTarget))
161 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
162 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
165 bool ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
167 return rTarget.ISA(ScTabViewTarget);
170 ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
171 SCTAB nTabNum,
172 std::vector<OUString>& newNameList) :
173 ScSimpleUndo( pNewDocShell ),
174 pDrawUndo( NULL ),
175 aNameList( newNameList ),
176 nTab( nTabNum )
178 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
180 SetChangeTrack();
183 ScUndoInsertTables::~ScUndoInsertTables()
185 DeleteSdrUndoAction( pDrawUndo );
188 OUString ScUndoInsertTables::GetComment() const
190 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
193 void ScUndoInsertTables::SetChangeTrack()
195 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
196 if ( pChangeTrack )
198 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
199 nEndChangeAction = 0;
200 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
201 for( size_t i = 0; i < aNameList.size(); i++ )
203 aRange.aStart.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
204 aRange.aEnd.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
205 pChangeTrack->AppendInsert( aRange );
206 nEndChangeAction = pChangeTrack->GetActionMax();
209 else
210 nStartChangeAction = nEndChangeAction = 0;
213 void ScUndoInsertTables::Undo()
215 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
216 pViewShell->SetTabNo(nTab);
218 pDocShell->SetInUndo( sal_True ); //! BeginUndo
219 bDrawIsInUndo = sal_True;
221 pViewShell->DeleteTables( nTab, static_cast<SCTAB>(aNameList.size()) );
223 bDrawIsInUndo = false;
224 pDocShell->SetInUndo( false ); //! EndUndo
226 DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
228 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
229 if ( pChangeTrack )
230 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
232 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
233 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
236 void ScUndoInsertTables::Redo()
238 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
240 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
242 pDocShell->SetInUndo( sal_True ); //! BeginRedo
243 bDrawIsInUndo = sal_True;
244 pViewShell->SetTabNo(nTab);
245 pViewShell->InsertTables( aNameList, nTab, static_cast<SCTAB>(aNameList.size()),false );
247 bDrawIsInUndo = false;
248 pDocShell->SetInUndo( false ); //! EndRedo
250 SetChangeTrack();
253 void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
255 if (rTarget.ISA(ScTabViewTarget))
256 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
257 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
260 bool ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
262 return rTarget.ISA(ScTabViewTarget);
265 ScUndoDeleteTab::ScUndoDeleteTab( ScDocShell* pNewDocShell, const vector<SCTAB> &aTab,
266 ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
267 ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST )
269 theTabs.insert(theTabs.end(), aTab.begin(), aTab.end() );
270 SetChangeTrack();
273 ScUndoDeleteTab::~ScUndoDeleteTab()
275 theTabs.clear();
278 OUString ScUndoDeleteTab::GetComment() const
280 return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
283 void ScUndoDeleteTab::SetChangeTrack()
285 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
286 if ( pChangeTrack )
288 sal_uLong nTmpChangeAction;
289 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
290 nEndChangeAction = 0;
291 ScRange aRange( 0, 0, 0, MAXCOL, MAXROW, 0 );
292 for ( unsigned int i = 0; i < theTabs.size(); ++i )
294 aRange.aStart.SetTab( theTabs[i] );
295 aRange.aEnd.SetTab( theTabs[i] );
296 pChangeTrack->AppendDeleteRange( aRange, pRefUndoDoc,
297 nTmpChangeAction, nEndChangeAction, (short) i );
300 else
301 nStartChangeAction = nEndChangeAction = 0;
304 static SCTAB lcl_GetVisibleTabBefore( ScDocument& rDoc, SCTAB nTab )
306 while ( nTab > 0 && !rDoc.IsVisible( nTab ) )
307 --nTab;
309 return nTab;
312 void ScUndoDeleteTab::Undo()
314 BeginUndo();
315 unsigned int i=0;
316 ScDocument* pDoc = pDocShell->GetDocument();
318 sal_Bool bLink = false;
319 OUString aName;
321 for(i=0; i<theTabs.size(); ++i)
323 SCTAB nTab = theTabs[i];
324 pRefUndoDoc->GetName( nTab, aName );
326 bDrawIsInUndo = sal_True;
327 sal_Bool bOk = pDoc->InsertTab( nTab, aName );
328 bDrawIsInUndo = false;
329 if (bOk)
331 pRefUndoDoc->CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,false, pDoc );
333 OUString aOldName;
334 pRefUndoDoc->GetName( nTab, aOldName );
335 pDoc->RenameTab( nTab, aOldName, false );
336 if (pRefUndoDoc->IsLinked(nTab))
338 pDoc->SetLink( nTab, pRefUndoDoc->GetLinkMode(nTab), pRefUndoDoc->GetLinkDoc(nTab),
339 pRefUndoDoc->GetLinkFlt(nTab), pRefUndoDoc->GetLinkOpt(nTab),
340 pRefUndoDoc->GetLinkTab(nTab), pRefUndoDoc->GetLinkRefreshDelay(nTab) );
341 bLink = sal_True;
344 if ( pRefUndoDoc->IsScenario(nTab) )
346 pDoc->SetScenario( nTab, sal_True );
347 OUString aComment;
348 Color aColor;
349 sal_uInt16 nScenFlags;
350 pRefUndoDoc->GetScenarioData( nTab, aComment, aColor, nScenFlags );
351 pDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
352 sal_Bool bActive = pRefUndoDoc->IsActiveScenario( nTab );
353 pDoc->SetActiveScenario( nTab, bActive );
355 pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
356 pDoc->SetTabBgColor( nTab, pRefUndoDoc->GetTabBgColor(nTab) );
357 pDoc->SetSheetEvents( nTab, pRefUndoDoc->GetSheetEvents( nTab ) );
358 pDoc->SetLayoutRTL( nTab, pRefUndoDoc->IsLayoutRTL( nTab ) );
360 if ( pRefUndoDoc->IsTabProtected( nTab ) )
361 pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
364 if (bLink)
366 pDocShell->UpdateLinks(); // update Link Manager
369 EndUndo(); // Draw-Undo has to be called before Broadcast!
371 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
372 if ( pChangeTrack )
373 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
375 for(i=0; i<theTabs.size(); ++i)
377 pDocShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, theTabs[i]) );
379 SfxApplication* pSfxApp = SFX_APP(); // Navigator
380 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
381 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
382 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
384 pDocShell->PostPaint(0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_ALL ); // incl. extras
386 // not ShowTable due to SetTabNo(..., sal_True):
387 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
388 if (pViewShell)
389 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDoc, theTabs[0] ), true );
392 void ScUndoDeleteTab::Redo()
394 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
395 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs.front() ) );
397 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
399 pDocShell->SetInUndo( sal_True ); //! BeginRedo
400 bDrawIsInUndo = sal_True;
401 pViewShell->DeleteTables( theTabs, false );
402 bDrawIsInUndo = false;
403 pDocShell->SetInUndo( sal_True ); //! EndRedo
405 SetChangeTrack();
407 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
408 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
411 void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
413 if (rTarget.ISA(ScTabViewTarget))
415 ScTabViewShell* pViewShell = ((ScTabViewTarget&)rTarget).GetViewShell();
416 pViewShell->DeleteTable( pViewShell->GetViewData()->GetTabNo(), sal_True );
420 bool ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
422 return rTarget.ISA(ScTabViewTarget);
425 ScUndoRenameTab::ScUndoRenameTab( ScDocShell* pNewDocShell,
426 SCTAB nT,
427 const OUString& rOldName,
428 const OUString& rNewName) :
429 ScSimpleUndo( pNewDocShell ),
430 nTab ( nT )
432 sOldName = rOldName;
433 sNewName = rNewName;
436 ScUndoRenameTab::~ScUndoRenameTab()
440 OUString ScUndoRenameTab::GetComment() const
442 return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
445 void ScUndoRenameTab::DoChange( SCTAB nTabP, const OUString& rName ) const
447 ScDocument* pDoc = pDocShell->GetDocument();
448 pDoc->RenameTab( nTabP, rName );
450 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
452 pDocShell->PostPaintGridAll();
453 pDocShell->PostPaintExtras();
454 pDocShell->PostDataChanged();
456 // The sheet name might be used in a formula ...
457 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
458 if (pViewShell)
459 pViewShell->UpdateInputHandler();
462 void ScUndoRenameTab::Undo()
464 DoChange(nTab, sOldName);
467 void ScUndoRenameTab::Redo()
469 DoChange(nTab, sNewName);
472 void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
474 // makes no sense
477 bool ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
479 return false;
482 ScUndoMoveTab::ScUndoMoveTab(
483 ScDocShell* pNewDocShell, vector<SCTAB>* pOldTabs, vector<SCTAB>* pNewTabs,
484 vector<OUString>* pOldNames, vector<OUString>* pNewNames) :
485 ScSimpleUndo( pNewDocShell ),
486 mpOldTabs(pOldTabs), mpNewTabs(pNewTabs),
487 mpOldNames(pOldNames), mpNewNames(pNewNames)
489 if (mpOldNames && mpOldTabs->size() != mpOldNames->size())
490 // The sizes differ. Something is wrong.
491 mpOldNames.reset();
493 if (mpNewNames && mpNewTabs->size() != mpNewNames->size())
494 // The sizes differ. Something is wrong.
495 mpNewNames.reset();
498 ScUndoMoveTab::~ScUndoMoveTab()
502 OUString ScUndoMoveTab::GetComment() const
504 return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
507 void ScUndoMoveTab::DoChange( sal_Bool bUndo ) const
509 ScDocument* pDoc = pDocShell->GetDocument();
510 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
512 if (bUndo) // UnDo
514 size_t i = mpNewTabs->size();
515 ScProgress* pProgress = new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
516 i * pDoc->GetCodeCount());
517 for (; i > 0; --i)
519 SCTAB nDestTab = (*mpNewTabs)[i-1];
520 SCTAB nOldTab = (*mpOldTabs)[i-1];
521 if (nDestTab > MAXTAB) // appended ?
522 nDestTab = pDoc->GetTableCount() - 1;
524 pDoc->MoveTab( nDestTab, nOldTab, pProgress );
525 pViewShell->GetViewData()->MoveTab( nDestTab, nOldTab );
526 pViewShell->SetTabNo( nOldTab, true );
527 if (mpOldNames)
529 const OUString& rOldName = (*mpOldNames)[i-1];
530 pDoc->RenameTab(nOldTab, rOldName);
533 delete pProgress;
535 else
537 size_t n = mpNewTabs->size();
538 ScProgress* pProgress = new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
539 n * pDoc->GetCodeCount());
540 for (size_t i = 0; i < n; ++i)
542 SCTAB nDestTab = (*mpNewTabs)[i];
543 SCTAB nNewTab = nDestTab;
544 SCTAB nOldTab = (*mpOldTabs)[i];
545 if (nDestTab > MAXTAB) // appended ?
546 nDestTab = pDoc->GetTableCount() - 1;
548 pDoc->MoveTab( nOldTab, nNewTab, pProgress );
549 pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
550 pViewShell->SetTabNo( nDestTab, true );
551 if (mpNewNames)
553 const OUString& rNewName = (*mpNewNames)[i];
554 pDoc->RenameTab(nNewTab, rNewName);
557 delete pProgress;
560 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
562 pDocShell->PostPaintGridAll();
563 pDocShell->PostPaintExtras();
564 pDocShell->PostDataChanged();
567 void ScUndoMoveTab::Undo()
569 DoChange( sal_True );
572 void ScUndoMoveTab::Redo()
574 DoChange( false );
577 void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
579 // No Repeat ! ? !
582 bool ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
584 return false;
587 ScUndoCopyTab::ScUndoCopyTab(
588 ScDocShell* pNewDocShell,
589 vector<SCTAB>* pOldTabs, vector<SCTAB>* pNewTabs,
590 vector<OUString>* pNewNames) :
591 ScSimpleUndo( pNewDocShell ),
592 mpOldTabs(pOldTabs),
593 mpNewTabs(pNewTabs),
594 mpNewNames(pNewNames),
595 pDrawUndo( NULL )
597 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
599 if (mpNewNames && mpNewTabs->size() != mpNewNames->size())
600 // The sizes differ. Something is wrong.
601 mpNewNames.reset();
604 ScUndoCopyTab::~ScUndoCopyTab()
606 DeleteSdrUndoAction( pDrawUndo );
609 OUString ScUndoCopyTab::GetComment() const
611 return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
614 void ScUndoCopyTab::DoChange() const
616 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
618 if (pViewShell)
619 pViewShell->SetTabNo((*mpOldTabs)[0],true);
621 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
623 pDocShell->PostPaintGridAll();
624 pDocShell->PostPaintExtras();
625 pDocShell->PostDataChanged();
628 void ScUndoCopyTab::Undo()
630 ScDocument* pDoc = pDocShell->GetDocument();
632 DoSdrUndoAction( pDrawUndo, pDoc ); // before the sheets are deleted
634 vector<SCTAB>::const_reverse_iterator itr, itrEnd = mpNewTabs->rend();
635 for (itr = mpNewTabs->rbegin(); itr != itrEnd; ++itr)
637 SCTAB nDestTab = *itr;
638 if (nDestTab > MAXTAB) // append?
639 nDestTab = pDoc->GetTableCount() - 1;
641 bDrawIsInUndo = sal_True;
642 pDoc->DeleteTab(nDestTab);
643 bDrawIsInUndo = false;
646 // ScTablesHint broadcasts after all sheets have been deleted,
647 // so sheets and draw pages are in sync!
649 for (itr = mpNewTabs->rbegin(); itr != itrEnd; ++itr)
651 SCTAB nDestTab = *itr;
652 if (nDestTab > MAXTAB) // append?
653 nDestTab = pDoc->GetTableCount() - 1;
655 pDocShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nDestTab ) );
658 DoChange();
661 void ScUndoCopyTab::Redo()
663 ScDocument* pDoc = pDocShell->GetDocument();
664 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
666 SCTAB nDestTab = 0;
667 for (size_t i = 0, n = mpNewTabs->size(); i < n; ++i)
669 nDestTab = (*mpNewTabs)[i];
670 SCTAB nNewTab = nDestTab;
671 SCTAB nOldTab = (*mpOldTabs)[i];
672 if (nDestTab > MAXTAB) // appended ?
673 nDestTab = pDoc->GetTableCount() - 1;
675 bDrawIsInUndo = sal_True;
676 pDoc->CopyTab( nOldTab, nNewTab );
677 bDrawIsInUndo = false;
679 pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
681 SCTAB nAdjSource = nOldTab;
682 if ( nNewTab <= nOldTab )
683 ++nAdjSource; // new position of source table after CopyTab
685 if ( pDoc->IsScenario(nAdjSource) )
687 pDoc->SetScenario(nNewTab, sal_True );
688 OUString aComment;
689 Color aColor;
690 sal_uInt16 nScenFlags;
691 pDoc->GetScenarioData(nAdjSource, aComment, aColor, nScenFlags );
692 pDoc->SetScenarioData(nNewTab, aComment, aColor, nScenFlags );
693 sal_Bool bActive = pDoc->IsActiveScenario(nAdjSource);
694 pDoc->SetActiveScenario(nNewTab, bActive );
695 sal_Bool bVisible=pDoc->IsVisible(nAdjSource);
696 pDoc->SetVisible(nNewTab,bVisible );
699 if ( pDoc->IsTabProtected( nAdjSource ) )
700 pDoc->CopyTabProtection(nAdjSource, nNewTab);
702 if (mpNewNames)
704 const OUString& rName = (*mpNewNames)[i];
705 pDoc->RenameTab(nNewTab, rName);
709 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
711 pViewShell->SetTabNo( nDestTab, sal_True ); // after draw-undo
713 DoChange();
717 void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
719 // no Repeat ! ? !
722 bool ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
724 return false;
728 ScUndoTabColor::ScUndoTabColor(
729 ScDocShell* pNewDocShell, SCTAB nT, const Color& aOTabBgColor, const Color& aNTabBgColor) :
730 ScSimpleUndo( pNewDocShell )
732 ScUndoTabColorInfo aInfo(nT);
733 aInfo.maOldTabBgColor = aOTabBgColor;
734 aInfo.maNewTabBgColor = aNTabBgColor;
735 aTabColorList.push_back(aInfo);
738 ScUndoTabColor::ScUndoTabColor(
739 ScDocShell* pNewDocShell,
740 const ScUndoTabColorInfo::List& rUndoTabColorList) :
741 ScSimpleUndo(pNewDocShell),
742 aTabColorList(rUndoTabColorList)
746 ScUndoTabColor::~ScUndoTabColor()
750 OUString ScUndoTabColor::GetComment() const
752 if (aTabColorList.size() > 1)
753 return ScGlobal::GetRscString(STR_UNDO_SET_MULTI_TAB_BG_COLOR);
754 return ScGlobal::GetRscString(STR_UNDO_SET_TAB_BG_COLOR);
757 void ScUndoTabColor::DoChange(bool bUndoType) const
759 ScDocument* pDoc = pDocShell->GetDocument();
760 if (!pDoc)
761 return;
763 size_t nTabColorCount = aTabColorList.size();
764 for (size_t i = 0; i < nTabColorCount; ++i)
766 const ScUndoTabColorInfo& rTabColor = aTabColorList[i];
767 pDoc->SetTabBgColor(rTabColor.mnTabId,
768 bUndoType ? rTabColor.maOldTabBgColor : rTabColor.maNewTabBgColor);
771 pDocShell->PostPaintExtras();
772 ScDocShellModificator aModificator( *pDocShell );
773 aModificator.SetDocumentModified();
776 void ScUndoTabColor::Undo()
778 DoChange(true);
781 void ScUndoTabColor::Redo()
783 DoChange(false);
786 void ScUndoTabColor::Repeat(SfxRepeatTarget& /* rTarget */)
788 // makes no sense
791 bool ScUndoTabColor::CanRepeat(SfxRepeatTarget& /* rTarget */) const
793 return false;
796 ScUndoMakeScenario::ScUndoMakeScenario( ScDocShell* pNewDocShell,
797 SCTAB nSrc, SCTAB nDest,
798 const OUString& rN, const OUString& rC,
799 const Color& rCol, sal_uInt16 nF,
800 const ScMarkData& rMark ) :
801 ScSimpleUndo( pNewDocShell ),
802 mpMarkData(new ScMarkData(rMark)),
803 nSrcTab( nSrc ),
804 nDestTab( nDest ),
805 aName( rN ),
806 aComment( rC ),
807 aColor( rCol ),
808 nFlags( nF ),
809 pDrawUndo( NULL )
811 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
814 ScUndoMakeScenario::~ScUndoMakeScenario()
816 DeleteSdrUndoAction( pDrawUndo );
819 OUString ScUndoMakeScenario::GetComment() const
821 return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
824 void ScUndoMakeScenario::Undo()
826 ScDocument* pDoc = pDocShell->GetDocument();
828 pDocShell->SetInUndo( sal_True );
829 bDrawIsInUndo = sal_True;
830 pDoc->DeleteTab( nDestTab );
831 bDrawIsInUndo = false;
832 pDocShell->SetInUndo( false );
834 DoSdrUndoAction( pDrawUndo, pDoc );
836 pDocShell->PostPaint(0,0,nDestTab,MAXCOL,MAXROW,MAXTAB, PAINT_ALL);
837 pDocShell->PostDataChanged();
839 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
840 if (pViewShell)
841 pViewShell->SetTabNo( nSrcTab, sal_True );
843 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
845 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
846 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
849 void ScUndoMakeScenario::Redo()
851 SetViewMarkData(*mpMarkData);
853 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
855 pDocShell->SetInUndo( sal_True );
856 bDrawIsInUndo = sal_True;
858 pDocShell->MakeScenario( nSrcTab, aName, aComment, aColor, nFlags, *mpMarkData, false );
860 bDrawIsInUndo = false;
861 pDocShell->SetInUndo( false );
863 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
864 if (pViewShell)
865 pViewShell->SetTabNo( nDestTab, sal_True );
867 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
870 void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
872 if (rTarget.ISA(ScTabViewTarget))
874 ((ScTabViewTarget&)rTarget).GetViewShell()->MakeScenario( aName, aComment, aColor, nFlags );
878 bool ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
880 return rTarget.ISA(ScTabViewTarget);
883 ScUndoImportTab::ScUndoImportTab( ScDocShell* pShell,
884 SCTAB nNewTab, SCTAB nNewCount ) :
885 ScSimpleUndo( pShell ),
886 nTab( nNewTab ),
887 nCount( nNewCount ),
888 pRedoDoc( NULL ),
889 pDrawUndo( NULL )
891 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
894 ScUndoImportTab::~ScUndoImportTab()
896 delete pRedoDoc;
897 DeleteSdrUndoAction( pDrawUndo );
900 OUString ScUndoImportTab::GetComment() const
902 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
905 void ScUndoImportTab::DoChange() const
907 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
908 ScDocument* pDoc = pDocShell->GetDocument();
909 SCTAB nTabCount = pDoc->GetTableCount();
910 if (pViewShell)
912 if(nTab<nTabCount)
914 pViewShell->SetTabNo(nTab,sal_True);
916 else
918 pViewShell->SetTabNo(nTab-1,sal_True);
922 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
923 pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB,
924 PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
927 void ScUndoImportTab::Undo()
929 // Inserted range names, etc.
931 SCTAB i;
932 ScDocument* pDoc = pDocShell->GetDocument();
933 sal_Bool bMakeRedo = !pRedoDoc;
934 if (bMakeRedo)
936 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
937 pRedoDoc->InitUndo( pDoc, nTab,nTab+nCount-1, sal_True,sal_True );
939 OUString aOldName;
940 for (i=0; i<nCount; i++)
942 SCTAB nTabPos=nTab+i;
944 pDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,false, pRedoDoc );
945 pDoc->GetName( nTabPos, aOldName );
946 pRedoDoc->RenameTab( nTabPos, aOldName, false );
947 pRedoDoc->SetTabBgColor( nTabPos, pDoc->GetTabBgColor(nTabPos) );
949 if ( pDoc->IsScenario(nTabPos) )
951 pRedoDoc->SetScenario(nTabPos, sal_True );
952 OUString aComment;
953 Color aColor;
954 sal_uInt16 nScenFlags;
955 pDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
956 pRedoDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
957 sal_Bool bActive = pDoc->IsActiveScenario(nTabPos);
958 pRedoDoc->SetActiveScenario(nTabPos, bActive );
959 sal_Bool bVisible=pDoc->IsVisible(nTabPos);
960 pRedoDoc->SetVisible(nTabPos,bVisible );
963 if ( pDoc->IsTabProtected( nTabPos ) )
964 pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
969 DoSdrUndoAction( pDrawUndo, pDoc ); // before the sheets are deleted
971 bDrawIsInUndo = sal_True;
972 for (i=0; i<nCount; i++)
973 pDoc->DeleteTab( nTab );
974 bDrawIsInUndo = false;
976 DoChange();
979 void ScUndoImportTab::Redo()
981 if (!pRedoDoc)
983 OSL_FAIL("Where is my Redo Document?");
984 return;
987 ScDocument* pDoc = pDocShell->GetDocument();
988 OUString aName;
989 SCTAB i;
990 for (i=0; i<nCount; i++) // first insert all sheets (#63304#)
992 SCTAB nTabPos=nTab+i;
993 pRedoDoc->GetName(nTabPos,aName);
994 bDrawIsInUndo = sal_True;
995 pDoc->InsertTab(nTabPos,aName);
996 bDrawIsInUndo = false;
998 for (i=0; i<nCount; i++) // then copy into inserted sheets
1000 SCTAB nTabPos=nTab+i;
1001 pRedoDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,false, pDoc );
1002 pDoc->SetTabBgColor( nTabPos, pRedoDoc->GetTabBgColor(nTabPos) );
1004 if ( pRedoDoc->IsScenario(nTabPos) )
1006 pDoc->SetScenario(nTabPos, sal_True );
1007 OUString aComment;
1008 Color aColor;
1009 sal_uInt16 nScenFlags;
1010 pRedoDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1011 pDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1012 sal_Bool bActive = pRedoDoc->IsActiveScenario(nTabPos);
1013 pDoc->SetActiveScenario(nTabPos, bActive );
1014 sal_Bool bVisible=pRedoDoc->IsVisible(nTabPos);
1015 pDoc->SetVisible(nTabPos,bVisible );
1018 if ( pRedoDoc->IsTabProtected( nTabPos ) )
1019 pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
1022 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
1024 DoChange();
1027 void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
1029 if (rTarget.ISA(ScTabViewTarget))
1030 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1031 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1034 bool ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
1036 return rTarget.ISA(ScTabViewTarget);
1039 ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const OUString& rDoc ) :
1040 ScSimpleUndo( pShell ),
1041 aDocName( rDoc ),
1042 nRefreshDelay( 0 ),
1043 nCount( 0 )
1045 ScDocument* pDoc = pDocShell->GetDocument();
1046 SCTAB nTabCount = pDoc->GetTableCount();
1047 pTabs = new SCTAB[nTabCount];
1048 pModes = new sal_uInt8[nTabCount];
1049 pTabNames = new OUString[nTabCount];
1051 for (SCTAB i=0; i<nTabCount; i++)
1053 sal_uInt8 nMode = pDoc->GetLinkMode(i);
1054 if (nMode)
1055 if (pDoc->GetLinkDoc(i) == aDocName)
1057 if (!nCount)
1059 aFltName = pDoc->GetLinkFlt(i);
1060 aOptions = pDoc->GetLinkOpt(i);
1061 nRefreshDelay = pDoc->GetLinkRefreshDelay(i);
1063 else
1065 OSL_ENSURE(OUString(aFltName) == pDoc->GetLinkFlt(i) &&
1066 OUString(aOptions) == pDoc->GetLinkOpt(i),
1067 "different Filter for a Document?");
1069 pTabs[nCount] = i;
1070 pModes[nCount] = nMode;
1071 pTabNames[nCount] = pDoc->GetLinkTab(i);
1072 ++nCount;
1077 ScUndoRemoveLink::~ScUndoRemoveLink()
1079 delete pTabs;
1080 delete pModes;
1081 delete[] pTabNames;
1084 OUString ScUndoRemoveLink::GetComment() const
1086 return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
1089 void ScUndoRemoveLink::DoChange( sal_Bool bLink ) const
1091 ScDocument* pDoc = pDocShell->GetDocument();
1092 OUString aEmpty;
1093 for (sal_uInt16 i=0; i<nCount; i++)
1094 if (bLink) // establish link
1095 pDoc->SetLink( pTabs[i], pModes[i], aDocName, aFltName, aOptions, pTabNames[i], nRefreshDelay );
1096 else // remove link
1097 pDoc->SetLink( pTabs[i], SC_LINK_NONE, aEmpty, aEmpty, aEmpty, aEmpty, 0 );
1098 pDocShell->UpdateLinks();
1101 void ScUndoRemoveLink::Undo()
1103 DoChange( sal_True );
1106 void ScUndoRemoveLink::Redo()
1108 DoChange( false );
1111 void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
1113 // makes no sense
1116 bool ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1118 return false;
1121 ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, const std::vector<SCTAB>& newUndoTabs, sal_Bool bNewShow ) :
1122 ScSimpleUndo( pShell ),
1123 undoTabs( newUndoTabs ),
1124 bShow( bNewShow )
1128 ScUndoShowHideTab::~ScUndoShowHideTab()
1132 void ScUndoShowHideTab::DoChange( sal_Bool bShowP ) const
1134 ScDocument* pDoc = pDocShell->GetDocument();
1135 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1137 SCTAB nTab;
1139 for(std::vector<SCTAB>::const_iterator itr = undoTabs.begin(), itrEnd = undoTabs.end(); itr != itrEnd; ++itr)
1141 nTab = *itr;
1142 pDoc->SetVisible( nTab, bShowP );
1143 if (pViewShell)
1144 pViewShell->SetTabNo(nTab,sal_True);
1147 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1148 pDocShell->SetDocumentModified();
1151 void ScUndoShowHideTab::Undo()
1153 DoChange(!bShow);
1156 void ScUndoShowHideTab::Redo()
1158 DoChange(bShow);
1161 void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
1163 if (rTarget.ISA(ScTabViewTarget))
1164 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1165 Execute( bShow ? FID_TABLE_SHOW : FID_TABLE_HIDE,
1166 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1169 bool ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
1171 return rTarget.ISA(ScTabViewTarget);
1174 OUString ScUndoShowHideTab::GetComment() const
1176 sal_uInt16 nId;
1177 if (undoTabs.size() > 1)
1179 nId = bShow ? STR_UNDO_SHOWTABS : STR_UNDO_HIDETABS;
1181 else
1183 nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
1186 return ScGlobal::GetRscString( nId );
1189 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1190 ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
1191 ScSimpleUndo(pShell),
1192 mpProtectSettings(pProtectSettings)
1195 SAL_WNODEPRECATED_DECLARATIONS_POP
1197 ScUndoDocProtect::~ScUndoDocProtect()
1201 void ScUndoDocProtect::DoProtect(bool bProtect)
1203 ScDocument* pDoc = pDocShell->GetDocument();
1205 if (bProtect)
1207 // set protection.
1208 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1209 auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
1210 SAL_WNODEPRECATED_DECLARATIONS_POP
1211 pCopy->setProtected(true);
1212 pDoc->SetDocProtection(pCopy.get());
1214 else
1216 // remove protection.
1217 pDoc->SetDocProtection(NULL);
1220 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1221 if (pViewShell)
1223 pViewShell->UpdateLayerLocks();
1224 pViewShell->UpdateInputHandler(sal_True); // so that input can be immediately entered again
1227 pDocShell->PostPaintGridAll();
1230 void ScUndoDocProtect::Undo()
1232 BeginUndo();
1233 DoProtect(!mpProtectSettings->isProtected());
1234 EndUndo();
1237 void ScUndoDocProtect::Redo()
1239 BeginRedo();
1240 DoProtect(mpProtectSettings->isProtected());
1241 EndRedo();
1244 void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1246 // makes no sense
1249 bool ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1251 return false; // makes no sense
1254 OUString ScUndoDocProtect::GetComment() const
1256 sal_uInt16 nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
1257 return ScGlobal::GetRscString( nId );
1260 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1261 ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
1262 ScSimpleUndo(pShell),
1263 mnTab(nTab),
1264 mpProtectSettings(pProtectSettings)
1267 SAL_WNODEPRECATED_DECLARATIONS_POP
1269 ScUndoTabProtect::~ScUndoTabProtect()
1273 void ScUndoTabProtect::DoProtect(bool bProtect)
1275 ScDocument* pDoc = pDocShell->GetDocument();
1277 if (bProtect)
1279 // set protection.
1280 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1281 auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
1282 SAL_WNODEPRECATED_DECLARATIONS_POP
1283 pCopy->setProtected(true);
1284 pDoc->SetTabProtection(mnTab, pCopy.get());
1286 else
1288 // remove protection.
1289 pDoc->SetTabProtection(mnTab, NULL);
1292 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1293 if (pViewShell)
1295 pViewShell->UpdateLayerLocks();
1296 pViewShell->UpdateInputHandler(sal_True); // so that input can be immediately entered again
1299 pDocShell->PostPaintGridAll();
1302 void ScUndoTabProtect::Undo()
1304 BeginUndo();
1305 DoProtect(!mpProtectSettings->isProtected());
1306 EndUndo();
1309 void ScUndoTabProtect::Redo()
1311 BeginRedo();
1312 DoProtect(mpProtectSettings->isProtected());
1313 EndRedo();
1316 void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1318 // makes no sense
1321 bool ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1323 return false; // makes no sense
1326 OUString ScUndoTabProtect::GetComment() const
1328 sal_uInt16 nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
1329 return ScGlobal::GetRscString( nId );
1332 ScUndoPrintRange::ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
1333 ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew ) :
1334 ScSimpleUndo( pShell ),
1335 nTab( nNewTab ),
1336 pOldRanges( pOld ),
1337 pNewRanges( pNew )
1341 ScUndoPrintRange::~ScUndoPrintRange()
1343 delete pOldRanges;
1344 delete pNewRanges;
1347 void ScUndoPrintRange::DoChange(sal_Bool bUndo)
1349 ScDocument* pDoc = pDocShell->GetDocument();
1350 if (bUndo)
1351 pDoc->RestorePrintRanges( *pOldRanges );
1352 else
1353 pDoc->RestorePrintRanges( *pNewRanges );
1355 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1356 if (pViewShell)
1357 pViewShell->SetTabNo( nTab );
1359 ScPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ).UpdatePages();
1361 pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
1364 void ScUndoPrintRange::Undo()
1366 BeginUndo();
1367 DoChange( sal_True );
1368 EndUndo();
1371 void ScUndoPrintRange::Redo()
1373 BeginRedo();
1374 DoChange( false );
1375 EndRedo();
1378 void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
1380 // makes no sense
1383 bool ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1385 return false; // makes no sense
1388 OUString ScUndoPrintRange::GetComment() const
1390 return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
1393 ScUndoScenarioFlags::ScUndoScenarioFlags( ScDocShell* pNewDocShell, SCTAB nT,
1394 const OUString& rON, const OUString& rNN, const OUString& rOC, const OUString& rNC,
1395 const Color& rOCol, const Color& rNCol, sal_uInt16 nOF, sal_uInt16 nNF ) :
1396 ScSimpleUndo( pNewDocShell ),
1397 nTab ( nT ),
1398 aOldName ( rON ),
1399 aNewName ( rNN ),
1400 aOldComment ( rOC ),
1401 aNewComment ( rNC ),
1402 aOldColor ( rOCol ),
1403 aNewColor ( rNCol ),
1404 nOldFlags ( nOF ),
1405 nNewFlags ( nNF )
1409 ScUndoScenarioFlags::~ScUndoScenarioFlags()
1413 OUString ScUndoScenarioFlags::GetComment() const
1415 return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
1418 void ScUndoScenarioFlags::Undo()
1420 ScDocument* pDoc = pDocShell->GetDocument();
1422 pDoc->RenameTab( nTab, aOldName );
1423 pDoc->SetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
1425 pDocShell->PostPaintGridAll();
1426 // The sheet name might be used in a formula ...
1427 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1428 if (pViewShell)
1429 pViewShell->UpdateInputHandler();
1431 if ( aOldName != aNewName )
1432 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1435 void ScUndoScenarioFlags::Redo()
1437 ScDocument* pDoc = pDocShell->GetDocument();
1439 pDoc->RenameTab( nTab, aNewName );
1440 pDoc->SetScenarioData( nTab, aNewComment, aNewColor, nNewFlags );
1442 pDocShell->PostPaintGridAll();
1443 // The sheet name might be used in a formula ...
1444 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1445 if (pViewShell)
1446 pViewShell->UpdateInputHandler();
1448 if ( aOldName != aNewName )
1449 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1452 void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
1454 // Repeat makes no sense
1457 bool ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1459 return false;
1462 // (move to different file?)
1463 ScUndoRenameObject::ScUndoRenameObject( ScDocShell* pNewDocShell, const OUString& rPN,
1464 const OUString& rON, const OUString& rNN ) :
1465 ScSimpleUndo( pNewDocShell ),
1466 aPersistName( rPN ),
1467 aOldName ( rON ),
1468 aNewName ( rNN )
1472 ScUndoRenameObject::~ScUndoRenameObject()
1476 OUString ScUndoRenameObject::GetComment() const
1478 // string resource shared with title for dialog
1479 return OUString( ScResId(SCSTR_RENAMEOBJECT) );
1482 SdrObject* ScUndoRenameObject::GetObject()
1484 ScDocument* pDoc = pDocShell->GetDocument();
1485 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1486 if ( pDrawLayer )
1488 sal_uInt16 nCount = pDrawLayer->GetPageCount();
1489 for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1491 SdrPage* pPage = pDrawLayer->GetPage(nTab);
1492 OSL_ENSURE(pPage,"Page ?");
1494 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
1495 SdrObject* pObject = aIter.Next();
1496 while (pObject)
1498 if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
1499 ((SdrOle2Obj*)pObject)->GetPersistName() == aPersistName )
1501 return pObject;
1504 pObject = aIter.Next();
1508 OSL_FAIL("Object not found");
1509 return NULL;
1512 void ScUndoRenameObject::Undo()
1514 BeginUndo();
1515 SdrObject* pObj = GetObject();
1516 if ( pObj )
1517 pObj->SetName( aOldName );
1518 EndUndo();
1521 void ScUndoRenameObject::Redo()
1523 BeginRedo();
1524 SdrObject* pObj = GetObject();
1525 if ( pObj )
1526 pObj->SetName( aNewName );
1527 EndRedo();
1530 void ScUndoRenameObject::Repeat(SfxRepeatTarget& /* rTarget */)
1534 bool ScUndoRenameObject::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1536 return false;
1539 ScUndoLayoutRTL::ScUndoLayoutRTL( ScDocShell* pShell, SCTAB nNewTab, sal_Bool bNewRTL ) :
1540 ScSimpleUndo( pShell ),
1541 nTab( nNewTab ),
1542 bRTL( bNewRTL )
1546 ScUndoLayoutRTL::~ScUndoLayoutRTL()
1550 void ScUndoLayoutRTL::DoChange( sal_Bool bNew )
1552 pDocShell->SetInUndo( sal_True );
1554 ScDocument* pDoc = pDocShell->GetDocument();
1555 pDoc->SetLayoutRTL( nTab, bNew );
1557 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1558 if (pViewShell)
1559 pViewShell->SetTabNo(nTab,sal_True);
1561 pDocShell->SetDocumentModified();
1563 pDocShell->SetInUndo( false );
1566 void ScUndoLayoutRTL::Undo()
1568 DoChange(!bRTL);
1571 void ScUndoLayoutRTL::Redo()
1573 DoChange(bRTL);
1576 void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
1578 if (rTarget.ISA(ScTabViewTarget))
1579 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1580 Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1583 bool ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
1585 return rTarget.ISA(ScTabViewTarget);
1588 OUString ScUndoLayoutRTL::GetComment() const
1590 return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
1593 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */