update dev300-m57
[ooovba.git] / sc / source / ui / undo / undotab.cxx
blob5650376b0e3b5cd42aa4e18d8f759a28411e4d60
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 extern BOOL bDrawIsInUndo; //! irgendwo als Member !!!
75 using namespace com::sun::star;
76 using ::com::sun::star::uno::Sequence;
77 using ::std::auto_ptr;
79 // STATIC DATA -----------------------------------------------------------
81 TYPEINIT1(ScUndoInsertTab, SfxUndoAction);
82 TYPEINIT1(ScUndoInsertTables, SfxUndoAction);
83 TYPEINIT1(ScUndoDeleteTab, SfxUndoAction);
84 TYPEINIT1(ScUndoRenameTab, SfxUndoAction);
85 TYPEINIT1(ScUndoMoveTab, SfxUndoAction);
86 TYPEINIT1(ScUndoCopyTab, SfxUndoAction);
87 TYPEINIT1(ScUndoMakeScenario, SfxUndoAction);
88 TYPEINIT1(ScUndoImportTab, SfxUndoAction);
89 TYPEINIT1(ScUndoRemoveLink, SfxUndoAction);
90 TYPEINIT1(ScUndoShowHideTab, SfxUndoAction);
91 TYPEINIT1(ScUndoPrintRange, SfxUndoAction);
92 TYPEINIT1(ScUndoScenarioFlags, SfxUndoAction);
93 TYPEINIT1(ScUndoRenameObject, SfxUndoAction);
94 TYPEINIT1(ScUndoLayoutRTL, SfxUndoAction);
95 //UNUSED2009-05 TYPEINIT1(ScUndoSetGrammar, SfxUndoAction);
98 // -----------------------------------------------------------------------
100 // Tabelle einfuegen
103 ScUndoInsertTab::ScUndoInsertTab( ScDocShell* pNewDocShell,
104 SCTAB nTabNum,
105 BOOL bApp,
106 const String& rNewName) :
107 ScSimpleUndo( pNewDocShell ),
108 sNewName( rNewName ),
109 pDrawUndo( NULL ),
110 nTab( nTabNum ),
111 bAppend( bApp )
113 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
114 SetChangeTrack();
117 ScUndoInsertTab::~ScUndoInsertTab()
119 DeleteSdrUndoAction( pDrawUndo );
122 String ScUndoInsertTab::GetComment() const
124 if (bAppend)
125 return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
126 else
127 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
130 void ScUndoInsertTab::SetChangeTrack()
132 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
133 if ( pChangeTrack )
135 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
136 pChangeTrack->AppendInsert( aRange );
137 nEndChangeAction = pChangeTrack->GetActionMax();
139 else
140 nEndChangeAction = 0;
143 void ScUndoInsertTab::Undo()
145 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
146 pViewShell->SetTabNo(nTab);
148 pDocShell->SetInUndo( TRUE ); //! BeginUndo
149 bDrawIsInUndo = TRUE;
150 pViewShell->DeleteTable( nTab, FALSE );
151 bDrawIsInUndo = FALSE;
152 pDocShell->SetInUndo( FALSE ); //! EndUndo
154 DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
156 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
157 if ( pChangeTrack )
158 pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
160 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
161 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
164 void ScUndoInsertTab::Redo()
166 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
168 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
170 pDocShell->SetInUndo( TRUE ); //! BeginRedo
171 bDrawIsInUndo = TRUE;
172 if (bAppend)
173 pViewShell->AppendTable( sNewName, FALSE );
174 else
176 pViewShell->SetTabNo(nTab);
177 pViewShell->InsertTable( sNewName, nTab, FALSE );
179 bDrawIsInUndo = FALSE;
180 pDocShell->SetInUndo( FALSE ); //! EndRedo
182 SetChangeTrack();
185 void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
187 if (rTarget.ISA(ScTabViewTarget))
188 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
189 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
192 BOOL ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
194 return (rTarget.ISA(ScTabViewTarget));
197 // -----------------------------------------------------------------------
199 // Tabellen einfuegen
202 ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
203 SCTAB nTabNum,
204 BOOL bApp,SvStrings *pNewNameList) :
205 ScSimpleUndo( pNewDocShell ),
206 pDrawUndo( NULL ),
207 nTab( nTabNum ),
208 bAppend( bApp )
210 pNameList = pNewNameList;
211 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
213 SetChangeTrack();
216 ScUndoInsertTables::~ScUndoInsertTables()
218 String *pStr=NULL;
219 if(pNameList!=NULL)
221 for(int i=0;i<pNameList->Count();i++)
223 pStr=pNameList->GetObject(sal::static_int_cast<USHORT>(i));
224 delete pStr;
226 pNameList->Remove(0,pNameList->Count());
227 delete pNameList;
229 DeleteSdrUndoAction( pDrawUndo );
232 String ScUndoInsertTables::GetComment() const
234 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
237 void ScUndoInsertTables::SetChangeTrack()
239 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
240 if ( pChangeTrack )
242 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
243 nEndChangeAction = 0;
244 ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
245 for( int i = 0; i < pNameList->Count(); i++ )
247 aRange.aStart.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
248 aRange.aEnd.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
249 pChangeTrack->AppendInsert( aRange );
250 nEndChangeAction = pChangeTrack->GetActionMax();
253 else
254 nStartChangeAction = nEndChangeAction = 0;
257 void ScUndoInsertTables::Undo()
259 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
260 pViewShell->SetTabNo(nTab);
262 pDocShell->SetInUndo( TRUE ); //! BeginUndo
263 bDrawIsInUndo = TRUE;
265 SvShorts TheTabs;
266 for(int i=0;i<pNameList->Count();i++)
268 TheTabs.Insert( sal::static_int_cast<short>(nTab+i), TheTabs.Count() );
271 pViewShell->DeleteTables( TheTabs, FALSE );
272 TheTabs.Remove(0,TheTabs.Count());
274 bDrawIsInUndo = FALSE;
275 pDocShell->SetInUndo( FALSE ); //! EndUndo
277 DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
279 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
280 if ( pChangeTrack )
281 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
283 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
284 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
287 void ScUndoInsertTables::Redo()
289 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
291 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
293 pDocShell->SetInUndo( TRUE ); //! BeginRedo
294 bDrawIsInUndo = TRUE;
295 pViewShell->SetTabNo(nTab);
296 pViewShell->InsertTables( pNameList, nTab, static_cast<SCTAB>(pNameList->Count()),FALSE );
298 bDrawIsInUndo = FALSE;
299 pDocShell->SetInUndo( FALSE ); //! EndRedo
301 SetChangeTrack();
304 void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
306 if (rTarget.ISA(ScTabViewTarget))
307 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
308 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
311 BOOL ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
313 return (rTarget.ISA(ScTabViewTarget));
317 //----------------------------------------------------------------------------------
319 // Tabelle loeschen
322 ScUndoDeleteTab::ScUndoDeleteTab( ScDocShell* pNewDocShell,const SvShorts &aTab, //SCTAB nNewTab,
323 ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
324 ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST )
326 for(int i=0;i<aTab.Count();i++)
327 theTabs.Insert(aTab[sal::static_int_cast<USHORT>(i)],theTabs.Count());
329 SetChangeTrack();
332 ScUndoDeleteTab::~ScUndoDeleteTab()
334 theTabs.Remove(0,theTabs.Count());
337 String ScUndoDeleteTab::GetComment() const
339 return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
342 void ScUndoDeleteTab::SetChangeTrack()
344 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
345 if ( pChangeTrack )
347 ULONG nTmpChangeAction;
348 nStartChangeAction = pChangeTrack->GetActionMax() + 1;
349 nEndChangeAction = 0;
350 ScRange aRange( 0, 0, 0, MAXCOL, MAXROW, 0 );
351 for ( int i = 0; i < theTabs.Count(); i++ )
353 aRange.aStart.SetTab( theTabs[sal::static_int_cast<USHORT>(i)] );
354 aRange.aEnd.SetTab( theTabs[sal::static_int_cast<USHORT>(i)] );
355 pChangeTrack->AppendDeleteRange( aRange, pRefUndoDoc,
356 nTmpChangeAction, nEndChangeAction, (short) i );
359 else
360 nStartChangeAction = nEndChangeAction = 0;
363 SCTAB lcl_GetVisibleTabBefore( ScDocument& rDoc, SCTAB nTab )
365 while ( nTab > 0 && !rDoc.IsVisible( nTab ) )
366 --nTab;
368 return nTab;
371 void ScUndoDeleteTab::Undo()
373 BeginUndo();
374 int i=0;
375 ScDocument* pDoc = pDocShell->GetDocument();
377 BOOL bLink = FALSE;
378 String aName;
380 for(i=0;i<theTabs.Count();i++)
382 SCTAB nTab = theTabs[sal::static_int_cast<USHORT>(i)];
383 pRefUndoDoc->GetName( nTab, aName );
385 bDrawIsInUndo = TRUE;
386 BOOL bOk = pDoc->InsertTab( nTab, aName );
387 bDrawIsInUndo = FALSE;
388 if (bOk)
390 // Ref-Undo passiert in EndUndo
391 // pUndoDoc->UndoToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,FALSE, pDoc );
392 pRefUndoDoc->CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,FALSE, pDoc );
394 String aOldName;
395 pRefUndoDoc->GetName( nTab, aOldName );
396 pDoc->RenameTab( nTab, aOldName, FALSE );
397 if (pRefUndoDoc->IsLinked(nTab))
399 pDoc->SetLink( nTab, pRefUndoDoc->GetLinkMode(nTab), pRefUndoDoc->GetLinkDoc(nTab),
400 pRefUndoDoc->GetLinkFlt(nTab), pRefUndoDoc->GetLinkOpt(nTab),
401 pRefUndoDoc->GetLinkTab(nTab), pRefUndoDoc->GetLinkRefreshDelay(nTab) );
402 bLink = TRUE;
405 if ( pRefUndoDoc->IsScenario(nTab) )
407 pDoc->SetScenario( nTab, TRUE );
408 String aComment;
409 Color aColor;
410 USHORT nScenFlags;
411 pRefUndoDoc->GetScenarioData( nTab, aComment, aColor, nScenFlags );
412 pDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
413 BOOL bActive = pRefUndoDoc->IsActiveScenario( nTab );
414 pDoc->SetActiveScenario( nTab, bActive );
416 pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
418 if ( pRefUndoDoc->IsTabProtected( nTab ) )
419 pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
421 // Drawing-Layer passiert beim MoveUndo::EndUndo
422 // pDoc->TransferDrawPage(pRefUndoDoc, nTab,nTab);
425 if (bLink)
427 pDocShell->UpdateLinks(); // Link-Manager updaten
430 EndUndo(); // Draw-Undo muss vor dem Broadcast kommen!
432 ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
433 if ( pChangeTrack )
434 pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
436 for(i=0;i<theTabs.Count();i++)
438 pDocShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, theTabs[sal::static_int_cast<USHORT>(i)]) );
440 SfxApplication* pSfxApp = SFX_APP(); // Navigator
441 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
442 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
443 pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
445 pDocShell->PostPaint(0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_ALL ); // incl. Extras
447 // nicht ShowTable wegen SetTabNo(..., TRUE):
448 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
449 if (pViewShell)
450 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDoc, theTabs[0] ), TRUE );
452 // EndUndo();
455 void ScUndoDeleteTab::Redo()
457 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
458 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs[0] ) );
460 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
462 pDocShell->SetInUndo( TRUE ); //! BeginRedo
463 bDrawIsInUndo = TRUE;
464 pViewShell->DeleteTables( theTabs, FALSE );
465 bDrawIsInUndo = FALSE;
466 pDocShell->SetInUndo( TRUE ); //! EndRedo
468 SetChangeTrack();
470 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
471 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
474 void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
476 if (rTarget.ISA(ScTabViewTarget))
478 ScTabViewShell* pViewShell = ((ScTabViewTarget&)rTarget).GetViewShell();
479 pViewShell->DeleteTable( pViewShell->GetViewData()->GetTabNo(), TRUE );
483 BOOL ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
485 return (rTarget.ISA(ScTabViewTarget));
489 //---------------------------------------------------------------------------------
491 // Tabelle umbenennen
494 ScUndoRenameTab::ScUndoRenameTab( ScDocShell* pNewDocShell,
495 SCTAB nT,
496 const String& rOldName,
497 const String& rNewName) :
498 ScSimpleUndo( pNewDocShell ),
499 nTab ( nT )
501 sOldName = rOldName;
502 sNewName = rNewName;
505 ScUndoRenameTab::~ScUndoRenameTab()
509 String ScUndoRenameTab::GetComment() const
511 return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
514 void ScUndoRenameTab::DoChange( SCTAB nTabP, const String& rName ) const
516 ScDocument* pDoc = pDocShell->GetDocument();
517 pDoc->RenameTab( nTabP, rName );
519 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
521 pDocShell->PostPaintGridAll();
522 pDocShell->PostPaintExtras();
523 pDocShell->PostDataChanged();
525 // Der Tabellenname koennte in einer Formel vorkommen...
526 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
527 if (pViewShell)
528 pViewShell->UpdateInputHandler();
531 void ScUndoRenameTab::Undo()
533 DoChange(nTab, sOldName);
536 void ScUndoRenameTab::Redo()
538 DoChange(nTab, sNewName);
541 void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
543 // Repeat macht keinen Sinn
546 BOOL ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
548 return FALSE;
552 //----------------------------------------------------------------------------------
554 // Tabelle verschieben
557 ScUndoMoveTab::ScUndoMoveTab( ScDocShell* pNewDocShell,
558 const SvShorts &aOldTab,
559 const SvShorts &aNewTab) :
560 ScSimpleUndo( pNewDocShell )
562 int i;
563 for(i=0;i<aOldTab.Count();i++)
564 theOldTabs.Insert(aOldTab[sal::static_int_cast<USHORT>(i)],theOldTabs.Count());
566 for(i=0;i<aNewTab.Count();i++)
567 theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
570 ScUndoMoveTab::~ScUndoMoveTab()
572 theNewTabs.Remove(0,theNewTabs.Count());
573 theOldTabs.Remove(0,theOldTabs.Count());
576 String ScUndoMoveTab::GetComment() const
578 return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
581 void ScUndoMoveTab::DoChange( BOOL bUndo ) const
583 ScDocument* pDoc = pDocShell->GetDocument();
584 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
586 if (bUndo) // UnDo
588 for(int i=theNewTabs.Count()-1;i>=0;i--)
590 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
591 SCTAB nOldTab = theOldTabs[sal::static_int_cast<USHORT>(i)];
592 if (nDestTab > MAXTAB) // angehaengt ?
593 nDestTab = pDoc->GetTableCount() - 1;
595 pDoc->MoveTab( nDestTab, nOldTab );
596 pViewShell->GetViewData()->MoveTab( nDestTab, nOldTab );
597 pViewShell->SetTabNo( nOldTab, TRUE );
600 else
602 for(int i=0;i<theNewTabs.Count();i++)
604 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
605 SCTAB nNewTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
606 SCTAB nOldTab = theOldTabs[sal::static_int_cast<USHORT>(i)];
607 if (nDestTab > MAXTAB) // angehaengt ?
608 nDestTab = pDoc->GetTableCount() - 1;
610 pDoc->MoveTab( nOldTab, nNewTab );
611 pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
612 pViewShell->SetTabNo( nDestTab, TRUE );
616 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
618 pDocShell->PostPaintGridAll();
619 pDocShell->PostPaintExtras();
620 pDocShell->PostDataChanged();
623 void ScUndoMoveTab::Undo()
625 DoChange( TRUE );
628 void ScUndoMoveTab::Redo()
630 DoChange( FALSE );
633 void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
635 // kein Repeat ! ? !
638 BOOL ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
640 return FALSE;
644 //----------------------------------------------------------------------------------
646 // Tabelle kopieren
649 ScUndoCopyTab::ScUndoCopyTab( ScDocShell* pNewDocShell,
650 const SvShorts &aOldTab,
651 const SvShorts &aNewTab) :
652 ScSimpleUndo( pNewDocShell ),
653 pDrawUndo( NULL )
655 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
657 int i;
658 for(i=0;i<aOldTab.Count();i++)
659 theOldTabs.Insert(aOldTab[sal::static_int_cast<USHORT>(i)],theOldTabs.Count());
661 for(i=0;i<aNewTab.Count();i++)
662 theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
665 ScUndoCopyTab::~ScUndoCopyTab()
667 DeleteSdrUndoAction( pDrawUndo );
670 String ScUndoCopyTab::GetComment() const
672 return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
675 void ScUndoCopyTab::DoChange() const
677 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
679 if (pViewShell)
680 pViewShell->SetTabNo(theOldTabs[0],TRUE);
682 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); // Navigator
684 pDocShell->PostPaintGridAll();
685 pDocShell->PostPaintExtras();
686 pDocShell->PostDataChanged();
689 void ScUndoCopyTab::Undo()
691 ScDocument* pDoc = pDocShell->GetDocument();
693 DoSdrUndoAction( pDrawUndo, pDoc ); // before the sheets are deleted
695 int i;
696 for(i=theNewTabs.Count()-1;i>=0;i--)
698 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
699 if (nDestTab > MAXTAB) // append?
700 nDestTab = pDoc->GetTableCount() - 1;
702 bDrawIsInUndo = TRUE;
703 pDoc->DeleteTab(nDestTab);
704 bDrawIsInUndo = FALSE;
707 // ScTablesHint broadcasts after all sheets have been deleted,
708 // so sheets and draw pages are in sync!
710 for(i=theNewTabs.Count()-1;i>=0;i--)
712 SCTAB nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
713 if (nDestTab > MAXTAB) // append?
714 nDestTab = pDoc->GetTableCount() - 1;
716 pDocShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nDestTab ) );
719 DoChange();
722 void ScUndoCopyTab::Redo()
724 ScDocument* pDoc = pDocShell->GetDocument();
725 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
727 SCTAB nDestTab = 0;
728 for(int i=0;i<theNewTabs.Count();i++)
730 nDestTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
731 SCTAB nNewTab = theNewTabs[sal::static_int_cast<USHORT>(i)];
732 SCTAB nOldTab = theOldTabs[sal::static_int_cast<USHORT>(i)];
733 if (nDestTab > MAXTAB) // angehaengt ?
734 nDestTab = pDoc->GetTableCount() - 1;
736 bDrawIsInUndo = TRUE;
737 pDoc->CopyTab( nOldTab, nNewTab );
738 bDrawIsInUndo = FALSE;
740 pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
742 SCTAB nAdjSource = nOldTab;
743 if ( nNewTab <= nOldTab )
744 ++nAdjSource; // new position of source table after CopyTab
746 if ( pDoc->IsScenario(nAdjSource) )
748 pDoc->SetScenario(nNewTab, TRUE );
749 String aComment;
750 Color aColor;
751 USHORT nScenFlags;
752 pDoc->GetScenarioData(nAdjSource, aComment, aColor, nScenFlags );
753 pDoc->SetScenarioData(nNewTab, aComment, aColor, nScenFlags );
754 BOOL bActive = pDoc->IsActiveScenario(nAdjSource);
755 pDoc->SetActiveScenario(nNewTab, bActive );
756 BOOL bVisible=pDoc->IsVisible(nAdjSource);
757 pDoc->SetVisible(nNewTab,bVisible );
760 if ( pDoc->IsTabProtected( nAdjSource ) )
761 pDoc->CopyTabProtection(nAdjSource, nNewTab);
764 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
766 pViewShell->SetTabNo( nDestTab, TRUE ); // after draw-undo
768 DoChange();
772 void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
774 // kein Repeat ! ? !
777 BOOL ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
779 return FALSE;
783 // -----------------------------------------------------------------------
785 // Szenario anlegen
788 ScUndoMakeScenario::ScUndoMakeScenario( ScDocShell* pNewDocShell,
789 SCTAB nSrc, SCTAB nDest,
790 const String& rN, const String& rC,
791 const Color& rCol, USHORT nF,
792 const ScMarkData& rMark ) :
793 ScSimpleUndo( pNewDocShell ),
794 nSrcTab( nSrc ),
795 nDestTab( nDest ),
796 aName( rN ),
797 aComment( rC ),
798 aColor( rCol ),
799 nFlags( nF ),
800 aMarkData( rMark ),
801 pDrawUndo( NULL )
803 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
806 ScUndoMakeScenario::~ScUndoMakeScenario()
808 DeleteSdrUndoAction( pDrawUndo );
811 String ScUndoMakeScenario::GetComment() const
813 return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
816 void ScUndoMakeScenario::Undo()
818 ScDocument* pDoc = pDocShell->GetDocument();
820 pDocShell->SetInUndo( TRUE );
821 bDrawIsInUndo = TRUE;
822 pDoc->DeleteTab( nDestTab );
823 bDrawIsInUndo = FALSE;
824 pDocShell->SetInUndo( FALSE );
826 DoSdrUndoAction( pDrawUndo, pDoc );
828 pDocShell->PostPaint(0,0,nDestTab,MAXCOL,MAXROW,MAXTAB, PAINT_ALL);
829 pDocShell->PostDataChanged();
831 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
832 if (pViewShell)
833 pViewShell->SetTabNo( nSrcTab, TRUE );
835 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
837 // SetTabNo(...,TRUE) for all views to sync with drawing layer pages
838 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
841 void ScUndoMakeScenario::Redo()
843 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
844 if (pViewShell)
845 pViewShell->SetMarkData( aMarkData );
847 RedoSdrUndoAction( pDrawUndo ); // Draw Redo first
849 pDocShell->SetInUndo( TRUE );
850 bDrawIsInUndo = TRUE;
852 pDocShell->MakeScenario( nSrcTab, aName, aComment, aColor, nFlags, aMarkData, FALSE );
854 bDrawIsInUndo = FALSE;
855 pDocShell->SetInUndo( FALSE );
857 if (pViewShell)
858 pViewShell->SetTabNo( nDestTab, TRUE );
860 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
863 void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
865 if (rTarget.ISA(ScTabViewTarget))
867 ((ScTabViewTarget&)rTarget).GetViewShell()->MakeScenario( aName, aComment, aColor, nFlags );
871 BOOL ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
873 return (rTarget.ISA(ScTabViewTarget));
877 // -----------------------------------------------------------------------
879 // Tabelle einfuegen
882 ScUndoImportTab::ScUndoImportTab( ScDocShell* pShell,
883 SCTAB nNewTab, SCTAB nNewCount, BOOL bNewLink ) :
884 ScSimpleUndo( pShell ),
885 nTab( nNewTab ),
886 nCount( nNewCount ),
887 bLink( bNewLink ),
888 pRedoDoc( NULL ),
889 pDrawUndo( NULL )
891 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
894 ScUndoImportTab::~ScUndoImportTab()
896 delete pRedoDoc;
897 DeleteSdrUndoAction( pDrawUndo );
900 String 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,TRUE);
916 else
918 pViewShell->SetTabNo(nTab-1,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 //! eingefuegte Bereichsnamen etc.
931 SCTAB i;
932 ScDocument* pDoc = pDocShell->GetDocument();
933 BOOL bMakeRedo = !pRedoDoc;
934 if (bMakeRedo)
936 pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
937 pRedoDoc->InitUndo( pDoc, nTab,nTab+nCount-1, TRUE,TRUE );
939 String 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 );
948 if ( pDoc->IsScenario(nTabPos) )
950 pRedoDoc->SetScenario(nTabPos, TRUE );
951 String aComment;
952 Color aColor;
953 USHORT nScenFlags;
954 pDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
955 pRedoDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
956 BOOL bActive = pDoc->IsActiveScenario(nTabPos);
957 pRedoDoc->SetActiveScenario(nTabPos, bActive );
958 BOOL bVisible=pDoc->IsVisible(nTabPos);
959 pRedoDoc->SetVisible(nTabPos,bVisible );
962 if ( pDoc->IsTabProtected( nTabPos ) )
963 pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
968 DoSdrUndoAction( pDrawUndo, pDoc ); // before the sheets are deleted
970 bDrawIsInUndo = TRUE;
971 for (i=0; i<nCount; i++)
972 pDoc->DeleteTab( nTab );
973 bDrawIsInUndo = FALSE;
975 DoChange();
978 void ScUndoImportTab::Redo()
980 if (!pRedoDoc)
982 DBG_ERROR("wo ist mein Redo-Document?");
983 return;
986 ScDocument* pDoc = pDocShell->GetDocument();
987 String aName;
988 SCTAB i;
989 for (i=0; i<nCount; i++) // first insert all sheets (#63304#)
991 SCTAB nTabPos=nTab+i;
992 pRedoDoc->GetName(nTabPos,aName);
993 bDrawIsInUndo = TRUE;
994 pDoc->InsertTab(nTabPos,aName);
995 bDrawIsInUndo = FALSE;
997 for (i=0; i<nCount; i++) // then copy into inserted sheets
999 SCTAB nTabPos=nTab+i;
1000 pRedoDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,FALSE, pDoc );
1002 if ( pRedoDoc->IsScenario(nTabPos) )
1004 pDoc->SetScenario(nTabPos, TRUE );
1005 String aComment;
1006 Color aColor;
1007 USHORT nScenFlags;
1008 pRedoDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1009 pDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1010 BOOL bActive = pRedoDoc->IsActiveScenario(nTabPos);
1011 pDoc->SetActiveScenario(nTabPos, bActive );
1012 BOOL bVisible=pRedoDoc->IsVisible(nTabPos);
1013 pDoc->SetVisible(nTabPos,bVisible );
1016 if ( pRedoDoc->IsTabProtected( nTabPos ) )
1017 pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
1020 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
1022 DoChange();
1025 void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
1027 if (rTarget.ISA(ScTabViewTarget))
1028 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1029 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1032 BOOL ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
1034 return (rTarget.ISA(ScTabViewTarget));
1038 // -----------------------------------------------------------------------
1040 // Tabellen-Verknuepfung aufheben
1043 ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const String& rDoc ) :
1044 ScSimpleUndo( pShell ),
1045 aDocName( rDoc ),
1046 nCount( 0 )
1048 ScDocument* pDoc = pDocShell->GetDocument();
1049 SCTAB nTabCount = pDoc->GetTableCount();
1050 pTabs = new SCTAB[nTabCount];
1051 pModes = new BYTE[nTabCount];
1052 pTabNames = new String[nTabCount];
1054 for (SCTAB i=0; i<nTabCount; i++)
1056 BYTE nMode = pDoc->GetLinkMode(i);
1057 if (nMode)
1058 if (pDoc->GetLinkDoc(i) == aDocName)
1060 if (!nCount)
1062 aFltName = pDoc->GetLinkFlt(i);
1063 aOptions = pDoc->GetLinkOpt(i);
1064 nRefreshDelay = pDoc->GetLinkRefreshDelay(i);
1066 else
1068 DBG_ASSERT(aFltName == pDoc->GetLinkFlt(i) &&
1069 aOptions == pDoc->GetLinkOpt(i),
1070 "verschiedene Filter fuer ein Dokument?");
1072 pTabs[nCount] = i;
1073 pModes[nCount] = nMode;
1074 pTabNames[nCount] = pDoc->GetLinkTab(i);
1075 ++nCount;
1080 ScUndoRemoveLink::~ScUndoRemoveLink()
1082 delete pTabs;
1083 delete pModes;
1084 delete[] pTabNames;
1087 String ScUndoRemoveLink::GetComment() const
1089 return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
1092 void ScUndoRemoveLink::DoChange( BOOL bLink ) const
1094 ScDocument* pDoc = pDocShell->GetDocument();
1095 String aEmpty;
1096 for (USHORT i=0; i<nCount; i++)
1097 if (bLink) // establish link
1098 pDoc->SetLink( pTabs[i], pModes[i], aDocName, aFltName, aOptions, pTabNames[i], nRefreshDelay );
1099 else // remove link
1100 pDoc->SetLink( pTabs[i], SC_LINK_NONE, aEmpty, aEmpty, aEmpty, aEmpty, 0 );
1101 pDocShell->UpdateLinks();
1104 void ScUndoRemoveLink::Undo()
1106 DoChange( TRUE );
1109 void ScUndoRemoveLink::Redo()
1111 DoChange( FALSE );
1114 void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
1116 // gippsnich
1119 BOOL ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1121 return FALSE;
1125 // -----------------------------------------------------------------------
1127 // Tabellen ein-/ausblenden
1130 ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, SCTAB nNewTab, BOOL bNewShow ) :
1131 ScSimpleUndo( pShell ),
1132 nTab( nNewTab ),
1133 bShow( bNewShow )
1137 ScUndoShowHideTab::~ScUndoShowHideTab()
1141 void ScUndoShowHideTab::DoChange( BOOL bShowP ) const
1143 ScDocument* pDoc = pDocShell->GetDocument();
1144 pDoc->SetVisible( nTab, bShowP );
1146 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1147 if (pViewShell)
1148 pViewShell->SetTabNo(nTab,TRUE);
1150 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1151 pDocShell->SetDocumentModified();
1154 void ScUndoShowHideTab::Undo()
1156 DoChange(!bShow);
1159 void ScUndoShowHideTab::Redo()
1161 DoChange(bShow);
1164 void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
1166 if (rTarget.ISA(ScTabViewTarget))
1167 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1168 Execute( bShow ? FID_TABLE_SHOW : FID_TABLE_HIDE,
1169 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1172 BOOL ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
1174 return (rTarget.ISA(ScTabViewTarget));
1177 String ScUndoShowHideTab::GetComment() const
1179 USHORT nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
1180 return ScGlobal::GetRscString( nId );
1183 // ============================================================================
1185 ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
1186 ScSimpleUndo(pShell),
1187 mpProtectSettings(pProtectSettings)
1191 ScUndoDocProtect::~ScUndoDocProtect()
1195 void ScUndoDocProtect::DoProtect(bool bProtect)
1197 ScDocument* pDoc = pDocShell->GetDocument();
1199 if (bProtect)
1201 // set protection.
1202 auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
1203 pCopy->setProtected(true);
1204 pDoc->SetDocProtection(pCopy.get());
1206 else
1208 // remove protection.
1209 pDoc->SetDocProtection(NULL);
1212 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1213 if (pViewShell)
1215 pViewShell->UpdateLayerLocks();
1216 pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
1219 pDocShell->PostPaintGridAll();
1222 void ScUndoDocProtect::Undo()
1224 BeginUndo();
1225 DoProtect(!mpProtectSettings->isProtected());
1226 EndUndo();
1229 void ScUndoDocProtect::Redo()
1231 BeginRedo();
1232 DoProtect(mpProtectSettings->isProtected());
1233 EndRedo();
1236 void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1238 // gippsnich
1241 BOOL ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1243 return FALSE; // gippsnich
1246 String ScUndoDocProtect::GetComment() const
1248 USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
1249 return ScGlobal::GetRscString( nId );
1252 // ============================================================================
1254 ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
1255 ScSimpleUndo(pShell),
1256 mnTab(nTab),
1257 mpProtectSettings(pProtectSettings)
1261 ScUndoTabProtect::~ScUndoTabProtect()
1265 void ScUndoTabProtect::DoProtect(bool bProtect)
1267 ScDocument* pDoc = pDocShell->GetDocument();
1269 if (bProtect)
1271 // set protection.
1272 auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
1273 pCopy->setProtected(true);
1274 pDoc->SetTabProtection(mnTab, pCopy.get());
1276 else
1278 // remove protection.
1279 pDoc->SetTabProtection(mnTab, NULL);
1282 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1283 if (pViewShell)
1285 pViewShell->UpdateLayerLocks();
1286 pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
1289 pDocShell->PostPaintGridAll();
1292 void ScUndoTabProtect::Undo()
1294 BeginUndo();
1295 DoProtect(!mpProtectSettings->isProtected());
1296 EndUndo();
1299 void ScUndoTabProtect::Redo()
1301 BeginRedo();
1302 DoProtect(mpProtectSettings->isProtected());
1303 EndRedo();
1306 void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1308 // gippsnich
1311 BOOL ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1313 return FALSE; // gippsnich
1316 String ScUndoTabProtect::GetComment() const
1318 USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
1319 return ScGlobal::GetRscString( nId );
1322 // -----------------------------------------------------------------------
1324 // Druck-/Wiederholungsbereiche aendern
1327 ScUndoPrintRange::ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
1328 ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew ) :
1329 ScSimpleUndo( pShell ),
1330 nTab( nNewTab ),
1331 pOldRanges( pOld ),
1332 pNewRanges( pNew )
1336 ScUndoPrintRange::~ScUndoPrintRange()
1338 delete pOldRanges;
1339 delete pNewRanges;
1342 void ScUndoPrintRange::DoChange(BOOL bUndo)
1344 ScDocument* pDoc = pDocShell->GetDocument();
1345 if (bUndo)
1346 pDoc->RestorePrintRanges( *pOldRanges );
1347 else
1348 pDoc->RestorePrintRanges( *pNewRanges );
1350 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1351 if (pViewShell)
1352 pViewShell->SetTabNo( nTab );
1354 ScPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ).UpdatePages();
1356 pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
1359 void ScUndoPrintRange::Undo()
1361 BeginUndo();
1362 DoChange( TRUE );
1363 EndUndo();
1366 void ScUndoPrintRange::Redo()
1368 BeginRedo();
1369 DoChange( FALSE );
1370 EndRedo();
1373 void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
1375 // gippsnich
1378 BOOL ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1380 return FALSE; // gippsnich
1383 String ScUndoPrintRange::GetComment() const
1385 return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
1389 //------------------------------------------------------------------------
1391 //---------------------------------------------------------------------------------
1393 // Szenario-Flags
1396 ScUndoScenarioFlags::ScUndoScenarioFlags( ScDocShell* pNewDocShell, SCTAB nT,
1397 const String& rON, const String& rNN, const String& rOC, const String& rNC,
1398 const Color& rOCol, const Color& rNCol, USHORT nOF, USHORT nNF ) :
1399 ScSimpleUndo( pNewDocShell ),
1400 nTab ( nT ),
1401 aOldName ( rON ),
1402 aNewName ( rNN ),
1403 aOldComment ( rOC ),
1404 aNewComment ( rNC ),
1405 aOldColor ( rOCol ),
1406 aNewColor ( rNCol ),
1407 nOldFlags ( nOF ),
1408 nNewFlags ( nNF )
1412 ScUndoScenarioFlags::~ScUndoScenarioFlags()
1416 String ScUndoScenarioFlags::GetComment() const
1418 return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
1421 void ScUndoScenarioFlags::Undo()
1423 ScDocument* pDoc = pDocShell->GetDocument();
1425 pDoc->RenameTab( nTab, aOldName );
1426 pDoc->SetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
1428 pDocShell->PostPaintGridAll();
1429 // Der Tabellenname koennte in einer Formel vorkommen...
1430 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1431 if (pViewShell)
1432 pViewShell->UpdateInputHandler();
1434 if ( aOldName != aNewName )
1435 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1438 void ScUndoScenarioFlags::Redo()
1440 ScDocument* pDoc = pDocShell->GetDocument();
1442 pDoc->RenameTab( nTab, aNewName );
1443 pDoc->SetScenarioData( nTab, aNewComment, aNewColor, nNewFlags );
1445 pDocShell->PostPaintGridAll();
1446 // Der Tabellenname koennte in einer Formel vorkommen...
1447 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1448 if (pViewShell)
1449 pViewShell->UpdateInputHandler();
1451 if ( aOldName != aNewName )
1452 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1455 void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
1457 // Repeat macht keinen Sinn
1460 BOOL ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1462 return FALSE;
1466 //---------------------------------------------------------------------------------
1468 // rename object
1469 // (move to different file?)
1472 ScUndoRenameObject::ScUndoRenameObject( ScDocShell* pNewDocShell, const String& rPN,
1473 const String& rON, const String& rNN ) :
1474 ScSimpleUndo( pNewDocShell ),
1475 aPersistName( rPN ),
1476 aOldName ( rON ),
1477 aNewName ( rNN )
1481 ScUndoRenameObject::~ScUndoRenameObject()
1485 String ScUndoRenameObject::GetComment() const
1487 // string resource shared with title for dialog
1488 return String( ScResId(SCSTR_RENAMEOBJECT) );
1491 SdrObject* ScUndoRenameObject::GetObject()
1493 ScDocument* pDoc = pDocShell->GetDocument();
1494 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1495 if ( pDrawLayer )
1497 USHORT nCount = pDrawLayer->GetPageCount();
1498 for (USHORT nTab=0; nTab<nCount; nTab++)
1500 SdrPage* pPage = pDrawLayer->GetPage(nTab);
1501 DBG_ASSERT(pPage,"Page ?");
1503 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
1504 SdrObject* pObject = aIter.Next();
1505 while (pObject)
1507 if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
1508 ((SdrOle2Obj*)pObject)->GetPersistName() == aPersistName )
1510 return pObject;
1513 pObject = aIter.Next();
1517 DBG_ERROR("Object not found");
1518 return NULL;
1521 void ScUndoRenameObject::Undo()
1523 BeginUndo();
1524 SdrObject* pObj = GetObject();
1525 if ( pObj )
1526 pObj->SetName( aOldName );
1527 EndUndo();
1530 void ScUndoRenameObject::Redo()
1532 BeginRedo();
1533 SdrObject* pObj = GetObject();
1534 if ( pObj )
1535 pObj->SetName( aNewName );
1536 EndRedo();
1539 void ScUndoRenameObject::Repeat(SfxRepeatTarget& /* rTarget */)
1543 BOOL ScUndoRenameObject::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1545 return FALSE;
1548 // -----------------------------------------------------------------------
1550 // Switch sheet between left-to-right and right-to-left
1553 ScUndoLayoutRTL::ScUndoLayoutRTL( ScDocShell* pShell, SCTAB nNewTab, BOOL bNewRTL ) :
1554 ScSimpleUndo( pShell ),
1555 nTab( nNewTab ),
1556 bRTL( bNewRTL )
1560 ScUndoLayoutRTL::~ScUndoLayoutRTL()
1564 void ScUndoLayoutRTL::DoChange( BOOL bNew )
1566 pDocShell->SetInUndo( TRUE );
1568 ScDocument* pDoc = pDocShell->GetDocument();
1569 pDoc->SetLayoutRTL( nTab, bNew );
1571 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1572 if (pViewShell)
1573 pViewShell->SetTabNo(nTab,TRUE);
1575 pDocShell->SetDocumentModified();
1577 pDocShell->SetInUndo( FALSE );
1580 void ScUndoLayoutRTL::Undo()
1582 DoChange(!bRTL);
1585 void ScUndoLayoutRTL::Redo()
1587 DoChange(bRTL);
1590 void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
1592 if (rTarget.ISA(ScTabViewTarget))
1593 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1594 Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1597 BOOL ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
1599 return (rTarget.ISA(ScTabViewTarget));
1602 String ScUndoLayoutRTL::GetComment() const
1604 return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
1609 // -----------------------------------------------------------------------
1611 // Set the grammar used for the sheet
1614 //UNUSED2009-05 ScUndoSetGrammar::ScUndoSetGrammar( ScDocShell* pShell,
1615 //UNUSED2009-05 formula::FormulaGrammar::Grammar eGrammar ) :
1616 //UNUSED2009-05 ScSimpleUndo( pShell ),
1617 //UNUSED2009-05 meNewGrammar( eGrammar )
1618 //UNUSED2009-05 {
1619 //UNUSED2009-05 meOldGrammar = pDocShell->GetDocument()->GetGrammar();
1620 //UNUSED2009-05 }
1621 //UNUSED2009-05
1622 //UNUSED2009-05 __EXPORT ScUndoSetGrammar::~ScUndoSetGrammar()
1623 //UNUSED2009-05 {
1624 //UNUSED2009-05 }
1625 //UNUSED2009-05
1626 //UNUSED2009-05 void ScUndoSetGrammar::DoChange( formula::FormulaGrammar::Grammar eGrammar )
1627 //UNUSED2009-05 {
1628 //UNUSED2009-05 pDocShell->SetInUndo( TRUE );
1629 //UNUSED2009-05 ScDocument* pDoc = pDocShell->GetDocument();
1630 //UNUSED2009-05 pDoc->SetGrammar( eGrammar );
1631 //UNUSED2009-05 pDocShell->SetDocumentModified();
1632 //UNUSED2009-05 pDocShell->SetInUndo( FALSE );
1633 //UNUSED2009-05 }
1634 //UNUSED2009-05
1635 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Undo()
1636 //UNUSED2009-05 {
1637 //UNUSED2009-05 DoChange( meOldGrammar );
1638 //UNUSED2009-05 }
1639 //UNUSED2009-05
1640 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Redo()
1641 //UNUSED2009-05 {
1642 //UNUSED2009-05 DoChange( meNewGrammar );
1643 //UNUSED2009-05 }
1644 //UNUSED2009-05
1645 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
1646 //UNUSED2009-05 {
1647 //UNUSED2009-05 #if 0
1648 //UNUSED2009-05 // erAck: 2006-09-07T23:00+0200 commented out in CWS scr1c1
1649 //UNUSED2009-05 if (rTarget.ISA(ScTabViewTarget))
1650 //UNUSED2009-05 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1651 //UNUSED2009-05 Execute( FID_TAB_USE_R1C1, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1652 //UNUSED2009-05 #endif
1653 //UNUSED2009-05 }
1654 //UNUSED2009-05
1655 //UNUSED2009-05 BOOL __EXPORT ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
1656 //UNUSED2009-05 {
1657 //UNUSED2009-05 return (rTarget.ISA(ScTabViewTarget));
1658 //UNUSED2009-05 }
1659 //UNUSED2009-05
1660 //UNUSED2009-05 String __EXPORT ScUndoSetGrammar::GetComment() const
1661 //UNUSED2009-05 {
1662 //UNUSED2009-05 return ScGlobal::GetRscString( STR_UNDO_TAB_R1C1 );
1663 //UNUSED2009-05 }