Line data Source code
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 SC_RANGEUTL_HXX
21 : #define SC_RANGEUTL_HXX
22 :
23 : #include "address.hxx"
24 : #include "rangenam.hxx"
25 : #include "dbdata.hxx"
26 : #include "scdllapi.h"
27 :
28 : #include <com/sun/star/table/CellAddress.hpp>
29 : #include <com/sun/star/table/CellRangeAddress.hpp>
30 : #include <com/sun/star/uno/Sequence.hxx>
31 :
32 : class ScArea;
33 : class ScDocument;
34 : class ScRange;
35 : class ScRangeName;
36 : class ScRangeList;
37 : class ScDBCollection;
38 :
39 : enum RutlNameScope { RUTL_NONE=0, RUTL_NAMES, RUTL_DBASE };
40 :
41 : class SC_DLLPUBLIC ScRangeUtil
42 : {
43 : public:
44 0 : ScRangeUtil() {}
45 0 : ~ScRangeUtil() {}
46 :
47 : bool MakeArea ( const OUString& rAreaStr,
48 : ScArea& rArea,
49 : ScDocument* pDoc,
50 : SCTAB nTab,
51 : ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
52 :
53 : void CutPosString ( const OUString& theAreaStr,
54 : OUString& thePosStr ) const;
55 :
56 : bool IsAbsTabArea ( const OUString& rAreaStr,
57 : ScDocument* pDoc,
58 : ScArea*** pppAreas = 0,
59 : sal_uInt16* pAreaCount = 0,
60 : bool bAcceptCellRef = false,
61 : ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
62 :
63 : bool IsAbsArea ( const OUString& rAreaStr,
64 : ScDocument* pDoc,
65 : SCTAB nTab,
66 : OUString* pCompleteStr = 0,
67 : ScRefAddress* pStartPos = 0,
68 : ScRefAddress* pEndPos = 0,
69 : ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
70 :
71 : bool IsRefArea ( const OUString&,
72 : ScDocument*,
73 : SCTAB,
74 : OUString* = 0,
75 : ScRefAddress* = 0 ) const
76 : { return false; }
77 :
78 : bool IsAbsPos ( const OUString& rPosStr,
79 : ScDocument* pDoc,
80 : SCTAB nTab,
81 : OUString* pCompleteStr = 0,
82 : ScRefAddress* pPosTripel = 0,
83 : ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
84 :
85 : bool MakeRangeFromName ( const OUString& rName,
86 : ScDocument* pDoc,
87 : SCTAB nCurTab,
88 : ScRange& rRange,
89 : RutlNameScope eScope=RUTL_NAMES,
90 : ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
91 : };
92 :
93 : class SC_DLLPUBLIC ScRangeStringConverter
94 : {
95 : public:
96 :
97 : /// helper methods
98 : static void AssignString(
99 : OUString& rString,
100 : const OUString& rNewStr,
101 : bool bAppendStr,
102 : sal_Unicode cSeparator = ' ');
103 :
104 : static sal_Int32 IndexOf(
105 : const OUString& rString,
106 : sal_Unicode cSearchChar,
107 : sal_Int32 nOffset,
108 : sal_Unicode cQuote = '\'');
109 :
110 : static sal_Int32 IndexOfDifferent(
111 : const OUString& rString,
112 : sal_Unicode cSearchChar,
113 : sal_Int32 nOffset );
114 :
115 : static sal_Int32 GetTokenCount(
116 : const OUString& rString,
117 : sal_Unicode cSeparator = ' ',
118 : sal_Unicode cQuote = '\'');
119 :
120 : static void GetTokenByOffset(
121 : OUString& rToken,
122 : const OUString& rString,
123 : sal_Int32& nOffset,
124 : sal_Unicode cSeparator = ' ',
125 : sal_Unicode cQuote = '\'');
126 :
127 : static void AppendTableName(
128 : OUStringBuffer& rBuf,
129 : const OUString& rTabName,
130 : sal_Unicode cQuote = '\'');
131 :
132 : /// String to Range core
133 : static bool GetAddressFromString(
134 : ScAddress& rAddress,
135 : const OUString& rAddressStr,
136 : const ScDocument* pDocument,
137 : formula::FormulaGrammar::AddressConvention eConv,
138 : sal_Int32& nOffset,
139 : sal_Unicode cSeparator = ' ',
140 : sal_Unicode cQuote = '\'');
141 : static bool GetRangeFromString(
142 : ScRange& rRange,
143 : const OUString& rRangeStr,
144 : const ScDocument* pDocument,
145 : formula::FormulaGrammar::AddressConvention eConv,
146 : sal_Int32& nOffset,
147 : sal_Unicode cSeparator = ' ',
148 : sal_Unicode cQuote = '\'');
149 : static bool GetRangeListFromString(
150 : ScRangeList& rRangeList,
151 : const OUString& rRangeListStr,
152 : const ScDocument* pDocument,
153 : formula::FormulaGrammar::AddressConvention eConv,
154 : sal_Unicode cSeparator = ' ',
155 : sal_Unicode cQuote = '\'');
156 :
157 : static bool GetAreaFromString(
158 : ScArea& rArea,
159 : const OUString& rRangeStr,
160 : const ScDocument* pDocument,
161 : formula::FormulaGrammar::AddressConvention eConv,
162 : sal_Int32& nOffset,
163 : sal_Unicode cSeparator = ' ',
164 : sal_Unicode cQuote = '\'');
165 :
166 : /// String to Range API
167 : static bool GetAddressFromString(
168 : ::com::sun::star::table::CellAddress& rAddress,
169 : const OUString& rAddressStr,
170 : const ScDocument* pDocument,
171 : formula::FormulaGrammar::AddressConvention eConv,
172 : sal_Int32& nOffset,
173 : sal_Unicode cSeparator = ' ',
174 : sal_Unicode cQuote = '\'');
175 : static bool GetRangeFromString(
176 : ::com::sun::star::table::CellRangeAddress& rRange,
177 : const OUString& rRangeStr,
178 : const ScDocument* pDocument,
179 : formula::FormulaGrammar::AddressConvention eConv,
180 : sal_Int32& nOffset,
181 : sal_Unicode cSeparator = ' ',
182 : sal_Unicode cQuote = '\'');
183 :
184 : /// Range to String core
185 : static void GetStringFromAddress(
186 : OUString& rString,
187 : const ScAddress& rAddress,
188 : const ScDocument* pDocument,
189 : formula::FormulaGrammar::AddressConvention eConv,
190 : sal_Unicode cSeparator = ' ',
191 : bool bAppendStr = false,
192 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
193 : static void GetStringFromRange(
194 : OUString& rString,
195 : const ScRange& rRange,
196 : const ScDocument* pDocument,
197 : formula::FormulaGrammar::AddressConvention eConv,
198 : sal_Unicode cSeparator = ' ',
199 : bool bAppendStr = false,
200 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
201 : static void GetStringFromRangeList(
202 : OUString& rString,
203 : const ScRangeList* pRangeList,
204 : const ScDocument* pDocument,
205 : formula::FormulaGrammar::AddressConvention eConv,
206 : sal_Unicode cSeparator = ' ',
207 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D));
208 :
209 : static void GetStringFromArea(
210 : OUString& rString,
211 : const ScArea& rArea,
212 : const ScDocument* pDocument,
213 : formula::FormulaGrammar::AddressConvention eConv,
214 : sal_Unicode cSeparator = ' ',
215 : bool bAppendStr = false,
216 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
217 :
218 : /// Range to String API
219 : static void GetStringFromAddress(
220 : OUString& rString,
221 : const ::com::sun::star::table::CellAddress& rAddress,
222 : const ScDocument* pDocument,
223 : formula::FormulaGrammar::AddressConvention eConv,
224 : sal_Unicode cSeparator = ' ',
225 : bool bAppendStr = false,
226 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
227 : static void GetStringFromRange(
228 : OUString& rString,
229 : const ::com::sun::star::table::CellRangeAddress& rRange,
230 : const ScDocument* pDocument,
231 : formula::FormulaGrammar::AddressConvention eConv,
232 : sal_Unicode cSeparator = ' ',
233 : bool bAppendStr = false,
234 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
235 : static void GetStringFromRangeList(
236 : OUString& rString,
237 : const ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
238 : const ScDocument* pDocument,
239 : formula::FormulaGrammar::AddressConvention eConv,
240 : sal_Unicode cSeparator = ' ',
241 : sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
242 :
243 : /// XML Range to Calc Range
244 : static void GetStringFromXMLRangeString(
245 : OUString& rString,
246 : const OUString& rXMLRange,
247 : ScDocument* pDoc );
248 :
249 : /// String to RangeData core
250 : static ScRangeData* GetRangeDataFromString(const OUString& rString, const SCTAB nTab, const ScDocument* pDoc);
251 : };
252 :
253 : class ScArea
254 : {
255 : public:
256 : ScArea( SCTAB tab = 0,
257 : SCCOL colStart = 0,
258 : SCROW rowStart = 0,
259 : SCCOL colEnd = 0,
260 : SCROW rowEnd = 0 );
261 :
262 : ScArea( const ScArea& r );
263 :
264 : ScArea& operator= ( const ScArea& r );
265 : bool operator== ( const ScArea& r ) const;
266 : bool operator!= ( const ScArea& r ) const { return !( operator==(r) ); }
267 :
268 : public:
269 : SCTAB nTab;
270 : SCCOL nColStart;
271 : SCROW nRowStart;
272 : SCCOL nColEnd;
273 : SCROW nRowEnd;
274 : };
275 :
276 :
277 : /// @return areas with reference and all db-areas
278 :
279 :
280 : class SC_DLLPUBLIC ScAreaNameIterator
281 : {
282 : private:
283 : ScRangeName* pRangeName;
284 : ScDBCollection* pDBCollection;
285 : ScRangeName::const_iterator maRNPos;
286 : ScRangeName::const_iterator maRNEnd;
287 : ScDBCollection::NamedDBs::const_iterator maDBPos;
288 : ScDBCollection::NamedDBs::const_iterator maDBEnd;
289 : bool bFirstPass;
290 :
291 : public:
292 : ScAreaNameIterator( ScDocument* pDoc );
293 0 : ~ScAreaNameIterator() {}
294 :
295 : bool Next( OUString& rName, ScRange& rRange );
296 0 : bool WasDBName() const { return !bFirstPass; }
297 : };
298 :
299 : #endif // SC_RANGEUTL_HXX
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|