xref: /aoo42x/main/sc/source/ui/undo/undobase.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <vcl/virdev.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "undobase.hxx"
34cdf0e10cSrcweir #include "refundo.hxx"
35cdf0e10cSrcweir #include "docsh.hxx"
36cdf0e10cSrcweir #include "tabvwsh.hxx"
37cdf0e10cSrcweir #include "undoolk.hxx"
38cdf0e10cSrcweir #include "undodraw.hxx"
39cdf0e10cSrcweir #include "dbcolect.hxx"
40cdf0e10cSrcweir #include "attrib.hxx"
41cdf0e10cSrcweir #include "queryparam.hxx"
42cdf0e10cSrcweir #include "globstr.hrc"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
45cdf0e10cSrcweir 
46cdf0e10cSrcweir TYPEINIT1(ScSimpleUndo,		SfxUndoAction);
47cdf0e10cSrcweir TYPEINIT1(ScBlockUndo,      ScSimpleUndo);
48cdf0e10cSrcweir TYPEINIT1(ScMoveUndo,       ScSimpleUndo);
49cdf0e10cSrcweir TYPEINIT1(ScDBFuncUndo,     ScSimpleUndo);
50cdf0e10cSrcweir TYPEINIT1(ScUndoWrapper,    SfxUndoAction);
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // -----------------------------------------------------------------------
53cdf0e10cSrcweir 
54cdf0e10cSrcweir ScSimpleUndo::ScSimpleUndo( ScDocShell* pDocSh ) :
55cdf0e10cSrcweir 	pDocShell( pDocSh ),
56cdf0e10cSrcweir 	pDetectiveUndo( NULL )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir __EXPORT ScSimpleUndo::~ScSimpleUndo()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	delete pDetectiveUndo;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir bool ScSimpleUndo::SetViewMarkData( const ScMarkData& rMarkData )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     if ( IsPaintLocked() )
68cdf0e10cSrcweir         return false;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
71cdf0e10cSrcweir     if ( !pViewShell )
72cdf0e10cSrcweir         return false;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     pViewShell->SetMarkData( rMarkData );
75cdf0e10cSrcweir     return true;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir sal_Bool __EXPORT ScSimpleUndo::Merge( SfxUndoAction *pNextAction )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	//	Zu jeder Undo-Action kann eine SdrUndoGroup fuer das Aktualisieren
81cdf0e10cSrcweir 	//	der Detektiv-Pfeile gehoeren.
82cdf0e10cSrcweir 	//	DetectiveRefresh kommt immer hinterher, die SdrUndoGroup ist in
83cdf0e10cSrcweir 	//	eine ScUndoDraw Action verpackt.
84cdf0e10cSrcweir 	//	Nur beim automatischen Aktualisieren wird AddUndoAction mit
85cdf0e10cSrcweir 	//	bTryMerg=sal_True gerufen.
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	if ( !pDetectiveUndo && pNextAction->ISA(ScUndoDraw) )
88cdf0e10cSrcweir 	{
89cdf0e10cSrcweir 		//	SdrUndoAction aus der ScUndoDraw Action uebernehmen,
90cdf0e10cSrcweir 		//	ScUndoDraw wird dann vom UndoManager geloescht
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 		ScUndoDraw* pCalcUndo = (ScUndoDraw*)pNextAction;
93cdf0e10cSrcweir 		pDetectiveUndo = pCalcUndo->GetDrawUndo();
94cdf0e10cSrcweir 		pCalcUndo->ForgetDrawUndo();
95cdf0e10cSrcweir 		return sal_True;
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	return sal_False;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir void ScSimpleUndo::BeginUndo()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	pDocShell->SetInUndo( sal_True );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
106cdf0e10cSrcweir 	if (pViewShell)
107cdf0e10cSrcweir 		pViewShell->HideAllCursors();		// z.B. wegen zusammengefassten Zellen
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	//	detective updates happened last, must be undone first
110cdf0e10cSrcweir 	if (pDetectiveUndo)
111cdf0e10cSrcweir 		pDetectiveUndo->Undo();
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir void ScSimpleUndo::EndUndo()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	pDocShell->SetDocumentModified();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
119cdf0e10cSrcweir 	if (pViewShell)
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		pViewShell->UpdateAutoFillMark();
122cdf0e10cSrcweir 		pViewShell->UpdateInputHandler();
123cdf0e10cSrcweir 		pViewShell->ShowAllCursors();
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	pDocShell->SetInUndo( sal_False );
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir void ScSimpleUndo::BeginRedo()
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	pDocShell->SetInUndo( sal_True );	//! eigenes Flag fuer Redo?
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
134cdf0e10cSrcweir 	if (pViewShell)
135cdf0e10cSrcweir 		pViewShell->HideAllCursors();		// z.B. wegen zusammengefassten Zellen
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir void ScSimpleUndo::EndRedo()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	if (pDetectiveUndo)
141cdf0e10cSrcweir 		pDetectiveUndo->Redo();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	pDocShell->SetDocumentModified();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
146cdf0e10cSrcweir 	if (pViewShell)
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir 		pViewShell->UpdateAutoFillMark();
149cdf0e10cSrcweir 		pViewShell->UpdateInputHandler();
150cdf0e10cSrcweir 		pViewShell->ShowAllCursors();
151cdf0e10cSrcweir 	}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	pDocShell->SetInUndo( sal_False );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir void ScSimpleUndo::ShowTable( SCTAB nTab )			// static
157cdf0e10cSrcweir {
158cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
159cdf0e10cSrcweir 	if (pViewShell)
160cdf0e10cSrcweir 		pViewShell->SetTabNo( nTab );
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir void ScSimpleUndo::ShowTable( const ScRange& rRange )			// static
164cdf0e10cSrcweir {
165cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
166cdf0e10cSrcweir 	if (pViewShell)
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir 		SCTAB nStart = rRange.aStart.Tab();
169cdf0e10cSrcweir 		SCTAB nEnd   = rRange.aEnd.Tab();
170cdf0e10cSrcweir 		SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
171cdf0e10cSrcweir 		if ( nTab < nStart || nTab > nEnd )						// wenn nicht im Bereich:
172cdf0e10cSrcweir 			pViewShell->SetTabNo( nStart );						// auf erste des Bereiches
173cdf0e10cSrcweir 	}
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // -----------------------------------------------------------------------
178cdf0e10cSrcweir 
179cdf0e10cSrcweir ScBlockUndo::ScBlockUndo( ScDocShell* pDocSh, const ScRange& rRange,
180cdf0e10cSrcweir 											ScBlockUndoMode eBlockMode ) :
181cdf0e10cSrcweir 	ScSimpleUndo( pDocSh ),
182cdf0e10cSrcweir 	aBlockRange( rRange ),
183cdf0e10cSrcweir 	eMode( eBlockMode )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir __EXPORT ScBlockUndo::~ScBlockUndo()
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	DeleteSdrUndoAction( pDrawUndo );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir void ScBlockUndo::BeginUndo()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	ScSimpleUndo::BeginUndo();
196cdf0e10cSrcweir 	EnableDrawAdjust( pDocShell->GetDocument(), sal_False );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir void ScBlockUndo::EndUndo()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	if (eMode == SC_UNDO_AUTOHEIGHT)
202cdf0e10cSrcweir 		AdjustHeight();
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	EnableDrawAdjust( pDocShell->GetDocument(), sal_True );
205cdf0e10cSrcweir     DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	ShowBlock();
208cdf0e10cSrcweir 	ScSimpleUndo::EndUndo();
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir /*
212cdf0e10cSrcweir void ScBlockUndo::BeginRedo()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	ScSimpleUndo::BeginRedo();
215cdf0e10cSrcweir }
216cdf0e10cSrcweir */
217cdf0e10cSrcweir 
218cdf0e10cSrcweir void ScBlockUndo::EndRedo()
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	if (eMode == SC_UNDO_AUTOHEIGHT)
221cdf0e10cSrcweir 		AdjustHeight();
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	ShowBlock();
224cdf0e10cSrcweir 	ScSimpleUndo::EndRedo();
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir sal_Bool ScBlockUndo::AdjustHeight()
228cdf0e10cSrcweir {
229cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	VirtualDevice aVirtDev;
232cdf0e10cSrcweir 	Fraction aZoomX( 1, 1 );
233cdf0e10cSrcweir 	Fraction aZoomY = aZoomX;
234cdf0e10cSrcweir 	double nPPTX, nPPTY;
235cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
236cdf0e10cSrcweir 	if (pViewShell)
237cdf0e10cSrcweir 	{
238cdf0e10cSrcweir 		ScViewData* pData = pViewShell->GetViewData();
239cdf0e10cSrcweir 		nPPTX = pData->GetPPTX();
240cdf0e10cSrcweir 		nPPTY = pData->GetPPTY();
241cdf0e10cSrcweir 		aZoomX = pData->GetZoomX();
242cdf0e10cSrcweir 		aZoomY = pData->GetZoomY();
243cdf0e10cSrcweir 	}
244cdf0e10cSrcweir 	else
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		//	Zoom auf 100 lassen
247cdf0e10cSrcweir 		nPPTX = ScGlobal::nScreenPPTX;
248cdf0e10cSrcweir 		nPPTY = ScGlobal::nScreenPPTY;
249cdf0e10cSrcweir 	}
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	sal_Bool bRet = pDoc->SetOptimalHeight( aBlockRange.aStart.Row(), aBlockRange.aEnd.Row(),
252cdf0e10cSrcweir /*!*/									aBlockRange.aStart.Tab(), 0, &aVirtDev,
253cdf0e10cSrcweir 										nPPTX, nPPTY, aZoomX, aZoomY, sal_False );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	if (bRet)
256cdf0e10cSrcweir 		pDocShell->PostPaint( 0,      aBlockRange.aStart.Row(), aBlockRange.aStart.Tab(),
257cdf0e10cSrcweir 							  MAXCOL, MAXROW,                   aBlockRange.aEnd.Tab(),
258cdf0e10cSrcweir 							  PAINT_GRID | PAINT_LEFT );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	return bRet;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir void ScBlockUndo::ShowBlock()
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     if ( IsPaintLocked() )
266cdf0e10cSrcweir         return;
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
269cdf0e10cSrcweir 	if (pViewShell)
270cdf0e10cSrcweir 	{
271cdf0e10cSrcweir 		ShowTable( aBlockRange );		// bei mehreren Tabs im Range ist jede davon gut
272cdf0e10cSrcweir 		pViewShell->MoveCursorAbs( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
273cdf0e10cSrcweir 								   SC_FOLLOW_JUMP, sal_False, sal_False );
274cdf0e10cSrcweir 		SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
275cdf0e10cSrcweir 		ScRange aRange = aBlockRange;
276cdf0e10cSrcweir 		aRange.aStart.SetTab( nTab );
277cdf0e10cSrcweir 		aRange.aEnd.SetTab( nTab );
278cdf0e10cSrcweir 		pViewShell->MarkRange( aRange );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 		//	nicht per SetMarkArea an MarkData, wegen evtl. fehlendem Paint
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 
285cdf0e10cSrcweir // -----------------------------------------------------------------------
286cdf0e10cSrcweir 
287cdf0e10cSrcweir ScMoveUndo::ScMoveUndo( ScDocShell* pDocSh, ScDocument* pRefDoc, ScRefUndoData* pRefData,
288cdf0e10cSrcweir 												ScMoveUndoMode eRefMode ) :
289cdf0e10cSrcweir 	ScSimpleUndo( pDocSh ),
290cdf0e10cSrcweir 	pRefUndoDoc( pRefDoc ),
291cdf0e10cSrcweir 	pRefUndoData( pRefData ),
292cdf0e10cSrcweir 	eMode( eRefMode )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
295cdf0e10cSrcweir 	if (pRefUndoData)
296cdf0e10cSrcweir 		pRefUndoData->DeleteUnchanged(pDoc);
297cdf0e10cSrcweir 	pDrawUndo = GetSdrUndoAction( pDoc );
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir __EXPORT ScMoveUndo::~ScMoveUndo()
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 	delete pRefUndoData;
303cdf0e10cSrcweir 	delete pRefUndoDoc;
304cdf0e10cSrcweir 	DeleteSdrUndoAction( pDrawUndo );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir void ScMoveUndo::UndoRef()
308cdf0e10cSrcweir {
309cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
310cdf0e10cSrcweir 	ScRange aRange(0,0,0, MAXCOL,MAXROW,pRefUndoDoc->GetTableCount()-1);
311cdf0e10cSrcweir 	pRefUndoDoc->CopyToDocument( aRange, IDF_FORMULA, sal_False, pDoc, NULL, sal_False );
312cdf0e10cSrcweir 	if (pRefUndoData)
313cdf0e10cSrcweir 		pRefUndoData->DoUndo( pDoc, (eMode == SC_UNDO_REFFIRST) );
314cdf0e10cSrcweir 		// #65055# HACK: ScDragDropUndo ist der einzige mit REFFIRST.
315cdf0e10cSrcweir 		// Falls nicht, resultiert daraus evtl. ein zu haeufiges Anpassen
316cdf0e10cSrcweir 		// der ChartRefs, nicht schoen, aber auch nicht schlecht..
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir void ScMoveUndo::BeginUndo()
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	ScSimpleUndo::BeginUndo();
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 	EnableDrawAdjust( pDocShell->GetDocument(), sal_False );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	if (pRefUndoDoc && eMode == SC_UNDO_REFFIRST)
326cdf0e10cSrcweir 		UndoRef();
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir void ScMoveUndo::EndUndo()
330cdf0e10cSrcweir {
331cdf0e10cSrcweir     //@17.12.97 Reihenfolge der Fkt.s geaendert
332cdf0e10cSrcweir     DoSdrUndoAction( pDrawUndo, pDocShell->GetDocument() );     // #125875# must also be called when pointer is null
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 	if (pRefUndoDoc && eMode == SC_UNDO_REFLAST)
335cdf0e10cSrcweir 		UndoRef();
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	EnableDrawAdjust( pDocShell->GetDocument(), sal_True );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 	ScSimpleUndo::EndUndo();
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir /*
343cdf0e10cSrcweir void ScMoveUndo::BeginRedo()
344cdf0e10cSrcweir {
345cdf0e10cSrcweir 	ScSimpleUndo::BeginRedo();
346cdf0e10cSrcweir }
347cdf0e10cSrcweir */
348cdf0e10cSrcweir 
349cdf0e10cSrcweir /*
350cdf0e10cSrcweir void ScMoveUndo::EndRedo()
351cdf0e10cSrcweir {
352cdf0e10cSrcweir 	ScSimpleUndo::EndRedo();
353cdf0e10cSrcweir }
354cdf0e10cSrcweir */
355cdf0e10cSrcweir 
356cdf0e10cSrcweir // -----------------------------------------------------------------------
357cdf0e10cSrcweir 
358cdf0e10cSrcweir ScDBFuncUndo::ScDBFuncUndo( ScDocShell* pDocSh, const ScRange& rOriginal, SdrUndoAction* pDrawUndo ) :
359cdf0e10cSrcweir     ScSimpleUndo( pDocSh ),
360cdf0e10cSrcweir     aOriginalRange( rOriginal ),
361cdf0e10cSrcweir     mpDrawUndo( pDrawUndo )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     pAutoDBRange = pDocSh->GetOldAutoDBRange();
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir ScDBFuncUndo::~ScDBFuncUndo()
367cdf0e10cSrcweir {
368cdf0e10cSrcweir     DeleteSdrUndoAction( mpDrawUndo );
369cdf0e10cSrcweir     delete pAutoDBRange;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir void ScDBFuncUndo::SetDrawUndoAction( SdrUndoAction* pDrawUndo )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir     DeleteSdrUndoAction( mpDrawUndo );
375cdf0e10cSrcweir     mpDrawUndo = pDrawUndo;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir void ScDBFuncUndo::BeginUndo()
379cdf0e10cSrcweir {
380cdf0e10cSrcweir     ScSimpleUndo::BeginUndo();
381cdf0e10cSrcweir     DoSdrUndoAction( mpDrawUndo, pDocShell->GetDocument() );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir void ScDBFuncUndo::EndUndo()
385cdf0e10cSrcweir {
386cdf0e10cSrcweir     ScSimpleUndo::EndUndo();
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     if ( pAutoDBRange )
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         sal_uInt16 nNoNameIndex;
391cdf0e10cSrcweir         ScDocument* pDoc = pDocShell->GetDocument();
392cdf0e10cSrcweir         ScDBCollection* pColl = pDoc->GetDBCollection();
393cdf0e10cSrcweir         if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
394cdf0e10cSrcweir         {
395cdf0e10cSrcweir             ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
396cdf0e10cSrcweir 
397cdf0e10cSrcweir             SCCOL nRangeX1;
398cdf0e10cSrcweir             SCROW nRangeY1;
399cdf0e10cSrcweir             SCCOL nRangeX2;
400cdf0e10cSrcweir             SCROW nRangeY2;
401cdf0e10cSrcweir             SCTAB nRangeTab;
402cdf0e10cSrcweir             pNoNameData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
403cdf0e10cSrcweir             pDocShell->DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir             *pNoNameData = *pAutoDBRange;
406cdf0e10cSrcweir 
407cdf0e10cSrcweir             if ( pAutoDBRange->HasAutoFilter() )
408cdf0e10cSrcweir             {
409cdf0e10cSrcweir                 // restore AutoFilter buttons
410cdf0e10cSrcweir                 pAutoDBRange->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
411cdf0e10cSrcweir                 pDoc->ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
412cdf0e10cSrcweir                 pDocShell->PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PAINT_GRID );
413cdf0e10cSrcweir             }
414cdf0e10cSrcweir         }
415cdf0e10cSrcweir     }
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir void ScDBFuncUndo::BeginRedo()
419cdf0e10cSrcweir {
420cdf0e10cSrcweir     RedoSdrUndoAction( mpDrawUndo );
421cdf0e10cSrcweir     if ( pAutoDBRange )
422cdf0e10cSrcweir     {
423cdf0e10cSrcweir         // move the database range to this function's position again (see ScDocShell::GetDBData)
424cdf0e10cSrcweir 
425cdf0e10cSrcweir         sal_uInt16 nNoNameIndex;
426cdf0e10cSrcweir         ScDocument* pDoc = pDocShell->GetDocument();
427cdf0e10cSrcweir         ScDBCollection* pColl = pDoc->GetDBCollection();
428cdf0e10cSrcweir         if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
431cdf0e10cSrcweir 
432cdf0e10cSrcweir             SCCOL nRangeX1;
433cdf0e10cSrcweir             SCROW nRangeY1;
434cdf0e10cSrcweir             SCCOL nRangeX2;
435cdf0e10cSrcweir             SCROW nRangeY2;
436cdf0e10cSrcweir             SCTAB nRangeTab;
437cdf0e10cSrcweir             pNoNameData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
438cdf0e10cSrcweir             pDocShell->DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
439cdf0e10cSrcweir 
440cdf0e10cSrcweir             pNoNameData->SetSortParam( ScSortParam() );
441cdf0e10cSrcweir             pNoNameData->SetQueryParam( ScQueryParam() );
442cdf0e10cSrcweir             pNoNameData->SetSubTotalParam( ScSubTotalParam() );
443cdf0e10cSrcweir 
444cdf0e10cSrcweir             pNoNameData->SetArea( aOriginalRange.aStart.Tab(),
445cdf0e10cSrcweir                                   aOriginalRange.aStart.Col(), aOriginalRange.aStart.Row(),
446cdf0e10cSrcweir                                   aOriginalRange.aEnd.Col(), aOriginalRange.aEnd.Row() );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir             pNoNameData->SetByRow( sal_True );
449cdf0e10cSrcweir             pNoNameData->SetAutoFilter( sal_False );
450cdf0e10cSrcweir             // header is always set with the operation in redo
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     ScSimpleUndo::BeginRedo();
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir void ScDBFuncUndo::EndRedo()
458cdf0e10cSrcweir {
459cdf0e10cSrcweir     ScSimpleUndo::EndRedo();
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir // -----------------------------------------------------------------------
463cdf0e10cSrcweir 
464cdf0e10cSrcweir ScUndoWrapper::ScUndoWrapper( SfxUndoAction* pUndo ) :
465cdf0e10cSrcweir     pWrappedUndo( pUndo )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir ScUndoWrapper::~ScUndoWrapper()
470cdf0e10cSrcweir {
471cdf0e10cSrcweir     delete pWrappedUndo;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir void ScUndoWrapper::ForgetWrappedUndo()
475cdf0e10cSrcweir {
476cdf0e10cSrcweir     pWrappedUndo = NULL;    // don't delete in dtor - pointer must be stored outside
477cdf0e10cSrcweir }
478cdf0e10cSrcweir 
479cdf0e10cSrcweir String ScUndoWrapper::GetComment() const
480cdf0e10cSrcweir {
481cdf0e10cSrcweir     if (pWrappedUndo)
482cdf0e10cSrcweir         return pWrappedUndo->GetComment();
483cdf0e10cSrcweir     else
484cdf0e10cSrcweir         return String();
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir String ScUndoWrapper::GetRepeatComment(SfxRepeatTarget& rTarget) const
488cdf0e10cSrcweir {
489cdf0e10cSrcweir     if (pWrappedUndo)
490cdf0e10cSrcweir         return pWrappedUndo->GetRepeatComment(rTarget);
491cdf0e10cSrcweir     else
492cdf0e10cSrcweir         return String();
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir sal_uInt16 ScUndoWrapper::GetId() const
496cdf0e10cSrcweir {
497cdf0e10cSrcweir     if (pWrappedUndo)
498cdf0e10cSrcweir         return pWrappedUndo->GetId();
499cdf0e10cSrcweir     else
500cdf0e10cSrcweir         return 0;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir sal_Bool ScUndoWrapper::IsLinked()
504cdf0e10cSrcweir {
505cdf0e10cSrcweir     if (pWrappedUndo)
506cdf0e10cSrcweir         return pWrappedUndo->IsLinked();
507cdf0e10cSrcweir     else
508cdf0e10cSrcweir         return sal_False;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir void ScUndoWrapper::SetLinked( sal_Bool bIsLinked )
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     if (pWrappedUndo)
514cdf0e10cSrcweir         pWrappedUndo->SetLinked(bIsLinked);
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir sal_Bool ScUndoWrapper::Merge( SfxUndoAction* pNextAction )
518cdf0e10cSrcweir {
519cdf0e10cSrcweir     if (pWrappedUndo)
520cdf0e10cSrcweir         return pWrappedUndo->Merge(pNextAction);
521cdf0e10cSrcweir     else
522cdf0e10cSrcweir         return sal_False;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir void ScUndoWrapper::Undo()
526cdf0e10cSrcweir {
527cdf0e10cSrcweir     if (pWrappedUndo)
528cdf0e10cSrcweir         pWrappedUndo->Undo();
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir void ScUndoWrapper::Redo()
532cdf0e10cSrcweir {
533cdf0e10cSrcweir     if (pWrappedUndo)
534cdf0e10cSrcweir         pWrappedUndo->Redo();
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir void ScUndoWrapper::Repeat(SfxRepeatTarget& rTarget)
538cdf0e10cSrcweir {
539cdf0e10cSrcweir     if (pWrappedUndo)
540cdf0e10cSrcweir         pWrappedUndo->Repeat(rTarget);
541cdf0e10cSrcweir }
542cdf0e10cSrcweir 
543cdf0e10cSrcweir sal_Bool ScUndoWrapper::CanRepeat(SfxRepeatTarget& rTarget) const
544cdf0e10cSrcweir {
545cdf0e10cSrcweir     if (pWrappedUndo)
546cdf0e10cSrcweir         return pWrappedUndo->CanRepeat(rTarget);
547cdf0e10cSrcweir     else
548cdf0e10cSrcweir         return sal_False;
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 
552