1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 #ifndef INCLUDED_SC_INC_DOCUMENT_HXX
21 #define INCLUDED_SC_INC_DOCUMENT_HXX
22 
23 #include <vcl/idle.hxx>
24 #include <vcl/errcode.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <vcl/vclptr.hxx>
27 #include "patattr.hxx"
28 #include "scdllapi.h"
29 #include "interpretercontext.hxx"
30 #include "rangelst.hxx"
31 #include "rangenam.hxx"
32 #include "tabopparams.hxx"
33 #include "types.hxx"
34 #include <formula/grammar.hxx>
35 #include <formula/types.hxx>
36 #include "typedstrdata.hxx"
37 #include "calcmacros.hxx"
38 #include "calcconfig.hxx"
39 #include <o3tl/deleter.hxx>
40 #include <o3tl/sorted_vector.hxx>
41 #include <svl/hint.hxx>
42 #include <svl/typedwhich.hxx>
43 #include <svl/zforlist.hxx>
44 #include <tools/gen.hxx>
45 #include <tools/solar.h>
46 
47 #include <cassert>
48 #include <memory>
49 #include <map>
50 #include <set>
51 #include <vector>
52 
53 #include "markdata.hxx"
54 
55 namespace com { namespace sun { namespace star { namespace chart2 { class XChartDocument; } } } }
56 
57 class Timer;
58 
59 enum class SvtScriptType;
60 enum class ScMF;
61 enum class FormulaError : sal_uInt16;
62 enum class CharCompressType;
63 enum class EEHorizontalTextDirection;
64 namespace editeng { class SvxBorderLine; }
65 namespace formula { struct VectorRefArray; }
66 namespace svl {
67 
68 class SharedString;
69 class SharedStringPool;
70 
71 }
72 
73 namespace sc {
74 
75 struct FormulaGroupContext;
76 class StartListeningContext;
77 class EndListeningContext;
78 class CopyFromClipContext;
79 class ColumnSpanSet;
80 class RangeColumnSpanSet;
81 struct ColumnBlockPosition;
82 struct RefUpdateContext;
83 class EditTextIterator;
84 struct NoteEntry;
85 class DocumentStreamAccess;
86 class DocumentLinkManager;
87 class CellValues;
88 class TableValues;
89 class RowHeightContext;
90 struct SetFormulaDirtyContext;
91 class RefMovedHint;
92 struct ReorderParam;
93 class FormulaGroupAreaListener;
94 class ColumnSet;
95 class UpdatedRangeNames;
96 class TableColumnBlockPositionSet;
97 class ColumnIterator;
98 class ExternalDataMapper;
99 
100 }
101 
102 class Fraction;
103 
104 class OutputDevice;
105 class SdrObject;
106 class SfxBroadcaster;
107 class SfxListener;
108 class SfxItemSet;
109 class SfxObjectShell;
110 class SfxBindings;
111 class SfxPoolItem;
112 class SfxItemPool;
113 class SfxPrinter;
114 class SfxStyleSheetBase;
115 class SvMemoryStream;
116 class SvxBoxInfoItem;
117 class SvxBoxItem;
118 class SvxForbiddenCharactersTable;
119 namespace sfx2 {
120     class LinkManager;
121     }
122 class SvxSearchItem;
123 namespace vcl { class Window; }
124 class XColorList;
125 
126 class ScAutoFormatData;
127 class ScBroadcastAreaSlotMachine;
128 class ScChangeViewSettings;
129 class ScChartListenerCollection;
130 class ScClipOptions;
131 class ScConditionalFormat;
132 class ScConditionalFormatList;
133 class ScDBCollection;
134 class ScDBData;
135 class ScDetOpData;
136 class ScDetOpList;
137 class ScDocOptions;
138 class ScDocProtection;
139 class ScDocumentPool;
140 class ScDrawLayer;
141 class ScExtDocOptions;
142 class ScExternalRefManager;
143 class ScFormulaCell;
144 class ScMacroManager;
145 class ScOutlineTable;
146 class ScPrintRangeSaver;
147 class ScStyleSheet;
148 class ScStyleSheetPool;
149 class ScTable;
150 class ScTableProtection;
151 class ScTokenArray;
152 class ScValidationData;
153 class ScValidationDataList;
154 class ScViewOptions;
155 class ScChangeTrack;
156 class ScEditEngineDefaulter;
157 class ScFieldEditEngine;
158 class ScNoteEditEngine;
159 class ScDPObject;
160 class ScDPCollection;
161 class ScMatrix;
162 class ScScriptTypeData;
163 class ScPoolHelper;
164 struct ScSortParam;
165 class ScRefreshTimerControl;
166 class ScUnoListenerCalls;
167 class ScUnoRefList;
168 class ScRecursionHelper;
169 struct RowInfo;
170 struct ScTableInfo;
171 struct ScTabOpParam;
172 class VirtualDevice;
173 class ScAutoNameCache;
174 class ScTemporaryChartLock;
175 class ScLookupCache;
176 struct ScLookupCacheMap;
177 class SfxUndoManager;
178 class ScFormulaParserPool;
179 struct ScClipParam;
180 class ScRowBreakIterator;
181 struct ScSetStringParam;
182 struct ScColWidthParam;
183 class ScSheetEvents;
184 class ScProgress;
185 class SvtListener;
186 class ScEditDataArray;
187 class EditTextObject;
188 struct ScRefCellValue;
189 class ScPostIt;
190 struct ScSubTotalParam;
191 struct ScQueryParam;
192 class ScHint;
193 class SvtBroadcaster;
194 enum class ScDBDataPortion;
195 enum class ScSheetEventId;
196 class BitmapEx;
197 class ScColumnsRange;
198 struct ScFilterEntries;
199 typedef o3tl::sorted_vector<sal_uInt32> ScCondFormatIndexes;
200 
201 namespace sc {
202 
203 typedef std::map<OUString, BitmapEx> IconSetBitmapMap;
204 
205 }
206 
207 namespace com { namespace sun { namespace star {
208     namespace lang {
209         struct EventObject;
210     }
211     namespace i18n {
212         class XBreakIterator;
213     }
214     namespace util {
215         class XModifyListener;
216     }
217     namespace embed {
218         class XEmbeddedObject;
219     }
220     namespace script { namespace vba {
221         class XVBAEventProcessor;
222     } }
223     namespace sheet {
224         struct TablePageBreakData;
225     }
226 } } }
227 
228 namespace weld {
229 
230 class Window;
231 
232 }
233 
234 #define SC_DOC_NEW          0xFFFF
235 
236 #define SC_MACROCALL_ALLOWED        0
237 
238 #define SC_ASIANKERNING_INVALID         0xff
239 
240 enum ScDocumentMode
241 {
242     SCDOCMODE_DOCUMENT,
243     SCDOCMODE_CLIP,
244     SCDOCMODE_UNDO,
245     SCDOCMODE_FUNCTIONACCESS
246 };
247 
248 enum CommentCaptionState
249 {
250     ALLSHOWN,                   // All comments captions are shown
251     ALLHIDDEN,                  // All comments captions are hidden
252     MIXED                       // There are comments in shown and hidden.
253 };
254 
255 enum RangeNameScope
256 {
257     GLOBAL,                    // A range name can be defined
258     SHEET                      // with two scope on Manage Names dialog.
259 };
260 
261 struct ScDocStat
262 {
263     OUString  aDocName;
264     SCTAB   nTableCount;
265     sal_uLong   nCellCount;
266     sal_uLong   nFormulaCount;
267     sal_uInt16  nPageCount;
ScDocStatScDocStat268     ScDocStat()
269         : nTableCount(0)
270         , nCellCount(0)
271         , nFormulaCount(0)
272         , nPageCount(0)
273     {
274     }
275 };
276 
277 // DDE link modes
278 const sal_uInt8 SC_DDE_DEFAULT       = 0;
279 const sal_uInt8 SC_DDE_ENGLISH       = 1;
280 const sal_uInt8 SC_DDE_TEXT          = 2;
281 const sal_uInt8 SC_DDE_IGNOREMODE    = 255;       /// For usage in FindDdeLink() only!
282 
283 // During threaded calculation fields being mutated are kept in this struct
284 struct ScDocumentThreadSpecific
285 {
286     ScRecursionHelper*      pRecursionHelper;               // information for recursive and iterative cell formulas
287     ScInterpreterContext* pContext;  // references the context passed around for easier access
288 
ScDocumentThreadSpecificScDocumentThreadSpecific289     ScDocumentThreadSpecific()
290         : pRecursionHelper(nullptr)
291         , pContext(nullptr)
292     {
293     }
294 
295     // To be called in the thread at start
296     static void SetupFromNonThreadedData(const ScDocumentThreadSpecific& rNonThreadedData);
297 
298     // To be called in the main thread after the thread has finished
299     static void MergeBackIntoNonThreadedData(ScDocumentThreadSpecific& rNonThreadedData);
300 };
301 
302 /// Enumeration to determine which pieces of the code should not be mutated when set.
303 enum ScMutationGuardFlags
304 {
305     // Bit mask bits
306     CORE = 0x0001, /// Core calc data structures should not be mutated
307 };
308 
309 typedef std::unique_ptr<ScTable, o3tl::default_delete<ScTable>> ScTableUniquePtr;
310 
311 class ScDocument
312 {
313 friend class ScValueIterator;
314 friend class ScHorizontalValueIterator;
315 friend class ScDBQueryDataIterator;
316 friend class ScFormulaGroupIterator;
317 friend class ScCellIterator;
318 friend class ScQueryCellIterator;
319 friend class ScCountIfCellIterator;
320 friend class ScHorizontalCellIterator;
321 friend class ScHorizontalAttrIterator;
322 friend class ScDocAttrIterator;
323 friend class ScAccessibleTableBase;
324 friend class ScAttrRectIterator;
325 friend class ScDocShell;
326 friend class ScDocRowHeightUpdater;
327 friend class ScColumnTextWidthIterator;
328 friend class ScFormulaCell;
329 friend class ScTable;
330 friend class ScColumn;
331 friend struct ScRefCellValue;
332 friend class ScDocumentImport;
333 friend class sc::DocumentStreamAccess;
334 friend class sc::ColumnSpanSet;
335 friend class sc::RangeColumnSpanSet;
336 friend class sc::EditTextIterator;
337 friend class sc::FormulaGroupAreaListener;
338 friend class sc::TableColumnBlockPositionSet;
339 friend struct ScMutationGuard;
340 friend struct ScMutationDisable;
341 
342     typedef std::vector<ScTableUniquePtr> TableContainer;
343 
344 public:
345     enum class HardRecalcState
346     {
347         OFF,        /// normal calculation of dependencies
348         TEMPORARY,  /// CalcAll() without broadcast/notify but setting up new listeners
349         ETERNAL     /// no new listeners are setup, no broadcast/notify
350     };
351 
352 private:
353     rtl::Reference<ScPoolHelper> mxPoolHelper;
354 
355     std::shared_ptr<svl::SharedStringPool> mpCellStringPool;
356     std::unique_ptr<sc::DocumentLinkManager> mpDocLinkMgr;
357 
358     std::shared_ptr<sc::FormulaGroupContext> mpFormulaGroupCxt;
359     bool                mbFormulaGroupCxtBlockDiscard;
360 
361     ScCalcConfig        maCalcConfig;
362 
363     SfxUndoManager*     mpUndoManager;
364     std::unique_ptr<ScFieldEditEngine>  mpEditEngine;                   // uses pEditPool from xPoolHelper
365     std::unique_ptr<ScNoteEditEngine>   mpNoteEngine;                   // uses pEditPool from xPoolHelper
366     SfxObjectShell*     mpShell;
367     VclPtr<SfxPrinter>  mpPrinter;
368     VclPtr<VirtualDevice> mpVirtualDevice_100th_mm;
369     std::unique_ptr<ScDrawLayer> mpDrawLayer;           // SdrModel
370     rtl::Reference<XColorList> pColorList;
371     std::unique_ptr<ScValidationDataList> pValidationList;              // validity
372     SvNumberFormatterIndexTable* pFormatExchangeList;    // for application of number formats
373     TableContainer maTabs;
374     SCCOL mnMaxCol; /// Maximum addressable column
375     SCROW mnMaxRow; /// Maximum addressable row
376     std::vector<OUString> maTabNames;               // for undo document, we need the information tab name <-> index
377     mutable std::unique_ptr<ScRangeName>    pRangeName;
378     std::unique_ptr<ScDBCollection>         pDBCollection;
379     std::unique_ptr<ScDPCollection>         pDPCollection;
380     std::unique_ptr< ScTemporaryChartLock > apTemporaryChartLock;
381     std::unique_ptr<ScPatternAttr>          pSelectionAttr;                 // Attributes of a block
382     ScFormulaCell*      pFormulaTree;                   // formula tree (start)
383     ScFormulaCell*      pEOFormulaTree;                 // formula tree (end), last cell
384     ScFormulaCell*      pFormulaTrack;                  // BroadcastTrack (start)
385     ScFormulaCell*      pEOFormulaTrack;                // BroadcastTrack (end), last cell
386     std::unique_ptr<ScBroadcastAreaSlotMachine> pBASM;                  // BroadcastAreas
387     std::unique_ptr<ScChartListenerCollection> pChartListenerCollection;
388     std::unique_ptr<SvMemoryStream>     pClipData;
389     std::unique_ptr<ScDetOpList>        pDetOpList;
390     std::unique_ptr<ScChangeTrack>      pChangeTrack;
391     std::unique_ptr<SfxBroadcaster>     pUnoBroadcaster;
392     std::unique_ptr<ScUnoListenerCalls> pUnoListenerCalls;
393     std::unique_ptr<ScUnoRefList>       pUnoRefUndoList;
394     std::unique_ptr<ScChangeViewSettings> pChangeViewSettings;
395     std::unique_ptr<ScScriptTypeData>   pScriptTypeData;
396     std::unique_ptr<ScRefreshTimerControl> pRefreshTimerControl;
397     std::shared_ptr<SvxForbiddenCharactersTable> xForbiddenCharacters;
398     std::unique_ptr<ScDBData>               mpAnonymousDBData;
399     std::unique_ptr<sc::ExternalDataMapper> mpDataMapper;
400 
401     std::unique_ptr<ScFieldEditEngine>    pCacheFieldEditEngine;
402 
403     std::unique_ptr<ScDocProtection>      pDocProtection;
404     std::unique_ptr<ScClipParam>          mpClipParam;
405 
406     std::unique_ptr<ScExternalRefManager> pExternalRefMgr;
407     std::unique_ptr<ScMacroManager>       mpMacroMgr;
408 
409     // mutable for lazy construction
410     mutable std::unique_ptr< ScFormulaParserPool >
411                         mxFormulaParserPool;            /// Pool for all external formula parsers used by this document.
412 
413     OUString       aDocName;                       // optional: name of document
414     OUString       aDocCodeName;                       // optional: name of document (twice?)
415     OUString       maFileURL;      // file URL for copy & paste
416     ScRangePairListRef  xColNameRanges;
417     ScRangePairListRef  xRowNameRanges;
418 
419     std::unique_ptr<ScViewOptions>   pViewOptions;      // view options
420     std::unique_ptr<ScDocOptions>    pDocOptions;       // document options
421     std::unique_ptr<ScExtDocOptions> pExtDocOptions;    // for import etc.
422     std::unique_ptr<ScClipOptions> mpClipOptions;       // clipboard options
423     std::unique_ptr<ScConsolidateParam> pConsolidateDlgData;
424 
425     std::unique_ptr<ScAutoNameCache> pAutoNameCache;    // for automatic name lookup during CompileXML
426 
427     std::unique_ptr<SfxItemSet> pPreviewFont; // convert to std::unique_ptr or whatever
428     ScStyleSheet*       pPreviewCellStyle;
429     ScMarkData          maPreviewSelection;
430     sal_Int64           nUnoObjectId;                   // counted up for UNO objects
431 
432     ErrCode             nRangeOverflowType;             // used in (xml) loading for overflow warnings
433 
434     ScRange             aEmbedRange;
435     ScAddress           aCurTextWidthCalcPos;
436 
437     Idle                aTrackIdle;
438 
439     css::uno::Reference< css::script::vba::XVBAEventProcessor >
440                         mxVbaEvents;
441 public:
442     /// list of ScInterpreterTableOpParams currently in use
443     std::vector<ScInterpreterTableOpParams*> m_TableOpList;
444     ScInterpreterTableOpParams  aLastTableOpParams;     // remember last params
445 
446 private:
447 
448     LanguageType        eLanguage;                      // default language
449     LanguageType        eCjkLanguage;                   // default language for asian text
450     LanguageType        eCtlLanguage;                   // default language for complex text
451     rtl_TextEncoding    eSrcSet;                        // during reading: source character set
452 
453     /** The compiler grammar used in document storage. GRAM_PODF for ODF 1.1
454         documents, GRAM_ODFF for ODF 1.2 documents. */
455     formula::FormulaGrammar::Grammar  eStorageGrammar;
456 
457     sal_uLong               nFormulaCodeInTree;             // formula RPN in the formula tree
458     sal_uLong               nXMLImportedFormulaCount;        // progress count during XML import
459     sal_uInt16              nInterpretLevel;                // >0 if in interpreter
460     sal_uInt16              nMacroInterpretLevel;           // >0 if macro in interpreter
461     sal_uInt16              nInterpreterTableOpLevel;       // >0 if in interpreter TableOp
462 
463     ScDocumentThreadSpecific maNonThreaded;
464 
465     // There can be only one ScDocument being calculated in a thread at a time, so we can use a
466     // plain thread_local static member.
467     thread_local static ScDocumentThreadSpecific maThreadSpecific;
468 
469     mutable ScInterpreterContext maInterpreterContext;
470 
471     osl::Mutex mScLookupMutex; // protection for thread-unsafe parts of handling ScLookup
472 
473     static const sal_uInt16 nSrcVer;                        // file version (load/save)
474     sal_uInt16              nFormulaTrackCount;
475     HardRecalcState         eHardRecalcState;               // off, temporary, eternal
476     SCTAB                   nVisibleTab;                    // for OLE etc., don't use inside ScDocument
477     SCCOL                   nPosLeft;                       // for OLE etc., don't use inside ScDocument
478     SCROW                   nPosTop;                        // for OLE etc., don't use inside ScDocument
479 
480     ScLkUpdMode         eLinkMode;
481 
482     bool                bAutoCalc;                      // calculate automatically
483     bool                bAutoCalcShellDisabled;         // in/from/for ScDocShell disabled
484     // are there ForcedFormulas which have to be calculated
485     // in interaction with ScDocShell SetDocumentModified,
486     // AutoCalcShellDisabled and TrackFormulas
487     bool                bForcedFormulaPending;
488     bool                bCalculatingFormulaTree;
489     bool const          bIsClip;
490     bool const          bIsUndo;
491     bool const          bIsFunctionAccess;
492     bool                bIsVisible;                     // set from view ctor
493 
494     bool                bIsEmbedded;                    // display/adjust Embedded area?
495 
496     // no broadcast, construct no listener during insert from a different
497     // Doc (per filter or the like ), not until CompileAll / CalcAfterLoad
498     bool                bInsertingFromOtherDoc;
499     bool                bLoadingMedium;
500     bool                bImportingXML;      // special handling of formula text
501     bool                bCalcingAfterLoad;              // in CalcAfterLoad TRUE
502     // don't construct/destruct listeners temporarily
503     bool                bNoListening;
504     bool                mbIdleEnabled;
505     bool                bInLinkUpdate;                  // TableLink or AreaLink
506     bool                bChartListenerCollectionNeedsUpdate;
507     // are/were there RC_FORCED formula cells in the document (if set once to TRUE then set forever)
508     bool                bHasForcedFormulas;
509     // is the Doc being destroyed? (no Notify-Tracking etc. needed anymore)
510     bool                bInDtorClear;
511     // expand reference if insert column/row takes place at the border
512     // of a reference
513     // is fetched in each UpdateReference from InputOptions,
514     // assigned, and restored at the end of UpdateReference
515     bool                bExpandRefs;
516     // for detective update, is set for each change of a formula
517     bool                bDetectiveDirty;
518     // If the pointer is set, formula cells will not be automatically grouped into shared formula groups,
519     // instead the range will be extended to contain all such cells.
520     std::unique_ptr< ScRange > pDelayedFormulaGrouping;
521 
522     bool                bLinkFormulaNeedingCheck; // valid only after loading, for ocDde and ocWebservice
523 
524     CharCompressType    nAsianCompression;
525     sal_uInt8           nAsianKerning;
526 
527     bool                bPastingDrawFromOtherDoc;
528 
529     sal_uInt8           nInDdeLinkUpdate;   // originating DDE links (stacked bool)
530 
531     bool                bInUnoBroadcast;
532     bool                bInUnoListenerCall;
533     sal_uInt32          nAdjustHeightLock;
534     formula::FormulaGrammar::Grammar  eGrammar;
535 
536     mutable bool        bStyleSheetUsageInvalid;
537 
538     bool                mbUndoEnabled:1;
539     bool                mbExecuteLinkEnabled:1;
540     bool                mbChangeReadOnlyEnabled:1;    // allow changes in read-only document (for API import filters)
541     bool                mbStreamValidLocked:1;
542     bool                mbUserInteractionEnabled:1;  // whether or not to launch any kind of interactive dialogs.
543 
544     sal_Int16           mnNamedRangesLockCount;
545 
546     std::set<ScFormulaCell*> maSubTotalCells;
547 
548 
549     bool mbEmbedFonts : 1;
550     bool mbEmbedUsedFontsOnly : 1;
551     bool mbEmbedFontScriptLatin : 1;
552     bool mbEmbedFontScriptAsian : 1;
553     bool mbEmbedFontScriptComplex : 1;
554 
555     std::unique_ptr<sc::IconSetBitmapMap> m_pIconSetBitmapMap;
556 
557     bool                mbTrackFormulasPending  : 1;
558     bool                mbFinalTrackFormulas    : 1;
559     // This indicates if a ScDocShell::DoRecalc() or ScDocShell::DoHardRecalc() is in progress.
560     bool                mbDocShellRecalc        : 1;
561 
562     size_t              mnMutationGuardFlags;
563 
564 public:
565     bool                     IsCellInChangeTrack(const ScAddress &cell,Color *pColCellBorder);
566     void                     GetCellChangeTrackNote(const ScAddress &cell, OUString &strTrackText, bool &pbLeftEdge);
567 
IsEmbedFonts() const568     bool IsEmbedFonts() const { return mbEmbedFonts; }
IsEmbedUsedFontsOnly() const569     bool IsEmbedUsedFontsOnly() const { return mbEmbedUsedFontsOnly; }
IsEmbedFontScriptLatin() const570     bool IsEmbedFontScriptLatin() const { return mbEmbedFontScriptLatin; }
IsEmbedFontScriptAsian() const571     bool IsEmbedFontScriptAsian() const { return mbEmbedFontScriptAsian; }
IsEmbedFontScriptComplex() const572     bool IsEmbedFontScriptComplex() const { return mbEmbedFontScriptComplex; }
573 
SetEmbedFonts(bool bUse)574     void SetEmbedFonts(bool bUse) { mbEmbedFonts = bUse; }
SetEmbedUsedFontsOnly(bool bUse)575     void SetEmbedUsedFontsOnly(bool bUse) { mbEmbedUsedFontsOnly = bUse; }
SetEmbedFontScriptLatin(bool bUse)576     void SetEmbedFontScriptLatin(bool bUse) { mbEmbedFontScriptLatin = bUse; }
SetEmbedFontScriptAsian(bool bUse)577     void SetEmbedFontScriptAsian(bool bUse) { mbEmbedFontScriptAsian = bUse; }
SetEmbedFontScriptComplex(bool bUse)578     void SetEmbedFontScriptComplex(bool bUse) { mbEmbedFontScriptComplex = bUse; }
579 
580     SC_DLLPUBLIC sal_uLong   GetCellCount() const;       // all cells
581     SC_DLLPUBLIC sal_uLong   GetFormulaGroupCount() const;       // all cells
582     sal_uLong                GetCodeCount() const;       // RPN-Code in formulas
583     DECL_LINK( GetUserDefinedColor, sal_uInt16, Color* );
584                                                                 // number formatter
585 public:
586     SC_DLLPUBLIC                ScDocument( ScDocumentMode eMode = SCDOCMODE_DOCUMENT,
587                                             SfxObjectShell* pDocShell = nullptr );
588     SC_DLLPUBLIC                ~ScDocument();
589 
SetName(const OUString & r)590     void              SetName( const OUString& r ) { aDocName = r; }
GetCodeName() const591     const OUString&   GetCodeName() const { return aDocCodeName; }
SetCodeName(const OUString & r)592     void              SetCodeName( const OUString& r ) { aDocCodeName = r; }
GetFileURL() const593     const OUString&   GetFileURL() const { return maFileURL; }
594 
595     void              GetDocStat( ScDocStat& rDocStat );
596 
597     SC_DLLPUBLIC void  InitDrawLayer( SfxObjectShell* pDocShell = nullptr );
598 
GetNonThreadedContext() const599     ScInterpreterContext& GetNonThreadedContext() const
600     {
601         assert(!IsThreadedGroupCalcInProgress());
602         return maInterpreterContext;
603     }
604     // Uses thread_local.
GetThreadedContext() const605     ScInterpreterContext& GetThreadedContext() const
606     {
607         return IsThreadedGroupCalcInProgress() ? *maThreadSpecific.pContext : GetNonThreadedContext();
608     }
609     static void SetupFromNonThreadedContext( ScInterpreterContext& threadedContext, int threadNumber );
610     void MergeBackIntoNonThreadedContext( ScInterpreterContext& threadedContext, int threadNumber );
SetThreadedGroupCalcInProgress(bool set)611     void SetThreadedGroupCalcInProgress( bool set ) { (void)this; ScGlobal::bThreadedGroupCalcInProgress = set; }
IsThreadedGroupCalcInProgress() const612     bool IsThreadedGroupCalcInProgress() const { (void)this; return ScGlobal::bThreadedGroupCalcInProgress; }
613 
614     SC_DLLPUBLIC sfx2::LinkManager*       GetLinkManager();
615     SC_DLLPUBLIC const sfx2::LinkManager* GetLinkManager() const;
616 
617     sc::DocumentLinkManager&       GetDocLinkManager();
618     const sc::DocumentLinkManager& GetDocLinkManager() const;
619 
620     SC_DLLPUBLIC const ScDocOptions&    GetDocOptions() const;
621     SC_DLLPUBLIC void                   SetDocOptions( const ScDocOptions& rOpt );
622     SC_DLLPUBLIC const ScViewOptions&   GetViewOptions() const;
623     SC_DLLPUBLIC void                   SetViewOptions( const ScViewOptions& rOpt );
624     void                                SetPrintOptions();
625 
GetExtDocOptions()626     ScExtDocOptions*            GetExtDocOptions()  { return pExtDocOptions.get(); }
627     SC_DLLPUBLIC void           SetExtDocOptions( std::unique_ptr<ScExtDocOptions> pNewOptions );
628 
GetClipOptions()629     ScClipOptions*              GetClipOptions()    { return mpClipOptions.get(); }
630     void                        SetClipOptions(std::unique_ptr<ScClipOptions> pClipOptions);
631 
632     SC_DLLPUBLIC void           GetLanguage( LanguageType& rLatin, LanguageType& rCjk, LanguageType& rCtl ) const;
633     void                        SetLanguage( LanguageType eLatin, LanguageType eCjk, LanguageType eCtl );
634 
635     void                        SetConsolidateDlgData( std::unique_ptr<ScConsolidateParam> pData );
GetConsolidateDlgData() const636     const ScConsolidateParam*   GetConsolidateDlgData() const { return pConsolidateDlgData.get(); }
637 
638     void                        Clear( bool bFromDestructor = false );
639 
640     std::unique_ptr<ScFieldEditEngine> CreateFieldEditEngine();
641     void                        DisposeFieldEditEngine(std::unique_ptr<ScFieldEditEngine>& rpEditEngine);
642 
643     /**
644      * Get all range names that are local to each table.  It only returns
645      * non-empty range name set.
646      */
647     SC_DLLPUBLIC void          GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rRangeNames) const;
648     SC_DLLPUBLIC void          SetAllRangeNames(const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap);
649     SC_DLLPUBLIC void          GetRangeNameMap(std::map<OUString, ScRangeName*>& rRangeName);
650     SC_DLLPUBLIC ScRangeName*  GetRangeName(SCTAB nTab) const;
651     SC_DLLPUBLIC ScRangeName*  GetRangeName() const;
652     void                       SetRangeName(SCTAB nTab, std::unique_ptr<ScRangeName> pNew);
653     void                       SetRangeName( std::unique_ptr<ScRangeName> pNewRangeName );
654     bool                       IsAddressInRangeName( RangeNameScope eScope, const ScAddress& rAddress);
655 
656     /** Find a named expression / range name in either global or a local scope.
657         @param  nTab
658                 If <0 search nIndex in global scope, if >=0 search nIndex in scope of nTab.
659         @param  nIndex
660                 Index of named expression / range name.
661         @return nullptr if indexed name not found.
662      */
663     ScRangeData* FindRangeNameBySheetAndIndex( SCTAB nTab, sal_uInt16 nIndex ) const;
664 
665     /** Recursively find all named expressions that directly or indirectly
666         (nested) reference a given sheet, starting from a given named
667         expression nTokenTab/nTokenIndex.
668 
669         Used to collect all named expressions/ranges that will need to be
670         copied along when copying sheets.
671 
672         The different tab/sheets passed cater for the situation that a sheet is
673         copied and was already inserted and global names are already adjusted
674         but the sheet-local names of the shifted original sheet are not yet. If
675         no sheet was inserted and global and local names' references not
676         updated yet, then all 4 tab arguments would be identical.
677 
678         @param  nTokenTab
679                 Tab/sheet on which to find the name, -1 if global scope.
680                 For example obtained from ocName token.
681 
682         @param  nTokenIndex
683                 Index of named expression. For example obtained from ocName token.
684 
685         @param  nGlobalRefTab
686                 Tab to check if used in global names.
687 
688         @param  nLocalRefTab
689                 Tab to check if used in sheet-local names.
690 
691         @param  nOldTokenTab
692                 The original tab of the copied sheet, used as sheet-local
693                 base position for relative references.
694 
695         @param  nOldTokenTabReplacement
696                 The replacement to use for relative references if the name
697                 encountered uses nOldTokenTab as base position.
698 
699         @param  bSameDoc
700                 FALSE if collecting names for a sheet to be copied to another
701                 document. Then all names encountered are considered to be
702                 referencing the sheet. Else TRUE if collecting names to be
703                 copied into the same document.
704 
705         @param  nRecursion
706                 Recursion guard, initialize with 0.
707       */
708     bool FindRangeNamesReferencingSheet( sc::UpdatedRangeNames& rIndexes,
709             SCTAB nTokenTab, const sal_uInt16 nTokenIndex,
710             SCTAB nGlobalRefTab, SCTAB nLocalRefTab, SCTAB nOldTokenTab, SCTAB nOldTokenTabReplacement,
711             bool bSameDoc, int nRecursion ) const;
712 
713     /** If necessary (name references sheet rOldPos.Tab()) copy and adjust
714         named expression/range from sheet-local to sheet-local, or global to
715         sheet-local if bGlobalNamesToLocal==true.
716 
717         Also copies nested names and adjusts the ocName tokens of the calling name.
718 
719         @param  rSheet
720                 On entry, the original sheet of the named expression/range, <0 global.
721                 On return TRUE, the new sheet. Else unchanged.
722 
723         @param  rIndex
724                 On entry, the original index of the named expression/range.
725                 On return TRUE, the new index, or 0 if a new copied name couldn't be inserted. Else unchanged.
726 
727         @param  rpRangeData
728                 On entry, the pointer to the original named expression/range.
729                 On return TRUE, the pointer to the new copied name, or nullptr if hits happened.
730 
731         @param  rNewPos
732                 New position of formula cell if called for that, else new base
733                 position of a to be created new name adjusted for Tab.
734                 rNewPos.nTab MUST point to the new sheet copied to.
735 
736         @param  rOldPos
737                 Old position of formula cell if called for that, else base
738                 position of the existing name adjusted for Tab.
739                 rOldPos.nTab MUST point to the old sheet copied from.
740 
741         @param  bGlobalNamesToLocal
742                 If TRUE, affected global names are copied to sheet-local names.
743                 If FALSE, global names are copied to global names in another document.
744 
745         @param  bUsedByFormula
746                 If TRUE, forces a global name to be affected/used.
747                 If FALSE, a global name is only affected if it evaluates to be
748                 referencing the sheet.
749 
750         @return TRUE if copied and caller may need to evaluate rpRangeData and rSheet and rIndex.
751                 FALSE if nothing to be done.
752      */
753     bool CopyAdjustRangeName( SCTAB& rSheet, sal_uInt16& rIndex, ScRangeData*& rpRangeData, ScDocument& rNewDoc,
754             const ScAddress& rNewPos, const ScAddress& rOldPos, const bool bGlobalNamesToLocal,
755             const bool bUsedByFormula ) const;
756 
757     /**
758      * Call this immediately before updating all named ranges.
759      */
760     SC_DLLPUBLIC void PreprocessAllRangeNamesUpdate( const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap );
761     SC_DLLPUBLIC void PreprocessRangeNameUpdate();
762     SC_DLLPUBLIC void PreprocessDBDataUpdate();
763     /**
764      * Call this immediately after updating named ranges.
765      */
766     SC_DLLPUBLIC void CompileHybridFormula();
767 
768     /**
769      * Insert a new named expression to the global scope.
770      *
771      * @param rName name for the expression.
772      * @param rPos base position.
773      * @param rExpr formula expression to be associated with the name.  The
774      *              current grammar is used to compile this expression.
775      *
776      * @return true if inserted successfully, false otherwise.
777      */
778     bool InsertNewRangeName( const OUString& rName, const ScAddress& rPos, const OUString& rExpr );
779 
780     /**
781      * Insert a new named expression to a sheet-local scope.
782      *
783      * @param nTab  sheet for local scope.
784      * @param rName name for the expression.
785      * @param rPos base position.
786      * @param rExpr formula expression to be associated with the name.  The
787      *              current grammar is used to compile this expression.
788      *
789      * @return true if inserted successfully, false otherwise.
790      */
791     bool InsertNewRangeName( SCTAB nTab, const OUString& rName, const ScAddress& rPos, const OUString& rExpr );
792 
GetMaxTableNumber() const793     SCTAB GetMaxTableNumber() const { return static_cast<SCTAB>(maTabs.size()) - 1; }
794 
GetColNameRanges()795     ScRangePairList*    GetColNameRanges() { return xColNameRanges.get(); }
GetRowNameRanges()796     ScRangePairList*    GetRowNameRanges() { return xRowNameRanges.get(); }
GetColNameRangesRef()797     ScRangePairListRef& GetColNameRangesRef() { return xColNameRanges; }
GetRowNameRangesRef()798     ScRangePairListRef& GetRowNameRangesRef() { return xRowNameRanges; }
799 
800     SC_DLLPUBLIC SCCOL ClampToAllocatedColumns(SCTAB nTab, SCCOL nCol) const;
801     SC_DLLPUBLIC SCCOL GetAllocatedColumnsCount(SCTAB nTab) const;
802 
GetDBCollection() const803     SC_DLLPUBLIC ScDBCollection* GetDBCollection() const { return pDBCollection.get();}
804     void                         SetDBCollection( std::unique_ptr<ScDBCollection> pNewDBCollection,
805                                                   bool bRemoveAutoFilter = false );
806     const ScDBData*              GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const;
807     ScDBData*                    GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion);
808     SC_DLLPUBLIC const ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
809     SC_DLLPUBLIC ScDBData*       GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
810     void                         RefreshDirtyTableColumnNames();
811     SC_DLLPUBLIC sc::ExternalDataMapper& GetExternalDataMapper();
812 
813     SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, OUString* pName ) const;
814 
815     SC_DLLPUBLIC bool                  HasPivotTable() const;
816     SC_DLLPUBLIC ScDPCollection*       GetDPCollection();
817     SC_DLLPUBLIC const ScDPCollection* GetDPCollection() const;
818     SC_DLLPUBLIC ScDPObject*           GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
819     ScDPObject*                        GetDPAtBlock( const ScRange& rBlock ) const;
820 
821     void                               StopTemporaryChartLock();
822 
823     void                               EnsureGraphicNames();
824 
825     SdrObject*      GetObjectAtPoint( SCTAB nTab, const Point& rPos );
826     bool            HasChartAtPoint( SCTAB nTab, const Point& rPos, OUString& rName );
827 
828     css::uno::Reference< css::chart2::XChartDocument > GetChartByName( const OUString& rChartName );
829 
830     SC_DLLPUBLIC void GetChartRanges( const OUString& rChartName, std::vector< ScRangeList >& rRanges, const ScDocument* pSheetNameDoc );
831     void              SetChartRanges( const OUString& rChartName, const std::vector< ScRangeList >& rRanges );
832 
833     void              UpdateChartArea( const OUString& rChartName, const ScRange& rNewArea,
834                                        bool bColHeaders, bool bRowHeaders, bool bAdd );
835     void              UpdateChartArea( const OUString& rChartName,
836                                        const ScRangeListRef& rNewList,
837                                        bool bColHeaders, bool bRowHeaders, bool bAdd );
838     void              GetOldChartParameters( const OUString& rName,
839                                              ScRangeList& rRanges, bool& rColHeaders, bool& rRowHeaders );
840     css::uno::Reference<
841             css::embed::XEmbeddedObject >
842                     FindOleObjectByName( const OUString& rName );
843 
844     SC_DLLPUBLIC void MakeTable( SCTAB nTab,bool _bNeedsNameCheck = true );
845 
GetVisibleTab() const846     SCTAB             GetVisibleTab() const       { return nVisibleTab; }
SetVisibleTab(SCTAB nTab)847     SC_DLLPUBLIC void SetVisibleTab(SCTAB nTab)   { nVisibleTab = nTab; }
GetPosLeft() const848     SCCOL             GetPosLeft() const          { return nPosLeft; }
SetPosLeft(SCCOL nCol)849     SC_DLLPUBLIC void SetPosLeft(SCCOL nCol)      { nPosLeft = nCol; }
GetPosTop() const850     SCROW             GetPosTop() const           { return nPosTop; }
SetPosTop(SCROW nRow)851     SC_DLLPUBLIC void SetPosTop(SCROW nRow)       { nPosTop = nRow; }
852 
853     SC_DLLPUBLIC bool HasTable( SCTAB nTab ) const;
854     SC_DLLPUBLIC bool GetHashCode( SCTAB nTab, sal_Int64& rHashCode) const;
855     SC_DLLPUBLIC bool GetName( SCTAB nTab, OUString& rName ) const;
856     SC_DLLPUBLIC bool GetCodeName( SCTAB nTab, OUString& rName ) const;
857     SC_DLLPUBLIC bool SetCodeName( SCTAB nTab, const OUString& rName );
858     SC_DLLPUBLIC bool GetTable( const OUString& rName, SCTAB& rTab ) const;
MaxCol() const859     SC_DLLPUBLIC SCCOL MaxCol() const { return mnMaxCol; }
MaxRow() const860     SC_DLLPUBLIC SCROW MaxRow() const { return mnMaxRow; }
861 
862     SC_DLLPUBLIC std::vector<OUString> GetAllTableNames() const;
863 
864     OUString GetCopyTabName(SCTAB nTab) const;
865 
866     SC_DLLPUBLIC void      SetAnonymousDBData(SCTAB nTab, std::unique_ptr<ScDBData> pDBData);
867     SC_DLLPUBLIC ScDBData* GetAnonymousDBData(SCTAB nTab);
868 
869     /** One document global anonymous database range for temporary operations,
870         used if the corresponding sheet-local anonymous database range is
871         already used with AutoFilter and range differs. Not stored in document
872         files. */
873     SC_DLLPUBLIC void             SetAnonymousDBData(std::unique_ptr<ScDBData> pDBData);
874     SC_DLLPUBLIC ScDBData*        GetAnonymousDBData();
875 
876     SC_DLLPUBLIC SCTAB            GetTableCount() const;
GetFormatExchangeList() const877     SvNumberFormatterIndexTable*  GetFormatExchangeList() const { return pFormatExchangeList; }
878 
879     SC_DLLPUBLIC ScDocProtection*      GetDocProtection() const;
880     SC_DLLPUBLIC void                  SetDocProtection(const ScDocProtection* pProtect);
881     SC_DLLPUBLIC bool                  IsDocProtected() const;
882     bool                               IsDocEditable() const;
883     SC_DLLPUBLIC bool                  IsTabProtected( SCTAB nTab ) const;
884     SC_DLLPUBLIC    ScTableProtection* GetTabProtection( SCTAB nTab ) const;
885     SC_DLLPUBLIC void                  SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect);
886     void                               CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest);
887 
888     void            LockTable(SCTAB nTab);
889     void            UnlockTable(SCTAB nTab);
890 
891     bool            IsBlockEditable( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
892                                      SCCOL nEndCol, SCROW nEndRow,
893                                      bool* pOnlyNotBecauseOfMatrix = nullptr,
894                                      bool bNoMatrixAtAll = false ) const;
895     bool            IsSelectionEditable( const ScMarkData& rMark,
896                                          bool* pOnlyNotBecauseOfMatrix = nullptr ) const;
897     bool            HasSelectedBlockMatrixFragment( SCCOL nStartCol, SCROW nStartRow,
898                                                     SCCOL nEndCol, SCROW nEndRow,
899                                                     const ScMarkData& rMark ) const;
900 
901     bool IsEditActionAllowed( sc::ColRowEditAction eAction, SCTAB nTab, SCCOLROW nStart, SCCOLROW nEnd ) const;
902     bool IsEditActionAllowed( sc::ColRowEditAction eAction, const ScMarkData& rMark, SCCOLROW nStart, SCCOLROW nEnd ) const;
903 
904     SC_DLLPUBLIC bool GetMatrixFormulaRange( const ScAddress& rCellPos, ScRange& rMatrix );
905 
IsEmbedded() const906     bool            IsEmbedded() const { return bIsEmbedded;}
907     void            GetEmbedded( ScRange& rRange ) const;
908     void            SetEmbedded( const ScRange& rRange );
909     void            ResetEmbedded();
910     tools::Rectangle       GetEmbeddedRect() const;                        // 1/100 mm
911     void            SetEmbedded( SCTAB nTab, const tools::Rectangle& rRect );          // from VisArea (1/100 mm)
912 
913     static SC_DLLPUBLIC bool ValidTabName( const OUString& rName );
914 
915     SC_DLLPUBLIC bool           ValidNewTabName( const OUString& rName ) const;
916     SC_DLLPUBLIC void           CreateValidTabName(OUString& rName) const;
917     SC_DLLPUBLIC void           CreateValidTabNames(std::vector<OUString>& aNames, SCTAB nCount) const;
918 
919     void AppendTabOnLoad(const OUString& rName);
920     void SetTabNameOnLoad(SCTAB nTab, const OUString& rName);
921     void InvalidateStreamOnSave();
922 
923     SC_DLLPUBLIC bool           InsertTab( SCTAB nPos, const OUString& rName,
924                                           bool bExternalDocument = false, bool bUndoDeleteTab = false );
925 
926     SC_DLLPUBLIC bool           InsertTabs( SCTAB nPos, const std::vector<OUString>& rNames,
927                                             bool bNamesValid = false );
928     SC_DLLPUBLIC bool           DeleteTabs( SCTAB nTab, SCTAB nSheets );
929     SC_DLLPUBLIC bool           DeleteTab( SCTAB nTab );
930     SC_DLLPUBLIC bool           RenameTab( SCTAB nTab, const OUString& rName,
931                                            bool bExternalDocument = false );
932     bool                        MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress = nullptr );
933     bool                        CopyTab( SCTAB nOldPos, SCTAB nNewPos,
934                                          const ScMarkData* pOnlyMarked = nullptr );
935     SC_DLLPUBLIC sal_uLong      TransferTab(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDestPos,
936                                             bool bInsertNew = true,
937                                             bool bResultsOnly = false );
938     SC_DLLPUBLIC void           TransferDrawPage(const ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDestPos);
939     SC_DLLPUBLIC void           SetVisible( SCTAB nTab, bool bVisible );
940     SC_DLLPUBLIC bool           IsVisible( SCTAB nTab ) const;
941     bool                        IsStreamValid( SCTAB nTab ) const;
942     void                        SetStreamValid( SCTAB nTab, bool bSet, bool bIgnoreLock = false );
943     void                        LockStreamValid( bool bLock );
IsStreamValidLocked() const944     bool                        IsStreamValidLocked() const { return mbStreamValidLocked; }
945     bool                        IsPendingRowHeights( SCTAB nTab ) const;
946     void                        SetPendingRowHeights( SCTAB nTab, bool bSet );
947     SC_DLLPUBLIC void           SetLayoutRTL( SCTAB nTab, bool bRTL );
948     SC_DLLPUBLIC bool           IsLayoutRTL( SCTAB nTab ) const;
949     SC_DLLPUBLIC bool           IsNegativePage( SCTAB nTab ) const;
950     SC_DLLPUBLIC void           SetScenario( SCTAB nTab, bool bFlag );
951     SC_DLLPUBLIC bool           IsScenario( SCTAB nTab ) const;
952     SC_DLLPUBLIC void           GetScenarioData(SCTAB nTab, OUString& rComment,
953                                                 Color& rColor, ScScenarioFlags &rFlags) const;
954     SC_DLLPUBLIC void           SetScenarioData(SCTAB nTab, const OUString& rComment,
955                                                 const Color& rColor, ScScenarioFlags nFlags);
956     SC_DLLPUBLIC Color          GetTabBgColor( SCTAB nTab ) const;
957     SC_DLLPUBLIC void           SetTabBgColor( SCTAB nTab, const Color& rColor );
958     SC_DLLPUBLIC bool           IsDefaultTabBgColor( SCTAB nTab ) const;
959     void                        GetScenarioFlags(SCTAB nTab, ScScenarioFlags &rFlags) const;
960     SC_DLLPUBLIC bool           IsActiveScenario( SCTAB nTab ) const;
961     SC_DLLPUBLIC void           SetActiveScenario( SCTAB nTab, bool bActive );      // only for Undo etc.
962     SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const;
GetGrammar() const963     SC_DLLPUBLIC formula::FormulaGrammar::Grammar           GetGrammar() const { return eGrammar;}
964     SC_DLLPUBLIC void                                       SetGrammar( formula::FormulaGrammar::Grammar eGram );
965     SC_DLLPUBLIC ScLinkMode                                 GetLinkMode( SCTAB nTab ) const;
966     bool                                                    IsLinked( SCTAB nTab ) const;
967     SC_DLLPUBLIC OUString                                   GetLinkDoc( SCTAB nTab ) const;
968     OUString                                                GetLinkFlt( SCTAB nTab ) const;
969     OUString                                                GetLinkOpt( SCTAB nTab ) const;
970     SC_DLLPUBLIC OUString                                   GetLinkTab( SCTAB nTab ) const;
971     sal_uLong                                               GetLinkRefreshDelay( SCTAB nTab ) const;
972     void                                                    SetLink( SCTAB nTab, ScLinkMode nMode, const OUString& rDoc,
973                                                                      const OUString& rFilter, const OUString& rOptions,
974                                                                      const OUString& rTabName, sal_uLong nRefreshDelay );
975     bool                                                    HasLink( const OUString& rDoc,
976                                                                      const OUString& rFilter, const OUString& rOptions ) const;
977     SC_DLLPUBLIC bool                                       LinkExternalTab( SCTAB& nTab, const OUString& aDocTab,
978                                                                              const OUString& aFileName,
979                                                                              const OUString& aTabName );
980 
HasExternalRefManager() const981     bool                               HasExternalRefManager() const { return pExternalRefMgr.get(); }
982     SC_DLLPUBLIC ScExternalRefManager* GetExternalRefManager() const;
983     bool                               IsInExternalReferenceMarking() const;
984     void                               MarkUsedExternalReferences();
985     bool                               MarkUsedExternalReferences( const ScTokenArray& rArr, const ScAddress& rPos );
986 
987     /** Returns the pool containing external formula parsers. Creates the pool
988         on first call. */
989     ScFormulaParserPool& GetFormulaParserPool() const;
990 
991     bool            HasAreaLinks() const;
992     void            UpdateExternalRefLinks(weld::Window* pWin);
993     void            UpdateAreaLinks();
994 
995                     // originating DDE links
IncInDdeLinkUpdate()996     void            IncInDdeLinkUpdate() { if ( nInDdeLinkUpdate < 255 ) ++nInDdeLinkUpdate; }
DecInDdeLinkUpdate()997     void            DecInDdeLinkUpdate() { if ( nInDdeLinkUpdate ) --nInDdeLinkUpdate; }
IsInDdeLinkUpdate() const998     bool            IsInDdeLinkUpdate() const   { return nInDdeLinkUpdate != 0; }
999 
1000     SC_DLLPUBLIC void CopyDdeLinks( ScDocument* pDestDoc ) const;
1001 
1002     /** Tries to find a DDE link with the specified connection data.
1003         @param rnDdePos  (out-param) Returns the index of the DDE link (does not include other links from link manager).
1004         @return  true = DDE link found, rnDdePos valid. */
1005     SC_DLLPUBLIC bool FindDdeLink( const OUString& rAppl, const OUString& rTopic,
1006                                    const OUString& rItem, sal_uInt8 nMode, size_t& rnDdePos );
1007 
1008     /** Returns the connection data of the specified DDE link.
1009         @param nDdePos  Index of the DDE link (does not include other links from link manager).
1010         @param rAppl  (out-param) The application name.
1011         @param rTopic  (out-param) The DDE topic.
1012         @param rItem  (out-param) The DDE item.
1013         @return  true = DDE link found, out-parameters valid. */
1014     bool            GetDdeLinkData( size_t nDdePos, OUString& rAppl, OUString& rTopic, OUString& rItem ) const;
1015     /** Returns the link mode of the specified DDE link.
1016         @param nDdePos  Index of the DDE link (does not include other links from link manager).
1017         @param rnMode  (out-param) The link mode of the specified DDE link.
1018         @return  true = DDE link found, rnMode valid. */
1019     bool            GetDdeLinkMode( size_t nDdePos, sal_uInt8& rnMode ) const;
1020     /** Returns the result matrix of the specified DDE link.
1021         @param nDdePos  Index of the DDE link (does not include other links from link manager).
1022         @return  The result matrix, if the DDE link has been found, 0 otherwise. */
1023     SC_DLLPUBLIC const ScMatrix* GetDdeLinkResultMatrix( size_t nDdePos ) const;
1024 
1025     /** Tries to find a DDE link or creates a new, if not extant.
1026         @param pResults  If not 0, sets the matrix as DDE link result matrix (also for existing links).
1027         @return  true = DDE link found; false = Unpredictable error occurred, no DDE link created. */
1028     SC_DLLPUBLIC bool            CreateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem, sal_uInt8 nMode, const ScMatrixRef& pResults );
1029     /** Sets a result matrix for the specified DDE link.
1030         @param nDdePos  Index of the DDE link (does not include other links from link manager).
1031         @param pResults  The array containing all results of the DDE link (intrusive-ref-counted, do not delete).
1032         @return  true = DDE link found and matrix set. */
1033     bool            SetDdeLinkResultMatrix( size_t nDdePos, const ScMatrixRef& pResults );
1034 
1035     SfxBindings*                    GetViewBindings();
GetDocumentShell() const1036     SfxObjectShell*                 GetDocumentShell() const    { return mpShell; }
GetDrawLayer()1037     SC_DLLPUBLIC ScDrawLayer*       GetDrawLayer() { return mpDrawLayer.get();  }
GetDrawLayer() const1038     SC_DLLPUBLIC const ScDrawLayer* GetDrawLayer() const { return mpDrawLayer.get();  }
1039     SfxBroadcaster*                 GetDrawBroadcaster();       // to avoid header
1040     void                            BeginDrawUndo();
1041 
1042     void            BeginUnoRefUndo();
HasUnoRefUndo() const1043     bool            HasUnoRefUndo() const       { return ( pUnoRefUndoList != nullptr ); }
1044     [[nodiscard]]
1045     std::unique_ptr<ScUnoRefList> EndUnoRefUndo();            // must be deleted by caller!
GetNewUnoId()1046     sal_Int64       GetNewUnoId() { return ++nUnoObjectId; }
1047     void            AddUnoRefChange( sal_Int64 nId, const ScRangeList& rOldRanges );
1048 
1049     static bool IsChart( const SdrObject* pObject );
1050 
1051     void              UpdateChartRef( UpdateRefMode eUpdateRefMode,
1052                                     SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
1053                                     SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
1054                                     SCCOL nDx, SCROW nDy, SCTAB nDz );
1055                     //! only assigns the new RangeList, no ChartListener or the like
1056     void            SetChartRangeList( const OUString& rChartName,
1057                                        const ScRangeListRef& rNewRangeListRef );
1058 
1059     void            StartAnimations( SCTAB nTab );
1060 
1061     bool            HasBackgroundDraw( SCTAB nTab, const tools::Rectangle& rMMRect ) const;
1062     bool            HasAnyDraw( SCTAB nTab, const tools::Rectangle& rMMRect ) const;
1063 
1064     const ScSheetEvents* GetSheetEvents( SCTAB nTab ) const;
1065     void                 SetSheetEvents( SCTAB nTab, std::unique_ptr<ScSheetEvents> pNew );
1066     bool                 HasSheetEventScript( SCTAB nTab, ScSheetEventId nEvent, bool bWithVbaEvents = false ) const;
1067     bool                 HasAnySheetEventScript( ScSheetEventId nEvent, bool bWithVbaEvents = false ) const;  // on any sheet
1068 
1069     bool            HasAnyCalcNotification() const;
1070     bool            HasCalcNotification( SCTAB nTab ) const;
1071     void            SetCalcNotification( SCTAB nTab );
1072     void            ResetCalcNotifications();
1073 
1074     SC_DLLPUBLIC ScOutlineTable*    GetOutlineTable( SCTAB nTab, bool bCreate = false );
1075     bool                            SetOutlineTable( SCTAB nTab, const ScOutlineTable* pNewOutline );
1076 
1077     void                            DoAutoOutline( SCCOL nStartCol, SCROW nStartRow,
1078                                                    SCCOL nEndCol, SCROW nEndRow, SCTAB nTab );
1079 
1080     bool            DoSubTotals( SCTAB nTab, ScSubTotalParam& rParam );
1081     void            RemoveSubTotals( SCTAB nTab, ScSubTotalParam& rParam );
1082     bool            TestRemoveSubTotals( SCTAB nTab, const ScSubTotalParam& rParam );
1083     bool            HasSubTotalCells( const ScRange& rRange );
1084 
1085     SC_DLLPUBLIC void EnsureTable( SCTAB nTab );
1086 
1087                     //  return TRUE = number format is set
1088     SC_DLLPUBLIC bool SetString( SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString& rString,
1089                                  const ScSetStringParam * pParam = nullptr );
1090     SC_DLLPUBLIC bool SetString( const ScAddress& rPos, const OUString& rString,
1091                                  const ScSetStringParam* pParam = nullptr );
1092 
1093     /**
1094      * This method manages the lifecycle of the passed edit text object. When
1095      * the text is successfully inserted, the cell takes over the ownership of
1096      * the text object. If not, the text object gets deleted.
1097      *
1098      * <p>The caller must ensure that the passed edit text object <i>uses the
1099      * SfxItemPool instance returned from ScDocument::GetEditPool()</i>.
1100      * This is very important.</p>
1101      */
1102     SC_DLLPUBLIC bool  SetEditText( const ScAddress& rPos, std::unique_ptr<EditTextObject> pEditText );
1103     void               SetEditText( const ScAddress& rPos, const EditTextObject& rEditText, const SfxItemPool* pEditPool );
1104     SC_DLLPUBLIC void  SetEditText( const ScAddress& rPos, const OUString& rStr );
1105     SC_DLLPUBLIC SCROW GetFirstEditTextRow( const ScRange& rRange ) const;
1106 
1107     /**
1108      * Call this if you are not sure whether to put this as an edit text or a
1109      * simple text.
1110      */
1111     SC_DLLPUBLIC void SetTextCell( const ScAddress& rPos, const OUString& rStr );
1112     void              SetEmptyCell( const ScAddress& rPos );
1113     SC_DLLPUBLIC void SetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, const double& rVal );
1114     SC_DLLPUBLIC void SetValue( const ScAddress& rPos, double fVal );
1115     void              SetValues( const ScAddress& rPos, const std::vector<double>& rVals );
1116     void              SetError( SCCOL nCol, SCROW nRow, SCTAB nTab, const FormulaError nError);
1117     SC_DLLPUBLIC void SetFormula( const ScAddress& rPos, const ScTokenArray& rArray );
1118     SC_DLLPUBLIC void SetFormula( const ScAddress& rPos, const OUString& rFormula,
1119                                   formula::FormulaGrammar::Grammar eGram );
1120 
1121     /**
1122      * Set formula cell, and transfer its ownership to the document. This call
1123      * attempts to group the passed formula cell with the adjacent cells or
1124      * cell groups if appropriate.
1125      *
1126      * @return pCell if it was successfully inserted, NULL otherwise. pCell
1127      *         is deleted automatically on failure to insert.
1128      */
1129     SC_DLLPUBLIC ScFormulaCell*  SetFormulaCell( const ScAddress& rPos, ScFormulaCell* pCell );
1130     bool                         SetFormulaCells( const ScAddress& rPos, std::vector<ScFormulaCell*>& rCells );
1131 
1132     /**
1133      * Check if there is at least one formula cell in specified range.
1134      */
1135     bool              HasFormulaCell( const ScRange& rRange ) const;
1136     SC_DLLPUBLIC void InsertMatrixFormula(SCCOL nCol1, SCROW nRow1,
1137                                         SCCOL nCol2, SCROW nRow2,
1138                                         const ScMarkData& rMark,
1139                                         const OUString& rFormula,
1140                                         const ScTokenArray* p = nullptr,
1141                                         const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT );
1142     SC_DLLPUBLIC void InsertTableOp(const ScTabOpParam& rParam,   // multi-operation
1143                                     SCCOL nCol1, SCROW nRow1,
1144                                     SCCOL nCol2, SCROW nRow2, const ScMarkData& rMark);
1145 
1146     SC_DLLPUBLIC OUString GetString( SCCOL nCol, SCROW nRow, SCTAB nTab,
1147                                      const ScInterpreterContext* pContext = nullptr ) const;
1148     SC_DLLPUBLIC OUString GetString( const ScAddress& rPos,
1149                                      const ScInterpreterContext* pContext = nullptr ) const;
1150 
1151     /**
1152      * Return a pointer to the double value stored in value cell.
1153      *
1154      * @param rPos cell position
1155      *
1156      * @return pointer to the double value stored in a numeric cell, or NULL
1157      *         if the cell at specified position is not a numeric cell.
1158      */
1159     double* GetValueCell( const ScAddress& rPos );
1160 
1161     SC_DLLPUBLIC svl::SharedStringPool&       GetSharedStringPool();
1162     const svl::SharedStringPool&              GetSharedStringPool() const;
1163 
1164     svl::SharedString                         GetSharedString( const ScAddress& rPos ) const;
1165 
1166     std::shared_ptr<sc::FormulaGroupContext>& GetFormulaGroupContext();
1167     void                                      DiscardFormulaGroupContext();
BlockFormulaGroupContextDiscard(bool block)1168     void                                      BlockFormulaGroupContextDiscard( bool block )
1169                                                   { mbFormulaGroupCxtBlockDiscard = block; }
1170 
1171     SC_DLLPUBLIC void                         GetInputString( SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rString );
1172     FormulaError                              GetStringForFormula( const ScAddress& rPos, OUString& rString );
1173     SC_DLLPUBLIC double                       GetValue( const ScAddress& rPos ) const;
1174     SC_DLLPUBLIC double                       GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1175     SC_DLLPUBLIC void                         GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue ) const;
1176     SC_DLLPUBLIC const EditTextObject*        GetEditText( const ScAddress& rPos ) const;
1177     void                                      RemoveEditTextCharAttribs( const ScAddress& rPos, const ScPatternAttr& rAttr );
1178     SC_DLLPUBLIC double                       RoundValueAsShown( double fVal, sal_uInt32 nFormat, const ScInterpreterContext* pContext = nullptr ) const;
1179     SC_DLLPUBLIC void                         GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab,
1180                                                                sal_uInt32& rFormat ) const;
1181     sal_uInt32                                GetNumberFormat( const ScRange& rRange ) const;
1182     SC_DLLPUBLIC sal_uInt32                   GetNumberFormat( const ScInterpreterContext& rContext, const ScAddress& ) const;
1183     void                                      SetNumberFormat( const ScAddress& rPos, sal_uInt32 nNumberFormat );
1184 
1185     void                                      GetNumberFormatInfo( const ScInterpreterContext& rContext, SvNumFormatType& nType, sal_uInt32& nIndex, const ScAddress& rPos ) const;
1186     SC_DLLPUBLIC const ScFormulaCell*         GetFormulaCell( const ScAddress& rPos ) const;
1187     SC_DLLPUBLIC ScFormulaCell*               GetFormulaCell( const ScAddress& rPos );
1188     SC_DLLPUBLIC void                         GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rFormula ) const;
1189     SC_DLLPUBLIC void                         GetCellType( SCCOL nCol, SCROW nRow, SCTAB nTab, CellType& rCellType ) const;
1190     SC_DLLPUBLIC CellType                     GetCellType( const ScAddress& rPos ) const;
1191 
1192     SC_DLLPUBLIC bool                         HasData( SCCOL nCol, SCROW nRow, SCTAB nTab );
1193     SC_DLLPUBLIC bool                         HasStringData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1194     SC_DLLPUBLIC bool                         HasValueData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1195     SC_DLLPUBLIC bool                         HasValueData( const ScAddress& rPos ) const;
1196     bool                                      HasStringCells( const ScRange& rRange ) const;
1197 
1198     /** Returns true, if there is any data to create a selection list for rPos. */
1199     bool            HasSelectionData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1200     bool            HasValidationData( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1201 
1202     /**
1203      * Check if the specified range contains either: 1) one non-empty cell, 2)
1204      * more than one non-empty cells, or 3) totally empty.  In case the range
1205      * contains at least one non-empty cell, specify the position of the first
1206      * non-empty cell.
1207      */
1208     sc::MultiDataCellState HasMultipleDataCells( const ScRange& rRange ) const;
1209 
1210     /** Notes **/
1211     SC_DLLPUBLIC ScPostIt*       GetNote(const ScAddress& rPos);
1212     SC_DLLPUBLIC ScPostIt*       GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab);
1213     void                         SetNote(const ScAddress& rPos, std::unique_ptr<ScPostIt> pNote);
1214     void                         SetNote(SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPostIt> pNote);
1215     SC_DLLPUBLIC bool            HasNote(const ScAddress& rPos) const;
1216     bool                         HasNote(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
1217     SC_DLLPUBLIC bool            HasColNotes(SCCOL nCol, SCTAB nTab) const;
1218     SC_DLLPUBLIC bool            HasTabNotes(SCTAB nTab) const;
1219     bool                         HasNotes() const;
1220     SC_DLLPUBLIC std::unique_ptr<ScPostIt> ReleaseNote(const ScAddress& rPos);
1221     SC_DLLPUBLIC ScPostIt*       GetOrCreateNote(const ScAddress& rPos);
1222     SC_DLLPUBLIC ScPostIt*       CreateNote(const ScAddress& rPos);
1223     size_t                       GetNoteCount( SCTAB nTab, SCCOL nCol ) const;
1224 
1225     /**
1226      * Ensure that all note objects have an associated sdr object.  The export
1227      * code uses sdr objects to export note data.
1228      */
1229     void                 CreateAllNoteCaptions();
1230     void                 ForgetNoteCaptions( const ScRangeList& rRanges, bool bPreserveData );
1231     CommentCaptionState  GetAllNoteCaptionsState( const ScRangeList& rRanges);
1232 
1233     ScAddress GetNotePosition( size_t nIndex ) const;
1234     ScAddress GetNotePosition( size_t nIndex, SCTAB nTab ) const;
1235     SCROW     GetNotePosition( SCTAB nTab, SCCOL nCol, size_t nIndex ) const;
1236 
1237     SC_DLLPUBLIC void GetAllNoteEntries( std::vector<sc::NoteEntry>& rNotes ) const;
1238     SC_DLLPUBLIC void GetAllNoteEntries( SCTAB nTab, std::vector<sc::NoteEntry>& rNotes ) const;
1239     void              GetNotesInRange( const ScRangeList& rRange, std::vector<sc::NoteEntry>& rNotes ) const;
1240     bool              ContainsNotesInRange( const ScRangeList& rRange ) const;
1241 
1242     SC_DLLPUBLIC void SetDrawPageSize(SCTAB nTab);
1243 
1244     bool              IsMerged( const ScAddress& rPos ) const;
1245 
1246     void              ExtendMergeSel( SCCOL nStartCol, SCROW nStartRow,
1247                                       SCCOL& rEndCol, SCROW& rEndRow, const ScMarkData& rMark,
1248                                       bool bRefresh = false );
1249     SC_DLLPUBLIC bool ExtendMerge( SCCOL nStartCol, SCROW nStartRow,
1250                                    SCCOL& rEndCol, SCROW& rEndRow, SCTAB nTab,
1251                                    bool bRefresh = false );
1252     bool              ExtendMerge( ScRange& rRange, bool bRefresh = false );
1253     SC_DLLPUBLIC void ExtendTotalMerge( ScRange& rRange ) const;
1254     SC_DLLPUBLIC void ExtendOverlapped( SCCOL& rStartCol, SCROW& rStartRow,
1255                                         SCCOL nEndCol, SCROW nEndRow, SCTAB nTab ) const;
1256     SC_DLLPUBLIC void ExtendOverlapped( ScRange& rRange ) const;
1257 
1258     bool              RefreshAutoFilter( SCCOL nStartCol, SCROW nStartRow,
1259                                          SCCOL nEndCol, SCROW nEndRow, SCTAB nTab );
1260 
1261     SC_DLLPUBLIC void DoMergeContents( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
1262                                        SCCOL nEndCol, SCROW nEndRow );
1263     SC_DLLPUBLIC void DoEmptyBlock( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
1264                                     SCCOL nEndCol, SCROW nEndRow );
1265                     //  without checking:
1266     SC_DLLPUBLIC void DoMerge( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
1267                                SCCOL nEndCol, SCROW nEndRow, bool bDeleteCaptions = true );
1268     void              RemoveMerge( SCCOL nCol, SCROW nRow, SCTAB nTab );
1269 
1270     bool              IsBlockEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
1271                                     SCCOL nEndCol, SCROW nEndRow, bool bIgnoreNotes = false ) const;
1272     bool              IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
1273                                     SCCOL nEndCol, SCROW nEndRow,
1274                                     bool bLeftIsEmpty = false,
1275                                     ScRange* pLastRange = nullptr,
1276                                     tools::Rectangle* pLastMM = nullptr ) const;
1277 
1278     void            SkipOverlapped( SCCOL& rCol, SCROW& rRow, SCTAB nTab ) const;
1279     bool            IsHorOverlapped( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1280     bool            IsVerOverlapped( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1281 
1282     SC_DLLPUBLIC bool HasAttrib( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
1283                                  SCCOL nCol2, SCROW nRow2, SCTAB nTab2, HasAttrFlags nMask ) const;
1284     SC_DLLPUBLIC bool HasAttrib( const ScRange& rRange, HasAttrFlags nMask ) const;
1285 
1286     SC_DLLPUBLIC void GetBorderLines( SCCOL nCol, SCROW nRow, SCTAB nTab,
1287                                     const ::editeng::SvxBorderLine** ppLeft,
1288                                     const ::editeng::SvxBorderLine** ppTop,
1289                                     const ::editeng::SvxBorderLine** ppRight,
1290                                     const ::editeng::SvxBorderLine** ppBottom ) const;
1291 
1292     void              ResetChanged( const ScRange& rRange );
1293 
1294     void              CheckVectorizationState();
1295     void              SetAllFormulasDirty( const sc::SetFormulaDirtyContext& rCxt );
1296     void              SetDirty( const ScRange&, bool bIncludeEmptyCells );
1297     void              SetTableOpDirty( const ScRange& );  // for Interpreter TableOp
1298     void              InterpretDirtyCells( const ScRangeList& rRanges );
1299     SC_DLLPUBLIC void CalcAll();
1300     SC_DLLPUBLIC void CalcAfterLoad( bool bStartListening = true );
1301     void              CompileAll();
1302     void              CompileXML();
1303 
1304     /**
1305      * Re-compile formula cells with error.
1306      *
1307      * @param nErrCode specified error code to match. Only those cells with
1308      *                 this error code will be re-compiled.  If this value is
1309      *                 0, cells with any error values will be re-compiled.
1310      *
1311      * @return true if at least one cell is re-compiled, false if no cells are
1312      *         re-compiled.
1313      */
1314     bool CompileErrorCells(FormulaError nErrCode);
1315 
GetAutoNameCache()1316     ScAutoNameCache*     GetAutoNameCache()     { return pAutoNameCache.get(); }
1317     void                 SetPreviewFont( std::unique_ptr<SfxItemSet> pFontSet );
GetPreviewFont()1318     SfxItemSet*          GetPreviewFont() { return pPreviewFont.get(); }
1319     SfxItemSet*          GetPreviewFont( SCCOL nCol, SCROW nRow, SCTAB nTab );
GetPreviewSelection() const1320     const ScMarkData&    GetPreviewSelection() const { return maPreviewSelection; }
1321     void                 SetPreviewSelection( const ScMarkData& rSel );
GetPreviewCellStyle()1322     ScStyleSheet*        GetPreviewCellStyle() { return pPreviewCellStyle; }
1323     ScStyleSheet*        GetPreviewCellStyle( SCCOL nCol, SCROW nRow, SCTAB nTab );
SetPreviewCellStyle(ScStyleSheet * pStyle)1324     void                 SetPreviewCellStyle( ScStyleSheet* pStyle ) { pPreviewCellStyle = pStyle; }
1325     SC_DLLPUBLIC  void   SetAutoNameCache(  std::unique_ptr<ScAutoNameCache> pCache );
1326 
1327                     /** Creates a ScLookupCache cache for the range if it
1328                         doesn't already exist. */
1329     ScLookupCache & GetLookupCache( const ScRange & rRange, ScInterpreterContext* pContext );
1330                     /** Only ScLookupCache dtor uses RemoveLookupCache(), do
1331                         not use elsewhere! */
1332     void            RemoveLookupCache( ScLookupCache & rCache );
1333                     /** Zap all caches. */
1334     void            ClearLookupCaches();
1335 
1336                     // calculate automatically
1337     SC_DLLPUBLIC void SetAutoCalc( bool bNewAutoCalc );
GetAutoCalc() const1338     SC_DLLPUBLIC bool GetAutoCalc() const { return bAutoCalc; }
1339                     // calculate automatically in/from/for ScDocShell disabled
SetAutoCalcShellDisabled(bool bNew)1340     void            SetAutoCalcShellDisabled( bool bNew ) { bAutoCalcShellDisabled = bNew; }
IsAutoCalcShellDisabled() const1341     bool            IsAutoCalcShellDisabled() const { return bAutoCalcShellDisabled; }
1342                     // ForcedFormulas are to be calculated
SetForcedFormulaPending(bool bNew)1343     void            SetForcedFormulaPending( bool bNew ) { bForcedFormulaPending = bNew; }
IsForcedFormulaPending() const1344     bool            IsForcedFormulaPending() const { return bForcedFormulaPending; }
1345                     // if CalcFormulaTree() is currently running
IsCalculatingFormulaTree() const1346     bool            IsCalculatingFormulaTree() const { return bCalculatingFormulaTree; }
1347     /// If set, joining cells into shared formula groups will be delayed until reset again
1348     /// (RegroupFormulaCells() will be called as needed).
1349     void            DelayFormulaGrouping( bool delay );
IsDelayedFormulaGrouping() const1350     bool            IsDelayedFormulaGrouping() const { return pDelayedFormulaGrouping.get() != nullptr; }
1351     /// To be used only by SharedFormulaUtil::joinFormulaCells().
1352     void            AddDelayedFormulaGroupingCell( const ScFormulaCell* cell );
1353 
1354     FormulaError    GetErrCode( const ScAddress& ) const;
1355 
1356                     /** Shrink a range to only include data area.
1357 
1358                         This is not the actually used area within the
1359                         selection, but the bounds of the sheet's data area
1360                         instead.
1361 
1362                         @returns TRUE if the area passed intersected the data
1363                                  area, FALSE if not, in which case the values
1364                                  obtained may be out of bounds, not in order or
1365                                  unmodified. TRUE does not mean that there
1366                                  actually is any data within the selection.
1367                      */
1368     bool            ShrinkToDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow ) const;
1369 
1370                     /** Shrink a range to only include used data area.
1371 
1372                         @param o_bShrunk
1373                                Out parameter, true if area was shrunk, false if not.
1374                         @param  bStickyTopRow
1375                                 If TRUE, do not adjust the top row.
1376                         @param  bStickyLeftCol
1377                                 If TRUE, do not adjust the left column.
1378                         @param  bConsiderCellNotes
1379                                 If TRUE, consider the presence of cell notes besides data.
1380                         @param  bConsiderCellDrawObjects
1381                                 If TRUE, consider the presence of draw objects anchored to the cell.
1382 
1383                         @returns true if there is any data, false if not.
1384                      */
1385     bool            ShrinkToUsedDataArea( bool& o_bShrunk,
1386                                           SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow,
1387                                           SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly,
1388                                           bool bStickyTopRow = false, bool bStickyLeftCol = false,
1389                                           bool bConsiderCellNotes = false,
1390                                           bool bConsiderCellDrawObjects = false ) const;
1391 
1392     /**
1393      * Return the last non-empty row position in given columns that's no
1394      * greater than the initial last row position, or 0 if the columns are
1395      * empty. A negative value is returned if the given sheet or column
1396      * positions are invalid.
1397      *
1398      * <p>It starts from the specified last row position, and finds the first
1399      * non-empty row position in the upward direction if the start row
1400      * position is empty.</p>
1401      */
1402     SCROW GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const;
1403 
1404     /**
1405      * Return the smallest area containing at least all contiguous cells
1406      * having data. This area is a square containing also empty cells. It may
1407      * shrink or extend the area given as input Flags as modifiers:
1408      *
1409      * @param bIncludeOld when true, ensure that the returned area contains at
1410      *                   least the initial area even if the actual data area
1411      *                   is smaller than the initial area.
1412      *
1413      * @param bOnlyDown when true, extend / shrink the data area only in a
1414      *                  downward direction i.e. only modify the end row
1415      *                  position.
1416      */
1417     SC_DLLPUBLIC void           GetDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow,
1418                                              SCCOL& rEndCol, SCROW& rEndRow,
1419                                              bool bIncludeOld, bool bOnlyDown ) const;
1420 
1421     /**
1422      * Returns true if there is a non-empty subrange in the range given as input.
1423      * In that case it also modifies rRange to largest subrange that does not
1424      * have empty col/row inrange-segments in the beginning/end.
1425      * It returns false if rRange is completely empty and in this case rRange is
1426      * left unmodified.
1427     */
1428     bool                        GetDataAreaSubrange(ScRange& rRange) const;
1429 
1430     SC_DLLPUBLIC bool           GetCellArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const;
1431     SC_DLLPUBLIC bool           GetTableArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const;
1432     SC_DLLPUBLIC bool           GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
1433                                               bool bNotes = true ) const;
1434     SC_DLLPUBLIC bool           GetPrintAreaHor( SCTAB nTab, SCROW nStartRow, SCROW nEndRow,
1435                                                  SCCOL& rEndCol ) const;
1436     SC_DLLPUBLIC bool           GetPrintAreaVer( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol,
1437                                                  SCROW& rEndRow, bool bNotes ) const;
1438     void                        InvalidateTableArea();
1439 
1440     /// Return the number of columns / rows that should be visible for the tiled rendering.
1441     SC_DLLPUBLIC void           GetTiledRenderingArea(SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow) const;
1442 
1443     SC_DLLPUBLIC bool           GetDataStart( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow ) const;
1444 
1445     /**
1446      * Find the maximum column position that contains printable data for the
1447      * specified row range.  The final column position must be equal or less
1448      * than the initial value of rEndCol.
1449      */
1450     void                        ExtendPrintArea( OutputDevice* pDev, SCTAB nTab,
1451                                                  SCCOL nStartCol, SCROW nStartRow,
1452                                                  SCCOL& rEndCol, SCROW nEndRow ) const;
1453     SC_DLLPUBLIC SCSIZE         GetEmptyLinesInBlock( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
1454                                                       SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab,
1455                                                       ScDirection eDir );
1456 
1457     void               FindAreaPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, ScMoveDirection eDirection ) const;
1458     SC_DLLPUBLIC void  GetNextPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, SCCOL nMovX, SCROW nMovY,
1459                                    bool bMarked, bool bUnprotected, const ScMarkData& rMark,
1460                                    SCCOL nTabStartCol = SC_TABSTART_NONE ) const;
1461 
1462     bool               GetNextMarkedCell( SCCOL& rCol, SCROW& rRow, SCTAB nTab,
1463                                           const ScMarkData& rMark );
1464 
1465     void               LimitChartArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow,
1466                                        SCCOL& rEndCol, SCROW& rEndRow );
1467     void               LimitChartIfAll( ScRangeListRef& rRangeList );
1468 
1469     bool               InsertRow( SCCOL nStartCol, SCTAB nStartTab,
1470                                   SCCOL nEndCol,   SCTAB nEndTab,
1471                                   SCROW nStartRow, SCSIZE nSize, ScDocument* pRefUndoDoc = nullptr,
1472                                   const ScMarkData* pTabMark = nullptr );
1473     SC_DLLPUBLIC bool  InsertRow( const ScRange& rRange );
1474     void               DeleteRow( SCCOL nStartCol, SCTAB nStartTab,
1475                                   SCCOL nEndCol,   SCTAB nEndTab,
1476                                   SCROW nStartRow, SCSIZE nSize,
1477                                   ScDocument* pRefUndoDoc = nullptr, bool* pUndoOutline = nullptr,
1478                                   const ScMarkData* pTabMark = nullptr );
1479     SC_DLLPUBLIC void  DeleteRow( const ScRange& rRange );
1480     bool               InsertCol( SCROW nStartRow, SCTAB nStartTab,
1481                                   SCROW nEndRow,   SCTAB nEndTab,
1482                                   SCCOL nStartCol, SCSIZE nSize, ScDocument* pRefUndoDoc = nullptr,
1483                                   const ScMarkData* pTabMark = nullptr );
1484     SC_DLLPUBLIC bool  InsertCol( const ScRange& rRange );
1485     void               DeleteCol( SCROW nStartRow, SCTAB nStartTab,
1486                                   SCROW nEndRow, SCTAB nEndTab,
1487                                   SCCOL nStartCol, SCSIZE nSize,
1488                                   ScDocument* pRefUndoDoc = nullptr, bool* pUndoOutline = nullptr,
1489                                   const ScMarkData* pTabMark = nullptr );
1490     void               DeleteCol( const ScRange& rRange );
1491 
1492     bool               CanInsertRow( const ScRange& rRange ) const;
1493     bool               CanInsertCol( const ScRange& rRange ) const;
1494 
1495     void               FitBlock( const ScRange& rOld, const ScRange& rNew, bool bClear = true );
1496     bool               CanFitBlock( const ScRange& rOld, const ScRange& rNew );
1497 
IsClipOrUndo() const1498     bool               IsClipOrUndo() const                        { return bIsClip || bIsUndo; }
IsUndo() const1499     bool               IsUndo() const                              { return bIsUndo; }
IsClipboard() const1500     bool               IsClipboard() const                         { return bIsClip; }
IsUndoEnabled() const1501     bool               IsUndoEnabled() const                       { return mbUndoEnabled; }
1502     SC_DLLPUBLIC void  EnableUndo( bool bVal );
IsFunctionAccess() const1503     bool                IsFunctionAccess() const        { return bIsFunctionAccess; }
1504 
IsAdjustHeightLocked() const1505     bool                         IsAdjustHeightLocked() const               { return nAdjustHeightLock != 0; }
LockAdjustHeight()1506     void                         LockAdjustHeight()                          { ++nAdjustHeightLock; }
1507     SC_DLLPUBLIC void            UnlockAdjustHeight();
IsExecuteLinkEnabled() const1508     bool                         IsExecuteLinkEnabled() const                { return mbExecuteLinkEnabled; }
EnableExecuteLink(bool bVal)1509     void                         EnableExecuteLink( bool bVal )              { mbExecuteLinkEnabled = bVal; }
IsChangeReadOnlyEnabled() const1510     bool                         IsChangeReadOnlyEnabled() const             { return mbChangeReadOnlyEnabled; }
EnableChangeReadOnly(bool bVal)1511     void                         EnableChangeReadOnly( bool bVal )           { mbChangeReadOnlyEnabled = bVal; }
IsUserInteractionEnabled() const1512     SC_DLLPUBLIC bool            IsUserInteractionEnabled() const { return mbUserInteractionEnabled;}
1513     SC_DLLPUBLIC void            EnableUserInteraction( bool bVal );
GetNamedRangesLockCount() const1514     SC_DLLPUBLIC sal_Int16       GetNamedRangesLockCount() const             { return mnNamedRangesLockCount; }
SetNamedRangesLockCount(sal_Int16 nCount)1515     void                         SetNamedRangesLockCount( sal_Int16 nCount ) { mnNamedRangesLockCount = nCount; }
1516     SC_DLLPUBLIC void            ResetClip( ScDocument* pSourceDoc, const ScMarkData* pMarks );
1517     SC_DLLPUBLIC void            ResetClip( ScDocument* pSourceDoc, SCTAB nTab );
1518     void                         SetCutMode( bool bCut );
1519     bool                         IsCutMode();
1520     void                         SetClipArea( const ScRange& rArea, bool bCut = false );
1521 
IsDocVisible() const1522     SC_DLLPUBLIC bool            IsDocVisible() const                        { return bIsVisible; }
1523     SC_DLLPUBLIC void            SetDocVisible( bool bSet );
1524 
1525     bool                         HasOLEObjectsInArea( const ScRange& rRange, const ScMarkData* pTabMark = nullptr );
1526 
1527     void                         DeleteObjectsInArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1528                                                       const ScMarkData& rMark, bool bAnchored = false );
1529     void                         DeleteObjectsInSelection( const ScMarkData& rMark );
1530 
1531     void                         DeleteArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, const ScMarkData& rMark,
1532                                              InsertDeleteFlags nDelFlag, bool bBroadcast = true,
1533                                              sc::ColumnSpanSet* pBroadcastSpans = nullptr );
1534 
1535     SC_DLLPUBLIC void            DeleteAreaTab(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1536                                                SCTAB nTab, InsertDeleteFlags nDelFlag);
1537     void                         DeleteAreaTab(const ScRange& rRange, InsertDeleteFlags nDelFlag);
1538 
1539     SC_DLLPUBLIC void            CopyToClip( const ScClipParam& rClipParam, ScDocument* pClipDoc,
1540                                              const ScMarkData* pMarks, bool bKeepScenarioFlags,
1541                                              bool bIncludeObjects );
1542 
1543     /**
1544      * Copy only raw cell values to another document.  Formula cells are
1545      * converted to raw cells.  No formatting info are copied except for
1546      * number formats.
1547      *
1548      * @param rSrcRange source range in the source document
1549      * @param nDestTab table in the clip document to copy to.
1550      * @param pDestDoc document to copy to
1551      */
1552     SC_DLLPUBLIC void CopyStaticToDocument(const ScRange& rSrcRange, SCTAB nDestTab, ScDocument* pDestDoc);
1553 
1554     /**
1555      * Copy only cell, nothing but cell to another document.
1556      *
1557      * @param rSrcPos source cell position
1558      * @param rDestPos destination cell position
1559      * @param rDestDoc destination document
1560      */
1561     void CopyCellToDocument( const ScAddress& rSrcPos, const ScAddress& rDestPos, ScDocument& rDestDoc );
1562 
1563     void CopyTabToClip( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1564                         SCTAB nTab, ScDocument* pClipDoc);
1565 
1566     SC_DLLPUBLIC bool InitColumnBlockPosition( sc::ColumnBlockPosition& rBlockPos, SCTAB nTab, SCCOL nCol );
1567 
1568     void DeleteBeforeCopyFromClip( sc::CopyFromClipContext& rCxt, const ScMarkData& rMark,
1569                                    sc::ColumnSpanSet& rBroadcastSpans );
1570 
1571     bool CopyOneCellFromClip(sc::CopyFromClipContext& rCxt, SCCOL nCol1, SCROW nRow1,
1572                              SCCOL nCol2, SCROW nRow2 );
1573     void CopyBlockFromClip( sc::CopyFromClipContext& rCxt, SCCOL nCol1, SCROW nRow1,
1574                             SCCOL nCol2, SCROW nRow2, const ScMarkData& rMark,
1575                             SCCOL nDx, SCROW nDy );
1576     void CopyNonFilteredFromClip( sc::CopyFromClipContext& rCxt, SCCOL nCol1,
1577                                   SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1578                                   const ScMarkData& rMark, SCCOL nDx, SCROW & rClipStartRow );
1579 
1580     void StartListeningFromClip( SCCOL nCol1, SCROW nRow1,
1581                                  SCCOL nCol2, SCROW nRow2,
1582                                  const ScMarkData& rMark, InsertDeleteFlags nInsFlag );
1583 
1584     void SetDirtyFromClip( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1585                            const ScMarkData& rMark,  InsertDeleteFlags nInsFlag,
1586                            sc::ColumnSpanSet& rBroadcastSpans );
1587 
1588     /** If pDestRanges is given it overrides rDestRange, rDestRange in this
1589         case is the overall encompassing range. */
1590     SC_DLLPUBLIC void   CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMark,
1591                                         InsertDeleteFlags nInsFlag,
1592                                         ScDocument* pRefUndoDoc,
1593                                         ScDocument* pClipDoc,
1594                                         bool bResetCut = true,
1595                                         bool bAsLink = false,
1596                                         bool bIncludeFiltered = true,
1597                                         bool bSkipAttrForEmpty = false,
1598                                         const ScRangeList * pDestRanges = nullptr );
1599 
1600     void                CopyMultiRangeFromClip(const ScAddress& rDestPos, const ScMarkData& rMark,
1601                                                InsertDeleteFlags nInsFlag, ScDocument* pClipDoc,
1602                                                bool bResetCut = true, bool bAsLink = false,
1603                                                bool bIncludeFiltered = true,
1604                                                bool bSkipAttrForEmpty = false);
1605 
1606     void                GetClipArea(SCCOL& nClipX, SCROW& nClipY, bool bIncludeFiltered);
1607     void                GetClipStart(SCCOL& nClipX, SCROW& nClipY);
1608 
1609     bool                HasClipFilteredRows();
1610 
1611     bool                IsClipboardSource() const;
1612 
1613     SC_DLLPUBLIC void   TransposeClip( ScDocument* pTransClip, InsertDeleteFlags nFlags, bool bAsLink );
1614 
1615     ScClipParam&        GetClipParam();
1616     void                SetClipParam(const ScClipParam& rParam);
1617 
1618     /** To be called at the clipboard document when closing a document that is
1619         the current clipboard source to decouple things from the originating
1620         document. Done in ScDocument dtor after determining
1621         IsClipboardSource().
1622      */
1623     void            ClosingClipboardSource();
1624 
1625     void            MixDocument( const ScRange& rRange, ScPasteFunc nFunction, bool bSkipEmpty,
1626                                     ScDocument* pSrcDoc );
1627 
1628     void            FillTab( const ScRange& rSrcArea, const ScMarkData& rMark,
1629                                 InsertDeleteFlags nFlags, ScPasteFunc nFunction,
1630                                 bool bSkipEmpty, bool bAsLink );
1631     void            FillTabMarked( SCTAB nSrcTab, const ScMarkData& rMark,
1632                                 InsertDeleteFlags nFlags, ScPasteFunc nFunction,
1633                                 bool bSkipEmpty, bool bAsLink );
1634 
1635     void            TransliterateText( const ScMarkData& rMultiMark, TransliterationFlags nType );
1636 
1637     SC_DLLPUBLIC void           InitUndo( const ScDocument* pSrcDoc, SCTAB nTab1, SCTAB nTab2,
1638                                 bool bColInfo = false, bool bRowInfo = false );
1639     void            AddUndoTab( SCTAB nTab1, SCTAB nTab2,
1640                                 bool bColInfo = false, bool bRowInfo = false );
1641     SC_DLLPUBLIC void           InitUndoSelected( const ScDocument* pSrcDoc, const ScMarkData& rTabSelection,
1642                                 bool bColInfo = false, bool bRowInfo = false );
1643 
1644                     //  don't use anymore:
1645     void            CopyToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
1646                                 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
1647                                 InsertDeleteFlags nFlags, bool bMarked, ScDocument& rDestDoc,
1648                                 const ScMarkData* pMarks = nullptr, bool bColRowFlags = true);
1649     void            UndoToDocument(SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
1650                                 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
1651                                 InsertDeleteFlags nFlags, bool bMarked, ScDocument& rDestDoc);
1652 
1653     void            CopyToDocument(const ScRange& rRange,
1654                                 InsertDeleteFlags nFlags, bool bMarked, ScDocument& rDestDoc,
1655                                 const ScMarkData* pMarks = nullptr, bool bColRowFlags = true);
1656     void            UndoToDocument(const ScRange& rRange,
1657                                 InsertDeleteFlags nFlags, bool bMarked, ScDocument& rDestDoc);
1658 
1659     void            CopyScenario( SCTAB nSrcTab, SCTAB nDestTab, bool bNewScenario = false );
1660     bool            TestCopyScenario( SCTAB nSrcTab, SCTAB nDestTab ) const;
1661     void            MarkScenario(SCTAB nSrcTab, SCTAB nDestTab,
1662                                 ScMarkData& rDestMark, bool bResetMark = true,
1663                                 ScScenarioFlags nNeededBits = ScScenarioFlags::NONE) const;
1664     bool            HasScenarioRange( SCTAB nTab, const ScRange& rRange ) const;
1665     SC_DLLPUBLIC const ScRangeList* GetScenarioRanges( SCTAB nTab ) const;
1666 
1667     SC_DLLPUBLIC void  CopyUpdated( ScDocument* pPosDoc, ScDocument* pDestDoc );
1668 
1669     void               UpdateReference( sc::RefUpdateContext& rCxt,  ScDocument*
1670                                         pUndoDoc = nullptr, bool bIncludeDraw = true,
1671                                         bool bUpdateNoteCaptionPos = true );
1672 
1673     SC_DLLPUBLIC void  UpdateTranspose( const ScAddress& rDestPos, ScDocument* pClipDoc,
1674                                         const ScMarkData& rMark, ScDocument* pUndoDoc );
1675 
1676     void               UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
1677 
1678     SC_DLLPUBLIC void   Fill(   SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1679                                 ScProgress* pProgress, const ScMarkData& rMark,
1680                                 sal_uLong nFillCount, FillDir eFillDir = FILL_TO_BOTTOM,
1681                                 FillCmd eFillCmd = FILL_LINEAR, FillDateCmd eFillDateCmd = FILL_DAY,
1682                                 double nStepValue = 1.0, double nMaxValue = 1E307 );
1683     OUString            GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW nEndY );
1684 
1685     bool                GetSelectionFunction( ScSubTotalFunc eFunc,
1686                                               const ScAddress& rCursor, const ScMarkData& rMark,
1687                                               double& rResult );
1688 
1689     SC_DLLPUBLIC const SfxPoolItem*         GetAttr( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich ) const;
GetAttr(SCCOL nCol,SCROW nRow,SCTAB nTab,TypedWhichId<T> nWhich) const1690     template<class T> const T*              GetAttr( SCCOL nCol, SCROW nRow, SCTAB nTab, TypedWhichId<T> nWhich ) const
1691     {
1692         return static_cast<const T*>(GetAttr(nCol, nRow, nTab, sal_uInt16(nWhich)));
1693     }
1694     SC_DLLPUBLIC const SfxPoolItem*         GetAttr( const ScAddress& rPos, sal_uInt16 nWhich ) const;
GetAttr(const ScAddress & rPos,TypedWhichId<T> nWhich) const1695     template<class T> const T*              GetAttr( const ScAddress& rPos, TypedWhichId<T> nWhich ) const
1696     {
1697         return static_cast<const T*>(GetAttr(rPos, sal_uInt16(nWhich)));
1698     }
1699     SC_DLLPUBLIC const ScPatternAttr*       GetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1700     SC_DLLPUBLIC const ScPatternAttr*       GetPattern( const ScAddress& rPos ) const;
1701     SC_DLLPUBLIC const ScPatternAttr*       GetMostUsedPattern( SCCOL nCol, SCROW nStartRow, SCROW nEndRow, SCTAB nTab ) const;
1702     const ScPatternAttr*                    GetSelectionPattern( const ScMarkData& rMark );
1703     std::unique_ptr<ScPatternAttr>          CreateSelectionPattern( const ScMarkData& rMark, bool bDeep = true );
1704     SC_DLLPUBLIC void                       AddCondFormatData( const ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex );
1705     void                                    RemoveCondFormatData( const ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex );
1706 
1707     SC_DLLPUBLIC ScConditionalFormat*       GetCondFormat( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1708     // pCell is an optimization, must point to rPos
1709     SC_DLLPUBLIC const SfxItemSet*          GetCondResult( SCCOL nCol, SCROW nRow, SCTAB nTab,
1710                                                            ScRefCellValue* pCell = nullptr ) const;
1711     const SfxItemSet*                       GetCondResult( ScRefCellValue& rCell, const ScAddress& rPos,
1712                                                            const ScConditionalFormatList& rList,
1713                                                            const ScCondFormatIndexes& rIndex ) const;
1714     const SfxPoolItem*                      GetEffItem( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich ) const;
GetEffItem(SCCOL nCol,SCROW nRow,SCTAB nTab,TypedWhichId<T> nWhich) const1715     template<class T> const T*              GetEffItem( SCCOL nCol, SCROW nRow, SCTAB nTab, TypedWhichId<T> nWhich ) const
1716     {
1717         return static_cast<const T*>(GetEffItem(nCol, nRow, nTab, sal_uInt16(nWhich)));
1718     }
1719 
1720     SC_DLLPUBLIC const css::uno::Reference< css::i18n::XBreakIterator >& GetBreakIterator();
1721     bool                        HasStringWeakCharacters( const OUString& rString );
1722     SC_DLLPUBLIC SvtScriptType  GetStringScriptType( const OUString& rString );
1723     // pCell is an optimization, must point to rPos
1724     SC_DLLPUBLIC SvtScriptType  GetCellScriptType( const ScAddress& rPos, sal_uInt32 nNumberFormat,
1725                                                    const ScRefCellValue* pCell = nullptr );
1726     // pCell is an optimization, must point to nCol,nRow,nTab
1727     SC_DLLPUBLIC SvtScriptType  GetScriptType( SCCOL nCol, SCROW nRow, SCTAB nTab,
1728                                                const ScRefCellValue* pCell = nullptr );
1729     SvtScriptType               GetRangeScriptType( sc::ColumnBlockPosition& rBlockPos, const ScAddress& rPos, SCROW nLength );
1730     SvtScriptType               GetRangeScriptType( const ScRangeList& rRanges );
1731 
1732     bool            HasDetectiveOperations() const;
1733     void            AddDetectiveOperation( const ScDetOpData& rData );
1734     void            ClearDetectiveOperations();
GetDetOpList() const1735     ScDetOpList*    GetDetOpList() const { return pDetOpList.get(); }
1736     void            SetDetOpList(std::unique_ptr<ScDetOpList> pNew);
1737 
1738     bool            HasDetectiveObjects(SCTAB nTab) const;
1739 
1740     void            GetSelectionFrame( const ScMarkData& rMark,
1741                                        SvxBoxItem&      rLineOuter,
1742                                        SvxBoxInfoItem&  rLineInner );
1743     void            ApplySelectionFrame(const ScMarkData& rMark,
1744                                         const SvxBoxItem& rLineOuter,
1745                                         const SvxBoxInfoItem* pLineInner);
1746     void            ApplyFrameAreaTab(const ScRange& rRange,
1747                                       const SvxBoxItem& rLineOuter,
1748                                       const SvxBoxInfoItem& rLineInner);
1749 
1750     void            ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark );
1751     void            ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark );
1752 
1753     SC_DLLPUBLIC sal_uLong  AddCondFormat( std::unique_ptr<ScConditionalFormat> pNew, SCTAB nTab );
1754     void                    DeleteConditionalFormat( sal_uLong nIndex, SCTAB nTab );
1755 
1756     void                                    SetCondFormList( ScConditionalFormatList* pList, SCTAB nTab );
1757     SC_DLLPUBLIC sal_uLong                  AddValidationEntry( const ScValidationData& rNew );
1758     SC_DLLPUBLIC const ScValidationData*    GetValidationEntry( sal_uLong nIndex ) const;
1759 
1760     SC_DLLPUBLIC ScConditionalFormatList*   GetCondFormList( SCTAB nTab ) const;
1761 
GetValidationList() const1762     const ScValidationDataList*             GetValidationList() const { return pValidationList.get();}
GetValidationList()1763     ScValidationDataList*                   GetValidationList() { return pValidationList.get();}
1764 
1765     SC_DLLPUBLIC void           ApplyAttr( SCCOL nCol, SCROW nRow, SCTAB nTab,
1766                                            const SfxPoolItem& rAttr );
1767     SC_DLLPUBLIC void           ApplyPattern( SCCOL nCol, SCROW nRow, SCTAB nTab,
1768                                               const ScPatternAttr& rAttr );
1769     SC_DLLPUBLIC void           ApplyPatternArea( SCCOL nStartCol, SCROW nStartRow,
1770                                                   SCCOL nEndCol, SCROW nEndRow,
1771                                                   const ScMarkData& rMark, const ScPatternAttr& rAttr,
1772                                                   ScEditDataArray* pDataArray = nullptr,
1773                                                   bool* const pIsChanged = nullptr );
1774     SC_DLLPUBLIC void           ApplyPatternAreaTab( SCCOL nStartCol, SCROW nStartRow,
1775                                                      SCCOL nEndCol, SCROW nEndRow, SCTAB nTab,
1776                                                      const ScPatternAttr& rAttr );
1777 
1778     SC_DLLPUBLIC void           ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
1779                                                                         const ScMarkData& rMark,
1780                                                                         const ScPatternAttr& rPattern,
1781                                                                         SvNumFormatType nNewType );
1782 
1783     void               ApplyStyle( SCCOL nCol, SCROW nRow, SCTAB nTab,
1784                                    const ScStyleSheet& rStyle);
1785     void               ApplyStyleArea( SCCOL nStartCol, SCROW nStartRow,
1786                                        SCCOL nEndCol, SCROW nEndRow,
1787                                        const ScMarkData& rMark, const ScStyleSheet& rStyle);
1788     SC_DLLPUBLIC void  ApplyStyleAreaTab( SCCOL nStartCol, SCROW nStartRow,
1789                                           SCCOL nEndCol, SCROW nEndRow, SCTAB nTab,
1790                                           const ScStyleSheet& rStyle);
1791 
1792     SC_DLLPUBLIC void  ApplySelectionStyle( const ScStyleSheet& rStyle, const ScMarkData& rMark );
1793     void               ApplySelectionLineStyle( const ScMarkData& rMark,
1794                                                 const ::editeng::SvxBorderLine* pLine, bool bColorOnly );
1795 
1796     const ScStyleSheet* GetStyle( SCCOL nCol, SCROW nRow, SCTAB nTab ) const;
1797     const ScStyleSheet* GetSelectionStyle( const ScMarkData& rMark ) const;
1798 
1799     void                StyleSheetChanged( const SfxStyleSheetBase* pStyleSheet, bool bRemoved,
1800                                            OutputDevice* pDev,
1801                                            double nPPTX, double nPPTY,
1802                                            const Fraction& rZoomX, const Fraction& rZoomY );
1803 
1804     bool                 IsStyleSheetUsed( const ScStyleSheet& rStyle ) const;
1805 
1806     SC_DLLPUBLIC bool    ApplyFlagsTab( SCCOL nStartCol, SCROW nStartRow,
1807                                         SCCOL nEndCol, SCROW nEndRow,
1808                                         SCTAB nTab, ScMF nFlags );
1809     SC_DLLPUBLIC bool    RemoveFlagsTab( SCCOL nStartCol, SCROW nStartRow,
1810                                          SCCOL nEndCol, SCROW nEndRow,
1811                                          SCTAB nTab, ScMF nFlags );
1812 
1813     SC_DLLPUBLIC void    SetPattern( const ScAddress&, const ScPatternAttr& rAttr );
1814     SC_DLLPUBLIC const ScPatternAttr* SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPatternAttr> );
1815     SC_DLLPUBLIC void    SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, const ScPatternAttr& rAttr );
1816 
1817     void                 AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1818                                      sal_uInt16 nFormatNo, const ScMarkData& rMark );
1819     void                 GetAutoFormatData( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1820                                             ScAutoFormatData& rData );
1821     bool                 SearchAndReplace( const SvxSearchItem& rSearchItem,
1822                                            SCCOL& rCol, SCROW& rRow, SCTAB& rTab,
1823                                            const ScMarkData& rMark, ScRangeList& rMatchedRanges,
1824                                            OUString& rUndoStr, ScDocument* pUndoDoc = nullptr );
1825 
1826                     // determine Col/Row of subsequent calls
1827                     // (e.g. not found from the beginning, or subsequent tables)
1828                     // meaning of explanation in "()" was already unclear in German
1829     void            GetSearchAndReplaceStart( const SvxSearchItem& rSearchItem,
1830                                               SCCOL& rCol, SCROW& rRow );
1831 
1832     bool            Solver( SCCOL nFCol, SCROW nFRow, SCTAB nFTab,
1833                             SCCOL nVCol, SCROW nVRow, SCTAB nVTab,
1834                             const OUString& sValStr, double& nX);
1835 
1836     SC_DLLPUBLIC void           ApplySelectionPattern( const ScPatternAttr& rAttr, const ScMarkData& rMark,
1837                                                        ScEditDataArray* pDataArray = nullptr, bool* pIsChanged = nullptr );
1838     void                        DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rMark, bool bBroadcast = true );
1839     void                        DeleteSelectionTab( SCTAB nTab, InsertDeleteFlags nDelFlag, const ScMarkData& rMark );
1840 
1841     SC_DLLPUBLIC void           SetColWidth( SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth );
1842     SC_DLLPUBLIC void           SetColWidthOnly( SCCOL nCol, SCTAB nTab, sal_uInt16 nNewWidth );
1843     SC_DLLPUBLIC void           SetRowHeight( SCROW nRow, SCTAB nTab, sal_uInt16 nNewHeight );
1844     SC_DLLPUBLIC void           SetRowHeightRange( SCROW nStartRow, SCROW nEndRow, SCTAB nTab,
1845                                                    sal_uInt16 nNewHeight );
1846 
1847     SC_DLLPUBLIC void           SetRowHeightOnly( SCROW nStartRow, SCROW nEndRow, SCTAB nTab,
1848                                                   sal_uInt16 nNewHeight );
1849     SC_DLLPUBLIC void           SetManualHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bManual );
1850 
1851     SC_DLLPUBLIC sal_uInt16         GetColWidth( SCCOL nCol, SCTAB nTab, bool bHiddenAsZero = true ) const;
1852     SC_DLLPUBLIC sal_uLong          GetColWidth( SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab ) const;
1853     SC_DLLPUBLIC sal_uInt16         GetRowHeight( SCROW nRow, SCTAB nTab, bool bHiddenAsZero = true ) const;
1854     SC_DLLPUBLIC sal_uInt16         GetRowHeight( SCROW nRow, SCTAB nTab, SCROW* pStartRow, SCROW* pEndRow ) const;
1855     SC_DLLPUBLIC sal_uLong          GetRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero = true ) const;
1856 
1857     /**
1858      * Given the height i.e. total vertical distance from the top of the sheet
1859      * grid, return the first visible row whose top position is below the
1860      * specified height.
1861      */
1862     SCROW                       GetRowForHeight( SCTAB nTab, sal_uLong nHeight ) const;
1863     sal_uLong                   GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, double fScale ) const;
1864     SC_DLLPUBLIC sal_uLong      GetColOffset( SCCOL nCol, SCTAB nTab, bool bHiddenAsZero = true ) const;
1865     SC_DLLPUBLIC sal_uLong      GetRowOffset( SCROW nRow, SCTAB nTab, bool bHiddenAsZero = true ) const;
1866 
1867     SC_DLLPUBLIC sal_uInt16     GetOriginalWidth( SCCOL nCol, SCTAB nTab ) const;
1868     SC_DLLPUBLIC sal_uInt16     GetOriginalHeight( SCROW nRow, SCTAB nTab ) const;
1869 
1870     sal_uInt16                  GetCommonWidth( SCCOL nEndCol, SCTAB nTab ) const;
1871 
1872     SCROW                       GetHiddenRowCount( SCROW nRow, SCTAB nTab ) const;
1873 
1874     sal_uInt16                  GetOptimalColWidth( SCCOL nCol, SCTAB nTab, OutputDevice* pDev,
1875                                                     double nPPTX, double nPPTY,
1876                                                     const Fraction& rZoomX, const Fraction& rZoomY,
1877                                                     bool bFormula,
1878                                                     const ScMarkData* pMarkData = nullptr,
1879                                                     const ScColWidthParam* pParam = nullptr );
1880 
1881     SC_DLLPUBLIC bool           SetOptimalHeight( sc::RowHeightContext& rCxt, SCROW nStartRow,
1882                                                    SCROW nEndRow, SCTAB nTab );
1883 
1884     void                        UpdateAllRowHeights( sc::RowHeightContext& rCxt, const ScMarkData* pTabMark );
1885 
1886     long                        GetNeededSize( SCCOL nCol, SCROW nRow, SCTAB nTab,
1887                                                OutputDevice* pDev,
1888                                                double nPPTX, double nPPTY,
1889                                                const Fraction& rZoomX, const Fraction& rZoomY,
1890                                                bool bWidth, bool bTotalSize = false );
1891 
1892     SC_DLLPUBLIC void           ShowCol(SCCOL nCol, SCTAB nTab, bool bShow);
1893     SC_DLLPUBLIC void           ShowRow(SCROW nRow, SCTAB nTab, bool bShow);
1894     SC_DLLPUBLIC void           ShowRows(SCROW nRow1, SCROW nRow2, SCTAB nTab, bool bShow);
1895     SC_DLLPUBLIC void           SetRowFlags( SCROW nRow, SCTAB nTab, CRFlags nNewFlags );
1896     SC_DLLPUBLIC void           SetRowFlags( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, CRFlags nNewFlags );
1897 
1898     SC_DLLPUBLIC CRFlags        GetColFlags( SCCOL nCol, SCTAB nTab ) const;
1899     SC_DLLPUBLIC CRFlags        GetRowFlags( SCROW nRow, SCTAB nTab ) const;
1900 
1901     SC_DLLPUBLIC void           GetAllRowBreaks(std::set<SCROW>& rBreaks, SCTAB nTab, bool bPage, bool bManual) const;
1902     SC_DLLPUBLIC void           GetAllColBreaks(std::set<SCCOL>& rBreaks, SCTAB nTab, bool bPage, bool bManual) const;
1903     SC_DLLPUBLIC ScBreakType    HasRowBreak(SCROW nRow, SCTAB nTab) const;
1904     SC_DLLPUBLIC ScBreakType    HasColBreak(SCCOL nCol, SCTAB nTab) const;
1905     SC_DLLPUBLIC void           SetRowBreak(SCROW nRow, SCTAB nTab, bool bPage, bool bManual);
1906     SC_DLLPUBLIC void           SetColBreak(SCCOL nCol, SCTAB nTab, bool bPage, bool bManual);
1907     void                        RemoveRowBreak(SCROW nRow, SCTAB nTab, bool bPage, bool bManual);
1908     void                        RemoveColBreak(SCCOL nCol, SCTAB nTab, bool bPage, bool bManual);
1909     css::uno::Sequence<
1910         css::sheet::TablePageBreakData> GetRowBreakData(SCTAB nTab) const;
1911 
1912     SC_DLLPUBLIC bool           RowHidden(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const;
1913     SC_DLLPUBLIC bool           HasHiddenRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1914     SC_DLLPUBLIC bool           ColHidden(SCCOL nCol, SCTAB nTab, SCCOL* pFirstCol = nullptr, SCCOL* pLastCol = nullptr) const;
1915     SC_DLLPUBLIC void           SetRowHidden(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bHidden);
1916     SC_DLLPUBLIC void           SetColHidden(SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bHidden);
1917     SC_DLLPUBLIC SCROW          FirstVisibleRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1918     SC_DLLPUBLIC SCROW          LastVisibleRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1919     SCROW                       CountVisibleRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1920 
1921     bool                        RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const;
1922     bool                        HasFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1923     bool                        ColFiltered(SCCOL nCol, SCTAB nTab) const;
1924     SC_DLLPUBLIC void           SetRowFiltered(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bFiltered);
1925     SCROW                       FirstNonFilteredRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1926     SCROW                       LastNonFilteredRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1927     SCROW                       CountNonFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const;
1928 
1929     SC_DLLPUBLIC bool           IsManualRowHeight(SCROW nRow, SCTAB nTab) const;
1930 
1931     bool                        HasUniformRowHeight( SCTAB nTab, SCROW nRow1, SCROW nRow2 ) const;
1932 
1933     /**
1934      * Write all column row flags to table's flag data, because not all column
1935      * row attributes are stored in the flag data members.  This is necessary
1936      * for ods export.
1937      */
1938     void                        SyncColRowFlags();
1939 
1940                     /// @return  the index of the last row with any set flags (auto-pagebreak is ignored).
1941     SC_DLLPUBLIC SCROW          GetLastFlaggedRow( SCTAB nTab ) const;
1942 
1943                     /// @return  the index of the last changed column (flags and column width, auto pagebreak is ignored).
1944     SCCOL           GetLastChangedCol( SCTAB nTab ) const;
1945                     /// @return  the index of the last changed row (flags and row height, auto pagebreak is ignored).
1946     SCROW           GetLastChangedRow( SCTAB nTab ) const;
1947 
1948     SCCOL           GetNextDifferentChangedCol( SCTAB nTab, SCCOL nStart) const;
1949 
1950     SCROW           GetNextDifferentChangedRow( SCTAB nTab, SCROW nStart) const;
1951 
1952     // returns whether to export a Default style for this col or not
1953     // nDefault is set to one position in the current row where the Default style is
1954     void            GetColDefault( SCTAB nTab, SCCOL nCol, SCROW nLastRow, SCROW& nDefault);
1955 
1956     bool            UpdateOutlineCol( SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bShow );
1957     bool            UpdateOutlineRow( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bShow );
1958 
1959     void            StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2, SCTAB nTab );
1960     void            ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2, SCTAB nTab );
1961 
1962     SC_DLLPUBLIC ScPatternAttr*     GetDefPattern() const;
1963     SC_DLLPUBLIC ScDocumentPool*    GetPool();
1964     SC_DLLPUBLIC ScStyleSheetPool*  GetStyleSheetPool() const;
1965     void GetUnprotectedCells( ScRangeList& rRange, SCTAB nTab ) const;
1966 
1967     // PageStyle:
1968     SC_DLLPUBLIC OUString GetPageStyle( SCTAB nTab ) const;
1969     SC_DLLPUBLIC void     SetPageStyle( SCTAB nTab, const OUString& rName );
1970     Size            GetPageSize( SCTAB nTab ) const;
1971     void            SetPageSize( SCTAB nTab, const Size& rSize );
1972     void            SetRepeatArea( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCROW nEndRow );
1973     void            InvalidatePageBreaks(SCTAB nTab);
1974     void            UpdatePageBreaks( SCTAB nTab, const ScRange* pUserArea = nullptr );
1975     void            RemoveManualBreaks( SCTAB nTab );
1976     bool            HasManualBreaks( SCTAB nTab ) const;
1977 
1978     bool            IsPageStyleInUse( const OUString& rStrPageStyle, SCTAB* pInTab );
1979     bool            RemovePageStyleInUse( const OUString& rStrPageStyle );
1980     bool            RenamePageStyleInUse( const OUString& rOld, const OUString& rNew );
1981     void            ModifyStyleSheet( SfxStyleSheetBase& rPageStyle,
1982                                       const SfxItemSet&  rChanges );
1983 
1984     void            PageStyleModified( SCTAB nTab, const OUString& rNewName );
1985 
1986     SC_DLLPUBLIC bool           NeedPageResetAfterTab( SCTAB nTab ) const;
1987 
1988     // Was stored in PageStyle previously. Now it exists for every table:
1989     SC_DLLPUBLIC bool           HasPrintRange();
1990     SC_DLLPUBLIC sal_uInt16     GetPrintRangeCount( SCTAB nTab );
1991     SC_DLLPUBLIC const ScRange* GetPrintRange( SCTAB nTab, sal_uInt16 nPos );
1992     SC_DLLPUBLIC const ScRange* GetRepeatColRange( SCTAB nTab );
1993     SC_DLLPUBLIC const ScRange* GetRepeatRowRange( SCTAB nTab );
1994     /** Returns true, if the specified sheet is always printed. */
1995     bool                        IsPrintEntireSheet( SCTAB nTab ) const;
1996 
1997     /** Removes all print ranges. */
1998     SC_DLLPUBLIC void            ClearPrintRanges( SCTAB nTab );
1999     /** Adds a new print ranges. */
2000     SC_DLLPUBLIC void            AddPrintRange( SCTAB nTab, const ScRange& rNew );
2001     /** Marks the specified sheet to be printed completely. Deletes old print ranges on the sheet! */
2002     SC_DLLPUBLIC void            SetPrintEntireSheet( SCTAB nTab );
2003     SC_DLLPUBLIC void            SetRepeatColRange( SCTAB nTab, std::unique_ptr<ScRange> pNew );
2004     SC_DLLPUBLIC void            SetRepeatRowRange( SCTAB nTab, std::unique_ptr<ScRange> pNew );
2005     std::unique_ptr<ScPrintRangeSaver> CreatePrintRangeSaver() const;
2006     void                         RestorePrintRanges( const ScPrintRangeSaver& rSaver );
2007 
2008     SC_DLLPUBLIC tools::Rectangle       GetMMRect( SCCOL nStartCol, SCROW nStartRow,
2009                                             SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero = true ) const;
2010     SC_DLLPUBLIC ScRange         GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool bHiddenAsZero = true ) const;
2011 
2012     void                         UpdStlShtPtrsFrmNms();
2013     void                         StylesToNames();
2014 
2015     SC_DLLPUBLIC void            CopyStdStylesFrom( const ScDocument* pSrcDoc );
2016 
GetSrcVersion()2017     static sal_uInt16            GetSrcVersion() { return nSrcVer; }
2018 
SetSrcCharSet(rtl_TextEncoding eNew)2019     void                         SetSrcCharSet( rtl_TextEncoding eNew )   { eSrcSet = eNew; }
2020     void                         UpdateFontCharSet();
2021 
2022     void                         FillInfo( ScTableInfo& rTabInfo, SCCOL nCol1, SCROW nRow1,
2023                                            SCCOL nCol2, SCROW nRow2, SCTAB nTab, double fColScale,
2024                                            double fRowScale, bool bPageMode, bool bFormulaMode,
2025                                            const ScMarkData* pMarkData = nullptr );
2026 
2027     SC_DLLPUBLIC SvNumberFormatter* GetFormatTable() const;
2028 
2029     /** Sort a range of data. */
2030     void               Sort( SCTAB nTab, const ScSortParam& rSortParam,
2031                              bool bKeepQuery, bool bUpdateRefs,
2032                              ScProgress* pProgress, sc::ReorderParam* pUndo );
2033 
2034     void               Reorder( const sc::ReorderParam& rParam );
2035 
2036     SCSIZE             Query( SCTAB nTab, const ScQueryParam& rQueryParam, bool bKeepSub );
2037     SC_DLLPUBLIC bool  CreateQueryParam( const ScRange& rRange, ScQueryParam& rQueryParam );
2038     void               GetUpperCellString(SCCOL nCol, SCROW nRow, SCTAB nTab, OUString& rStr);
2039 
2040     /**
2041      * Get a list of unique strings to use in filtering criteria.  The string
2042      * values are sorted, and there are no duplicate values in the list.  The
2043      * data range to use to populate the filter entries is inferred from the
2044      * database range that contains the specified cell position.
2045      */
2046     void              GetFilterEntries( SCCOL nCol, SCROW nRow,
2047                                         SCTAB nTab, ScFilterEntries& rFilterEntries );
2048 
2049     SC_DLLPUBLIC void GetFilterEntriesArea( SCCOL nCol, SCROW nStartRow, SCROW nEndRow,
2050                                             SCTAB nTab, bool bCaseSens,
2051                                             ScFilterEntries& rFilterEntries );
2052 
2053     void              GetDataEntries( SCCOL nCol, SCROW nRow, SCTAB nTab,
2054                                       std::vector<ScTypedStrData>& rStrings, bool bLimit = false );
2055     void              GetFormulaEntries( ScTypedCaseStrSet& rStrings );
2056 
2057     bool               HasAutoFilter( SCCOL nCol, SCROW nRow, SCTAB nTab );
2058     void               GetFilterSelCount( SCCOL nCol, SCROW nRow, SCTAB nTab, SCSIZE& nSelected, SCSIZE& nTotal );
2059 
2060     SC_DLLPUBLIC bool  HasColHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2061                                      SCTAB nTab );
2062     SC_DLLPUBLIC bool  HasRowHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2063                                      SCTAB nTab );
2064 
2065     SfxPrinter*                 GetPrinter( bool bCreateIfNotExist = true );
2066     void                        SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter );
2067     VirtualDevice*              GetVirtualDevice_100th_mm();
2068     SC_DLLPUBLIC OutputDevice*  GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
2069 
2070     bool            GetNextSpellingCell( SCCOL& nCol, SCROW& nRow, SCTAB nTab,
2071                                          bool bInSel, const ScMarkData& rMark) const;
2072 
2073     void            ReplaceStyle( const SvxSearchItem& rSearchItem,
2074                                   SCCOL nCol, SCROW nRow, SCTAB nTab,
2075                                   const ScMarkData& rMark);
2076 
2077     void            InvalidateTextWidth( const OUString& rStyleName );
2078     void            InvalidateTextWidth( SCTAB nTab );
2079     void            InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo, bool bNumFormatChanged );
2080 
2081     bool            IdleCalcTextWidth();
2082 
2083     void            RepaintRange( const ScRange& rRange );
2084     void            RepaintRange( const ScRangeList& rRange );
2085 
IsIdleEnabled() const2086     bool            IsIdleEnabled() const { return mbIdleEnabled; }
EnableIdle(bool bDo)2087     void            EnableIdle(bool bDo) { mbIdleEnabled = bDo; }
2088 
IsDetectiveDirty() const2089     bool            IsDetectiveDirty() const     { return bDetectiveDirty; }
SetDetectiveDirty(bool bSet)2090     void            SetDetectiveDirty(bool bSet) { bDetectiveDirty = bSet; }
2091 
HasLinkFormulaNeedingCheck() const2092     bool            HasLinkFormulaNeedingCheck() const      { return bLinkFormulaNeedingCheck; }
SetLinkFormulaNeedingCheck(bool bSet)2093     void            SetLinkFormulaNeedingCheck(bool bSet)   { bLinkFormulaNeedingCheck = bSet; }
2094     /** Check token array and set link check if ocDde/ocWebservice is contained. */
2095     SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck( const ScTokenArray& rCode );
2096 
SetRangeOverflowType(ErrCode nType)2097     void            SetRangeOverflowType(ErrCode nType)  { nRangeOverflowType = nType; }
HasRangeOverflow() const2098     bool            HasRangeOverflow() const             { return nRangeOverflowType != ERRCODE_NONE; }
GetRangeOverflowType() const2099     SC_DLLPUBLIC const ErrCode& GetRangeOverflowType() const    { return nRangeOverflowType; }
2100 
2101     // for broadcasting/listening
SetInsertingFromOtherDoc(bool bVal)2102     void            SetInsertingFromOtherDoc( bool bVal ) { bInsertingFromOtherDoc = bVal; }
IsInsertingFromOtherDoc() const2103     bool            IsInsertingFromOtherDoc() const { return bInsertingFromOtherDoc; }
2104     void            SetLoadingMedium( bool bVal );
2105     SC_DLLPUBLIC void SetImportingXML( bool bVal );
IsImportingXML() const2106     bool            IsImportingXML() const { return bImportingXML; }
IsCalcingAfterLoad() const2107     bool            IsCalcingAfterLoad() const { return bCalcingAfterLoad; }
SetNoListening(bool bVal)2108     void            SetNoListening( bool bVal ) { bNoListening = bVal; }
GetNoListening() const2109     bool            GetNoListening() const { return bNoListening; }
GetBASM() const2110     ScBroadcastAreaSlotMachine* GetBASM() const { return pBASM.get(); }
2111 
GetChartListenerCollection() const2112     SC_DLLPUBLIC ScChartListenerCollection* GetChartListenerCollection() const { return pChartListenerCollection.get(); }
2113     void                  SetChartListenerCollection( std::unique_ptr<ScChartListenerCollection>,
2114                                                        bool bSetChartRangeLists );
2115     void                  UpdateChart( const OUString& rName );
2116     void                  RestoreChartListener( const OUString& rName );
2117     SC_DLLPUBLIC void     UpdateChartListenerCollection();
IsChartListenerCollectionNeedsUpdate() const2118     bool                  IsChartListenerCollectionNeedsUpdate() const { return bChartListenerCollectionNeedsUpdate; }
SetChartListenerCollectionNeedsUpdate(bool bFlg)2119     void                  SetChartListenerCollectionNeedsUpdate( bool bFlg ) { bChartListenerCollectionNeedsUpdate = bFlg; }
2120     void                  AddOLEObjectToCollection(const OUString& rName);
2121 
GetChangeViewSettings() const2122     ScChangeViewSettings* GetChangeViewSettings() const     { return pChangeViewSettings.get(); }
2123     SC_DLLPUBLIC void     SetChangeViewSettings(const ScChangeViewSettings& rNew);
2124 
2125     const std::shared_ptr<SvxForbiddenCharactersTable>& GetForbiddenCharacters() const;
2126     void            SetForbiddenCharacters(const std::shared_ptr<SvxForbiddenCharactersTable>& rNew);
2127 
2128     CharCompressType GetAsianCompression() const;
2129     bool             IsValidAsianCompression() const;
2130     void             SetAsianCompression(CharCompressType nNew);
2131 
2132     bool            GetAsianKerning() const;
2133     bool            IsValidAsianKerning() const;
2134     void            SetAsianKerning(bool bNew);
2135     void            ApplyAsianEditSettings(ScEditEngineDefaulter& rEngine);
2136 
2137     EEHorizontalTextDirection       GetEditTextDirection(SCTAB nTab) const; // EEHorizontalTextDirection values
2138 
GetLinkMode() const2139     SC_DLLPUBLIC ScLkUpdMode        GetLinkMode() const             { return eLinkMode ;}
SetLinkMode(ScLkUpdMode nSet)2140     void                            SetLinkMode( ScLkUpdMode nSet ) {   eLinkMode  = nSet;}
2141 
2142     SC_DLLPUBLIC ScMacroManager*    GetMacroManager();
2143 
2144     void                            FillMatrix( ScMatrix& rMat, SCTAB nTab, SCCOL nCol1,
2145                                                 SCROW nRow1, SCCOL nCol2, SCROW nRow2,
2146                                                 svl::SharedStringPool* pPool = nullptr) const;
2147 
2148     /**
2149      * Set an array of numerical formula results to a group of contiguous
2150      * formula cells.
2151      *
2152      * @param rTopPos position of the top formula cell of a group.
2153      * @param pResults array of numeric results.
2154      * @param nLen length of numeric results.
2155      */
2156     void SC_DLLPUBLIC SetFormulaResults( const ScAddress& rTopPos, const double* pResults, size_t nLen );
2157 
2158     const ScDocumentThreadSpecific& CalculateInColumnInThread( ScInterpreterContext& rContext, const ScRange& rCalcRange, unsigned nThisThread, unsigned nThreadsTotal);
2159     void HandleStuffAfterParallelCalculation( SCCOL nColStart, SCCOL nColEnd, SCROW nRow, size_t nLen, SCTAB nTab, ScInterpreter* pInterpreter );
2160 
2161     /**
2162      * Transfer a series of contiguous cell values from specified position to
2163      * the passed container. The specified segment will become empty after the
2164      * transfer.
2165      */
2166     void TransferCellValuesTo( const ScAddress& rTopPos, size_t nLen, sc::CellValues& rDest );
2167     void CopyCellValuesFrom( const ScAddress& rTopPos, const sc::CellValues& rSrc );
2168 
2169     std::set<Color>       GetDocColors();
2170     sc::IconSetBitmapMap& GetIconSetBitmapMap();
2171 
2172 private:
2173     ScDocument(const ScDocument& r) = delete;
2174 
2175     void                FindMaxRotCol( SCTAB nTab, RowInfo* pRowInfo, SCSIZE nArrCount,
2176                                        SCCOL nX1, SCCOL nX2 ) const;
2177 
2178     sal_uInt16          RowDifferences( SCROW nThisRow, SCTAB nThisTab,
2179                                         ScDocument& rOtherDoc,
2180                                         SCROW nOtherRow, SCTAB nOtherTab,
2181                                         SCCOL nMaxCol, const SCCOLROW* pOtherCols );
2182     sal_uInt16          ColDifferences( SCCOL nThisCol, SCTAB nThisTab,
2183                                         ScDocument& rOtherDoc,
2184                                         SCCOL nOtherCol, SCTAB nOtherTab,
2185                                         SCROW nMaxRow, const SCCOLROW* pOtherRows );
2186     void                FindOrder( SCCOLROW* pOtherRows, SCCOLROW nThisEndRow, SCCOLROW nOtherEndRow,
2187                                         bool bColumns,
2188                                         ScDocument& rOtherDoc, SCTAB nThisTab, SCTAB nOtherTab,
2189                                         SCCOLROW nEndCol, const SCCOLROW* pTranslate,
2190                                         ScProgress* pProgress, sal_uLong nProAdd );
2191 
2192     DECL_LINK(TrackTimeHdl, Timer *, void);
2193 
2194     static ScRecursionHelper*   CreateRecursionHelperInstance();
2195 
2196     /** Adjust a range to available sheets.
2197 
2198         Used to start and stop listening on a sane range. Both o_rRange and
2199         o_bEntirelyOutOfBounds are set only if needed and don't have to be
2200         initialized by the caller.
2201 
2202         @param  o_bEntirelyOutOfBounds
2203                 <TRUE/> if both sheets in the range point outside the
2204                 available sheet range, in which case no adjustment is done and
2205                 o_rRange is not modified.
2206 
2207         @return <TRUE/> if any adjustment was done or o_bEntirelyOutOfBounds
2208                 was set <TRUE/>.
2209                 <FALSE/> if rRange was within the available sheets.
2210      */
2211     bool                LimitRangeToAvailableSheets( const ScRange& rRange, ScRange& o_rRange,
2212                                                      bool& o_bEntirelyOutOfBounds ) const;
2213 
2214 public:
2215     void StartListeningArea( const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
2216 
2217     void EndListeningArea( const ScRange& rRange, bool bGroupListening, SvtListener* pListener );
2218                         /** Broadcast wrapper, calls
2219                             rHint.GetCell()->Broadcast() and AreaBroadcast()
2220                             and TrackFormulas()
2221                             Preferred.
2222                          */
2223     void                Broadcast( const ScHint& rHint );
2224 
2225     void BroadcastCells( const ScRange& rRange, SfxHintId nHint, bool bBroadcastSingleBroadcasters = true );
2226 
2227                         /// only area, no cell broadcast
2228     void                AreaBroadcast( const ScHint& rHint );
2229     void                DelBroadcastAreasInRange( const ScRange& rRange );
2230     void                UpdateBroadcastAreas( UpdateRefMode eUpdateRefMode,
2231                                             const ScRange& rRange,
2232                                             SCCOL nDx, SCROW nDy, SCTAB nDz );
2233 
2234     void                StartListeningCell( const ScAddress& rAddress,
2235                                             SvtListener* pListener );
2236     void                EndListeningCell( const ScAddress& rAddress,
2237                                             SvtListener* pListener );
2238 
2239     void StartListeningCell( sc::StartListeningContext& rCxt, const ScAddress& rPos, SvtListener& rListener );
2240     void EndListeningCell( sc::EndListeningContext& rCxt, const ScAddress& rPos, SvtListener& rListener );
2241 
2242     void EndListeningFormulaCells( std::vector<ScFormulaCell*>& rCells );
2243 
2244     void                PutInFormulaTree( ScFormulaCell* pCell );
2245     void                RemoveFromFormulaTree( ScFormulaCell* pCell );
2246 
2247 /**
2248      * Calculate formula cells that are on the formula tree either partially,
2249      * or in full.
2250      *
2251      * @param bOnlyForced when true, it only calculates those formula cells
2252      *                    that are marked "recalc forced".
2253      * @param bProgressBar whether or not to use progress bar.
2254      * @param bSetAllDirty when true, it marks all formula cells currently on
2255      *                     the formula tree dirty, which forces all of them to
2256      *                     be recalculated.  When false, only those cells
2257      *                     that are marked dirty prior to this call get
2258      *                     recalculated.
2259      */
2260     SC_DLLPUBLIC void   CalcFormulaTree( bool bOnlyForced = false, bool bProgressBar = true, bool bSetAllDirty = true );
2261     void                ClearFormulaTree();
2262     void                AppendToFormulaTrack( ScFormulaCell* pCell );
2263     void                RemoveFromFormulaTrack( ScFormulaCell* pCell );
2264     void                TrackFormulas( SfxHintId nHintId = SfxHintId::ScDataChanged );
SetTrackFormulasPending()2265     void                SetTrackFormulasPending() { mbTrackFormulasPending = true; }
IsTrackFormulasPending() const2266     bool                IsTrackFormulasPending() const { return mbTrackFormulasPending; }
2267     void                FinalTrackFormulas( SfxHintId nHintId );
IsFinalTrackFormulas() const2268     bool                IsFinalTrackFormulas() const { return mbFinalTrackFormulas; }
2269     bool                IsInFormulaTree( const ScFormulaCell* pCell ) const;
2270     bool                IsInFormulaTrack( const ScFormulaCell* pCell ) const;
GetHardRecalcState() const2271     HardRecalcState     GetHardRecalcState() const { return eHardRecalcState; }
SetHardRecalcState(HardRecalcState eVal)2272     void                SetHardRecalcState( HardRecalcState eVal ) { eHardRecalcState = eVal; }
2273     void                StartAllListeners();
2274     void                StartNeededListeners();
2275     void                StartNeededListeners( const std::shared_ptr<const sc::ColumnSet>& rpColSet );
2276     void                StartAllListeners( const ScRange& rRange );
2277 
SetForcedFormulas(bool bVal)2278     void                SetForcedFormulas( bool bVal ) { bHasForcedFormulas = bVal; }
GetFormulaCodeInTree() const2279     sal_uLong           GetFormulaCodeInTree() const { return nFormulaCodeInTree; }
2280 
IsInInterpreter() const2281     bool                IsInInterpreter() const { return nInterpretLevel != 0; }
2282 
IncInterpretLevel()2283     void                IncInterpretLevel()
2284                             {
2285                                 assert(!IsThreadedGroupCalcInProgress());
2286                                 if ( nInterpretLevel < USHRT_MAX )
2287                                     nInterpretLevel++;
2288                             }
DecInterpretLevel()2289     void                DecInterpretLevel()
2290                             {
2291                                 assert(!IsThreadedGroupCalcInProgress());
2292                                 if ( nInterpretLevel )
2293                                     nInterpretLevel--;
2294                             }
GetMacroInterpretLevel() const2295     sal_uInt16          GetMacroInterpretLevel() const { return nMacroInterpretLevel; }
IncMacroInterpretLevel()2296     void                IncMacroInterpretLevel()
2297                             {
2298                                 assert(!IsThreadedGroupCalcInProgress());
2299                                 if ( nMacroInterpretLevel < USHRT_MAX )
2300                                     nMacroInterpretLevel++;
2301                             }
DecMacroInterpretLevel()2302     void                DecMacroInterpretLevel()
2303                             {
2304                                 assert(!IsThreadedGroupCalcInProgress());
2305                                 if ( nMacroInterpretLevel )
2306                                     nMacroInterpretLevel--;
2307                             }
IsInInterpreterTableOp() const2308     bool                IsInInterpreterTableOp() const { return nInterpreterTableOpLevel != 0; }
IncInterpreterTableOpLevel()2309     void                IncInterpreterTableOpLevel()
2310                             {
2311                                 if ( nInterpreterTableOpLevel < USHRT_MAX )
2312                                     nInterpreterTableOpLevel++;
2313                             }
DecInterpreterTableOpLevel()2314     void                DecInterpreterTableOpLevel()
2315                             {
2316                                 if ( nInterpreterTableOpLevel )
2317                                     nInterpreterTableOpLevel--;
2318                             }
2319 
2320     // add a formula to be remembered for TableOp broadcasts
2321     void                AddTableOpFormulaCell( ScFormulaCell* );
InvalidateLastTableOpParams()2322     void                InvalidateLastTableOpParams() { aLastTableOpParams.bValid = false; }
2323     ScRecursionHelper&  GetRecursionHelper();
IsInDtorClear() const2324     bool                IsInDtorClear() const { return bInDtorClear; }
2325     void                SetExpandRefs( bool bVal );
IsExpandRefs() const2326     bool                IsExpandRefs() const { return bExpandRefs; }
2327 
GetXMLImportedFormulaCount() const2328     sal_uLong           GetXMLImportedFormulaCount() const { return nXMLImportedFormulaCount; }
IncXMLImportedFormulaCount(sal_uLong nVal)2329     void                IncXMLImportedFormulaCount( sal_uLong nVal )
2330                             {
2331                                 if ( nXMLImportedFormulaCount + nVal > nXMLImportedFormulaCount )
2332                                     nXMLImportedFormulaCount += nVal;
2333                             }
DecXMLImportedFormulaCount(sal_uLong nVal)2334     void                DecXMLImportedFormulaCount( sal_uLong nVal )
2335                             {
2336                                 if ( nVal <= nXMLImportedFormulaCount )
2337                                     nXMLImportedFormulaCount -= nVal;
2338                                 else
2339                                     nXMLImportedFormulaCount = 0;
2340                             }
2341 
2342     void                StartTrackTimer();
2343 
2344     void                CompileDBFormula();
2345     void                CompileColRowNameFormula();
2346 
2347     /** Maximum string length of a column, e.g. for dBase export.
2348         @return String length in octets (!) of the destination encoding. In
2349                 case of non-octet encodings (e.g. UCS2) the length in code
2350                 points times sizeof(sal_Unicode) is returned. */
2351     sal_Int32       GetMaxStringLen( SCTAB nTab, SCCOL nCol,
2352                                      SCROW nRowStart, SCROW nRowEnd,
2353                                      rtl_TextEncoding eCharSet ) const;
2354     /** Maximum string length of numerical cells of a column, e.g. for dBase export.
2355         @return String length in characters (!) including the decimal
2356                 separator, and the decimal precision needed. */
2357     sal_Int32       GetMaxNumberStringLen( sal_uInt16& nPrecision,
2358                                            SCTAB nTab, SCCOL nCol,
2359                                            SCROW nRowStart, SCROW nRowEnd ) const;
2360 
2361     void            KeyInput();      // TimerDelays etc.
2362 
GetChangeTrack() const2363     ScChangeTrack*  GetChangeTrack() const { return pChangeTrack.get(); }
2364 
2365     //! only for import filter, deletes any existing ChangeTrack via
2366     //! EndChangeTracking() and takes ownership of new ChangeTrack pTrack
2367     SC_DLLPUBLIC void  SetChangeTrack( std::unique_ptr<ScChangeTrack> pTrack );
2368 
2369     void               StartChangeTracking();
2370     void               EndChangeTracking();
2371 
2372     SC_DLLPUBLIC void  CompareDocument( ScDocument& rOtherDoc );
2373 
2374     void               AddUnoObject( SfxListener& rObject );
2375     void               RemoveUnoObject( SfxListener& rObject );
2376     void               BroadcastUno( const SfxHint &rHint );
2377     void               AddUnoListenerCall( const css::uno::Reference<
2378                                            css::util::XModifyListener >& rListener,
2379                                            const css::lang::EventObject& rEvent );
2380 
2381     void                           SetInLinkUpdate(bool bSet);             // TableLink or AreaLink
2382     bool                           IsInLinkUpdate() const;                 // including DdeLink
2383 
2384     SC_DLLPUBLIC SfxItemPool*       GetEditPool() const;
2385     SC_DLLPUBLIC SfxItemPool*       GetEnginePool() const;
2386     SC_DLLPUBLIC ScFieldEditEngine& GetEditEngine();
2387     SC_DLLPUBLIC ScNoteEditEngine&  GetNoteEngine();
2388 
GetRefreshTimerControlAddress() const2389     std::unique_ptr<ScRefreshTimerControl> const & GetRefreshTimerControlAddress() const
2390                                        { return pRefreshTimerControl; }
2391 
SetPastingDrawFromOtherDoc(bool bVal)2392     void              SetPastingDrawFromOtherDoc( bool bVal )
2393                           { bPastingDrawFromOtherDoc = bVal; }
PastingDrawFromOtherDoc() const2394     bool              PastingDrawFromOtherDoc() const
2395                           { return bPastingDrawFromOtherDoc; }
2396 
2397                       /// an ID unique to each document instance
2398     sal_uInt32        GetDocumentID() const;
2399 
InvalidateStyleSheetUsage()2400     void              InvalidateStyleSheetUsage() { bStyleSheetUsageInvalid = true; }
2401     void SC_DLLPUBLIC GetSortParam( ScSortParam& rParam, SCTAB nTab );
2402     void SC_DLLPUBLIC SetSortParam( const ScSortParam& rParam, SCTAB nTab );
2403 
SetVbaEventProcessor(const css::uno::Reference<css::script::vba::XVBAEventProcessor> & rxVbaEvents)2404     void SetVbaEventProcessor( const css::uno::Reference< css::script::vba::XVBAEventProcessor >& rxVbaEvents )
2405                         { mxVbaEvents = rxVbaEvents; }
GetVbaEventProcessor() const2406     const css::uno::Reference< css::script::vba::XVBAEventProcessor >& GetVbaEventProcessor() const { return mxVbaEvents; }
2407 
2408     /** Should only be GRAM_PODF or GRAM_ODFF. */
2409     void                              SetStorageGrammar( formula::FormulaGrammar::Grammar eGrammar );
GetStorageGrammar() const2410     formula::FormulaGrammar::Grammar  GetStorageGrammar() const { return eStorageGrammar; }
2411 
2412     SC_DLLPUBLIC SfxUndoManager* GetUndoManager();
2413     bool                         IsInVBAMode() const;
2414     ScRowBreakIterator*          GetRowBreakIterator(SCTAB nTab) const;
2415 
2416     void                         AddSubTotalCell(ScFormulaCell* pCell);
2417     void                         RemoveSubTotalCell(ScFormulaCell* pCell);
2418     void                         SetSubTotalCellsDirty(const ScRange& rDirtyRange);
2419 
2420     sal_uInt16                   GetTextWidth( const ScAddress& rPos ) const;
2421 
2422     SvtScriptType                GetScriptType( const ScAddress& rPos ) const;
2423     void                         SetScriptType( const ScAddress& rPos, SvtScriptType nType );
2424     void                         UpdateScriptTypes( const ScAddress& rPos, SCCOL nColSize, SCROW nRowSize );
2425 
2426     size_t                       GetFormulaHash( const ScAddress& rPos ) const;
2427 
2428     /**
2429      * Make specified formula cells non-grouped.
2430      *
2431      * @param nTab sheet index
2432      * @param nCol column index
2433      * @param rRows list of row indices at which formula cells are to be
2434      *              unshared. This call sorts the passed row indices and
2435      *              removes duplicates, which is why the caller must pass it
2436      *              as reference.
2437      */
2438     void UnshareFormulaCells( SCTAB nTab, SCCOL nCol, std::vector<SCROW>& rRows );
2439     void RegroupFormulaCells( SCTAB nTab, SCCOL nCol );
2440     void RegroupFormulaCells( const ScRange& range );
2441 
2442     ScFormulaVectorState GetFormulaVectorState( const ScAddress& rPos ) const;
2443 
2444     formula::FormulaTokenRef ResolveStaticReference( const ScAddress& rPos );
2445     formula::FormulaTokenRef ResolveStaticReference( const ScRange& rRange );
2446 
2447     formula::VectorRefArray FetchVectorRefArray( const ScAddress& rPos, SCROW nLength );
2448     bool HandleRefArrayForParallelism( const ScAddress& rPos, SCROW nLength, const ScFormulaCellGroupRef& mxGroup );
2449 #ifdef DBG_UTIL
2450     void AssertNoInterpretNeeded( const ScAddress& rPos, SCROW nLength );
2451 #endif
2452 
2453     /**
2454      * Call this before any operations that might trigger one or more formula
2455      * cells to get calculated.
2456      */
2457     void PrepareFormulaCalc();
2458 
2459     /**
2460      * Make sure all of the formula cells in the specified range have been
2461      * fully calculated.  This method only re-calculates those formula cells
2462      * that have been flagged dirty. In case of formula-groups, this calculates
2463      * only the dirty subspans along with the dependents in the same way
2464      * recursively.
2465      *
2466      * @param rRange       range in which to potentially calculate the formula
2467      *                     cells.
2468      * @param bSkipRunning flag to skip evaluation of formula-cells that are
2469      *                     marked as already being evaluated.
2470      * @return             true if at least one formula-cell in the specified range was dirty
2471      *                     else returns false.
2472      */
2473     SC_DLLPUBLIC bool EnsureFormulaCellResults( const ScRange& rRange, bool bSkipRunning = false );
2474 
2475     SvtBroadcaster*         GetBroadcaster( const ScAddress& rPos );
2476     const SvtBroadcaster*   GetBroadcaster( const ScAddress& rPos ) const;
2477     void                    DeleteBroadcasters( sc::ColumnBlockPosition& rBlockPos, const ScAddress& rTopPos, SCROW nLength );
2478 
2479     std::unique_ptr<sc::ColumnIterator> GetColumnIterator( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const;
2480     void CreateColumnIfNotExists( SCTAB nTab, SCCOL nCol );
2481 
2482     SC_DLLPUBLIC void StoreTabToCache(SCTAB nTab, SvStream& rStrm) const;
2483     SC_DLLPUBLIC void RestoreTabFromCache(SCTAB nTab, SvStream& rStream);
2484 
2485 #if DUMP_COLUMN_STORAGE
2486     SC_DLLPUBLIC void DumpColumnStorage( SCTAB nTab, SCCOL nCol ) const;
2487 #endif
2488 
2489 #if DEBUG_AREA_BROADCASTER
2490     SC_DLLPUBLIC void DumpAreaBroadcasters() const;
2491 #endif
2492 
2493     SC_DLLPUBLIC void   SetCalcConfig( const ScCalcConfig& rConfig );
GetCalcConfig() const2494     const ScCalcConfig& GetCalcConfig() const { return maCalcConfig; }
2495     void                ConvertFormulaToValue( const ScRange& rRange, sc::TableValues* pUndo );
2496     void                SwapNonEmpty( sc::TableValues& rValues );
2497     void                finalizeOutlineImport();
2498     bool                TableExists( SCTAB nTab ) const;
2499 
2500     SC_DLLPUBLIC ScColumnsRange GetColumnsRange(SCTAB nTab, SCCOL nColBegin, SCCOL nColEnd) const;
2501 
IsInDocShellRecalc() const2502     bool IsInDocShellRecalc() const   { return mbDocShellRecalc; }
SetDocShellRecalc(bool bSet)2503     void SetDocShellRecalc(bool bSet) { mbDocShellRecalc = bSet; }
2504 
2505 private:
2506 
2507     /**
2508      * Use this class as a locale variable to merge number formatter from
2509      * another document, and set NULL pointer to pFormatExchangeList when
2510      * done.
2511      */
2512     class NumFmtMergeHandler
2513     {
2514     public:
2515         explicit NumFmtMergeHandler(ScDocument* pDoc, const ScDocument* pSrcDoc);
2516         ~NumFmtMergeHandler();
2517 
2518     private:
2519         ScDocument* mpDoc;
2520     };
2521 
2522     ScTable* FetchTable( SCTAB nTab );
2523     const ScTable* FetchTable( SCTAB nTab ) const;
2524 
2525     void    MergeNumberFormatter(const ScDocument* pSrcDoc);
2526 
2527     void    ImplCreateOptions(); // Suggestion: switch to on-demand?
2528     void    ImplDeleteOptions();
2529 
2530     void    DeleteDrawLayer();
2531     SC_DLLPUBLIC bool   DrawGetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) const;
2532 
2533     void    UpdateDrawPrinter();
2534     void    UpdateDrawLanguages();
2535     SC_DLLPUBLIC void   InitClipPtrs( ScDocument* pSourceDoc );
2536 
2537     void    LoadDdeLinks(SvStream& rStream);
2538     void    SaveDdeLinks(SvStream& rStream) const;
2539 
2540     void    DeleteAreaLinksOnTab( SCTAB nTab );
2541     void    UpdateRefAreaLinks( UpdateRefMode eUpdateRefMode,
2542                              const ScRange& r, SCCOL nDx, SCROW nDy, SCTAB nDz );
2543 
2544     void    CopyRangeNamesToClip(ScDocument* pClipDoc, const ScRange& rClipRange, const ScMarkData* pMarks);
2545 
2546     bool    HasPartOfMerged( const ScRange& rRange );
2547 
2548     ScRefCellValue GetRefCellValue( const ScAddress& rPos );
2549     ScRefCellValue GetRefCellValue( const ScAddress& rPos, sc::ColumnBlockPosition& rBlockPos );
2550 
2551     std::map< SCTAB, ScSortParam > mSheetSortParams;
2552 
2553     SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol ) const;
2554     SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const;
2555     void   ReservePatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserve );
2556 
2557     void SharePooledResources( const ScDocument* pSrcDoc );
2558 
2559     void EndListeningIntersectedGroup(
2560         sc::EndListeningContext& rCxt, const ScAddress& rPos, std::vector<ScAddress>* pGroupPos );
2561 
2562     void EndListeningIntersectedGroups(
2563         sc::EndListeningContext& rCxt, const ScRange& rRange, std::vector<ScAddress>* pGroupPos );
2564 
2565     void EndListeningGroups( const std::vector<ScAddress>& rPosArray );
2566     void SetNeedsListeningGroups( const std::vector<ScAddress>& rPosArray );
2567 };
2568 
2569 typedef std::unique_ptr<ScDocument, o3tl::default_delete<ScDocument>> ScDocumentUniquePtr;
2570 
2571 /**
2572  * Instantiate this to ensure that subsequent modification of
2573  * the document will cause an assertion failure while this is
2574  * in-scope.
2575  */
2576 struct ScMutationDisable
2577 {
ScMutationDisableScMutationDisable2578     ScMutationDisable(ScDocument* pDocument, ScMutationGuardFlags nFlags)
2579     {
2580 #ifndef NDEBUG
2581         mpDocument = pDocument;
2582         mnFlagRestore = pDocument->mnMutationGuardFlags;
2583         assert((mnFlagRestore & nFlags) == 0);
2584         mpDocument->mnMutationGuardFlags |= static_cast<size_t>(nFlags);
2585 #else
2586         (void)pDocument; (void)nFlags;
2587 #endif
2588     }
2589 #ifndef NDEBUG
~ScMutationDisableScMutationDisable2590     ~ScMutationDisable()
2591     {
2592         mpDocument->mnMutationGuardFlags = mnFlagRestore;
2593     }
2594     size_t mnFlagRestore;
2595     ScDocument* mpDocument;
2596 #endif
2597 };
2598 
2599 /**
2600  * A pretty assertion that checks that the relevant bits in
2601  * the @nFlags are not set on the document at entry and exit.
2602  *
2603  * Its primary use is for debugging threading. As such, an
2604  * @ScMutationDisable is created to forbid mutation, and this
2605  * condition is then asserted on at prominent sites that
2606  * mutate @nFlags.
2607  */
2608 struct ScMutationGuard
2609 {
ScMutationGuardScMutationGuard2610     ScMutationGuard(ScDocument* pDocument, ScMutationGuardFlags nFlags)
2611     {
2612 #ifndef NDEBUG
2613         mpDocument = pDocument;
2614         mnFlags = static_cast<size_t>(nFlags);
2615         assert((mpDocument->mnMutationGuardFlags & mnFlags) == 0);
2616 #else
2617         (void)pDocument; (void)nFlags;
2618 #endif
2619     }
2620 #ifndef NDEBUG
~ScMutationGuardScMutationGuard2621     ~ScMutationGuard()
2622     {
2623         assert((mpDocument->mnMutationGuardFlags & mnFlags) == 0);
2624     }
2625     size_t mnFlags;
2626     ScDocument* mpDocument;
2627 #endif
2628 
2629 };
2630 
2631 class ScDocShellRecalcGuard
2632 {
2633     ScDocument& mrDoc;
2634 
2635 public:
ScDocShellRecalcGuard(ScDocument & rDoc)2636     ScDocShellRecalcGuard(ScDocument& rDoc)
2637         : mrDoc(rDoc)
2638     {
2639         assert(!mrDoc.IsInDocShellRecalc());
2640         mrDoc.SetDocShellRecalc(true);
2641     }
2642 
~ScDocShellRecalcGuard()2643     ~ScDocShellRecalcGuard()
2644     {
2645         mrDoc.SetDocShellRecalc(false);
2646     }
2647 };
2648 
2649 #endif
2650 
2651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2652