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