Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/inc/docsh.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#include <sfx2/objsh.hxx>
23
#include <sfx2/docfac.hxx>
24
#include <sfx2/sfxmodelfactory.hxx>
25
#include <sfx2/viewsh.hxx>
26
#include <o3tl/deleter.hxx>
27
#include <comphelper/lok.hxx>
28
#include <comphelper/servicehelper.hxx>
29
30
#include <scdllapi.h>
31
#include <document.hxx>
32
#include <shellids.hxx>
33
#include <optutil.hxx>
34
#include <docuno.hxx>
35
36
#include <memory>
37
#include <string_view>
38
#include <unordered_map>
39
#include <map>
40
41
class ScRefreshTimerProtector;
42
class ScEditEngineDefaulter;
43
class SfxStyleSheetHint;
44
class INetURLObject;
45
46
class ScViewData;
47
class ScDocFunc;
48
class ScDrawLayer;
49
class ScTabViewShell;
50
class ScAutoStyleList;
51
class ScMarkData;
52
class ScPaintLockData;
53
class ScChangeAction;
54
class ScImportOptions;
55
class ScDocShellModificator;
56
class ScSheetSaveData;
57
class ScFlatBoolRowSegments;
58
struct ScColWidthParam;
59
class ScFormulaOptions;
60
namespace com::sun::star::script::vba { class XVBAScriptListener; }
61
namespace ooo::vba::excel { class XWorkbook; }
62
namespace com::sun::star::datatransfer { class XTransferable2; }
63
namespace sfx2 { class FileDialogHelper; }
64
struct DocShell_Impl;
65
66
typedef std::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
67
68
//enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
69
70
enum class LOKCommentNotificationType { Add, Modify, Remove };
71
72
extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDBF(SvStream &rStream);
73
74
                                    // Extra flags for Repaint
75
30.2k
#define SC_PF_LINES         1
76
29.9k
#define SC_PF_TESTMERGE     2
77
307
#define SC_PF_WHOLEROWS     4
78
79
class SAL_DLLPUBLIC_RTTI ScDocShell final: public SfxObjectShell, public SfxListener
80
{
81
    std::shared_ptr<ScDocument> m_pDocument;
82
83
    OUString            m_aDdeTextFmt;
84
85
    double              m_nPrtToScreenFactor;
86
    std::unique_ptr<DocShell_Impl> m_pImpl;
87
    std::unique_ptr<ScDocFunc> m_pDocFunc;
88
89
    bool                m_bHeaderOn;
90
    bool                m_bFooterOn;
91
    bool                m_bIsInplace:1;         // Is set by the View
92
    bool                m_bIsEmpty:1;
93
    bool                m_bIsInUndo:1;
94
    bool                m_bDocumentModifiedPending:1;
95
    bool                m_bUpdateEnabled:1;
96
    bool                m_bAreasChangedNeedBroadcast:1;
97
    sal_uInt16          m_nDocumentLock;
98
    sal_Int16           m_nCanUpdate;  // stores the UpdateDocMode from loading a document till update links
99
100
    std::unique_ptr<ScDBData> m_pOldAutoDBRange;
101
102
    std::unique_ptr<ScAutoStyleList>    m_pAutoStyleList;
103
    std::unique_ptr<ScPaintLockData>    m_pPaintLockData;
104
    std::unique_ptr<ScSheetSaveData>    m_pSheetSaveData;
105
    std::unique_ptr<ScFormatSaveData>   m_pFormatSaveData;
106
107
    std::unique_ptr<ScDocShellModificator, o3tl::default_delete<ScDocShellModificator>> m_pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
108
109
    css::uno::Reference< ooo::vba::excel::XWorkbook> mxAutomationWorkbookObject;
110
111
    // Only used by Vba helper functions
112
    css::uno::Reference<css::script::vba::XVBAScriptListener>   m_xVBAListener;
113
    css::uno::Reference<css::datatransfer::XTransferable2>      m_xClipData;
114
115
    void          InitItems();
116
    void          DoEnterHandler();
117
    void          InitOptions(bool bForLoading);
118
    void          ResetDrawObjectShell();
119
120
    /** Do things that need to be done before saving to our own format and
121
        necessary clean ups in dtor. */
122
    class PrepareSaveGuard
123
    {
124
        public:
125
            explicit    PrepareSaveGuard( ScDocShell & rDocShell );
126
                        ~PrepareSaveGuard();
127
        private:
128
                        ScDocShell & mrDocShell;
129
    };
130
131
    bool ImportFrom(SfxMedium&, const css::uno::Reference<css::text::XTextRange>&) override;
132
133
    bool          LoadXML( SfxMedium* pMedium, const css::uno::Reference< css::embed::XStorage >& );
134
    bool          SaveXML( SfxMedium* pMedium, const css::uno::Reference< css::embed::XStorage >& );
135
    SCTAB         GetSaveTab();
136
137
    friend bool TestImportDBF(SvStream &rStream);
138
139
    ErrCode       DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
140
                                             std::map<SCCOL, ScColWidthParam>& aColWidthParam, ScFlatBoolRowSegments& rRowHeightsRecalc );
141
    ErrCodeMsg    DBaseExport(
142
                                    const OUString& rFullFileName, rtl_TextEncoding eCharSet, bool& bHasMemo );
143
144
    static bool       MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
145
    static bool       KillFile( const INetURLObject& rURL );
146
    static bool       IsDocument( const INetURLObject& rURL );
147
148
    void          LockPaint_Impl(bool bDoc);
149
    void          UnlockPaint_Impl(bool bDoc);
150
    void          LockDocument_Impl(sal_uInt16 nNew);
151
    void          UnlockDocument_Impl(sal_uInt16 nNew);
152
153
    void          EnableSharedSettings( bool bEnable );
154
    css::uno::Reference< css::frame::XModel > LoadSharedDocument();
155
156
    void          UseSheetSaveEntries();
157
158
    std::unique_ptr<ScDocFunc> CreateDocFunc();
159
160
    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
161
162
public:
163
                    SFX_DECL_INTERFACE(SCID_DOC_SHELL)
164
   SC_DLLPUBLIC static SfxObjectFactory&    Factory();                                  \
165
426k
   virtual SfxObjectFactory&   GetFactory() const override { return Factory(); }
166
167
private:
168
    /// SfxInterface initializer.
169
    static void InitInterface_Impl();
170
171
public:
172
    explicit        ScDocShell( const ScDocShell& rDocShell ) = delete;
173
    SC_DLLPUBLIC explicit ScDocShell( const SfxModelFlags i_nSfxCreationFlags = SfxModelFlags::EMBEDDED_OBJECT, const std::shared_ptr<ScDocument>& pDoc = {} );
174
    explicit ScDocShell(const SfxModelFlags i_nSfxCreationFlags, ScDocumentMode);
175
                    virtual ~ScDocShell() override;
176
177
    SC_DLLPUBLIC virtual SfxUndoManager* GetUndoManager() override;
178
179
    virtual void    FillClass( SvGlobalName * pClassName,
180
                               SotClipboardFormatId * pFormat,
181
                               OUString * pFullTypeName,
182
                               sal_Int32 nFileFormat,
183
                               bool bTemplate = false ) const override;
184
185
    std::shared_ptr<sfx::IDocumentModelAccessor> GetDocumentModelAccessor() const override;
186
    virtual std::set<Color> GetDocColors() override;
187
    virtual std::shared_ptr<model::ColorSet> GetThemeColors() override;
188
189
    virtual bool    InitNew( const css::uno::Reference< css::embed::XStorage >& ) override;
190
    virtual bool    Load( SfxMedium& rMedium ) override;
191
    virtual bool    LoadFrom( SfxMedium& rMedium ) override;
192
    virtual bool    ConvertFrom( SfxMedium &rMedium ) override;
193
    virtual bool    LoadExternal( SfxMedium& rMedium ) override;
194
    virtual bool    Save() override;
195
    virtual bool    SaveAs( SfxMedium& rMedium ) override;
196
    virtual bool    ConvertTo( SfxMedium &rMedium ) override;
197
    virtual bool    PrepareClose( bool bUI = true ) override;
198
    virtual void    LoadStyles( SfxObjectShell &rSource ) override;
199
200
    virtual bool    DoSaveCompleted( SfxMedium * pNewStor=nullptr, bool bRegisterRecent=true ) override;     // SfxObjectShell
201
    virtual bool    QuerySlotExecutable( sal_uInt16 nSlotId ) override;
202
203
    virtual void    Draw(OutputDevice *, const JobSetup & rSetup, sal_uInt16 nAspect, bool bOutputForScreen) override;
204
205
    SC_DLLPUBLIC virtual void SetVisArea( const tools::Rectangle & rVisArea ) override;
206
207
    virtual void    TerminateEditing() override;
208
209
    using SfxObjectShell::GetVisArea;
210
    virtual tools::Rectangle GetVisArea( sal_uInt16 nAspect ) const override;
211
212
    virtual Printer* GetDocumentPrinter() override;
213
214
    virtual void    SetModified( bool = true ) override;
215
216
    void            SetVisAreaOrSize( const tools::Rectangle& rVisArea );
217
218
    virtual std::shared_ptr<SfxDocumentInfoDialog> CreateDocumentInfoDialog(weld::Window* pParent, const SfxItemSet &rSet) override;
219
220
    SC_DLLPUBLIC void GetDocStat( ScDocStat& rDocStat );
221
222
0
    const ScDocument& GetDocument() const { return *m_pDocument; }
223
4.28M
    ScDocument&     GetDocument()   { return *m_pDocument; }
224
84.7k
    ScDocFunc&      GetDocFunc()    { return *m_pDocFunc; }
225
226
0
    css::uno::Reference<css::datatransfer::XTransferable2> const & GetClipData() const { return m_xClipData; }
227
0
    void SetClipData(const css::uno::Reference<css::datatransfer::XTransferable2>& xTransferable) { m_xClipData = xTransferable; }
228
229
    SfxPrinter*     GetPrinter( bool bCreateIfNotExist = true );
230
    sal_uInt16      SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL );
231
232
    void            UpdateFontList();
233
234
    ScDrawLayer*    MakeDrawLayer();
235
236
    void            AsciiSave( SvStream& rStream, const ScImportOptions& rOpt, SCTAB nTab );
237
238
    void            Execute( SfxRequest& rReq );
239
    void            GetState( SfxItemSet &rSet );
240
    void            ExecutePageStyle ( const SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
241
    void            GetStatePageStyle( SfxItemSet& rSet, SCTAB nCurTab );
242
243
    void            CompareDocument( ScDocument& rOtherDoc );
244
    void            MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = nullptr, bool bInverseMap = false );
245
    bool            MergeSharedDocument( ScDocShell* pSharedDocShell );
246
247
    ScChangeAction* GetChangeAction( const ScAddress& rPos );
248
    void            SetChangeComment( ScChangeAction* pAction, const OUString& rComment );
249
    void            ExecuteChangeCommentDialog( ScChangeAction* pAction, weld::Window* pParent, bool bPrevNext = true );
250
                    /// Protect/unprotect ChangeTrack and return <TRUE/> if
251
                    /// protection was successfully changed.
252
                    /// If bJustQueryIfProtected==sal_True protection is not
253
                    /// changed and <TRUE/> is returned if not protected or
254
                    /// password was entered correctly.
255
    bool            ExecuteChangeProtectionDialog( bool bJustQueryIfProtected = false );
256
257
    void            SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
258
    bool            AdjustPrintZoom( const ScRange& rRange );
259
260
    void            LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellStyles, bool bPageStyles );
261
262
    void            PageStyleModified( std::u16string_view rStyleName, bool bApi );
263
264
    void            NotifyStyle( const SfxStyleSheetHint& rHint );
265
    void            DoAutoStyle( const ScRange& rRange, const OUString& rStyle );
266
267
    SC_DLLPUBLIC static weld::Window*  GetActiveDialogParent();
268
    void            ErrorMessage(TranslateId pGlobStrId);
269
    bool            IsEditable() const;
270
271
    /// check config if on file-open optimal row heights should run, or if the user should be asked
272
    SC_DLLPUBLIC bool GetRecalcRowHeightsMode();
273
    bool            AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
274
    SC_DLLPUBLIC void UpdateAllRowHeights( const ScMarkData* pTabMark = nullptr );
275
    SC_DLLPUBLIC void UpdateAllRowHeights(const bool bOnlyUsedRows);
276
    void            UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
277
278
    void            RefreshPivotTables( const ScRange& rSource );
279
    void            DoConsolidate( const ScConsolidateParam& rParam, bool bRecord = true );
280
    void            UseScenario( SCTAB nTab, const OUString& rName, bool bRecord = true );
281
    SCTAB           MakeScenario(SCTAB nTab, const OUString& rName, const OUString& rComment,
282
                                    const Color& rColor, ScScenarioFlags nFlags,
283
                                    ScMarkData& rMark, bool bRecord = true);
284
    void            ModifyScenario(SCTAB nTab, const OUString& rName, const OUString& rComment,
285
                                    const Color& rColor, ScScenarioFlags nFlags);
286
    SC_DLLPUBLIC bool TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
287
                                SCTAB nDestPos, bool bInsertNew,
288
                                bool bNotifyAndPaint );
289
290
    bool            MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRecord );
291
292
    SC_DLLPUBLIC void DoRecalc( bool bApi );
293
    SC_DLLPUBLIC void DoHardRecalc();
294
295
    void            UpdateOle(const ScViewData& rViewData, bool bSnapSize = false);
296
    bool            IsOle() const;
297
298
    void            DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2 );
299
    ScDBData*       GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
300
    ScDBData*       GetAnonymousDBData(const ScRange& rRange);
301
    std::unique_ptr<ScDBData> GetOldAutoDBRange();
302
    void            CancelAutoDBRange();    // called when dialog is cancelled
303
304
    virtual void    ReconnectDdeLink(SfxObjectShell& rServer) override;
305
    void            UpdateLinks() override;
306
    SC_DLLPUBLIC void SetInitialLinkUpdate( const SfxMedium* pMedium );
307
    void            AllowLinkUpdate();
308
    SC_DLLPUBLIC void ReloadAllLinks();
309
    void            ReloadTabLinks();
310
    ScLkUpdMode     GetLinkUpdateModeState() const;
311
312
    SC_DLLPUBLIC void SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoading = false );
313
    /**
314
     * Called when the Options dialog is dismissed with the OK button, to
315
     * handle potentially conflicting option settings.
316
     */
317
    void            CheckConfigOptions();
318
319
    void            PostEditView(ScEditEngineDefaulter& rEditEngine, const ScAddress& rCursorPos);
320
321
    tools::Long     GetTwipWidthHint(const ScAddress& rPos);
322
323
    void            PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
324
                            SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, PaintPartFlags nPart,
325
                            sal_uInt16 nExtFlags = 0, tools::Long nMaxWidthAffectedHint = -1 );
326
    SC_DLLPUBLIC void PostPaint( const ScRangeList& rRanges, PaintPartFlags nPart, sal_uInt16 nExtFlags = 0,
327
                               tools::Long nMaxWidthAffectedHint = -1 );
328
329
    void            PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab, tools::Long nMaxWidthAffectedHint = -1);
330
    void            PostPaintCell( const ScAddress& rPos, tools::Long nMaxWidthAffectedHint = -1);
331
    SC_DLLPUBLIC void PostPaintGridAll();
332
    void            PostPaintExtras();
333
334
0
    bool            IsPaintLocked() const { return m_pPaintLockData != nullptr; }
335
336
    void            PostDataChanged();
337
338
    void            UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
339
                                                       SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
340
    void            UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
341
342
    SC_DLLPUBLIC void SetDocumentModified();
343
    void            SetDrawModified();
344
345
    SC_DLLPUBLIC void LockPaint();
346
    SC_DLLPUBLIC void UnlockPaint();
347
0
    sal_uInt16          GetLockCount() const { return m_nDocumentLock;}
348
    void            SetLockCount(sal_uInt16 nNew);
349
350
    void            LockDocument();
351
    void            UnlockDocument();
352
353
    DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void );
354
    DECL_LINK( ReloadAllLinksHdl, weld::Button&, void );
355
356
    virtual SfxStyleSheetBasePool*  GetStyleSheetPool() override;
357
358
    void            SetInplace( bool bInplace );
359
0
    bool            IsEmpty() const { return m_bIsEmpty; }
360
    SC_DLLPUBLIC void SetEmpty(bool bSet);
361
362
0
    bool            IsInUndo() const                { return m_bIsInUndo; }
363
    void            SetInUndo(bool bSet);
364
365
    void            CalcOutputFactor();
366
12.9k
    double          GetOutputFactor() const { return m_nPrtToScreenFactor;}
367
    void            GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
368
                                               SCTAB             nCurTab,
369
                                               bool&             rbHeader,
370
                                               bool&             rbFooter );
371
372
#if defined(_WIN32)
373
    virtual bool DdeGetData( const OUString& rItem, const OUString& rMimeType,
374
                                css::uno::Any & rValue ) override;
375
    virtual bool DdeSetData( const OUString& rItem, const OUString& rMimeType,
376
                                const css::uno::Any & rValue ) override;
377
#endif
378
379
    virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem ) override;
380
381
0
    const OUString& GetDdeTextFmt() const { return m_aDdeTextFmt; }
382
383
    SAL_RET_MAYBENULL SfxBindings* GetViewBindings();
384
385
    SAL_RET_MAYBENULL SC_DLLPUBLIC ScTabViewShell* GetBestViewShell( bool bOnlyVisible = true );
386
387
    void            SetDocumentModifiedPending( bool bVal )
388
14.8k
                        { m_bDocumentModifiedPending = bVal; }
389
    bool            IsDocumentModifiedPending() const
390
213k
                        { return m_bDocumentModifiedPending; }
391
392
    bool            IsUpdateEnabled() const
393
0
                        { return m_bUpdateEnabled; }
394
    void            SetUpdateEnabled(bool bValue)
395
0
                        { m_bUpdateEnabled = bValue; }
396
397
    void            SetAreasChangedNeedBroadcast()
398
0
                        { m_bAreasChangedNeedBroadcast = true; }
399
400
    OutputDevice*   GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
401
402
    SAL_RET_MAYBENULL SC_DLLPUBLIC static ScViewData* GetViewData();
403
    SC_DLLPUBLIC static SCTAB       GetCurTab();
404
405
    SAL_RET_MAYBENULL static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
406
    static bool       HasAutomaticTableName( std::u16string_view rFilter );
407
    static void       LOKCommentNotify(LOKCommentNotificationType nType, const ScDocument& rDocument, const ScAddress& rPos, const ScPostIt* pNote);
408
409
    DECL_LINK( RefreshDBDataHdl, Timer*, void );
410
411
    void            BeforeXMLLoading();
412
    void            AfterXMLLoading(bool bRet);
413
414
    virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) override;
415
416
    ScSheetSaveData* GetSheetSaveData();
417
    ScFormatSaveData* GetFormatSaveData();
418
419
    static void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
420
421
    // password protection for Calc (derived from SfxObjectShell)
422
    // see also:    FID_CHG_RECORD, SID_CHG_PROTECT
423
    virtual bool    IsChangeRecording(SfxViewShell* pViewShell = nullptr, bool bRecordAllViews = true) const override;
424
    virtual bool    HasChangeRecordProtection() const override;
425
    virtual void    SetChangeRecording( bool bActivate, bool bLockAllViews = false, SfxRedlineRecordingMode eRedlineRecordingMode = SfxRedlineRecordingMode::ViewAgnostic) override;
426
    virtual void    SetProtectionPassword( const OUString &rPassword ) override;
427
    virtual bool    GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override;
428
429
    void SnapVisArea( tools::Rectangle& rRect ) const;
430
431
    SC_DLLPUBLIC void RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const& xWorkbook);
432
433
49.0k
    ScModelObj* GetModel() const { return static_cast<ScModelObj*>(SfxObjectShell::GetModel().get()); }
434
435
    void AddDelayedInfobarEntry(const OUString& sId, const OUString& sPrimaryMessage,
436
                                const OUString& sSecondaryMessage, InfobarType aInfobarType,
437
                                bool bShowCloseButton);
438
439
private:
440
    void ExecuteChartSource(SfxRequest& rReq);
441
    void ExecuteChartSourcePost( bool bUndo, bool bMultiRange,
442
        const OUString& rChartName, const ScRangeListRef& rRangeListRef,
443
        bool bColHeaders, bool bRowHeaders, bool bAddRange,
444
        SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCTAB nTab);
445
446
    void SetLanguage(LanguageType eLatin, LanguageType eCjk, LanguageType eCtl);
447
};
448
449
void UpdateAcceptChangesDialog();
450
451
typedef rtl::Reference<ScDocShell> ScDocShellRef;
452
453
/** Create before modifications of the document and destroy thereafter.
454
    Call SetDocumentModified() at an instance of this class instead of at
455
    ScDocShell.
456
457
    Remembers in the ctor ScDocument's AutoCalcShellDisabled and IdleDisabled,
458
    switches them off and restores them in the dtor, AutoCalcShellDisabled
459
    also before a ScDocShell::SetDocumentModified() call if necessary.
460
    In the dtor, if ScDocShell's bDocumentModifiedPending is set and
461
    bAutoCalcShellDisabled is not set, then ScDocShell::SetDocumentModified()
462
    is called.
463
464
    Several instances can be used in nested calls to ScDocFunc or ScDocShell
465
    methods to avoid multiple modified status changes, only the last instance
466
    destroyed calls ScDocShell::SetDocumentModified().
467
 */
468
class ScDocShellModificator
469
{
470
    ScDocShell&     rDocShell;
471
    std::unique_ptr<ScRefreshTimerProtector> mpProtector;
472
    bool            bAutoCalcShellDisabled;
473
    bool            bIdleEnabled;
474
475
    ScDocShellModificator( const ScDocShellModificator& ) = delete;
476
    ScDocShellModificator&  operator=( const ScDocShellModificator& ) = delete;
477
478
    void ImplDestroy();
479
480
public:
481
    explicit ScDocShellModificator( ScDocShell& );
482
    ~ScDocShellModificator();
483
    void            SetDocumentModified();
484
};
485
486
//#i97876# Spreadsheet data changes are not notified
487
namespace HelperNotifyChanges
488
{
489
    inline bool isDataAreaInvalidateType(std::u16string_view rType)
490
22.2k
    {
491
22.2k
        if (rType == u"delete-content")
492
0
            return true;
493
22.2k
        if (rType == u"delete-rows")
494
0
            return true;
495
22.2k
        if (rType == u"delete-columns")
496
0
            return true;
497
22.2k
        if (rType == u"undo")
498
0
            return true;
499
22.2k
        if (rType == u"redo")
500
0
            return true;
501
22.2k
        if (rType == u"paste")
502
0
            return true;
503
22.2k
        if (rType == u"note")
504
22.2k
            return true;
505
506
0
        return false;
507
22.2k
    }
508
509
    inline bool getMustPropagateChangesModel(const ScModelObj* pModelObj)
510
22.2k
    {
511
22.2k
        return pModelObj && pModelObj->HasChangesListeners();
512
22.2k
    }
513
514
    inline void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges,
515
        const OUString &rType = u"cell-change"_ustr,
516
        const css::uno::Sequence< css::beans::PropertyValue >& rProperties =
517
            css::uno::Sequence< css::beans::PropertyValue >())
518
22.2k
    {
519
22.2k
        rModelObj.NotifyChanges(rType, rChangeRanges, rProperties);
520
22.2k
    }
521
522
    inline void NotifyIfChangesListeners(const ScDocShell &rDocShell, const ScRange &rRange,
523
        const OUString &rType = u"cell-change"_ustr)
524
22.2k
    {
525
22.2k
        ScModelObj* pModelObj = rDocShell.GetModel();
526
22.2k
        ScRangeList aChangeRanges(rRange);
527
528
22.2k
        if (getMustPropagateChangesModel(pModelObj))
529
0
            Notify(*pModelObj, aChangeRanges, rType);
530
22.2k
        else if (pModelObj) // possibly need to invalidate getCellArea results
531
22.2k
        {
532
22.2k
            Notify(*pModelObj, aChangeRanges, isDataAreaInvalidateType(rType)
533
22.2k
                ? u"data-area-invalidate"_ustr : u"data-area-extend"_ustr);
534
22.2k
        }
535
22.2k
    }
536
};
537
538
void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const OUString& sModuleSource );
539
540
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */