Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / inc / docsh.hxx
blob7e103902fb1f32479b28e03efba8a01e2aa98ad6
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 SC_DOCSHELL_HXX
21 #define SC_DOCSHELL_HXX
24 #include <sfx2/objsh.hxx>
26 #include <sfx2/docfac.hxx>
27 #include <sfx2/sfxmodelfactory.hxx>
28 #include <sfx2/viewsh.hxx>
30 #include "scdllapi.h"
31 #include "scdll.hxx"
32 #include "document.hxx"
33 #include "appoptio.hxx"
34 #include "formulaopt.hxx"
35 #include "shellids.hxx"
36 #include "optutil.hxx"
37 #include "docuno.hxx"
39 #include <boost/unordered_map.hpp>
40 #include <boost/scoped_ptr.hpp>
41 #include <cppuhelper/implbase1.hxx>
43 #include <config_telepathy.h>
45 class ScRefreshTimerProtector;
46 class ScEditEngineDefaulter;
47 class SfxStyleSheetBasePool;
48 class SfxStyleSheetHint;
49 class INetURLObject;
51 class ScViewData;
52 class ScDocFunc;
53 class ScDrawLayer;
54 class ScTabViewShell;
55 class ScSbxDocHelper;
56 class ScAutoStyleList;
57 class ScRange;
58 class ScMarkData;
59 class ScPaintLockData;
60 class ScChangeAction;
61 class VirtualDevice;
62 class ScImportOptions;
63 class ScDocShellModificator;
64 class ScOptSolverSave;
65 class ScRefreshTimer;
66 class ScSheetSaveData;
67 class ScFlatBoolRowSegments;
68 class HelperModelObj;
69 struct ScColWidthParam;
70 #if ENABLE_TELEPATHY
71 class ScCollaboration;
72 #endif
74 namespace sfx2 { class FileDialogHelper; }
75 struct DocShell_Impl;
77 typedef ::boost::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
79 //==================================================================
81 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
83 // Extra flags for Repaint
84 #define SC_PF_LINES 1
85 #define SC_PF_TESTMERGE 2
86 #define SC_PF_WHOLEROWS 4
88 class SC_DLLPUBLIC ScDocShell: public SfxObjectShell, public SfxListener
90 ScDocument aDocument;
92 OUString aDdeTextFmt;
94 double nPrtToScreenFactor;
95 DocShell_Impl* pImpl;
96 ScDocFunc* pDocFunc;
98 bool bHeaderOn;
99 bool bFooterOn;
100 bool bIsInplace:1; // Is set by the View
101 bool bIsEmpty:1;
102 bool bIsInUndo:1;
103 bool bDocumentModifiedPending:1;
104 bool bUpdateEnabled:1;
105 sal_uInt16 nDocumentLock;
106 sal_Int16 nCanUpdate; // stores the UpdateDocMode from loading a document till update links
108 ScDBData* pOldAutoDBRange;
110 ScSbxDocHelper* pDocHelper;
112 ScAutoStyleList* pAutoStyleList;
113 ScPaintLockData* pPaintLockData;
114 ScOptSolverSave* pSolverSaveData;
115 ScSheetSaveData* pSheetSaveData;
117 ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
118 #if ENABLE_TELEPATHY
119 ScCollaboration* mpCollaboration;
120 #endif
122 SC_DLLPRIVATE void InitItems();
123 SC_DLLPRIVATE void DoEnterHandler();
124 SC_DLLPRIVATE void InitOptions(bool bForLoading);
125 SC_DLLPRIVATE void ResetDrawObjectShell();
127 // SUNWS needs a forward declared friend, otherwise types and members
128 // of the outer class are not accessible.
129 class PrepareSaveGuard;
130 friend class ScDocShell::PrepareSaveGuard;
131 /** Do things that need to be done before saving to our own format and
132 necessary clean ups in dtor. */
133 class PrepareSaveGuard
135 public:
136 explicit PrepareSaveGuard( ScDocShell & rDocShell );
137 ~PrepareSaveGuard();
138 private:
139 ScDocShell & mrDocShell;
142 SC_DLLPRIVATE sal_Bool LoadXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
143 SC_DLLPRIVATE sal_Bool SaveXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
144 SC_DLLPRIVATE SCTAB GetSaveTab();
146 SC_DLLPRIVATE bool SaveCurrentChart( SfxMedium& rMedium );
148 SC_DLLPRIVATE sal_uLong DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
149 ScColWidthParam aColWidthParam[MAXCOLCOUNT], ScFlatBoolRowSegments& rRowHeightsRecalc );
150 SC_DLLPRIVATE sal_uLong DBaseExport(
151 const OUString& rFullFileName, rtl_TextEncoding eCharSet, bool& bHasMemo );
153 SC_DLLPRIVATE static bool MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
154 SC_DLLPRIVATE static bool KillFile( const INetURLObject& rURL );
155 SC_DLLPRIVATE static bool IsDocument( const INetURLObject& rURL );
157 SC_DLLPRIVATE void LockPaint_Impl(sal_Bool bDoc);
158 SC_DLLPRIVATE void UnlockPaint_Impl(sal_Bool bDoc);
159 SC_DLLPRIVATE void LockDocument_Impl(sal_uInt16 nNew);
160 SC_DLLPRIVATE void UnlockDocument_Impl(sal_uInt16 nNew);
162 SC_DLLPRIVATE void EnableSharedSettings( bool bEnable );
163 SC_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument();
165 SC_DLLPRIVATE void UseSheetSaveEntries();
167 SC_DLLPRIVATE ScDocFunc *CreateDocFunc();
169 protected:
171 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
173 public:
174 TYPEINFO();
176 SFX_DECL_INTERFACE(SCID_DOC_SHELL)
177 SFX_DECL_OBJECTFACTORY();
179 ScDocShell( const ScDocShell& rDocShell );
180 ScDocShell( const sal_uInt64 i_nSfxCreationFlags = SFXMODEL_EMBEDDED_OBJECT );
181 ~ScDocShell();
183 using SotObject::GetInterface;
184 using SfxShell::Activate; // with sal_Bool bMDI
185 using SfxShell::Deactivate; // with sal_Bool bMDI
187 #if ENABLE_TELEPATHY
188 SC_DLLPRIVATE ScCollaboration* GetCollaboration();
189 #endif
190 virtual void Activate();
191 virtual void Deactivate();
193 virtual ::svl::IUndoManager*
194 GetUndoManager();
196 virtual void FillClass( SvGlobalName * pClassName,
197 sal_uInt32 * pFormat,
198 OUString * pAppName,
199 OUString * pFullTypeName,
200 OUString * pShortTypeName,
201 sal_Int32 nFileFormat,
202 sal_Bool bTemplate = false ) const;
204 virtual sal_Bool InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
205 virtual sal_Bool Load( SfxMedium& rMedium );
206 virtual sal_Bool LoadFrom( SfxMedium& rMedium );
207 virtual sal_Bool ConvertFrom( SfxMedium &rMedium );
208 virtual bool LoadExternal( SfxMedium& rMedium );
209 virtual sal_Bool Save();
210 virtual sal_Bool SaveAs( SfxMedium& rMedium );
211 virtual sal_Bool ConvertTo( SfxMedium &rMedium );
212 virtual sal_uInt16 PrepareClose( sal_Bool bUI = sal_True, sal_Bool bForBrowsing = false );
213 virtual void PrepareReload();
214 virtual sal_Bool IsInformationLost();
215 virtual void LoadStyles( SfxObjectShell &rSource );
217 virtual sal_Bool SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ); // SfxInPlaceObject
218 virtual sal_Bool DoSaveCompleted( SfxMedium * pNewStor); // SfxObjectShell
219 virtual sal_Bool QuerySlotExecutable( sal_uInt16 nSlotId );
221 virtual void Draw( OutputDevice *, const JobSetup & rSetup,
222 sal_uInt16 nAspect = ASPECT_CONTENT );
224 virtual void SetVisArea( const Rectangle & rVisArea );
226 using SfxObjectShell::GetVisArea;
227 virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const;
229 virtual Printer* GetDocumentPrinter();
231 virtual void SetModified( sal_Bool = sal_True );
233 void SetVisAreaOrSize( const Rectangle& rVisArea, sal_Bool bModifyStart );
235 virtual SfxDocumentInfoDialog* CreateDocumentInfoDialog( Window *pParent,
236 const SfxItemSet &rSet );
238 void GetDocStat( ScDocStat& rDocStat );
240 ScDocument* GetDocument() { return &aDocument; }
241 ScDocFunc& GetDocFunc() { return *pDocFunc; }
242 void SetDocFunc( ScDocFunc *pDF ) { pDocFunc = pDF; }
244 SfxPrinter* GetPrinter( sal_Bool bCreateIfNotExist = sal_True );
245 sal_uInt16 SetPrinter( SfxPrinter* pNewPrinter, sal_uInt16 nDiffFlags = SFX_PRINTER_ALL );
247 void UpdateFontList();
249 OUString CreateObjectName( const OUString& rPrefix );
251 ScDrawLayer* MakeDrawLayer();
253 void AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
255 void GetSbxState( SfxItemSet &rSet );
256 void GetDrawObjState( SfxItemSet &rSet );
258 void Execute( SfxRequest& rReq );
259 void GetState( SfxItemSet &rSet );
260 void ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
261 void GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab );
263 void CompareDocument( ScDocument& rOtherDoc );
264 void MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = NULL, bool bInverseMap = false );
265 bool MergeSharedDocument( ScDocShell* pSharedDocShell );
267 ScChangeAction* GetChangeAction( const ScAddress& rPos );
268 void SetChangeComment( ScChangeAction* pAction, const OUString& rComment );
269 void ExecuteChangeCommentDialog( ScChangeAction* pAction, Window* pParent,sal_Bool bPrevNext=sal_True );
270 /// Protect/unprotect ChangeTrack and return <TRUE/> if
271 /// protection was successfully changed.
272 /// If bJustQueryIfProtected==sal_True protection is not
273 /// changed and <TRUE/> is returned if not protected or
274 /// password was entered correctly.
275 bool ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected = false );
277 void SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
278 bool AdjustPrintZoom( const ScRange& rRange );
280 void LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellStyles, bool bPageStyles );
282 void PageStyleModified( const OUString& rStyleName, sal_Bool bApi );
284 void NotifyStyle( const SfxStyleSheetHint& rHint );
285 void DoAutoStyle( const ScRange& rRange, const OUString& rStyle );
287 Window* GetActiveDialogParent();
288 void ErrorMessage( sal_uInt16 nGlobStrId );
289 sal_Bool IsEditable() const;
291 sal_Bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
292 void UpdateAllRowHeights( const ScMarkData* pTabMark = NULL );
293 void UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
295 void RefreshPivotTables( const ScRange& rSource );
296 void DoConsolidate( const ScConsolidateParam& rParam, sal_Bool bRecord = sal_True );
297 void UseScenario( SCTAB nTab, const OUString& rName, sal_Bool bRecord = sal_True );
298 SCTAB MakeScenario( SCTAB nTab, const OUString& rName, const OUString& rComment,
299 const Color& rColor, sal_uInt16 nFlags,
300 ScMarkData& rMark, sal_Bool bRecord = sal_True );
301 void ModifyScenario( SCTAB nTab, const OUString& rName, const OUString& rComment,
302 const Color& rColor, sal_uInt16 nFlags );
303 sal_uLong TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
304 SCTAB nDestPos, sal_Bool bInsertNew,
305 sal_Bool bNotifyAndPaint );
307 sal_Bool MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord );
309 void DoRecalc( bool bApi );
310 void DoHardRecalc( bool bApi );
312 void UpdateOle( const ScViewData* pViewData, sal_Bool bSnapSize = false);
313 sal_Bool IsOle();
315 void DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
316 ScDBData* GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
317 ScDBData* GetAnonymousDBData(const ScRange& rRange);
318 ScDBData* GetOldAutoDBRange(); // has to be deleted by caller!
319 void CancelAutoDBRange(); // called when dialog is cancelled
321 virtual void ReconnectDdeLink(SfxObjectShell& rServer);
322 void UpdateLinks();
323 sal_Bool ReloadTabLinks();
325 void SetFormulaOptions(const ScFormulaOptions& rOpt );
326 virtual void CheckConfigOptions();
328 void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
330 void PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
331 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart,
332 sal_uInt16 nExtFlags = 0 );
333 void PostPaint( const ScRangeList& rRanges, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 );
335 void PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
336 void PostPaintCell( const ScAddress& rPos );
337 void PostPaintGridAll();
338 void PostPaintExtras();
340 bool IsPaintLocked() const { return pPaintLockData != NULL; }
342 void PostDataChanged();
344 void UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
345 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
346 void UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
348 void SetDocumentModified( sal_Bool bIsModified = sal_True );
349 void SetDrawModified( sal_Bool bIsModified = sal_True );
351 void LockPaint();
352 void UnlockPaint();
353 sal_uInt16 GetLockCount() const;
354 void SetLockCount(sal_uInt16 nNew);
356 void LockDocument();
357 void UnlockDocument();
359 DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
361 virtual SfxStyleSheetBasePool* GetStyleSheetPool();
363 void SetInplace( bool bInplace );
364 bool IsEmpty() const;
365 void SetEmpty(bool bSet);
367 bool IsInUndo() const { return bIsInUndo; }
368 void SetInUndo(bool bSet);
370 void CalcOutputFactor();
371 double GetOutputFactor() const;
372 void GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
373 SCTAB nCurTab,
374 bool& rbHeader,
375 bool& rbFooter );
377 virtual long DdeGetData( const OUString& rItem, const OUString& rMimeType,
378 ::com::sun::star::uno::Any & rValue );
379 virtual long DdeSetData( const OUString& rItem, const OUString& rMimeType,
380 const ::com::sun::star::uno::Any & rValue );
381 virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem );
383 const OUString& GetDdeTextFmt() const { return aDdeTextFmt; }
385 SfxBindings* GetViewBindings();
387 ScTabViewShell* GetBestViewShell( sal_Bool bOnlyVisible = sal_True );
388 ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; }
390 void SetDocumentModifiedPending( bool bVal )
391 { bDocumentModifiedPending = bVal; }
392 bool IsDocumentModifiedPending() const
393 { return bDocumentModifiedPending; }
395 bool IsUpdateEnabled() const
396 { return bUpdateEnabled; }
397 void SetUpdateEnabled(bool bValue)
398 { bUpdateEnabled = bValue; }
400 OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
402 static ScViewData* GetViewData();
403 static SCTAB GetCurTab();
405 static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
406 static OUString GetOwnFilterName();
407 static OUString GetHtmlFilterName();
408 static OUString GetWebQueryFilterName();
409 static OUString GetAsciiFilterName();
410 static OUString GetLotusFilterName();
411 static OUString GetDBaseFilterName();
412 static OUString GetDifFilterName();
413 static sal_Bool HasAutomaticTableName( const OUString& rFilter );
415 DECL_LINK( RefreshDBDataHdl, ScRefreshTimer* );
417 void BeforeXMLLoading();
418 void AfterXMLLoading(sal_Bool bRet);
420 virtual sal_uInt16 GetHiddenInformationState( sal_uInt16 nStates );
422 const ScOptSolverSave* GetSolverSaveData() const { return pSolverSaveData; } // may be null
423 void SetSolverSaveData( const ScOptSolverSave& rData );
424 ScSheetSaveData* GetSheetSaveData();
426 void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
428 // password protection for Calc (derived from SfxObjectShell)
429 // see also: FID_CHG_RECORD, SID_CHG_PROTECT
430 virtual bool IsChangeRecording() const;
431 virtual bool HasChangeRecordProtection() const;
432 virtual void SetChangeRecording( bool bActivate );
433 virtual bool SetProtectionPassword( const OUString &rPassword );
434 virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash );
437 void SnapVisArea( Rectangle& rRect ) const;
441 void UpdateAcceptChangesDialog();
444 SV_DECL_REF(ScDocShell)
445 SV_IMPL_REF(ScDocShell)
448 /** Create before modifications of the document and destroy thereafter.
449 Call SetDocumentModified() at an instance of this class instead of at
450 ScDocShell.
452 Remembers in the ctor ScDocument's AutoCalcShellDisabled and IdleDisabled,
453 switches them off and restores them in the dtor, AutoCalcShellDisabled
454 also before a ScDocShell::SetDocumentModified() call if necessary.
455 In the dtor, if ScDocShell's bDocumentModifiedPending is set and
456 bAutoCalcShellDisabled is not set, then ScDocShell::SetDocumentModified()
457 is called.
459 Several instances can be used in nested calls to ScDocFunc or ScDocShell
460 methods to avoid multiple modified status changes, only the last instance
461 destroyed calls ScDocShell::SetDocumentModified().
463 class SC_DLLPUBLIC ScDocShellModificator
465 ScDocShell& rDocShell;
466 boost::scoped_ptr<ScRefreshTimerProtector> mpProtector;
467 bool bAutoCalcShellDisabled;
468 bool bIdleEnabled;
470 // not implemented
471 ScDocShellModificator( const ScDocShellModificator& );
472 ScDocShellModificator& operator=( const ScDocShellModificator& );
474 public:
475 ScDocShellModificator( ScDocShell& );
476 ~ScDocShellModificator();
477 void SetDocumentModified();
480 //#i97876# Spreadsheet data changes are not notified
481 namespace HelperNotifyChanges
483 inline ScModelObj* getMustPropagateChangesModel(ScDocShell &rDocShell)
485 ScModelObj* pModelObj = ScModelObj::getImplementation(rDocShell.GetModel());
486 if (pModelObj && pModelObj->HasChangesListeners())
487 return pModelObj;
488 return NULL;
491 inline void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges,
492 const OUString &rType = OUString("cell-change"),
493 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProperties =
494 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >())
496 rModelObj.NotifyChanges(rType, rChangeRanges, rProperties);
499 inline void NotifyIfChangesListeners(ScDocShell &rDocShell, const ScRange &rRange,
500 const OUString &rType = OUString("cell-change"))
502 if (ScModelObj* pModelObj = getMustPropagateChangesModel(rDocShell))
504 ScRangeList aChangeRanges;
505 aChangeRanges.Append(rRange);
506 Notify(*pModelObj, aChangeRanges, rType);
512 #endif
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */