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