1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
32 #include "document.hxx"
33 #include "appoptio.hxx"
34 #include "formulaopt.hxx"
35 #include "shellids.hxx"
36 #include "refreshtimer.hxx"
37 #include "optutil.hxx"
39 #include <boost/unordered_map.hpp>
40 #include <cppuhelper/implbase1.hxx>
42 #include <config_telepathy.h>
44 class ScEditEngineDefaulter
;
45 class SfxStyleSheetBasePool
;
46 class SfxStyleSheetHint
;
54 class ScAutoStyleList
;
57 class ScPaintLockData
;
60 class ScImportOptions
;
61 class ScDocShellModificator
;
62 class ScOptSolverSave
;
63 class ScSheetSaveData
;
64 class ScFlatBoolRowSegments
;
65 struct ScColWidthParam
;
67 class ScCollaboration
;
70 namespace sfx2
{ class FileDialogHelper
; }
73 typedef ::boost::unordered_map
< sal_uLong
, sal_uLong
> ScChangeActionMergeMap
;
75 //==================================================================
77 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
79 // Extra flags for Repaint
81 #define SC_PF_TESTMERGE 2
82 #define SC_PF_WHOLEROWS 4
84 class SC_DLLPUBLIC ScDocShell
: public SfxObjectShell
, public SfxListener
90 double nPrtToScreenFactor
;
96 bool bIsInplace
:1; // Is set by the View
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)
115 ScCollaboration
* mpCollaboration
;
118 SC_DLLPRIVATE
void InitItems();
119 SC_DLLPRIVATE
void DoEnterHandler();
120 SC_DLLPRIVATE
void InitOptions(bool bForLoading
);
121 SC_DLLPRIVATE
void ResetDrawObjectShell();
123 // SUNWS needs a forward declared friend, otherwise types and members
124 // of the outer class are not accessible.
125 class PrepareSaveGuard
;
126 friend class ScDocShell::PrepareSaveGuard
;
127 /** Do things that need to be done before saving to our own format and
128 necessary clean ups in dtor. */
129 class PrepareSaveGuard
132 explicit PrepareSaveGuard( ScDocShell
& rDocShell
);
135 ScDocShell
& mrDocShell
;
138 SC_DLLPRIVATE sal_Bool
LoadXML( SfxMedium
* pMedium
, const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
139 SC_DLLPRIVATE sal_Bool
SaveXML( SfxMedium
* pMedium
, const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
140 SC_DLLPRIVATE SCTAB
GetSaveTab();
142 SC_DLLPRIVATE
bool SaveCurrentChart( SfxMedium
& rMedium
);
144 SC_DLLPRIVATE sal_uLong
DBaseImport( const String
& rFullFileName
, CharSet eCharSet
,
145 ScColWidthParam aColWidthParam
[MAXCOLCOUNT
], ScFlatBoolRowSegments
& rRowHeightsRecalc
);
146 SC_DLLPRIVATE sal_uLong
DBaseExport(
147 const OUString
& rFullFileName
, CharSet eCharSet
, bool& bHasMemo
);
149 SC_DLLPRIVATE
static bool MoveFile( const INetURLObject
& rSource
, const INetURLObject
& rDest
);
150 SC_DLLPRIVATE
static bool KillFile( const INetURLObject
& rURL
);
151 SC_DLLPRIVATE
static bool IsDocument( const INetURLObject
& rURL
);
153 SC_DLLPRIVATE
void LockPaint_Impl(sal_Bool bDoc
);
154 SC_DLLPRIVATE
void UnlockPaint_Impl(sal_Bool bDoc
);
155 SC_DLLPRIVATE
void LockDocument_Impl(sal_uInt16 nNew
);
156 SC_DLLPRIVATE
void UnlockDocument_Impl(sal_uInt16 nNew
);
158 SC_DLLPRIVATE
void EnableSharedSettings( bool bEnable
);
159 SC_DLLPRIVATE ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> LoadSharedDocument();
161 SC_DLLPRIVATE
void UseSheetSaveEntries();
163 SC_DLLPRIVATE ScDocFunc
*CreateDocFunc();
167 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
172 SFX_DECL_INTERFACE(SCID_DOC_SHELL
)
173 SFX_DECL_OBJECTFACTORY();
175 ScDocShell( const ScDocShell
& rDocShell
);
176 ScDocShell( const sal_uInt64 i_nSfxCreationFlags
= SFXMODEL_EMBEDDED_OBJECT
);
179 using SotObject::GetInterface
;
180 using SfxShell::Activate
; // with sal_Bool bMDI
181 using SfxShell::Deactivate
; // with sal_Bool bMDI
184 SC_DLLPRIVATE ScCollaboration
* GetCollaboration();
186 virtual void Activate();
187 virtual void Deactivate();
189 virtual ::svl::IUndoManager
*
192 virtual void FillClass( SvGlobalName
* pClassName
,
193 sal_uInt32
* pFormat
,
195 OUString
* pFullTypeName
,
196 OUString
* pShortTypeName
,
197 sal_Int32 nFileFormat
,
198 sal_Bool bTemplate
= false ) const;
200 virtual sal_Bool
InitNew( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
201 virtual sal_Bool
Load( SfxMedium
& rMedium
);
202 virtual sal_Bool
LoadFrom( SfxMedium
& rMedium
);
203 virtual sal_Bool
ConvertFrom( SfxMedium
&rMedium
);
204 virtual bool LoadExternal( SfxMedium
& rMedium
);
205 virtual sal_Bool
Save();
206 virtual sal_Bool
SaveAs( SfxMedium
& rMedium
);
207 virtual sal_Bool
ConvertTo( SfxMedium
&rMedium
);
208 virtual sal_uInt16
PrepareClose( sal_Bool bUI
= sal_True
, sal_Bool bForBrowsing
= false );
209 virtual void PrepareReload();
210 virtual sal_Bool
IsInformationLost();
211 virtual void LoadStyles( SfxObjectShell
&rSource
);
212 virtual sal_Bool
Insert( SfxObjectShell
&rSource
,
213 sal_uInt16 nSourceIdx1
, sal_uInt16 nSourceIdx2
, sal_uInt16 nSourceIdx3
,
214 sal_uInt16
&nIdx1
, sal_uInt16
&nIdx2
, sal_uInt16
&nIdx3
, sal_uInt16
&rIdxDeleted
);
216 virtual sal_Bool
SaveCompleted( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& ); // SfxInPlaceObject
217 virtual sal_Bool
DoSaveCompleted( SfxMedium
* pNewStor
); // SfxObjectShell
218 virtual sal_Bool
QuerySlotExecutable( sal_uInt16 nSlotId
);
220 virtual void Draw( OutputDevice
*, const JobSetup
& rSetup
,
221 sal_uInt16 nAspect
= ASPECT_CONTENT
);
223 virtual void SetVisArea( const Rectangle
& rVisArea
);
225 using SfxObjectShell::GetVisArea
;
226 virtual Rectangle
GetVisArea( sal_uInt16 nAspect
) const;
228 virtual Printer
* GetDocumentPrinter();
230 virtual void SetModified( sal_Bool
= sal_True
);
232 void SetVisAreaOrSize( const Rectangle
& rVisArea
, sal_Bool bModifyStart
);
234 virtual SfxDocumentInfoDialog
* CreateDocumentInfoDialog( Window
*pParent
,
235 const SfxItemSet
&rSet
);
237 void GetDocStat( ScDocStat
& rDocStat
);
239 ScDocument
* GetDocument() { return &aDocument
; }
240 ScDocFunc
& GetDocFunc() { return *pDocFunc
; }
241 void SetDocFunc( ScDocFunc
*pDF
) { pDocFunc
= pDF
; }
243 SfxPrinter
* GetPrinter( sal_Bool bCreateIfNotExist
= sal_True
);
244 sal_uInt16
SetPrinter( SfxPrinter
* pNewPrinter
, sal_uInt16 nDiffFlags
= SFX_PRINTER_ALL
);
246 void UpdateFontList();
248 String
CreateObjectName( const String
& rPrefix
);
250 ScDrawLayer
* MakeDrawLayer();
252 void AsciiSave( SvStream
& rStream
, const ScImportOptions
& rOpt
);
254 void GetSbxState( SfxItemSet
&rSet
);
255 void GetDrawObjState( SfxItemSet
&rSet
);
257 void Execute( SfxRequest
& rReq
);
258 void GetState( SfxItemSet
&rSet
);
259 void ExecutePageStyle ( SfxViewShell
& rCaller
, SfxRequest
& rReq
, SCTAB nCurTab
);
260 void GetStatePageStyle( SfxViewShell
& rCaller
, SfxItemSet
& rSet
, SCTAB nCurTab
);
262 void CompareDocument( ScDocument
& rOtherDoc
);
263 void MergeDocument( ScDocument
& rOtherDoc
, bool bShared
= false, bool bCheckDuplicates
= false, sal_uLong nOffset
= 0, ScChangeActionMergeMap
* pMergeMap
= NULL
, bool bInverseMap
= false );
264 bool MergeSharedDocument( ScDocShell
* pSharedDocShell
);
266 ScChangeAction
* GetChangeAction( const ScAddress
& rPos
);
267 void SetChangeComment( ScChangeAction
* pAction
, const String
& rComment
);
268 void ExecuteChangeCommentDialog( ScChangeAction
* pAction
, Window
* pParent
,sal_Bool bPrevNext
=sal_True
);
269 /// Protect/unprotect ChangeTrack and return <TRUE/> if
270 /// protection was successfully changed.
271 /// If bJustQueryIfProtected==sal_True protection is not
272 /// changed and <TRUE/> is returned if not protected or
273 /// password was entered correctly.
274 bool ExecuteChangeProtectionDialog( Window
* _pParent
, sal_Bool bJustQueryIfProtected
= false );
276 void SetPrintZoom( SCTAB nTab
, sal_uInt16 nScale
, sal_uInt16 nPages
);
277 bool AdjustPrintZoom( const ScRange
& rRange
);
279 void LoadStylesArgs( ScDocShell
& rSource
, bool bReplace
, bool bCellStyles
, bool bPageStyles
);
281 void PageStyleModified( const OUString
& rStyleName
, sal_Bool bApi
);
283 void NotifyStyle( const SfxStyleSheetHint
& rHint
);
284 void DoAutoStyle( const ScRange
& rRange
, const String
& rStyle
);
286 Window
* GetActiveDialogParent();
287 void ErrorMessage( sal_uInt16 nGlobStrId
);
288 sal_Bool
IsEditable() const;
290 sal_Bool
AdjustRowHeight( SCROW nStartRow
, SCROW nEndRow
, SCTAB nTab
);
291 void UpdateAllRowHeights( const ScMarkData
* pTabMark
= NULL
);
292 void UpdatePendingRowHeights( SCTAB nUpdateTab
, bool bBefore
= false );
294 void RefreshPivotTables( const ScRange
& rSource
);
295 void DoConsolidate( const ScConsolidateParam
& rParam
, sal_Bool bRecord
= sal_True
);
296 void UseScenario( SCTAB nTab
, const String
& rName
, sal_Bool bRecord
= sal_True
);
297 SCTAB
MakeScenario( SCTAB nTab
, const String
& rName
, const String
& rComment
,
298 const Color
& rColor
, sal_uInt16 nFlags
,
299 ScMarkData
& rMark
, sal_Bool bRecord
= sal_True
);
300 void ModifyScenario( SCTAB nTab
, const String
& rName
, const String
& rComment
,
301 const Color
& rColor
, sal_uInt16 nFlags
);
302 sal_uLong
TransferTab( ScDocShell
& rSrcDocShell
, SCTAB nSrcPos
,
303 SCTAB nDestPos
, sal_Bool bInsertNew
,
304 sal_Bool bNotifyAndPaint
);
306 sal_Bool
MoveTable( SCTAB nSrcTab
, SCTAB nDestTab
, sal_Bool bCopy
, sal_Bool bRecord
);
308 void DoRecalc( bool bApi
);
309 void DoHardRecalc( bool bApi
);
311 void UpdateOle( const ScViewData
* pViewData
, sal_Bool bSnapSize
= false);
314 void DBAreaDeleted( SCTAB nTab
, SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
);
315 ScDBData
* GetDBData( const ScRange
& rMarked
, ScGetDBMode eMode
, ScGetDBSelection eSel
);
316 ScDBData
* GetAnonymousDBData(const ScRange
& rRange
);
317 ScDBData
* GetOldAutoDBRange(); // has to be deleted by caller!
318 void CancelAutoDBRange(); // called when dialog is cancelled
320 virtual void ReconnectDdeLink(SfxObjectShell
& rServer
);
322 sal_Bool
ReloadTabLinks();
324 void SetFormulaOptions(const ScFormulaOptions
& rOpt
);
325 virtual void CheckConfigOptions();
327 void PostEditView( ScEditEngineDefaulter
* pEditEngine
, const ScAddress
& rCursorPos
);
329 void PostPaint( SCCOL nStartCol
, SCROW nStartRow
, SCTAB nStartTab
,
330 SCCOL nEndCol
, SCROW nEndRow
, SCTAB nEndTab
, sal_uInt16 nPart
,
331 sal_uInt16 nExtFlags
= 0 );
332 void PostPaint( const ScRangeList
& rRanges
, sal_uInt16 nPart
, sal_uInt16 nExtFlags
= 0 );
334 void PostPaintCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
335 void PostPaintCell( const ScAddress
& rPos
);
336 void PostPaintGridAll();
337 void PostPaintExtras();
339 bool IsPaintLocked() const { return pPaintLockData
!= NULL
; }
341 void PostDataChanged();
343 void UpdatePaintExt( sal_uInt16
& rExtFlags
, SCCOL nStartCol
, SCROW nStartRow
, SCTAB nStartTab
,
344 SCCOL nEndCol
, SCROW nEndRow
, SCTAB nEndTab
);
345 void UpdatePaintExt( sal_uInt16
& rExtFlags
, const ScRange
& rRange
);
347 void SetDocumentModified( sal_Bool bIsModified
= sal_True
);
348 void SetDrawModified( sal_Bool bIsModified
= sal_True
);
352 sal_uInt16
GetLockCount() const;
353 void SetLockCount(sal_uInt16 nNew
);
356 void UnlockDocument();
358 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
* );
360 virtual SfxStyleSheetBasePool
* GetStyleSheetPool();
362 void SetInplace( bool bInplace
);
363 bool IsEmpty() const;
364 void SetEmpty(bool bSet
);
366 bool IsInUndo() const { return bIsInUndo
; }
367 void SetInUndo(bool bSet
);
369 void CalcOutputFactor();
370 double GetOutputFactor() const;
371 void GetPageOnFromPageStyleSet( const SfxItemSet
* pStyleSet
,
376 virtual long DdeGetData( const String
& rItem
, const String
& rMimeType
,
377 ::com::sun::star::uno::Any
& rValue
);
378 virtual long DdeSetData( const String
& rItem
, const String
& rMimeType
,
379 const ::com::sun::star::uno::Any
& rValue
);
380 virtual ::sfx2::SvLinkSource
* DdeCreateLinkSource( const String
& rItem
);
382 const String
& GetDdeTextFmt() const { return aDdeTextFmt
; }
384 SfxBindings
* GetViewBindings();
386 ScTabViewShell
* GetBestViewShell( sal_Bool bOnlyVisible
= sal_True
);
387 ScSbxDocHelper
* GetDocHelperObject() { return pDocHelper
; }
389 void SetDocumentModifiedPending( bool bVal
)
390 { bDocumentModifiedPending
= bVal
; }
391 bool IsDocumentModifiedPending() const
392 { return bDocumentModifiedPending
; }
394 bool IsUpdateEnabled() const
395 { return bUpdateEnabled
; }
396 void SetUpdateEnabled(bool bValue
)
397 { bUpdateEnabled
= bValue
; }
399 OutputDevice
* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
401 static ScViewData
* GetViewData();
402 static SCTAB
GetCurTab();
404 static ScDocShell
* GetShellByNum( sal_uInt16 nDocNo
);
405 static String
GetOwnFilterName();
406 static String
GetHtmlFilterName();
407 static String
GetWebQueryFilterName();
408 static String
GetAsciiFilterName();
409 static String
GetLotusFilterName();
410 static String
GetDBaseFilterName();
411 static String
GetDifFilterName();
412 static sal_Bool
HasAutomaticTableName( const String
& rFilter
);
414 DECL_LINK( RefreshDBDataHdl
, ScRefreshTimer
* );
416 void BeforeXMLLoading();
417 void AfterXMLLoading(sal_Bool bRet
);
419 virtual sal_uInt16
GetHiddenInformationState( sal_uInt16 nStates
);
421 const ScOptSolverSave
* GetSolverSaveData() const { return pSolverSaveData
; } // may be null
422 void SetSolverSaveData( const ScOptSolverSave
& rData
);
423 ScSheetSaveData
* GetSheetSaveData();
425 void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType
);
427 // password protection for Calc (derived from SfxObjectShell)
428 // see also: FID_CHG_RECORD, SID_CHG_PROTECT
429 virtual bool IsChangeRecording() const;
430 virtual bool HasChangeRecordProtection() const;
431 virtual void SetChangeRecording( bool bActivate
);
432 virtual bool SetProtectionPassword( const String
&rPassword
);
433 virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence
< sal_Int8
> &rPasswordHash
);
436 void SnapVisArea( Rectangle
& rRect
) const;
440 void UpdateAcceptChangesDialog();
443 SV_DECL_REF(ScDocShell
)
444 SV_IMPL_REF(ScDocShell
)
447 /** Create before modifications of the document and then destroy.
448 If noted in the ctor AutoCalcShellDisabled and IdleDisabled,
449 switches them off and restores the dtor AutoCalcShellDisabled
450 also before a ScDocShell SetDocumentModified.
451 Call SetDocumentModified after instead of the ScDocShell.
452 In the dtor, if ScDocShell bDocumentModifiedPending is set and
453 bAutoCalcShellDisabled is not set, then SetDocumentModified is called. */
454 class SC_DLLPUBLIC ScDocShellModificator
456 ScDocShell
& rDocShell
;
457 ScRefreshTimerProtector aProtector
;
458 sal_Bool bAutoCalcShellDisabled
;
462 ScDocShellModificator( const ScDocShellModificator
& );
463 ScDocShellModificator
& operator=( const ScDocShellModificator
& );
466 ScDocShellModificator( ScDocShell
& );
467 ~ScDocShellModificator();
468 void SetDocumentModified();
476 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */