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