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 2 : 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 : rtl::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 ScStringCell;
212 : class ScEditCell;
213 : class ScPatternAttr;
214 :
215 : /** This class provides methods to create an XclExpString.
216 : @descr The string can be created from an edit engine text object or
217 : directly from a Calc edit cell. */
218 : class XclExpStringHelper : boost::noncopyable
219 : {
220 : public:
221 : /** Creates a new unformatted string from the passed string.
222 : @descr Creates a Unicode string or a byte string, depending on the
223 : current BIFF version contained in the passed XclExpRoot object.
224 : @param rString The source string.
225 : @param nFlags Modifiers for string export.
226 : @param nMaxLen The maximum number of characters to store in this string.
227 : @return The new string object (shared pointer). */
228 : static XclExpStringRef CreateString(
229 : const XclExpRoot& rRoot,
230 : const String& rString,
231 : XclStrFlags nFlags = EXC_STR_DEFAULT,
232 : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
233 :
234 : /** Creates a new unformatted string from the passed character.
235 : @descr Creates a Unicode string or a byte string, depending on the
236 : current BIFF version contained in the passed XclExpRoot object.
237 : @param cChar The source character. The NUL character is explicitly allowed.
238 : @param nFlags Modifiers for string export.
239 : @param nMaxLen The maximum number of characters to store in this string.
240 : @return The new string object (shared pointer). */
241 : static XclExpStringRef CreateString(
242 : const XclExpRoot& rRoot,
243 : sal_Unicode cChar,
244 : XclStrFlags nFlags = EXC_STR_DEFAULT,
245 : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
246 :
247 : /** Appends an unformatted string to an Excel string object.
248 : @descr Selects the correct Append() function depending on the current
249 : BIFF version contained in the passed XclExpRoot object.
250 : @param rXclString The Excel string object.
251 : @param rString The source string. */
252 : static void AppendString(
253 : XclExpString& rXclString,
254 : const XclExpRoot& rRoot,
255 : const String& rString );
256 :
257 : /** Appends a character to an Excel string object.
258 : @descr Selects the correct Append() function depending on the current
259 : BIFF version contained in the passed XclExpRoot object.
260 : @param rXclString The Excel string object.
261 : @param rString The source string. */
262 : static void AppendChar(
263 : XclExpString& rXclString,
264 : const XclExpRoot& rRoot,
265 : sal_Unicode cChar );
266 :
267 : /** Creates a new formatted string from a Calc string cell.
268 : @descr Creates a Unicode string or a byte string, depending on the
269 : current BIFF version contained in the passed XclExpRoot object.
270 : May create a formatted string object, if the cell text contains
271 : different script types.
272 : @param rStringCell The Calc string cell object.
273 : @param pCellAttr The set item containing the cell formatting.
274 : @param nFlags Modifiers for string export.
275 : @param nMaxLen The maximum number of characters to store in this string.
276 : @return The new string object (shared pointer). */
277 : static XclExpStringRef CreateCellString(
278 : const XclExpRoot& rRoot,
279 : const ScStringCell& rStringCell,
280 : const ScPatternAttr* pCellAttr,
281 : XclStrFlags nFlags = EXC_STR_DEFAULT,
282 : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
283 :
284 : /** Creates a new formatted string from a Calc edit cell.
285 : @descr Creates a Unicode string or a byte string, depending on the
286 : current BIFF version contained in the passed XclExpRoot object.
287 : @param rEditCell The Calc edit cell object.
288 : @param pCellAttr The set item containing the cell formatting.
289 : @param rLinkHelper Helper object for hyperlink conversion.
290 : @param nFlags Modifiers for string export.
291 : @param nMaxLen The maximum number of characters to store in this string.
292 : @return The new string object (shared pointer). */
293 : static XclExpStringRef CreateCellString(
294 : const XclExpRoot& rRoot,
295 : const ScEditCell& rEditCell,
296 : const ScPatternAttr* pCellAttr,
297 : XclExpHyperlinkHelper& rLinkHelper,
298 : XclStrFlags nFlags = EXC_STR_DEFAULT,
299 : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
300 :
301 : /** Creates a new formatted string from a drawing text box.
302 : @descr Creates a Unicode string or a byte string, depending on the
303 : current BIFF version contained in the passed XclExpRoot object.
304 : @param rTextObj The text box object.
305 : @param nFlags Modifiers for string export.
306 : @param nMaxLen The maximum number of characters to store in this string.
307 : @return The new string object (shared pointer). */
308 : static XclExpStringRef CreateString(
309 : const XclExpRoot& rRoot,
310 : const SdrTextObj& rTextObj,
311 : XclStrFlags nFlags = EXC_STR_DEFAULT,
312 : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
313 :
314 : /** Creates a new formatted string from a edit text string.
315 : @param rEditObj The edittext object.
316 : @param nFlags Modifiers for string export.
317 : @param nMaxLen The maximum number of characters to store in this string.
318 : @return The new string object. */
319 : static XclExpStringRef CreateString(
320 : const XclExpRoot& rRoot,
321 : const EditTextObject& rEditObj,
322 : XclStrFlags nFlags = EXC_STR_DEFAULT,
323 : sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
324 :
325 : /** Returns the script type first text portion different to WEAK, or the system
326 : default script type, if there is only weak script in the passed string. */
327 : static sal_Int16 GetLeadingScriptType( const XclExpRoot& rRoot, const String& rString );
328 :
329 : private:
330 : /** We don't want anybody to instantiate this class, since it is just a
331 : collection of static methods. To enforce this, the default constructor
332 : is made private */
333 : XclExpStringHelper();
334 : };
335 :
336 : // Header/footer conversion ===================================================
337 :
338 : class EditEngine;
339 :
340 : /** Converts edit engine text objects to an Excel header/footer string.
341 : @descr Header/footer content is divided into three parts: Left, center and
342 : right portion. All formatting information will be encoded in the Excel string
343 : using special character seuences. A control sequence starts with the ampersand
344 : character.
345 :
346 : Supported control sequences:
347 : &L start of left portion
348 : &C start of center portion
349 : &R start of right portion
350 : &P current page number
351 : &N page count
352 : &D current date
353 : &T current time
354 : &A table name
355 : &F file name without path
356 : &Z file path without file name
357 : &Z&F file path and name
358 : &U underlining on/off
359 : &E double underlining on/off
360 : &S strikeout characters on/off
361 : &X superscript on/off
362 : &Y subscript on/off
363 : &"fontname,fontstyle" use font with name 'fontname' and style 'fontstyle'
364 : &fontheight set font height in points ('fontheight' is a decimal value)
365 :
366 : Known but unsupported control sequences:
367 : &G picture
368 : */
369 1 : class XclExpHFConverter : protected XclExpRoot, private boost::noncopyable
370 : {
371 : public:
372 : explicit XclExpHFConverter( const XclExpRoot& rRoot );
373 :
374 : /** Generates the header/footer string from the passed edit engine text objects. */
375 : void GenerateString(
376 : const EditTextObject* pLeftObj,
377 : const EditTextObject* pCenterObj,
378 : const EditTextObject* pRightObj );
379 :
380 : /** Returns the last generated header/footer string. */
381 0 : inline const String& GetHFString() const { return maHFString; }
382 : /** Returns the total height of the last generated header/footer in twips. */
383 0 : inline sal_Int32 GetTotalHeight() const { return mnTotalHeight; }
384 :
385 : private:
386 : /** Converts the text object contents and stores it in the passed string. */
387 : void AppendPortion(
388 : const EditTextObject* pTextObj,
389 : sal_Unicode cPortionCode );
390 :
391 : private:
392 : EditEngine& mrEE; /// The header/footer edit engine.
393 : String maHFString; /// The last generated header/footer string.
394 : sal_Int32 mnTotalHeight; /// Total height of the last header/footer (twips).
395 : };
396 :
397 : // URL conversion =============================================================
398 :
399 : /** This class contains static methods to encode a file URL.
400 : @descr Excel stores URLs in a format that contains special control characters,
401 : i.e. for directory separators or volume names. */
402 : class XclExpUrlHelper : boost::noncopyable
403 : {
404 : public:
405 : /** Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
406 : @param pTableName Optional pointer to a table name to be encoded in this URL. */
407 : static rtl::OUString EncodeUrl( const XclExpRoot& rRoot, const rtl::OUString& rAbsUrl, const rtl::OUString* pTableName = 0 );
408 : /** Encodes and returns the passed DDE link to an Excel like DDE link. */
409 : static rtl::OUString EncodeDde( const rtl::OUString& rApplic, const rtl::OUString& rTopic );
410 :
411 : private:
412 : /** We don't want anybody to instantiate this class, since it is just a
413 : collection of static methods. To enforce this, the default constructor
414 : is made private */
415 : XclExpUrlHelper();
416 : };
417 :
418 : // ----------------------------------------------------------------------------
419 : class ScMatrix;
420 :
421 : /** Contains cached values in a 2-dimensional array. */
422 : class XclExpCachedMatrix
423 : {
424 : void GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
425 : public:
426 : /** Constructs and fills a new matrix.
427 : @param rMatrix The Calc value matrix. */
428 : explicit XclExpCachedMatrix( const ScMatrix& rMatrix );
429 : ~XclExpCachedMatrix();
430 :
431 : /** Returns the byte count of all contained data. */
432 : sal_Size GetSize() const;
433 : /** Writes the complete matrix to stream. */
434 : void Save( XclExpStream& rStrm ) const;
435 :
436 : private:
437 : const ScMatrix& mrMatrix;
438 : };
439 :
440 : // ============================================================================
441 :
442 : #endif
443 :
444 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|