LibreOffice Module sc (master)  1
xehelper.hxx
Go to the documentation of this file.
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 INCLUDED_SC_SOURCE_FILTER_INC_XEHELPER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XEHELPER_HXX
22 
23 #include <memory>
24 #include <rangelst.hxx>
25 #include "xladdress.hxx"
26 #include "xeroot.hxx"
27 #include "xlstring.hxx"
28 
29 // Export progress bar ========================================================
30 
31 class ScfProgressBar;
32 
41 class XclExpProgressBar : protected XclExpRoot
42 {
43 public:
44  explicit XclExpProgressBar( const XclExpRoot& rRoot );
45  virtual ~XclExpProgressBar() override;
46 
48  void Initialize();
49 
51  void IncRowRecordCount();
52 
57 
59  void Progress();
60 
61 private:
62  typedef std::unique_ptr< ScfProgressBar > ScfProgressBarPtr;
63 
64  ScfProgressBarPtr mxProgress;
66 
69 
71  sal_Int32 mnSegRowFinal;
72 
73  std::size_t mnRowCount;
74 };
75 
76 // Calc->Excel cell address/range conversion ==================================
77 
80 {
81 public:
82  explicit XclExpAddressConverter( const XclExpRoot& rRoot );
83 
84  // cell address -----------------------------------------------------------
85 
91  bool CheckAddress( const ScAddress& rScPos, bool bWarn );
92 
99  bool ConvertAddress( XclAddress& rXclPos,
100  const ScAddress& rScPos, bool bWarn );
101 
107  XclAddress CreateValidAddress( const ScAddress& rScPos, bool bWarn );
108 
109  // cell range -------------------------------------------------------------
110 
116  bool CheckRange( const ScRange& rScRange, bool bWarn );
117 
126  bool ValidateRange( ScRange& rScRange, bool bWarn );
127 
134  bool ConvertRange( XclRange& rXclRange, const ScRange& rScRange, bool bWarn );
135 
136  // cell range list --------------------------------------------------------
137 
147  void ValidateRangeList( ScRangeList& rScRanges, bool bWarn );
148 
159  void ConvertRangeList( XclRangeList& rXclRanges,
160  const ScRangeList& rScRanges, bool bWarn );
161 };
162 
163 // EditEngine->String conversion ==============================================
164 
165 class SvxURLField;
166 class XclExpHyperlink;
167 
176 {
177 public:
179 
180  explicit XclExpHyperlinkHelper( const XclExpRoot& rRoot, const ScAddress& rScPos );
181  virtual ~XclExpHyperlinkHelper() override;
182 
185  OUString ProcessUrlField( const SvxURLField& rUrlField );
186 
188  bool HasLinkRecord() const;
190  XclExpHyperlinkRef GetLinkRecord() const;
191 
193  bool HasMultipleUrls() const { return mbMultipleUrls; }
195  const OUString& GetUrlList() const { return maUrlList; }
196 
197 private:
198  XclExpHyperlinkRef mxLinkRec;
200  OUString maUrlList;
202 };
203 
204 class EditEngine;
205 class EditTextObject;
206 class SdrTextObj;
207 class ScPatternAttr;
208 
213 {
214 public:
216  XclExpStringHelper(const XclExpStringHelper &) = delete;
218  const XclExpStringHelper& operator=(const XclExpStringHelper&) = delete;
221  XclExpStringHelper() = delete;
222 
231  const XclExpRoot& rRoot,
232  const OUString& rString,
234  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
235 
244  const XclExpRoot& rRoot,
245  sal_Unicode cChar,
247  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
248 
254  static void AppendString(
255  XclExpString& rXclString,
256  const XclExpRoot& rRoot,
257  const OUString& rString );
258 
264  static void AppendChar(
265  XclExpString& rXclString,
266  const XclExpRoot& rRoot,
267  sal_Unicode cChar );
268 
280  const XclExpRoot& rRoot,
281  const OUString& rString,
282  const ScPatternAttr* pCellAttr,
284  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
285 
296  const XclExpRoot& rRoot,
297  const EditTextObject& rEditText,
298  const ScPatternAttr* pCellAttr,
299  XclExpHyperlinkHelper& rLinkHelper,
301  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
302 
310  const XclExpRoot& rRoot,
311  const SdrTextObj& rTextObj,
312  XclStrFlags nFlags = XclStrFlags::NONE );
313 
319  const XclExpRoot& rRoot,
320  const EditTextObject& rEditObj,
321  XclStrFlags nFlags = XclStrFlags::NONE );
322 
325  static sal_Int16 GetLeadingScriptType( const XclExpRoot& rRoot, const OUString& rString );
326 };
327 
328 // Header/footer conversion ===================================================
329 
359 class XclExpHFConverter : protected XclExpRoot
360 {
361 public:
363  XclExpHFConverter(const XclExpHFConverter&) = delete;
365  const XclExpHFConverter& operator=(const XclExpHFConverter&) = delete;
366 
367  explicit XclExpHFConverter( const XclExpRoot& rRoot );
368 
370  void GenerateString(
371  const EditTextObject* pLeftObj,
372  const EditTextObject* pCenterObj,
373  const EditTextObject* pRightObj );
374 
376  const OUString& GetHFString() const { return maHFString; }
378  sal_Int32 GetTotalHeight() const { return mnTotalHeight; }
379 
380 private:
382  void AppendPortion(
383  const EditTextObject* pTextObj,
384  sal_Unicode cPortionCode );
385 
386 private:
388  OUString maHFString;
389  sal_Int32 mnTotalHeight;
390 };
391 
392 // URL conversion =============================================================
393 
398 {
399 public:
401  XclExpUrlHelper(const XclExpUrlHelper&) = delete;
403  const XclExpUrlHelper& operator=(const XclExpUrlHelper&) = delete;
406  XclExpUrlHelper() = delete;
407 
410  static OUString EncodeUrl( const XclExpRoot& rRoot, const OUString& rAbsUrl, const OUString* pTableName = nullptr );
412  static OUString EncodeDde( const OUString& rApplic, const OUString& rTopic );
413 };
414 
415 class ScMatrix;
416 
419 {
420  void GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
421 public:
424  explicit XclExpCachedMatrix( const ScMatrix& rMatrix );
426 
428  std::size_t GetSize() const;
430  void Save( XclExpStream& rStrm ) const;
431 
432 private:
434 };
435 
436 #endif
437 
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< XclExpHyperlink > XclExpHyperlinkRef
Definition: xehelper.hxx:178
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:113
static OUString EncodeUrl(const XclExpRoot &rRoot, const OUString &rAbsUrl, const OUString *pTableName=nullptr)
Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
Definition: xehelper.cxx:976
void ConvertRangeList(XclRangeList &rXclRanges, const ScRangeList &rScRanges, bool bWarn)
Converts the passed Calc cell range list to an Excel cell range list.
Definition: xehelper.cxx:265
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:43
const sal_uInt16 EXC_STR_MAXLEN
Definition: xlstring.hxx:43
XclExpHyperlinkRef mxLinkRec
Definition: xehelper.hxx:198
sal_Int32 mnSegRowFinal
Sub progress bar for finalizing ROW records.
Definition: xehelper.hxx:71
bool ConvertRange(XclRange &rXclRange, const ScRange &rScRange, bool bWarn)
Converts the passed Calc cell range to an Excel cell range.
Definition: xehelper.cxx:231
The main progress bar for the export filter.
Definition: xehelper.hxx:41
XclExpAddressConverter(const XclExpRoot &rRoot)
Definition: xehelper.cxx:158
void ActivateCreateRowsSegment()
Activates the progress segment to create ROW records.
Definition: xehelper.cxx:112
This class is used to export Excel record streams.
Definition: xestream.hxx:71
XclStrFlags
Flags used to specify import/export mode of strings.
Definition: xlstring.hxx:29
void Initialize()
Initializes all segments and sub progress bars.
Definition: xehelper.cxx:77
ScAddress maScPos
Created HLINK record.
Definition: xehelper.hxx:199
void Progress()
Increases the currently activated (sub) progress bar by 1 step.
Definition: xehelper.cxx:139
bool CheckRange(const ScRange &rScRange, bool bWarn)
Checks if the passed cell range is valid (checks start and end position).
Definition: xehelper.cxx:205
ScfProgressBarPtr mxProgress
Definition: xehelper.hxx:64
ScfProgressBar * mpSubRowCreate
Current sub progress bar.
Definition: xehelper.hxx:67
EditEngine & mrEE
Definition: xehelper.hxx:387
void ActivateFinalRowsSegment()
Activates the progress segment to finalize ROW records.
Definition: xehelper.cxx:127
XclExpHFConverter(const XclExpHFConverter &)=delete
delete copy constructor
XclExpCachedMatrix(const ScMatrix &rMatrix)
Constructs and fills a new matrix.
Definition: xehelper.cxx:990
const XclExpStringHelper & operator=(const XclExpStringHelper &)=delete
remove copy-assignment operator
const OUString & GetUrlList() const
Returns a string containing all processed URLs.
Definition: xehelper.hxx:195
sal_uInt16 sal_Unicode
Access to global data from other classes.
Definition: xeroot.hxx:113
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:45
Helper to create HLINK records during creation of formatted cell strings.
Definition: xehelper.hxx:175
bool mbMultipleUrls
List with all processed URLs.
Definition: xehelper.hxx:201
ScfInt32Vec maSubSegRowCreate
Sub progress bar for creating table rows.
Definition: xehelper.hxx:68
void GenerateString(const EditTextObject *pLeftObj, const EditTextObject *pCenterObj, const EditTextObject *pRightObj)
Generates the header/footer string from the passed edit engine text objects.
Definition: xehelper.cxx:667
XclAddress CreateValidAddress(const ScAddress &rScPos, bool bWarn)
Returns a valid cell address by moving it into allowed dimensions.
Definition: xehelper.cxx:195
void GetDimensions(SCSIZE &nCols, SCSIZE &nRows) const
Definition: xehelper.cxx:1000
std::size_t GetSize() const
Returns the byte count of all contained data.
Definition: xehelper.cxx:1008
void IncRowRecordCount()
Increases the number of existing ROW records by 1.
Definition: xehelper.cxx:107
XclExpHyperlinkHelper(const XclExpRoot &rRoot, const ScAddress &rScPos)
Definition: xehelper.cxx:291
Contains cached values in a 2-dimensional array.
Definition: xehelper.hxx:418
OUString maHFString
The header/footer edit engine.
Definition: xehelper.hxx:388
XclExpHyperlinkRef GetLinkRecord() const
Returns the created single HLINk record, or an empty reference.
Definition: xehelper.cxx:329
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:101
bool HasMultipleUrls() const
Returns true, if multiple URLs have been processed.
Definition: xehelper.hxx:193
const ScMatrix & mrMatrix
Definition: xehelper.hxx:433
static sal_Int16 GetLeadingScriptType(const XclExpRoot &rRoot, const OUString &rString)
Returns the script type first text portion different to WEAK, or the system default script type...
Definition: xehelper.cxx:643
std::unique_ptr< ScfProgressBar > ScfProgressBarPtr
Definition: xehelper.hxx:62
OUString maUrlList
Cell position to set at the HLINK record.
Definition: xehelper.hxx:200
A 2D cell address struct with Excel column and row indexes.
Definition: xladdress.hxx:30
bool HasLinkRecord() const
Returns true, if a single HLINK record has been created.
Definition: xehelper.cxx:324
Progress bar for complex progress representation.
This class contains static methods to encode a file URL.
Definition: xehelper.hxx:397
static void AppendString(XclExpString &rXclString, const XclExpRoot &rRoot, const OUString &rString)
Appends an unformatted string to an Excel string object.
Definition: xehelper.cxx:545
sal_Int32 GetTotalHeight() const
Returns the total height of the last generated header/footer in twips.
Definition: xehelper.hxx:378
static OUString EncodeDde(const OUString &rApplic, const OUString &rTopic)
Encodes and returns the passed DDE link to an Excel like DDE link.
Definition: xehelper.cxx:983
bool ValidateRange(ScRange &rScRange, bool bWarn)
Checks and eventually crops the cell range to valid dimensions.
Definition: xehelper.cxx:210
virtual ~XclExpProgressBar() override
Definition: xehelper.cxx:73
ScfProgressBar * mpSubProgress
Progress bar implementation.
Definition: xehelper.hxx:65
const XclExpUrlHelper & operator=(const XclExpUrlHelper &)=delete
delete copy-assignment operator
Provides functions to convert Calc cell addresses to Excel cell addresses.
Definition: xehelper.hxx:79
std::size_t mnRowCount
Progress segment for finalizing ROW records.
Definition: xehelper.hxx:73
sal_Int32 mnTotalHeight
The last generated header/footer string.
Definition: xehelper.hxx:389
static XclExpStringRef CreateCellString(const XclExpRoot &rRoot, const OUString &rString, const ScPatternAttr *pCellAttr, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Creates a new formatted string from a Calc string cell.
Definition: xehelper.cxx:561
XclExpProgressBar(const XclExpRoot &rRoot)
Definition: xehelper.cxx:62
const OUString & GetHFString() const
Returns the last generated header/footer string.
Definition: xehelper.hxx:376
void AppendPortion(const EditTextObject *pTextObj, sal_Unicode cPortionCode)
Converts the text object contents and stores it in the passed string.
Definition: xehelper.cxx:679
static void AppendChar(XclExpString &rXclString, const XclExpRoot &rRoot, sal_Unicode cChar)
Appends a character to an Excel string object.
Definition: xehelper.cxx:553
void Save(XclExpStream &rStrm) const
Writes the complete matrix to stream.
Definition: xehelper.cxx:1020
const XclExpHFConverter & operator=(const XclExpHFConverter &)=delete
delete copy-assignment operator
Base class for import/export address converters.
Definition: xladdress.hxx:139
OUString ProcessUrlField(const SvxURLField &rUrlField)
Processes the passed URL field (tries to create a HLINK record).
Definition: xehelper.cxx:302
This class provides methods to create an XclExpString.
Definition: xehelper.hxx:212
void ValidateRangeList(ScRangeList &rScRanges, bool bWarn)
Checks and eventually crops the cell ranges to valid dimensions.
Definition: xehelper.cxx:255
static XclExpStringRef CreateString(const XclExpRoot &rRoot, const OUString &rString, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Creates a new unformatted string from the passed string.
Definition: xehelper.cxx:526
XclExpStringHelper()=delete
We don't want anybody to instantiate this class, since it is just a collection of static methods...
std::shared_ptr< XclExpString > XclExpStringRef
Definition: xeroot.hxx:36
::std::vector< sal_Int32 > ScfInt32Vec
Definition: ftools.hxx:255
ScfProgressBar * mpSubRowFinal
Segment ID's for all sheets in sub progress bar.
Definition: xehelper.hxx:70
void SvStream & rStrm
Converts edit engine text objects to an Excel header/footer string.
Definition: xehelper.hxx:359
virtual ~XclExpHyperlinkHelper() override
Definition: xehelper.cxx:298
XclExpUrlHelper()=delete
We don't want anybody to instantiate this class, since it is just a collection of static methods...
bool CheckAddress(const ScAddress &rScPos, bool bWarn)
Checks if the passed Calc cell address is valid.
Definition: xehelper.cxx:165
bool ConvertAddress(XclAddress &rXclPos, const ScAddress &rScPos, bool bWarn)
Converts the passed Calc cell address to an Excel cell address.
Definition: xehelper.cxx:186
A 2D cell range address struct with Excel column and row indexes.
Definition: xladdress.hxx:58