xref: /AOO41X/main/sc/source/ui/inc/docsh.hxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_DOCSHELL_HXX
25 #define SC_DOCSHELL_HXX
26 
27 
28 #include <sfx2/objsh.hxx>
29 
30 #include <sfx2/docfac.hxx>
31 #include <sfx2/sfxmodelfactory.hxx>
32 #include <sfx2/viewsh.hxx>
33 
34 #include "scdllapi.h"
35 #include "scdll.hxx"
36 #include "document.hxx"
37 #include "shellids.hxx"
38 #include "refreshtimer.hxx"
39 
40 #include <hash_map>
41 
42 class ScEditEngineDefaulter;
43 class FontList;
44 class SfxStyleSheetBasePool;
45 class SfxStyleSheetHint;
46 struct ChartSelectionInfo;
47 class INetURLObject;
48 
49 class ScPaintItem;
50 class ScViewData;
51 class ScDocFunc;
52 class ScDrawLayer;
53 class ScTabViewShell;
54 class ScSbxDocHelper;
55 class ScAutoStyleList;
56 class ScRange;
57 class ScMarkData;
58 class ScPaintLockData;
59 class ScJobSetup;
60 class ScChangeAction;
61 class VirtualDevice;
62 class ScImportOptions;
63 class ScDocShellModificator;
64 class ScOptSolverSave;
65 class ScSheetSaveData;
66 
67 namespace sfx2 { class FileDialogHelper; }
68 struct DocShell_Impl;
69 
70 typedef ::std::hash_map< sal_uLong, sal_uLong > ScChangeActionMergeMap;
71 
72 //==================================================================
73 
74 //enum ScDBFormat { SC_FORMAT_SDF, SC_FORMAT_DBF };
75 
76                                     // Extra-Flags fuer Repaint
77 #define SC_PF_LINES         1
78 #define SC_PF_TESTMERGE     2
79 #define SC_PF_WHOLEROWS     4
80 
81 class SC_DLLPUBLIC ScDocShell: public SfxObjectShell, public SfxListener
82 {
83     static const sal_Char __FAR_DATA pStarCalcDoc[];
84     static const sal_Char __FAR_DATA pStyleName[];
85 
86     ScDocument          aDocument;
87 
88     String              aDdeTextFmt;
89     String              aConvFilterName; //@ #BugId 54198
90 
91     double              nPrtToScreenFactor;
92 //!   FontList*           pFontList;
93     DocShell_Impl*      pImpl;
94     ScDocFunc*          pDocFunc;
95 
96     //SfxObjectCreateMode   eShellMode;
97 
98     sal_Bool                bIsInplace;         // wird von der View gesetzt
99     sal_Bool                bHeaderOn;
100     sal_Bool                bFooterOn;
101     sal_Bool                bNoInformLost;
102     sal_Bool                bIsEmpty;
103     sal_Bool                bIsInUndo;
104     sal_Bool                bDocumentModifiedPending;
105     sal_uInt16              nDocumentLock;
106     sal_Int16           nCanUpdate;  // stores the UpdateDocMode from loading a document till update links
107     sal_Bool                bUpdateEnabled;
108 
109     ScDBData*           pOldAutoDBRange;
110 
111     ScSbxDocHelper*     pDocHelper;
112 
113     ScAutoStyleList*    pAutoStyleList;
114     ScPaintLockData*    pPaintLockData;
115     ScJobSetup*         pOldJobSetup;
116     ScOptSolverSave*    pSolverSaveData;
117     ScSheetSaveData*    pSheetSaveData;
118 
119     ScDocShellModificator* pModificator; // #109979#; is used to load XML (created in BeforeXMLLoading and destroyed in AfterXMLLoading)
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                                  sal_Bool bSimpleColWidth[MAXCOLCOUNT] );
147     SC_DLLPRIVATE sal_uLong         DBaseExport( const String& rFullFileName, CharSet eCharSet,
148                                  sal_Bool& bHasMemo );
149 
150     SC_DLLPRIVATE static sal_Bool       MoveFile( const INetURLObject& rSource, const INetURLObject& rDest );
151     SC_DLLPRIVATE static sal_Bool       KillFile( const INetURLObject& rURL );
152     SC_DLLPRIVATE static sal_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     ScDBData*       GetDBDataAdd( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
162 
163     SC_DLLPRIVATE void          UseSheetSaveEntries();
164 
165 protected:
166 
167     virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
168 
169 public:
170                     TYPEINFO();
171 
172                     SFX_DECL_INTERFACE(SCID_DOC_SHELL)
173                     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     using SfxObjectShell::Print;        // print styles
183 
184     virtual void    Activate();
185     virtual void    Deactivate();
186 
187     virtual ::svl::IUndoManager*
188                     GetUndoManager();
189 
190     virtual void    FillClass( SvGlobalName * pClassName,
191                                sal_uInt32 * pFormat,
192                                String * pAppName,
193                                String * pFullTypeName,
194                                String * pShortTypeName,
195                                sal_Int32 nFileFormat,
196                                sal_Bool bTemplate = sal_False ) const;
197 
198     virtual sal_Bool    InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );
199     virtual sal_Bool    Load( SfxMedium& rMedium );
200     virtual sal_Bool    LoadFrom( SfxMedium& rMedium );
201     virtual sal_Bool    ConvertFrom( SfxMedium &rMedium );
202     virtual sal_Bool    Save();
203     virtual sal_Bool    SaveAs( SfxMedium& rMedium );
204     virtual sal_Bool    ConvertTo( SfxMedium &rMedium );
205     virtual sal_uInt16  PrepareClose( sal_Bool bUI = sal_True, sal_Bool bForBrowsing = sal_False );
206     virtual void    PrepareReload();
207     virtual sal_Bool    IsInformationLost();
208     virtual void    LoadStyles( SfxObjectShell &rSource );
209     virtual sal_Bool    Insert( SfxObjectShell &rSource,
210                                 sal_uInt16 nSourceIdx1, sal_uInt16 nSourceIdx2, sal_uInt16 nSourceIdx3,
211                                 sal_uInt16 &nIdx1, sal_uInt16 &nIdx2, sal_uInt16 &nIdx3, sal_uInt16 &rIdxDeleted );
212 
213     virtual sal_Bool    SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& );      // SfxInPlaceObject
214     virtual sal_Bool    DoSaveCompleted( SfxMedium * pNewStor);     // SfxObjectShell
215     virtual sal_Bool QuerySlotExecutable( sal_uInt16 nSlotId );
216 
217     virtual void    Draw( OutputDevice *, const JobSetup & rSetup,
218                                 sal_uInt16 nAspect = ASPECT_CONTENT );
219 
220     virtual void    SetVisArea( const Rectangle & rVisArea );
221 
222     using SfxObjectShell::GetVisArea;
223     virtual Rectangle GetVisArea( sal_uInt16 nAspect ) const;
224 
225     virtual Printer* GetDocumentPrinter();
226 
227     virtual void    SetModified( sal_Bool = sal_True );
228 
229     void            SetVisAreaOrSize( const Rectangle& rVisArea, sal_Bool bModifyStart );
230 
231     virtual SfxDocumentInfoDialog*  CreateDocumentInfoDialog( Window *pParent,
232                                                               const SfxItemSet &rSet );
233 
234     void    GetDocStat( ScDocStat& rDocStat );
235 
236     ScDocument*     GetDocument()   { return &aDocument; }
237     ScDocFunc&      GetDocFunc()    { return *pDocFunc; }
238 
239     SfxPrinter*     GetPrinter( sal_Bool bCreateIfNotExist = sal_True );
240     sal_uInt16          SetPrinter( SfxPrinter* pNewPrinter, sal_uInt16 nDiffFlags = SFX_PRINTER_ALL );
241 
242     void            UpdateFontList();
243 
244     String          CreateObjectName( const String& rPrefix );
245 
246     ScDrawLayer*    MakeDrawLayer();
247 
248     void            AsciiSave( SvStream& rStream, const ScImportOptions& rOpt );
249 
250     void            GetSbxState( SfxItemSet &rSet );
251     void            GetDrawObjState( SfxItemSet &rSet );
252 
253     void            Execute( SfxRequest& rReq );
254     void            GetState( SfxItemSet &rSet );
255     void            ExecutePageStyle ( SfxViewShell& rCaller, SfxRequest& rReq, SCTAB nCurTab );
256     void            GetStatePageStyle( SfxViewShell& rCaller, SfxItemSet& rSet, SCTAB nCurTab );
257 
258     void            CompareDocument( ScDocument& rOtherDoc );
259     void            MergeDocument( ScDocument& rOtherDoc, bool bShared = false, bool bCheckDuplicates = false, sal_uLong nOffset = 0, ScChangeActionMergeMap* pMergeMap = NULL, bool bInverseMap = false );
260     bool            MergeSharedDocument( ScDocShell* pSharedDocShell );
261 
262     ScChangeAction* GetChangeAction( const ScAddress& rPos );
263     void            SetChangeComment( ScChangeAction* pAction, const String& rComment );
264     void            ExecuteChangeCommentDialog( ScChangeAction* pAction, Window* pParent,sal_Bool bPrevNext=sal_True );
265                     /// Protect/unprotect ChangeTrack and return <TRUE/> if
266                     /// protection was successfully changed.
267                     /// If bJustQueryIfProtected==sal_True protection is not
268                     /// changed and <TRUE/> is returned if not protected or
269                     /// password was entered correctly.
270     sal_Bool            ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected = sal_False );
271 
272     void            SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages );
273     sal_Bool            AdjustPrintZoom( const ScRange& rRange );
274 
275     void            LoadStylesArgs( ScDocShell& rSource, sal_Bool bReplace, sal_Bool bCellStyles, sal_Bool bPageStyles );
276 
277     void            PageStyleModified( const String& rStyleName, sal_Bool bApi );
278 
279     void            NotifyStyle( const SfxStyleSheetHint& rHint );
280     void            DoAutoStyle( const ScRange& rRange, const String& rStyle );
281 
282     Window*         GetActiveDialogParent();
283     void            ErrorMessage( sal_uInt16 nGlobStrId );
284     sal_Bool            IsEditable() const;
285 
286     sal_Bool            AdjustRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab );
287     void            UpdateAllRowHeights( const ScMarkData* pTabMark = NULL );
288     void            UpdatePendingRowHeights( SCTAB nUpdateTab, bool bBefore = false );
289 
290     void            RefreshPivotTables( const ScRange& rSource );
291     void            DoConsolidate( const ScConsolidateParam& rParam, sal_Bool bRecord = sal_True );
292     void            UseScenario( SCTAB nTab, const String& rName, sal_Bool bRecord = sal_True );
293     SCTAB           MakeScenario( SCTAB nTab, const String& rName, const String& rComment,
294                                     const Color& rColor, sal_uInt16 nFlags,
295                                     ScMarkData& rMark, sal_Bool bRecord = sal_True );
296     void            ModifyScenario( SCTAB nTab, const String& rName, const String& rComment,
297                                     const Color& rColor, sal_uInt16 nFlags );
298     sal_Bool            MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, sal_Bool bRecord );
299 
300     void            DoRecalc( sal_Bool bApi );
301     void            DoHardRecalc( sal_Bool bApi );
302 
303     void            UpdateOle( const ScViewData* pViewData, sal_Bool bSnapSize = sal_False);
304     sal_Bool        IsOle();
305 
306     void            DBAreaDeleted( SCTAB nTab, SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2 );
307     ScDBData*       GetDBData( const ScRange& rMarked, ScGetDBMode eMode, ScGetDBSelection eSel );
308     ScDBData*       GetOldAutoDBRange();    // has to be deleted by caller!
309     void            CancelAutoDBRange();    // called when dialog is cancelled
310     ScDBCollection* GetDBCollection(){ return aDocument.GetDBCollection();}
311 
312     void            UpdateLinks();          // Link-Eintraege aktuallisieren
313     sal_Bool            ReloadTabLinks();       // Links ausfuehren (Inhalt aktualisieren)
314 
315     void            PostEditView( ScEditEngineDefaulter* pEditEngine, const ScAddress& rCursorPos );
316 
317     void            PostPaint( SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
318                             SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab, sal_uInt16 nPart,
319                             sal_uInt16 nExtFlags = 0 );
320     void            PostPaint( const ScRange& rRange, sal_uInt16 nPart, sal_uInt16 nExtFlags = 0 );
321 
322     void            PostPaintCell( SCCOL nCol, SCROW nRow, SCTAB nTab );
323     void            PostPaintCell( const ScAddress& rPos );
324     void            PostPaintGridAll();
325     void            PostPaintExtras();
326 
327     bool            IsPaintLocked() const { return pPaintLockData != NULL; }
328 
329     void            PostDataChanged();
330 
331     void            UpdatePaintExt( sal_uInt16& rExtFlags, SCCOL nStartCol, SCROW nStartRow, SCTAB nStartTab,
332                                                        SCCOL nEndCol, SCROW nEndRow, SCTAB nEndTab );
333     void            UpdatePaintExt( sal_uInt16& rExtFlags, const ScRange& rRange );
334 
335     void            SetDocumentModified( sal_Bool bIsModified = sal_True );
336     void            SetDrawModified( sal_Bool bIsModified = sal_True );
337 
338     void            LockPaint();
339     void            UnlockPaint();
340     sal_uInt16          GetLockCount() const;
341     void            SetLockCount(sal_uInt16 nNew);
342 
343     void            LockDocument();
344     void            UnlockDocument();
345 
346     DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper* );
347 
348     virtual SfxStyleSheetBasePool*  GetStyleSheetPool();
349 
350     void            SetInplace( sal_Bool bInplace );
351     sal_Bool            IsEmpty() const;
352     void            SetEmpty(sal_Bool bSet);
353 
354     sal_Bool            IsInUndo() const                { return bIsInUndo; }
355     void            SetInUndo(sal_Bool bSet);
356 
357     void            CalcOutputFactor();
358     double          GetOutputFactor() const;
359     void            GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
360                                                SCTAB             nCurTab,
361                                                sal_Bool&             rbHeader,
362                                                sal_Bool&             rbFooter );
363 
364     virtual long DdeGetData( const String& rItem, const String& rMimeType,
365                                 ::com::sun::star::uno::Any & rValue );
366     virtual long DdeSetData( const String& rItem, const String& rMimeType,
367                                 const ::com::sun::star::uno::Any & rValue );
368     virtual ::sfx2::SvLinkSource* DdeCreateLinkSource( const String& rItem );
369 
370     const String& GetDdeTextFmt() const { return aDdeTextFmt; }
371 
372     SfxBindings*    GetViewBindings();
373 
374     ScTabViewShell* GetBestViewShell( sal_Bool bOnlyVisible = sal_True );
375     ScSbxDocHelper* GetDocHelperObject() { return pDocHelper; }
376 
377     void            SetDocumentModifiedPending( sal_Bool bVal )
378                         { bDocumentModifiedPending = bVal; }
379     sal_Bool            IsDocumentModifiedPending() const
380                         { return bDocumentModifiedPending; }
381 
382     sal_Bool            IsUpdateEnabled() const
383                         { return bUpdateEnabled; }
384     void            SetUpdateEnabled(sal_Bool bValue)
385                         { bUpdateEnabled = bValue; }
386 
387     OutputDevice*   GetRefDevice(); // WYSIWYG: Printer, otherwise VirtualDevice...
388 
389     static ScViewData* GetViewData();
390     static SCTAB       GetCurTab();
391 
392     static ScDocShell* GetShellByNum( sal_uInt16 nDocNo );
393     static String   GetOwnFilterName();
394         static String   GetHtmlFilterName();
395     static String   GetWebQueryFilterName();
396     static String   GetAsciiFilterName();
397     static String   GetLotusFilterName();
398     static String   GetDBaseFilterName();
399     static String   GetDifFilterName();
400     static sal_Bool     HasAutomaticTableName( const String& rFilter );
401 
402     DECL_LINK( RefreshDBDataHdl, ScRefreshTimer* );
403 
404     void            BeforeXMLLoading();
405     void            AfterXMLLoading(sal_Bool bRet);
406 
407     virtual sal_uInt16 GetHiddenInformationState( sal_uInt16 nStates );
408 
409     const ScOptSolverSave* GetSolverSaveData() const    { return pSolverSaveData; }     // may be null
410     void            SetSolverSaveData( const ScOptSolverSave& rData );
411     //<!--Added by PengYunQuan for Validity Cell Range Picker
412     sal_Bool        AcceptStateUpdate() const;
413     //-->Added by PengYunQuan for Validity Cell Range Picker
414     ScSheetSaveData* GetSheetSaveData();
415 
416     // passwword protection for Calc (derived from SfxObjectShell)
417     // see also:    FID_CHG_RECORD, SID_CHG_PROTECT
418     virtual bool    IsChangeRecording() const;
419     virtual bool    HasChangeRecordProtection() const;
420     virtual void    SetChangeRecording( bool bActivate );
421     virtual bool    SetProtectionPassword( const String &rPassword );
422     virtual bool    GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > &rPasswordHash );
423     void BeforeLoading( SfxMedium&, const ::rtl::OUString &, const ::rtl::OUString & );
424     void AfterLoading( SfxMedium&, const ::rtl::OUString &, const ::rtl::OUString & );
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