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 <string_view>
25 
26 #include "ftools.hxx"
27 #include <rangelst.hxx>
28 #include "xladdress.hxx"
29 #include "xeroot.hxx"
30 #include "xlstring.hxx"
31 
32 // Export progress bar ========================================================
33 
34 class ScfProgressBar;
35 
44 class XclExpProgressBar : protected XclExpRoot
45 {
46 public:
47  explicit XclExpProgressBar( const XclExpRoot& rRoot );
48  virtual ~XclExpProgressBar() override;
49 
51  void Initialize();
52 
54  void IncRowRecordCount();
55 
60 
62  void Progress();
63 
64 private:
65  typedef std::unique_ptr< ScfProgressBar > ScfProgressBarPtr;
66 
67  ScfProgressBarPtr mxProgress;
69 
72 
74  sal_Int32 mnSegRowFinal;
75 
76  std::size_t mnRowCount;
77 };
78 
79 // Calc->Excel cell address/range conversion ==================================
80 
83 {
84 public:
85  explicit XclExpAddressConverter( const XclExpRoot& rRoot );
86 
87  // cell address -----------------------------------------------------------
88 
94  bool CheckAddress( const ScAddress& rScPos, bool bWarn );
95 
102  bool ConvertAddress( XclAddress& rXclPos,
103  const ScAddress& rScPos, bool bWarn );
104 
110  XclAddress CreateValidAddress( const ScAddress& rScPos, bool bWarn );
111 
112  // cell range -------------------------------------------------------------
113 
119  bool CheckRange( const ScRange& rScRange, bool bWarn );
120 
129  bool ValidateRange( ScRange& rScRange, bool bWarn );
130 
137  bool ConvertRange( XclRange& rXclRange, const ScRange& rScRange, bool bWarn );
138 
139  // cell range list --------------------------------------------------------
140 
150  void ValidateRangeList( ScRangeList& rScRanges, bool bWarn );
151 
162  void ConvertRangeList( XclRangeList& rXclRanges,
163  const ScRangeList& rScRanges, bool bWarn );
164 };
165 
166 // EditEngine->String conversion ==============================================
167 
168 class SvxURLField;
169 class XclExpHyperlink;
170 
179 {
180 public:
182 
183  explicit XclExpHyperlinkHelper( const XclExpRoot& rRoot, const ScAddress& rScPos );
184  virtual ~XclExpHyperlinkHelper() override;
185 
188  OUString ProcessUrlField( const SvxURLField& rUrlField );
189 
191  bool HasLinkRecord() const;
193  XclExpHyperlinkRef GetLinkRecord() const;
194 
196  bool HasMultipleUrls() const { return mbMultipleUrls; }
198  const OUString& GetUrlList() const { return maUrlList; }
199 
200 private:
201  XclExpHyperlinkRef mxLinkRec;
203  OUString maUrlList;
205 };
206 
207 class EditEngine;
208 class EditTextObject;
209 class SdrTextObj;
210 class ScPatternAttr;
211 
216 {
217 public:
219  XclExpStringHelper(const XclExpStringHelper &) = delete;
221  const XclExpStringHelper& operator=(const XclExpStringHelper&) = delete;
224  XclExpStringHelper() = delete;
225 
234  const XclExpRoot& rRoot,
235  const OUString& rString,
237  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
238 
247  const XclExpRoot& rRoot,
248  sal_Unicode cChar,
250  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
251 
257  static void AppendString(
258  XclExpString& rXclString,
259  const XclExpRoot& rRoot,
260  const OUString& rString );
261 
267  static void AppendChar(
268  XclExpString& rXclString,
269  const XclExpRoot& rRoot,
270  sal_Unicode cChar );
271 
283  const XclExpRoot& rRoot,
284  const OUString& rString,
285  const ScPatternAttr* pCellAttr,
287  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
288 
299  const XclExpRoot& rRoot,
300  const EditTextObject& rEditText,
301  const ScPatternAttr* pCellAttr,
302  XclExpHyperlinkHelper& rLinkHelper,
304  sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
305 
313  const XclExpRoot& rRoot,
314  const SdrTextObj& rTextObj,
315  XclStrFlags nFlags = XclStrFlags::NONE );
316 
322  const XclExpRoot& rRoot,
323  const EditTextObject& rEditObj,
324  XclStrFlags nFlags = XclStrFlags::NONE );
325 
328  static sal_Int16 GetLeadingScriptType( const XclExpRoot& rRoot, const OUString& rString );
329 };
330 
331 // Header/footer conversion ===================================================
332 
362 class XclExpHFConverter : protected XclExpRoot
363 {
364 public:
366  XclExpHFConverter(const XclExpHFConverter&) = delete;
368  const XclExpHFConverter& operator=(const XclExpHFConverter&) = delete;
369 
370  explicit XclExpHFConverter( const XclExpRoot& rRoot );
371 
373  void GenerateString(
374  const EditTextObject* pLeftObj,
375  const EditTextObject* pCenterObj,
376  const EditTextObject* pRightObj );
377 
379  const OUString& GetHFString() const { return maHFString; }
381  sal_Int32 GetTotalHeight() const { return mnTotalHeight; }
382 
383 private:
385  void AppendPortion(
386  const EditTextObject* pTextObj,
387  sal_Unicode cPortionCode );
388 
389 private:
391  OUString maHFString;
392  sal_Int32 mnTotalHeight;
393 };
394 
395 // URL conversion =============================================================
396 
401 {
402 public:
404  XclExpUrlHelper(const XclExpUrlHelper&) = delete;
406  const XclExpUrlHelper& operator=(const XclExpUrlHelper&) = delete;
409  XclExpUrlHelper() = delete;
410 
413  static OUString EncodeUrl( const XclExpRoot& rRoot, const OUString& rAbsUrl, const OUString* pTableName = nullptr );
415  static OUString EncodeDde( std::u16string_view rApplic, std::u16string_view rTopic );
416 };
417 
418 class ScMatrix;
419 
422 {
423  void GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
424 public:
427  explicit XclExpCachedMatrix( const ScMatrix& rMatrix );
429 
431  std::size_t GetSize() const;
433  void Save( XclExpStream& rStrm ) const;
434 
435 private:
437 };
438 
439 #endif
440 
441 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< XclExpHyperlink > XclExpHyperlinkRef
Definition: xehelper.hxx:181
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:48
const sal_uInt16 EXC_STR_MAXLEN
Definition: xlstring.hxx:43
XclExpHyperlinkRef mxLinkRec
Definition: xehelper.hxx:201
sal_Int32 mnSegRowFinal
Sub progress bar for finalizing ROW records.
Definition: xehelper.hxx:74
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:44
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:73
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:202
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:67
ScfProgressBar * mpSubRowCreate
Current sub progress bar.
Definition: xehelper.hxx:70
EditEngine & mrEE
Definition: xehelper.hxx:390
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:198
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:178
bool mbMultipleUrls
List with all processed URLs.
Definition: xehelper.hxx:204
ScfInt32Vec maSubSegRowCreate
Sub progress bar for creating table rows.
Definition: xehelper.hxx:71
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:421
OUString maHFString
The header/footer edit engine.
Definition: xehelper.hxx:391
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:196
const ScMatrix & mrMatrix
Definition: xehelper.hxx:436
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:65
OUString maUrlList
Cell position to set at the HLINK record.
Definition: xehelper.hxx:203
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:400
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:381
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:68
const XclExpUrlHelper & operator=(const XclExpUrlHelper &)=delete
delete copy-assignment operator
Provides functions to convert Calc cell addresses to Excel cell addresses.
Definition: xehelper.hxx:82
std::size_t mnRowCount
Progress segment for finalizing ROW records.
Definition: xehelper.hxx:76
sal_Int32 mnTotalHeight
The last generated header/footer string.
Definition: xehelper.hxx:392
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:379
static OUString EncodeDde(std::u16string_view rApplic, std::u16string_view rTopic)
Encodes and returns the passed DDE link to an Excel like DDE link.
Definition: xehelper.cxx:983
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:215
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:257
ScfProgressBar * mpSubRowFinal
Segment ID's for all sheets in sub progress bar.
Definition: xehelper.hxx:73
void SvStream & rStrm
Converts edit engine text objects to an Excel header/footer string.
Definition: xehelper.hxx:362
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