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
;
76 class ScSheetSaveData
;
78 namespace sfx2
{ class FileDialogHelper
; }
81 typedef ::std::hash_map
< ULONG
, ULONG
> ScChangeActionMergeMap
;
83 //==================================================================
85 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
87 // Extra-Flags fuer Repaint
89 #define SC_PF_TESTMERGE 2
90 #define SC_PF_WHOLEROWS 4
92 class SC_DLLPUBLIC ScDocShell
: public SfxObjectShell
, public SfxListener
94 static const sal_Char __FAR_DATA pStarCalcDoc
[];
95 static const sal_Char __FAR_DATA pStyleName
[];
100 String aConvFilterName
; //@ #BugId 54198
102 double nPrtToScreenFactor
;
103 //! FontList* pFontList;
104 DocShell_Impl
* pImpl
;
107 //SfxObjectCreateMode eShellMode;
109 BOOL bIsInplace
; // wird von der View gesetzt
115 BOOL bDocumentModifiedPending
;
116 USHORT nDocumentLock
;
117 sal_Int16 nCanUpdate
; // stores the UpdateDocMode from loading a document till update links
120 ScDBData
* pOldAutoDBRange
;
122 ScSbxDocHelper
* pDocHelper
;
124 ScAutoStyleList
* pAutoStyleList
;
125 ScPaintLockData
* pPaintLockData
;
126 ScJobSetup
* pOldJobSetup
;
127 ScOptSolverSave
* pSolverSaveData
;
128 ScSheetSaveData
* pSheetSaveData
;
130 ScDocShellModificator
* pModificator
; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
132 SC_DLLPRIVATE
void InitItems();
133 SC_DLLPRIVATE
void DoEnterHandler();
134 SC_DLLPRIVATE
void InitOptions();
135 SC_DLLPRIVATE
void ResetDrawObjectShell();
137 // SUNWS needs a forward declared friend, otherwise types and members
138 // of the outer class are not accessible.
139 class PrepareSaveGuard
;
140 friend class ScDocShell::PrepareSaveGuard
;
141 /** Do things that need to be done before saving to our own format and
142 necessary clean ups in dtor. */
143 class PrepareSaveGuard
146 explicit PrepareSaveGuard( ScDocShell
& rDocShell
);
149 ScDocShell
& mrDocShell
;
152 SC_DLLPRIVATE BOOL
LoadXML( SfxMedium
* pMedium
, const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
153 SC_DLLPRIVATE BOOL
SaveXML( SfxMedium
* pMedium
, const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
154 SC_DLLPRIVATE SCTAB
GetSaveTab();
156 SC_DLLPRIVATE ULONG
DBaseImport( const String
& rFullFileName
, CharSet eCharSet
,
157 BOOL bSimpleColWidth
[MAXCOLCOUNT
] );
158 SC_DLLPRIVATE ULONG
DBaseExport( const String
& rFullFileName
, CharSet eCharSet
,
161 SC_DLLPRIVATE
static BOOL
MoveFile( const INetURLObject
& rSource
, const INetURLObject
& rDest
);
162 SC_DLLPRIVATE
static BOOL
KillFile( const INetURLObject
& rURL
);
163 SC_DLLPRIVATE
static BOOL
IsDocument( const INetURLObject
& rURL
);
165 SC_DLLPRIVATE
void LockPaint_Impl(BOOL bDoc
);
166 SC_DLLPRIVATE
void UnlockPaint_Impl(BOOL bDoc
);
167 SC_DLLPRIVATE
void LockDocument_Impl(USHORT nNew
);
168 SC_DLLPRIVATE
void UnlockDocument_Impl(USHORT nNew
);
170 SC_DLLPRIVATE
void EnableSharedSettings( bool bEnable
);
171 SC_DLLPRIVATE ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> LoadSharedDocument();
173 SC_DLLPRIVATE
void UseSheetSaveEntries();
177 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
182 SFX_DECL_INTERFACE(SCID_DOC_SHELL
)
183 SFX_DECL_OBJECTFACTORY();
185 ScDocShell( const ScDocShell
& rDocShell
);
186 ScDocShell( SfxObjectCreateMode eMode
= SFX_CREATE_MODE_EMBEDDED
, const bool _bScriptSupport
= true );
189 using SotObject::GetInterface
;
190 using SfxShell::Activate
; // with BOOL bMDI
191 using SfxShell::Deactivate
; // with BOOL bMDI
192 using SfxObjectShell::Print
; // print styles
194 virtual void Activate();
195 virtual void Deactivate();
197 virtual SfxUndoManager
* GetUndoManager();
199 virtual void FillClass( SvGlobalName
* pClassName
,
200 sal_uInt32
* pFormat
,
202 String
* pFullTypeName
,
203 String
* pShortTypeName
,
204 sal_Int32 nFileFormat
,
205 sal_Bool bTemplate
= sal_False
) const;
207 virtual BOOL
InitNew( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& );
208 virtual BOOL
Load( SfxMedium
& rMedium
);
209 virtual BOOL
LoadFrom( SfxMedium
& rMedium
);
210 virtual BOOL
ConvertFrom( SfxMedium
&rMedium
);
212 virtual BOOL
SaveAs( SfxMedium
& rMedium
);
213 virtual BOOL
ConvertTo( SfxMedium
&rMedium
);
214 virtual USHORT
PrepareClose( BOOL bUI
= TRUE
, BOOL bForBrowsing
= FALSE
);
215 virtual void PrepareReload();
216 virtual BOOL
IsInformationLost();
217 virtual void LoadStyles( SfxObjectShell
&rSource
);
218 virtual BOOL
Insert( SfxObjectShell
&rSource
,
219 USHORT nSourceIdx1
, USHORT nSourceIdx2
, USHORT nSourceIdx3
,
220 USHORT
&nIdx1
, USHORT
&nIdx2
, USHORT
&nIdx3
, USHORT
&rIdxDeleted
);
222 virtual BOOL
SaveCompleted( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& ); // SfxInPlaceObject
223 virtual BOOL
DoSaveCompleted( SfxMedium
* pNewStor
); // SfxObjectShell
225 virtual void Draw( OutputDevice
*, const JobSetup
& rSetup
,
226 USHORT nAspect
= ASPECT_CONTENT
);
228 virtual void SetVisArea( const Rectangle
& rVisArea
);
230 using SfxObjectShell::GetVisArea
;
231 virtual Rectangle
GetVisArea( USHORT nAspect
) const;
233 virtual Printer
* GetDocumentPrinter();
235 virtual void SetModified( BOOL
= TRUE
);
237 void SetVisAreaOrSize( const Rectangle
& rVisArea
, BOOL bModifyStart
);
239 virtual SfxDocumentInfoDialog
* CreateDocumentInfoDialog( Window
*pParent
,
240 const SfxItemSet
&rSet
);
242 void GetDocStat( ScDocStat
& rDocStat
);
244 ScDocument
* GetDocument() { return &aDocument
; }
245 ScDocFunc
& GetDocFunc() { return *pDocFunc
; }
247 SfxPrinter
* GetPrinter( BOOL bCreateIfNotExist
= TRUE
);
248 USHORT
SetPrinter( SfxPrinter
* pNewPrinter
, USHORT nDiffFlags
= SFX_PRINTER_ALL
);
250 void UpdateFontList();
252 String
CreateObjectName( const String
& rPrefix
);
254 ScDrawLayer
* MakeDrawLayer();
256 void AsciiSave( SvStream
& rStream
, const ScImportOptions
& rOpt
);
258 void GetSbxState( SfxItemSet
&rSet
);
259 void GetDrawObjState( SfxItemSet
&rSet
);
261 void Execute( SfxRequest
& rReq
);
262 void GetState( SfxItemSet
&rSet
);
263 void ExecutePageStyle ( SfxViewShell
& rCaller
, SfxRequest
& rReq
, SCTAB nCurTab
);
264 void GetStatePageStyle( SfxViewShell
& rCaller
, SfxItemSet
& rSet
, SCTAB nCurTab
);
266 void CompareDocument( ScDocument
& rOtherDoc
);
267 void MergeDocument( ScDocument
& rOtherDoc
, bool bShared
= false, bool bCheckDuplicates
= false, ULONG nOffset
= 0, ScChangeActionMergeMap
* pMergeMap
= NULL
, bool bInverseMap
= false );
268 bool MergeSharedDocument( ScDocShell
* pSharedDocShell
);
270 ScChangeAction
* GetChangeAction( const ScAddress
& rPos
);
271 void SetChangeComment( ScChangeAction
* pAction
, const String
& rComment
);
272 void ExecuteChangeCommentDialog( ScChangeAction
* pAction
, Window
* pParent
,BOOL bPrevNext
=TRUE
);
273 /// Protect/unprotect ChangeTrack and return <TRUE/> if
274 /// protection was successfully changed.
275 /// If bJustQueryIfProtected==TRUE protection is not
276 /// changed and <TRUE/> is returned if not protected or
277 /// password was entered correctly.
278 BOOL
ExecuteChangeProtectionDialog( Window
* _pParent
, BOOL bJustQueryIfProtected
= FALSE
);
280 void SetPrintZoom( SCTAB nTab
, USHORT nScale
, USHORT nPages
);
281 BOOL
AdjustPrintZoom( const ScRange
& rRange
);
283 void LoadStylesArgs( ScDocShell
& rSource
, BOOL bReplace
, BOOL bCellStyles
, BOOL bPageStyles
);
285 void PageStyleModified( const String
& rStyleName
, BOOL bApi
);
287 void NotifyStyle( const SfxStyleSheetHint
& rHint
);
288 void DoAutoStyle( const ScRange
& rRange
, const String
& rStyle
);
290 Window
* GetActiveDialogParent();
291 void ErrorMessage( USHORT nGlobStrId
);
292 BOOL
IsEditable() const;
294 BOOL
AdjustRowHeight( SCROW nStartRow
, SCROW nEndRow
, SCTAB nTab
);
295 void UpdateAllRowHeights( const ScMarkData
* pTabMark
= NULL
);
296 void UpdatePendingRowHeights( SCTAB nUpdateTab
, bool bBefore
= false );
298 void RefreshPivotTables( const ScRange
& rSource
);
299 void DoConsolidate( const ScConsolidateParam
& rParam
, BOOL bRecord
= TRUE
);
300 void UseScenario( SCTAB nTab
, const String
& rName
, BOOL bRecord
= TRUE
);
301 SCTAB
MakeScenario( SCTAB nTab
, const String
& rName
, const String
& rComment
,
302 const Color
& rColor
, USHORT nFlags
,
303 ScMarkData
& rMark
, BOOL bRecord
= TRUE
);
304 void ModifyScenario( SCTAB nTab
, const String
& rName
, const String
& rComment
,
305 const Color
& rColor
, USHORT nFlags
);
306 BOOL
MoveTable( SCTAB nSrcTab
, SCTAB nDestTab
, BOOL bCopy
, BOOL bRecord
);
308 void DoRecalc( BOOL bApi
);
309 void DoHardRecalc( BOOL bApi
);
311 bool CheckPrint( PrintDialog
* pPrintDialog
, ScMarkData
* pMarkData
,
312 bool bForceSelected
, bool bIsAPI
);
313 void PreparePrint( PrintDialog
* pPrintDialog
, ScMarkData
* pMarkData
);
314 void Print( SfxProgress
& rProgress
, PrintDialog
* pPrintDialog
,
315 ScMarkData
* pMarkData
, Window
* pDialogParent
,
316 BOOL bForceSelected
, BOOL bIsAPI
);
318 void UpdateOle( const ScViewData
* pViewData
, BOOL bSnapSize
= FALSE
);
321 void DBAreaDeleted( SCTAB nTab
, SCCOL nX1
, SCROW nY1
, SCCOL nX2
, SCROW nY2
);
322 ScDBData
* GetDBData( const ScRange
& rMarked
, ScGetDBMode eMode
, BOOL bForceMark
);
323 ScDBData
* GetOldAutoDBRange(); // has to be deleted by caller!
324 void CancelAutoDBRange(); // called when dialog is cancelled
326 void UpdateLinks(); // Link-Eintraege aktuallisieren
328 virtual bool GetApplicationFlag(SfxApplicationFlagType eFlagType
);
330 BOOL
ReloadTabLinks(); // Links ausfuehren (Inhalt aktualisieren)
332 void PostEditView( ScEditEngineDefaulter
* pEditEngine
, const ScAddress
& rCursorPos
);
334 void PostPaint( SCCOL nStartCol
, SCROW nStartRow
, SCTAB nStartTab
,
335 SCCOL nEndCol
, SCROW nEndRow
, SCTAB nEndTab
, USHORT nPart
,
336 USHORT nExtFlags
= 0 );
337 void PostPaint( const ScRange
& rRange
, USHORT nPart
, USHORT nExtFlags
= 0 );
339 void PostPaintCell( SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
340 void PostPaintCell( const ScAddress
& rPos
);
341 void PostPaintGridAll();
342 void PostPaintExtras();
344 void PostDataChanged();
346 void UpdatePaintExt( USHORT
& rExtFlags
, SCCOL nStartCol
, SCROW nStartRow
, SCTAB nStartTab
,
347 SCCOL nEndCol
, SCROW nEndRow
, SCTAB nEndTab
);
348 void UpdatePaintExt( USHORT
& rExtFlags
, const ScRange
& rRange
);
350 void SetDocumentModified( BOOL bIsModified
= TRUE
);
351 void SetDrawModified( BOOL bIsModified
= TRUE
);
355 USHORT
GetLockCount() const;
356 void SetLockCount(USHORT nNew
);
359 void UnlockDocument();
361 DECL_LINK( DialogClosedHdl
, sfx2::FileDialogHelper
* );
363 virtual SfxStyleSheetBasePool
* GetStyleSheetPool();
365 void SetInplace( BOOL bInplace
);
366 BOOL
IsEmpty() const;
367 void SetEmpty(BOOL bSet
);
369 BOOL
IsInUndo() const { return bIsInUndo
; }
370 void SetInUndo(BOOL bSet
);
372 void CalcOutputFactor();
373 double GetOutputFactor() const;
374 void GetPageOnFromPageStyleSet( const SfxItemSet
* pStyleSet
,
379 virtual long DdeGetData( const String
& rItem
, const String
& rMimeType
,
380 ::com::sun::star::uno::Any
& rValue
);
381 virtual long DdeSetData( const String
& rItem
, const String
& rMimeType
,
382 const ::com::sun::star::uno::Any
& rValue
);
383 virtual ::sfx2::SvLinkSource
* DdeCreateLinkSource( const String
& rItem
);
385 const String
& GetDdeTextFmt() const { return aDdeTextFmt
; }
387 SfxBindings
* GetViewBindings();
389 ScTabViewShell
* GetBestViewShell( BOOL bOnlyVisible
= TRUE
);
390 ScSbxDocHelper
* GetDocHelperObject() { return pDocHelper
; }
392 void SetDocumentModifiedPending( BOOL bVal
)
393 { bDocumentModifiedPending
= bVal
; }
394 BOOL
IsDocumentModifiedPending() const
395 { return bDocumentModifiedPending
; }
397 BOOL
IsUpdateEnabled() const
398 { return bUpdateEnabled
; }
399 void SetUpdateEnabled(BOOL bValue
)
400 { bUpdateEnabled
= bValue
; }
402 OutputDevice
* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
404 static ScViewData
* GetViewData();
405 static SCTAB
GetCurTab();
407 static ScDocShell
* GetShellByNum( USHORT nDocNo
);
408 static String
GetOwnFilterName();
409 static String
GetHtmlFilterName();
410 static String
GetWebQueryFilterName();
411 static String
GetAsciiFilterName();
412 static String
GetLotusFilterName();
413 static String
GetDBaseFilterName();
414 static String
GetDifFilterName();
415 static BOOL
HasAutomaticTableName( const String
& rFilter
);
417 DECL_LINK( RefreshDBDataHdl
, ScRefreshTimer
* );
419 void BeforeXMLLoading();
420 void AfterXMLLoading(sal_Bool bRet
);
422 virtual sal_uInt16
GetHiddenInformationState( sal_uInt16 nStates
);
424 const ScOptSolverSave
* GetSolverSaveData() const { return pSolverSaveData
; } // may be null
425 void SetSolverSaveData( const ScOptSolverSave
& rData
);
427 ScSheetSaveData
* GetSheetSaveData();
430 SO2_DECL_REF(ScDocShell
)
431 SO2_IMPL_REF(ScDocShell
)
434 // Vor Modifizierungen des Dokuments anlegen und danach zerstoeren.
435 // Merkt sich im Ctor AutoCalcShellDisabled und IdleDisabled, schaltet sie ab
436 // und stellt sie im Dtor wieder her, AutoCalcShellDisabled ggbf. auch vor
437 // einem ScDocShell SetDocumentModified.
438 // SetDocumentModified hierdran aufrufen statt an der ScDocShell.
439 // Im Dtor wird wenn ScDocShell bDocumentModifiedPending gesetzt ist und
440 // bAutoCalcShellDisabled nicht gesetzt ist ein SetDocumentModified gerufen.
441 class SC_DLLPUBLIC ScDocShellModificator
443 ScDocShell
& rDocShell
;
444 ScRefreshTimerProtector aProtector
;
445 BOOL bAutoCalcShellDisabled
;
449 ScDocShellModificator( const ScDocShellModificator
& );
450 ScDocShellModificator
& operator=( const ScDocShellModificator
& );
453 ScDocShellModificator( ScDocShell
& );
454 ~ScDocShellModificator();
455 void SetDocumentModified();