xref: /aoo41x/main/sc/inc/rangeutl.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_RANGEUTL_HXX
29 #define SC_RANGEUTL_HXX
30 
31 #include "address.hxx"
32 #include <tools/string.hxx>
33 #include "scdllapi.h"
34 #include <com/sun/star/table/CellAddress.hpp>
35 #include <com/sun/star/table/CellRangeAddress.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37 
38 //------------------------------------------------------------------------
39 
40 class SvStream;
41 
42 class ScArea;
43 class ScDocument;
44 class ScRange;
45 class ScRangeName;
46 class ScRangeList;
47 class ScDBCollection;
48 
49 enum RutlNameScope { RUTL_NONE=0, RUTL_NAMES, RUTL_DBASE };
50 
51 //------------------------------------------------------------------------
52 
53 class SC_DLLPUBLIC ScRangeUtil
54 {
55 public:
56 				ScRangeUtil()  {}
57 				~ScRangeUtil() {}
58 
59 	sal_Bool	MakeArea			( const String&		rAreaStr,
60 								  ScArea&			rArea,
61 								  ScDocument*		pDoc,
62 								  SCTAB			nTab,
63 								  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
64 
65 	void	CutPosString		( const String&		theAreaStr,
66 								  String&			thePosStr ) const;
67 
68 	sal_Bool 	IsAbsTabArea		( const String& 	rAreaStr,
69 								  ScDocument*		pDoc,
70 								  ScArea***			pppAreas 	= 0,
71 								  sal_uInt16*			pAreaCount	= 0,
72 								  sal_Bool				bAcceptCellRef = sal_False,
73 								  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
74 
75 	sal_Bool	IsAbsArea			( const String& rAreaStr,
76 								  ScDocument*	pDoc,
77 								  SCTAB		nTab,
78 								  String*		pCompleteStr = 0,
79 								  ScRefAddress*	pStartPos	 = 0,
80 								  ScRefAddress*	pEndPos		 = 0,
81 								  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
82 
83     sal_Bool    IsRefArea           ( const String&,
84                                   ScDocument*,
85                                   SCTAB,
86                                   String* = 0,
87                                   ScRefAddress* = 0 ) const
88 									  { return sal_False; }
89 
90 	sal_Bool	IsAbsPos			( const String&	rPosStr,
91 								  ScDocument*	pDoc,
92 								  SCTAB		nTab,
93 								  String*		pCompleteStr = 0,
94 								  ScRefAddress*	pPosTripel	 = 0,
95 								  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
96 
97 	sal_Bool	MakeRangeFromName	( const String&	rName,
98 									ScDocument*		pDoc,
99 									SCTAB			nCurTab,
100 									ScRange&		rRange,
101 								  RutlNameScope eScope=RUTL_NAMES,
102 								  ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
103 };
104 
105 //------------------------------------------------------------------------
106 
107 class SC_DLLPUBLIC ScRangeStringConverter
108 {
109 public:
110 
111 // helper methods
112 	static void			AssignString(
113 							::rtl::OUString& rString,
114 							const ::rtl::OUString& rNewStr,
115 							sal_Bool bAppendStr,
116                             sal_Unicode cSeperator = ' ');
117 
118 	static sal_Int32	IndexOf(
119 							const ::rtl::OUString& rString,
120 							sal_Unicode cSearchChar,
121 							sal_Int32 nOffset,
122 							sal_Unicode cQuote = '\'');
123 
124 	static sal_Int32	IndexOfDifferent(
125 							const ::rtl::OUString& rString,
126 							sal_Unicode cSearchChar,
127 							sal_Int32 nOffset );
128 
129     static sal_Int32	GetTokenCount(
130 							const ::rtl::OUString& rString,
131                             sal_Unicode cSeperator = ' ',
132                             sal_Unicode cQuote = '\'');
133 
134     static void			GetTokenByOffset(
135 							::rtl::OUString& rToken,
136 							const ::rtl::OUString& rString,
137 							sal_Int32& nOffset,
138                             sal_Unicode cSeperator = ' ',
139 							sal_Unicode cQuote = '\'');
140 
141     static void         AppendTableName(
142                             ::rtl::OUStringBuffer& rBuf,
143                             const ::rtl::OUString& rTabName,
144                             sal_Unicode cQuote = '\'');
145 
146 // String to Range core
147 	static sal_Bool		GetAddressFromString(
148 							ScAddress& rAddress,
149 							const ::rtl::OUString& rAddressStr,
150 							const ScDocument* pDocument,
151                             formula::FormulaGrammar::AddressConvention eConv,
152                             sal_Int32& nOffset,
153                             sal_Unicode cSeperator = ' ',
154                             sal_Unicode cQuote = '\'');
155 	static sal_Bool		GetRangeFromString(
156 							ScRange& rRange,
157 							const ::rtl::OUString& rRangeStr,
158 							const ScDocument* pDocument,
159                             formula::FormulaGrammar::AddressConvention eConv,
160 							sal_Int32& nOffset,
161                             sal_Unicode cSeperator = ' ',
162                             sal_Unicode cQuote = '\'');
163 	static sal_Bool		GetRangeListFromString(
164 							ScRangeList& rRangeList,
165 							const ::rtl::OUString& rRangeListStr,
166 							const ScDocument* pDocument,
167                             formula::FormulaGrammar::AddressConvention eConv,
168                             sal_Unicode cSeperator = ' ',
169                             sal_Unicode cQuote = '\'');
170 
171 	static sal_Bool		GetAreaFromString(
172 							ScArea& rArea,
173 							const ::rtl::OUString& rRangeStr,
174 							const ScDocument* pDocument,
175                             formula::FormulaGrammar::AddressConvention eConv,
176 							sal_Int32& nOffset,
177                             sal_Unicode cSeperator = ' ',
178                             sal_Unicode cQuote = '\'');
179 
180 // String to Range API
181 	static sal_Bool		GetAddressFromString(
182 							::com::sun::star::table::CellAddress& rAddress,
183 							const ::rtl::OUString& rAddressStr,
184 							const ScDocument* pDocument,
185                             formula::FormulaGrammar::AddressConvention eConv,
186 							sal_Int32& nOffset,
187                             sal_Unicode cSeperator = ' ',
188                             sal_Unicode cQuote = '\'');
189 	static sal_Bool		GetRangeFromString(
190 							::com::sun::star::table::CellRangeAddress& rRange,
191 							const ::rtl::OUString& rRangeStr,
192 							const ScDocument* pDocument,
193                             formula::FormulaGrammar::AddressConvention eConv,
194 							sal_Int32& nOffset,
195                             sal_Unicode cSeperator = ' ',
196                             sal_Unicode cQuote = '\'');
197 	static sal_Bool		GetRangeListFromString(
198 							::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
199 							const ::rtl::OUString& rRangeListStr,
200 							const ScDocument* pDocument,
201                             formula::FormulaGrammar::AddressConvention eConv,
202                             sal_Unicode cSeperator = ' ',
203                             sal_Unicode cQuote = '\'');
204 
205 // Range to String core
206 	static void			GetStringFromAddress(
207 							::rtl::OUString& rString,
208 							const ScAddress& rAddress,
209 							const ScDocument* pDocument,
210                             formula::FormulaGrammar::AddressConvention eConv,
211                             sal_Unicode cSeperator = ' ',
212 							sal_Bool bAppendStr = sal_False,
213 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
214 	static void			GetStringFromRange(
215 							::rtl::OUString& rString,
216 							const ScRange& rRange,
217 							const ScDocument* pDocument,
218                             formula::FormulaGrammar::AddressConvention eConv,
219                             sal_Unicode cSeperator = ' ',
220 							sal_Bool bAppendStr = sal_False,
221 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
222 	static void			GetStringFromRangeList(
223 							::rtl::OUString& rString,
224 							const ScRangeList* pRangeList,
225 							const ScDocument* pDocument,
226                             formula::FormulaGrammar::AddressConvention eConv,
227                             sal_Unicode cSeperator = ' ',
228 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D));
229 
230 	static void			GetStringFromArea(
231 							::rtl::OUString& rString,
232 							const ScArea& rArea,
233 							const ScDocument* pDocument,
234                             formula::FormulaGrammar::AddressConvention eConv,
235                             sal_Unicode cSeperator = ' ',
236 							sal_Bool bAppendStr = sal_False,
237 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
238 
239 // Range to String API
240 	static void			GetStringFromAddress(
241 							::rtl::OUString& rString,
242 							const ::com::sun::star::table::CellAddress& rAddress,
243 							const ScDocument* pDocument,
244                             formula::FormulaGrammar::AddressConvention eConv,
245                             sal_Unicode cSeperator = ' ',
246 							sal_Bool bAppendStr = sal_False,
247 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
248 	static void			GetStringFromRange(
249 							::rtl::OUString& rString,
250 							const ::com::sun::star::table::CellRangeAddress& rRange,
251 							const ScDocument* pDocument,
252                             formula::FormulaGrammar::AddressConvention eConv,
253                             sal_Unicode cSeperator = ' ',
254 							sal_Bool bAppendStr = sal_False,
255 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
256 	static void			GetStringFromRangeList(
257 							::rtl::OUString& rString,
258 							const ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
259 							const ScDocument* pDocument,
260                             formula::FormulaGrammar::AddressConvention eConv,
261                             sal_Unicode cSeperator = ' ',
262 							sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
263 
264 // XML Range to Calc Range
265     static void         GetStringFromXMLRangeString(
266                             ::rtl::OUString& rString,
267                             const ::rtl::OUString& rXMLRange,
268                             ScDocument* pDoc );
269 };
270 
271 //------------------------------------------------------------------------
272 
273 class ScArea
274 {
275 public:
276 			ScArea( SCTAB tab      = 0,
277 					SCCOL colStart = 0,
278 					SCROW rowStart = 0,
279 					SCCOL colEnd   = 0,
280 					SCROW rowEnd   = 0 );
281 
282 			ScArea( const ScArea& r );
283 
284 	ScArea&	operator=	( const ScArea& r );
285 	sal_Bool	operator==	( const ScArea& r ) const;
286 	sal_Bool	operator!=	( const ScArea& r ) const  { return !( operator==(r) ); }
287 
288 public:
289 	SCTAB nTab;
290 	SCCOL nColStart;
291 	SCROW nRowStart;
292 	SCCOL nColEnd;
293 	SCROW nRowEnd;
294 };
295 
296 //------------------------------------------------------------------------
297 
298 //
299 //	gibt Bereiche mit Referenz und alle DB-Bereiche zurueck
300 //
301 
302 class SC_DLLPUBLIC ScAreaNameIterator
303 {
304 private:
305 	ScRangeName*	pRangeName;
306 	ScDBCollection*	pDBCollection;
307 	sal_Bool			bFirstPass;
308 	sal_uInt16			nPos;
309 	String			aStrNoName;
310 
311 public:
312 			ScAreaNameIterator( ScDocument* pDoc );
313 			~ScAreaNameIterator() {}
314 
315 	sal_Bool	Next( String& rName, ScRange& rRange );
316 	sal_Bool	WasDBName() const	{ return !bFirstPass; }
317 };
318 
319 
320 #endif // SC_RANGEUTL_HXX
321 
322