update dev300-m57
[ooovba.git] / sc / inc / rangeutl.hxx
blob1dc463dd78204d4b3c7759b1e9dc0af4852b1e1d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rangeutl.hxx,v $
10 * $Revision: 1.10.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_RANGEUTL_HXX
32 #define SC_RANGEUTL_HXX
34 #include "address.hxx"
35 #include <tools/string.hxx>
36 #include "scdllapi.h"
37 #include <com/sun/star/table/CellAddress.hpp>
38 #include <com/sun/star/table/CellRangeAddress.hpp>
39 #include <com/sun/star/uno/Sequence.hxx>
41 // Chart always stores cell range addresses using CONV_OOO convention. But
42 // if parsing with CONV_OOO fails, try parsing it using the current address
43 // convention.
44 #define CHART_ADDRESS_CONV_WORKAROUND 1
46 //------------------------------------------------------------------------
48 class SvStream;
50 class ScArea;
51 class ScDocument;
52 class ScRange;
53 class ScRangeName;
54 class ScRangeList;
55 class ScDBCollection;
57 enum RutlNameScope { RUTL_NONE=0, RUTL_NAMES, RUTL_DBASE };
59 //------------------------------------------------------------------------
61 class SC_DLLPUBLIC ScRangeUtil
63 public:
64 ScRangeUtil() {}
65 ~ScRangeUtil() {}
67 BOOL MakeArea ( const String& rAreaStr,
68 ScArea& rArea,
69 ScDocument* pDoc,
70 SCTAB nTab,
71 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
73 void CutPosString ( const String& theAreaStr,
74 String& thePosStr ) const;
76 BOOL IsAbsTabArea ( const String& rAreaStr,
77 ScDocument* pDoc,
78 ScArea*** pppAreas = 0,
79 USHORT* pAreaCount = 0,
80 BOOL bAcceptCellRef = FALSE,
81 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
83 BOOL IsAbsArea ( const String& rAreaStr,
84 ScDocument* pDoc,
85 SCTAB nTab,
86 String* pCompleteStr = 0,
87 ScRefAddress* pStartPos = 0,
88 ScRefAddress* pEndPos = 0,
89 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
91 BOOL IsRefArea ( const String&,
92 ScDocument*,
93 SCTAB,
94 String* = 0,
95 ScRefAddress* = 0 ) const
96 { return FALSE; }
98 BOOL IsAbsPos ( const String& rPosStr,
99 ScDocument* pDoc,
100 SCTAB nTab,
101 String* pCompleteStr = 0,
102 ScRefAddress* pPosTripel = 0,
103 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
105 BOOL MakeRangeFromName ( const String& rName,
106 ScDocument* pDoc,
107 SCTAB nCurTab,
108 ScRange& rRange,
109 RutlNameScope eScope=RUTL_NAMES,
110 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
113 //------------------------------------------------------------------------
115 class SC_DLLPUBLIC ScRangeStringConverter
117 public:
119 // helper methods
120 static void AssignString(
121 ::rtl::OUString& rString,
122 const ::rtl::OUString& rNewStr,
123 sal_Bool bAppendStr,
124 sal_Unicode cSeperator = ' ');
126 static sal_Int32 IndexOf(
127 const ::rtl::OUString& rString,
128 sal_Unicode cSearchChar,
129 sal_Int32 nOffset,
130 sal_Unicode cQuote = '\'');
132 static sal_Int32 IndexOfDifferent(
133 const ::rtl::OUString& rString,
134 sal_Unicode cSearchChar,
135 sal_Int32 nOffset );
137 static sal_Int32 GetTokenCount(
138 const ::rtl::OUString& rString,
139 sal_Unicode cSeperator = ' ',
140 sal_Unicode cQuote = '\'');
142 static void GetTokenByOffset(
143 ::rtl::OUString& rToken,
144 const ::rtl::OUString& rString,
145 sal_Int32& nOffset,
146 sal_Unicode cSeperator = ' ',
147 sal_Unicode cQuote = '\'');
149 static void AppendTableName(
150 ::rtl::OUStringBuffer& rBuf,
151 const ::rtl::OUString& rTabName,
152 sal_Unicode cQuote = '\'');
154 // String to Range core
155 static sal_Bool GetAddressFromString(
156 ScAddress& rAddress,
157 const ::rtl::OUString& rAddressStr,
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 GetRangeFromString(
164 ScRange& rRange,
165 const ::rtl::OUString& rRangeStr,
166 const ScDocument* pDocument,
167 formula::FormulaGrammar::AddressConvention eConv,
168 sal_Int32& nOffset,
169 sal_Unicode cSeperator = ' ',
170 sal_Unicode cQuote = '\'');
171 static sal_Bool GetRangeListFromString(
172 ScRangeList& rRangeList,
173 const ::rtl::OUString& rRangeListStr,
174 const ScDocument* pDocument,
175 formula::FormulaGrammar::AddressConvention eConv,
176 sal_Unicode cSeperator = ' ',
177 sal_Unicode cQuote = '\'');
179 static sal_Bool GetAreaFromString(
180 ScArea& rArea,
181 const ::rtl::OUString& rRangeStr,
182 const ScDocument* pDocument,
183 formula::FormulaGrammar::AddressConvention eConv,
184 sal_Int32& nOffset,
185 sal_Unicode cSeperator = ' ',
186 sal_Unicode cQuote = '\'');
188 // String to Range API
189 static sal_Bool GetAddressFromString(
190 ::com::sun::star::table::CellAddress& rAddress,
191 const ::rtl::OUString& rAddressStr,
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 GetRangeFromString(
198 ::com::sun::star::table::CellRangeAddress& rRange,
199 const ::rtl::OUString& rRangeStr,
200 const ScDocument* pDocument,
201 formula::FormulaGrammar::AddressConvention eConv,
202 sal_Int32& nOffset,
203 sal_Unicode cSeperator = ' ',
204 sal_Unicode cQuote = '\'');
205 static sal_Bool GetRangeListFromString(
206 ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
207 const ::rtl::OUString& rRangeListStr,
208 const ScDocument* pDocument,
209 formula::FormulaGrammar::AddressConvention eConv,
210 sal_Unicode cSeperator = ' ',
211 sal_Unicode cQuote = '\'');
213 // Range to String core
214 static void GetStringFromAddress(
215 ::rtl::OUString& rString,
216 const ScAddress& rAddress,
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 GetStringFromRange(
223 ::rtl::OUString& rString,
224 const ScRange& rRange,
225 const ScDocument* pDocument,
226 formula::FormulaGrammar::AddressConvention eConv,
227 sal_Unicode cSeperator = ' ',
228 sal_Bool bAppendStr = sal_False,
229 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
230 static void GetStringFromRangeList(
231 ::rtl::OUString& rString,
232 const ScRangeList* pRangeList,
233 const ScDocument* pDocument,
234 formula::FormulaGrammar::AddressConvention eConv,
235 sal_Unicode cSeperator = ' ',
236 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D));
238 static void GetStringFromArea(
239 ::rtl::OUString& rString,
240 const ScArea& rArea,
241 const ScDocument* pDocument,
242 formula::FormulaGrammar::AddressConvention eConv,
243 sal_Unicode cSeperator = ' ',
244 sal_Bool bAppendStr = sal_False,
245 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
247 // Range to String API
248 static void GetStringFromAddress(
249 ::rtl::OUString& rString,
250 const ::com::sun::star::table::CellAddress& rAddress,
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 GetStringFromRange(
257 ::rtl::OUString& rString,
258 const ::com::sun::star::table::CellRangeAddress& rRange,
259 const ScDocument* pDocument,
260 formula::FormulaGrammar::AddressConvention eConv,
261 sal_Unicode cSeperator = ' ',
262 sal_Bool bAppendStr = sal_False,
263 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
264 static void GetStringFromRangeList(
265 ::rtl::OUString& rString,
266 const ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
267 const ScDocument* pDocument,
268 formula::FormulaGrammar::AddressConvention eConv,
269 sal_Unicode cSeperator = ' ',
270 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
272 // XML Range to Calc Range
273 static void GetStringFromXMLRangeString(
274 ::rtl::OUString& rString,
275 const ::rtl::OUString& rXMLRange,
276 ScDocument* pDoc );
279 //------------------------------------------------------------------------
281 class ScArea
283 public:
284 ScArea( SCTAB tab = 0,
285 SCCOL colStart = 0,
286 SCROW rowStart = 0,
287 SCCOL colEnd = 0,
288 SCROW rowEnd = 0 );
290 ScArea( const ScArea& r );
292 ScArea& operator= ( const ScArea& r );
293 BOOL operator== ( const ScArea& r ) const;
294 BOOL operator!= ( const ScArea& r ) const { return !( operator==(r) ); }
296 public:
297 SCTAB nTab;
298 SCCOL nColStart;
299 SCROW nRowStart;
300 SCCOL nColEnd;
301 SCROW nRowEnd;
304 //------------------------------------------------------------------------
307 // gibt Bereiche mit Referenz und alle DB-Bereiche zurueck
310 class SC_DLLPUBLIC ScAreaNameIterator
312 private:
313 ScRangeName* pRangeName;
314 ScDBCollection* pDBCollection;
315 BOOL bFirstPass;
316 USHORT nPos;
317 String aStrNoName;
319 public:
320 ScAreaNameIterator( ScDocument* pDoc );
321 ~ScAreaNameIterator() {}
323 BOOL Next( String& rName, ScRange& rRange );
324 BOOL WasDBName() const { return !bFirstPass; }
328 #endif // SC_RANGEUTL_HXX