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#pragma once
21
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>
29
30class ScRangeList;
31
32namespace svl {
33
34class SharedStringPool;
35
36}
37
38// Excel->Calc cell address/range conversion ==================================
39
42{
43public:
44 explicit XclImpAddressConverter( const XclImpRoot& rRoot );
45
46 // cell address -----------------------------------------------------------
47
53 bool CheckAddress( const XclAddress& rXclPos, bool bWarn );
54
61 bool ConvertAddress( ScAddress& rScPos,
62 const XclAddress& rXclPos, SCTAB nScTab, bool bWarn );
63
70 SCTAB nScTab, bool bWarn );
71
72 // cell range -------------------------------------------------------------
73
80 bool ConvertRange( ScRange& rScRange, const XclRange& rXclRange,
81 SCTAB nScTab1, SCTAB nScTab2, bool bWarn );
82
83 // cell range list --------------------------------------------------------
84
95 void ConvertRangeList( ScRangeList& rScRanges,
96 const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn );
97};
98
99// String->EditEngine conversion ==============================================
100
101class EditTextObject;
102
107{
108public:
118 static std::unique_ptr<EditTextObject> CreateTextObject(
119 const XclImpRoot& rRoot,
120 const XclImpString& rString );
121
122 static void SetToDocument(
123 ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot,
124 const XclImpString& rString, sal_uInt16 nXFIndex );
125};
126
127// Header/footer conversion ===================================================
128
129class EditEngine;
130class SfxItemSet;
131class SvxFieldItem;
132struct XclFontData;
133
164{
165public:
170
171 explicit XclImpHFConverter( const XclImpRoot& rRoot );
172 virtual ~XclImpHFConverter() override;
173
175 void ParseString( const OUString& rHFString );
176
178 void FillToItemSet( SfxItemSet& rItemSet, sal_uInt16 nWhichId ) const;
180 sal_Int32 GetTotalHeight() const;
181
182private: // types
183 typedef ::std::unique_ptr< XclFontData > XclFontDataPtr;
184
187
190 {
191 typedef std::shared_ptr< EditTextObject > EditTextObjectRef;
194 sal_Int32 mnHeight;
195 sal_uInt16 mnMaxLineHt;
196 explicit XclImpHFPortionInfo();
197 };
198
199private:
206
208 sal_uInt16 GetMaxLineHeight( XclImpHFPortion ePortion ) const;
209
211 void UpdateMaxLineHeight( XclImpHFPortion ePortion );
214
218 void SetAttribs();
220 void ResetFontData();
221
225 void InsertText();
227 void InsertField( const SvxFieldItem& rFieldItem );
229 void InsertLineBreak();
230
232 void CreateCurrObject();
235 void SetNewPortion( XclImpHFPortion eNew );
236
237private:
239 std::vector< XclImpHFPortionInfo >
241 OUStringBuffer maCurrText;
244};
245
246// URL conversion =============================================================
247
252{
253public:
260 XclImpUrlHelper() = delete;
261
267 static void DecodeUrl(
268 OUString& rUrl,
269 OUString& rTabName,
270 bool& rbSameWb,
271 const XclImpRoot& rRoot,
272 const OUString& rEncodedUrl );
273
279 static void DecodeUrl(
280 OUString& rUrl,
281 bool& rbSameWb,
282 const XclImpRoot& rRoot,
283 const OUString& rEncodedUrl );
284
289 static bool DecodeLink( OUString& rApplic, OUString& rTopic, std::u16string_view aEncUrl );
290};
291
292// Cached values ==============================================================
293
294class ScTokenArray;
295
299{
300public:
306 explicit XclImpCachedValue( XclImpStream& rStrm );
307 virtual ~XclImpCachedValue();
308
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;
321
322private:
323 typedef ::std::unique_ptr< const ScTokenArray > ScTokenArrayPtr;
324
325 OUString maStr;
326 double mfValue;
330};
331
334{
335public:
338
341
342private:
343 typedef std::vector< std::unique_ptr<XclImpCachedValue> > XclImpValueList;
344
348};
349
350/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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
Accessor class to ScDocument.
Base class for import/export address converters.
Definition: xladdress.hxx:140
Provides functions to convert Excel cell addresses to Calc cell addresses.
Definition: xihelper.hxx:42
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
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
bool CheckAddress(const XclAddress &rXclPos, bool bWarn)
Checks if the passed Excel cell address is valid.
Definition: xihelper.cxx:62
XclImpAddressConverter(const XclImpRoot &rRoot)
Definition: xihelper.cxx:55
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
ScAddress CreateValidAddress(const XclAddress &rXclPos, SCTAB nScTab, bool bWarn)
Returns a valid cell address by moving it into allowed dimensions.
Definition: xihelper.cxx:86
Contains cached values in a 2-dimensional array.
Definition: xihelper.hxx:334
std::vector< std::unique_ptr< XclImpCachedValue > > XclImpValueList
Definition: xihelper.hxx:343
SCSIZE mnScRows
Number of cached columns.
Definition: xihelper.hxx:347
SCSIZE mnScCols
List of cached cell values.
Definition: xihelper.hxx:346
XclImpCachedMatrix(XclImpStream &rStrm)
Definition: xihelper.cxx:822
XclImpValueList maValueList
Definition: xihelper.hxx:345
ScMatrixRef CreateScMatrix(svl::SharedStringPool &rPool) const
Creates a new ScMatrix object and fills it with the contained values.
Definition: xihelper.cxx:861
This class stores one cached value of a cached value list (used for instance in CRN,...
Definition: xihelper.hxx:299
XclImpCachedValue(const XclImpCachedValue &)=delete
delete copy constructor
bool GetBool() const
Returns the cached Boolean value, if this value has Boolean type, else false.
Definition: xihelper.hxx:316
const OUString & GetString() const
Returns the cached string value, if this value is a string, else an empty string.
Definition: xihelper.hxx:312
sal_uInt8 mnType
Boolean value or Excel error code.
Definition: xihelper.hxx:329
sal_uInt8 mnBoolErr
Cached value is a formula or error code or Boolean.
Definition: xihelper.hxx:328
sal_uInt8 GetXclError() const
Returns the cached Calc error code, if this value has Error type, else 0.
Definition: xihelper.hxx:318
sal_uInt8 GetType() const
Returns the type of the cached value (EXC_CACHEDVAL_*).
Definition: xihelper.hxx:310
::std::unique_ptr< const ScTokenArray > ScTokenArrayPtr
Definition: xihelper.hxx:323
double GetValue() const
Returns the cached number, if this value has number type, else 0.0.
Definition: xihelper.hxx:314
ScTokenArrayPtr mxTokArr
Cached value is a double.
Definition: xihelper.hxx:327
double mfValue
Cached value is a string.
Definition: xihelper.hxx:326
const XclImpCachedValue & operator=(const XclImpCachedValue &)=delete
delete copy-assignment operator
FormulaError GetScError() const
Returns the cached Calc error code, if this value has Error type, else 0.
Definition: xihelper.cxx:815
virtual ~XclImpCachedValue()
Definition: xihelper.cxx:811
Converts an Excel header/footer string into three edit engine text objects.
Definition: xihelper.hxx:164
void ParseString(const OUString &rHFString)
Parses the passed string and creates three new edit engine text objects.
Definition: xihelper.cxx:282
void InsertLineBreak()
Inserts a line break and adjusts the current selection object.
Definition: xihelper.cxx:561
void FillToItemSet(SfxItemSet &rItemSet, sal_uInt16 nWhichId) const
Creates a ScPageHFItem and inserts it into the passed item set.
Definition: xihelper.cxx:479
XclImpHFConverter(const XclImpHFConverter &)=delete
delete copy constructor
const XclImpHFConverter & operator=(const XclImpHFConverter &)=delete
delete copy-assignment operator
sal_uInt16 GetMaxLineHeight(XclImpHFPortion ePortion) const
Returns the maximum line height of the specified portion.
Definition: xihelper.cxx:499
void InsertField(const SvxFieldItem &rFieldItem)
Inserts the passed text field and adjusts the current selection object.
Definition: xihelper.cxx:553
std::vector< XclImpHFPortionInfo > maInfos
The header/footer edit engine.
Definition: xihelper.hxx:240
::std::unique_ptr< XclFontData > XclFontDataPtr
Definition: xihelper.hxx:183
XclImpHFPortion meCurrObj
Font data of current text.
Definition: xihelper.hxx:243
void ResetFontData()
Resets font data to application default font.
Definition: xihelper.cxx:530
ESelection & GetCurrSel()
Returns the current selection.
Definition: xihelper.hxx:205
EditEngine & mrEE
Definition: xihelper.hxx:238
void SetAttribs()
Sets the font attributes at the current selection.
Definition: xihelper.cxx:516
XclFontDataPtr mxFontData
Current text to insert into edit engine.
Definition: xihelper.hxx:242
void InsertText()
Inserts maCurrText into edit engine and adjusts the current selection object.
Definition: xihelper.cxx:541
void CreateCurrObject()
Creates the edit engine text object of current portion from edit engine.
Definition: xihelper.cxx:571
XclImpHFPortion
Enumerates the supported header/footer portions.
Definition: xihelper.hxx:186
sal_Int32 GetTotalHeight() const
Returns the total height of the converted header or footer in twips.
Definition: xihelper.cxx:491
XclImpHFPortionInfo::EditTextObjectRef & GetCurrObj()
Returns the current edit engine text object.
Definition: xihelper.hxx:203
void UpdateCurrMaxLineHeight()
Updates the current maximum line height, using the current font size.
Definition: xihelper.cxx:511
void UpdateMaxLineHeight(XclImpHFPortion ePortion)
Updates the maximum line height of the specified portion, using the current font size.
Definition: xihelper.cxx:505
virtual ~XclImpHFConverter() override
Definition: xihelper.cxx:278
void SetNewPortion(XclImpHFPortion eNew)
Changes current header/footer portion to eNew.
Definition: xihelper.cxx:578
OUStringBuffer maCurrText
Edit engine text objects for all portions.
Definition: xihelper.hxx:241
XclImpHFPortionInfo & GetCurrInfo()
Returns the current edit engine text object.
Definition: xihelper.hxx:201
Access to global data from other classes.
Definition: xiroot.hxx:129
This class is used to import record oriented streams.
Definition: xistream.hxx:278
This class provides methods to convert an XclImpString.
Definition: xihelper.hxx:107
static std::unique_ptr< EditTextObject > CreateTextObject(const XclImpRoot &rRoot, const XclImpString &rString)
Returns a new edit engine text object.
Definition: xihelper.cxx:217
XclImpStringHelper(const XclImpStringHelper &)=delete
delete copy constructor
XclImpStringHelper()=delete
We don't want anybody to instantiate this class, since it is just a collection of static methods.
static void SetToDocument(ScDocumentImport &rDoc, const ScAddress &rPos, const XclImpRoot &rRoot, const XclImpString &rString, sal_uInt16 nXFIndex)
Definition: xihelper.cxx:223
const XclImpStringHelper & operator=(const XclImpStringHelper &)=delete
delete copy-assignment operator
This class represents an unformatted or formatted string and provides importing from stream.
Definition: xistring.hxx:31
This class contains static methods to decode a URL stored in an Excel file.
Definition: xihelper.hxx:252
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:609
XclImpUrlHelper(const XclImpUrlHelper &)=delete
delete copy constructor
const XclImpUrlHelper & operator=(const XclImpUrlHelper &)=delete
delete copy-assignment operator
static bool DecodeLink(OUString &rApplic, OUString &rTopic, std::u16string_view aEncUrl)
Decodes the passed URL to OLE or DDE link components.
Definition: xihelper.cxx:763
XclImpUrlHelper()=delete
We don't want anybody to instantiate this class, since it is just a collection of static methods.
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:102
FormulaError
void SvStream & rStrm
These need to be in global namespace just like their respective types are.
A 2D cell address struct with Excel column and row indexes.
Definition: xladdress.hxx:30
This struct helps reading and writing Excel fonts.
Definition: xlstyle.hxx:285
Contains all information about a header/footer portion.
Definition: xihelper.hxx:190
XclImpHFPortionInfo()
Maximum font height for the current text line.
Definition: xihelper.cxx:262
sal_uInt16 mnMaxLineHt
Height of previous lines in twips.
Definition: xihelper.hxx:195
sal_Int32 mnHeight
Edit engine selection.
Definition: xihelper.hxx:194
ESelection maSel
Edit engine text object.
Definition: xihelper.hxx:193
std::shared_ptr< EditTextObject > EditTextObjectRef
Definition: xihelper.hxx:191
A 2D cell range address struct with Excel column and row indexes.
Definition: xladdress.hxx:59
unsigned char sal_uInt8
sal_Int16 SCTAB
Definition: types.hxx:22
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:25
const sal_uInt8 EXC_ERR_NA
Definition: xlconst.hxx:110
const sal_uInt8 EXC_CACHEDVAL_ERROR
Definition: xlconst.hxx:118
const sal_uInt8 EXC_CACHEDVAL_BOOL
Definition: xlconst.hxx:117