fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / inc / docsh.hxx
blob8eba21ac633fa90513153826f6671f266448121a
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 <boost/scoped_ptr.hpp>
39 #include <cppuhelper/implbase1.hxx>
40 #include <config_telepathy.h>
41 #include <unordered_map>
43 class ScRefreshTimerProtector;
44 class ScEditEngineDefaulter;
45 class SfxStyleSheetBasePool;
46 class SfxStyleSheetHint;
47 class INetURLObject;
49 class ScViewData;
50 class ScDocFunc;
51 class ScDrawLayer;
52 class ScTabViewShell;
53 class ScSbxDocHelper;
54 class ScAutoStyleList;
55 class ScRange;
56 class ScMarkData;
57 class ScPaintLockData;
58 class ScChangeAction;
59 class VirtualDevice;
60 class ScImportOptions;
61 class ScDocShellModificator;
62 class ScOptSolverSave;
63 class ScRefreshTimer;
64 class ScSheetSaveData;
65 class ScFlatBoolRowSegments;
66 class HelperModelObj;
67 struct ScColWidthParam;
68 #if ENABLE_TELEPATHY
69 class ScCollaboration;
70 #endif
72 namespace sfx2 { class FileDialogHelper; }
73 struct DocShell_Impl;
75 typedef std::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
77 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
79 // Extra flags for Repaint
80 #define SC_PF_LINES 1
81 #define SC_PF_TESTMERGE 2
82 #define SC_PF_WHOLEROWS 4
84 class SC_DLLPUBLIC ScDocShell: public SfxObjectShell, public SfxListener
86 ScDocument aDocument;
88 OUString aDdeTextFmt;
90 double nPrtToScreenFactor;
91 DocShell_Impl* pImpl;
92 ScDocFunc* pDocFunc;
94 bool bHeaderOn;
95 bool bFooterOn;
96 bool bIsInplace:1; // Is set by the View
97 bool bIsEmpty:1;
98 bool bIsInUndo:1;
99 bool bDocumentModifiedPending:1;
100 bool bUpdateEnabled:1;
101 sal_uInt16 nDocumentLock;
102 sal_Int16 nCanUpdate; // stores the UpdateDocMode from loading a document till update links
104 ScDBData* pOldAutoDBRange;
106 ScSbxDocHelper* pDocHelper;
108 ScAutoStyleList* pAutoStyleList;
109 ScPaintLockData* pPaintLockData;
110 ScOptSolverSave* pSolverSaveData;
111 ScSheetSaveData* pSheetSaveData;
113 ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
114 #if ENABLE_TELEPATHY
115 ScCollaboration* mpCollaboration;
116 #endif
118 SAL_DLLPRIVATE void InitItems();
119 SAL_DLLPRIVATE void DoEnterHandler();
120 SAL_DLLPRIVATE void InitOptions(bool bForLoading);
121 SAL_DLLPRIVATE void ResetDrawObjectShell();
123 /** Do things that need to be done before saving to our own format and
124 necessary clean ups in dtor. */
125 class PrepareSaveGuard
127 public:
128 explicit PrepareSaveGuard( ScDocShell & rDocShell );
129 ~PrepareSaveGuard();
130 private:
131 ScDocShell & mrDocShell;
134 SAL_DLLPRIVATE bool LoadXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
135 SAL_DLLPRIVATE bool SaveXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
136 SAL_DLLPRIVATE SCTAB GetSaveTab();
138 SAL_DLLPRIVATE bool SaveCurrentChart( SfxMedium& rMedium );
140 SAL_DLLPRIVATE sal_uLong DBaseImport( const OUString& rFullFileName, rtl_TextEncoding eCharSet,
141 ScColWidthParam aColWidthParam[MAXCOLCOUNT], ScFlatBoolRowSegments& rRowHeightsRecalc );
142 SAL_DLLPRIVATE sal_uLong DBaseExport(
143 const OUString& rFullFileName, rtl_TextEncoding eCharSet, bool& bHasMemo );
145 SAL_DLLPRIVATE static bool MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
146 SAL_DLLPRIVATE static bool KillFile( const INetURLObject& rURL );
147 SAL_DLLPRIVATE static bool IsDocument( const INetURLObject& rURL );
149 SAL_DLLPRIVATE void LockPaint_Impl(bool bDoc);
150 SAL_DLLPRIVATE void UnlockPaint_Impl(bool bDoc);
151 SAL_DLLPRIVATE void LockDocument_Impl(sal_uInt16 nNew);
152 SAL_DLLPRIVATE void UnlockDocument_Impl(sal_uInt16 nNew);
154 SAL_DLLPRIVATE void EnableSharedSettings( bool bEnable );
155 SAL_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument();
157 SAL_DLLPRIVATE void UseSheetSaveEntries();
159 SAL_DLLPRIVATE ScDocFunc *CreateDocFunc();
161 protected:
163 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
165 public:
166 TYPEINFO_OVERRIDE();
167 SFX_DECL_INTERFACE(SCID_DOC_SHELL)
168 SFX_DECL_OBJECTFACTORY();
170 private:
171 /// SfxInterface initializer.
172 static void InitInterface_Impl();
174 public:
175 ScDocShell( const ScDocShell& rDocShell );
176 ScDocShell( const SfxModelFlags i_nSfxCreationFlags = SfxModelFlags::EMBEDDED_OBJECT );
177 virtual ~ScDocShell();
179 #if ENABLE_TELEPATHY
180 SAL_DLLPRIVATE ScCollaboration* GetCollaboration();
181 #endif
183 virtual ::svl::IUndoManager*
184 GetUndoManager() SAL_OVERRIDE;
186 virtual void FillClass( SvGlobalName * pClassName,
187 SotClipboardFormatId * pFormat,
188 OUString * pAppName,
189 OUString * pFullTypeName,
190 OUString * pShortTypeName,
191 sal_Int32 nFileFormat,
192 bool bTemplate = false ) const SAL_OVERRIDE;
194 virtual std::set<Color> GetDocColors() SAL_OVERRIDE;
196 virtual bool InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ) SAL_OVERRIDE;
197 virtual bool Load( SfxMedium& rMedium ) SAL_OVERRIDE;
198 virtual bool LoadFrom( SfxMedium& rMedium ) SAL_OVERRIDE;
199 virtual bool ConvertFrom( SfxMedium &rMedium ) SAL_OVERRIDE;
200 virtual bool LoadExternal( SfxMedium& rMedium ) SAL_OVERRIDE;
201 virtual bool Save() SAL_OVERRIDE;
202 virtual bool SaveAs( SfxMedium& rMedium ) SAL_OVERRIDE;
203 virtual bool ConvertTo( SfxMedium &rMedium ) SAL_OVERRIDE;
204 virtual bool PrepareClose( bool bUI = true ) SAL_OVERRIDE;
205 virtual void PrepareReload() SAL_OVERRIDE;
206 virtual bool IsInformationLost() SAL_OVERRIDE;
207 virtual void LoadStyles( SfxObjectShell &rSource ) SAL_OVERRIDE;
209 virtual bool SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ) SAL_OVERRIDE; // SfxInPlaceObject
210 virtual bool DoSaveCompleted( SfxMedium * pNewStor) SAL_OVERRIDE; // SfxObjectShell
211 virtual bool QuerySlotExecutable( sal_uInt16 nSlotId ) SAL_OVERRIDE;
213 virtual void Draw( OutputDevice *, const JobSetup & rSetup,
214 sal_uInt16 nAspect = ASPECT_CONTENT ) SAL_OVERRIDE;
216 virtual void SetVisArea( const Rectangle & rVisArea ) SAL_OVERRIDE;
218 using SfxObjectShell::GetVisArea;
219 virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const SAL_OVERRIDE;
221 virtual Printer* GetDocumentPrinter() SAL_OVERRIDE;
223 virtual void SetModified( bool = true ) SAL_OVERRIDE;
225 void SetVisAreaOrSize( const Rectangle& rVisArea, bool bModifyStart );
227 virtual VclPtr<SfxDocumentInfoDialog> CreateDocumentInfoDialog( vcl::Window *pParent,
228 const SfxItemSet &rSet ) SAL_OVERRIDE;
230 void GetDocStat( ScDocStat& rDocStat );
232 ScDocument& GetDocument() { return aDocument; }
233 ScDocFunc& GetDocFunc() { return *pDocFunc; }
234 void SetDocFunc( ScDocFunc *pDF ) { pDocFunc = pDF; }
236 SfxPrinter* GetPrinter( bool bCreateIfNotExist = true );
237 sal_uInt16 SetPrinter( SfxPrinter* pNewPrinter, SfxPrinterChangeFlags nDiffFlags = SFX_PRINTER_ALL );
239 void UpdateFontList();
241 OUString CreateObjectName( const OUString& rPrefix );
243 ScDrawLayer* MakeDrawLayer();
245 void AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
247 void GetSbxState( SfxItemSet &rSet );
248 static void GetDrawObjState( SfxItemSet &rSet );
250 void Execute( SfxRequest& rReq );
251 void GetState( SfxItemSet &rSet );
252 void ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
253 void GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab );
255 void CompareDocument( ScDocument& rOtherDoc );
256 void MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = NULL, bool bInverseMap = false );
257 bool MergeSharedDocument( ScDocShell* pSharedDocShell );
259 ScChangeAction* GetChangeAction( const ScAddress& rPos );
260 void SetChangeComment( ScChangeAction* pAction, const OUString& rComment );
261 void ExecuteChangeCommentDialog( ScChangeAction* pAction, vcl::Window* pParent, bool bPrevNext = true );
262 /// Protect/unprotect ChangeTrack and return <TRUE/> if
263 /// protection was successfully changed.
264 /// If bJustQueryIfProtected==sal_True protection is not
265 /// changed and <TRUE/> is returned if not protected or
266 /// password was entered correctly.
267 bool ExecuteChangeProtectionDialog( vcl::Window* _pParent, bool bJustQueryIfProtected = false );
269 void SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
270 bool AdjustPrintZoom( const ScRange& rRange );
272 void LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellStyles, bool bPageStyles );
274 void PageStyleModified( const OUString& rStyleName, bool bApi );
276 void NotifyStyle( const SfxStyleSheetHint& rHint );
277 void DoAutoStyle( const ScRange& rRange, const OUString& rStyle );
279 static vcl::Window* GetActiveDialogParent();
280 void ErrorMessage( sal_uInt16 nGlobStrId );
281 bool IsEditable() const;
283 bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
284 void UpdateAllRowHeights( const ScMarkData* pTabMark = NULL );
285 void UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
287 void RefreshPivotTables( const ScRange& rSource );
288 void DoConsolidate( const ScConsolidateParam& rParam, bool bRecord = true );
289 void UseScenario( SCTAB nTab, const OUString& rName, bool bRecord = true );
290 SCTAB MakeScenario( SCTAB nTab, const OUString& rName, const OUString& rComment,
291 const Color& rColor, sal_uInt16 nFlags,
292 ScMarkData& rMark, bool bRecord = true );
293 void ModifyScenario( SCTAB nTab, const OUString& rName, const OUString& rComment,
294 const Color& rColor, sal_uInt16 nFlags );
295 sal_uLong TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
296 SCTAB nDestPos, bool bInsertNew,
297 bool bNotifyAndPaint );
299 bool MoveTable( SCTAB nSrcTab, SCTAB nDestTab, bool bCopy, bool bRecord );
301 void DoRecalc( bool bApi );
302 void DoHardRecalc( bool bApi );
304 void UpdateOle( const ScViewData* pViewData, bool bSnapSize = false);
305 bool IsOle();
307 void DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
308 ScDBData* GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
309 ScDBData* GetAnonymousDBData(const ScRange& rRange);
310 ScDBData* GetOldAutoDBRange(); // has to be deleted by caller!
311 void CancelAutoDBRange(); // called when dialog is cancelled
313 virtual void ReconnectDdeLink(SfxObjectShell& rServer) SAL_OVERRIDE;
314 void UpdateLinks() SAL_OVERRIDE;
315 bool ReloadTabLinks();
317 void SetFormulaOptions( const ScFormulaOptions& rOpt, bool bForLoading = false );
318 void SetCalcConfig( const ScCalcConfig& rConfig );
319 virtual void CheckConfigOptions() SAL_OVERRIDE;
321 void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
323 void PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
324 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart,
325 sal_uInt16 nExtFlags = 0 );
326 void PostPaint( const ScRangeList& rRanges, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 );
328 void PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
329 void PostPaintCell( const ScAddress& rPos );
330 void PostPaintGridAll();
331 void PostPaintExtras();
333 bool IsPaintLocked() const { return pPaintLockData != NULL; }
335 void PostDataChanged();
337 void UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
338 SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
339 void UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
341 void SetDocumentModified( bool bIsModified = true );
342 void SetDrawModified( bool bIsModified = true );
344 void LockPaint();
345 void UnlockPaint();
346 sal_uInt16 GetLockCount() const { return nDocumentLock;}
347 void SetLockCount(sal_uInt16 nNew);
349 void LockDocument();
350 void UnlockDocument();
352 DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
354 virtual SfxStyleSheetBasePool* GetStyleSheetPool() SAL_OVERRIDE;
356 void SetInplace( bool bInplace );
357 bool IsEmpty() const { return bIsEmpty; }
358 void SetEmpty(bool bSet);
360 bool IsInUndo() const { return bIsInUndo; }
361 void SetInUndo(bool bSet);
363 void CalcOutputFactor();
364 double GetOutputFactor() const { return nPrtToScreenFactor;}
365 void GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
366 SCTAB nCurTab,
367 bool& rbHeader,
368 bool& rbFooter );
370 #if defined WNT
371 virtual bool DdeGetData( const OUString& rItem, const OUString& rMimeType,
372 ::com::sun::star::uno::Any & rValue ) SAL_OVERRIDE;
373 virtual bool DdeSetData( const OUString& rItem, const OUString& rMimeType,
374 const ::com::sun::star::uno::Any & rValue ) SAL_OVERRIDE;
375 #endif
377 virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem ) SAL_OVERRIDE;
379 const OUString& GetDdeTextFmt() const { return aDdeTextFmt; }
381 SfxBindings* GetViewBindings();
383 ScTabViewShell* GetBestViewShell( bool bOnlyVisible = true );
384 ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; }
386 void SetDocumentModifiedPending( bool bVal )
387 { bDocumentModifiedPending = bVal; }
388 bool IsDocumentModifiedPending() const
389 { return bDocumentModifiedPending; }
391 bool IsUpdateEnabled() const
392 { return bUpdateEnabled; }
393 void SetUpdateEnabled(bool bValue)
394 { bUpdateEnabled = bValue; }
396 OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
398 static ScViewData* GetViewData();
399 static SCTAB GetCurTab();
401 static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
402 static OUString GetOwnFilterName();
403 static OUString GetHtmlFilterName();
404 static OUString GetWebQueryFilterName();
405 static OUString GetAsciiFilterName();
406 static OUString GetLotusFilterName();
407 static OUString GetDBaseFilterName();
408 static OUString GetDifFilterName();
409 static bool HasAutomaticTableName( const OUString& rFilter );
411 DECL_LINK_TYPED( RefreshDBDataHdl, Timer*, void );
413 void BeforeXMLLoading();
414 void AfterXMLLoading(bool bRet);
416 virtual HiddenInformation GetHiddenInformationState( HiddenInformation nStates ) SAL_OVERRIDE;
418 const ScOptSolverSave* GetSolverSaveData() const { return pSolverSaveData; } // may be null
419 void SetSolverSaveData( const ScOptSolverSave& rData );
420 ScSheetSaveData* GetSheetSaveData();
422 static void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
424 // password protection for Calc (derived from SfxObjectShell)
425 // see also: FID_CHG_RECORD, SID_CHG_PROTECT
426 virtual bool IsChangeRecording() const SAL_OVERRIDE;
427 virtual bool HasChangeRecordProtection() const SAL_OVERRIDE;
428 virtual void SetChangeRecording( bool bActivate ) SAL_OVERRIDE;
429 virtual bool SetProtectionPassword( const OUString &rPassword ) SAL_OVERRIDE;
430 virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash ) SAL_OVERRIDE;
432 void SnapVisArea( Rectangle& rRect ) const;
434 virtual void libreOfficeKitCallback(int nType, const char* pPayload) const SAL_OVERRIDE;
435 virtual bool isTiledRendering() const SAL_OVERRIDE;
438 void UpdateAcceptChangesDialog();
440 class ScDocShell;
441 typedef tools::SvRef<ScDocShell> ScDocShellRef;
443 /** Create before modifications of the document and destroy thereafter.
444 Call SetDocumentModified() at an instance of this class instead of at
445 ScDocShell.
447 Remembers in the ctor ScDocument's AutoCalcShellDisabled and IdleDisabled,
448 switches them off and restores them in the dtor, AutoCalcShellDisabled
449 also before a ScDocShell::SetDocumentModified() call if necessary.
450 In the dtor, if ScDocShell's bDocumentModifiedPending is set and
451 bAutoCalcShellDisabled is not set, then ScDocShell::SetDocumentModified()
452 is called.
454 Several instances can be used in nested calls to ScDocFunc or ScDocShell
455 methods to avoid multiple modified status changes, only the last instance
456 destroyed calls ScDocShell::SetDocumentModified().
458 class SC_DLLPUBLIC ScDocShellModificator
460 ScDocShell& rDocShell;
461 boost::scoped_ptr<ScRefreshTimerProtector> mpProtector;
462 bool bAutoCalcShellDisabled;
463 bool bIdleEnabled;
465 ScDocShellModificator( const ScDocShellModificator& ) SAL_DELETED_FUNCTION;
466 ScDocShellModificator& operator=( const ScDocShellModificator& ) SAL_DELETED_FUNCTION;
468 public:
469 ScDocShellModificator( ScDocShell& );
470 ~ScDocShellModificator();
471 void SetDocumentModified();
474 //#i97876# Spreadsheet data changes are not notified
475 namespace HelperNotifyChanges
477 inline ScModelObj* getMustPropagateChangesModel(ScDocShell &rDocShell)
479 ScModelObj* pModelObj = ScModelObj::getImplementation(rDocShell.GetModel());
480 if (pModelObj && pModelObj->HasChangesListeners())
481 return pModelObj;
482 return NULL;
485 inline void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges,
486 const OUString &rType = OUString("cell-change"),
487 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProperties =
488 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >())
490 rModelObj.NotifyChanges(rType, rChangeRanges, rProperties);
493 inline void NotifyIfChangesListeners(ScDocShell &rDocShell, const ScRange &rRange,
494 const OUString &rType = OUString("cell-change"))
496 if (ScModelObj* pModelObj = getMustPropagateChangesModel(rDocShell))
498 ScRangeList aChangeRanges;
499 aChangeRanges.Append(rRange);
500 Notify(*pModelObj, aChangeRanges, rType);
505 void VBA_InsertModule( ScDocument& rDoc, SCTAB nTab, const OUString& sModuleName, const OUString& sModuleSource );
507 #endif
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */