1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
41 #include <basic/basmgr.hxx>
43 #include "document.hxx"
46 #include "patattr.hxx"
47 #include "rangenam.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"
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"
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"
88 #include "formulacell.hxx"
89 #include "clipcontext.hxx"
91 using namespace com::sun::star
;
93 // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
94 // dtor plus helpers are convenient.
95 struct ScLookupCacheMapImpl
97 ScLookupCacheMap aCacheMap
;
98 ~ScLookupCacheMapImpl()
106 ScLookupCacheMap aTmp
;
107 aCacheMap
.swap( aTmp
);
112 for (ScLookupCacheMap::iterator
it( aCacheMap
.begin()); it
!= aCacheMap
.end(); ++it
)
117 // STATIC DATA -----------------------------------------------------------
119 ScDocument::ScDocument( ScDocumentMode eMode
,
120 SfxObjectShell
* pDocShell
) :
121 xServiceManager( ::comphelper::getProcessServiceFactory() ),
122 mpUndoManager( NULL
),
127 pVirtualDevice_100th_mm( NULL
),
129 pValidationList( NULL
),
130 pFormatExchangeList( NULL
),
132 pDPCollection( NULL
),
133 pLinkManager( NULL
),
134 pFormulaTree( NULL
),
135 pEOFormulaTree( NULL
),
136 pFormulaTrack( NULL
),
137 pEOFormulaTrack( NULL
),
140 pChangeTrack( NULL
),
141 pUnoBroadcaster( NULL
),
142 pUnoListenerCalls( NULL
),
143 pUnoRefUndoList( NULL
),
144 pChangeViewSettings( NULL
),
145 pScriptTypeData( NULL
),
146 pCacheFieldEditEngine( NULL
),
147 pDocProtection( NULL
),
149 pExternalRefMgr( NULL
),
151 pViewOptions( NULL
),
153 pExtDocOptions( NULL
),
154 pConsolidateDlgData( NULL
),
155 pRecursionHelper( NULL
),
156 pAutoNameCache( NULL
),
157 pLookupCacheMapImpl( NULL
),
158 pPreviewFont( NULL
),
159 pPreviewSelection( NULL
),
161 nRangeOverflowType( 0 ),
162 aCurTextWidthCalcPos(MAXCOL
,0,0),
164 nFormulaCodeInTree(0),
165 nXMLImportedFormulaCount( 0 ),
167 nMacroInterpretLevel(0),
168 nInterpreterTableOpLevel(0),
169 nSrcVer( SC_CURRENT_VERSION
),
170 nSrcMaxRow( MAXROW
),
171 nFormulaTrackCount(0),
172 bHardRecalcState(false),
174 eLinkMode(LM_UNKNOWN
),
175 bAutoCalc( eMode
== SCDOCMODE_DOCUMENT
),
176 bAutoCalcShellDisabled( false ),
177 bForcedFormulaPending( false ),
178 bCalculatingFormulaTree( false ),
179 bIsClip( eMode
== SCDOCMODE_CLIP
),
180 bIsUndo( eMode
== SCDOCMODE_UNDO
),
182 bIsEmbedded( false ),
183 bInsertingFromOtherDoc( false ),
184 bLoadingMedium( false ),
185 bImportingXML( false ),
186 bXMLFromWrapper( false ),
187 bCalcingAfterLoad( false ),
188 bNoListening( false ),
190 bInLinkUpdate( false ),
191 bChartListenerCollectionNeedsUpdate( false ),
192 bHasForcedFormulas( false ),
193 bInDtorClear( false ),
194 bExpandRefs( false ),
195 bDetectiveDirty( false ),
196 nMacroCallMode( SC_MACROCALL_ALLOWED
),
197 bHasMacroFunc( false ),
199 nAsianCompression(SC_ASIANCOMPRESSION_INVALID
),
200 nAsianKerning(SC_ASIANKERNING_INVALID
),
201 bSetDrawDefaults( false ),
202 bPastingDrawFromOtherDoc( false ),
203 nInDdeLinkUpdate( 0 ),
204 bInUnoBroadcast( false ),
205 bInUnoListenerCall( false ),
206 eGrammar( formula::FormulaGrammar::GRAM_NATIVE
),
207 bStyleSheetUsageInvalid( true ),
208 mbUndoEnabled( true ),
209 mbAdjustHeightEnabled( true ),
210 mbExecuteLinkEnabled( true ),
211 mbChangeReadOnlyEnabled( false ),
212 mbStreamValidLocked( false ),
213 mbUserInteractionEnabled(true),
214 mnNamedRangesLockCount(0),
215 mbUseEmbedFonts(false)
217 SetStorageGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT
);
219 eSrcSet
= osl_getThreadTextEncoding();
221 if ( eMode
== SCDOCMODE_DOCUMENT
)
224 pLinkManager
= new sfx2::LinkManager( pDocShell
);
226 xPoolHelper
= new ScPoolHelper( this );
228 pBASM
= new ScBroadcastAreaSlotMachine( this );
229 pChartListenerCollection
= new ScChartListenerCollection( this );
230 pRefreshTimerControl
= new ScRefreshTimerControl
;
235 pChartListenerCollection
= NULL
;
236 pRefreshTimerControl
= NULL
;
238 pDBCollection
= new ScDBCollection(this);
239 pSelectionAttr
= NULL
;
240 pChartCollection
= new ScChartCollection
;
241 apTemporaryChartLock
= std::auto_ptr
< ScTemporaryChartLock
>( new ScTemporaryChartLock(this) );
242 xColNameRanges
= new ScRangePairList
;
243 xRowNameRanges
= new ScRangePairList
;
245 // languages for a visible document are set by docshell later (from options)
246 SetLanguage( ScGlobal::eLnge
, ScGlobal::eLnge
, ScGlobal::eLnge
);
248 aTrackTimer
.SetTimeoutHdl( LINK( this, ScDocument
, TrackTimeHdl
) );
249 aTrackTimer
.SetTimeout( 100 );
252 sfx2::LinkManager
* ScDocument::GetLinkManager() const
254 if ( bAutoCalc
&& !pLinkManager
&& pShell
)
256 pLinkManager
= new sfx2::LinkManager( pShell
);
262 void ScDocument::SetStorageGrammar( formula::FormulaGrammar::Grammar eGram
)
265 eGram
== formula::FormulaGrammar::GRAM_ODFF
||
266 eGram
== formula::FormulaGrammar::GRAM_PODF
,
267 "ScDocument::SetStorageGrammar: wrong storage grammar");
269 eStorageGrammar
= eGram
;
271 // FIXME: the XML import shouldn't strip brackets, the compiler should
272 // digest them instead, which could also speedup reference recognition
275 eXmlImportGrammar
= formula::FormulaGrammar::mergeToGrammar( eGram
,
276 formula::FormulaGrammar::CONV_OOO
);
280 void ScDocument::SetDocVisible( bool bSet
)
282 // called from view ctor - only for a visible document,
283 // each new sheet's RTL flag is initialized from the locale
288 sal_uInt32
ScDocument::GetDocumentID() const
290 const ScDocument
* pThis
= this;
291 sal_uInt32 nCrc
= rtl_crc32( 0, &pThis
, sizeof(ScDocument
*) );
292 // the this pointer only might not be sufficient
293 nCrc
= rtl_crc32( nCrc
, &pShell
, sizeof(SfxObjectShell
*) );
298 void ScDocument::StartChangeTracking()
301 pChangeTrack
= new ScChangeTrack( this );
304 void ScDocument::EndChangeTracking()
310 void ScDocument::SetChangeTrack( ScChangeTrack
* pTrack
)
312 OSL_ENSURE( pTrack
->GetDocument() == this, "SetChangeTrack: different documents" );
313 if ( !pTrack
|| pTrack
== pChangeTrack
|| pTrack
->GetDocument() != this )
316 pChangeTrack
= pTrack
;
320 IMPL_LINK_NOARG(ScDocument
, TrackTimeHdl
)
322 if ( ScDdeLink::IsInUpdate() ) // nicht verschachteln
324 aTrackTimer
.Start(); // spaeter nochmal versuchen
326 else if (pShell
) // ausfuehren
329 pShell
->Broadcast( SfxSimpleHint( FID_DATACHANGED
) );
333 if (!pShell
->IsModified())
335 pShell
->SetModified( true );
336 SfxBindings
* pBindings
= GetViewBindings();
339 pBindings
->Invalidate( SID_SAVEDOC
);
340 pBindings
->Invalidate( SID_DOC_MODIFIED
);
348 void ScDocument::StartTrackTimer()
350 if (!aTrackTimer
.IsActive()) // nicht ewig aufschieben
354 ScDocument::~ScDocument()
356 OSL_PRECOND( !bInLinkUpdate
, "bInLinkUpdate in dtor" );
360 // first of all disable all refresh timers by deleting the control
361 if ( pRefreshTimerControl
)
362 { // To be sure there isn't anything running do it with a protector,
363 // this ensures also that nothing needs the control anymore.
364 ScRefreshTimerProtector
aProt( GetRefreshTimerControlAddress() );
365 delete pRefreshTimerControl
, pRefreshTimerControl
= NULL
;
370 if ( GetLinkManager() )
372 // BaseLinks freigeben
373 ::sfx2::SvLinkSources
aTemp(pLinkManager
->GetServers());
374 for( ::sfx2::SvLinkSources::const_iterator it
= aTemp
.begin(); it
!= aTemp
.end(); ++it
)
377 if ( pLinkManager
->GetLinks().size() )
378 pLinkManager
->Remove( 0, pLinkManager
->GetLinks().size() );
381 mxFormulaParserPool
.reset();
382 // Destroy the external ref mgr instance here because it has a timer
383 // which needs to be stopped before the app closes.
384 pExternalRefMgr
.reset();
386 ScAddInAsync::RemoveDocument( this );
387 ScAddInListener::RemoveDocument( this );
388 DELETEZ( pChartListenerCollection
); // vor pBASM wg. evtl. Listener!
389 DELETEZ( pLookupCacheMapImpl
); // before pBASM because of listeners
390 // BroadcastAreas vor allen Zellen zerstoeren um unnoetige
391 // Einzel-EndListenings der Formelzellen zu vermeiden
392 delete pBASM
; // BroadcastAreaSlotMachine
395 delete pUnoBroadcaster
; // broadcasted nochmal SFX_HINT_DYING
396 pUnoBroadcaster
= NULL
;
398 delete pUnoRefUndoList
;
399 delete pUnoListenerCalls
;
401 Clear( true ); // true = from destructor (needed for SdrModel::ClearModel)
405 for( ScValidationDataList::iterator it
= pValidationList
->begin(); it
!= pValidationList
->end(); ++it
)
407 pValidationList
->clear();
408 DELETEZ(pValidationList
);
411 delete pDBCollection
;
412 delete pSelectionAttr
;
413 apTemporaryChartLock
.reset();
414 delete pChartCollection
;
416 delete pFormatExchangeList
;
419 delete pConsolidateDlgData
;
422 delete pDetOpList
; // loescht auch die Eintraege
426 delete pChangeViewSettings
; // und weg damit
427 delete pVirtualDevice_100th_mm
;
429 delete pDPCollection
;
431 // delete the EditEngine before destroying the xPoolHelper
432 delete pCacheFieldEditEngine
;
434 if ( xPoolHelper
.is() && !bIsClip
)
435 xPoolHelper
->SourceDocumentGone();
438 delete pScriptTypeData
;
439 delete pRecursionHelper
;
441 OSL_POSTCOND( !pAutoNameCache
, "AutoNameCache still set in dtor" );
444 void ScDocument::InitClipPtrs( ScDocument
* pSourceDoc
)
446 OSL_ENSURE(bIsClip
, "InitClipPtrs and not bIsClip");
450 for(ScValidationDataList::iterator it
= pValidationList
->begin(); it
!= pValidationList
->end(); ++it
)
452 pValidationList
->clear();
453 DELETEZ(pValidationList
);
458 xPoolHelper
= pSourceDoc
->xPoolHelper
;
460 // bedingte Formate / Gueltigkeiten
461 //! Vorlagen kopieren?
462 const ScValidationDataList
* pSourceValid
= pSourceDoc
->pValidationList
;
464 pValidationList
= new ScValidationDataList(this, *pSourceValid
);
466 // Links in Stream speichern
468 if (pSourceDoc
->HasDdeLinks())
470 pClipData
= new SvMemoryStream
;
471 pSourceDoc
->SaveDdeLinks(*pClipData
);
476 // Options pointers exist (ImplCreateOptions) for any document.
477 // Must be copied for correct results in OLE objects (#i42666#).
478 SetDocOptions( pSourceDoc
->GetDocOptions() );
479 SetViewOptions( pSourceDoc
->GetViewOptions() );
482 SvNumberFormatter
* ScDocument::GetFormatTable() const
484 return xPoolHelper
->GetFormTable();
487 SfxItemPool
* ScDocument::GetEditPool() const
489 return xPoolHelper
->GetEditPool();
492 SfxItemPool
* ScDocument::GetEnginePool() const
494 return xPoolHelper
->GetEnginePool();
497 ScFieldEditEngine
& ScDocument::GetEditEngine()
501 pEditEngine
= new ScFieldEditEngine(this, GetEnginePool(), GetEditPool());
502 pEditEngine
->SetUpdateMode( false );
503 pEditEngine
->EnableUndo( false );
504 pEditEngine
->SetRefMapMode( MAP_100TH_MM
);
505 ApplyAsianEditSettings( *pEditEngine
);
510 ScNoteEditEngine
& ScDocument::GetNoteEngine()
514 pNoteEngine
= new ScNoteEditEngine( GetEnginePool(), GetEditPool() );
515 pNoteEngine
->SetUpdateMode( false );
516 pNoteEngine
->EnableUndo( false );
517 pNoteEngine
->SetRefMapMode( MAP_100TH_MM
);
518 ApplyAsianEditSettings( *pNoteEngine
);
519 const SfxItemSet
& rItemSet
= GetDefPattern()->GetItemSet();
520 SfxItemSet
* pEEItemSet
= new SfxItemSet( pNoteEngine
->GetEmptyItemSet() );
521 ScPatternAttr::FillToEditItemSet( *pEEItemSet
, rItemSet
);
522 pNoteEngine
->SetDefaults( pEEItemSet
); // edit engine takes ownership
528 void ScDocument::ResetClip( ScDocument
* pSourceDoc
, const ScMarkData
* pMarks
)
532 InitClipPtrs(pSourceDoc
);
534 for (SCTAB i
= 0; i
< static_cast<SCTAB
>(pSourceDoc
->maTabs
.size()); i
++)
535 if (pSourceDoc
->maTabs
[i
])
536 if (!pMarks
|| pMarks
->GetTableSelect(i
))
539 pSourceDoc
->maTabs
[i
]->GetName(aString
);
540 if ( i
< static_cast<SCTAB
>(maTabs
.size()) )
542 maTabs
[i
] = new ScTable(this, i
, aString
);
547 if( i
> static_cast<SCTAB
>(maTabs
.size()) )
549 maTabs
.resize(i
, NULL
);
551 maTabs
.push_back(new ScTable(this, i
, aString
));
553 maTabs
[i
]->SetLayoutRTL( pSourceDoc
->maTabs
[i
]->IsLayoutRTL() );
558 OSL_FAIL("ResetClip");
562 void ScDocument::ResetClip( ScDocument
* pSourceDoc
, SCTAB nTab
)
566 InitClipPtrs(pSourceDoc
);
567 if (nTab
>= static_cast<SCTAB
>(maTabs
.size()))
569 maTabs
.resize(nTab
+1, NULL
);
571 maTabs
[nTab
] = new ScTable(this, nTab
,
573 if (nTab
< static_cast<SCTAB
>(pSourceDoc
->maTabs
.size()) && pSourceDoc
->maTabs
[nTab
])
574 maTabs
[nTab
]->SetLayoutRTL( pSourceDoc
->maTabs
[nTab
]->IsLayoutRTL() );
578 OSL_FAIL("ResetClip");
582 void ScDocument::EnsureTable( SCTAB nTab
)
584 bool bExtras
= !bIsUndo
; // Spaltenbreiten, Zeilenhoehen, Flags
585 if (static_cast<size_t>(nTab
) >= maTabs
.size())
586 maTabs
.resize(nTab
+1, NULL
);
589 maTabs
[nTab
] = new ScTable(this, nTab
, "temp", bExtras
, bExtras
);
592 void ScDocument::PutCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
,
593 ScBaseCell
* pCell
, sal_uLong nFormatIndex
, bool bForceTab
)
600 if ( nTab
< static_cast<SCTAB
>(maTabs
.size()) && maTabs
[nTab
] )
601 maTabs
[nTab
]->PutCell( nCol
, nRow
, nFormatIndex
, pCell
);
605 ScRefCellValue
ScDocument::GetRefCellValue( const ScAddress
& rPos
)
607 if (!TableExists(rPos
.Tab()))
608 return ScRefCellValue(); // empty
610 return maTabs
[rPos
.Tab()]->GetRefCellValue(rPos
.Col(), rPos
.Row());
613 bool ScDocument::GetPrintArea( SCTAB nTab
, SCCOL
& rEndCol
, SCROW
& rEndRow
,
616 if (ValidTab(nTab
) && nTab
< static_cast<SCTAB
>(maTabs
.size()) && maTabs
[nTab
])
618 bool bAny
= maTabs
[nTab
]->GetPrintArea( rEndCol
, rEndRow
, bNotes
);
621 ScRange
aDrawRange(0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
622 if (DrawGetPrintArea( aDrawRange
, true, true ))
624 if (aDrawRange
.aEnd
.Col()>rEndCol
) rEndCol
=aDrawRange
.aEnd
.Col();
625 if (aDrawRange
.aEnd
.Row()>rEndRow
) rEndRow
=aDrawRange
.aEnd
.Row();
637 bool ScDocument::GetPrintAreaHor( SCTAB nTab
, SCROW nStartRow
, SCROW nEndRow
,
638 SCCOL
& rEndCol
, bool bNotes
) const
640 if (ValidTab(nTab
) && nTab
< static_cast<SCTAB
>(maTabs
.size()) && maTabs
[nTab
])
642 bool bAny
= maTabs
[nTab
]->GetPrintAreaHor( nStartRow
, nEndRow
, rEndCol
, bNotes
);
645 ScRange
aDrawRange(0,nStartRow
,nTab
, MAXCOL
,nEndRow
,nTab
);
646 if (DrawGetPrintArea( aDrawRange
, true, false ))
648 if (aDrawRange
.aEnd
.Col()>rEndCol
) rEndCol
=aDrawRange
.aEnd
.Col();
659 bool ScDocument::GetPrintAreaVer( SCTAB nTab
, SCCOL nStartCol
, SCCOL nEndCol
,
660 SCROW
& rEndRow
, bool bNotes
) const
662 if (ValidTab(nTab
) && nTab
< static_cast<SCTAB
>(maTabs
.size()) && maTabs
[nTab
])
664 bool bAny
= maTabs
[nTab
]->GetPrintAreaVer( nStartCol
, nEndCol
, rEndRow
, bNotes
);
667 ScRange
aDrawRange(nStartCol
,0,nTab
, nEndCol
,MAXROW
,nTab
);
668 if (DrawGetPrintArea( aDrawRange
, false, true ))
670 if (aDrawRange
.aEnd
.Row()>rEndRow
) rEndRow
=aDrawRange
.aEnd
.Row();
681 bool ScDocument::GetDataStart( SCTAB nTab
, SCCOL
& rStartCol
, SCROW
& rStartRow
) const
683 if (ValidTab(nTab
) && nTab
< static_cast<SCTAB
>(maTabs
.size()) && maTabs
[nTab
])
685 bool bAny
= maTabs
[nTab
]->GetDataStart( rStartCol
, rStartRow
);
688 ScRange
aDrawRange(0,0,nTab
, MAXCOL
,MAXROW
,nTab
);
689 if (DrawGetPrintArea( aDrawRange
, true, true ))
691 if (aDrawRange
.aStart
.Col()<rStartCol
) rStartCol
=aDrawRange
.aStart
.Col();
692 if (aDrawRange
.aStart
.Row()<rStartRow
) rStartRow
=aDrawRange
.aStart
.Row();
704 bool ScDocument::MoveTab( SCTAB nOldPos
, SCTAB nNewPos
, ScProgress
* pProgress
)
706 if (nOldPos
== nNewPos
)
709 SCTAB nTabCount
= static_cast<SCTAB
>(maTabs
.size());
714 if (ValidTab(nOldPos
) && nOldPos
< nTabCount
)
718 bool bOldAutoCalc
= GetAutoCalc();
719 SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
720 SetNoListening( true );
721 if (nNewPos
== SC_TAB_APPEND
|| nNewPos
>= nTabCount
)
722 nNewPos
= nTabCount
-1;
724 // Referenz-Updaterei
725 //! mit UpdateReference zusammenfassen!
727 SCsTAB nDz
= ((SCsTAB
)nNewPos
) - (SCsTAB
)nOldPos
;
728 ScRange
aSourceRange( 0,0,nOldPos
, MAXCOL
,MAXROW
,nOldPos
);
730 pRangeName
->UpdateTabRef(nOldPos
, 3, nNewPos
);
731 pDBCollection
->UpdateMoveTab( nOldPos
, nNewPos
);
732 xColNameRanges
->UpdateReference( URM_REORDER
, this, aSourceRange
, 0,0,nDz
);
733 xRowNameRanges
->UpdateReference( URM_REORDER
, this, aSourceRange
, 0,0,nDz
);
735 pDPCollection
->UpdateReference( URM_REORDER
, aSourceRange
, 0,0,nDz
);
737 pDetOpList
->UpdateReference( this, URM_REORDER
, aSourceRange
, 0,0,nDz
);
738 UpdateChartRef( URM_REORDER
,
739 0,0,nOldPos
, MAXCOL
,MAXROW
,nOldPos
, 0,0,nDz
);
740 UpdateRefAreaLinks( URM_REORDER
, aSourceRange
, 0,0,nDz
);
741 if ( pValidationList
)
742 pValidationList
->UpdateMoveTab( nOldPos
, nNewPos
);
743 if ( pUnoBroadcaster
)
744 pUnoBroadcaster
->Broadcast( ScUpdateRefHint( URM_REORDER
,
745 aSourceRange
, 0,0,nDz
) );
747 ScTable
* pSaveTab
= maTabs
[nOldPos
];
748 maTabs
.erase(maTabs
.begin()+nOldPos
);
749 maTabs
.insert(maTabs
.begin()+nNewPos
, pSaveTab
);
750 TableContainer::iterator it
= maTabs
.begin();
751 for (SCTAB i
= 0; i
< nTabCount
; i
++)
753 maTabs
[i
]->UpdateMoveTab( nOldPos
, nNewPos
, i
, pProgress
);
755 for (; it
!= maTabs
.end(); ++it
)
757 (*it
)->UpdateCompile();
758 SetNoListening( false );
760 for (; it
!= maTabs
.end(); ++it
)
762 (*it
)->StartAllListeners();
763 // sheet names of references may not be valid until sheet is moved
764 pChartListenerCollection
->UpdateScheduledSeriesRanges();
766 SetAutoCalc( bOldAutoCalc
);
769 DrawMovePage( static_cast<sal_uInt16
>(nOldPos
), static_cast<sal_uInt16
>(nNewPos
) );
777 bool ScDocument::CopyTab( SCTAB nOldPos
, SCTAB nNewPos
, const ScMarkData
* pOnlyMarked
)
779 if (SC_TAB_APPEND
== nNewPos
|| nNewPos
>= static_cast<SCTAB
>(maTabs
.size()))
780 nNewPos
= static_cast<SCTAB
>(maTabs
.size());
782 GetName(nOldPos
, aName
);
784 // vorneweg testen, ob der Prefix als gueltig erkannt wird
785 // wenn nicht, nur doppelte vermeiden
786 bool bPrefix
= ValidTabName( aName
);
787 OSL_ENSURE(bPrefix
, "invalid table name");
790 CreateValidTabName(aName
);
794 bValid
= ValidNewTabName(aName
);
796 bValid
= !GetTable( aName
, nDummy
);
798 bool bOldAutoCalc
= GetAutoCalc();
799 SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
802 if (nNewPos
>= static_cast<SCTAB
>(maTabs
.size()))
804 nNewPos
= static_cast<SCTAB
>(maTabs
.size());
805 maTabs
.push_back(new ScTable(this, nNewPos
, aName
));
809 if (ValidTab(nNewPos
) && (nNewPos
< static_cast<SCTAB
>(maTabs
.size())))
811 SetNoListening( true );
813 ScRange
aRange( 0,0,nNewPos
, MAXCOL
,MAXROW
,MAXTAB
);
814 xColNameRanges
->UpdateReference( URM_INSDEL
, this, aRange
, 0,0,1 );
815 xRowNameRanges
->UpdateReference( URM_INSDEL
, this, aRange
, 0,0,1 );
817 pRangeName
->UpdateTabRef(nNewPos
, 1);
818 pDBCollection
->UpdateReference(
819 URM_INSDEL
, 0,0,nNewPos
, MAXCOL
,MAXROW
,MAXTAB
, 0,0,1 );
821 pDPCollection
->UpdateReference( URM_INSDEL
, aRange
, 0,0,1 );
823 pDetOpList
->UpdateReference( this, URM_INSDEL
, aRange
, 0,0,1 );
824 UpdateChartRef( URM_INSDEL
, 0,0,nNewPos
, MAXCOL
,MAXROW
,MAXTAB
, 0,0,1 );
825 UpdateRefAreaLinks( URM_INSDEL
, aRange
, 0,0,1 );
826 if ( pUnoBroadcaster
)
827 pUnoBroadcaster
->Broadcast( ScUpdateRefHint( URM_INSDEL
, aRange
, 0,0,1 ) );
830 for (TableContainer::iterator it
= maTabs
.begin(); it
!= maTabs
.end(); ++it
)
831 if (*it
&& it
!= (maTabs
.begin() + nOldPos
))
832 (*it
)->UpdateInsertTab(nNewPos
);
833 maTabs
.push_back(NULL
);
834 for (i
= static_cast<SCTAB
>(maTabs
.size())-1; i
> nNewPos
; i
--)
835 maTabs
[i
] = maTabs
[i
- 1];
836 if (nNewPos
<= nOldPos
)
838 maTabs
[nNewPos
] = new ScTable(this, nNewPos
, aName
);
840 for (TableContainer::iterator it
= maTabs
.begin(); it
!= maTabs
.end(); ++it
)
841 if (*it
&& it
!= maTabs
.begin()+nOldPos
&& it
!= maTabs
.begin() + nNewPos
)
842 (*it
)->UpdateCompile();
843 SetNoListening( false );
844 for (TableContainer::iterator it
= maTabs
.begin(); it
!= maTabs
.end(); ++it
)
845 if (*it
&& it
!= maTabs
.begin()+nOldPos
&& it
!= maTabs
.begin()+nNewPos
)
846 (*it
)->StartAllListeners();
848 if ( pValidationList
)
849 pValidationList
->UpdateReference( URM_INSDEL
, aRange
, 0,0,1 );
850 // sheet names of references may not be valid until sheet is copied
851 pChartListenerCollection
->UpdateScheduledSeriesRanges();
859 sc::CopyToDocContext
aCxt(*this);
860 SetNoListening( true ); // noch nicht bei CopyToTable/Insert
861 maTabs
[nOldPos
]->CopyToTable(aCxt
, 0, 0, MAXCOL
, MAXROW
, IDF_ALL
, (pOnlyMarked
!= NULL
),
862 maTabs
[nNewPos
], pOnlyMarked
);
863 maTabs
[nNewPos
]->SetTabBgColor(maTabs
[nOldPos
]->GetTabBgColor());
865 SCsTAB nDz
= (static_cast<SCsTAB
>(nNewPos
)) - static_cast<SCsTAB
>(nOldPos
);
866 maTabs
[nNewPos
]->UpdateReference(URM_COPY
, 0, 0, nNewPos
, MAXCOL
, MAXROW
,
867 nNewPos
, 0, 0, nDz
, NULL
);
869 maTabs
[nNewPos
]->UpdateInsertTabAbs(nNewPos
); // alle abs. um eins hoch!!
870 maTabs
[nOldPos
]->UpdateInsertTab(nNewPos
);
872 maTabs
[nOldPos
]->UpdateCompile();
873 maTabs
[nNewPos
]->UpdateCompile( true ); // maybe already compiled in Clone, but used names need recompilation
874 SetNoListening( false );
875 maTabs
[nOldPos
]->StartAllListeners();
876 maTabs
[nNewPos
]->StartAllListeners();
878 ScConditionalFormatList
* pNewList
= new ScConditionalFormatList(*maTabs
[nOldPos
]->GetCondFormList());
879 pNewList
->UpdateReference(URM_COPY
, ScRange( 0, 0, nNewPos
, MAXCOL
, MAXROW
,
880 nNewPos
), 0, 0, nDz
);
881 maTabs
[nNewPos
]->SetCondFormList( pNewList
);
884 SetAutoCalc( bOldAutoCalc
);
887 DrawCopyPage( static_cast<sal_uInt16
>(nOldPos
), static_cast<sal_uInt16
>(nNewPos
) );
890 pDPCollection
->CopyToTab(nOldPos
, nNewPos
);
892 maTabs
[nNewPos
]->SetPageStyle( maTabs
[nOldPos
]->GetPageStyle() );
893 maTabs
[nNewPos
]->SetPendingRowHeights( maTabs
[nOldPos
]->IsPendingRowHeights() );
895 // Copy the custom print range if exists.
896 maTabs
[nNewPos
]->CopyPrintRange(*maTabs
[nOldPos
]);
898 // Copy the RTL settings
899 maTabs
[nNewPos
]->SetLayoutRTL(maTabs
[nOldPos
]->IsLayoutRTL());
900 maTabs
[nNewPos
]->SetLoadingRTL(maTabs
[nOldPos
]->IsLoadingRTL());
903 SetAutoCalc( bOldAutoCalc
);
907 void VBA_InsertModule( ScDocument
& rDoc
, SCTAB nTab
, const OUString
& sModuleName
, const OUString
& sModuleSource
);
909 sal_uLong
ScDocument::TransferTab( ScDocument
* pSrcDoc
, SCTAB nSrcPos
,
910 SCTAB nDestPos
, bool bInsertNew
,
913 sal_uLong nRetVal
= 1; // 0 => Fehler 1 = ok
917 if (pSrcDoc
->pShell
->GetMedium())
919 pSrcDoc
->maFileURL
= pSrcDoc
->pShell
->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI
);
920 // for unsaved files use the title name and adjust during save of file
921 if (pSrcDoc
->maFileURL
.isEmpty())
922 pSrcDoc
->maFileURL
= pSrcDoc
->pShell
->GetName();
926 pSrcDoc
->maFileURL
= pSrcDoc
->pShell
->GetName();
930 if (bInsertNew
) // neu einfuegen
933 pSrcDoc
->GetName(nSrcPos
, aName
);
934 CreateValidTabName(aName
);
935 bValid
= InsertTab(nDestPos
, aName
);
937 // Copy the RTL settings
938 maTabs
[nDestPos
]->SetLayoutRTL(pSrcDoc
->maTabs
[nSrcPos
]->IsLayoutRTL());
939 maTabs
[nDestPos
]->SetLoadingRTL(pSrcDoc
->maTabs
[nSrcPos
]->IsLoadingRTL());
941 else // bestehende Tabelle ersetzen
943 if (ValidTab(nDestPos
) && nDestPos
< static_cast<SCTAB
>(maTabs
.size()) && maTabs
[nDestPos
])
945 maTabs
[nDestPos
]->DeleteArea( 0,0, MAXCOL
,MAXROW
, IDF_ALL
);
953 bool bOldAutoCalcSrc
= false;
954 bool bOldAutoCalc
= GetAutoCalc();
955 SetAutoCalc( false ); // Mehrfachberechnungen vermeiden
956 SetNoListening( true );
959 bOldAutoCalcSrc
= pSrcDoc
->GetAutoCalc();
960 pSrcDoc
->SetAutoCalc( true ); // falls was berechnet werden muss
964 NumFmtMergeHandler
aNumFmtMergeHdl(this, pSrcDoc
);
966 sc::CopyToDocContext
aCxt(*this);
967 nDestPos
= std::min(nDestPos
, (SCTAB
)(GetTableCount() - 1));
968 { // scope for bulk broadcast
969 ScBulkBroadcast
aBulkBroadcast( pBASM
);
970 pSrcDoc
->maTabs
[nSrcPos
]->CopyToTable(aCxt
, 0, 0, MAXCOL
, MAXROW
,
971 ( bResultsOnly
? IDF_ALL
& ~IDF_FORMULA
: IDF_ALL
),
972 false, maTabs
[nDestPos
] );
973 maTabs
[nDestPos
]->CopyConditionalFormat(0, 0, MAXCOL
, MAXROW
,
974 0, 0, pSrcDoc
->maTabs
[nSrcPos
]);
977 maTabs
[nDestPos
]->SetTabNo(nDestPos
);
978 maTabs
[nDestPos
]->SetTabBgColor(pSrcDoc
->maTabs
[nSrcPos
]->GetTabBgColor());
983 SCsTAB nDz
= ((SCsTAB
)nDestPos
) - (SCsTAB
)nSrcPos
;
984 maTabs
[nDestPos
]->UpdateReference(URM_COPY
, 0, 0, nDestPos
,
985 MAXCOL
, MAXROW
, nDestPos
,
987 // Readjust self-contained absolute references to this sheet
988 maTabs
[nDestPos
]->TestTabRefAbs(nSrcPos
);
989 maTabs
[nDestPos
]->CompileAll();
992 SetNoListening( false );
994 maTabs
[nDestPos
]->StartAllListeners();
995 SetDirty( ScRange( 0, 0, nDestPos
, MAXCOL
, MAXROW
, nDestPos
));
998 pSrcDoc
->SetAutoCalc( bOldAutoCalcSrc
);
999 SetAutoCalc( bOldAutoCalc
);
1004 TransferDrawPage( pSrcDoc
, nSrcPos
, nDestPos
);
1006 maTabs
[nDestPos
]->SetPendingRowHeights( pSrcDoc
->maTabs
[nSrcPos
]->IsPendingRowHeights() );
1010 bool bVbaEnabled
= IsInVBAMode();
1014 SfxObjectShell
* pSrcShell
= pSrcDoc
? pSrcDoc
->GetDocumentShell() : NULL
;
1017 OUString
aLibName("Standard");
1018 const BasicManager
*pBasicManager
= pSrcShell
->GetBasicManager();
1019 if (pBasicManager
&& !pBasicManager
->GetName().isEmpty())
1021 aLibName
= pSrcShell
->GetBasicManager()->GetName();
1025 uno::Reference
< script::XLibraryContainer
> xLibContainer
= pSrcShell
->GetBasicContainer();
1026 uno::Reference
< container::XNameContainer
> xLib
;
1027 if( xLibContainer
.is() )
1029 uno::Any aLibAny
= xLibContainer
->getByName(aLibName
);
1035 OUString sSrcCodeName
;
1036 pSrcDoc
->GetCodeName( nSrcPos
, sSrcCodeName
);
1037 OUString sRTLSource
;
1038 xLib
->getByName( sSrcCodeName
) >>= sRTLSource
;
1039 sSource
= sRTLSource
;
1041 VBA_InsertModule( *this, nDestPos
, sCodeName
, sSource
);
1048 void ScDocument::SetError( SCCOL nCol
, SCROW nRow
, SCTAB nTab
, const sal_uInt16 nError
)
1050 if (ValidTab(nTab
) && nTab
< static_cast<SCTAB
>(maTabs
.size()))
1052 maTabs
[nTab
]->SetError( nCol
, nRow
, nError
);
1055 void ScDocument::SetFormula(
1056 const ScAddress
& rPos
, const ScTokenArray
& rArray
, formula::FormulaGrammar::Grammar eGram
)
1058 if (!TableExists(rPos
.Tab()))
1061 maTabs
[rPos
.Tab()]->SetFormula(rPos
.Col(), rPos
.Row(), rArray
, eGram
);
1064 void ScDocument::SetFormula(
1065 const ScAddress
& rPos
, const OUString
& rFormula
, formula::FormulaGrammar::Grammar eGram
)
1067 if (!TableExists(rPos
.Tab()))
1070 maTabs
[rPos
.Tab()]->SetFormula(rPos
.Col(), rPos
.Row(), rFormula
, eGram
);
1073 void ScDocument::SetFormulaCell( const ScAddress
& rPos
, ScFormulaCell
* pCell
)
1075 if (!TableExists(rPos
.Tab()))
1081 maTabs
[rPos
.Tab()]->SetFormulaCell(rPos
.Col(), rPos
.Row(), pCell
);
1084 void ScDocument::SetConsolidateDlgData( const ScConsolidateParam
* pData
)
1086 delete pConsolidateDlgData
;
1089 pConsolidateDlgData
= new ScConsolidateParam( *pData
);
1091 pConsolidateDlgData
= NULL
;
1094 void ScDocument::SetChangeViewSettings(const ScChangeViewSettings
& rNew
)
1096 if (pChangeViewSettings
==NULL
)
1097 pChangeViewSettings
= new ScChangeViewSettings
;
1099 OSL_ENSURE( pChangeViewSettings
, "Oops. No ChangeViewSettings :-( by!" );
1101 *pChangeViewSettings
=rNew
;
1104 // ----------------------------------------------------------------------------
1106 ScFieldEditEngine
* ScDocument::CreateFieldEditEngine()
1108 ScFieldEditEngine
* pNewEditEngine
= NULL
;
1109 if (!pCacheFieldEditEngine
)
1111 pNewEditEngine
= new ScFieldEditEngine(
1112 this, GetEnginePool(), GetEditPool(), false);
1116 if ( !bImportingXML
)
1118 // #i66209# previous use might not have restored update mode,
1119 // ensure same state as for a new EditEngine (UpdateMode = true)
1120 if ( !pCacheFieldEditEngine
->GetUpdateMode() )
1121 pCacheFieldEditEngine
->SetUpdateMode(true);
1124 pNewEditEngine
= pCacheFieldEditEngine
;
1125 pCacheFieldEditEngine
= NULL
;
1127 return pNewEditEngine
;
1130 void ScDocument::DisposeFieldEditEngine(ScFieldEditEngine
*& rpEditEngine
)
1132 if (!pCacheFieldEditEngine
&& rpEditEngine
)
1134 pCacheFieldEditEngine
= rpEditEngine
;
1135 pCacheFieldEditEngine
->Clear();
1138 delete rpEditEngine
;
1139 rpEditEngine
= NULL
;
1142 // ----------------------------------------------------------------------------
1144 ScRecursionHelper
* ScDocument::CreateRecursionHelperInstance()
1146 return new ScRecursionHelper
;
1149 // ----------------------------------------------------------------------------
1151 ScLookupCache
& ScDocument::GetLookupCache( const ScRange
& rRange
)
1153 ScLookupCache
* pCache
= 0;
1154 if (!pLookupCacheMapImpl
)
1155 pLookupCacheMapImpl
= new ScLookupCacheMapImpl
;
1156 ScLookupCacheMap::iterator
it( pLookupCacheMapImpl
->aCacheMap
.find( rRange
));
1157 if (it
== pLookupCacheMapImpl
->aCacheMap
.end())
1159 pCache
= new ScLookupCache( this, rRange
);
1160 AddLookupCache( *pCache
);
1163 pCache
= (*it
).second
;
1167 void ScDocument::AddLookupCache( ScLookupCache
& rCache
)
1169 if (!pLookupCacheMapImpl
->aCacheMap
.insert( ::std::pair
< const ScRange
,
1170 ScLookupCache
*>( rCache
.getRange(), &rCache
)).second
)
1172 OSL_FAIL( "ScDocument::AddLookupCache: couldn't add to hash map");
1175 StartListeningArea( rCache
.getRange(), &rCache
);
1178 void ScDocument::RemoveLookupCache( ScLookupCache
& rCache
)
1180 ScLookupCacheMap::iterator
it( pLookupCacheMapImpl
->aCacheMap
.find(
1181 rCache
.getRange()));
1182 if (it
== pLookupCacheMapImpl
->aCacheMap
.end())
1184 OSL_FAIL( "ScDocument::RemoveLookupCache: range not found in hash map");
1188 ScLookupCache
* pCache
= (*it
).second
;
1189 pLookupCacheMapImpl
->aCacheMap
.erase( it
);
1190 EndListeningArea( pCache
->getRange(), &rCache
);
1194 void ScDocument::ClearLookupCaches()
1196 if( pLookupCacheMapImpl
)
1197 pLookupCacheMapImpl
->clear();
1200 void ScDocument::SetPreviewFont( SfxItemSet
* pFont
)
1202 delete pPreviewFont
;
1203 pPreviewFont
= pFont
;
1206 const ScMarkData
& ScDocument::GetPreviewSelection()
1208 if ( !pPreviewSelection
)
1209 pPreviewSelection
= new ScMarkData();
1211 return *pPreviewSelection
;
1214 void ScDocument::SetPreviewSelection( ScMarkData
& rSel
)
1216 // yeuch, why do I have a pointer here ???? ( other problems
1217 // to fix right now though )
1218 if ( !pPreviewSelection
)
1219 pPreviewSelection
= new ScMarkData();
1220 *pPreviewSelection
= rSel
;
1223 SfxItemSet
* ScDocument::GetPreviewFont( SCCOL nCol
, SCROW nRow
, SCTAB nTab
)
1225 SfxItemSet
* pRet
= NULL
;
1228 if ( GetPreviewSelection().IsCellMarked( nCol
, nRow
) && GetPreviewSelection().GetFirstSelected() == nTab
)
1229 pRet
= pPreviewFont
;
1234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */