1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "address.hxx"
23 #include "rangenam.hxx"
27 namespace com::sun::star::table
{ struct CellAddress
; }
28 namespace com::sun::star::table
{ struct CellRangeAddress
; }
29 namespace com::sun::star::uno
{ template <typename
> class Sequence
; }
44 class SC_DLLPUBLIC ScRangeUtil
47 ScRangeUtil() = delete;
49 static bool MakeArea ( const OUString
& rAreaStr
,
51 const ScDocument
& rDoc
,
53 ScAddress::Details
const & rDetails
);
55 static void CutPosString ( const OUString
& theAreaStr
,
56 OUString
& thePosStr
);
58 static bool IsAbsTabArea ( const OUString
& rAreaStr
,
59 const ScDocument
* pDoc
,
60 std::unique_ptr
<ScArea
[]>* ppAreas
,
61 sal_uInt16
* pAreaCount
,
62 bool bAcceptCellRef
= false,
63 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
65 static bool IsAbsArea ( const OUString
& rAreaStr
,
66 const ScDocument
& rDoc
,
68 OUString
* pCompleteStr
,
69 ScRefAddress
* pStartPos
= nullptr,
70 ScRefAddress
* pEndPos
= nullptr,
71 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
73 static bool IsAbsPos ( const OUString
& rPosStr
,
74 const ScDocument
& rDoc
,
76 OUString
* pCompleteStr
,
77 ScRefAddress
* pPosTripel
= nullptr,
78 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
80 static bool MakeRangeFromName( const OUString
& rName
,
81 const ScDocument
& rDoc
,
84 RutlNameScope eScope
=RUTL_NAMES
,
85 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
,
86 bool bUseDetailsPos
= false );
89 class SC_DLLPUBLIC ScRangeStringConverter
94 static void AssignString(
96 const OUString
& rNewStr
,
98 sal_Unicode cSeparator
= ' ');
100 static sal_Int32
IndexOf(
101 std::u16string_view rString
,
102 sal_Unicode cSearchChar
,
104 sal_Unicode cQuote
= '\'');
106 static sal_Int32
IndexOfDifferent(
107 std::u16string_view rString
,
108 sal_Unicode cSearchChar
,
111 static sal_Int32
GetTokenCount(
112 std::u16string_view rString
,
113 sal_Unicode cSeparator
= ' ');
115 static void GetTokenByOffset(
117 std::u16string_view rString
,
119 sal_Unicode cSeparator
= ' ',
120 sal_Unicode cQuote
= '\'');
122 static void AppendTableName(
123 OUStringBuffer
& rBuf
,
124 const OUString
& rTabName
);
126 /// String to Range core
127 static bool GetAddressFromString(
129 std::u16string_view rAddressStr
,
130 const ScDocument
& rDocument
,
131 formula::FormulaGrammar::AddressConvention eConv
,
133 sal_Unicode cSeparator
= ' ',
134 sal_Unicode cQuote
= '\'');
135 static bool GetRangeFromString(
137 std::u16string_view rRangeStr
,
138 const ScDocument
& rDocument
,
139 formula::FormulaGrammar::AddressConvention eConv
,
141 sal_Unicode cSeparator
= ' ',
142 sal_Unicode cQuote
= '\'');
143 static bool GetRangeListFromString(
144 ScRangeList
& rRangeList
,
145 std::u16string_view rRangeListStr
,
146 const ScDocument
& rDocument
,
147 formula::FormulaGrammar::AddressConvention eConv
,
148 sal_Unicode cSeparator
= ' ',
149 sal_Unicode cQuote
= '\'');
151 static bool GetAreaFromString(
153 std::u16string_view rRangeStr
,
154 const ScDocument
& rDocument
,
155 formula::FormulaGrammar::AddressConvention eConv
,
157 sal_Unicode cSeparator
= ' ');
159 /// String to Range API
160 static bool GetRangeFromString(
161 css::table::CellRangeAddress
& rRange
,
162 std::u16string_view rRangeStr
,
163 const ScDocument
& rDocument
,
164 formula::FormulaGrammar::AddressConvention eConv
,
166 sal_Unicode cSeparator
= ' ');
168 /// Range to String core
169 static void GetStringFromAddress(
171 const ScAddress
& rAddress
,
172 const ScDocument
* pDocument
,
173 formula::FormulaGrammar::AddressConvention eConv
,
174 sal_Unicode cSeparator
= ' ',
175 bool bAppendStr
= false,
176 ScRefFlags nFormatFlags
= ScRefFlags::VALID
| ScRefFlags::TAB_3D
);
177 static void GetStringFromRange(
179 const ScRange
& rRange
,
180 const ScDocument
* pDocument
,
181 formula::FormulaGrammar::AddressConvention eConv
,
182 sal_Unicode cSeparator
= ' ',
183 bool bAppendStr
= false,
184 ScRefFlags nFormatFlags
= ScRefFlags::VALID
| ScRefFlags::TAB_3D
);
185 static void GetStringFromRangeList(
187 const ScRangeList
* pRangeList
,
188 const ScDocument
* pDocument
,
189 formula::FormulaGrammar::AddressConvention eConv
,
190 sal_Unicode cSeparator
= ' ');
192 static void GetStringFromArea(
195 const ScDocument
* pDocument
,
196 formula::FormulaGrammar::AddressConvention eConv
,
197 sal_Unicode cSeparator
,
198 bool bAppendStr
= false,
199 ScRefFlags nFormatFlags
= ScRefFlags::VALID
| ScRefFlags::TAB_3D
);
201 /// Range to String API
202 static void GetStringFromAddress(
204 const css::table::CellAddress
& rAddress
,
205 const ScDocument
* pDocument
,
206 formula::FormulaGrammar::AddressConvention eConv
,
207 sal_Unicode cSeparator
= ' ',
208 bool bAppendStr
= false );
209 static void GetStringFromRange(
211 const css::table::CellRangeAddress
& rRange
,
212 const ScDocument
* pDocument
,
213 formula::FormulaGrammar::AddressConvention eConv
,
214 sal_Unicode cSeparator
= ' ',
215 bool bAppendStr
= false,
216 ScRefFlags nFormatFlags
= ScRefFlags::VALID
| ScRefFlags::TAB_3D
);
217 static void GetStringFromRangeList(
219 const css::uno::Sequence
< css::table::CellRangeAddress
>& rRangeSeq
,
220 const ScDocument
* pDocument
,
221 formula::FormulaGrammar::AddressConvention eConv
,
222 sal_Unicode cSeparator
= ' ' );
224 /// XML Range to Calc Range
225 static void GetStringFromXMLRangeString(
227 std::u16string_view rXMLRange
,
228 const ScDocument
& rDoc
);
230 /// String to RangeData core
231 static ScRangeData
* GetRangeDataFromString( const OUString
& rString
, const SCTAB nTab
,
232 const ScDocument
& rDoc
, formula::FormulaGrammar::AddressConvention eConv
);
238 ScArea( SCTAB tab
= 0,
244 bool operator== ( const ScArea
& r
) const;
254 /// @return areas with reference and all db-areas
256 class SC_DLLPUBLIC ScAreaNameIterator
259 ScRangeName
* pRangeName
;
260 ScDBCollection
* pDBCollection
;
261 ScRangeName::const_iterator maRNPos
;
262 ScRangeName::const_iterator maRNEnd
;
263 ScDBCollection::NamedDBs::const_iterator maDBPos
;
264 ScDBCollection::NamedDBs::const_iterator maDBEnd
;
268 ScAreaNameIterator( const ScDocument
& rDoc
);
270 bool Next( OUString
& rName
, ScRange
& rRange
);
271 bool WasDBName() const { return !bFirstPass
; }
274 struct SC_DLLPUBLIC ScRangeUpdater
276 ScRangeUpdater() = delete;
278 static void UpdateInsertTab(ScAddress
& rAddr
, const sc::RefUpdateInsertTabContext
& rCxt
);
280 /** This is for the base-cell-address of a defined name or conditional
281 format, not for references. A sheet position on or after the start of
282 the deleted range is moved towards the beginning by the amount of
283 deleted sheets, within the deleted range to the front of that or set to
284 0 (as there is always at least one sheet in a document) if the position
285 would result in a negative value, e.g. if position was 0 and (only)
286 sheet 0 is deleted it would had become -1.
288 static void UpdateDeleteTab(ScAddress
& rAddr
, const sc::RefUpdateDeleteTabContext
& rCxt
);
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */