Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_XLROOT_HXX
30 : : #define SC_XLROOT_HXX
31 : :
32 : : #include <com/sun/star/beans/NamedValue.hpp>
33 : :
34 : : #include <i18npool/lang.h>
35 : : #include <sot/storage.hxx>
36 : : #include "xlconst.hxx"
37 : : #include "xltools.hxx"
38 : : #include <boost/shared_ptr.hpp>
39 : :
40 : : namespace comphelper { class IDocPasswordVerifier; }
41 : :
42 : : // Forward declarations of objects in public use ==============================
43 : :
44 : : class DateTime;
45 : :
46 : : struct XclAddress;
47 : : struct XclRange;
48 : :
49 : : // Global data ================================================================
50 : :
51 : : #ifdef DBG_UTIL
52 : : /** Counts the number of created root objects. */
53 : : struct XclDebugObjCounter
54 : : {
55 : : sal_Int32 mnObjCnt;
56 : : inline explicit XclDebugObjCounter() : mnObjCnt( 0 ) {}
57 : : ~XclDebugObjCounter();
58 : : };
59 : : #endif
60 : :
61 : : // ----------------------------------------------------------------------------
62 : :
63 : : class SfxMedium;
64 : : class ScEditEngineDefaulter;
65 : : class ScHeaderEditEngine;
66 : : class EditEngine;
67 : : class ScExtDocOptions;
68 : : class XclFontPropSetHelper;
69 : : class XclChPropSetHelper;
70 : : class XclTracer;
71 : :
72 : : struct RootData;//!
73 : :
74 : : /** Stores global buffers and data needed elsewhere in the Excel filters. */
75 : : struct XclRootData
76 : : #ifdef DBG_UTIL
77 : : : public XclDebugObjCounter
78 : : #endif
79 : : {
80 : : typedef boost::shared_ptr< ScEditEngineDefaulter > ScEEDefaulterRef;
81 : : typedef boost::shared_ptr< ScHeaderEditEngine > ScHeaderEERef;
82 : : typedef boost::shared_ptr< EditEngine > EditEngineRef;
83 : : typedef boost::shared_ptr< XclFontPropSetHelper > XclFontPropSetHlpRef;
84 : : typedef boost::shared_ptr< XclChPropSetHelper > XclChPropSetHlpRef;
85 : : typedef boost::shared_ptr< ScExtDocOptions > ScExtDocOptRef;
86 : : typedef boost::shared_ptr< XclTracer > XclTracerRef;
87 : : typedef boost::shared_ptr< RootData > RootDataRef;
88 : :
89 : : XclBiff meBiff; /// Current BIFF version.
90 : : XclOutput meOutput; /// Current Output format.
91 : : SfxMedium& mrMedium; /// The medium to import from.
92 : : SotStorageRef mxRootStrg; /// The root OLE storage of imported/exported file.
93 : : ScDocument& mrDoc; /// The source or destination document.
94 : : String maDocUrl; /// Document URL of imported/exported file.
95 : : String maBasePath; /// Base path of imported/exported file (path of maDocUrl).
96 : : String maUserName; /// Current user name.
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.
106 : :
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.
110 : :
111 : : XclFontPropSetHlpRef mxFontPropSetHlp; /// Property set helper for fonts.
112 : : XclChPropSetHlpRef mxChPropSetHlp; /// Property set helper for chart filter.
113 : :
114 : : ScExtDocOptRef mxExtDocOpt; /// Extended document options.
115 : : XclTracerRef mxTracer; /// Filter tracer.
116 : : RootDataRef mxRD; /// Old RootData struct. Will be removed.
117 : :
118 : : double mfScreenPixelX; /// Width of a screen pixel (1/100 mm).
119 : : double mfScreenPixelY; /// Height of a screen pixel (1/100 mm).
120 : : long mnCharWidth; /// Width of '0' in default font (twips).
121 : : SCTAB mnScTab; /// Current Calc sheet index.
122 : : const bool mbExport; /// false = Import, true = Export.
123 : :
124 : : explicit XclRootData( XclBiff eBiff, SfxMedium& rMedium,
125 : : SotStorageRef xRootStrg, ScDocument& rDoc,
126 : : rtl_TextEncoding eTextEnc, bool bExport );
127 : : virtual ~XclRootData();
128 : : };
129 : :
130 : : // ----------------------------------------------------------------------------
131 : :
132 : : class SfxObjectShell;
133 : : class ScModelObj;
134 : : class OutputDevice;
135 : : class SvNumberFormatter;
136 : : class SdrPage;
137 : : class ScStyleSheetPool;
138 : : class ScRangeName;
139 : : struct XclFontData;
140 : :
141 : : /** Access to global data for a filter object (imported or exported document) from other classes. */
142 : : class XclRoot
143 : : {
144 : : public:
145 : : explicit XclRoot( XclRootData& rRootData );
146 : : XclRoot( const XclRoot& rRoot );
147 : :
148 : : virtual ~XclRoot();
149 : :
150 : : XclRoot& operator=( const XclRoot& rRoot );
151 : :
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 : 647 : inline RootData& GetOldRoot() const { return *mrData.mxRD; }
156 : :
157 : : /** Returns the current BIFF version of the importer/exporter. */
158 : 10294 : inline XclBiff GetBiff() const { return mrData.meBiff; }
159 : : /** Returns the current output format of the importer/exporter. */
160 : 0 : inline XclOutput GetOutput() const { return mrData.meOutput; }
161 : : /** Returns true, if currently a document is imported. */
162 : 165 : 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 : 1320 : inline rtl_TextEncoding GetTextEncoding() const { return mrData.meTextEnc; }
167 : : /** Returns the system language, i.e. for number formats. */
168 : 55 : inline LanguageType GetSysLanguage() const { return mrData.meSysLang; }
169 : : /** Returns the document language. */
170 : 0 : inline LanguageType GetDocLanguage() const { return mrData.meDocLang; }
171 : : /** Returns the UI language. */
172 : 0 : inline LanguageType GetUILanguage() const { return mrData.meUILang; }
173 : : /** Returns the default script type, e.g. for blank cells. */
174 : 0 : inline sal_Int16 GetDefApiScript() const { return mrData.mnDefApiScript; }
175 : : /** Returns the width of the '0' character (default font) for the current printer (twips). */
176 : 453 : inline long GetCharWidth() const { return mrData.mnCharWidth; }
177 : : /** Returns the current Calc sheet index. */
178 : 0 : inline bool IsInGlobals() const { return mrData.mnScTab == SCTAB_GLOBAL; }
179 : : /** Returns the current Calc sheet index. */
180 : 20762 : inline SCTAB GetCurrScTab() const { return mrData.mnScTab; }
181 : :
182 : : /** Calculates the width of the passed number of pixels in 1/100 mm. */
183 : : sal_Int32 GetHmmFromPixelX( double fPixelX ) const;
184 : : /** Calculates the height of the passed number of pixels in 1/100 mm. */
185 : : sal_Int32 GetHmmFromPixelY( double fPixelY ) const;
186 : :
187 : : /** Returns the medium to import from. */
188 : 13 : inline SfxMedium& GetMedium() const { return mrData.mrMedium; }
189 : : /** Returns the document URL of the imported/exported file. */
190 : 55 : inline const String& GetDocUrl() const { return mrData.maDocUrl; }
191 : : /** Returns the base path of the imported/exported file. */
192 : 20 : inline const String& GetBasePath() const { return mrData.maBasePath; }
193 : : /** Returns the current user name. */
194 : 0 : inline const String& GetUserName() const { return mrData.maUserName; }
195 : :
196 : : /** Returns the default password used for stream encryption. */
197 : 0 : inline const String& GetDefaultPassword() const { return mrData.maDefPassword; }
198 : : /** Requests and verifies a password from the medium or the user. */
199 : : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
200 : : RequestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier ) const;
201 : :
202 : : /** Returns the OLE2 root storage of the imported/exported file.
203 : : @return Pointer to root storage or 0, if the file is a simple stream. */
204 : 146 : inline SotStorageRef GetRootStorage() const { return mrData.mxRootStrg; }
205 : : /** Returns true, if the document contains a VBA storage. */
206 : : bool HasVbaStorage() const;
207 : :
208 : : /** Tries to open a storage as child of the specified storage for reading or writing. */
209 : : SotStorageRef OpenStorage( SotStorageRef xStrg, const String& rStrgName ) const;
210 : : /** Tries to open a storage as child of the root storage for reading or writing. */
211 : : SotStorageRef OpenStorage( const String& rStrgName ) const;
212 : : /** Tries to open a new stream in the specified storage for reading or writing. */
213 : : SotStorageStreamRef OpenStream( SotStorageRef xStrg, const String& rStrmName ) const;
214 : : /** Tries to open a new stream in the root storage for reading or writing. */
215 : : SotStorageStreamRef OpenStream( const String& rStrmName ) const;
216 : :
217 : : /** Returns the destination document (import) or source document (export). */
218 : 41605 : inline ScDocument& GetDoc() const { return mrData.mrDoc; }
219 : : /** Returns pointer to the destination document (import) or source document (export). */
220 : 102 : inline ScDocument* GetDocPtr() const { return &mrData.mrDoc; }
221 : : /** Returns the object shell of the Calc document. May be 0 (i.e. import from clipboard). */
222 : : SfxObjectShell* GetDocShell() const;
223 : : /** Returns the object model of the Calc document. */
224 : : ScModelObj* GetDocModelObj() const;
225 : : /** Returns pointer to the printer of the Calc document. */
226 : : OutputDevice* GetPrinter() const;
227 : : /** Returns the style sheet pool of the Calc document. */
228 : : ScStyleSheetPool& GetStyleSheetPool() const;
229 : : /** Returns the defined names container of the Calc document. */
230 : : ScRangeName& GetNamedRanges() const;
231 : : /** Returns the drawing layer page of the passed sheet, if present. */
232 : : SdrPage* GetSdrPage( SCTAB nScTab ) const;
233 : :
234 : : /** Returns the number formatter of the Calc document. */
235 : : SvNumberFormatter& GetFormatter() const;
236 : : /** Returns the null date of the current number formatter. */
237 : : DateTime GetNullDate() const;
238 : : /** Returns the base year depending on the current null date (1900 or 1904). */
239 : : sal_uInt16 GetBaseYear() const;
240 : : /** Converts a date/time value to a floating-point value. */
241 : : double GetDoubleFromDateTime( const DateTime& rDateTime ) const;
242 : : /** Converts a floating-point value to a date/time value. */
243 : : DateTime GetDateTimeFromDouble( double fValue ) const;
244 : :
245 : : /** Returns the edit engine for import/export of rich strings etc. */
246 : : ScEditEngineDefaulter& GetEditEngine() const;
247 : : /** Returns the edit engine for import/export of headers/footers. */
248 : : ScHeaderEditEngine& GetHFEditEngine() const;
249 : : /** Returns the edit engine for import/export of drawing text boxes. */
250 : : EditEngine& GetDrawEditEngine() const;
251 : :
252 : : /** Returns the property set helper for fonts. */
253 : : XclFontPropSetHelper& GetFontPropSetHelper() const;
254 : : /** Returns the property set helper for the chart filters. */
255 : : XclChPropSetHelper& GetChartPropSetHelper() const;
256 : :
257 : : /** Returns the extended document options. */
258 : : ScExtDocOptions& GetExtDocOptions() const;
259 : : /** Returns the filter tracer. */
260 : : XclTracer& GetTracer() const;
261 : :
262 : : /** Returns the highest possible cell address in a Calc document. */
263 : 346 : inline const ScAddress& GetScMaxPos() const { return mrData.maScMaxPos; }
264 : : /** Returns the highest possible cell address in an Excel document (using current BIFF version). */
265 : 495 : inline const ScAddress& GetXclMaxPos() const { return mrData.maXclMaxPos; }
266 : : /** Returns the highest possible cell address valid in Calc and Excel (using current BIFF version). */
267 : 220 : inline const ScAddress& GetMaxPos() const { return mrData.maMaxPos; }
268 : :
269 : : /** Sets the document language. */
270 : 46 : inline void SetDocLanguage( LanguageType eLang ) { mrData.meDocLang = eLang; }
271 : : /** Sets the UI language, i.e. if it has been read from a file. */
272 : 46 : inline void SetUILanguage( LanguageType eLang ) { mrData.meUILang = eLang; }
273 : : /** Sets the text encoding to import/export byte strings. */
274 : : void SetTextEncoding( rtl_TextEncoding eTextEnc );
275 : : /** Sets the width of the '0' character (default font) for the current printer (twips).
276 : : @param rFontData The font used for the '0' character. */
277 : : void SetCharWidth( const XclFontData& rFontData );
278 : : /** Sets the current Calc sheet index. */
279 : 0 : inline void SetCurrScTab( SCTAB nScTab ) { mrData.mnScTab = nScTab; }
280 : : /** Increases the current Calc sheet index by 1. */
281 : 165 : inline void IncCurrScTab() { ++mrData.mnScTab; }
282 : :
283 : : private:
284 : : XclRootData& mrData; /// Reference to the global data struct.
285 : : };
286 : :
287 : : // ============================================================================
288 : :
289 : : #endif
290 : :
291 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|