xref: /aoo41x/main/sc/source/filter/inc/xlroot.hxx (revision 38d50f7b)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*38d50f7bSAndrew Rist  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*38d50f7bSAndrew Rist  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19*38d50f7bSAndrew Rist  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_XLROOT_HXX
25cdf0e10cSrcweir #define SC_XLROOT_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <i18npool/lang.h>
30cdf0e10cSrcweir #include <sot/storage.hxx>
31cdf0e10cSrcweir #include "xlconst.hxx"
32cdf0e10cSrcweir #include "xltools.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace comphelper { class IDocPasswordVerifier; }
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // Forward declarations of objects in public use ==============================
37cdf0e10cSrcweir 
38cdf0e10cSrcweir class DateTime;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir struct XclAddress;
41cdf0e10cSrcweir struct XclRange;
42cdf0e10cSrcweir class XclRangeList;
43cdf0e10cSrcweir class XclTokenArray;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // Global data ================================================================
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #ifdef DBG_UTIL
48cdf0e10cSrcweir /** Counts the number of created root objects. */
49cdf0e10cSrcweir struct XclDebugObjCounter
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     sal_Int32           mnObjCnt;
XclDebugObjCounterXclDebugObjCounter52cdf0e10cSrcweir     inline explicit     XclDebugObjCounter() : mnObjCnt( 0 ) {}
53cdf0e10cSrcweir                         ~XclDebugObjCounter();
54cdf0e10cSrcweir };
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // ----------------------------------------------------------------------------
58cdf0e10cSrcweir 
59cdf0e10cSrcweir class SfxMedium;
60cdf0e10cSrcweir class ScEditEngineDefaulter;
61cdf0e10cSrcweir class ScHeaderEditEngine;
62cdf0e10cSrcweir class EditEngine;
63cdf0e10cSrcweir class ScExtDocOptions;
64cdf0e10cSrcweir class XclFontPropSetHelper;
65cdf0e10cSrcweir class XclChPropSetHelper;
66cdf0e10cSrcweir class XclTracer;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir struct RootData;//!
69cdf0e10cSrcweir 
70cdf0e10cSrcweir /** Stores global buffers and data needed elsewhere in the Excel filters. */
71cdf0e10cSrcweir struct XclRootData
72cdf0e10cSrcweir #ifdef DBG_UTIL
73cdf0e10cSrcweir     : public XclDebugObjCounter
74cdf0e10cSrcweir #endif
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     typedef ScfRef< ScEditEngineDefaulter > ScEEDefaulterRef;
77cdf0e10cSrcweir     typedef ScfRef< ScHeaderEditEngine >    ScHeaderEERef;
78cdf0e10cSrcweir     typedef ScfRef< EditEngine >            EditEngineRef;
79cdf0e10cSrcweir     typedef ScfRef< XclFontPropSetHelper >  XclFontPropSetHlpRef;
80cdf0e10cSrcweir     typedef ScfRef< XclChPropSetHelper >    XclChPropSetHlpRef;
81cdf0e10cSrcweir     typedef ScfRef< ScExtDocOptions >       ScExtDocOptRef;
82cdf0e10cSrcweir     typedef ScfRef< XclTracer >             XclTracerRef;
83cdf0e10cSrcweir     typedef ScfRef< RootData >              RootDataRef;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     XclBiff             meBiff;             /// Current BIFF version.
86cdf0e10cSrcweir     XclOutput           meOutput;           /// Current Output format.
87cdf0e10cSrcweir     SfxMedium&          mrMedium;           /// The medium to import from.
88cdf0e10cSrcweir     SotStorageRef       mxRootStrg;         /// The root OLE storage of imported/exported file.
89cdf0e10cSrcweir     ScDocument&         mrDoc;              /// The source or destination document.
90cdf0e10cSrcweir     String              maDocUrl;           /// Document URL of imported/exported file.
91cdf0e10cSrcweir     String              maBasePath;         /// Base path of imported/exported file (path of maDocUrl).
92cdf0e10cSrcweir     String              maUserName;         /// Current user name.
93cdf0e10cSrcweir     const String        maDefPassword;      /// The default password used for stream encryption.
94cdf0e10cSrcweir     rtl_TextEncoding    meTextEnc;          /// Text encoding to import/export byte strings.
95cdf0e10cSrcweir     LanguageType        meSysLang;          /// System language.
96cdf0e10cSrcweir     LanguageType        meDocLang;          /// Document language (import: from file, export: from system).
97cdf0e10cSrcweir     LanguageType        meUILang;           /// UI language (import: from file, export: from system).
98cdf0e10cSrcweir     sal_Int16           mnDefApiScript;     /// Default script type for blank cells (API constant).
99cdf0e10cSrcweir     ScAddress           maScMaxPos;         /// Highest Calc cell position.
100cdf0e10cSrcweir     ScAddress           maXclMaxPos;        /// Highest Excel cell position.
101cdf0e10cSrcweir     ScAddress           maMaxPos;           /// Highest position valid in Calc and Excel.
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     ScEEDefaulterRef    mxEditEngine;       /// Edit engine for rich strings etc.
104cdf0e10cSrcweir     ScHeaderEERef       mxHFEditEngine;     /// Edit engine for header/footer.
105cdf0e10cSrcweir     EditEngineRef       mxDrawEditEng;      /// Edit engine for text boxes.
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     XclFontPropSetHlpRef mxFontPropSetHlp;  /// Property set helper for fonts.
108cdf0e10cSrcweir     XclChPropSetHlpRef  mxChPropSetHlp;     /// Property set helper for chart filter.
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     ScExtDocOptRef      mxExtDocOpt;        /// Extended document options.
111cdf0e10cSrcweir     XclTracerRef        mxTracer;           /// Filter tracer.
112cdf0e10cSrcweir     RootDataRef         mxRD;               /// Old RootData struct. Will be removed.
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     double              mfScreenPixelX;     /// Width of a screen pixel (1/100 mm).
115cdf0e10cSrcweir     double              mfScreenPixelY;     /// Height of a screen pixel (1/100 mm).
116cdf0e10cSrcweir     long                mnCharWidth;        /// Width of '0' in default font (twips).
117cdf0e10cSrcweir     SCTAB               mnScTab;            /// Current Calc sheet index.
118cdf0e10cSrcweir     const bool          mbExport;           /// false = Import, true = Export.
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     explicit            XclRootData( XclBiff eBiff, SfxMedium& rMedium,
121cdf0e10cSrcweir                             SotStorageRef xRootStrg, ScDocument& rDoc,
122cdf0e10cSrcweir                             rtl_TextEncoding eTextEnc, bool bExport );
123cdf0e10cSrcweir     virtual             ~XclRootData();
124cdf0e10cSrcweir };
125cdf0e10cSrcweir 
126cdf0e10cSrcweir // ----------------------------------------------------------------------------
127cdf0e10cSrcweir 
128cdf0e10cSrcweir class SfxObjectShell;
129cdf0e10cSrcweir class ScModelObj;
130cdf0e10cSrcweir class OutputDevice;
131cdf0e10cSrcweir class SvNumberFormatter;
132cdf0e10cSrcweir class SdrPage;
133cdf0e10cSrcweir class ScDocumentPool;
134cdf0e10cSrcweir class ScStyleSheetPool;
135cdf0e10cSrcweir class ScRangeName;
136cdf0e10cSrcweir class ScDBCollection;
137cdf0e10cSrcweir struct XclFontData;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir /** Access to global data for a filter object (imported or exported document) from other classes. */
140cdf0e10cSrcweir class XclRoot
141cdf0e10cSrcweir {
142cdf0e10cSrcweir public:
143cdf0e10cSrcweir     explicit            XclRoot( XclRootData& rRootData );
144cdf0e10cSrcweir                         XclRoot( const XclRoot& rRoot );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     virtual             ~XclRoot();
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     XclRoot&            operator=( const XclRoot& rRoot );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     /** Returns this root instance - for code readability in derived classes. */
GetRoot() const151cdf0e10cSrcweir     inline const XclRoot& GetRoot() const { return *this; }
152cdf0e10cSrcweir     /** Returns old RootData struct. Deprecated. */
GetOldRoot() const153cdf0e10cSrcweir     inline RootData&    GetOldRoot() const { return *mrData.mxRD; }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** Returns the current BIFF version of the importer/exporter. */
GetBiff() const156cdf0e10cSrcweir     inline XclBiff      GetBiff() const { return mrData.meBiff; }
157cdf0e10cSrcweir     /** Returns the current output format of the importer/exporter. */
GetOutput() const158cdf0e10cSrcweir     inline XclOutput    GetOutput() const { return mrData.meOutput; }
159cdf0e10cSrcweir     /** Returns true, if currently a document is imported. */
IsImport() const160cdf0e10cSrcweir     inline bool         IsImport() const { return !mrData.mbExport; }
161cdf0e10cSrcweir     /** Returns true, if currently a document is exported. */
IsExport() const162cdf0e10cSrcweir     inline bool         IsExport() const { return mrData.mbExport; }
163cdf0e10cSrcweir     /** Returns the text encoding to import/export byte strings. */
GetTextEncoding() const164cdf0e10cSrcweir     inline rtl_TextEncoding GetTextEncoding() const { return mrData.meTextEnc; }
165cdf0e10cSrcweir     /** Returns the system language, i.e. for number formats. */
GetSysLanguage() const166cdf0e10cSrcweir     inline LanguageType GetSysLanguage() const { return mrData.meSysLang; }
167cdf0e10cSrcweir     /** Returns the document language. */
GetDocLanguage() const168cdf0e10cSrcweir     inline LanguageType GetDocLanguage() const { return mrData.meDocLang; }
169cdf0e10cSrcweir     /** Returns the UI language. */
GetUILanguage() const170cdf0e10cSrcweir     inline LanguageType GetUILanguage() const { return mrData.meUILang; }
171cdf0e10cSrcweir     /** Returns the default script type, e.g. for blank cells. */
GetDefApiScript() const172cdf0e10cSrcweir     inline sal_Int16    GetDefApiScript() const { return mrData.mnDefApiScript; }
173cdf0e10cSrcweir     /** Returns the width of the '0' character (default font) for the current printer (twips). */
GetCharWidth() const174cdf0e10cSrcweir     inline long         GetCharWidth() const { return mrData.mnCharWidth; }
175cdf0e10cSrcweir     /** Returns the current Calc sheet index. */
IsInGlobals() const176cdf0e10cSrcweir     inline bool         IsInGlobals() const { return mrData.mnScTab == SCTAB_GLOBAL; }
177cdf0e10cSrcweir     /** Returns the current Calc sheet index. */
GetCurrScTab() const178cdf0e10cSrcweir     inline SCTAB        GetCurrScTab() const { return mrData.mnScTab; }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     /** Calculates the width of the passed number of pixels in 1/100 mm. */
181cdf0e10cSrcweir     sal_Int32           GetHmmFromPixelX( double fPixelX ) const;
182cdf0e10cSrcweir     /** Calculates the height of the passed number of pixels in 1/100 mm. */
183cdf0e10cSrcweir     sal_Int32           GetHmmFromPixelY( double fPixelY ) const;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     /** Returns the medium to import from. */
GetMedium() const186cdf0e10cSrcweir     inline SfxMedium&   GetMedium() const { return mrData.mrMedium; }
187cdf0e10cSrcweir     /** Returns the document URL of the imported/exported file. */
GetDocUrl() const188cdf0e10cSrcweir     inline const String& GetDocUrl() const { return mrData.maDocUrl; }
189cdf0e10cSrcweir     /** Returns the base path of the imported/exported file. */
GetBasePath() const190cdf0e10cSrcweir     inline const String& GetBasePath() const { return mrData.maBasePath; }
191cdf0e10cSrcweir     /** Returns the current user name. */
GetUserName() const192cdf0e10cSrcweir     inline const String& GetUserName() const { return mrData.maUserName; }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     /** Returns the default password used for stream encryption. */
GetDefaultPassword() const195cdf0e10cSrcweir     inline const String& GetDefaultPassword() const { return mrData.maDefPassword; }
196cdf0e10cSrcweir     /** Requests and verifies a password from the medium or the user. */
197cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
198cdf0e10cSrcweir         RequestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier ) const;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     /** Returns the OLE2 root storage of the imported/exported file.
201cdf0e10cSrcweir         @return  Pointer to root storage or 0, if the file is a simple stream. */
GetRootStorage() const202cdf0e10cSrcweir     inline SotStorageRef GetRootStorage() const { return mrData.mxRootStrg; }
203cdf0e10cSrcweir     /** Returns true, if the document contains a VBA storage. */
204cdf0e10cSrcweir     bool                HasVbaStorage() const;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     /** Tries to open a storage as child of the specified storage for reading or writing. */
207cdf0e10cSrcweir     SotStorageRef       OpenStorage( SotStorageRef xStrg, const String& rStrgName ) const;
208cdf0e10cSrcweir     /** Tries to open a storage as child of the root storage for reading or writing. */
209cdf0e10cSrcweir     SotStorageRef       OpenStorage( const String& rStrgName ) const;
210cdf0e10cSrcweir     /** Tries to open a new stream in the specified storage for reading or writing. */
211cdf0e10cSrcweir     SotStorageStreamRef OpenStream( SotStorageRef xStrg, const String& rStrmName ) const;
212cdf0e10cSrcweir     /** Tries to open a new stream in the root storage for reading or writing. */
213cdf0e10cSrcweir     SotStorageStreamRef OpenStream( const String& rStrmName ) const;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     /** Returns the destination document (import) or source document (export). */
GetDoc() const216cdf0e10cSrcweir     inline ScDocument&  GetDoc() const { return mrData.mrDoc; }
217cdf0e10cSrcweir     /** Returns pointer to the destination document (import) or source document (export). */
GetDocPtr() const218cdf0e10cSrcweir     inline ScDocument*  GetDocPtr() const { return &mrData.mrDoc; }
219cdf0e10cSrcweir     /** Returns the object shell of the Calc document. May be 0 (i.e. import from clipboard). */
220cdf0e10cSrcweir     SfxObjectShell*     GetDocShell() const;
221cdf0e10cSrcweir     /** Returns the object model of the Calc document. */
222cdf0e10cSrcweir     ScModelObj*         GetDocModelObj() const;
223cdf0e10cSrcweir     /** Returns pointer to the printer of the Calc document. */
224cdf0e10cSrcweir     OutputDevice*       GetPrinter() const;
225cdf0e10cSrcweir     /** Returns the style sheet pool of the Calc document. */
226cdf0e10cSrcweir     ScStyleSheetPool&   GetStyleSheetPool() const;
227cdf0e10cSrcweir     /** Returns the defined names container of the Calc document. */
228cdf0e10cSrcweir     ScRangeName&        GetNamedRanges() const;
229cdf0e10cSrcweir     /** Returns the database ranges container of the Calc document. */
230cdf0e10cSrcweir     ScDBCollection&     GetDatabaseRanges() const;
231cdf0e10cSrcweir     /** Returns the drawing layer page of the passed sheet, if present. */
232cdf0e10cSrcweir     SdrPage*            GetSdrPage( SCTAB nScTab ) const;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     /** Returns the number formatter of the Calc document. */
235cdf0e10cSrcweir     SvNumberFormatter&  GetFormatter() const;
236cdf0e10cSrcweir     /** Returns the null date of the current number formatter. */
237cdf0e10cSrcweir     DateTime            GetNullDate() const;
238cdf0e10cSrcweir     /** Returns the base year depending on the current null date (1900 or 1904). */
239cdf0e10cSrcweir     sal_uInt16          GetBaseYear() const;
240cdf0e10cSrcweir     /** Converts a date/time value to a floating-point value. */
241cdf0e10cSrcweir     double              GetDoubleFromDateTime( const DateTime& rDateTime ) const;
242cdf0e10cSrcweir     /** Converts a floating-point value to a date/time value. */
243cdf0e10cSrcweir     DateTime            GetDateTimeFromDouble( double fValue ) const;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     /** Returns the edit engine for import/export of rich strings etc. */
246cdf0e10cSrcweir     ScEditEngineDefaulter& GetEditEngine() const;
247cdf0e10cSrcweir     /** Returns the edit engine for import/export of headers/footers. */
248cdf0e10cSrcweir     ScHeaderEditEngine& GetHFEditEngine() const;
249cdf0e10cSrcweir     /** Returns the edit engine for import/export of drawing text boxes. */
250cdf0e10cSrcweir     EditEngine&         GetDrawEditEngine() const;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     /** Returns the property set helper for fonts. */
253cdf0e10cSrcweir     XclFontPropSetHelper& GetFontPropSetHelper() const;
254cdf0e10cSrcweir     /** Returns the property set helper for the chart filters. */
255cdf0e10cSrcweir     XclChPropSetHelper& GetChartPropSetHelper() const;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     /** Returns the extended document options. */
258cdf0e10cSrcweir     ScExtDocOptions&    GetExtDocOptions() const;
259cdf0e10cSrcweir     /** Returns the filter tracer. */
260cdf0e10cSrcweir     XclTracer&          GetTracer() const;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     /** Returns the highest possible cell address in a Calc document. */
GetScMaxPos() const263cdf0e10cSrcweir     inline const ScAddress& GetScMaxPos() const { return mrData.maScMaxPos; }
264cdf0e10cSrcweir     /** Returns the highest possible cell address in an Excel document (using current BIFF version). */
GetXclMaxPos() const265cdf0e10cSrcweir     inline const ScAddress& GetXclMaxPos() const { return mrData.maXclMaxPos; }
266cdf0e10cSrcweir     /** Returns the highest possible cell address valid in Calc and Excel (using current BIFF version). */
GetMaxPos() const267cdf0e10cSrcweir     inline const ScAddress& GetMaxPos() const { return mrData.maMaxPos; }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     /** Sets the document language. */
SetDocLanguage(LanguageType eLang)270cdf0e10cSrcweir     inline void         SetDocLanguage( LanguageType eLang ) { mrData.meDocLang = eLang; }
271cdf0e10cSrcweir     /** Sets the UI language, i.e. if it has been read from a file. */
SetUILanguage(LanguageType eLang)272cdf0e10cSrcweir     inline void         SetUILanguage( LanguageType eLang ) { mrData.meUILang = eLang; }
273cdf0e10cSrcweir     /** Sets the text encoding to import/export byte strings. */
274cdf0e10cSrcweir     void                SetTextEncoding( rtl_TextEncoding eTextEnc );
275cdf0e10cSrcweir     /** Sets the width of the '0' character (default font) for the current printer (twips).
276cdf0e10cSrcweir         @param rFontData  The font used for the '0' character. */
277cdf0e10cSrcweir     void                SetCharWidth( const XclFontData& rFontData );
278cdf0e10cSrcweir     /** Sets the current Calc sheet index. */
SetCurrScTab(SCTAB nScTab)279cdf0e10cSrcweir     inline void         SetCurrScTab( SCTAB nScTab ) { mrData.mnScTab = nScTab; }
280cdf0e10cSrcweir     /** Increases the current Calc sheet index by 1. */
IncCurrScTab()281cdf0e10cSrcweir     inline void         IncCurrScTab() { ++mrData.mnScTab; }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir private:
2847925e912SMichael Stahl     XclRootData& mrData;        /// Reference to the global data struct.
285cdf0e10cSrcweir };
286cdf0e10cSrcweir 
287cdf0e10cSrcweir // ============================================================================
288cdf0e10cSrcweir 
289cdf0e10cSrcweir #endif
290cdf0e10cSrcweir 
291