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