xref: /trunk/main/sc/source/ui/undo/undotab.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <sfx2/app.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <svl/smplhint.hxx>
35 
36 #include "undotab.hxx"
37 #include "document.hxx"
38 #include "docsh.hxx"
39 #include "tabvwsh.hxx"
40 #include "globstr.hrc"
41 #include "global.hxx"
42 #include "sc.hrc"
43 #include "undoolk.hxx"
44 #include "target.hxx"
45 #include "uiitems.hxx"
46 #include "prnsave.hxx"
47 #include "printfun.hxx"
48 #include "chgtrack.hxx"
49 #include "tabprotection.hxx"
50 #include "viewdata.hxx"
51 
52 // for ScUndoRenameObject - might me moved to another file later
53 #include <svx/svditer.hxx>
54 #include <svx/svdoole2.hxx>
55 #include <svx/svdpage.hxx>
56 #include "drwlayer.hxx"
57 #include "scresid.hxx"
58 
59 extern sal_Bool bDrawIsInUndo;          //! irgendwo als Member !!!
60 
61 using namespace com::sun::star;
62 using ::com::sun::star::uno::Sequence;
63 using ::std::auto_ptr;
64 
65 // STATIC DATA -----------------------------------------------------------
66 
67 TYPEINIT1(ScUndoInsertTab,      SfxUndoAction);
68 TYPEINIT1(ScUndoInsertTables,   SfxUndoAction);
69 TYPEINIT1(ScUndoDeleteTab,      SfxUndoAction);
70 TYPEINIT1(ScUndoRenameTab,      SfxUndoAction);
71 TYPEINIT1(ScUndoMoveTab,        SfxUndoAction);
72 TYPEINIT1(ScUndoCopyTab,        SfxUndoAction);
73 TYPEINIT1(ScUndoMakeScenario,   SfxUndoAction);
74 TYPEINIT1(ScUndoImportTab,      SfxUndoAction);
75 TYPEINIT1(ScUndoRemoveLink,     SfxUndoAction);
76 TYPEINIT1(ScUndoShowHideTab,    SfxUndoAction);
77 TYPEINIT1(ScUndoPrintRange,     SfxUndoAction);
78 TYPEINIT1(ScUndoScenarioFlags,  SfxUndoAction);
79 TYPEINIT1(ScUndoRenameObject,   SfxUndoAction);
80 TYPEINIT1(ScUndoLayoutRTL,      SfxUndoAction);
81 //UNUSED2009-05 TYPEINIT1(ScUndoSetGrammar,     SfxUndoAction);
82 TYPEINIT1(ScUndoTabColor,  SfxUndoAction);
83 
84 
85 // -----------------------------------------------------------------------
86 //
87 //      Tabelle einfuegen
88 //
89 
90 ScUndoInsertTab::ScUndoInsertTab( ScDocShell* pNewDocShell,
91                                   SCTAB nTabNum,
92                                   sal_Bool bApp,
93                                   const String& rNewName) :
94     ScSimpleUndo( pNewDocShell ),
95     sNewName( rNewName ),
96     pDrawUndo( NULL ),
97     nTab( nTabNum ),
98     bAppend( bApp )
99 {
100     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
101     SetChangeTrack();
102 }
103 
104 ScUndoInsertTab::~ScUndoInsertTab()
105 {
106     DeleteSdrUndoAction( pDrawUndo );
107 }
108 
109 String ScUndoInsertTab::GetComment() const
110 {
111     if (bAppend)
112         return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
113     else
114         return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
115 }
116 
117 void ScUndoInsertTab::SetChangeTrack()
118 {
119     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
120     if ( pChangeTrack )
121     {
122         ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
123         pChangeTrack->AppendInsert( aRange );
124         nEndChangeAction = pChangeTrack->GetActionMax();
125     }
126     else
127         nEndChangeAction = 0;
128 }
129 
130 void ScUndoInsertTab::Undo()
131 {
132     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
133     pViewShell->SetTabNo(nTab);
134 
135     pDocShell->SetInUndo( sal_True );               //! BeginUndo
136     bDrawIsInUndo = sal_True;
137     pViewShell->DeleteTable( nTab, sal_False );
138     bDrawIsInUndo = sal_False;
139     pDocShell->SetInUndo( sal_False );              //! EndUndo
140 
141     DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
142 
143     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
144     if ( pChangeTrack )
145         pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
146 
147     //  SetTabNo(...,sal_True) for all views to sync with drawing layer pages
148     pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
149 }
150 
151 void ScUndoInsertTab::Redo()
152 {
153     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
154 
155     RedoSdrUndoAction( pDrawUndo );             // Draw Redo first
156 
157     pDocShell->SetInUndo( sal_True );               //! BeginRedo
158     bDrawIsInUndo = sal_True;
159     if (bAppend)
160         pViewShell->AppendTable( sNewName, sal_False );
161     else
162     {
163         pViewShell->SetTabNo(nTab);
164         pViewShell->InsertTable( sNewName, nTab, sal_False );
165     }
166     bDrawIsInUndo = sal_False;
167     pDocShell->SetInUndo( sal_False );              //! EndRedo
168 
169     SetChangeTrack();
170 }
171 
172 void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
173 {
174     if (rTarget.ISA(ScTabViewTarget))
175         ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
176             Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
177 }
178 
179 sal_Bool ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
180 {
181     return (rTarget.ISA(ScTabViewTarget));
182 }
183 
184 // -----------------------------------------------------------------------
185 //
186 //      Tabellen einfuegen
187 //
188 
189 ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
190                                         SCTAB nTabNum,
191                                         sal_Bool bApp,SvStrings *pNewNameList) :
192     ScSimpleUndo( pNewDocShell ),
193     pDrawUndo( NULL ),
194     nTab( nTabNum ),
195     bAppend( bApp )
196 {
197     pNameList = pNewNameList;
198     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
199 
200     SetChangeTrack();
201 }
202 
203 ScUndoInsertTables::~ScUndoInsertTables()
204 {
205     String *pStr=NULL;
206     if(pNameList!=NULL)
207     {
208         for(int i=0;i<pNameList->Count();i++)
209         {
210             pStr=pNameList->GetObject(sal::static_int_cast<sal_uInt16>(i));
211             delete pStr;
212         }
213         pNameList->Remove(0,pNameList->Count());
214         delete pNameList;
215     }
216     DeleteSdrUndoAction( pDrawUndo );
217 }
218 
219 String ScUndoInsertTables::GetComment() const
220 {
221     return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
222 }
223 
224 void ScUndoInsertTables::SetChangeTrack()
225 {
226     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
227     if ( pChangeTrack )
228     {
229         nStartChangeAction = pChangeTrack->GetActionMax() + 1;
230         nEndChangeAction = 0;
231         ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
232         for( int i = 0; i < pNameList->Count(); i++ )
233         {
234             aRange.aStart.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
235             aRange.aEnd.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
236             pChangeTrack->AppendInsert( aRange );
237             nEndChangeAction = pChangeTrack->GetActionMax();
238         }
239     }
240     else
241         nStartChangeAction = nEndChangeAction = 0;
242 }
243 
244 void ScUndoInsertTables::Undo()
245 {
246     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
247     pViewShell->SetTabNo(nTab);
248 
249     pDocShell->SetInUndo( sal_True );               //! BeginUndo
250     bDrawIsInUndo = sal_True;
251 
252     SvShorts TheTabs;
253     for(int i=0;i<pNameList->Count();i++)
254     {
255         TheTabs.push_back( sal::static_int_cast<short>(nTab+i) );
256     }
257 
258     pViewShell->DeleteTables( TheTabs, sal_False );
259     TheTabs.clear();
260 
261     bDrawIsInUndo = sal_False;
262     pDocShell->SetInUndo( sal_False );              //! EndUndo
263 
264     DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
265 
266     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
267     if ( pChangeTrack )
268         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
269 
270     //  SetTabNo(...,sal_True) for all views to sync with drawing layer pages
271     pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
272 }
273 
274 void ScUndoInsertTables::Redo()
275 {
276     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
277 
278     RedoSdrUndoAction( pDrawUndo );             // Draw Redo first
279 
280     pDocShell->SetInUndo( sal_True );               //! BeginRedo
281     bDrawIsInUndo = sal_True;
282     pViewShell->SetTabNo(nTab);
283     pViewShell->InsertTables( pNameList, nTab, static_cast<SCTAB>(pNameList->Count()),sal_False );
284 
285     bDrawIsInUndo = sal_False;
286     pDocShell->SetInUndo( sal_False );              //! EndRedo
287 
288     SetChangeTrack();
289 }
290 
291 void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
292 {
293     if (rTarget.ISA(ScTabViewTarget))
294         ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
295             Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
296 }
297 
298 sal_Bool ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
299 {
300     return (rTarget.ISA(ScTabViewTarget));
301 }
302 
303 
304 //----------------------------------------------------------------------------------
305 //
306 //      Tabelle loeschen
307 //
308 
309 ScUndoDeleteTab::ScUndoDeleteTab( ScDocShell* pNewDocShell,const SvShorts &aTab, //SCTAB nNewTab,
310                                     ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
311     ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST )
312 {
313         theTabs=aTab;
314 
315         SetChangeTrack();
316 }
317 
318 ScUndoDeleteTab::~ScUndoDeleteTab()
319 {
320     theTabs.clear();
321 }
322 
323 String ScUndoDeleteTab::GetComment() const
324 {
325     return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
326 }
327 
328 void ScUndoDeleteTab::SetChangeTrack()
329 {
330     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
331     if ( pChangeTrack )
332     {
333         sal_uLong nTmpChangeAction;
334         nStartChangeAction = pChangeTrack->GetActionMax() + 1;
335         nEndChangeAction = 0;
336         ScRange aRange( 0, 0, 0, MAXCOL, MAXROW, 0 );
337         for ( size_t i = 0; i < theTabs.size(); i++ )
338         {
339             aRange.aStart.SetTab( theTabs[sal::static_int_cast<sal_uInt16>(i)] );
340             aRange.aEnd.SetTab( theTabs[sal::static_int_cast<sal_uInt16>(i)] );
341             pChangeTrack->AppendDeleteRange( aRange, pRefUndoDoc,
342                 nTmpChangeAction, nEndChangeAction, (short) i );
343         }
344     }
345     else
346         nStartChangeAction = nEndChangeAction = 0;
347 }
348 
349 SCTAB lcl_GetVisibleTabBefore( ScDocument& rDoc, SCTAB nTab )
350 {
351     while ( nTab > 0 && !rDoc.IsVisible( nTab ) )
352         --nTab;
353 
354     return nTab;
355 }
356 
357 void ScUndoDeleteTab::Undo()
358 {
359     BeginUndo();
360     size_t i=0;
361     ScDocument* pDoc = pDocShell->GetDocument();
362 
363     sal_Bool bLink = sal_False;
364     String aName;
365 
366     for(i=0;i<theTabs.size();i++)
367     {
368         SCTAB nTab = theTabs[sal::static_int_cast<sal_uInt16>(i)];
369         pRefUndoDoc->GetName( nTab, aName );
370 
371         bDrawIsInUndo = sal_True;
372         sal_Bool bOk = pDoc->InsertTab( nTab, aName );
373         bDrawIsInUndo = sal_False;
374         if (bOk)
375         {
376             //  Ref-Undo passiert in EndUndo
377     //      pUndoDoc->UndoToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,sal_False, pDoc );
378             pRefUndoDoc->CopyToDocument(0,0,nTab, MAXCOL,MAXROW,nTab, IDF_ALL,sal_False, pDoc );
379 
380             String aOldName;
381             pRefUndoDoc->GetName( nTab, aOldName );
382             pDoc->RenameTab( nTab, aOldName, sal_False );
383             if (pRefUndoDoc->IsLinked(nTab))
384             {
385                 pDoc->SetLink( nTab, pRefUndoDoc->GetLinkMode(nTab), pRefUndoDoc->GetLinkDoc(nTab),
386                                      pRefUndoDoc->GetLinkFlt(nTab), pRefUndoDoc->GetLinkOpt(nTab),
387                                      pRefUndoDoc->GetLinkTab(nTab), pRefUndoDoc->GetLinkRefreshDelay(nTab) );
388                 bLink = sal_True;
389             }
390 
391             if ( pRefUndoDoc->IsScenario(nTab) )
392             {
393                 pDoc->SetScenario( nTab, sal_True );
394                 String aComment;
395                 Color  aColor;
396                 sal_uInt16 nScenFlags;
397                 pRefUndoDoc->GetScenarioData( nTab, aComment, aColor, nScenFlags );
398                 pDoc->SetScenarioData( nTab, aComment, aColor, nScenFlags );
399                 sal_Bool bActive = pRefUndoDoc->IsActiveScenario( nTab );
400                 pDoc->SetActiveScenario( nTab, bActive );
401             }
402             pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
403             pDoc->SetTabBgColor( nTab, pRefUndoDoc->GetTabBgColor(nTab) );
404             pDoc->SetSheetEvents( nTab, pRefUndoDoc->GetSheetEvents( nTab ) );
405 
406             if ( pRefUndoDoc->IsTabProtected( nTab ) )
407                 pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
408 
409             //  Drawing-Layer passiert beim MoveUndo::EndUndo
410     //      pDoc->TransferDrawPage(pRefUndoDoc, nTab,nTab);
411         }
412     }
413     if (bLink)
414     {
415         pDocShell->UpdateLinks();               // Link-Manager updaten
416     }
417 
418     EndUndo();      // Draw-Undo muss vor dem Broadcast kommen!
419 
420     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
421     if ( pChangeTrack )
422         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
423 
424     for(i=0;i<theTabs.size();i++)
425     {
426         pDocShell->Broadcast( ScTablesHint( SC_TAB_INSERTED, theTabs[sal::static_int_cast<sal_uInt16>(i)]) );
427     }
428     SfxApplication* pSfxApp = SFX_APP();                                // Navigator
429     pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
430     pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
431     pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
432 
433     pDocShell->PostPaint(0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_ALL );  // incl. Extras
434 
435     //  nicht ShowTable wegen SetTabNo(..., sal_True):
436     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
437     if (pViewShell)
438         pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDoc, theTabs.front() ), sal_True );
439 
440 //  EndUndo();
441 }
442 
443 void ScUndoDeleteTab::Redo()
444 {
445     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
446     pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs.front() ) );
447 
448     RedoSdrUndoAction( pDrawUndo );             // Draw Redo first
449 
450     pDocShell->SetInUndo( sal_True );               //! BeginRedo
451     bDrawIsInUndo = sal_True;
452     pViewShell->DeleteTables( theTabs, sal_False );
453     bDrawIsInUndo = sal_False;
454     pDocShell->SetInUndo( sal_True );               //! EndRedo
455 
456     SetChangeTrack();
457 
458     //  SetTabNo(...,sal_True) for all views to sync with drawing layer pages
459     pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
460 }
461 
462 void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
463 {
464     if (rTarget.ISA(ScTabViewTarget))
465     {
466         ScTabViewShell* pViewShell = ((ScTabViewTarget&)rTarget).GetViewShell();
467         pViewShell->DeleteTable( pViewShell->GetViewData()->GetTabNo(), sal_True );
468     }
469 }
470 
471 sal_Bool ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
472 {
473     return (rTarget.ISA(ScTabViewTarget));
474 }
475 
476 
477 //---------------------------------------------------------------------------------
478 //
479 //      Tabelle umbenennen
480 //
481 
482 ScUndoRenameTab::ScUndoRenameTab( ScDocShell* pNewDocShell,
483                                   SCTAB nT,
484                                   const String& rOldName,
485                                   const String& rNewName) :
486     ScSimpleUndo( pNewDocShell ),
487     nTab     ( nT )
488 {
489     sOldName = rOldName;
490     sNewName = rNewName;
491 }
492 
493 ScUndoRenameTab::~ScUndoRenameTab()
494 {
495 }
496 
497 String ScUndoRenameTab::GetComment() const
498 {
499     return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
500 }
501 
502 void ScUndoRenameTab::DoChange( SCTAB nTabP, const String& rName ) const
503 {
504     ScDocument* pDoc = pDocShell->GetDocument();
505     pDoc->RenameTab( nTabP, rName );
506 
507     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );    // Navigator
508 
509     pDocShell->PostPaintGridAll();
510     pDocShell->PostPaintExtras();
511     pDocShell->PostDataChanged();
512 
513     //  Der Tabellenname koennte in einer Formel vorkommen...
514     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
515     if (pViewShell)
516         pViewShell->UpdateInputHandler();
517 }
518 
519 void ScUndoRenameTab::Undo()
520 {
521     DoChange(nTab, sOldName);
522 }
523 
524 void ScUndoRenameTab::Redo()
525 {
526     DoChange(nTab, sNewName);
527 }
528 
529 void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
530 {
531     //  Repeat macht keinen Sinn
532 }
533 
534 sal_Bool ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
535 {
536     return sal_False;
537 }
538 
539 
540 //----------------------------------------------------------------------------------
541 //
542 //      Tabelle verschieben
543 //
544 
545 ScUndoMoveTab::ScUndoMoveTab( ScDocShell* pNewDocShell,
546                                   const SvShorts &aOldTab,
547                                   const SvShorts &aNewTab) :
548     ScSimpleUndo( pNewDocShell )
549 {
550     theOldTabs=aOldTab;
551     theNewTabs=aNewTab;
552 }
553 
554 ScUndoMoveTab::~ScUndoMoveTab()
555 {
556     theNewTabs.clear();
557     theOldTabs.clear();
558 }
559 
560 String ScUndoMoveTab::GetComment() const
561 {
562     return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
563 }
564 
565 void ScUndoMoveTab::DoChange( sal_Bool bUndo ) const
566 {
567     ScDocument* pDoc = pDocShell->GetDocument();
568     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
569 
570     if (bUndo)                                      // UnDo
571     {
572         for (size_t i = theNewTabs.size(); i > 0; i--)
573         {
574             SCTAB nDestTab = theNewTabs[i - 1];
575             SCTAB nOldTab = theOldTabs[i - 1];
576             if (nDestTab > MAXTAB)                          // append ?
577                 nDestTab = pDoc->GetTableCount() - 1;
578 
579             pDoc->MoveTab( nDestTab, nOldTab );
580             pViewShell->GetViewData()->MoveTab( nDestTab, nOldTab );
581             pViewShell->SetTabNo( nOldTab, sal_True );
582         }
583     }
584     else
585     {
586         for(size_t i=0;i<theNewTabs.size();i++)
587         {
588             SCTAB nDestTab = theNewTabs[i];
589             SCTAB nNewTab = theNewTabs[i];
590             SCTAB nOldTab = theOldTabs[i];
591             if (nDestTab > MAXTAB)                          // append ?
592                 nDestTab = pDoc->GetTableCount() - 1;
593 
594             pDoc->MoveTab( nOldTab, nNewTab );
595             pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
596             pViewShell->SetTabNo( nDestTab, sal_True );
597         }
598     }
599 
600     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );    // Navigator
601 
602     pDocShell->PostPaintGridAll();
603     pDocShell->PostPaintExtras();
604     pDocShell->PostDataChanged();
605 }
606 
607 void ScUndoMoveTab::Undo()
608 {
609     DoChange( sal_True );
610 }
611 
612 void ScUndoMoveTab::Redo()
613 {
614     DoChange( sal_False );
615 }
616 
617 void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
618 {
619         // No Repeat ! ? !
620 }
621 
622 sal_Bool ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
623 {
624     return sal_False;
625 }
626 
627 
628 //----------------------------------------------------------------------------------
629 //
630 //      Copy table
631 //
632 
633 ScUndoCopyTab::ScUndoCopyTab( ScDocShell* pNewDocShell,
634                                   const SvShorts &aOldTab,
635                                   const SvShorts &aNewTab) :
636     ScSimpleUndo( pNewDocShell ),
637     pDrawUndo( NULL )
638 {
639     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
640 
641     theOldTabs=aOldTab;
642     theNewTabs=aNewTab;
643 }
644 
645 ScUndoCopyTab::~ScUndoCopyTab()
646 {
647     DeleteSdrUndoAction( pDrawUndo );
648 }
649 
650 String ScUndoCopyTab::GetComment() const
651 {
652     return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
653 }
654 
655 void ScUndoCopyTab::DoChange() const
656 {
657     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
658 
659     if (pViewShell)
660         pViewShell->SetTabNo(theOldTabs.front(),sal_True);
661 
662     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );    // Navigator
663 
664     pDocShell->PostPaintGridAll();
665     pDocShell->PostPaintExtras();
666     pDocShell->PostDataChanged();
667 }
668 
669 void ScUndoCopyTab::Undo()
670 {
671     ScDocument* pDoc = pDocShell->GetDocument();
672 
673     DoSdrUndoAction( pDrawUndo, pDoc );                 // before the sheets are deleted
674 
675     for (size_t i = theNewTabs.size(); i > 0; i--)
676     {
677         SCTAB nDestTab = theNewTabs[i - 1];
678         if (nDestTab > MAXTAB)                          // append?
679             nDestTab = pDoc->GetTableCount() - 1;
680 
681         bDrawIsInUndo = sal_True;
682         pDoc->DeleteTab(nDestTab);
683         bDrawIsInUndo = sal_False;
684     }
685 
686     //  ScTablesHint broadcasts after all sheets have been deleted,
687     //  so sheets and draw pages are in sync!
688 
689     for (size_t i = theNewTabs.size(); i > 0; i--)
690     {
691         SCTAB nDestTab = theNewTabs[i - 1];
692         if (nDestTab > MAXTAB)                          // append?
693             nDestTab = pDoc->GetTableCount() - 1;
694 
695         pDocShell->Broadcast( ScTablesHint( SC_TAB_DELETED, nDestTab ) );
696     }
697 
698     DoChange();
699 }
700 
701 void ScUndoCopyTab::Redo()
702 {
703     ScDocument* pDoc = pDocShell->GetDocument();
704     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
705 
706     SCTAB nDestTab = 0;
707     for(size_t i=0;i<theNewTabs.size();i++)
708     {
709         nDestTab = theNewTabs[i];
710         SCTAB nNewTab = theNewTabs[i];
711         SCTAB nOldTab = theOldTabs[i];
712         if (nDestTab > MAXTAB)                          // append ?
713             nDestTab = pDoc->GetTableCount() - 1;
714 
715         bDrawIsInUndo = sal_True;
716         pDoc->CopyTab( nOldTab, nNewTab );
717         bDrawIsInUndo = sal_False;
718 
719         pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
720 
721         SCTAB nAdjSource = nOldTab;
722         if ( nNewTab <= nOldTab )
723             ++nAdjSource;               // new position of source table after CopyTab
724 
725         if ( pDoc->IsScenario(nAdjSource) )
726         {
727             pDoc->SetScenario(nNewTab, sal_True );
728             String aComment;
729             Color  aColor;
730             sal_uInt16 nScenFlags;
731             pDoc->GetScenarioData(nAdjSource, aComment, aColor, nScenFlags );
732             pDoc->SetScenarioData(nNewTab, aComment, aColor, nScenFlags );
733             sal_Bool bActive = pDoc->IsActiveScenario(nAdjSource);
734             pDoc->SetActiveScenario(nNewTab, bActive );
735             sal_Bool bVisible=pDoc->IsVisible(nAdjSource);
736             pDoc->SetVisible(nNewTab,bVisible );
737         }
738 
739         if ( pDoc->IsTabProtected( nAdjSource ) )
740             pDoc->CopyTabProtection(nAdjSource, nNewTab);
741     }
742 
743     RedoSdrUndoAction( pDrawUndo );             // after the sheets are inserted
744 
745     pViewShell->SetTabNo( nDestTab, sal_True );     // after draw-undo
746 
747     DoChange();
748 
749 }
750 
751 void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
752 {
753         // kein Repeat ! ? !
754 }
755 
756 sal_Bool ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
757 {
758     return sal_False;
759 }
760 
761 //---------------------------------------------------------------------------------
762 //
763 //      Tab Bg Color
764 //
765 
766 ScUndoTabColor::ScUndoTabColor(
767     ScDocShell* pNewDocShell, SCTAB nT, const Color& aOTabBgColor, const Color& aNTabBgColor) :
768     ScSimpleUndo( pNewDocShell )
769 {
770     ScUndoTabColorInfo aInfo(nT);
771     aInfo.maOldTabBgColor = aOTabBgColor;
772     aInfo.maNewTabBgColor = aNTabBgColor;
773     aTabColorList.push_back(aInfo);
774 }
775 
776 ScUndoTabColor::ScUndoTabColor(
777     ScDocShell* pNewDocShell,
778     const ScUndoTabColorInfo::List& rUndoTabColorList) :
779     ScSimpleUndo(pNewDocShell),
780     aTabColorList(rUndoTabColorList)
781 {
782 }
783 
784 ScUndoTabColor::~ScUndoTabColor()
785 {
786 }
787 
788 String ScUndoTabColor::GetComment() const
789 {
790     if (aTabColorList.size() > 1)
791         return ScGlobal::GetRscString(STR_UNDO_SET_MULTI_TAB_BG_COLOR);
792     return ScGlobal::GetRscString(STR_UNDO_SET_TAB_BG_COLOR);
793 }
794 
795 void ScUndoTabColor::DoChange(bool bUndoType) const
796 {
797     ScDocument* pDoc = pDocShell->GetDocument();
798     if (!pDoc)
799         return;
800 
801     size_t nTabColorCount = aTabColorList.size();
802     for (size_t i = 0; i < nTabColorCount; ++i)
803     {
804         const ScUndoTabColorInfo& rTabColor = aTabColorList[i];
805         pDoc->SetTabBgColor(rTabColor.mnTabId,
806             bUndoType ? rTabColor.maOldTabBgColor : rTabColor.maNewTabBgColor);
807     }
808 
809     pDocShell->PostPaintExtras();
810     ScDocShellModificator aModificator( *pDocShell );
811     aModificator.SetDocumentModified();
812 }
813 
814 void ScUndoTabColor::Undo()
815 {
816     DoChange(true);
817 }
818 
819 void ScUndoTabColor::Redo()
820 {
821     DoChange(false);
822 }
823 
824 void ScUndoTabColor::Repeat(SfxRepeatTarget& /* rTarget */)
825 {
826     //  No Repeat
827 }
828 
829 sal_Bool ScUndoTabColor::CanRepeat(SfxRepeatTarget& /* rTarget */) const
830 {
831     return sal_False;
832 }
833 
834 // -----------------------------------------------------------------------
835 //
836 //      Szenario anlegen
837 //
838 
839 ScUndoMakeScenario::ScUndoMakeScenario( ScDocShell* pNewDocShell,
840                         SCTAB nSrc, SCTAB nDest,
841                         const String& rN, const String& rC,
842                         const Color& rCol, sal_uInt16 nF,
843                         const ScMarkData& rMark ) :
844     ScSimpleUndo( pNewDocShell ),
845     nSrcTab( nSrc ),
846     nDestTab( nDest ),
847     aName( rN ),
848     aComment( rC ),
849     aColor( rCol ),
850     nFlags( nF ),
851     aMarkData( rMark ),
852     pDrawUndo( NULL )
853 {
854     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
855 }
856 
857 ScUndoMakeScenario::~ScUndoMakeScenario()
858 {
859     DeleteSdrUndoAction( pDrawUndo );
860 }
861 
862 String ScUndoMakeScenario::GetComment() const
863 {
864     return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
865 }
866 
867 void ScUndoMakeScenario::Undo()
868 {
869     ScDocument* pDoc = pDocShell->GetDocument();
870 
871     pDocShell->SetInUndo( sal_True );
872     bDrawIsInUndo = sal_True;
873     pDoc->DeleteTab( nDestTab );
874     bDrawIsInUndo = sal_False;
875     pDocShell->SetInUndo( sal_False );
876 
877     DoSdrUndoAction( pDrawUndo, pDoc );
878 
879     pDocShell->PostPaint(0,0,nDestTab,MAXCOL,MAXROW,MAXTAB, PAINT_ALL);
880     pDocShell->PostDataChanged();
881 
882     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
883     if (pViewShell)
884         pViewShell->SetTabNo( nSrcTab, sal_True );
885 
886     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
887 
888     //  SetTabNo(...,sal_True) for all views to sync with drawing layer pages
889     pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
890 }
891 
892 void ScUndoMakeScenario::Redo()
893 {
894     SetViewMarkData( aMarkData );
895 
896     RedoSdrUndoAction( pDrawUndo );             // Draw Redo first
897 
898     pDocShell->SetInUndo( sal_True );
899     bDrawIsInUndo = sal_True;
900 
901     pDocShell->MakeScenario( nSrcTab, aName, aComment, aColor, nFlags, aMarkData, sal_False );
902 
903     bDrawIsInUndo = sal_False;
904     pDocShell->SetInUndo( sal_False );
905 
906     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
907     if (pViewShell)
908         pViewShell->SetTabNo( nDestTab, sal_True );
909 
910     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
911 }
912 
913 void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
914 {
915     if (rTarget.ISA(ScTabViewTarget))
916     {
917         ((ScTabViewTarget&)rTarget).GetViewShell()->MakeScenario( aName, aComment, aColor, nFlags );
918     }
919 }
920 
921 sal_Bool ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
922 {
923     return (rTarget.ISA(ScTabViewTarget));
924 }
925 
926 
927 // -----------------------------------------------------------------------
928 //
929 //      Tabelle einfuegen
930 //
931 
932 ScUndoImportTab::ScUndoImportTab( ScDocShell* pShell,
933                         SCTAB nNewTab, SCTAB nNewCount, sal_Bool bNewLink ) :
934     ScSimpleUndo( pShell ),
935     nTab( nNewTab ),
936     nCount( nNewCount ),
937     bLink( bNewLink ),
938     pRedoDoc( NULL ),
939     pDrawUndo( NULL )
940 {
941     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
942 }
943 
944 ScUndoImportTab::~ScUndoImportTab()
945 {
946     delete pRedoDoc;
947     DeleteSdrUndoAction( pDrawUndo );
948 }
949 
950 String ScUndoImportTab::GetComment() const
951 {
952     return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
953 }
954 
955 void ScUndoImportTab::DoChange() const
956 {
957     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
958     ScDocument* pDoc = pDocShell->GetDocument();
959     SCTAB nTabCount = pDoc->GetTableCount();
960     if (pViewShell)
961     {
962         if(nTab<nTabCount)
963         {
964             pViewShell->SetTabNo(nTab,sal_True);
965         }
966         else
967         {
968             pViewShell->SetTabNo(nTab-1,sal_True);
969         }
970     }
971 
972     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );    // Navigator
973     pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB,
974                                 PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
975 }
976 
977 void ScUndoImportTab::Undo()
978 {
979     //! eingefuegte Bereichsnamen etc.
980 
981     SCTAB i;
982     ScDocument* pDoc = pDocShell->GetDocument();
983     sal_Bool bMakeRedo = !pRedoDoc;
984     if (bMakeRedo)
985     {
986         pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
987         pRedoDoc->InitUndo( pDoc, nTab,nTab+nCount-1, sal_True,sal_True );
988 
989         String aOldName;
990         for (i=0; i<nCount; i++)
991         {
992             SCTAB nTabPos=nTab+i;
993 
994             pDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,sal_False, pRedoDoc );
995             pDoc->GetName( nTabPos, aOldName );
996             pRedoDoc->RenameTab( nTabPos, aOldName, sal_False );
997 
998             if ( pDoc->IsScenario(nTabPos) )
999             {
1000                 pRedoDoc->SetScenario(nTabPos, sal_True );
1001                 String aComment;
1002                 Color  aColor;
1003                 sal_uInt16 nScenFlags;
1004                 pDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1005                 pRedoDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1006                 sal_Bool bActive = pDoc->IsActiveScenario(nTabPos);
1007                 pRedoDoc->SetActiveScenario(nTabPos, bActive );
1008                 sal_Bool bVisible=pDoc->IsVisible(nTabPos);
1009                 pRedoDoc->SetVisible(nTabPos,bVisible );
1010             }
1011 
1012             if ( pDoc->IsTabProtected( nTabPos ) )
1013                 pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
1014         }
1015 
1016     }
1017 
1018     DoSdrUndoAction( pDrawUndo, pDoc );             // before the sheets are deleted
1019 
1020     bDrawIsInUndo = sal_True;
1021     for (i=0; i<nCount; i++)
1022         pDoc->DeleteTab( nTab );
1023     bDrawIsInUndo = sal_False;
1024 
1025     DoChange();
1026 }
1027 
1028 void ScUndoImportTab::Redo()
1029 {
1030     if (!pRedoDoc)
1031     {
1032         DBG_ERROR("wo ist mein Redo-Document?");
1033         return;
1034     }
1035 
1036     ScDocument* pDoc = pDocShell->GetDocument();
1037     String aName;
1038     SCTAB i;
1039     for (i=0; i<nCount; i++)                // first insert all sheets (#63304#)
1040     {
1041         SCTAB nTabPos=nTab+i;
1042         pRedoDoc->GetName(nTabPos,aName);
1043         bDrawIsInUndo = sal_True;
1044         pDoc->InsertTab(nTabPos,aName);
1045         bDrawIsInUndo = sal_False;
1046     }
1047     for (i=0; i<nCount; i++)                // then copy into inserted sheets
1048     {
1049         SCTAB nTabPos=nTab+i;
1050         pRedoDoc->CopyToDocument(0,0,nTabPos, MAXCOL,MAXROW,nTabPos, IDF_ALL,sal_False, pDoc );
1051 
1052         if ( pRedoDoc->IsScenario(nTabPos) )
1053         {
1054             pDoc->SetScenario(nTabPos, sal_True );
1055             String aComment;
1056             Color  aColor;
1057             sal_uInt16 nScenFlags;
1058             pRedoDoc->GetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1059             pDoc->SetScenarioData(nTabPos, aComment, aColor, nScenFlags );
1060             sal_Bool bActive = pRedoDoc->IsActiveScenario(nTabPos);
1061             pDoc->SetActiveScenario(nTabPos, bActive );
1062             sal_Bool bVisible=pRedoDoc->IsVisible(nTabPos);
1063             pDoc->SetVisible(nTabPos,bVisible );
1064         }
1065 
1066         if ( pRedoDoc->IsTabProtected( nTabPos ) )
1067             pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
1068     }
1069 
1070     RedoSdrUndoAction( pDrawUndo );     // after the sheets are inserted
1071 
1072     DoChange();
1073 }
1074 
1075 void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
1076 {
1077     if (rTarget.ISA(ScTabViewTarget))
1078         ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1079             Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1080 }
1081 
1082 sal_Bool ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
1083 {
1084     return (rTarget.ISA(ScTabViewTarget));
1085 }
1086 
1087 
1088 // -----------------------------------------------------------------------
1089 //
1090 //      Tabellen-Verknuepfung aufheben
1091 //
1092 
1093 ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const String& rDoc ) :
1094     ScSimpleUndo( pShell ),
1095     aDocName( rDoc ),
1096     nCount( 0 )
1097 {
1098     ScDocument* pDoc = pDocShell->GetDocument();
1099     SCTAB nTabCount = pDoc->GetTableCount();
1100     pTabs     = new SCTAB[nTabCount];
1101     pModes    = new sal_uInt8[nTabCount];
1102     pTabNames = new String[nTabCount];
1103 
1104     for (SCTAB i=0; i<nTabCount; i++)
1105     {
1106         sal_uInt8 nMode = pDoc->GetLinkMode(i);
1107         if (nMode)
1108             if (pDoc->GetLinkDoc(i) == aDocName)
1109             {
1110                 if (!nCount)
1111                 {
1112                     aFltName = pDoc->GetLinkFlt(i);
1113                     aOptions = pDoc->GetLinkOpt(i);
1114                     nRefreshDelay = pDoc->GetLinkRefreshDelay(i);
1115                 }
1116                 else
1117                 {
1118                     DBG_ASSERT(aFltName == pDoc->GetLinkFlt(i) &&
1119                                aOptions == pDoc->GetLinkOpt(i),
1120                                     "verschiedene Filter fuer ein Dokument?");
1121                 }
1122                 pTabs[nCount] = i;
1123                 pModes[nCount] = nMode;
1124                 pTabNames[nCount] = pDoc->GetLinkTab(i);
1125                 ++nCount;
1126             }
1127     }
1128 }
1129 
1130 ScUndoRemoveLink::~ScUndoRemoveLink()
1131 {
1132     delete pTabs;
1133     delete pModes;
1134     delete[] pTabNames;
1135 }
1136 
1137 String ScUndoRemoveLink::GetComment() const
1138 {
1139     return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
1140 }
1141 
1142 void ScUndoRemoveLink::DoChange( sal_Bool bLink ) const
1143 {
1144     ScDocument* pDoc = pDocShell->GetDocument();
1145     String aEmpty;
1146     for (sal_uInt16 i=0; i<nCount; i++)
1147         if (bLink)      // establish link
1148             pDoc->SetLink( pTabs[i], pModes[i], aDocName, aFltName, aOptions, pTabNames[i], nRefreshDelay );
1149         else            // remove link
1150             pDoc->SetLink( pTabs[i], SC_LINK_NONE, aEmpty, aEmpty, aEmpty, aEmpty, 0 );
1151     pDocShell->UpdateLinks();
1152 }
1153 
1154 void ScUndoRemoveLink::Undo()
1155 {
1156     DoChange( sal_True );
1157 }
1158 
1159 void ScUndoRemoveLink::Redo()
1160 {
1161     DoChange( sal_False );
1162 }
1163 
1164 void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
1165 {
1166     //  gippsnich
1167 }
1168 
1169 sal_Bool ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1170 {
1171     return sal_False;
1172 }
1173 
1174 
1175 // -----------------------------------------------------------------------
1176 //
1177 //      Tabellen ein-/ausblenden
1178 //
1179 
1180 ScUndoShowHideTab::ScUndoShowHideTab( ScDocShell* pShell, SCTAB nNewTab, sal_Bool bNewShow ) :
1181     ScSimpleUndo( pShell ),
1182     nTab( nNewTab ),
1183     bShow( bNewShow )
1184 {
1185 }
1186 
1187 ScUndoShowHideTab::~ScUndoShowHideTab()
1188 {
1189 }
1190 
1191 void ScUndoShowHideTab::DoChange( sal_Bool bShowP ) const
1192 {
1193     ScDocument* pDoc = pDocShell->GetDocument();
1194     pDoc->SetVisible( nTab, bShowP );
1195 
1196     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1197     if (pViewShell)
1198         pViewShell->SetTabNo(nTab,sal_True);
1199 
1200     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1201     pDocShell->SetDocumentModified();
1202 }
1203 
1204 void ScUndoShowHideTab::Undo()
1205 {
1206     DoChange(!bShow);
1207 }
1208 
1209 void ScUndoShowHideTab::Redo()
1210 {
1211     DoChange(bShow);
1212 }
1213 
1214 void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
1215 {
1216     if (rTarget.ISA(ScTabViewTarget))
1217         ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1218             Execute( bShow ? FID_TABLE_SHOW : FID_TABLE_HIDE,
1219                                 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1220 }
1221 
1222 sal_Bool ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
1223 {
1224     return (rTarget.ISA(ScTabViewTarget));
1225 }
1226 
1227 String ScUndoShowHideTab::GetComment() const
1228 {
1229     sal_uInt16 nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
1230     return ScGlobal::GetRscString( nId );
1231 }
1232 
1233 // ============================================================================
1234 
1235 ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
1236     ScSimpleUndo(pShell),
1237     mpProtectSettings(pProtectSettings)
1238 {
1239 }
1240 
1241 ScUndoDocProtect::~ScUndoDocProtect()
1242 {
1243 }
1244 
1245 void ScUndoDocProtect::DoProtect(bool bProtect)
1246 {
1247     ScDocument* pDoc = pDocShell->GetDocument();
1248 
1249     if (bProtect)
1250     {
1251         // set protection.
1252         auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
1253         pCopy->setProtected(true);
1254         pDoc->SetDocProtection(pCopy.get());
1255     }
1256     else
1257     {
1258         // remove protection.
1259         pDoc->SetDocProtection(NULL);
1260     }
1261 
1262     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1263     if (pViewShell)
1264     {
1265         pViewShell->UpdateLayerLocks();
1266         pViewShell->UpdateInputHandler(sal_True);   // damit sofort wieder eingegeben werden kann
1267     }
1268 
1269     pDocShell->PostPaintGridAll();
1270 }
1271 
1272 void ScUndoDocProtect::Undo()
1273 {
1274     BeginUndo();
1275     DoProtect(!mpProtectSettings->isProtected());
1276     EndUndo();
1277 }
1278 
1279 void ScUndoDocProtect::Redo()
1280 {
1281     BeginRedo();
1282     DoProtect(mpProtectSettings->isProtected());
1283     EndRedo();
1284 }
1285 
1286 void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1287 {
1288     //  gippsnich
1289 }
1290 
1291 sal_Bool ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1292 {
1293     return sal_False;       // gippsnich
1294 }
1295 
1296 String ScUndoDocProtect::GetComment() const
1297 {
1298     sal_uInt16 nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
1299     return ScGlobal::GetRscString( nId );
1300 }
1301 
1302 // ============================================================================
1303 
1304 ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
1305     ScSimpleUndo(pShell),
1306     mnTab(nTab),
1307     mpProtectSettings(pProtectSettings)
1308 {
1309 }
1310 
1311 ScUndoTabProtect::~ScUndoTabProtect()
1312 {
1313 }
1314 
1315 void ScUndoTabProtect::DoProtect(bool bProtect)
1316 {
1317     ScDocument* pDoc = pDocShell->GetDocument();
1318 
1319     if (bProtect)
1320     {
1321         // set protection.
1322         auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
1323         pCopy->setProtected(true);
1324         pDoc->SetTabProtection(mnTab, pCopy.get());
1325     }
1326     else
1327     {
1328         // remove protection.
1329         pDoc->SetTabProtection(mnTab, NULL);
1330     }
1331 
1332     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1333     if (pViewShell)
1334     {
1335         pViewShell->UpdateLayerLocks();
1336         pViewShell->UpdateInputHandler(sal_True);   // damit sofort wieder eingegeben werden kann
1337     }
1338 
1339     pDocShell->PostPaintGridAll();
1340 }
1341 
1342 void ScUndoTabProtect::Undo()
1343 {
1344     BeginUndo();
1345     DoProtect(!mpProtectSettings->isProtected());
1346     EndUndo();
1347 }
1348 
1349 void ScUndoTabProtect::Redo()
1350 {
1351     BeginRedo();
1352     DoProtect(mpProtectSettings->isProtected());
1353     EndRedo();
1354 }
1355 
1356 void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
1357 {
1358     //  gippsnich
1359 }
1360 
1361 sal_Bool ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1362 {
1363     return sal_False;       // gippsnich
1364 }
1365 
1366 String ScUndoTabProtect::GetComment() const
1367 {
1368     sal_uInt16 nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
1369     return ScGlobal::GetRscString( nId );
1370 }
1371 
1372 // -----------------------------------------------------------------------
1373 //
1374 //      Druck-/Wiederholungsbereiche aendern
1375 //
1376 
1377 ScUndoPrintRange::ScUndoPrintRange( ScDocShell* pShell, SCTAB nNewTab,
1378                                     ScPrintRangeSaver* pOld, ScPrintRangeSaver* pNew ) :
1379     ScSimpleUndo( pShell ),
1380     nTab( nNewTab ),
1381     pOldRanges( pOld ),
1382     pNewRanges( pNew )
1383 {
1384 }
1385 
1386 ScUndoPrintRange::~ScUndoPrintRange()
1387 {
1388     delete pOldRanges;
1389     delete pNewRanges;
1390 }
1391 
1392 void ScUndoPrintRange::DoChange(sal_Bool bUndo)
1393 {
1394     ScDocument* pDoc = pDocShell->GetDocument();
1395     if (bUndo)
1396         pDoc->RestorePrintRanges( *pOldRanges );
1397     else
1398         pDoc->RestorePrintRanges( *pNewRanges );
1399 
1400     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1401     if (pViewShell)
1402         pViewShell->SetTabNo( nTab );
1403 
1404     ScPrintFunc( pDocShell, pDocShell->GetPrinter(), nTab ).UpdatePages();
1405 
1406     pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
1407 }
1408 
1409 void ScUndoPrintRange::Undo()
1410 {
1411     BeginUndo();
1412     DoChange( sal_True );
1413     EndUndo();
1414 }
1415 
1416 void ScUndoPrintRange::Redo()
1417 {
1418     BeginRedo();
1419     DoChange( sal_False );
1420     EndRedo();
1421 }
1422 
1423 void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
1424 {
1425     //  gippsnich
1426 }
1427 
1428 sal_Bool ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1429 {
1430     return sal_False;       // gippsnich
1431 }
1432 
1433 String ScUndoPrintRange::GetComment() const
1434 {
1435     return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
1436 }
1437 
1438 
1439 //------------------------------------------------------------------------
1440 
1441 //---------------------------------------------------------------------------------
1442 //
1443 //      Szenario-Flags
1444 //
1445 
1446 ScUndoScenarioFlags::ScUndoScenarioFlags( ScDocShell* pNewDocShell, SCTAB nT,
1447                     const String& rON, const String& rNN, const String& rOC, const String& rNC,
1448                     const Color& rOCol, const Color& rNCol, sal_uInt16 nOF, sal_uInt16 nNF ) :
1449     ScSimpleUndo( pNewDocShell ),
1450     nTab        ( nT ),
1451     aOldName    ( rON ),
1452     aNewName    ( rNN ),
1453     aOldComment ( rOC ),
1454     aNewComment ( rNC ),
1455     aOldColor   ( rOCol ),
1456     aNewColor   ( rNCol ),
1457     nOldFlags   ( nOF ),
1458     nNewFlags   ( nNF )
1459 {
1460 }
1461 
1462 ScUndoScenarioFlags::~ScUndoScenarioFlags()
1463 {
1464 }
1465 
1466 String ScUndoScenarioFlags::GetComment() const
1467 {
1468     return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
1469 }
1470 
1471 void ScUndoScenarioFlags::Undo()
1472 {
1473     ScDocument* pDoc = pDocShell->GetDocument();
1474 
1475     pDoc->RenameTab( nTab, aOldName );
1476     pDoc->SetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
1477 
1478     pDocShell->PostPaintGridAll();
1479     //  Der Tabellenname koennte in einer Formel vorkommen...
1480     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1481     if (pViewShell)
1482         pViewShell->UpdateInputHandler();
1483 
1484     if ( aOldName != aNewName )
1485         SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1486 }
1487 
1488 void ScUndoScenarioFlags::Redo()
1489 {
1490     ScDocument* pDoc = pDocShell->GetDocument();
1491 
1492     pDoc->RenameTab( nTab, aNewName );
1493     pDoc->SetScenarioData( nTab, aNewComment, aNewColor, nNewFlags );
1494 
1495     pDocShell->PostPaintGridAll();
1496     //  Der Tabellenname koennte in einer Formel vorkommen...
1497     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1498     if (pViewShell)
1499         pViewShell->UpdateInputHandler();
1500 
1501     if ( aOldName != aNewName )
1502         SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
1503 }
1504 
1505 void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
1506 {
1507     //  Repeat macht keinen Sinn
1508 }
1509 
1510 sal_Bool ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1511 {
1512     return sal_False;
1513 }
1514 
1515 
1516 //---------------------------------------------------------------------------------
1517 //
1518 //      rename object
1519 //      (move to different file?)
1520 //
1521 
1522 ScUndoRenameObject::ScUndoRenameObject( ScDocShell* pNewDocShell, const String& rPN,
1523                                         const String& rON, const String& rNN ) :
1524     ScSimpleUndo( pNewDocShell ),
1525     aPersistName( rPN ),
1526     aOldName    ( rON ),
1527     aNewName    ( rNN )
1528 {
1529 }
1530 
1531 ScUndoRenameObject::~ScUndoRenameObject()
1532 {
1533 }
1534 
1535 String ScUndoRenameObject::GetComment() const
1536 {
1537     //  string resource shared with title for dialog
1538     return String( ScResId(SCSTR_RENAMEOBJECT) );
1539 }
1540 
1541 SdrObject* ScUndoRenameObject::GetObject()
1542 {
1543     ScDocument* pDoc = pDocShell->GetDocument();
1544     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1545     if ( pDrawLayer )
1546     {
1547         sal_uInt16 nCount = pDrawLayer->GetPageCount();
1548         for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
1549         {
1550             SdrPage* pPage = pDrawLayer->GetPage(nTab);
1551             DBG_ASSERT(pPage,"Page ?");
1552 
1553             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
1554             SdrObject* pObject = aIter.Next();
1555             while (pObject)
1556             {
1557                 if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
1558                         ((SdrOle2Obj*)pObject)->GetPersistName() == aPersistName )
1559                 {
1560                     return pObject;
1561                 }
1562 
1563                 pObject = aIter.Next();
1564             }
1565         }
1566     }
1567     DBG_ERROR("Object not found");
1568     return NULL;
1569 }
1570 
1571 void ScUndoRenameObject::Undo()
1572 {
1573     BeginUndo();
1574     SdrObject* pObj = GetObject();
1575     if ( pObj )
1576         pObj->SetName( aOldName );
1577     EndUndo();
1578 }
1579 
1580 void ScUndoRenameObject::Redo()
1581 {
1582     BeginRedo();
1583     SdrObject* pObj = GetObject();
1584     if ( pObj )
1585         pObj->SetName( aNewName );
1586     EndRedo();
1587 }
1588 
1589 void ScUndoRenameObject::Repeat(SfxRepeatTarget& /* rTarget */)
1590 {
1591 }
1592 
1593 sal_Bool ScUndoRenameObject::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1594 {
1595     return sal_False;
1596 }
1597 
1598 // -----------------------------------------------------------------------
1599 //
1600 //      Switch sheet between left-to-right and right-to-left
1601 //
1602 
1603 ScUndoLayoutRTL::ScUndoLayoutRTL( ScDocShell* pShell, SCTAB nNewTab, sal_Bool bNewRTL ) :
1604     ScSimpleUndo( pShell ),
1605     nTab( nNewTab ),
1606     bRTL( bNewRTL )
1607 {
1608 }
1609 
1610 ScUndoLayoutRTL::~ScUndoLayoutRTL()
1611 {
1612 }
1613 
1614 void ScUndoLayoutRTL::DoChange( sal_Bool bNew )
1615 {
1616     pDocShell->SetInUndo( sal_True );
1617 
1618     ScDocument* pDoc = pDocShell->GetDocument();
1619     pDoc->SetLayoutRTL( nTab, bNew );
1620 
1621     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1622     if (pViewShell)
1623         pViewShell->SetTabNo(nTab,sal_True);
1624 
1625     pDocShell->SetDocumentModified();
1626 
1627     pDocShell->SetInUndo( sal_False );
1628 }
1629 
1630 void ScUndoLayoutRTL::Undo()
1631 {
1632     DoChange(!bRTL);
1633 }
1634 
1635 void ScUndoLayoutRTL::Redo()
1636 {
1637     DoChange(bRTL);
1638 }
1639 
1640 void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
1641 {
1642     if (rTarget.ISA(ScTabViewTarget))
1643         ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1644             Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1645 }
1646 
1647 sal_Bool ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
1648 {
1649     return (rTarget.ISA(ScTabViewTarget));
1650 }
1651 
1652 String ScUndoLayoutRTL::GetComment() const
1653 {
1654     return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
1655 }
1656 
1657 
1658 
1659 // -----------------------------------------------------------------------
1660 //
1661 //      Set the grammar used for the sheet
1662 //
1663 
1664 //UNUSED2009-05 ScUndoSetGrammar::ScUndoSetGrammar( ScDocShell* pShell,
1665 //UNUSED2009-05                                     formula::FormulaGrammar::Grammar eGrammar ) :
1666 //UNUSED2009-05     ScSimpleUndo( pShell ),
1667 //UNUSED2009-05     meNewGrammar( eGrammar )
1668 //UNUSED2009-05 {
1669 //UNUSED2009-05     meOldGrammar = pDocShell->GetDocument()->GetGrammar();
1670 //UNUSED2009-05 }
1671 //UNUSED2009-05
1672 //UNUSED2009-05 __EXPORT ScUndoSetGrammar::~ScUndoSetGrammar()
1673 //UNUSED2009-05 {
1674 //UNUSED2009-05 }
1675 //UNUSED2009-05
1676 //UNUSED2009-05 void ScUndoSetGrammar::DoChange( formula::FormulaGrammar::Grammar eGrammar )
1677 //UNUSED2009-05 {
1678 //UNUSED2009-05     pDocShell->SetInUndo( sal_True );
1679 //UNUSED2009-05     ScDocument* pDoc = pDocShell->GetDocument();
1680 //UNUSED2009-05     pDoc->SetGrammar( eGrammar );
1681 //UNUSED2009-05     pDocShell->SetDocumentModified();
1682 //UNUSED2009-05     pDocShell->SetInUndo( sal_False );
1683 //UNUSED2009-05 }
1684 //UNUSED2009-05
1685 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Undo()
1686 //UNUSED2009-05 {
1687 //UNUSED2009-05     DoChange( meOldGrammar );
1688 //UNUSED2009-05 }
1689 //UNUSED2009-05
1690 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Redo()
1691 //UNUSED2009-05 {
1692 //UNUSED2009-05     DoChange( meNewGrammar );
1693 //UNUSED2009-05 }
1694 //UNUSED2009-05
1695 //UNUSED2009-05 void __EXPORT ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
1696 //UNUSED2009-05 {
1697 //UNUSED2009-05 #if 0
1698 //UNUSED2009-05 // erAck: 2006-09-07T23:00+0200  commented out in CWS scr1c1
1699 //UNUSED2009-05     if (rTarget.ISA(ScTabViewTarget))
1700 //UNUSED2009-05         ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
1701 //UNUSED2009-05             Execute( FID_TAB_USE_R1C1, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
1702 //UNUSED2009-05 #endif
1703 //UNUSED2009-05 }
1704 //UNUSED2009-05
1705 //UNUSED2009-05 sal_Bool __EXPORT ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
1706 //UNUSED2009-05 {
1707 //UNUSED2009-05     return (rTarget.ISA(ScTabViewTarget));
1708 //UNUSED2009-05 }
1709 //UNUSED2009-05
1710 //UNUSED2009-05 String __EXPORT ScUndoSetGrammar::GetComment() const
1711 //UNUSED2009-05 {
1712 //UNUSED2009-05     return ScGlobal::GetRscString( STR_UNDO_TAB_R1C1 );
1713 //UNUSED2009-05 }
1714 
1715