LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - documen2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 296 543 54.5 %
Date: 2012-12-27 Functions: 28 44 63.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : 
      23             : #include <editeng/editeng.hxx>
      24             : #include <editeng/forbiddencharacterstable.hxx>
      25             : #include <svx/xtable.hxx>
      26             : #include <sfx2/linkmgr.hxx>
      27             : #include <svx/svdpool.hxx>
      28             : #include <svx/svdobj.hxx>
      29             : #include <sfx2/bindings.hxx>
      30             : #include <sfx2/objsh.hxx>
      31             : #include <sfx2/docfile.hxx>
      32             : #include <sfx2/printer.hxx>
      33             : #include <svl/zforlist.hxx>
      34             : #include <svl/zformat.hxx>
      35             : #include <vcl/virdev.hxx>
      36             : #include <comphelper/processfactory.hxx>
      37             : #include <svl/PasswordHelper.hxx>
      38             : #include <tools/tenccvt.hxx>
      39             : #include <tools/urlobj.hxx>
      40             : #include <rtl/crc.h>
      41             : #include <basic/basmgr.hxx>
      42             : 
      43             : #include "document.hxx"
      44             : #include "table.hxx"
      45             : #include "attrib.hxx"
      46             : #include "patattr.hxx"
      47             : #include "rangenam.hxx"
      48             : #include "dbdata.hxx"
      49             : #include "pivot.hxx"
      50             : #include "docpool.hxx"
      51             : #include "stlpool.hxx"
      52             : #include "stlsheet.hxx"
      53             : #include "globstr.hrc"
      54             : #include "chartarr.hxx"
      55             : #include "chartlock.hxx"
      56             : #include "rechead.hxx"
      57             : #include "global.hxx"
      58             : #include "brdcst.hxx"
      59             : #include "bcaslot.hxx"
      60             : #include "adiasync.hxx"
      61             : #include "addinlis.hxx"
      62             : #include "chartlis.hxx"
      63             : #include "markdata.hxx"
      64             : #include "conditio.hxx"
      65             : #include "colorscale.hxx"
      66             : #include "validat.hxx"
      67             : #include "progress.hxx"
      68             : #include "detdata.hxx"
      69             : #include "sc.hrc"               // FID_DATACHANGED
      70             : #include "ddelink.hxx"
      71             : #include "chgtrack.hxx"
      72             : #include "chgviset.hxx"
      73             : #include "editutil.hxx"
      74             : #include "hints.hxx"
      75             : #include "dpobject.hxx"
      76             : #include "scrdata.hxx"
      77             : #include "poolhelp.hxx"
      78             : #include "unoreflist.hxx"
      79             : #include "listenercalls.hxx"
      80             : #include "recursionhelper.hxx"
      81             : #include "lookupcache.hxx"
      82             : #include "externalrefmgr.hxx"
      83             : #include "tabprotection.hxx"
      84             : #include "formulaparserpool.hxx"
      85             : #include "clipparam.hxx"
      86             : #include "macromgr.hxx"
      87             : 
      88             : using namespace com::sun::star;
      89             : 
      90             : // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
      91             : // dtor plus helpers are convenient.
      92           2 : struct ScLookupCacheMapImpl
      93             : {
      94             :     ScLookupCacheMap aCacheMap;
      95           1 :     ~ScLookupCacheMapImpl()
      96           1 :     {
      97           1 :         freeCaches();
      98           1 :     }
      99           8 :     void clear()
     100             :     {
     101           8 :         freeCaches();
     102             :         // Zap map.
     103           8 :         ScLookupCacheMap aTmp;
     104           8 :         aCacheMap.swap( aTmp);
     105           8 :     }
     106             : private:
     107           9 :     void freeCaches()
     108             :     {
     109          10 :         for (ScLookupCacheMap::iterator it( aCacheMap.begin()); it != aCacheMap.end(); ++it)
     110           1 :             delete (*it).second;
     111           9 :     }
     112             : };
     113             : 
     114             : // STATIC DATA -----------------------------------------------------------
     115             : 
     116         197 : ScDocument::ScDocument( ScDocumentMode  eMode,
     117             :                         SfxObjectShell* pDocShell ) :
     118             :         xServiceManager( ::comphelper::getProcessServiceFactory() ),
     119             :         mpUndoManager( NULL ),
     120             :         pEditEngine( NULL ),
     121             :         pNoteEngine( NULL ),
     122             :         pShell( pDocShell ),
     123             :         pPrinter( NULL ),
     124             :         pVirtualDevice_100th_mm( NULL ),
     125             :         pDrawLayer( NULL ),
     126             :         pValidationList( NULL ),
     127             :         pFormatExchangeList( NULL ),
     128             :         pRangeName(NULL),
     129             :         pDPCollection( NULL ),
     130             :         pLinkManager( NULL ),
     131             :         pFormulaTree( NULL ),
     132             :         pEOFormulaTree( NULL ),
     133             :         pFormulaTrack( NULL ),
     134             :         pEOFormulaTrack( NULL ),
     135             :         pClipData( NULL ),
     136             :         pDetOpList(NULL),
     137             :         pChangeTrack( NULL ),
     138             :         pUnoBroadcaster( NULL ),
     139             :         pUnoListenerCalls( NULL ),
     140             :         pUnoRefUndoList( NULL ),
     141             :         pChangeViewSettings( NULL ),
     142             :         pScriptTypeData( NULL ),
     143             :         pCacheFieldEditEngine( NULL ),
     144             :         pDocProtection( NULL ),
     145             :         mpClipParam( NULL),
     146             :         pExternalRefMgr( NULL ),
     147             :         mpMacroMgr( NULL ),
     148             :         pViewOptions( NULL ),
     149             :         pDocOptions( NULL ),
     150             :         pExtDocOptions( NULL ),
     151             :         pConsolidateDlgData( NULL ),
     152             :         pRecursionHelper( NULL ),
     153             :         pAutoNameCache( NULL ),
     154             :         pLookupCacheMapImpl( NULL ),
     155             :         nUnoObjectId( 0 ),
     156             :         nRangeOverflowType( 0 ),
     157             :         aCurTextWidthCalcPos(MAXCOL,0,0),
     158             :         aTableOpList( 0 ),
     159             :         nFormulaCodeInTree(0),
     160             :         nXMLImportedFormulaCount( 0 ),
     161             :         nInterpretLevel(0),
     162             :         nMacroInterpretLevel(0),
     163             :         nInterpreterTableOpLevel(0),
     164             :         nSrcVer( SC_CURRENT_VERSION ),
     165             :         nSrcMaxRow( MAXROW ),
     166             :         nFormulaTrackCount(0),
     167             :         bHardRecalcState(false),
     168             :         nVisibleTab( 0 ),
     169             :         eLinkMode(LM_UNKNOWN),
     170             :         bAutoCalc( eMode == SCDOCMODE_DOCUMENT ),
     171             :         bAutoCalcShellDisabled( false ),
     172             :         bForcedFormulaPending( false ),
     173             :         bCalculatingFormulaTree( false ),
     174             :         bIsClip( eMode == SCDOCMODE_CLIP ),
     175             :         bIsUndo( eMode == SCDOCMODE_UNDO ),
     176             :         bIsVisible( false ),
     177             :         bIsEmbedded( false ),
     178             :         bInsertingFromOtherDoc( false ),
     179             :         bLoadingMedium( false ),
     180             :         bImportingXML( false ),
     181             :         bXMLFromWrapper( false ),
     182             :         bCalcingAfterLoad( false ),
     183             :         bNoListening( false ),
     184             :         bIdleDisabled( false ),
     185             :         bInLinkUpdate( false ),
     186             :         bChartListenerCollectionNeedsUpdate( false ),
     187             :         bHasForcedFormulas( false ),
     188             :         bInDtorClear( false ),
     189             :         bExpandRefs( false ),
     190             :         bDetectiveDirty( false ),
     191             :         nMacroCallMode( SC_MACROCALL_ALLOWED ),
     192             :         bHasMacroFunc( false ),
     193             :         nVisSpellState( 0 ),
     194             :         nAsianCompression(SC_ASIANCOMPRESSION_INVALID),
     195             :         nAsianKerning(SC_ASIANKERNING_INVALID),
     196             :         bSetDrawDefaults( false ),
     197             :         bPastingDrawFromOtherDoc( false ),
     198             :         nInDdeLinkUpdate( 0 ),
     199             :         bInUnoBroadcast( false ),
     200             :         bInUnoListenerCall( false ),
     201             :         eGrammar( formula::FormulaGrammar::GRAM_NATIVE ),
     202             :         bStyleSheetUsageInvalid( true ),
     203             :         mbUndoEnabled( true ),
     204             :         mbAdjustHeightEnabled( true ),
     205             :         mbExecuteLinkEnabled( true ),
     206             :         mbChangeReadOnlyEnabled( false ),
     207             :         mbStreamValidLocked( false ),
     208             :         mbUserInteractionEnabled(true),
     209             :         mnNamedRangesLockCount( 0 ),
     210         197 :         mbIsInTest( false )
     211             : {
     212         197 :     SetStorageGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT);
     213             : 
     214         197 :     eSrcSet = osl_getThreadTextEncoding();
     215             : 
     216         197 :     if ( eMode == SCDOCMODE_DOCUMENT )
     217             :     {
     218         189 :         if ( pDocShell )
     219         189 :             pLinkManager = new sfx2::LinkManager( pDocShell );
     220             : 
     221         189 :         xPoolHelper = new ScPoolHelper( this );
     222             : 
     223         189 :         pBASM = new ScBroadcastAreaSlotMachine( this );
     224         189 :         pChartListenerCollection = new ScChartListenerCollection( this );
     225         189 :         pRefreshTimerControl = new ScRefreshTimerControl;
     226             :     }
     227             :     else
     228             :     {
     229           8 :         pBASM       = NULL;
     230           8 :         pChartListenerCollection = NULL;
     231           8 :         pRefreshTimerControl = NULL;
     232             :     }
     233         197 :     pDBCollection = new ScDBCollection(this);
     234         197 :     pSelectionAttr = NULL;
     235         197 :     pChartCollection = new ScChartCollection;
     236         197 :     apTemporaryChartLock = std::auto_ptr< ScTemporaryChartLock >( new ScTemporaryChartLock(this) );
     237         197 :     xColNameRanges = new ScRangePairList;
     238         197 :     xRowNameRanges = new ScRangePairList;
     239         197 :     ImplCreateOptions();
     240             :     // languages for a visible document are set by docshell later (from options)
     241         197 :     SetLanguage( ScGlobal::eLnge, ScGlobal::eLnge, ScGlobal::eLnge );
     242             : 
     243         197 :     aTrackTimer.SetTimeoutHdl( LINK( this, ScDocument, TrackTimeHdl ) );
     244         197 :     aTrackTimer.SetTimeout( 100 );
     245         197 : }
     246             : 
     247         403 : sfx2::LinkManager*  ScDocument::GetLinkManager()  const
     248             : {
     249         403 :     if ( bAutoCalc && !pLinkManager && pShell)
     250             :     {
     251           0 :         pLinkManager = new sfx2::LinkManager( pShell );
     252             :     }
     253         403 :     return pLinkManager;
     254             : }
     255             : 
     256             : 
     257         227 : void ScDocument::SetStorageGrammar( formula::FormulaGrammar::Grammar eGram )
     258             : {
     259             :     OSL_PRECOND(
     260             :         eGram == formula::FormulaGrammar::GRAM_ODFF ||
     261             :             eGram == formula::FormulaGrammar::GRAM_PODF,
     262             :             "ScDocument::SetStorageGrammar: wrong storage grammar");
     263             : 
     264         227 :     eStorageGrammar = eGram;
     265             : 
     266             :     // FIXME: the XML import shouldn't strip brackets, the compiler should
     267             :     // digest them instead, which could also speedup reference recognition
     268             :     // during import.
     269             : 
     270             :     eXmlImportGrammar = formula::FormulaGrammar::mergeToGrammar( eGram,
     271         227 :             formula::FormulaGrammar::CONV_OOO);
     272         227 : }
     273             : 
     274             : 
     275           0 : void ScDocument::SetDocVisible( bool bSet )
     276             : {
     277             :     //  called from view ctor - only for a visible document,
     278             :     //  each new sheet's RTL flag is initialized from the locale
     279           0 :     bIsVisible = bSet;
     280           0 : }
     281             : 
     282             : 
     283           0 : sal_uInt32 ScDocument::GetDocumentID() const
     284             : {
     285           0 :     const ScDocument* pThis = this;
     286           0 :     sal_uInt32 nCrc = rtl_crc32( 0, &pThis, sizeof(ScDocument*) );
     287             :     // the this pointer only might not be sufficient
     288           0 :     nCrc = rtl_crc32( nCrc, &pShell, sizeof(SfxObjectShell*) );
     289           0 :     return nCrc;
     290             : }
     291             : 
     292             : 
     293           0 : void ScDocument::StartChangeTracking()
     294             : {
     295           0 :     if (!pChangeTrack)
     296           0 :         pChangeTrack = new ScChangeTrack( this );
     297           0 : }
     298             : 
     299           0 : void ScDocument::EndChangeTracking()
     300             : {
     301           0 :     delete pChangeTrack;
     302           0 :     pChangeTrack = NULL;
     303           0 : }
     304             : 
     305           0 : void ScDocument::SetChangeTrack( ScChangeTrack* pTrack )
     306             : {
     307             :     OSL_ENSURE( pTrack->GetDocument() == this, "SetChangeTrack: different documents" );
     308           0 :     if ( !pTrack || pTrack == pChangeTrack || pTrack->GetDocument() != this )
     309           0 :         return ;
     310           0 :     EndChangeTracking();
     311           0 :     pChangeTrack = pTrack;
     312             : }
     313             : 
     314             : 
     315           0 : IMPL_LINK_NOARG(ScDocument, TrackTimeHdl)
     316             : {
     317           0 :     if ( ScDdeLink::IsInUpdate() )      // nicht verschachteln
     318             :     {
     319           0 :         aTrackTimer.Start();            // spaeter nochmal versuchen
     320             :     }
     321           0 :     else if (pShell)                    // ausfuehren
     322             :     {
     323           0 :         TrackFormulas();
     324           0 :         pShell->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
     325             : 
     326             :             //  modified...
     327             : 
     328           0 :         if (!pShell->IsModified())
     329             :         {
     330           0 :             pShell->SetModified( true );
     331           0 :             SfxBindings* pBindings = GetViewBindings();
     332           0 :             if (pBindings)
     333             :             {
     334           0 :                 pBindings->Invalidate( SID_SAVEDOC );
     335           0 :                 pBindings->Invalidate( SID_DOC_MODIFIED );
     336             :             }
     337             :         }
     338             :     }
     339             : 
     340           0 :     return 0;
     341             : }
     342             : 
     343           0 : void ScDocument::StartTrackTimer()
     344             : {
     345           0 :     if (!aTrackTimer.IsActive())        // nicht ewig aufschieben
     346           0 :         aTrackTimer.Start();
     347           0 : }
     348             : 
     349         222 : ScDocument::~ScDocument()
     350             : {
     351             :     OSL_PRECOND( !bInLinkUpdate, "bInLinkUpdate in dtor" );
     352             : 
     353         111 :     bInDtorClear = true;
     354             : 
     355             :     // first of all disable all refresh timers by deleting the control
     356         111 :     if ( pRefreshTimerControl )
     357             :     {   // To be sure there isn't anything running do it with a protector,
     358             :         // this ensures also that nothing needs the control anymore.
     359         108 :         ScRefreshTimerProtector aProt( GetRefreshTimerControlAddress() );
     360         108 :         delete pRefreshTimerControl, pRefreshTimerControl = NULL;
     361             :     }
     362             : 
     363             :     // Links aufrauemen
     364             : 
     365         111 :     if ( GetLinkManager() )
     366             :     {
     367             :         // BaseLinks freigeben
     368         108 :         ::sfx2::SvLinkSources aTemp(pLinkManager->GetServers());
     369         108 :         for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it )
     370           0 :             (*it)->Closed();
     371             : 
     372         108 :         if ( pLinkManager->GetLinks().size() )
     373           0 :             pLinkManager->Remove( 0, pLinkManager->GetLinks().size() );
     374             :     }
     375             : 
     376         111 :     mxFormulaParserPool.reset();
     377             :     // Destroy the external ref mgr instance here because it has a timer
     378             :     // which needs to be stopped before the app closes.
     379         111 :     pExternalRefMgr.reset();
     380             : 
     381         111 :     ScAddInAsync::RemoveDocument( this );
     382         111 :     ScAddInListener::RemoveDocument( this );
     383         111 :     DELETEZ( pChartListenerCollection);   // vor pBASM wg. evtl. Listener!
     384         111 :     DELETEZ( pLookupCacheMapImpl);  // before pBASM because of listeners
     385             :     // BroadcastAreas vor allen Zellen zerstoeren um unnoetige
     386             :     // Einzel-EndListenings der Formelzellen zu vermeiden
     387         111 :     delete pBASM;       // BroadcastAreaSlotMachine
     388         111 :     pBASM = NULL;
     389             : 
     390         111 :     delete pUnoBroadcaster;     // broadcasted nochmal SFX_HINT_DYING
     391         111 :     pUnoBroadcaster = NULL;
     392             : 
     393         111 :     delete pUnoRefUndoList;
     394         111 :     delete pUnoListenerCalls;
     395             : 
     396         111 :     Clear( true );              // true = from destructor (needed for SdrModel::ClearModel)
     397             : 
     398         111 :     if (pValidationList)
     399             :     {
     400           5 :         for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
     401           3 :             delete *it;
     402           2 :         pValidationList->clear();
     403           2 :         DELETEZ(pValidationList);
     404             :     }
     405         111 :     delete pRangeName;
     406         111 :     delete pDBCollection;
     407         111 :     delete pSelectionAttr;
     408         111 :     apTemporaryChartLock.reset();
     409         111 :     delete pChartCollection;
     410         111 :     DeleteDrawLayer();
     411         111 :     delete pFormatExchangeList;
     412         111 :     delete pPrinter;
     413         111 :     ImplDeleteOptions();
     414         111 :     delete pConsolidateDlgData;
     415         111 :     delete pLinkManager;
     416         111 :     delete pClipData;
     417         111 :     delete pDetOpList;                  // loescht auch die Eintraege
     418         111 :     delete pChangeTrack;
     419         111 :     delete pEditEngine;
     420         111 :     delete pNoteEngine;
     421         111 :     delete pChangeViewSettings;         // und weg damit
     422         111 :     delete pVirtualDevice_100th_mm;
     423             : 
     424         111 :     delete pDPCollection;
     425             : 
     426             :     // delete the EditEngine before destroying the xPoolHelper
     427         111 :     delete pCacheFieldEditEngine;
     428             : 
     429         111 :     if ( xPoolHelper.is() && !bIsClip )
     430         109 :         xPoolHelper->SourceDocumentGone();
     431         111 :     xPoolHelper.clear();
     432             : 
     433         111 :     delete pScriptTypeData;
     434         111 :     delete pRecursionHelper;
     435             : 
     436             :     OSL_POSTCOND( !pAutoNameCache, "AutoNameCache still set in dtor" );
     437         111 : }
     438             : 
     439           3 : void ScDocument::InitClipPtrs( ScDocument* pSourceDoc )
     440             : {
     441             :     OSL_ENSURE(bIsClip, "InitClipPtrs und nicht bIsClip");
     442             : 
     443           3 :     if (pValidationList)
     444             :     {
     445           0 :         for(ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
     446           0 :             delete *it;
     447           0 :         pValidationList->clear();
     448           0 :         DELETEZ(pValidationList);
     449             :     }
     450             : 
     451           3 :     Clear();
     452             : 
     453           3 :     xPoolHelper = pSourceDoc->xPoolHelper;
     454             : 
     455             :     //  bedingte Formate / Gueltigkeiten
     456             :     //! Vorlagen kopieren?
     457           3 :     const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList;
     458           3 :     if ( pSourceValid )
     459           0 :         pValidationList = new ScValidationDataList(this, *pSourceValid);
     460             : 
     461             :                         // Links in Stream speichern
     462           3 :     delete pClipData;
     463           3 :     if (pSourceDoc->HasDdeLinks())
     464             :     {
     465           0 :         pClipData = new SvMemoryStream;
     466           0 :         pSourceDoc->SaveDdeLinks(*pClipData);
     467             :     }
     468             :     else
     469           3 :         pClipData = NULL;
     470             : 
     471             :     // Options pointers exist (ImplCreateOptions) for any document.
     472             :     // Must be copied for correct results in OLE objects (#i42666#).
     473           3 :     SetDocOptions( pSourceDoc->GetDocOptions() );
     474           3 :     SetViewOptions( pSourceDoc->GetViewOptions() );
     475           3 : }
     476             : 
     477       22790 : SvNumberFormatter* ScDocument::GetFormatTable() const
     478             : {
     479       22790 :     return xPoolHelper->GetFormTable();
     480             : }
     481             : 
     482          93 : SfxItemPool* ScDocument::GetEditPool() const
     483             : {
     484          93 :     return xPoolHelper->GetEditPool();
     485             : }
     486             : 
     487          25 : SfxItemPool* ScDocument::GetEnginePool() const
     488             : {
     489          25 :     return xPoolHelper->GetEnginePool();
     490             : }
     491             : 
     492          48 : ScFieldEditEngine& ScDocument::GetEditEngine()
     493             : {
     494          48 :     if ( !pEditEngine )
     495             :     {
     496           6 :         pEditEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
     497           6 :         pEditEngine->SetUpdateMode( false );
     498           6 :         pEditEngine->EnableUndo( false );
     499           6 :         pEditEngine->SetRefMapMode( MAP_100TH_MM );
     500           6 :         ApplyAsianEditSettings( *pEditEngine );
     501             :     }
     502          48 :     return *pEditEngine;
     503             : }
     504             : 
     505           0 : ScNoteEditEngine& ScDocument::GetNoteEngine()
     506             : {
     507           0 :     if ( !pNoteEngine )
     508             :     {
     509           0 :         pNoteEngine = new ScNoteEditEngine( GetEnginePool(), GetEditPool() );
     510           0 :         pNoteEngine->SetUpdateMode( false );
     511           0 :         pNoteEngine->EnableUndo( false );
     512           0 :         pNoteEngine->SetRefMapMode( MAP_100TH_MM );
     513           0 :         ApplyAsianEditSettings( *pNoteEngine );
     514           0 :         const SfxItemSet& rItemSet = GetDefPattern()->GetItemSet();
     515           0 :         SfxItemSet* pEEItemSet = new SfxItemSet( pNoteEngine->GetEmptyItemSet() );
     516           0 :         ScPatternAttr::FillToEditItemSet( *pEEItemSet, rItemSet );
     517           0 :         pNoteEngine->SetDefaults( pEEItemSet );      // edit engine takes ownership
     518             :     }
     519           0 :     return *pNoteEngine;
     520             : }
     521             : 
     522             : 
     523           3 : void ScDocument::ResetClip( ScDocument* pSourceDoc, const ScMarkData* pMarks )
     524             : {
     525           3 :     if (bIsClip)
     526             :     {
     527           3 :         InitClipPtrs(pSourceDoc);
     528             : 
     529           9 :         for (SCTAB i = 0; i < static_cast<SCTAB>(pSourceDoc->maTabs.size()); i++)
     530           6 :             if (pSourceDoc->maTabs[i])
     531           6 :                 if (!pMarks || pMarks->GetTableSelect(i))
     532             :                 {
     533           3 :                     rtl::OUString aString;
     534           3 :                     pSourceDoc->maTabs[i]->GetName(aString);
     535           3 :                     if ( i < static_cast<SCTAB>(maTabs.size()) )
     536             :                     {
     537           0 :                         maTabs[i] = new ScTable(this, i, aString);
     538             : 
     539             :                     }
     540             :                     else
     541             :                     {
     542           3 :                         if( i > static_cast<SCTAB>(maTabs.size()) )
     543             :                         {
     544           0 :                             maTabs.resize(i, NULL );
     545             :                         }
     546           3 :                         maTabs.push_back(new ScTable(this, i, aString));
     547             :                     }
     548           3 :                     maTabs[i]->SetLayoutRTL( pSourceDoc->maTabs[i]->IsLayoutRTL() );
     549             :                 }
     550             :     }
     551             :     else
     552             :     {
     553             :         OSL_FAIL("ResetClip");
     554             :     }
     555           3 : }
     556             : 
     557           0 : void ScDocument::ResetClip( ScDocument* pSourceDoc, SCTAB nTab )
     558             : {
     559           0 :     if (bIsClip)
     560             :     {
     561           0 :         InitClipPtrs(pSourceDoc);
     562           0 :         if (nTab >= static_cast<SCTAB>(maTabs.size()))
     563             :         {
     564           0 :             maTabs.resize(nTab+1, NULL );
     565             :         }
     566           0 :         maTabs[nTab] = new ScTable(this, nTab,
     567           0 :                             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baeh")));
     568           0 :         if (nTab < static_cast<SCTAB>(pSourceDoc->maTabs.size()) && pSourceDoc->maTabs[nTab])
     569           0 :             maTabs[nTab]->SetLayoutRTL( pSourceDoc->maTabs[nTab]->IsLayoutRTL() );
     570             :     }
     571             :     else
     572             :     {
     573             :         OSL_FAIL("ResetClip");
     574             :     }
     575           0 : }
     576             : 
     577           0 : void ScDocument::PutCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
     578             :                           ScBaseCell* pCell, sal_uLong nFormatIndex, bool bForceTab )
     579             : {
     580           0 :     if (VALIDTAB(nTab))
     581             :     {
     582           0 :         if ( bForceTab && ( nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab] ) )
     583             :         {
     584           0 :             bool bExtras = !bIsUndo;        // Spaltenbreiten, Zeilenhoehen, Flags
     585           0 :             if ( nTab >= static_cast<SCTAB>(maTabs.size()) )
     586             :             {
     587           0 :                 maTabs.resize( nTab + 1, NULL );
     588             :             }
     589           0 :             maTabs.at(nTab) = new ScTable(this, nTab,
     590             :                                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("temp")),
     591           0 :                                     bExtras, bExtras);
     592             :         }
     593             : 
     594           0 :         if ( nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
     595           0 :             maTabs[nTab]->PutCell( nCol, nRow, nFormatIndex, pCell );
     596             :     }
     597           0 : }
     598             : 
     599             : 
     600          75 : bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
     601             :                                 bool bNotes ) const
     602             : {
     603          75 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     604             :     {
     605          75 :         bool bAny = maTabs[nTab]->GetPrintArea( rEndCol, rEndRow, bNotes );
     606          75 :         if (pDrawLayer)
     607             :         {
     608          33 :             ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
     609          33 :             if (DrawGetPrintArea( aDrawRange, true, true ))
     610             :             {
     611           0 :                 if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
     612           0 :                 if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
     613           0 :                 bAny = true;
     614             :             }
     615             :         }
     616          75 :         return bAny;
     617             :     }
     618             : 
     619           0 :     rEndCol = 0;
     620           0 :     rEndRow = 0;
     621           0 :     return false;
     622             : }
     623             : 
     624           0 : bool ScDocument::GetPrintAreaHor( SCTAB nTab, SCROW nStartRow, SCROW nEndRow,
     625             :                                         SCCOL& rEndCol, bool bNotes ) const
     626             : {
     627           0 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     628             :     {
     629           0 :         bool bAny = maTabs[nTab]->GetPrintAreaHor( nStartRow, nEndRow, rEndCol, bNotes );
     630           0 :         if (pDrawLayer)
     631             :         {
     632           0 :             ScRange aDrawRange(0,nStartRow,nTab, MAXCOL,nEndRow,nTab);
     633           0 :             if (DrawGetPrintArea( aDrawRange, true, false ))
     634             :             {
     635           0 :                 if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
     636           0 :                 bAny = true;
     637             :             }
     638             :         }
     639           0 :         return bAny;
     640             :     }
     641             : 
     642           0 :     rEndCol = 0;
     643           0 :     return false;
     644             : }
     645             : 
     646          17 : bool ScDocument::GetPrintAreaVer( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol,
     647             :                                         SCROW& rEndRow, bool bNotes ) const
     648             : {
     649          17 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     650             :     {
     651          17 :         bool bAny = maTabs[nTab]->GetPrintAreaVer( nStartCol, nEndCol, rEndRow, bNotes );
     652          17 :         if (pDrawLayer)
     653             :         {
     654          17 :             ScRange aDrawRange(nStartCol,0,nTab, nEndCol,MAXROW,nTab);
     655          17 :             if (DrawGetPrintArea( aDrawRange, false, true ))
     656             :             {
     657           0 :                 if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
     658           0 :                 bAny = true;
     659             :             }
     660             :         }
     661          17 :         return bAny;
     662             :     }
     663             : 
     664           0 :     rEndRow = 0;
     665           0 :     return false;
     666             : }
     667             : 
     668           6 : bool ScDocument::GetDataStart( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow ) const
     669             : {
     670           6 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     671             :     {
     672           6 :         bool bAny = maTabs[nTab]->GetDataStart( rStartCol, rStartRow );
     673           6 :         if (pDrawLayer)
     674             :         {
     675           4 :             ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
     676           4 :             if (DrawGetPrintArea( aDrawRange, true, true ))
     677             :             {
     678           0 :                 if (aDrawRange.aStart.Col()<rStartCol) rStartCol=aDrawRange.aStart.Col();
     679           0 :                 if (aDrawRange.aStart.Row()<rStartRow) rStartRow=aDrawRange.aStart.Row();
     680           0 :                 bAny = true;
     681             :             }
     682             :         }
     683           6 :         return bAny;
     684             :     }
     685             : 
     686           0 :     rStartCol = 0;
     687           0 :     rStartRow = 0;
     688           0 :     return false;
     689             : }
     690             : 
     691           5 : bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
     692             : {
     693           5 :     if (nOldPos == nNewPos)
     694           0 :         return false;
     695             : 
     696           5 :     SCTAB nTabCount = static_cast<SCTAB>(maTabs.size());
     697           5 :     if(nTabCount < 2)
     698           0 :         return false;
     699             : 
     700           5 :     bool bValid = false;
     701           5 :     if (VALIDTAB(nOldPos) && nOldPos < nTabCount )
     702             :     {
     703           5 :         if (maTabs[nOldPos])
     704             :         {
     705           5 :             bool bOldAutoCalc = GetAutoCalc();
     706           5 :             SetAutoCalc( false );   // Mehrfachberechnungen vermeiden
     707           5 :             SetNoListening( true );
     708           5 :             if (nNewPos == SC_TAB_APPEND || nNewPos >= nTabCount)
     709           0 :                 nNewPos = nTabCount-1;
     710             : 
     711             :             //  Referenz-Updaterei
     712             :             //! mit UpdateReference zusammenfassen!
     713             : 
     714           5 :             SCsTAB nDz = ((SCsTAB)nNewPos) - (SCsTAB)nOldPos;
     715           5 :             ScRange aSourceRange( 0,0,nOldPos, MAXCOL,MAXROW,nOldPos );
     716           5 :             if (pRangeName)
     717           1 :                 pRangeName->UpdateTabRef(nOldPos, 3, nNewPos);
     718           5 :             pDBCollection->UpdateMoveTab( nOldPos, nNewPos );
     719           5 :             xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
     720           5 :             xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
     721           5 :             if (pDPCollection)
     722           2 :                 pDPCollection->UpdateReference( URM_REORDER, aSourceRange, 0,0,nDz );
     723           5 :             if (pDetOpList)
     724           0 :                 pDetOpList->UpdateReference( this, URM_REORDER, aSourceRange, 0,0,nDz );
     725             :             UpdateChartRef( URM_REORDER,
     726           5 :                     0,0,nOldPos, MAXCOL,MAXROW,nOldPos, 0,0,nDz );
     727           5 :             UpdateRefAreaLinks( URM_REORDER, aSourceRange, 0,0,nDz );
     728           5 :             if ( pValidationList )
     729           0 :                 pValidationList->UpdateMoveTab( nOldPos, nNewPos );
     730           5 :             if ( pUnoBroadcaster )
     731             :                 pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_REORDER,
     732           5 :                             aSourceRange, 0,0,nDz ) );
     733             : 
     734           5 :             ScTable* pSaveTab = maTabs[nOldPos];
     735           5 :             maTabs.erase(maTabs.begin()+nOldPos);
     736           5 :             maTabs.insert(maTabs.begin()+nNewPos, pSaveTab);
     737           5 :             TableContainer::iterator it = maTabs.begin();
     738          15 :             for (SCTAB i = 0; i < nTabCount; i++)
     739          10 :                 if (maTabs[i])
     740          10 :                     maTabs[i]->UpdateMoveTab( nOldPos, nNewPos, i, pProgress );
     741           5 :             it = maTabs.begin();
     742          15 :             for (; it != maTabs.end(); ++it)
     743          10 :                 if (*it)
     744          10 :                     (*it)->UpdateCompile();
     745           5 :             SetNoListening( false );
     746           5 :             it = maTabs.begin();
     747          15 :             for (; it != maTabs.end(); ++it)
     748          10 :                 if (*it)
     749          10 :                     (*it)->StartAllListeners();
     750             :             // sheet names of references may not be valid until sheet is moved
     751           5 :             pChartListenerCollection->UpdateScheduledSeriesRanges();
     752           5 :             SetDirty();
     753           5 :             SetAutoCalc( bOldAutoCalc );
     754             : 
     755           5 :             if (pDrawLayer)
     756           1 :                 DrawMovePage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
     757             : 
     758           5 :             bValid = true;
     759             :         }
     760             :     }
     761           5 :     return bValid;
     762             : }
     763             : 
     764           3 : bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyMarked )
     765             : {
     766           3 :     if (SC_TAB_APPEND == nNewPos  || nNewPos >= static_cast<SCTAB>(maTabs.size()))
     767           3 :         nNewPos = static_cast<SCTAB>(maTabs.size());
     768           3 :     rtl::OUString aName;
     769           3 :     GetName(nOldPos, aName);
     770             : 
     771             :     //  vorneweg testen, ob der Prefix als gueltig erkannt wird
     772             :     //  wenn nicht, nur doppelte vermeiden
     773           3 :     bool bPrefix = ValidTabName( aName );
     774             :     OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
     775             :     SCTAB nDummy;
     776             : 
     777           3 :     CreateValidTabName(aName);
     778             : 
     779             :     bool bValid;
     780           3 :     if (bPrefix)
     781           3 :         bValid = ValidNewTabName(aName);
     782             :     else
     783           0 :         bValid = !GetTable( aName, nDummy );
     784             : 
     785           3 :     bool bOldAutoCalc = GetAutoCalc();
     786           3 :     SetAutoCalc( false );   // Mehrfachberechnungen vermeiden
     787           3 :     if (bValid)
     788             :     {
     789           3 :         if (nNewPos >= static_cast<SCTAB>(maTabs.size()))
     790             :         {
     791           3 :             nNewPos = static_cast<SCTAB>(maTabs.size());
     792           3 :             maTabs.push_back(new ScTable(this, nNewPos, aName));
     793             :         }
     794             :         else
     795             :         {
     796           0 :             if (VALIDTAB(nNewPos) && (nNewPos < static_cast<SCTAB>(maTabs.size())))
     797             :             {
     798           0 :                 SetNoListening( true );
     799             : 
     800           0 :                 ScRange aRange( 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB );
     801           0 :                 xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
     802           0 :                 xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
     803           0 :                 if (pRangeName)
     804           0 :                     pRangeName->UpdateTabRef(nNewPos, 1);
     805             :                 pDBCollection->UpdateReference(
     806           0 :                                     URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
     807           0 :                 if (pDPCollection)
     808           0 :                     pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,1 );
     809           0 :                 if (pDetOpList)
     810           0 :                     pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,1 );
     811           0 :                 UpdateChartRef( URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
     812           0 :                 UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,1 );
     813           0 :                 if ( pUnoBroadcaster )
     814           0 :                     pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,1 ) );
     815             : 
     816             :                 SCTAB i;
     817           0 :                 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
     818           0 :                     if (*it && it != (maTabs.begin() + nOldPos))
     819           0 :                         (*it)->UpdateInsertTab(nNewPos);
     820           0 :                 maTabs.push_back(NULL);
     821           0 :                 for (i = static_cast<SCTAB>(maTabs.size())-1; i > nNewPos; i--)
     822           0 :                     maTabs[i] = maTabs[i - 1];
     823           0 :                 if (nNewPos <= nOldPos)
     824           0 :                     nOldPos++;
     825           0 :                 maTabs[nNewPos] = new ScTable(this, nNewPos, aName);
     826           0 :                 bValid = true;
     827           0 :                 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
     828           0 :                     if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin() + nNewPos)
     829           0 :                         (*it)->UpdateCompile();
     830           0 :                 SetNoListening( false );
     831           0 :                 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
     832           0 :                     if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin()+nNewPos)
     833           0 :                         (*it)->StartAllListeners();
     834             : 
     835           0 :                 if ( pValidationList )
     836           0 :                     pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,1 );
     837             :                 // sheet names of references may not be valid until sheet is copied
     838           0 :                 pChartListenerCollection->UpdateScheduledSeriesRanges();
     839             :             }
     840             :             else
     841           0 :                 bValid = false;
     842             :         }
     843             :     }
     844           3 :     if (bValid)
     845             :     {
     846           3 :         SetNoListening( true );     // noch nicht bei CopyToTable/Insert
     847           3 :         maTabs[nOldPos]->CopyToTable(0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
     848           6 :                                         maTabs[nNewPos], pOnlyMarked );
     849           3 :         maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
     850             : 
     851           3 :         SCsTAB nDz = (static_cast<SCsTAB>(nNewPos)) - static_cast<SCsTAB>(nOldPos);
     852           3 :         maTabs[nNewPos]->UpdateReference(URM_COPY, 0, 0, nNewPos , MAXCOL, MAXROW,
     853           6 :                                         nNewPos, 0, 0, nDz, NULL);
     854             : 
     855           3 :         maTabs[nNewPos]->UpdateInsertTabAbs(nNewPos); // alle abs. um eins hoch!!
     856           3 :         maTabs[nOldPos]->UpdateInsertTab(nNewPos);
     857             : 
     858           3 :         maTabs[nOldPos]->UpdateCompile();
     859           3 :         maTabs[nNewPos]->UpdateCompile( true ); //  maybe already compiled in Clone, but used names need recompilation
     860           3 :         SetNoListening( false );
     861           3 :         maTabs[nOldPos]->StartAllListeners();
     862           3 :         maTabs[nNewPos]->StartAllListeners();
     863             : 
     864           3 :         ScConditionalFormatList* pNewList = new ScConditionalFormatList(*maTabs[nOldPos]->GetCondFormList());
     865             :         pNewList->UpdateReference(URM_COPY, ScRange( 0, 0, nNewPos , MAXCOL, MAXROW,
     866           3 :                                         nNewPos), 0, 0, nDz);
     867           3 :         maTabs[nNewPos]->SetCondFormList( pNewList );
     868             : 
     869           3 :         SetDirty();
     870           3 :         SetAutoCalc( bOldAutoCalc );
     871             : 
     872           3 :         if (pDrawLayer)
     873           1 :             DrawCopyPage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
     874             : 
     875           3 :         if (pDPCollection)
     876           0 :             pDPCollection->CopyToTab(nOldPos, nNewPos);
     877             : 
     878           3 :         maTabs[nNewPos]->SetPageStyle( maTabs[nOldPos]->GetPageStyle() );
     879           3 :         maTabs[nNewPos]->SetPendingRowHeights( maTabs[nOldPos]->IsPendingRowHeights() );
     880             : 
     881             :         // Copy the custom print range if exists.
     882           3 :         maTabs[nNewPos]->CopyPrintRange(*maTabs[nOldPos]);
     883             : 
     884             :         // Copy the RTL settings
     885           3 :         maTabs[nNewPos]->SetLayoutRTL(maTabs[nOldPos]->IsLayoutRTL());
     886           3 :         maTabs[nNewPos]->SetLoadingRTL(maTabs[nOldPos]->IsLoadingRTL());
     887             :     }
     888             :     else
     889           0 :         SetAutoCalc( bOldAutoCalc );
     890           3 :     return bValid;
     891             : }
     892             : 
     893             : void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const rtl::OUString& sModuleName, const rtl::OUString& sModuleSource );
     894             : 
     895           0 : sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
     896             :                                 SCTAB nDestPos, bool bInsertNew,
     897             :                                 bool bResultsOnly )
     898             : {
     899           0 :     sal_uLong nRetVal = 1;                      // 0 => Fehler 1 = ok
     900             :                                             // 3 => NameBox
     901             :                                             // 4 => beides
     902             : 
     903           0 :     if (pSrcDoc->pShell->GetMedium())
     904             :     {
     905           0 :         pSrcDoc->maFileURL = pSrcDoc->pShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI);
     906             :         // for unsaved files use the title name and adjust during save of file
     907           0 :         if (pSrcDoc->maFileURL.isEmpty())
     908           0 :             pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
     909             :     }
     910             :     else
     911             :     {
     912           0 :         pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
     913             :     }
     914             : 
     915           0 :     bool bValid = true;
     916           0 :     if (bInsertNew)             // neu einfuegen
     917             :     {
     918           0 :         rtl::OUString aName;
     919           0 :         pSrcDoc->GetName(nSrcPos, aName);
     920           0 :         CreateValidTabName(aName);
     921           0 :         bValid = InsertTab(nDestPos, aName);
     922             : 
     923             :         // Copy the RTL settings
     924           0 :         maTabs[nDestPos]->SetLayoutRTL(pSrcDoc->maTabs[nSrcPos]->IsLayoutRTL());
     925           0 :         maTabs[nDestPos]->SetLoadingRTL(pSrcDoc->maTabs[nSrcPos]->IsLoadingRTL());
     926             :     }
     927             :     else                        // bestehende Tabelle ersetzen
     928             :     {
     929           0 :         if (VALIDTAB(nDestPos) && nDestPos < static_cast<SCTAB>(maTabs.size()) && maTabs[nDestPos])
     930             :         {
     931           0 :             maTabs[nDestPos]->DeleteArea( 0,0, MAXCOL,MAXROW, IDF_ALL );
     932             :         }
     933             :         else
     934           0 :             bValid = false;
     935             :     }
     936             : 
     937           0 :     if (bValid)
     938             :     {
     939           0 :         bool bOldAutoCalcSrc = false;
     940           0 :         bool bOldAutoCalc = GetAutoCalc();
     941           0 :         SetAutoCalc( false );   // Mehrfachberechnungen vermeiden
     942           0 :         SetNoListening( true );
     943           0 :         if ( bResultsOnly )
     944             :         {
     945           0 :             bOldAutoCalcSrc = pSrcDoc->GetAutoCalc();
     946           0 :             pSrcDoc->SetAutoCalc( true );   // falls was berechnet werden muss
     947             :         }
     948             : 
     949             :         {
     950           0 :             NumFmtMergeHandler aNumFmtMergeHdl(this, pSrcDoc);
     951             : 
     952           0 :             nDestPos = Min(nDestPos, (SCTAB)(GetTableCount() - 1));
     953             :             {   // scope for bulk broadcast
     954           0 :                 ScBulkBroadcast aBulkBroadcast( pBASM);
     955           0 :                 pSrcDoc->maTabs[nSrcPos]->CopyToTable(0, 0, MAXCOL, MAXROW,
     956             :                         ( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL),
     957           0 :                         false, maTabs[nDestPos] );
     958           0 :             }
     959             :         }
     960           0 :         maTabs[nDestPos]->SetTabNo(nDestPos);
     961           0 :         maTabs[nDestPos]->SetTabBgColor(pSrcDoc->maTabs[nSrcPos]->GetTabBgColor());
     962             : 
     963           0 :         if ( !bResultsOnly )
     964             :         {
     965             : 
     966           0 :             SCsTAB nDz = ((SCsTAB)nDestPos) - (SCsTAB)nSrcPos;
     967           0 :             maTabs[nDestPos]->UpdateReference(URM_COPY, 0, 0, nDestPos,
     968             :                                                      MAXCOL, MAXROW, nDestPos,
     969           0 :                                                      0, 0, nDz, NULL);
     970             :             // Readjust self-contained absolute references to this sheet
     971           0 :             maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
     972           0 :             maTabs[nDestPos]->CompileAll();
     973             :         }
     974             : 
     975           0 :         SetNoListening( false );
     976           0 :         if ( !bResultsOnly )
     977           0 :             maTabs[nDestPos]->StartAllListeners();
     978           0 :         SetDirty( ScRange( 0, 0, nDestPos, MAXCOL, MAXROW, nDestPos));
     979             : 
     980           0 :         if ( bResultsOnly )
     981           0 :             pSrcDoc->SetAutoCalc( bOldAutoCalcSrc );
     982           0 :         SetAutoCalc( bOldAutoCalc );
     983             : 
     984             :         //  Drawing kopieren
     985             : 
     986           0 :         if (bInsertNew)
     987           0 :             TransferDrawPage( pSrcDoc, nSrcPos, nDestPos );
     988             : 
     989           0 :         maTabs[nDestPos]->SetPendingRowHeights( pSrcDoc->maTabs[nSrcPos]->IsPendingRowHeights() );
     990             :     }
     991           0 :     if (!bValid)
     992           0 :         nRetVal = 0;
     993           0 :     bool bVbaEnabled = IsInVBAMode();
     994             : 
     995           0 :     if ( bVbaEnabled  )
     996             :     {
     997           0 :         SfxObjectShell* pSrcShell = pSrcDoc ? pSrcDoc->GetDocumentShell() : NULL;
     998           0 :         if ( pSrcShell )
     999             :         {
    1000           0 :             rtl::OUString aLibName("Standard");
    1001           0 :             const BasicManager *pBasicManager = pSrcShell->GetBasicManager();
    1002           0 :             if (pBasicManager && !pBasicManager->GetName().isEmpty())
    1003             :             {
    1004           0 :                 aLibName = pSrcShell->GetBasicManager()->GetName();
    1005             :             }
    1006           0 :             rtl::OUString sCodeName;
    1007           0 :             rtl::OUString sSource;
    1008           0 :             uno::Reference< script::XLibraryContainer > xLibContainer = pSrcShell->GetBasicContainer();
    1009           0 :             uno::Reference< container::XNameContainer > xLib;
    1010           0 :             if( xLibContainer.is() )
    1011             :             {
    1012           0 :                 uno::Any aLibAny = xLibContainer->getByName(aLibName);
    1013           0 :                 aLibAny >>= xLib;
    1014             :             }
    1015             : 
    1016           0 :             if( xLib.is() )
    1017             :             {
    1018           0 :                 rtl::OUString sSrcCodeName;
    1019           0 :                 pSrcDoc->GetCodeName( nSrcPos, sSrcCodeName );
    1020           0 :                 rtl::OUString sRTLSource;
    1021           0 :                 xLib->getByName( sSrcCodeName ) >>= sRTLSource;
    1022           0 :                 sSource = sRTLSource;
    1023             :             }
    1024           0 :             VBA_InsertModule( *this, nDestPos, sCodeName, sSource );
    1025             :         }
    1026             :     }
    1027             : 
    1028           0 :     return nRetVal;
    1029             : }
    1030             : 
    1031             : //  ----------------------------------------------------------------------------
    1032             : 
    1033           0 : void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError)
    1034             : {
    1035           0 :     if (VALIDTAB(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
    1036           0 :         if (maTabs[nTab])
    1037           0 :             maTabs[nTab]->SetError( nCol, nRow, nError );
    1038           0 : }
    1039             : 
    1040             : //  ----------------------------------------------------------------------------
    1041             : 
    1042           0 : void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData )
    1043             : {
    1044           0 :     delete pConsolidateDlgData;
    1045             : 
    1046           0 :     if ( pData )
    1047           0 :         pConsolidateDlgData = new ScConsolidateParam( *pData );
    1048             :     else
    1049           0 :         pConsolidateDlgData = NULL;
    1050           0 : }
    1051             : 
    1052           0 : void ScDocument::SetChangeViewSettings(const ScChangeViewSettings& rNew)
    1053             : {
    1054           0 :     if (pChangeViewSettings==NULL)
    1055           0 :         pChangeViewSettings = new ScChangeViewSettings;
    1056             : 
    1057             :     OSL_ENSURE( pChangeViewSettings, "Oops. No ChangeViewSettings :-( by!" );
    1058             : 
    1059           0 :     *pChangeViewSettings=rNew;
    1060           0 : }
    1061             : 
    1062             : //  ----------------------------------------------------------------------------
    1063             : 
    1064          32 : ScFieldEditEngine* ScDocument::CreateFieldEditEngine()
    1065             : {
    1066          32 :     ScFieldEditEngine* pNewEditEngine = NULL;
    1067          32 :     if (!pCacheFieldEditEngine)
    1068             :     {
    1069             :         pNewEditEngine = new ScFieldEditEngine(
    1070          14 :             this, GetEnginePool(), GetEditPool(), false);
    1071             :     }
    1072             :     else
    1073             :     {
    1074          18 :         if ( !bImportingXML )
    1075             :         {
    1076             :             // #i66209# previous use might not have restored update mode,
    1077             :             // ensure same state as for a new EditEngine (UpdateMode = true)
    1078          17 :             if ( !pCacheFieldEditEngine->GetUpdateMode() )
    1079           0 :                 pCacheFieldEditEngine->SetUpdateMode(true);
    1080             :         }
    1081             : 
    1082          18 :         pNewEditEngine = pCacheFieldEditEngine;
    1083          18 :         pCacheFieldEditEngine = NULL;
    1084             :     }
    1085          32 :     return pNewEditEngine;
    1086             : }
    1087             : 
    1088          38 : void ScDocument::DisposeFieldEditEngine(ScFieldEditEngine*& rpEditEngine)
    1089             : {
    1090          38 :     if (!pCacheFieldEditEngine && rpEditEngine)
    1091             :     {
    1092          21 :         pCacheFieldEditEngine = rpEditEngine;
    1093          21 :         pCacheFieldEditEngine->Clear();
    1094             :     }
    1095             :     else
    1096          17 :         delete rpEditEngine;
    1097          38 :     rpEditEngine = NULL;
    1098          38 : }
    1099             : 
    1100             : //  ----------------------------------------------------------------------------
    1101             : 
    1102          41 : ScRecursionHelper* ScDocument::CreateRecursionHelperInstance()
    1103             : {
    1104          41 :     return new ScRecursionHelper;
    1105             : }
    1106             : 
    1107             : //  ----------------------------------------------------------------------------
    1108             : 
    1109          52 : ScLookupCache & ScDocument::GetLookupCache( const ScRange & rRange )
    1110             : {
    1111          52 :     ScLookupCache* pCache = 0;
    1112          52 :     if (!pLookupCacheMapImpl)
    1113           2 :         pLookupCacheMapImpl = new ScLookupCacheMapImpl;
    1114          52 :     ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find( rRange));
    1115          52 :     if (it == pLookupCacheMapImpl->aCacheMap.end())
    1116             :     {
    1117           4 :         pCache = new ScLookupCache( this, rRange);
    1118           4 :         AddLookupCache( *pCache);
    1119             :     }
    1120             :     else
    1121          48 :         pCache = (*it).second;
    1122          52 :     return *pCache;
    1123             : }
    1124             : 
    1125           4 : void ScDocument::AddLookupCache( ScLookupCache & rCache )
    1126             : {
    1127           8 :     if (!pLookupCacheMapImpl->aCacheMap.insert( ::std::pair< const ScRange,
    1128           8 :                 ScLookupCache*>( rCache.getRange(), &rCache)).second)
    1129             :     {
    1130             :         OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map");
    1131             :     }
    1132             :     else
    1133           4 :         StartListeningArea( rCache.getRange(), &rCache);
    1134           4 : }
    1135             : 
    1136           3 : void ScDocument::RemoveLookupCache( ScLookupCache & rCache )
    1137             : {
    1138             :     ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find(
    1139           3 :                 rCache.getRange()));
    1140           3 :     if (it == pLookupCacheMapImpl->aCacheMap.end())
    1141             :     {
    1142             :         OSL_FAIL( "ScDocument::RemoveLookupCache: range not found in hash map");
    1143             :     }
    1144             :     else
    1145             :     {
    1146           3 :         ScLookupCache* pCache = (*it).second;
    1147           3 :         pLookupCacheMapImpl->aCacheMap.erase( it);
    1148           3 :         EndListeningArea( pCache->getRange(), &rCache);
    1149             :     }
    1150           3 : }
    1151             : 
    1152          54 : void ScDocument::ClearLookupCaches()
    1153             : {
    1154          54 :     if( pLookupCacheMapImpl )
    1155           8 :         pLookupCacheMapImpl->clear();
    1156          69 : }
    1157             : 
    1158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10