1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <i18nlangtag/lang.h>
23 #include <rtl/ref.hxx>
24 #include <tools/long.hxx>
25 #include "xlconst.hxx"
28 namespace com::sun::star::beans
{ struct NamedValue
; }
29 namespace comphelper
{ class IDocPasswordVerifier
; }
31 // Forward declarations of objects in public use ==============================
36 class SotStorageStream
;
39 // Global data ================================================================
42 /** Counts the number of created root objects. */
43 struct XclDebugObjCounter
46 explicit XclDebugObjCounter() : mnObjCnt( 0 ) {}
47 ~XclDebugObjCounter();
52 class ScEditEngineDefaulter
;
53 class ScHeaderEditEngine
;
55 class ScExtDocOptions
;
56 class XclFontPropSetHelper
;
57 class XclChPropSetHelper
;
62 /** Stores global buffers and data needed elsewhere in the Excel filters. */
65 : public XclDebugObjCounter
68 typedef std::shared_ptr
< ScEditEngineDefaulter
> ScEEDefaulterRef
;
69 typedef std::shared_ptr
< ScHeaderEditEngine
> ScHeaderEERef
;
70 typedef std::shared_ptr
< EditEngine
> EditEngineRef
;
71 typedef std::shared_ptr
< XclFontPropSetHelper
> XclFontPropSetHlpRef
;
72 typedef std::shared_ptr
< XclChPropSetHelper
> XclChPropSetHlpRef
;
73 typedef std::shared_ptr
< ScExtDocOptions
> ScExtDocOptRef
;
74 typedef std::shared_ptr
< XclTracer
> XclTracerRef
;
75 typedef std::shared_ptr
< RootData
> RootDataRef
;
77 XclBiff meBiff
; /// Current BIFF version.
78 XclOutput meOutput
; /// Current Output format.
79 SfxMedium
& mrMedium
; /// The medium to import from.
80 rtl::Reference
<SotStorage
> mxRootStrg
; /// The root OLE storage of imported/exported file.
81 ScDocument
& mrDoc
; /// The source or destination document.
82 OUString maDocUrl
; /// Document URL of imported/exported file.
83 OUString maBasePath
; /// Base path of imported/exported file (path of maDocUrl).
84 OUString maUserName
; /// Current user name.
85 static constexpr OUString gaDefPassword
= u
"VelvetSweatshop"_ustr
; /// The default password used for stream encryption.
86 rtl_TextEncoding meTextEnc
; /// Text encoding to import/export byte strings.
87 LanguageType meSysLang
; /// System language.
88 LanguageType meDocLang
; /// Document language (import: from file, export: from system).
89 LanguageType meUILang
; /// UI language (import: from file, export: from system).
90 sal_Int16 mnDefApiScript
; /// Default script type for blank cells (API constant).
91 ScAddress maScMaxPos
; /// Highest Calc cell position.
92 ScAddress maXclMaxPos
; /// Highest Excel cell position.
93 ScAddress maMaxPos
; /// Highest position valid in Calc and Excel.
95 ScEEDefaulterRef mxEditEngine
; /// Edit engine for rich strings etc.
96 ScHeaderEERef mxHFEditEngine
; /// Edit engine for header/footer.
97 EditEngineRef mxDrawEditEng
; /// Edit engine for text boxes.
99 XclFontPropSetHlpRef mxFontPropSetHlp
; /// Property set helper for fonts.
100 XclChPropSetHlpRef mxChPropSetHlp
; /// Property set helper for chart filter.
102 ScExtDocOptRef mxExtDocOpt
; /// Extended document options.
103 XclTracerRef mxTracer
; /// Filter tracer.
104 RootDataRef mxRD
; /// Old RootData struct. Will be removed.
106 double mfScreenPixelX
; /// Width of a screen pixel (1/100 mm).
107 double mfScreenPixelY
; /// Height of a screen pixel (1/100 mm).
108 tools::Long mnCharWidth
; /// Width of '0' in default font (twips).
109 tools::Long mnSpaceWidth
; /// Width of space char ' ' using default font.
110 SCTAB mnScTab
; /// Current Calc sheet index.
111 const bool mbExport
; /// false = Import, true = Export.
113 explicit XclRootData( XclBiff eBiff
, SfxMedium
& rMedium
,
114 rtl::Reference
<SotStorage
> xRootStrg
, ScDocument
& rDoc
,
115 rtl_TextEncoding eTextEnc
, bool bExport
);
116 virtual ~XclRootData();
119 class SfxObjectShell
;
122 class SvNumberFormatter
;
124 class ScStyleSheetPool
;
128 /** Access to global data for a filter object (imported or exported document) from other classes. */
132 explicit XclRoot( XclRootData
& rRootData
);
133 XclRoot( const XclRoot
& rRoot
);
137 XclRoot
& operator=( const XclRoot
& rRoot
);
139 /** Returns old RootData struct. Deprecated. */
140 RootData
& GetOldRoot() const { return *mrData
.mxRD
; }
142 /** Returns the current BIFF version of the importer/exporter. */
143 XclBiff
GetBiff() const { return mrData
.meBiff
; }
144 /** Returns the current output format of the importer/exporter. */
145 XclOutput
GetOutput() const { return mrData
.meOutput
; }
146 /** Returns true, if currently a document is imported. */
147 bool IsImport() const { return !mrData
.mbExport
; }
148 /** Returns the text encoding to import/export byte strings. */
149 rtl_TextEncoding
GetTextEncoding() const { return mrData
.meTextEnc
; }
150 /** Returns the system language, i.e. for number formats. */
151 LanguageType
GetSysLanguage() const { return mrData
.meSysLang
; }
152 /** Returns the document language. */
153 LanguageType
GetDocLanguage() const { return mrData
.meDocLang
; }
154 /** Returns the UI language. */
155 LanguageType
GetUILanguage() const { return mrData
.meUILang
; }
156 /** Returns the default script type, e.g. for blank cells. */
157 sal_Int16
GetDefApiScript() const { return mrData
.mnDefApiScript
; }
158 /** Returns the width of the '0' character (default font) for the current printer (twips). */
159 tools::Long
GetCharWidth() const { return mrData
.mnCharWidth
; }
160 tools::Long
GetSpaceWidth() const { return mrData
.mnSpaceWidth
; }
161 /** Returns the current Calc sheet index. */
162 bool IsInGlobals() const { return mrData
.mnScTab
== SCTAB_GLOBAL
; }
163 /** Returns the current Calc sheet index. */
164 SCTAB
GetCurrScTab() const { return mrData
.mnScTab
; }
166 /** Calculates the width of the passed number of pixels in 1/100 mm. */
167 sal_Int32
GetHmmFromPixelX( double fPixelX
) const;
168 /** Calculates the height of the passed number of pixels in 1/100 mm. */
169 sal_Int32
GetHmmFromPixelY( double fPixelY
) const;
171 /** Returns the medium to import from. */
172 SfxMedium
& GetMedium() const { return mrData
.mrMedium
; }
173 /** Returns the document URL of the imported/exported file. */
174 const OUString
& GetDocUrl() const { return mrData
.maDocUrl
; }
175 /** Returns the base path of the imported/exported file. */
176 const OUString
& GetBasePath() const { return mrData
.maBasePath
; }
177 /** Returns the current user name. */
178 const OUString
& GetUserName() const { return mrData
.maUserName
; }
180 /** Returns the default password used for stream encryption. */
181 static const OUString
& GetDefaultPassword() { return XclRootData::gaDefPassword
; }
182 /** Requests and verifies a password from the medium or the user. */
183 css::uno::Sequence
< css::beans::NamedValue
>
184 RequestEncryptionData( ::comphelper::IDocPasswordVerifier
& rVerifier
) const;
186 /** Returns the OLE2 root storage of the imported/exported file.
187 @return Pointer to root storage or 0, if the file is a simple stream. */
188 const rtl::Reference
<SotStorage
>& GetRootStorage() const { return mrData
.mxRootStrg
; }
189 /** Returns true, if the document contains a VBA storage. */
190 bool HasVbaStorage() const;
192 /** Tries to open a storage as child of the specified storage for reading or writing. */
193 rtl::Reference
<SotStorage
> OpenStorage( rtl::Reference
<SotStorage
> const & xStrg
, const OUString
& rStrgName
) const;
194 /** Tries to open a storage as child of the root storage for reading or writing. */
195 rtl::Reference
<SotStorage
> OpenStorage(const OUString
& rStrgName
) const;
196 /** Tries to open a new stream in the specified storage for reading or writing. */
197 rtl::Reference
<SotStorageStream
> OpenStream( rtl::Reference
<SotStorage
> const & xStrg
, const OUString
& rStrmName
) const;
198 /** Tries to open a new stream in the root storage for reading or writing. */
199 rtl::Reference
<SotStorageStream
> OpenStream(const OUString
& rStrmName
) const;
201 /** Returns reference to the destination document (import) or source document (export). */
202 ScDocument
& GetDoc() const { return mrData
.mrDoc
; }
204 /** Returns the object shell of the Calc document. May be 0 (i.e. import from clipboard). */
205 ScDocShell
* GetDocShell() const;
206 /** Returns the object model of the Calc document. */
207 ScModelObj
* GetDocModelObj() const;
208 /** Returns pointer to the printer of the Calc document. */
209 OutputDevice
* GetPrinter(bool bForceVirtDev
= false) const;
210 /** Returns the style sheet pool of the Calc document. */
211 ScStyleSheetPool
& GetStyleSheetPool() const;
212 /** Returns the defined names container of the Calc document. */
213 ScRangeName
& GetNamedRanges() const;
214 /** Returns the drawing layer page of the passed sheet, if present. */
215 SdrPage
* GetSdrPage( SCTAB nScTab
) const;
217 /** Returns the number formatter of the Calc document. */
218 SvNumberFormatter
& GetFormatter() const;
219 /** Returns the null date of the current number formatter. */
220 const Date
& GetNullDate() const;
221 /** Returns the base year depending on the current null date (1900 or 1904). */
222 sal_uInt16
GetBaseYear() const;
223 /** Converts a date/time value to a floating-point value. */
224 double GetDoubleFromDateTime( const DateTime
& rDateTime
) const;
225 /** Converts a floating-point value to a date/time value. */
226 DateTime
GetDateTimeFromDouble( double fValue
) const;
228 /** Returns the edit engine for import/export of rich strings etc. */
229 ScEditEngineDefaulter
& GetEditEngine() const;
230 /** Returns the edit engine for import/export of headers/footers. */
231 ScHeaderEditEngine
& GetHFEditEngine() const;
232 /** Returns the edit engine for import/export of drawing text boxes. */
233 EditEngine
& GetDrawEditEngine() const;
235 /** Returns the property set helper for fonts. */
236 XclFontPropSetHelper
& GetFontPropSetHelper() const;
237 /** Returns the property set helper for the chart filters. */
238 XclChPropSetHelper
& GetChartPropSetHelper() const;
240 /** Returns the extended document options. */
241 ScExtDocOptions
& GetExtDocOptions() const;
242 /** Returns the filter tracer. */
243 XclTracer
& GetTracer() const;
245 /** Returns the highest possible cell address in a Calc document. */
246 const ScAddress
& GetScMaxPos() const { return mrData
.maScMaxPos
; }
247 /** Returns the highest possible cell address in an Excel document (using current BIFF version). */
248 const ScAddress
& GetXclMaxPos() const { return mrData
.maXclMaxPos
; }
249 /** Returns the highest possible cell address valid in Calc and Excel (using current BIFF version). */
250 const ScAddress
& GetMaxPos() const { return mrData
.maMaxPos
; }
252 /** Sets the document language. */
253 void SetDocLanguage( LanguageType eLang
) { mrData
.meDocLang
= eLang
; }
254 /** Sets the UI language, i.e. if it has been read from a file. */
255 void SetUILanguage( LanguageType eLang
) { mrData
.meUILang
= eLang
; }
256 /** Sets the text encoding to import/export byte strings. */
257 void SetTextEncoding( rtl_TextEncoding eTextEnc
);
258 /** Sets the width of the '0' - '9' digit character as well as the ' ' space char
259 (using the default font) for the current printer (twips).
260 @param rFontData The font used for the '0' character. */
261 void SetCharWidth( const XclFontData
& rFontData
);
262 /** Sets the current Calc sheet index. */
263 void SetCurrScTab( SCTAB nScTab
) { mrData
.mnScTab
= nScTab
; }
264 /** Increases the current Calc sheet index by 1. */
265 void IncCurrScTab() { ++mrData
.mnScTab
; }
268 XclRootData
& mrData
; /// Reference to the global data struct.
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */