update dev300-m58
[ooovba.git] / sc / source / filter / inc / xltools.hxx
blob2c16c052c2f523dd4186a59c535c45de418b268c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xltools.hxx,v $
10 * $Revision: 1.27.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_XLTOOLS_HXX
32 #define SC_XLTOOLS_HXX
34 #include "address.hxx"
35 #include "ftools.hxx"
37 // BIFF versions ==============================================================
39 #define DBG_ERROR_BIFF() DBG_ERRORFILE( "Unknown BIFF type!" )
40 #define DBG_ASSERT_BIFF( c ) DBG_ASSERT( c, "Unknown BIFF type!" )
42 // Enumerations ===============================================================
44 /** An enumeration for all Excel error codes and the values true and false. */
45 enum XclBoolError
47 xlErrNull, /// The error code #NULL!
48 xlErrDiv0, /// The error code #DIV/0!
49 xlErrValue, /// The error code #VALUE!
50 xlErrRef, /// The error code #REF!
51 xlErrName, /// The error code #NAME?
52 xlErrNum, /// The error code #NUM!
53 xlErrNA, /// The error code #N/A!
54 xlErrTrue, /// The Boolean value true.
55 xlErrFalse, /// The Boolean value false.
56 xlErrUnknown /// For unknown codes and values.
59 // GUID import/export =========================================================
61 class XclImpStream;
62 class XclExpStream;
64 /** This struct stores a GUID (class ID) and supports reading, writing and comparison. */
65 struct XclGuid
67 sal_uInt8 mpnData[ 16 ]; /// Stores GUID always in little endian.
69 explicit XclGuid();
70 explicit XclGuid(
71 sal_uInt32 nData1,
72 sal_uInt16 nData2, sal_uInt16 nData3,
73 sal_uInt8 nData41, sal_uInt8 nData42,
74 sal_uInt8 nData43, sal_uInt8 nData44,
75 sal_uInt8 nData45, sal_uInt8 nData46,
76 sal_uInt8 nData47, sal_uInt8 nData48 );
79 bool operator==( const XclGuid& rCmp1, const XclGuid& rCmp2 );
80 inline bool operator!=( const XclGuid& rCmp1, const XclGuid& rCmp2 ) { return !(rCmp1 == rCmp2); }
81 bool operator<( const XclGuid& rCmp1, const XclGuid& rCmp2 );
83 XclImpStream& operator>>( XclImpStream& rStrm, XclGuid& rGuid );
84 XclExpStream& operator<<( XclExpStream& rStrm, const XclGuid& rGuid );
86 // Excel Tools ================================================================
88 class SvStream;
89 class ScDocument;
91 /** This class contains static helper methods for the Excel import and export filters. */
92 class XclTools : ScfNoInstance
94 public:
95 // GUID's -----------------------------------------------------------------
97 static const XclGuid maGuidStdLink; /// GUID of StdLink (HLINK record).
98 static const XclGuid maGuidUrlMoniker; /// GUID of URL moniker (HLINK record).
99 static const XclGuid maGuidFileMoniker; /// GUID of file moniker (HLINK record).
101 // numeric conversion -----------------------------------------------------
103 /** Calculates the double value from an RK value (encoded integer or double). */
104 static double GetDoubleFromRK( sal_Int32 nRKValue );
105 /** Calculates an RK value (encoded integer or double) from a double value.
106 @param rnRKValue Returns the calculated RK value.
107 @param fValue The double value.
108 @return true = An RK value could be created. */
109 static bool GetRKFromDouble( sal_Int32& rnRKValue, double fValue );
111 /** Calculates an angle (in 1/100 of degrees) from an Excel angle value.
112 @param nRotForStacked This value will be returned, if nXclRot contains 'stacked'. */
113 static sal_Int32 GetScRotation( sal_uInt16 nXclRot, sal_Int32 nRotForStacked );
114 /** Calculates the Excel angle value from an angle in 1/100 of degrees. */
115 static sal_uInt8 GetXclRotation( sal_Int32 nScRot );
117 /** Calculates BIFF8 rotation angle from BIFF2-BIFF5 text orientation. */
118 static sal_uInt8 GetXclRotFromOrient( sal_uInt8 nXclOrient );
119 /** Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle. */
120 static sal_uInt8 GetXclOrientFromRot( sal_uInt16 nXclRot );
122 /** Converts a Calc error code to an Excel error code. */
123 static sal_uInt8 GetXclErrorCode( USHORT nScError );
124 /** Converts an Excel error code to a Calc error code. */
125 static USHORT GetScErrorCode( sal_uInt8 nXclError );
127 /** Gets a translated error code or Boolean value from Excel error codes.
128 @param rfDblValue Returns 0.0 for error codes or the value of a Boolean (0.0 or 1.0).
129 @param bErrorOrBool false = nError is a Boolean value; true = is an error value.
130 @param nValue The error code or Boolean value. */
131 static XclBoolError ErrorToEnum( double& rfDblValue, sal_uInt8 bErrOrBool, sal_uInt8 nValue );
133 /** Returns the length in twips calculated from a length in inches. */
134 static sal_uInt16 GetTwipsFromInch( double fInches );
135 /** Returns the length in twips calculated from a length in 1/100 mm. */
136 static sal_uInt16 GetTwipsFromHmm( sal_Int32 nHmm );
138 /** Returns the length in inches calculated from a length in twips. */
139 static double GetInchFromTwips( sal_Int32 nTwips );
140 /** Returns the length in inches calculated from a length in 1/100 mm. */
141 static double GetInchFromHmm( sal_Int32 nHmm );
143 /** Returns the length in 1/100 mm calculated from a length in inches. */
144 static sal_Int32 GetHmmFromInch( double fInches );
145 /** Returns the length in 1/100 mm calculated from a length in twips. */
146 static sal_Int32 GetHmmFromTwips( sal_Int32 nTwips );
148 /** Returns the Calc column width (twips) for the passed Excel width.
149 @param nScCharWidth Width of the '0' character in Calc (twips). */
150 static USHORT GetScColumnWidth( sal_uInt16 nXclWidth, long nScCharWidth );
151 /** Returns the Excel column width for the passed Calc width (twips).
152 @param nScCharWidth Width of the '0' character in Calc (twips). */
153 static sal_uInt16 GetXclColumnWidth( USHORT nScWidth, long nScCharWidth );
155 /** Returns a correction value to convert column widths from/to default column widths.
156 @param nXclDefFontHeight Excel height of application default font. */
157 static double GetXclDefColWidthCorrection( long nXclDefFontHeight );
159 // formatting -------------------------------------------------------------
161 /** Returns the best fitting color for an Excel pattern area format. */
162 static Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt16 nXclPattern );
164 // text encoding ----------------------------------------------------------
166 /** Returns a text encoding from an Excel code page.
167 @return The corresponding text encoding or RTL_TEXTENCODING_DONTKNOW. */
168 static rtl_TextEncoding GetTextEncoding( sal_uInt16 nCodePage );
170 //UNUSED2008-05 /** Returns an Excel code page from a text encoding. */
171 //UNUSED2008-05 static sal_uInt16 GetXclCodePage( rtl_TextEncoding eTextEnc );
173 // font names -------------------------------------------------------------
175 /** Returns the matching Excel font name for a passed Calc font name. */
176 static String GetXclFontName( const String& rFontName );
178 // built-in defined names -------------------------------------------------
180 /** Returns the raw English UI representation of a built-in defined name used in NAME records.
181 @param cBuiltIn Excel index of the built-in name. */
182 static String GetXclBuiltInDefName( sal_Unicode cBuiltIn );
183 /** Returns the Calc UI representation of a built-in defined name used in NAME records.
184 @descr Adds a prefix to the representation returned by GetXclBuiltInDefName().
185 @param cBuiltIn Excel index of the built-in name. */
186 static String GetBuiltInDefName( sal_Unicode cBuiltIn );
187 /** Returns the Excel built-in name index of the passed defined name from Calc.
188 @descr Ignores any characters following a valid representation of a built-in name.
189 @param pcBuiltIn (out-param) If not 0, the index of the built-in name will be returned here.
190 @return true = passed string is a built-in name; false = user-defined name. */
191 static sal_Unicode GetBuiltInDefNameIndex( const String& rDefName );
193 // built-in style names ---------------------------------------------------
195 /** Returns the specified built-in cell style name.
196 @param nStyleId The identifier of the built-in style.
197 @param nLevel The zero-based outline level for RowLevel and ColLevel styles.
198 @return The style name or an empty string, if the parameters are not valid. */
199 static String GetBuiltInStyleName( sal_uInt8 nStyleId, sal_uInt8 nLevel );
200 /** Returns true, if the passed string is a name of an Excel built-in style.
201 @param pnStyleId If not 0, the found style identifier will be returned here.
202 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
203 static bool IsBuiltInStyleName( const String& rStyleName, sal_uInt8* pnStyleId = 0, xub_StrLen* pnNextChar = 0 );
204 /** Returns the Excel built-in style identifier of a passed style name.
205 @param rnStyleId The style identifier is returned here.
206 @param rnLevel The zero-based outline level for RowLevel and ColLevel styles is returned here.
207 @param rStyleName The style name to examine.
208 @return true = passed string is a built-in style name, false = user style. */
209 static bool GetBuiltInStyleId(
210 sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
211 const String& rStyleName );
213 // conditional formatting style names -------------------------------------
215 /** Returns the style name for a single condition of a conditional formatting.
216 @param nScTab The current Calc sheet index.
217 @param nFormat The zero-based index of the conditional formatting.
218 @param nCondition The zero-based index of the condition.
219 @return A style sheet name in the form "Excel_CondFormat_<sheet>_<format>_<condition>". */
220 static String GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
221 /** Returns true, if the passed string is a name of a conditional format style created by Excel import.
222 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
223 static bool IsCondFormatStyleName( const String& rStyleName, xub_StrLen* pnNextChar = 0 );
225 // stream handling --------------------------------------------------------
227 /** Skips a substream (BOF/EOF record block). Includes all embedded substreams. */
228 static void SkipSubStream( XclImpStream& rStrm );
230 // ------------------------------------------------------------------------
231 private:
232 static const String maDefNamePrefix; /// Prefix for built-in defined names.
233 static const String maStyleNamePrefix; /// Prefix for built-in cell style names.
234 static const String maCFStyleNamePrefix; /// Prefix for cond. formatting style names.
237 // read/write colors ----------------------------------------------------------
239 /** Reads a color from the passed stream.
240 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
241 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
243 /** Reads a color to the passed stream.
244 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
245 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
247 // ============================================================================
249 #endif