Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_XEHELPER_HXX
30 : : #define SC_XEHELPER_HXX
31 : :
32 : : #include <boost/noncopyable.hpp>
33 : : #include <boost/shared_ptr.hpp>
34 : : #include "xladdress.hxx"
35 : : #include "xeroot.hxx"
36 : : #include "xestring.hxx"
37 : :
38 : : // Export progress bar ========================================================
39 : :
40 : : class ScfProgressBar;
41 : :
42 : : /** The main progress bar for the export filter.
43 : :
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.
49 : : */
50 : : class XclExpProgressBar : protected XclExpRoot
51 : : {
52 : : public:
53 : : explicit XclExpProgressBar( const XclExpRoot& rRoot );
54 : : virtual ~XclExpProgressBar();
55 : :
56 : : /** Initializes all segments and sub progress bars. */
57 : : void Initialize();
58 : :
59 : : /** Increases the number of existing ROW records by 1. */
60 : : void IncRowRecordCount();
61 : :
62 : : /** Activates the progress segment to create ROW records. */
63 : : void ActivateCreateRowsSegment();
64 : : /** Activates the progress segment to finalize ROW records. */
65 : : void ActivateFinalRowsSegment();
66 : :
67 : : /** Increases the currently activated (sub) progress bar by 1 step. */
68 : : void Progress();
69 : :
70 : : private:
71 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
72 : : typedef ::std::auto_ptr< ScfProgressBar > ScfProgressBarPtr;
73 : : SAL_WNODEPRECATED_DECLARATIONS_POP
74 : :
75 : : ScfProgressBarPtr mxProgress; /// Progress bar implementation.
76 : : ScfProgressBar* mpSubProgress; /// Current sub progress bar.
77 : :
78 : : ScfProgressBar* mpSubRowCreate; /// Sub progress bar for creating table rows.
79 : : ScfInt32Vec maSubSegRowCreate; /// Segment ID's for all sheets in sub progress bar.
80 : :
81 : : ScfProgressBar* mpSubRowFinal; /// Sub progress bar for finalizing ROW records.
82 : : sal_Int32 mnSegRowFinal; /// Progress segment for finalizing ROW records.
83 : :
84 : : sal_Size mnRowCount; /// Number of created ROW records.
85 : : };
86 : :
87 : : // Calc->Excel cell address/range conversion ==================================
88 : :
89 : : /** Provides functions to convert Calc cell addresses to Excel cell addresses. */
90 [ # # ]: 0 : class XclExpAddressConverter : public XclAddressConverterBase
91 : : {
92 : : public:
93 : : explicit XclExpAddressConverter( const XclExpRoot& rRoot );
94 : :
95 : : // cell address -----------------------------------------------------------
96 : :
97 : : /** Checks if the passed Calc cell address is valid.
98 : : @param rScPos The Calc cell address to check.
99 : : @param bWarn true = Sets the internal flag that produces a warning box
100 : : after loading/saving the file, if the cell address is not valid.
101 : : @return true = Cell address in rScPos is valid. */
102 : : bool CheckAddress( const ScAddress& rScPos, bool bWarn );
103 : :
104 : : /** Converts the passed Calc cell address to an Excel cell address.
105 : : @param rXclPos (Out) The converted Excel cell address, if valid.
106 : : @param rScPos The Calc cell address to convert.
107 : : @param bWarn true = Sets the internal flag that produces a warning box
108 : : after loading/saving the file, if the cell address is not valid.
109 : : @return true = Cell address returned in rXclPos is valid. */
110 : : bool ConvertAddress( XclAddress& rXclPos,
111 : : const ScAddress& rScPos, bool bWarn );
112 : :
113 : : /** Returns a valid cell address by moving it into allowed dimensions.
114 : : @param rScPos The Calc cell address to convert.
115 : : @param bWarn true = Sets the internal flag that produces a warning box
116 : : after loading/saving the file, if the cell address is invalid.
117 : : @return The converted Excel cell address. */
118 : : XclAddress CreateValidAddress( const ScAddress& rScPos, bool bWarn );
119 : :
120 : : // cell range -------------------------------------------------------------
121 : :
122 : : /** Checks if the passed cell range is valid (checks start and end position).
123 : : @param rScRange The Calc cell range to check.
124 : : @param bWarn true = Sets the internal flag that produces a warning box
125 : : after loading/saving the file, if the cell range is not valid.
126 : : @return true = Cell range in rScRange is valid. */
127 : : bool CheckRange( const ScRange& rScRange, bool bWarn );
128 : :
129 : : /** Checks and eventually crops the cell range to valid dimensions.
130 : : @descr The start position of the range will not be modified.
131 : : @param rScRange (In/out) The cell range to validate.
132 : : @param bWarn true = Sets the internal flag that produces a warning box
133 : : after loading/saving the file, if the cell range contains invalid
134 : : cells. If the range is partly valid, this function sets the warning
135 : : flag, corrects the range and returns true.
136 : : @return true = Cell range in rScRange is valid (original or cropped). */
137 : : bool ValidateRange( ScRange& rScRange, bool bWarn );
138 : :
139 : : /** Converts the passed Calc cell range to an Excel cell range.
140 : : @param rXclRange (Out) The converted Excel cell range, if valid.
141 : : @param rScRange The Calc cell range to convert.
142 : : @param bWarn true = Sets the internal flag that produces a warning box
143 : : after loading/saving the file, if the cell range contains invalid cells.
144 : : @return true = Cell range returned in rXclRange is valid (original or cropped). */
145 : : bool ConvertRange( XclRange& rXclRange, const ScRange& rScRange, bool bWarn );
146 : :
147 : : // cell range list --------------------------------------------------------
148 : :
149 : : /** Checks and eventually crops the cell ranges to valid dimensions.
150 : : @descr The start position of the ranges will not be modified. Cell
151 : : ranges that fit partly into valid dimensions are cropped
152 : : accordingly. Cell ranges that do not fit at all, are removed from
153 : : the cell range list.
154 : : @param rScRanges (In/out) The cell range list to check.
155 : : @param bWarn true = Sets the internal flag that produces a warning box
156 : : after loading/saving the file, if at least one of the cell ranges
157 : : contains invalid cells. */
158 : : void ValidateRangeList( ScRangeList& rScRanges, bool bWarn );
159 : :
160 : : /** Converts the passed Calc cell range list to an Excel cell range list.
161 : : @descr The start position of the ranges will not be modified. Cell
162 : : ranges that fit partly into valid dimensions are cropped
163 : : accordingly. Cell ranges that do not fit at all, are not inserted
164 : : into the Excel cell range list.
165 : : @param rXclRanges (Out) The converted Excel cell range list.
166 : : @param rScRanges The Calc cell range list to convert.
167 : : @param bWarn true = Sets the internal flag that produces a warning box
168 : : after loading/saving the file, if at least one of the cell ranges
169 : : contains invalid cells. */
170 : : void ConvertRangeList( XclRangeList& rXclRanges,
171 : : const ScRangeList& rScRanges, bool bWarn );
172 : : };
173 : :
174 : : // EditEngine->String conversion ==============================================
175 : :
176 : : class SvxURLField;
177 : : class XclExpHyperlink;
178 : :
179 : : /** Helper to create HLINK records during creation of formatted cell strings.
180 : :
181 : : In Excel it is not possible to have more than one hyperlink in a cell. This
182 : : helper detects multiple occurrences of hyperlinks and fills a string which
183 : : is used to create a cell note containing all URLs. Only cells containing
184 : : one hyperlink are exported as hyperlink cells.
185 : : */
186 : : class XclExpHyperlinkHelper : protected XclExpRoot
187 : : {
188 : : public:
189 : : typedef boost::shared_ptr< XclExpHyperlink > XclExpHyperlinkRef;
190 : :
191 : : explicit XclExpHyperlinkHelper( const XclExpRoot& rRoot, const ScAddress& rScPos );
192 : : ~XclExpHyperlinkHelper();
193 : :
194 : : /** Processes the passed URL field (tries to create a HLINK record).
195 : : @return The representation string of the URL field. */
196 : : rtl::OUString ProcessUrlField( const SvxURLField& rUrlField );
197 : :
198 : : /** Returns true, if a single HLINK record has been created. */
199 : : bool HasLinkRecord() const;
200 : : /** Returns the craeted single HLINk record, or an empty reference. */
201 : : XclExpHyperlinkRef GetLinkRecord();
202 : :
203 : : /** Returns true, if multiple URLs have been processed. */
204 : 0 : inline bool HasMultipleUrls() const { return mbMultipleUrls; }
205 : : /** Returns a string containing all processed URLs. */
206 : 0 : inline const String& GetUrlList() { return maUrlList; }
207 : :
208 : : private:
209 : : XclExpHyperlinkRef mxLinkRec; /// Created HLINK record.
210 : : ScAddress maScPos; /// Cell position to set at the HLINK record.
211 : : String maUrlList; /// List with all processed URLs.
212 : : bool mbMultipleUrls; /// true = Multiple URL fields processed.
213 : : };
214 : :
215 : : // ----------------------------------------------------------------------------
216 : :
217 : : class EditEngine;
218 : : class EditTextObject;
219 : : class SdrTextObj;
220 : : class ScStringCell;
221 : : class ScEditCell;
222 : : class ScPatternAttr;
223 : :
224 : : /** This class provides methods to create an XclExpString.
225 : : @descr The string can be created from an edit engine text object or
226 : : directly from a Calc edit cell. */
227 : : class XclExpStringHelper : boost::noncopyable
228 : : {
229 : : public:
230 : : /** Creates a new unformatted string from the passed string.
231 : : @descr Creates a Unicode string or a byte string, depending on the
232 : : current BIFF version contained in the passed XclExpRoot object.
233 : : @param rString The source string.
234 : : @param nFlags Modifiers for string export.
235 : : @param nMaxLen The maximum number of characters to store in this string.
236 : : @return The new string object (shared pointer). */
237 : : static XclExpStringRef CreateString(
238 : : const XclExpRoot& rRoot,
239 : : const String& rString,
240 : : XclStrFlags nFlags = EXC_STR_DEFAULT,
241 : : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
242 : :
243 : : /** Creates a new unformatted string from the passed character.
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 cChar The source character. The NUL character is explicitly allowed.
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 : : sal_Unicode cChar,
253 : : XclStrFlags nFlags = EXC_STR_DEFAULT,
254 : : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
255 : :
256 : : /** Appends an unformatted string to an Excel string object.
257 : : @descr Selects the correct Append() function depending on the current
258 : : BIFF version contained in the passed XclExpRoot object.
259 : : @param rXclString The Excel string object.
260 : : @param rString The source string. */
261 : : static void AppendString(
262 : : XclExpString& rXclString,
263 : : const XclExpRoot& rRoot,
264 : : const String& rString );
265 : :
266 : : /** Appends a character to an Excel string object.
267 : : @descr Selects the correct Append() function depending on the current
268 : : BIFF version contained in the passed XclExpRoot object.
269 : : @param rXclString The Excel string object.
270 : : @param rString The source string. */
271 : : static void AppendChar(
272 : : XclExpString& rXclString,
273 : : const XclExpRoot& rRoot,
274 : : sal_Unicode cChar );
275 : :
276 : : /** Creates a new formatted string from a Calc string cell.
277 : : @descr Creates a Unicode string or a byte string, depending on the
278 : : current BIFF version contained in the passed XclExpRoot object.
279 : : May create a formatted string object, if the cell text contains
280 : : different script types.
281 : : @param rStringCell The Calc string cell object.
282 : : @param pCellAttr The set item containing the cell formatting.
283 : : @param nFlags Modifiers for string export.
284 : : @param nMaxLen The maximum number of characters to store in this string.
285 : : @return The new string object (shared pointer). */
286 : : static XclExpStringRef CreateCellString(
287 : : const XclExpRoot& rRoot,
288 : : const ScStringCell& rStringCell,
289 : : const ScPatternAttr* pCellAttr,
290 : : XclStrFlags nFlags = EXC_STR_DEFAULT,
291 : : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
292 : :
293 : : /** Creates a new formatted string from a Calc edit cell.
294 : : @descr Creates a Unicode string or a byte string, depending on the
295 : : current BIFF version contained in the passed XclExpRoot object.
296 : : @param rEditCell The Calc edit cell object.
297 : : @param pCellAttr The set item containing the cell formatting.
298 : : @param rLinkHelper Helper object for hyperlink conversion.
299 : : @param nFlags Modifiers for string export.
300 : : @param nMaxLen The maximum number of characters to store in this string.
301 : : @return The new string object (shared pointer). */
302 : : static XclExpStringRef CreateCellString(
303 : : const XclExpRoot& rRoot,
304 : : const ScEditCell& rEditCell,
305 : : const ScPatternAttr* pCellAttr,
306 : : XclExpHyperlinkHelper& rLinkHelper,
307 : : XclStrFlags nFlags = EXC_STR_DEFAULT,
308 : : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
309 : :
310 : : /** Creates a new formatted string from a drawing text box.
311 : : @descr Creates a Unicode string or a byte string, depending on the
312 : : current BIFF version contained in the passed XclExpRoot object.
313 : : @param rTextObj The text box object.
314 : : @param nFlags Modifiers for string export.
315 : : @param nMaxLen The maximum number of characters to store in this string.
316 : : @return The new string object (shared pointer). */
317 : : static XclExpStringRef CreateString(
318 : : const XclExpRoot& rRoot,
319 : : const SdrTextObj& rTextObj,
320 : : XclStrFlags nFlags = EXC_STR_DEFAULT,
321 : : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
322 : :
323 : : /** Creates a new formatted string from a edit text string.
324 : : @param rEditObj The edittext object.
325 : : @param nFlags Modifiers for string export.
326 : : @param nMaxLen The maximum number of characters to store in this string.
327 : : @return The new string object. */
328 : : static XclExpStringRef CreateString(
329 : : const XclExpRoot& rRoot,
330 : : const EditTextObject& rEditObj,
331 : : XclStrFlags nFlags = EXC_STR_DEFAULT,
332 : : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
333 : :
334 : : /** Returns the script type first text portion different to WEAK, or the system
335 : : default script type, if there is only weak script in the passed string. */
336 : : static sal_Int16 GetLeadingScriptType( const XclExpRoot& rRoot, const String& rString );
337 : :
338 : : private:
339 : : /** We don't want anybody to instantiate this class, since it is just a
340 : : collection of static methods. To enforce this, the default constructor
341 : : is made private */
342 : : XclExpStringHelper();
343 : : };
344 : :
345 : : // Header/footer conversion ===================================================
346 : :
347 : : class EditEngine;
348 : :
349 : : /** Converts edit engine text objects to an Excel header/footer string.
350 : : @descr Header/footer content is divided into three parts: Left, center and
351 : : right portion. All formatting information will be encoded in the Excel string
352 : : using special character seuences. A control sequence starts with the ampersand
353 : : character.
354 : :
355 : : Supported control sequences:
356 : : &L start of left portion
357 : : &C start of center portion
358 : : &R start of right portion
359 : : &P current page number
360 : : &N page count
361 : : &D current date
362 : : &T current time
363 : : &A table name
364 : : &F file name without path
365 : : &Z file path without file name
366 : : &Z&F file path and name
367 : : &U underlining on/off
368 : : &E double underlining on/off
369 : : &S strikeout characters on/off
370 : : &X superscript on/off
371 : : &Y subscript on/off
372 : : &"fontname,fontstyle" use font with name 'fontname' and style 'fontstyle'
373 : : &fontheight set font height in points ('fontheight' is a decimal value)
374 : :
375 : : Known but unsupported control sequences:
376 : : &G picture
377 : : */
378 [ # # ][ # # ]: 0 : class XclExpHFConverter : protected XclExpRoot, private boost::noncopyable
379 : : {
380 : : public:
381 : : explicit XclExpHFConverter( const XclExpRoot& rRoot );
382 : :
383 : : /** Generates the header/footer string from the passed edit engine text objects. */
384 : : void GenerateString(
385 : : const EditTextObject* pLeftObj,
386 : : const EditTextObject* pCenterObj,
387 : : const EditTextObject* pRightObj );
388 : :
389 : : /** Returns the last generated header/footer string. */
390 : 0 : inline const String& GetHFString() const { return maHFString; }
391 : : /** Returns the total height of the last generated header/footer in twips. */
392 : 0 : inline sal_Int32 GetTotalHeight() const { return mnTotalHeight; }
393 : :
394 : : private:
395 : : /** Converts the text object contents and stores it in the passed string. */
396 : : void AppendPortion(
397 : : const EditTextObject* pTextObj,
398 : : sal_Unicode cPortionCode );
399 : :
400 : : private:
401 : : EditEngine& mrEE; /// The header/footer edit engine.
402 : : String maHFString; /// The last generated header/footer string.
403 : : sal_Int32 mnTotalHeight; /// Total height of the last header/footer (twips).
404 : : };
405 : :
406 : : // URL conversion =============================================================
407 : :
408 : : /** This class contains static methods to encode a file URL.
409 : : @descr Excel stores URLs in a format that contains special control characters,
410 : : i.e. for directory separators or volume names. */
411 : : class XclExpUrlHelper : boost::noncopyable
412 : : {
413 : : public:
414 : : /** Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
415 : : @param pTableName Optional pointer to a table name to be encoded in this URL. */
416 : : static rtl::OUString EncodeUrl( const XclExpRoot& rRoot, const rtl::OUString& rAbsUrl, const rtl::OUString* pTableName = 0 );
417 : : /** Encodes and returns the passed DDE link to an Excel like DDE link. */
418 : : static rtl::OUString EncodeDde( const rtl::OUString& rApplic, const rtl::OUString& rTopic );
419 : :
420 : : private:
421 : : /** We don't want anybody to instantiate this class, since it is just a
422 : : collection of static methods. To enforce this, the default constructor
423 : : is made private */
424 : : XclExpUrlHelper();
425 : : };
426 : :
427 : : // ----------------------------------------------------------------------------
428 : : class ScMatrix;
429 : :
430 : : /** Contains cached values in a 2-dimensional array. */
431 : : class XclExpCachedMatrix
432 : : {
433 : : void GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
434 : : public:
435 : : /** Constructs and fills a new matrix.
436 : : @param rMatrix The Calc value matrix. */
437 : : explicit XclExpCachedMatrix( const ScMatrix& rMatrix );
438 : : ~XclExpCachedMatrix();
439 : :
440 : : /** Returns the byte count of all contained data. */
441 : : sal_Size GetSize() const;
442 : : /** Writes the complete matrix to stream. */
443 : : void Save( XclExpStream& rStrm ) const;
444 : :
445 : : private:
446 : : const ScMatrix& mrMatrix;
447 : : };
448 : :
449 : : // ============================================================================
450 : :
451 : : #endif
452 : :
453 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|