xref: /aoo41x/main/sc/source/ui/inc/docsh.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_DOCSHELL_HXX
29 #define SC_DOCSHELL_HXX
30 
31 
32 #include <sfx2/objsh.hxx>
33 
34 #include <sfx2/docfac.hxx>
35 #include <sfx2/sfxmodelfactory.hxx>
36 #include <sfx2/viewsh.hxx>
37 
38 #include "scdllapi.h"
39 #include "scdll.hxx"
40 #include "document.hxx"
41 #include "shellids.hxx"
42 #include "refreshtimer.hxx"
43 
44 #include <hash_map>
45 
46 class ScEditEngineDefaulter;
47 class FontList;
48 class SfxStyleSheetBasePool;
49 class SfxStyleSheetHint;
50 struct ChartSelectionInfo;
51 class INetURLObject;
52 
53 class ScPaintItem;
54 class ScViewData;
55 class ScDocFunc;
56 class ScDrawLayer;
57 class ScTabViewShell;
58 class ScSbxDocHelper;
59 class ScAutoStyleList;
60 class ScRange;
61 class ScMarkData;
62 class ScPaintLockData;
63 class ScJobSetup;
64 class ScChangeAction;
65 class VirtualDevice;
66 class ScImportOptions;
67 class ScDocShellModificator;
68 class ScOptSolverSave;
69 class ScSheetSaveData;
70 
71 namespace sfx2 { class FileDialogHelper; }
72 struct DocShell_Impl;
73 
74 typedef ::std::hash_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
75 
76 //==================================================================
77 
78 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
79 
80 									// Extra-Flags fuer Repaint
81 #define SC_PF_LINES         1
82 #define SC_PF_TESTMERGE     2
83 #define SC_PF_WHOLEROWS     4
84 
85 class SC_DLLPUBLIC ScDocShell: public SfxObjectShell, public SfxListener
86 {
87 	static const sal_Char __FAR_DATA pStarCalcDoc[];
88 	static const sal_Char __FAR_DATA pStyleName[];
89 
90 	ScDocument          aDocument;
91 
92 	String				aDdeTextFmt;
93 	String				aConvFilterName; //@ #BugId	54198
94 
95 	double				nPrtToScreenFactor;
96 //!   FontList*           pFontList;
97     DocShell_Impl*      pImpl;
98 	ScDocFunc*			pDocFunc;
99 
100 	//SfxObjectCreateMode	eShellMode;
101 
102 	sal_Bool				bIsInplace;			// wird von der View gesetzt
103 	sal_Bool				bHeaderOn;
104 	sal_Bool				bFooterOn;
105 	sal_Bool				bNoInformLost;
106 	sal_Bool				bIsEmpty;
107 	sal_Bool				bIsInUndo;
108 	sal_Bool				bDocumentModifiedPending;
109 	sal_uInt16				nDocumentLock;
110     sal_Int16           nCanUpdate;  // stores the UpdateDocMode from loading a document till update links
111     sal_Bool                bUpdateEnabled;
112 
113     ScDBData*           pOldAutoDBRange;
114 
115 	ScSbxDocHelper* 	pDocHelper;
116 
117 	ScAutoStyleList*	pAutoStyleList;
118 	ScPaintLockData*	pPaintLockData;
119 	ScJobSetup*			pOldJobSetup;
120     ScOptSolverSave*    pSolverSaveData;
121     ScSheetSaveData*    pSheetSaveData;
122 
123     ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
124 
125 	SC_DLLPRIVATE void			InitItems();
126 	SC_DLLPRIVATE void			DoEnterHandler();
127     SC_DLLPRIVATE void          InitOptions(bool bForLoading);
128 	SC_DLLPRIVATE void			ResetDrawObjectShell();
129 
130     // SUNWS needs a forward declared friend, otherwise types and members
131     // of the outer class are not accessible.
132     class PrepareSaveGuard;
133     friend class ScDocShell::PrepareSaveGuard;
134     /** Do things that need to be done before saving to our own format and
135         necessary clean ups in dtor. */
136     class PrepareSaveGuard
137     {
138         public:
139             explicit    PrepareSaveGuard( ScDocShell & rDocShell );
140                         ~PrepareSaveGuard();
141         private:
142                         ScDocShell & mrDocShell;
143     };
144 
145     SC_DLLPRIVATE sal_Bool            LoadXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
146     SC_DLLPRIVATE sal_Bool            SaveXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
147 	SC_DLLPRIVATE SCTAB			GetSaveTab();
148 
149 	SC_DLLPRIVATE sal_uLong			DBaseImport( const String& rFullFileName, CharSet eCharSet,
150 								 sal_Bool bSimpleColWidth[MAXCOLCOUNT] );
151 	SC_DLLPRIVATE sal_uLong			DBaseExport( const String& rFullFileName, CharSet eCharSet,
152 								 sal_Bool& bHasMemo );
153 
154 	SC_DLLPRIVATE static sal_Bool		MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
155 	SC_DLLPRIVATE static sal_Bool		KillFile( const INetURLObject& rURL );
156 	SC_DLLPRIVATE static sal_Bool		IsDocument( const INetURLObject& rURL );
157 
158 	SC_DLLPRIVATE void			LockPaint_Impl(sal_Bool bDoc);
159 	SC_DLLPRIVATE void			UnlockPaint_Impl(sal_Bool bDoc);
160 	SC_DLLPRIVATE void			LockDocument_Impl(sal_uInt16 nNew);
161 	SC_DLLPRIVATE void			UnlockDocument_Impl(sal_uInt16 nNew);
162 
163     SC_DLLPRIVATE void          EnableSharedSettings( bool bEnable );
164     SC_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument();
165 
166     SC_DLLPRIVATE void          UseSheetSaveEntries();
167 
168 protected:
169 
170 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
171 
172 public:
173 					TYPEINFO();
174 
175 					SFX_DECL_INTERFACE(SCID_DOC_SHELL)
176 					SFX_DECL_OBJECTFACTORY();
177 
178 					ScDocShell( const ScDocShell& rDocShell );
179 					ScDocShell( const sal_uInt64 i_nSfxCreationFlags = SFXMODEL_EMBEDDED_OBJECT );
180 					~ScDocShell();
181 
182     using SotObject::GetInterface;
183     using SfxShell::Activate;           // with sal_Bool bMDI
184     using SfxShell::Deactivate;         // with sal_Bool bMDI
185     using SfxObjectShell::Print;        // print styles
186 
187 	virtual void    Activate();
188 	virtual void    Deactivate();
189 
190     virtual ::svl::IUndoManager*
191                     GetUndoManager();
192 
193 	virtual void	FillClass( SvGlobalName * pClassName,
194 							   sal_uInt32 * pFormat,
195 							   String * pAppName,
196 							   String * pFullTypeName,
197 							   String * pShortTypeName,
198 							   sal_Int32 nFileFormat,
199                                sal_Bool bTemplate = sal_False ) const;
200 
201     virtual sal_Bool    InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
202     virtual sal_Bool    Load( SfxMedium& rMedium );
203     virtual sal_Bool    LoadFrom( SfxMedium& rMedium );
204 	virtual sal_Bool    ConvertFrom( 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 = sal_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 );
215 
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 );
219 
220 	virtual void	Draw( OutputDevice *, const JobSetup & rSetup,
221 								sal_uInt16 nAspect = ASPECT_CONTENT );
222 
223 	virtual void    SetVisArea( const Rectangle & rVisArea );
224 
225     using SfxObjectShell::GetVisArea;
226 	virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const;
227 
228 	virtual Printer* GetDocumentPrinter();
229 
230 	virtual void	SetModified( sal_Bool = sal_True );
231 
232 	void			SetVisAreaOrSize( const Rectangle& rVisArea, sal_Bool bModifyStart );
233 
234 	virtual SfxDocumentInfoDialog*  CreateDocumentInfoDialog( Window *pParent,
235 															  const SfxItemSet &rSet );
236 
237 	void	GetDocStat( ScDocStat& rDocStat );
238 
239 	ScDocument*     GetDocument()	{ return &aDocument; }
240 	ScDocFunc&		GetDocFunc()	{ return *pDocFunc; }
241 
242 	SfxPrinter*		GetPrinter( sal_Bool bCreateIfNotExist = sal_True );
243 	sal_uInt16			SetPrinter( SfxPrinter* pNewPrinter, sal_uInt16 nDiffFlags = SFX_PRINTER_ALL );
244 
245 	void			UpdateFontList();
246 
247 	String			CreateObjectName( const String& rPrefix );
248 
249 	ScDrawLayer*	MakeDrawLayer();
250 
251 	void 			AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
252 
253 	void			GetSbxState( SfxItemSet &rSet );
254 	void			GetDrawObjState( SfxItemSet &rSet );
255 
256 	void            Execute( SfxRequest& rReq );
257 	void            GetState( SfxItemSet &rSet );
258 	void			ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
259 	void			GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab );
260 
261 	void			CompareDocument( ScDocument& rOtherDoc );
262     void            MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = NULL, bool bInverseMap = false );
263     bool            MergeSharedDocument( ScDocShell* pSharedDocShell );
264 
265 	ScChangeAction*	GetChangeAction( const ScAddress& rPos );
266 	void			SetChangeComment( ScChangeAction* pAction, const String& rComment );
267 	void			ExecuteChangeCommentDialog( ScChangeAction* pAction, Window* pParent,sal_Bool bPrevNext=sal_True );
268                     /// Protect/unprotect ChangeTrack and return <TRUE/> if
269                     /// protection was successfully changed.
270                     /// If bJustQueryIfProtected==sal_True protection is not
271                     /// changed and <TRUE/> is returned if not protected or
272                     /// password was entered correctly.
273     sal_Bool            ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected = sal_False );
274 
275 	void			SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
276 	sal_Bool			AdjustPrintZoom( const ScRange& rRange );
277 
278 	void			LoadStylesArgs( ScDocShell& rSource, sal_Bool bReplace, sal_Bool bCellStyles, sal_Bool bPageStyles );
279 
280 	void			PageStyleModified( const String& rStyleName, sal_Bool bApi );
281 
282 	void			NotifyStyle( const SfxStyleSheetHint& rHint );
283 	void			DoAutoStyle( const ScRange& rRange, const String& rStyle );
284 
285 	Window*			GetActiveDialogParent();
286 	void			ErrorMessage( sal_uInt16 nGlobStrId );
287 	sal_Bool			IsEditable() const;
288 
289 	sal_Bool			AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
290     void            UpdateAllRowHeights( const ScMarkData* pTabMark = NULL );
291     void            UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
292 
293 	void			RefreshPivotTables( const ScRange& rSource );
294 	void			DoConsolidate( const ScConsolidateParam& rParam, sal_Bool bRecord = sal_True );
295 	void			UseScenario( SCTAB nTab, const String& rName, sal_Bool bRecord = sal_True );
296 	SCTAB			MakeScenario( SCTAB nTab, const String& rName, const String& rComment,
297 									const Color& rColor, sal_uInt16 nFlags,
298 									ScMarkData& rMark, sal_Bool bRecord = sal_True );
299 	void			ModifyScenario( SCTAB nTab, const String& rName, const String& rComment,
300 									const Color& rColor, sal_uInt16 nFlags );
301 	sal_Bool			MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord );
302 
303 	void			DoRecalc( sal_Bool bApi );
304 	void			DoHardRecalc( sal_Bool bApi );
305 
306 	void			UpdateOle( const ScViewData* pViewData, sal_Bool bSnapSize = sal_False);
307 	sal_Bool		IsOle();
308 
309 	void			DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
310 	ScDBData*		GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
311     ScDBData*       GetOldAutoDBRange();    // has to be deleted by caller!
312     void            CancelAutoDBRange();    // called when dialog is cancelled
313 
314 	void			UpdateLinks();			// Link-Eintraege aktuallisieren
315 	sal_Bool			ReloadTabLinks();		// Links ausfuehren (Inhalt aktualisieren)
316 
317 	void            PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
318 
319 	void            PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
320 							SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart,
321 							sal_uInt16 nExtFlags = 0 );
322 	void            PostPaint( const ScRange& rRange, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 );
323 
324 	void            PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
325 	void            PostPaintCell( const ScAddress& rPos );
326 	void            PostPaintGridAll();
327 	void            PostPaintExtras();
328 
329     bool            IsPaintLocked() const { return pPaintLockData != NULL; }
330 
331 	void            PostDataChanged();
332 
333 	void			UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
334 													   SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
335 	void			UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
336 
337 	void			SetDocumentModified( sal_Bool bIsModified = sal_True );
338 	void			SetDrawModified( sal_Bool bIsModified = sal_True );
339 
340 	void			LockPaint();
341 	void			UnlockPaint();
342 	sal_uInt16			GetLockCount() const;
343 	void			SetLockCount(sal_uInt16 nNew);
344 
345 	void			LockDocument();
346 	void			UnlockDocument();
347 
348     DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
349 
350 	virtual SfxStyleSheetBasePool*	GetStyleSheetPool();
351 
352 	void			SetInplace( sal_Bool bInplace );
353 	sal_Bool			IsEmpty() const;
354 	void			SetEmpty(sal_Bool bSet);
355 
356 	sal_Bool			IsInUndo() const				{ return bIsInUndo; }
357 	void			SetInUndo(sal_Bool bSet);
358 
359 	void			CalcOutputFactor();
360 	double			GetOutputFactor() const;
361 	void			GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
362 											   SCTAB			 nCurTab,
363 											   sal_Bool&			 rbHeader,
364 											   sal_Bool&			 rbFooter );
365 
366 	virtual long DdeGetData( const String& rItem, const String& rMimeType,
367 								::com::sun::star::uno::Any & rValue );
368 	virtual long DdeSetData( const String& rItem, const String& rMimeType,
369 								const ::com::sun::star::uno::Any & rValue );
370 	virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const String& rItem );
371 
372 	const String& GetDdeTextFmt() const { return aDdeTextFmt; }
373 
374 	SfxBindings*	GetViewBindings();
375 
376 	ScTabViewShell* GetBestViewShell( sal_Bool bOnlyVisible = sal_True );
377 	ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; }
378 
379 	void			SetDocumentModifiedPending( sal_Bool bVal )
380 						{ bDocumentModifiedPending = bVal; }
381 	sal_Bool			IsDocumentModifiedPending() const
382 						{ return bDocumentModifiedPending; }
383 
384     sal_Bool            IsUpdateEnabled() const
385                         { return bUpdateEnabled; }
386     void            SetUpdateEnabled(sal_Bool bValue)
387                         { bUpdateEnabled = bValue; }
388 
389 	OutputDevice*	GetRefDevice();	// WYSIWYG: Printer, otherwise VirtualDevice...
390 
391 	static ScViewData* GetViewData();
392 	static SCTAB	   GetCurTab();
393 
394 	static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
395 	static String	GetOwnFilterName();
396         static String   GetHtmlFilterName();
397 	static String	GetWebQueryFilterName();
398 	static String	GetAsciiFilterName();
399 	static String	GetLotusFilterName();
400 	static String	GetDBaseFilterName();
401 	static String	GetDifFilterName();
402 	static sal_Bool		HasAutomaticTableName( const String& rFilter );
403 
404 	DECL_LINK( RefreshDBDataHdl, ScRefreshTimer* );
405 
406     void            BeforeXMLLoading();
407     void            AfterXMLLoading(sal_Bool bRet);
408 
409     virtual sal_uInt16 GetHiddenInformationState( sal_uInt16 nStates );
410 
411     const ScOptSolverSave* GetSolverSaveData() const    { return pSolverSaveData; }     // may be null
412     void            SetSolverSaveData( const ScOptSolverSave& rData );
413 	//<!--Added by PengYunQuan for Validity Cell Range Picker
414 	sal_Bool		AcceptStateUpdate() const;
415 	//-->Added by PengYunQuan for Validity Cell Range Picker
416     ScSheetSaveData* GetSheetSaveData();
417 
418     // passwword protection for Calc (derived from SfxObjectShell)
419     // see also:    FID_CHG_RECORD, SID_CHG_PROTECT
420     virtual bool    IsChangeRecording() const;
421     virtual bool    HasChangeRecordProtection() const;
422     virtual void    SetChangeRecording( bool bActivate );
423     virtual bool    SetProtectionPassword( const String &rPassword );
424     virtual bool    GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash );
425 };
426 
427 
428 void UpdateAcceptChangesDialog();
429 
430 
431 SO2_DECL_REF(ScDocShell)
432 SO2_IMPL_REF(ScDocShell)
433 
434 
435 // Vor Modifizierungen des Dokuments anlegen und danach zerstoeren.
436 // Merkt sich im Ctor AutoCalcShellDisabled und IdleDisabled, schaltet sie ab
437 // und stellt sie im Dtor wieder her, AutoCalcShellDisabled ggbf. auch vor
438 // einem ScDocShell SetDocumentModified.
439 // SetDocumentModified hierdran aufrufen statt an der ScDocShell.
440 // Im Dtor wird wenn ScDocShell bDocumentModifiedPending gesetzt ist und
441 // bAutoCalcShellDisabled nicht gesetzt ist ein SetDocumentModified gerufen.
442 class SC_DLLPUBLIC ScDocShellModificator
443 {
444 			ScDocShell&		rDocShell;
445 	ScRefreshTimerProtector	aProtector;
446 			sal_Bool			bAutoCalcShellDisabled;
447 			sal_Bool			bIdleDisabled;
448 
449 							// not implemented
450 							ScDocShellModificator( const ScDocShellModificator& );
451 	ScDocShellModificator&	operator=( const ScDocShellModificator& );
452 
453 public:
454 							ScDocShellModificator( ScDocShell& );
455 							~ScDocShellModificator();
456 			void			SetDocumentModified();
457 };
458 
459 
460 
461 #endif
462 
463 
464