fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / undotab.cxx
blobdb8d941a90b45bf5cb80846f71d144b8d76d7904
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 <utility>
51 #include <vector>
52 #include <boost/scoped_ptr.hpp>
54 extern bool bDrawIsInUndo; // somewhere as member!
56 using namespace com::sun::star;
57 using ::com::sun::star::uno::Sequence;
58 using ::std::unique_ptr;
59 using ::std::vector;
60 using ::boost::shared_ptr;
62 TYPEINIT1(ScUndoInsertTab, SfxUndoAction);
63 TYPEINIT1(ScUndoInsertTables, SfxUndoAction);
64 TYPEINIT1(ScUndoDeleteTab, SfxUndoAction);
65 TYPEINIT1(ScUndoRenameTab, SfxUndoAction);
66 TYPEINIT1(ScUndoMoveTab, SfxUndoAction);
67 TYPEINIT1(ScUndoCopyTab, SfxUndoAction);
68 TYPEINIT1(ScUndoMakeScenario, SfxUndoAction);
69 TYPEINIT1(ScUndoImportTab, SfxUndoAction);
70 TYPEINIT1(ScUndoRemoveLink, SfxUndoAction);
71 TYPEINIT1(ScUndoShowHideTab, SfxUndoAction);
72 TYPEINIT1(ScUndoPrintRange, SfxUndoAction);
73 TYPEINIT1(ScUndoScenarioFlags, SfxUndoAction);
74 TYPEINIT1(ScUndoRenameObject, SfxUndoAction);
75 TYPEINIT1(ScUndoLayoutRTL, SfxUndoAction);
76 TYPEINIT1(ScUndoTabColor, SfxUndoAction);
78 ScUndoInsertTab::ScUndoInsertTab( ScDocShell* pNewDocShell,
79 SCTAB nTabNum,
80 bool bApp,
81 const OUString& rNewName) :
82 ScSimpleUndo( pNewDocShell ),
83 sNewName( rNewName ),
84 pDrawUndo( NULL ),
85 nTab( nTabNum ),
86 bAppend( bApp )
88 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
89 SetChangeTrack();
92 ScUndoInsertTab::~ScUndoInsertTab()
94 DeleteSdrUndoAction( pDrawUndo );
97 OUString ScUndoInsertTab::GetComment() const
99 if (bAppend)
100 return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
101 else
102 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
105 void ScUndoInsertTab::SetChangeTrack()
107 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
108 if ( pChangeTrack )
110 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
111 pChangeTrack->AppendInsert( aRange );
112 nEndChangeAction = pChangeTrack->GetActionMax();
114 else
115 nEndChangeAction = 0;
118 void ScUndoInsertTab::Undo()
120 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
121 pViewShell->SetTabNo(nTab);
123 pDocShell->SetInUndo( true ); //! BeginUndo
124 bDrawIsInUndo = true;
125 pViewShell->DeleteTable( nTab, false );
126 bDrawIsInUndo = false;
127 pDocShell->SetInUndo( false ); //! EndUndo
129 DoSdrUndoAction( pDrawUndo, &pDocShell->GetDocument() );
131 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
132 if ( pChangeTrack )
133 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
135 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
136 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
139 void ScUndoInsertTab::Redo()
141 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
143 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
145 pDocShell->SetInUndo( true ); //! BeginRedo
146 bDrawIsInUndo = true;
147 if (bAppend)
148 pViewShell->AppendTable( sNewName, false );
149 else
151 pViewShell->SetTabNo(nTab);
152 pViewShell->InsertTable( sNewName, nTab, false );
154 bDrawIsInUndo = false;
155 pDocShell->SetInUndo( false ); //! EndRedo
157 SetChangeTrack();
160 void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
162 if (rTarget.ISA(ScTabViewTarget))
163 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData().GetDispatcher().
164 Execute(FID_INS_TABLE, SfxCallMode::SLOT | SfxCallMode::RECORD);
167 bool ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
169 return rTarget.ISA(ScTabViewTarget);
172 ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
173 SCTAB nTabNum,
174 std::vector<OUString>& newNameList) :
175 ScSimpleUndo( pNewDocShell ),
176 pDrawUndo( NULL ),
177 aNameList( newNameList ),
178 nTab( nTabNum )
180 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
182 SetChangeTrack();
185 ScUndoInsertTables::~ScUndoInsertTables()
187 DeleteSdrUndoAction( pDrawUndo );
190 OUString ScUndoInsertTables::GetComment() const
192 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
195 void ScUndoInsertTables::SetChangeTrack()
197 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
198 if ( pChangeTrack )
200 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
201 nEndChangeAction = 0;
202 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
203 for( size_t i = 0; i < aNameList.size(); i++ )
205 aRange.aStart.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
206 aRange.aEnd.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
207 pChangeTrack->AppendInsert( aRange );
208 nEndChangeAction = pChangeTrack->GetActionMax();
211 else
212 nStartChangeAction = nEndChangeAction = 0;
215 void ScUndoInsertTables::Undo()
217 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
218 pViewShell->SetTabNo(nTab);
220 pDocShell->SetInUndo( true ); //! BeginUndo
221 bDrawIsInUndo = true;
223 pViewShell->DeleteTables( nTab, static_cast<SCTAB>(aNameList.size()) );
225 bDrawIsInUndo = false;
226 pDocShell->SetInUndo( false ); //! EndUndo
228 DoSdrUndoAction( pDrawUndo, &pDocShell->GetDocument() );
230 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
231 if ( pChangeTrack )
232 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
234 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
235 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
238 void ScUndoInsertTables::Redo()
240 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
242 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
244 pDocShell->SetInUndo( true ); //! BeginRedo
245 bDrawIsInUndo = true;
246 pViewShell->SetTabNo(nTab);
247 pViewShell->InsertTables( aNameList, nTab, static_cast<SCTAB>(aNameList.size()),false );
249 bDrawIsInUndo = false;
250 pDocShell->SetInUndo( false ); //! EndRedo
252 SetChangeTrack();
255 void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
257 if (rTarget.ISA(ScTabViewTarget))
258 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData().GetDispatcher().
259 Execute(FID_INS_TABLE, SfxCallMode::SLOT | SfxCallMode::RECORD);
262 bool ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
264 return rTarget.ISA(ScTabViewTarget);
267 ScUndoDeleteTab::ScUndoDeleteTab( ScDocShell* pNewDocShell, const vector<SCTAB> &aTab,
268 ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
269 ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST )
271 theTabs.insert(theTabs.end(), aTab.begin(), aTab.end() );
272 SetChangeTrack();
275 ScUndoDeleteTab::~ScUndoDeleteTab()
277 theTabs.clear();
280 OUString ScUndoDeleteTab::GetComment() const
282 return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
285 void ScUndoDeleteTab::SetChangeTrack()
287 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
288 if ( pChangeTrack )
290 sal_uLong nTmpChangeAction;
291 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
292 nEndChangeAction = 0;
293 ScRange aRange( 0, 0, 0, MAXCOL, MAXROW, 0 );
294 for ( unsigned int i = 0; i < theTabs.size(); ++i )
296 aRange.aStart.SetTab( theTabs[i] );
297 aRange.aEnd.SetTab( theTabs[i] );
298 pChangeTrack->AppendDeleteRange( aRange, pRefUndoDoc,
299 nTmpChangeAction, nEndChangeAction, (short) i );
302 else
303 nStartChangeAction = nEndChangeAction = 0;
306 static SCTAB lcl_GetVisibleTabBefore( ScDocument& rDoc, SCTAB nTab )
308 while ( nTab > 0 && !rDoc.IsVisible( nTab ) )
309 --nTab;
311 return nTab;
314 void ScUndoDeleteTab::Undo()
316 BeginUndo();
317 unsigned int i=0;
318 ScDocument& rDoc = pDocShell->GetDocument();
320 bool bLink = false;
321 OUString aName;
323 for(i=0; i<theTabs.size(); ++i)
325 SCTAB nTab = theTabs[i];
326 pRefUndoDoc->GetName( nTab, aName );
328 bDrawIsInUndo = true;
329 bool bOk = rDoc.InsertTab(nTab, aName, false, true);
330 bDrawIsInUndo = false;
331 if (bOk)
333 pRefUndoDoc->CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,false, &rDoc );
335 OUString aOldName;
336 pRefUndoDoc->GetName( nTab, aOldName );
337 rDoc.RenameTab( nTab, aOldName, false );
338 if (pRefUndoDoc->IsLinked(nTab))
340 rDoc.SetLink( nTab, pRefUndoDoc->GetLinkMode(nTab), pRefUndoDoc->GetLinkDoc(nTab),
341 pRefUndoDoc->GetLinkFlt(nTab), pRefUndoDoc->GetLinkOpt(nTab),
342 pRefUndoDoc->GetLinkTab(nTab), pRefUndoDoc->GetLinkRefreshDelay(nTab) );
343 bLink = true;
346 if ( pRefUndoDoc->IsScenario(nTab) )
348 rDoc.SetScenario( nTab, true );
349 OUString aComment;
350 Color aColor;
351 sal_uInt16 nScenFlags;
352 pRefUndoDoc->GetScenarioData( nTab, aComment, aColor, nScenFlags );
353 rDoc.SetScenarioData( nTab, aComment, aColor, nScenFlags );
354 bool bActive = pRefUndoDoc->IsActiveScenario( nTab );
355 rDoc.SetActiveScenario( nTab, bActive );
357 rDoc.SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
358 rDoc.SetTabBgColor( nTab, pRefUndoDoc->GetTabBgColor(nTab) );
359 rDoc.SetSheetEvents( nTab, pRefUndoDoc->GetSheetEvents( nTab ) );
360 rDoc.SetLayoutRTL( nTab, pRefUndoDoc->IsLayoutRTL( nTab ) );
362 if ( pRefUndoDoc->IsTabProtected( nTab ) )
363 rDoc.SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
366 if (bLink)
368 pDocShell->UpdateLinks(); // update Link Manager
371 EndUndo(); // Draw-Undo has to be called before Broadcast!
373 ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
374 if ( pChangeTrack )
375 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
377 for(i=0; i<theTabs.size(); ++i)
379 pDocShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, theTabs[i]) );
381 SfxApplication* pSfxApp = SfxGetpApp(); // Navigator
382 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
383 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
384 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
386 pDocShell->PostPaint(0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_ALL ); // incl. extras
388 // not ShowTable due to SetTabNo(..., sal_True):
389 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
390 if (pViewShell)
391 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( rDoc, theTabs[0] ), true );
394 void ScUndoDeleteTab::Redo()
396 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
397 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( pDocShell->GetDocument(), theTabs.front() ) );
399 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
401 pDocShell->SetInUndo( true ); //! BeginRedo
402 bDrawIsInUndo = true;
403 pViewShell->DeleteTables( theTabs, false );
404 bDrawIsInUndo = false;
405 pDocShell->SetInUndo( true ); //! EndRedo
407 SetChangeTrack();
409 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
410 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
413 void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
415 if (rTarget.ISA(ScTabViewTarget))
417 ScTabViewShell* pViewShell = static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
418 pViewShell->DeleteTable( pViewShell->GetViewData().GetTabNo(), true );
422 bool ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
424 return rTarget.ISA(ScTabViewTarget);
427 ScUndoRenameTab::ScUndoRenameTab( ScDocShell* pNewDocShell,
428 SCTAB nT,
429 const OUString& rOldName,
430 const OUString& rNewName) :
431 ScSimpleUndo( pNewDocShell ),
432 nTab ( nT )
434 sOldName = rOldName;
435 sNewName = rNewName;
438 ScUndoRenameTab::~ScUndoRenameTab()
442 OUString ScUndoRenameTab::GetComment() const
444 return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
447 void ScUndoRenameTab::DoChange( SCTAB nTabP, const OUString& rName ) const
449 ScDocument& rDoc = pDocShell->GetDocument();
450 rDoc.RenameTab( nTabP, rName );
452 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
454 pDocShell->PostPaintGridAll();
455 pDocShell->PostPaintExtras();
456 pDocShell->PostDataChanged();
458 // The sheet name might be used in a formula ...
459 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
460 if (pViewShell)
461 pViewShell->UpdateInputHandler();
464 void ScUndoRenameTab::Undo()
466 DoChange(nTab, sOldName);
469 void ScUndoRenameTab::Redo()
471 DoChange(nTab, sNewName);
474 void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
476 // makes no sense
479 bool ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
481 return false;
484 ScUndoMoveTab::ScUndoMoveTab(
485 ScDocShell* pNewDocShell, vector<SCTAB>* pOldTabs, vector<SCTAB>* pNewTabs,
486 vector<OUString>* pOldNames, vector<OUString>* pNewNames) :
487 ScSimpleUndo( pNewDocShell ),
488 mpOldTabs(pOldTabs), mpNewTabs(pNewTabs),
489 mpOldNames(pOldNames), mpNewNames(pNewNames)
491 if (mpOldNames && mpOldTabs->size() != mpOldNames->size())
492 // The sizes differ. Something is wrong.
493 mpOldNames.reset();
495 if (mpNewNames && mpNewTabs->size() != mpNewNames->size())
496 // The sizes differ. Something is wrong.
497 mpNewNames.reset();
500 ScUndoMoveTab::~ScUndoMoveTab()
504 OUString ScUndoMoveTab::GetComment() const
506 return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
509 void ScUndoMoveTab::DoChange( bool bUndo ) const
511 ScDocument& rDoc = pDocShell->GetDocument();
512 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
514 if (bUndo) // UnDo
516 size_t i = mpNewTabs->size();
517 boost::scoped_ptr<ScProgress> pProgress(new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
518 i * rDoc.GetCodeCount()));
519 for (; i > 0; --i)
521 SCTAB nDestTab = (*mpNewTabs)[i-1];
522 SCTAB nOldTab = (*mpOldTabs)[i-1];
523 if (nDestTab > MAXTAB) // appended ?
524 nDestTab = rDoc.GetTableCount() - 1;
526 rDoc.MoveTab( nDestTab, nOldTab, pProgress.get() );
527 pViewShell->GetViewData().MoveTab( nDestTab, nOldTab );
528 pViewShell->SetTabNo( nOldTab, true );
529 if (mpOldNames)
531 const OUString& rOldName = (*mpOldNames)[i-1];
532 rDoc.RenameTab(nOldTab, rOldName);
536 else
538 size_t n = mpNewTabs->size();
539 boost::scoped_ptr<ScProgress> pProgress(new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
540 n * rDoc.GetCodeCount()));
541 for (size_t i = 0; i < n; ++i)
543 SCTAB nDestTab = (*mpNewTabs)[i];
544 SCTAB nNewTab = nDestTab;
545 SCTAB nOldTab = (*mpOldTabs)[i];
546 if (nDestTab > MAXTAB) // appended ?
547 nDestTab = rDoc.GetTableCount() - 1;
549 rDoc.MoveTab( nOldTab, nNewTab, pProgress.get() );
550 pViewShell->GetViewData().MoveTab( nOldTab, nNewTab );
551 pViewShell->SetTabNo( nDestTab, true );
552 if (mpNewNames)
554 const OUString& rNewName = (*mpNewNames)[i];
555 rDoc.RenameTab(nNewTab, rNewName);
560 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
562 pDocShell->PostPaintGridAll();
563 pDocShell->PostPaintExtras();
564 pDocShell->PostDataChanged();
567 void ScUndoMoveTab::Undo()
569 DoChange( 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 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
623 pDocShell->PostPaintGridAll();
624 pDocShell->PostPaintExtras();
625 pDocShell->PostDataChanged();
628 void ScUndoCopyTab::Undo()
630 ScDocument& rDoc = pDocShell->GetDocument();
632 DoSdrUndoAction( pDrawUndo, &rDoc ); // 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 = rDoc.GetTableCount() - 1;
641 bDrawIsInUndo = true;
642 rDoc.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 = rDoc.GetTableCount() - 1;
655 pDocShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nDestTab ) );
658 DoChange();
661 void ScUndoCopyTab::Redo()
663 ScDocument& rDoc = 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 = rDoc.GetTableCount() - 1;
675 bDrawIsInUndo = true;
676 rDoc.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 ( rDoc.IsScenario(nAdjSource) )
687 rDoc.SetScenario(nNewTab, true );
688 OUString aComment;
689 Color aColor;
690 sal_uInt16 nScenFlags;
691 rDoc.GetScenarioData(nAdjSource, aComment, aColor, nScenFlags );
692 rDoc.SetScenarioData(nNewTab, aComment, aColor, nScenFlags );
693 bool bActive = rDoc.IsActiveScenario(nAdjSource);
694 rDoc.SetActiveScenario(nNewTab, bActive );
695 bool bVisible = rDoc.IsVisible(nAdjSource);
696 rDoc.SetVisible(nNewTab,bVisible );
699 if ( rDoc.IsTabProtected( nAdjSource ) )
700 rDoc.CopyTabProtection(nAdjSource, nNewTab);
702 if (mpNewNames)
704 const OUString& rName = (*mpNewNames)[i];
705 rDoc.RenameTab(nNewTab, rName);
709 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
711 pViewShell->SetTabNo( nDestTab, 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;
727 ScUndoTabColor::ScUndoTabColor(
728 ScDocShell* pNewDocShell, SCTAB nT, const Color& aOTabBgColor, const Color& aNTabBgColor) :
729 ScSimpleUndo( pNewDocShell )
731 ScUndoTabColorInfo aInfo(nT);
732 aInfo.maOldTabBgColor = aOTabBgColor;
733 aInfo.maNewTabBgColor = aNTabBgColor;
734 aTabColorList.push_back(aInfo);
737 ScUndoTabColor::ScUndoTabColor(
738 ScDocShell* pNewDocShell,
739 const ScUndoTabColorInfo::List& rUndoTabColorList) :
740 ScSimpleUndo(pNewDocShell),
741 aTabColorList(rUndoTabColorList)
745 ScUndoTabColor::~ScUndoTabColor()
749 OUString ScUndoTabColor::GetComment() const
751 if (aTabColorList.size() > 1)
752 return ScGlobal::GetRscString(STR_UNDO_SET_MULTI_TAB_BG_COLOR);
753 return ScGlobal::GetRscString(STR_UNDO_SET_TAB_BG_COLOR);
756 void ScUndoTabColor::DoChange(bool bUndoType) const
758 ScDocument& rDoc = pDocShell->GetDocument();
760 size_t nTabColorCount = aTabColorList.size();
761 for (size_t i = 0; i < nTabColorCount; ++i)
763 const ScUndoTabColorInfo& rTabColor = aTabColorList[i];
764 rDoc.SetTabBgColor(rTabColor.mnTabId,
765 bUndoType ? rTabColor.maOldTabBgColor : rTabColor.maNewTabBgColor);
768 pDocShell->PostPaintExtras();
769 ScDocShellModificator aModificator( *pDocShell );
770 aModificator.SetDocumentModified();
773 void ScUndoTabColor::Undo()
775 DoChange(true);
778 void ScUndoTabColor::Redo()
780 DoChange(false);
783 void ScUndoTabColor::Repeat(SfxRepeatTarget& /* rTarget */)
785 // makes no sense
788 bool ScUndoTabColor::CanRepeat(SfxRepeatTarget& /* rTarget */) const
790 return false;
793 ScUndoMakeScenario::ScUndoMakeScenario( ScDocShell* pNewDocShell,
794 SCTAB nSrc, SCTAB nDest,
795 const OUString& rN, const OUString& rC,
796 const Color& rCol, sal_uInt16 nF,
797 const ScMarkData& rMark ) :
798 ScSimpleUndo( pNewDocShell ),
799 mpMarkData(new ScMarkData(rMark)),
800 nSrcTab( nSrc ),
801 nDestTab( nDest ),
802 aName( rN ),
803 aComment( rC ),
804 aColor( rCol ),
805 nFlags( nF ),
806 pDrawUndo( NULL )
808 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
811 ScUndoMakeScenario::~ScUndoMakeScenario()
813 DeleteSdrUndoAction( pDrawUndo );
816 OUString ScUndoMakeScenario::GetComment() const
818 return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
821 void ScUndoMakeScenario::Undo()
823 ScDocument& rDoc = pDocShell->GetDocument();
825 pDocShell->SetInUndo( true );
826 bDrawIsInUndo = true;
827 rDoc.DeleteTab( nDestTab );
828 bDrawIsInUndo = false;
829 pDocShell->SetInUndo( false );
831 DoSdrUndoAction( pDrawUndo, &rDoc );
833 pDocShell->PostPaint(0,0,nDestTab,MAXCOL,MAXROW,MAXTAB, PAINT_ALL);
834 pDocShell->PostDataChanged();
836 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
837 if (pViewShell)
838 pViewShell->SetTabNo( nSrcTab, true );
840 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
842 // SetTabNo(...,sal_True) for all views to sync with drawing layer pages
843 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
846 void ScUndoMakeScenario::Redo()
848 SetViewMarkData(*mpMarkData);
850 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
852 pDocShell->SetInUndo( true );
853 bDrawIsInUndo = true;
855 pDocShell->MakeScenario( nSrcTab, aName, aComment, aColor, nFlags, *mpMarkData, false );
857 bDrawIsInUndo = false;
858 pDocShell->SetInUndo( false );
860 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
861 if (pViewShell)
862 pViewShell->SetTabNo( nDestTab, true );
864 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
867 void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
869 if (rTarget.ISA(ScTabViewTarget))
871 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->MakeScenario( aName, aComment, aColor, nFlags );
875 bool ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
877 return rTarget.ISA(ScTabViewTarget);
880 ScUndoImportTab::ScUndoImportTab( ScDocShell* pShell,
881 SCTAB nNewTab, SCTAB nNewCount ) :
882 ScSimpleUndo( pShell ),
883 nTab( nNewTab ),
884 nCount( nNewCount ),
885 pRedoDoc( NULL ),
886 pDrawUndo( NULL )
888 pDrawUndo = GetSdrUndoAction( &pDocShell->GetDocument() );
891 ScUndoImportTab::~ScUndoImportTab()
893 delete pRedoDoc;
894 DeleteSdrUndoAction( pDrawUndo );
897 OUString ScUndoImportTab::GetComment() const
899 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
902 void ScUndoImportTab::DoChange() const
904 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
905 ScDocument& rDoc = pDocShell->GetDocument();
906 SCTAB nTabCount = rDoc.GetTableCount();
907 if (pViewShell)
909 if(nTab<nTabCount)
911 pViewShell->SetTabNo(nTab,true);
913 else
915 pViewShell->SetTabNo(nTab-1,true);
919 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
920 pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB,
921 PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
924 void ScUndoImportTab::Undo()
926 // Inserted range names, etc.
928 SCTAB i;
929 ScDocument& rDoc = pDocShell->GetDocument();
930 bool bMakeRedo = !pRedoDoc;
931 if (bMakeRedo)
933 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
934 pRedoDoc->InitUndo( &rDoc, nTab,nTab+nCount-1, true,true );
936 OUString aOldName;
937 for (i=0; i<nCount; i++)
939 SCTAB nTabPos=nTab+i;
941 rDoc.CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,false, pRedoDoc );
942 rDoc.GetName( nTabPos, aOldName );
943 pRedoDoc->RenameTab( nTabPos, aOldName, false );
944 pRedoDoc->SetTabBgColor( nTabPos, rDoc.GetTabBgColor(nTabPos) );
946 if ( rDoc.IsScenario(nTabPos) )
948 pRedoDoc->SetScenario(nTabPos, true );
949 OUString aComment;
950 Color aColor;
951 sal_uInt16 nScenFlags;
952 rDoc.GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
953 pRedoDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
954 bool bActive = rDoc.IsActiveScenario(nTabPos);
955 pRedoDoc->SetActiveScenario(nTabPos, bActive );
956 bool bVisible = rDoc.IsVisible(nTabPos);
957 pRedoDoc->SetVisible(nTabPos,bVisible );
960 if ( rDoc.IsTabProtected( nTabPos ) )
961 pRedoDoc->SetTabProtection(nTabPos, rDoc.GetTabProtection(nTabPos));
966 DoSdrUndoAction( pDrawUndo, &rDoc ); // before the sheets are deleted
968 bDrawIsInUndo = true;
969 for (i=0; i<nCount; i++)
970 rDoc.DeleteTab( nTab );
971 bDrawIsInUndo = false;
973 DoChange();
976 void ScUndoImportTab::Redo()
978 if (!pRedoDoc)
980 OSL_FAIL("Where is my Redo Document?");
981 return;
984 ScDocument& rDoc = pDocShell->GetDocument();
985 OUString aName;
986 SCTAB i;
987 for (i=0; i<nCount; i++) // first insert all sheets (#63304#)
989 SCTAB nTabPos=nTab+i;
990 pRedoDoc->GetName(nTabPos,aName);
991 bDrawIsInUndo = true;
992 rDoc.InsertTab(nTabPos,aName);
993 bDrawIsInUndo = false;
995 for (i=0; i<nCount; i++) // then copy into inserted sheets
997 SCTAB nTabPos=nTab+i;
998 pRedoDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,false, &rDoc );
999 rDoc.SetTabBgColor( nTabPos, pRedoDoc->GetTabBgColor(nTabPos) );
1001 if ( pRedoDoc->IsScenario(nTabPos) )
1003 rDoc.SetScenario(nTabPos, true );
1004 OUString aComment;
1005 Color aColor;
1006 sal_uInt16 nScenFlags;
1007 pRedoDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1008 rDoc.SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1009 bool bActive = pRedoDoc->IsActiveScenario(nTabPos);
1010 rDoc.SetActiveScenario(nTabPos, bActive );
1011 bool bVisible=pRedoDoc->IsVisible(nTabPos);
1012 rDoc.SetVisible(nTabPos,bVisible );
1015 if ( pRedoDoc->IsTabProtected( nTabPos ) )
1016 rDoc.SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
1019 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
1021 DoChange();
1024 void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
1026 if (rTarget.ISA(ScTabViewTarget))
1027 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData().GetDispatcher().
1028 Execute(FID_INS_TABLE, SfxCallMode::SLOT | SfxCallMode::RECORD);
1031 bool ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
1033 return rTarget.ISA(ScTabViewTarget);
1036 ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const OUString& rDocName ) :
1037 ScSimpleUndo( pShell ),
1038 aDocName( rDocName ),
1039 nRefreshDelay( 0 ),
1040 nCount( 0 )
1042 ScDocument& rDoc = pDocShell->GetDocument();
1043 SCTAB nTabCount = rDoc.GetTableCount();
1044 pTabs = new SCTAB[nTabCount];
1045 pModes = new sal_uInt8[nTabCount];
1046 pTabNames = new OUString[nTabCount];
1048 for (SCTAB i=0; i<nTabCount; i++)
1050 sal_uInt8 nMode = rDoc.GetLinkMode(i);
1051 if (nMode)
1052 if (rDoc.GetLinkDoc(i) == aDocName)
1054 if (!nCount)
1056 aFltName = rDoc.GetLinkFlt(i);
1057 aOptions = rDoc.GetLinkOpt(i);
1058 nRefreshDelay = rDoc.GetLinkRefreshDelay(i);
1060 else
1062 OSL_ENSURE(OUString(aFltName) == rDoc.GetLinkFlt(i) &&
1063 OUString(aOptions) == rDoc.GetLinkOpt(i),
1064 "different Filter for a Document?");
1066 pTabs[nCount] = i;
1067 pModes[nCount] = nMode;
1068 pTabNames[nCount] = rDoc.GetLinkTab(i);
1069 ++nCount;
1074 ScUndoRemoveLink::~ScUndoRemoveLink()
1076 delete pTabs;
1077 delete pModes;
1078 delete[] pTabNames;
1081 OUString ScUndoRemoveLink::GetComment() const
1083 return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
1086 void ScUndoRemoveLink::DoChange( bool bLink ) const
1088 ScDocument& rDoc = pDocShell->GetDocument();
1089 OUString aEmpty;
1090 for (sal_uInt16 i=0; i<nCount; i++)
1091 if (bLink) // establish link
1092 rDoc.SetLink( pTabs[i], pModes[i], aDocName, aFltName, aOptions, pTabNames[i], nRefreshDelay );
1093 else // remove link
1094 rDoc.SetLink( pTabs[i], SC_LINK_NONE, aEmpty, aEmpty, aEmpty, aEmpty, 0 );
1095 pDocShell->UpdateLinks();
1098 void ScUndoRemoveLink::Undo()
1100 DoChange( true );
1103 void ScUndoRemoveLink::Redo()
1105 DoChange( false );
1108 void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
1110 // makes no sense
1113 bool ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1115 return false;
1118 ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, const std::vector<SCTAB>& newUndoTabs, bool bNewShow ) :
1119 ScSimpleUndo( pShell ),
1120 undoTabs( newUndoTabs ),
1121 bShow( bNewShow )
1125 ScUndoShowHideTab::~ScUndoShowHideTab()
1129 void ScUndoShowHideTab::DoChange( bool bShowP ) const
1131 ScDocument& rDoc = pDocShell->GetDocument();
1132 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1134 SCTAB nTab;
1136 for(std::vector<SCTAB>::const_iterator itr = undoTabs.begin(), itrEnd = undoTabs.end(); itr != itrEnd; ++itr)
1138 nTab = *itr;
1139 rDoc.SetVisible( nTab, bShowP );
1140 if (pViewShell)
1141 pViewShell->SetTabNo(nTab,true);
1144 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1145 pDocShell->SetDocumentModified();
1148 void ScUndoShowHideTab::Undo()
1150 DoChange(!bShow);
1153 void ScUndoShowHideTab::Redo()
1155 DoChange(bShow);
1158 void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
1160 if (rTarget.ISA(ScTabViewTarget))
1161 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData().GetDispatcher().
1162 Execute( bShow ? FID_TABLE_SHOW : FID_TABLE_HIDE,
1163 SfxCallMode::SLOT | SfxCallMode::RECORD);
1166 bool ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
1168 return rTarget.ISA(ScTabViewTarget);
1171 OUString ScUndoShowHideTab::GetComment() const
1173 sal_uInt16 nId;
1174 if (undoTabs.size() > 1)
1176 nId = bShow ? STR_UNDO_SHOWTABS : STR_UNDO_HIDETABS;
1178 else
1180 nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
1183 return ScGlobal::GetRscString( nId );
1186 ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, unique_ptr<ScDocProtection> && pProtectSettings) :
1187 ScSimpleUndo(pShell),
1188 mpProtectSettings(std::move(pProtectSettings))
1192 ScUndoDocProtect::~ScUndoDocProtect()
1196 void ScUndoDocProtect::DoProtect(bool bProtect)
1198 ScDocument& rDoc = pDocShell->GetDocument();
1200 if (bProtect)
1202 // set protection.
1203 unique_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
1204 pCopy->setProtected(true);
1205 rDoc.SetDocProtection(pCopy.get());
1207 else
1209 // remove protection.
1210 rDoc.SetDocProtection(NULL);
1213 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1214 if (pViewShell)
1216 pViewShell->UpdateLayerLocks();
1217 pViewShell->UpdateInputHandler(true); // so that input can be immediately entered again
1220 pDocShell->PostPaintGridAll();
1223 void ScUndoDocProtect::Undo()
1225 BeginUndo();
1226 DoProtect(!mpProtectSettings->isProtected());
1227 EndUndo();
1230 void ScUndoDocProtect::Redo()
1232 BeginRedo();
1233 DoProtect(mpProtectSettings->isProtected());
1234 EndRedo();
1237 void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1239 // makes no sense
1242 bool ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1244 return false; // makes no sense
1247 OUString ScUndoDocProtect::GetComment() const
1249 sal_uInt16 nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
1250 return ScGlobal::GetRscString( nId );
1253 ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, unique_ptr<ScTableProtection> && pProtectSettings) :
1254 ScSimpleUndo(pShell),
1255 mnTab(nTab),
1256 mpProtectSettings(std::move(pProtectSettings))
1260 ScUndoTabProtect::~ScUndoTabProtect()
1264 void ScUndoTabProtect::DoProtect(bool bProtect)
1266 ScDocument& rDoc = pDocShell->GetDocument();
1268 if (bProtect)
1270 // set protection.
1271 unique_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
1272 pCopy->setProtected(true);
1273 rDoc.SetTabProtection(mnTab, pCopy.get());
1275 else
1277 // remove protection.
1278 rDoc.SetTabProtection(mnTab, NULL);
1281 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1282 if (pViewShell)
1284 pViewShell->UpdateLayerLocks();
1285 pViewShell->UpdateInputHandler(true); // so that input can be immediately entered again
1288 pDocShell->PostPaintGridAll();
1291 void ScUndoTabProtect::Undo()
1293 BeginUndo();
1294 DoProtect(!mpProtectSettings->isProtected());
1295 EndUndo();
1298 void ScUndoTabProtect::Redo()
1300 BeginRedo();
1301 DoProtect(mpProtectSettings->isProtected());
1302 EndRedo();
1305 void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1307 // makes no sense
1310 bool ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1312 return false; // makes no sense
1315 OUString ScUndoTabProtect::GetComment() const
1317 sal_uInt16 nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
1318 return ScGlobal::GetRscString( nId );
1321 ScUndoPrintRange::ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
1322 ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew ) :
1323 ScSimpleUndo( pShell ),
1324 nTab( nNewTab ),
1325 pOldRanges( pOld ),
1326 pNewRanges( pNew )
1330 ScUndoPrintRange::~ScUndoPrintRange()
1332 delete pOldRanges;
1333 delete pNewRanges;
1336 void ScUndoPrintRange::DoChange(bool bUndo)
1338 ScDocument& rDoc = pDocShell->GetDocument();
1339 if (bUndo)
1340 rDoc.RestorePrintRanges( *pOldRanges );
1341 else
1342 rDoc.RestorePrintRanges( *pNewRanges );
1344 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1345 if (pViewShell)
1346 pViewShell->SetTabNo( nTab );
1348 ScPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ).UpdatePages();
1350 pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
1353 void ScUndoPrintRange::Undo()
1355 BeginUndo();
1356 DoChange( true );
1357 EndUndo();
1360 void ScUndoPrintRange::Redo()
1362 BeginRedo();
1363 DoChange( false );
1364 EndRedo();
1367 void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
1369 // makes no sense
1372 bool ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1374 return false; // makes no sense
1377 OUString ScUndoPrintRange::GetComment() const
1379 return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
1382 ScUndoScenarioFlags::ScUndoScenarioFlags( ScDocShell* pNewDocShell, SCTAB nT,
1383 const OUString& rON, const OUString& rNN, const OUString& rOC, const OUString& rNC,
1384 const Color& rOCol, const Color& rNCol, sal_uInt16 nOF, sal_uInt16 nNF ) :
1385 ScSimpleUndo( pNewDocShell ),
1386 nTab ( nT ),
1387 aOldName ( rON ),
1388 aNewName ( rNN ),
1389 aOldComment ( rOC ),
1390 aNewComment ( rNC ),
1391 aOldColor ( rOCol ),
1392 aNewColor ( rNCol ),
1393 nOldFlags ( nOF ),
1394 nNewFlags ( nNF )
1398 ScUndoScenarioFlags::~ScUndoScenarioFlags()
1402 OUString ScUndoScenarioFlags::GetComment() const
1404 return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
1407 void ScUndoScenarioFlags::Undo()
1409 ScDocument& rDoc = pDocShell->GetDocument();
1411 rDoc.RenameTab( nTab, aOldName );
1412 rDoc.SetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
1414 pDocShell->PostPaintGridAll();
1415 // The sheet name might be used in a formula ...
1416 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1417 if (pViewShell)
1418 pViewShell->UpdateInputHandler();
1420 if ( aOldName != aNewName )
1421 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1424 void ScUndoScenarioFlags::Redo()
1426 ScDocument& rDoc = pDocShell->GetDocument();
1428 rDoc.RenameTab( nTab, aNewName );
1429 rDoc.SetScenarioData( nTab, aNewComment, aNewColor, nNewFlags );
1431 pDocShell->PostPaintGridAll();
1432 // The sheet name might be used in a formula ...
1433 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1434 if (pViewShell)
1435 pViewShell->UpdateInputHandler();
1437 if ( aOldName != aNewName )
1438 SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1441 void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
1443 // Repeat makes no sense
1446 bool ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1448 return false;
1451 // (move to different file?)
1452 ScUndoRenameObject::ScUndoRenameObject( ScDocShell* pNewDocShell, const OUString& rPN,
1453 const OUString& rON, const OUString& rNN ) :
1454 ScSimpleUndo( pNewDocShell ),
1455 aPersistName( rPN ),
1456 aOldName ( rON ),
1457 aNewName ( rNN )
1461 ScUndoRenameObject::~ScUndoRenameObject()
1465 OUString ScUndoRenameObject::GetComment() const
1467 // string resource shared with title for dialog
1468 return OUString( ScResId(SCSTR_RENAMEOBJECT) );
1471 SdrObject* ScUndoRenameObject::GetObject()
1473 ScDocument& rDoc = pDocShell->GetDocument();
1474 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
1475 if ( pDrawLayer )
1477 sal_uInt16 nCount = pDrawLayer->GetPageCount();
1478 for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1480 SdrPage* pPage = pDrawLayer->GetPage(nTab);
1481 assert(pPage && "Page ?");
1483 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
1484 SdrObject* pObject = aIter.Next();
1485 while (pObject)
1487 if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
1488 static_cast<SdrOle2Obj*>(pObject)->GetPersistName() == aPersistName )
1490 return pObject;
1493 pObject = aIter.Next();
1497 OSL_FAIL("Object not found");
1498 return NULL;
1501 void ScUndoRenameObject::Undo()
1503 BeginUndo();
1504 SdrObject* pObj = GetObject();
1505 if ( pObj )
1506 pObj->SetName( aOldName );
1507 EndUndo();
1510 void ScUndoRenameObject::Redo()
1512 BeginRedo();
1513 SdrObject* pObj = GetObject();
1514 if ( pObj )
1515 pObj->SetName( aNewName );
1516 EndRedo();
1519 void ScUndoRenameObject::Repeat(SfxRepeatTarget& /* rTarget */)
1523 bool ScUndoRenameObject::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1525 return false;
1528 ScUndoLayoutRTL::ScUndoLayoutRTL( ScDocShell* pShell, SCTAB nNewTab, bool bNewRTL ) :
1529 ScSimpleUndo( pShell ),
1530 nTab( nNewTab ),
1531 bRTL( bNewRTL )
1535 ScUndoLayoutRTL::~ScUndoLayoutRTL()
1539 void ScUndoLayoutRTL::DoChange( bool bNew )
1541 pDocShell->SetInUndo( true );
1543 ScDocument& rDoc = pDocShell->GetDocument();
1544 rDoc.SetLayoutRTL( nTab, bNew );
1546 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1547 if (pViewShell)
1548 pViewShell->SetTabNo(nTab,true);
1550 pDocShell->SetDocumentModified();
1552 pDocShell->SetInUndo( false );
1555 void ScUndoLayoutRTL::Undo()
1557 DoChange(!bRTL);
1560 void ScUndoLayoutRTL::Redo()
1562 DoChange(bRTL);
1565 void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
1567 if (rTarget.ISA(ScTabViewTarget))
1568 static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData().GetDispatcher().
1569 Execute( FID_TAB_RTL, SfxCallMode::SLOT | SfxCallMode::RECORD);
1572 bool ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
1574 return rTarget.ISA(ScTabViewTarget);
1577 OUString ScUndoLayoutRTL::GetComment() const
1579 return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
1582 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */