Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_DOCSHELL_HXX
21 : #define SC_DOCSHELL_HXX
22 :
23 :
24 : #include <sfx2/objsh.hxx>
25 :
26 : #include <sfx2/docfac.hxx>
27 : #include <sfx2/sfxmodelfactory.hxx>
28 : #include <sfx2/viewsh.hxx>
29 :
30 : #include "scdllapi.h"
31 : #include "scdll.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"
38 :
39 : #include <boost/unordered_map.hpp>
40 : #include <cppuhelper/implbase1.hxx>
41 :
42 : #include <config_telepathy.h>
43 :
44 : class ScEditEngineDefaulter;
45 : class SfxStyleSheetBasePool;
46 : class SfxStyleSheetHint;
47 : class INetURLObject;
48 :
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 ScSheetSaveData;
64 : class ScFlatBoolRowSegments;
65 : struct ScColWidthParam;
66 : #if ENABLE_TELEPATHY
67 : class ScCollaboration;
68 : #endif
69 :
70 : namespace sfx2 { class FileDialogHelper; }
71 : struct DocShell_Impl;
72 :
73 : typedef ::boost::unordered_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
74 :
75 : //==================================================================
76 :
77 : //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
78 :
79 : // Extra flags for Repaint
80 : #define SC_PF_LINES 1
81 : #define SC_PF_TESTMERGE 2
82 : #define SC_PF_WHOLEROWS 4
83 :
84 : class SC_DLLPUBLIC ScDocShell: public SfxObjectShell, public SfxListener
85 : {
86 : ScDocument aDocument;
87 :
88 : String aDdeTextFmt;
89 :
90 : double nPrtToScreenFactor;
91 : DocShell_Impl* pImpl;
92 : ScDocFunc* pDocFunc;
93 :
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
103 :
104 : ScDBData* pOldAutoDBRange;
105 :
106 : ScSbxDocHelper* pDocHelper;
107 :
108 : ScAutoStyleList* pAutoStyleList;
109 : ScPaintLockData* pPaintLockData;
110 : ScOptSolverSave* pSolverSaveData;
111 : ScSheetSaveData* pSheetSaveData;
112 :
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
117 :
118 : SC_DLLPRIVATE void InitItems();
119 : SC_DLLPRIVATE void DoEnterHandler();
120 : SC_DLLPRIVATE void InitOptions(bool bForLoading);
121 : SC_DLLPRIVATE void ResetDrawObjectShell();
122 :
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
130 : {
131 : public:
132 : explicit PrepareSaveGuard( ScDocShell & rDocShell );
133 : ~PrepareSaveGuard();
134 : private:
135 : ScDocShell & mrDocShell;
136 : };
137 :
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();
141 :
142 : SC_DLLPRIVATE bool SaveCurrentChart( SfxMedium& rMedium );
143 :
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 );
148 :
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 );
152 :
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);
157 :
158 : SC_DLLPRIVATE void EnableSharedSettings( bool bEnable );
159 : SC_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument();
160 :
161 : SC_DLLPRIVATE void UseSheetSaveEntries();
162 :
163 : SC_DLLPRIVATE ScDocFunc *CreateDocFunc();
164 :
165 : protected:
166 :
167 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
168 :
169 : public:
170 : TYPEINFO();
171 :
172 31 : SFX_DECL_INTERFACE(SCID_DOC_SHELL)
173 88584 : SFX_DECL_OBJECTFACTORY();
174 :
175 : ScDocShell( const ScDocShell& rDocShell );
176 : ScDocShell( const sal_uInt64 i_nSfxCreationFlags = SFXMODEL_EMBEDDED_OBJECT );
177 : ~ScDocShell();
178 :
179 : using SotObject::GetInterface;
180 : using SfxShell::Activate; // with sal_Bool bMDI
181 : using SfxShell::Deactivate; // with sal_Bool bMDI
182 :
183 : #if ENABLE_TELEPATHY
184 : SC_DLLPRIVATE ScCollaboration* GetCollaboration();
185 : #endif
186 : virtual void Activate();
187 : virtual void Deactivate();
188 :
189 : virtual ::svl::IUndoManager*
190 : GetUndoManager();
191 :
192 : virtual void FillClass( SvGlobalName * pClassName,
193 : sal_uInt32 * pFormat,
194 : OUString * pAppName,
195 : OUString * pFullTypeName,
196 : OUString * pShortTypeName,
197 : sal_Int32 nFileFormat,
198 : sal_Bool bTemplate = false ) const;
199 :
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 );
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 288752 : ScDocument* GetDocument() { return &aDocument; }
240 12370 : ScDocFunc& GetDocFunc() { return *pDocFunc; }
241 : void SetDocFunc( ScDocFunc *pDF ) { pDocFunc = pDF; }
242 :
243 : SfxPrinter* GetPrinter( sal_Bool bCreateIfNotExist = sal_True );
244 : sal_uInt16 SetPrinter( SfxPrinter* pNewPrinter, sal_uInt16 nDiffFlags = SFX_PRINTER_ALL );
245 :
246 : void UpdateFontList();
247 :
248 : String CreateObjectName( const String& rPrefix );
249 :
250 : ScDrawLayer* MakeDrawLayer();
251 :
252 : void AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
253 :
254 : void GetSbxState( SfxItemSet &rSet );
255 : void GetDrawObjState( SfxItemSet &rSet );
256 :
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 );
261 :
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 );
265 :
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 );
275 :
276 : void SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
277 : bool AdjustPrintZoom( const ScRange& rRange );
278 :
279 : void LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellStyles, bool bPageStyles );
280 :
281 : void PageStyleModified( const OUString& rStyleName, sal_Bool bApi );
282 :
283 : void NotifyStyle( const SfxStyleSheetHint& rHint );
284 : void DoAutoStyle( const ScRange& rRange, const String& rStyle );
285 :
286 : Window* GetActiveDialogParent();
287 : void ErrorMessage( sal_uInt16 nGlobStrId );
288 : sal_Bool IsEditable() const;
289 :
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 );
293 :
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 );
305 :
306 : sal_Bool MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord );
307 :
308 : void DoRecalc( bool bApi );
309 : void DoHardRecalc( bool bApi );
310 :
311 : void UpdateOle( const ScViewData* pViewData, sal_Bool bSnapSize = false);
312 : sal_Bool IsOle();
313 :
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
319 :
320 : virtual void ReconnectDdeLink(SfxObjectShell& rServer);
321 : void UpdateLinks();
322 : sal_Bool ReloadTabLinks();
323 :
324 : void SetFormulaOptions(const ScFormulaOptions& rOpt );
325 : virtual void CheckConfigOptions();
326 :
327 : void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
328 :
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 );
333 :
334 : void PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
335 : void PostPaintCell( const ScAddress& rPos );
336 : void PostPaintGridAll();
337 : void PostPaintExtras();
338 :
339 2 : bool IsPaintLocked() const { return pPaintLockData != NULL; }
340 :
341 : void PostDataChanged();
342 :
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 );
346 :
347 : void SetDocumentModified( sal_Bool bIsModified = sal_True );
348 : void SetDrawModified( sal_Bool bIsModified = sal_True );
349 :
350 : void LockPaint();
351 : void UnlockPaint();
352 : sal_uInt16 GetLockCount() const;
353 : void SetLockCount(sal_uInt16 nNew);
354 :
355 : void LockDocument();
356 : void UnlockDocument();
357 :
358 : DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
359 :
360 : virtual SfxStyleSheetBasePool* GetStyleSheetPool();
361 :
362 : void SetInplace( bool bInplace );
363 : bool IsEmpty() const;
364 : void SetEmpty(bool bSet);
365 :
366 6 : bool IsInUndo() const { return bIsInUndo; }
367 : void SetInUndo(bool bSet);
368 :
369 : void CalcOutputFactor();
370 : double GetOutputFactor() const;
371 : void GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
372 : SCTAB nCurTab,
373 : bool& rbHeader,
374 : bool& rbFooter );
375 :
376 : virtual long DdeGetData( const OUString& rItem, const OUString& rMimeType,
377 : ::com::sun::star::uno::Any & rValue );
378 : virtual long DdeSetData( const OUString& rItem, const OUString& rMimeType,
379 : const ::com::sun::star::uno::Any & rValue );
380 : virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const OUString& rItem );
381 :
382 8 : const String& GetDdeTextFmt() const { return aDdeTextFmt; }
383 :
384 : SfxBindings* GetViewBindings();
385 :
386 : ScTabViewShell* GetBestViewShell( sal_Bool bOnlyVisible = sal_True );
387 : ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; }
388 :
389 8467 : void SetDocumentModifiedPending( bool bVal )
390 8467 : { bDocumentModifiedPending = bVal; }
391 9359 : bool IsDocumentModifiedPending() const
392 9359 : { return bDocumentModifiedPending; }
393 :
394 202 : bool IsUpdateEnabled() const
395 202 : { return bUpdateEnabled; }
396 203 : void SetUpdateEnabled(bool bValue)
397 203 : { bUpdateEnabled = bValue; }
398 :
399 : OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
400 :
401 : static ScViewData* GetViewData();
402 : static SCTAB GetCurTab();
403 :
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 );
413 :
414 : DECL_LINK( RefreshDBDataHdl, ScRefreshTimer* );
415 :
416 : void BeforeXMLLoading();
417 : void AfterXMLLoading(sal_Bool bRet);
418 :
419 : virtual sal_uInt16 GetHiddenInformationState( sal_uInt16 nStates );
420 :
421 0 : const ScOptSolverSave* GetSolverSaveData() const { return pSolverSaveData; } // may be null
422 : void SetSolverSaveData( const ScOptSolverSave& rData );
423 : ScSheetSaveData* GetSheetSaveData();
424 :
425 : void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
426 :
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 );
434 :
435 :
436 : void SnapVisArea( Rectangle& rRect ) const;
437 : };
438 :
439 :
440 : void UpdateAcceptChangesDialog();
441 :
442 :
443 793 : SV_DECL_REF(ScDocShell)
444 828 : SV_IMPL_REF(ScDocShell)
445 :
446 :
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
455 : {
456 : ScDocShell& rDocShell;
457 : ScRefreshTimerProtector aProtector;
458 : sal_Bool bAutoCalcShellDisabled;
459 : bool bIdleEnabled;
460 :
461 : // not implemented
462 : ScDocShellModificator( const ScDocShellModificator& );
463 : ScDocShellModificator& operator=( const ScDocShellModificator& );
464 :
465 : public:
466 : ScDocShellModificator( ScDocShell& );
467 : ~ScDocShellModificator();
468 : void SetDocumentModified();
469 : };
470 :
471 :
472 :
473 : #endif
474 :
475 :
476 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|