LCOV - code coverage report
Current view: top level - sc/source/core/data - documen2.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 498 704 70.7 %
Date: 2014-04-11 Functions: 51 62 82.3 %
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 <osl/thread.h>
      26             : #include <svx/xtable.hxx>
      27             : #include <sfx2/linkmgr.hxx>
      28             : #include <svx/svdpool.hxx>
      29             : #include <svx/svdobj.hxx>
      30             : #include <sfx2/bindings.hxx>
      31             : #include <sfx2/objsh.hxx>
      32             : #include <sfx2/docfile.hxx>
      33             : #include <sfx2/printer.hxx>
      34             : #include <svl/zforlist.hxx>
      35             : #include <svl/zformat.hxx>
      36             : #include <vcl/virdev.hxx>
      37             : #include <comphelper/processfactory.hxx>
      38             : #include <svl/PasswordHelper.hxx>
      39             : #include "svl/sharedstringpool.hxx"
      40             : #include <tools/tenccvt.hxx>
      41             : #include <tools/urlobj.hxx>
      42             : #include <rtl/crc.h>
      43             : #include <basic/basmgr.hxx>
      44             : 
      45             : #include "document.hxx"
      46             : #include "table.hxx"
      47             : #include "attrib.hxx"
      48             : #include "patattr.hxx"
      49             : #include "rangenam.hxx"
      50             : #include "dbdata.hxx"
      51             : #include "pivot.hxx"
      52             : #include "docpool.hxx"
      53             : #include "stlpool.hxx"
      54             : #include "stlsheet.hxx"
      55             : #include "globstr.hrc"
      56             : #include "chartarr.hxx"
      57             : #include "chartlock.hxx"
      58             : #include "rechead.hxx"
      59             : #include "global.hxx"
      60             : #include "brdcst.hxx"
      61             : #include "bcaslot.hxx"
      62             : #include "adiasync.hxx"
      63             : #include "addinlis.hxx"
      64             : #include "chartlis.hxx"
      65             : #include "markdata.hxx"
      66             : #include "conditio.hxx"
      67             : #include "colorscale.hxx"
      68             : #include "validat.hxx"
      69             : #include "progress.hxx"
      70             : #include "detdata.hxx"
      71             : #include "sc.hrc"
      72             : #include "ddelink.hxx"
      73             : #include "chgtrack.hxx"
      74             : #include "chgviset.hxx"
      75             : #include "editutil.hxx"
      76             : #include "hints.hxx"
      77             : #include "dpobject.hxx"
      78             : #include "scrdata.hxx"
      79             : #include "poolhelp.hxx"
      80             : #include "unoreflist.hxx"
      81             : #include "listenercalls.hxx"
      82             : #include "recursionhelper.hxx"
      83             : #include "lookupcache.hxx"
      84             : #include "externalrefmgr.hxx"
      85             : #include "appoptio.hxx"
      86             : #include "scmod.hxx"
      87             : #include "../../ui/inc/viewutil.hxx"
      88             : #include "tabprotection.hxx"
      89             : #include "formulaparserpool.hxx"
      90             : #include "clipparam.hxx"
      91             : #include "macromgr.hxx"
      92             : #include "formulacell.hxx"
      93             : #include "clipcontext.hxx"
      94             : #include "refupdatecontext.hxx"
      95             : #include "refreshtimerprotector.hxx"
      96             : #include "scopetools.hxx"
      97             : #include "formulagroup.hxx"
      98             : #include "documentlinkmgr.hxx"
      99             : #include "interpre.hxx"
     100             : #include <tokenstringcontext.hxx>
     101             : 
     102             : using namespace com::sun::star;
     103             : 
     104             : // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
     105             : // dtor plus helpers are convenient.
     106           5 : struct ScLookupCacheMapImpl
     107             : {
     108             :     ScLookupCacheMap aCacheMap;
     109           2 :     ~ScLookupCacheMapImpl()
     110           2 :     {
     111           2 :         freeCaches();
     112           2 :     }
     113           5 :     void clear()
     114             :     {
     115           5 :         freeCaches();
     116             :         // Zap map.
     117           5 :         ScLookupCacheMap aTmp;
     118           5 :         aCacheMap.swap( aTmp);
     119           5 :     }
     120             : private:
     121           7 :     void freeCaches()
     122             :     {
     123           9 :         for (ScLookupCacheMap::iterator it( aCacheMap.begin()); it != aCacheMap.end(); ++it)
     124           2 :             delete (*it).second;
     125           7 :     }
     126             : };
     127             : 
     128             : // STATIC DATA -----------------------------------------------------------
     129             : 
     130        1899 : ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
     131        1899 :         mpCellStringPool(new svl::SharedStringPool(ScGlobal::pCharClass)),
     132             :         mpFormulaGroupCxt(NULL),
     133        1899 :         maCalcConfig( ScInterpreter::GetGlobalConfig()),
     134             :         mpUndoManager( NULL ),
     135             :         pEditEngine( NULL ),
     136             :         pNoteEngine( NULL ),
     137             :         pShell( pDocShell ),
     138             :         pPrinter( NULL ),
     139             :         pVirtualDevice_100th_mm( NULL ),
     140             :         pDrawLayer( NULL ),
     141             :         pValidationList( NULL ),
     142             :         pFormatExchangeList( NULL ),
     143             :         pRangeName(NULL),
     144             :         pDPCollection( NULL ),
     145             :         pFormulaTree( NULL ),
     146             :         pEOFormulaTree( NULL ),
     147             :         pFormulaTrack( NULL ),
     148             :         pEOFormulaTrack( NULL ),
     149             :         pClipData( NULL ),
     150             :         pDetOpList(NULL),
     151             :         pChangeTrack( NULL ),
     152             :         pUnoBroadcaster( NULL ),
     153             :         pUnoListenerCalls( NULL ),
     154             :         pUnoRefUndoList( NULL ),
     155             :         pChangeViewSettings( NULL ),
     156             :         pScriptTypeData( NULL ),
     157             :         pCacheFieldEditEngine( NULL ),
     158             :         pDocProtection( NULL ),
     159             :         mpClipParam( NULL),
     160             :         pExternalRefMgr( NULL ),
     161             :         mpMacroMgr( NULL ),
     162             :         pViewOptions( NULL ),
     163             :         pDocOptions( NULL ),
     164             :         pExtDocOptions( NULL ),
     165             :         pConsolidateDlgData( NULL ),
     166             :         pRecursionHelper( NULL ),
     167             :         pAutoNameCache( NULL ),
     168             :         pLookupCacheMapImpl( NULL ),
     169             :         pPreviewFont( NULL ),
     170             :         pPreviewCellStyle( NULL ),
     171             :         nUnoObjectId( 0 ),
     172             :         nRangeOverflowType( 0 ),
     173             :         aCurTextWidthCalcPos(MAXCOL,0,0),
     174             :         aTableOpList( 0 ),
     175             :         nFormulaCodeInTree(0),
     176             :         nXMLImportedFormulaCount( 0 ),
     177             :         nInterpretLevel(0),
     178             :         nMacroInterpretLevel(0),
     179             :         nInterpreterTableOpLevel(0),
     180             :         nSrcVer( SC_CURRENT_VERSION ),
     181             :         nSrcMaxRow( MAXROW ),
     182             :         nFormulaTrackCount(0),
     183             :         bHardRecalcState(false),
     184             :         nVisibleTab( 0 ),
     185             :         eLinkMode(LM_UNKNOWN),
     186        1899 :         bAutoCalc( eMode == SCDOCMODE_DOCUMENT ),
     187             :         bAutoCalcShellDisabled( false ),
     188             :         bForcedFormulaPending( false ),
     189             :         bCalculatingFormulaTree( false ),
     190        1899 :         bIsClip( eMode == SCDOCMODE_CLIP ),
     191        1899 :         bIsUndo( eMode == SCDOCMODE_UNDO ),
     192             :         bIsVisible( false ),
     193             :         bIsEmbedded( false ),
     194             :         bInsertingFromOtherDoc( false ),
     195             :         bLoadingMedium( false ),
     196             :         bImportingXML( false ),
     197             :         bXMLFromWrapper( false ),
     198             :         bCalcingAfterLoad( false ),
     199             :         bNoListening( false ),
     200             :         mbIdleEnabled(true),
     201             :         bInLinkUpdate( false ),
     202             :         bChartListenerCollectionNeedsUpdate( false ),
     203             :         bHasForcedFormulas( false ),
     204             :         bInDtorClear( false ),
     205             :         bExpandRefs( false ),
     206             :         bDetectiveDirty( false ),
     207             :         nMacroCallMode( SC_MACROCALL_ALLOWED ),
     208             :         bHasMacroFunc( false ),
     209             :         nVisSpellState( 0 ),
     210             :         nAsianCompression(SC_ASIANCOMPRESSION_INVALID),
     211             :         nAsianKerning(SC_ASIANKERNING_INVALID),
     212             :         bPastingDrawFromOtherDoc( false ),
     213             :         nInDdeLinkUpdate( 0 ),
     214             :         bInUnoBroadcast( false ),
     215             :         bInUnoListenerCall( false ),
     216             :         eGrammar( formula::FormulaGrammar::GRAM_NATIVE ),
     217             :         bStyleSheetUsageInvalid( true ),
     218             :         mbUndoEnabled( true ),
     219             :         mbAdjustHeightEnabled( true ),
     220             :         mbExecuteLinkEnabled( true ),
     221             :         mbChangeReadOnlyEnabled( false ),
     222             :         mbStreamValidLocked( false ),
     223             :         mbUserInteractionEnabled(true),
     224             :         mnNamedRangesLockCount(0),
     225       11394 :         mbUseEmbedFonts(false)
     226             : {
     227        1899 :     SetStorageGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT);
     228             : 
     229        1899 :     eSrcSet = osl_getThreadTextEncoding();
     230             : 
     231        1899 :     if ( eMode == SCDOCMODE_DOCUMENT )
     232             :     {
     233         970 :         xPoolHelper = new ScPoolHelper( this );
     234             : 
     235         970 :         pBASM = new ScBroadcastAreaSlotMachine( this );
     236         970 :         pChartListenerCollection = new ScChartListenerCollection( this );
     237         970 :         pRefreshTimerControl = new ScRefreshTimerControl;
     238             :     }
     239             :     else
     240             :     {
     241         929 :         pBASM       = NULL;
     242         929 :         pChartListenerCollection = NULL;
     243         929 :         pRefreshTimerControl = NULL;
     244             :     }
     245        1899 :     pDBCollection = new ScDBCollection(this);
     246        1899 :     pSelectionAttr = NULL;
     247        1899 :     pChartCollection = new ScChartCollection;
     248        1899 :     apTemporaryChartLock.reset( new ScTemporaryChartLock(this) );
     249        1899 :     xColNameRanges = new ScRangePairList;
     250        1899 :     xRowNameRanges = new ScRangePairList;
     251        1899 :     ImplCreateOptions();
     252             :     // languages for a visible document are set by docshell later (from options)
     253        1899 :     SetLanguage( ScGlobal::eLnge, ScGlobal::eLnge, ScGlobal::eLnge );
     254             : 
     255        1899 :     aTrackTimer.SetTimeoutHdl( LINK( this, ScDocument, TrackTimeHdl ) );
     256        1899 :     aTrackTimer.SetTimeout( 100 );
     257        1899 : }
     258             : 
     259         805 : sfx2::LinkManager* ScDocument::GetLinkManager()
     260             : {
     261         805 :     return GetDocLinkManager().getLinkManager(true);
     262             : }
     263             : 
     264          13 : const sfx2::LinkManager* ScDocument::GetLinkManager() const
     265             : {
     266          13 :     return GetDocLinkManager().getExistingLinkManager();
     267             : }
     268             : 
     269        3815 : sc::DocumentLinkManager& ScDocument::GetDocLinkManager()
     270             : {
     271        3815 :     if (!mpDocLinkMgr)
     272         561 :         mpDocLinkMgr.reset(new sc::DocumentLinkManager(*this, pShell));
     273        3815 :     return *mpDocLinkMgr;
     274             : }
     275             : 
     276         234 : const sc::DocumentLinkManager& ScDocument::GetDocLinkManager() const
     277             : {
     278         234 :     return const_cast<ScDocument*>(this)->GetDocLinkManager();
     279             : }
     280             : 
     281        2075 : void ScDocument::SetStorageGrammar( formula::FormulaGrammar::Grammar eGram )
     282             : {
     283             :     OSL_PRECOND(
     284             :         eGram == formula::FormulaGrammar::GRAM_ODFF ||
     285             :             eGram == formula::FormulaGrammar::GRAM_PODF,
     286             :             "ScDocument::SetStorageGrammar: wrong storage grammar");
     287             : 
     288        2075 :     eStorageGrammar = eGram;
     289             : 
     290             :     // FIXME: the XML import shouldn't strip brackets, the compiler should
     291             :     // digest them instead, which could also speedup reference recognition
     292             :     // during import.
     293             : 
     294             :     eXmlImportGrammar = formula::FormulaGrammar::mergeToGrammar( eGram,
     295        2075 :             formula::FormulaGrammar::CONV_OOO);
     296        2075 : }
     297             : 
     298             : 
     299         221 : void ScDocument::SetDocVisible( bool bSet )
     300             : {
     301             :     //  called from view ctor - only for a visible document,
     302             :     //  each new sheet's RTL flag is initialized from the locale
     303         221 :     bIsVisible = bSet;
     304         221 : }
     305             : 
     306             : 
     307          27 : sal_uInt32 ScDocument::GetDocumentID() const
     308             : {
     309          27 :     const ScDocument* pThis = this;
     310          27 :     sal_uInt32 nCrc = rtl_crc32( 0, &pThis, sizeof(ScDocument*) );
     311             :     // the this pointer only might not be sufficient
     312          27 :     nCrc = rtl_crc32( nCrc, &pShell, sizeof(SfxObjectShell*) );
     313          27 :     return nCrc;
     314             : }
     315             : 
     316             : 
     317           0 : void ScDocument::StartChangeTracking()
     318             : {
     319           0 :     if (!pChangeTrack)
     320           0 :         pChangeTrack = new ScChangeTrack( this );
     321           0 : }
     322             : 
     323           0 : void ScDocument::EndChangeTracking()
     324             : {
     325           0 :     delete pChangeTrack;
     326           0 :     pChangeTrack = NULL;
     327           0 : }
     328             : 
     329           0 : void ScDocument::SetChangeTrack( ScChangeTrack* pTrack )
     330             : {
     331             :     OSL_ENSURE( pTrack->GetDocument() == this, "SetChangeTrack: different documents" );
     332           0 :     if ( !pTrack || pTrack == pChangeTrack || pTrack->GetDocument() != this )
     333           0 :         return ;
     334           0 :     EndChangeTracking();
     335           0 :     pChangeTrack = pTrack;
     336             : }
     337             : 
     338             : 
     339           2 : IMPL_LINK_NOARG(ScDocument, TrackTimeHdl)
     340             : {
     341           1 :     if ( ScDdeLink::IsInUpdate() )      // nicht verschachteln
     342             :     {
     343           0 :         aTrackTimer.Start();            // spaeter nochmal versuchen
     344             :     }
     345           1 :     else if (pShell)                    // ausfuehren
     346             :     {
     347           1 :         TrackFormulas();
     348           1 :         pShell->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
     349             : 
     350             :             //  modified...
     351             : 
     352           1 :         if (!pShell->IsModified())
     353             :         {
     354           0 :             pShell->SetModified( true );
     355           0 :             SfxBindings* pBindings = GetViewBindings();
     356           0 :             if (pBindings)
     357             :             {
     358           0 :                 pBindings->Invalidate( SID_SAVEDOC );
     359           0 :                 pBindings->Invalidate( SID_DOC_MODIFIED );
     360             :             }
     361             :         }
     362             :     }
     363             : 
     364           1 :     return 0;
     365             : }
     366             : 
     367           2 : void ScDocument::StartTrackTimer()
     368             : {
     369           2 :     if (!aTrackTimer.IsActive())        // nicht ewig aufschieben
     370           1 :         aTrackTimer.Start();
     371           2 : }
     372             : 
     373        3420 : ScDocument::~ScDocument()
     374             : {
     375             :     OSL_PRECOND( !bInLinkUpdate, "bInLinkUpdate in dtor" );
     376             : 
     377        1710 :     bInDtorClear = true;
     378             : 
     379             :     // first of all disable all refresh timers by deleting the control
     380        1710 :     if ( pRefreshTimerControl )
     381             :     {   // To be sure there isn't anything running do it with a protector,
     382             :         // this ensures also that nothing needs the control anymore.
     383         799 :         ScRefreshTimerProtector aProt( GetRefreshTimerControlAddress() );
     384         799 :         delete pRefreshTimerControl, pRefreshTimerControl = NULL;
     385             :     }
     386             : 
     387        1710 :     mxFormulaParserPool.reset();
     388             :     // Destroy the external ref mgr instance here because it has a timer
     389             :     // which needs to be stopped before the app closes.
     390        1710 :     pExternalRefMgr.reset();
     391             : 
     392        1710 :     ScAddInAsync::RemoveDocument( this );
     393        1710 :     ScAddInListener::RemoveDocument( this );
     394        1710 :     DELETEZ( pChartListenerCollection);   // vor pBASM wg. evtl. Listener!
     395        1710 :     DELETEZ( pLookupCacheMapImpl);  // before pBASM because of listeners
     396             :     // BroadcastAreas vor allen Zellen zerstoeren um unnoetige
     397             :     // Einzel-EndListenings der Formelzellen zu vermeiden
     398        1710 :     delete pBASM;       // BroadcastAreaSlotMachine
     399        1710 :     pBASM = NULL;
     400             : 
     401        1710 :     delete pUnoBroadcaster;     // broadcasted nochmal SFX_HINT_DYING
     402        1710 :     pUnoBroadcaster = NULL;
     403             : 
     404        1710 :     delete pUnoRefUndoList;
     405        1710 :     delete pUnoListenerCalls;
     406             : 
     407        1710 :     Clear( true );              // true = from destructor (needed for SdrModel::ClearModel)
     408             : 
     409        1710 :     if (pValidationList)
     410             :     {
     411          33 :         for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
     412          26 :             delete *it;
     413           7 :         pValidationList->clear();
     414           7 :         DELETEZ(pValidationList);
     415             :     }
     416        1710 :     delete pRangeName;
     417        1710 :     delete pDBCollection;
     418        1710 :     delete pSelectionAttr;
     419        1710 :     apTemporaryChartLock.reset();
     420        1710 :     delete pChartCollection;
     421        1710 :     DeleteDrawLayer();
     422        1710 :     delete pFormatExchangeList;
     423        1710 :     delete pPrinter;
     424        1710 :     ImplDeleteOptions();
     425        1710 :     delete pConsolidateDlgData;
     426        1710 :     delete pClipData;
     427        1710 :     delete pDetOpList;                  // loescht auch die Eintraege
     428        1710 :     delete pChangeTrack;
     429        1710 :     delete pEditEngine;
     430        1710 :     delete pNoteEngine;
     431        1710 :     delete pChangeViewSettings;         // und weg damit
     432        1710 :     delete pVirtualDevice_100th_mm;
     433             : 
     434        1710 :     delete pDPCollection;
     435             : 
     436             :     // delete the EditEngine before destroying the xPoolHelper
     437        1710 :     delete pCacheFieldEditEngine;
     438             : 
     439        1710 :     if ( xPoolHelper.is() && !bIsClip )
     440        1657 :         xPoolHelper->SourceDocumentGone();
     441        1710 :     xPoolHelper.clear();
     442             : 
     443        1710 :     delete pScriptTypeData;
     444        1710 :     delete pRecursionHelper;
     445             : 
     446        1710 :     delete pPreviewFont;
     447             :     SAL_WARN_IF( pAutoNameCache, "sc.core", "AutoNameCache still set in dtor" );
     448             : 
     449        1710 :     mpFormulaGroupCxt.reset();
     450        1710 :     mpCellStringPool.reset();
     451        1710 : }
     452             : 
     453          56 : void ScDocument::InitClipPtrs( ScDocument* pSourceDoc )
     454             : {
     455             :     OSL_ENSURE(bIsClip, "InitClipPtrs and not bIsClip");
     456             : 
     457          56 :     if (pValidationList)
     458             :     {
     459           0 :         for(ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
     460           0 :             delete *it;
     461           0 :         pValidationList->clear();
     462           0 :         DELETEZ(pValidationList);
     463             :     }
     464             : 
     465          56 :     Clear();
     466             : 
     467          56 :     xPoolHelper = pSourceDoc->xPoolHelper;
     468             : 
     469             :     //  bedingte Formate / Gueltigkeiten
     470             :     //! Vorlagen kopieren?
     471          56 :     const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList;
     472          56 :     if ( pSourceValid )
     473           1 :         pValidationList = new ScValidationDataList(this, *pSourceValid);
     474             : 
     475             :                         // Links in Stream speichern
     476          56 :     delete pClipData;
     477          56 :     if (pSourceDoc->GetDocLinkManager().hasDdeLinks())
     478             :     {
     479           0 :         pClipData = new SvMemoryStream;
     480           0 :         pSourceDoc->SaveDdeLinks(*pClipData);
     481             :     }
     482             :     else
     483          56 :         pClipData = NULL;
     484             : 
     485             :     // Options pointers exist (ImplCreateOptions) for any document.
     486             :     // Must be copied for correct results in OLE objects (#i42666#).
     487          56 :     SetDocOptions( pSourceDoc->GetDocOptions() );
     488          56 :     SetViewOptions( pSourceDoc->GetViewOptions() );
     489          56 : }
     490             : 
     491      204022 : SvNumberFormatter* ScDocument::GetFormatTable() const
     492             : {
     493      204022 :     return xPoolHelper->GetFormTable();
     494             : }
     495             : 
     496           0 : SvNumberFormatter* ScDocument::CreateFormatTable() const
     497             : {
     498           0 :     return xPoolHelper->CreateNumberFormatter();
     499             : }
     500             : 
     501        1142 : SfxItemPool* ScDocument::GetEditPool() const
     502             : {
     503        1142 :     return xPoolHelper->GetEditPool();
     504             : }
     505             : 
     506        1299 : SfxItemPool* ScDocument::GetEnginePool() const
     507             : {
     508        1299 :     return xPoolHelper->GetEnginePool();
     509             : }
     510             : 
     511         312 : ScFieldEditEngine& ScDocument::GetEditEngine()
     512             : {
     513         312 :     if ( !pEditEngine )
     514             :     {
     515          27 :         pEditEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
     516          27 :         pEditEngine->SetUpdateMode( false );
     517          27 :         pEditEngine->EnableUndo( false );
     518          27 :         pEditEngine->SetRefMapMode( MAP_100TH_MM );
     519          27 :         ApplyAsianEditSettings( *pEditEngine );
     520             :     }
     521         312 :     return *pEditEngine;
     522             : }
     523             : 
     524           4 : ScNoteEditEngine& ScDocument::GetNoteEngine()
     525             : {
     526           4 :     if ( !pNoteEngine )
     527             :     {
     528           2 :         pNoteEngine = new ScNoteEditEngine( GetEnginePool(), GetEditPool() );
     529           2 :         pNoteEngine->SetUpdateMode( false );
     530           2 :         pNoteEngine->EnableUndo( false );
     531           2 :         pNoteEngine->SetRefMapMode( MAP_100TH_MM );
     532           2 :         ApplyAsianEditSettings( *pNoteEngine );
     533           2 :         const SfxItemSet& rItemSet = GetDefPattern()->GetItemSet();
     534           2 :         SfxItemSet* pEEItemSet = new SfxItemSet( pNoteEngine->GetEmptyItemSet() );
     535           2 :         ScPatternAttr::FillToEditItemSet( *pEEItemSet, rItemSet );
     536           2 :         pNoteEngine->SetDefaults( pEEItemSet );      // edit engine takes ownership
     537             :     }
     538           4 :     return *pNoteEngine;
     539             : }
     540             : 
     541             : 
     542          40 : void ScDocument::ResetClip( ScDocument* pSourceDoc, const ScMarkData* pMarks )
     543             : {
     544          40 :     if (bIsClip)
     545             :     {
     546          40 :         InitClipPtrs(pSourceDoc);
     547             : 
     548         117 :         for (SCTAB i = 0; i < static_cast<SCTAB>(pSourceDoc->maTabs.size()); i++)
     549          77 :             if (pSourceDoc->maTabs[i])
     550          77 :                 if (!pMarks || pMarks->GetTableSelect(i))
     551             :                 {
     552          39 :                     OUString aString;
     553          39 :                     pSourceDoc->maTabs[i]->GetName(aString);
     554          39 :                     if ( i < static_cast<SCTAB>(maTabs.size()) )
     555             :                     {
     556           0 :                         maTabs[i] = new ScTable(this, i, aString);
     557             : 
     558             :                     }
     559             :                     else
     560             :                     {
     561          39 :                         if( i > static_cast<SCTAB>(maTabs.size()) )
     562             :                         {
     563           0 :                             maTabs.resize(i, NULL );
     564             :                         }
     565          39 :                         maTabs.push_back(new ScTable(this, i, aString));
     566             :                     }
     567          39 :                     maTabs[i]->SetLayoutRTL( pSourceDoc->maTabs[i]->IsLayoutRTL() );
     568             :                 }
     569             :     }
     570             :     else
     571             :     {
     572             :         OSL_FAIL("ResetClip");
     573             :     }
     574          40 : }
     575             : 
     576          16 : void ScDocument::ResetClip( ScDocument* pSourceDoc, SCTAB nTab )
     577             : {
     578          16 :     if (bIsClip)
     579             :     {
     580          16 :         InitClipPtrs(pSourceDoc);
     581          16 :         if (nTab >= static_cast<SCTAB>(maTabs.size()))
     582             :         {
     583          16 :             maTabs.resize(nTab+1, NULL );
     584             :         }
     585          16 :         maTabs[nTab] = new ScTable(this, nTab,
     586          32 :                             OUString("baeh"));
     587          16 :         if (nTab < static_cast<SCTAB>(pSourceDoc->maTabs.size()) && pSourceDoc->maTabs[nTab])
     588          16 :             maTabs[nTab]->SetLayoutRTL( pSourceDoc->maTabs[nTab]->IsLayoutRTL() );
     589             :     }
     590             :     else
     591             :     {
     592             :         OSL_FAIL("ResetClip");
     593             :     }
     594          16 : }
     595             : 
     596        3541 : void ScDocument::EnsureTable( SCTAB nTab )
     597             : {
     598        3541 :     bool bExtras = !bIsUndo;        // Spaltenbreiten, Zeilenhoehen, Flags
     599        3541 :     if (static_cast<size_t>(nTab) >= maTabs.size())
     600           0 :         maTabs.resize(nTab+1, NULL);
     601             : 
     602        3541 :     if (!maTabs[nTab])
     603           0 :         maTabs[nTab] = new ScTable(this, nTab, "temp", bExtras, bExtras);
     604        3541 : }
     605             : 
     606       70076 : ScRefCellValue ScDocument::GetRefCellValue( const ScAddress& rPos )
     607             : {
     608       70076 :     if (!TableExists(rPos.Tab()))
     609           0 :         return ScRefCellValue(); // empty
     610             : 
     611       70076 :     return maTabs[rPos.Tab()]->GetRefCellValue(rPos.Col(), rPos.Row());
     612             : }
     613             : 
     614       29608 : svl::SharedStringPool& ScDocument::GetSharedStringPool()
     615             : {
     616       29608 :     return *mpCellStringPool;
     617             : }
     618             : 
     619           0 : const svl::SharedStringPool& ScDocument::GetSharedStringPool() const
     620             : {
     621           0 :     return *mpCellStringPool;
     622             : }
     623             : 
     624        1351 : bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
     625             :                                 bool bNotes ) const
     626             : {
     627        1351 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     628             :     {
     629        1351 :         bool bAny = maTabs[nTab]->GetPrintArea( rEndCol, rEndRow, bNotes );
     630        1351 :         if (pDrawLayer)
     631             :         {
     632        1022 :             ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
     633        1022 :             if (DrawGetPrintArea( aDrawRange, true, true ))
     634             :             {
     635         384 :                 if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
     636         384 :                 if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
     637         384 :                 bAny = true;
     638             :             }
     639             :         }
     640        1351 :         return bAny;
     641             :     }
     642             : 
     643           0 :     rEndCol = 0;
     644           0 :     rEndRow = 0;
     645           0 :     return false;
     646             : }
     647             : 
     648           0 : bool ScDocument::GetPrintAreaHor( SCTAB nTab, SCROW nStartRow, SCROW nEndRow,
     649             :                                         SCCOL& rEndCol, bool bNotes ) const
     650             : {
     651           0 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     652             :     {
     653           0 :         bool bAny = maTabs[nTab]->GetPrintAreaHor( nStartRow, nEndRow, rEndCol, bNotes );
     654           0 :         if (pDrawLayer)
     655             :         {
     656           0 :             ScRange aDrawRange(0,nStartRow,nTab, MAXCOL,nEndRow,nTab);
     657           0 :             if (DrawGetPrintArea( aDrawRange, true, false ))
     658             :             {
     659           0 :                 if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
     660           0 :                 bAny = true;
     661             :             }
     662             :         }
     663           0 :         return bAny;
     664             :     }
     665             : 
     666           0 :     rEndCol = 0;
     667           0 :     return false;
     668             : }
     669             : 
     670          40 : bool ScDocument::GetPrintAreaVer( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol,
     671             :                                         SCROW& rEndRow, bool bNotes ) const
     672             : {
     673          40 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     674             :     {
     675          40 :         bool bAny = maTabs[nTab]->GetPrintAreaVer( nStartCol, nEndCol, rEndRow, bNotes );
     676          40 :         if (pDrawLayer)
     677             :         {
     678          34 :             ScRange aDrawRange(nStartCol,0,nTab, nEndCol,MAXROW,nTab);
     679          34 :             if (DrawGetPrintArea( aDrawRange, false, true ))
     680             :             {
     681           4 :                 if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
     682           4 :                 bAny = true;
     683             :             }
     684             :         }
     685          40 :         return bAny;
     686             :     }
     687             : 
     688           0 :     rEndRow = 0;
     689           0 :     return false;
     690             : }
     691             : 
     692        1111 : bool ScDocument::GetDataStart( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow ) const
     693             : {
     694        1111 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
     695             :     {
     696        1111 :         bool bAny = maTabs[nTab]->GetDataStart( rStartCol, rStartRow );
     697        1111 :         if (pDrawLayer)
     698             :         {
     699         926 :             ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
     700         926 :             if (DrawGetPrintArea( aDrawRange, true, true ))
     701             :             {
     702         406 :                 if (aDrawRange.aStart.Col()<rStartCol) rStartCol=aDrawRange.aStart.Col();
     703         406 :                 if (aDrawRange.aStart.Row()<rStartRow) rStartRow=aDrawRange.aStart.Row();
     704         406 :                 bAny = true;
     705             :             }
     706             :         }
     707        1111 :         return bAny;
     708             :     }
     709             : 
     710           0 :     rStartCol = 0;
     711           0 :     rStartRow = 0;
     712           0 :     return false;
     713             : }
     714             : 
     715          14 : bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
     716             : {
     717          14 :     if (nOldPos == nNewPos)
     718           0 :         return false;
     719             : 
     720          14 :     SCTAB nTabCount = static_cast<SCTAB>(maTabs.size());
     721          14 :     if(nTabCount < 2)
     722           0 :         return false;
     723             : 
     724          14 :     bool bValid = false;
     725          14 :     if (ValidTab(nOldPos) && nOldPos < nTabCount )
     726             :     {
     727          14 :         if (maTabs[nOldPos])
     728             :         {
     729          14 :             sc::AutoCalcSwitch aACSwitch(*this, false);
     730             : 
     731          14 :             SetNoListening( true );
     732          14 :             if (nNewPos == SC_TAB_APPEND || nNewPos >= nTabCount)
     733           0 :                 nNewPos = nTabCount-1;
     734             : 
     735             :             //  Referenz-Updaterei
     736             :             //! mit UpdateReference zusammenfassen!
     737             : 
     738          28 :             sc::RefUpdateMoveTabContext aCxt(nOldPos, nNewPos);
     739             : 
     740          14 :             SCsTAB nDz = ((SCsTAB)nNewPos) - (SCsTAB)nOldPos;
     741          14 :             ScRange aSourceRange( 0,0,nOldPos, MAXCOL,MAXROW,nOldPos );
     742          14 :             if (pRangeName)
     743           1 :                 pRangeName->UpdateMoveTab(aCxt);
     744             : 
     745          14 :             pDBCollection->UpdateMoveTab( nOldPos, nNewPos );
     746          14 :             xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
     747          14 :             xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
     748          14 :             if (pDPCollection)
     749           2 :                 pDPCollection->UpdateReference( URM_REORDER, aSourceRange, 0,0,nDz );
     750          14 :             if (pDetOpList)
     751           0 :                 pDetOpList->UpdateReference( this, URM_REORDER, aSourceRange, 0,0,nDz );
     752             :             UpdateChartRef( URM_REORDER,
     753          14 :                     0,0,nOldPos, MAXCOL,MAXROW,nOldPos, 0,0,nDz );
     754          14 :             UpdateRefAreaLinks( URM_REORDER, aSourceRange, 0,0,nDz );
     755          14 :             if ( pValidationList )
     756           0 :                 pValidationList->UpdateMoveTab(aCxt);
     757          14 :             if ( pUnoBroadcaster )
     758             :                 pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_REORDER,
     759          14 :                             aSourceRange, 0,0,nDz ) );
     760             : 
     761          14 :             ScTable* pSaveTab = maTabs[nOldPos];
     762          14 :             maTabs.erase(maTabs.begin()+nOldPos);
     763          14 :             maTabs.insert(maTabs.begin()+nNewPos, pSaveTab);
     764          14 :             TableContainer::iterator it = maTabs.begin();
     765          53 :             for (SCTAB i = 0; i < nTabCount; i++)
     766          39 :                 if (maTabs[i])
     767          39 :                     maTabs[i]->UpdateMoveTab(aCxt, i, pProgress);
     768          14 :             it = maTabs.begin();
     769          53 :             for (; it != maTabs.end(); ++it)
     770          39 :                 if (*it)
     771          39 :                     (*it)->UpdateCompile();
     772          14 :             SetNoListening( false );
     773          14 :             it = maTabs.begin();
     774          53 :             for (; it != maTabs.end(); ++it)
     775          39 :                 if (*it)
     776          39 :                     (*it)->StartAllListeners();
     777             :             // sheet names of references may not be valid until sheet is moved
     778          14 :             pChartListenerCollection->UpdateScheduledSeriesRanges();
     779             : 
     780          14 :             sc::SetFormulaDirtyContext aFormulaDirtyCxt;
     781          14 :             SetAllFormulasDirty(aFormulaDirtyCxt);
     782             : 
     783          14 :             if (pDrawLayer)
     784           1 :                 DrawMovePage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
     785             : 
     786          28 :             bValid = true;
     787             :         }
     788             :     }
     789          14 :     return bValid;
     790             : }
     791             : 
     792           5 : bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyMarked )
     793             : {
     794           5 :     if (SC_TAB_APPEND == nNewPos  || nNewPos >= static_cast<SCTAB>(maTabs.size()))
     795           4 :         nNewPos = static_cast<SCTAB>(maTabs.size());
     796           5 :     OUString aName;
     797           5 :     GetName(nOldPos, aName);
     798             : 
     799             :     //  vorneweg testen, ob der Prefix als gueltig erkannt wird
     800             :     //  wenn nicht, nur doppelte vermeiden
     801           5 :     bool bPrefix = ValidTabName( aName );
     802             :     OSL_ENSURE(bPrefix, "invalid table name");
     803             :     SCTAB nDummy;
     804             : 
     805           5 :     CreateValidTabName(aName);
     806             : 
     807             :     bool bValid;
     808           5 :     if (bPrefix)
     809           5 :         bValid = ValidNewTabName(aName);
     810             :     else
     811           0 :         bValid = !GetTable( aName, nDummy );
     812             : 
     813          10 :     sc::AutoCalcSwitch aACSwitch(*this, false);
     814          10 :     sc::RefUpdateInsertTabContext aCxt(nNewPos, 1);
     815             : 
     816           5 :     if (bValid)
     817             :     {
     818           5 :         if (nNewPos >= static_cast<SCTAB>(maTabs.size()))
     819             :         {
     820           4 :             nNewPos = static_cast<SCTAB>(maTabs.size());
     821           4 :             maTabs.push_back(new ScTable(this, nNewPos, aName));
     822             :         }
     823             :         else
     824             :         {
     825           1 :             if (ValidTab(nNewPos) && (nNewPos < static_cast<SCTAB>(maTabs.size())))
     826             :             {
     827           1 :                 SetNoListening( true );
     828             : 
     829           1 :                 ScRange aRange( 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB );
     830           1 :                 xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
     831           1 :                 xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
     832           1 :                 if (pRangeName)
     833           0 :                     pRangeName->UpdateInsertTab(aCxt);
     834             : 
     835             :                 pDBCollection->UpdateReference(
     836           1 :                                     URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
     837           1 :                 if (pDPCollection)
     838           0 :                     pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,1 );
     839           1 :                 if (pDetOpList)
     840           0 :                     pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,1 );
     841           1 :                 UpdateChartRef( URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
     842           1 :                 UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,1 );
     843           1 :                 if ( pUnoBroadcaster )
     844           1 :                     pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,1 ) );
     845             : 
     846             :                 SCTAB i;
     847           3 :                 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
     848           2 :                     if (*it && it != (maTabs.begin() + nOldPos))
     849           1 :                         (*it)->UpdateInsertTab(aCxt);
     850           1 :                 maTabs.push_back(NULL);
     851           3 :                 for (i = static_cast<SCTAB>(maTabs.size())-1; i > nNewPos; i--)
     852           2 :                     maTabs[i] = maTabs[i - 1];
     853           1 :                 if (nNewPos <= nOldPos)
     854           1 :                     nOldPos++;
     855           1 :                 maTabs[nNewPos] = new ScTable(this, nNewPos, aName);
     856           1 :                 bValid = true;
     857           4 :                 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
     858           3 :                     if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin() + nNewPos)
     859           1 :                         (*it)->UpdateCompile();
     860           1 :                 SetNoListening( false );
     861           4 :                 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
     862           3 :                     if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin()+nNewPos)
     863           1 :                         (*it)->StartAllListeners();
     864             : 
     865           1 :                 if (pValidationList)
     866           0 :                     pValidationList->UpdateInsertTab(aCxt);
     867             : 
     868             :                 // sheet names of references may not be valid until sheet is copied
     869           1 :                 pChartListenerCollection->UpdateScheduledSeriesRanges();
     870             :             }
     871             :             else
     872           0 :                 bValid = false;
     873             :         }
     874             :     }
     875             : 
     876           5 :     if (bValid)
     877             :     {
     878           5 :         SetNoListening( true );     // noch nicht bei CopyToTable/Insert
     879           5 :         sc::CopyToDocContext aCopyDocCxt(*this);
     880           5 :         maTabs[nOldPos]->CopyToTable(aCopyDocCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
     881          10 :                                         maTabs[nNewPos], pOnlyMarked );
     882           5 :         maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
     883             : 
     884           5 :         SCTAB nDz = nNewPos - nOldPos;
     885          10 :         sc::RefUpdateContext aRefCxt(*this);
     886           5 :         aRefCxt.meMode = URM_COPY;
     887           5 :         aRefCxt.maRange = ScRange(0, 0, nNewPos, MAXCOL, MAXROW, nNewPos);
     888           5 :         aRefCxt.mnTabDelta = nDz;
     889           5 :         maTabs[nNewPos]->UpdateReference(aRefCxt, NULL);
     890             : 
     891          10 :         sc::RefUpdateInsertTabContext aInsTabCxt(nNewPos, 1);
     892           5 :         maTabs[nNewPos]->UpdateInsertTabAbs(nNewPos); // alle abs. um eins hoch!!
     893           5 :         maTabs[nOldPos]->UpdateInsertTab(aInsTabCxt);
     894             : 
     895           5 :         maTabs[nOldPos]->UpdateCompile();
     896           5 :         maTabs[nNewPos]->UpdateCompile( true ); //  maybe already compiled in Clone, but used names need recompilation
     897           5 :         SetNoListening( false );
     898           5 :         maTabs[nOldPos]->StartAllListeners();
     899           5 :         maTabs[nNewPos]->StartAllListeners();
     900             : 
     901           5 :         ScConditionalFormatList* pNewList = new ScConditionalFormatList(*maTabs[nOldPos]->GetCondFormList());
     902           5 :         pNewList->UpdateReference(aRefCxt);
     903           5 :         maTabs[nNewPos]->SetCondFormList( pNewList );
     904             : 
     905           5 :         sc::SetFormulaDirtyContext aFormulaDirtyCxt;
     906           5 :         SetAllFormulasDirty(aFormulaDirtyCxt);
     907             : 
     908           5 :         if (pDrawLayer)
     909           2 :             DrawCopyPage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
     910             : 
     911           5 :         if (pDPCollection)
     912           0 :             pDPCollection->CopyToTab(nOldPos, nNewPos);
     913             : 
     914           5 :         maTabs[nNewPos]->SetPageStyle( maTabs[nOldPos]->GetPageStyle() );
     915           5 :         maTabs[nNewPos]->SetPendingRowHeights( maTabs[nOldPos]->IsPendingRowHeights() );
     916             : 
     917             :         // Copy the custom print range if exists.
     918           5 :         maTabs[nNewPos]->CopyPrintRange(*maTabs[nOldPos]);
     919             : 
     920             :         // Copy the RTL settings
     921           5 :         maTabs[nNewPos]->SetLayoutRTL(maTabs[nOldPos]->IsLayoutRTL());
     922          10 :         maTabs[nNewPos]->SetLoadingRTL(maTabs[nOldPos]->IsLoadingRTL());
     923             :     }
     924             : 
     925          10 :     return bValid;
     926             : }
     927             : 
     928             : void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const OUString& sModuleName, const OUString& sModuleSource );
     929             : 
     930           3 : sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
     931             :                                 SCTAB nDestPos, bool bInsertNew,
     932             :                                 bool bResultsOnly )
     933             : {
     934           3 :     sal_uLong nRetVal = 1;                      // 0 => Fehler 1 = ok
     935             :                                             // 3 => NameBox
     936             :                                             // 4 => beides
     937             : 
     938           3 :     if (pSrcDoc->pShell->GetMedium())
     939             :     {
     940           3 :         pSrcDoc->maFileURL = pSrcDoc->pShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI);
     941             :         // for unsaved files use the title name and adjust during save of file
     942           3 :         if (pSrcDoc->maFileURL.isEmpty())
     943           0 :             pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
     944             :     }
     945             :     else
     946             :     {
     947           0 :         pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
     948             :     }
     949             : 
     950           3 :     bool bValid = true;
     951           3 :     if (bInsertNew)             // neu einfuegen
     952             :     {
     953           1 :         OUString aName;
     954           1 :         pSrcDoc->GetName(nSrcPos, aName);
     955           1 :         CreateValidTabName(aName);
     956           1 :         bValid = InsertTab(nDestPos, aName);
     957             : 
     958             :         // Copy the RTL settings
     959           1 :         maTabs[nDestPos]->SetLayoutRTL(pSrcDoc->maTabs[nSrcPos]->IsLayoutRTL());
     960           1 :         maTabs[nDestPos]->SetLoadingRTL(pSrcDoc->maTabs[nSrcPos]->IsLoadingRTL());
     961             :     }
     962             :     else                        // bestehende Tabelle ersetzen
     963             :     {
     964           2 :         if (ValidTab(nDestPos) && nDestPos < static_cast<SCTAB>(maTabs.size()) && maTabs[nDestPos])
     965             :         {
     966           2 :             maTabs[nDestPos]->DeleteArea( 0,0, MAXCOL,MAXROW, IDF_ALL );
     967             :         }
     968             :         else
     969           0 :             bValid = false;
     970             :     }
     971             : 
     972           3 :     if (bValid)
     973             :     {
     974           3 :         bool bOldAutoCalcSrc = false;
     975           3 :         bool bOldAutoCalc = GetAutoCalc();
     976           3 :         SetAutoCalc( false );   // Mehrfachberechnungen vermeiden
     977           3 :         SetNoListening( true );
     978           3 :         if ( bResultsOnly )
     979             :         {
     980           2 :             bOldAutoCalcSrc = pSrcDoc->GetAutoCalc();
     981           2 :             pSrcDoc->SetAutoCalc( true );   // falls was berechnet werden muss
     982             :         }
     983             : 
     984             :         {
     985           3 :             NumFmtMergeHandler aNumFmtMergeHdl(this, pSrcDoc);
     986             : 
     987           6 :             sc::CopyToDocContext aCxt(*this);
     988           3 :             nDestPos = std::min(nDestPos, (SCTAB)(GetTableCount() - 1));
     989             :             {   // scope for bulk broadcast
     990           3 :                 ScBulkBroadcast aBulkBroadcast( pBASM);
     991           3 :                 pSrcDoc->maTabs[nSrcPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW,
     992             :                         ( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL),
     993           6 :                         false, maTabs[nDestPos] );
     994           3 :                 maTabs[nDestPos]->CopyConditionalFormat(0, 0, MAXCOL, MAXROW,
     995           6 :                             0, 0, pSrcDoc->maTabs[nSrcPos]);
     996           3 :             }
     997             :         }
     998           3 :         maTabs[nDestPos]->SetTabNo(nDestPos);
     999           3 :         maTabs[nDestPos]->SetTabBgColor(pSrcDoc->maTabs[nSrcPos]->GetTabBgColor());
    1000             : 
    1001           3 :         if ( !bResultsOnly )
    1002             :         {
    1003           1 :             sc::RefUpdateContext aRefCxt(*this);
    1004           1 :             aRefCxt.meMode = URM_COPY;
    1005           1 :             aRefCxt.maRange = ScRange(0, 0, nDestPos, MAXCOL, MAXROW, nDestPos);
    1006           1 :             aRefCxt.mnTabDelta = nDestPos - nSrcPos;
    1007           1 :             maTabs[nDestPos]->UpdateReference(aRefCxt, NULL);
    1008             : 
    1009             :             // Readjust self-contained absolute references to this sheet
    1010           1 :             maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
    1011           2 :             sc::CompileFormulaContext aFormulaCxt(this);
    1012           2 :             maTabs[nDestPos]->CompileAll(aFormulaCxt);
    1013             :         }
    1014             : 
    1015           3 :         SetNoListening( false );
    1016           3 :         if ( !bResultsOnly )
    1017           1 :             maTabs[nDestPos]->StartAllListeners();
    1018           3 :         SetDirty( ScRange( 0, 0, nDestPos, MAXCOL, MAXROW, nDestPos));
    1019             : 
    1020           3 :         if ( bResultsOnly )
    1021           2 :             pSrcDoc->SetAutoCalc( bOldAutoCalcSrc );
    1022           3 :         SetAutoCalc( bOldAutoCalc );
    1023             : 
    1024             :         //  Drawing kopieren
    1025             : 
    1026           3 :         if (bInsertNew)
    1027           1 :             TransferDrawPage( pSrcDoc, nSrcPos, nDestPos );
    1028             : 
    1029           3 :         maTabs[nDestPos]->SetPendingRowHeights( pSrcDoc->maTabs[nSrcPos]->IsPendingRowHeights() );
    1030             :     }
    1031           3 :     if (!bValid)
    1032           0 :         nRetVal = 0;
    1033           3 :     bool bVbaEnabled = IsInVBAMode();
    1034             : 
    1035           3 :     if ( bVbaEnabled  )
    1036             :     {
    1037           0 :         SfxObjectShell* pSrcShell = pSrcDoc->GetDocumentShell();
    1038           0 :         if ( pSrcShell )
    1039             :         {
    1040           0 :             OUString aLibName("Standard");
    1041           0 :             const BasicManager *pBasicManager = pSrcShell->GetBasicManager();
    1042           0 :             if (pBasicManager && !pBasicManager->GetName().isEmpty())
    1043             :             {
    1044           0 :                 aLibName = pSrcShell->GetBasicManager()->GetName();
    1045             :             }
    1046           0 :             OUString sCodeName;
    1047           0 :             OUString sSource;
    1048           0 :             uno::Reference< script::XLibraryContainer > xLibContainer = pSrcShell->GetBasicContainer();
    1049           0 :             uno::Reference< container::XNameContainer > xLib;
    1050           0 :             if( xLibContainer.is() )
    1051             :             {
    1052           0 :                 uno::Any aLibAny = xLibContainer->getByName(aLibName);
    1053           0 :                 aLibAny >>= xLib;
    1054             :             }
    1055             : 
    1056           0 :             if( xLib.is() )
    1057             :             {
    1058           0 :                 OUString sSrcCodeName;
    1059           0 :                 pSrcDoc->GetCodeName( nSrcPos, sSrcCodeName );
    1060           0 :                 OUString sRTLSource;
    1061           0 :                 xLib->getByName( sSrcCodeName ) >>= sRTLSource;
    1062           0 :                 sSource = sRTLSource;
    1063             :             }
    1064           0 :             VBA_InsertModule( *this, nDestPos, sCodeName, sSource );
    1065             :         }
    1066             :     }
    1067             : 
    1068           3 :     return nRetVal;
    1069             : }
    1070             : 
    1071           1 : void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError)
    1072             : {
    1073           1 :     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
    1074           1 :         if (maTabs[nTab])
    1075           1 :             maTabs[nTab]->SetError( nCol, nRow, nError );
    1076           1 : }
    1077             : 
    1078           0 : void ScDocument::SetFormula(
    1079             :     const ScAddress& rPos, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
    1080             : {
    1081           0 :     if (!TableExists(rPos.Tab()))
    1082           0 :         return;
    1083             : 
    1084           0 :     maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rArray, eGram);
    1085             : }
    1086             : 
    1087           0 : void ScDocument::SetFormula(
    1088             :     const ScAddress& rPos, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
    1089             : {
    1090           0 :     if (!TableExists(rPos.Tab()))
    1091           0 :         return;
    1092             : 
    1093           0 :     maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rFormula, eGram);
    1094             : }
    1095             : 
    1096         122 : ScFormulaCell* ScDocument::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell )
    1097             : {
    1098         122 :     if (!TableExists(rPos.Tab()))
    1099             :     {
    1100           0 :         delete pCell;
    1101           0 :         return NULL;
    1102             :     }
    1103             : 
    1104         122 :     return maTabs[rPos.Tab()]->SetFormulaCell(rPos.Col(), rPos.Row(), pCell);
    1105             : }
    1106             : 
    1107           3 : bool ScDocument::SetFormulaCells( const ScAddress& rPos, std::vector<ScFormulaCell*>& rCells )
    1108             : {
    1109           3 :     if (rCells.empty())
    1110           0 :         return false;
    1111             : 
    1112           3 :     ScTable* pTab = FetchTable(rPos.Tab());
    1113           3 :     if (!pTab)
    1114           0 :         return false;
    1115             : 
    1116           3 :     return pTab->SetFormulaCells(rPos.Col(), rPos.Row(), rCells);
    1117             : }
    1118             : 
    1119           1 : void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData )
    1120             : {
    1121           1 :     delete pConsolidateDlgData;
    1122             : 
    1123           1 :     if ( pData )
    1124           1 :         pConsolidateDlgData = new ScConsolidateParam( *pData );
    1125             :     else
    1126           0 :         pConsolidateDlgData = NULL;
    1127           1 : }
    1128             : 
    1129           0 : void ScDocument::SetChangeViewSettings(const ScChangeViewSettings& rNew)
    1130             : {
    1131           0 :     if (pChangeViewSettings==NULL)
    1132           0 :         pChangeViewSettings = new ScChangeViewSettings;
    1133             : 
    1134             :     OSL_ENSURE( pChangeViewSettings, "Oops. No ChangeViewSettings :-( by!" );
    1135             : 
    1136           0 :     *pChangeViewSettings=rNew;
    1137           0 : }
    1138             : 
    1139         651 : ScFieldEditEngine* ScDocument::CreateFieldEditEngine()
    1140             : {
    1141         651 :     ScFieldEditEngine* pNewEditEngine = NULL;
    1142         651 :     if (!pCacheFieldEditEngine)
    1143             :     {
    1144             :         pNewEditEngine = new ScFieldEditEngine(
    1145          57 :             this, GetEnginePool(), GetEditPool(), false);
    1146             :     }
    1147             :     else
    1148             :     {
    1149         594 :         if ( !bImportingXML )
    1150             :         {
    1151             :             // #i66209# previous use might not have restored update mode,
    1152             :             // ensure same state as for a new EditEngine (UpdateMode = true)
    1153         594 :             if ( !pCacheFieldEditEngine->GetUpdateMode() )
    1154           0 :                 pCacheFieldEditEngine->SetUpdateMode(true);
    1155             :         }
    1156             : 
    1157         594 :         pNewEditEngine = pCacheFieldEditEngine;
    1158         594 :         pCacheFieldEditEngine = NULL;
    1159             :     }
    1160         651 :     return pNewEditEngine;
    1161             : }
    1162             : 
    1163         618 : void ScDocument::DisposeFieldEditEngine(ScFieldEditEngine*& rpEditEngine)
    1164             : {
    1165         618 :     if (!pCacheFieldEditEngine && rpEditEngine)
    1166             :     {
    1167         605 :         pCacheFieldEditEngine = rpEditEngine;
    1168         605 :         pCacheFieldEditEngine->Clear();
    1169             :     }
    1170             :     else
    1171          13 :         delete rpEditEngine;
    1172         618 :     rpEditEngine = NULL;
    1173         618 : }
    1174             : 
    1175         142 : ScRecursionHelper* ScDocument::CreateRecursionHelperInstance()
    1176             : {
    1177         142 :     return new ScRecursionHelper;
    1178             : }
    1179             : 
    1180          62 : ScLookupCache & ScDocument::GetLookupCache( const ScRange & rRange )
    1181             : {
    1182          62 :     ScLookupCache* pCache = 0;
    1183          62 :     if (!pLookupCacheMapImpl)
    1184           5 :         pLookupCacheMapImpl = new ScLookupCacheMapImpl;
    1185          62 :     ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find( rRange));
    1186          62 :     if (it == pLookupCacheMapImpl->aCacheMap.end())
    1187             :     {
    1188           9 :         pCache = new ScLookupCache( this, rRange);
    1189           9 :         AddLookupCache( *pCache);
    1190             :     }
    1191             :     else
    1192          53 :         pCache = (*it).second;
    1193          62 :     return *pCache;
    1194             : }
    1195             : 
    1196           9 : void ScDocument::AddLookupCache( ScLookupCache & rCache )
    1197             : {
    1198          18 :     if (!pLookupCacheMapImpl->aCacheMap.insert( ::std::pair< const ScRange,
    1199          18 :                 ScLookupCache*>( rCache.getRange(), &rCache)).second)
    1200             :     {
    1201             :         OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map");
    1202             :     }
    1203             :     else
    1204           9 :         StartListeningArea( rCache.getRange(), &rCache);
    1205           9 : }
    1206             : 
    1207           4 : void ScDocument::RemoveLookupCache( ScLookupCache & rCache )
    1208             : {
    1209             :     ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find(
    1210           4 :                 rCache.getRange()));
    1211           4 :     if (it == pLookupCacheMapImpl->aCacheMap.end())
    1212             :     {
    1213             :         OSL_FAIL( "ScDocument::RemoveLookupCache: range not found in hash map");
    1214             :     }
    1215             :     else
    1216             :     {
    1217           4 :         ScLookupCache* pCache = (*it).second;
    1218           4 :         pLookupCacheMapImpl->aCacheMap.erase( it);
    1219           4 :         EndListeningArea( pCache->getRange(), &rCache);
    1220             :     }
    1221           4 : }
    1222             : 
    1223         189 : void ScDocument::ClearLookupCaches()
    1224             : {
    1225         189 :     if( pLookupCacheMapImpl )
    1226           5 :         pLookupCacheMapImpl->clear();
    1227         189 : }
    1228             : 
    1229           0 : sal_Bool ScDocument::IsCellInChangeTrack(const ScAddress &cell,Color *pColCellBoder)
    1230             : {
    1231           0 :     ScChangeTrack* pTrack = GetChangeTrack();
    1232           0 :     ScChangeViewSettings* pSettings = GetChangeViewSettings();
    1233           0 :     if ( !pTrack || !pTrack->GetFirst() || !pSettings || !pSettings->ShowChanges() )
    1234           0 :         return sal_False;           // nix da oder abgeschaltet
    1235           0 :     ScActionColorChanger aColorChanger(*pTrack);
    1236             :     //  Clipping passiert von aussen
    1237             :     //! ohne Clipping, nur betroffene Zeilen painten ??!??!?
    1238           0 :     const ScChangeAction* pAction = pTrack->GetFirst();
    1239           0 :     while (pAction)
    1240             :     {
    1241             :         ScChangeActionType eType;
    1242           0 :         if ( pAction->IsVisible() )
    1243             :         {
    1244           0 :             eType = pAction->GetType();
    1245           0 :             const ScBigRange& rBig = pAction->GetBigRange();
    1246           0 :             if ( rBig.aStart.Tab() == cell.Tab())
    1247             :             {
    1248           0 :                 ScRange aRange = rBig.MakeRange();
    1249           0 :                 if ( eType == SC_CAT_DELETE_ROWS )
    1250           0 :                     aRange.aEnd.SetRow( aRange.aStart.Row() );
    1251           0 :                 else if ( eType == SC_CAT_DELETE_COLS )
    1252           0 :                     aRange.aEnd.SetCol( aRange.aStart.Col() );
    1253           0 :                 if (ScViewUtil::IsActionShown( *pAction, *pSettings, *this ) )
    1254             :                 {
    1255           0 :                     if (aRange.In(cell))
    1256             :                     {
    1257           0 :                         if (pColCellBoder != NULL)
    1258             :                         {
    1259           0 :                             aColorChanger.Update( *pAction );
    1260           0 :                             Color aColor( aColorChanger.GetColor() );
    1261           0 :                             *pColCellBoder = aColor;
    1262             :                         }
    1263           0 :                         return sal_True;
    1264             :                     }
    1265             :                 }
    1266             :             }
    1267           0 :             if ( eType == SC_CAT_MOVE &&
    1268             :                 ((const ScChangeActionMove*)pAction)->
    1269           0 :                 GetFromRange().aStart.Tab() == cell.Col() )
    1270             :             {
    1271             :                 ScRange aRange = ((const ScChangeActionMove*)pAction)->
    1272           0 :                     GetFromRange().MakeRange();
    1273           0 :                 if (ScViewUtil::IsActionShown( *pAction, *pSettings, *this ) )
    1274             :                 {
    1275           0 :                     if (aRange.In(cell))
    1276             :                     {
    1277           0 :                         if (pColCellBoder != NULL)
    1278             :                         {
    1279           0 :                             aColorChanger.Update( *pAction );
    1280           0 :                             Color aColor( aColorChanger.GetColor() );
    1281           0 :                             *pColCellBoder = aColor;
    1282             :                         }
    1283           0 :                         return sal_True;
    1284             :                     }
    1285             :                 }
    1286             :             }
    1287             :         }
    1288           0 :         pAction = pAction->GetNext();
    1289             :     }
    1290           0 :     return sal_False;
    1291             : }
    1292             : 
    1293           0 : void ScDocument::GetCellChangeTrackNote( const ScAddress &aCellPos, OUString &aTrackText,sal_Bool &bLeftEdge)
    1294             : {
    1295           0 :     aTrackText = OUString();
    1296             :     //  Change-Tracking
    1297           0 :     ScChangeTrack* pTrack = GetChangeTrack();
    1298           0 :     ScChangeViewSettings* pSettings = GetChangeViewSettings();
    1299           0 :     if ( pTrack && pTrack->GetFirst() && pSettings && pSettings->ShowChanges())
    1300             :     {
    1301           0 :         const ScChangeAction* pFound = NULL;
    1302           0 :         const ScChangeAction* pFoundContent = NULL;
    1303           0 :         const ScChangeAction* pFoundMove = NULL;
    1304           0 :         long nModified = 0;
    1305           0 :         const ScChangeAction* pAction = pTrack->GetFirst();
    1306           0 :         while (pAction)
    1307             :         {
    1308           0 :             if ( pAction->IsVisible() &&
    1309           0 :                  ScViewUtil::IsActionShown( *pAction, *pSettings, *this ) )
    1310             :             {
    1311           0 :                 ScChangeActionType eType = pAction->GetType();
    1312           0 :                 const ScBigRange& rBig = pAction->GetBigRange();
    1313           0 :                 if ( rBig.aStart.Tab() == aCellPos.Tab())
    1314             :                 {
    1315           0 :                     ScRange aRange = rBig.MakeRange();
    1316           0 :                     if ( eType == SC_CAT_DELETE_ROWS )
    1317           0 :                         aRange.aEnd.SetRow( aRange.aStart.Row() );
    1318           0 :                     else if ( eType == SC_CAT_DELETE_COLS )
    1319           0 :                         aRange.aEnd.SetCol( aRange.aStart.Col() );
    1320           0 :                     if ( aRange.In( aCellPos ) )
    1321             :                     {
    1322           0 :                         pFound = pAction;       // der letzte gewinnt
    1323           0 :                         switch ( eType )
    1324             :                         {
    1325             :                             case SC_CAT_CONTENT :
    1326           0 :                                 pFoundContent = pAction;
    1327           0 :                             break;
    1328             :                             case SC_CAT_MOVE :
    1329           0 :                                 pFoundMove = pAction;
    1330           0 :                             break;
    1331             :                             default:
    1332           0 :                                 break;
    1333             :                         }
    1334           0 :                         ++nModified;
    1335             :                     }
    1336             :                 }
    1337           0 :                 if ( eType == SC_CAT_MOVE )
    1338             :                 {
    1339             :                     ScRange aRange =
    1340             :                         ((const ScChangeActionMove*)pAction)->
    1341           0 :                         GetFromRange().MakeRange();
    1342           0 :                     if ( aRange.In( aCellPos ) )
    1343             :                     {
    1344           0 :                         pFound = pAction;
    1345           0 :                         ++nModified;
    1346             :                     }
    1347             :                 }
    1348             :             }
    1349           0 :             pAction = pAction->GetNext();
    1350             :         }
    1351           0 :         if ( pFound )
    1352             :         {
    1353           0 :             if ( pFoundContent && pFound->GetType() != SC_CAT_CONTENT )
    1354           0 :                 pFound = pFoundContent;     // Content gewinnt
    1355           0 :             if ( pFoundMove && pFound->GetType() != SC_CAT_MOVE &&
    1356           0 :                     pFoundMove->GetActionNumber() >
    1357           0 :                     pFound->GetActionNumber() )
    1358           0 :                 pFound = pFoundMove;        // Move gewinnt
    1359             :             //  bei geloeschten Spalten: Pfeil auf die linke Seite der Zelle
    1360           0 :             if ( pFound->GetType() == SC_CAT_DELETE_COLS )
    1361           0 :                 bLeftEdge = sal_True;
    1362           0 :             DateTime aDT = pFound->GetDateTime();
    1363           0 :             aTrackText  = pFound->GetUser();
    1364           0 :             aTrackText += ", ";
    1365           0 :             aTrackText += ScGlobal::pLocaleData->getDate(aDT);
    1366           0 :             aTrackText += " ";
    1367           0 :             aTrackText += ScGlobal::pLocaleData->getTime(aDT);
    1368           0 :             aTrackText += ":\n";
    1369           0 :             OUString aComStr = pFound->GetComment();
    1370           0 :             if(!aComStr.isEmpty())
    1371             :             {
    1372           0 :                 aTrackText += aComStr;
    1373           0 :                 aTrackText += "\n( ";
    1374             :             }
    1375           0 :             pFound->GetDescription( aTrackText, this );
    1376           0 :             if (!aComStr.isEmpty())
    1377             :             {
    1378           0 :                 aTrackText += ")";
    1379           0 :             }
    1380             :         }
    1381             :     }
    1382           0 : }
    1383             : 
    1384         154 : void ScDocument::SetPreviewFont( SfxItemSet* pFont )
    1385             : {
    1386         154 :     delete pPreviewFont;
    1387         154 :     pPreviewFont = pFont;
    1388         154 : }
    1389             : 
    1390     4170946 : const ScMarkData ScDocument::GetPreviewSelection()
    1391             : {
    1392     4170946 :     return maPreviewSelection;
    1393             : }
    1394             : 
    1395         154 : void  ScDocument::SetPreviewSelection( ScMarkData& rSel )
    1396             : {
    1397         154 :     maPreviewSelection = rSel;
    1398         154 : }
    1399             : 
    1400       12025 : SfxItemSet* ScDocument::GetPreviewFont( SCCOL nCol, SCROW nRow, SCTAB nTab )
    1401             : {
    1402       12025 :     SfxItemSet* pRet = NULL;
    1403       12025 :     if ( pPreviewFont )
    1404             :     {
    1405       11984 :         ScMarkData aSel = GetPreviewSelection();
    1406       11984 :         if ( aSel.IsCellMarked( nCol, nRow ) && aSel.GetFirstSelected() == nTab )
    1407         368 :             pRet = pPreviewFont;
    1408             :     }
    1409       12025 :     return pRet;
    1410             : }
    1411             : 
    1412     4157297 : ScStyleSheet* ScDocument::GetPreviewCellStyle( SCCOL nCol, SCROW nRow, SCTAB nTab )
    1413             : {
    1414     4157297 :     ScStyleSheet* pRet = NULL;
    1415     4157297 :     ScMarkData aSel = GetPreviewSelection();
    1416     4157297 :     if ( pPreviewCellStyle && aSel.IsCellMarked( nCol, nRow ) && aSel.GetFirstSelected() == nTab  )
    1417           0 :         pRet = pPreviewCellStyle;
    1418     4157297 :     return pRet;
    1419         102 : }
    1420             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10