Update ooo320-m1
[ooovba.git] / sc / source / ui / undo / undotab.cxx
blob0e5640599204a93925534ea8719ade6d157d9422
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: undotab.cxx,v $
10 * $Revision: 1.19.28.2 $
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"
36 //------------------------------------------------------------------
38 // ?#define _MACRODLG_HXX
39 // ? #define _BIGINT_HXX
40 // ? #define _SVDXOUT_HXX
41 // ? #define _SVDATTR_HXX
42 // ? #define _SVDSURO_HXX
44 // INCLUDE ---------------------------------------------------------------
46 #include <sfx2/app.hxx>
47 #include <sfx2/bindings.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include <svtools/smplhint.hxx>
51 #include "undotab.hxx"
52 #include "document.hxx"
53 #include "docsh.hxx"
54 #include "tabvwsh.hxx"
55 #include "globstr.hrc"
56 #include "global.hxx"
57 #include "sc.hrc"
58 #include "undoolk.hxx"
59 #include "target.hxx"
60 #include "uiitems.hxx"
61 #include "prnsave.hxx"
62 #include "printfun.hxx"
63 #include "chgtrack.hxx"
64 #include "tabprotection.hxx"
66 // for ScUndoRenameObject - might me moved to another file later
67 #include <svx/svditer.hxx>
68 #include <svx/svdoole2.hxx>
69 #include <svx/svdpage.hxx>
70 #include "drwlayer.hxx"
71 #include "scresid.hxx"
73 // for set tab bg color
74 #include "viewdata.hxx"
76 extern BOOL bDrawIsInUndo; //! irgendwo als Member !!!
78 using namespace com::sun::star;
79 using ::com::sun::star::uno::Sequence;
80 using ::std::auto_ptr;
82 // STATIC DATA -----------------------------------------------------------
84 TYPEINIT1(ScUndoInsertTab, SfxUndoAction);
85 TYPEINIT1(ScUndoInsertTables, SfxUndoAction);
86 TYPEINIT1(ScUndoDeleteTab, SfxUndoAction);
87 TYPEINIT1(ScUndoRenameTab, SfxUndoAction);
88 TYPEINIT1(ScUndoMoveTab, SfxUndoAction);
89 TYPEINIT1(ScUndoCopyTab, SfxUndoAction);
90 TYPEINIT1(ScUndoMakeScenario, SfxUndoAction);
91 TYPEINIT1(ScUndoImportTab, SfxUndoAction);
92 TYPEINIT1(ScUndoRemoveLink, SfxUndoAction);
93 TYPEINIT1(ScUndoShowHideTab, SfxUndoAction);
94 TYPEINIT1(ScUndoPrintRange, SfxUndoAction);
95 TYPEINIT1(ScUndoScenarioFlags, SfxUndoAction);
96 TYPEINIT1(ScUndoRenameObject, SfxUndoAction);
97 TYPEINIT1(ScUndoLayoutRTL, SfxUndoAction);
98 //UNUSED2009-05 TYPEINIT1(ScUndoSetGrammar, SfxUndoAction);
99 TYPEINIT1(ScUndoSetTabBgColor, SfxUndoAction);
102 // -----------------------------------------------------------------------
104 // Tabelle einfuegen
107 ScUndoInsertTab::ScUndoInsertTab( ScDocShell* pNewDocShell,
108 SCTAB nTabNum,
109 BOOL bApp,
110 const String& rNewName) :
111 ScSimpleUndo( pNewDocShell ),
112 sNewName( rNewName ),
113 pDrawUndo( NULL ),
114 nTab( nTabNum ),
115 bAppend( bApp )
117 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
118 SetChangeTrack();
121 ScUndoInsertTab::~ScUndoInsertTab()
123 DeleteSdrUndoAction( pDrawUndo );
126 String ScUndoInsertTab::GetComment() const
128 if (bAppend)
129 return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
130 else
131 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
134 void ScUndoInsertTab::SetChangeTrack()
136 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
137 if ( pChangeTrack )
139 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
140 pChangeTrack->AppendInsert( aRange );
141 nEndChangeAction = pChangeTrack->GetActionMax();
143 else
144 nEndChangeAction = 0;
147 void ScUndoInsertTab::Undo()
149 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
150 pViewShell->SetTabNo(nTab);
152 pDocShell->SetInUndo( TRUE ); //! BeginUndo
153 bDrawIsInUndo = TRUE;
154 pViewShell->DeleteTable( nTab, FALSE );
155 bDrawIsInUndo = FALSE;
156 pDocShell->SetInUndo( FALSE ); //! EndUndo
158 DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
160 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
161 if ( pChangeTrack )
162 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
164 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
165 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
168 void ScUndoInsertTab::Redo()
170 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
172 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
174 pDocShell->SetInUndo( TRUE ); //! BeginRedo
175 bDrawIsInUndo = TRUE;
176 if (bAppend)
177 pViewShell->AppendTable( sNewName, FALSE );
178 else
180 pViewShell->SetTabNo(nTab);
181 pViewShell->InsertTable( sNewName, nTab, FALSE );
183 bDrawIsInUndo = FALSE;
184 pDocShell->SetInUndo( FALSE ); //! EndRedo
186 SetChangeTrack();
189 void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
191 if (rTarget.ISA(ScTabViewTarget))
192 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
193 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
196 BOOL ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
198 return (rTarget.ISA(ScTabViewTarget));
201 // -----------------------------------------------------------------------
203 // Tabellen einfuegen
206 ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
207 SCTAB nTabNum,
208 BOOL bApp,SvStrings *pNewNameList) :
209 ScSimpleUndo( pNewDocShell ),
210 pDrawUndo( NULL ),
211 nTab( nTabNum ),
212 bAppend( bApp )
214 pNameList = pNewNameList;
215 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
217 SetChangeTrack();
220 ScUndoInsertTables::~ScUndoInsertTables()
222 String *pStr=NULL;
223 if(pNameList!=NULL)
225 for(int i=0;i<pNameList->Count();i++)
227 pStr=pNameList->GetObject(sal::static_int_cast<USHORT>(i));
228 delete pStr;
230 pNameList->Remove(0,pNameList->Count());
231 delete pNameList;
233 DeleteSdrUndoAction( pDrawUndo );
236 String ScUndoInsertTables::GetComment() const
238 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
241 void ScUndoInsertTables::SetChangeTrack()
243 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
244 if ( pChangeTrack )
246 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
247 nEndChangeAction = 0;
248 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
249 for( int i = 0; i < pNameList->Count(); i++ )
251 aRange.aStart.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
252 aRange.aEnd.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
253 pChangeTrack->AppendInsert( aRange );
254 nEndChangeAction = pChangeTrack->GetActionMax();
257 else
258 nStartChangeAction = nEndChangeAction = 0;
261 void ScUndoInsertTables::Undo()
263 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
264 pViewShell->SetTabNo(nTab);
266 pDocShell->SetInUndo( TRUE ); //! BeginUndo
267 bDrawIsInUndo = TRUE;
269 SvShorts TheTabs;
270 for(int i=0;i<pNameList->Count();i++)
272 TheTabs.Insert( sal::static_int_cast<short>(nTab+i), TheTabs.Count() );
275 pViewShell->DeleteTables( TheTabs, FALSE );
276 TheTabs.Remove(0,TheTabs.Count());
278 bDrawIsInUndo = FALSE;
279 pDocShell->SetInUndo( FALSE ); //! EndUndo
281 DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
283 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
284 if ( pChangeTrack )
285 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
287 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
288 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
291 void ScUndoInsertTables::Redo()
293 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
295 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
297 pDocShell->SetInUndo( TRUE ); //! BeginRedo
298 bDrawIsInUndo = TRUE;
299 pViewShell->SetTabNo(nTab);
300 pViewShell->InsertTables( pNameList, nTab, static_cast<SCTAB>(pNameList->Count()),FALSE );
302 bDrawIsInUndo = FALSE;
303 pDocShell->SetInUndo( FALSE ); //! EndRedo
305 SetChangeTrack();
308 void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
310 if (rTarget.ISA(ScTabViewTarget))
311 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
312 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
315 BOOL ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
317 return (rTarget.ISA(ScTabViewTarget));
321 //----------------------------------------------------------------------------------
323 // Tabelle loeschen
326 ScUndoDeleteTab::ScUndoDeleteTab( ScDocShell* pNewDocShell,const SvShorts &aTab, //SCTAB nNewTab,
327 ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
328 ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST )
330 for(int i=0;i<aTab.Count();i++)
331 theTabs.Insert(aTab[sal::static_int_cast<USHORT>(i)],theTabs.Count());
333 SetChangeTrack();
336 ScUndoDeleteTab::~ScUndoDeleteTab()
338 theTabs.Remove(0,theTabs.Count());
341 String ScUndoDeleteTab::GetComment() const
343 return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
346 void ScUndoDeleteTab::SetChangeTrack()
348 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
349 if ( pChangeTrack )
351 ULONG nTmpChangeAction;
352 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
353 nEndChangeAction = 0;
354 ScRange aRange( 0, 0, 0, MAXCOL, MAXROW, 0 );
355 for ( int i = 0; i < theTabs.Count(); i++ )
357 aRange.aStart.SetTab( theTabs[sal::static_int_cast<USHORT>(i)] );
358 aRange.aEnd.SetTab( theTabs[sal::static_int_cast<USHORT>(i)] );
359 pChangeTrack->AppendDeleteRange( aRange, pRefUndoDoc,
360 nTmpChangeAction, nEndChangeAction, (short) i );
363 else
364 nStartChangeAction = nEndChangeAction = 0;
367 SCTAB lcl_GetVisibleTabBefore( ScDocument& rDoc, SCTAB nTab )
369 while ( nTab > 0 && !rDoc.IsVisible( nTab ) )
370 --nTab;
372 return nTab;
375 void ScUndoDeleteTab::Undo()
377 BeginUndo();
378 int i=0;
379 ScDocument* pDoc = pDocShell->GetDocument();
381 BOOL bLink = FALSE;
382 String aName;
384 for(i=0;i<theTabs.Count();i++)
386 SCTAB nTab = theTabs[sal::static_int_cast<USHORT>(i)];
387 pRefUndoDoc->GetName( nTab, aName );
389 bDrawIsInUndo = TRUE;
390 BOOL bOk = pDoc->InsertTab( nTab, aName );
391 bDrawIsInUndo = FALSE;
392 if (bOk)
394 // Ref-Undo passiert in EndUndo
395 // pUndoDoc->UndoToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,FALSE, pDoc );
396 pRefUndoDoc->CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,FALSE, pDoc );
398 String aOldName;
399 pRefUndoDoc->GetName( nTab, aOldName );
400 pDoc->RenameTab( nTab, aOldName, FALSE );
401 if (pRefUndoDoc->IsLinked(nTab))
403 pDoc->SetLink( nTab, pRefUndoDoc->GetLinkMode(nTab), pRefUndoDoc->GetLinkDoc(nTab),
404 pRefUndoDoc->GetLinkFlt(nTab), pRefUndoDoc->GetLinkOpt(nTab),
405 pRefUndoDoc->GetLinkTab(nTab), pRefUndoDoc->GetLinkRefreshDelay(nTab) );
406 bLink = TRUE;
409 if ( pRefUndoDoc->IsScenario(nTab) )
411 pDoc->SetScenario( nTab, TRUE );
412 String aComment;
413 Color aColor;
414 USHORT nScenFlags;
415 pRefUndoDoc->GetScenarioData( nTab, aComment, aColor, nScenFlags );
416 pDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
417 BOOL bActive = pRefUndoDoc->IsActiveScenario( nTab );
418 pDoc->SetActiveScenario( nTab, bActive );
420 pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
422 if ( pRefUndoDoc->IsTabProtected( nTab ) )
423 pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
425 // Drawing-Layer passiert beim MoveUndo::EndUndo
426 // pDoc->TransferDrawPage(pRefUndoDoc, nTab,nTab);
429 if (bLink)
431 pDocShell->UpdateLinks(); // Link-Manager updaten
434 EndUndo(); // Draw-Undo muss vor dem Broadcast kommen!
436 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
437 if ( pChangeTrack )
438 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
440 for(i=0;i<theTabs.Count();i++)
442 pDocShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, theTabs[sal::static_int_cast<USHORT>(i)]) );
444 SfxApplication* pSfxApp = SFX_APP(); // Navigator
445 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
446 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
447 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
449 pDocShell->PostPaint(0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_ALL ); // incl. Extras
451 // nicht ShowTable wegen SetTabNo(..., TRUE):
452 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
453 if (pViewShell)
454 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDoc, theTabs[0] ), TRUE );
456 // EndUndo();
459 void ScUndoDeleteTab::Redo()
461 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
462 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs[0] ) );
464 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
466 pDocShell->SetInUndo( TRUE ); //! BeginRedo
467 bDrawIsInUndo = TRUE;
468 pViewShell->DeleteTables( theTabs, FALSE );
469 bDrawIsInUndo = FALSE;
470 pDocShell->SetInUndo( TRUE ); //! EndRedo
472 SetChangeTrack();
474 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
475 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
478 void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
480 if (rTarget.ISA(ScTabViewTarget))
482 ScTabViewShell* pViewShell = ((ScTabViewTarget&)rTarget).GetViewShell();
483 pViewShell->DeleteTable( pViewShell->GetViewData()->GetTabNo(), TRUE );
487 BOOL ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
489 return (rTarget.ISA(ScTabViewTarget));
493 //---------------------------------------------------------------------------------
495 // Tabelle umbenennen
498 ScUndoRenameTab::ScUndoRenameTab( ScDocShell* pNewDocShell,
499 SCTAB nT,
500 const String& rOldName,
501 const String& rNewName) :
502 ScSimpleUndo( pNewDocShell ),
503 nTab ( nT )
505 sOldName = rOldName;
506 sNewName = rNewName;
509 ScUndoRenameTab::~ScUndoRenameTab()
513 String ScUndoRenameTab::GetComment() const
515 return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
518 void ScUndoRenameTab::DoChange( SCTAB nTabP, const String& rName ) const
520 ScDocument* pDoc = pDocShell->GetDocument();
521 pDoc->RenameTab( nTabP, rName );
523 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
525 pDocShell->PostPaintGridAll();
526 pDocShell->PostPaintExtras();
527 pDocShell->PostDataChanged();
529 // Der Tabellenname koennte in einer Formel vorkommen...
530 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
531 if (pViewShell)
532 pViewShell->UpdateInputHandler();
535 void ScUndoRenameTab::Undo()
537 DoChange(nTab, sOldName);
540 void ScUndoRenameTab::Redo()
542 DoChange(nTab, sNewName);
545 void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
547 // Repeat macht keinen Sinn
550 BOOL ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
552 return FALSE;
556 //----------------------------------------------------------------------------------
558 // Tabelle verschieben
561 ScUndoMoveTab::ScUndoMoveTab( ScDocShell* pNewDocShell,
562 const SvShorts &aOldTab,
563 const SvShorts &aNewTab) :
564 ScSimpleUndo( pNewDocShell )
566 int i;
567 for(i=0;i<aOldTab.Count();i++)
568 theOldTabs.Insert(aOldTab[sal::static_int_cast<USHORT>(i)],theOldTabs.Count());
570 for(i=0;i<aNewTab.Count();i++)
571 theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
574 ScUndoMoveTab::~ScUndoMoveTab()
576 theNewTabs.Remove(0,theNewTabs.Count());
577 theOldTabs.Remove(0,theOldTabs.Count());
580 String ScUndoMoveTab::GetComment() const
582 return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
585 void ScUndoMoveTab::DoChange( BOOL bUndo ) const
587 ScDocument* pDoc = pDocShell->GetDocument();
588 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
590 if (bUndo) // UnDo
592 for(int i=theNewTabs.Count()-1;i>=0;i--)
594 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
595 SCTAB nOldTab = theOldTabs[sal::static_int_cast<USHORT>(i)];
596 if (nDestTab > MAXTAB) // angehaengt ?
597 nDestTab = pDoc->GetTableCount() - 1;
599 pDoc->MoveTab( nDestTab, nOldTab );
600 pViewShell->GetViewData()->MoveTab( nDestTab, nOldTab );
601 pViewShell->SetTabNo( nOldTab, TRUE );
604 else
606 for(int i=0;i<theNewTabs.Count();i++)
608 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
609 SCTAB nNewTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
610 SCTAB nOldTab = theOldTabs[sal::static_int_cast<USHORT>(i)];
611 if (nDestTab > MAXTAB) // angehaengt ?
612 nDestTab = pDoc->GetTableCount() - 1;
614 pDoc->MoveTab( nOldTab, nNewTab );
615 pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
616 pViewShell->SetTabNo( nDestTab, TRUE );
620 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
622 pDocShell->PostPaintGridAll();
623 pDocShell->PostPaintExtras();
624 pDocShell->PostDataChanged();
627 void ScUndoMoveTab::Undo()
629 DoChange( TRUE );
632 void ScUndoMoveTab::Redo()
634 DoChange( FALSE );
637 void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
639 // kein Repeat ! ? !
642 BOOL ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
644 return FALSE;
648 //----------------------------------------------------------------------------------
650 // Tabelle kopieren
653 ScUndoCopyTab::ScUndoCopyTab( ScDocShell* pNewDocShell,
654 const SvShorts &aOldTab,
655 const SvShorts &aNewTab) :
656 ScSimpleUndo( pNewDocShell ),
657 pDrawUndo( NULL )
659 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
661 int i;
662 for(i=0;i<aOldTab.Count();i++)
663 theOldTabs.Insert(aOldTab[sal::static_int_cast<USHORT>(i)],theOldTabs.Count());
665 for(i=0;i<aNewTab.Count();i++)
666 theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
669 ScUndoCopyTab::~ScUndoCopyTab()
671 DeleteSdrUndoAction( pDrawUndo );
674 String ScUndoCopyTab::GetComment() const
676 return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
679 void ScUndoCopyTab::DoChange() const
681 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
683 if (pViewShell)
684 pViewShell->SetTabNo(theOldTabs[0],TRUE);
686 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
688 pDocShell->PostPaintGridAll();
689 pDocShell->PostPaintExtras();
690 pDocShell->PostDataChanged();
693 void ScUndoCopyTab::Undo()
695 ScDocument* pDoc = pDocShell->GetDocument();
697 DoSdrUndoAction( pDrawUndo, pDoc ); // before the sheets are deleted
699 int i;
700 for(i=theNewTabs.Count()-1;i>=0;i--)
702 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
703 if (nDestTab > MAXTAB) // append?
704 nDestTab = pDoc->GetTableCount() - 1;
706 bDrawIsInUndo = TRUE;
707 pDoc->DeleteTab(nDestTab);
708 bDrawIsInUndo = FALSE;
711 // ScTablesHint broadcasts after all sheets have been deleted,
712 // so sheets and draw pages are in sync!
714 for(i=theNewTabs.Count()-1;i>=0;i--)
716 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
717 if (nDestTab > MAXTAB) // append?
718 nDestTab = pDoc->GetTableCount() - 1;
720 pDocShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nDestTab ) );
723 DoChange();
726 void ScUndoCopyTab::Redo()
728 ScDocument* pDoc = pDocShell->GetDocument();
729 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
731 SCTAB nDestTab = 0;
732 for(int i=0;i<theNewTabs.Count();i++)
734 nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
735 SCTAB nNewTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
736 SCTAB nOldTab = theOldTabs[sal::static_int_cast<USHORT>(i)];
737 if (nDestTab > MAXTAB) // angehaengt ?
738 nDestTab = pDoc->GetTableCount() - 1;
740 bDrawIsInUndo = TRUE;
741 pDoc->CopyTab( nOldTab, nNewTab );
742 bDrawIsInUndo = FALSE;
744 pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
746 SCTAB nAdjSource = nOldTab;
747 if ( nNewTab <= nOldTab )
748 ++nAdjSource; // new position of source table after CopyTab
750 if ( pDoc->IsScenario(nAdjSource) )
752 pDoc->SetScenario(nNewTab, TRUE );
753 String aComment;
754 Color aColor;
755 USHORT nScenFlags;
756 pDoc->GetScenarioData(nAdjSource, aComment, aColor, nScenFlags );
757 pDoc->SetScenarioData(nNewTab, aComment, aColor, nScenFlags );
758 BOOL bActive = pDoc->IsActiveScenario(nAdjSource);
759 pDoc->SetActiveScenario(nNewTab, bActive );
760 BOOL bVisible=pDoc->IsVisible(nAdjSource);
761 pDoc->SetVisible(nNewTab,bVisible );
764 if ( pDoc->IsTabProtected( nAdjSource ) )
765 pDoc->CopyTabProtection(nAdjSource, nNewTab);
768 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
770 pViewShell->SetTabNo( nDestTab, TRUE ); // after draw-undo
772 DoChange();
776 void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
778 // kein Repeat ! ? !
781 BOOL ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
783 return FALSE;
786 //---------------------------------------------------------------------------------
788 // Tab Bg Color
791 ScUndoSetTabBgColor::ScUndoSetTabBgColor( ScDocShell* pNewDocShell,
792 SCTAB nT,
793 const Color& aOTabBgColor,
794 const Color& aNTabBgColor) :
795 ScSimpleUndo( pNewDocShell ),
796 nTab ( nT ),
797 bIsMultipleUndo ( FALSE ),
798 aUndoSetTabBgColorInfoList ( NULL )
800 aOldTabBgColor = aOTabBgColor;
801 aNewTabBgColor = aNTabBgColor;
804 ScUndoSetTabBgColor::ScUndoSetTabBgColor( ScDocShell* pNewDocShell,
805 ScUndoSetTabBgColorInfoList* pUndoSetTabBgColorInfoList) :
806 ScSimpleUndo( pNewDocShell ),
807 bIsMultipleUndo ( TRUE )
809 aUndoSetTabBgColorInfoList = pUndoSetTabBgColorInfoList;
812 __EXPORT ScUndoSetTabBgColor::~ScUndoSetTabBgColor()
816 String __EXPORT ScUndoSetTabBgColor::GetComment() const
818 if (bIsMultipleUndo && aUndoSetTabBgColorInfoList && aUndoSetTabBgColorInfoList->Count() > 1)
819 return ScGlobal::GetRscString( STR_UNDO_SET_MULTI_TAB_BG_COLOR );
820 return ScGlobal::GetRscString( STR_UNDO_SET_TAB_BG_COLOR );
823 void ScUndoSetTabBgColor::DoChange( SCTAB nTabP, const Color& rTabBgColor ) const
825 if (bIsMultipleUndo)
826 return;
827 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
828 if (pViewShell)
830 ScViewData* pViewData = pViewShell->GetViewData();
831 if (pViewData)
833 pViewData->SetTabBgColor( rTabBgColor, nTabP );
834 pDocShell->PostPaintExtras();
835 pDocShell->PostDataChanged();
836 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
837 pViewShell->UpdateInputHandler();
842 void ScUndoSetTabBgColor::DoChange(BOOL bUndoType) const
844 if (!bIsMultipleUndo)
845 return;
846 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
847 if (pViewShell)
849 ScViewData* pViewData = pViewShell->GetViewData();
850 if (pViewData)
852 ScUndoSetTabBgColorInfo* aUndoSetTabBgColorInfo=NULL;
853 for (USHORT i=0; i < aUndoSetTabBgColorInfoList->Count(); i++)
855 aUndoSetTabBgColorInfo = aUndoSetTabBgColorInfoList->GetObject(i);
856 pViewData->SetTabBgColor(
857 bUndoType ? aUndoSetTabBgColorInfo->aOldTabBgColor : aUndoSetTabBgColorInfo->aNewTabBgColor,
858 aUndoSetTabBgColorInfo->nTabId);
860 pDocShell->PostPaintExtras();
861 pDocShell->PostDataChanged();
862 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
863 pViewShell->UpdateInputHandler();
868 void __EXPORT ScUndoSetTabBgColor::Undo()
870 if ( bIsMultipleUndo )
871 DoChange(TRUE);
872 else
873 DoChange(nTab, aOldTabBgColor);
876 void __EXPORT ScUndoSetTabBgColor::Redo()
878 if ( bIsMultipleUndo )
879 DoChange(FALSE);
880 else
881 DoChange(nTab, aNewTabBgColor);
884 void __EXPORT ScUndoSetTabBgColor::Repeat(SfxRepeatTarget& /* rTarget */)
886 // No Repeat
889 BOOL __EXPORT ScUndoSetTabBgColor::CanRepeat(SfxRepeatTarget& /* rTarget */) const
891 return FALSE;
894 // -----------------------------------------------------------------------
896 // Szenario anlegen
899 ScUndoMakeScenario::ScUndoMakeScenario( ScDocShell* pNewDocShell,
900 SCTAB nSrc, SCTAB nDest,
901 const String& rN, const String& rC,
902 const Color& rCol, USHORT nF,
903 const ScMarkData& rMark ) :
904 ScSimpleUndo( pNewDocShell ),
905 nSrcTab( nSrc ),
906 nDestTab( nDest ),
907 aName( rN ),
908 aComment( rC ),
909 aColor( rCol ),
910 nFlags( nF ),
911 aMarkData( rMark ),
912 pDrawUndo( NULL )
914 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
917 ScUndoMakeScenario::~ScUndoMakeScenario()
919 DeleteSdrUndoAction( pDrawUndo );
922 String ScUndoMakeScenario::GetComment() const
924 return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
927 void ScUndoMakeScenario::Undo()
929 ScDocument* pDoc = pDocShell->GetDocument();
931 pDocShell->SetInUndo( TRUE );
932 bDrawIsInUndo = TRUE;
933 pDoc->DeleteTab( nDestTab );
934 bDrawIsInUndo = FALSE;
935 pDocShell->SetInUndo( FALSE );
937 DoSdrUndoAction( pDrawUndo, pDoc );
939 pDocShell->PostPaint(0,0,nDestTab,MAXCOL,MAXROW,MAXTAB, PAINT_ALL);
940 pDocShell->PostDataChanged();
942 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
943 if (pViewShell)
944 pViewShell->SetTabNo( nSrcTab, TRUE );
946 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
948 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
949 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
952 void ScUndoMakeScenario::Redo()
954 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
955 if (pViewShell)
956 pViewShell->SetMarkData( aMarkData );
958 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
960 pDocShell->SetInUndo( TRUE );
961 bDrawIsInUndo = TRUE;
963 pDocShell->MakeScenario( nSrcTab, aName, aComment, aColor, nFlags, aMarkData, FALSE );
965 bDrawIsInUndo = FALSE;
966 pDocShell->SetInUndo( FALSE );
968 if (pViewShell)
969 pViewShell->SetTabNo( nDestTab, TRUE );
971 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
974 void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
976 if (rTarget.ISA(ScTabViewTarget))
978 ((ScTabViewTarget&)rTarget).GetViewShell()->MakeScenario( aName, aComment, aColor, nFlags );
982 BOOL ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
984 return (rTarget.ISA(ScTabViewTarget));
988 // -----------------------------------------------------------------------
990 // Tabelle einfuegen
993 ScUndoImportTab::ScUndoImportTab( ScDocShell* pShell,
994 SCTAB nNewTab, SCTAB nNewCount, BOOL bNewLink ) :
995 ScSimpleUndo( pShell ),
996 nTab( nNewTab ),
997 nCount( nNewCount ),
998 bLink( bNewLink ),
999 pRedoDoc( NULL ),
1000 pDrawUndo( NULL )
1002 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
1005 ScUndoImportTab::~ScUndoImportTab()
1007 delete pRedoDoc;
1008 DeleteSdrUndoAction( pDrawUndo );
1011 String ScUndoImportTab::GetComment() const
1013 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
1016 void ScUndoImportTab::DoChange() const
1018 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1019 ScDocument* pDoc = pDocShell->GetDocument();
1020 SCTAB nTabCount = pDoc->GetTableCount();
1021 if (pViewShell)
1023 if(nTab<nTabCount)
1025 pViewShell->SetTabNo(nTab,TRUE);
1027 else
1029 pViewShell->SetTabNo(nTab-1,TRUE);
1033 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
1034 pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB,
1035 PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
1038 void ScUndoImportTab::Undo()
1040 //! eingefuegte Bereichsnamen etc.
1042 SCTAB i;
1043 ScDocument* pDoc = pDocShell->GetDocument();
1044 BOOL bMakeRedo = !pRedoDoc;
1045 if (bMakeRedo)
1047 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
1048 pRedoDoc->InitUndo( pDoc, nTab,nTab+nCount-1, TRUE,TRUE );
1050 String aOldName;
1051 for (i=0; i<nCount; i++)
1053 SCTAB nTabPos=nTab+i;
1055 pDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,FALSE, pRedoDoc );
1056 pDoc->GetName( nTabPos, aOldName );
1057 pRedoDoc->RenameTab( nTabPos, aOldName, FALSE );
1059 if ( pDoc->IsScenario(nTabPos) )
1061 pRedoDoc->SetScenario(nTabPos, TRUE );
1062 String aComment;
1063 Color aColor;
1064 USHORT nScenFlags;
1065 pDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1066 pRedoDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1067 BOOL bActive = pDoc->IsActiveScenario(nTabPos);
1068 pRedoDoc->SetActiveScenario(nTabPos, bActive );
1069 BOOL bVisible=pDoc->IsVisible(nTabPos);
1070 pRedoDoc->SetVisible(nTabPos,bVisible );
1073 if ( pDoc->IsTabProtected( nTabPos ) )
1074 pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
1079 DoSdrUndoAction( pDrawUndo, pDoc ); // before the sheets are deleted
1081 bDrawIsInUndo = TRUE;
1082 for (i=0; i<nCount; i++)
1083 pDoc->DeleteTab( nTab );
1084 bDrawIsInUndo = FALSE;
1086 DoChange();
1089 void ScUndoImportTab::Redo()
1091 if (!pRedoDoc)
1093 DBG_ERROR("wo ist mein Redo-Document?");
1094 return;
1097 ScDocument* pDoc = pDocShell->GetDocument();
1098 String aName;
1099 SCTAB i;
1100 for (i=0; i<nCount; i++) // first insert all sheets (#63304#)
1102 SCTAB nTabPos=nTab+i;
1103 pRedoDoc->GetName(nTabPos,aName);
1104 bDrawIsInUndo = TRUE;
1105 pDoc->InsertTab(nTabPos,aName);
1106 bDrawIsInUndo = FALSE;
1108 for (i=0; i<nCount; i++) // then copy into inserted sheets
1110 SCTAB nTabPos=nTab+i;
1111 pRedoDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,FALSE, pDoc );
1113 if ( pRedoDoc->IsScenario(nTabPos) )
1115 pDoc->SetScenario(nTabPos, TRUE );
1116 String aComment;
1117 Color aColor;
1118 USHORT nScenFlags;
1119 pRedoDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1120 pDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1121 BOOL bActive = pRedoDoc->IsActiveScenario(nTabPos);
1122 pDoc->SetActiveScenario(nTabPos, bActive );
1123 BOOL bVisible=pRedoDoc->IsVisible(nTabPos);
1124 pDoc->SetVisible(nTabPos,bVisible );
1127 if ( pRedoDoc->IsTabProtected( nTabPos ) )
1128 pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
1131 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
1133 DoChange();
1136 void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
1138 if (rTarget.ISA(ScTabViewTarget))
1139 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1140 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1143 BOOL ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
1145 return (rTarget.ISA(ScTabViewTarget));
1149 // -----------------------------------------------------------------------
1151 // Tabellen-Verknuepfung aufheben
1154 ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const String& rDoc ) :
1155 ScSimpleUndo( pShell ),
1156 aDocName( rDoc ),
1157 nCount( 0 )
1159 ScDocument* pDoc = pDocShell->GetDocument();
1160 SCTAB nTabCount = pDoc->GetTableCount();
1161 pTabs = new SCTAB[nTabCount];
1162 pModes = new BYTE[nTabCount];
1163 pTabNames = new String[nTabCount];
1165 for (SCTAB i=0; i<nTabCount; i++)
1167 BYTE nMode = pDoc->GetLinkMode(i);
1168 if (nMode)
1169 if (pDoc->GetLinkDoc(i) == aDocName)
1171 if (!nCount)
1173 aFltName = pDoc->GetLinkFlt(i);
1174 aOptions = pDoc->GetLinkOpt(i);
1175 nRefreshDelay = pDoc->GetLinkRefreshDelay(i);
1177 else
1179 DBG_ASSERT(aFltName == pDoc->GetLinkFlt(i) &&
1180 aOptions == pDoc->GetLinkOpt(i),
1181 "verschiedene Filter fuer ein Dokument?");
1183 pTabs[nCount] = i;
1184 pModes[nCount] = nMode;
1185 pTabNames[nCount] = pDoc->GetLinkTab(i);
1186 ++nCount;
1191 ScUndoRemoveLink::~ScUndoRemoveLink()
1193 delete pTabs;
1194 delete pModes;
1195 delete[] pTabNames;
1198 String ScUndoRemoveLink::GetComment() const
1200 return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
1203 void ScUndoRemoveLink::DoChange( BOOL bLink ) const
1205 ScDocument* pDoc = pDocShell->GetDocument();
1206 String aEmpty;
1207 for (USHORT i=0; i<nCount; i++)
1208 if (bLink) // establish link
1209 pDoc->SetLink( pTabs[i], pModes[i], aDocName, aFltName, aOptions, pTabNames[i], nRefreshDelay );
1210 else // remove link
1211 pDoc->SetLink( pTabs[i], SC_LINK_NONE, aEmpty, aEmpty, aEmpty, aEmpty, 0 );
1212 pDocShell->UpdateLinks();
1215 void ScUndoRemoveLink::Undo()
1217 DoChange( TRUE );
1220 void ScUndoRemoveLink::Redo()
1222 DoChange( FALSE );
1225 void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
1227 // gippsnich
1230 BOOL ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1232 return FALSE;
1236 // -----------------------------------------------------------------------
1238 // Tabellen ein-/ausblenden
1241 ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, SCTAB nNewTab, BOOL bNewShow ) :
1242 ScSimpleUndo( pShell ),
1243 nTab( nNewTab ),
1244 bShow( bNewShow )
1248 ScUndoShowHideTab::~ScUndoShowHideTab()
1252 void ScUndoShowHideTab::DoChange( BOOL bShowP ) const
1254 ScDocument* pDoc = pDocShell->GetDocument();
1255 pDoc->SetVisible( nTab, bShowP );
1257 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1258 if (pViewShell)
1259 pViewShell->SetTabNo(nTab,TRUE);
1261 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1262 pDocShell->SetDocumentModified();
1265 void ScUndoShowHideTab::Undo()
1267 DoChange(!bShow);
1270 void ScUndoShowHideTab::Redo()
1272 DoChange(bShow);
1275 void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
1277 if (rTarget.ISA(ScTabViewTarget))
1278 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1279 Execute( bShow ? FID_TABLE_SHOW : FID_TABLE_HIDE,
1280 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1283 BOOL ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
1285 return (rTarget.ISA(ScTabViewTarget));
1288 String ScUndoShowHideTab::GetComment() const
1290 USHORT nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
1291 return ScGlobal::GetRscString( nId );
1294 // ============================================================================
1296 ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
1297 ScSimpleUndo(pShell),
1298 mpProtectSettings(pProtectSettings)
1302 ScUndoDocProtect::~ScUndoDocProtect()
1306 void ScUndoDocProtect::DoProtect(bool bProtect)
1308 ScDocument* pDoc = pDocShell->GetDocument();
1310 if (bProtect)
1312 // set protection.
1313 auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
1314 pCopy->setProtected(true);
1315 pDoc->SetDocProtection(pCopy.get());
1317 else
1319 // remove protection.
1320 pDoc->SetDocProtection(NULL);
1323 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1324 if (pViewShell)
1326 pViewShell->UpdateLayerLocks();
1327 pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
1330 pDocShell->PostPaintGridAll();
1333 void ScUndoDocProtect::Undo()
1335 BeginUndo();
1336 DoProtect(!mpProtectSettings->isProtected());
1337 EndUndo();
1340 void ScUndoDocProtect::Redo()
1342 BeginRedo();
1343 DoProtect(mpProtectSettings->isProtected());
1344 EndRedo();
1347 void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1349 // gippsnich
1352 BOOL ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1354 return FALSE; // gippsnich
1357 String ScUndoDocProtect::GetComment() const
1359 USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
1360 return ScGlobal::GetRscString( nId );
1363 // ============================================================================
1365 ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
1366 ScSimpleUndo(pShell),
1367 mnTab(nTab),
1368 mpProtectSettings(pProtectSettings)
1372 ScUndoTabProtect::~ScUndoTabProtect()
1376 void ScUndoTabProtect::DoProtect(bool bProtect)
1378 ScDocument* pDoc = pDocShell->GetDocument();
1380 if (bProtect)
1382 // set protection.
1383 auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
1384 pCopy->setProtected(true);
1385 pDoc->SetTabProtection(mnTab, pCopy.get());
1387 else
1389 // remove protection.
1390 pDoc->SetTabProtection(mnTab, NULL);
1393 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1394 if (pViewShell)
1396 pViewShell->UpdateLayerLocks();
1397 pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
1400 pDocShell->PostPaintGridAll();
1403 void ScUndoTabProtect::Undo()
1405 BeginUndo();
1406 DoProtect(!mpProtectSettings->isProtected());
1407 EndUndo();
1410 void ScUndoTabProtect::Redo()
1412 BeginRedo();
1413 DoProtect(mpProtectSettings->isProtected());
1414 EndRedo();
1417 void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1419 // gippsnich
1422 BOOL ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1424 return FALSE; // gippsnich
1427 String ScUndoTabProtect::GetComment() const
1429 USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
1430 return ScGlobal::GetRscString( nId );
1433 // -----------------------------------------------------------------------
1435 // Druck-/Wiederholungsbereiche aendern
1438 ScUndoPrintRange::ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
1439 ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew ) :
1440 ScSimpleUndo( pShell ),
1441 nTab( nNewTab ),
1442 pOldRanges( pOld ),
1443 pNewRanges( pNew )
1447 ScUndoPrintRange::~ScUndoPrintRange()
1449 delete pOldRanges;
1450 delete pNewRanges;
1453 void ScUndoPrintRange::DoChange(BOOL bUndo)
1455 ScDocument* pDoc = pDocShell->GetDocument();
1456 if (bUndo)
1457 pDoc->RestorePrintRanges( *pOldRanges );
1458 else
1459 pDoc->RestorePrintRanges( *pNewRanges );
1461 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1462 if (pViewShell)
1463 pViewShell->SetTabNo( nTab );
1465 ScPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ).UpdatePages();
1467 pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
1470 void ScUndoPrintRange::Undo()
1472 BeginUndo();
1473 DoChange( TRUE );
1474 EndUndo();
1477 void ScUndoPrintRange::Redo()
1479 BeginRedo();
1480 DoChange( FALSE );
1481 EndRedo();
1484 void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
1486 // gippsnich
1489 BOOL ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1491 return FALSE; // gippsnich
1494 String ScUndoPrintRange::GetComment() const
1496 return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
1500 //------------------------------------------------------------------------
1502 //---------------------------------------------------------------------------------
1504 // Szenario-Flags
1507 ScUndoScenarioFlags::ScUndoScenarioFlags( ScDocShell* pNewDocShell, SCTAB nT,
1508 const String& rON, const String& rNN, const String& rOC, const String& rNC,
1509 const Color& rOCol, const Color& rNCol, USHORT nOF, USHORT nNF ) :
1510 ScSimpleUndo( pNewDocShell ),
1511 nTab ( nT ),
1512 aOldName ( rON ),
1513 aNewName ( rNN ),
1514 aOldComment ( rOC ),
1515 aNewComment ( rNC ),
1516 aOldColor ( rOCol ),
1517 aNewColor ( rNCol ),
1518 nOldFlags ( nOF ),
1519 nNewFlags ( nNF )
1523 ScUndoScenarioFlags::~ScUndoScenarioFlags()
1527 String ScUndoScenarioFlags::GetComment() const
1529 return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
1532 void ScUndoScenarioFlags::Undo()
1534 ScDocument* pDoc = pDocShell->GetDocument();
1536 pDoc->RenameTab( nTab, aOldName );
1537 pDoc->SetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
1539 pDocShell->PostPaintGridAll();
1540 // Der Tabellenname koennte in einer Formel vorkommen...
1541 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1542 if (pViewShell)
1543 pViewShell->UpdateInputHandler();
1545 if ( aOldName != aNewName )
1546 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1549 void ScUndoScenarioFlags::Redo()
1551 ScDocument* pDoc = pDocShell->GetDocument();
1553 pDoc->RenameTab( nTab, aNewName );
1554 pDoc->SetScenarioData( nTab, aNewComment, aNewColor, nNewFlags );
1556 pDocShell->PostPaintGridAll();
1557 // Der Tabellenname koennte in einer Formel vorkommen...
1558 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1559 if (pViewShell)
1560 pViewShell->UpdateInputHandler();
1562 if ( aOldName != aNewName )
1563 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1566 void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
1568 // Repeat macht keinen Sinn
1571 BOOL ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1573 return FALSE;
1577 //---------------------------------------------------------------------------------
1579 // rename object
1580 // (move to different file?)
1583 ScUndoRenameObject::ScUndoRenameObject( ScDocShell* pNewDocShell, const String& rPN,
1584 const String& rON, const String& rNN ) :
1585 ScSimpleUndo( pNewDocShell ),
1586 aPersistName( rPN ),
1587 aOldName ( rON ),
1588 aNewName ( rNN )
1592 ScUndoRenameObject::~ScUndoRenameObject()
1596 String ScUndoRenameObject::GetComment() const
1598 // string resource shared with title for dialog
1599 return String( ScResId(SCSTR_RENAMEOBJECT) );
1602 SdrObject* ScUndoRenameObject::GetObject()
1604 ScDocument* pDoc = pDocShell->GetDocument();
1605 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1606 if ( pDrawLayer )
1608 USHORT nCount = pDrawLayer->GetPageCount();
1609 for (USHORT nTab=0; nTab<nCount; nTab++)
1611 SdrPage* pPage = pDrawLayer->GetPage(nTab);
1612 DBG_ASSERT(pPage,"Page ?");
1614 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
1615 SdrObject* pObject = aIter.Next();
1616 while (pObject)
1618 if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
1619 ((SdrOle2Obj*)pObject)->GetPersistName() == aPersistName )
1621 return pObject;
1624 pObject = aIter.Next();
1628 DBG_ERROR("Object not found");
1629 return NULL;
1632 void ScUndoRenameObject::Undo()
1634 BeginUndo();
1635 SdrObject* pObj = GetObject();
1636 if ( pObj )
1637 pObj->SetName( aOldName );
1638 EndUndo();
1641 void ScUndoRenameObject::Redo()
1643 BeginRedo();
1644 SdrObject* pObj = GetObject();
1645 if ( pObj )
1646 pObj->SetName( aNewName );
1647 EndRedo();
1650 void ScUndoRenameObject::Repeat(SfxRepeatTarget& /* rTarget */)
1654 BOOL ScUndoRenameObject::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1656 return FALSE;
1659 // -----------------------------------------------------------------------
1661 // Switch sheet between left-to-right and right-to-left
1664 ScUndoLayoutRTL::ScUndoLayoutRTL( ScDocShell* pShell, SCTAB nNewTab, BOOL bNewRTL ) :
1665 ScSimpleUndo( pShell ),
1666 nTab( nNewTab ),
1667 bRTL( bNewRTL )
1671 ScUndoLayoutRTL::~ScUndoLayoutRTL()
1675 void ScUndoLayoutRTL::DoChange( BOOL bNew )
1677 pDocShell->SetInUndo( TRUE );
1679 ScDocument* pDoc = pDocShell->GetDocument();
1680 pDoc->SetLayoutRTL( nTab, bNew );
1682 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1683 if (pViewShell)
1684 pViewShell->SetTabNo(nTab,TRUE);
1686 pDocShell->SetDocumentModified();
1688 pDocShell->SetInUndo( FALSE );
1691 void ScUndoLayoutRTL::Undo()
1693 DoChange(!bRTL);
1696 void ScUndoLayoutRTL::Redo()
1698 DoChange(bRTL);
1701 void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
1703 if (rTarget.ISA(ScTabViewTarget))
1704 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1705 Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1708 BOOL ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
1710 return (rTarget.ISA(ScTabViewTarget));
1713 String ScUndoLayoutRTL::GetComment() const
1715 return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
1720 // -----------------------------------------------------------------------
1722 // Set the grammar used for the sheet
1725 //UNUSED2009-05 ScUndoSetGrammar::ScUndoSetGrammar( ScDocShell* pShell,
1726 //UNUSED2009-05 formula::FormulaGrammar::Grammar eGrammar ) :
1727 //UNUSED2009-05 ScSimpleUndo( pShell ),
1728 //UNUSED2009-05 meNewGrammar( eGrammar )
1729 //UNUSED2009-05 {
1730 //UNUSED2009-05 meOldGrammar = pDocShell->GetDocument()->GetGrammar();
1731 //UNUSED2009-05 }
1732 //UNUSED2009-05
1733 //UNUSED2009-05 __EXPORT ScUndoSetGrammar::~ScUndoSetGrammar()
1734 //UNUSED2009-05 {
1735 //UNUSED2009-05 }
1736 //UNUSED2009-05
1737 //UNUSED2009-05 void ScUndoSetGrammar::DoChange( formula::FormulaGrammar::Grammar eGrammar )
1738 //UNUSED2009-05 {
1739 //UNUSED2009-05 pDocShell->SetInUndo( TRUE );
1740 //UNUSED2009-05 ScDocument* pDoc = pDocShell->GetDocument();
1741 //UNUSED2009-05 pDoc->SetGrammar( eGrammar );
1742 //UNUSED2009-05 pDocShell->SetDocumentModified();
1743 //UNUSED2009-05 pDocShell->SetInUndo( FALSE );
1744 //UNUSED2009-05 }
1745 //UNUSED2009-05
1746 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Undo()
1747 //UNUSED2009-05 {
1748 //UNUSED2009-05 DoChange( meOldGrammar );
1749 //UNUSED2009-05 }
1750 //UNUSED2009-05
1751 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Redo()
1752 //UNUSED2009-05 {
1753 //UNUSED2009-05 DoChange( meNewGrammar );
1754 //UNUSED2009-05 }
1755 //UNUSED2009-05
1756 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
1757 //UNUSED2009-05 {
1758 //UNUSED2009-05 #if 0
1759 //UNUSED2009-05 // erAck: 2006-09-07T23:00+0200 commented out in CWS scr1c1
1760 //UNUSED2009-05 if (rTarget.ISA(ScTabViewTarget))
1761 //UNUSED2009-05 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1762 //UNUSED2009-05 Execute( FID_TAB_USE_R1C1, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1763 //UNUSED2009-05 #endif
1764 //UNUSED2009-05 }
1765 //UNUSED2009-05
1766 //UNUSED2009-05 BOOL __EXPORT ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
1767 //UNUSED2009-05 {
1768 //UNUSED2009-05 return (rTarget.ISA(ScTabViewTarget));
1769 //UNUSED2009-05 }
1770 //UNUSED2009-05
1771 //UNUSED2009-05 String __EXPORT ScUndoSetGrammar::GetComment() const
1772 //UNUSED2009-05 {
1773 //UNUSED2009-05 return ScGlobal::GetRscString( STR_UNDO_TAB_R1C1 );
1774 //UNUSED2009-05 }