xref: /trunk/main/sc/source/ui/undo/undodat.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 ---------------------------------------------------------------
28 
29 #include <sfx2/app.hxx>
30 
31 #include "undodat.hxx"
32 #include "undoutil.hxx"
33 #include "undoolk.hxx"
34 #include "document.hxx"
35 #include "docsh.hxx"
36 #include "tabvwsh.hxx"
37 #include "olinetab.hxx"
38 #include "dbcolect.hxx"
39 #include "rangenam.hxx"
40 #include "pivot.hxx"
41 #include "globstr.hrc"
42 #include "global.hxx"
43 #include "target.hxx"
44 #include "chartarr.hxx"
45 #include "dbdocfun.hxx"
46 #include "olinefun.hxx"
47 #include "dpobject.hxx"
48 #include "attrib.hxx"
49 #include "hints.hxx"
50 #include "sc.hrc"
51 
52 // -----------------------------------------------------------------------
53 
54 TYPEINIT1(ScUndoDoOutline,          ScSimpleUndo);
55 TYPEINIT1(ScUndoMakeOutline,        ScSimpleUndo);
56 TYPEINIT1(ScUndoOutlineLevel,       ScSimpleUndo);
57 TYPEINIT1(ScUndoOutlineBlock,       ScSimpleUndo);
58 TYPEINIT1(ScUndoRemoveAllOutlines,  ScSimpleUndo);
59 TYPEINIT1(ScUndoAutoOutline,        ScSimpleUndo);
60 TYPEINIT1(ScUndoSubTotals,          ScDBFuncUndo);
61 TYPEINIT1(ScUndoSort,               ScDBFuncUndo);
62 TYPEINIT1(ScUndoQuery,              ScDBFuncUndo);
63 TYPEINIT1(ScUndoAutoFilter,         ScDBFuncUndo);
64 TYPEINIT1(ScUndoDBData,             ScSimpleUndo);
65 TYPEINIT1(ScUndoImportData,         ScSimpleUndo);
66 TYPEINIT1(ScUndoRepeatDB,           ScSimpleUndo);
67 //UNUSED2008-05  TYPEINIT1(ScUndoPivot,              ScSimpleUndo);
68 TYPEINIT1(ScUndoDataPilot,          ScSimpleUndo);
69 TYPEINIT1(ScUndoConsolidate,        ScSimpleUndo);
70 TYPEINIT1(ScUndoChartData,          ScSimpleUndo);
71 
72 // -----------------------------------------------------------------------
73 
74 
75 //
76 //		Outline-Gruppen ein- oder ausblenden
77 //
78 
ScUndoDoOutline(ScDocShell * pNewDocShell,SCCOLROW nNewStart,SCCOLROW nNewEnd,SCTAB nNewTab,ScDocument * pNewUndoDoc,sal_Bool bNewColumns,sal_uInt16 nNewLevel,sal_uInt16 nNewEntry,sal_Bool bNewShow)79 ScUndoDoOutline::ScUndoDoOutline( ScDocShell* pNewDocShell,
80 							SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
81 							ScDocument* pNewUndoDoc, sal_Bool bNewColumns,
82 							sal_uInt16 nNewLevel, sal_uInt16 nNewEntry, sal_Bool bNewShow ) :
83 	ScSimpleUndo( pNewDocShell ),
84 	nStart( nNewStart ),
85 	nEnd( nNewEnd ),
86 	nTab( nNewTab ),
87 	pUndoDoc( pNewUndoDoc ),
88 	bColumns( bNewColumns ),
89 	nLevel( nNewLevel ),
90 	nEntry( nNewEntry ),
91 	bShow( bNewShow )
92 {
93 }
94 
~ScUndoDoOutline()95 __EXPORT ScUndoDoOutline::~ScUndoDoOutline()
96 {
97 	delete pUndoDoc;
98 }
99 
GetComment() const100 String __EXPORT ScUndoDoOutline::GetComment() const
101 {	// Detail einblenden" "Detail ausblenden"
102 	return bShow ?
103 		ScGlobal::GetRscString( STR_UNDO_DOOUTLINE ) :
104 		ScGlobal::GetRscString( STR_UNDO_REDOOUTLINE );
105 }
106 
Undo()107 void __EXPORT ScUndoDoOutline::Undo()
108 {
109 	BeginUndo();
110 
111 	ScDocument* pDoc = pDocShell->GetDocument();
112 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
113 
114 	//	Tabelle muss vorher umgeschaltet sein (#46952#) !!!
115 
116 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
117 	if ( nVisTab != nTab )
118 		pViewShell->SetTabNo( nTab );
119 
120 	//	inverse Funktion ausfuehren
121 
122 	if (bShow)
123 		pViewShell->HideOutline( bColumns, nLevel, nEntry, sal_False, sal_False );
124 	else
125 		pViewShell->ShowOutline( bColumns, nLevel, nEntry, sal_False, sal_False );
126 
127 	//	Original Spalten-/Zeilenstatus
128 
129 	if (bColumns)
130         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
131                 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, sal_False, pDoc);
132 	else
133 		pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, sal_False, pDoc );
134 
135 	pViewShell->UpdateScrollBars();
136 
137 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
138 
139 	EndUndo();
140 }
141 
Redo()142 void __EXPORT ScUndoDoOutline::Redo()
143 {
144 	BeginRedo();
145 
146 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
147 
148 	//	Tabelle muss vorher umgeschaltet sein (#46952#) !!!
149 
150 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
151 	if ( nVisTab != nTab )
152 		pViewShell->SetTabNo( nTab );
153 
154 	if (bShow)
155 		pViewShell->ShowOutline( bColumns, nLevel, nEntry, sal_False );
156 	else
157 		pViewShell->HideOutline( bColumns, nLevel, nEntry, sal_False );
158 
159 	EndRedo();
160 }
161 
Repeat(SfxRepeatTarget &)162 void __EXPORT ScUndoDoOutline::Repeat(SfxRepeatTarget& /* rTarget */)
163 {
164 }
165 
CanRepeat(SfxRepeatTarget &) const166 sal_Bool __EXPORT ScUndoDoOutline::CanRepeat(SfxRepeatTarget& /* rTarget */) const
167 {
168 	return sal_False;						// geht nicht
169 }
170 
171 //
172 //		Outline-Gruppen erzeugen oder loeschen
173 //
174 
ScUndoMakeOutline(ScDocShell * pNewDocShell,SCCOL nStartX,SCROW nStartY,SCTAB nStartZ,SCCOL nEndX,SCROW nEndY,SCTAB nEndZ,ScOutlineTable * pNewUndoTab,sal_Bool bNewColumns,sal_Bool bNewMake)175 ScUndoMakeOutline::ScUndoMakeOutline( ScDocShell* pNewDocShell,
176 							SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
177 							SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
178 							ScOutlineTable* pNewUndoTab, sal_Bool bNewColumns, sal_Bool bNewMake ) :
179 	ScSimpleUndo( pNewDocShell ),
180 	aBlockStart( nStartX, nStartY, nStartZ ),
181 	aBlockEnd( nEndX, nEndY, nEndZ ),
182 	pUndoTable( pNewUndoTab ),
183 	bColumns( bNewColumns ),
184 	bMake( bNewMake )
185 {
186 }
187 
~ScUndoMakeOutline()188 __EXPORT ScUndoMakeOutline::~ScUndoMakeOutline()
189 {
190 	delete pUndoTable;
191 }
192 
GetComment() const193 String __EXPORT ScUndoMakeOutline::GetComment() const
194 {	// "Gruppierung" "Gruppierung aufheben"
195 	return bMake ?
196 		ScGlobal::GetRscString( STR_UNDO_MAKEOUTLINE ) :
197 		ScGlobal::GetRscString( STR_UNDO_REMAKEOUTLINE );
198 }
199 
Undo()200 void __EXPORT ScUndoMakeOutline::Undo()
201 {
202 	BeginUndo();
203 
204 	ScDocument* pDoc = pDocShell->GetDocument();
205 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
206 	SCTAB nTab = aBlockStart.Tab();
207 
208 	ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
209 
210 	pDoc->SetOutlineTable( nTab, pUndoTable );
211 
212 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
213 	if ( nVisTab != nTab )
214 		pViewShell->SetTabNo( nTab );
215 
216 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
217 
218 	EndUndo();
219 }
220 
Redo()221 void __EXPORT ScUndoMakeOutline::Redo()
222 {
223 	BeginRedo();
224 
225 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
226 
227 	ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
228 
229 	if (bMake)
230 		pViewShell->MakeOutline( bColumns, sal_False );
231 	else
232 		pViewShell->RemoveOutline( bColumns, sal_False );
233 
234 	pDocShell->PostPaint(0,0,aBlockStart.Tab(),MAXCOL,MAXROW,aBlockEnd.Tab(),PAINT_GRID);
235 
236 	EndRedo();
237 }
238 
Repeat(SfxRepeatTarget & rTarget)239 void __EXPORT ScUndoMakeOutline::Repeat(SfxRepeatTarget& rTarget)
240 {
241 	if (rTarget.ISA(ScTabViewTarget))
242 	{
243 		ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
244 
245 		if (bMake)
246 			rViewShell.MakeOutline( bColumns, sal_True );
247 		else
248 			rViewShell.RemoveOutline( bColumns, sal_True );
249 	}
250 }
251 
CanRepeat(SfxRepeatTarget & rTarget) const252 sal_Bool __EXPORT ScUndoMakeOutline::CanRepeat(SfxRepeatTarget& rTarget) const
253 {
254 	return (rTarget.ISA(ScTabViewTarget));
255 }
256 
257 //
258 //		Outline-Ebene auswaehlen
259 //
260 
ScUndoOutlineLevel(ScDocShell * pNewDocShell,SCCOLROW nNewStart,SCCOLROW nNewEnd,SCTAB nNewTab,ScDocument * pNewUndoDoc,ScOutlineTable * pNewUndoTab,sal_Bool bNewColumns,sal_uInt16 nNewLevel)261 ScUndoOutlineLevel::ScUndoOutlineLevel( ScDocShell* pNewDocShell,
262 						SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
263 						ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
264 						sal_Bool bNewColumns, sal_uInt16 nNewLevel ) :
265 	ScSimpleUndo( pNewDocShell ),
266 	nStart( nNewStart ),
267 	nEnd( nNewEnd ),
268 	nTab( nNewTab ),
269 	pUndoDoc( pNewUndoDoc ),
270 	pUndoTable( pNewUndoTab ),
271 	bColumns( bNewColumns ),
272 	nLevel( nNewLevel )
273 {
274 }
275 
~ScUndoOutlineLevel()276 __EXPORT ScUndoOutlineLevel::~ScUndoOutlineLevel()
277 {
278 	delete pUndoDoc;
279 	delete pUndoTable;
280 }
281 
GetComment() const282 String __EXPORT ScUndoOutlineLevel::GetComment() const
283 {	// "Gliederungsebene auswaehlen";
284 	return ScGlobal::GetRscString( STR_UNDO_OUTLINELEVEL );
285 }
286 
Undo()287 void __EXPORT ScUndoOutlineLevel::Undo()
288 {
289 	BeginUndo();
290 
291 	ScDocument* pDoc = pDocShell->GetDocument();
292 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
293 
294 	//	Original Outline-Table
295 
296 	pDoc->SetOutlineTable( nTab, pUndoTable );
297 
298 	//	Original Spalten-/Zeilenstatus
299 
300 	if (bColumns)
301         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart), 0, nTab,
302                 static_cast<SCCOL>(nEnd), MAXROW, nTab, IDF_NONE, sal_False, pDoc);
303 	else
304 		pUndoDoc->CopyToDocument( 0, nStart, nTab, MAXCOL, nEnd, nTab, IDF_NONE, sal_False, pDoc );
305 
306 	pDoc->UpdatePageBreaks( nTab );
307 
308 	pViewShell->UpdateScrollBars();
309 
310 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
311 	if ( nVisTab != nTab )
312 		pViewShell->SetTabNo( nTab );
313 
314 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
315 
316 	EndUndo();
317 }
318 
Redo()319 void __EXPORT ScUndoOutlineLevel::Redo()
320 {
321 	BeginRedo();
322 
323 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
324 
325 	//	Tabelle muss vorher umgeschaltet sein (#46952#) !!!
326 
327 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
328 	if ( nVisTab != nTab )
329 		pViewShell->SetTabNo( nTab );
330 
331 	pViewShell->SelectLevel( bColumns, nLevel, sal_False );
332 
333 	EndRedo();
334 }
335 
Repeat(SfxRepeatTarget & rTarget)336 void __EXPORT ScUndoOutlineLevel::Repeat(SfxRepeatTarget& rTarget)
337 {
338 	if (rTarget.ISA(ScTabViewTarget))
339 		((ScTabViewTarget&)rTarget).GetViewShell()->SelectLevel( bColumns, nLevel, sal_True );
340 }
341 
CanRepeat(SfxRepeatTarget & rTarget) const342 sal_Bool __EXPORT ScUndoOutlineLevel::CanRepeat(SfxRepeatTarget& rTarget) const
343 {
344 	return (rTarget.ISA(ScTabViewTarget));
345 }
346 
347 //
348 //		Outline ueber Blockmarken ein- oder ausblenden
349 //
350 
ScUndoOutlineBlock(ScDocShell * pNewDocShell,SCCOL nStartX,SCROW nStartY,SCTAB nStartZ,SCCOL nEndX,SCROW nEndY,SCTAB nEndZ,ScDocument * pNewUndoDoc,ScOutlineTable * pNewUndoTab,sal_Bool bNewShow)351 ScUndoOutlineBlock::ScUndoOutlineBlock( ScDocShell* pNewDocShell,
352 						SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
353 						SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
354 						ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab, sal_Bool bNewShow ) :
355 	ScSimpleUndo( pNewDocShell ),
356 	aBlockStart( nStartX, nStartY, nStartZ ),
357 	aBlockEnd( nEndX, nEndY, nEndZ ),
358 	pUndoDoc( pNewUndoDoc ),
359 	pUndoTable( pNewUndoTab ),
360 	bShow( bNewShow )
361 {
362 }
363 
~ScUndoOutlineBlock()364 __EXPORT ScUndoOutlineBlock::~ScUndoOutlineBlock()
365 {
366 	delete pUndoDoc;
367 	delete pUndoTable;
368 }
369 
GetComment() const370 String __EXPORT ScUndoOutlineBlock::GetComment() const
371 {	// "Detail einblenden" "Detail ausblenden"
372 	return bShow ?
373 		ScGlobal::GetRscString( STR_UNDO_DOOUTLINEBLK ) :
374 		ScGlobal::GetRscString( STR_UNDO_REDOOUTLINEBLK );
375 }
376 
Undo()377 void __EXPORT ScUndoOutlineBlock::Undo()
378 {
379 	BeginUndo();
380 
381 	ScDocument* pDoc = pDocShell->GetDocument();
382 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
383 	SCTAB nTab = aBlockStart.Tab();
384 
385 	//	Original Outline-Table
386 
387 	pDoc->SetOutlineTable( nTab, pUndoTable );
388 
389 	//	Original Spalten-/Zeilenstatus
390 
391 	SCCOLROW	nStartCol = aBlockStart.Col();
392 	SCCOLROW	nEndCol = aBlockEnd.Col();
393 	SCCOLROW	nStartRow = aBlockStart.Row();
394 	SCCOLROW	nEndRow = aBlockEnd.Row();
395 
396 	if (!bShow)
397 	{								//	Groesse des ausgeblendeten Blocks
398 		sal_uInt16 nLevel;
399 		pUndoTable->GetColArray()->FindTouchedLevel( nStartCol, nEndCol, nLevel );
400 		pUndoTable->GetColArray()->ExtendBlock( nLevel, nStartCol, nEndCol );
401 		pUndoTable->GetRowArray()->FindTouchedLevel( nStartRow, nEndRow, nLevel );
402 		pUndoTable->GetRowArray()->ExtendBlock( nLevel, nStartRow, nEndRow );
403 	}
404 
405     pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
406             static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, sal_False, pDoc );
407 	pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, sal_False, pDoc );
408 
409 	pDoc->UpdatePageBreaks( nTab );
410 
411 	pViewShell->UpdateScrollBars();
412 
413 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
414 	if ( nVisTab != nTab )
415 		pViewShell->SetTabNo( nTab );
416 
417 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP);
418 
419 	EndUndo();
420 }
421 
Redo()422 void __EXPORT ScUndoOutlineBlock::Redo()
423 {
424 	BeginRedo();
425 
426 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
427 
428 	ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart, aBlockEnd );
429 	if (bShow)
430 		pViewShell->ShowMarkedOutlines( sal_False );
431 	else
432 		pViewShell->HideMarkedOutlines( sal_False );
433 
434 	EndRedo();
435 }
436 
Repeat(SfxRepeatTarget & rTarget)437 void __EXPORT ScUndoOutlineBlock::Repeat(SfxRepeatTarget& rTarget)
438 {
439 	if (rTarget.ISA(ScTabViewTarget))
440 	{
441 		ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
442 
443 		if (bShow)
444 			rViewShell.ShowMarkedOutlines( sal_True );
445 		else
446 			rViewShell.HideMarkedOutlines( sal_True );
447 	}
448 }
449 
CanRepeat(SfxRepeatTarget & rTarget) const450 sal_Bool __EXPORT ScUndoOutlineBlock::CanRepeat(SfxRepeatTarget& rTarget) const
451 {
452 	return (rTarget.ISA(ScTabViewTarget));
453 }
454 
455 //
456 //		alle Outlines loeschen
457 //
458 
ScUndoRemoveAllOutlines(ScDocShell * pNewDocShell,SCCOL nStartX,SCROW nStartY,SCTAB nStartZ,SCCOL nEndX,SCROW nEndY,SCTAB nEndZ,ScDocument * pNewUndoDoc,ScOutlineTable * pNewUndoTab)459 ScUndoRemoveAllOutlines::ScUndoRemoveAllOutlines( ScDocShell* pNewDocShell,
460 									SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
461 									SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
462 									ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
463 	ScSimpleUndo( pNewDocShell ),
464 	aBlockStart( nStartX, nStartY, nStartZ ),
465 	aBlockEnd( nEndX, nEndY, nEndZ ),
466 	pUndoDoc( pNewUndoDoc ),
467 	pUndoTable( pNewUndoTab )
468 {
469 }
470 
~ScUndoRemoveAllOutlines()471 __EXPORT ScUndoRemoveAllOutlines::~ScUndoRemoveAllOutlines()
472 {
473 	delete pUndoDoc;
474 	delete pUndoTable;
475 }
476 
GetComment() const477 String __EXPORT ScUndoRemoveAllOutlines::GetComment() const
478 {	// "Gliederung entfernen"
479 	return ScGlobal::GetRscString( STR_UNDO_REMOVEALLOTLNS );
480 }
481 
Undo()482 void __EXPORT ScUndoRemoveAllOutlines::Undo()
483 {
484 	BeginUndo();
485 
486 	ScDocument* pDoc = pDocShell->GetDocument();
487 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
488 	SCTAB nTab = aBlockStart.Tab();
489 
490 	//	Original Outline-Table
491 
492 	pDoc->SetOutlineTable( nTab, pUndoTable );
493 
494 	//	Original Spalten-/Zeilenstatus
495 
496 	SCCOL	nStartCol = aBlockStart.Col();
497 	SCCOL	nEndCol = aBlockEnd.Col();
498 	SCROW	nStartRow = aBlockStart.Row();
499 	SCROW	nEndRow = aBlockEnd.Row();
500 
501 	pUndoDoc->CopyToDocument( nStartCol, 0, nTab, nEndCol, MAXROW, nTab, IDF_NONE, sal_False, pDoc );
502 	pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, sal_False, pDoc );
503 
504 	pDoc->UpdatePageBreaks( nTab );
505 
506 	pViewShell->UpdateScrollBars();
507 
508 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
509 	if ( nVisTab != nTab )
510 		pViewShell->SetTabNo( nTab );
511 
512 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
513 
514 	EndUndo();
515 }
516 
Redo()517 void __EXPORT ScUndoRemoveAllOutlines::Redo()
518 {
519 	BeginRedo();
520 
521 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
522 
523 	//	Tabelle muss vorher umgeschaltet sein (#46952#) !!!
524 
525 	SCTAB nTab = aBlockStart.Tab();
526 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
527 	if ( nVisTab != nTab )
528 		pViewShell->SetTabNo( nTab );
529 
530 	pViewShell->RemoveAllOutlines( sal_False );
531 
532 	EndRedo();
533 }
534 
Repeat(SfxRepeatTarget & rTarget)535 void __EXPORT ScUndoRemoveAllOutlines::Repeat(SfxRepeatTarget& rTarget)
536 {
537 	if (rTarget.ISA(ScTabViewTarget))
538 		((ScTabViewTarget&)rTarget).GetViewShell()->RemoveAllOutlines( sal_True );
539 }
540 
CanRepeat(SfxRepeatTarget & rTarget) const541 sal_Bool __EXPORT ScUndoRemoveAllOutlines::CanRepeat(SfxRepeatTarget& rTarget) const
542 {
543 	return (rTarget.ISA(ScTabViewTarget));
544 }
545 
546 //
547 //		Auto-Outline
548 //
549 
ScUndoAutoOutline(ScDocShell * pNewDocShell,SCCOL nStartX,SCROW nStartY,SCTAB nStartZ,SCCOL nEndX,SCROW nEndY,SCTAB nEndZ,ScDocument * pNewUndoDoc,ScOutlineTable * pNewUndoTab)550 ScUndoAutoOutline::ScUndoAutoOutline( ScDocShell* pNewDocShell,
551 									SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
552 									SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
553 									ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
554 	ScSimpleUndo( pNewDocShell ),
555 	aBlockStart( nStartX, nStartY, nStartZ ),
556 	aBlockEnd( nEndX, nEndY, nEndZ ),
557 	pUndoDoc( pNewUndoDoc ),
558 	pUndoTable( pNewUndoTab )
559 {
560 }
561 
~ScUndoAutoOutline()562 __EXPORT ScUndoAutoOutline::~ScUndoAutoOutline()
563 {
564 	delete pUndoDoc;
565 	delete pUndoTable;
566 }
567 
GetComment() const568 String __EXPORT ScUndoAutoOutline::GetComment() const
569 {	// "Auto-Gliederung"
570 	return ScGlobal::GetRscString( STR_UNDO_AUTOOUTLINE );
571 }
572 
Undo()573 void __EXPORT ScUndoAutoOutline::Undo()
574 {
575 	BeginUndo();
576 
577 	ScDocument* pDoc = pDocShell->GetDocument();
578 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
579 	SCTAB nTab = aBlockStart.Tab();
580 
581 	//	Original Outline-Table
582 
583 	pDoc->SetOutlineTable( nTab, pUndoTable );
584 
585 	//	Original Spalten-/Zeilenstatus
586 
587 	if (pUndoDoc && pUndoTable)
588 	{
589 		SCCOLROW nStartCol;
590 		SCCOLROW nStartRow;
591 		SCCOLROW nEndCol;
592 		SCCOLROW nEndRow;
593 		pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
594 		pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
595 
596         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
597                 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, sal_False,
598                 pDoc);
599 		pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, sal_False, pDoc );
600 
601 		pViewShell->UpdateScrollBars();
602 	}
603 
604 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
605 	if ( nVisTab != nTab )
606 		pViewShell->SetTabNo( nTab );
607 
608 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
609 
610 	EndUndo();
611 }
612 
Redo()613 void __EXPORT ScUndoAutoOutline::Redo()
614 {
615 	BeginRedo();
616 
617 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
618 
619 	SCTAB nTab = aBlockStart.Tab();
620 	if (pViewShell)
621 	{
622 		//	Tabelle muss vorher umgeschaltet sein (#46952#) !!!
623 
624 		SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
625 		if ( nVisTab != nTab )
626 			pViewShell->SetTabNo( nTab );
627 	}
628 
629 	ScRange aRange( aBlockStart.Col(), aBlockStart.Row(), nTab,
630 					aBlockEnd.Col(),   aBlockEnd.Row(),   nTab );
631 	ScOutlineDocFunc aFunc( *pDocShell );
632 	aFunc.AutoOutline( aRange, sal_False, sal_False );
633 
634 	//	auf der View markieren
635 	//	Wenn's beim Aufruf eine Mehrfachselektion war, ist es jetzt der
636 	//	umschliessende Bereich...
637 
638 	if (pViewShell)
639 		pViewShell->MarkRange( aRange );
640 
641 	EndRedo();
642 }
643 
Repeat(SfxRepeatTarget & rTarget)644 void __EXPORT ScUndoAutoOutline::Repeat(SfxRepeatTarget& rTarget)
645 {
646 	if (rTarget.ISA(ScTabViewTarget))
647 		((ScTabViewTarget&)rTarget).GetViewShell()->AutoOutline( sal_True );
648 }
649 
CanRepeat(SfxRepeatTarget & rTarget) const650 sal_Bool __EXPORT ScUndoAutoOutline::CanRepeat(SfxRepeatTarget& rTarget) const
651 {
652 	return (rTarget.ISA(ScTabViewTarget));
653 }
654 
655 //
656 //		Zwischenergebnisse
657 //
658 
ScUndoSubTotals(ScDocShell * pNewDocShell,SCTAB nNewTab,const ScSubTotalParam & rNewParam,SCROW nNewEndY,ScDocument * pNewUndoDoc,ScOutlineTable * pNewUndoTab,ScRangeName * pNewUndoRange,ScDBCollection * pNewUndoDB)659 ScUndoSubTotals::ScUndoSubTotals( ScDocShell* pNewDocShell, SCTAB nNewTab,
660 								const ScSubTotalParam& rNewParam, SCROW nNewEndY,
661 								ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
662 								ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB ) :
663 	ScDBFuncUndo( pNewDocShell, ScRange( rNewParam.nCol1, rNewParam.nRow1, nNewTab,
664 	                                     rNewParam.nCol2, rNewParam.nRow2, nNewTab ) ),
665 	nTab( nNewTab ),
666 	aParam( rNewParam ),
667 	nNewEndRow( nNewEndY ),
668 	pUndoDoc( pNewUndoDoc ),
669 	pUndoTable( pNewUndoTab ),
670 	pUndoRange( pNewUndoRange ),
671 	pUndoDB( pNewUndoDB )
672 {
673 }
674 
~ScUndoSubTotals()675 __EXPORT ScUndoSubTotals::~ScUndoSubTotals()
676 {
677 	delete pUndoDoc;
678 	delete pUndoTable;
679 	delete pUndoRange;
680 	delete pUndoDB;
681 }
682 
GetComment() const683 String __EXPORT ScUndoSubTotals::GetComment() const
684 {	// "Teilergebnisse"
685 	return ScGlobal::GetRscString( STR_UNDO_SUBTOTALS );
686 }
687 
Undo()688 void __EXPORT ScUndoSubTotals::Undo()
689 {
690 	BeginUndo();
691 
692 	ScDocument* pDoc = pDocShell->GetDocument();
693 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
694 
695 	//	um einzelnen DB-Bereich anzupassen
696 /*	ScDBData* pOldDBData = ScUndoUtil::GetOldDBData( pUndoDBData, pDoc, nTab,
697 										aParam.nCol1, aParam.nRow1, aParam.nCol2, nNewEndRow );
698 */
699 
700 	if (nNewEndRow > aParam.nRow2)
701 	{
702 		pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aParam.nRow2+1, static_cast<SCSIZE>(nNewEndRow-aParam.nRow2) );
703 	}
704 	else if (nNewEndRow < aParam.nRow2)
705 	{
706 		pDoc->InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(aParam.nRow2-nNewEndRow) );
707 	}
708 
709 
710 	//	Original Outline-Table
711 
712 	pDoc->SetOutlineTable( nTab, pUndoTable );
713 
714 	//	Original Spalten-/Zeilenstatus
715 
716 	if (pUndoDoc && pUndoTable)
717 	{
718 		SCCOLROW nStartCol;
719 		SCCOLROW nStartRow;
720 		SCCOLROW nEndCol;
721 		SCCOLROW nEndRow;
722 		pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
723 		pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
724 
725         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
726                 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, sal_False,
727                 pDoc);
728 		pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, sal_False, pDoc );
729 
730 		pViewShell->UpdateScrollBars();
731 	}
732 
733 	//	Original-Daten & Referenzen
734 
735 	ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aParam.nRow1+1, nTab,
736 											MAXCOL, aParam.nRow2, nTab );
737 
738 	pDoc->DeleteAreaTab( 0,aParam.nRow1+1, MAXCOL,aParam.nRow2, nTab, IDF_ALL );
739 
740 	pUndoDoc->CopyToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
741 															IDF_NONE, sal_False, pDoc );	// Flags
742 	pUndoDoc->UndoToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
743 															IDF_ALL, sal_False, pDoc );
744 
745 	ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
746 											aParam.nCol2,aParam.nRow2,nTab );
747 
748 /*	if (pUndoDBData)
749 		*pOldDBData = *pUndoDBData;
750 */
751 	if (pUndoRange)
752 		pDoc->SetRangeName( new ScRangeName( *pUndoRange ) );
753 	if (pUndoDB)
754 		pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
755 
756 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
757 	if ( nVisTab != nTab )
758 		pViewShell->SetTabNo( nTab );
759 
760 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
761 	pDocShell->PostDataChanged();
762 
763 	EndUndo();
764 }
765 
Redo()766 void __EXPORT ScUndoSubTotals::Redo()
767 {
768 	BeginRedo();
769 
770 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
771 
772 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
773 	if ( nVisTab != nTab )
774 		pViewShell->SetTabNo( nTab );
775 
776 	ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
777 											aParam.nCol2,aParam.nRow2,nTab );
778 	pViewShell->DoSubTotals( aParam, sal_False );
779 
780 	EndRedo();
781 }
782 
Repeat(SfxRepeatTarget &)783 void __EXPORT ScUndoSubTotals::Repeat(SfxRepeatTarget& /* rTarget */)
784 {
785 }
786 
CanRepeat(SfxRepeatTarget &) const787 sal_Bool __EXPORT ScUndoSubTotals::CanRepeat(SfxRepeatTarget& /* rTarget */) const
788 {
789 	return sal_False;						// geht nicht wegen Spaltennummern
790 }
791 
792 //
793 //		Sortieren
794 //
795 
ScUndoSort(ScDocShell * pNewDocShell,SCTAB nNewTab,const ScSortParam & rParam,sal_Bool bQuery,ScDocument * pNewUndoDoc,ScDBCollection * pNewUndoDB,const ScRange * pDest)796 ScUndoSort::ScUndoSort( ScDocShell* pNewDocShell,
797 						SCTAB nNewTab, const ScSortParam& rParam,
798 						sal_Bool bQuery, ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
799 						const ScRange* pDest ) :
800 	ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
801 	                                     rParam.nCol2, rParam.nRow2, nNewTab ) ),
802 	nTab( nNewTab ),
803 	aSortParam( rParam ),
804 	bRepeatQuery( bQuery ),
805 	pUndoDoc( pNewUndoDoc ),
806 	pUndoDB( pNewUndoDB ),
807 	bDestArea( sal_False )
808 {
809 	if ( pDest )
810 	{
811 		bDestArea = sal_True;
812 		aDestRange = *pDest;
813 	}
814 }
815 
~ScUndoSort()816 __EXPORT ScUndoSort::~ScUndoSort()
817 {
818 	delete pUndoDoc;
819 	delete pUndoDB;
820 }
821 
GetComment() const822 String __EXPORT ScUndoSort::GetComment() const
823 {
824 	return ScGlobal::GetRscString( STR_UNDO_SORT );
825 }
826 
Undo()827 void __EXPORT ScUndoSort::Undo()
828 {
829 	BeginUndo();
830 
831 	ScDocument* pDoc = pDocShell->GetDocument();
832 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
833 
834 	SCCOL nStartCol = aSortParam.nCol1;
835 	SCROW nStartRow = aSortParam.nRow1;
836 	SCCOL nEndCol	 = aSortParam.nCol2;
837 	SCROW nEndRow	 = aSortParam.nRow2;
838 	SCTAB nSortTab  = nTab;
839 	if ( !aSortParam.bInplace )
840 	{
841 		nStartCol = aSortParam.nDestCol;
842 		nStartRow = aSortParam.nDestRow;
843 		nEndCol   = nStartCol + ( aSortParam.nCol2 - aSortParam.nCol1 );
844 		nEndRow   = nStartRow + ( aSortParam.nRow2 - aSortParam.nRow1 );
845 		nSortTab  = aSortParam.nDestTab;
846 	}
847 
848 	ScUndoUtil::MarkSimpleBlock( pDocShell, nStartCol, nStartRow, nSortTab,
849 								 nEndCol, nEndRow, nSortTab );
850 
851     // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
852     pDoc->DeleteAreaTab( nStartCol,nStartRow, nEndCol,nEndRow, nSortTab, IDF_ALL|IDF_NOCAPTIONS );
853 	pUndoDoc->CopyToDocument( nStartCol, nStartRow, nSortTab, nEndCol, nEndRow, nSortTab,
854                                 IDF_ALL|IDF_NOCAPTIONS, sal_False, pDoc );
855 
856 	if (bDestArea)
857 	{
858         // do not delete/copy note captions, they are handled in drawing undo (ScDBFuncUndo::mpDrawUndo)
859         pDoc->DeleteAreaTab( aDestRange, IDF_ALL|IDF_NOCAPTIONS );
860         pUndoDoc->CopyToDocument( aDestRange, IDF_ALL|IDF_NOCAPTIONS, sal_False, pDoc );
861 	}
862 
863 	//	Zeilenhoehen immer (wegen automatischer Anpassung)
864 	//!	auf ScBlockUndo umstellen
865 //	if (bRepeatQuery)
866 		pUndoDoc->CopyToDocument( 0, nStartRow, nSortTab, MAXCOL, nEndRow, nSortTab,
867 								IDF_NONE, sal_False, pDoc );
868 
869 	if (pUndoDB)
870 		pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
871 
872 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
873 	if ( nVisTab != nSortTab )
874 		pViewShell->SetTabNo( nSortTab );
875 
876 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
877 	pDocShell->PostDataChanged();
878 
879 	EndUndo();
880 }
881 
Redo()882 void __EXPORT ScUndoSort::Redo()
883 {
884 	BeginRedo();
885 
886 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
887 
888 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
889 	if ( nVisTab != nTab )
890 		pViewShell->SetTabNo( nTab );
891 
892 //	pViewShell->DoneBlockMode();
893 //	pViewShell->InitOwnBlockMode();
894 //	pViewShell->GetViewData()->GetMarkData() = aMarkData;	// CopyMarksTo
895 
896 	pViewShell->MarkRange( ScRange( aSortParam.nCol1, aSortParam.nRow1, nTab,
897 									  aSortParam.nCol2, aSortParam.nRow2, nTab ) );
898 
899 	pViewShell->Sort( aSortParam, sal_False );
900 
901 	//	Quellbereich painten wegen Markierung
902 	if ( !aSortParam.bInplace )
903 		pDocShell->PostPaint( aSortParam.nCol1, aSortParam.nRow1, nTab,
904 							  aSortParam.nCol2, aSortParam.nRow2, nTab, PAINT_GRID );
905 
906 	EndRedo();
907 }
908 
Repeat(SfxRepeatTarget &)909 void __EXPORT ScUndoSort::Repeat(SfxRepeatTarget& /* rTarget */)
910 {
911 }
912 
CanRepeat(SfxRepeatTarget &) const913 sal_Bool __EXPORT ScUndoSort::CanRepeat(SfxRepeatTarget& /* rTarget */) const
914 {
915 	return sal_False;						// geht nicht wegen Spaltennummern
916 }
917 
918 //
919 //		Filtern
920 //
921 
ScUndoQuery(ScDocShell * pNewDocShell,SCTAB nNewTab,const ScQueryParam & rParam,ScDocument * pNewUndoDoc,ScDBCollection * pNewUndoDB,const ScRange * pOld,sal_Bool bSize,const ScRange * pAdvSrc)922 ScUndoQuery::ScUndoQuery( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScQueryParam& rParam,
923 							ScDocument* pNewUndoDoc, ScDBCollection* pNewUndoDB,
924 							const ScRange* pOld, sal_Bool bSize, const ScRange* pAdvSrc ) :
925 	ScDBFuncUndo( pNewDocShell, ScRange( rParam.nCol1, rParam.nRow1, nNewTab,
926 	                                     rParam.nCol2, rParam.nRow2, nNewTab ) ),
927 	pDrawUndo( NULL ),
928 	nTab( nNewTab ),
929 	aQueryParam( rParam ),
930 	pUndoDoc( pNewUndoDoc ),
931 //	pUndoDBData( pNewData )
932 	pUndoDB( pNewUndoDB ),
933 	bIsAdvanced( sal_False ),
934 	bDestArea( sal_False ),
935 	bDoSize( bSize )
936 {
937 	if ( pOld )
938 	{
939 		bDestArea = sal_True;
940 		aOldDest = *pOld;
941 	}
942 	if ( pAdvSrc )
943 	{
944 		bIsAdvanced = sal_True;
945 		aAdvSource = *pAdvSrc;
946 	}
947 
948     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
949 }
950 
~ScUndoQuery()951 __EXPORT ScUndoQuery::~ScUndoQuery()
952 {
953 	delete pUndoDoc;
954 //	delete pUndoDBData;
955 	delete pUndoDB;
956     DeleteSdrUndoAction( pDrawUndo );
957 }
958 
GetComment() const959 String __EXPORT ScUndoQuery::GetComment() const
960 {	// "Filtern";
961 	return ScGlobal::GetRscString( STR_UNDO_QUERY );
962 }
963 
Undo()964 void __EXPORT ScUndoQuery::Undo()
965 {
966 	BeginUndo();
967 
968 	ScDocument* pDoc = pDocShell->GetDocument();
969 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
970 
971 	sal_Bool bCopy = !aQueryParam.bInplace;
972 	SCCOL nDestEndCol = 0;
973 	SCROW nDestEndRow = 0;
974 	if (bCopy)
975 	{
976 		nDestEndCol = aQueryParam.nDestCol + ( aQueryParam.nCol2-aQueryParam.nCol1 );
977 		nDestEndRow = aQueryParam.nDestRow + ( aQueryParam.nRow2-aQueryParam.nRow1 );
978 
979 		ScDBData* pData = pDoc->GetDBAtCursor( aQueryParam.nDestCol, aQueryParam.nDestRow,
980 												aQueryParam.nDestTab, sal_True );
981 		if (pData)
982 		{
983 			ScRange aNewDest;
984 			pData->GetArea( aNewDest );
985 			nDestEndCol = aNewDest.aEnd.Col();
986 			nDestEndRow = aNewDest.aEnd.Row();
987 		}
988 
989 		if ( bDoSize && bDestArea )
990 		{
991 			//	aDestRange ist der alte Bereich
992 			pDoc->FitBlock( ScRange(
993 								aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
994 								nDestEndCol, nDestEndRow, aQueryParam.nDestTab ),
995 							aOldDest );
996 		}
997 
998 		ScUndoUtil::MarkSimpleBlock( pDocShell,
999 									aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
1000 									nDestEndCol, nDestEndRow, aQueryParam.nDestTab );
1001 		pDoc->DeleteAreaTab( aQueryParam.nDestCol, aQueryParam.nDestRow,
1002 							nDestEndCol, nDestEndRow, aQueryParam.nDestTab, IDF_ALL );
1003 
1004 		pViewShell->DoneBlockMode();
1005 
1006 		pUndoDoc->CopyToDocument( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
1007 									nDestEndCol, nDestEndRow, aQueryParam.nDestTab,
1008 									IDF_ALL, sal_False, pDoc );
1009 		//	Attribute werden immer mitkopiert (#49287#)
1010 
1011 		//	Rest von altem Bereich
1012 		if ( bDestArea && !bDoSize )
1013 		{
1014 			pDoc->DeleteAreaTab( aOldDest, IDF_ALL );
1015 			pUndoDoc->CopyToDocument( aOldDest, IDF_ALL, sal_False, pDoc );
1016 		}
1017 	}
1018 	else
1019 		pUndoDoc->CopyToDocument( 0, aQueryParam.nRow1, nTab, MAXCOL, aQueryParam.nRow2, nTab,
1020 										IDF_NONE, sal_False, pDoc );
1021 
1022 	if (pUndoDB)
1023 		pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
1024 
1025 	if (!bCopy)
1026     {
1027         pDoc->InvalidatePageBreaks(nTab);
1028 		pDoc->UpdatePageBreaks( nTab );
1029     }
1030 
1031     ScRange aDirtyRange( 0 , aQueryParam.nRow1, nTab,
1032         MAXCOL, aQueryParam.nRow2, nTab );
1033     pDoc->SetDirty( aDirtyRange );
1034 
1035     DoSdrUndoAction( pDrawUndo, pDoc );
1036 
1037 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1038 	if ( nVisTab != nTab )
1039 		pViewShell->SetTabNo( nTab );
1040 
1041 		//	Paint
1042 
1043 	if (bCopy)
1044 	{
1045 		SCCOL nEndX = nDestEndCol;
1046 		SCROW nEndY = nDestEndRow;
1047 		if (bDestArea)
1048 		{
1049 			if ( aOldDest.aEnd.Col() > nEndX )
1050 				nEndX = aOldDest.aEnd.Col();
1051 			if ( aOldDest.aEnd.Row() > nEndY )
1052 				nEndY = aOldDest.aEnd.Row();
1053 		}
1054 		if (bDoSize)
1055 			nEndY = MAXROW;
1056 		pDocShell->PostPaint( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
1057 									nEndX, nEndY, aQueryParam.nDestTab, PAINT_GRID );
1058 	}
1059 	else
1060 		pDocShell->PostPaint( 0, aQueryParam.nRow1, nTab, MAXCOL, MAXROW, nTab,
1061 													PAINT_GRID | PAINT_LEFT );
1062 	pDocShell->PostDataChanged();
1063 
1064 	EndUndo();
1065 }
1066 
Redo()1067 void __EXPORT ScUndoQuery::Redo()
1068 {
1069 	BeginRedo();
1070 
1071 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1072 
1073 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1074 	if ( nVisTab != nTab )
1075 		pViewShell->SetTabNo( nTab );
1076 
1077 	if ( bIsAdvanced )
1078 		pViewShell->Query( aQueryParam, &aAdvSource, sal_False );
1079 	else
1080 		pViewShell->Query( aQueryParam, NULL, sal_False );
1081 
1082 	EndRedo();
1083 }
1084 
Repeat(SfxRepeatTarget &)1085 void __EXPORT ScUndoQuery::Repeat(SfxRepeatTarget& /* rTarget */)
1086 {
1087 }
1088 
CanRepeat(SfxRepeatTarget &) const1089 sal_Bool __EXPORT ScUndoQuery::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1090 {
1091 	return sal_False;						// geht nicht wegen Spaltennummern
1092 }
1093 
1094 //
1095 //      Show or hide AutoFilter buttons (doesn't include filter settings)
1096 //
1097 
ScUndoAutoFilter(ScDocShell * pNewDocShell,const ScRange & rRange,const String & rName,sal_Bool bSet)1098 ScUndoAutoFilter::ScUndoAutoFilter( ScDocShell* pNewDocShell, const ScRange& rRange,
1099                                     const String& rName, sal_Bool bSet ) :
1100     ScDBFuncUndo( pNewDocShell, rRange ),
1101     aDBName( rName ),
1102     bFilterSet( bSet )
1103 {
1104 }
1105 
~ScUndoAutoFilter()1106 ScUndoAutoFilter::~ScUndoAutoFilter()
1107 {
1108 }
1109 
GetComment() const1110 String ScUndoAutoFilter::GetComment() const
1111 {
1112     return ScGlobal::GetRscString( STR_UNDO_QUERY );    // same as ScUndoQuery
1113 }
1114 
DoChange(sal_Bool bUndo)1115 void ScUndoAutoFilter::DoChange( sal_Bool bUndo )
1116 {
1117     sal_Bool bNewFilter = bUndo ? !bFilterSet : bFilterSet;
1118 
1119     sal_uInt16 nIndex;
1120     ScDocument* pDoc = pDocShell->GetDocument();
1121     ScDBCollection* pColl = pDoc->GetDBCollection();
1122     if ( pColl->SearchName( aDBName, nIndex ) )
1123     {
1124         ScDBData* pDBData = (*pColl)[nIndex];
1125         pDBData->SetAutoFilter( bNewFilter );
1126 
1127         SCCOL nRangeX1;
1128         SCROW nRangeY1;
1129         SCCOL nRangeX2;
1130         SCROW nRangeY2;
1131         SCTAB nRangeTab;
1132         pDBData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
1133 
1134         if ( bNewFilter )
1135             pDoc->ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
1136         else
1137             pDoc->RemoveFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
1138 
1139         pDocShell->PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PAINT_GRID );
1140     }
1141 }
1142 
Undo()1143 void ScUndoAutoFilter::Undo()
1144 {
1145     BeginUndo();
1146     DoChange( sal_True );
1147     EndUndo();
1148 }
1149 
Redo()1150 void ScUndoAutoFilter::Redo()
1151 {
1152     BeginRedo();
1153     DoChange( sal_False );
1154     EndRedo();
1155 }
1156 
Repeat(SfxRepeatTarget &)1157 void ScUndoAutoFilter::Repeat(SfxRepeatTarget& /* rTarget */)
1158 {
1159 }
1160 
CanRepeat(SfxRepeatTarget &) const1161 sal_Bool ScUndoAutoFilter::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1162 {
1163     return sal_False;
1164 }
1165 
1166 //
1167 //		Datenbankbereiche aendern (Dialog)
1168 //
1169 
ScUndoDBData(ScDocShell * pNewDocShell,ScDBCollection * pNewUndoColl,ScDBCollection * pNewRedoColl)1170 ScUndoDBData::ScUndoDBData( ScDocShell* pNewDocShell,
1171 							ScDBCollection* pNewUndoColl, ScDBCollection* pNewRedoColl ) :
1172 	ScSimpleUndo( pNewDocShell ),
1173 	pUndoColl( pNewUndoColl ),
1174 	pRedoColl( pNewRedoColl )
1175 {
1176 }
1177 
~ScUndoDBData()1178 __EXPORT ScUndoDBData::~ScUndoDBData()
1179 {
1180 	delete pUndoColl;
1181 	delete pRedoColl;
1182 }
1183 
GetComment() const1184 String __EXPORT ScUndoDBData::GetComment() const
1185 {	// "Datenbankbereiche aendern";
1186 	return ScGlobal::GetRscString( STR_UNDO_DBDATA );
1187 }
1188 
Undo()1189 void __EXPORT ScUndoDBData::Undo()
1190 {
1191 	BeginUndo();
1192 
1193 	ScDocument* pDoc = pDocShell->GetDocument();
1194 
1195 	sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
1196 	pDoc->SetAutoCalc( sal_False );			// unnoetige Berechnungen vermeiden
1197 	pDoc->CompileDBFormula( sal_True );		// CreateFormulaString
1198 	pDoc->SetDBCollection( new ScDBCollection(*pUndoColl), sal_True );
1199 	pDoc->CompileDBFormula( sal_False );	// CompileFormulaString
1200 	pDoc->SetAutoCalc( bOldAutoCalc );
1201 
1202 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1203 
1204 	EndUndo();
1205 }
1206 
Redo()1207 void __EXPORT ScUndoDBData::Redo()
1208 {
1209 	BeginRedo();
1210 
1211 	ScDocument* pDoc = pDocShell->GetDocument();
1212 
1213 	sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
1214 	pDoc->SetAutoCalc( sal_False );			// unnoetige Berechnungen vermeiden
1215 	pDoc->CompileDBFormula( sal_True );		// CreateFormulaString
1216 	pDoc->SetDBCollection( new ScDBCollection(*pRedoColl), sal_True );
1217 	pDoc->CompileDBFormula( sal_False );	// CompileFormulaString
1218 	pDoc->SetAutoCalc( bOldAutoCalc );
1219 
1220 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
1221 
1222 	EndRedo();
1223 }
1224 
Repeat(SfxRepeatTarget &)1225 void __EXPORT ScUndoDBData::Repeat(SfxRepeatTarget& /* rTarget */)
1226 {
1227 }
1228 
CanRepeat(SfxRepeatTarget &) const1229 sal_Bool __EXPORT ScUndoDBData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1230 {
1231 	return sal_False;						// geht nicht
1232 }
1233 
1234 //
1235 //		Import
1236 //
1237 
ScUndoImportData(ScDocShell * pNewDocShell,SCTAB nNewTab,const ScImportParam & rParam,SCCOL nNewEndX,SCROW nNewEndY,SCCOL nNewFormula,ScDocument * pNewUndoDoc,ScDocument * pNewRedoDoc,ScDBData * pNewUndoData,ScDBData * pNewRedoData)1238 ScUndoImportData::ScUndoImportData( ScDocShell* pNewDocShell, SCTAB nNewTab,
1239 								const ScImportParam& rParam, SCCOL nNewEndX, SCROW nNewEndY,
1240 								SCCOL nNewFormula,
1241 								ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
1242 								ScDBData* pNewUndoData, ScDBData* pNewRedoData ) :
1243 	ScSimpleUndo( pNewDocShell ),
1244 	nTab( nNewTab ),
1245 	aImportParam( rParam ),
1246 	nEndCol( nNewEndX ),
1247 	nEndRow( nNewEndY ),
1248 	pUndoDoc( pNewUndoDoc ),
1249 	pRedoDoc( pNewRedoDoc ),
1250 	pUndoDBData( pNewUndoData ),
1251 	pRedoDBData( pNewRedoData ),
1252 	nFormulaCols( nNewFormula ),
1253 	bRedoFilled( sal_False )
1254 {
1255 	// redo doc doesn't contain imported data (but everything else)
1256 }
1257 
~ScUndoImportData()1258 __EXPORT ScUndoImportData::~ScUndoImportData()
1259 {
1260 	delete pUndoDoc;
1261 	delete pRedoDoc;
1262 	delete pUndoDBData;
1263 	delete pRedoDBData;
1264 }
1265 
GetComment() const1266 String __EXPORT ScUndoImportData::GetComment() const
1267 {	// "Importieren";
1268 	return ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
1269 }
1270 
Undo()1271 void __EXPORT ScUndoImportData::Undo()
1272 {
1273 	BeginUndo();
1274 
1275 	ScDocument* pDoc = pDocShell->GetDocument();
1276 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1277 
1278 	ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
1279 														nEndCol,nEndRow,nTab );
1280 
1281 	SCTAB nTable;
1282 	SCCOL nCol1, nCol2;
1283 	SCROW nRow1, nRow2;
1284 	ScDBData* pCurrentData = NULL;
1285 	if (pUndoDBData && pRedoDBData)
1286 	{
1287 		pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1288 		pCurrentData = ScUndoUtil::GetOldDBData( pRedoDBData, pDoc, nTab,
1289 													nCol1, nRow1, nCol2, nRow2 );
1290 
1291 		if ( !bRedoFilled )
1292 		{
1293 			//	read redo data from document at first undo
1294 			//	imported data is deleted later anyway,
1295 			//	so now delete each column after copying to save memory (#41216#)
1296 
1297 			sal_Bool bOldAutoCalc = pDoc->GetAutoCalc();
1298 			pDoc->SetAutoCalc( sal_False );				// outside of the loop
1299 			for (SCCOL nCopyCol = nCol1; nCopyCol <= nCol2; nCopyCol++)
1300 			{
1301 				pDoc->CopyToDocument( nCopyCol,nRow1,nTab, nCopyCol,nRow2,nTab,
1302                                         IDF_CONTENTS & ~IDF_NOTE, sal_False, pRedoDoc );
1303                 pDoc->DeleteAreaTab( nCopyCol,nRow1, nCopyCol,nRow2, nTab, IDF_CONTENTS & ~IDF_NOTE );
1304 				pDoc->DoColResize( nTab, nCopyCol, nCopyCol, 0 );
1305 			}
1306 			pDoc->SetAutoCalc( bOldAutoCalc );
1307 			bRedoFilled = sal_True;
1308 		}
1309 	}
1310 	sal_Bool bMoveCells = pUndoDBData && pRedoDBData &&
1311 						pRedoDBData->IsDoSize();		// in alt und neu gleich
1312 	if (bMoveCells)
1313 	{
1314 		//	Undo: erst die neuen Daten loeschen, dann FitBlock rueckwaerts
1315 
1316 		ScRange aOld, aNew;
1317 		pUndoDBData->GetArea( aOld );
1318 		pRedoDBData->GetArea( aNew );
1319 
1320 		pDoc->DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
1321                                 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
1322 
1323 		aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols );		// FitBlock auch fuer Formeln
1324 		aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
1325 		pDoc->FitBlock( aNew, aOld, sal_False );					// rueckwaerts
1326 	}
1327 	else
1328 		pDoc->DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
1329                                 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
1330 
1331 	pUndoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
1332 								nEndCol+nFormulaCols,nEndRow,nTab,
1333                                 IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
1334 
1335 	if (pCurrentData)
1336 	{
1337 		*pCurrentData = *pUndoDBData;
1338 
1339 		pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1340 		ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
1341 	}
1342 
1343 // erack! it's broadcasted
1344 //	pDoc->SetDirty();
1345 
1346 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1347 	if ( nVisTab != nTab )
1348 		pViewShell->SetTabNo( nTab );
1349 
1350 	if (bMoveCells)
1351 		pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
1352 	else
1353 		pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
1354 								nEndCol,nEndRow,nTab, PAINT_GRID );
1355 	pDocShell->PostDataChanged();
1356 
1357 	EndUndo();
1358 }
1359 
Redo()1360 void __EXPORT ScUndoImportData::Redo()
1361 {
1362 	BeginRedo();
1363 
1364 	ScDocument* pDoc = pDocShell->GetDocument();
1365 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1366 
1367 	ScUndoUtil::MarkSimpleBlock( pDocShell, aImportParam.nCol1,aImportParam.nRow1,nTab,
1368 														nEndCol,nEndRow,nTab );
1369 
1370 	SCTAB nTable;
1371 	SCCOL nCol1, nCol2;
1372 	SCROW nRow1, nRow2;
1373 	ScDBData* pCurrentData = NULL;
1374 	if (pUndoDBData && pRedoDBData)
1375 	{
1376 		pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1377 		pCurrentData = ScUndoUtil::GetOldDBData( pUndoDBData, pDoc, nTab,
1378 													nCol1, nRow1, nCol2, nRow2 );
1379 	}
1380 	sal_Bool bMoveCells = pUndoDBData && pRedoDBData &&
1381 						pRedoDBData->IsDoSize();		// in alt und neu gleich
1382 	if (bMoveCells)
1383 	{
1384 		//	Redo: FitBlock, dann Daten loeschen (noetig fuer CopyToDocument)
1385 
1386 		ScRange aOld, aNew;
1387 		pUndoDBData->GetArea( aOld );
1388 		pRedoDBData->GetArea( aNew );
1389 
1390 		aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols );		// FitBlock auch fuer Formeln
1391 		aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
1392 		pDoc->FitBlock( aOld, aNew );
1393 
1394 		pDoc->DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
1395                                 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, IDF_ALL & ~IDF_NOTE );
1396 
1397         pRedoDoc->CopyToDocument( aNew, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );        // incl. Formeln
1398 	}
1399 	else
1400 	{
1401 		pDoc->DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
1402                                 nEndCol,nEndRow, nTab, IDF_ALL & ~IDF_NOTE );
1403 		pRedoDoc->CopyToDocument( aImportParam.nCol1,aImportParam.nRow1,nTab,
1404                                 nEndCol,nEndRow,nTab, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
1405 	}
1406 
1407 	if (pCurrentData)
1408 	{
1409 		*pCurrentData = *pRedoDBData;
1410 
1411 		pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
1412 		ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
1413 	}
1414 
1415 // erack! it's broadcasted
1416 //	pDoc->SetDirty();
1417 
1418 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1419 	if ( nVisTab != nTab )
1420 		pViewShell->SetTabNo( nTab );
1421 
1422 	if (bMoveCells)
1423 		pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
1424 	else
1425 		pDocShell->PostPaint( aImportParam.nCol1,aImportParam.nRow1,nTab,
1426 								nEndCol,nEndRow,nTab, PAINT_GRID );
1427 	pDocShell->PostDataChanged();
1428 
1429 	EndRedo();
1430 }
1431 
Repeat(SfxRepeatTarget & rTarget)1432 void __EXPORT ScUndoImportData::Repeat(SfxRepeatTarget& rTarget)
1433 {
1434 	if (rTarget.ISA(ScTabViewTarget))
1435 	{
1436 		ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
1437 
1438 		SCTAB nDummy;
1439 		ScImportParam aNewParam(aImportParam);
1440 		ScDBData* pDBData = rViewShell.GetDBData();
1441 		pDBData->GetArea( nDummy, aNewParam.nCol1,aNewParam.nRow1, aNewParam.nCol2,aNewParam.nRow2 );
1442 
1443 		rViewShell.ImportData( aNewParam );
1444 	}
1445 }
1446 
CanRepeat(SfxRepeatTarget & rTarget) const1447 sal_Bool __EXPORT ScUndoImportData::CanRepeat(SfxRepeatTarget& rTarget) const
1448 {
1449 	//	Repeat nur fuer Import per DB-Bereich, dann ist pUndoDBData gesetzt
1450 
1451 	if (pUndoDBData)
1452 		return (rTarget.ISA(ScTabViewTarget));
1453 	else
1454 		return sal_False;		// Adressbuch
1455 }
1456 
1457 //
1458 //		Operationen wiederholen
1459 //
1460 
ScUndoRepeatDB(ScDocShell * pNewDocShell,SCTAB nNewTab,SCCOL nStartX,SCROW nStartY,SCCOL nEndX,SCROW nEndY,SCROW nResultEndRow,SCCOL nCurX,SCROW nCurY,ScDocument * pNewUndoDoc,ScOutlineTable * pNewUndoTab,ScRangeName * pNewUndoRange,ScDBCollection * pNewUndoDB,const ScRange * pOldQ,const ScRange * pNewQ)1461 ScUndoRepeatDB::ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
1462 								SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY,
1463 								SCROW nResultEndRow, SCCOL nCurX, SCROW nCurY,
1464 								ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
1465 								ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB,
1466 								const ScRange* pOldQ, const ScRange* pNewQ ) :
1467 	ScSimpleUndo( pNewDocShell ),
1468 	aBlockStart( nStartX,nStartY,nNewTab ),
1469 	aBlockEnd( nEndX,nEndY,nNewTab ),
1470 	nNewEndRow( nResultEndRow ),
1471 	aCursorPos( nCurX,nCurY,nNewTab ),
1472 	pUndoDoc( pNewUndoDoc ),
1473 	pUndoTable( pNewUndoTab ),
1474 	pUndoRange( pNewUndoRange ),
1475 	pUndoDB( pNewUndoDB ),
1476 	bQuerySize( sal_False )
1477 {
1478 	if ( pOldQ && pNewQ )
1479 	{
1480 		aOldQuery = *pOldQ;
1481 		aNewQuery = *pNewQ;
1482 		bQuerySize = sal_True;;
1483 	}
1484 }
1485 
~ScUndoRepeatDB()1486 __EXPORT ScUndoRepeatDB::~ScUndoRepeatDB()
1487 {
1488 	delete pUndoDoc;
1489 	delete pUndoTable;
1490 	delete pUndoRange;
1491 	delete pUndoDB;
1492 }
1493 
GetComment() const1494 String __EXPORT ScUndoRepeatDB::GetComment() const
1495 {	// "Wiederholen";       //! bessere Beschreibung!
1496 	return ScGlobal::GetRscString( STR_UNDO_REPEATDB );
1497 }
1498 
Undo()1499 void __EXPORT ScUndoRepeatDB::Undo()
1500 {
1501 	BeginUndo();
1502 
1503 	ScDocument* pDoc = pDocShell->GetDocument();
1504 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1505 	SCTAB nTab = aBlockStart.Tab();
1506 
1507 	if (bQuerySize)
1508 	{
1509 		pDoc->FitBlock( aNewQuery, aOldQuery, sal_False );
1510 
1511 		if ( aNewQuery.aEnd.Col() == aOldQuery.aEnd.Col() )
1512 		{
1513 			SCCOL nFormulaCols = 0;
1514 			SCCOL nCol = aOldQuery.aEnd.Col() + 1;
1515 			SCROW nRow = aOldQuery.aStart.Row() + 1;		//! Header testen
1516 			while ( nCol <= MAXCOL &&
1517 					pDoc->GetCellType(ScAddress( nCol, nRow, nTab )) == CELLTYPE_FORMULA )
1518 				++nCol, ++nFormulaCols;
1519 
1520 			if ( nFormulaCols > 0 )
1521 			{
1522 				ScRange aOldForm = aOldQuery;
1523 				aOldForm.aStart.SetCol( aOldQuery.aEnd.Col() + 1 );
1524 				aOldForm.aEnd.SetCol( aOldQuery.aEnd.Col() + nFormulaCols );
1525 				ScRange aNewForm = aOldForm;
1526 				aNewForm.aEnd.SetRow( aNewQuery.aEnd.Row() );
1527 				pDoc->FitBlock( aNewForm, aOldForm, sal_False );
1528 			}
1529 		}
1530 	}
1531 
1532 	//!		Daten von Filter in anderen Bereich fehlen noch	!!!!!!!!!!!!!!!!!
1533 
1534 	if (nNewEndRow > aBlockEnd.Row())
1535 	{
1536 		pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aBlockEnd.Row()+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
1537 	}
1538 	else if (nNewEndRow < aBlockEnd.Row())
1539 	{
1540 		pDoc->InsertRow( 0,nTab, MAXCOL,nTab, nNewEndRow+1, static_cast<SCSIZE>(nNewEndRow-aBlockEnd.Row()) );
1541 	}
1542 
1543 	//	Original Outline-Table
1544 
1545 	pDoc->SetOutlineTable( nTab, pUndoTable );
1546 
1547 	//	Original Spalten-/Zeilenstatus
1548 
1549 	if (pUndoDoc && pUndoTable)
1550 	{
1551 		SCCOLROW nStartCol;
1552 		SCCOLROW nStartRow;
1553 		SCCOLROW nEndCol;
1554 		SCCOLROW nEndRow;
1555 		pUndoTable->GetColArray()->GetRange( nStartCol, nEndCol );
1556 		pUndoTable->GetRowArray()->GetRange( nStartRow, nEndRow );
1557 
1558         pUndoDoc->CopyToDocument( static_cast<SCCOL>(nStartCol), 0, nTab,
1559                 static_cast<SCCOL>(nEndCol), MAXROW, nTab, IDF_NONE, sal_False,
1560                 pDoc );
1561 		pUndoDoc->CopyToDocument( 0, nStartRow, nTab, MAXCOL, nEndRow, nTab, IDF_NONE, sal_False, pDoc );
1562 
1563 		pViewShell->UpdateScrollBars();
1564 	}
1565 
1566 	//	Original-Daten & Referenzen
1567 
1568 	ScUndoUtil::MarkSimpleBlock( pDocShell, 0, aBlockStart.Row(), nTab,
1569 											MAXCOL, aBlockEnd.Row(), nTab );
1570 	pDoc->DeleteAreaTab( 0, aBlockStart.Row(),
1571 							MAXCOL, aBlockEnd.Row(), nTab, IDF_ALL );
1572 
1573 	pUndoDoc->CopyToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
1574 															IDF_NONE, sal_False, pDoc );			// Flags
1575 	pUndoDoc->UndoToDocument( 0, aBlockStart.Row(), nTab, MAXCOL, aBlockEnd.Row(), nTab,
1576 															IDF_ALL, sal_False, pDoc );
1577 
1578 	ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
1579 											aBlockEnd.Col(),aBlockEnd.Row(),nTab );
1580 
1581 	if (pUndoRange)
1582 		pDoc->SetRangeName( new ScRangeName( *pUndoRange ) );
1583 	if (pUndoDB)
1584 		pDoc->SetDBCollection( new ScDBCollection( *pUndoDB ), sal_True );
1585 
1586 // erack! it's broadcasted
1587 //	pDoc->SetDirty();
1588 
1589 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1590 	if ( nVisTab != nTab )
1591 		pViewShell->SetTabNo( nTab );
1592 
1593 	pDocShell->PostPaint(0,0,nTab,MAXCOL,MAXROW,nTab,PAINT_GRID|PAINT_LEFT|PAINT_TOP|PAINT_SIZE);
1594 	pDocShell->PostDataChanged();
1595 
1596 	EndUndo();
1597 }
1598 
Redo()1599 void __EXPORT ScUndoRepeatDB::Redo()
1600 {
1601 	BeginRedo();
1602 
1603 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1604 	SCTAB nTab = aBlockStart.Tab();
1605 
1606 	SCTAB nVisTab = pViewShell->GetViewData()->GetTabNo();
1607 	if ( nVisTab != nTab )
1608 		pViewShell->SetTabNo( nTab );
1609 
1610 	ScUndoUtil::MarkSimpleBlock( pDocShell, aBlockStart.Col(),aBlockStart.Row(),nTab,
1611 											aBlockEnd.Col(),aBlockEnd.Row(),nTab );
1612 	pViewShell->SetCursor( aCursorPos.Col(), aCursorPos.Row() );
1613 
1614 	pViewShell->RepeatDB( sal_False );
1615 
1616 	EndRedo();
1617 }
1618 
Repeat(SfxRepeatTarget & rTarget)1619 void __EXPORT ScUndoRepeatDB::Repeat(SfxRepeatTarget& rTarget)
1620 {
1621 	if (rTarget.ISA(ScTabViewTarget))
1622 		((ScTabViewTarget&)rTarget).GetViewShell()->RepeatDB( sal_True );
1623 }
1624 
CanRepeat(SfxRepeatTarget & rTarget) const1625 sal_Bool __EXPORT ScUndoRepeatDB::CanRepeat(SfxRepeatTarget& rTarget) const
1626 {
1627 	return (rTarget.ISA(ScTabViewTarget));
1628 }
1629 
1630 //UNUSED2008-05  //
1631 //UNUSED2008-05  //		Pivot-Tabellen
1632 //UNUSED2008-05  //
1633 //UNUSED2008-05
1634 //UNUSED2008-05  ScUndoPivot::ScUndoPivot( ScDocShell* pNewDocShell,
1635 //UNUSED2008-05                              const ScArea& rOld, const ScArea& rNew,
1636 //UNUSED2008-05                              ScDocument* pOldDoc, ScDocument* pNewDoc,
1637 //UNUSED2008-05                              const ScPivot* pOldPivot, const ScPivot* pNewPivot ) :
1638 //UNUSED2008-05      ScSimpleUndo( pNewDocShell ),
1639 //UNUSED2008-05      aOldArea( rOld ),
1640 //UNUSED2008-05      aNewArea( rNew ),
1641 //UNUSED2008-05      pOldUndoDoc( pOldDoc ),
1642 //UNUSED2008-05      pNewUndoDoc( pNewDoc )
1643 //UNUSED2008-05  {
1644 //UNUSED2008-05      if (pNewPivot)
1645 //UNUSED2008-05      {
1646 //UNUSED2008-05          pNewPivot->GetParam( aNewParam, aNewQuery, aNewSrc );
1647 //UNUSED2008-05          aNewName = pNewPivot->GetName();
1648 //UNUSED2008-05          aNewTag = pNewPivot->GetTag();
1649 //UNUSED2008-05      }
1650 //UNUSED2008-05      if (pOldPivot)
1651 //UNUSED2008-05      {
1652 //UNUSED2008-05          pOldPivot->GetParam( aOldParam, aOldQuery, aOldSrc );
1653 //UNUSED2008-05          aOldName = pOldPivot->GetName();
1654 //UNUSED2008-05          aOldTag = pOldPivot->GetTag();
1655 //UNUSED2008-05      }
1656 //UNUSED2008-05  }
1657 //UNUSED2008-05
1658 //UNUSED2008-05  __EXPORT ScUndoPivot::~ScUndoPivot()
1659 //UNUSED2008-05  {
1660 //UNUSED2008-05      delete pOldUndoDoc;
1661 //UNUSED2008-05      delete pNewUndoDoc;
1662 //UNUSED2008-05  }
1663 //UNUSED2008-05
1664 //UNUSED2008-05  String __EXPORT ScUndoPivot::GetComment() const
1665 //UNUSED2008-05  {
1666 //UNUSED2008-05      sal_uInt16 nIndex;
1667 //UNUSED2008-05      if ( pOldUndoDoc && pNewUndoDoc )
1668 //UNUSED2008-05          nIndex = STR_UNDO_PIVOT_MODIFY;
1669 //UNUSED2008-05      else if ( pNewUndoDoc )
1670 //UNUSED2008-05          nIndex = STR_UNDO_PIVOT_NEW;
1671 //UNUSED2008-05      else
1672 //UNUSED2008-05          nIndex = STR_UNDO_PIVOT_DELETE;
1673 //UNUSED2008-05
1674 //UNUSED2008-05      return ScGlobal::GetRscString( nIndex );
1675 //UNUSED2008-05  }
1676 //UNUSED2008-05
1677 //UNUSED2008-05  void __EXPORT ScUndoPivot::Undo()
1678 //UNUSED2008-05  {
1679 //UNUSED2008-05      BeginUndo();
1680 //UNUSED2008-05
1681 //UNUSED2008-05      ScDocument* pDoc = pDocShell->GetDocument();
1682 //UNUSED2008-05
1683 //UNUSED2008-05      if (pNewUndoDoc)
1684 //UNUSED2008-05      {
1685 //UNUSED2008-05          pDoc->DeleteAreaTab( aNewArea.nColStart,aNewArea.nRowStart,
1686 //UNUSED2008-05                              aNewArea.nColEnd,aNewArea.nRowEnd, aNewArea.nTab, IDF_ALL );
1687 //UNUSED2008-05          pNewUndoDoc->CopyToDocument( aNewArea.nColStart, aNewArea.nRowStart, aNewArea.nTab,
1688 //UNUSED2008-05                                  aNewArea.nColEnd, aNewArea.nRowEnd, aNewArea.nTab,
1689 //UNUSED2008-05                                  IDF_ALL, sal_False, pDoc );
1690 //UNUSED2008-05      }
1691 //UNUSED2008-05      if (pOldUndoDoc)
1692 //UNUSED2008-05      {
1693 //UNUSED2008-05          pDoc->DeleteAreaTab( aOldArea.nColStart,aOldArea.nRowStart,
1694 //UNUSED2008-05                              aOldArea.nColEnd,aOldArea.nRowEnd, aOldArea.nTab, IDF_ALL );
1695 //UNUSED2008-05          pOldUndoDoc->CopyToDocument( aOldArea.nColStart, aOldArea.nRowStart, aOldArea.nTab,
1696 //UNUSED2008-05                                  aOldArea.nColEnd, aOldArea.nRowEnd, aOldArea.nTab,
1697 //UNUSED2008-05                                  IDF_ALL, sal_False, pDoc );
1698 //UNUSED2008-05      }
1699 //UNUSED2008-05
1700 //UNUSED2008-05      ScPivotCollection* pPivotCollection = pDoc->GetPivotCollection();
1701 //UNUSED2008-05      if ( pNewUndoDoc )
1702 //UNUSED2008-05      {
1703 //UNUSED2008-05          ScPivot* pNewPivot = pPivotCollection->GetPivotAtCursor(
1704 //UNUSED2008-05                                  aNewParam.nCol, aNewParam.nRow, aNewParam.nTab );
1705 //UNUSED2008-05          if (pNewPivot)
1706 //UNUSED2008-05              pPivotCollection->Free( pNewPivot );
1707 //UNUSED2008-05      }
1708 //UNUSED2008-05      if ( pOldUndoDoc )
1709 //UNUSED2008-05      {
1710 //UNUSED2008-05          ScPivot* pOldPivot = new ScPivot( pDoc );
1711 //UNUSED2008-05          pOldPivot->SetParam( aOldParam, aOldQuery, aOldSrc );
1712 //UNUSED2008-05          pOldPivot->SetName( aOldName );
1713 //UNUSED2008-05          pOldPivot->SetTag( aOldTag );
1714 //UNUSED2008-05          if (pOldPivot->CreateData())                            // Felder berechnen
1715 //UNUSED2008-05              pOldPivot->ReleaseData();
1716 //UNUSED2008-05          pPivotCollection->Insert( pOldPivot );
1717 //UNUSED2008-05      }
1718 //UNUSED2008-05
1719 //UNUSED2008-05  // erack! it's broadcasted
1720 //UNUSED2008-05  //	pDoc->SetDirty();
1721 //UNUSED2008-05      if (pNewUndoDoc)
1722 //UNUSED2008-05          pDocShell->PostPaint( aNewArea.nColStart, aNewArea.nRowStart, aNewArea.nTab,
1723 //UNUSED2008-05                                  aNewArea.nColEnd, aNewArea.nRowEnd, aNewArea.nTab,
1724 //UNUSED2008-05                                  PAINT_GRID, SC_PF_LINES );
1725 //UNUSED2008-05      if (pOldUndoDoc)
1726 //UNUSED2008-05          pDocShell->PostPaint( aOldArea.nColStart, aOldArea.nRowStart, aOldArea.nTab,
1727 //UNUSED2008-05                                  aOldArea.nColEnd, aOldArea.nRowEnd, aOldArea.nTab,
1728 //UNUSED2008-05                                  PAINT_GRID, SC_PF_LINES );
1729 //UNUSED2008-05      pDocShell->PostDataChanged();
1730 //UNUSED2008-05
1731 //UNUSED2008-05      ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1732 //UNUSED2008-05      if (pViewShell)
1733 //UNUSED2008-05      {
1734 //UNUSED2008-05          SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
1735 //UNUSED2008-05          if ( pOldUndoDoc )
1736 //UNUSED2008-05          {
1737 //UNUSED2008-05              if ( nTab != aOldArea.nTab )
1738 //UNUSED2008-05                  pViewShell->SetTabNo( aOldArea.nTab );
1739 //UNUSED2008-05          }
1740 //UNUSED2008-05          else if ( pNewUndoDoc )
1741 //UNUSED2008-05          {
1742 //UNUSED2008-05              if ( nTab != aNewArea.nTab )
1743 //UNUSED2008-05                  pViewShell->SetTabNo( aNewArea.nTab );
1744 //UNUSED2008-05          }
1745 //UNUSED2008-05      }
1746 //UNUSED2008-05
1747 //UNUSED2008-05      EndUndo();
1748 //UNUSED2008-05  }
1749 //UNUSED2008-05
1750 //UNUSED2008-05  void __EXPORT ScUndoPivot::Redo()
1751 //UNUSED2008-05  {
1752 //UNUSED2008-05      BeginRedo();
1753 //UNUSED2008-05
1754 //UNUSED2008-05      ScDocument* pDoc = pDocShell->GetDocument();
1755 //UNUSED2008-05      ScPivotCollection* pPivotCollection = pDoc->GetPivotCollection();
1756 //UNUSED2008-05      ScPivot* pOldPivot = pPivotCollection->GetPivotAtCursor(
1757 //UNUSED2008-05                                              aOldParam.nCol, aOldParam.nRow, aOldParam.nTab );
1758 //UNUSED2008-05
1759 //UNUSED2008-05      ScPivot* pNewPivot = NULL;
1760 //UNUSED2008-05      if (pNewUndoDoc)
1761 //UNUSED2008-05      {
1762 //UNUSED2008-05          pNewPivot = new ScPivot( pDoc );
1763 //UNUSED2008-05          pNewPivot->SetParam( aNewParam, aNewQuery, aNewSrc );
1764 //UNUSED2008-05          pNewPivot->SetName( aNewName );
1765 //UNUSED2008-05          pNewPivot->SetTag( aNewTag );
1766 //UNUSED2008-05      }
1767 //UNUSED2008-05
1768 //UNUSED2008-05      pDocShell->PivotUpdate( pOldPivot, pNewPivot, sal_False );
1769 //UNUSED2008-05
1770 //UNUSED2008-05      EndRedo();
1771 //UNUSED2008-05  }
1772 //UNUSED2008-05
1773 //UNUSED2008-05  void __EXPORT ScUndoPivot::Repeat(SfxRepeatTarget& rTarget)
1774 //UNUSED2008-05  {
1775 //UNUSED2008-05      //  Wiederholen: nur loeschen
1776 //UNUSED2008-05
1777 //UNUSED2008-05      if ( pOldUndoDoc && !pNewUndoDoc && rTarget.ISA(ScTabViewTarget) )
1778 //UNUSED2008-05          ((ScTabViewTarget&)rTarget).GetViewShell()->DeletePivotTable();
1779 //UNUSED2008-05  }
1780 //UNUSED2008-05
1781 //UNUSED2008-05  sal_Bool __EXPORT ScUndoPivot::CanRepeat(SfxRepeatTarget& rTarget) const
1782 //UNUSED2008-05  {
1783 //UNUSED2008-05      //  Wiederholen: nur loeschen
1784 //UNUSED2008-05
1785 //UNUSED2008-05      return ( pOldUndoDoc && !pNewUndoDoc && rTarget.ISA(ScTabViewTarget) );
1786 //UNUSED2008-05  }
1787 
1788 //
1789 //		data pilot
1790 //
1791 
ScUndoDataPilot(ScDocShell * pNewDocShell,ScDocument * pOldDoc,ScDocument * pNewDoc,const ScDPObject * pOldObj,const ScDPObject * pNewObj,sal_Bool bMove)1792 ScUndoDataPilot::ScUndoDataPilot( ScDocShell* pNewDocShell,
1793 							ScDocument* pOldDoc, ScDocument* pNewDoc,
1794 							const ScDPObject* pOldObj, const ScDPObject* pNewObj, sal_Bool bMove ) :
1795 	ScSimpleUndo( pNewDocShell ),
1796 	pOldUndoDoc( pOldDoc ),
1797 	pNewUndoDoc( pNewDoc ),
1798 	pOldDPObject( NULL ),
1799 	pNewDPObject( NULL ),
1800 	bAllowMove( bMove )
1801 {
1802 	if (pOldObj)
1803 		pOldDPObject = new ScDPObject( *pOldObj );
1804 	if (pNewObj)
1805 		pNewDPObject = new ScDPObject( *pNewObj );
1806 }
1807 
~ScUndoDataPilot()1808 __EXPORT ScUndoDataPilot::~ScUndoDataPilot()
1809 {
1810 	delete pOldDPObject;
1811 	delete pNewDPObject;
1812 	delete pOldUndoDoc;
1813 	delete pNewUndoDoc;
1814 }
1815 
GetComment() const1816 String __EXPORT ScUndoDataPilot::GetComment() const
1817 {
1818 	sal_uInt16 nIndex;
1819 	if ( pOldUndoDoc && pNewUndoDoc )
1820 		nIndex = STR_UNDO_PIVOT_MODIFY;
1821 	else if ( pNewUndoDoc )
1822 		nIndex = STR_UNDO_PIVOT_NEW;
1823 	else
1824 		nIndex = STR_UNDO_PIVOT_DELETE;
1825 
1826 	return ScGlobal::GetRscString( nIndex );
1827 }
1828 
Undo()1829 void __EXPORT ScUndoDataPilot::Undo()
1830 {
1831 	BeginUndo();
1832 
1833 	ScDocument* pDoc = pDocShell->GetDocument();
1834 
1835 	ScRange aOldRange;
1836 	ScRange aNewRange;
1837 
1838 	if ( pNewDPObject && pNewUndoDoc )
1839 	{
1840 		aNewRange = pNewDPObject->GetOutRange();
1841 		pDoc->DeleteAreaTab( aNewRange, IDF_ALL );
1842 		pNewUndoDoc->CopyToDocument( aNewRange, IDF_ALL, sal_False, pDoc );
1843 	}
1844 	if ( pOldDPObject && pOldUndoDoc )
1845 	{
1846 		aOldRange = pOldDPObject->GetOutRange();
1847 		pDoc->DeleteAreaTab( aOldRange, IDF_ALL );
1848 		pOldUndoDoc->CopyToDocument( aOldRange, IDF_ALL, sal_False, pDoc );
1849 	}
1850 
1851 	//	update objects in collection
1852 
1853 	if ( pNewDPObject )
1854 	{
1855 		//	find updated object
1856 		//!	find by name!
1857 
1858 		ScDPObject* pDocObj = pDoc->GetDPAtCursor(
1859 							aNewRange.aStart.Col(), aNewRange.aStart.Row(), aNewRange.aStart.Tab() );
1860 		DBG_ASSERT(pDocObj, "DPObject not found");
1861 		if (pDocObj)
1862 		{
1863 			if ( pOldDPObject )
1864 			{
1865 				//	restore old settings
1866 				pOldDPObject->WriteSourceDataTo( *pDocObj );
1867 				ScDPSaveData* pData = pOldDPObject->GetSaveData();
1868 				if (pData)
1869 					pDocObj->SetSaveData(*pData);
1870 				pDocObj->SetOutRange( pOldDPObject->GetOutRange() );
1871 				pOldDPObject->WriteTempDataTo( *pDocObj );
1872 			}
1873 			else
1874 			{
1875 				//	delete inserted object
1876                 pDoc->GetDPCollection()->FreeTable(pDocObj);
1877 			}
1878 		}
1879 	}
1880 	else if ( pOldDPObject )
1881 	{
1882 		//	re-insert deleted object
1883 
1884 		ScDPObject* pDestObj = new ScDPObject( *pOldDPObject );
1885 		pDestObj->SetAlive(sal_True);
1886 		if ( !pDoc->GetDPCollection()->InsertNewTable(pDestObj) )
1887 		{
1888 			DBG_ERROR("cannot insert DPObject");
1889 			DELETEZ( pDestObj );
1890 		}
1891 	}
1892 
1893 	if (pNewUndoDoc)
1894 		pDocShell->PostPaint( aNewRange, PAINT_GRID, SC_PF_LINES );
1895 	if (pOldUndoDoc)
1896 		pDocShell->PostPaint( aOldRange, PAINT_GRID, SC_PF_LINES );
1897 	pDocShell->PostDataChanged();
1898 
1899 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1900 	if (pViewShell)
1901 	{
1902 		//!	set current sheet
1903 	}
1904 
1905     if (pNewDPObject)
1906     {
1907         // notify API objects
1908         pDoc->BroadcastUno( ScDataPilotModifiedHint( pNewDPObject->GetName() ) );
1909     }
1910 
1911 	EndUndo();
1912 }
1913 
Redo()1914 void __EXPORT ScUndoDataPilot::Redo()
1915 {
1916 	BeginRedo();
1917 
1918 	//!	copy output data instead of repeating the change,
1919 	//!	in case external data have changed!
1920 
1921 	ScDocument* pDoc = pDocShell->GetDocument();
1922 
1923 	ScDPObject* pSourceObj = NULL;
1924 	if ( pOldDPObject )
1925 	{
1926 		//	find object to modify
1927 		//!	find by name!
1928 
1929 		ScRange aOldRange = pOldDPObject->GetOutRange();
1930 		pSourceObj = pDoc->GetDPAtCursor(
1931 						aOldRange.aStart.Col(), aOldRange.aStart.Row(), aOldRange.aStart.Tab() );
1932 		DBG_ASSERT(pSourceObj, "DPObject not found");
1933 	}
1934 
1935 	ScDBDocFunc aFunc( *pDocShell );
1936 	aFunc.DataPilotUpdate( pSourceObj, pNewDPObject, sal_False, sal_False, bAllowMove );	// no new undo action
1937 
1938 	EndRedo();
1939 }
1940 
Repeat(SfxRepeatTarget &)1941 void __EXPORT ScUndoDataPilot::Repeat(SfxRepeatTarget& /* rTarget */)
1942 {
1943 	//!	allow deletion
1944 }
1945 
CanRepeat(SfxRepeatTarget &) const1946 sal_Bool __EXPORT ScUndoDataPilot::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1947 {
1948 	//!	allow deletion
1949 	return sal_False;
1950 }
1951 
1952 
1953 //
1954 //		Konsolidieren
1955 //
1956 
ScUndoConsolidate(ScDocShell * pNewDocShell,const ScArea & rArea,const ScConsolidateParam & rPar,ScDocument * pNewUndoDoc,sal_Bool bReference,SCROW nInsCount,ScOutlineTable * pTab,ScDBData * pData)1957 ScUndoConsolidate::ScUndoConsolidate( ScDocShell* pNewDocShell, const ScArea& rArea,
1958 					const ScConsolidateParam& rPar, ScDocument* pNewUndoDoc,
1959 					sal_Bool bReference, SCROW nInsCount, ScOutlineTable* pTab,
1960 					ScDBData* pData ) :
1961 	ScSimpleUndo( pNewDocShell ),
1962 	aDestArea( rArea ),
1963 	pUndoDoc( pNewUndoDoc ),
1964 	aParam( rPar ),
1965 	bInsRef( bReference ),
1966 	nInsertCount( nInsCount ),
1967 	pUndoTab( pTab ),
1968 	pUndoData( pData )
1969 {
1970 }
1971 
~ScUndoConsolidate()1972 __EXPORT ScUndoConsolidate::~ScUndoConsolidate()
1973 {
1974 	delete pUndoDoc;
1975 	delete pUndoTab;
1976 	delete pUndoData;
1977 }
1978 
GetComment() const1979 String __EXPORT ScUndoConsolidate::GetComment() const
1980 {
1981 	return ScGlobal::GetRscString( STR_UNDO_CONSOLIDATE );
1982 }
1983 
Undo()1984 void __EXPORT ScUndoConsolidate::Undo()
1985 {
1986 	BeginUndo();
1987 
1988 	ScDocument* pDoc = pDocShell->GetDocument();
1989 	SCTAB nTab = aDestArea.nTab;
1990 
1991 	ScRange aOldRange;
1992 	if (pUndoData)
1993 		pUndoData->GetArea(aOldRange);
1994 
1995 	if (bInsRef)
1996 	{
1997 		//	Zeilen loeschen
1998 		pDoc->DeleteRow( 0,nTab, MAXCOL,nTab, aDestArea.nRowStart, nInsertCount );
1999 
2000 		//	Outlines
2001 		pDoc->SetOutlineTable( nTab, pUndoTab );
2002 
2003 		//	Zeilenstatus
2004 		pUndoDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, IDF_NONE, sal_False, pDoc );
2005 
2006 		//	Daten & Referenzen
2007 		pDoc->DeleteAreaTab( 0,aDestArea.nRowStart, MAXCOL,aDestArea.nRowEnd, nTab, IDF_ALL );
2008 		pUndoDoc->UndoToDocument( 0, aDestArea.nRowStart, nTab,
2009 									MAXCOL, aDestArea.nRowEnd, nTab,
2010 									IDF_ALL, sal_False, pDoc );
2011 
2012 		//	Original-Bereich
2013 		if (pUndoData)
2014 		{
2015 			pDoc->DeleteAreaTab(aOldRange, IDF_ALL);
2016 			pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, sal_False, pDoc);
2017 		}
2018 
2019 		pDocShell->PostPaint( 0,aDestArea.nRowStart,nTab, MAXCOL,MAXROW,nTab,
2020 								PAINT_GRID | PAINT_LEFT | PAINT_SIZE );
2021 	}
2022 	else
2023 	{
2024 		pDoc->DeleteAreaTab( aDestArea.nColStart,aDestArea.nRowStart,
2025 								aDestArea.nColEnd,aDestArea.nRowEnd, nTab, IDF_ALL );
2026 		pUndoDoc->CopyToDocument( aDestArea.nColStart, aDestArea.nRowStart, nTab,
2027 									aDestArea.nColEnd, aDestArea.nRowEnd, nTab,
2028 									IDF_ALL, sal_False, pDoc );
2029 
2030 		//	Original-Bereich
2031 		if (pUndoData)
2032 		{
2033 			pDoc->DeleteAreaTab(aOldRange, IDF_ALL);
2034 			pUndoDoc->CopyToDocument(aOldRange, IDF_ALL, sal_False, pDoc);
2035 		}
2036 
2037 		SCCOL nEndX = aDestArea.nColEnd;
2038 		SCROW nEndY = aDestArea.nRowEnd;
2039 		if ( pUndoData )
2040 		{
2041 			if ( aOldRange.aEnd.Col() > nEndX )
2042 				nEndX = aOldRange.aEnd.Col();
2043 			if ( aOldRange.aEnd.Row() > nEndY )
2044 				nEndY = aOldRange.aEnd.Row();
2045 		}
2046 		pDocShell->PostPaint( aDestArea.nColStart, aDestArea.nRowStart, nTab,
2047 									nEndX, nEndY, nTab, PAINT_GRID );
2048 	}
2049 
2050 	//	DB-Bereich wieder anpassen
2051 	if (pUndoData)
2052 	{
2053 		ScDBCollection*	pColl = pDoc->GetDBCollection();
2054 		if (pColl)
2055 		{
2056 			sal_uInt16 nIndex;
2057 			if (pColl->SearchName( pUndoData->GetName(), nIndex ))
2058 			{
2059 				ScDBData* pDocData = (*pColl)[nIndex];
2060 				if (pDocData)
2061 					*pDocData = *pUndoData;
2062 			}
2063 			else
2064 			{
2065 				DBG_ERROR("alte DB-Daten nicht gefunden");
2066 			}
2067 		}
2068 	}
2069 
2070 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
2071 	if (pViewShell)
2072 	{
2073 		SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
2074 		if ( nViewTab != nTab )
2075 			pViewShell->SetTabNo( nTab );
2076 	}
2077 
2078 	EndUndo();
2079 }
2080 
Redo()2081 void __EXPORT ScUndoConsolidate::Redo()
2082 {
2083 	BeginRedo();
2084 
2085 	pDocShell->DoConsolidate( aParam, sal_False );
2086 
2087 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
2088 	if (pViewShell)
2089 	{
2090 		SCTAB nViewTab = pViewShell->GetViewData()->GetTabNo();
2091 		if ( nViewTab != aParam.nTab )
2092 			pViewShell->SetTabNo( aParam.nTab );
2093 	}
2094 
2095 	EndRedo();
2096 }
2097 
Repeat(SfxRepeatTarget &)2098 void __EXPORT ScUndoConsolidate::Repeat(SfxRepeatTarget& /* rTarget */)
2099 {
2100 }
2101 
CanRepeat(SfxRepeatTarget &) const2102 sal_Bool __EXPORT ScUndoConsolidate::CanRepeat(SfxRepeatTarget& /* rTarget */) const
2103 {
2104 	return sal_False;
2105 }
2106 
2107 
2108 //
2109 //		Quell-Daten von Chart aendern
2110 //
2111 
Init()2112 void ScUndoChartData::Init()
2113 {
2114 	ScDocument* pDoc = pDocShell->GetDocument();
2115     aOldRangeListRef = new ScRangeList;
2116     pDoc->GetOldChartParameters( aChartName, *aOldRangeListRef, bOldColHeaders, bOldRowHeaders );
2117 }
2118 
ScUndoChartData(ScDocShell * pNewDocShell,const String & rName,const ScRange & rNew,sal_Bool bColHdr,sal_Bool bRowHdr,sal_Bool bAdd)2119 ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const String& rName,
2120 									const ScRange& rNew, sal_Bool bColHdr, sal_Bool bRowHdr,
2121 									sal_Bool bAdd ) :
2122 	ScSimpleUndo( pNewDocShell ),
2123 	aChartName( rName ),
2124 	bNewColHeaders( bColHdr ),
2125 	bNewRowHeaders( bRowHdr ),
2126 	bAddRange( bAdd )
2127 {
2128 	aNewRangeListRef = new ScRangeList;
2129 	aNewRangeListRef->Append( rNew );
2130 
2131 	Init();
2132 }
2133 
ScUndoChartData(ScDocShell * pNewDocShell,const String & rName,const ScRangeListRef & rNew,sal_Bool bColHdr,sal_Bool bRowHdr,sal_Bool bAdd)2134 ScUndoChartData::ScUndoChartData( ScDocShell* pNewDocShell, const String& rName,
2135 									const ScRangeListRef& rNew, sal_Bool bColHdr, sal_Bool bRowHdr,
2136 									sal_Bool bAdd ) :
2137 	ScSimpleUndo( pNewDocShell ),
2138 	aChartName( rName ),
2139 	aNewRangeListRef( rNew ),
2140 	bNewColHeaders( bColHdr ),
2141 	bNewRowHeaders( bRowHdr ),
2142 	bAddRange( bAdd )
2143 {
2144 	Init();
2145 }
2146 
~ScUndoChartData()2147 __EXPORT ScUndoChartData::~ScUndoChartData()
2148 {
2149 }
2150 
GetComment() const2151 String __EXPORT ScUndoChartData::GetComment() const
2152 {
2153 	return ScGlobal::GetRscString( STR_UNDO_CHARTDATA );
2154 }
2155 
Undo()2156 void __EXPORT ScUndoChartData::Undo()
2157 {
2158 	BeginUndo();
2159 
2160 	pDocShell->GetDocument()->UpdateChartArea( aChartName, aOldRangeListRef,
2161 								bOldColHeaders, bOldRowHeaders, sal_False );
2162 
2163 	EndUndo();
2164 }
2165 
Redo()2166 void __EXPORT ScUndoChartData::Redo()
2167 {
2168 	BeginRedo();
2169 
2170 	pDocShell->GetDocument()->UpdateChartArea( aChartName, aNewRangeListRef,
2171 								bNewColHeaders, bNewRowHeaders, bAddRange );
2172 
2173 	EndRedo();
2174 }
2175 
Repeat(SfxRepeatTarget &)2176 void __EXPORT ScUndoChartData::Repeat(SfxRepeatTarget& /* rTarget */)
2177 {
2178 }
2179 
CanRepeat(SfxRepeatTarget &) const2180 sal_Bool __EXPORT ScUndoChartData::CanRepeat(SfxRepeatTarget& /* rTarget */) const
2181 {
2182 	return sal_False;
2183 }
2184 
2185 
2186 
2187 
2188 
2189 
2190