Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / xltools.hxx
blob212d9e46fb40837b725ab7d53d5acc5a03b86c8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_XLTOOLS_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XLTOOLS_HXX
23 #include <types.hxx>
24 #include "ftools.hxx"
26 class SfxObjectShell;
27 enum class FormulaError : sal_uInt16;
29 // BIFF versions ==============================================================
31 #define DBG_ERROR_BIFF() OSL_FAIL( "Unknown BIFF type!" )
32 #define OSL_ENSURE_BIFF( c ) OSL_ENSURE( c, "Unknown BIFF type!" )
34 // Enumerations ===============================================================
36 /** An enumeration for all Excel error codes and the values true and false. */
37 enum XclBoolError
39 xlErrNull, /// The error code #NULL!
40 xlErrDiv0, /// The error code #DIV/0!
41 xlErrValue, /// The error code #VALUE!
42 xlErrRef, /// The error code #REF!
43 xlErrName, /// The error code #NAME?
44 xlErrNum, /// The error code #NUM!
45 xlErrNA, /// The error code #N/A!
46 xlErrTrue, /// The Boolean value true.
47 xlErrFalse, /// The Boolean value false.
48 xlErrUnknown /// For unknown codes and values.
51 // GUID import/export =========================================================
53 class XclImpStream;
54 class XclExpStream;
56 /** This struct stores a GUID (class ID) and supports reading, writing and comparison. */
57 struct XclGuid
59 sal_uInt8 mpnData[ 16 ]; /// Stores GUID always in little endian.
61 explicit XclGuid();
62 explicit XclGuid(
63 sal_uInt32 nData1,
64 sal_uInt16 nData2, sal_uInt16 nData3,
65 sal_uInt8 nData41, sal_uInt8 nData42,
66 sal_uInt8 nData43, sal_uInt8 nData44,
67 sal_uInt8 nData45, sal_uInt8 nData46,
68 sal_uInt8 nData47, sal_uInt8 nData48 );
71 bool operator==( const XclGuid& rCmp1, const XclGuid& rCmp2 );
73 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
74 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
76 // Excel Tools ================================================================
78 /** This class contains static helper methods for the Excel import and export filters. */
79 class XclTools
81 public:
82 // noncopyable nonconstructable -------------------------------------------
84 XclTools(const XclTools&) = delete;
85 const XclTools& operator=(const XclTools&) = delete;
86 /** We don't want anybody to instantiate this class, since it is just a
87 collection of static items. */
88 XclTools() = delete;
91 // GUID's -----------------------------------------------------------------
93 static const XclGuid maGuidStdLink; /// GUID of StdLink (HLINK record).
94 static const XclGuid maGuidUrlMoniker; /// GUID of URL moniker (HLINK record).
95 static const XclGuid maGuidFileMoniker; /// GUID of file moniker (HLINK record).
97 // numeric conversion -----------------------------------------------------
99 /** Calculates the double value from an RK value (encoded integer or double). */
100 static double GetDoubleFromRK( sal_Int32 nRKValue );
101 /** Calculates an RK value (encoded integer or double) from a double value.
102 @param rnRKValue Returns the calculated RK value.
103 @param fValue The double value.
104 @return true = An RK value could be created. */
105 static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
107 /** Calculates an angle (in 1/100 of degrees) from an Excel angle value.
108 @param nRotForStacked This value will be returned, if nXclRot contains 'stacked'. */
109 static sal_Int32 GetScRotation( sal_uInt16 nXclRot, sal_Int32 nRotForStacked );
110 /** Calculates the Excel angle value from an angle in 1/100 of degrees. */
111 static sal_uInt8 GetXclRotation( sal_Int32 nScRot );
113 /** Calculates BIFF8 rotation angle from BIFF2-BIFF5 text orientation. */
114 static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
115 /** Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle. */
116 static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
118 /** Converts a Calc error code to an Excel error code. */
119 static sal_uInt8 GetXclErrorCode( FormulaError nScError );
120 /** Converts an Excel error code to a Calc error code. */
121 static FormulaError GetScErrorCode( sal_uInt8 nXclError );
123 /** Converts the passed BIFF error to a double containing the respective Calc error code. */
124 static double ErrorToDouble( sal_uInt8 nXclError );
125 /** Gets a translated error code or Boolean value from Excel error codes.
126 @param rfDblValue Returns 0.0 for error codes or the value of a Boolean (0.0 or 1.0).
127 @param bErrorOrBool false = nError is a Boolean value; true = is an error value.
128 @param nValue The error code or Boolean value. */
129 static XclBoolError ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uInt8 nValue );
131 /** Returns the length in twips calculated from a length in inches. */
132 static sal_uInt16 GetTwipsFromInch( double fInches );
133 /** Returns the length in twips calculated from a length in 1/100 mm. */
134 static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
136 /** Returns the length in inches calculated from a length in twips. */
137 static double GetInchFromTwips( sal_Int32 nTwips );
138 /** Returns the length in inches calculated from a length in 1/100 mm. */
139 static double GetInchFromHmm( sal_Int32 nHmm );
141 /** Returns the length in 1/100 mm calculated from a length in inches. */
142 static sal_Int32 GetHmmFromInch( double fInches );
143 /** Returns the length in 1/100 mm calculated from a length in twips. */
144 static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
146 /** Returns the Calc column width (twips) for the passed Excel width.
147 * Excel Column width is stored as 1/256th of a character.
148 @param nScCharWidth Width of the '0' character in Calc (twips). */
149 static sal_uInt16 GetScColumnWidth( sal_uInt16 nXclWidth, long nScCharWidth );
150 /** Returns the Excel column width for the passed Calc width (twips).
151 @param nScCharWidth Width of the '0' character in Calc (twips). */
152 static sal_uInt16 GetXclColumnWidth( sal_uInt16 nScWidth, long nScCharWidth );
154 /** Returns a correction value to convert column widths from/to default column widths.
155 @param nXclDefFontHeight Excel height of application default font. */
156 static double GetXclDefColWidthCorrection( long nXclDefFontHeight );
158 // formatting -------------------------------------------------------------
160 /** Returns the best fitting color for an Excel pattern area format. */
161 static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
163 // text encoding ----------------------------------------------------------
165 /** Returns a text encoding from an Excel code page.
166 @return The corresponding text encoding or RTL_TEXTENCODING_DONTKNOW. */
167 static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
169 /** Returns an Excel code page from a text encoding. */
170 static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
172 // font names -------------------------------------------------------------
174 /** Returns the matching Excel font name for a passed Calc font name. */
175 static OUString GetXclFontName( const OUString& rFontName );
177 // built-in defined names -------------------------------------------------
179 /** Returns the raw English UI representation of a built-in defined name used in NAME records.
180 @param cBuiltIn Excel index of the built-in name. */
181 static OUString GetXclBuiltInDefName( sal_Unicode cBuiltIn );
182 /** Returns the Calc UI representation of a built-in defined name used in NAME records.
183 @descr Adds a prefix to the representation returned by GetXclBuiltInDefName().
184 @param cBuiltIn Excel index of the built-in name. */
185 static OUString GetBuiltInDefName( sal_Unicode cBuiltIn );
186 /** Returns the Excel built-in name with OOXML prefix
187 @descr Adds the "_xlnm." prefix to the representation returned by GetXclBuiltInDefName()
188 @param cBuiltIn Excel index of the built in name.*/
189 static OUString GetBuiltInDefNameXml( sal_Unicode cBuiltIn );
190 /** Returns the Excel built-in name index of the passed defined name from Calc.
191 @descr Ignores any characters following a valid representation of a built-in name.
192 @param rDefName raw English UI representation of a built-in defined name used in NAME records.
193 @return the index of the built-in name, or EXC_BUILTIN_UNKNOWN if it is not a built-in name. */
194 static sal_Unicode GetBuiltInDefNameIndex( const OUString& rDefName );
196 // built-in style names ---------------------------------------------------
198 /** Returns the specified built-in cell style name.
199 @param nStyleId The identifier of the built-in style.
200 @param rName Default name for unknown styles.
201 @param nLevel The zero-based outline level for RowLevel and ColLevel styles.
202 @return The style name or an empty string, if the parameters are not valid. */
203 static OUString GetBuiltInStyleName( sal_uInt8 nStyleId, const OUString& rName, sal_uInt8 nLevel );
205 /** Returns true, if the passed string is a name of an Excel built-in style.
206 @param pnStyleId If not 0, the found style identifier will be returned here.
207 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
208 static bool IsBuiltInStyleName( const OUString& rStyleName, sal_uInt8* pnStyleId = nullptr, sal_Int32* pnNextChar = nullptr );
209 /** Returns the Excel built-in style identifier of a passed style name.
210 @param rnStyleId The style identifier is returned here.
211 @param rnLevel The zero-based outline level for RowLevel and ColLevel styles is returned here.
212 @param rStyleName The style name to examine.
213 @return true = passed string is a built-in style name, false = user style. */
214 static bool GetBuiltInStyleId(
215 sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
216 const OUString& rStyleName );
218 // conditional formatting style names -------------------------------------
220 /** Returns the style name for a single condition of a conditional formatting.
221 @param nScTab The current Calc sheet index.
222 @param nFormat The zero-based index of the conditional formatting.
223 @param nCondition The zero-based index of the condition.
224 @return A style sheet name in the form "Excel_CondFormat_<sheet>_<format>_<condition>". */
225 static OUString GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
226 /** Returns true, if the passed string is a name of a conditional format style created by Excel import.
227 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
228 static bool IsCondFormatStyleName( const OUString& rStyleName );
230 // stream handling --------------------------------------------------------
232 /** Skips a substream (BOF/EOF record block). Includes all embedded substreams. */
233 static void SkipSubStream( XclImpStream& rStrm );
235 // Basic macro names ------------------------------------------------------
237 /** Returns the full StarBasic macro URL from an Excel macro name. */
238 static OUString GetSbMacroUrl( const OUString& rMacroName, SfxObjectShell* pDocShell );
239 /** Returns the Excel macro name from a full StarBasic macro URL. */
240 static OUString GetXclMacroName( const OUString& rSbMacroUrl );
244 // read/write colors ----------------------------------------------------------
246 /** Reads a color from the passed stream.
247 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
248 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
250 /** Reads a color to the passed stream.
251 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
252 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
254 #endif
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */