xref: /aoo41x/main/sc/source/ui/undo/undoblk3.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 // INCLUDE -------------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include <editeng/boxitem.hxx>
31cdf0e10cSrcweir #include <svl/srchitem.hxx>
32cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
33cdf0e10cSrcweir #include <sfx2/bindings.hxx>
34cdf0e10cSrcweir #include <vcl/virdev.hxx>
35cdf0e10cSrcweir #include <sfx2/app.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "undoblk.hxx"
38cdf0e10cSrcweir #include "sc.hrc"
39cdf0e10cSrcweir #include "globstr.hrc"
40cdf0e10cSrcweir #include "global.hxx"
41cdf0e10cSrcweir #include "rangenam.hxx"
42cdf0e10cSrcweir #include "arealink.hxx"
43cdf0e10cSrcweir #include "patattr.hxx"
44cdf0e10cSrcweir #include "target.hxx"
45cdf0e10cSrcweir #include "document.hxx"
46cdf0e10cSrcweir #include "docpool.hxx"
47cdf0e10cSrcweir #include "table.hxx"
48cdf0e10cSrcweir #include "docsh.hxx"
49cdf0e10cSrcweir #include "tabvwsh.hxx"
50cdf0e10cSrcweir #include "undoolk.hxx"
51cdf0e10cSrcweir #include "undoutil.hxx"
52cdf0e10cSrcweir #include "chgtrack.hxx"
53cdf0e10cSrcweir #include "dociter.hxx"
54cdf0e10cSrcweir #include "cell.hxx"
55cdf0e10cSrcweir #include "paramisc.hxx"
56cdf0e10cSrcweir #include "postit.hxx"
57cdf0e10cSrcweir #include "docuno.hxx"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // STATIC DATA ---------------------------------------------------------------
60cdf0e10cSrcweir 
61cdf0e10cSrcweir TYPEINIT1(ScUndoDeleteContents, 	SfxUndoAction);
62cdf0e10cSrcweir TYPEINIT1(ScUndoFillTable,		 	SfxUndoAction);
63cdf0e10cSrcweir TYPEINIT1(ScUndoSelectionAttr,		SfxUndoAction);
64cdf0e10cSrcweir TYPEINIT1(ScUndoAutoFill,			SfxUndoAction);
65cdf0e10cSrcweir TYPEINIT1(ScUndoMerge,				SfxUndoAction);
66cdf0e10cSrcweir TYPEINIT1(ScUndoAutoFormat, 		SfxUndoAction);
67cdf0e10cSrcweir TYPEINIT1(ScUndoReplace,			SfxUndoAction);
68cdf0e10cSrcweir TYPEINIT1(ScUndoTabOp,				SfxUndoAction);
69cdf0e10cSrcweir TYPEINIT1(ScUndoConversion,         SfxUndoAction);
70cdf0e10cSrcweir TYPEINIT1(ScUndoRefConversion,      SfxUndoAction);
71cdf0e10cSrcweir TYPEINIT1(ScUndoRefreshLink,		SfxUndoAction);
72cdf0e10cSrcweir TYPEINIT1(ScUndoInsertAreaLink,		SfxUndoAction);
73cdf0e10cSrcweir TYPEINIT1(ScUndoRemoveAreaLink,		SfxUndoAction);
74cdf0e10cSrcweir TYPEINIT1(ScUndoUpdateAreaLink,		SfxUndoAction);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // To Do:
78cdf0e10cSrcweir /*A*/	// SetOptimalHeight auf Dokument, wenn keine View
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir //============================================================================
82cdf0e10cSrcweir //	class ScUndoDeleteContents
83cdf0e10cSrcweir //
84cdf0e10cSrcweir //	Inhalte loeschen
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //----------------------------------------------------------------------------
87cdf0e10cSrcweir 
88cdf0e10cSrcweir ScUndoDeleteContents::ScUndoDeleteContents(
89cdf0e10cSrcweir 				ScDocShell* pNewDocShell,
90cdf0e10cSrcweir 				const ScMarkData& rMark, const ScRange& rRange,
91cdf0e10cSrcweir 				ScDocument* pNewUndoDoc, sal_Bool bNewMulti,
92cdf0e10cSrcweir 				sal_uInt16 nNewFlags, sal_Bool bObjects )
93cdf0e10cSrcweir 		//
94cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
95cdf0e10cSrcweir 		//
96cdf0e10cSrcweir 		aRange		( rRange ),
97cdf0e10cSrcweir 		aMarkData	( rMark ),
98cdf0e10cSrcweir 		pUndoDoc	( pNewUndoDoc ),
99cdf0e10cSrcweir 		pDrawUndo	( NULL ),
100cdf0e10cSrcweir 		nFlags		( nNewFlags ),
101cdf0e10cSrcweir 		bMulti		( bNewMulti )	// ueberliquid
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	if (bObjects)
104cdf0e10cSrcweir 		pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	if ( !(aMarkData.IsMarked() || aMarkData.IsMultiMarked()) )		// keine Zelle markiert:
107cdf0e10cSrcweir 		aMarkData.SetMarkArea( aRange );							// Zelle unter Cursor markieren
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	SetChangeTrack();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir //----------------------------------------------------------------------------
114cdf0e10cSrcweir 
115cdf0e10cSrcweir __EXPORT ScUndoDeleteContents::~ScUndoDeleteContents()
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	delete pUndoDoc;
118cdf0e10cSrcweir 	DeleteSdrUndoAction( pDrawUndo );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //----------------------------------------------------------------------------
123cdf0e10cSrcweir 
124cdf0e10cSrcweir String __EXPORT ScUndoDeleteContents::GetComment() const
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS );	 // "Loeschen"
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir void ScUndoDeleteContents::SetChangeTrack()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
133cdf0e10cSrcweir 	if ( pChangeTrack && (nFlags & IDF_CONTENTS) )
134cdf0e10cSrcweir 		pChangeTrack->AppendContentRange( aRange, pUndoDoc,
135cdf0e10cSrcweir 			nStartChangeAction, nEndChangeAction );
136cdf0e10cSrcweir 	else
137cdf0e10cSrcweir 		nStartChangeAction = nEndChangeAction = 0;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //----------------------------------------------------------------------------
142cdf0e10cSrcweir 
143cdf0e10cSrcweir void ScUndoDeleteContents::DoChange( const sal_Bool bUndo )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	SetViewMarkData( aMarkData );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	sal_uInt16 nExtFlags = 0;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	if (bUndo)	// nur Undo
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		sal_uInt16 nUndoFlags = IDF_NONE;		//	entweder alle oder keine Inhalte kopieren
154cdf0e10cSrcweir 		if (nFlags & IDF_CONTENTS)			//	(es sind nur die richtigen ins UndoDoc kopiert worden)
155cdf0e10cSrcweir 			nUndoFlags |= IDF_CONTENTS;
156cdf0e10cSrcweir 		if (nFlags & IDF_ATTRIB)
157cdf0e10cSrcweir 			nUndoFlags |= IDF_ATTRIB;
158cdf0e10cSrcweir 		if (nFlags & IDF_EDITATTR)			// Edit-Engine-Attribute
159cdf0e10cSrcweir 			nUndoFlags |= IDF_STRING;		// -> Zellen werden geaendert
160cdf0e10cSrcweir         // do not create clones of note captions, they will be restored via drawing undo
161cdf0e10cSrcweir         nUndoFlags |= IDF_NOCAPTIONS;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		ScRange aCopyRange = aRange;
164cdf0e10cSrcweir 		SCTAB nTabCount = pDoc->GetTableCount();
165cdf0e10cSrcweir 		aCopyRange.aStart.SetTab(0);
166cdf0e10cSrcweir 		aCopyRange.aEnd.SetTab(nTabCount-1);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		pUndoDoc->CopyToDocument( aCopyRange, nUndoFlags, bMulti, pDoc, &aMarkData );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         DoSdrUndoAction( pDrawUndo, pDoc );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 		ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
173cdf0e10cSrcweir 		if ( pChangeTrack )
174cdf0e10cSrcweir 			pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		pDocShell->UpdatePaintExt( nExtFlags, aRange );				// content after the change
177cdf0e10cSrcweir 	}
178cdf0e10cSrcweir 	else		// nur Redo
179cdf0e10cSrcweir 	{
180cdf0e10cSrcweir 		pDocShell->UpdatePaintExt( nExtFlags, aRange );				// content before the change
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		aMarkData.MarkToMulti();
183cdf0e10cSrcweir         RedoSdrUndoAction( pDrawUndo );
184cdf0e10cSrcweir         // do not delete objects and note captions, they have been removed via drawing undo
185cdf0e10cSrcweir         sal_uInt16 nRedoFlags = (nFlags & ~IDF_OBJECTS) | IDF_NOCAPTIONS;
186cdf0e10cSrcweir         pDoc->DeleteSelection( nRedoFlags, aMarkData );
187cdf0e10cSrcweir 		aMarkData.MarkToSimple();
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 		SetChangeTrack();
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
193cdf0e10cSrcweir 	if ( !( (pViewShell) && pViewShell->AdjustRowHeight(
194cdf0e10cSrcweir 								aRange.aStart.Row(), aRange.aEnd.Row() ) ) )
195cdf0e10cSrcweir /*A*/	pDocShell->PostPaint( aRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	pDocShell->PostDataChanged();
198cdf0e10cSrcweir 	if (pViewShell)
199cdf0e10cSrcweir 		pViewShell->CellContentChanged();
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	ShowTable( aRange );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
205cdf0e10cSrcweir //----------------------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir void __EXPORT ScUndoDeleteContents::Undo()
208cdf0e10cSrcweir {
209cdf0e10cSrcweir 	BeginUndo();
210cdf0e10cSrcweir 	DoChange( sal_True );
211cdf0e10cSrcweir 	EndUndo();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     // #i97876# Spreadsheet data changes are not notified
214cdf0e10cSrcweir     ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
215cdf0e10cSrcweir     if ( pModelObj && pModelObj->HasChangesListeners() )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         ScRangeList aChangeRanges;
218cdf0e10cSrcweir         aChangeRanges.Append( aRange );
219cdf0e10cSrcweir         pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges );
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
224cdf0e10cSrcweir //----------------------------------------------------------------------------
225cdf0e10cSrcweir 
226cdf0e10cSrcweir void __EXPORT ScUndoDeleteContents::Redo()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir 	BeginRedo();
229cdf0e10cSrcweir 	DoChange( sal_False );
230cdf0e10cSrcweir 	EndRedo();
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     // #i97876# Spreadsheet data changes are not notified
233cdf0e10cSrcweir     ScModelObj* pModelObj = ScModelObj::getImplementation( pDocShell->GetModel() );
234cdf0e10cSrcweir     if ( pModelObj && pModelObj->HasChangesListeners() )
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         ScRangeList aChangeRanges;
237cdf0e10cSrcweir         aChangeRanges.Append( aRange );
238cdf0e10cSrcweir         pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aChangeRanges );
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir //----------------------------------------------------------------------------
244cdf0e10cSrcweir 
245cdf0e10cSrcweir void __EXPORT ScUndoDeleteContents::Repeat(SfxRepeatTarget& rTarget)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
248cdf0e10cSrcweir 		((ScTabViewTarget&)rTarget).GetViewShell()->DeleteContents( nFlags, sal_True );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
252cdf0e10cSrcweir //----------------------------------------------------------------------------
253cdf0e10cSrcweir 
254cdf0e10cSrcweir sal_Bool __EXPORT ScUndoDeleteContents::CanRepeat(SfxRepeatTarget& rTarget) const
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
260cdf0e10cSrcweir //============================================================================
261cdf0e10cSrcweir //	class ScUndoFillTable
262cdf0e10cSrcweir //
263cdf0e10cSrcweir //	Tabellen ausfuellen
264cdf0e10cSrcweir //	(Bearbeiten|Ausfuellen|...)
265cdf0e10cSrcweir 
266cdf0e10cSrcweir //----------------------------------------------------------------------------
267cdf0e10cSrcweir 
268cdf0e10cSrcweir ScUndoFillTable::ScUndoFillTable( ScDocShell* pNewDocShell,
269cdf0e10cSrcweir 				const ScMarkData& rMark,
270cdf0e10cSrcweir 				SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
271cdf0e10cSrcweir 				SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
272cdf0e10cSrcweir 				ScDocument* pNewUndoDoc, sal_Bool bNewMulti, SCTAB nSrc,
273cdf0e10cSrcweir 				sal_uInt16 nFlg, sal_uInt16 nFunc, sal_Bool bSkip, sal_Bool bLink )
274cdf0e10cSrcweir 		//
275cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
276cdf0e10cSrcweir 		//
277cdf0e10cSrcweir 		aRange		( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
278cdf0e10cSrcweir 		aMarkData	( rMark ),
279cdf0e10cSrcweir 		pUndoDoc	( pNewUndoDoc ),
280cdf0e10cSrcweir 		nFlags		( nFlg ),
281cdf0e10cSrcweir 		nFunction	( nFunc ),
282cdf0e10cSrcweir 		nSrcTab		( nSrc ),
283cdf0e10cSrcweir 		bMulti		( bNewMulti ),
284cdf0e10cSrcweir 		bSkipEmpty	( bSkip ),
285cdf0e10cSrcweir 		bAsLink		( bLink )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	SetChangeTrack();
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir //----------------------------------------------------------------------------
292cdf0e10cSrcweir 
293cdf0e10cSrcweir __EXPORT ScUndoFillTable::~ScUndoFillTable()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir 	delete pUndoDoc;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 
299cdf0e10cSrcweir //----------------------------------------------------------------------------
300cdf0e10cSrcweir 
301cdf0e10cSrcweir String __EXPORT ScUndoFillTable::GetComment() const
302cdf0e10cSrcweir {
303cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_FILL_TAB );
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir void ScUndoFillTable::SetChangeTrack()
308cdf0e10cSrcweir {
309cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
310cdf0e10cSrcweir 	if ( pChangeTrack )
311cdf0e10cSrcweir 	{
312cdf0e10cSrcweir 		SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount();
313cdf0e10cSrcweir 		ScRange aWorkRange(aRange);
314cdf0e10cSrcweir 		nStartChangeAction = 0;
315cdf0e10cSrcweir 		sal_uLong nTmpAction;
316cdf0e10cSrcweir 		for ( SCTAB i = 0; i < nTabCount; i++ )
317cdf0e10cSrcweir 		{
318cdf0e10cSrcweir 			if (i != nSrcTab && aMarkData.GetTableSelect(i))
319cdf0e10cSrcweir 			{
320cdf0e10cSrcweir 				aWorkRange.aStart.SetTab(i);
321cdf0e10cSrcweir 				aWorkRange.aEnd.SetTab(i);
322cdf0e10cSrcweir 				pChangeTrack->AppendContentRange( aWorkRange, pUndoDoc,
323cdf0e10cSrcweir 					nTmpAction, nEndChangeAction );
324cdf0e10cSrcweir 				if ( !nStartChangeAction )
325cdf0e10cSrcweir 					nStartChangeAction = nTmpAction;
326cdf0e10cSrcweir 			}
327cdf0e10cSrcweir 		}
328cdf0e10cSrcweir 	}
329cdf0e10cSrcweir 	else
330cdf0e10cSrcweir 		nStartChangeAction = nEndChangeAction = 0;
331cdf0e10cSrcweir }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 
334cdf0e10cSrcweir //----------------------------------------------------------------------------
335cdf0e10cSrcweir 
336cdf0e10cSrcweir void ScUndoFillTable::DoChange( const sal_Bool bUndo )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 	SetViewMarkData( aMarkData );
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	if (bUndo)	// nur Undo
343cdf0e10cSrcweir 	{
344cdf0e10cSrcweir 		SCTAB nTabCount = pDoc->GetTableCount();
345cdf0e10cSrcweir 		ScRange aWorkRange(aRange);
346cdf0e10cSrcweir 		for ( SCTAB i = 0; i < nTabCount; i++ )
347cdf0e10cSrcweir 			if (i != nSrcTab && aMarkData.GetTableSelect(i))
348cdf0e10cSrcweir 			{
349cdf0e10cSrcweir 				aWorkRange.aStart.SetTab(i);
350cdf0e10cSrcweir 				aWorkRange.aEnd.SetTab(i);
351cdf0e10cSrcweir 				if (bMulti)
352cdf0e10cSrcweir 					pDoc->DeleteSelectionTab( i, IDF_ALL, aMarkData );
353cdf0e10cSrcweir 				else
354cdf0e10cSrcweir 					pDoc->DeleteAreaTab( aWorkRange, IDF_ALL );
355cdf0e10cSrcweir 				pUndoDoc->CopyToDocument( aWorkRange, IDF_ALL, bMulti, pDoc, &aMarkData );
356cdf0e10cSrcweir 			}
357cdf0e10cSrcweir 
358cdf0e10cSrcweir 		ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
359cdf0e10cSrcweir 		if ( pChangeTrack )
360cdf0e10cSrcweir 			pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
361cdf0e10cSrcweir 	}
362cdf0e10cSrcweir 	else		// nur Redo
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		aMarkData.MarkToMulti();
365cdf0e10cSrcweir 		pDoc->FillTabMarked( nSrcTab, aMarkData, nFlags, nFunction, bSkipEmpty, bAsLink );
366cdf0e10cSrcweir 		aMarkData.MarkToSimple();
367cdf0e10cSrcweir 		SetChangeTrack();
368cdf0e10cSrcweir 	}
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	pDocShell->PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_EXTRAS);
371cdf0e10cSrcweir 	pDocShell->PostDataChanged();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	//	CellContentChanged kommt mit der Markierung
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
376cdf0e10cSrcweir 	if (pViewShell)
377cdf0e10cSrcweir 	{
378cdf0e10cSrcweir 		SCTAB nTab = pViewShell->GetViewData()->GetTabNo();
379cdf0e10cSrcweir 		if ( !aMarkData.GetTableSelect(nTab) )
380cdf0e10cSrcweir 			pViewShell->SetTabNo( nSrcTab );
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 		pViewShell->DoneBlockMode();	// gibt sonst Probleme, weil Markierung auf falscher Tabelle
383cdf0e10cSrcweir 	}
384cdf0e10cSrcweir }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 
387cdf0e10cSrcweir //----------------------------------------------------------------------------
388cdf0e10cSrcweir 
389cdf0e10cSrcweir void __EXPORT ScUndoFillTable::Undo()
390cdf0e10cSrcweir {
391cdf0e10cSrcweir 	BeginUndo();
392cdf0e10cSrcweir 	DoChange( sal_True );
393cdf0e10cSrcweir 	EndUndo();
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 
397cdf0e10cSrcweir //----------------------------------------------------------------------------
398cdf0e10cSrcweir 
399cdf0e10cSrcweir void __EXPORT ScUndoFillTable::Redo()
400cdf0e10cSrcweir {
401cdf0e10cSrcweir 	BeginRedo();
402cdf0e10cSrcweir 	DoChange( sal_False );
403cdf0e10cSrcweir 	EndRedo();
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 
407cdf0e10cSrcweir //----------------------------------------------------------------------------
408cdf0e10cSrcweir 
409cdf0e10cSrcweir void __EXPORT ScUndoFillTable::Repeat(SfxRepeatTarget& rTarget)
410cdf0e10cSrcweir {
411cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
412cdf0e10cSrcweir 		((ScTabViewTarget&)rTarget).GetViewShell()->FillTab( nFlags, nFunction, bSkipEmpty, bAsLink );
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 
416cdf0e10cSrcweir //----------------------------------------------------------------------------
417cdf0e10cSrcweir 
418cdf0e10cSrcweir sal_Bool __EXPORT ScUndoFillTable::CanRepeat(SfxRepeatTarget& rTarget) const
419cdf0e10cSrcweir {
420cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 
424cdf0e10cSrcweir //============================================================================
425cdf0e10cSrcweir //	class ScUndoSelectionAttr
426cdf0e10cSrcweir //
427cdf0e10cSrcweir //	Zellformat aendern
428cdf0e10cSrcweir 
429cdf0e10cSrcweir //----------------------------------------------------------------------------
430cdf0e10cSrcweir 
431cdf0e10cSrcweir ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell,
432cdf0e10cSrcweir 				const ScMarkData& rMark,
433cdf0e10cSrcweir 				SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
434cdf0e10cSrcweir 				SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
435cdf0e10cSrcweir 				ScDocument* pNewUndoDoc, sal_Bool bNewMulti,
436cdf0e10cSrcweir 				const ScPatternAttr* pNewApply,
437cdf0e10cSrcweir 				const SvxBoxItem* pNewOuter, const SvxBoxInfoItem* pNewInner )
438cdf0e10cSrcweir 		//
439cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
440cdf0e10cSrcweir 		//
441cdf0e10cSrcweir 		aMarkData	( rMark ),
442cdf0e10cSrcweir 		aRange		( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
443cdf0e10cSrcweir 		pUndoDoc	( pNewUndoDoc ),
444cdf0e10cSrcweir 		bMulti		( bNewMulti )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir 	ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
447cdf0e10cSrcweir 	pApplyPattern = (ScPatternAttr*) &pPool->Put( *pNewApply );
448cdf0e10cSrcweir 	pLineOuter = pNewOuter ? (SvxBoxItem*) &pPool->Put( *pNewOuter ) : NULL;
449cdf0e10cSrcweir 	pLineInner = pNewInner ? (SvxBoxInfoItem*) &pPool->Put( *pNewInner ) : NULL;
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 
453cdf0e10cSrcweir //----------------------------------------------------------------------------
454cdf0e10cSrcweir 
455cdf0e10cSrcweir __EXPORT ScUndoSelectionAttr::~ScUndoSelectionAttr()
456cdf0e10cSrcweir {
457cdf0e10cSrcweir 	ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
458cdf0e10cSrcweir 	pPool->Remove(*pApplyPattern);
459cdf0e10cSrcweir 	if (pLineOuter)
460cdf0e10cSrcweir 		pPool->Remove(*pLineOuter);
461cdf0e10cSrcweir 	if (pLineInner)
462cdf0e10cSrcweir 		pPool->Remove(*pLineInner);
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	delete pUndoDoc;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 
468cdf0e10cSrcweir //----------------------------------------------------------------------------
469cdf0e10cSrcweir 
470cdf0e10cSrcweir String __EXPORT ScUndoSelectionAttr::GetComment() const
471cdf0e10cSrcweir {
472cdf0e10cSrcweir 	//"Attribute" "/Linien"
473cdf0e10cSrcweir 	return ScGlobal::GetRscString( pLineOuter ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR );
474cdf0e10cSrcweir }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 
477cdf0e10cSrcweir //----------------------------------------------------------------------------
478cdf0e10cSrcweir 
479cdf0e10cSrcweir void ScUndoSelectionAttr::DoChange( const sal_Bool bUndo )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	SetViewMarkData( aMarkData );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 	ScRange aEffRange( aRange );
486cdf0e10cSrcweir 	if ( pDoc->HasAttrib( aEffRange, HASATTR_MERGED ) )			// zusammengefasste Zellen?
487cdf0e10cSrcweir 		pDoc->ExtendMerge( aEffRange );
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 	sal_uInt16 nExtFlags = 0;
490cdf0e10cSrcweir 	pDocShell->UpdatePaintExt( nExtFlags, aEffRange );
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 	if (bUndo)	// nur bei Undo
493cdf0e10cSrcweir 	{
494cdf0e10cSrcweir 		ScRange aCopyRange = aRange;
495cdf0e10cSrcweir 		SCTAB nTabCount = pDoc->GetTableCount();
496cdf0e10cSrcweir 		aCopyRange.aStart.SetTab(0);
497cdf0e10cSrcweir 		aCopyRange.aEnd.SetTab(nTabCount-1);
498cdf0e10cSrcweir 		pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, bMulti, pDoc, &aMarkData );
499cdf0e10cSrcweir 	}
500cdf0e10cSrcweir 	else		// nur bei Redo
501cdf0e10cSrcweir 	{
502cdf0e10cSrcweir 		aMarkData.MarkToMulti();
503cdf0e10cSrcweir 		pDoc->ApplySelectionPattern( *pApplyPattern, aMarkData );
504cdf0e10cSrcweir 		aMarkData.MarkToSimple();
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 		if (pLineOuter)
507cdf0e10cSrcweir 			pDoc->ApplySelectionFrame( aMarkData, pLineOuter, pLineInner );
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
511cdf0e10cSrcweir 	if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
512cdf0e10cSrcweir /*A*/	pDocShell->PostPaint( aEffRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
513cdf0e10cSrcweir 
514cdf0e10cSrcweir 	ShowTable( aRange );
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 
518cdf0e10cSrcweir //----------------------------------------------------------------------------
519cdf0e10cSrcweir 
520cdf0e10cSrcweir void __EXPORT ScUndoSelectionAttr::Undo()
521cdf0e10cSrcweir {
522cdf0e10cSrcweir 	BeginUndo();
523cdf0e10cSrcweir 	DoChange( sal_True );
524cdf0e10cSrcweir 	EndUndo();
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 
528cdf0e10cSrcweir //----------------------------------------------------------------------------
529cdf0e10cSrcweir 
530cdf0e10cSrcweir void __EXPORT ScUndoSelectionAttr::Redo()
531cdf0e10cSrcweir {
532cdf0e10cSrcweir 	BeginRedo();
533cdf0e10cSrcweir 	DoChange( sal_False );
534cdf0e10cSrcweir 	EndRedo();
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 
538cdf0e10cSrcweir //----------------------------------------------------------------------------
539cdf0e10cSrcweir 
540cdf0e10cSrcweir void __EXPORT ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget)
541cdf0e10cSrcweir {
542cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
543cdf0e10cSrcweir 	{
544cdf0e10cSrcweir 		ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
545cdf0e10cSrcweir 		if (pLineOuter)
546cdf0e10cSrcweir 			rViewShell.ApplyPatternLines( *pApplyPattern, pLineOuter, pLineInner, sal_True );
547cdf0e10cSrcweir 		else
548cdf0e10cSrcweir 			rViewShell.ApplySelectionPattern( *pApplyPattern, sal_True );
549cdf0e10cSrcweir 	}
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 
553cdf0e10cSrcweir //----------------------------------------------------------------------------
554cdf0e10cSrcweir 
555cdf0e10cSrcweir sal_Bool __EXPORT ScUndoSelectionAttr::CanRepeat(SfxRepeatTarget& rTarget) const
556cdf0e10cSrcweir {
557cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561cdf0e10cSrcweir //============================================================================
562cdf0e10cSrcweir //	class ScUndoAutoFill
563cdf0e10cSrcweir //
564cdf0e10cSrcweir //	Auto-Fill (nur einfache Bloecke)
565cdf0e10cSrcweir 
566cdf0e10cSrcweir //----------------------------------------------------------------------------
567cdf0e10cSrcweir 
568cdf0e10cSrcweir ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
569cdf0e10cSrcweir 				const ScRange& rRange, const ScRange& rSourceArea,
570cdf0e10cSrcweir 				ScDocument* pNewUndoDoc, const ScMarkData& rMark,
571cdf0e10cSrcweir 				FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
572cdf0e10cSrcweir 				double fNewStartValue, double fNewStepValue, double fNewMaxValue,
573cdf0e10cSrcweir 				sal_uInt16 nMaxShIndex )
574cdf0e10cSrcweir 		//
575cdf0e10cSrcweir 	:	ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
576cdf0e10cSrcweir 		//
577cdf0e10cSrcweir 		aSource			( rSourceArea ),
578cdf0e10cSrcweir 		aMarkData		( rMark ),
579cdf0e10cSrcweir 		pUndoDoc		( pNewUndoDoc ),
580cdf0e10cSrcweir 		eFillDir		( eNewFillDir ),
581cdf0e10cSrcweir 		eFillCmd		( eNewFillCmd ),
582cdf0e10cSrcweir 		eFillDateCmd	( eNewFillDateCmd ),
583cdf0e10cSrcweir 		fStartValue		( fNewStartValue ),
584cdf0e10cSrcweir 		fStepValue		( fNewStepValue ),
585cdf0e10cSrcweir 		fMaxValue		( fNewMaxValue ),
586cdf0e10cSrcweir 		nMaxSharedIndex	( nMaxShIndex)
587cdf0e10cSrcweir {
588cdf0e10cSrcweir 	SetChangeTrack();
589cdf0e10cSrcweir }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 
592cdf0e10cSrcweir //----------------------------------------------------------------------------
593cdf0e10cSrcweir 
594cdf0e10cSrcweir __EXPORT ScUndoAutoFill::~ScUndoAutoFill()
595cdf0e10cSrcweir {
596cdf0e10cSrcweir 	pDocShell->GetDocument()->EraseNonUsedSharedNames(nMaxSharedIndex);
597cdf0e10cSrcweir 	delete pUndoDoc;
598cdf0e10cSrcweir }
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 
601cdf0e10cSrcweir //----------------------------------------------------------------------------
602cdf0e10cSrcweir 
603cdf0e10cSrcweir String __EXPORT ScUndoAutoFill::GetComment() const
604cdf0e10cSrcweir {
605cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_AUTOFILL ); //"Ausfuellen"
606cdf0e10cSrcweir }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 
609cdf0e10cSrcweir void ScUndoAutoFill::SetChangeTrack()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
612cdf0e10cSrcweir 	if ( pChangeTrack )
613cdf0e10cSrcweir 		pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
614cdf0e10cSrcweir 			nStartChangeAction, nEndChangeAction );
615cdf0e10cSrcweir 	else
616cdf0e10cSrcweir 		nStartChangeAction = nEndChangeAction = 0;
617cdf0e10cSrcweir }
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 
620cdf0e10cSrcweir //----------------------------------------------------------------------------
621cdf0e10cSrcweir 
622cdf0e10cSrcweir void __EXPORT ScUndoAutoFill::Undo()
623cdf0e10cSrcweir {
624cdf0e10cSrcweir 	BeginUndo();
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
629cdf0e10cSrcweir 	for (SCTAB nTab=0; nTab<nTabCount; nTab++)
630cdf0e10cSrcweir 	{
631cdf0e10cSrcweir 		if (aMarkData.GetTableSelect(nTab))
632cdf0e10cSrcweir 		{
633cdf0e10cSrcweir 			ScRange aWorkRange = aBlockRange;
634cdf0e10cSrcweir 			aWorkRange.aStart.SetTab(nTab);
635cdf0e10cSrcweir 			aWorkRange.aEnd.SetTab(nTab);
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 			sal_uInt16 nExtFlags = 0;
638cdf0e10cSrcweir 			pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
639cdf0e10cSrcweir             pDoc->DeleteAreaTab( aWorkRange, IDF_AUTOFILL );
640cdf0e10cSrcweir             pUndoDoc->CopyToDocument( aWorkRange, IDF_AUTOFILL, sal_False, pDoc );
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 			pDoc->ExtendMerge( aWorkRange, sal_True );
643cdf0e10cSrcweir 			pDocShell->PostPaint( aWorkRange, PAINT_GRID, nExtFlags );
644cdf0e10cSrcweir 		}
645cdf0e10cSrcweir 	}
646cdf0e10cSrcweir 	pDocShell->PostDataChanged();
647cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
648cdf0e10cSrcweir 	if (pViewShell)
649cdf0e10cSrcweir 		pViewShell->CellContentChanged();
650cdf0e10cSrcweir 
651cdf0e10cSrcweir // Shared-Names loeschen
652cdf0e10cSrcweir // Falls Undo ins Dokument gespeichert
653cdf0e10cSrcweir // => automatisches Loeschen am Ende
654cdf0e10cSrcweir // umarbeiten!!
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	String aName = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("___SC_"));
657cdf0e10cSrcweir 	aName += String::CreateFromInt32(nMaxSharedIndex);
658cdf0e10cSrcweir 	aName += '_';
659cdf0e10cSrcweir 	ScRangeName* pRangeName = pDoc->GetRangeName();
660cdf0e10cSrcweir 	sal_Bool bHasFound = sal_False;
661cdf0e10cSrcweir 	for (sal_uInt16 i = 0; i < pRangeName->GetCount(); i++)
662cdf0e10cSrcweir 	{
663cdf0e10cSrcweir 		ScRangeData* pRangeData = (*pRangeName)[i];
664cdf0e10cSrcweir 		if (pRangeData)
665cdf0e10cSrcweir 		{
666cdf0e10cSrcweir 			String aRName;
667cdf0e10cSrcweir 			pRangeData->GetName(aRName);
668cdf0e10cSrcweir 			if (aRName.Search(aName) != STRING_NOTFOUND)
669cdf0e10cSrcweir 			{
670cdf0e10cSrcweir 				pRangeName->AtFree(i);
671cdf0e10cSrcweir 				bHasFound = sal_True;
672cdf0e10cSrcweir 			}
673cdf0e10cSrcweir 		}
674cdf0e10cSrcweir 	}
675cdf0e10cSrcweir 	if (bHasFound)
676cdf0e10cSrcweir 		pRangeName->SetSharedMaxIndex(pRangeName->GetSharedMaxIndex()-1);
677cdf0e10cSrcweir 
678cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
679cdf0e10cSrcweir 	if ( pChangeTrack )
680cdf0e10cSrcweir 		pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
681cdf0e10cSrcweir 
682cdf0e10cSrcweir 	EndUndo();
683cdf0e10cSrcweir }
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 
686cdf0e10cSrcweir //----------------------------------------------------------------------------
687cdf0e10cSrcweir 
688cdf0e10cSrcweir void __EXPORT ScUndoAutoFill::Redo()
689cdf0e10cSrcweir {
690cdf0e10cSrcweir 	BeginRedo();
691cdf0e10cSrcweir 
692cdf0e10cSrcweir //!	Tabellen selektieren
693cdf0e10cSrcweir 
694cdf0e10cSrcweir     SCCOLROW nCount = 0;
695cdf0e10cSrcweir 	switch (eFillDir)
696cdf0e10cSrcweir 	{
697cdf0e10cSrcweir 		case FILL_TO_BOTTOM:
698cdf0e10cSrcweir 			nCount = aBlockRange.aEnd.Row() - aSource.aEnd.Row();
699cdf0e10cSrcweir 			break;
700cdf0e10cSrcweir 		case FILL_TO_RIGHT:
701cdf0e10cSrcweir 			nCount = aBlockRange.aEnd.Col() - aSource.aEnd.Col();
702cdf0e10cSrcweir 			break;
703cdf0e10cSrcweir 		case FILL_TO_TOP:
704cdf0e10cSrcweir 			nCount = aSource.aStart.Row() - aBlockRange.aStart.Row();
705cdf0e10cSrcweir 			break;
706cdf0e10cSrcweir 		case FILL_TO_LEFT:
707cdf0e10cSrcweir 			nCount = aSource.aStart.Col() - aBlockRange.aStart.Col();
708cdf0e10cSrcweir 			break;
709cdf0e10cSrcweir 	}
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
712cdf0e10cSrcweir 	if ( fStartValue != MAXDOUBLE )
713cdf0e10cSrcweir 	{
714cdf0e10cSrcweir 		SCCOL nValX = (eFillDir == FILL_TO_LEFT) ? aSource.aEnd.Col() : aSource.aStart.Col();
715cdf0e10cSrcweir 		SCROW nValY = (eFillDir == FILL_TO_TOP ) ? aSource.aEnd.Row() : aSource.aStart.Row();
716cdf0e10cSrcweir 		SCTAB nTab = aSource.aStart.Tab();
717cdf0e10cSrcweir 		pDoc->SetValue( nValX, nValY, nTab, fStartValue );
718cdf0e10cSrcweir 	}
719cdf0e10cSrcweir 	pDoc->Fill( aSource.aStart.Col(), aSource.aStart.Row(),
720cdf0e10cSrcweir 				aSource.aEnd.Col(),   aSource.aEnd.Row(),
721cdf0e10cSrcweir 				aMarkData, nCount,
722cdf0e10cSrcweir 				eFillDir, eFillCmd, eFillDateCmd,
723cdf0e10cSrcweir 				fStepValue, fMaxValue );
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 	SetChangeTrack();
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 	pDocShell->PostPaint( aBlockRange, PAINT_GRID );
728cdf0e10cSrcweir 	pDocShell->PostDataChanged();
729cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
730cdf0e10cSrcweir 	if (pViewShell)
731cdf0e10cSrcweir 		pViewShell->CellContentChanged();
732cdf0e10cSrcweir 
733cdf0e10cSrcweir 	EndRedo();
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 
737cdf0e10cSrcweir //----------------------------------------------------------------------------
738cdf0e10cSrcweir 
739cdf0e10cSrcweir void __EXPORT ScUndoAutoFill::Repeat(SfxRepeatTarget& rTarget)
740cdf0e10cSrcweir {
741cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
742cdf0e10cSrcweir 	{
743cdf0e10cSrcweir 		ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
744cdf0e10cSrcweir 		if (eFillCmd==FILL_SIMPLE)
745cdf0e10cSrcweir 			rViewShell.FillSimple( eFillDir, sal_True );
746cdf0e10cSrcweir 		else
747cdf0e10cSrcweir 			rViewShell.FillSeries( eFillDir, eFillCmd, eFillDateCmd,
748cdf0e10cSrcweir 								   fStartValue, fStepValue, fMaxValue, sal_True );
749cdf0e10cSrcweir 	}
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir 
753cdf0e10cSrcweir //----------------------------------------------------------------------------
754cdf0e10cSrcweir 
755cdf0e10cSrcweir sal_Bool __EXPORT ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
756cdf0e10cSrcweir {
757cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
758cdf0e10cSrcweir }
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 
761cdf0e10cSrcweir //============================================================================
762cdf0e10cSrcweir //	class ScUndoMerge
763cdf0e10cSrcweir //
764cdf0e10cSrcweir //	Zellen zusammenfassen / Zusammenfassung aufheben
765cdf0e10cSrcweir 
766cdf0e10cSrcweir //----------------------------------------------------------------------------
767cdf0e10cSrcweir 
768cdf0e10cSrcweir ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell,
769cdf0e10cSrcweir 							SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
770cdf0e10cSrcweir 							SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
771cdf0e10cSrcweir                             bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
772cdf0e10cSrcweir 		//
773cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
774cdf0e10cSrcweir 		//
775cdf0e10cSrcweir 		maRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
776cdf0e10cSrcweir         mbMergeContents( bMergeContents ),
777cdf0e10cSrcweir         mpUndoDoc( pUndoDoc ),
778cdf0e10cSrcweir         mpDrawUndo( pDrawUndo )
779cdf0e10cSrcweir {
780cdf0e10cSrcweir }
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 
783cdf0e10cSrcweir //----------------------------------------------------------------------------
784cdf0e10cSrcweir 
785cdf0e10cSrcweir ScUndoMerge::~ScUndoMerge()
786cdf0e10cSrcweir {
787cdf0e10cSrcweir 	delete mpUndoDoc;
788cdf0e10cSrcweir     DeleteSdrUndoAction( mpDrawUndo );
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 
792cdf0e10cSrcweir //----------------------------------------------------------------------------
793cdf0e10cSrcweir 
794cdf0e10cSrcweir String ScUndoMerge::GetComment() const
795cdf0e10cSrcweir {
796cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_MERGE );
797cdf0e10cSrcweir }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 
800cdf0e10cSrcweir //----------------------------------------------------------------------------
801cdf0e10cSrcweir 
802cdf0e10cSrcweir void ScUndoMerge::DoChange( bool bUndo ) const
803cdf0e10cSrcweir {
804cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 	ScUndoUtil::MarkSimpleBlock( pDocShell, maRange );
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 	if (bUndo)
809cdf0e10cSrcweir         // remove merge (contents are copied back below from undo document)
810cdf0e10cSrcweir 		pDoc->RemoveMerge( maRange.aStart.Col(), maRange.aStart.Row(), maRange.aStart.Tab() );
811cdf0e10cSrcweir 	else
812cdf0e10cSrcweir         // repeat merge, but do not remove note captions (will be done by drawing redo below)
813cdf0e10cSrcweir /*!*/	pDoc->DoMerge( maRange.aStart.Tab(),
814cdf0e10cSrcweir 					   maRange.aStart.Col(), maRange.aStart.Row(),
815cdf0e10cSrcweir                        maRange.aEnd.Col(),   maRange.aEnd.Row(), false );
816cdf0e10cSrcweir 
817cdf0e10cSrcweir     // undo -> copy back deleted contents
818cdf0e10cSrcweir 	if (bUndo && mpUndoDoc)
819cdf0e10cSrcweir     {
820cdf0e10cSrcweir         pDoc->DeleteAreaTab( maRange, IDF_CONTENTS|IDF_NOCAPTIONS );
821cdf0e10cSrcweir         mpUndoDoc->CopyToDocument( maRange, IDF_ALL|IDF_NOCAPTIONS, sal_False, pDoc );
822cdf0e10cSrcweir     }
823cdf0e10cSrcweir 
824cdf0e10cSrcweir     // redo -> merge contents again
825cdf0e10cSrcweir     else if (!bUndo && mbMergeContents)
826cdf0e10cSrcweir     {
827cdf0e10cSrcweir /*!*/   pDoc->DoMergeContents( maRange.aStart.Tab(),
828cdf0e10cSrcweir 							   maRange.aStart.Col(), maRange.aStart.Row(),
829cdf0e10cSrcweir 							   maRange.aEnd.Col(),   maRange.aEnd.Row()   );
830cdf0e10cSrcweir     }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir     if (bUndo)
833cdf0e10cSrcweir         DoSdrUndoAction( mpDrawUndo, pDoc );
834cdf0e10cSrcweir     else
835cdf0e10cSrcweir         RedoSdrUndoAction( mpDrawUndo );
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 	sal_Bool bDidPaint = sal_False;
838cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
839cdf0e10cSrcweir 	if ( pViewShell )
840cdf0e10cSrcweir 	{
841cdf0e10cSrcweir 		pViewShell->SetTabNo( maRange.aStart.Tab() );
842cdf0e10cSrcweir 		bDidPaint = pViewShell->AdjustRowHeight( maRange.aStart.Row(), maRange.aEnd.Row() );
843cdf0e10cSrcweir 	}
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 	if (!bDidPaint)
846cdf0e10cSrcweir 		ScUndoUtil::PaintMore( pDocShell, maRange );
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 	ShowTable( maRange );
849cdf0e10cSrcweir }
850cdf0e10cSrcweir 
851cdf0e10cSrcweir 
852cdf0e10cSrcweir //----------------------------------------------------------------------------
853cdf0e10cSrcweir 
854cdf0e10cSrcweir void ScUndoMerge::Undo()
855cdf0e10cSrcweir {
856cdf0e10cSrcweir 	BeginUndo();
857cdf0e10cSrcweir 	DoChange( true );
858cdf0e10cSrcweir 	EndUndo();
859cdf0e10cSrcweir }
860cdf0e10cSrcweir 
861cdf0e10cSrcweir 
862cdf0e10cSrcweir //----------------------------------------------------------------------------
863cdf0e10cSrcweir 
864cdf0e10cSrcweir void ScUndoMerge::Redo()
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	BeginRedo();
867cdf0e10cSrcweir 	DoChange( false );
868cdf0e10cSrcweir 	EndRedo();
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir 
872cdf0e10cSrcweir //----------------------------------------------------------------------------
873cdf0e10cSrcweir 
874cdf0e10cSrcweir void ScUndoMerge::Repeat(SfxRepeatTarget& rTarget)
875cdf0e10cSrcweir {
876cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
877cdf0e10cSrcweir 	{
878cdf0e10cSrcweir 		ScTabViewShell& rViewShell = *((ScTabViewTarget&)rTarget).GetViewShell();
879cdf0e10cSrcweir 		sal_Bool bCont = sal_False;
880cdf0e10cSrcweir 		rViewShell.MergeCells( sal_False, bCont, sal_True );
881cdf0e10cSrcweir 	}
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 
885cdf0e10cSrcweir //----------------------------------------------------------------------------
886cdf0e10cSrcweir 
887cdf0e10cSrcweir sal_Bool ScUndoMerge::CanRepeat(SfxRepeatTarget& rTarget) const
888cdf0e10cSrcweir {
889cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
890cdf0e10cSrcweir }
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 
893cdf0e10cSrcweir //============================================================================
894cdf0e10cSrcweir //	class ScUndoAutoFormat
895cdf0e10cSrcweir //
896cdf0e10cSrcweir //		Auto-Format (nur einfache Bloecke)
897cdf0e10cSrcweir 
898cdf0e10cSrcweir //----------------------------------------------------------------------------
899cdf0e10cSrcweir 
900cdf0e10cSrcweir ScUndoAutoFormat::ScUndoAutoFormat( ScDocShell* pNewDocShell,
901cdf0e10cSrcweir 						const ScRange& rRange, ScDocument* pNewUndoDoc,
902cdf0e10cSrcweir 						const ScMarkData& rMark, sal_Bool bNewSize, sal_uInt16 nNewFormatNo )
903cdf0e10cSrcweir 		//
904cdf0e10cSrcweir 	:	ScBlockUndo( pNewDocShell, rRange, bNewSize ? SC_UNDO_MANUALHEIGHT : SC_UNDO_AUTOHEIGHT ),
905cdf0e10cSrcweir 		//
906cdf0e10cSrcweir 		pUndoDoc	( pNewUndoDoc ),
907cdf0e10cSrcweir 		aMarkData	( rMark ),
908cdf0e10cSrcweir 		bSize		( bNewSize ),
909cdf0e10cSrcweir 		nFormatNo	( nNewFormatNo )
910cdf0e10cSrcweir {
911cdf0e10cSrcweir }
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 
914cdf0e10cSrcweir //----------------------------------------------------------------------------
915cdf0e10cSrcweir 
916cdf0e10cSrcweir __EXPORT ScUndoAutoFormat::~ScUndoAutoFormat()
917cdf0e10cSrcweir {
918cdf0e10cSrcweir 	delete pUndoDoc;
919cdf0e10cSrcweir }
920cdf0e10cSrcweir 
921cdf0e10cSrcweir 
922cdf0e10cSrcweir //----------------------------------------------------------------------------
923cdf0e10cSrcweir 
924cdf0e10cSrcweir String __EXPORT ScUndoAutoFormat::GetComment() const
925cdf0e10cSrcweir {
926cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_AUTOFORMAT );	//"Auto-Format"
927cdf0e10cSrcweir }
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 
930cdf0e10cSrcweir //----------------------------------------------------------------------------
931cdf0e10cSrcweir 
932cdf0e10cSrcweir void __EXPORT ScUndoAutoFormat::Undo()
933cdf0e10cSrcweir {
934cdf0e10cSrcweir 	BeginUndo();
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
937cdf0e10cSrcweir 
938cdf0e10cSrcweir 	// Attribute
939cdf0e10cSrcweir //	pDoc->DeleteAreaTab( aBlockRange, IDF_ATTRIB );
940cdf0e10cSrcweir //	pUndoDoc->CopyToDocument( aBlockRange, IDF_ATTRIB, sal_False, pDoc );
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 	SCTAB nTabCount = pDoc->GetTableCount();
943cdf0e10cSrcweir 	pDoc->DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
944cdf0e10cSrcweir 					  aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(),
945cdf0e10cSrcweir 					  aMarkData, IDF_ATTRIB );
946cdf0e10cSrcweir 	ScRange aCopyRange = aBlockRange;
947cdf0e10cSrcweir 	aCopyRange.aStart.SetTab(0);
948cdf0e10cSrcweir 	aCopyRange.aEnd.SetTab(nTabCount-1);
949cdf0e10cSrcweir 	pUndoDoc->CopyToDocument( aCopyRange, IDF_ATTRIB, sal_False, pDoc, &aMarkData );
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 	// Zellhoehen und -breiten (IDF_NONE)
952cdf0e10cSrcweir 	if (bSize)
953cdf0e10cSrcweir 	{
954cdf0e10cSrcweir 		SCCOL nStartX = aBlockRange.aStart.Col();
955cdf0e10cSrcweir 		SCROW nStartY = aBlockRange.aStart.Row();
956cdf0e10cSrcweir 		SCTAB nStartZ = aBlockRange.aStart.Tab();
957cdf0e10cSrcweir 		SCCOL nEndX = aBlockRange.aEnd.Col();
958cdf0e10cSrcweir 		SCROW nEndY = aBlockRange.aEnd.Row();
959cdf0e10cSrcweir 		SCTAB nEndZ = aBlockRange.aEnd.Tab();
960cdf0e10cSrcweir 
961cdf0e10cSrcweir 		pUndoDoc->CopyToDocument( nStartX, 0, 0, nEndX, MAXROW, nTabCount-1,
962cdf0e10cSrcweir 									IDF_NONE, sal_False, pDoc, &aMarkData );
963cdf0e10cSrcweir 		pUndoDoc->CopyToDocument( 0, nStartY, 0, MAXCOL, nEndY, nTabCount-1,
964cdf0e10cSrcweir 									IDF_NONE, sal_False, pDoc, &aMarkData );
965cdf0e10cSrcweir 		pDocShell->PostPaint( 0, 0, nStartZ, MAXCOL, MAXROW, nEndZ,
966cdf0e10cSrcweir 							  PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES );
967cdf0e10cSrcweir 	}
968cdf0e10cSrcweir 	else
969cdf0e10cSrcweir 		pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
970cdf0e10cSrcweir 
971cdf0e10cSrcweir 	EndUndo();
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
974cdf0e10cSrcweir 
975cdf0e10cSrcweir //----------------------------------------------------------------------------
976cdf0e10cSrcweir 
977cdf0e10cSrcweir void __EXPORT ScUndoAutoFormat::Redo()
978cdf0e10cSrcweir {
979cdf0e10cSrcweir 	BeginRedo();
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
982cdf0e10cSrcweir 
983cdf0e10cSrcweir 	SCCOL nStartX = aBlockRange.aStart.Col();
984cdf0e10cSrcweir 	SCROW nStartY = aBlockRange.aStart.Row();
985cdf0e10cSrcweir 	SCTAB nStartZ = aBlockRange.aStart.Tab();
986cdf0e10cSrcweir 	SCCOL nEndX = aBlockRange.aEnd.Col();
987cdf0e10cSrcweir 	SCROW nEndY = aBlockRange.aEnd.Row();
988cdf0e10cSrcweir 	SCTAB nEndZ = aBlockRange.aEnd.Tab();
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 	pDoc->AutoFormat( nStartX, nStartY, nEndX, nEndY, nFormatNo, aMarkData );
991cdf0e10cSrcweir 
992cdf0e10cSrcweir 	if (bSize)
993cdf0e10cSrcweir 	{
994cdf0e10cSrcweir 		VirtualDevice aVirtDev;
995cdf0e10cSrcweir 		Fraction aZoomX(1,1);
996cdf0e10cSrcweir 		Fraction aZoomY = aZoomX;
997cdf0e10cSrcweir 		double nPPTX,nPPTY;
998cdf0e10cSrcweir 		ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
999cdf0e10cSrcweir 		if (pViewShell)
1000cdf0e10cSrcweir 		{
1001cdf0e10cSrcweir 			ScViewData* pData = pViewShell->GetViewData();
1002cdf0e10cSrcweir 			nPPTX = pData->GetPPTX();
1003cdf0e10cSrcweir 			nPPTY = pData->GetPPTY();
1004cdf0e10cSrcweir 			aZoomX = pData->GetZoomX();
1005cdf0e10cSrcweir 			aZoomY = pData->GetZoomY();
1006cdf0e10cSrcweir 		}
1007cdf0e10cSrcweir 		else
1008cdf0e10cSrcweir 		{
1009cdf0e10cSrcweir 			//	Zoom auf 100 lassen
1010cdf0e10cSrcweir 			nPPTX = ScGlobal::nScreenPPTX;
1011cdf0e10cSrcweir 			nPPTY = ScGlobal::nScreenPPTY;
1012cdf0e10cSrcweir 		}
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir 		sal_Bool bFormula = sal_False;	//! merken
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 		for (SCTAB nTab=nStartZ; nTab<=nEndZ; nTab++)
1017cdf0e10cSrcweir 		{
1018cdf0e10cSrcweir 			ScMarkData aDestMark;
1019cdf0e10cSrcweir 			aDestMark.SelectOneTable( nTab );
1020cdf0e10cSrcweir 			aDestMark.SetMarkArea( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) );
1021cdf0e10cSrcweir 			aDestMark.MarkToMulti();
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir 			// wie SC_SIZE_VISOPT
1024cdf0e10cSrcweir             SCROW nLastRow = -1;
1025cdf0e10cSrcweir 			for (SCROW nRow=nStartY; nRow<=nEndY; nRow++)
1026cdf0e10cSrcweir 			{
1027cdf0e10cSrcweir 				sal_uInt8 nOld = pDoc->GetRowFlags(nRow,nTab);
1028cdf0e10cSrcweir                 bool bHidden = pDoc->RowHidden(nRow, nTab, nLastRow);
1029cdf0e10cSrcweir 				if ( !bHidden && ( nOld & CR_MANUALSIZE ) )
1030cdf0e10cSrcweir 					pDoc->SetRowFlags( nRow, nTab, nOld & ~CR_MANUALSIZE );
1031cdf0e10cSrcweir 			}
1032cdf0e10cSrcweir 			pDoc->SetOptimalHeight( nStartY, nEndY, nTab, 0, &aVirtDev,
1033cdf0e10cSrcweir 										nPPTX, nPPTY, aZoomX, aZoomY, sal_False );
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir             SCCOL nLastCol = -1;
1036cdf0e10cSrcweir 			for (SCCOL nCol=nStartX; nCol<=nEndX; nCol++)
1037cdf0e10cSrcweir                 if (!pDoc->ColHidden(nCol, nTab, nLastCol))
1038cdf0e10cSrcweir 				{
1039cdf0e10cSrcweir 					sal_uInt16 nThisSize = STD_EXTRA_WIDTH + pDoc->GetOptimalColWidth( nCol, nTab,
1040cdf0e10cSrcweir 												&aVirtDev, nPPTX, nPPTY, aZoomX, aZoomY, bFormula,
1041cdf0e10cSrcweir 												&aDestMark );
1042cdf0e10cSrcweir 					pDoc->SetColWidth( nCol, nTab, nThisSize );
1043cdf0e10cSrcweir 					pDoc->ShowCol( nCol, nTab, sal_True );
1044cdf0e10cSrcweir 				}
1045cdf0e10cSrcweir 		}
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir 		pDocShell->PostPaint( 0,      0,      nStartZ,
1048cdf0e10cSrcweir 							  MAXCOL, MAXROW, nEndZ,
1049cdf0e10cSrcweir 							  PAINT_GRID | PAINT_LEFT | PAINT_TOP, SC_PF_LINES);
1050cdf0e10cSrcweir 	}
1051cdf0e10cSrcweir 	else
1052cdf0e10cSrcweir 		pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES );
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 	EndRedo();
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir 
1058cdf0e10cSrcweir //----------------------------------------------------------------------------
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir void __EXPORT ScUndoAutoFormat::Repeat(SfxRepeatTarget& rTarget)
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
1063cdf0e10cSrcweir 		((ScTabViewTarget&)rTarget).GetViewShell()->AutoFormat( nFormatNo, sal_True );
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 
1067cdf0e10cSrcweir //----------------------------------------------------------------------------
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir sal_Bool __EXPORT ScUndoAutoFormat::CanRepeat(SfxRepeatTarget& rTarget) const
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir //============================================================================
1076cdf0e10cSrcweir //	class ScUndoReplace
1077cdf0e10cSrcweir //
1078cdf0e10cSrcweir //		Ersetzen
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir //----------------------------------------------------------------------------
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir ScUndoReplace::ScUndoReplace( ScDocShell* pNewDocShell, const ScMarkData& rMark,
1083cdf0e10cSrcweir 									SCCOL nCurX, SCROW nCurY, SCTAB nCurZ,
1084cdf0e10cSrcweir 									const String& rNewUndoStr, ScDocument* pNewUndoDoc,
1085cdf0e10cSrcweir 									const SvxSearchItem* pItem )
1086cdf0e10cSrcweir 		//
1087cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
1088cdf0e10cSrcweir 		//
1089cdf0e10cSrcweir 		aCursorPos	( nCurX, nCurY, nCurZ ),
1090cdf0e10cSrcweir 		aMarkData	( rMark ),
1091cdf0e10cSrcweir 		aUndoStr	( rNewUndoStr ),
1092cdf0e10cSrcweir 		pUndoDoc	( pNewUndoDoc )
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir 	pSearchItem = new SvxSearchItem( *pItem );
1095cdf0e10cSrcweir 	SetChangeTrack();
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir //----------------------------------------------------------------------------
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir __EXPORT ScUndoReplace::~ScUndoReplace()
1102cdf0e10cSrcweir {
1103cdf0e10cSrcweir 	delete pUndoDoc;
1104cdf0e10cSrcweir 	delete pSearchItem;
1105cdf0e10cSrcweir }
1106cdf0e10cSrcweir 
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir //----------------------------------------------------------------------------
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir void ScUndoReplace::SetChangeTrack()
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1113cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1114cdf0e10cSrcweir 	if ( pChangeTrack )
1115cdf0e10cSrcweir 	{
1116cdf0e10cSrcweir 		if ( pUndoDoc )
1117cdf0e10cSrcweir 		{	//! im UndoDoc stehen nur die geaenderten Zellen,
1118cdf0e10cSrcweir 			// deswegen per Iterator moeglich
1119cdf0e10cSrcweir 			pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1120cdf0e10cSrcweir 				nStartChangeAction,	nEndChangeAction );
1121cdf0e10cSrcweir 		}
1122cdf0e10cSrcweir 		else
1123cdf0e10cSrcweir 		{
1124cdf0e10cSrcweir 			nStartChangeAction = pChangeTrack->GetActionMax() + 1;
1125cdf0e10cSrcweir 			ScChangeActionContent* pContent = new ScChangeActionContent(
1126cdf0e10cSrcweir 				ScRange( aCursorPos) );
1127cdf0e10cSrcweir 			pContent->SetOldValue( aUndoStr, pDoc );
1128cdf0e10cSrcweir 			pContent->SetNewValue( pDoc->GetCell( aCursorPos ), pDoc );
1129cdf0e10cSrcweir 			pChangeTrack->Append( pContent );
1130cdf0e10cSrcweir 			nEndChangeAction = pChangeTrack->GetActionMax();
1131cdf0e10cSrcweir 		}
1132cdf0e10cSrcweir 	}
1133cdf0e10cSrcweir 	else
1134cdf0e10cSrcweir 		nStartChangeAction = nEndChangeAction = 0;
1135cdf0e10cSrcweir }
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir //----------------------------------------------------------------------------
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir String __EXPORT ScUndoReplace::GetComment() const
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_REPLACE );	// "Ersetzen"
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir //----------------------------------------------------------------------------
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir void __EXPORT ScUndoReplace::Undo()
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir 	BeginUndo();
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1152cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1153cdf0e10cSrcweir 
1154cdf0e10cSrcweir 	ShowTable( aCursorPos.Tab() );
1155cdf0e10cSrcweir 
1156cdf0e10cSrcweir 	if (pUndoDoc)		// nur bei ReplaceAll !!
1157cdf0e10cSrcweir 	{
1158cdf0e10cSrcweir 		DBG_ASSERT(pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE_ALL,
1159cdf0e10cSrcweir 				   "ScUndoReplace:: Falscher Modus");
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir 	    SetViewMarkData( aMarkData );
1162cdf0e10cSrcweir 
1163cdf0e10cSrcweir //!	markierte Tabellen
1164cdf0e10cSrcweir //!	Bereich merken ?
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 		//	Undo-Dokument hat keine Zeilen-/Spalten-Infos, also mit bColRowFlags = FALSE
1167cdf0e10cSrcweir 		//	kopieren, um Outline-Gruppen nicht kaputtzumachen.
1168cdf0e10cSrcweir 
1169cdf0e10cSrcweir 		sal_uInt16 nUndoFlags = (pSearchItem->GetPattern()) ? IDF_ATTRIB : IDF_CONTENTS;
1170cdf0e10cSrcweir 		pUndoDoc->CopyToDocument( 0,      0,      0,
1171cdf0e10cSrcweir 								  MAXCOL, MAXROW, MAXTAB,
1172cdf0e10cSrcweir 								  nUndoFlags, sal_False, pDoc, NULL, sal_False );	// ohne Row-Flags
1173cdf0e10cSrcweir 		pDocShell->PostPaintGridAll();
1174cdf0e10cSrcweir 	}
1175cdf0e10cSrcweir 	else if (pSearchItem->GetPattern() &&
1176cdf0e10cSrcweir 			 pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
1177cdf0e10cSrcweir 	{
1178cdf0e10cSrcweir 		String aTempStr = pSearchItem->GetSearchString();		// vertauschen
1179cdf0e10cSrcweir 		pSearchItem->SetSearchString(pSearchItem->GetReplaceString());
1180cdf0e10cSrcweir 		pSearchItem->SetReplaceString(aTempStr);
1181cdf0e10cSrcweir 		pDoc->ReplaceStyle( *pSearchItem,
1182cdf0e10cSrcweir 							aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1183cdf0e10cSrcweir 							aMarkData, sal_True);
1184cdf0e10cSrcweir 		pSearchItem->SetReplaceString(pSearchItem->GetSearchString());
1185cdf0e10cSrcweir 		pSearchItem->SetSearchString(aTempStr);
1186cdf0e10cSrcweir 		if (pViewShell)
1187cdf0e10cSrcweir 			pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1188cdf0e10cSrcweir 									   SC_FOLLOW_JUMP, sal_False, sal_False );
1189cdf0e10cSrcweir 		pDocShell->PostPaintGridAll();
1190cdf0e10cSrcweir 	}
1191cdf0e10cSrcweir 	else if (pSearchItem->GetCellType() == SVX_SEARCHIN_NOTE)
1192cdf0e10cSrcweir 	{
1193cdf0e10cSrcweir         ScPostIt* pNote = pDoc->GetNote( aCursorPos );
1194cdf0e10cSrcweir         DBG_ASSERT( pNote, "ScUndoReplace::Undo - cell does not contain a note" );
1195cdf0e10cSrcweir         if (pNote)
1196cdf0e10cSrcweir             pNote->SetText( aCursorPos, aUndoStr );
1197cdf0e10cSrcweir 		if (pViewShell)
1198cdf0e10cSrcweir 			pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1199cdf0e10cSrcweir 									   SC_FOLLOW_JUMP, sal_False, sal_False );
1200cdf0e10cSrcweir 	}
1201cdf0e10cSrcweir 	else
1202cdf0e10cSrcweir 	{
1203cdf0e10cSrcweir 		// #78889# aUndoStr may contain line breaks
1204cdf0e10cSrcweir 		if ( aUndoStr.Search('\n') != STRING_NOTFOUND )
1205cdf0e10cSrcweir 			pDoc->PutCell( aCursorPos, new ScEditCell( aUndoStr, pDoc ) );
1206cdf0e10cSrcweir 		else
1207cdf0e10cSrcweir 			pDoc->SetString( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aUndoStr );
1208cdf0e10cSrcweir 		if (pViewShell)
1209cdf0e10cSrcweir 			pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1210cdf0e10cSrcweir 									   SC_FOLLOW_JUMP, sal_False, sal_False );
1211cdf0e10cSrcweir 		pDocShell->PostPaintGridAll();
1212cdf0e10cSrcweir 	}
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1215cdf0e10cSrcweir 	if ( pChangeTrack )
1216cdf0e10cSrcweir 		pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir 	EndUndo();
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 
1222cdf0e10cSrcweir //----------------------------------------------------------------------------
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir void __EXPORT ScUndoReplace::Redo()
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir 	BeginRedo();
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1229cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 	if (pViewShell)
1232cdf0e10cSrcweir 		pViewShell->MoveCursorAbs( aCursorPos.Col(), aCursorPos.Row(),
1233cdf0e10cSrcweir 								   SC_FOLLOW_JUMP, sal_False, sal_False );
1234cdf0e10cSrcweir 	if (pUndoDoc)
1235cdf0e10cSrcweir 	{
1236cdf0e10cSrcweir 		if (pViewShell)
1237cdf0e10cSrcweir 		{
1238cdf0e10cSrcweir             SetViewMarkData( aMarkData );
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir 			pViewShell->SearchAndReplace( pSearchItem, sal_False, sal_True );
1241cdf0e10cSrcweir 		}
1242cdf0e10cSrcweir 	}
1243cdf0e10cSrcweir 	else if (pSearchItem->GetPattern() &&
1244cdf0e10cSrcweir 			 pSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
1245cdf0e10cSrcweir 	{
1246cdf0e10cSrcweir 		pDoc->ReplaceStyle( *pSearchItem,
1247cdf0e10cSrcweir 							aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(),
1248cdf0e10cSrcweir 							aMarkData, sal_True);
1249cdf0e10cSrcweir 		pDocShell->PostPaintGridAll();
1250cdf0e10cSrcweir 	}
1251cdf0e10cSrcweir 	else
1252cdf0e10cSrcweir 		if (pViewShell)
1253cdf0e10cSrcweir 			pViewShell->SearchAndReplace( pSearchItem, sal_False, sal_True );
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 	SetChangeTrack();
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 	EndRedo();
1258cdf0e10cSrcweir }
1259cdf0e10cSrcweir 
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir //----------------------------------------------------------------------------
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir void __EXPORT ScUndoReplace::Repeat(SfxRepeatTarget& rTarget)
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir 	if (rTarget.ISA(ScTabViewTarget))
1266cdf0e10cSrcweir 		((ScTabViewTarget&)rTarget).GetViewShell()->SearchAndReplace( pSearchItem, sal_True, sal_False );
1267cdf0e10cSrcweir }
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir //----------------------------------------------------------------------------
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir sal_Bool __EXPORT ScUndoReplace::CanRepeat(SfxRepeatTarget& rTarget) const
1273cdf0e10cSrcweir {
1274cdf0e10cSrcweir 	return (rTarget.ISA(ScTabViewTarget));
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir //============================================================================
1279cdf0e10cSrcweir //	class ScUndoTabOp
1280cdf0e10cSrcweir //
1281cdf0e10cSrcweir //	Mehrfachoperation (nur einfache Bloecke)
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir //----------------------------------------------------------------------------
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir ScUndoTabOp::ScUndoTabOp( ScDocShell* pNewDocShell,
1286cdf0e10cSrcweir 				SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
1287cdf0e10cSrcweir 				SCCOL nEndX, SCROW nEndY, SCTAB nEndZ, ScDocument* pNewUndoDoc,
1288cdf0e10cSrcweir 				const ScRefAddress& rFormulaCell,
1289cdf0e10cSrcweir 				const ScRefAddress& rFormulaEnd,
1290cdf0e10cSrcweir 				const ScRefAddress& rRowCell,
1291cdf0e10cSrcweir 				const ScRefAddress& rColCell,
1292cdf0e10cSrcweir 				sal_uInt8 nMd )
1293cdf0e10cSrcweir 		//
1294cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
1295cdf0e10cSrcweir 		//
1296cdf0e10cSrcweir 		aRange			( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
1297cdf0e10cSrcweir 		pUndoDoc		( pNewUndoDoc ),
1298cdf0e10cSrcweir 		theFormulaCell	( rFormulaCell ),
1299cdf0e10cSrcweir 		theFormulaEnd	( rFormulaEnd ),
1300cdf0e10cSrcweir 		theRowCell		( rRowCell ),
1301cdf0e10cSrcweir 		theColCell		( rColCell ),
1302cdf0e10cSrcweir 		nMode			( nMd )
1303cdf0e10cSrcweir {
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir //----------------------------------------------------------------------------
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir __EXPORT ScUndoTabOp::~ScUndoTabOp()
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir 	delete pUndoDoc;
1312cdf0e10cSrcweir }
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir //----------------------------------------------------------------------------
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir String __EXPORT ScUndoTabOp::GetComment() const
1318cdf0e10cSrcweir {
1319cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_TABOP );	// "Mehrfachoperation"
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir //----------------------------------------------------------------------------
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir void __EXPORT ScUndoTabOp::Undo()
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir 	BeginUndo();
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir 	ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir 	sal_uInt16 nExtFlags = 0;
1332cdf0e10cSrcweir 	pDocShell->UpdatePaintExt( nExtFlags, aRange );
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1335cdf0e10cSrcweir     pDoc->DeleteAreaTab( aRange,IDF_ALL & ~IDF_NOTE );
1336cdf0e10cSrcweir     pUndoDoc->CopyToDocument( aRange, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
1337cdf0e10cSrcweir 	pDocShell->PostPaint( aRange, PAINT_GRID, nExtFlags );
1338cdf0e10cSrcweir 	pDocShell->PostDataChanged();
1339cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1340cdf0e10cSrcweir 	if (pViewShell)
1341cdf0e10cSrcweir 		pViewShell->CellContentChanged();
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir 	EndUndo();
1344cdf0e10cSrcweir }
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir //----------------------------------------------------------------------------
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir void __EXPORT ScUndoTabOp::Redo()
1350cdf0e10cSrcweir {
1351cdf0e10cSrcweir 	BeginRedo();
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir 	ScUndoUtil::MarkSimpleBlock( pDocShell, aRange );
1354cdf0e10cSrcweir 
1355cdf0e10cSrcweir 	ScTabOpParam aParam( theFormulaCell, theFormulaEnd,
1356cdf0e10cSrcweir 						 theRowCell,     theColCell,
1357cdf0e10cSrcweir 						 nMode );
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1360cdf0e10cSrcweir 	if (pViewShell)
1361cdf0e10cSrcweir 		pViewShell->TabOp( aParam, sal_False);
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 	EndRedo();
1364cdf0e10cSrcweir }
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir //----------------------------------------------------------------------------
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir void __EXPORT ScUndoTabOp::Repeat(SfxRepeatTarget& /* rTarget */)
1370cdf0e10cSrcweir {
1371cdf0e10cSrcweir }
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir //----------------------------------------------------------------------------
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir sal_Bool __EXPORT ScUndoTabOp::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir 	return sal_False;
1379cdf0e10cSrcweir }
1380cdf0e10cSrcweir 
1381cdf0e10cSrcweir 
1382cdf0e10cSrcweir //============================================================================
1383cdf0e10cSrcweir //  class ScUndoConversion
1384cdf0e10cSrcweir //
1385cdf0e10cSrcweir //	Spelling
1386cdf0e10cSrcweir 
1387cdf0e10cSrcweir //----------------------------------------------------------------------------
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir ScUndoConversion::ScUndoConversion(
1390cdf0e10cSrcweir         ScDocShell* pNewDocShell, const ScMarkData& rMark,
1391cdf0e10cSrcweir         SCCOL nCurX, SCROW nCurY, SCTAB nCurZ, ScDocument* pNewUndoDoc,
1392cdf0e10cSrcweir         SCCOL nNewX, SCROW nNewY, SCTAB nNewZ, ScDocument* pNewRedoDoc,
1393cdf0e10cSrcweir         const ScConversionParam& rConvParam ) :
1394cdf0e10cSrcweir     ScSimpleUndo( pNewDocShell ),
1395cdf0e10cSrcweir     aMarkData( rMark ),
1396cdf0e10cSrcweir     aCursorPos( nCurX, nCurY, nCurZ ),
1397cdf0e10cSrcweir     pUndoDoc( pNewUndoDoc ),
1398cdf0e10cSrcweir     aNewCursorPos( nNewX, nNewY, nNewZ ),
1399cdf0e10cSrcweir     pRedoDoc( pNewRedoDoc ),
1400cdf0e10cSrcweir     maConvParam( rConvParam )
1401cdf0e10cSrcweir {
1402cdf0e10cSrcweir 	SetChangeTrack();
1403cdf0e10cSrcweir }
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir //----------------------------------------------------------------------------
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir __EXPORT ScUndoConversion::~ScUndoConversion()
1409cdf0e10cSrcweir {
1410cdf0e10cSrcweir 	delete pUndoDoc;
1411cdf0e10cSrcweir 	delete pRedoDoc;
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir 
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir //----------------------------------------------------------------------------
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir void ScUndoConversion::SetChangeTrack()
1418cdf0e10cSrcweir {
1419cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1420cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
1421cdf0e10cSrcweir 	if ( pChangeTrack )
1422cdf0e10cSrcweir 	{
1423cdf0e10cSrcweir 		if ( pUndoDoc )
1424cdf0e10cSrcweir 			pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1425cdf0e10cSrcweir 				nStartChangeAction, nEndChangeAction );
1426cdf0e10cSrcweir 		else
1427cdf0e10cSrcweir 		{
1428cdf0e10cSrcweir             DBG_ERROR( "ScUndoConversion::SetChangeTrack: kein UndoDoc" );
1429cdf0e10cSrcweir 			nStartChangeAction = nEndChangeAction = 0;
1430cdf0e10cSrcweir 		}
1431cdf0e10cSrcweir 	}
1432cdf0e10cSrcweir 	else
1433cdf0e10cSrcweir 		nStartChangeAction = nEndChangeAction = 0;
1434cdf0e10cSrcweir }
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir //----------------------------------------------------------------------------
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir String ScUndoConversion::GetComment() const
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir     String aText;
1441cdf0e10cSrcweir     switch( maConvParam.GetType() )
1442cdf0e10cSrcweir     {
1443cdf0e10cSrcweir         case SC_CONVERSION_SPELLCHECK:      aText = ScGlobal::GetRscString( STR_UNDO_SPELLING );    break;
1444cdf0e10cSrcweir         case SC_CONVERSION_HANGULHANJA:     aText = ScGlobal::GetRscString( STR_UNDO_HANGULHANJA ); break;
1445cdf0e10cSrcweir         case SC_CONVERSION_CHINESE_TRANSL:  aText = ScGlobal::GetRscString( STR_UNDO_CHINESE_TRANSLATION ); break;
1446cdf0e10cSrcweir         default: DBG_ERRORFILE( "ScUndoConversion::GetComment - unknown conversion type" );
1447cdf0e10cSrcweir     }
1448cdf0e10cSrcweir     return aText;
1449cdf0e10cSrcweir }
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir //----------------------------------------------------------------------------
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir void ScUndoConversion::DoChange( ScDocument* pRefDoc, const ScAddress& rCursorPos )
1455cdf0e10cSrcweir {
1456cdf0e10cSrcweir 	if (pRefDoc)
1457cdf0e10cSrcweir 	{
1458cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
1459cdf0e10cSrcweir 		ShowTable( rCursorPos.Tab() );
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir 	    SetViewMarkData( aMarkData );
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir 		SCTAB nTabCount = pDoc->GetTableCount();
1464cdf0e10cSrcweir 		//	Undo/Redo-doc has only selected tables
1465cdf0e10cSrcweir 
1466cdf0e10cSrcweir 		sal_Bool bMulti = aMarkData.IsMultiMarked();
1467cdf0e10cSrcweir 		pRefDoc->CopyToDocument( 0,      0,      0,
1468cdf0e10cSrcweir 								 MAXCOL, MAXROW, nTabCount-1,
1469cdf0e10cSrcweir 								 IDF_CONTENTS, bMulti, pDoc, &aMarkData );
1470cdf0e10cSrcweir 		pDocShell->PostPaintGridAll();
1471cdf0e10cSrcweir 	}
1472cdf0e10cSrcweir 	else
1473cdf0e10cSrcweir 	{
1474cdf0e10cSrcweir 		DBG_ERROR("Kein Un-/RedoDoc bei Un-/RedoSpelling");
1475cdf0e10cSrcweir 	}
1476cdf0e10cSrcweir }
1477cdf0e10cSrcweir 
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir //----------------------------------------------------------------------------
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir void ScUndoConversion::Undo()
1482cdf0e10cSrcweir {
1483cdf0e10cSrcweir 	BeginUndo();
1484cdf0e10cSrcweir 	DoChange( pUndoDoc, aCursorPos );
1485cdf0e10cSrcweir 	ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1486cdf0e10cSrcweir 	if ( pChangeTrack )
1487cdf0e10cSrcweir 		pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1488cdf0e10cSrcweir 	EndUndo();
1489cdf0e10cSrcweir }
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir 
1492cdf0e10cSrcweir //----------------------------------------------------------------------------
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir void ScUndoConversion::Redo()
1495cdf0e10cSrcweir {
1496cdf0e10cSrcweir 	BeginRedo();
1497cdf0e10cSrcweir 	DoChange( pRedoDoc, aNewCursorPos );
1498cdf0e10cSrcweir 	SetChangeTrack();
1499cdf0e10cSrcweir 	EndRedo();
1500cdf0e10cSrcweir }
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir 
1503cdf0e10cSrcweir //----------------------------------------------------------------------------
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir void ScUndoConversion::Repeat( SfxRepeatTarget& rTarget )
1506cdf0e10cSrcweir {
1507cdf0e10cSrcweir     if( rTarget.ISA( ScTabViewTarget ) )
1508cdf0e10cSrcweir         ((ScTabViewTarget&)rTarget).GetViewShell()->DoSheetConversion( maConvParam, sal_True );
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir 
1512cdf0e10cSrcweir //----------------------------------------------------------------------------
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir sal_Bool ScUndoConversion::CanRepeat(SfxRepeatTarget& rTarget) const
1515cdf0e10cSrcweir {
1516cdf0e10cSrcweir     return rTarget.ISA( ScTabViewTarget );
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir //============================================================================
1521cdf0e10cSrcweir //  class ScUndoRefConversion
1522cdf0e10cSrcweir //
1523cdf0e10cSrcweir //	cell reference conversion
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir //----------------------------------------------------------------------------
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir ScUndoRefConversion::ScUndoRefConversion( ScDocShell* pNewDocShell,
1528cdf0e10cSrcweir                                          const ScRange& aMarkRange, const ScMarkData& rMark,
1529cdf0e10cSrcweir                                          ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc, sal_Bool bNewMulti, sal_uInt16 nNewFlag) :
1530cdf0e10cSrcweir ScSimpleUndo( pNewDocShell ),
1531cdf0e10cSrcweir aMarkData   ( rMark ),
1532cdf0e10cSrcweir pUndoDoc	( pNewUndoDoc ),
1533cdf0e10cSrcweir pRedoDoc	( pNewRedoDoc ),
1534cdf0e10cSrcweir aRange  	( aMarkRange ),
1535cdf0e10cSrcweir bMulti      ( bNewMulti ),
1536cdf0e10cSrcweir nFlags      ( nNewFlag )
1537cdf0e10cSrcweir {
1538cdf0e10cSrcweir     SetChangeTrack();
1539cdf0e10cSrcweir }
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir __EXPORT ScUndoRefConversion::~ScUndoRefConversion()
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir     delete pUndoDoc;
1544cdf0e10cSrcweir     delete pRedoDoc;
1545cdf0e10cSrcweir }
1546cdf0e10cSrcweir 
1547cdf0e10cSrcweir String __EXPORT ScUndoRefConversion::GetComment() const
1548cdf0e10cSrcweir {
1549cdf0e10cSrcweir     return ScGlobal::GetRscString( STR_UNDO_ENTERDATA ); // "Eingabe"
1550cdf0e10cSrcweir }
1551cdf0e10cSrcweir 
1552cdf0e10cSrcweir void ScUndoRefConversion::SetChangeTrack()
1553cdf0e10cSrcweir {
1554cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1555cdf0e10cSrcweir     if ( pChangeTrack && (nFlags & IDF_FORMULA) )
1556cdf0e10cSrcweir         pChangeTrack->AppendContentsIfInRefDoc( pUndoDoc,
1557cdf0e10cSrcweir             nStartChangeAction, nEndChangeAction );
1558cdf0e10cSrcweir     else
1559cdf0e10cSrcweir         nStartChangeAction = nEndChangeAction = 0;
1560cdf0e10cSrcweir }
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir void ScUndoRefConversion::DoChange( ScDocument* pRefDoc)
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir     ScDocument* pDoc = pDocShell->GetDocument();
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir     ShowTable(aRange);
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir     SetViewMarkData( aMarkData );
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir     ScRange aCopyRange = aRange;
1571cdf0e10cSrcweir     SCTAB nTabCount = pDoc->GetTableCount();
1572cdf0e10cSrcweir     aCopyRange.aStart.SetTab(0);
1573cdf0e10cSrcweir     aCopyRange.aEnd.SetTab(nTabCount-1);
1574cdf0e10cSrcweir     pRefDoc->CopyToDocument( aCopyRange, nFlags, bMulti, pDoc, &aMarkData );
1575cdf0e10cSrcweir     pDocShell->PostPaint( aRange, PAINT_GRID);
1576cdf0e10cSrcweir     pDocShell->PostDataChanged();
1577cdf0e10cSrcweir     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
1578cdf0e10cSrcweir     if (pViewShell)
1579cdf0e10cSrcweir         pViewShell->CellContentChanged();
1580cdf0e10cSrcweir }
1581cdf0e10cSrcweir void __EXPORT ScUndoRefConversion::Undo()
1582cdf0e10cSrcweir {
1583cdf0e10cSrcweir     BeginUndo();
1584cdf0e10cSrcweir     if (pUndoDoc)
1585cdf0e10cSrcweir         DoChange(pUndoDoc);
1586cdf0e10cSrcweir     ScChangeTrack* pChangeTrack = pDocShell->GetDocument()->GetChangeTrack();
1587cdf0e10cSrcweir     if ( pChangeTrack )
1588cdf0e10cSrcweir         pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
1589cdf0e10cSrcweir     EndUndo();
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir void __EXPORT ScUndoRefConversion::Redo()
1593cdf0e10cSrcweir {
1594cdf0e10cSrcweir     BeginRedo();
1595cdf0e10cSrcweir     if (pRedoDoc)
1596cdf0e10cSrcweir         DoChange(pRedoDoc);
1597cdf0e10cSrcweir     SetChangeTrack();
1598cdf0e10cSrcweir     EndRedo();
1599cdf0e10cSrcweir }
1600cdf0e10cSrcweir 
1601cdf0e10cSrcweir void __EXPORT ScUndoRefConversion::Repeat(SfxRepeatTarget& rTarget)
1602cdf0e10cSrcweir {
1603cdf0e10cSrcweir     if (rTarget.ISA(ScTabViewTarget))
1604cdf0e10cSrcweir         ((ScTabViewTarget&)rTarget).GetViewShell()->DoRefConversion();
1605cdf0e10cSrcweir }
1606cdf0e10cSrcweir 
1607cdf0e10cSrcweir sal_Bool __EXPORT ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const
1608cdf0e10cSrcweir {
1609cdf0e10cSrcweir     return (rTarget.ISA(ScTabViewTarget));
1610cdf0e10cSrcweir }
1611cdf0e10cSrcweir //============================================================================
1612cdf0e10cSrcweir //	class ScUndoRefreshLink
1613cdf0e10cSrcweir //
1614cdf0e10cSrcweir //	Link aktualisieren / aendern
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir //----------------------------------------------------------------------------
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir ScUndoRefreshLink::ScUndoRefreshLink( ScDocShell* pNewDocShell,
1619cdf0e10cSrcweir 									ScDocument* pNewUndoDoc )
1620cdf0e10cSrcweir 		//
1621cdf0e10cSrcweir 	:	ScSimpleUndo( pNewDocShell ),
1622cdf0e10cSrcweir 		//
1623cdf0e10cSrcweir 		pUndoDoc( pNewUndoDoc ),
1624cdf0e10cSrcweir 		pRedoDoc( NULL )
1625cdf0e10cSrcweir {
1626cdf0e10cSrcweir }
1627cdf0e10cSrcweir 
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir //----------------------------------------------------------------------------
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir __EXPORT ScUndoRefreshLink::~ScUndoRefreshLink()
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir 	delete pUndoDoc;
1634cdf0e10cSrcweir 	delete pRedoDoc;
1635cdf0e10cSrcweir }
1636cdf0e10cSrcweir 
1637cdf0e10cSrcweir 
1638cdf0e10cSrcweir //----------------------------------------------------------------------------
1639cdf0e10cSrcweir 
1640cdf0e10cSrcweir String __EXPORT ScUndoRefreshLink::GetComment() const
1641cdf0e10cSrcweir {
1642cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );
1643cdf0e10cSrcweir }
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir //----------------------------------------------------------------------------
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir void __EXPORT ScUndoRefreshLink::Undo()
1649cdf0e10cSrcweir {
1650cdf0e10cSrcweir 	BeginUndo();
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir 	sal_Bool bMakeRedo = !pRedoDoc;
1653cdf0e10cSrcweir 	if (bMakeRedo)
1654cdf0e10cSrcweir 		pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir 	sal_Bool bFirst = sal_True;
1657cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1658cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
1659cdf0e10cSrcweir 	for (SCTAB nTab=0; nTab<nCount; nTab++)
1660cdf0e10cSrcweir 		if (pUndoDoc->HasTable(nTab))
1661cdf0e10cSrcweir 		{
1662cdf0e10cSrcweir 			ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1663cdf0e10cSrcweir 			if (bMakeRedo)
1664cdf0e10cSrcweir 			{
1665cdf0e10cSrcweir 				if (bFirst)
1666cdf0e10cSrcweir 					pRedoDoc->InitUndo( pDoc, nTab, nTab, sal_True, sal_True );
1667cdf0e10cSrcweir 				else
1668cdf0e10cSrcweir 					pRedoDoc->AddUndoTab( nTab, nTab, sal_True, sal_True );
1669cdf0e10cSrcweir 				bFirst = sal_False;
1670cdf0e10cSrcweir 				pDoc->CopyToDocument(aRange, IDF_ALL, sal_False, pRedoDoc);
1671cdf0e10cSrcweir //				pRedoDoc->TransferDrawPage( pDoc, nTab, nTab );
1672cdf0e10cSrcweir 				pRedoDoc->SetLink( nTab,
1673cdf0e10cSrcweir 								   pDoc->GetLinkMode(nTab),
1674cdf0e10cSrcweir 								   pDoc->GetLinkDoc(nTab),
1675cdf0e10cSrcweir 								   pDoc->GetLinkFlt(nTab),
1676cdf0e10cSrcweir 								   pDoc->GetLinkOpt(nTab),
1677cdf0e10cSrcweir 								   pDoc->GetLinkTab(nTab),
1678cdf0e10cSrcweir 								   pDoc->GetLinkRefreshDelay(nTab) );
1679cdf0e10cSrcweir 			}
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir 			pDoc->DeleteAreaTab( aRange,IDF_ALL );
1682cdf0e10cSrcweir 			pUndoDoc->CopyToDocument( aRange, IDF_ALL, sal_False, pDoc );
1683cdf0e10cSrcweir //			pDoc->TransferDrawPage( pUndoDoc, nTab, nTab );
1684cdf0e10cSrcweir 			pDoc->SetLink( nTab, pUndoDoc->GetLinkMode(nTab), pUndoDoc->GetLinkDoc(nTab),
1685cdf0e10cSrcweir 								 pUndoDoc->GetLinkFlt(nTab),  pUndoDoc->GetLinkOpt(nTab),
1686cdf0e10cSrcweir 								 pUndoDoc->GetLinkTab(nTab),
1687cdf0e10cSrcweir 								 pUndoDoc->GetLinkRefreshDelay(nTab) );
1688cdf0e10cSrcweir 		}
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir 	pDocShell->PostPaintGridAll();
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir 	EndUndo();
1693cdf0e10cSrcweir }
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir //----------------------------------------------------------------------------
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir void __EXPORT ScUndoRefreshLink::Redo()
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir 	DBG_ASSERT(pRedoDoc, "Kein RedoDoc bei ScUndoRefreshLink::Redo");
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir 	BeginUndo();
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1705cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
1706cdf0e10cSrcweir 	for (SCTAB nTab=0; nTab<nCount; nTab++)
1707cdf0e10cSrcweir 		if (pRedoDoc->HasTable(nTab))
1708cdf0e10cSrcweir 		{
1709cdf0e10cSrcweir 			ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir 			pDoc->DeleteAreaTab( aRange, IDF_ALL );
1712cdf0e10cSrcweir 			pRedoDoc->CopyToDocument( aRange, IDF_ALL, sal_False, pDoc );
1713cdf0e10cSrcweir //			pDoc->TransferDrawPage( pRedoDoc, nTab, nTab );
1714cdf0e10cSrcweir 			pDoc->SetLink( nTab,
1715cdf0e10cSrcweir 						   pRedoDoc->GetLinkMode(nTab),
1716cdf0e10cSrcweir 						   pRedoDoc->GetLinkDoc(nTab),
1717cdf0e10cSrcweir 						   pRedoDoc->GetLinkFlt(nTab),
1718cdf0e10cSrcweir 						   pRedoDoc->GetLinkOpt(nTab),
1719cdf0e10cSrcweir 						   pRedoDoc->GetLinkTab(nTab),
1720cdf0e10cSrcweir 						   pRedoDoc->GetLinkRefreshDelay(nTab) );
1721cdf0e10cSrcweir 		}
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir 	pDocShell->PostPaintGridAll();
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir 	EndUndo();
1726cdf0e10cSrcweir }
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir 
1729cdf0e10cSrcweir //----------------------------------------------------------------------------
1730cdf0e10cSrcweir 
1731cdf0e10cSrcweir void __EXPORT ScUndoRefreshLink::Repeat(SfxRepeatTarget& /* rTarget */)
1732cdf0e10cSrcweir {
1733cdf0e10cSrcweir 	//	gippsnich
1734cdf0e10cSrcweir }
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir 
1737cdf0e10cSrcweir //----------------------------------------------------------------------------
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir sal_Bool __EXPORT ScUndoRefreshLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1740cdf0e10cSrcweir {
1741cdf0e10cSrcweir 	return sal_False;
1742cdf0e10cSrcweir }
1743cdf0e10cSrcweir 
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir //----------------------------------------------------------------------------
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir ScAreaLink* lcl_FindAreaLink( sfx2::LinkManager* pLinkManager, const String& rDoc,
1748cdf0e10cSrcweir 							const String& rFlt, const String& rOpt,
1749cdf0e10cSrcweir 							const String& rSrc, const ScRange& rDest )
1750cdf0e10cSrcweir {
1751cdf0e10cSrcweir     const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
1752cdf0e10cSrcweir 	sal_uInt16 nCount = pLinkManager->GetLinks().Count();
1753cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nCount; i++)
1754cdf0e10cSrcweir 	{
1755cdf0e10cSrcweir         ::sfx2::SvBaseLink* pBase = *rLinks[i];
1756cdf0e10cSrcweir 		if (pBase->ISA(ScAreaLink))
1757cdf0e10cSrcweir 			if ( ((ScAreaLink*)pBase)->IsEqual( rDoc, rFlt, rOpt, rSrc, rDest ) )
1758cdf0e10cSrcweir 				return (ScAreaLink*)pBase;
1759cdf0e10cSrcweir 	}
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir 	DBG_ERROR("ScAreaLink nicht gefunden");
1762cdf0e10cSrcweir 	return NULL;
1763cdf0e10cSrcweir }
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir 
1766cdf0e10cSrcweir //============================================================================
1767cdf0e10cSrcweir //	class ScUndoInsertAreaLink
1768cdf0e10cSrcweir //
1769cdf0e10cSrcweir //	Bereichs-Verknuepfung einfuegen
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir //----------------------------------------------------------------------------
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir ScUndoInsertAreaLink::ScUndoInsertAreaLink( ScDocShell* pShell,
1774cdf0e10cSrcweir 							const String& rDoc,
1775cdf0e10cSrcweir 							const String& rFlt, const String& rOpt,
1776cdf0e10cSrcweir 							const String& rArea, const ScRange& rDestRange,
1777cdf0e10cSrcweir 							sal_uLong nRefresh )
1778cdf0e10cSrcweir 		//
1779cdf0e10cSrcweir 	:	ScSimpleUndo	( pShell ),
1780cdf0e10cSrcweir 		//
1781cdf0e10cSrcweir 		aDocName		( rDoc ),
1782cdf0e10cSrcweir 		aFltName		( rFlt ),
1783cdf0e10cSrcweir 		aOptions		( rOpt ),
1784cdf0e10cSrcweir 		aAreaName		( rArea ),
1785cdf0e10cSrcweir 		aRange			( rDestRange ),
1786cdf0e10cSrcweir 		nRefreshDelay	( nRefresh )
1787cdf0e10cSrcweir {
1788cdf0e10cSrcweir }
1789cdf0e10cSrcweir 
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir //----------------------------------------------------------------------------
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir __EXPORT ScUndoInsertAreaLink::~ScUndoInsertAreaLink()
1794cdf0e10cSrcweir {
1795cdf0e10cSrcweir }
1796cdf0e10cSrcweir 
1797cdf0e10cSrcweir 
1798cdf0e10cSrcweir //----------------------------------------------------------------------------
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir String __EXPORT ScUndoInsertAreaLink::GetComment() const
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_INSERTAREALINK );
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir //----------------------------------------------------------------------------
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir void __EXPORT ScUndoInsertAreaLink::Undo()
1809cdf0e10cSrcweir {
1810cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1811cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir 	ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1814cdf0e10cSrcweir 											aAreaName, aRange );
1815cdf0e10cSrcweir 	if (pLink)
1816cdf0e10cSrcweir 		pLinkManager->Remove( pLink );
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );		// Navigator
1819cdf0e10cSrcweir }
1820cdf0e10cSrcweir 
1821cdf0e10cSrcweir 
1822cdf0e10cSrcweir //----------------------------------------------------------------------------
1823cdf0e10cSrcweir 
1824cdf0e10cSrcweir void __EXPORT ScUndoInsertAreaLink::Redo()
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1827cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1828cdf0e10cSrcweir 
1829cdf0e10cSrcweir 	ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1830cdf0e10cSrcweir 											aAreaName, aRange.aStart, nRefreshDelay );
1831cdf0e10cSrcweir 	pLink->SetInCreate( sal_True );
1832cdf0e10cSrcweir 	pLink->SetDestArea( aRange );
1833cdf0e10cSrcweir 	pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1834cdf0e10cSrcweir 	pLink->Update();
1835cdf0e10cSrcweir 	pLink->SetInCreate( sal_False );
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );		// Navigator
1838cdf0e10cSrcweir }
1839cdf0e10cSrcweir 
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir //----------------------------------------------------------------------------
1842cdf0e10cSrcweir 
1843cdf0e10cSrcweir void __EXPORT ScUndoInsertAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1844cdf0e10cSrcweir {
1845cdf0e10cSrcweir 	//!	....
1846cdf0e10cSrcweir }
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir 
1849cdf0e10cSrcweir //----------------------------------------------------------------------------
1850cdf0e10cSrcweir 
1851cdf0e10cSrcweir sal_Bool __EXPORT ScUndoInsertAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1852cdf0e10cSrcweir {
1853cdf0e10cSrcweir 	return sal_False;
1854cdf0e10cSrcweir }
1855cdf0e10cSrcweir 
1856cdf0e10cSrcweir 
1857cdf0e10cSrcweir //============================================================================
1858cdf0e10cSrcweir //	class ScUndoRemoveAreaLink
1859cdf0e10cSrcweir //
1860cdf0e10cSrcweir //	Bereichs-Verknuepfung loeschen
1861cdf0e10cSrcweir 
1862cdf0e10cSrcweir //----------------------------------------------------------------------------
1863cdf0e10cSrcweir 
1864cdf0e10cSrcweir ScUndoRemoveAreaLink::ScUndoRemoveAreaLink( ScDocShell* pShell,
1865cdf0e10cSrcweir 							const String& rDoc, const String& rFlt, const String& rOpt,
1866cdf0e10cSrcweir 							const String& rArea, const ScRange& rDestRange,
1867cdf0e10cSrcweir 							sal_uLong nRefresh )
1868cdf0e10cSrcweir 		//
1869cdf0e10cSrcweir 	:	ScSimpleUndo	( pShell ),
1870cdf0e10cSrcweir 		//
1871cdf0e10cSrcweir 		aDocName		( rDoc ),
1872cdf0e10cSrcweir 		aFltName		( rFlt ),
1873cdf0e10cSrcweir 		aOptions		( rOpt ),
1874cdf0e10cSrcweir 		aAreaName		( rArea ),
1875cdf0e10cSrcweir 		aRange			( rDestRange ),
1876cdf0e10cSrcweir 		nRefreshDelay	( nRefresh )
1877cdf0e10cSrcweir {
1878cdf0e10cSrcweir }
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir //----------------------------------------------------------------------------
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir __EXPORT ScUndoRemoveAreaLink::~ScUndoRemoveAreaLink()
1884cdf0e10cSrcweir {
1885cdf0e10cSrcweir }
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir 
1888cdf0e10cSrcweir //----------------------------------------------------------------------------
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir String __EXPORT ScUndoRemoveAreaLink::GetComment() const
1891cdf0e10cSrcweir {
1892cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );	//! eigener Text ??
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 
1896cdf0e10cSrcweir //----------------------------------------------------------------------------
1897cdf0e10cSrcweir 
1898cdf0e10cSrcweir void __EXPORT ScUndoRemoveAreaLink::Undo()
1899cdf0e10cSrcweir {
1900cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1901cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir 	ScAreaLink* pLink = new ScAreaLink( pDocShell, aDocName, aFltName, aOptions,
1904cdf0e10cSrcweir 										aAreaName, aRange.aStart, nRefreshDelay );
1905cdf0e10cSrcweir 	pLink->SetInCreate( sal_True );
1906cdf0e10cSrcweir 	pLink->SetDestArea( aRange );
1907cdf0e10cSrcweir 	pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName, &aAreaName );
1908cdf0e10cSrcweir 	pLink->Update();
1909cdf0e10cSrcweir 	pLink->SetInCreate( sal_False );
1910cdf0e10cSrcweir 
1911cdf0e10cSrcweir 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );		// Navigator
1912cdf0e10cSrcweir }
1913cdf0e10cSrcweir 
1914cdf0e10cSrcweir 
1915cdf0e10cSrcweir //----------------------------------------------------------------------------
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir void __EXPORT ScUndoRemoveAreaLink::Redo()
1918cdf0e10cSrcweir {
1919cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
1920cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
1921cdf0e10cSrcweir 
1922cdf0e10cSrcweir 	ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aDocName, aFltName, aOptions,
1923cdf0e10cSrcweir 											aAreaName, aRange );
1924cdf0e10cSrcweir 	if (pLink)
1925cdf0e10cSrcweir 		pLinkManager->Remove( pLink );
1926cdf0e10cSrcweir 
1927cdf0e10cSrcweir 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );		// Navigator
1928cdf0e10cSrcweir }
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir 
1931cdf0e10cSrcweir //----------------------------------------------------------------------------
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir void __EXPORT ScUndoRemoveAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
1934cdf0e10cSrcweir {
1935cdf0e10cSrcweir 	//	gippsnich
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir 
1938cdf0e10cSrcweir 
1939cdf0e10cSrcweir //----------------------------------------------------------------------------
1940cdf0e10cSrcweir 
1941cdf0e10cSrcweir sal_Bool __EXPORT ScUndoRemoveAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
1942cdf0e10cSrcweir {
1943cdf0e10cSrcweir 	return sal_False;
1944cdf0e10cSrcweir }
1945cdf0e10cSrcweir 
1946cdf0e10cSrcweir 
1947cdf0e10cSrcweir //============================================================================
1948cdf0e10cSrcweir //	class ScUndoUpdateAreaLink
1949cdf0e10cSrcweir //
1950cdf0e10cSrcweir //	Bereichs-Verknuepfung aktualisieren
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir //----------------------------------------------------------------------------
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
1955cdf0e10cSrcweir 							const String& rOldD, const String& rOldF, const String& rOldO,
1956cdf0e10cSrcweir 							const String& rOldA, const ScRange& rOldR, sal_uLong nOldRD,
1957cdf0e10cSrcweir 							const String& rNewD, const String& rNewF, const String& rNewO,
1958cdf0e10cSrcweir 							const String& rNewA, const ScRange& rNewR, sal_uLong nNewRD,
1959cdf0e10cSrcweir 							ScDocument* pUndo, ScDocument* pRedo, sal_Bool bDoInsert )
1960cdf0e10cSrcweir 		//
1961cdf0e10cSrcweir 	:	ScSimpleUndo( pShell ),
1962cdf0e10cSrcweir 		//
1963cdf0e10cSrcweir 		aOldDoc		( rOldD ),
1964cdf0e10cSrcweir 		aOldFlt		( rOldF ),
1965cdf0e10cSrcweir 		aOldOpt		( rOldO ),
1966cdf0e10cSrcweir 		aOldArea	( rOldA ),
1967cdf0e10cSrcweir 		aOldRange	( rOldR ),
1968cdf0e10cSrcweir 		aNewDoc		( rNewD ),
1969cdf0e10cSrcweir 		aNewFlt		( rNewF ),
1970cdf0e10cSrcweir 		aNewOpt		( rNewO ),
1971cdf0e10cSrcweir 		aNewArea	( rNewA ),
1972cdf0e10cSrcweir 		aNewRange	( rNewR ),
1973cdf0e10cSrcweir 		pUndoDoc	( pUndo ),
1974cdf0e10cSrcweir 		pRedoDoc	( pRedo ),
1975cdf0e10cSrcweir 		nOldRefresh	( nOldRD ),
1976cdf0e10cSrcweir 		nNewRefresh	( nNewRD ),
1977cdf0e10cSrcweir 		bWithInsert	( bDoInsert )
1978cdf0e10cSrcweir {
1979cdf0e10cSrcweir 	DBG_ASSERT( aOldRange.aStart == aNewRange.aStart, "AreaLink verschoben ?" );
1980cdf0e10cSrcweir }
1981cdf0e10cSrcweir 
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir //----------------------------------------------------------------------------
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir __EXPORT ScUndoUpdateAreaLink::~ScUndoUpdateAreaLink()
1986cdf0e10cSrcweir {
1987cdf0e10cSrcweir 	delete pUndoDoc;
1988cdf0e10cSrcweir 	delete pRedoDoc;
1989cdf0e10cSrcweir }
1990cdf0e10cSrcweir 
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir //----------------------------------------------------------------------------
1993cdf0e10cSrcweir 
1994cdf0e10cSrcweir String __EXPORT ScUndoUpdateAreaLink::GetComment() const
1995cdf0e10cSrcweir {
1996cdf0e10cSrcweir 	return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );	//! eigener Text ??
1997cdf0e10cSrcweir }
1998cdf0e10cSrcweir 
1999cdf0e10cSrcweir 
2000cdf0e10cSrcweir //----------------------------------------------------------------------------
2001cdf0e10cSrcweir 
2002cdf0e10cSrcweir void ScUndoUpdateAreaLink::DoChange( const sal_Bool bUndo ) const
2003cdf0e10cSrcweir {
2004cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
2005cdf0e10cSrcweir 
2006cdf0e10cSrcweir 	SCCOL nEndX = Max( aOldRange.aEnd.Col(), aNewRange.aEnd.Col() );
2007cdf0e10cSrcweir 	SCROW nEndY = Max( aOldRange.aEnd.Row(), aNewRange.aEnd.Row() );
2008cdf0e10cSrcweir 	SCTAB nEndZ = Max( aOldRange.aEnd.Tab(), aNewRange.aEnd.Tab() );	//?
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir 	if ( bUndo )
2011cdf0e10cSrcweir 	{
2012cdf0e10cSrcweir 		if ( bWithInsert )
2013cdf0e10cSrcweir 		{
2014cdf0e10cSrcweir 			pDoc->FitBlock( aNewRange, aOldRange );
2015cdf0e10cSrcweir             pDoc->DeleteAreaTab( aOldRange, IDF_ALL & ~IDF_NOTE );
2016cdf0e10cSrcweir             pUndoDoc->UndoToDocument( aOldRange, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
2017cdf0e10cSrcweir 		}
2018cdf0e10cSrcweir 		else
2019cdf0e10cSrcweir 		{
2020cdf0e10cSrcweir 			ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
2021cdf0e10cSrcweir             pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
2022cdf0e10cSrcweir             pUndoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
2023cdf0e10cSrcweir 		}
2024cdf0e10cSrcweir 	}
2025cdf0e10cSrcweir 	else
2026cdf0e10cSrcweir 	{
2027cdf0e10cSrcweir 		if ( bWithInsert )
2028cdf0e10cSrcweir 		{
2029cdf0e10cSrcweir 			pDoc->FitBlock( aOldRange, aNewRange );
2030cdf0e10cSrcweir             pDoc->DeleteAreaTab( aNewRange, IDF_ALL & ~IDF_NOTE );
2031cdf0e10cSrcweir             pRedoDoc->CopyToDocument( aNewRange, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
2032cdf0e10cSrcweir 		}
2033cdf0e10cSrcweir 		else
2034cdf0e10cSrcweir 		{
2035cdf0e10cSrcweir 			ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
2036cdf0e10cSrcweir             pDoc->DeleteAreaTab( aCopyRange, IDF_ALL & ~IDF_NOTE );
2037cdf0e10cSrcweir             pRedoDoc->CopyToDocument( aCopyRange, IDF_ALL & ~IDF_NOTE, sal_False, pDoc );
2038cdf0e10cSrcweir 		}
2039cdf0e10cSrcweir 	}
2040cdf0e10cSrcweir 
2041cdf0e10cSrcweir 	ScRange aWorkRange( aNewRange.aStart, ScAddress( nEndX, nEndY, nEndZ ) );
2042cdf0e10cSrcweir 	pDoc->ExtendMerge( aWorkRange, sal_True );
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir 	//	Paint
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir 	if ( aNewRange.aEnd.Col() != aOldRange.aEnd.Col() )
2047cdf0e10cSrcweir 		aWorkRange.aEnd.SetCol(MAXCOL);
2048cdf0e10cSrcweir 	if ( aNewRange.aEnd.Row() != aOldRange.aEnd.Row() )
2049cdf0e10cSrcweir 		aWorkRange.aEnd.SetRow(MAXROW);
2050cdf0e10cSrcweir 
2051cdf0e10cSrcweir 	if ( !pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), aWorkRange.aStart.Tab() ) )
2052cdf0e10cSrcweir 		pDocShell->PostPaint( aWorkRange, PAINT_GRID );
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir 	pDocShell->PostDataChanged();
2055cdf0e10cSrcweir 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
2056cdf0e10cSrcweir 	if (pViewShell)
2057cdf0e10cSrcweir 		pViewShell->CellContentChanged();
2058cdf0e10cSrcweir }
2059cdf0e10cSrcweir 
2060cdf0e10cSrcweir 
2061cdf0e10cSrcweir //----------------------------------------------------------------------------
2062cdf0e10cSrcweir 
2063cdf0e10cSrcweir void __EXPORT ScUndoUpdateAreaLink::Undo()
2064cdf0e10cSrcweir {
2065cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
2066cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
2067cdf0e10cSrcweir 	ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aNewDoc, aNewFlt, aNewOpt,
2068cdf0e10cSrcweir 											aNewArea, aNewRange );
2069cdf0e10cSrcweir 	if (pLink)
2070cdf0e10cSrcweir 	{
2071cdf0e10cSrcweir 		pLink->SetSource( aOldDoc, aOldFlt, aOldOpt, aOldArea );		// alte Werte im Link
2072cdf0e10cSrcweir 		pLink->SetDestArea( aOldRange );
2073cdf0e10cSrcweir 		pLink->SetRefreshDelay( nOldRefresh );
2074cdf0e10cSrcweir 	}
2075cdf0e10cSrcweir 
2076cdf0e10cSrcweir 	DoChange(sal_True);
2077cdf0e10cSrcweir }
2078cdf0e10cSrcweir 
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir //----------------------------------------------------------------------------
2081cdf0e10cSrcweir 
2082cdf0e10cSrcweir void __EXPORT ScUndoUpdateAreaLink::Redo()
2083cdf0e10cSrcweir {
2084cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
2085cdf0e10cSrcweir 	sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
2086cdf0e10cSrcweir 	ScAreaLink* pLink = lcl_FindAreaLink( pLinkManager, aOldDoc, aOldFlt, aOldOpt,
2087cdf0e10cSrcweir 											aOldArea, aOldRange );
2088cdf0e10cSrcweir 	if (pLink)
2089cdf0e10cSrcweir 	{
2090cdf0e10cSrcweir 		pLink->SetSource( aNewDoc, aNewFlt, aNewOpt, aNewArea );		// neue Werte im Link
2091cdf0e10cSrcweir 		pLink->SetDestArea( aNewRange );
2092cdf0e10cSrcweir 		pLink->SetRefreshDelay( nNewRefresh );
2093cdf0e10cSrcweir 	}
2094cdf0e10cSrcweir 
2095cdf0e10cSrcweir 	DoChange(sal_False);
2096cdf0e10cSrcweir }
2097cdf0e10cSrcweir 
2098cdf0e10cSrcweir 
2099cdf0e10cSrcweir //----------------------------------------------------------------------------
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir void __EXPORT ScUndoUpdateAreaLink::Repeat(SfxRepeatTarget& /* rTarget */)
2102cdf0e10cSrcweir {
2103cdf0e10cSrcweir 	//	gippsnich
2104cdf0e10cSrcweir }
2105cdf0e10cSrcweir 
2106cdf0e10cSrcweir 
2107cdf0e10cSrcweir //----------------------------------------------------------------------------
2108cdf0e10cSrcweir 
2109cdf0e10cSrcweir sal_Bool __EXPORT ScUndoUpdateAreaLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
2110cdf0e10cSrcweir {
2111cdf0e10cSrcweir 	return sal_False;
2112cdf0e10cSrcweir }
2113cdf0e10cSrcweir 
2114cdf0e10cSrcweir 
2115cdf0e10cSrcweir 
2116cdf0e10cSrcweir 
2117