merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / inc / xlroot.hxx
blob8b0873b25475cdd9ce242ab680e1481f7907c556
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xlroot.hxx,v $
10 * $Revision: 1.31 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XLROOT_HXX
32 #define SC_XLROOT_HXX
34 #include <i18npool/lang.h>
35 #include <sot/storage.hxx>
36 #include "xlconst.hxx"
37 #include "xltools.hxx"
39 namespace comphelper { class IDocPasswordVerifier; }
41 // Forward declarations of objects in public use ==============================
43 class DateTime;
45 struct XclAddress;
46 struct XclRange;
47 class XclRangeList;
48 class XclTokenArray;
50 // Global data ================================================================
52 #ifdef DBG_UTIL
53 /** Counts the number of created root objects. */
54 struct XclDebugObjCounter
56 sal_Int32 mnObjCnt;
57 inline explicit XclDebugObjCounter() : mnObjCnt( 0 ) {}
58 ~XclDebugObjCounter();
60 #endif
62 // ----------------------------------------------------------------------------
64 class SfxMedium;
65 class ScEditEngineDefaulter;
66 class ScHeaderEditEngine;
67 class EditEngine;
68 class ScExtDocOptions;
69 class XclFontPropSetHelper;
70 class XclChPropSetHelper;
71 class XclTracer;
73 struct RootData;//!
75 /** Stores global buffers and data needed elsewhere in the Excel filters. */
76 struct XclRootData
77 #ifdef DBG_UTIL
78 : public XclDebugObjCounter
79 #endif
81 typedef ScfRef< ScEditEngineDefaulter > ScEEDefaulterRef;
82 typedef ScfRef< ScHeaderEditEngine > ScHeaderEERef;
83 typedef ScfRef< EditEngine > EditEngineRef;
84 typedef ScfRef< XclFontPropSetHelper > XclFontPropSetHlpRef;
85 typedef ScfRef< XclChPropSetHelper > XclChPropSetHlpRef;
86 typedef ScfRef< ScExtDocOptions > ScExtDocOptRef;
87 typedef ScfRef< XclTracer > XclTracerRef;
88 typedef ScfRef< RootData > RootDataRef;
90 XclBiff meBiff; /// Current BIFF version.
91 XclOutput meOutput; /// Current Output format.
92 SfxMedium& mrMedium; /// The medium to import from.
93 SotStorageRef mxRootStrg; /// The root OLE storage of imported/exported file.
94 ScDocument& mrDoc; /// The source or destination document.
95 String maDocUrl; /// Document URL of imported/exported file.
96 String maBasePath; /// Base path of imported/exported file (path of maDocUrl).
97 String maUserName; /// Current user name.
98 const String maDefPassword; /// The default password used for stream encryption.
99 rtl_TextEncoding meTextEnc; /// Text encoding to import/export byte strings.
100 LanguageType meSysLang; /// System language.
101 LanguageType meDocLang; /// Document language (import: from file, export: from system).
102 LanguageType meUILang; /// UI language (import: from file, export: from system).
103 sal_Int16 mnDefApiScript; /// Default script type for blank cells (API constant).
104 ScAddress maScMaxPos; /// Highest Calc cell position.
105 ScAddress maXclMaxPos; /// Highest Excel cell position.
106 ScAddress maMaxPos; /// Highest position valid in Calc and Excel.
108 ScEEDefaulterRef mxEditEngine; /// Edit engine for rich strings etc.
109 ScHeaderEERef mxHFEditEngine; /// Edit engine for header/footer.
110 EditEngineRef mxDrawEditEng; /// Edit engine for text boxes.
112 XclFontPropSetHlpRef mxFontPropSetHlp; /// Property set helper for fonts.
113 XclChPropSetHlpRef mxChPropSetHlp; /// Property set helper for chart filter.
115 ScExtDocOptRef mxExtDocOpt; /// Extended document options.
116 XclTracerRef mxTracer; /// Filter tracer.
117 RootDataRef mxRD; /// Old RootData struct. Will be removed.
119 long mnCharWidth; /// Width of '0' in default font (twips).
120 SCTAB mnScTab; /// Current Calc sheet index.
121 const bool mbExport; /// false = Import, true = Export.
123 explicit XclRootData( XclBiff eBiff, SfxMedium& rMedium,
124 SotStorageRef xRootStrg, ScDocument& rDoc,
125 rtl_TextEncoding eTextEnc, bool bExport );
126 virtual ~XclRootData();
129 // ----------------------------------------------------------------------------
131 class SfxObjectShell;
132 class ScModelObj;
133 class OutputDevice;
134 class SvNumberFormatter;
135 class SdrPage;
136 class ScDocumentPool;
137 class ScStyleSheetPool;
138 class ScRangeName;
139 class ScDBCollection;
140 struct XclFontData;
142 /** Access to global data for a filter object (imported or exported document) from other classes. */
143 class XclRoot
145 public:
146 explicit XclRoot( XclRootData& rRootData );
147 XclRoot( const XclRoot& rRoot );
149 virtual ~XclRoot();
151 XclRoot& operator=( const XclRoot& rRoot );
153 /** Returns this root instance - for code readability in derived classes. */
154 inline const XclRoot& GetRoot() const { return *this; }
155 /** Returns old RootData struct. Deprecated. */
156 inline RootData& GetOldRoot() const { return *mrData.mxRD; }
158 /** Returns the current BIFF version of the importer/exporter. */
159 inline XclBiff GetBiff() const { return mrData.meBiff; }
160 /** Returns the current output format of the importer/exporter. */
161 inline XclOutput GetOutput() const { return mrData.meOutput; }
162 /** Returns true, if currently a document is imported. */
163 inline bool IsImport() const { return !mrData.mbExport; }
164 /** Returns true, if currently a document is exported. */
165 inline bool IsExport() const { return mrData.mbExport; }
166 /** Returns the text encoding to import/export byte strings. */
167 inline rtl_TextEncoding GetTextEncoding() const { return mrData.meTextEnc; }
168 /** Returns the system language, i.e. for number formats. */
169 inline LanguageType GetSysLanguage() const { return mrData.meSysLang; }
170 /** Returns the document language. */
171 inline LanguageType GetDocLanguage() const { return mrData.meDocLang; }
172 /** Returns the UI language. */
173 inline LanguageType GetUILanguage() const { return mrData.meUILang; }
174 /** Returns the default script type, e.g. for blank cells. */
175 inline sal_Int16 GetDefApiScript() const { return mrData.mnDefApiScript; }
176 /** Returns the width of the '0' character (default font) for the current printer (twips). */
177 inline long GetCharWidth() const { return mrData.mnCharWidth; }
178 /** Returns the current Calc sheet index. */
179 inline bool IsInGlobals() const { return mrData.mnScTab == SCTAB_GLOBAL; }
180 /** Returns the current Calc sheet index. */
181 inline SCTAB GetCurrScTab() const { return mrData.mnScTab; }
183 /** Returns the medium to import from. */
184 inline SfxMedium& GetMedium() const { return mrData.mrMedium; }
185 /** Returns the document URL of the imported/exported file. */
186 inline const String& GetDocUrl() const { return mrData.maDocUrl; }
187 /** Returns the base path of the imported/exported file. */
188 inline const String& GetBasePath() const { return mrData.maBasePath; }
189 /** Returns the current user name. */
190 inline const String& GetUserName() const { return mrData.maUserName; }
192 /** Returns the default password used for stream encryption. */
193 inline const String& GetDefaultPassword() const { return mrData.maDefPassword; }
194 /** Requests and verifies a password from the medium or the user. */
195 String RequestPassword( ::comphelper::IDocPasswordVerifier& rVerifier ) const;
197 /** Returns the OLE2 root storage of the imported/exported file.
198 @return Pointer to root storage or 0, if the file is a simple stream. */
199 inline SotStorageRef GetRootStorage() const { return mrData.mxRootStrg; }
200 /** Returns true, if the document contains a VBA storage. */
201 bool HasVbaStorage() const;
203 /** Tries to open a storage as child of the specified storage for reading or writing. */
204 SotStorageRef OpenStorage( SotStorageRef xStrg, const String& rStrgName ) const;
205 /** Tries to open a storage as child of the root storage for reading or writing. */
206 SotStorageRef OpenStorage( const String& rStrgName ) const;
207 /** Tries to open a new stream in the specified storage for reading or writing. */
208 SotStorageStreamRef OpenStream( SotStorageRef xStrg, const String& rStrmName ) const;
209 /** Tries to open a new stream in the root storage for reading or writing. */
210 SotStorageStreamRef OpenStream( const String& rStrmName ) const;
212 /** Returns the destination document (import) or source document (export). */
213 inline ScDocument& GetDoc() const { return mrData.mrDoc; }
214 /** Returns pointer to the destination document (import) or source document (export). */
215 inline ScDocument* GetDocPtr() const { return &mrData.mrDoc; }
216 /** Returns the object shell of the Calc document. May be 0 (i.e. import from clipboard). */
217 SfxObjectShell* GetDocShell() const;
218 /** Returns the object model of the Calc document. */
219 ScModelObj* GetDocModelObj() const;
220 /** Returns pointer to the printer of the Calc document. */
221 OutputDevice* GetPrinter() const;
222 /** Returns the style sheet pool of the Calc document. */
223 ScStyleSheetPool& GetStyleSheetPool() const;
224 /** Returns the defined names container of the Calc document. */
225 ScRangeName& GetNamedRanges() const;
226 /** Returns the database ranges container of the Calc document. */
227 ScDBCollection& GetDatabaseRanges() const;
228 /** Returns the drawing layer page of the passed sheet, if present. */
229 SdrPage* GetSdrPage( SCTAB nScTab ) const;
231 /** Returns the number formatter of the Calc document. */
232 SvNumberFormatter& GetFormatter() const;
233 /** Returns the null date of the current number formatter. */
234 DateTime GetNullDate() const;
235 /** Converts a date/time value to a floating-point value. */
236 double GetDoubleFromDateTime( const DateTime& rDateTime ) const;
237 /** Converts a floating-point value to a date/time value. */
238 DateTime GetDateTimeFromDouble( double fValue ) const;
240 /** Returns the edit engine for import/export of rich strings etc. */
241 ScEditEngineDefaulter& GetEditEngine() const;
242 /** Returns the edit engine for import/export of headers/footers. */
243 ScHeaderEditEngine& GetHFEditEngine() const;
244 /** Returns the edit engine for import/export of drawing text boxes. */
245 EditEngine& GetDrawEditEngine() const;
247 /** Returns the property set helper for fonts. */
248 XclFontPropSetHelper& GetFontPropSetHelper() const;
249 /** Returns the property set helper for the chart filters. */
250 XclChPropSetHelper& GetChartPropSetHelper() const;
252 /** Returns the extended document options. */
253 ScExtDocOptions& GetExtDocOptions() const;
254 /** Returns the filter tracer. */
255 XclTracer& GetTracer() const;
257 /** Returns the highest possible cell address in a Calc document. */
258 inline const ScAddress& GetScMaxPos() const { return mrData.maScMaxPos; }
259 /** Returns the highest possible cell address in an Excel document (using current BIFF version). */
260 inline const ScAddress& GetXclMaxPos() const { return mrData.maXclMaxPos; }
261 /** Returns the highest possible cell address valid in Calc and Excel (using current BIFF version). */
262 inline const ScAddress& GetMaxPos() const { return mrData.maMaxPos; }
264 /** Sets the document language. */
265 inline void SetDocLanguage( LanguageType eLang ) { mrData.meDocLang = eLang; }
266 /** Sets the UI language, i.e. if it has been read from a file. */
267 inline void SetUILanguage( LanguageType eLang ) { mrData.meUILang = eLang; }
268 /** Sets the text encoding to import/export byte strings. */
269 void SetTextEncoding( rtl_TextEncoding eTextEnc );
270 /** Sets the width of the '0' character (default font) for the current printer (twips).
271 @param rFontData The font used for the '0' character. */
272 void SetCharWidth( const XclFontData& rFontData );
273 /** Sets the current Calc sheet index. */
274 inline void SetCurrScTab( SCTAB nScTab ) { mrData.mnScTab = nScTab; }
275 /** Increases the current Calc sheet index by 1. */
276 inline void IncCurrScTab() { ++mrData.mnScTab; }
278 private:
279 mutable XclRootData& mrData; /// Reference to the global data struct.
282 // ============================================================================
284 #endif