xref: /AOO41X/main/sc/source/ui/docshell/docsh5.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // System - Includes -----------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "scitems.hxx"
37*cdf0e10cSrcweir #include <vcl/svapp.hxx>
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
40*cdf0e10cSrcweir #include <sfx2/app.hxx>
41*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
42*cdf0e10cSrcweir #include <svl/smplhint.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include "docsh.hxx"
47*cdf0e10cSrcweir #include "global.hxx"
48*cdf0e10cSrcweir #include "globstr.hrc"
49*cdf0e10cSrcweir #include "undodat.hxx"
50*cdf0e10cSrcweir #include "undotab.hxx"
51*cdf0e10cSrcweir #include "undoblk.hxx"
52*cdf0e10cSrcweir //#include "pivot.hxx"
53*cdf0e10cSrcweir #include "dpobject.hxx"
54*cdf0e10cSrcweir #include "dpshttab.hxx"
55*cdf0e10cSrcweir #include "dbdocfun.hxx"
56*cdf0e10cSrcweir #include "consoli.hxx"
57*cdf0e10cSrcweir #include "dbcolect.hxx"
58*cdf0e10cSrcweir #include "olinetab.hxx"
59*cdf0e10cSrcweir #include "patattr.hxx"
60*cdf0e10cSrcweir #include "attrib.hxx"
61*cdf0e10cSrcweir #include "docpool.hxx"
62*cdf0e10cSrcweir #include "uiitems.hxx"
63*cdf0e10cSrcweir #include "sc.hrc"
64*cdf0e10cSrcweir #include "waitoff.hxx"
65*cdf0e10cSrcweir #include "sizedev.hxx"
66*cdf0e10cSrcweir #include <basic/sbstar.hxx>
67*cdf0e10cSrcweir #include <basic/basmgr.hxx>
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir // defined in docfunc.cxx
70*cdf0e10cSrcweir void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, String& sModuleName, String& sModuleSource );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir // ---------------------------------------------------------------------------
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir //
75*cdf0e10cSrcweir //	ehemalige viewfunc/dbfunc Methoden
76*cdf0e10cSrcweir //
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir void ScDocShell::ErrorMessage( sal_uInt16 nGlobStrId )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	//!	StopMarking an der (aktiven) View?
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	Window* pParent = GetActiveDialogParent();
83*cdf0e10cSrcweir 	ScWaitCursorOff aWaitOff( pParent );
84*cdf0e10cSrcweir 	sal_Bool bFocus = pParent && pParent->HasFocus();
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	if(nGlobStrId==STR_PROTECTIONERR)
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		if(IsReadOnly())
89*cdf0e10cSrcweir 		{
90*cdf0e10cSrcweir 			nGlobStrId=STR_READONLYERR;
91*cdf0e10cSrcweir 		}
92*cdf0e10cSrcweir 	}
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	InfoBox aBox( pParent, ScGlobal::GetRscString( nGlobStrId ) );
95*cdf0e10cSrcweir 	aBox.Execute();
96*cdf0e10cSrcweir 	if (bFocus)
97*cdf0e10cSrcweir 		pParent->GrabFocus();
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir sal_Bool ScDocShell::IsEditable() const
101*cdf0e10cSrcweir {
102*cdf0e10cSrcweir 	// import into read-only document is possible - must be extended if other filters use api
103*cdf0e10cSrcweir 	// #i108547# MSOOXML filter uses "IsChangeReadOnlyEnabled" property
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	return !IsReadOnly() || aDocument.IsImportingXML() || aDocument.IsChangeReadOnlyEnabled();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void ScDocShell::DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW /* nY2 */ )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	ScDocShellModificator aModificator( *this );
111*cdf0e10cSrcweir 	aDocument.RemoveFlagsTab( nX1, nY1, nX2, nY1, nTab, SC_MF_AUTO );
112*cdf0e10cSrcweir 	PostPaint( nX1, nY1, nTab, nX2, nY1, nTab, PAINT_GRID );
113*cdf0e10cSrcweir     // No SetDocumentModified, as the unnamed database range might have to be restored later.
114*cdf0e10cSrcweir     // The UNO hint is broadcast directly instead, to keep UNO objects in valid state.
115*cdf0e10cSrcweir     aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir ScDBData* lcl_GetDBNearCursor( ScDBCollection* pColl, SCCOL nCol, SCROW nRow, SCTAB nTab )
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	//!	nach document/dbcolect verschieben
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	if (!pColl)
123*cdf0e10cSrcweir 		return NULL;
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir 	ScDBData* pNoNameData = NULL;
126*cdf0e10cSrcweir 	ScDBData* pNearData = NULL;
127*cdf0e10cSrcweir 	sal_uInt16 nCount = pColl->GetCount();
128*cdf0e10cSrcweir 	String aNoName = ScGlobal::GetRscString( STR_DB_NONAME );
129*cdf0e10cSrcweir 	SCTAB nAreaTab;
130*cdf0e10cSrcweir 	SCCOL nStartCol, nEndCol;
131*cdf0e10cSrcweir 	SCROW nStartRow, nEndRow;
132*cdf0e10cSrcweir 	for (sal_uInt16 i = 0; i < nCount; i++)
133*cdf0e10cSrcweir 	{
134*cdf0e10cSrcweir 		ScDBData* pDB = (*pColl)[i];
135*cdf0e10cSrcweir 		pDB->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow );
136*cdf0e10cSrcweir 		if ( nTab == nAreaTab && nCol+1 >= nStartCol && nCol <= nEndCol+1 &&
137*cdf0e10cSrcweir 								 nRow+1 >= nStartRow && nRow <= nEndRow+1 )
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			if ( pDB->GetName() == aNoName )
140*cdf0e10cSrcweir 				pNoNameData = pDB;
141*cdf0e10cSrcweir 			else if ( nCol < nStartCol || nCol > nEndCol || nRow < nStartRow || nRow > nEndRow )
142*cdf0e10cSrcweir 			{
143*cdf0e10cSrcweir 				if (!pNearData)
144*cdf0e10cSrcweir 					pNearData = pDB;	// ersten angrenzenden Bereich merken
145*cdf0e10cSrcweir 			}
146*cdf0e10cSrcweir 			else
147*cdf0e10cSrcweir 				return pDB;				// nicht "unbenannt" und Cursor steht wirklich drin
148*cdf0e10cSrcweir 		}
149*cdf0e10cSrcweir 	}
150*cdf0e10cSrcweir 	if (pNearData)
151*cdf0e10cSrcweir 		return pNearData;				// angrenzender, wenn nichts direkt getroffen
152*cdf0e10cSrcweir 	return pNoNameData;					// "unbenannt" nur zurueck, wenn sonst nichts gefunden
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	SCCOL nCol = rMarked.aStart.Col();
158*cdf0e10cSrcweir 	SCROW nRow = rMarked.aStart.Row();
159*cdf0e10cSrcweir 	SCTAB nTab = rMarked.aStart.Tab();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	SCCOL nStartCol = nCol;
162*cdf0e10cSrcweir 	SCROW nStartRow = nRow;
163*cdf0e10cSrcweir 	SCTAB nStartTab = nTab;
164*cdf0e10cSrcweir 	SCCOL nEndCol = rMarked.aEnd.Col();
165*cdf0e10cSrcweir 	SCROW nEndRow = rMarked.aEnd.Row();
166*cdf0e10cSrcweir 	SCTAB nEndTab = rMarked.aEnd.Tab();
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	//	Wegen #49655# nicht einfach GetDBAtCursor: Der zusammenhaengende Datenbereich
169*cdf0e10cSrcweir 	//	fuer "unbenannt" (GetDataArea) kann neben dem Cursor legen, also muss auch ein
170*cdf0e10cSrcweir 	//	benannter DB-Bereich dort gesucht werden.
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 	ScDBData* pData = aDocument.GetDBAtArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow );
173*cdf0e10cSrcweir 	if (!pData)
174*cdf0e10cSrcweir 		pData = lcl_GetDBNearCursor( aDocument.GetDBCollection(), nCol, nRow, nTab );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	sal_Bool bSelected = ( eSel == SC_DBSEL_FORCE_MARK ||
177*cdf0e10cSrcweir             (rMarked.aStart != rMarked.aEnd && eSel != SC_DBSEL_ROW_DOWN) );
178*cdf0e10cSrcweir     bool bOnlyDown = (!bSelected && eSel == SC_DBSEL_ROW_DOWN && rMarked.aStart.Row() == rMarked.aEnd.Row());
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	sal_Bool bUseThis = sal_False;
181*cdf0e10cSrcweir 	if (pData)
182*cdf0e10cSrcweir 	{
183*cdf0e10cSrcweir 		//		Bereich nehmen, wenn nichts anderes markiert
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 		SCTAB nDummy;
186*cdf0e10cSrcweir 		SCCOL nOldCol1;
187*cdf0e10cSrcweir 		SCROW nOldRow1;
188*cdf0e10cSrcweir 		SCCOL nOldCol2;
189*cdf0e10cSrcweir 		SCROW nOldRow2;
190*cdf0e10cSrcweir 		pData->GetArea( nDummy, nOldCol1,nOldRow1, nOldCol2,nOldRow2 );
191*cdf0e10cSrcweir 		sal_Bool bIsNoName = ( pData->GetName() == ScGlobal::GetRscString( STR_DB_NONAME ) );
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		if (!bSelected)
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir 			bUseThis = sal_True;
196*cdf0e10cSrcweir 			if ( bIsNoName && eMode == SC_DB_MAKE )
197*cdf0e10cSrcweir 			{
198*cdf0e10cSrcweir                 // If nothing marked or only one row marked, adapt
199*cdf0e10cSrcweir                 // "unbenannt"/"unnamed" to contiguous area.
200*cdf0e10cSrcweir                 nStartCol = nCol;
201*cdf0e10cSrcweir                 nStartRow = nRow;
202*cdf0e10cSrcweir                 if (bOnlyDown)
203*cdf0e10cSrcweir                 {
204*cdf0e10cSrcweir                     nEndCol = rMarked.aEnd.Col();
205*cdf0e10cSrcweir                     nEndRow = rMarked.aEnd.Row();
206*cdf0e10cSrcweir                 }
207*cdf0e10cSrcweir                 else
208*cdf0e10cSrcweir                 {
209*cdf0e10cSrcweir                     nEndCol = nStartCol;
210*cdf0e10cSrcweir                     nEndRow = nStartRow;
211*cdf0e10cSrcweir                 }
212*cdf0e10cSrcweir 				aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_False, bOnlyDown );
213*cdf0e10cSrcweir 				if ( nOldCol1 != nStartCol || nOldCol2 != nEndCol || nOldRow1 != nStartRow )
214*cdf0e10cSrcweir 					bUseThis = sal_False;				// passt gar nicht
215*cdf0e10cSrcweir 				else if ( nOldRow2 != nEndRow )
216*cdf0e10cSrcweir 				{
217*cdf0e10cSrcweir 					//	Bereich auf neue End-Zeile erweitern
218*cdf0e10cSrcweir 					pData->SetArea( nTab, nOldCol1,nOldRow1, nOldCol2,nEndRow );
219*cdf0e10cSrcweir 				}
220*cdf0e10cSrcweir 			}
221*cdf0e10cSrcweir 		}
222*cdf0e10cSrcweir 		else
223*cdf0e10cSrcweir 		{
224*cdf0e10cSrcweir 			if ( nOldCol1 == nStartCol && nOldRow1 == nStartRow &&
225*cdf0e10cSrcweir 				 nOldCol2 == nEndCol && nOldRow2 == nEndRow )				// genau markiert?
226*cdf0e10cSrcweir 				bUseThis = sal_True;
227*cdf0e10cSrcweir 			else
228*cdf0e10cSrcweir 				bUseThis = sal_False;			// immer Markierung nehmen (Bug 11964)
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 		//		fuer Import nie "unbenannt" nehmen
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 		if ( bUseThis && eMode == SC_DB_IMPORT && bIsNoName )
234*cdf0e10cSrcweir 			bUseThis = sal_False;
235*cdf0e10cSrcweir 	}
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 	if ( bUseThis )
238*cdf0e10cSrcweir 	{
239*cdf0e10cSrcweir 		pData->GetArea( nStartTab, nStartCol,nStartRow, nEndCol,nEndRow );
240*cdf0e10cSrcweir 		nEndTab = nStartTab;
241*cdf0e10cSrcweir 	}
242*cdf0e10cSrcweir 	else if ( eMode == SC_DB_OLD )
243*cdf0e10cSrcweir 	{
244*cdf0e10cSrcweir 		pData = NULL;							// nichts gefunden
245*cdf0e10cSrcweir 		nStartCol = nEndCol = nCol;
246*cdf0e10cSrcweir 		nStartRow = nEndRow = nRow;
247*cdf0e10cSrcweir 		nStartTab = nEndTab = nTab;
248*cdf0e10cSrcweir //		bMark = sal_False;							// nichts zu markieren
249*cdf0e10cSrcweir 	}
250*cdf0e10cSrcweir 	else
251*cdf0e10cSrcweir 	{
252*cdf0e10cSrcweir 		if ( bSelected )
253*cdf0e10cSrcweir 		{
254*cdf0e10cSrcweir //			bMark = sal_False;
255*cdf0e10cSrcweir 		}
256*cdf0e10cSrcweir 		else
257*cdf0e10cSrcweir 		{										// zusammenhaengender Bereich
258*cdf0e10cSrcweir 			nStartCol = nCol;
259*cdf0e10cSrcweir 			nStartRow = nRow;
260*cdf0e10cSrcweir             if (bOnlyDown)
261*cdf0e10cSrcweir             {
262*cdf0e10cSrcweir                 nEndCol = rMarked.aEnd.Col();
263*cdf0e10cSrcweir                 nEndRow = rMarked.aEnd.Row();
264*cdf0e10cSrcweir             }
265*cdf0e10cSrcweir             else
266*cdf0e10cSrcweir             {
267*cdf0e10cSrcweir                 nEndCol = nStartCol;
268*cdf0e10cSrcweir                 nEndRow = nStartRow;
269*cdf0e10cSrcweir             }
270*cdf0e10cSrcweir 			aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, sal_False, bOnlyDown );
271*cdf0e10cSrcweir 		}
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 		sal_Bool bHasHeader = aDocument.HasColHeader( nStartCol,nStartRow, nEndCol,nEndRow, nTab );
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 		ScDBData* pNoNameData;
276*cdf0e10cSrcweir 		sal_uInt16 nNoNameIndex;
277*cdf0e10cSrcweir 		ScDBCollection* pColl = aDocument.GetDBCollection();
278*cdf0e10cSrcweir 		if ( eMode != SC_DB_IMPORT &&
279*cdf0e10cSrcweir 				pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
280*cdf0e10cSrcweir 		{
281*cdf0e10cSrcweir 			pNoNameData = (*pColl)[nNoNameIndex];
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir             if ( !pOldAutoDBRange )
284*cdf0e10cSrcweir             {
285*cdf0e10cSrcweir                 // store the old unnamed database range with its settings for undo
286*cdf0e10cSrcweir                 // (store at the first change, get the state before all changes)
287*cdf0e10cSrcweir                 pOldAutoDBRange = new ScDBData( *pNoNameData );
288*cdf0e10cSrcweir             }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 			SCCOL nOldX1;									// alten Bereich sauber wegnehmen
291*cdf0e10cSrcweir 			SCROW nOldY1;									//! (UNDO ???)
292*cdf0e10cSrcweir 			SCCOL nOldX2;
293*cdf0e10cSrcweir 			SCROW nOldY2;
294*cdf0e10cSrcweir 			SCTAB nOldTab;
295*cdf0e10cSrcweir 			pNoNameData->GetArea( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 );
296*cdf0e10cSrcweir 			DBAreaDeleted( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 );
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 			pNoNameData->SetSortParam( ScSortParam() ); 			// Parameter zuruecksetzen
299*cdf0e10cSrcweir 			pNoNameData->SetQueryParam( ScQueryParam() );
300*cdf0e10cSrcweir 			pNoNameData->SetSubTotalParam( ScSubTotalParam() );
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir 			pNoNameData->SetArea( nTab, nStartCol,nStartRow, nEndCol,nEndRow ); 	// neu setzen
303*cdf0e10cSrcweir 			pNoNameData->SetByRow( sal_True );
304*cdf0e10cSrcweir 			pNoNameData->SetHeader( bHasHeader );
305*cdf0e10cSrcweir 			pNoNameData->SetAutoFilter( sal_False );
306*cdf0e10cSrcweir 		}
307*cdf0e10cSrcweir 		else
308*cdf0e10cSrcweir 		{
309*cdf0e10cSrcweir 			ScDBCollection* pUndoColl = NULL;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 			String aNewName;
312*cdf0e10cSrcweir 			if (eMode==SC_DB_IMPORT)
313*cdf0e10cSrcweir 			{
314*cdf0e10cSrcweir 				aDocument.CompileDBFormula( sal_True );			// CreateFormulaString
315*cdf0e10cSrcweir 				pUndoColl = new ScDBCollection( *pColl );	// Undo fuer Import1-Bereich
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 				String aImport = ScGlobal::GetRscString( STR_DBNAME_IMPORT );
318*cdf0e10cSrcweir 				long nCount = 0;
319*cdf0e10cSrcweir 				sal_uInt16 nDummy;
320*cdf0e10cSrcweir 				do
321*cdf0e10cSrcweir 				{
322*cdf0e10cSrcweir 					++nCount;
323*cdf0e10cSrcweir 					aNewName = aImport;
324*cdf0e10cSrcweir 					aNewName += String::CreateFromInt32( nCount );
325*cdf0e10cSrcweir 				}
326*cdf0e10cSrcweir 				while (pColl->SearchName( aNewName, nDummy ));
327*cdf0e10cSrcweir 			}
328*cdf0e10cSrcweir 			else
329*cdf0e10cSrcweir 				aNewName = ScGlobal::GetRscString( STR_DB_NONAME );
330*cdf0e10cSrcweir 			pNoNameData = new ScDBData( aNewName, nTab,
331*cdf0e10cSrcweir 								nStartCol,nStartRow, nEndCol,nEndRow,
332*cdf0e10cSrcweir 								sal_True, bHasHeader );
333*cdf0e10cSrcweir 			pColl->Insert( pNoNameData );
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 			if ( pUndoColl )
336*cdf0e10cSrcweir 			{
337*cdf0e10cSrcweir 				aDocument.CompileDBFormula( sal_False );		// CompileFormulaString
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 				ScDBCollection* pRedoColl = new ScDBCollection( *pColl );
340*cdf0e10cSrcweir 				GetUndoManager()->AddUndoAction( new ScUndoDBData( this, pUndoColl, pRedoColl ) );
341*cdf0e10cSrcweir 			}
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 			//	neuen Bereich am Sba anmelden nicht mehr noetig
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 			//	"Import1" etc am Navigator bekanntmachen
346*cdf0e10cSrcweir 			if (eMode==SC_DB_IMPORT)
347*cdf0e10cSrcweir 				SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
348*cdf0e10cSrcweir 		}
349*cdf0e10cSrcweir 		pData = pNoNameData;
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir //	if (bMark)
353*cdf0e10cSrcweir //		MarkRange( ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab ), sal_False );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	return pData;
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir ScDBData* ScDocShell::GetOldAutoDBRange()
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir     ScDBData* pRet = pOldAutoDBRange;
361*cdf0e10cSrcweir     pOldAutoDBRange = NULL;
362*cdf0e10cSrcweir     return pRet;                    // has to be deleted by caller!
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir void ScDocShell::CancelAutoDBRange()
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     // called when dialog is cancelled
368*cdf0e10cSrcweir     if ( pOldAutoDBRange )
369*cdf0e10cSrcweir     {
370*cdf0e10cSrcweir         sal_uInt16 nNoNameIndex;
371*cdf0e10cSrcweir         ScDBCollection* pColl = aDocument.GetDBCollection();
372*cdf0e10cSrcweir         if ( pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) )
373*cdf0e10cSrcweir         {
374*cdf0e10cSrcweir             ScDBData* pNoNameData = (*pColl)[nNoNameIndex];
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir             SCCOL nRangeX1;
377*cdf0e10cSrcweir             SCROW nRangeY1;
378*cdf0e10cSrcweir             SCCOL nRangeX2;
379*cdf0e10cSrcweir             SCROW nRangeY2;
380*cdf0e10cSrcweir             SCTAB nRangeTab;
381*cdf0e10cSrcweir             pNoNameData->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
382*cdf0e10cSrcweir             DBAreaDeleted( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir             *pNoNameData = *pOldAutoDBRange;    // restore old settings
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir             if ( pOldAutoDBRange->HasAutoFilter() )
387*cdf0e10cSrcweir             {
388*cdf0e10cSrcweir                 // restore AutoFilter buttons
389*cdf0e10cSrcweir                 pOldAutoDBRange->GetArea( nRangeTab, nRangeX1, nRangeY1, nRangeX2, nRangeY2 );
390*cdf0e10cSrcweir                 aDocument.ApplyFlagsTab( nRangeX1, nRangeY1, nRangeX2, nRangeY1, nRangeTab, SC_MF_AUTO );
391*cdf0e10cSrcweir                 PostPaint( nRangeX1, nRangeY1, nRangeTab, nRangeX2, nRangeY1, nRangeTab, PAINT_GRID );
392*cdf0e10cSrcweir             }
393*cdf0e10cSrcweir         }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         delete pOldAutoDBRange;
396*cdf0e10cSrcweir         pOldAutoDBRange = NULL;
397*cdf0e10cSrcweir     }
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 		//	Hoehen anpassen
402*cdf0e10cSrcweir 		//!	mit docfunc zusammenfassen
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir sal_Bool ScDocShell::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab )
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir 	ScSizeDeviceProvider aProv(this);
407*cdf0e10cSrcweir 	Fraction aZoom(1,1);
408*cdf0e10cSrcweir 	sal_Bool bChange = aDocument.SetOptimalHeight( nStartRow,nEndRow, nTab, 0, aProv.GetDevice(),
409*cdf0e10cSrcweir 												aProv.GetPPTX(),aProv.GetPPTY(), aZoom,aZoom, sal_False );
410*cdf0e10cSrcweir 	if (bChange)
411*cdf0e10cSrcweir 		PostPaint( 0,nStartRow,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID|PAINT_LEFT );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 	return bChange;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir void ScDocShell::UpdateAllRowHeights( const ScMarkData* pTabMark )
417*cdf0e10cSrcweir {
418*cdf0e10cSrcweir 	// update automatic row heights
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	ScSizeDeviceProvider aProv(this);
421*cdf0e10cSrcweir 	Fraction aZoom(1,1);
422*cdf0e10cSrcweir     aDocument.UpdateAllRowHeights( aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), aZoom, aZoom, pTabMark );
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir void ScDocShell::UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore )
426*cdf0e10cSrcweir {
427*cdf0e10cSrcweir     sal_Bool bIsUndoEnabled = aDocument.IsUndoEnabled();
428*cdf0e10cSrcweir     aDocument.EnableUndo( sal_False );
429*cdf0e10cSrcweir     aDocument.LockStreamValid( true );      // ignore draw page size (but not formula results)
430*cdf0e10cSrcweir     if ( bBefore )          // check all sheets up to nUpdateTab
431*cdf0e10cSrcweir     {
432*cdf0e10cSrcweir         SCTAB nTabCount = aDocument.GetTableCount();
433*cdf0e10cSrcweir         if ( nUpdateTab >= nTabCount )
434*cdf0e10cSrcweir             nUpdateTab = nTabCount-1;     // nUpdateTab is inclusive
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir         ScMarkData aUpdateSheets;
437*cdf0e10cSrcweir         SCTAB nTab;
438*cdf0e10cSrcweir         for (nTab=0; nTab<=nUpdateTab; ++nTab)
439*cdf0e10cSrcweir             if ( aDocument.IsPendingRowHeights( nTab ) )
440*cdf0e10cSrcweir                 aUpdateSheets.SelectTable( nTab, sal_True );
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         if (aUpdateSheets.GetSelectCount())
443*cdf0e10cSrcweir             UpdateAllRowHeights(&aUpdateSheets);        // update with a single progress bar
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir         for (nTab=0; nTab<=nUpdateTab; ++nTab)
446*cdf0e10cSrcweir             if ( aUpdateSheets.GetTableSelect( nTab ) )
447*cdf0e10cSrcweir             {
448*cdf0e10cSrcweir                 aDocument.UpdatePageBreaks( nTab );
449*cdf0e10cSrcweir                 aDocument.SetPendingRowHeights( nTab, sal_False );
450*cdf0e10cSrcweir             }
451*cdf0e10cSrcweir     }
452*cdf0e10cSrcweir     else                    // only nUpdateTab
453*cdf0e10cSrcweir     {
454*cdf0e10cSrcweir         if ( aDocument.IsPendingRowHeights( nUpdateTab ) )
455*cdf0e10cSrcweir         {
456*cdf0e10cSrcweir             AdjustRowHeight( 0, MAXROW, nUpdateTab );
457*cdf0e10cSrcweir             aDocument.UpdatePageBreaks( nUpdateTab );
458*cdf0e10cSrcweir             aDocument.SetPendingRowHeights( nUpdateTab, sal_False );
459*cdf0e10cSrcweir         }
460*cdf0e10cSrcweir     }
461*cdf0e10cSrcweir     aDocument.LockStreamValid( false );
462*cdf0e10cSrcweir     aDocument.EnableUndo( bIsUndoEnabled );
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir void ScDocShell::RefreshPivotTables( const ScRange& rSource )
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir 	//!	rename to RefreshDataPilotTables?
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 	ScDPCollection* pColl = aDocument.GetDPCollection();
470*cdf0e10cSrcweir 	if ( pColl )
471*cdf0e10cSrcweir 	{
472*cdf0e10cSrcweir 		//	DataPilotUpdate doesn't modify the collection order like PivotUpdate did,
473*cdf0e10cSrcweir 		//	so a simple loop can be used.
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 		sal_uInt16 nCount = pColl->GetCount();
476*cdf0e10cSrcweir 		for ( sal_uInt16 i=0; i<nCount; i++ )
477*cdf0e10cSrcweir 		{
478*cdf0e10cSrcweir 			ScDPObject* pOld = (*pColl)[i];
479*cdf0e10cSrcweir 			if ( pOld )
480*cdf0e10cSrcweir 			{
481*cdf0e10cSrcweir 				const ScSheetSourceDesc* pSheetDesc = pOld->GetSheetDesc();
482*cdf0e10cSrcweir 				if ( pSheetDesc && pSheetDesc->aSourceRange.Intersects( rSource ) )
483*cdf0e10cSrcweir 				{
484*cdf0e10cSrcweir 					ScDPObject* pNew = new ScDPObject( *pOld );
485*cdf0e10cSrcweir 					ScDBDocFunc aFunc( *this );
486*cdf0e10cSrcweir 					aFunc.DataPilotUpdate( pOld, pNew, sal_True, sal_False );
487*cdf0e10cSrcweir 					delete pNew;	// DataPilotUpdate copies settings from "new" object
488*cdf0e10cSrcweir 				}
489*cdf0e10cSrcweir 			}
490*cdf0e10cSrcweir 		}
491*cdf0e10cSrcweir 	}
492*cdf0e10cSrcweir }
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir String lcl_GetAreaName( ScDocument* pDoc, ScArea* pArea )
495*cdf0e10cSrcweir {
496*cdf0e10cSrcweir 	String aName;
497*cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
498*cdf0e10cSrcweir 	ScDBData* pData = pDoc->GetDBAtArea( pArea->nTab, pArea->nColStart, pArea->nRowStart,
499*cdf0e10cSrcweir 														pArea->nColEnd, pArea->nRowEnd );
500*cdf0e10cSrcweir 	if (pData)
501*cdf0e10cSrcweir 	{
502*cdf0e10cSrcweir 		pData->GetName( aName );
503*cdf0e10cSrcweir 		if ( aName != ScGlobal::GetRscString( STR_DB_NONAME ) )
504*cdf0e10cSrcweir 			bOk = sal_True;
505*cdf0e10cSrcweir 	}
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 	if (!bOk)
508*cdf0e10cSrcweir 		pDoc->GetName( pArea->nTab, aName );
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir 	return aName;
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, sal_Bool bRecord )
514*cdf0e10cSrcweir {
515*cdf0e10cSrcweir 	ScConsData aData;
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 	sal_uInt16 nPos;
518*cdf0e10cSrcweir 	SCCOL nColSize = 0;
519*cdf0e10cSrcweir 	SCROW nRowSize = 0;
520*cdf0e10cSrcweir 	sal_Bool bErr = sal_False;
521*cdf0e10cSrcweir 	for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
522*cdf0e10cSrcweir 	{
523*cdf0e10cSrcweir 		ScArea* pArea = rParam.ppDataAreas[nPos];
524*cdf0e10cSrcweir 		nColSize = Max( nColSize, SCCOL( pArea->nColEnd - pArea->nColStart + 1 ) );
525*cdf0e10cSrcweir 		nRowSize = Max( nRowSize, SCROW( pArea->nRowEnd - pArea->nRowStart + 1 ) );
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 										// Test, ob Quelldaten verschoben wuerden
528*cdf0e10cSrcweir 		if (rParam.bReferenceData)
529*cdf0e10cSrcweir 			if (pArea->nTab == rParam.nTab && pArea->nRowEnd >= rParam.nRow)
530*cdf0e10cSrcweir 				bErr = sal_True;
531*cdf0e10cSrcweir 	}
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 	if (bErr)
534*cdf0e10cSrcweir 	{
535*cdf0e10cSrcweir 		InfoBox aBox( GetActiveDialogParent(),
536*cdf0e10cSrcweir 				ScGlobal::GetRscString( STR_CONSOLIDATE_ERR1 ) );
537*cdf0e10cSrcweir 		aBox.Execute();
538*cdf0e10cSrcweir 		return;
539*cdf0e10cSrcweir 	}
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir 	//		ausfuehren
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir 	WaitObject aWait( GetActiveDialogParent() );
544*cdf0e10cSrcweir 	ScDocShellModificator aModificator( *this );
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 	ScRange aOldDest;
547*cdf0e10cSrcweir 	ScDBData* pDestData = aDocument.GetDBAtCursor( rParam.nCol, rParam.nRow, rParam.nTab, sal_True );
548*cdf0e10cSrcweir 	if (pDestData)
549*cdf0e10cSrcweir 		pDestData->GetArea(aOldDest);
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir 	aData.SetSize( nColSize, nRowSize );
552*cdf0e10cSrcweir 	aData.SetFlags( rParam.eFunction, rParam.bByCol, rParam.bByRow, rParam.bReferenceData );
553*cdf0e10cSrcweir 	if ( rParam.bByCol || rParam.bByRow )
554*cdf0e10cSrcweir 		for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
555*cdf0e10cSrcweir 		{
556*cdf0e10cSrcweir 			ScArea* pArea = rParam.ppDataAreas[nPos];
557*cdf0e10cSrcweir 			aData.AddFields( &aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
558*cdf0e10cSrcweir 														pArea->nColEnd, pArea->nRowEnd );
559*cdf0e10cSrcweir 		}
560*cdf0e10cSrcweir 	aData.DoneFields();
561*cdf0e10cSrcweir 	for (nPos=0; nPos<rParam.nDataAreaCount; nPos++)
562*cdf0e10cSrcweir 	{
563*cdf0e10cSrcweir 		ScArea* pArea = rParam.ppDataAreas[nPos];
564*cdf0e10cSrcweir 		aData.AddData( &aDocument, pArea->nTab, pArea->nColStart, pArea->nRowStart,
565*cdf0e10cSrcweir 													pArea->nColEnd, pArea->nRowEnd );
566*cdf0e10cSrcweir 		aData.AddName( lcl_GetAreaName(&aDocument,pArea) );
567*cdf0e10cSrcweir 	}
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir 	aData.GetSize( nColSize, nRowSize );
570*cdf0e10cSrcweir 	if (bRecord && nColSize > 0 && nRowSize > 0)
571*cdf0e10cSrcweir 	{
572*cdf0e10cSrcweir 		ScDBData* pUndoData = pDestData ? new ScDBData(*pDestData) : NULL;
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 		SCTAB nDestTab = rParam.nTab;
575*cdf0e10cSrcweir 		ScArea aDestArea( rParam.nTab, rParam.nCol, rParam.nRow,
576*cdf0e10cSrcweir 							rParam.nCol+nColSize-1, rParam.nRow+nRowSize-1 );
577*cdf0e10cSrcweir 		if (rParam.bByCol) ++aDestArea.nColEnd;
578*cdf0e10cSrcweir 		if (rParam.bByRow) ++aDestArea.nRowEnd;
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 		if (rParam.bReferenceData)
581*cdf0e10cSrcweir 		{
582*cdf0e10cSrcweir 			SCTAB nTabCount = aDocument.GetTableCount();
583*cdf0e10cSrcweir 			SCROW nInsertCount = aData.GetInsertCount();
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir 			// alte Outlines
586*cdf0e10cSrcweir 			ScOutlineTable* pTable = aDocument.GetOutlineTable( nDestTab );
587*cdf0e10cSrcweir 			ScOutlineTable* pUndoTab = pTable ? new ScOutlineTable( *pTable ) : NULL;
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 			ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
590*cdf0e10cSrcweir 			pUndoDoc->InitUndo( &aDocument, 0, nTabCount-1, sal_False, sal_True );
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 			// Zeilenstatus
593*cdf0e10cSrcweir 			aDocument.CopyToDocument( 0,0,nDestTab, MAXCOL,MAXROW,nDestTab,
594*cdf0e10cSrcweir 									IDF_NONE, sal_False, pUndoDoc );
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 			// alle Formeln
597*cdf0e10cSrcweir 			aDocument.CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1,
598*cdf0e10cSrcweir 										IDF_FORMULA, sal_False, pUndoDoc );
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 			// komplette Ausgangszeilen
601*cdf0e10cSrcweir 			aDocument.CopyToDocument( 0,aDestArea.nRowStart,nDestTab,
602*cdf0e10cSrcweir 									MAXCOL,aDestArea.nRowEnd,nDestTab,
603*cdf0e10cSrcweir 									IDF_ALL, sal_False, pUndoDoc );
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 			// alten Ausgabebereich
606*cdf0e10cSrcweir 			if (pDestData)
607*cdf0e10cSrcweir 				aDocument.CopyToDocument( aOldDest, IDF_ALL, sal_False, pUndoDoc );
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 			GetUndoManager()->AddUndoAction(
610*cdf0e10cSrcweir 					new ScUndoConsolidate( this, aDestArea, rParam, pUndoDoc,
611*cdf0e10cSrcweir 											sal_True, nInsertCount, pUndoTab, pUndoData ) );
612*cdf0e10cSrcweir 		}
613*cdf0e10cSrcweir 		else
614*cdf0e10cSrcweir 		{
615*cdf0e10cSrcweir 			ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
616*cdf0e10cSrcweir 			pUndoDoc->InitUndo( &aDocument, aDestArea.nTab, aDestArea.nTab );
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir 			aDocument.CopyToDocument( aDestArea.nColStart, aDestArea.nRowStart, aDestArea.nTab,
619*cdf0e10cSrcweir 									aDestArea.nColEnd, aDestArea.nRowEnd, aDestArea.nTab,
620*cdf0e10cSrcweir 									IDF_ALL, sal_False, pUndoDoc );
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 			// alten Ausgabebereich
623*cdf0e10cSrcweir 			if (pDestData)
624*cdf0e10cSrcweir 				aDocument.CopyToDocument( aOldDest, IDF_ALL, sal_False, pUndoDoc );
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir 			GetUndoManager()->AddUndoAction(
627*cdf0e10cSrcweir 					new ScUndoConsolidate( this, aDestArea, rParam, pUndoDoc,
628*cdf0e10cSrcweir 											sal_False, 0, NULL, pUndoData ) );
629*cdf0e10cSrcweir 		}
630*cdf0e10cSrcweir 	}
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 	if (pDestData)										// Zielbereich loeschen / anpassen
633*cdf0e10cSrcweir 	{
634*cdf0e10cSrcweir 		aDocument.DeleteAreaTab(aOldDest, IDF_CONTENTS);
635*cdf0e10cSrcweir 		pDestData->SetArea( rParam.nTab, rParam.nCol, rParam.nRow,
636*cdf0e10cSrcweir 							rParam.nCol + nColSize - 1, rParam.nRow + nRowSize - 1 );
637*cdf0e10cSrcweir 		pDestData->SetHeader( rParam.bByRow );
638*cdf0e10cSrcweir 	}
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir 	aData.OutputToDocument( &aDocument, rParam.nCol, rParam.nRow, rParam.nTab );
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 	SCCOL nPaintStartCol = rParam.nCol;
643*cdf0e10cSrcweir 	SCROW nPaintStartRow = rParam.nRow;
644*cdf0e10cSrcweir 	SCCOL nPaintEndCol = nPaintStartCol + nColSize - 1;
645*cdf0e10cSrcweir 	SCROW nPaintEndRow = nPaintStartRow + nRowSize - 1;
646*cdf0e10cSrcweir 	sal_uInt16 nPaintFlags = PAINT_GRID;
647*cdf0e10cSrcweir 	if (rParam.bByCol)
648*cdf0e10cSrcweir 		++nPaintEndRow;
649*cdf0e10cSrcweir 	if (rParam.bByRow)
650*cdf0e10cSrcweir 		++nPaintEndCol;
651*cdf0e10cSrcweir 	if (rParam.bReferenceData)
652*cdf0e10cSrcweir 	{
653*cdf0e10cSrcweir 		nPaintStartCol = 0;
654*cdf0e10cSrcweir 		nPaintEndCol = MAXCOL;
655*cdf0e10cSrcweir 		nPaintEndRow = MAXROW;
656*cdf0e10cSrcweir 		nPaintFlags |= PAINT_LEFT | PAINT_SIZE;
657*cdf0e10cSrcweir 	}
658*cdf0e10cSrcweir 	if (pDestData)
659*cdf0e10cSrcweir 	{
660*cdf0e10cSrcweir 		if ( aOldDest.aEnd.Col() > nPaintEndCol )
661*cdf0e10cSrcweir 			nPaintEndCol = aOldDest.aEnd.Col();
662*cdf0e10cSrcweir 		if ( aOldDest.aEnd.Row() > nPaintEndRow )
663*cdf0e10cSrcweir 			nPaintEndRow = aOldDest.aEnd.Row();
664*cdf0e10cSrcweir 	}
665*cdf0e10cSrcweir 	PostPaint( nPaintStartCol, nPaintStartRow, rParam.nTab,
666*cdf0e10cSrcweir 				nPaintEndCol, nPaintEndRow, rParam.nTab, nPaintFlags );
667*cdf0e10cSrcweir 	aModificator.SetDocumentModified();
668*cdf0e10cSrcweir }
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir void ScDocShell::UseScenario( SCTAB nTab, const String& rName, sal_Bool bRecord )
671*cdf0e10cSrcweir {
672*cdf0e10cSrcweir 	if (!aDocument.IsScenario(nTab))
673*cdf0e10cSrcweir 	{
674*cdf0e10cSrcweir 		SCTAB	nTabCount = aDocument.GetTableCount();
675*cdf0e10cSrcweir 		SCTAB	nSrcTab = SCTAB_MAX;
676*cdf0e10cSrcweir 		SCTAB	nEndTab = nTab;
677*cdf0e10cSrcweir 		String aCompare;
678*cdf0e10cSrcweir 		while ( nEndTab+1 < nTabCount && aDocument.IsScenario(nEndTab+1) )
679*cdf0e10cSrcweir 		{
680*cdf0e10cSrcweir 			++nEndTab;
681*cdf0e10cSrcweir 			if (nSrcTab > MAXTAB)			// noch auf der Suche nach dem Szenario?
682*cdf0e10cSrcweir 			{
683*cdf0e10cSrcweir 				aDocument.GetName( nEndTab, aCompare );
684*cdf0e10cSrcweir 				if (aCompare == rName)
685*cdf0e10cSrcweir 					nSrcTab = nEndTab;		// gefunden
686*cdf0e10cSrcweir 			}
687*cdf0e10cSrcweir 		}
688*cdf0e10cSrcweir 		if (ValidTab(nSrcTab))
689*cdf0e10cSrcweir 		{
690*cdf0e10cSrcweir 			if ( aDocument.TestCopyScenario( nSrcTab, nTab ) )			// Zellschutz testen
691*cdf0e10cSrcweir 			{
692*cdf0e10cSrcweir 				ScDocShellModificator aModificator( *this );
693*cdf0e10cSrcweir 				ScMarkData aScenMark;
694*cdf0e10cSrcweir 				aDocument.MarkScenario( nSrcTab, nTab, aScenMark );
695*cdf0e10cSrcweir 				ScRange aMultiRange;
696*cdf0e10cSrcweir 				aScenMark.GetMultiMarkArea( aMultiRange );
697*cdf0e10cSrcweir 				SCCOL nStartCol = aMultiRange.aStart.Col();
698*cdf0e10cSrcweir 				SCROW nStartRow = aMultiRange.aStart.Row();
699*cdf0e10cSrcweir 				SCCOL nEndCol = aMultiRange.aEnd.Col();
700*cdf0e10cSrcweir 				SCROW nEndRow = aMultiRange.aEnd.Row();
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 				if (bRecord)
703*cdf0e10cSrcweir 				{
704*cdf0e10cSrcweir 					ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
705*cdf0e10cSrcweir 					pUndoDoc->InitUndo( &aDocument, nTab,nEndTab );				// auch alle Szenarien
706*cdf0e10cSrcweir 					//	angezeigte Tabelle:
707*cdf0e10cSrcweir 					aDocument.CopyToDocument( nStartCol,nStartRow,nTab,
708*cdf0e10cSrcweir 									nEndCol,nEndRow,nTab, IDF_ALL,sal_True, pUndoDoc, &aScenMark );
709*cdf0e10cSrcweir 					//	Szenarien
710*cdf0e10cSrcweir 					for (SCTAB i=nTab+1; i<=nEndTab; i++)
711*cdf0e10cSrcweir 					{
712*cdf0e10cSrcweir 						pUndoDoc->SetScenario( i, sal_True );
713*cdf0e10cSrcweir 						String aComment;
714*cdf0e10cSrcweir 						Color  aColor;
715*cdf0e10cSrcweir 						sal_uInt16 nScenFlags;
716*cdf0e10cSrcweir 						aDocument.GetScenarioData( i, aComment, aColor, nScenFlags );
717*cdf0e10cSrcweir 						pUndoDoc->SetScenarioData( i, aComment, aColor, nScenFlags );
718*cdf0e10cSrcweir 						sal_Bool bActive = aDocument.IsActiveScenario( i );
719*cdf0e10cSrcweir 						pUndoDoc->SetActiveScenario( i, bActive );
720*cdf0e10cSrcweir 						//	Bei Zurueckkopier-Szenarios auch Inhalte
721*cdf0e10cSrcweir 						if ( nScenFlags & SC_SCENARIO_TWOWAY )
722*cdf0e10cSrcweir 							aDocument.CopyToDocument( 0,0,i, MAXCOL,MAXROW,i,
723*cdf0e10cSrcweir 														IDF_ALL,sal_False, pUndoDoc );
724*cdf0e10cSrcweir 					}
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir 					GetUndoManager()->AddUndoAction(
727*cdf0e10cSrcweir 						new ScUndoUseScenario( this, aScenMark,
728*cdf0e10cSrcweir 										ScArea( nTab,nStartCol,nStartRow,nEndCol,nEndRow ),
729*cdf0e10cSrcweir 										pUndoDoc, rName ) );
730*cdf0e10cSrcweir 				}
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir 				aDocument.CopyScenario( nSrcTab, nTab );
733*cdf0e10cSrcweir 				aDocument.SetDirty();
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir 				//	alles painten, weil in anderen Bereichen das aktive Szenario
736*cdf0e10cSrcweir 				//	geaendert sein kann
737*cdf0e10cSrcweir 				//!	nur, wenn sichtbare Rahmen vorhanden?
738*cdf0e10cSrcweir 				PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
739*cdf0e10cSrcweir 				aModificator.SetDocumentModified();
740*cdf0e10cSrcweir 			}
741*cdf0e10cSrcweir 			else
742*cdf0e10cSrcweir 			{
743*cdf0e10cSrcweir 				InfoBox aBox(GetActiveDialogParent(),
744*cdf0e10cSrcweir 					ScGlobal::GetRscString( STR_PROTECTIONERR ) );
745*cdf0e10cSrcweir 				aBox.Execute();
746*cdf0e10cSrcweir 			}
747*cdf0e10cSrcweir 		}
748*cdf0e10cSrcweir 		else
749*cdf0e10cSrcweir 		{
750*cdf0e10cSrcweir 			InfoBox aBox(GetActiveDialogParent(),
751*cdf0e10cSrcweir 				ScGlobal::GetRscString( STR_SCENARIO_NOTFOUND ) );
752*cdf0e10cSrcweir 			aBox.Execute();
753*cdf0e10cSrcweir 		}
754*cdf0e10cSrcweir 	}
755*cdf0e10cSrcweir 	else
756*cdf0e10cSrcweir 	{
757*cdf0e10cSrcweir 		DBG_ERROR( "UseScenario auf Szenario-Blatt" );
758*cdf0e10cSrcweir 	}
759*cdf0e10cSrcweir }
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir void ScDocShell::ModifyScenario( SCTAB nTab, const String& rName, const String& rComment,
762*cdf0e10cSrcweir 									const Color& rColor, sal_uInt16 nFlags )
763*cdf0e10cSrcweir {
764*cdf0e10cSrcweir 	//	Undo
765*cdf0e10cSrcweir 	String aOldName;
766*cdf0e10cSrcweir 	aDocument.GetName( nTab, aOldName );
767*cdf0e10cSrcweir 	String aOldComment;
768*cdf0e10cSrcweir 	Color aOldColor;
769*cdf0e10cSrcweir 	sal_uInt16 nOldFlags;
770*cdf0e10cSrcweir 	aDocument.GetScenarioData( nTab, aOldComment, aOldColor, nOldFlags );
771*cdf0e10cSrcweir 	GetUndoManager()->AddUndoAction(
772*cdf0e10cSrcweir 		new ScUndoScenarioFlags( this, nTab,
773*cdf0e10cSrcweir 				aOldName, rName, aOldComment, rComment,
774*cdf0e10cSrcweir 				aOldColor, rColor, nOldFlags, nFlags ) );
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir 	//	ausfuehren
777*cdf0e10cSrcweir 	ScDocShellModificator aModificator( *this );
778*cdf0e10cSrcweir 	aDocument.RenameTab( nTab, rName );
779*cdf0e10cSrcweir 	aDocument.SetScenarioData( nTab, rComment, rColor, nFlags );
780*cdf0e10cSrcweir 	PostPaintGridAll();
781*cdf0e10cSrcweir 	aModificator.SetDocumentModified();
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir 	if ( rName != aOldName )
784*cdf0e10cSrcweir 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir 	SfxBindings* pBindings = GetViewBindings();
787*cdf0e10cSrcweir 	if (pBindings)
788*cdf0e10cSrcweir 		pBindings->Invalidate( SID_SELECT_SCENARIO );
789*cdf0e10cSrcweir }
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir SCTAB ScDocShell::MakeScenario( SCTAB nTab, const String& rName, const String& rComment,
792*cdf0e10cSrcweir 									const Color& rColor, sal_uInt16 nFlags,
793*cdf0e10cSrcweir 									ScMarkData& rMark, sal_Bool bRecord )
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir 	rMark.MarkToMulti();
796*cdf0e10cSrcweir 	if (rMark.IsMultiMarked())
797*cdf0e10cSrcweir 	{
798*cdf0e10cSrcweir 		SCTAB nNewTab = nTab + 1;
799*cdf0e10cSrcweir 		while (aDocument.IsScenario(nNewTab))
800*cdf0e10cSrcweir 			++nNewTab;
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir 		sal_Bool bCopyAll = ( (nFlags & SC_SCENARIO_COPYALL) != 0 );
803*cdf0e10cSrcweir 		const ScMarkData* pCopyMark = NULL;
804*cdf0e10cSrcweir 		if (!bCopyAll)
805*cdf0e10cSrcweir 			pCopyMark = &rMark;
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir 		ScDocShellModificator aModificator( *this );
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir         if (bRecord)
810*cdf0e10cSrcweir             aDocument.BeginDrawUndo();      // drawing layer must do its own undo actions
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir 		if (aDocument.CopyTab( nTab, nNewTab, pCopyMark ))
813*cdf0e10cSrcweir 		{
814*cdf0e10cSrcweir 			if (bRecord)
815*cdf0e10cSrcweir 			{
816*cdf0e10cSrcweir 				GetUndoManager()->AddUndoAction(
817*cdf0e10cSrcweir                         new ScUndoMakeScenario( this, nTab, nNewTab,
818*cdf0e10cSrcweir 												rName, rComment, rColor, nFlags, rMark ));
819*cdf0e10cSrcweir 			}
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir 			aDocument.RenameTab( nNewTab, rName, sal_False );			// ohne Formel-Update
822*cdf0e10cSrcweir 			aDocument.SetScenario( nNewTab, sal_True );
823*cdf0e10cSrcweir 			aDocument.SetScenarioData( nNewTab, rComment, rColor, nFlags );
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir 			ScMarkData aDestMark = rMark;
826*cdf0e10cSrcweir 			aDestMark.SelectOneTable( nNewTab );
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir 			//!		auf Filter / Buttons / Merging testen !
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir 			ScPatternAttr aProtPattern( aDocument.GetPool() );
831*cdf0e10cSrcweir 			aProtPattern.GetItemSet().Put( ScProtectionAttr( sal_True ) );
832*cdf0e10cSrcweir 			aDocument.ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nNewTab, aProtPattern );
833*cdf0e10cSrcweir 
834*cdf0e10cSrcweir 			ScPatternAttr aPattern( aDocument.GetPool() );
835*cdf0e10cSrcweir 			aPattern.GetItemSet().Put( ScMergeFlagAttr( SC_MF_SCENARIO ) );
836*cdf0e10cSrcweir 			aPattern.GetItemSet().Put( ScProtectionAttr( sal_True ) );
837*cdf0e10cSrcweir 			aDocument.ApplySelectionPattern( aPattern, aDestMark );
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir 			if (!bCopyAll)
840*cdf0e10cSrcweir 				aDocument.SetVisible( nNewTab, sal_False );
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir 			//	dies ist dann das aktive Szenario
843*cdf0e10cSrcweir 			aDocument.CopyScenario( nNewTab, nTab, sal_True );	// sal_True - nicht aus Szenario kopieren
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 			if (nFlags & SC_SCENARIO_SHOWFRAME)
846*cdf0e10cSrcweir 				PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );	// Rahmen painten
847*cdf0e10cSrcweir 			PostPaintExtras();											// Tabellenreiter
848*cdf0e10cSrcweir 			aModificator.SetDocumentModified();
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir 			SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir 			return nNewTab;
853*cdf0e10cSrcweir 		}
854*cdf0e10cSrcweir 	}
855*cdf0e10cSrcweir 	return nTab;
856*cdf0e10cSrcweir }
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir sal_Bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord )
859*cdf0e10cSrcweir {
860*cdf0e10cSrcweir 	ScDocShellModificator aModificator( *this );
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir     // #i92477# be consistent with ScDocFunc::InsertTable: any index past the last sheet means "append"
863*cdf0e10cSrcweir     // #i101139# nDestTab must be the target position, not APPEND (for CopyTabProtection etc.)
864*cdf0e10cSrcweir     if ( nDestTab >= aDocument.GetTableCount() )
865*cdf0e10cSrcweir         nDestTab = aDocument.GetTableCount();
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir 	if (bCopy)
868*cdf0e10cSrcweir 	{
869*cdf0e10cSrcweir 		if (bRecord)
870*cdf0e10cSrcweir 			aDocument.BeginDrawUndo();			// drawing layer must do its own undo actions
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir         String sSrcCodeName;
873*cdf0e10cSrcweir         aDocument.GetCodeName( nSrcTab, sSrcCodeName );
874*cdf0e10cSrcweir 		if (!aDocument.CopyTab( nSrcTab, nDestTab ))
875*cdf0e10cSrcweir 		{
876*cdf0e10cSrcweir 			//!	EndDrawUndo?
877*cdf0e10cSrcweir 			return sal_False;
878*cdf0e10cSrcweir 		}
879*cdf0e10cSrcweir 		else
880*cdf0e10cSrcweir 		{
881*cdf0e10cSrcweir 			SCTAB nAdjSource = nSrcTab;
882*cdf0e10cSrcweir 			if ( nDestTab <= nSrcTab )
883*cdf0e10cSrcweir 				++nAdjSource;				// new position of source table after CopyTab
884*cdf0e10cSrcweir 
885*cdf0e10cSrcweir 			if ( aDocument.IsTabProtected( nAdjSource ) )
886*cdf0e10cSrcweir                 aDocument.CopyTabProtection(nAdjSource, nDestTab);
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir 			if (bRecord)
889*cdf0e10cSrcweir 			{
890*cdf0e10cSrcweir 				SvShorts aSrcList;
891*cdf0e10cSrcweir 				SvShorts aDestList;
892*cdf0e10cSrcweir 				aSrcList.push_front(nSrcTab);
893*cdf0e10cSrcweir 				aDestList.push_front(nDestTab);
894*cdf0e10cSrcweir 				GetUndoManager()->AddUndoAction(
895*cdf0e10cSrcweir 						new ScUndoCopyTab( this, aSrcList, aDestList ) );
896*cdf0e10cSrcweir 			}
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir 			sal_Bool bVbaEnabled = aDocument.IsInVBAMode();
899*cdf0e10cSrcweir                         if ( bVbaEnabled )
900*cdf0e10cSrcweir                         {
901*cdf0e10cSrcweir 			    StarBASIC* pStarBASIC = GetBasic();
902*cdf0e10cSrcweir                             String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
903*cdf0e10cSrcweir                             if ( GetBasicManager()->GetName().Len() > 0 )
904*cdf0e10cSrcweir                             {
905*cdf0e10cSrcweir                                 aLibName = GetBasicManager()->GetName();
906*cdf0e10cSrcweir                                 pStarBASIC = GetBasicManager()->GetLib( aLibName );
907*cdf0e10cSrcweir                             }
908*cdf0e10cSrcweir                             SCTAB nTabToUse = nDestTab;
909*cdf0e10cSrcweir                             if ( nDestTab == SC_TAB_APPEND )
910*cdf0e10cSrcweir                                 nTabToUse = aDocument.GetMaxTableNumber() - 1;
911*cdf0e10cSrcweir                             String sCodeName;
912*cdf0e10cSrcweir                             String sSource;
913*cdf0e10cSrcweir                             com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = GetBasicContainer();
914*cdf0e10cSrcweir                             com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xLib;
915*cdf0e10cSrcweir                             if( xLibContainer.is() )
916*cdf0e10cSrcweir                             {
917*cdf0e10cSrcweir                                 com::sun::star::uno::Any aLibAny = xLibContainer->getByName( aLibName );
918*cdf0e10cSrcweir                                 aLibAny >>= xLib;
919*cdf0e10cSrcweir                             }
920*cdf0e10cSrcweir                             if( xLib.is() )
921*cdf0e10cSrcweir                             {
922*cdf0e10cSrcweir                                 rtl::OUString sRTLSource;
923*cdf0e10cSrcweir                                 xLib->getByName( sSrcCodeName ) >>= sRTLSource;
924*cdf0e10cSrcweir                                 sSource = sRTLSource;
925*cdf0e10cSrcweir                             }
926*cdf0e10cSrcweir                             VBA_InsertModule( aDocument, nTabToUse, sCodeName, sSource );
927*cdf0e10cSrcweir                         }
928*cdf0e10cSrcweir                 }
929*cdf0e10cSrcweir 		Broadcast( ScTablesHint( SC_TAB_COPIED, nSrcTab, nDestTab ) );
930*cdf0e10cSrcweir 	}
931*cdf0e10cSrcweir 	else
932*cdf0e10cSrcweir 	{
933*cdf0e10cSrcweir 		if ( aDocument.GetChangeTrack() )
934*cdf0e10cSrcweir 			return sal_False;
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir 		if ( nSrcTab<nDestTab && nDestTab!=SC_TAB_APPEND )
937*cdf0e10cSrcweir 			nDestTab--;
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir 		if ( nSrcTab == nDestTab )
940*cdf0e10cSrcweir 		{
941*cdf0e10cSrcweir 			//!	allow only for api calls?
942*cdf0e10cSrcweir 			return sal_True;	// nothing to do, but valid
943*cdf0e10cSrcweir 		}
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 		if (!aDocument.MoveTab( nSrcTab, nDestTab ))
946*cdf0e10cSrcweir 			return sal_False;
947*cdf0e10cSrcweir 		else if (bRecord)
948*cdf0e10cSrcweir 		{
949*cdf0e10cSrcweir 			SvShorts aSrcList;
950*cdf0e10cSrcweir 			SvShorts aDestList;
951*cdf0e10cSrcweir 			aSrcList.push_front(nSrcTab);
952*cdf0e10cSrcweir 			aDestList.push_front(nDestTab);
953*cdf0e10cSrcweir 			GetUndoManager()->AddUndoAction(
954*cdf0e10cSrcweir 					new ScUndoMoveTab( this, aSrcList, aDestList ) );
955*cdf0e10cSrcweir 		}
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir 		Broadcast( ScTablesHint( SC_TAB_MOVED, nSrcTab, nDestTab ) );
958*cdf0e10cSrcweir 	}
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir 	PostPaintGridAll();
961*cdf0e10cSrcweir 	PostPaintExtras();
962*cdf0e10cSrcweir 	aModificator.SetDocumentModified();
963*cdf0e10cSrcweir 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir 	return sal_True;
966*cdf0e10cSrcweir }
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir IMPL_LINK( ScDocShell, RefreshDBDataHdl, ScRefreshTimer*, pRefreshTimer )
970*cdf0e10cSrcweir {
971*cdf0e10cSrcweir 	ScDBDocFunc aFunc(*this);
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 	sal_Bool bContinue = sal_True;
974*cdf0e10cSrcweir     ScDBData* pDBData = static_cast<ScDBData*>(pRefreshTimer);
975*cdf0e10cSrcweir 	ScImportParam aImportParam;
976*cdf0e10cSrcweir 	pDBData->GetImportParam( aImportParam );
977*cdf0e10cSrcweir 	if (aImportParam.bImport && !pDBData->HasImportSelection())
978*cdf0e10cSrcweir 	{
979*cdf0e10cSrcweir 		ScRange aRange;
980*cdf0e10cSrcweir 		pDBData->GetArea( aRange );
981*cdf0e10cSrcweir         bContinue = aFunc.DoImport( aRange.aStart.Tab(), aImportParam, NULL, sal_True, sal_False ); //! Api-Flag as parameter
982*cdf0e10cSrcweir 		// internal operations (sort, query, subtotal) only if no error
983*cdf0e10cSrcweir 		if (bContinue)
984*cdf0e10cSrcweir 		{
985*cdf0e10cSrcweir 			aFunc.RepeatDB( pDBData->GetName(), sal_True, sal_True );
986*cdf0e10cSrcweir 			RefreshPivotTables(aRange);
987*cdf0e10cSrcweir 		}
988*cdf0e10cSrcweir 	}
989*cdf0e10cSrcweir 
990*cdf0e10cSrcweir 	return bContinue != 0;
991*cdf0e10cSrcweir }
992*cdf0e10cSrcweir 
993