Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / inc / docsh.hxx
blob079b542e68dc9640b7403bc081ac2116e360ede3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_DOCSH_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_DOCSH_HXX
23 #include <sfx2/objsh.hxx>
25 #include <sfx2/docfac.hxx>
26 #include <sfx2/sfxmodelfactory.hxx>
27 #include <sfx2/viewsh.hxx>
29 #include "scdllapi.h"
30 #include "scdll.hxx"
31 #include "document.hxx"
32 #include "appoptio.hxx"
33 #include "formulaopt.hxx"
34 #include "shellids.hxx"
35 #include "optutil.hxx"
36 #include "docuno.hxx"
38 #include <config_telepathy.h>
39 #include <memory>
40 #include <unordered_map>
42 class ScRefreshTimerProtector;
43 class ScEditEngineDefaulter;
44 class SfxStyleSheetBasePool;
45 class SfxStyleSheetHint;
46 class INetURLObject;
48 class ScViewData;
49 class ScDocFunc;
50 class ScDrawLayer;
51 class ScTabViewShell;
52 class ScSbxDocHelper;
53 class ScAutoStyleList;
54 class ScRange;
55 class ScMarkData;
56 class ScPaintLockData;
57 class ScChangeAction;
58 class VirtualDevice;
59 class ScImportOptions;
60 class ScDocShellModificator;
61 class ScOptSolverSave;
62 class ScRefreshTimer;
63 class ScSheetSaveData;
64 class ScFlatBoolRowSegments;
65 class HelperModelObj;
66 struct ScColWidthParam;
67 #if ENABLE_TELEPATHY
68 class ScCollaboration;
69 #endif
71 namespace sfx2 { class FileDialogHelper; }
72 struct DocShell_Impl;
74 typedef std::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
76 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
78 // Extra flags for Repaint
79 #define SC_PF_LINES 1
80 #define SC_PF_TESTMERGE 2
81 #define SC_PF_WHOLEROWS 4
83 class SC_DLLPUBLIC ScDocShell final: public SfxObjectShell, public SfxListener
85 ScDocument aDocument;
87 OUString aDdeTextFmt;
89 double nPrtToScreenFactor;
90 DocShell_Impl* pImpl;
91 ScDocFunc* pDocFunc;
93 bool bHeaderOn;
94 bool bFooterOn;
95 bool bIsInplace:1; // Is set by the View
96 bool bIsEmpty:1;
97 bool bIsInUndo:1;
98 bool bDocumentModifiedPending:1;
99 bool bUpdateEnabled:1;
100 sal_uInt16 nDocumentLock;
101 sal_Int16 nCanUpdate; // stores the UpdateDocMode from loading a document till update links
103 ScDBData* pOldAutoDBRange;
105 ScAutoStyleList* pAutoStyleList;
106 ScPaintLockData* pPaintLockData;
107 ScOptSolverSave* pSolverSaveData;
108 ScSheetSaveData* pSheetSaveData;
110 ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
111 #if ENABLE_TELEPATHY
112 ScCollaboration* mpCollaboration;
113 #endif
115 SAL_DLLPRIVATE void InitItems();
116 SAL_DLLPRIVATE void DoEnterHandler();
117 SAL_DLLPRIVATE void InitOptions(bool bForLoading);
118 SAL_DLLPRIVATE void ResetDrawObjectShell();
120 /** Do things that need to be done before saving to our own format and
121 necessary clean ups in dtor. */
122 class PrepareSaveGuard
124 public:
125 explicit PrepareSaveGuard( ScDocShell & rDocShell );
126 ~PrepareSaveGuard();
127 private:
128 ScDocShell & mrDocShell;
131 SAL_DLLPRIVATE bool LoadXML( SfxMedium* pMedium, const css::uno::Reference< css::embed::XStorage >& );
132 SAL_DLLPRIVATE bool SaveXML( SfxMedium* pMedium, const css::uno::Reference< css::embed::XStorage >& );
133 SAL_DLLPRIVATE SCTAB GetSaveTab();
135 SAL_DLLPRIVATE bool SaveCurrentChart( SfxMedium& rMedium );
137 SAL_DLLPRIVATE sal_uLong DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
138 ScColWidthParam aColWidthParam[MAXCOLCOUNT], ScFlatBoolRowSegments& rRowHeightsRecalc );
139 SAL_DLLPRIVATE sal_uLong DBaseExport(
140 const OUString& rFullFileName, rtl_TextEncoding eCharSet, bool& bHasMemo );
142 SAL_DLLPRIVATE static bool MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
143 SAL_DLLPRIVATE static bool KillFile( const INetURLObject& rURL );
144 SAL_DLLPRIVATE static bool IsDocument( const INetURLObject& rURL );
146 SAL_DLLPRIVATE void LockPaint_Impl(bool bDoc);
147 SAL_DLLPRIVATE void UnlockPaint_Impl(bool bDoc);
148 SAL_DLLPRIVATE void LockDocument_Impl(sal_uInt16 nNew);
149 SAL_DLLPRIVATE void UnlockDocument_Impl(sal_uInt16 nNew);
151 SAL_DLLPRIVATE void EnableSharedSettings( bool bEnable );
152 SAL_DLLPRIVATE css::uno::Reference< css::frame::XModel > LoadSharedDocument();
154 SAL_DLLPRIVATE void UseSheetSaveEntries();
156 SAL_DLLPRIVATE ScDocFunc *CreateDocFunc();
158 protected:
160 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
162 public:
163 SFX_DECL_INTERFACE(SCID_DOC_SHELL)
164 SFX_DECL_OBJECTFACTORY();
166 private:
167 /// SfxInterface initializer.
168 static void InitInterface_Impl();
170 public:
171 ScDocShell( const ScDocShell& rDocShell );
172 ScDocShell( const SfxModelFlags i_nSfxCreationFlags = SfxModelFlags::EMBEDDED_OBJECT );
173 virtual ~ScDocShell();
175 #if ENABLE_TELEPATHY
176 SAL_DLLPRIVATE ScCollaboration* GetCollaboration();
177 #endif
179 virtual ::svl::IUndoManager*
180 GetUndoManager() override;
182 virtual void FillClass( SvGlobalName * pClassName,
183 SotClipboardFormatId * pFormat,
184 OUString * pAppName,
185 OUString * pFullTypeName,
186 OUString * pShortTypeName,
187 sal_Int32 nFileFormat,
188 bool bTemplate = false ) const override;
190 virtual std::set<Color> GetDocColors() override;
192 virtual bool InitNew( const css::uno::Reference< css::embed::XStorage >& ) override;
193 virtual bool Load( SfxMedium& rMedium ) override;
194 virtual bool LoadFrom( SfxMedium& rMedium ) override;
195 virtual bool ConvertFrom( SfxMedium &rMedium ) override;
196 virtual bool LoadExternal( SfxMedium& rMedium ) override;
197 virtual bool Save() override;
198 virtual bool SaveAs( SfxMedium& rMedium ) override;
199 virtual bool ConvertTo( SfxMedium &rMedium ) override;
200 virtual bool PrepareClose( bool bUI = true ) override;
201 virtual void PrepareReload() override;
202 virtual bool IsInformationLost() override;
203 virtual void LoadStyles( SfxObjectShell &rSource ) override;
205 virtual bool SaveCompleted( const css::uno::Reference< css::embed::XStorage >& ) override; // SfxInPlaceObject
206 virtual bool DoSaveCompleted( SfxMedium * pNewStor, bool bRegisterRecent ) override; // SfxObjectShell
207 virtual bool QuerySlotExecutable( sal_uInt16 nSlotId ) override;
209 virtual void Draw( OutputDevice *, const JobSetup & rSetup,
210 sal_uInt16 nAspect = ASPECT_CONTENT ) override;
212 virtual void SetVisArea( const Rectangle & rVisArea ) override;
214 using SfxObjectShell::GetVisArea;
215 virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const override;
217 virtual Printer* GetDocumentPrinter() override;
219 virtual void SetModified( bool = true ) override;
221 void SetVisAreaOrSize( const Rectangle& rVisArea );
223 virtual VclPtr<SfxDocumentInfoDialog> CreateDocumentInfoDialog( const SfxItemSet &rSet ) override;
225 void GetDocStat( ScDocStat& rDocStat );
227 ScDocument& GetDocument() { return aDocument; }
228 ScDocFunc& GetDocFunc() { return *pDocFunc; }
229 void SetDocFunc( ScDocFunc *pDF ) { pDocFunc = pDF; }
231 SfxPrinter* GetPrinter( bool bCreateIfNotExist = true );
232 sal_uInt16 SetPrinter( SfxPrinter* pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL );
234 void UpdateFontList();
236 ScDrawLayer* MakeDrawLayer();
238 void AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
240 void GetSbxState( SfxItemSet &rSet );
241 static void GetDrawObjState( SfxItemSet &rSet );
243 void Execute( SfxRequest& rReq );
244 void GetState( SfxItemSet &rSet );
245 void ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
246 void GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab );
248 void CompareDocument( ScDocument& rOtherDoc );
249 void MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = nullptr, bool bInverseMap = false );
250 bool MergeSharedDocument( ScDocShell* pSharedDocShell );
252 ScChangeAction* GetChangeAction( const ScAddress& rPos );
253 void SetChangeComment( ScChangeAction* pAction, const OUString& rComment );
254 void ExecuteChangeCommentDialog( ScChangeAction* pAction, vcl::Window* pParent, bool bPrevNext = true );
255 /// Protect/unprotect ChangeTrack and return <TRUE/> if
256 /// protection was successfully changed.
257 /// If bJustQueryIfProtected==sal_True protection is not
258 /// changed and <TRUE/> is returned if not protected or
259 /// password was entered correctly.
260 bool ExecuteChangeProtectionDialog( vcl::Window* _pParent, bool bJustQueryIfProtected = false );
262 void SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
263 bool AdjustPrintZoom( const ScRange& rRange );
265 void LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellStyles, bool bPageStyles );
267 void PageStyleModified( const OUString& rStyleName, bool bApi );
269 void NotifyStyle( const SfxStyleSheetHint& rHint );
270 void DoAutoStyle( const ScRange& rRange, const OUString& rStyle );
272 static vcl::Window* GetActiveDialogParent();
273 void ErrorMessage( sal_uInt16 nGlobStrId );
274 bool IsEditable() const;
276 bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
277 void UpdateAllRowHeights( const ScMarkData* pTabMark = nullptr );
278 void UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
280 void RefreshPivotTables( const ScRange& rSource );
281 void DoConsolidate( const ScConsolidateParam& rParam, bool bRecord = true );
282 void UseScenario( SCTAB nTab, const OUString& rName, bool bRecord = true );
283 SCTAB MakeScenario( SCTAB nTab, const OUString& rName, const OUString& rComment,
284 const Color& rColor, sal_uInt16 nFlags,
285 ScMarkData& rMark, bool bRecord = true );
286 void ModifyScenario( SCTAB nTab, const OUString& rName, const OUString& rComment,
287 const Color& rColor, sal_uInt16 nFlags );
288 sal_uLong TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
289 SCTAB nDestPos, bool bInsertNew,
290 bool bNotifyAndPaint );
292 bool MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRecord );
294 void DoRecalc( bool bApi );
295 void DoHardRecalc( bool bApi );
297 void UpdateOle( const ScViewData* pViewData, bool bSnapSize = false);
298 bool IsOle();
300 void DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
301 ScDBData* GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
302 ScDBData* GetAnonymousDBData(const ScRange& rRange);
303 ScDBData* GetOldAutoDBRange(); // has to be deleted by caller!
304 void CancelAutoDBRange(); // called when dialog is cancelled
306 virtual void ReconnectDdeLink(SfxObjectShell& rServer) override;
307 void UpdateLinks() override;
308 void ReloadTabLinks();
310 void SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoading = false );
311 void SetCalcConfig( const ScCalcConfig& rConfig );
312 virtual void CheckConfigOptions() override;
314 void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
316 void PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
317 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart,
318 sal_uInt16 nExtFlags = 0 );
319 void PostPaint( const ScRangeList& rRanges, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 );
321 void PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
322 void PostPaintCell( const ScAddress& rPos );
323 void PostPaintGridAll();
324 void PostPaintExtras();
326 bool IsPaintLocked() const { return pPaintLockData != nullptr; }
328 void PostDataChanged();
330 void UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
331 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
332 void UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
334 void SetDocumentModified();
335 void SetDrawModified();
337 void LockPaint();
338 void UnlockPaint();
339 sal_uInt16 GetLockCount() const { return nDocumentLock;}
340 void SetLockCount(sal_uInt16 nNew);
342 void LockDocument();
343 void UnlockDocument();
345 DECL_LINK_TYPED( DialogClosedHdl, sfx2::FileDialogHelper*, void );
347 virtual SfxStyleSheetBasePool* GetStyleSheetPool() override;
349 void SetInplace( bool bInplace );
350 bool IsEmpty() const { return bIsEmpty; }
351 void SetEmpty(bool bSet);
353 bool IsInUndo() const { return bIsInUndo; }
354 void SetInUndo(bool bSet);
356 void CalcOutputFactor();
357 double GetOutputFactor() const { return nPrtToScreenFactor;}
358 void GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
359 SCTAB nCurTab,
360 bool& rbHeader,
361 bool& rbFooter );
363 #if defined(_WIN32)
364 virtual bool DdeGetData( const OUString& rItem, const OUString& rMimeType,
365 css::uno::Any & rValue ) override;
366 virtual bool DdeSetData( const OUString& rItem, const OUString& rMimeType,
367 const css::uno::Any & rValue ) override;
368 #endif
370 virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem ) override;
372 const OUString& GetDdeTextFmt() const { return aDdeTextFmt; }
374 SfxBindings* GetViewBindings();
376 ScTabViewShell* GetBestViewShell( bool bOnlyVisible = true );
378 void SetDocumentModifiedPending( bool bVal )
379 { bDocumentModifiedPending = bVal; }
380 bool IsDocumentModifiedPending() const
381 { return bDocumentModifiedPending; }
383 bool IsUpdateEnabled() const
384 { return bUpdateEnabled; }
385 void SetUpdateEnabled(bool bValue)
386 { bUpdateEnabled = bValue; }
388 OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
390 static ScViewData* GetViewData();
391 static SCTAB GetCurTab();
393 static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
394 static OUString GetOwnFilterName();
395 static OUString GetHtmlFilterName();
396 static OUString GetWebQueryFilterName();
397 static OUString GetAsciiFilterName();
398 static OUString GetLotusFilterName();
399 static OUString GetDBaseFilterName();
400 static OUString GetDifFilterName();
401 static bool HasAutomaticTableName( const OUString& rFilter );
403 DECL_LINK_TYPED( RefreshDBDataHdl, Timer*, void );
405 void BeforeXMLLoading();
406 void AfterXMLLoading(bool bRet);
408 virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) override;
410 const ScOptSolverSave* GetSolverSaveData() const { return pSolverSaveData; } // may be null
411 void SetSolverSaveData( const ScOptSolverSave& rData );
412 ScSheetSaveData* GetSheetSaveData();
414 static void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
416 // password protection for Calc (derived from SfxObjectShell)
417 // see also: FID_CHG_RECORD, SID_CHG_PROTECT
418 virtual bool IsChangeRecording() const override;
419 virtual bool HasChangeRecordProtection() const override;
420 virtual void SetChangeRecording( bool bActivate ) override;
421 virtual void SetProtectionPassword( const OUString &rPassword ) override;
422 virtual bool GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > &rPasswordHash ) override;
424 void SnapVisArea( Rectangle& rRect ) const;
426 virtual void libreOfficeKitCallback(int nType, const char* pPayload) const override;
429 void UpdateAcceptChangesDialog();
431 class ScDocShell;
432 typedef tools::SvRef<ScDocShell> ScDocShellRef;
434 /** Create before modifications of the document and destroy thereafter.
435 Call SetDocumentModified() at an instance of this class instead of at
436 ScDocShell.
438 Remembers in the ctor ScDocument's AutoCalcShellDisabled and IdleDisabled,
439 switches them off and restores them in the dtor, AutoCalcShellDisabled
440 also before a ScDocShell::SetDocumentModified() call if necessary.
441 In the dtor, if ScDocShell's bDocumentModifiedPending is set and
442 bAutoCalcShellDisabled is not set, then ScDocShell::SetDocumentModified()
443 is called.
445 Several instances can be used in nested calls to ScDocFunc or ScDocShell
446 methods to avoid multiple modified status changes, only the last instance
447 destroyed calls ScDocShell::SetDocumentModified().
449 class SC_DLLPUBLIC ScDocShellModificator
451 ScDocShell& rDocShell;
452 std::unique_ptr<ScRefreshTimerProtector> mpProtector;
453 bool bAutoCalcShellDisabled;
454 bool bIdleEnabled;
456 ScDocShellModificator( const ScDocShellModificator& ) = delete;
457 ScDocShellModificator& operator=( const ScDocShellModificator& ) = delete;
459 public:
460 ScDocShellModificator( ScDocShell& );
461 ~ScDocShellModificator();
462 void SetDocumentModified();
465 //#i97876# Spreadsheet data changes are not notified
466 namespace HelperNotifyChanges
468 inline ScModelObj* getMustPropagateChangesModel(ScDocShell &rDocShell)
470 ScModelObj* pModelObj = ScModelObj::getImplementation(rDocShell.GetModel());
471 if (pModelObj && pModelObj->HasChangesListeners())
472 return pModelObj;
473 return nullptr;
476 inline void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges,
477 const OUString &rType = OUString("cell-change"),
478 const css::uno::Sequence< css::beans::PropertyValue >& rProperties =
479 css::uno::Sequence< css::beans::PropertyValue >())
481 rModelObj.NotifyChanges(rType, rChangeRanges, rProperties);
484 inline void NotifyIfChangesListeners(ScDocShell &rDocShell, const ScRange &rRange,
485 const OUString &rType = OUString("cell-change"))
487 if (ScModelObj* pModelObj = getMustPropagateChangesModel(rDocShell))
489 ScRangeList aChangeRanges;
490 aChangeRanges.Append(rRange);
491 Notify(*pModelObj, aChangeRanges, rType);
496 void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const OUString& sModuleName, const OUString& sModuleSource );
498 #endif
500 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */