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 : #ifdef 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 : static const sal_Char pStarCalcDoc[];
87 : static const sal_Char pStyleName[];
88 :
89 : ScDocument aDocument;
90 :
91 : String aDdeTextFmt;
92 :
93 : double nPrtToScreenFactor;
94 : DocShell_Impl* pImpl;
95 : ScDocFunc* pDocFunc;
96 :
97 : bool bHeaderOn;
98 : bool bFooterOn;
99 : bool bIsInplace:1; // Is set by the View
100 : bool bIsEmpty:1;
101 : bool bIsInUndo:1;
102 : bool bDocumentModifiedPending:1;
103 : bool bUpdateEnabled:1;
104 : sal_uInt16 nDocumentLock;
105 : sal_Int16 nCanUpdate; // stores the UpdateDocMode from loading a document till update links
106 :
107 : ScDBData* pOldAutoDBRange;
108 :
109 : ScSbxDocHelper* pDocHelper;
110 :
111 : ScAutoStyleList* pAutoStyleList;
112 : ScPaintLockData* pPaintLockData;
113 : ScOptSolverSave* pSolverSaveData;
114 : ScSheetSaveData* pSheetSaveData;
115 :
116 : ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
117 : #ifdef ENABLE_TELEPATHY
118 : ScCollaboration* mpCollaboration;
119 : #endif
120 :
121 : SC_DLLPRIVATE void InitItems();
122 : SC_DLLPRIVATE void DoEnterHandler();
123 : SC_DLLPRIVATE void InitOptions(bool bForLoading);
124 : SC_DLLPRIVATE void ResetDrawObjectShell();
125 :
126 : // SUNWS needs a forward declared friend, otherwise types and members
127 : // of the outer class are not accessible.
128 : class PrepareSaveGuard;
129 : friend class ScDocShell::PrepareSaveGuard;
130 : /** Do things that need to be done before saving to our own format and
131 : necessary clean ups in dtor. */
132 : class PrepareSaveGuard
133 : {
134 : public:
135 : explicit PrepareSaveGuard( ScDocShell & rDocShell );
136 : ~PrepareSaveGuard();
137 : private:
138 : ScDocShell & mrDocShell;
139 : };
140 :
141 : SC_DLLPRIVATE sal_Bool LoadXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
142 : SC_DLLPRIVATE sal_Bool SaveXML( SfxMedium* pMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
143 : SC_DLLPRIVATE SCTAB GetSaveTab();
144 :
145 : SC_DLLPRIVATE sal_uLong DBaseImport( const String& rFullFileName, CharSet eCharSet,
146 : ScColWidthParam aColWidthParam[MAXCOLCOUNT], ScFlatBoolRowSegments& rRowHeightsRecalc );
147 : SC_DLLPRIVATE sal_uLong DBaseExport(
148 : const rtl::OUString& rFullFileName, CharSet eCharSet, bool& bHasMemo );
149 :
150 : SC_DLLPRIVATE static bool MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
151 : SC_DLLPRIVATE static bool KillFile( const INetURLObject& rURL );
152 : SC_DLLPRIVATE static bool IsDocument( const INetURLObject& rURL );
153 :
154 : SC_DLLPRIVATE void LockPaint_Impl(sal_Bool bDoc);
155 : SC_DLLPRIVATE void UnlockPaint_Impl(sal_Bool bDoc);
156 : SC_DLLPRIVATE void LockDocument_Impl(sal_uInt16 nNew);
157 : SC_DLLPRIVATE void UnlockDocument_Impl(sal_uInt16 nNew);
158 :
159 : SC_DLLPRIVATE void EnableSharedSettings( bool bEnable );
160 : SC_DLLPRIVATE ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > LoadSharedDocument();
161 :
162 : SC_DLLPRIVATE void UseSheetSaveEntries();
163 :
164 : SC_DLLPRIVATE ScDocFunc *CreateDocFunc();
165 :
166 : protected:
167 :
168 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
169 :
170 : public:
171 : TYPEINFO();
172 :
173 5 : SFX_DECL_INTERFACE(SCID_DOC_SHELL)
174 486 : SFX_DECL_OBJECTFACTORY();
175 :
176 : ScDocShell( const ScDocShell& rDocShell );
177 : ScDocShell( const sal_uInt64 i_nSfxCreationFlags = SFXMODEL_EMBEDDED_OBJECT );
178 : ~ScDocShell();
179 :
180 : using SotObject::GetInterface;
181 : using SfxShell::Activate; // with sal_Bool bMDI
182 : using SfxShell::Deactivate; // with sal_Bool bMDI
183 : using SfxObjectShell::Print; // print styles
184 :
185 : #ifdef ENABLE_TELEPATHY
186 : SC_DLLPRIVATE ScCollaboration* GetCollaboration();
187 : #endif
188 : virtual void Activate();
189 : virtual void Deactivate();
190 :
191 : virtual ::svl::IUndoManager*
192 : GetUndoManager();
193 :
194 : virtual void FillClass( SvGlobalName * pClassName,
195 : sal_uInt32 * pFormat,
196 : String * pAppName,
197 : String * pFullTypeName,
198 : String * pShortTypeName,
199 : sal_Int32 nFileFormat,
200 : sal_Bool bTemplate = false ) const;
201 :
202 : virtual sal_Bool InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
203 : virtual sal_Bool Load( SfxMedium& rMedium );
204 : virtual sal_Bool LoadFrom( SfxMedium& rMedium );
205 : virtual sal_Bool ConvertFrom( SfxMedium &rMedium );
206 : virtual bool LoadExternal(SfxMedium& rMedium, const rtl::OUString& rProvider);
207 : virtual sal_Bool Save();
208 : virtual sal_Bool SaveAs( SfxMedium& rMedium );
209 : virtual sal_Bool ConvertTo( SfxMedium &rMedium );
210 : virtual sal_uInt16 PrepareClose( sal_Bool bUI = sal_True, sal_Bool bForBrowsing = false );
211 : virtual void PrepareReload();
212 : virtual sal_Bool IsInformationLost();
213 : virtual void LoadStyles( SfxObjectShell &rSource );
214 : virtual sal_Bool Insert( SfxObjectShell &rSource,
215 : sal_uInt16 nSourceIdx1, sal_uInt16 nSourceIdx2, sal_uInt16 nSourceIdx3,
216 : sal_uInt16 &nIdx1, sal_uInt16 &nIdx2, sal_uInt16 &nIdx3, sal_uInt16 &rIdxDeleted );
217 :
218 : virtual sal_Bool SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& ); // SfxInPlaceObject
219 : virtual sal_Bool DoSaveCompleted( SfxMedium * pNewStor); // SfxObjectShell
220 : virtual sal_Bool QuerySlotExecutable( sal_uInt16 nSlotId );
221 :
222 : virtual void Draw( OutputDevice *, const JobSetup & rSetup,
223 : sal_uInt16 nAspect = ASPECT_CONTENT );
224 :
225 : virtual void SetVisArea( const Rectangle & rVisArea );
226 :
227 : using SfxObjectShell::GetVisArea;
228 : virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const;
229 :
230 : virtual Printer* GetDocumentPrinter();
231 :
232 : virtual void SetModified( sal_Bool = sal_True );
233 :
234 : void SetVisAreaOrSize( const Rectangle& rVisArea, sal_Bool bModifyStart );
235 :
236 : virtual SfxDocumentInfoDialog* CreateDocumentInfoDialog( Window *pParent,
237 : const SfxItemSet &rSet );
238 :
239 : void GetDocStat( ScDocStat& rDocStat );
240 :
241 43598 : ScDocument* GetDocument() { return &aDocument; }
242 2459 : ScDocFunc& GetDocFunc() { return *pDocFunc; }
243 : void SetDocFunc( ScDocFunc *pDF ) { pDocFunc = pDF; }
244 :
245 : SfxPrinter* GetPrinter( sal_Bool bCreateIfNotExist = sal_True );
246 : sal_uInt16 SetPrinter( SfxPrinter* pNewPrinter, sal_uInt16 nDiffFlags = SFX_PRINTER_ALL );
247 :
248 : void UpdateFontList();
249 :
250 : String CreateObjectName( const String& rPrefix );
251 :
252 : ScDrawLayer* MakeDrawLayer();
253 :
254 : void AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
255 :
256 : void GetSbxState( SfxItemSet &rSet );
257 : void GetDrawObjState( SfxItemSet &rSet );
258 :
259 : void Execute( SfxRequest& rReq );
260 : void GetState( SfxItemSet &rSet );
261 : void ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
262 : void GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab );
263 :
264 : void CompareDocument( ScDocument& rOtherDoc );
265 : void MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = NULL, bool bInverseMap = false );
266 : bool MergeSharedDocument( ScDocShell* pSharedDocShell );
267 :
268 : ScChangeAction* GetChangeAction( const ScAddress& rPos );
269 : void SetChangeComment( ScChangeAction* pAction, const String& rComment );
270 : void ExecuteChangeCommentDialog( ScChangeAction* pAction, Window* pParent,sal_Bool bPrevNext=sal_True );
271 : /// Protect/unprotect ChangeTrack and return <TRUE/> if
272 : /// protection was successfully changed.
273 : /// If bJustQueryIfProtected==sal_True protection is not
274 : /// changed and <TRUE/> is returned if not protected or
275 : /// password was entered correctly.
276 : bool ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected = false );
277 :
278 : void SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
279 : bool AdjustPrintZoom( const ScRange& rRange );
280 :
281 : void LoadStylesArgs( ScDocShell& rSource, bool bReplace, bool bCellStyles, bool bPageStyles );
282 :
283 : void PageStyleModified( const rtl::OUString& rStyleName, sal_Bool bApi );
284 :
285 : void NotifyStyle( const SfxStyleSheetHint& rHint );
286 : void DoAutoStyle( const ScRange& rRange, const String& rStyle );
287 :
288 : Window* GetActiveDialogParent();
289 : void ErrorMessage( sal_uInt16 nGlobStrId );
290 : sal_Bool IsEditable() const;
291 :
292 : sal_Bool AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
293 : void UpdateAllRowHeights( const ScMarkData* pTabMark = NULL );
294 : void UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
295 :
296 : void RefreshPivotTables( const ScRange& rSource );
297 : void DoConsolidate( const ScConsolidateParam& rParam, sal_Bool bRecord = sal_True );
298 : void UseScenario( SCTAB nTab, const String& rName, sal_Bool bRecord = sal_True );
299 : SCTAB MakeScenario( SCTAB nTab, const String& rName, const String& rComment,
300 : const Color& rColor, sal_uInt16 nFlags,
301 : ScMarkData& rMark, sal_Bool bRecord = sal_True );
302 : void ModifyScenario( SCTAB nTab, const String& rName, const String& rComment,
303 : const Color& rColor, sal_uInt16 nFlags );
304 : sal_uLong TransferTab( ScDocShell& rSrcDocShell, SCTAB nSrcPos,
305 : SCTAB nDestPos, sal_Bool bInsertNew,
306 : sal_Bool bNotifyAndPaint );
307 :
308 : sal_Bool MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord );
309 :
310 : void DoRecalc( bool bApi );
311 : void DoHardRecalc( bool bApi );
312 :
313 : void UpdateOle( const ScViewData* pViewData, sal_Bool bSnapSize = false);
314 : sal_Bool IsOle();
315 :
316 : void DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
317 : ScDBData* GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
318 : ScDBData* GetAnonymousDBData(const ScRange& rRange);
319 : ScDBData* GetOldAutoDBRange(); // has to be deleted by caller!
320 : void CancelAutoDBRange(); // called when dialog is cancelled
321 :
322 : virtual void ReconnectDdeLink(SfxObjectShell& rServer);
323 : void UpdateLinks();
324 : sal_Bool ReloadTabLinks();
325 :
326 : void SetFormulaOptions(const ScFormulaOptions& rOpt );
327 : virtual void CheckConfigOptions();
328 :
329 : void PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
330 :
331 : void PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
332 : SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart,
333 : sal_uInt16 nExtFlags = 0 );
334 : void PostPaint( const ScRangeList& rRanges, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 );
335 :
336 : void PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
337 : void PostPaintCell( const ScAddress& rPos );
338 : void PostPaintGridAll();
339 : void PostPaintExtras();
340 :
341 2 : bool IsPaintLocked() const { return pPaintLockData != NULL; }
342 :
343 : void PostDataChanged();
344 :
345 : void UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
346 : SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
347 : void UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
348 :
349 : void SetDocumentModified( sal_Bool bIsModified = sal_True );
350 : void SetDrawModified( sal_Bool bIsModified = sal_True );
351 :
352 : void LockPaint();
353 : void UnlockPaint();
354 : sal_uInt16 GetLockCount() const;
355 : void SetLockCount(sal_uInt16 nNew);
356 :
357 : void LockDocument();
358 : void UnlockDocument();
359 :
360 : DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
361 :
362 : virtual SfxStyleSheetBasePool* GetStyleSheetPool();
363 :
364 : void SetInplace( bool bInplace );
365 : bool IsEmpty() const;
366 : void SetEmpty(bool bSet);
367 :
368 0 : bool IsInUndo() const { return bIsInUndo; }
369 : void SetInUndo(bool bSet);
370 :
371 : void CalcOutputFactor();
372 : double GetOutputFactor() const;
373 : void GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
374 : SCTAB nCurTab,
375 : bool& rbHeader,
376 : bool& rbFooter );
377 :
378 : virtual long DdeGetData( const String& rItem, const String& rMimeType,
379 : ::com::sun::star::uno::Any & rValue );
380 : virtual long DdeSetData( const String& rItem, const String& rMimeType,
381 : const ::com::sun::star::uno::Any & rValue );
382 : virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const String& rItem );
383 :
384 0 : const String& GetDdeTextFmt() const { return aDdeTextFmt; }
385 :
386 : SfxBindings* GetViewBindings();
387 :
388 : ScTabViewShell* GetBestViewShell( sal_Bool bOnlyVisible = sal_True );
389 : ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; }
390 :
391 70 : void SetDocumentModifiedPending( bool bVal )
392 70 : { bDocumentModifiedPending = bVal; }
393 833 : bool IsDocumentModifiedPending() const
394 833 : { return bDocumentModifiedPending; }
395 :
396 0 : bool IsUpdateEnabled() const
397 0 : { return bUpdateEnabled; }
398 0 : void SetUpdateEnabled(bool bValue)
399 0 : { bUpdateEnabled = bValue; }
400 :
401 : OutputDevice* GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
402 :
403 : static ScViewData* GetViewData();
404 : static SCTAB GetCurTab();
405 :
406 : static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
407 : static String GetOwnFilterName();
408 : static String GetHtmlFilterName();
409 : static String GetWebQueryFilterName();
410 : static String GetAsciiFilterName();
411 : static String GetLotusFilterName();
412 : static String GetDBaseFilterName();
413 : static String GetDifFilterName();
414 : static sal_Bool HasAutomaticTableName( const String& rFilter );
415 :
416 : DECL_LINK( RefreshDBDataHdl, ScRefreshTimer* );
417 :
418 : void BeforeXMLLoading();
419 : void AfterXMLLoading(sal_Bool bRet);
420 :
421 : virtual sal_uInt16 GetHiddenInformationState( sal_uInt16 nStates );
422 :
423 0 : const ScOptSolverSave* GetSolverSaveData() const { return pSolverSaveData; } // may be null
424 : void SetSolverSaveData( const ScOptSolverSave& rData );
425 : ScSheetSaveData* GetSheetSaveData();
426 :
427 : void ResetKeyBindings( ScOptionsUtil::KeyBindingType eType );
428 :
429 : // password protection for Calc (derived from SfxObjectShell)
430 : // see also: FID_CHG_RECORD, SID_CHG_PROTECT
431 : virtual bool IsChangeRecording() const;
432 : virtual bool HasChangeRecordProtection() const;
433 : virtual void SetChangeRecording( bool bActivate );
434 : virtual bool SetProtectionPassword( const String &rPassword );
435 : virtual bool GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash );
436 : };
437 :
438 :
439 : void UpdateAcceptChangesDialog();
440 :
441 :
442 504 : SV_DECL_REF(ScDocShell)
443 584 : SV_IMPL_REF(ScDocShell)
444 :
445 :
446 : /** Create before modifications of the document and then destroy.
447 : If noted in the ctor AutoCalcShellDisabled and IdleDisabled,
448 : switches them off and restores the dtor AutoCalcShellDisabled
449 : also before a ScDocShell SetDocumentModified.
450 : Call SetDocumentModified after instead of the ScDocShell.
451 : In the dtor, if ScDocShell bDocumentModifiedPending is set and
452 : bAutoCalcShellDisabled is not set, then SetDocumentModified is called. */
453 : class SC_DLLPUBLIC ScDocShellModificator
454 : {
455 : ScDocShell& rDocShell;
456 : ScRefreshTimerProtector aProtector;
457 : sal_Bool bAutoCalcShellDisabled;
458 : sal_Bool bIdleDisabled;
459 :
460 : // not implemented
461 : ScDocShellModificator( const ScDocShellModificator& );
462 : ScDocShellModificator& operator=( const ScDocShellModificator& );
463 :
464 : public:
465 : ScDocShellModificator( ScDocShell& );
466 : ~ScDocShellModificator();
467 : void SetDocumentModified();
468 : };
469 :
470 :
471 :
472 : #endif
473 :
474 :
475 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|