1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docsh.hxx,v $
10 * $Revision: 1.50.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_DOCSHELL_HXX
32 #define SC_DOCSHELL_HXX
35 #include <sfx2/objsh.hxx>
37 //REMOVE #ifndef _SFX_INTERNO_HXX //autogen
38 //REMOVE #include <sfx2/interno.hxx>
40 #include <sfx2/docfac.hxx>
41 #include <sfx2/viewsh.hxx>
45 #include "document.hxx"
46 #include "shellids.hxx"
47 #include "refreshtimer.hxx"
50 #include <cppuhelper/implbase1.hxx>
52 class ScEditEngineDefaulter
;
55 class SfxStyleSheetBasePool
;
56 class SfxStyleSheetHint
;
57 struct ChartSelectionInfo
;
66 class ScAutoStyleList
;
69 class ScPaintLockData
;
73 class ScImportOptions
;
74 class ScDocShellModificator
;
75 class ScOptSolverSave
;
77 namespace sfx2
{ class FileDialogHelper
; }
80 typedef ::std::hash_map
< ULONG
, ULONG
> ScChangeActionMergeMap
;
82 //==================================================================
84 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
86 // Extra-Flags fuer Repaint
88 #define SC_PF_TESTMERGE 2
89 #define SC_PF_WHOLEROWS 4
91 class SC_DLLPUBLIC ScDocShell
: public SfxObjectShell
, public SfxListener
93 static const sal_Char __FAR_DATA pStarCalcDoc
[];
94 static const sal_Char __FAR_DATA pStyleName
[];
99 String aConvFilterName
; //@ #BugId 54198
101 double nPrtToScreenFactor
;
102 //! FontList* pFontList;
103 DocShell_Impl
* pImpl
;
106 //SfxObjectCreateMode eShellMode;
108 BOOL bIsInplace
; // wird von der View gesetzt
114 BOOL bDocumentModifiedPending
;
115 USHORT nDocumentLock
;
116 sal_Int16 nCanUpdate
; // stores the UpdateDocMode from loading a document till update links
119 ScDBData
* pOldAutoDBRange
;
121 ScSbxDocHelper
* pDocHelper
;
123 ScAutoStyleList
* pAutoStyleList
;
124 ScPaintLockData
* pPaintLockData
;
125 ScJobSetup
* pOldJobSetup
;
126 ScOptSolverSave
* pSolverSaveData
;
128 ScDocShellModificator
* pModificator
; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
130 SC_DLLPRIVATE
void InitItems();
131 SC_DLLPRIVATE
void DoEnterHandler();
132 SC_DLLPRIVATE
void InitOptions();
133 SC_DLLPRIVATE
void ResetDrawObjectShell();
135 // SUNWS needs a forward declared friend, otherwise types and members
136 // of the outer class are not accessible.
137 class PrepareSaveGuard
;
138 friend class ScDocShell::PrepareSaveGuard
;
139 /** Do things that need to be done before saving to our own format and
140 necessary clean ups in dtor. */
141 class PrepareSaveGuard
144 explicit PrepareSaveGuard( ScDocShell
& rDocShell
);
147 ScDocShell
& mrDocShell
;
150 SC_DLLPRIVATE BOOL
LoadXML( SfxMedium
* pMedium
, const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
151 SC_DLLPRIVATE BOOL
SaveXML( SfxMedium
* pMedium
, const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
152 SC_DLLPRIVATE SCTAB
GetSaveTab();
154 SC_DLLPRIVATE ULONG
DBaseImport( const String
& rFullFileName
, CharSet eCharSet
,
155 BOOL bSimpleColWidth
[MAXCOLCOUNT
] );
156 SC_DLLPRIVATE ULONG
DBaseExport( const String
& rFullFileName
, CharSet eCharSet
,
159 SC_DLLPRIVATE
static BOOL
MoveFile( const INetURLObject
& rSource
, const INetURLObject
& rDest
);
160 SC_DLLPRIVATE
static BOOL
KillFile( const INetURLObject
& rURL
);
161 SC_DLLPRIVATE
static BOOL
IsDocument( const INetURLObject
& rURL
);
163 SC_DLLPRIVATE
void LockPaint_Impl(BOOL bDoc
);
164 SC_DLLPRIVATE
void UnlockPaint_Impl(BOOL bDoc
);
165 SC_DLLPRIVATE
void LockDocument_Impl(USHORT nNew
);
166 SC_DLLPRIVATE
void UnlockDocument_Impl(USHORT nNew
);
168 SC_DLLPRIVATE
void EnableSharedSettings( bool bEnable
);
169 SC_DLLPRIVATE ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> LoadSharedDocument();
173 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
178 SFX_DECL_INTERFACE(SCID_DOC_SHELL
)
179 SFX_DECL_OBJECTFACTORY();
181 ScDocShell( const ScDocShell
& rDocShell
);
182 ScDocShell( SfxObjectCreateMode eMode
= SFX_CREATE_MODE_EMBEDDED
, const bool _bScriptSupport
= true );
185 using SotObject::GetInterface
;
186 using SfxShell::Activate
; // with BOOL bMDI
187 using SfxShell::Deactivate
; // with BOOL bMDI
188 using SfxObjectShell::Print
; // print styles
190 virtual void Activate();
191 virtual void Deactivate();
193 virtual SfxUndoManager
* GetUndoManager();
195 virtual void FillClass( SvGlobalName
* pClassName
,
196 sal_uInt32
* pFormat
,
198 String
* pFullTypeName
,
199 String
* pShortTypeName
,
200 sal_Int32 nFileFormat
,
201 sal_Bool bTemplate
= sal_False
) const;
203 virtual BOOL
InitNew( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
204 virtual BOOL
Load( SfxMedium
& rMedium
);
205 virtual BOOL
LoadFrom( SfxMedium
& rMedium
);
206 virtual BOOL
ConvertFrom( SfxMedium
&rMedium
);
208 virtual BOOL
SaveAs( SfxMedium
& rMedium
);
209 virtual BOOL
ConvertTo( SfxMedium
&rMedium
);
210 virtual USHORT
PrepareClose( BOOL bUI
= TRUE
, BOOL bForBrowsing
= FALSE
);
211 virtual void PrepareReload();
212 virtual BOOL
IsInformationLost();
213 virtual void LoadStyles( SfxObjectShell
&rSource
);
214 virtual BOOL
Insert( SfxObjectShell
&rSource
,
215 USHORT nSourceIdx1
, USHORT nSourceIdx2
, USHORT nSourceIdx3
,
216 USHORT
&nIdx1
, USHORT
&nIdx2
, USHORT
&nIdx3
, USHORT
&rIdxDeleted
);
218 virtual BOOL
SaveCompleted( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& ); // SfxInPlaceObject
219 virtual BOOL
DoSaveCompleted( SfxMedium
* pNewStor
); // SfxObjectShell
221 virtual void Draw( OutputDevice
*, const JobSetup
& rSetup
,
222 USHORT nAspect
= ASPECT_CONTENT
);
224 virtual void SetVisArea( const Rectangle
& rVisArea
);
226 using SfxObjectShell::GetVisArea
;
227 virtual Rectangle
GetVisArea( USHORT nAspect
) const;
229 virtual Printer
* GetDocumentPrinter();
231 virtual void SetModified( BOOL
= TRUE
);
233 void SetVisAreaOrSize( const Rectangle
& rVisArea
, 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
; }
243 SfxPrinter
* GetPrinter( BOOL bCreateIfNotExist
= TRUE
);
244 USHORT
SetPrinter( SfxPrinter
* pNewPrinter
, USHORT 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, 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
,BOOL bPrevNext
=TRUE
);
269 /// Protect/unprotect ChangeTrack and return <TRUE/> if
270 /// protection was successfully changed.
271 /// If bJustQueryIfProtected==TRUE protection is not
272 /// changed and <TRUE/> is returned if not protected or
273 /// password was entered correctly.
274 BOOL
ExecuteChangeProtectionDialog( Window
* _pParent
, BOOL bJustQueryIfProtected
= FALSE
);
276 void SetPrintZoom( SCTAB nTab
, USHORT nScale
, USHORT nPages
);
277 BOOL
AdjustPrintZoom( const ScRange
& rRange
);
279 void LoadStylesArgs( ScDocShell
& rSource
, BOOL bReplace
, BOOL bCellStyles
, BOOL bPageStyles
);
281 void PageStyleModified( const String
& rStyleName
, BOOL bApi
);
283 void NotifyStyle( const SfxStyleSheetHint
& rHint
);
284 void DoAutoStyle( const ScRange
& rRange
, const String
& rStyle
);
286 Window
* GetActiveDialogParent();
287 void ErrorMessage( USHORT nGlobStrId
);
288 BOOL
IsEditable() const;
290 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
, BOOL bRecord
= TRUE
);
296 void UseScenario( SCTAB nTab
, const String
& rName
, BOOL bRecord
= TRUE
);
297 SCTAB
MakeScenario( SCTAB nTab
, const String
& rName
, const String
& rComment
,
298 const Color
& rColor
, USHORT nFlags
,
299 ScMarkData
& rMark
, BOOL bRecord
= TRUE
);
300 void ModifyScenario( SCTAB nTab
, const String
& rName
, const String
& rComment
,
301 const Color
& rColor
, USHORT nFlags
);
302 BOOL
MoveTable( SCTAB nSrcTab
, SCTAB nDestTab
, BOOL bCopy
, BOOL bRecord
);
304 void DoRecalc( BOOL bApi
);
305 void DoHardRecalc( BOOL bApi
);
307 bool CheckPrint( PrintDialog
* pPrintDialog
, ScMarkData
* pMarkData
,
308 bool bForceSelected
, bool bIsAPI
);
309 void PreparePrint( PrintDialog
* pPrintDialog
, ScMarkData
* pMarkData
);
310 void Print( SfxProgress
& rProgress
, PrintDialog
* pPrintDialog
,
311 ScMarkData
* pMarkData
, Window
* pDialogParent
,
312 BOOL bForceSelected
, BOOL bIsAPI
);
314 void UpdateOle( const ScViewData
* pViewData
, BOOL bSnapSize
= FALSE
);
317 void DBAreaDeleted( SCTAB nTab
, SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
);
318 ScDBData
* GetDBData( const ScRange
& rMarked
, ScGetDBMode eMode
, BOOL bForceMark
);
319 ScDBData
* GetOldAutoDBRange(); // has to be deleted by caller!
320 void CancelAutoDBRange(); // called when dialog is cancelled
322 void UpdateLinks(); // Link-Eintraege aktuallisieren
324 virtual bool GetApplicationFlag(SfxApplicationFlagType eFlagType
);
326 BOOL
ReloadTabLinks(); // Links ausfuehren (Inhalt aktualisieren)
328 void PostEditView( ScEditEngineDefaulter
* pEditEngine
, const ScAddress
& rCursorPos
);
330 void PostPaint( SCCOL nStartCol
, SCROW nStartRow
, SCTAB nStartTab
,
331 SCCOL nEndCol
, SCROW nEndRow
, SCTAB nEndTab
, USHORT nPart
,
332 USHORT nExtFlags
= 0 );
333 void PostPaint( const ScRange
& rRange
, USHORT nPart
, USHORT nExtFlags
= 0 );
335 void PostPaintCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
336 void PostPaintCell( const ScAddress
& rPos
);
337 void PostPaintGridAll();
338 void PostPaintExtras();
340 void PostDataChanged();
342 void UpdatePaintExt( USHORT
& rExtFlags
, SCCOL nStartCol
, SCROW nStartRow
, SCTAB nStartTab
,
343 SCCOL nEndCol
, SCROW nEndRow
, SCTAB nEndTab
);
344 void UpdatePaintExt( USHORT
& rExtFlags
, const ScRange
& rRange
);
346 void SetDocumentModified( BOOL bIsModified
= TRUE
);
347 void SetDrawModified( BOOL bIsModified
= TRUE
);
351 USHORT
GetLockCount() const;
352 void SetLockCount(USHORT nNew
);
355 void UnlockDocument();
357 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
* );
359 virtual SfxStyleSheetBasePool
* GetStyleSheetPool();
361 void SetInplace( BOOL bInplace
);
362 BOOL
IsEmpty() const;
363 void SetEmpty(BOOL bSet
);
365 BOOL
IsInUndo() const { return bIsInUndo
; }
366 void SetInUndo(BOOL bSet
);
368 void CalcOutputFactor();
369 double GetOutputFactor() const;
370 void GetPageOnFromPageStyleSet( const SfxItemSet
* pStyleSet
,
375 virtual long DdeGetData( const String
& rItem
, const String
& rMimeType
,
376 ::com::sun::star::uno::Any
& rValue
);
377 virtual long DdeSetData( const String
& rItem
, const String
& rMimeType
,
378 const ::com::sun::star::uno::Any
& rValue
);
379 virtual ::sfx2::SvLinkSource
* DdeCreateLinkSource( const String
& rItem
);
381 const String
& GetDdeTextFmt() const { return aDdeTextFmt
; }
383 SfxBindings
* GetViewBindings();
385 ScTabViewShell
* GetBestViewShell( BOOL bOnlyVisible
= TRUE
);
386 ScSbxDocHelper
* GetDocHelperObject() { return pDocHelper
; }
388 void SetDocumentModifiedPending( BOOL bVal
)
389 { bDocumentModifiedPending
= bVal
; }
390 BOOL
IsDocumentModifiedPending() const
391 { return bDocumentModifiedPending
; }
393 BOOL
IsUpdateEnabled() const
394 { return bUpdateEnabled
; }
395 void SetUpdateEnabled(BOOL bValue
)
396 { bUpdateEnabled
= bValue
; }
398 OutputDevice
* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
400 static ScViewData
* GetViewData();
401 static SCTAB
GetCurTab();
403 static ScDocShell
* GetShellByNum( USHORT nDocNo
);
404 static String
GetOwnFilterName();
405 static String
GetHtmlFilterName();
406 static String
GetWebQueryFilterName();
407 static String
GetAsciiFilterName();
408 static String
GetLotusFilterName();
409 static String
GetDBaseFilterName();
410 static String
GetDifFilterName();
411 static BOOL
HasAutomaticTableName( const String
& rFilter
);
413 DECL_LINK( RefreshDBDataHdl
, ScRefreshTimer
* );
415 void BeforeXMLLoading();
416 void AfterXMLLoading(sal_Bool bRet
);
418 virtual sal_uInt16
GetHiddenInformationState( sal_uInt16 nStates
);
420 const ScOptSolverSave
* GetSolverSaveData() const { return pSolverSaveData
; } // may be null
421 void SetSolverSaveData( const ScOptSolverSave
& rData
);
424 SO2_DECL_REF(ScDocShell
)
425 SO2_IMPL_REF(ScDocShell
)
428 // Vor Modifizierungen des Dokuments anlegen und danach zerstoeren.
429 // Merkt sich im Ctor AutoCalcShellDisabled und IdleDisabled, schaltet sie ab
430 // und stellt sie im Dtor wieder her, AutoCalcShellDisabled ggbf. auch vor
431 // einem ScDocShell SetDocumentModified.
432 // SetDocumentModified hierdran aufrufen statt an der ScDocShell.
433 // Im Dtor wird wenn ScDocShell bDocumentModifiedPending gesetzt ist und
434 // bAutoCalcShellDisabled nicht gesetzt ist ein SetDocumentModified gerufen.
435 class SC_DLLPUBLIC ScDocShellModificator
437 ScDocShell
& rDocShell
;
438 ScRefreshTimerProtector aProtector
;
439 BOOL bAutoCalcShellDisabled
;
443 ScDocShellModificator( const ScDocShellModificator
& );
444 ScDocShellModificator
& operator=( const ScDocShellModificator
& );
447 ScDocShellModificator( ScDocShell
& );
448 ~ScDocShellModificator();
449 void SetDocumentModified();