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