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 4 : struct ScLookupCacheMapImpl
93 : {
94 : ScLookupCacheMap aCacheMap;
95 2 : ~ScLookupCacheMapImpl()
96 2 : {
97 2 : freeCaches();
98 2 : }
99 16 : void clear()
100 : {
101 16 : freeCaches();
102 : // Zap map.
103 16 : ScLookupCacheMap aTmp;
104 16 : aCacheMap.swap( aTmp);
105 16 : }
106 : private:
107 18 : void freeCaches()
108 : {
109 20 : for (ScLookupCacheMap::iterator it( aCacheMap.begin()); it != aCacheMap.end(); ++it)
110 2 : delete (*it).second;
111 18 : }
112 : };
113 :
114 : // STATIC DATA -----------------------------------------------------------
115 :
116 688 : 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 688 : mbIsInTest( false )
211 : {
212 688 : SetStorageGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT);
213 :
214 688 : eSrcSet = osl_getThreadTextEncoding();
215 :
216 688 : if ( eMode == SCDOCMODE_DOCUMENT )
217 : {
218 586 : if ( pDocShell )
219 586 : pLinkManager = new sfx2::LinkManager( pDocShell );
220 :
221 586 : xPoolHelper = new ScPoolHelper( this );
222 :
223 586 : pBASM = new ScBroadcastAreaSlotMachine( this );
224 586 : pChartListenerCollection = new ScChartListenerCollection( this );
225 586 : pRefreshTimerControl = new ScRefreshTimerControl;
226 : }
227 : else
228 : {
229 102 : pBASM = NULL;
230 102 : pChartListenerCollection = NULL;
231 102 : pRefreshTimerControl = NULL;
232 : }
233 688 : pDBCollection = new ScDBCollection(this);
234 688 : pSelectionAttr = NULL;
235 688 : pChartCollection = new ScChartCollection;
236 688 : apTemporaryChartLock = std::auto_ptr< ScTemporaryChartLock >( new ScTemporaryChartLock(this) );
237 688 : xColNameRanges = new ScRangePairList;
238 688 : xRowNameRanges = new ScRangePairList;
239 688 : ImplCreateOptions();
240 : // languages for a visible document are set by docshell later (from options)
241 688 : SetLanguage( ScGlobal::eLnge, ScGlobal::eLnge, ScGlobal::eLnge );
242 :
243 688 : aTrackTimer.SetTimeoutHdl( LINK( this, ScDocument, TrackTimeHdl ) );
244 688 : aTrackTimer.SetTimeout( 100 );
245 688 : }
246 :
247 1259 : sfx2::LinkManager* ScDocument::GetLinkManager() const
248 : {
249 1259 : if ( bAutoCalc && !pLinkManager && pShell)
250 : {
251 0 : pLinkManager = new sfx2::LinkManager( pShell );
252 : }
253 1259 : return pLinkManager;
254 : }
255 :
256 :
257 770 : 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 770 : 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 770 : formula::FormulaGrammar::CONV_OOO);
272 770 : }
273 :
274 :
275 30 : 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 30 : bIsVisible = bSet;
280 30 : }
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 1016 : ScDocument::~ScDocument()
350 : {
351 : OSL_PRECOND( !bInLinkUpdate, "bInLinkUpdate in dtor" );
352 :
353 508 : bInDtorClear = true;
354 :
355 : // first of all disable all refresh timers by deleting the control
356 508 : 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 420 : ScRefreshTimerProtector aProt( GetRefreshTimerControlAddress() );
360 420 : delete pRefreshTimerControl, pRefreshTimerControl = NULL;
361 : }
362 :
363 : // Links aufrauemen
364 :
365 508 : if ( GetLinkManager() )
366 : {
367 : // BaseLinks freigeben
368 420 : ::sfx2::SvLinkSources aTemp(pLinkManager->GetServers());
369 420 : for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it )
370 0 : (*it)->Closed();
371 :
372 420 : if ( pLinkManager->GetLinks().size() )
373 0 : pLinkManager->Remove( 0, pLinkManager->GetLinks().size() );
374 : }
375 :
376 508 : 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 508 : pExternalRefMgr.reset();
380 :
381 508 : ScAddInAsync::RemoveDocument( this );
382 508 : ScAddInListener::RemoveDocument( this );
383 508 : DELETEZ( pChartListenerCollection); // vor pBASM wg. evtl. Listener!
384 508 : DELETEZ( pLookupCacheMapImpl); // before pBASM because of listeners
385 : // BroadcastAreas vor allen Zellen zerstoeren um unnoetige
386 : // Einzel-EndListenings der Formelzellen zu vermeiden
387 508 : delete pBASM; // BroadcastAreaSlotMachine
388 508 : pBASM = NULL;
389 :
390 508 : delete pUnoBroadcaster; // broadcasted nochmal SFX_HINT_DYING
391 508 : pUnoBroadcaster = NULL;
392 :
393 508 : delete pUnoRefUndoList;
394 508 : delete pUnoListenerCalls;
395 :
396 508 : Clear( true ); // true = from destructor (needed for SdrModel::ClearModel)
397 :
398 508 : if (pValidationList)
399 : {
400 10 : for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
401 6 : delete *it;
402 4 : pValidationList->clear();
403 4 : DELETEZ(pValidationList);
404 : }
405 508 : delete pRangeName;
406 508 : delete pDBCollection;
407 508 : delete pSelectionAttr;
408 508 : apTemporaryChartLock.reset();
409 508 : delete pChartCollection;
410 508 : DeleteDrawLayer();
411 508 : delete pFormatExchangeList;
412 508 : delete pPrinter;
413 508 : ImplDeleteOptions();
414 508 : delete pConsolidateDlgData;
415 508 : delete pLinkManager;
416 508 : delete pClipData;
417 508 : delete pDetOpList; // loescht auch die Eintraege
418 508 : delete pChangeTrack;
419 508 : delete pEditEngine;
420 508 : delete pNoteEngine;
421 508 : delete pChangeViewSettings; // und weg damit
422 508 : delete pVirtualDevice_100th_mm;
423 :
424 508 : delete pDPCollection;
425 :
426 : // delete the EditEngine before destroying the xPoolHelper
427 508 : delete pCacheFieldEditEngine;
428 :
429 508 : if ( xPoolHelper.is() && !bIsClip )
430 504 : xPoolHelper->SourceDocumentGone();
431 508 : xPoolHelper.clear();
432 :
433 508 : delete pScriptTypeData;
434 508 : delete pRecursionHelper;
435 :
436 : OSL_POSTCOND( !pAutoNameCache, "AutoNameCache still set in dtor" );
437 508 : }
438 :
439 6 : void ScDocument::InitClipPtrs( ScDocument* pSourceDoc )
440 : {
441 : OSL_ENSURE(bIsClip, "InitClipPtrs und nicht bIsClip");
442 :
443 6 : 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 6 : Clear();
452 :
453 6 : xPoolHelper = pSourceDoc->xPoolHelper;
454 :
455 : // bedingte Formate / Gueltigkeiten
456 : //! Vorlagen kopieren?
457 6 : const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList;
458 6 : if ( pSourceValid )
459 0 : pValidationList = new ScValidationDataList(this, *pSourceValid);
460 :
461 : // Links in Stream speichern
462 6 : delete pClipData;
463 6 : if (pSourceDoc->HasDdeLinks())
464 : {
465 0 : pClipData = new SvMemoryStream;
466 0 : pSourceDoc->SaveDdeLinks(*pClipData);
467 : }
468 : else
469 6 : pClipData = NULL;
470 :
471 : // Options pointers exist (ImplCreateOptions) for any document.
472 : // Must be copied for correct results in OLE objects (#i42666#).
473 6 : SetDocOptions( pSourceDoc->GetDocOptions() );
474 6 : SetViewOptions( pSourceDoc->GetViewOptions() );
475 6 : }
476 :
477 50196 : SvNumberFormatter* ScDocument::GetFormatTable() const
478 : {
479 50196 : return xPoolHelper->GetFormTable();
480 : }
481 :
482 381 : SfxItemPool* ScDocument::GetEditPool() const
483 : {
484 381 : return xPoolHelper->GetEditPool();
485 : }
486 :
487 111 : SfxItemPool* ScDocument::GetEnginePool() const
488 : {
489 111 : return xPoolHelper->GetEnginePool();
490 : }
491 :
492 128 : ScFieldEditEngine& ScDocument::GetEditEngine()
493 : {
494 128 : if ( !pEditEngine )
495 : {
496 16 : pEditEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
497 16 : pEditEngine->SetUpdateMode( false );
498 16 : pEditEngine->EnableUndo( false );
499 16 : pEditEngine->SetRefMapMode( MAP_100TH_MM );
500 16 : ApplyAsianEditSettings( *pEditEngine );
501 : }
502 128 : 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 6 : void ScDocument::ResetClip( ScDocument* pSourceDoc, const ScMarkData* pMarks )
524 : {
525 6 : if (bIsClip)
526 : {
527 6 : InitClipPtrs(pSourceDoc);
528 :
529 18 : for (SCTAB i = 0; i < static_cast<SCTAB>(pSourceDoc->maTabs.size()); i++)
530 12 : if (pSourceDoc->maTabs[i])
531 12 : if (!pMarks || pMarks->GetTableSelect(i))
532 : {
533 6 : rtl::OUString aString;
534 6 : pSourceDoc->maTabs[i]->GetName(aString);
535 6 : if ( i < static_cast<SCTAB>(maTabs.size()) )
536 : {
537 0 : maTabs[i] = new ScTable(this, i, aString);
538 :
539 : }
540 : else
541 : {
542 6 : if( i > static_cast<SCTAB>(maTabs.size()) )
543 : {
544 0 : maTabs.resize(i, NULL );
545 : }
546 6 : maTabs.push_back(new ScTable(this, i, aString));
547 : }
548 6 : maTabs[i]->SetLayoutRTL( pSourceDoc->maTabs[i]->IsLayoutRTL() );
549 : }
550 : }
551 : else
552 : {
553 : OSL_FAIL("ResetClip");
554 : }
555 6 : }
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 428 : bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
601 : bool bNotes ) const
602 : {
603 428 : if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
604 : {
605 428 : bool bAny = maTabs[nTab]->GetPrintArea( rEndCol, rEndRow, bNotes );
606 428 : if (pDrawLayer)
607 : {
608 262 : ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
609 262 : if (DrawGetPrintArea( aDrawRange, true, true ))
610 : {
611 16 : if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
612 16 : if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
613 16 : bAny = true;
614 : }
615 : }
616 428 : 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 38 : bool ScDocument::GetPrintAreaVer( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol,
647 : SCROW& rEndRow, bool bNotes ) const
648 : {
649 38 : if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
650 : {
651 38 : bool bAny = maTabs[nTab]->GetPrintAreaVer( nStartCol, nEndCol, rEndRow, bNotes );
652 38 : if (pDrawLayer)
653 : {
654 38 : ScRange aDrawRange(nStartCol,0,nTab, nEndCol,MAXROW,nTab);
655 38 : if (DrawGetPrintArea( aDrawRange, false, true ))
656 : {
657 0 : if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
658 0 : bAny = true;
659 : }
660 : }
661 38 : return bAny;
662 : }
663 :
664 0 : rEndRow = 0;
665 0 : return false;
666 : }
667 :
668 242 : bool ScDocument::GetDataStart( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow ) const
669 : {
670 242 : if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
671 : {
672 242 : bool bAny = maTabs[nTab]->GetDataStart( rStartCol, rStartRow );
673 242 : if (pDrawLayer)
674 : {
675 200 : ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
676 200 : if (DrawGetPrintArea( aDrawRange, true, true ))
677 : {
678 16 : if (aDrawRange.aStart.Col()<rStartCol) rStartCol=aDrawRange.aStart.Col();
679 16 : if (aDrawRange.aStart.Row()<rStartRow) rStartRow=aDrawRange.aStart.Row();
680 16 : bAny = true;
681 : }
682 : }
683 242 : return bAny;
684 : }
685 :
686 0 : rStartCol = 0;
687 0 : rStartRow = 0;
688 0 : return false;
689 : }
690 :
691 10 : bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
692 : {
693 10 : if (nOldPos == nNewPos)
694 0 : return false;
695 :
696 10 : SCTAB nTabCount = static_cast<SCTAB>(maTabs.size());
697 10 : if(nTabCount < 2)
698 0 : return false;
699 :
700 10 : bool bValid = false;
701 10 : if (VALIDTAB(nOldPos) && nOldPos < nTabCount )
702 : {
703 10 : if (maTabs[nOldPos])
704 : {
705 10 : bool bOldAutoCalc = GetAutoCalc();
706 10 : SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
707 10 : SetNoListening( true );
708 10 : if (nNewPos == SC_TAB_APPEND || nNewPos >= nTabCount)
709 0 : nNewPos = nTabCount-1;
710 :
711 : // Referenz-Updaterei
712 : //! mit UpdateReference zusammenfassen!
713 :
714 10 : SCsTAB nDz = ((SCsTAB)nNewPos) - (SCsTAB)nOldPos;
715 10 : ScRange aSourceRange( 0,0,nOldPos, MAXCOL,MAXROW,nOldPos );
716 10 : if (pRangeName)
717 2 : pRangeName->UpdateTabRef(nOldPos, 3, nNewPos);
718 10 : pDBCollection->UpdateMoveTab( nOldPos, nNewPos );
719 10 : xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
720 10 : xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
721 10 : if (pDPCollection)
722 4 : pDPCollection->UpdateReference( URM_REORDER, aSourceRange, 0,0,nDz );
723 10 : if (pDetOpList)
724 0 : pDetOpList->UpdateReference( this, URM_REORDER, aSourceRange, 0,0,nDz );
725 : UpdateChartRef( URM_REORDER,
726 10 : 0,0,nOldPos, MAXCOL,MAXROW,nOldPos, 0,0,nDz );
727 10 : UpdateRefAreaLinks( URM_REORDER, aSourceRange, 0,0,nDz );
728 10 : if ( pValidationList )
729 0 : pValidationList->UpdateMoveTab( nOldPos, nNewPos );
730 10 : if ( pUnoBroadcaster )
731 : pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_REORDER,
732 10 : aSourceRange, 0,0,nDz ) );
733 :
734 10 : ScTable* pSaveTab = maTabs[nOldPos];
735 10 : maTabs.erase(maTabs.begin()+nOldPos);
736 10 : maTabs.insert(maTabs.begin()+nNewPos, pSaveTab);
737 10 : TableContainer::iterator it = maTabs.begin();
738 30 : for (SCTAB i = 0; i < nTabCount; i++)
739 20 : if (maTabs[i])
740 20 : maTabs[i]->UpdateMoveTab( nOldPos, nNewPos, i, pProgress );
741 10 : it = maTabs.begin();
742 30 : for (; it != maTabs.end(); ++it)
743 20 : if (*it)
744 20 : (*it)->UpdateCompile();
745 10 : SetNoListening( false );
746 10 : it = maTabs.begin();
747 30 : for (; it != maTabs.end(); ++it)
748 20 : if (*it)
749 20 : (*it)->StartAllListeners();
750 : // sheet names of references may not be valid until sheet is moved
751 10 : pChartListenerCollection->UpdateScheduledSeriesRanges();
752 10 : SetDirty();
753 10 : SetAutoCalc( bOldAutoCalc );
754 :
755 10 : if (pDrawLayer)
756 2 : DrawMovePage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
757 :
758 10 : bValid = true;
759 : }
760 : }
761 10 : return bValid;
762 : }
763 :
764 6 : bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyMarked )
765 : {
766 6 : if (SC_TAB_APPEND == nNewPos || nNewPos >= static_cast<SCTAB>(maTabs.size()))
767 6 : nNewPos = static_cast<SCTAB>(maTabs.size());
768 6 : rtl::OUString aName;
769 6 : GetName(nOldPos, aName);
770 :
771 : // vorneweg testen, ob der Prefix als gueltig erkannt wird
772 : // wenn nicht, nur doppelte vermeiden
773 6 : bool bPrefix = ValidTabName( aName );
774 : OSL_ENSURE(bPrefix, "ungueltiger Tabellenname");
775 : SCTAB nDummy;
776 :
777 6 : CreateValidTabName(aName);
778 :
779 : bool bValid;
780 6 : if (bPrefix)
781 6 : bValid = ValidNewTabName(aName);
782 : else
783 0 : bValid = !GetTable( aName, nDummy );
784 :
785 6 : bool bOldAutoCalc = GetAutoCalc();
786 6 : SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
787 6 : if (bValid)
788 : {
789 6 : if (nNewPos >= static_cast<SCTAB>(maTabs.size()))
790 : {
791 6 : nNewPos = static_cast<SCTAB>(maTabs.size());
792 6 : 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 6 : if (bValid)
845 : {
846 6 : SetNoListening( true ); // noch nicht bei CopyToTable/Insert
847 6 : maTabs[nOldPos]->CopyToTable(0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
848 12 : maTabs[nNewPos], pOnlyMarked );
849 6 : maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
850 :
851 6 : SCsTAB nDz = (static_cast<SCsTAB>(nNewPos)) - static_cast<SCsTAB>(nOldPos);
852 6 : maTabs[nNewPos]->UpdateReference(URM_COPY, 0, 0, nNewPos , MAXCOL, MAXROW,
853 12 : nNewPos, 0, 0, nDz, NULL);
854 :
855 6 : maTabs[nNewPos]->UpdateInsertTabAbs(nNewPos); // alle abs. um eins hoch!!
856 6 : maTabs[nOldPos]->UpdateInsertTab(nNewPos);
857 :
858 6 : maTabs[nOldPos]->UpdateCompile();
859 6 : maTabs[nNewPos]->UpdateCompile( true ); // maybe already compiled in Clone, but used names need recompilation
860 6 : SetNoListening( false );
861 6 : maTabs[nOldPos]->StartAllListeners();
862 6 : maTabs[nNewPos]->StartAllListeners();
863 :
864 6 : ScConditionalFormatList* pNewList = new ScConditionalFormatList(*maTabs[nOldPos]->GetCondFormList());
865 : pNewList->UpdateReference(URM_COPY, ScRange( 0, 0, nNewPos , MAXCOL, MAXROW,
866 6 : nNewPos), 0, 0, nDz);
867 6 : maTabs[nNewPos]->SetCondFormList( pNewList );
868 :
869 6 : SetDirty();
870 6 : SetAutoCalc( bOldAutoCalc );
871 :
872 6 : if (pDrawLayer)
873 2 : DrawCopyPage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
874 :
875 6 : if (pDPCollection)
876 0 : pDPCollection->CopyToTab(nOldPos, nNewPos);
877 :
878 6 : maTabs[nNewPos]->SetPageStyle( maTabs[nOldPos]->GetPageStyle() );
879 6 : maTabs[nNewPos]->SetPendingRowHeights( maTabs[nOldPos]->IsPendingRowHeights() );
880 :
881 : // Copy the custom print range if exists.
882 6 : maTabs[nNewPos]->CopyPrintRange(*maTabs[nOldPos]);
883 :
884 : // Copy the RTL settings
885 6 : maTabs[nNewPos]->SetLayoutRTL(maTabs[nOldPos]->IsLayoutRTL());
886 6 : maTabs[nNewPos]->SetLoadingRTL(maTabs[nOldPos]->IsLoadingRTL());
887 : }
888 : else
889 0 : SetAutoCalc( bOldAutoCalc );
890 6 : return bValid;
891 : }
892 :
893 : void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const rtl::OUString& sModuleName, const rtl::OUString& sModuleSource );
894 :
895 2 : sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
896 : SCTAB nDestPos, bool bInsertNew,
897 : bool bResultsOnly )
898 : {
899 2 : sal_uLong nRetVal = 1; // 0 => Fehler 1 = ok
900 : // 3 => NameBox
901 : // 4 => beides
902 :
903 2 : if (pSrcDoc->pShell->GetMedium())
904 : {
905 2 : 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 2 : 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 2 : bool bValid = true;
916 2 : if (bInsertNew) // neu einfuegen
917 : {
918 2 : rtl::OUString aName;
919 2 : pSrcDoc->GetName(nSrcPos, aName);
920 2 : CreateValidTabName(aName);
921 2 : bValid = InsertTab(nDestPos, aName);
922 :
923 : // Copy the RTL settings
924 2 : maTabs[nDestPos]->SetLayoutRTL(pSrcDoc->maTabs[nSrcPos]->IsLayoutRTL());
925 2 : 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 2 : if (bValid)
938 : {
939 2 : bool bOldAutoCalcSrc = false;
940 2 : bool bOldAutoCalc = GetAutoCalc();
941 2 : SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
942 2 : SetNoListening( true );
943 2 : if ( bResultsOnly )
944 : {
945 0 : bOldAutoCalcSrc = pSrcDoc->GetAutoCalc();
946 0 : pSrcDoc->SetAutoCalc( true ); // falls was berechnet werden muss
947 : }
948 :
949 : {
950 2 : NumFmtMergeHandler aNumFmtMergeHdl(this, pSrcDoc);
951 :
952 2 : nDestPos = Min(nDestPos, (SCTAB)(GetTableCount() - 1));
953 : { // scope for bulk broadcast
954 2 : ScBulkBroadcast aBulkBroadcast( pBASM);
955 2 : pSrcDoc->maTabs[nSrcPos]->CopyToTable(0, 0, MAXCOL, MAXROW,
956 : ( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL),
957 4 : false, maTabs[nDestPos] );
958 2 : }
959 : }
960 2 : maTabs[nDestPos]->SetTabNo(nDestPos);
961 2 : maTabs[nDestPos]->SetTabBgColor(pSrcDoc->maTabs[nSrcPos]->GetTabBgColor());
962 :
963 2 : if ( !bResultsOnly )
964 : {
965 :
966 2 : SCsTAB nDz = ((SCsTAB)nDestPos) - (SCsTAB)nSrcPos;
967 2 : maTabs[nDestPos]->UpdateReference(URM_COPY, 0, 0, nDestPos,
968 : MAXCOL, MAXROW, nDestPos,
969 4 : 0, 0, nDz, NULL);
970 : // Readjust self-contained absolute references to this sheet
971 2 : maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
972 2 : maTabs[nDestPos]->CompileAll();
973 : }
974 :
975 2 : SetNoListening( false );
976 2 : if ( !bResultsOnly )
977 2 : maTabs[nDestPos]->StartAllListeners();
978 2 : SetDirty( ScRange( 0, 0, nDestPos, MAXCOL, MAXROW, nDestPos));
979 :
980 2 : if ( bResultsOnly )
981 0 : pSrcDoc->SetAutoCalc( bOldAutoCalcSrc );
982 2 : SetAutoCalc( bOldAutoCalc );
983 :
984 : // Drawing kopieren
985 :
986 2 : if (bInsertNew)
987 2 : TransferDrawPage( pSrcDoc, nSrcPos, nDestPos );
988 :
989 2 : maTabs[nDestPos]->SetPendingRowHeights( pSrcDoc->maTabs[nSrcPos]->IsPendingRowHeights() );
990 : }
991 2 : if (!bValid)
992 0 : nRetVal = 0;
993 2 : bool bVbaEnabled = IsInVBAMode();
994 :
995 2 : 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 2 : 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 104 : ScFieldEditEngine* ScDocument::CreateFieldEditEngine()
1065 : {
1066 104 : ScFieldEditEngine* pNewEditEngine = NULL;
1067 104 : if (!pCacheFieldEditEngine)
1068 : {
1069 : pNewEditEngine = new ScFieldEditEngine(
1070 42 : this, GetEnginePool(), GetEditPool(), false);
1071 : }
1072 : else
1073 : {
1074 62 : 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 60 : if ( !pCacheFieldEditEngine->GetUpdateMode() )
1079 0 : pCacheFieldEditEngine->SetUpdateMode(true);
1080 : }
1081 :
1082 62 : pNewEditEngine = pCacheFieldEditEngine;
1083 62 : pCacheFieldEditEngine = NULL;
1084 : }
1085 104 : return pNewEditEngine;
1086 : }
1087 :
1088 126 : void ScDocument::DisposeFieldEditEngine(ScFieldEditEngine*& rpEditEngine)
1089 : {
1090 126 : if (!pCacheFieldEditEngine && rpEditEngine)
1091 : {
1092 72 : pCacheFieldEditEngine = rpEditEngine;
1093 72 : pCacheFieldEditEngine->Clear();
1094 : }
1095 : else
1096 54 : delete rpEditEngine;
1097 126 : rpEditEngine = NULL;
1098 126 : }
1099 :
1100 : // ----------------------------------------------------------------------------
1101 :
1102 86 : ScRecursionHelper* ScDocument::CreateRecursionHelperInstance()
1103 : {
1104 86 : return new ScRecursionHelper;
1105 : }
1106 :
1107 : // ----------------------------------------------------------------------------
1108 :
1109 104 : ScLookupCache & ScDocument::GetLookupCache( const ScRange & rRange )
1110 : {
1111 104 : ScLookupCache* pCache = 0;
1112 104 : if (!pLookupCacheMapImpl)
1113 4 : pLookupCacheMapImpl = new ScLookupCacheMapImpl;
1114 104 : ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find( rRange));
1115 104 : if (it == pLookupCacheMapImpl->aCacheMap.end())
1116 : {
1117 8 : pCache = new ScLookupCache( this, rRange);
1118 8 : AddLookupCache( *pCache);
1119 : }
1120 : else
1121 96 : pCache = (*it).second;
1122 104 : return *pCache;
1123 : }
1124 :
1125 8 : void ScDocument::AddLookupCache( ScLookupCache & rCache )
1126 : {
1127 16 : if (!pLookupCacheMapImpl->aCacheMap.insert( ::std::pair< const ScRange,
1128 16 : ScLookupCache*>( rCache.getRange(), &rCache)).second)
1129 : {
1130 : OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map");
1131 : }
1132 : else
1133 8 : StartListeningArea( rCache.getRange(), &rCache);
1134 8 : }
1135 :
1136 6 : void ScDocument::RemoveLookupCache( ScLookupCache & rCache )
1137 : {
1138 : ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find(
1139 6 : rCache.getRange()));
1140 6 : if (it == pLookupCacheMapImpl->aCacheMap.end())
1141 : {
1142 : OSL_FAIL( "ScDocument::RemoveLookupCache: range not found in hash map");
1143 : }
1144 : else
1145 : {
1146 6 : ScLookupCache* pCache = (*it).second;
1147 6 : pLookupCacheMapImpl->aCacheMap.erase( it);
1148 6 : EndListeningArea( pCache->getRange(), &rCache);
1149 : }
1150 6 : }
1151 :
1152 108 : void ScDocument::ClearLookupCaches()
1153 : {
1154 108 : if( pLookupCacheMapImpl )
1155 16 : pLookupCacheMapImpl->clear();
1156 210 : }
1157 :
1158 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|