fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / documen2.cxx
blob8d3e4e3d3b8fd1927bb7857d65e53dcf88f07fd2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
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>
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 #include "docsh.hxx"
102 #include <listenercontext.hxx>
104 using namespace com::sun::star;
106 // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
107 // dtor plus helpers are convenient.
108 struct ScLookupCacheMapImpl
110 ScLookupCacheMap aCacheMap;
111 ~ScLookupCacheMapImpl()
113 freeCaches();
115 void clear()
117 freeCaches();
118 // free mapping
119 ScLookupCacheMap aTmp;
120 aCacheMap.swap( aTmp);
122 private:
123 void freeCaches()
125 for (ScLookupCacheMap::iterator it( aCacheMap.begin()); it != aCacheMap.end(); ++it)
126 delete (*it).second;
130 // STATIC DATA -----------------------------------------------------------
132 ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
133 mpCellStringPool(new svl::SharedStringPool(ScGlobal::pCharClass)),
134 mpFormulaGroupCxt(NULL),
135 maCalcConfig( ScInterpreter::GetGlobalConfig()),
136 mpUndoManager( NULL ),
137 pEditEngine( NULL ),
138 pNoteEngine( NULL ),
139 pShell( pDocShell ),
140 pPrinter( NULL ),
141 pVirtualDevice_100th_mm( NULL ),
142 pDrawLayer( NULL ),
143 pValidationList( NULL ),
144 pFormatExchangeList( NULL ),
145 pRangeName(NULL),
146 pDPCollection( NULL ),
147 pFormulaTree( NULL ),
148 pEOFormulaTree( NULL ),
149 pFormulaTrack( NULL ),
150 pEOFormulaTrack( NULL ),
151 pClipData( NULL ),
152 pDetOpList(NULL),
153 pChangeTrack( NULL ),
154 pUnoBroadcaster( NULL ),
155 pUnoListenerCalls( NULL ),
156 pUnoRefUndoList( NULL ),
157 pChangeViewSettings( NULL ),
158 pScriptTypeData( NULL ),
159 pCacheFieldEditEngine( NULL ),
160 pViewOptions( NULL ),
161 pDocOptions( NULL ),
162 pExtDocOptions( NULL ),
163 pConsolidateDlgData( NULL ),
164 pRecursionHelper( NULL ),
165 pAutoNameCache( NULL ),
166 pLookupCacheMapImpl( NULL ),
167 pPreviewFont( NULL ),
168 pPreviewCellStyle( NULL ),
169 nUnoObjectId( 0 ),
170 nRangeOverflowType( 0 ),
171 aCurTextWidthCalcPos(MAXCOL,0,0),
172 aTableOpList( 0 ),
173 nFormulaCodeInTree(0),
174 nXMLImportedFormulaCount( 0 ),
175 nInterpretLevel(0),
176 nMacroInterpretLevel(0),
177 nInterpreterTableOpLevel(0),
178 nSrcVer( SC_CURRENT_VERSION ),
179 nSrcMaxRow( MAXROW ),
180 nFormulaTrackCount(0),
181 bHardRecalcState(false),
182 nVisibleTab( 0 ),
183 eLinkMode(LM_UNKNOWN),
184 bAutoCalc( eMode == SCDOCMODE_DOCUMENT ),
185 bAutoCalcShellDisabled( false ),
186 bForcedFormulaPending( false ),
187 bCalculatingFormulaTree( false ),
188 bIsClip( eMode == SCDOCMODE_CLIP ),
189 bIsUndo( eMode == SCDOCMODE_UNDO ),
190 bIsVisible( false ),
191 bIsEmbedded( false ),
192 bInsertingFromOtherDoc( false ),
193 bLoadingMedium( false ),
194 bImportingXML( false ),
195 bCalcingAfterLoad( false ),
196 bNoListening( false ),
197 mbIdleEnabled(true),
198 bInLinkUpdate( false ),
199 bChartListenerCollectionNeedsUpdate( false ),
200 bHasForcedFormulas( false ),
201 bInDtorClear( false ),
202 bExpandRefs( false ),
203 bDetectiveDirty( false ),
204 nMacroCallMode( SC_MACROCALL_ALLOWED ),
205 bHasMacroFunc( false ),
206 nVisSpellState( 0 ),
207 nAsianCompression(SC_ASIANCOMPRESSION_INVALID),
208 nAsianKerning(SC_ASIANKERNING_INVALID),
209 bPastingDrawFromOtherDoc( false ),
210 nInDdeLinkUpdate( 0 ),
211 bInUnoBroadcast( false ),
212 bInUnoListenerCall( false ),
213 eGrammar( formula::FormulaGrammar::GRAM_NATIVE ),
214 bStyleSheetUsageInvalid( true ),
215 mbUndoEnabled( true ),
216 mbAdjustHeightEnabled( true ),
217 mbExecuteLinkEnabled( true ),
218 mbChangeReadOnlyEnabled( false ),
219 mbStreamValidLocked( false ),
220 mbUserInteractionEnabled(true),
221 mnNamedRangesLockCount(0),
222 mbUseEmbedFonts(false)
224 SetStorageGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT);
226 eSrcSet = osl_getThreadTextEncoding();
228 if ( eMode == SCDOCMODE_DOCUMENT )
230 xPoolHelper = new ScPoolHelper( this );
232 pBASM = new ScBroadcastAreaSlotMachine( this );
233 pChartListenerCollection = new ScChartListenerCollection( this );
234 pRefreshTimerControl = new ScRefreshTimerControl;
236 else
238 pBASM = NULL;
239 pChartListenerCollection = NULL;
240 pRefreshTimerControl = NULL;
242 pDBCollection = new ScDBCollection(this);
243 pSelectionAttr = NULL;
244 pChartCollection = new ScChartCollection;
245 apTemporaryChartLock.reset( new ScTemporaryChartLock(this) );
246 xColNameRanges = new ScRangePairList;
247 xRowNameRanges = new ScRangePairList;
248 ImplCreateOptions();
249 // languages for a visible document are set by docshell later (from options)
250 SetLanguage( ScGlobal::eLnge, ScGlobal::eLnge, ScGlobal::eLnge );
252 aTrackIdle.SetIdleHdl( LINK( this, ScDocument, TrackTimeHdl ) );
253 aTrackIdle.SetPriority( SchedulerPriority::LOW );
256 sfx2::LinkManager* ScDocument::GetLinkManager()
258 return GetDocLinkManager().getLinkManager(true);
261 const sfx2::LinkManager* ScDocument::GetLinkManager() const
263 return GetDocLinkManager().getExistingLinkManager();
266 sc::DocumentLinkManager& ScDocument::GetDocLinkManager()
268 if (!mpDocLinkMgr)
269 mpDocLinkMgr.reset(new sc::DocumentLinkManager(*this, pShell));
270 return *mpDocLinkMgr;
273 const sc::DocumentLinkManager& ScDocument::GetDocLinkManager() const
275 return const_cast<ScDocument*>(this)->GetDocLinkManager();
278 void ScDocument::SetStorageGrammar( formula::FormulaGrammar::Grammar eGram )
280 OSL_PRECOND(
281 eGram == formula::FormulaGrammar::GRAM_ODFF ||
282 eGram == formula::FormulaGrammar::GRAM_PODF,
283 "ScDocument::SetStorageGrammar: wrong storage grammar");
285 eStorageGrammar = eGram;
287 // FIXME: the XML import shouldn't strip brackets, the compiler should
288 // digest them instead, which could also speedup reference recognition
289 // during import.
291 eXmlImportGrammar = formula::FormulaGrammar::mergeToGrammar( eGram,
292 formula::FormulaGrammar::CONV_OOO);
295 void ScDocument::SetDocVisible( bool bSet )
297 // called from view ctor - only for a visible document,
298 // each new sheet's RTL flag is initialized from the locale
299 bIsVisible = bSet;
302 sal_uInt32 ScDocument::GetDocumentID() const
304 const ScDocument* pThis = this;
305 sal_uInt32 nCrc = rtl_crc32( 0, &pThis, sizeof(ScDocument*) );
306 // the this pointer only might not be sufficient
307 nCrc = rtl_crc32( nCrc, &pShell, sizeof(SfxObjectShell*) );
308 return nCrc;
311 void ScDocument::StartChangeTracking()
313 if (!pChangeTrack)
314 pChangeTrack = new ScChangeTrack( this );
317 void ScDocument::EndChangeTracking()
319 delete pChangeTrack;
320 pChangeTrack = NULL;
323 void ScDocument::SetChangeTrack( ScChangeTrack* pTrack )
325 OSL_ENSURE( pTrack->GetDocument() == this, "SetChangeTrack: different documents" );
326 if ( !pTrack || pTrack == pChangeTrack || pTrack->GetDocument() != this )
327 return ;
328 EndChangeTracking();
329 pChangeTrack = pTrack;
332 IMPL_LINK_NOARG_TYPED(ScDocument, TrackTimeHdl, Idle *, void)
334 if ( ScDdeLink::IsInUpdate() ) // do not nest
336 aTrackIdle.Start(); // try again later
338 else if (pShell) // execute
340 TrackFormulas();
341 pShell->Broadcast( SfxSimpleHint( FID_DATACHANGED ) );
343 // modified...
345 if (!pShell->IsModified())
347 pShell->SetModified( true );
348 SfxBindings* pBindings = GetViewBindings();
349 if (pBindings)
351 pBindings->Invalidate( SID_SAVEDOC );
352 pBindings->Invalidate( SID_DOC_MODIFIED );
358 void ScDocument::SetExpandRefs( bool bVal )
360 bExpandRefs = bVal;
363 void ScDocument::StartTrackTimer()
365 if (!aTrackIdle.IsActive()) // do not postpone for forever
366 aTrackIdle.Start();
369 ScDocument::~ScDocument()
371 OSL_PRECOND( !bInLinkUpdate, "bInLinkUpdate in dtor" );
373 bInDtorClear = true;
375 // first of all disable all refresh timers by deleting the control
376 if ( pRefreshTimerControl )
377 { // To be sure there isn't anything running do it with a protector,
378 // this ensures also that nothing needs the control anymore.
379 ScRefreshTimerProtector aProt( GetRefreshTimerControlAddress() );
380 delete pRefreshTimerControl, pRefreshTimerControl = NULL;
383 mxFormulaParserPool.reset();
384 // Destroy the external ref mgr instance here because it has a timer
385 // which needs to be stopped before the app closes.
386 pExternalRefMgr.reset();
388 ScAddInAsync::RemoveDocument( this );
389 ScAddInListener::RemoveDocument( this );
390 DELETEZ( pChartListenerCollection); // before pBASM because of potential Listener!
391 DELETEZ( pLookupCacheMapImpl); // before pBASM because of listeners
392 // destroy BroadcastAreas first to avoid un-needed Single-EndListenings of Formula-Cells
393 delete pBASM; // BroadcastAreaSlotMachine
394 pBASM = NULL;
396 delete pUnoBroadcaster; // broadcasted nochmal SFX_HINT_DYING
397 pUnoBroadcaster = NULL;
399 delete pUnoRefUndoList;
400 delete pUnoListenerCalls;
402 Clear( true ); // true = from destructor (needed for SdrModel::ClearModel)
404 if (pValidationList)
406 for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
407 delete *it;
408 pValidationList->clear();
409 DELETEZ(pValidationList);
411 delete pRangeName;
412 delete pDBCollection;
413 delete pSelectionAttr;
414 apTemporaryChartLock.reset();
415 delete pChartCollection;
416 DeleteDrawLayer();
417 delete pFormatExchangeList;
418 pPrinter.disposeAndClear();
419 ImplDeleteOptions();
420 delete pConsolidateDlgData;
421 delete pClipData;
422 delete pDetOpList; // also deletes entries
423 delete pChangeTrack;
424 delete pEditEngine;
425 delete pNoteEngine;
426 delete pChangeViewSettings; // and delete
427 pVirtualDevice_100th_mm.disposeAndClear();
429 delete pDPCollection;
431 // delete the EditEngine before destroying the xPoolHelper
432 delete pCacheFieldEditEngine;
434 if ( xPoolHelper.is() && !bIsClip )
435 xPoolHelper->SourceDocumentGone();
436 xPoolHelper.clear();
438 delete pScriptTypeData;
439 delete pRecursionHelper;
441 delete pPreviewFont;
442 SAL_WARN_IF( pAutoNameCache, "sc.core", "AutoNameCache still set in dtor" );
444 mpFormulaGroupCxt.reset();
445 mpCellStringPool.reset();
448 void ScDocument::InitClipPtrs( ScDocument* pSourceDoc )
450 OSL_ENSURE(bIsClip, "InitClipPtrs and not bIsClip");
452 if (pValidationList)
454 for(ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it )
455 delete *it;
456 pValidationList->clear();
457 DELETEZ(pValidationList);
460 Clear();
462 SharePooledResources(pSourceDoc);
464 // conditional Formats / validations
465 // TODO: Copy Templates?
466 const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList;
467 if ( pSourceValid )
468 pValidationList = new ScValidationDataList(this, *pSourceValid);
470 // store Links in Stream
471 delete pClipData;
472 if (pSourceDoc->GetDocLinkManager().hasDdeLinks())
474 pClipData = new SvMemoryStream;
475 pSourceDoc->SaveDdeLinks(*pClipData);
477 else
478 pClipData = NULL;
480 // Options pointers exist (ImplCreateOptions) for any document.
481 // Must be copied for correct results in OLE objects (#i42666#).
482 SetDocOptions( pSourceDoc->GetDocOptions() );
483 SetViewOptions( pSourceDoc->GetViewOptions() );
486 SvNumberFormatter* ScDocument::GetFormatTable() const
488 return xPoolHelper->GetFormTable();
491 SvNumberFormatter* ScDocument::CreateFormatTable() const
493 return xPoolHelper->CreateNumberFormatter();
496 SfxItemPool* ScDocument::GetEditPool() const
498 return xPoolHelper->GetEditPool();
501 SfxItemPool* ScDocument::GetEnginePool() const
503 return xPoolHelper->GetEnginePool();
506 ScFieldEditEngine& ScDocument::GetEditEngine()
508 if ( !pEditEngine )
510 pEditEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
511 pEditEngine->SetUpdateMode( false );
512 pEditEngine->EnableUndo( false );
513 pEditEngine->SetRefMapMode( MAP_100TH_MM );
514 ApplyAsianEditSettings( *pEditEngine );
516 return *pEditEngine;
519 ScNoteEditEngine& ScDocument::GetNoteEngine()
521 if ( !pNoteEngine )
523 pNoteEngine = new ScNoteEditEngine( GetEnginePool(), GetEditPool() );
524 pNoteEngine->SetUpdateMode( false );
525 pNoteEngine->EnableUndo( false );
526 pNoteEngine->SetRefMapMode( MAP_100TH_MM );
527 ApplyAsianEditSettings( *pNoteEngine );
528 const SfxItemSet& rItemSet = GetDefPattern()->GetItemSet();
529 SfxItemSet* pEEItemSet = new SfxItemSet( pNoteEngine->GetEmptyItemSet() );
530 ScPatternAttr::FillToEditItemSet( *pEEItemSet, rItemSet );
531 pNoteEngine->SetDefaults( pEEItemSet ); // edit engine takes ownership
533 return *pNoteEngine;
536 void ScDocument::ResetClip( ScDocument* pSourceDoc, const ScMarkData* pMarks )
538 if (bIsClip)
540 InitClipPtrs(pSourceDoc);
542 for (SCTAB i = 0; i < static_cast<SCTAB>(pSourceDoc->maTabs.size()); i++)
543 if (pSourceDoc->maTabs[i])
544 if (!pMarks || pMarks->GetTableSelect(i))
546 OUString aString;
547 pSourceDoc->maTabs[i]->GetName(aString);
548 if ( i < static_cast<SCTAB>(maTabs.size()) )
550 maTabs[i] = new ScTable(this, i, aString);
553 else
555 if( i > static_cast<SCTAB>(maTabs.size()) )
557 maTabs.resize(i, NULL );
559 maTabs.push_back(new ScTable(this, i, aString));
561 maTabs[i]->SetLayoutRTL( pSourceDoc->maTabs[i]->IsLayoutRTL() );
564 else
566 OSL_FAIL("ResetClip");
570 void ScDocument::ResetClip( ScDocument* pSourceDoc, SCTAB nTab )
572 if (bIsClip)
574 InitClipPtrs(pSourceDoc);
575 if (nTab >= static_cast<SCTAB>(maTabs.size()))
577 maTabs.resize(nTab+1, NULL );
579 maTabs[nTab] = new ScTable(this, nTab,
580 OUString("baeh"));
581 if (nTab < static_cast<SCTAB>(pSourceDoc->maTabs.size()) && pSourceDoc->maTabs[nTab])
582 maTabs[nTab]->SetLayoutRTL( pSourceDoc->maTabs[nTab]->IsLayoutRTL() );
584 else
586 OSL_FAIL("ResetClip");
590 void ScDocument::EnsureTable( SCTAB nTab )
592 bool bExtras = !bIsUndo; // Column-Widths, Row-Heights, Flags
593 if (static_cast<size_t>(nTab) >= maTabs.size())
594 maTabs.resize(nTab+1, NULL);
596 if (!maTabs[nTab])
597 maTabs[nTab] = new ScTable(this, nTab, "temp", bExtras, bExtras);
600 ScRefCellValue ScDocument::GetRefCellValue( const ScAddress& rPos )
602 if (!TableExists(rPos.Tab()))
603 return ScRefCellValue(); // empty
605 return maTabs[rPos.Tab()]->GetRefCellValue(rPos.Col(), rPos.Row());
608 svl::SharedStringPool& ScDocument::GetSharedStringPool()
610 return *mpCellStringPool;
613 const svl::SharedStringPool& ScDocument::GetSharedStringPool() const
615 return *mpCellStringPool;
618 bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
619 bool bNotes ) const
621 if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
623 bool bAny = maTabs[nTab]->GetPrintArea( rEndCol, rEndRow, bNotes );
624 if (pDrawLayer)
626 ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
627 if (DrawGetPrintArea( aDrawRange, true, true ))
629 if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
630 if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
631 bAny = true;
634 return bAny;
637 rEndCol = 0;
638 rEndRow = 0;
639 return false;
642 bool ScDocument::GetPrintAreaHor( SCTAB nTab, SCROW nStartRow, SCROW nEndRow,
643 SCCOL& rEndCol, bool bNotes ) const
645 if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
647 bool bAny = maTabs[nTab]->GetPrintAreaHor( nStartRow, nEndRow, rEndCol, bNotes );
648 if (pDrawLayer)
650 ScRange aDrawRange(0,nStartRow,nTab, MAXCOL,nEndRow,nTab);
651 if (DrawGetPrintArea( aDrawRange, true, false ))
653 if (aDrawRange.aEnd.Col()>rEndCol) rEndCol=aDrawRange.aEnd.Col();
654 bAny = true;
657 return bAny;
660 rEndCol = 0;
661 return false;
664 bool ScDocument::GetPrintAreaVer( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol,
665 SCROW& rEndRow, bool bNotes ) const
667 if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
669 bool bAny = maTabs[nTab]->GetPrintAreaVer( nStartCol, nEndCol, rEndRow, bNotes );
670 if (pDrawLayer)
672 ScRange aDrawRange(nStartCol,0,nTab, nEndCol,MAXROW,nTab);
673 if (DrawGetPrintArea( aDrawRange, false, true ))
675 if (aDrawRange.aEnd.Row()>rEndRow) rEndRow=aDrawRange.aEnd.Row();
676 bAny = true;
679 return bAny;
682 rEndRow = 0;
683 return false;
686 bool ScDocument::GetDataStart( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow ) const
688 if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
690 bool bAny = maTabs[nTab]->GetDataStart( rStartCol, rStartRow );
691 if (pDrawLayer)
693 ScRange aDrawRange(0,0,nTab, MAXCOL,MAXROW,nTab);
694 if (DrawGetPrintArea( aDrawRange, true, true ))
696 if (aDrawRange.aStart.Col()<rStartCol) rStartCol=aDrawRange.aStart.Col();
697 if (aDrawRange.aStart.Row()<rStartRow) rStartRow=aDrawRange.aStart.Row();
698 bAny = true;
701 return bAny;
704 rStartCol = 0;
705 rStartRow = 0;
706 return false;
709 bool ScDocument::GetTiledRenderingArea(SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow) const
711 if (!GetPrintArea(nTab, rEndCol, rEndRow, false))
712 return false;
714 // we need some reasonable minimal document size
715 if (rEndCol < 12)
716 rEndCol = 12;
718 if (rEndRow < 36)
719 rEndRow = 36;
721 return true;
724 bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
726 if (nOldPos == nNewPos)
727 return false;
729 SCTAB nTabCount = static_cast<SCTAB>(maTabs.size());
730 if(nTabCount < 2)
731 return false;
733 bool bValid = false;
734 if (ValidTab(nOldPos) && nOldPos < nTabCount )
736 if (maTabs[nOldPos])
738 sc::AutoCalcSwitch aACSwitch(*this, false);
740 SetNoListening( true );
741 if (nNewPos == SC_TAB_APPEND || nNewPos >= nTabCount)
742 nNewPos = nTabCount-1;
744 // Update Reference
745 // TODO: combine with UpdateReference!
747 sc::RefUpdateMoveTabContext aCxt( *this, nOldPos, nNewPos);
749 SCsTAB nDz = ((SCsTAB)nNewPos) - (SCsTAB)nOldPos;
750 ScRange aSourceRange( 0,0,nOldPos, MAXCOL,MAXROW,nOldPos );
751 if (pRangeName)
752 pRangeName->UpdateMoveTab(aCxt);
754 pDBCollection->UpdateMoveTab( nOldPos, nNewPos );
755 xColNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
756 xRowNameRanges->UpdateReference( URM_REORDER, this, aSourceRange, 0,0,nDz );
757 if (pDPCollection)
758 pDPCollection->UpdateReference( URM_REORDER, aSourceRange, 0,0,nDz );
759 if (pDetOpList)
760 pDetOpList->UpdateReference( this, URM_REORDER, aSourceRange, 0,0,nDz );
761 UpdateChartRef( URM_REORDER,
762 0,0,nOldPos, MAXCOL,MAXROW,nOldPos, 0,0,nDz );
763 UpdateRefAreaLinks( URM_REORDER, aSourceRange, 0,0,nDz );
764 if ( pValidationList )
765 pValidationList->UpdateMoveTab(aCxt);
766 if ( pUnoBroadcaster )
767 pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_REORDER,
768 aSourceRange, 0,0,nDz ) );
770 ScTable* pSaveTab = maTabs[nOldPos];
771 maTabs.erase(maTabs.begin()+nOldPos);
772 maTabs.insert(maTabs.begin()+nNewPos, pSaveTab);
773 TableContainer::iterator it = maTabs.begin();
774 for (SCTAB i = 0; i < nTabCount; i++)
775 if (maTabs[i])
776 maTabs[i]->UpdateMoveTab(aCxt, i, pProgress);
777 it = maTabs.begin();
778 for (; it != maTabs.end(); ++it)
779 if (*it)
780 (*it)->UpdateCompile();
781 SetNoListening( false );
782 StartAllListeners();
784 // sheet names of references may not be valid until sheet is moved
785 pChartListenerCollection->UpdateScheduledSeriesRanges();
787 sc::SetFormulaDirtyContext aFormulaDirtyCxt;
788 SetAllFormulasDirty(aFormulaDirtyCxt);
790 if (pDrawLayer)
791 DrawMovePage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
793 bValid = true;
796 return bValid;
799 bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyMarked )
801 if (SC_TAB_APPEND == nNewPos || nNewPos >= static_cast<SCTAB>(maTabs.size()))
802 nNewPos = static_cast<SCTAB>(maTabs.size());
803 OUString aName;
804 GetName(nOldPos, aName);
806 // check first if Prefix is valid; if not, then only avoid duplicates
807 bool bPrefix = ValidTabName( aName );
808 OSL_ENSURE(bPrefix, "invalid table name");
809 SCTAB nDummy;
811 CreateValidTabName(aName);
813 bool bValid;
814 if (bPrefix)
815 bValid = ValidNewTabName(aName);
816 else
817 bValid = !GetTable( aName, nDummy );
819 sc::AutoCalcSwitch aACSwitch(*this, false);
820 sc::RefUpdateInsertTabContext aCxt( *this, nNewPos, 1);
821 sc::StartListeningContext aSLCxt(*this);
823 if (bValid)
825 if (nNewPos >= static_cast<SCTAB>(maTabs.size()))
827 nNewPos = static_cast<SCTAB>(maTabs.size());
828 maTabs.push_back(new ScTable(this, nNewPos, aName));
830 else
832 if (ValidTab(nNewPos) && (nNewPos < static_cast<SCTAB>(maTabs.size())))
834 SetNoListening( true );
836 ScRange aRange( 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB );
837 xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
838 xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,1 );
839 if (pRangeName)
840 pRangeName->UpdateInsertTab(aCxt);
842 pDBCollection->UpdateReference(
843 URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
844 if (pDPCollection)
845 pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,1 );
846 if (pDetOpList)
847 pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,1 );
848 UpdateChartRef( URM_INSDEL, 0,0,nNewPos, MAXCOL,MAXROW,MAXTAB, 0,0,1 );
849 UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,1 );
850 if ( pUnoBroadcaster )
851 pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,1 ) );
853 SCTAB i;
854 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
855 if (*it && it != (maTabs.begin() + nOldPos))
856 (*it)->UpdateInsertTab(aCxt);
857 maTabs.push_back(NULL);
858 for (i = static_cast<SCTAB>(maTabs.size())-1; i > nNewPos; i--)
859 maTabs[i] = maTabs[i - 1];
860 if (nNewPos <= nOldPos)
861 nOldPos++;
862 maTabs[nNewPos] = new ScTable(this, nNewPos, aName);
863 bValid = true;
864 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
865 if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin() + nNewPos)
866 (*it)->UpdateCompile();
867 SetNoListening( false );
868 for (TableContainer::iterator it = maTabs.begin(); it != maTabs.end(); ++it)
869 if (*it && it != maTabs.begin()+nOldPos && it != maTabs.begin()+nNewPos)
870 (*it)->StartListeners(aSLCxt, true);
872 if (pValidationList)
873 pValidationList->UpdateInsertTab(aCxt);
875 // sheet names of references may not be valid until sheet is copied
876 pChartListenerCollection->UpdateScheduledSeriesRanges();
878 else
879 bValid = false;
883 if (bValid)
885 SetNoListening( true ); // noch nicht bei CopyToTable/Insert
886 sc::CopyToDocContext aCopyDocCxt(*this);
887 maTabs[nOldPos]->CopyToTable(aCopyDocCxt, 0, 0, MAXCOL, MAXROW, IDF_ALL, (pOnlyMarked != NULL),
888 maTabs[nNewPos], pOnlyMarked );
889 maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
891 SCTAB nDz = nNewPos - nOldPos;
892 sc::RefUpdateContext aRefCxt(*this);
893 aRefCxt.meMode = URM_COPY;
894 aRefCxt.maRange = ScRange(0, 0, nNewPos, MAXCOL, MAXROW, nNewPos);
895 aRefCxt.mnTabDelta = nDz;
896 maTabs[nNewPos]->UpdateReference(aRefCxt, NULL);
898 maTabs[nNewPos]->UpdateInsertTabAbs(nNewPos); // move all paragraphs up by one!!
899 maTabs[nOldPos]->UpdateInsertTab(aCxt);
901 maTabs[nOldPos]->UpdateCompile();
902 maTabs[nNewPos]->UpdateCompile( true ); // maybe already compiled in Clone, but used names need recompilation
903 SetNoListening( false );
904 maTabs[nOldPos]->StartListeners(aSLCxt, true);
905 maTabs[nNewPos]->StartListeners(aSLCxt, true);
907 sc::SetFormulaDirtyContext aFormulaDirtyCxt;
908 SetAllFormulasDirty(aFormulaDirtyCxt);
910 if (pDrawLayer)
911 DrawCopyPage( static_cast<sal_uInt16>(nOldPos), static_cast<sal_uInt16>(nNewPos) );
913 if (pDPCollection)
914 pDPCollection->CopyToTab(nOldPos, nNewPos);
916 maTabs[nNewPos]->SetPageStyle( maTabs[nOldPos]->GetPageStyle() );
917 maTabs[nNewPos]->SetPendingRowHeights( maTabs[nOldPos]->IsPendingRowHeights() );
919 // Copy the custom print range if exists.
920 maTabs[nNewPos]->CopyPrintRange(*maTabs[nOldPos]);
922 // Copy the RTL settings
923 maTabs[nNewPos]->SetLayoutRTL(maTabs[nOldPos]->IsLayoutRTL());
924 maTabs[nNewPos]->SetLoadingRTL(maTabs[nOldPos]->IsLoadingRTL());
927 return bValid;
930 sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
931 SCTAB nDestPos, bool bInsertNew,
932 bool bResultsOnly )
934 sal_uLong nRetVal = 1; // 0 => error 1 = ok
935 // 3 => NameBox
936 // 4 => both
938 if (pSrcDoc->pShell->GetMedium())
940 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 if (pSrcDoc->maFileURL.isEmpty())
943 pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
945 else
947 pSrcDoc->maFileURL = pSrcDoc->pShell->GetName();
950 bool bValid = true;
951 if (bInsertNew) // re-insert
953 OUString aName;
954 pSrcDoc->GetName(nSrcPos, aName);
955 CreateValidTabName(aName);
956 bValid = InsertTab(nDestPos, aName);
958 // Copy the RTL settings
959 maTabs[nDestPos]->SetLayoutRTL(pSrcDoc->maTabs[nSrcPos]->IsLayoutRTL());
960 maTabs[nDestPos]->SetLoadingRTL(pSrcDoc->maTabs[nSrcPos]->IsLoadingRTL());
962 else // replace existing tables
964 if (ValidTab(nDestPos) && nDestPos < static_cast<SCTAB>(maTabs.size()) && maTabs[nDestPos])
966 maTabs[nDestPos]->DeleteArea( 0,0, MAXCOL,MAXROW, IDF_ALL );
968 else
969 bValid = false;
972 if (bValid)
974 bool bOldAutoCalcSrc = false;
975 bool bOldAutoCalc = GetAutoCalc();
976 SetAutoCalc( false ); // avoid repeated calculations
977 SetNoListening( true );
978 if ( bResultsOnly )
980 bOldAutoCalcSrc = pSrcDoc->GetAutoCalc();
981 pSrcDoc->SetAutoCalc( true ); // in case something needs calculation
985 NumFmtMergeHandler aNumFmtMergeHdl(this, pSrcDoc);
987 sc::CopyToDocContext aCxt(*this);
988 nDestPos = std::min(nDestPos, (SCTAB)(GetTableCount() - 1));
989 { // scope for bulk broadcast
990 ScBulkBroadcast aBulkBroadcast( pBASM);
991 pSrcDoc->maTabs[nSrcPos]->CopyToTable(aCxt, 0, 0, MAXCOL, MAXROW,
992 ( bResultsOnly ? IDF_ALL & ~IDF_FORMULA : IDF_ALL),
993 false, maTabs[nDestPos] );
996 maTabs[nDestPos]->SetTabNo(nDestPos);
997 maTabs[nDestPos]->SetTabBgColor(pSrcDoc->maTabs[nSrcPos]->GetTabBgColor());
999 if ( !bResultsOnly )
1001 sc::RefUpdateContext aRefCxt(*this);
1002 aRefCxt.meMode = URM_COPY;
1003 aRefCxt.maRange = ScRange(0, 0, nDestPos, MAXCOL, MAXROW, nDestPos);
1004 aRefCxt.mnTabDelta = nDestPos - nSrcPos;
1005 maTabs[nDestPos]->UpdateReference(aRefCxt, NULL);
1007 // Readjust self-contained absolute references to this sheet
1008 maTabs[nDestPos]->TestTabRefAbs(nSrcPos);
1009 sc::CompileFormulaContext aFormulaCxt(this);
1010 maTabs[nDestPos]->CompileAll(aFormulaCxt);
1013 SetNoListening( false );
1014 if ( !bResultsOnly )
1016 sc::StartListeningContext aSLCxt(*this);
1017 maTabs[nDestPos]->StartListeners(aSLCxt, true);
1019 SetDirty( ScRange( 0, 0, nDestPos, MAXCOL, MAXROW, nDestPos), false);
1021 if ( bResultsOnly )
1022 pSrcDoc->SetAutoCalc( bOldAutoCalcSrc );
1023 SetAutoCalc( bOldAutoCalc );
1025 // copy Drawing
1027 if (bInsertNew)
1028 TransferDrawPage( pSrcDoc, nSrcPos, nDestPos );
1030 maTabs[nDestPos]->SetPendingRowHeights( pSrcDoc->maTabs[nSrcPos]->IsPendingRowHeights() );
1032 if (!bValid)
1033 nRetVal = 0;
1034 bool bVbaEnabled = IsInVBAMode();
1036 if ( bVbaEnabled )
1038 SfxObjectShell* pSrcShell = pSrcDoc->GetDocumentShell();
1039 if ( pSrcShell )
1041 OUString aLibName("Standard");
1042 const BasicManager *pBasicManager = pSrcShell->GetBasicManager();
1043 if (pBasicManager && !pBasicManager->GetName().isEmpty())
1045 aLibName = pSrcShell->GetBasicManager()->GetName();
1047 OUString sCodeName;
1048 OUString sSource;
1049 uno::Reference< script::XLibraryContainer > xLibContainer = pSrcShell->GetBasicContainer();
1050 uno::Reference< container::XNameContainer > xLib;
1051 if( xLibContainer.is() )
1053 uno::Any aLibAny = xLibContainer->getByName(aLibName);
1054 aLibAny >>= xLib;
1057 if( xLib.is() )
1059 OUString sSrcCodeName;
1060 pSrcDoc->GetCodeName( nSrcPos, sSrcCodeName );
1061 OUString sRTLSource;
1062 xLib->getByName( sSrcCodeName ) >>= sRTLSource;
1063 sSource = sRTLSource;
1065 VBA_InsertModule( *this, nDestPos, sCodeName, sSource );
1069 return nRetVal;
1072 void ScDocument::SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const sal_uInt16 nError)
1074 if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()))
1075 if (maTabs[nTab])
1076 maTabs[nTab]->SetError( nCol, nRow, nError );
1079 void ScDocument::SetFormula(
1080 const ScAddress& rPos, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
1082 if (!TableExists(rPos.Tab()))
1083 return;
1085 maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rArray, eGram);
1088 void ScDocument::SetFormula(
1089 const ScAddress& rPos, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
1091 if (!TableExists(rPos.Tab()))
1092 return;
1094 maTabs[rPos.Tab()]->SetFormula(rPos.Col(), rPos.Row(), rFormula, eGram);
1097 ScFormulaCell* ScDocument::SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell )
1099 if (!TableExists(rPos.Tab()))
1101 delete pCell;
1102 return NULL;
1105 return maTabs[rPos.Tab()]->SetFormulaCell(rPos.Col(), rPos.Row(), pCell);
1108 bool ScDocument::SetFormulaCells( const ScAddress& rPos, std::vector<ScFormulaCell*>& rCells )
1110 if (rCells.empty())
1111 return false;
1113 ScTable* pTab = FetchTable(rPos.Tab());
1114 if (!pTab)
1115 return false;
1117 return pTab->SetFormulaCells(rPos.Col(), rPos.Row(), rCells);
1120 void ScDocument::SetConsolidateDlgData( const ScConsolidateParam* pData )
1122 delete pConsolidateDlgData;
1124 if ( pData )
1125 pConsolidateDlgData = new ScConsolidateParam( *pData );
1126 else
1127 pConsolidateDlgData = NULL;
1130 void ScDocument::SetChangeViewSettings(const ScChangeViewSettings& rNew)
1132 if (pChangeViewSettings==NULL)
1133 pChangeViewSettings = new ScChangeViewSettings;
1135 OSL_ENSURE( pChangeViewSettings, "Oops. No ChangeViewSettings :-( by!" );
1137 *pChangeViewSettings=rNew;
1140 ScFieldEditEngine* ScDocument::CreateFieldEditEngine()
1142 ScFieldEditEngine* pNewEditEngine = NULL;
1143 if (!pCacheFieldEditEngine)
1145 pNewEditEngine = new ScFieldEditEngine(
1146 this, GetEnginePool(), GetEditPool(), false);
1148 else
1150 if ( !bImportingXML )
1152 // #i66209# previous use might not have restored update mode,
1153 // ensure same state as for a new EditEngine (UpdateMode = true)
1154 if ( !pCacheFieldEditEngine->GetUpdateMode() )
1155 pCacheFieldEditEngine->SetUpdateMode(true);
1158 pNewEditEngine = pCacheFieldEditEngine;
1159 pCacheFieldEditEngine = NULL;
1161 return pNewEditEngine;
1164 void ScDocument::DisposeFieldEditEngine(ScFieldEditEngine*& rpEditEngine)
1166 if (!pCacheFieldEditEngine && rpEditEngine)
1168 pCacheFieldEditEngine = rpEditEngine;
1169 pCacheFieldEditEngine->Clear();
1171 else
1172 delete rpEditEngine;
1173 rpEditEngine = NULL;
1176 ScRecursionHelper* ScDocument::CreateRecursionHelperInstance()
1178 return new ScRecursionHelper;
1181 ScLookupCache & ScDocument::GetLookupCache( const ScRange & rRange )
1183 ScLookupCache* pCache = 0;
1184 if (!pLookupCacheMapImpl)
1185 pLookupCacheMapImpl = new ScLookupCacheMapImpl;
1186 ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find( rRange));
1187 if (it == pLookupCacheMapImpl->aCacheMap.end())
1189 pCache = new ScLookupCache( this, rRange);
1190 AddLookupCache( *pCache);
1192 else
1193 pCache = (*it).second;
1194 return *pCache;
1197 void ScDocument::AddLookupCache( ScLookupCache & rCache )
1199 if (!pLookupCacheMapImpl->aCacheMap.insert( ::std::pair< const ScRange,
1200 ScLookupCache*>( rCache.getRange(), &rCache)).second)
1202 OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map");
1204 else
1205 StartListeningArea( rCache.getRange(), false, &rCache);
1208 void ScDocument::RemoveLookupCache( ScLookupCache & rCache )
1210 ScLookupCacheMap::iterator it( pLookupCacheMapImpl->aCacheMap.find(
1211 rCache.getRange()));
1212 if (it == pLookupCacheMapImpl->aCacheMap.end())
1214 OSL_FAIL( "ScDocument::RemoveLookupCache: range not found in hash map");
1216 else
1218 ScLookupCache* pCache = (*it).second;
1219 pLookupCacheMapImpl->aCacheMap.erase( it);
1220 EndListeningArea( pCache->getRange(), false, &rCache);
1224 void ScDocument::ClearLookupCaches()
1226 if( pLookupCacheMapImpl )
1227 pLookupCacheMapImpl->clear();
1230 bool ScDocument::IsCellInChangeTrack(const ScAddress &cell,Color *pColCellBoder)
1232 ScChangeTrack* pTrack = GetChangeTrack();
1233 ScChangeViewSettings* pSettings = GetChangeViewSettings();
1234 if ( !pTrack || !pTrack->GetFirst() || !pSettings || !pSettings->ShowChanges() )
1235 return false; // missing or turned-off
1236 ScActionColorChanger aColorChanger(*pTrack);
1237 // Clipping happens from outside
1238 //! TODO: without Clipping; only paint affected cells ??!??!?
1239 const ScChangeAction* pAction = pTrack->GetFirst();
1240 while (pAction)
1242 ScChangeActionType eType;
1243 if ( pAction->IsVisible() )
1245 eType = pAction->GetType();
1246 const ScBigRange& rBig = pAction->GetBigRange();
1247 if ( rBig.aStart.Tab() == cell.Tab())
1249 ScRange aRange = rBig.MakeRange();
1250 if ( eType == SC_CAT_DELETE_ROWS )
1251 aRange.aEnd.SetRow( aRange.aStart.Row() );
1252 else if ( eType == SC_CAT_DELETE_COLS )
1253 aRange.aEnd.SetCol( aRange.aStart.Col() );
1254 if (ScViewUtil::IsActionShown( *pAction, *pSettings, *this ) )
1256 if (aRange.In(cell))
1258 if (pColCellBoder != NULL)
1260 aColorChanger.Update( *pAction );
1261 Color aColor( aColorChanger.GetColor() );
1262 *pColCellBoder = aColor;
1264 return true;
1268 if ( eType == SC_CAT_MOVE &&
1269 static_cast<const ScChangeActionMove*>(pAction)->
1270 GetFromRange().aStart.Tab() == cell.Col() )
1272 ScRange aRange = static_cast<const ScChangeActionMove*>(pAction)->
1273 GetFromRange().MakeRange();
1274 if (ScViewUtil::IsActionShown( *pAction, *pSettings, *this ) )
1276 if (aRange.In(cell))
1278 if (pColCellBoder != NULL)
1280 aColorChanger.Update( *pAction );
1281 Color aColor( aColorChanger.GetColor() );
1282 *pColCellBoder = aColor;
1284 return true;
1289 pAction = pAction->GetNext();
1291 return false;
1294 void ScDocument::GetCellChangeTrackNote( const ScAddress &aCellPos, OUString &aTrackText,bool &bLeftEdge)
1296 aTrackText.clear();
1297 // Change-Tracking
1298 ScChangeTrack* pTrack = GetChangeTrack();
1299 ScChangeViewSettings* pSettings = GetChangeViewSettings();
1300 if ( pTrack && pTrack->GetFirst() && pSettings && pSettings->ShowChanges())
1302 const ScChangeAction* pFound = NULL;
1303 const ScChangeAction* pFoundContent = NULL;
1304 const ScChangeAction* pFoundMove = NULL;
1305 long nModified = 0;
1306 const ScChangeAction* pAction = pTrack->GetFirst();
1307 while (pAction)
1309 if ( pAction->IsVisible() &&
1310 ScViewUtil::IsActionShown( *pAction, *pSettings, *this ) )
1312 ScChangeActionType eType = pAction->GetType();
1313 const ScBigRange& rBig = pAction->GetBigRange();
1314 if ( rBig.aStart.Tab() == aCellPos.Tab())
1316 ScRange aRange = rBig.MakeRange();
1317 if ( eType == SC_CAT_DELETE_ROWS )
1318 aRange.aEnd.SetRow( aRange.aStart.Row() );
1319 else if ( eType == SC_CAT_DELETE_COLS )
1320 aRange.aEnd.SetCol( aRange.aStart.Col() );
1321 if ( aRange.In( aCellPos ) )
1323 pFound = pAction; // the last wins
1324 switch ( eType )
1326 case SC_CAT_CONTENT :
1327 pFoundContent = pAction;
1328 break;
1329 case SC_CAT_MOVE :
1330 pFoundMove = pAction;
1331 break;
1332 default:
1333 break;
1335 ++nModified;
1338 if ( eType == SC_CAT_MOVE )
1340 ScRange aRange =
1341 static_cast<const ScChangeActionMove*>(pAction)->
1342 GetFromRange().MakeRange();
1343 if ( aRange.In( aCellPos ) )
1345 pFound = pAction;
1346 ++nModified;
1350 pAction = pAction->GetNext();
1352 if ( pFound )
1354 if ( pFoundContent && pFound->GetType() != SC_CAT_CONTENT )
1355 pFound = pFoundContent; // Content wins
1356 if ( pFoundMove && pFound->GetType() != SC_CAT_MOVE &&
1357 pFoundMove->GetActionNumber() >
1358 pFound->GetActionNumber() )
1359 pFound = pFoundMove; // Move wins
1360 // for deleted columns: arrow on left side of row
1361 if ( pFound->GetType() == SC_CAT_DELETE_COLS )
1362 bLeftEdge = true;
1363 DateTime aDT = pFound->GetDateTime();
1364 aTrackText = pFound->GetUser();
1365 aTrackText += ", ";
1366 aTrackText += ScGlobal::pLocaleData->getDate(aDT);
1367 aTrackText += " ";
1368 aTrackText += ScGlobal::pLocaleData->getTime(aDT);
1369 aTrackText += ":\n";
1370 OUString aComStr = pFound->GetComment();
1371 if(!aComStr.isEmpty())
1373 aTrackText += aComStr;
1374 aTrackText += "\n( ";
1376 pFound->GetDescription( aTrackText, this );
1377 if (!aComStr.isEmpty())
1379 aTrackText += ")";
1385 void ScDocument::SetPreviewFont( SfxItemSet* pFont )
1387 delete pPreviewFont;
1388 pPreviewFont = pFont;
1391 void ScDocument::SetPreviewSelection( ScMarkData& rSel )
1393 maPreviewSelection = rSel;
1396 SfxItemSet* ScDocument::GetPreviewFont( SCCOL nCol, SCROW nRow, SCTAB nTab )
1398 SfxItemSet* pRet = NULL;
1399 if ( pPreviewFont )
1401 ScMarkData aSel = GetPreviewSelection();
1402 if ( aSel.IsCellMarked( nCol, nRow ) && aSel.GetFirstSelected() == nTab )
1403 pRet = pPreviewFont;
1405 return pRet;
1408 ScStyleSheet* ScDocument::GetPreviewCellStyle( SCCOL nCol, SCROW nRow, SCTAB nTab )
1410 ScStyleSheet* pRet = NULL;
1411 ScMarkData aSel = GetPreviewSelection();
1412 if ( pPreviewCellStyle && aSel.IsCellMarked( nCol, nRow ) && aSel.GetFirstSelected() == nTab )
1413 pRet = pPreviewCellStyle;
1414 return pRet;
1416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */