LibreOffice Module sc (master)  1
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
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 .
18  */
20 #pragma once
22 #include <editeng/editdata.hxx>
23 #include <types.hxx>
24 #include "xladdress.hxx"
25 #include "xiroot.hxx"
26 #include "xltools.hxx"
27 #include <memory>
28 #include <vector>
30 class ScRangeList;
32 namespace svl {
34 class SharedStringPool;
36 }
38 // Excel->Calc cell address/range conversion ==================================
42 {
43 public:
44  explicit XclImpAddressConverter( const XclImpRoot& rRoot );
46  // cell address -----------------------------------------------------------
53  bool CheckAddress( const XclAddress& rXclPos, bool bWarn );
61  bool ConvertAddress( ScAddress& rScPos,
62  const XclAddress& rXclPos, SCTAB nScTab, bool bWarn );
69  ScAddress CreateValidAddress( const XclAddress& rXclPos,
70  SCTAB nScTab, bool bWarn );
72  // cell range -------------------------------------------------------------
80  bool ConvertRange( ScRange& rScRange, const XclRange& rXclRange,
81  SCTAB nScTab1, SCTAB nScTab2, bool bWarn );
83  // cell range list --------------------------------------------------------
95  void ConvertRangeList( ScRangeList& rScRanges,
96  const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn );
97 };
99 // String->EditEngine conversion ==============================================
101 class EditTextObject;
107 {
108 public:
110  XclImpStringHelper(const XclImpStringHelper&) = delete;
112  const XclImpStringHelper& operator=(const XclImpStringHelper&) = delete;
115  XclImpStringHelper() = delete;
118  static std::unique_ptr<EditTextObject> CreateTextObject(
119  const XclImpRoot& rRoot,
120  const XclImpString& rString );
122  static void SetToDocument(
123  ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot,
124  const XclImpString& rString, sal_uInt16 nXFIndex );
125 };
127 // Header/footer conversion ===================================================
129 class EditEngine;
130 class SfxItemSet;
131 class SvxFieldItem;
132 struct XclFontData;
163 class XclImpHFConverter : protected XclImpRoot
164 {
165 public:
167  XclImpHFConverter(const XclImpHFConverter&) = delete;
169  const XclImpHFConverter& operator=(const XclImpHFConverter&) = delete;
171  explicit XclImpHFConverter( const XclImpRoot& rRoot );
172  virtual ~XclImpHFConverter() override;
175  void ParseString( const OUString& rHFString );
178  void FillToItemSet( SfxItemSet& rItemSet, sal_uInt16 nWhichId ) const;
180  sal_Int32 GetTotalHeight() const;
182 private: // types
183  typedef ::std::unique_ptr< XclFontData > XclFontDataPtr;
190  {
191  typedef std::shared_ptr< EditTextObject > EditTextObjectRef;
192  EditTextObjectRef mxObj;
194  sal_Int32 mnHeight;
195  sal_uInt16 mnMaxLineHt;
196  explicit XclImpHFPortionInfo();
197  };
199 private:
208  sal_uInt16 GetMaxLineHeight( XclImpHFPortion ePortion ) const;
211  void UpdateMaxLineHeight( XclImpHFPortion ePortion );
218  void SetAttribs();
220  void ResetFontData();
225  void InsertText();
227  void InsertField( const SvxFieldItem& rFieldItem );
229  void InsertLineBreak();
232  void CreateCurrObject();
235  void SetNewPortion( XclImpHFPortion eNew );
237 private:
239  std::vector< XclImpHFPortionInfo >
241  OUStringBuffer maCurrText;
242  XclFontDataPtr mxFontData;
244 };
246 // URL conversion =============================================================
252 {
253 public:
255  XclImpUrlHelper(const XclImpUrlHelper&) = delete;
257  const XclImpUrlHelper& operator=(const XclImpUrlHelper&) = delete;
260  XclImpUrlHelper() = delete;
267  static void DecodeUrl(
268  OUString& rUrl,
269  OUString& rTabName,
270  bool& rbSameWb,
271  const XclImpRoot& rRoot,
272  const OUString& rEncodedUrl );
279  static void DecodeUrl(
280  OUString& rUrl,
281  bool& rbSameWb,
282  const XclImpRoot& rRoot,
283  const OUString& rEncodedUrl );
289  static bool DecodeLink( OUString& rApplic, OUString& rTopic, const OUString& rEncUrl );
290 };
292 // Cached values ==============================================================
294 class ScTokenArray;
299 {
300 public:
302  XclImpCachedValue(const XclImpCachedValue&) = delete;
304  const XclImpCachedValue& operator=(const XclImpCachedValue&) = delete;
306  explicit XclImpCachedValue( XclImpStream& rStrm );
307  virtual ~XclImpCachedValue();
310  sal_uInt8 GetType() const { return mnType; }
312  const OUString& GetString() const { return maStr;}
314  double GetValue() const { return mfValue; }
316  bool GetBool() const { return (mnType == EXC_CACHEDVAL_BOOL) && (mnBoolErr != 0); }
320  FormulaError GetScError() const;
322 protected:
323  typedef ::std::unique_ptr< const ScTokenArray > ScTokenArrayPtr;
325  OUString maStr;
326  double mfValue;
327  ScTokenArrayPtr mxTokArr;
330 };
334 {
335 public:
342 private:
343  typedef std::vector< std::unique_ptr<XclImpCachedValue> > XclImpValueList;
345  XclImpValueList maValueList;
348 };
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~XclImpCachedValue()
Definition: xihelper.cxx:805
This class provides methods to convert an XclImpString.
Definition: xihelper.hxx:106
sal_uInt16 mnMaxLineHt
Height of previous lines in twips.
Definition: xihelper.hxx:195
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:110
void InsertLineBreak()
Inserts a line break and adjusts the current selection object.
Definition: xihelper.cxx:555
We don't want anybody to instantiate this class, since it is just a collection of static methods...
List of cached cell values.
Definition: xihelper.hxx:346
Maximum font height for the current text line.
Definition: xihelper.cxx:256
EditEngine & mrEE
Definition: xihelper.hxx:238
XclFontDataPtr mxFontData
Current text to insert into edit engine.
Definition: xihelper.hxx:242
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:285
sal_uInt8 mnType
Boolean value or Excel error code.
Definition: xihelper.hxx:329
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
Definition: xlconst.hxx:118
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:163
Provides functions to convert Excel cell addresses to Calc cell addresses.
Definition: xihelper.hxx:41
const OUString & GetString() const
Returns the cached string value, if this value is a string, else an empty string. ...
Definition: xihelper.hxx:312
double GetValue() const
Returns the cached number, if this value has number type, else 0.0.
Definition: xihelper.hxx:314
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:44
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:25
double mfValue
Cached value is a string.
Definition: xihelper.hxx:326
Number of cached columns.
Definition: xihelper.hxx:347
sal_uInt8 GetType() const
Returns the type of the cached value (EXC_CACHEDVAL_*).
Definition: xihelper.hxx:310
ESelection maSel
Edit engine text object.
Definition: xihelper.hxx:193
std::shared_ptr< EditTextObject > EditTextObjectRef
Definition: xihelper.hxx:191
ESelection & GetCurrSel()
Returns the current selection.
Definition: xihelper.hxx:205
ScTokenArrayPtr mxTokArr
Cached value is a double.
Definition: xihelper.hxx:327
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:241
std::vector< std::unique_ptr< XclImpCachedValue > > XclImpValueList
Definition: xihelper.hxx:343
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:100
XclImpHFPortion meCurrObj
Font data of current text.
Definition: xihelper.hxx:243
const XclImpHFConverter & operator=(const XclImpHFConverter &)=delete
delete copy-assignment operator
const sal_uInt8 EXC_CACHEDVAL_BOOL
Definition: xlconst.hxx:117
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:323
Contains cached values in a 2-dimensional array.
Definition: xihelper.hxx:333
std::vector< XclImpHFPortionInfo > maInfos
The header/footer edit engine.
Definition: xihelper.hxx:240
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:29
XclImpCachedMatrix(XclImpStream &rStrm)
Definition: xihelper.cxx:816
sal_uInt8 mnBoolErr
Cached value is a formula or error code or Boolean.
Definition: xihelper.hxx:328
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:251
XclImpHFPortionInfo::EditTextObjectRef & GetCurrObj()
Returns the current edit engine text object.
Definition: xihelper.hxx:203
unsigned char sal_uInt8
XclImpCachedValue(const XclImpCachedValue &)=delete
delete copy constructor
XclImpHFPortionInfo & GetCurrInfo()
Returns the current edit engine text object.
Definition: xihelper.hxx:201
const XclImpUrlHelper & operator=(const XclImpUrlHelper &)=delete
delete copy-assignment operator
Enumerates the supported header/footer portions.
Definition: xihelper.hxx:186
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:183
sal_uInt8 GetXclError() const
Returns the cached Calc error code, if this value has Error type, else 0.
Definition: xihelper.hxx:318
These need to be in global namespace just like their respective types are.
Contains all information about a header/footer portion.
Definition: xihelper.hxx:189
Base class for import/export address converters.
Definition: xladdress.hxx:138
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:345
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:316
This class is used to import record oriented streams.
Definition: xistream.hxx:277
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:298
void SvStream & rStrm
Access to global data from other classes.
Definition: xiroot.hxx:125
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:30
sal_Int32 mnHeight
Edit engine selection.
Definition: xihelper.hxx:194
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:57
sal_Int16 SCTAB
Definition: types.hxx:22
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