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