fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / xltools.hxx
blob23aa9bf17c6d48bcb048ae115dd0842bf8e53b46
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 "address.hxx"
24 #include "ftools.hxx"
25 #include <boost/noncopyable.hpp>
27 class SfxObjectShell;
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 );
72 inline bool operator!=( const XclGuid& rCmp1, const XclGuid& rCmp2 ) { return !(rCmp1 == rCmp2); }
73 bool operator<( const XclGuid& rCmp1, const XclGuid& rCmp2 );
75 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
76 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
78 // Excel Tools ================================================================
80 /** This class contains static helper methods for the Excel import and export filters. */
81 class XclTools : boost::noncopyable
83 public:
84 // GUID's -----------------------------------------------------------------
86 static const XclGuid maGuidStdLink; /// GUID of StdLink (HLINK record).
87 static const XclGuid maGuidUrlMoniker; /// GUID of URL moniker (HLINK record).
88 static const XclGuid maGuidFileMoniker; /// GUID of file moniker (HLINK record).
90 // numeric conversion -----------------------------------------------------
92 /** Calculates the double value from an RK value (encoded integer or double). */
93 static double GetDoubleFromRK( sal_Int32 nRKValue );
94 /** Calculates an RK value (encoded integer or double) from a double value.
95 @param rnRKValue Returns the calculated RK value.
96 @param fValue The double value.
97 @return true = An RK value could be created. */
98 static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
100 /** Calculates an angle (in 1/100 of degrees) from an Excel angle value.
101 @param nRotForStacked This value will be returned, if nXclRot contains 'stacked'. */
102 static sal_Int32 GetScRotation( sal_uInt16 nXclRot, sal_Int32 nRotForStacked );
103 /** Calculates the Excel angle value from an angle in 1/100 of degrees. */
104 static sal_uInt8 GetXclRotation( sal_Int32 nScRot );
106 /** Calculates BIFF8 rotation angle from BIFF2-BIFF5 text orientation. */
107 static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
108 /** Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle. */
109 static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
111 /** Converts a Calc error code to an Excel error code. */
112 static sal_uInt8 GetXclErrorCode( sal_uInt16 nScError );
113 /** Converts an Excel error code to a Calc error code. */
114 static sal_uInt16 GetScErrorCode( sal_uInt8 nXclError );
116 /** Converts the passed BIFF error to a double containing the respective Calc error code. */
117 static double ErrorToDouble( sal_uInt8 nXclError );
118 /** Gets a translated error code or Boolean value from Excel error codes.
119 @param rfDblValue Returns 0.0 for error codes or the value of a Boolean (0.0 or 1.0).
120 @param bErrorOrBool false = nError is a Boolean value; true = is an error value.
121 @param nValue The error code or Boolean value. */
122 static XclBoolError ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uInt8 nValue );
124 /** Returns the length in twips calculated from a length in inches. */
125 static sal_uInt16 GetTwipsFromInch( double fInches );
126 /** Returns the length in twips calculated from a length in 1/100 mm. */
127 static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
129 /** Returns the length in inches calculated from a length in twips. */
130 static double GetInchFromTwips( sal_Int32 nTwips );
131 /** Returns the length in inches calculated from a length in 1/100 mm. */
132 static double GetInchFromHmm( sal_Int32 nHmm );
134 /** Returns the length in 1/100 mm calculated from a length in inches. */
135 static sal_Int32 GetHmmFromInch( double fInches );
136 /** Returns the length in 1/100 mm calculated from a length in twips. */
137 static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
139 /** Returns the Calc column width (twips) for the passed Excel width.
140 @param nScCharWidth Width of the '0' character in Calc (twips). */
141 static sal_uInt16 GetScColumnWidth( sal_uInt16 nXclWidth, long nScCharWidth );
142 /** Returns the Excel column width for the passed Calc width (twips).
143 @param nScCharWidth Width of the '0' character in Calc (twips). */
144 static sal_uInt16 GetXclColumnWidth( sal_uInt16 nScWidth, long nScCharWidth );
146 /** Returns a correction value to convert column widths from/to default column widths.
147 @param nXclDefFontHeight Excel height of application default font. */
148 static double GetXclDefColWidthCorrection( long nXclDefFontHeight );
150 // formatting -------------------------------------------------------------
152 /** Returns the best fitting color for an Excel pattern area format. */
153 static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
155 // text encoding ----------------------------------------------------------
157 /** Returns a text encoding from an Excel code page.
158 @return The corresponding text encoding or RTL_TEXTENCODING_DONTKNOW. */
159 static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
161 /** Returns an Excel code page from a text encoding. */
162 static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
164 // font names -------------------------------------------------------------
166 /** Returns the matching Excel font name for a passed Calc font name. */
167 static OUString GetXclFontName( const OUString& rFontName );
169 // built-in defined names -------------------------------------------------
171 /** Returns the raw English UI representation of a built-in defined name used in NAME records.
172 @param cBuiltIn Excel index of the built-in name. */
173 static OUString GetXclBuiltInDefName( sal_Unicode cBuiltIn );
174 /** Returns the Calc UI representation of a built-in defined name used in NAME records.
175 @descr Adds a prefix to the representation returned by GetXclBuiltInDefName().
176 @param cBuiltIn Excel index of the built-in name. */
177 static OUString GetBuiltInDefName( sal_Unicode cBuiltIn );
178 /** Returns the Excel built-in name with OOXML prefix
179 @descr Adds the "_xlnm." prefix to the representation returned by GetXclBuiltInDefName()
180 @param cBuiltIn Excel index of the built in name.*/
181 static OUString GetBuiltInDefNameXml( sal_Unicode cBuiltIn );
182 /** Returns the Excel built-in name index of the passed defined name from Calc.
183 @descr Ignores any characters following a valid representation of a built-in name.
184 @param pcBuiltIn (out-param) If not 0, the index of the built-in name will be returned here.
185 @return true = passed string is a built-in name; false = user-defined name. */
186 static sal_Unicode GetBuiltInDefNameIndex( const OUString& rDefName );
188 // built-in style names ---------------------------------------------------
190 /** Returns the specified built-in cell style name.
191 @param nStyleId The identifier of the built-in style.
192 @param rName Default name for unknown styles.
193 @param nLevel The zero-based outline level for RowLevel and ColLevel styles.
194 @return The style name or an empty string, if the parameters are not valid. */
195 static OUString GetBuiltInStyleName( sal_uInt8 nStyleId, const OUString& rName, sal_uInt8 nLevel );
197 /** Returns true, if the passed string is a name of an Excel built-in style.
198 @param pnStyleId If not 0, the found style identifier will be returned here.
199 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
200 static bool IsBuiltInStyleName( const OUString& rStyleName, sal_uInt8* pnStyleId = 0, sal_Int32* pnNextChar = 0 );
201 /** Returns the Excel built-in style identifier of a passed style name.
202 @param rnStyleId The style identifier is returned here.
203 @param rnLevel The zero-based outline level for RowLevel and ColLevel styles is returned here.
204 @param rStyleName The style name to examine.
205 @return true = passed string is a built-in style name, false = user style. */
206 static bool GetBuiltInStyleId(
207 sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
208 const OUString& rStyleName );
210 // conditional formatting style names -------------------------------------
212 /** Returns the style name for a single condition of a conditional formatting.
213 @param nScTab The current Calc sheet index.
214 @param nFormat The zero-based index of the conditional formatting.
215 @param nCondition The zero-based index of the condition.
216 @return A style sheet name in the form "Excel_CondFormat_<sheet>_<format>_<condition>". */
217 static OUString GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
218 /** Returns true, if the passed string is a name of a conditional format style created by Excel import.
219 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
220 static bool IsCondFormatStyleName( const OUString& rStyleName );
222 // stream handling --------------------------------------------------------
224 /** Skips a substream (BOF/EOF record block). Includes all embedded substreams. */
225 static void SkipSubStream( XclImpStream& rStrm );
227 // Basic macro names ------------------------------------------------------
229 /** Returns the full StarBasic macro URL from an Excel macro name. */
230 static OUString GetSbMacroUrl( const OUString& rMacroName, SfxObjectShell* pDocShell = 0 );
231 /** Returns the Excel macro name from a full StarBasic macro URL. */
232 static OUString GetXclMacroName( const OUString& rSbMacroUrl );
234 private:
235 static const OUString maDefNamePrefix; /// Prefix for built-in defined names.
236 static const OUString maDefNamePrefixXml; /// Prefix for built-in defined names for OOX
237 static const OUString maStyleNamePrefix1; /// Prefix for built-in cell style names.
238 static const OUString maStyleNamePrefix2; /// Prefix for built-in cell style names from OOX filter.
239 static const OUString maCFStyleNamePrefix1; /// Prefix for cond. formatting style names.
240 static const OUString maCFStyleNamePrefix2; /// Prefix for cond. formatting style names from OOX filter.
241 static const OUString maSbMacroPrefix; /// Prefix for StarBasic macros.
242 static const OUString maSbMacroSuffix; /// Suffix for StarBasic macros.
244 /** We don't want anybody to instantiate this class, since it is just a
245 collection of static items. To enforce this, the default constructor
246 is made private */
247 XclTools();
250 // read/write colors ----------------------------------------------------------
252 /** Reads a color from the passed stream.
253 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
254 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
256 /** Reads a color to the passed stream.
257 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
258 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
260 #endif
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */