1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_RANGEUTL_HXX 25 #define SC_RANGEUTL_HXX 26 27 #include "address.hxx" 28 #include <tools/string.hxx> 29 #include "scdllapi.h" 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 SvStream; 37 38 class ScArea; 39 class ScDocument; 40 class ScRange; 41 class ScRangeName; 42 class ScRangeList; 43 class ScDBCollection; 44 45 enum RutlNameScope { RUTL_NONE=0, RUTL_NAMES, RUTL_DBASE }; 46 47 //------------------------------------------------------------------------ 48 49 class SC_DLLPUBLIC ScRangeUtil 50 { 51 public: 52 ScRangeUtil() {} 53 ~ScRangeUtil() {} 54 55 sal_Bool MakeArea ( const String& rAreaStr, 56 ScArea& rArea, 57 ScDocument* pDoc, 58 SCTAB nTab, 59 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const; 60 61 void CutPosString ( const String& theAreaStr, 62 String& thePosStr ) const; 63 64 sal_Bool IsAbsTabArea ( const String& rAreaStr, 65 ScDocument* pDoc, 66 ScArea*** pppAreas = 0, 67 sal_uInt16* pAreaCount = 0, 68 sal_Bool bAcceptCellRef = sal_False, 69 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const; 70 71 sal_Bool IsAbsArea ( const String& rAreaStr, 72 ScDocument* pDoc, 73 SCTAB nTab, 74 String* pCompleteStr = 0, 75 ScRefAddress* pStartPos = 0, 76 ScRefAddress* pEndPos = 0, 77 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const; 78 79 sal_Bool IsRefArea ( const String&, 80 ScDocument*, 81 SCTAB, 82 String* = 0, 83 ScRefAddress* = 0 ) const 84 { return sal_False; } 85 86 sal_Bool IsAbsPos ( const String& rPosStr, 87 ScDocument* pDoc, 88 SCTAB nTab, 89 String* pCompleteStr = 0, 90 ScRefAddress* pPosTripel = 0, 91 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const; 92 93 sal_Bool MakeRangeFromName ( const String& rName, 94 ScDocument* pDoc, 95 SCTAB nCurTab, 96 ScRange& rRange, 97 RutlNameScope eScope=RUTL_NAMES, 98 ScAddress::Details const & rDetails = ScAddress::detailsOOOa1 ) const; 99 }; 100 101 //------------------------------------------------------------------------ 102 103 class SC_DLLPUBLIC ScRangeStringConverter 104 { 105 public: 106 107 // helper methods 108 static void AssignString( 109 ::rtl::OUString& rString, 110 const ::rtl::OUString& rNewStr, 111 sal_Bool bAppendStr, 112 sal_Unicode cSeperator = ' '); 113 114 static sal_Int32 IndexOf( 115 const ::rtl::OUString& rString, 116 sal_Unicode cSearchChar, 117 sal_Int32 nOffset, 118 sal_Unicode cQuote = '\''); 119 120 static sal_Int32 IndexOfDifferent( 121 const ::rtl::OUString& rString, 122 sal_Unicode cSearchChar, 123 sal_Int32 nOffset ); 124 125 static sal_Int32 GetTokenCount( 126 const ::rtl::OUString& rString, 127 sal_Unicode cSeperator = ' ', 128 sal_Unicode cQuote = '\''); 129 130 static void GetTokenByOffset( 131 ::rtl::OUString& rToken, 132 const ::rtl::OUString& rString, 133 sal_Int32& nOffset, 134 sal_Unicode cSeperator = ' ', 135 sal_Unicode cQuote = '\''); 136 137 static void AppendTableName( 138 ::rtl::OUStringBuffer& rBuf, 139 const ::rtl::OUString& rTabName, 140 sal_Unicode cQuote = '\''); 141 142 // String to Range core 143 static sal_Bool GetAddressFromString( 144 ScAddress& rAddress, 145 const ::rtl::OUString& rAddressStr, 146 const ScDocument* pDocument, 147 formula::FormulaGrammar::AddressConvention eConv, 148 sal_Int32& nOffset, 149 sal_Unicode cSeperator = ' ', 150 sal_Unicode cQuote = '\''); 151 static sal_Bool GetRangeFromString( 152 ScRange& rRange, 153 const ::rtl::OUString& rRangeStr, 154 const ScDocument* pDocument, 155 formula::FormulaGrammar::AddressConvention eConv, 156 sal_Int32& nOffset, 157 sal_Unicode cSeperator = ' ', 158 sal_Unicode cQuote = '\''); 159 static sal_Bool GetRangeListFromString( 160 ScRangeList& rRangeList, 161 const ::rtl::OUString& rRangeListStr, 162 const ScDocument* pDocument, 163 formula::FormulaGrammar::AddressConvention eConv, 164 sal_Unicode cSeperator = ' ', 165 sal_Unicode cQuote = '\''); 166 167 static sal_Bool GetAreaFromString( 168 ScArea& rArea, 169 const ::rtl::OUString& rRangeStr, 170 const ScDocument* pDocument, 171 formula::FormulaGrammar::AddressConvention eConv, 172 sal_Int32& nOffset, 173 sal_Unicode cSeperator = ' ', 174 sal_Unicode cQuote = '\''); 175 176 // String to Range API 177 static sal_Bool GetAddressFromString( 178 ::com::sun::star::table::CellAddress& rAddress, 179 const ::rtl::OUString& rAddressStr, 180 const ScDocument* pDocument, 181 formula::FormulaGrammar::AddressConvention eConv, 182 sal_Int32& nOffset, 183 sal_Unicode cSeperator = ' ', 184 sal_Unicode cQuote = '\''); 185 static sal_Bool GetRangeFromString( 186 ::com::sun::star::table::CellRangeAddress& rRange, 187 const ::rtl::OUString& rRangeStr, 188 const ScDocument* pDocument, 189 formula::FormulaGrammar::AddressConvention eConv, 190 sal_Int32& nOffset, 191 sal_Unicode cSeperator = ' ', 192 sal_Unicode cQuote = '\''); 193 static sal_Bool GetRangeListFromString( 194 ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq, 195 const ::rtl::OUString& rRangeListStr, 196 const ScDocument* pDocument, 197 formula::FormulaGrammar::AddressConvention eConv, 198 sal_Unicode cSeperator = ' ', 199 sal_Unicode cQuote = '\''); 200 201 // Range to String core 202 static void GetStringFromAddress( 203 ::rtl::OUString& rString, 204 const ScAddress& rAddress, 205 const ScDocument* pDocument, 206 formula::FormulaGrammar::AddressConvention eConv, 207 sal_Unicode cSeperator = ' ', 208 sal_Bool bAppendStr = sal_False, 209 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) ); 210 static void GetStringFromRange( 211 ::rtl::OUString& rString, 212 const ScRange& rRange, 213 const ScDocument* pDocument, 214 formula::FormulaGrammar::AddressConvention eConv, 215 sal_Unicode cSeperator = ' ', 216 sal_Bool bAppendStr = sal_False, 217 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) ); 218 static void GetStringFromRangeList( 219 ::rtl::OUString& rString, 220 const ScRangeList* pRangeList, 221 const ScDocument* pDocument, 222 formula::FormulaGrammar::AddressConvention eConv, 223 sal_Unicode cSeperator = ' ', 224 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D)); 225 226 static void GetStringFromArea( 227 ::rtl::OUString& rString, 228 const ScArea& rArea, 229 const ScDocument* pDocument, 230 formula::FormulaGrammar::AddressConvention eConv, 231 sal_Unicode cSeperator = ' ', 232 sal_Bool bAppendStr = sal_False, 233 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) ); 234 235 // Range to String API 236 static void GetStringFromAddress( 237 ::rtl::OUString& rString, 238 const ::com::sun::star::table::CellAddress& rAddress, 239 const ScDocument* pDocument, 240 formula::FormulaGrammar::AddressConvention eConv, 241 sal_Unicode cSeperator = ' ', 242 sal_Bool bAppendStr = sal_False, 243 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) ); 244 static void GetStringFromRange( 245 ::rtl::OUString& rString, 246 const ::com::sun::star::table::CellRangeAddress& rRange, 247 const ScDocument* pDocument, 248 formula::FormulaGrammar::AddressConvention eConv, 249 sal_Unicode cSeperator = ' ', 250 sal_Bool bAppendStr = sal_False, 251 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) ); 252 static void GetStringFromRangeList( 253 ::rtl::OUString& rString, 254 const ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >& rRangeSeq, 255 const ScDocument* pDocument, 256 formula::FormulaGrammar::AddressConvention eConv, 257 sal_Unicode cSeperator = ' ', 258 sal_uInt16 nFormatFlags = (SCA_VALID | SCA_TAB_3D) ); 259 260 // XML Range to Calc Range 261 static void GetStringFromXMLRangeString( 262 ::rtl::OUString& rString, 263 const ::rtl::OUString& rXMLRange, 264 ScDocument* pDoc ); 265 }; 266 267 //------------------------------------------------------------------------ 268 269 class ScArea 270 { 271 public: 272 ScArea( SCTAB tab = 0, 273 SCCOL colStart = 0, 274 SCROW rowStart = 0, 275 SCCOL colEnd = 0, 276 SCROW rowEnd = 0 ); 277 278 ScArea( const ScArea& r ); 279 280 ScArea& operator= ( const ScArea& r ); 281 sal_Bool operator== ( const ScArea& r ) const; 282 sal_Bool operator!= ( const ScArea& r ) const { return !( operator==(r) ); } 283 284 public: 285 SCTAB nTab; 286 SCCOL nColStart; 287 SCROW nRowStart; 288 SCCOL nColEnd; 289 SCROW nRowEnd; 290 }; 291 292 //------------------------------------------------------------------------ 293 294 // 295 // gibt Bereiche mit Referenz und alle DB-Bereiche zurueck 296 // 297 298 class SC_DLLPUBLIC ScAreaNameIterator 299 { 300 private: 301 ScRangeName* pRangeName; 302 ScDBCollection* pDBCollection; 303 sal_Bool bFirstPass; 304 sal_uInt16 nPos; 305 String aStrNoName; 306 307 public: 308 ScAreaNameIterator( ScDocument* pDoc ); 309 ~ScAreaNameIterator() {} 310 311 sal_Bool Next( String& rName, ScRange& rRange ); 312 sal_Bool WasDBName() const { return !bFirstPass; } 313 }; 314 315 316 #endif // SC_RANGEUTL_HXX 317 318