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 .
20 #ifndef INCLUDED_SC_INC_RANGEUTL_HXX
21 #define INCLUDED_SC_INC_RANGEUTL_HXX
23 #include "address.hxx"
24 #include "rangenam.hxx"
28 #include <com/sun/star/table/CellAddress.hpp>
29 #include <com/sun/star/table/CellRangeAddress.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
39 enum RutlNameScope
{ RUTL_NONE
=0, RUTL_NAMES
, RUTL_DBASE
};
41 class SC_DLLPUBLIC ScRangeUtil
46 static bool MakeArea ( const OUString
& rAreaStr
,
48 const ScDocument
* pDoc
,
50 ScAddress::Details
const & rDetails
);
52 static void CutPosString ( const OUString
& theAreaStr
,
53 OUString
& thePosStr
);
55 static bool IsAbsTabArea ( const OUString
& rAreaStr
,
56 const ScDocument
* pDoc
,
58 sal_uInt16
* pAreaCount
= nullptr,
59 bool bAcceptCellRef
= false,
60 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
62 static bool IsAbsArea ( const OUString
& rAreaStr
,
63 const ScDocument
* pDoc
,
65 OUString
* pCompleteStr
,
66 ScRefAddress
* pStartPos
= nullptr,
67 ScRefAddress
* pEndPos
= nullptr,
68 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
70 static bool IsAbsPos ( const OUString
& rPosStr
,
71 const ScDocument
* pDoc
,
73 OUString
* pCompleteStr
,
74 ScRefAddress
* pPosTripel
= nullptr,
75 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
77 static bool MakeRangeFromName( const OUString
& rName
,
78 const ScDocument
* pDoc
,
81 RutlNameScope eScope
=RUTL_NAMES
,
82 ScAddress::Details
const & rDetails
= ScAddress::detailsOOOa1
);
85 class SC_DLLPUBLIC ScRangeStringConverter
90 static void AssignString(
92 const OUString
& rNewStr
,
94 sal_Unicode cSeparator
= ' ');
96 static sal_Int32
IndexOf(
97 const OUString
& rString
,
98 sal_Unicode cSearchChar
,
100 sal_Unicode cQuote
= '\'');
102 static sal_Int32
IndexOfDifferent(
103 const OUString
& rString
,
104 sal_Unicode cSearchChar
,
107 static sal_Int32
GetTokenCount(
108 const OUString
& rString
,
109 sal_Unicode cSeparator
= ' ');
111 static void GetTokenByOffset(
113 const OUString
& rString
,
115 sal_Unicode cSeparator
= ' ',
116 sal_Unicode cQuote
= '\'');
118 static void AppendTableName(
119 OUStringBuffer
& rBuf
,
120 const OUString
& rTabName
);
122 /// String to Range core
123 static bool GetAddressFromString(
125 const OUString
& rAddressStr
,
126 const ScDocument
* pDocument
,
127 formula::FormulaGrammar::AddressConvention eConv
,
129 sal_Unicode cSeparator
= ' ',
130 sal_Unicode cQuote
= '\'');
131 static bool GetRangeFromString(
133 const OUString
& rRangeStr
,
134 const ScDocument
* pDocument
,
135 formula::FormulaGrammar::AddressConvention eConv
,
137 sal_Unicode cSeparator
= ' ',
138 sal_Unicode cQuote
= '\'');
139 static bool GetRangeListFromString(
140 ScRangeList
& rRangeList
,
141 const OUString
& rRangeListStr
,
142 const ScDocument
* pDocument
,
143 formula::FormulaGrammar::AddressConvention eConv
,
144 sal_Unicode cSeparator
= ' ',
145 sal_Unicode cQuote
= '\'');
147 static bool GetAreaFromString(
149 const OUString
& rRangeStr
,
150 const ScDocument
* pDocument
,
151 formula::FormulaGrammar::AddressConvention eConv
,
153 sal_Unicode cSeparator
= ' ');
155 /// String to Range API
156 static bool GetRangeFromString(
157 css::table::CellRangeAddress
& rRange
,
158 const OUString
& rRangeStr
,
159 const ScDocument
* pDocument
,
160 formula::FormulaGrammar::AddressConvention eConv
,
162 sal_Unicode cSeparator
= ' ');
164 /// Range to String core
165 static void GetStringFromAddress(
167 const ScAddress
& rAddress
,
168 const ScDocument
* pDocument
,
169 formula::FormulaGrammar::AddressConvention eConv
,
170 sal_Unicode cSeparator
= ' ',
171 bool bAppendStr
= false,
172 ScRefFlags nFormatFlags
= (ScRefFlags::VALID
| ScRefFlags::TAB_3D
) );
173 static void GetStringFromRange(
175 const ScRange
& rRange
,
176 const ScDocument
* pDocument
,
177 formula::FormulaGrammar::AddressConvention eConv
,
178 sal_Unicode cSeparator
= ' ',
179 bool bAppendStr
= false,
180 ScRefFlags nFormatFlags
= (ScRefFlags::VALID
| ScRefFlags::TAB_3D
) );
181 static void GetStringFromRangeList(
183 const ScRangeList
* pRangeList
,
184 const ScDocument
* pDocument
,
185 formula::FormulaGrammar::AddressConvention eConv
,
186 sal_Unicode cSeparator
= ' ');
188 static void GetStringFromArea(
191 const ScDocument
* pDocument
,
192 formula::FormulaGrammar::AddressConvention eConv
,
193 sal_Unicode cSeparator
,
194 bool bAppendStr
= false,
195 ScRefFlags nFormatFlags
= (ScRefFlags::VALID
| ScRefFlags::TAB_3D
) );
197 /// Range to String API
198 static void GetStringFromAddress(
200 const css::table::CellAddress
& rAddress
,
201 const ScDocument
* pDocument
,
202 formula::FormulaGrammar::AddressConvention eConv
,
203 sal_Unicode cSeparator
= ' ',
204 bool bAppendStr
= false );
205 static void GetStringFromRange(
207 const css::table::CellRangeAddress
& rRange
,
208 const ScDocument
* pDocument
,
209 formula::FormulaGrammar::AddressConvention eConv
,
210 sal_Unicode cSeparator
= ' ',
211 bool bAppendStr
= false,
212 ScRefFlags nFormatFlags
= (ScRefFlags::VALID
| ScRefFlags::TAB_3D
) );
213 static void GetStringFromRangeList(
215 const css::uno::Sequence
< css::table::CellRangeAddress
>& rRangeSeq
,
216 const ScDocument
* pDocument
,
217 formula::FormulaGrammar::AddressConvention eConv
,
218 sal_Unicode cSeparator
= ' ' );
220 /// XML Range to Calc Range
221 static void GetStringFromXMLRangeString(
223 const OUString
& rXMLRange
,
224 const ScDocument
* pDoc
);
226 /// String to RangeData core
227 static ScRangeData
* GetRangeDataFromString(const OUString
& rString
, const SCTAB nTab
, const ScDocument
* pDoc
);
233 ScArea( SCTAB tab
= 0,
239 ScArea( const ScArea
& r
);
241 ScArea
& operator= ( const ScArea
& r
);
242 bool operator== ( const ScArea
& r
) const;
252 /// @return areas with reference and all db-areas
254 class SC_DLLPUBLIC ScAreaNameIterator
257 ScRangeName
* pRangeName
;
258 ScDBCollection
* pDBCollection
;
259 ScRangeName::const_iterator maRNPos
;
260 ScRangeName::const_iterator maRNEnd
;
261 ScDBCollection::NamedDBs::const_iterator maDBPos
;
262 ScDBCollection::NamedDBs::const_iterator maDBEnd
;
266 ScAreaNameIterator( const ScDocument
* pDoc
);
268 bool Next( OUString
& rName
, ScRange
& rRange
);
269 bool WasDBName() const { return !bFirstPass
; }
272 struct SC_DLLPUBLIC ScRangeUpdater
274 ScRangeUpdater() = delete;
276 static void UpdateInsertTab(ScAddress
& rAddr
, const sc::RefUpdateInsertTabContext
& rCxt
);
277 static void UpdateDeleteTab(ScAddress
& rAddr
, const sc::RefUpdateDeleteTabContext
& rCxt
);
280 #endif // INCLUDED_SC_INC_RANGEUTL_HXX
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */