Update ooo320-m1
[ooovba.git] / sc / source / filter / inc / xltools.hxx
blob392b0a2ae1fc548c887b4965a8f3bef9e6d68d68
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 /** Returns an Excel code page from a text encoding. */
171 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 rName Default name for unknown styles.
198 @param nLevel The zero-based outline level for RowLevel and ColLevel styles.
199 @return The style name or an empty string, if the parameters are not valid. */
200 static String GetBuiltInStyleName( sal_uInt8 nStyleId, const String& rName, sal_uInt8 nLevel );
201 /** Returns the passed style name with a special built-in prefix. */
202 static String GetBuiltInStyleName( const String& rStyleName );
203 /** Returns true, if the passed string is a name of an Excel built-in style.
204 @param pnStyleId If not 0, the found style identifier will be returned here.
205 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
206 static bool IsBuiltInStyleName( const String& rStyleName, sal_uInt8* pnStyleId = 0, xub_StrLen* pnNextChar = 0 );
207 /** Returns the Excel built-in style identifier of a passed style name.
208 @param rnStyleId The style identifier is returned here.
209 @param rnLevel The zero-based outline level for RowLevel and ColLevel styles is returned here.
210 @param rStyleName The style name to examine.
211 @return true = passed string is a built-in style name, false = user style. */
212 static bool GetBuiltInStyleId(
213 sal_uInt8& rnStyleId, sal_uInt8& rnLevel,
214 const String& rStyleName );
216 // conditional formatting style names -------------------------------------
218 /** Returns the style name for a single condition of a conditional formatting.
219 @param nScTab The current Calc sheet index.
220 @param nFormat The zero-based index of the conditional formatting.
221 @param nCondition The zero-based index of the condition.
222 @return A style sheet name in the form "Excel_CondFormat_<sheet>_<format>_<condition>". */
223 static String GetCondFormatStyleName( SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition );
224 /** Returns true, if the passed string is a name of a conditional format style created by Excel import.
225 @param pnNextChar If not 0, the index of the char after the evaluated substring will be returned here. */
226 static bool IsCondFormatStyleName( const String& rStyleName, xub_StrLen* pnNextChar = 0 );
228 // stream handling --------------------------------------------------------
230 /** Skips a substream (BOF/EOF record block). Includes all embedded substreams. */
231 static void SkipSubStream( XclImpStream& rStrm );
233 // ------------------------------------------------------------------------
234 private:
235 static const String maDefNamePrefix; /// Prefix for built-in defined names.
236 static const String maStyleNamePrefix1; /// Prefix for built-in cell style names.
237 static const String maStyleNamePrefix2; /// Prefix for built-in cell style names from OOX filter.
238 static const String maCFStyleNamePrefix1; /// Prefix for cond. formatting style names.
239 static const String maCFStyleNamePrefix2; /// Prefix for cond. formatting style names from OOX filter.
242 // read/write colors ----------------------------------------------------------
244 /** Reads a color from the passed stream.
245 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
246 XclImpStream& operator>>( XclImpStream& rStrm, Color& rColor );
248 /** Reads a color to the passed stream.
249 @descr The color has the format (all values 8-bit): Red, Green, Blue, 0. */
250 XclExpStream& operator<<( XclExpStream& rStrm, const Color& rColor );
252 // ============================================================================
254 #endif