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