update dev300-m58
[ooovba.git] / sc / source / filter / inc / xehelper.hxx
blobb9ed31997b0c82c90a1cf84d786906e0c56f3e6a
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: xehelper.hxx,v $
10 * $Revision: 1.20.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_XEHELPER_HXX
32 #define SC_XEHELPER_HXX
34 #include "xladdress.hxx"
35 #include "xeroot.hxx"
36 #include "xestring.hxx"
38 // Export progress bar ========================================================
40 class ScfProgressBar;
42 /** The main progress bar for the export filter.
44 This class encapsulates creation and initialization of sub progress
45 segments. The Activate***Segment() functions activate a specific segement
46 of the main progress bar. The implementation of these functions contain the
47 calculation of the needed size of the segment. Following calls of the
48 Progress() function increase the currently activated sub segment.
50 class XclExpProgressBar : protected XclExpRoot
52 public:
53 explicit XclExpProgressBar( const XclExpRoot& rRoot );
54 virtual ~XclExpProgressBar();
56 /** Initializes all segments and sub progress bars. */
57 void Initialize();
59 /** Increases the number of existing ROW records by 1. */
60 void IncRowRecordCount();
62 /** Activates the progress segment to create ROW records. */
63 void ActivateCreateRowsSegment();
64 /** Activates the progress segment to finalize ROW records. */
65 void ActivateFinalRowsSegment();
67 /** Increases the currently activated (sub) progress bar by 1 step. */
68 void Progress();
70 private:
71 typedef ::std::auto_ptr< ScfProgressBar > ScfProgressBarPtr;
73 ScfProgressBarPtr mxProgress; /// Progress bar implementation.
74 ScfProgressBar* mpSubProgress; /// Current sub progress bar.
76 ScfProgressBar* mpSubRowCreate; /// Sub progress bar for creating table rows.
77 ScfInt32Vec maSubSegRowCreate; /// Segment ID's for all sheets in sub progress bar.
79 ScfProgressBar* mpSubRowFinal; /// Sub progress bar for finalizing ROW records.
80 sal_Int32 mnSegRowFinal; /// Progress segment for finalizing ROW records.
82 sal_Size mnRowCount; /// Number of created ROW records.
85 // Calc->Excel cell address/range conversion ==================================
87 /** Provides functions to convert Calc cell addresses to Excel cell addresses. */
88 class XclExpAddressConverter : public XclAddressConverterBase
90 public:
91 explicit XclExpAddressConverter( const XclExpRoot& rRoot );
93 // cell address -----------------------------------------------------------
95 /** Checks if the passed Calc cell address is valid.
96 @param rScPos The Calc cell address to check.
97 @param bWarn true = Sets the internal flag that produces a warning box
98 after loading/saving the file, if the cell address is not valid.
99 @return true = Cell address in rScPos is valid. */
100 bool CheckAddress( const ScAddress& rScPos, bool bWarn );
102 /** Converts the passed Calc cell address to an Excel cell address.
103 @param rXclPos (Out) The converted Excel cell address, if valid.
104 @param rScPos The Calc cell address to convert.
105 @param bWarn true = Sets the internal flag that produces a warning box
106 after loading/saving the file, if the cell address is not valid.
107 @return true = Cell address returned in rXclPos is valid. */
108 bool ConvertAddress( XclAddress& rXclPos,
109 const ScAddress& rScPos, bool bWarn );
111 /** Returns a valid cell address by moving it into allowed dimensions.
112 @param rScPos The Calc cell address to convert.
113 @param bWarn true = Sets the internal flag that produces a warning box
114 after loading/saving the file, if the cell address is invalid.
115 @return The converted Excel cell address. */
116 XclAddress CreateValidAddress( const ScAddress& rScPos, bool bWarn );
118 // cell range -------------------------------------------------------------
120 /** Checks if the passed cell range is valid (checks start and end position).
121 @param rScRange The Calc cell range to check.
122 @param bWarn true = Sets the internal flag that produces a warning box
123 after loading/saving the file, if the cell range is not valid.
124 @return true = Cell range in rScRange is valid. */
125 bool CheckRange( const ScRange& rScRange, bool bWarn );
127 /** Checks and eventually crops the cell range to valid dimensions.
128 @descr The start position of the range will not be modified.
129 @param rScRange (In/out) The cell range to validate.
130 @param bWarn true = Sets the internal flag that produces a warning box
131 after loading/saving the file, if the cell range contains invalid
132 cells. If the range is partly valid, this function sets the warning
133 flag, corrects the range and returns true.
134 @return true = Cell range in rScRange is valid (original or cropped). */
135 bool ValidateRange( ScRange& rScRange, bool bWarn );
137 /** Converts the passed Calc cell range to an Excel cell range.
138 @param rXclRange (Out) The converted Excel cell range, if valid.
139 @param rScRange The Calc cell range to convert.
140 @param bWarn true = Sets the internal flag that produces a warning box
141 after loading/saving the file, if the cell range contains invalid cells.
142 @return true = Cell range returned in rXclRange is valid (original or cropped). */
143 bool ConvertRange( XclRange& rXclRange, const ScRange& rScRange, bool bWarn );
145 //UNUSED2008-05 /** Returns a valid cell range by moving it into allowed dimensions.
146 //UNUSED2008-05 @descr The start and/or end position of the range may be modified.
147 //UNUSED2008-05 @param rScRange The Calc cell range to convert.
148 //UNUSED2008-05 @param bWarn true = Sets the internal flag that produces a warning box
149 //UNUSED2008-05 after loading/saving the file, if the cell range contains invalid cells.
150 //UNUSED2008-05 @return The converted Excel cell range. */
151 //UNUSED2008-05 XclRange CreateValidRange( const ScRange& rScRange, bool bWarn );
153 // cell range list --------------------------------------------------------
155 //UNUSED2008-05 /** Checks if the passed cell range list is valid.
156 //UNUSED2008-05 @param rScRanges The Calc cell range list to check.
157 //UNUSED2008-05 @param bWarn true = Sets the internal flag that produces a warning box
158 //UNUSED2008-05 after loading/saving the file, if the cell range list contains at
159 //UNUSED2008-05 least one invalid range.
160 //UNUSED2008-05 @return true = Cell range list in rScRanges is completly valid. */
161 //UNUSED2008-05 bool CheckRangeList( const ScRangeList& rScRanges, bool bWarn );
163 /** Checks and eventually crops the cell ranges to valid dimensions.
164 @descr The start position of the ranges will not be modified. Cell
165 ranges that fit partly into valid dimensions are cropped
166 accordingly. Cell ranges that do not fit at all, are removed from
167 the cell range list.
168 @param rScRanges (In/out) The cell range list to check.
169 @param bWarn true = Sets the internal flag that produces a warning box
170 after loading/saving the file, if at least one of the cell ranges
171 contains invalid cells. */
172 void ValidateRangeList( ScRangeList& rScRanges, bool bWarn );
174 /** Converts the passed Calc cell range list to an Excel cell range list.
175 @descr The start position of the ranges will not be modified. Cell
176 ranges that fit partly into valid dimensions are cropped
177 accordingly. Cell ranges that do not fit at all, are not inserted
178 into the Excel cell range list.
179 @param rXclRanges (Out) The converted Excel cell range list.
180 @param rScRanges The Calc cell range list to convert.
181 @param bWarn true = Sets the internal flag that produces a warning box
182 after loading/saving the file, if at least one of the cell ranges
183 contains invalid cells. */
184 void ConvertRangeList( XclRangeList& rXclRanges,
185 const ScRangeList& rScRanges, bool bWarn );
188 // EditEngine->String conversion ==============================================
190 class SvxURLField;
191 class XclExpHyperlink;
193 /** Helper to create HLINK records during creation of formatted cell strings.
195 In Excel it is not possible to have more than one hyperlink in a cell. This
196 helper detects multiple occurences of hyperlinks and fills a string which
197 is used to create a cell note containing all URLs. Only cells containing
198 one hyperlink are exported as hyperlink cells.
200 class XclExpHyperlinkHelper : protected XclExpRoot
202 public:
203 typedef ScfRef< XclExpHyperlink > XclExpHyperlinkRef;
205 explicit XclExpHyperlinkHelper( const XclExpRoot& rRoot, const ScAddress& rScPos );
206 ~XclExpHyperlinkHelper();
208 /** Processes the passed URL field (tries to create a HLINK record).
209 @return The representation string of the URL field. */
210 String ProcessUrlField( const SvxURLField& rUrlField );
212 /** Returns true, if a single HLINK record has been created. */
213 bool HasLinkRecord() const;
214 /** Returns the craeted single HLINk record, or an empty reference. */
215 XclExpHyperlinkRef GetLinkRecord();
217 /** Returns true, if multiple URLs have been processed. */
218 inline bool HasMultipleUrls() const { return mbMultipleUrls; }
219 /** Returns a string containing all processed URLs. */
220 inline const String& GetUrlList() { return maUrlList; }
222 private:
223 XclExpHyperlinkRef mxLinkRec; /// Created HLINK record.
224 ScAddress maScPos; /// Cell position to set at the HLINK record.
225 String maUrlList; /// List with all processed URLs.
226 bool mbMultipleUrls; /// true = Multiple URL fields processed.
229 // ----------------------------------------------------------------------------
231 class EditEngine;
232 class SdrTextObj;
233 class ScStringCell;
234 class ScEditCell;
235 class ScPatternAttr;
237 /** This class provides methods to create an XclExpString.
238 @descr The string can be created from an edit engine text object or
239 directly from a Calc edit cell. */
240 class XclExpStringHelper : ScfNoInstance
242 public:
243 /** Creates a new unformatted string from the passed string.
244 @descr Creates a Unicode string or a byte string, depending on the
245 current BIFF version contained in the passed XclExpRoot object.
246 @param rString The source string.
247 @param nFlags Modifiers for string export.
248 @param nMaxLen The maximum number of characters to store in this string.
249 @return The new string object (shared pointer). */
250 static XclExpStringRef CreateString(
251 const XclExpRoot& rRoot,
252 const String& rString,
253 XclStrFlags nFlags = EXC_STR_DEFAULT,
254 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
256 /** Creates a new unformatted string from the passed character.
257 @descr Creates a Unicode string or a byte string, depending on the
258 current BIFF version contained in the passed XclExpRoot object.
259 @param cChar The source character. The NUL character is explicitly allowed.
260 @param nFlags Modifiers for string export.
261 @param nMaxLen The maximum number of characters to store in this string.
262 @return The new string object (shared pointer). */
263 static XclExpStringRef CreateString(
264 const XclExpRoot& rRoot,
265 sal_Unicode cChar,
266 XclStrFlags nFlags = EXC_STR_DEFAULT,
267 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
269 /** Appends an unformatted string to an Excel string object.
270 @descr Selects the correct Append() function depending on the current
271 BIFF version contained in the passed XclExpRoot object.
272 @param rXclString The Excel string object.
273 @param rString The source string. */
274 static void AppendString(
275 XclExpString& rXclString,
276 const XclExpRoot& rRoot,
277 const String& rString );
279 /** Appends a character to an Excel string object.
280 @descr Selects the correct Append() function depending on the current
281 BIFF version contained in the passed XclExpRoot object.
282 @param rXclString The Excel string object.
283 @param rString The source string. */
284 static void AppendChar(
285 XclExpString& rXclString,
286 const XclExpRoot& rRoot,
287 sal_Unicode cChar );
289 /** Creates a new formatted string from a Calc string cell.
290 @descr Creates a Unicode string or a byte string, depending on the
291 current BIFF version contained in the passed XclExpRoot object.
292 May create a formatted string object, if the cell text contains
293 different script types.
294 @param rStringCell The Calc string cell object.
295 @param pCellAttr The set item containing the cell formatting.
296 @param nFlags Modifiers for string export.
297 @param nMaxLen The maximum number of characters to store in this string.
298 @return The new string object (shared pointer). */
299 static XclExpStringRef CreateCellString(
300 const XclExpRoot& rRoot,
301 const ScStringCell& rStringCell,
302 const ScPatternAttr* pCellAttr,
303 XclStrFlags nFlags = EXC_STR_DEFAULT,
304 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
306 /** Creates a new formatted string from a Calc edit cell.
307 @descr Creates a Unicode string or a byte string, depending on the
308 current BIFF version contained in the passed XclExpRoot object.
309 @param rEditCell The Calc edit cell object.
310 @param pCellAttr The set item containing the cell formatting.
311 @param rLinkHelper Helper object for hyperlink conversion.
312 @param nFlags Modifiers for string export.
313 @param nMaxLen The maximum number of characters to store in this string.
314 @return The new string object (shared pointer). */
315 static XclExpStringRef CreateCellString(
316 const XclExpRoot& rRoot,
317 const ScEditCell& rEditCell,
318 const ScPatternAttr* pCellAttr,
319 XclExpHyperlinkHelper& rLinkHelper,
320 XclStrFlags nFlags = EXC_STR_DEFAULT,
321 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
323 /** Creates a new formatted string from a drawing text box.
324 @descr Creates a Unicode string or a byte string, depending on the
325 current BIFF version contained in the passed XclExpRoot object.
326 @param rTextObj The text box object.
327 @param nFlags Modifiers for string export.
328 @param nMaxLen The maximum number of characters to store in this string.
329 @return The new string object (shared pointer). */
330 static XclExpStringRef CreateString(
331 const XclExpRoot& rRoot,
332 const SdrTextObj& rTextObj,
333 XclStrFlags nFlags = EXC_STR_DEFAULT,
334 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
336 /** Creates a new formatted string from a edit text string.
337 @param rEditObj The edittext object.
338 @param nFlags Modifiers for string export.
339 @param nMaxLen The maximum number of characters to store in this string.
340 @return The new string object. */
341 static XclExpStringRef CreateString(
342 const XclExpRoot& rRoot,
343 const EditTextObject& rEditObj,
344 XclStrFlags nFlags = EXC_STR_DEFAULT,
345 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
347 /** Returns the script type first text portion different to WEAK, or the system
348 default script type, if there is only weak script in the passed string. */
349 static sal_Int16 GetLeadingScriptType( const XclExpRoot& rRoot, const String& rString );
352 // Header/footer conversion ===================================================
354 class EditEngine;
356 /** Converts edit engine text objects to an Excel header/footer string.
357 @descr Header/footer content is divided into three parts: Left, center and
358 right portion. All formatting information will be encoded in the Excel string
359 using special character seuences. A control sequence starts with the ampersand
360 character.
362 Supported control sequences:
363 &L start of left portion
364 &C start of center portion
365 &R start of right portion
366 &P current page number
367 &N page count
368 &D current date
369 &T current time
370 &A table name
371 &F file name without path
372 &Z file path without file name
373 &Z&F file path and name
374 &U underlining on/off
375 &E double underlining on/off
376 &S strikeout characters on/off
377 &X superscript on/off
378 &Y subscript on/off
379 &"fontname,fontstyle" use font with name 'fontname' and style 'fontstyle'
380 &fontheight set font height in points ('fontheight' is a decimal value)
382 Known but unsupported control sequences:
383 &G picture
385 class XclExpHFConverter : protected XclExpRoot, ScfNoCopy
387 public:
388 explicit XclExpHFConverter( const XclExpRoot& rRoot );
390 /** Generates the header/footer string from the passed edit engine text objects. */
391 void GenerateString(
392 const EditTextObject* pLeftObj,
393 const EditTextObject* pCenterObj,
394 const EditTextObject* pRightObj );
396 /** Returns the last generated header/footer string. */
397 inline const String& GetHFString() const { return maHFString; }
398 /** Returns the total height of the last generated header/footer in twips. */
399 inline sal_Int32 GetTotalHeight() const { return mnTotalHeight; }
401 private:
402 /** Converts the text object contents and stores it in the passed string. */
403 void AppendPortion(
404 const EditTextObject* pTextObj,
405 sal_Unicode cPortionCode );
407 private:
408 EditEngine& mrEE; /// The header/footer edit engine.
409 String maHFString; /// The last generated header/footer string.
410 sal_Int32 mnTotalHeight; /// Total height of the last header/footer (twips).
413 // URL conversion =============================================================
415 /** This class contains static methods to encode a file URL.
416 @descr Excel stores URLs in a format that contains special control characters,
417 i.e. for directory separators or volume names. */
418 class XclExpUrlHelper : ScfNoInstance
420 public:
421 /** Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
422 @param pTableName Optional pointer to a table name to be encoded in this URL. */
423 static String EncodeUrl( const XclExpRoot& rRoot, const String& rAbsUrl, const String* pTableName = 0 );
424 /** Encodes and returns the passed DDE link to an Excel like DDE link. */
425 static String EncodeDde( const String& rApplic, const String rTopic );
428 // ----------------------------------------------------------------------------
429 class ScDocument;
430 class ScMatrix;
432 /** Contains cached values in a 2-dimensional array. */
433 class XclExpCachedMatrix
435 void GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
436 public:
437 /** Constructs and fills a new matrix.
438 @param rMatrix The Calc value matrix. */
439 explicit XclExpCachedMatrix( const ScMatrix& rMatrix );
440 ~XclExpCachedMatrix();
442 /** Returns the byte count of all contained data. */
443 sal_Size GetSize() const;
444 /** Writes the complete matrix to stream. */
445 void Save( XclExpStream& rStrm ) const;
447 private:
448 const ScMatrix& mrMatrix;
451 // ============================================================================
453 #endif