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