update dev300-m58
[ooovba.git] / sc / source / filter / inc / xlroot.hxx
blob8571dafcbc749027b71ec9aac9f6b93f18e39ea8
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 const String maDefPassword; /// The default password used for stream encryption.
98 rtl_TextEncoding meTextEnc; /// Text encoding to import/export byte strings.
99 LanguageType meSysLang; /// System language.
100 LanguageType meDocLang; /// Document language (import: from file, export: from system).
101 LanguageType meUILang; /// UI language (import: from file, export: from system).
102 sal_Int16 mnDefApiScript; /// Default script type for blank cells (API constant).
103 ScAddress maScMaxPos; /// Highest Calc cell position.
104 ScAddress maXclMaxPos; /// Highest Excel cell position.
105 ScAddress maMaxPos; /// Highest position valid in Calc and Excel.
107 ScEEDefaulterRef mxEditEngine; /// Edit engine for rich strings etc.
108 ScHeaderEERef mxHFEditEngine; /// Edit engine for header/footer.
109 EditEngineRef mxDrawEditEng; /// Edit engine for text boxes.
111 XclFontPropSetHlpRef mxFontPropSetHlp; /// Property set helper for fonts.
112 XclChPropSetHlpRef mxChPropSetHlp; /// Property set helper for chart filter.
114 ScExtDocOptRef mxExtDocOpt; /// Extended document options.
115 XclTracerRef mxTracer; /// Filter tracer.
116 RootDataRef mxRD; /// Old RootData struct. Will be removed.
118 long mnCharWidth; /// Width of '0' in default font (twips).
119 SCTAB mnScTab; /// Current Calc sheet index.
120 const bool mbExport; /// false = Import, true = Export.
122 explicit XclRootData( XclBiff eBiff, SfxMedium& rMedium,
123 SotStorageRef xRootStrg, ScDocument& rDoc,
124 rtl_TextEncoding eTextEnc, bool bExport );
125 virtual ~XclRootData();
128 // ----------------------------------------------------------------------------
130 class SfxObjectShell;
131 class ScModelObj;
132 class OutputDevice;
133 class SvNumberFormatter;
134 class SdrPage;
135 class ScDocumentPool;
136 class ScStyleSheetPool;
137 class ScRangeName;
138 class ScDBCollection;
139 struct XclFontData;
141 /** Access to global data for a filter object (imported or exported document) from other classes. */
142 class XclRoot
144 public:
145 explicit XclRoot( XclRootData& rRootData );
146 XclRoot( const XclRoot& rRoot );
148 virtual ~XclRoot();
150 XclRoot& operator=( const XclRoot& rRoot );
152 /** Returns this root instance - for code readability in derived classes. */
153 inline const XclRoot& GetRoot() const { return *this; }
154 /** Returns old RootData struct. Deprecated. */
155 inline RootData& GetOldRoot() const { return *mrData.mxRD; }
157 /** Returns the current BIFF version of the importer/exporter. */
158 inline XclBiff GetBiff() const { return mrData.meBiff; }
159 /** Returns the current output format of the importer/exporter. */
160 inline XclOutput GetOutput() const { return mrData.meOutput; }
161 /** Returns true, if currently a document is imported. */
162 inline bool IsImport() const { return !mrData.mbExport; }
163 /** Returns true, if currently a document is exported. */
164 inline bool IsExport() const { return mrData.mbExport; }
165 /** Returns the text encoding to import/export byte strings. */
166 inline rtl_TextEncoding GetTextEncoding() const { return mrData.meTextEnc; }
167 /** Returns the system language, i.e. for number formats. */
168 inline LanguageType GetSysLanguage() const { return mrData.meSysLang; }
169 /** Returns the document language. */
170 inline LanguageType GetDocLanguage() const { return mrData.meDocLang; }
171 /** Returns the UI language. */
172 inline LanguageType GetUILanguage() const { return mrData.meUILang; }
173 /** Returns the default script type, e.g. for blank cells. */
174 inline sal_Int16 GetDefApiScript() const { return mrData.mnDefApiScript; }
175 /** Returns the width of the '0' character (default font) for the current printer (twips). */
176 inline long GetCharWidth() const { return mrData.mnCharWidth; }
177 /** Returns the current Calc sheet index. */
178 inline bool IsInGlobals() const { return mrData.mnScTab == SCTAB_GLOBAL; }
179 /** Returns the current Calc sheet index. */
180 inline SCTAB GetCurrScTab() const { return mrData.mnScTab; }
182 /** Returns the medium to import from. */
183 inline SfxMedium& GetMedium() const { return mrData.mrMedium; }
184 /** Returns the document URL of the imported/exported file. */
185 inline const String& GetDocUrl() const { return mrData.maDocUrl; }
186 /** Returns the base path of the imported/exported file. */
187 inline const String& GetBasePath() const { return mrData.maBasePath; }
189 /** Returns the default password used for stream encryption. */
190 inline const String& GetDefaultPassword() const { return mrData.maDefPassword; }
191 /** Requests and verifies a password from the medium or the user. */
192 String RequestPassword( ::comphelper::IDocPasswordVerifier& rVerifier ) const;
194 /** Returns the OLE2 root storage of the imported/exported file.
195 @return Pointer to root storage or 0, if the file is a simple stream. */
196 inline SotStorageRef GetRootStorage() const { return mrData.mxRootStrg; }
197 /** Returns true, if the document contains a VBA storage. */
198 bool HasVbaStorage() const;
200 /** Tries to open a storage as child of the specified storage for reading or writing. */
201 SotStorageRef OpenStorage( SotStorageRef xStrg, const String& rStrgName ) const;
202 /** Tries to open a storage as child of the root storage for reading or writing. */
203 SotStorageRef OpenStorage( const String& rStrgName ) const;
204 /** Tries to open a new stream in the specified storage for reading or writing. */
205 SotStorageStreamRef OpenStream( SotStorageRef xStrg, const String& rStrmName ) const;
206 /** Tries to open a new stream in the root storage for reading or writing. */
207 SotStorageStreamRef OpenStream( const String& rStrmName ) const;
209 /** Returns the destination document (import) or source document (export). */
210 inline ScDocument& GetDoc() const { return mrData.mrDoc; }
211 /** Returns pointer to the destination document (import) or source document (export). */
212 inline ScDocument* GetDocPtr() const { return &mrData.mrDoc; }
213 /** Returns the object shell of the Calc document. May be 0 (i.e. import from clipboard). */
214 SfxObjectShell* GetDocShell() const;
215 /** Returns the object model of the Calc document. */
216 ScModelObj* GetDocModelObj() const;
217 /** Returns pointer to the printer of the Calc document. */
218 OutputDevice* GetPrinter() const;
219 /** Returns the style sheet pool of the Calc document. */
220 ScStyleSheetPool& GetStyleSheetPool() const;
221 /** Returns the defined names container of the Calc document. */
222 ScRangeName& GetNamedRanges() const;
223 /** Returns the database ranges container of the Calc document. */
224 ScDBCollection& GetDatabaseRanges() const;
225 /** Returns the drawing layer page of the passed sheet, if present. */
226 SdrPage* GetSdrPage( SCTAB nScTab ) const;
228 /** Returns the number formatter of the Calc document. */
229 SvNumberFormatter& GetFormatter() const;
230 /** Returns the null date of the current number formatter. */
231 DateTime GetNullDate() const;
232 /** Converts a date/time value to a floating-point value. */
233 double GetDoubleFromDateTime( const DateTime& rDateTime ) const;
234 /** Converts a floating-point value to a date/time value. */
235 DateTime GetDateTimeFromDouble( double fValue ) const;
237 /** Returns the edit engine for import/export of rich strings etc. */
238 ScEditEngineDefaulter& GetEditEngine() const;
239 /** Returns the edit engine for import/export of headers/footers. */
240 ScHeaderEditEngine& GetHFEditEngine() const;
241 /** Returns the edit engine for import/export of drawing text boxes. */
242 EditEngine& GetDrawEditEngine() const;
244 /** Returns the property set helper for fonts. */
245 XclFontPropSetHelper& GetFontPropSetHelper() const;
246 /** Returns the property set helper for the chart filters. */
247 XclChPropSetHelper& GetChartPropSetHelper() const;
249 /** Returns the extended document options. */
250 ScExtDocOptions& GetExtDocOptions() const;
251 /** Returns the filter tracer. */
252 XclTracer& GetTracer() const;
254 /** Returns the highest possible cell address in a Calc document. */
255 inline const ScAddress& GetScMaxPos() const { return mrData.maScMaxPos; }
256 /** Returns the highest possible cell address in an Excel document (using current BIFF version). */
257 inline const ScAddress& GetXclMaxPos() const { return mrData.maXclMaxPos; }
258 /** Returns the highest possible cell address valid in Calc and Excel (using current BIFF version). */
259 inline const ScAddress& GetMaxPos() const { return mrData.maMaxPos; }
261 /** Sets the document language. */
262 inline void SetDocLanguage( LanguageType eLang ) { mrData.meDocLang = eLang; }
263 /** Sets the UI language, i.e. if it has been read from a file. */
264 inline void SetUILanguage( LanguageType eLang ) { mrData.meUILang = eLang; }
265 /** Sets the text encoding to import/export byte strings. */
266 void SetTextEncoding( rtl_TextEncoding eTextEnc );
267 /** Sets the width of the '0' character (default font) for the current printer (twips).
268 @param rFontData The font used for the '0' character. */
269 void SetCharWidth( const XclFontData& rFontData );
270 /** Sets the current Calc sheet index. */
271 inline void SetCurrScTab( SCTAB nScTab ) { mrData.mnScTab = nScTab; }
272 /** Increases the current Calc sheet index by 1. */
273 inline void IncCurrScTab() { ++mrData.mnScTab; }
275 private:
276 mutable XclRootData& mrData; /// Reference to the global data struct.
279 // ============================================================================
281 #endif