/************************************************************************* * * $RCSfile: docsh5.cxx,v $ * * $Revision: 1.12 $ * * last change: $Author: obo $ $Date: 2004-06-04 11:24:25 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses * * - GNU Lesser General Public License Version 2.1 * - Sun Industry Standards Source License Version 1.1 * * Sun Microsystems Inc., October, 2000 * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2000 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * * Sun Industry Standards Source License Version 1.1 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.1 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://www.openoffice.org/license.html. * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2000 by Sun Microsystems, Inc. * * All Rights Reserved. * * Contributor(s): _______________________________________ * * ************************************************************************/ // System - Includes ----------------------------------------------------- #define _BASEDLGS_HXX #define _BIGINT_HXX #define _CACHESTR_HXX //#define _CLIP_HXX #define _CONFIG_HXX #define _CURSOR_HXX //#define _COLOR_HXX //#define _CTRLBOX_HXX //#define _CTRLTOOL_HXX #define _DIALOGS_HXX #define _DLGCFG_HXX #define _DYNARR_HXX #define _EXTATTR_HXX //#define _FIELD_HXX #define _FILDLG_HXX //#define _FILTER_HXX #define _FONTDLG_HXX #define _FRM3D_HXX //#define _GRAPH_HXX //#define _GDIMTF_HXX #define _INTRO_HXX #define _ISETBWR_HXX #define _NO_SVRTF_PARSER_HXX //#define _MDIFRM_HXX #define _MACRODLG_HXX #define _MODALDLG_HXX #define _MOREBUTTON_HXX //#define _MAPMOD_HXX #define _OUTLINER_HXX //#define _PAL_HXX #define _PASSWD_HXX //#define _PRNDLG_HXX // #define _POLY_HXX #define _PVRWIN_HXX #define _QUEUE_HXX #define _RULER_HXX #define _SCRWIN_HXX //#define _SELENG_HXX #define _SETBRW_HXX //#define _SOUND_HXX #define _STACK_HXX //#define _STATUS_HXX *** #define _STDMENU_HXX //#define _STDCTRL_HXX //#define _SYSDLG_HXX //#define _TAB_HXX #define _TABBAR_HXX //#define _TREELIST_HXX //#define _VALUESET_HXX #define _VCBRW_HXX #define _VCTRLS_HXX //#define _VCATTR_HXX #define _VCSBX_HXX #define _VCONT_HXX #define _VDRWOBJ_HXX //#define _VIEWFAC_HXX #define _SFX_PRNMON_HXX #define _SFX_RESMGR_HXX //#define _SFX_SAVEOPT_HXX #define _SFX_TEMPLDLG_HXX //#define _SFXAPP_HXX #define _SFXBASIC_HXX //#define _SFXCTRLITEM_HXX //#define _SFXDISPATCH_HXX #define _SFXFILEDLG_HXX #define _SFXIMGMGR_HXX #define _SFXMNUMGR_HXX //#define _SFXMSG_HXX #define _SFXMSGDESCR_HXX #define _SFXMSGPOOL_HXX //#define _SFXOBJFACE_HXX //#define _SFXREQUEST_HXX #define _SFXSTBITEM_HXX #define _SFXSTBMGR_HXX #define _SFXTBXCTRL_HXX #define _SFXTBXMGR_HXX #define _SFX_TEMPLDLG_HXX #define _SI_DLL_HXX #define _SIDLL_HXX #define _SI_NOITEMS #define _SI_NOOTHERFORMS #define _SI_NOSBXCONTROLS #define _SINOSBXCONTROLS #define _SI_NODRW #define _SI_NOCONTROL #define _SV_NOXSOUND #define _SVDATTR_HXX #define _SVDETC_HXX #define _SVDIO_HXX #define _SVDRAG_HXX #define _SVDLAYER_HXX #define _SVDXOUT_HXX #define _SVX_DAILDLL_HXX #define _SVX_HYPHEN_HXX #define _SVX_IMPGRF_HXX #define _SVX_OPTITEMS_HXX #define _SVX_OPTGERL_HXX #define _SVX_OPTSAVE_HXX #define _SVX_OPTSPELL_HXX #define _SVX_OPTPATH_HXX #define _SVX_OPTLINGU_HXX #define _SVX_RULER_HXX #define _SVX_RULRITEM_HXX #define _SVX_SPLWRAP_HXX #define _SVX_SPLDLG_HXX #define _SVX_THESDLG_HXX #ifdef PCH #include "ui_pch.hxx" #endif #pragma hdrstop #include "scitems.hxx" #include #include #include #include #include #include #include // INCLUDE --------------------------------------------------------------- #include "docsh.hxx" #include "global.hxx" #include "globstr.hrc" #include "undodat.hxx" #include "undotab.hxx" #include "undoblk.hxx" //#include "pivot.hxx" #include "dpobject.hxx" #include "dpshttab.hxx" #include "dbdocfun.hxx" #include "consoli.hxx" #include "dbcolect.hxx" #include "olinetab.hxx" #include "patattr.hxx" #include "attrib.hxx" #include "docpool.hxx" #include "uiitems.hxx" #include "sc.hrc" #include "waitoff.hxx" #include "sizedev.hxx" // --------------------------------------------------------------------------- // // ehemalige viewfunc/dbfunc Methoden // void ScDocShell::ErrorMessage( USHORT nGlobStrId ) { //! StopMarking an der (aktiven) View? Window* pParent = GetDialogParent(); ScWaitCursorOff aWaitOff( pParent ); BOOL bFocus = pParent && pParent->HasFocus(); if(nGlobStrId==STR_PROTECTIONERR) { if(IsReadOnly()) { nGlobStrId=STR_READONLYERR; } } InfoBox aBox( pParent, ScGlobal::GetRscString( nGlobStrId ) ); aBox.Execute(); if (bFocus) pParent->GrabFocus(); } BOOL ScDocShell::IsEditable() const { // import into read-only document is possible - must be extended if other filters use api return !IsReadOnly() || aDocument.IsImportingXML(); } void ScDocShell::DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 ) { ScDocShellModificator aModificator( *this ); aDocument.RemoveFlagsTab( nX1, nY1, nX2, nY1, nTab, SC_MF_AUTO ); PostPaint( nX1, nY1, nTab, nX2, nY1, nTab, PAINT_GRID ); aModificator.SetDocumentModified(); } ScDBData* lcl_GetDBNearCursor( ScDBCollection* pColl, SCCOL nCol, SCROW nRow, SCTAB nTab ) { //! nach document/dbcolect verschieben if (!pColl) return NULL; ScDBData* pNoNameData = NULL; ScDBData* pNearData = NULL; USHORT nCount = pColl->GetCount(); String aNoName = ScGlobal::GetRscString( STR_DB_NONAME ); SCTAB nAreaTab; SCCOL nStartCol, nEndCol; SCROW nStartRow, nEndRow; for (USHORT i = 0; i < nCount; i++) { ScDBData* pDB = (*pColl)[i]; pDB->GetArea( nAreaTab, nStartCol, nStartRow, nEndCol, nEndRow ); if ( nTab == nAreaTab && nCol+1 >= nStartCol && nCol <= nEndCol+1 && nRow+1 >= nStartRow && nRow <= nEndRow+1 ) { if ( pDB->GetName() == aNoName ) pNoNameData = pDB; else if ( nCol < nStartCol || nCol > nEndCol || nRow < nStartRow || nRow > nEndRow ) { if (!pNearData) pNearData = pDB; // ersten angrenzenden Bereich merken } else return pDB; // nicht "unbenannt" und Cursor steht wirklich drin } } if (pNearData) return pNearData; // angrenzender, wenn nichts direkt getroffen return pNoNameData; // "unbenannt" nur zurueck, wenn sonst nichts gefunden } ScDBData* ScDocShell::GetDBData( const ScRange& rMarked, ScGetDBMode eMode, BOOL bForceMark ) { SCCOL nCol = rMarked.aStart.Col(); SCROW nRow = rMarked.aStart.Row(); SCTAB nTab = rMarked.aStart.Tab(); SCCOL nStartCol = nCol; SCROW nStartRow = nRow; SCTAB nStartTab = nTab; SCCOL nEndCol = rMarked.aEnd.Col(); SCROW nEndRow = rMarked.aEnd.Row(); SCTAB nEndTab = rMarked.aEnd.Tab(); // Wegen #49655# nicht einfach GetDBAtCursor: Der zusammenhaengende Datenbereich // fuer "unbenannt" (GetDataArea) kann neben dem Cursor legen, also muss auch ein // benannter DB-Bereich dort gesucht werden. ScDBData* pData = aDocument.GetDBAtArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow ); if (!pData) pData = lcl_GetDBNearCursor( aDocument.GetDBCollection(), nCol, nRow, nTab ); BOOL bSelected = ( bForceMark || rMarked.aStart != rMarked.aEnd ); BOOL bUseThis = FALSE; if (pData) { // Bereich nehmen, wenn nichts anderes markiert SCTAB nDummy; SCCOL nOldCol1; SCROW nOldRow1; SCCOL nOldCol2; SCROW nOldRow2; pData->GetArea( nDummy, nOldCol1,nOldRow1, nOldCol2,nOldRow2 ); BOOL bIsNoName = ( pData->GetName() == ScGlobal::GetRscString( STR_DB_NONAME ) ); if (!bSelected) { bUseThis = TRUE; if ( bIsNoName && eMode == SC_DB_MAKE ) { // wenn nichts markiert, "unbenannt" auf zusammenhaengenden Bereich anpassen nStartCol = nCol; nStartRow = nRow; nEndCol = nStartCol; nEndRow = nStartRow; aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, FALSE ); if ( nOldCol1 != nStartCol || nOldCol2 != nEndCol || nOldRow1 != nStartRow ) bUseThis = FALSE; // passt gar nicht else if ( nOldRow2 != nEndRow ) { // Bereich auf neue End-Zeile erweitern pData->SetArea( nTab, nOldCol1,nOldRow1, nOldCol2,nEndRow ); } } } else { if ( nOldCol1 == nStartCol && nOldRow1 == nStartRow && nOldCol2 == nEndCol && nOldRow2 == nEndRow ) // genau markiert? bUseThis = TRUE; else bUseThis = FALSE; // immer Markierung nehmen (Bug 11964) } // fuer Import nie "unbenannt" nehmen if ( bUseThis && eMode == SC_DB_IMPORT && bIsNoName ) bUseThis = FALSE; } if ( bUseThis ) { pData->GetArea( nStartTab, nStartCol,nStartRow, nEndCol,nEndRow ); nEndTab = nStartTab; } else if ( eMode == SC_DB_OLD ) { pData = NULL; // nichts gefunden nStartCol = nEndCol = nCol; nStartRow = nEndRow = nRow; nStartTab = nEndTab = nTab; // bMark = FALSE; // nichts zu markieren } else { if ( bSelected ) { // bMark = FALSE; } else { // zusammenhaengender Bereich nStartCol = nCol; nStartRow = nRow; nEndCol = nStartCol; nEndRow = nStartRow; aDocument.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, FALSE ); } BOOL bHasHeader = aDocument.HasColHeader( nStartCol,nStartRow, nEndCol,nEndRow, nTab ); ScDBData* pNoNameData; USHORT nNoNameIndex; ScDBCollection* pColl = aDocument.GetDBCollection(); if ( eMode != SC_DB_IMPORT && pColl->SearchName( ScGlobal::GetRscString( STR_DB_NONAME ), nNoNameIndex ) ) { pNoNameData = (*pColl)[nNoNameIndex]; SCCOL nOldX1; // alten Bereich sauber wegnehmen SCROW nOldY1; //! (UNDO ???) SCCOL nOldX2; SCROW nOldY2; SCTAB nOldTab; pNoNameData->GetArea( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 ); DBAreaDeleted( nOldTab, nOldX1, nOldY1, nOldX2, nOldY2 ); pNoNameData->SetSortParam( ScSortParam() ); // Parameter zuruecksetzen pNoNameData->SetQueryParam( ScQueryParam() ); pNoNameData->SetSubTotalParam( ScSubTotalParam() ); pNoNameData->SetArea( nTab, nStartCol,nStartRow, nEndCol,nEndRow ); // neu setzen pNoNameData->SetByRow( TRUE ); pNoNameData->SetHeader( bHasHeader ); pNoNameData->SetAutoFilter( FALSE ); } else { ScDBCollection* pUndoColl = NULL; String aNewName; if (eMode==SC_DB_IMPORT) { aDocument.CompileDBFormula( TRUE ); // CreateFormulaString pUndoColl = new ScDBCollection( *pColl ); // Undo fuer Import1-Bereich String aImport = ScGlobal::GetRscString( STR_DBNAME_IMPORT ); long nCount = 0; USHORT nDummy; do { ++nCount; aNewName = aImport; aNewName += String::CreateFromInt32( nCount ); } while (pColl->SearchName( aNewName, nDummy )); } else aNewName = ScGlobal::GetRscString( STR_DB_NONAME ); pNoNameData = new ScDBData( aNewName, nTab, nStartCol,nStartRow, nEndCol,nEndRow, TRUE, bHasHeader ); pColl->Insert( pNoNameData ); if ( pUndoColl ) { aDocument.CompileDBFormula( FALSE ); // CompileFormulaString ScDBCollection* pRedoColl = new ScDBCollection( *pColl ); GetUndoManager()->AddUndoAction( new ScUndoDBData( this, pUndoColl, pRedoColl ) ); } // neuen Bereich am Sba anmelden nicht mehr noetig // "Import1" etc am Navigator bekanntmachen if (eMode==SC_DB_IMPORT) SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) ); } pData = pNoNameData; } // if (bMark) // MarkRange( ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab ), FALSE ); return pData; } // Hoehen anpassen //! mit docfunc zusammenfassen BOOL ScDocShell::AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab ) { ScSizeDeviceProvider aProv(this); Fraction aZoom(1,1); BOOL bChange = aDocument.SetOptimalHeight( nStartRow,nEndRow, nTab, 0, aProv.GetDevice(), aProv.GetPPTX(),aProv.GetPPTY(), aZoom,aZoom, FALSE ); if (bChange) PostPaint( 0,nStartRow,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID|PAINT_LEFT ); return bChange; } void ScDocShell::UpdateAllRowHeights() { // update automatic row heights ScSizeDeviceProvider aProv(this); Fraction aZoom(1,1); SCTAB nTabCnt = aDocument.GetTableCount(); for (SCTAB nTab=0; nTabGetCount(); for ( USHORT i=0; iGetSheetDesc(); if ( pSheetDesc && pSheetDesc->aSourceRange.Intersects( rSource ) ) { ScDPObject* pNew = new ScDPObject( *pOld ); ScDBDocFunc aFunc( *this ); aFunc.DataPilotUpdate( pOld, pNew, TRUE, FALSE ); delete pNew; // DataPilotUpdate copies settings from "new" object } } } } } String lcl_GetAreaName( ScDocument* pDoc, ScArea* pArea ) { String aName; BOOL bOk = FALSE; ScDBData* pData = pDoc->GetDBAtArea( pArea->nTab, pArea->nColStart, pArea->nRowStart, pArea->nColEnd, pArea->nRowEnd ); if (pData) { pData->GetName( aName ); if ( aName != ScGlobal::GetRscString( STR_DB_NONAME ) ) bOk = TRUE; } if (!bOk) pDoc->GetName( pArea->nTab, aName ); return aName; } void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, BOOL bRecord ) { ScConsData aData; USHORT nPos; SCCOL nColSize = 0; SCROW nRowSize = 0; BOOL bErr = FALSE; for (nPos=0; nPosnColEnd - pArea->nColStart + 1 ) ); nRowSize = Max( nRowSize, SCROW( pArea->nRowEnd - pArea->nRowStart + 1 ) ); // Test, ob Quelldaten verschoben wuerden if (rParam.bReferenceData) if (pArea->nTab == rParam.nTab && pArea->nRowEnd >= rParam.nRow) bErr = TRUE; } if (bErr) { InfoBox aBox( GetDialogParent(), ScGlobal::GetRscString( STR_CONSOLIDATE_ERR1 ) ); aBox.Execute(); return; } // ausfuehren WaitObject aWait( GetDialogParent() ); ScDocShellModificator aModificator( *this ); ScRange aOldDest; ScDBData* pDestData = aDocument.GetDBAtCursor( rParam.nCol, rParam.nRow, rParam.nTab, TRUE ); if (pDestData) pDestData->GetArea(aOldDest); aData.SetSize( nColSize, nRowSize ); aData.SetFlags( rParam.eFunction, rParam.bByCol, rParam.bByRow, rParam.bReferenceData ); if ( rParam.bByCol || rParam.bByRow ) for (nPos=0; nPosnTab, pArea->nColStart, pArea->nRowStart, pArea->nColEnd, pArea->nRowEnd ); } aData.DoneFields(); for (nPos=0; nPosnTab, pArea->nColStart, pArea->nRowStart, pArea->nColEnd, pArea->nRowEnd ); aData.AddName( lcl_GetAreaName(&aDocument,pArea) ); } aData.GetSize( nColSize, nRowSize ); if (bRecord && nColSize > 0 && nRowSize > 0) { ScDBData* pUndoData = pDestData ? new ScDBData(*pDestData) : NULL; SCTAB nDestTab = rParam.nTab; ScArea aDestArea( rParam.nTab, rParam.nCol, rParam.nRow, rParam.nCol+nColSize-1, rParam.nRow+nRowSize-1 ); if (rParam.bByCol) ++aDestArea.nColEnd; if (rParam.bByRow) ++aDestArea.nRowEnd; if (rParam.bReferenceData) { SCTAB nTabCount = aDocument.GetTableCount(); SCROW nInsertCount = aData.GetInsertCount(); // alte Outlines ScOutlineTable* pTable = aDocument.GetOutlineTable( nDestTab ); ScOutlineTable* pUndoTab = pTable ? new ScOutlineTable( *pTable ) : NULL; ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); pUndoDoc->InitUndo( &aDocument, 0, nTabCount-1, FALSE, TRUE ); // Zeilenstatus aDocument.CopyToDocument( 0,0,nDestTab, MAXCOL,MAXROW,nDestTab, IDF_NONE, FALSE, pUndoDoc ); // alle Formeln aDocument.CopyToDocument( 0,0,0, MAXCOL,MAXROW,nTabCount-1, IDF_FORMULA, FALSE, pUndoDoc ); // komplette Ausgangszeilen aDocument.CopyToDocument( 0,aDestArea.nRowStart,nDestTab, MAXCOL,aDestArea.nRowEnd,nDestTab, IDF_ALL, FALSE, pUndoDoc ); // alten Ausgabebereich if (pDestData) aDocument.CopyToDocument( aOldDest, IDF_ALL, FALSE, pUndoDoc ); GetUndoManager()->AddUndoAction( new ScUndoConsolidate( this, aDestArea, rParam, pUndoDoc, TRUE, nInsertCount, pUndoTab, pUndoData ) ); } else { ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); pUndoDoc->InitUndo( &aDocument, aDestArea.nTab, aDestArea.nTab ); aDocument.CopyToDocument( aDestArea.nColStart, aDestArea.nRowStart, aDestArea.nTab, aDestArea.nColEnd, aDestArea.nRowEnd, aDestArea.nTab, IDF_ALL, FALSE, pUndoDoc ); // alten Ausgabebereich if (pDestData) aDocument.CopyToDocument( aOldDest, IDF_ALL, FALSE, pUndoDoc ); GetUndoManager()->AddUndoAction( new ScUndoConsolidate( this, aDestArea, rParam, pUndoDoc, FALSE, 0, NULL, pUndoData ) ); } } if (pDestData) // Zielbereich loeschen / anpassen { aDocument.DeleteAreaTab(aOldDest, IDF_CONTENTS); pDestData->SetArea( rParam.nTab, rParam.nCol, rParam.nRow, rParam.nCol + nColSize - 1, rParam.nRow + nRowSize - 1 ); pDestData->SetHeader( rParam.bByRow ); } aData.OutputToDocument( &aDocument, rParam.nCol, rParam.nRow, rParam.nTab ); SCCOL nPaintStartCol = rParam.nCol; SCROW nPaintStartRow = rParam.nRow; SCCOL nPaintEndCol = nPaintStartCol + nColSize - 1; SCROW nPaintEndRow = nPaintStartRow + nRowSize - 1; USHORT nPaintFlags = PAINT_GRID; if (rParam.bByCol) ++nPaintEndRow; if (rParam.bByRow) ++nPaintEndCol; if (rParam.bReferenceData) { nPaintStartCol = 0; nPaintEndCol = MAXCOL; nPaintEndRow = MAXROW; nPaintFlags |= PAINT_LEFT | PAINT_SIZE; } if (pDestData) { if ( aOldDest.aEnd.Col() > nPaintEndCol ) nPaintEndCol = aOldDest.aEnd.Col(); if ( aOldDest.aEnd.Row() > nPaintEndRow ) nPaintEndRow = aOldDest.aEnd.Row(); } PostPaint( nPaintStartCol, nPaintStartRow, rParam.nTab, nPaintEndCol, nPaintEndRow, rParam.nTab, nPaintFlags ); aModificator.SetDocumentModified(); } void ScDocShell::UseScenario( SCTAB nTab, const String& rName, BOOL bRecord ) { if (!aDocument.IsScenario(nTab)) { SCTAB nTabCount = aDocument.GetTableCount(); SCTAB nSrcTab = SCTAB_MAX; SCTAB nEndTab = nTab; String aCompare; while ( nEndTab+1 < nTabCount && aDocument.IsScenario(nEndTab+1) ) { ++nEndTab; if (nSrcTab > MAXTAB) // noch auf der Suche nach dem Szenario? { aDocument.GetName( nEndTab, aCompare ); if (aCompare == rName) nSrcTab = nEndTab; // gefunden } } if (ValidTab(nSrcTab)) { if ( aDocument.TestCopyScenario( nSrcTab, nTab ) ) // Zellschutz testen { ScDocShellModificator aModificator( *this ); ScMarkData aScenMark; aDocument.MarkScenario( nSrcTab, nTab, aScenMark ); ScRange aMultiRange; aScenMark.GetMultiMarkArea( aMultiRange ); SCCOL nStartCol = aMultiRange.aStart.Col(); SCROW nStartRow = aMultiRange.aStart.Row(); SCCOL nEndCol = aMultiRange.aEnd.Col(); SCROW nEndRow = aMultiRange.aEnd.Row(); if (bRecord) { ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); pUndoDoc->InitUndo( &aDocument, nTab,nEndTab ); // auch alle Szenarien // angezeigte Tabelle: aDocument.CopyToDocument( nStartCol,nStartRow,nTab, nEndCol,nEndRow,nTab, IDF_ALL,TRUE, pUndoDoc, &aScenMark ); // Szenarien for (SCTAB i=nTab+1; i<=nEndTab; i++) { pUndoDoc->SetScenario( i, TRUE ); String aComment; Color aColor; USHORT nScenFlags; aDocument.GetScenarioData( i, aComment, aColor, nScenFlags ); pUndoDoc->SetScenarioData( i, aComment, aColor, nScenFlags ); BOOL bActive = aDocument.IsActiveScenario( i ); pUndoDoc->SetActiveScenario( i, bActive ); // Bei Zurueckkopier-Szenarios auch Inhalte if ( nScenFlags & SC_SCENARIO_TWOWAY ) aDocument.CopyToDocument( 0,0,i, MAXCOL,MAXROW,i, IDF_ALL,FALSE, pUndoDoc ); } GetUndoManager()->AddUndoAction( new ScUndoUseScenario( this, aScenMark, ScArea( nTab,nStartCol,nStartRow,nEndCol,nEndRow ), pUndoDoc, rName ) ); } aDocument.CopyScenario( nSrcTab, nTab ); aDocument.SetDirty(); // alles painten, weil in anderen Bereichen das aktive Szenario // geaendert sein kann //! nur, wenn sichtbare Rahmen vorhanden? PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID ); aModificator.SetDocumentModified(); } else { InfoBox aBox(GetDialogParent(), ScGlobal::GetRscString( STR_PROTECTIONERR ) ); aBox.Execute(); } } else { InfoBox aBox(GetDialogParent(), ScGlobal::GetRscString( STR_SCENARIO_NOTFOUND ) ); aBox.Execute(); } } else DBG_ERROR( "UseScenario auf Szenario-Blatt" ); } void ScDocShell::ModifyScenario( SCTAB nTab, const String& rName, const String& rComment, const Color& rColor, USHORT nFlags ) { // Undo String aOldName; aDocument.GetName( nTab, aOldName ); String aOldComment; Color aOldColor; USHORT nOldFlags; aDocument.GetScenarioData( nTab, aOldComment, aOldColor, nOldFlags ); GetUndoManager()->AddUndoAction( new ScUndoScenarioFlags( this, nTab, aOldName, rName, aOldComment, rComment, aOldColor, rColor, nOldFlags, nFlags ) ); // ausfuehren ScDocShellModificator aModificator( *this ); aDocument.RenameTab( nTab, rName ); aDocument.SetScenarioData( nTab, rComment, rColor, nFlags ); PostPaintGridAll(); aModificator.SetDocumentModified(); if ( rName != aOldName ) SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); SfxBindings* pBindings = GetViewBindings(); if (pBindings) pBindings->Invalidate( SID_SELECT_SCENARIO ); } SCTAB ScDocShell::MakeScenario( SCTAB nTab, const String& rName, const String& rComment, const Color& rColor, USHORT nFlags, ScMarkData& rMark, BOOL bRecord ) { rMark.MarkToMulti(); if (rMark.IsMultiMarked()) { SCTAB nNewTab = nTab + 1; while (aDocument.IsScenario(nNewTab)) ++nNewTab; BOOL bCopyAll = ( (nFlags & SC_SCENARIO_COPYALL) != 0 ); const ScMarkData* pCopyMark = NULL; if (!bCopyAll) pCopyMark = &rMark; ScDocShellModificator aModificator( *this ); if (aDocument.CopyTab( nTab, nNewTab, pCopyMark )) { if (bRecord) { ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO ); pUndoDoc->InitUndo( &aDocument, nTab,nTab ); GetUndoManager()->AddUndoAction( new ScUndoMakeScenario( this, nTab, nNewTab, pUndoDoc, rName, rComment, rColor, nFlags, rMark )); } aDocument.RenameTab( nNewTab, rName, FALSE ); // ohne Formel-Update aDocument.SetScenario( nNewTab, TRUE ); aDocument.SetScenarioData( nNewTab, rComment, rColor, nFlags ); ScMarkData aDestMark = rMark; aDestMark.SelectOneTable( nNewTab ); //! auf Filter / Buttons / Merging testen ! ScPatternAttr aProtPattern( aDocument.GetPool() ); aProtPattern.GetItemSet().Put( ScProtectionAttr( TRUE ) ); aDocument.ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nNewTab, aProtPattern ); ScPatternAttr aPattern( aDocument.GetPool() ); aPattern.GetItemSet().Put( ScMergeFlagAttr( SC_MF_SCENARIO ) ); aPattern.GetItemSet().Put( ScProtectionAttr( TRUE ) ); aDocument.ApplySelectionPattern( aPattern, aDestMark ); if (!bCopyAll) aDocument.SetVisible( nNewTab, FALSE ); // dies ist dann das aktive Szenario aDocument.CopyScenario( nNewTab, nTab, TRUE ); // TRUE - nicht aus Szenario kopieren if (nFlags & SC_SCENARIO_SHOWFRAME) PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID ); // Rahmen painten PostPaintExtras(); // Tabellenreiter aModificator.SetDocumentModified(); SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); return nNewTab; } } return nTab; } BOOL ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, BOOL bCopy, BOOL bRecord ) { ScDocShellModificator aModificator( *this ); if (bCopy) { if (bRecord) aDocument.BeginDrawUndo(); // drawing layer must do its own undo actions if (!aDocument.CopyTab( nSrcTab, nDestTab )) { //! EndDrawUndo? return FALSE; } else { SCTAB nAdjSource = nSrcTab; if ( nDestTab <= nSrcTab ) ++nAdjSource; // new position of source table after CopyTab if ( aDocument.IsTabProtected( nAdjSource ) ) aDocument.SetTabProtection( nDestTab, TRUE, aDocument.GetTabPassword( nAdjSource ) ); if (bRecord) { SvShorts aSrcList; SvShorts aDestList; aSrcList.Insert(nSrcTab,0); aDestList.Insert(nDestTab,0); GetUndoManager()->AddUndoAction( new ScUndoCopyTab( this, aSrcList, aDestList ) ); } } Broadcast( ScTablesHint( SC_TAB_COPIED, nSrcTab, nDestTab ) ); } else { if ( aDocument.GetChangeTrack() ) return FALSE; if ( nSrcTabAddUndoAction( new ScUndoMoveTab( this, aSrcList, aDestList ) ); } Broadcast( ScTablesHint( SC_TAB_MOVED, nSrcTab, nDestTab ) ); } PostPaintGridAll(); PostPaintExtras(); aModificator.SetDocumentModified(); SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) ); return TRUE; } IMPL_LINK( ScDocShell, RefreshDBDataHdl, ScRefreshTimer*, pRefreshTimer ) { ScDBDocFunc aFunc(*this); BOOL bContinue = TRUE; ScDBData* pDBData = static_cast(pRefreshTimer); ScImportParam aImportParam; pDBData->GetImportParam( aImportParam ); if (aImportParam.bImport && !pDBData->HasImportSelection()) { ScRange aRange; pDBData->GetArea( aRange ); ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> xResultSet; bContinue = aFunc.DoImport( aRange.aStart.Tab(), aImportParam, xResultSet, NULL, TRUE, FALSE ); //! Api-Flag as parameter // internal operations (sort, query, subtotal) only if no error if (bContinue) { aFunc.RepeatDB( pDBData->GetName(), TRUE, TRUE ); RefreshPivotTables(aRange); } } return bContinue != 0; }