LibreOffice Module sc (master)  1
xihelper.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_XIHELPER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XIHELPER_HXX
22 
23 #include <editeng/editdata.hxx>
24 #include <types.hxx>
25 #include "xladdress.hxx"
26 #include "xiroot.hxx"
27 #include "xltools.hxx"
28 #include <memory>
29 #include <vector>
30 
31 class ScRangeList;
32 
33 namespace svl {
34 
35 class SharedStringPool;
36 
37 }
38 
39 // Excel->Calc cell address/range conversion ==================================
40 
43 {
44 public:
45  explicit XclImpAddressConverter( const XclImpRoot& rRoot );
46 
47  // cell address -----------------------------------------------------------
48 
54  bool CheckAddress( const XclAddress& rXclPos, bool bWarn );
55 
62  bool ConvertAddress( ScAddress& rScPos,
63  const XclAddress& rXclPos, SCTAB nScTab, bool bWarn );
64 
70  ScAddress CreateValidAddress( const XclAddress& rXclPos,
71  SCTAB nScTab, bool bWarn );
72 
73  // cell range -------------------------------------------------------------
74 
81  bool ConvertRange( ScRange& rScRange, const XclRange& rXclRange,
82  SCTAB nScTab1, SCTAB nScTab2, bool bWarn );
83 
84  // cell range list --------------------------------------------------------
85 
96  void ConvertRangeList( ScRangeList& rScRanges,
97  const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn );
98 };
99 
100 // String->EditEngine conversion ==============================================
101 
102 class EditTextObject;
103 
108 {
109 public:
111  XclImpStringHelper(const XclImpStringHelper&) = delete;
113  const XclImpStringHelper& operator=(const XclImpStringHelper&) = delete;
116  XclImpStringHelper() = delete;
119  static std::unique_ptr<EditTextObject> CreateTextObject(
120  const XclImpRoot& rRoot,
121  const XclImpString& rString );
122 
123  static void SetToDocument(
124  ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot,
125  const XclImpString& rString, sal_uInt16 nXFIndex );
126 };
127 
128 // Header/footer conversion ===================================================
129 
130 class EditEngine;
131 class SfxItemSet;
132 class SvxFieldItem;
133 struct XclFontData;
134 
164 class XclImpHFConverter : protected XclImpRoot
165 {
166 public:
168  XclImpHFConverter(const XclImpHFConverter&) = delete;
170  const XclImpHFConverter& operator=(const XclImpHFConverter&) = delete;
171 
172  explicit XclImpHFConverter( const XclImpRoot& rRoot );
173  virtual ~XclImpHFConverter() override;
174 
176  void ParseString( const OUString& rHFString );
177 
179  void FillToItemSet( SfxItemSet& rItemSet, sal_uInt16 nWhichId ) const;
181  sal_Int32 GetTotalHeight() const;
182 
183 private: // types
184  typedef ::std::unique_ptr< XclFontData > XclFontDataPtr;
185 
188 
191  {
192  typedef std::shared_ptr< EditTextObject > EditTextObjectRef;
193  EditTextObjectRef mxObj;
195  sal_Int32 mnHeight;
196  sal_uInt16 mnMaxLineHt;
197  explicit XclImpHFPortionInfo();
198  };
199 
200 private:
207 
209  sal_uInt16 GetMaxLineHeight( XclImpHFPortion ePortion ) const;
210 
212  void UpdateMaxLineHeight( XclImpHFPortion ePortion );
215 
219  void SetAttribs();
221  void ResetFontData();
222 
226  void InsertText();
228  void InsertField( const SvxFieldItem& rFieldItem );
230  void InsertLineBreak();
231 
233  void CreateCurrObject();
236  void SetNewPortion( XclImpHFPortion eNew );
237 
238 private:
240  std::vector< XclImpHFPortionInfo >
242  OUStringBuffer maCurrText;
243  XclFontDataPtr mxFontData;
245 };
246 
247 // URL conversion =============================================================
248 
253 {
254 public:
256  XclImpUrlHelper(const XclImpUrlHelper&) = delete;
258  const XclImpUrlHelper& operator=(const XclImpUrlHelper&) = delete;
261  XclImpUrlHelper() = delete;
262 
268  static void DecodeUrl(
269  OUString& rUrl,
270  OUString& rTabName,
271  bool& rbSameWb,
272  const XclImpRoot& rRoot,
273  const OUString& rEncodedUrl );
274 
280  static void DecodeUrl(
281  OUString& rUrl,
282  bool& rbSameWb,
283  const XclImpRoot& rRoot,
284  const OUString& rEncodedUrl );
285 
290  static bool DecodeLink( OUString& rApplic, OUString& rTopic, const OUString& rEncUrl );
291 };
292 
293 // Cached values ==============================================================
294 
295 class ScTokenArray;
296 
300 {
301 public:
303  XclImpCachedValue(const XclImpCachedValue&) = delete;
305  const XclImpCachedValue& operator=(const XclImpCachedValue&) = delete;
307  explicit XclImpCachedValue( XclImpStream& rStrm );
308  virtual ~XclImpCachedValue();
309 
311  sal_uInt8 GetType() const { return mnType; }
313  const OUString& GetString() const { return maStr;}
315  double GetValue() const { return mfValue; }
317  bool GetBool() const { return (mnType == EXC_CACHEDVAL_BOOL) && (mnBoolErr != 0); }
321  FormulaError GetScError() const;
322 
323 protected:
324  typedef ::std::unique_ptr< const ScTokenArray > ScTokenArrayPtr;
325 
326  OUString maStr;
327  double mfValue;
328  ScTokenArrayPtr mxTokArr;
331 };
332 
335 {
336 public:
339 
342 
343 private:
344  typedef std::vector< std::unique_ptr<XclImpCachedValue> > XclImpValueList;
345 
346  XclImpValueList maValueList;
349 };
350 
351 #endif
352 
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~XclImpCachedValue()
Definition: xihelper.cxx:805
This class provides methods to convert an XclImpString.
Definition: xihelper.hxx:107
sal_uInt16 mnMaxLineHt
Height of previous lines in twips.
Definition: xihelper.hxx:196
static std::unique_ptr< EditTextObject > CreateTextObject(const XclImpRoot &rRoot, const XclImpString &rString)
Returns a new edit engine text object.
Definition: xihelper.cxx:217
static bool DecodeLink(OUString &rApplic, OUString &rTopic, const OUString &rEncUrl)
Decodes the passed URL to OLE or DDE link components.
Definition: xihelper.cxx:757
const sal_uInt8 EXC_ERR_NA
Definition: xlconst.hxx:111
void InsertLineBreak()
Inserts a line break and adjusts the current selection object.
Definition: xihelper.cxx:555
XclImpUrlHelper()=delete
We don't want anybody to instantiate this class, since it is just a collection of static methods...
SCSIZE mnScCols
List of cached cell values.
Definition: xihelper.hxx:347
XclImpHFPortionInfo()
Maximum font height for the current text line.
Definition: xihelper.cxx:256
EditEngine & mrEE
Definition: xihelper.hxx:239
XclFontDataPtr mxFontData
Current text to insert into edit engine.
Definition: xihelper.hxx:243
void SetAttribs()
Sets the font attributes at the current selection.
Definition: xihelper.cxx:510
void ResetFontData()
Resets font data to application default font.
Definition: xihelper.cxx:524
sal_uInt16 GetMaxLineHeight(XclImpHFPortion ePortion) const
Returns the maximum line height of the specified portion.
Definition: xihelper.cxx:493
This struct helps reading and writing Excel fonts.
Definition: xlstyle.hxx:286
sal_uInt8 mnType
Boolean value or Excel error code.
Definition: xihelper.hxx:330
void ConvertRangeList(ScRangeList &rScRanges, const XclRangeList &rXclRanges, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell range list to a Calc cell range list.
Definition: xihelper.cxx:125
const sal_uInt8 EXC_CACHEDVAL_ERROR
Definition: xlconst.hxx:119
Accessor class to ScDocument.
static void SetToDocument(ScDocumentImport &rDoc, const ScAddress &rPos, const XclImpRoot &rRoot, const XclImpString &rString, sal_uInt16 nXFIndex)
Definition: xihelper.cxx:223
virtual ~XclImpHFConverter() override
Definition: xihelper.cxx:272
void SetNewPortion(XclImpHFPortion eNew)
Changes current header/footer portion to eNew.
Definition: xihelper.cxx:572
Converts an Excel header/footer string into three edit engine text objects.
Definition: xihelper.hxx:164
Provides functions to convert Excel cell addresses to Calc cell addresses.
Definition: xihelper.hxx:42
const OUString & GetString() const
Returns the cached string value, if this value is a string, else an empty string. ...
Definition: xihelper.hxx:313
double GetValue() const
Returns the cached number, if this value has number type, else 0.0.
Definition: xihelper.hxx:315
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
ScMatrixRef CreateScMatrix(svl::SharedStringPool &rPool) const
Creates a new ScMatrix object and fills it with the contained values.
Definition: xihelper.cxx:855
void UpdateMaxLineHeight(XclImpHFPortion ePortion)
Updates the maximum line height of the specified portion, using the current font size.
Definition: xihelper.cxx:499
void ParseString(const OUString &rHFString)
Parses the passed string and creates three new edit engine text objects.
Definition: xihelper.cxx:276
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:26
double mfValue
Cached value is a string.
Definition: xihelper.hxx:327
SCSIZE mnScRows
Number of cached columns.
Definition: xihelper.hxx:348
sal_uInt8 GetType() const
Returns the type of the cached value (EXC_CACHEDVAL_*).
Definition: xihelper.hxx:311
ESelection maSel
Edit engine text object.
Definition: xihelper.hxx:194
std::shared_ptr< EditTextObject > EditTextObjectRef
Definition: xihelper.hxx:192
ESelection & GetCurrSel()
Returns the current selection.
Definition: xihelper.hxx:206
ScTokenArrayPtr mxTokArr
Cached value is a double.
Definition: xihelper.hxx:328
bool ConvertAddress(ScAddress &rScPos, const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell address to a Calc cell address.
Definition: xihelper.cxx:77
void UpdateCurrMaxLineHeight()
Updates the current maximum line height, using the current font size.
Definition: xihelper.cxx:505
OUStringBuffer maCurrText
Edit engine text objects for all portions.
Definition: xihelper.hxx:242
std::vector< std::unique_ptr< XclImpCachedValue > > XclImpValueList
Definition: xihelper.hxx:344
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:101
XclImpHFPortion meCurrObj
Font data of current text.
Definition: xihelper.hxx:244
const XclImpHFConverter & operator=(const XclImpHFConverter &)=delete
delete copy-assignment operator
const sal_uInt8 EXC_CACHEDVAL_BOOL
Definition: xlconst.hxx:118
bool CheckAddress(const XclAddress &rXclPos, bool bWarn)
Checks if the passed Excel cell address is valid.
Definition: xihelper.cxx:62
::std::unique_ptr< const ScTokenArray > ScTokenArrayPtr
Definition: xihelper.hxx:324
Contains cached values in a 2-dimensional array.
Definition: xihelper.hxx:334
std::vector< XclImpHFPortionInfo > maInfos
The header/footer edit engine.
Definition: xihelper.hxx:241
XclImpStringHelper()=delete
We don't want anybody to instantiate this class, since it is just a collection of static methods...
A 2D cell address struct with Excel column and row indexes.
Definition: xladdress.hxx:30
XclImpCachedMatrix(XclImpStream &rStrm)
Definition: xihelper.cxx:816
sal_uInt8 mnBoolErr
Cached value is a formula or error code or Boolean.
Definition: xihelper.hxx:329
FormulaError
ScAddress CreateValidAddress(const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Returns a valid cell address by moving it into allowed dimensions.
Definition: xihelper.cxx:86
This class contains static methods to decode a URL stored in an Excel file.
Definition: xihelper.hxx:252
XclImpHFPortionInfo::EditTextObjectRef & GetCurrObj()
Returns the current edit engine text object.
Definition: xihelper.hxx:204
unsigned char sal_uInt8
XclImpCachedValue(const XclImpCachedValue &)=delete
delete copy constructor
XclImpHFPortionInfo & GetCurrInfo()
Returns the current edit engine text object.
Definition: xihelper.hxx:202
const XclImpUrlHelper & operator=(const XclImpUrlHelper &)=delete
delete copy-assignment operator
XclImpHFPortion
Enumerates the supported header/footer portions.
Definition: xihelper.hxx:187
void FillToItemSet(SfxItemSet &rItemSet, sal_uInt16 nWhichId) const
Creates a ScPageHFItem and inserts it into the passed item set.
Definition: xihelper.cxx:473
::std::unique_ptr< XclFontData > XclFontDataPtr
Definition: xihelper.hxx:184
sal_uInt8 GetXclError() const
Returns the cached Calc error code, if this value has Error type, else 0.
Definition: xihelper.hxx:319
These need to be in global namespace just like their respective types are.
Contains all information about a header/footer portion.
Definition: xihelper.hxx:190
Base class for import/export address converters.
Definition: xladdress.hxx:139
void InsertField(const SvxFieldItem &rFieldItem)
Inserts the passed text field and adjusts the current selection object.
Definition: xihelper.cxx:547
bool ConvertRange(ScRange &rScRange, const XclRange &rXclRange, SCTAB nScTab1, SCTAB nScTab2, bool bWarn)
Converts the passed Excel cell range to a Calc cell range.
Definition: xihelper.cxx:101
const XclImpCachedValue & operator=(const XclImpCachedValue &)=delete
delete copy-assignment operator
const XclImpStringHelper & operator=(const XclImpStringHelper &)=delete
delete copy-assignment operator
XclImpAddressConverter(const XclImpRoot &rRoot)
Definition: xihelper.cxx:55
sal_Int32 GetTotalHeight() const
Returns the total height of the converted header or footer in twips.
Definition: xihelper.cxx:485
XclImpValueList maValueList
Definition: xihelper.hxx:346
void CreateCurrObject()
Creates the edit engine text object of current portion from edit engine.
Definition: xihelper.cxx:565
bool GetBool() const
Returns the cached Boolean value, if this value has Boolean type, else false.
Definition: xihelper.hxx:317
This class is used to import record oriented streams.
Definition: xistream.hxx:278
XclImpHFConverter(const XclImpHFConverter &)=delete
delete copy constructor
This class stores one cached value of a cached value list (used for instance in CRN, EXTERNNAME, tArray).
Definition: xihelper.hxx:299
void SvStream & rStrm
Access to global data from other classes.
Definition: xiroot.hxx:126
FormulaError GetScError() const
Returns the cached Calc error code, if this value has Error type, else 0.
Definition: xihelper.cxx:809
This class represents an unformatted or formatted string and provides importing from stream...
Definition: xistring.hxx:31
sal_Int32 mnHeight
Edit engine selection.
Definition: xihelper.hxx:195
void InsertText()
Inserts maCurrText into edit engine and adjusts the current selection object.
Definition: xihelper.cxx:535
A 2D cell range address struct with Excel column and row indexes.
Definition: xladdress.hxx:58
sal_Int16 SCTAB
Definition: types.hxx:23
static void DecodeUrl(OUString &rUrl, OUString &rTabName, bool &rbSameWb, const XclImpRoot &rRoot, const OUString &rEncodedUrl)
Decodes an encoded external document URL with optional sheet name.
Definition: xihelper.cxx:603