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