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