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