Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / rangeutl.hxx
blob3b51c26906643f113d1ebcebda771ab16c01eb89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 SC_RANGEUTL_HXX
21 #define SC_RANGEUTL_HXX
23 #include "address.hxx"
24 #include "rangenam.hxx"
25 #include "dbdata.hxx"
26 #include "scdllapi.h"
28 #include <com/sun/star/table/CellAddress.hpp>
29 #include <com/sun/star/table/CellRangeAddress.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
32 class ScArea;
33 class ScDocument;
34 class ScRange;
35 class ScRangeName;
36 class ScRangeList;
37 class ScDBCollection;
39 enum RutlNameScope { RUTL_NONE=0, RUTL_NAMES, RUTL_DBASE };
41 class SC_DLLPUBLIC ScRangeUtil
43 public:
44 ScRangeUtil() {}
45 ~ScRangeUtil() {}
47 sal_Bool MakeArea ( const OUString& rAreaStr,
48 ScArea& rArea,
49 ScDocument* pDoc,
50 SCTAB nTab,
51 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
53 void CutPosString ( const OUString& theAreaStr,
54 OUString& thePosStr ) const;
56 sal_Bool IsAbsTabArea ( const OUString& rAreaStr,
57 ScDocument* pDoc,
58 ScArea*** pppAreas = 0,
59 sal_uInt16* pAreaCount = 0,
60 sal_Bool bAcceptCellRef = false,
61 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const;
63 sal_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;
71 sal_Bool IsRefArea ( const OUString&,
72 ScDocument*,
73 SCTAB,
74 OUString* = 0,
75 ScRefAddress* = 0 ) const
76 { return false; }
78 sal_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;
85 sal_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;
93 class SC_DLLPUBLIC ScRangeStringConverter
95 public:
97 /// helper methods
98 static void AssignString(
99 OUString& rString,
100 const OUString& rNewStr,
101 sal_Bool bAppendStr,
102 sal_Unicode cSeparator = ' ');
104 static sal_Int32 IndexOf(
105 const OUString& rString,
106 sal_Unicode cSearchChar,
107 sal_Int32 nOffset,
108 sal_Unicode cQuote = '\'');
110 static sal_Int32 IndexOfDifferent(
111 const OUString& rString,
112 sal_Unicode cSearchChar,
113 sal_Int32 nOffset );
115 static sal_Int32 GetTokenCount(
116 const OUString& rString,
117 sal_Unicode cSeparator = ' ',
118 sal_Unicode cQuote = '\'');
120 static void GetTokenByOffset(
121 OUString& rToken,
122 const OUString& rString,
123 sal_Int32& nOffset,
124 sal_Unicode cSeparator = ' ',
125 sal_Unicode cQuote = '\'');
127 static void AppendTableName(
128 OUStringBuffer& rBuf,
129 const OUString& rTabName,
130 sal_Unicode cQuote = '\'');
132 /// String to Range core
133 static sal_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 sal_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 sal_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 = '\'');
157 static sal_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 = '\'');
166 /// String to Range API
167 static sal_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 sal_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 static sal_Bool GetRangeListFromString(
184 ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
185 const OUString& rRangeListStr,
186 const ScDocument* pDocument,
187 formula::FormulaGrammar::AddressConvention eConv,
188 sal_Unicode cSeparator = ' ',
189 sal_Unicode cQuote = '\'');
191 /// Range to String core
192 static void GetStringFromAddress(
193 OUString& rString,
194 const ScAddress& rAddress,
195 const ScDocument* pDocument,
196 formula::FormulaGrammar::AddressConvention eConv,
197 sal_Unicode cSeparator = ' ',
198 sal_Bool bAppendStr = false,
199 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
200 static void GetStringFromRange(
201 OUString& rString,
202 const ScRange& rRange,
203 const ScDocument* pDocument,
204 formula::FormulaGrammar::AddressConvention eConv,
205 sal_Unicode cSeparator = ' ',
206 sal_Bool bAppendStr = false,
207 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
208 static void GetStringFromRangeList(
209 OUString& rString,
210 const ScRangeList* pRangeList,
211 const ScDocument* pDocument,
212 formula::FormulaGrammar::AddressConvention eConv,
213 sal_Unicode cSeparator = ' ',
214 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D));
216 static void GetStringFromArea(
217 OUString& rString,
218 const ScArea& rArea,
219 const ScDocument* pDocument,
220 formula::FormulaGrammar::AddressConvention eConv,
221 sal_Unicode cSeparator = ' ',
222 sal_Bool bAppendStr = false,
223 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
225 /// Range to String API
226 static void GetStringFromAddress(
227 OUString& rString,
228 const ::com::sun::star::table::CellAddress& rAddress,
229 const ScDocument* pDocument,
230 formula::FormulaGrammar::AddressConvention eConv,
231 sal_Unicode cSeparator = ' ',
232 sal_Bool bAppendStr = false,
233 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
234 static void GetStringFromRange(
235 OUString& rString,
236 const ::com::sun::star::table::CellRangeAddress& rRange,
237 const ScDocument* pDocument,
238 formula::FormulaGrammar::AddressConvention eConv,
239 sal_Unicode cSeparator = ' ',
240 sal_Bool bAppendStr = false,
241 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
242 static void GetStringFromRangeList(
243 OUString& rString,
244 const ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq,
245 const ScDocument* pDocument,
246 formula::FormulaGrammar::AddressConvention eConv,
247 sal_Unicode cSeparator = ' ',
248 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) );
250 /// XML Range to Calc Range
251 static void GetStringFromXMLRangeString(
252 OUString& rString,
253 const OUString& rXMLRange,
254 ScDocument* pDoc );
256 /// String to RangeData core
257 static ScRangeData* GetRangeDataFromString(const OUString& rString, const SCTAB nTab, const ScDocument* pDoc);
260 class ScArea
262 public:
263 ScArea( SCTAB tab = 0,
264 SCCOL colStart = 0,
265 SCROW rowStart = 0,
266 SCCOL colEnd = 0,
267 SCROW rowEnd = 0 );
269 ScArea( const ScArea& r );
271 ScArea& operator= ( const ScArea& r );
272 sal_Bool operator== ( const ScArea& r ) const;
273 sal_Bool operator!= ( const ScArea& r ) const { return !( operator==(r) ); }
275 public:
276 SCTAB nTab;
277 SCCOL nColStart;
278 SCROW nRowStart;
279 SCCOL nColEnd;
280 SCROW nRowEnd;
284 /// @return areas with reference and all db-areas
287 class SC_DLLPUBLIC ScAreaNameIterator
289 private:
290 ScRangeName* pRangeName;
291 ScDBCollection* pDBCollection;
292 ScRangeName::const_iterator maRNPos;
293 ScRangeName::const_iterator maRNEnd;
294 ScDBCollection::NamedDBs::const_iterator maDBPos;
295 ScDBCollection::NamedDBs::const_iterator maDBEnd;
296 bool bFirstPass;
298 public:
299 ScAreaNameIterator( ScDocument* pDoc );
300 ~ScAreaNameIterator() {}
302 bool Next( OUString& rName, ScRange& rRange );
303 bool WasDBName() const { return !bFirstPass; }
306 #endif // SC_RANGEUTL_HXX
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */