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_RANGENAM_HXX 29 #define SC_RANGENAM_HXX 30 31 #include "global.hxx" // -> enum UpdateRefMode 32 #include "address.hxx" 33 #include "collect.hxx" 34 #include "formula/grammar.hxx" 35 #include "scdllapi.h" 36 37 #include <map> 38 39 //------------------------------------------------------------------------ 40 41 class ScDocument; 42 43 namespace rtl { 44 class OUStringBuffer; 45 } 46 47 48 //------------------------------------------------------------------------ 49 50 typedef sal_uInt16 RangeType; 51 52 #define RT_NAME ((RangeType)0x0000) 53 #define RT_DATABASE ((RangeType)0x0001) 54 #define RT_CRITERIA ((RangeType)0x0002) 55 #define RT_PRINTAREA ((RangeType)0x0004) 56 #define RT_COLHEADER ((RangeType)0x0008) 57 #define RT_ROWHEADER ((RangeType)0x0010) 58 #define RT_ABSAREA ((RangeType)0x0020) 59 #define RT_REFAREA ((RangeType)0x0040) 60 #define RT_ABSPOS ((RangeType)0x0080) 61 #define RT_SHARED ((RangeType)0x0100) 62 #define RT_SHAREDMOD ((RangeType)0x0200) 63 64 //------------------------------------------------------------------------ 65 66 class ScTokenArray; 67 68 class ScRangeData : public ScDataObject 69 { 70 private: 71 String aName; 72 String aUpperName; // #i62977# for faster searching (aName is never modified after ctor) 73 ScTokenArray* pCode; 74 ScAddress aPos; 75 RangeType eType; 76 ScDocument* pDoc; 77 sal_uInt16 nIndex; 78 sal_Bool bModified; // wird bei UpdateReference gesetzt/geloescht 79 80 // max row and column to use for wrapping of references. If -1 use the 81 // application's default. 82 SCROW mnMaxRow; 83 SCCOL mnMaxCol; 84 85 friend class ScRangeName; 86 ScRangeData( sal_uInt16 nIndex ); 87 public: 88 typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap; 89 90 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc, 91 const String& rName, 92 const String& rSymbol, 93 const ScAddress& rAdr = ScAddress(), 94 RangeType nType = RT_NAME, 95 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ); 96 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc, 97 const String& rName, 98 const ScTokenArray& rArr, 99 const ScAddress& rAdr = ScAddress(), 100 RangeType nType = RT_NAME ); 101 SC_DLLPUBLIC ScRangeData( ScDocument* pDoc, 102 const String& rName, 103 const ScAddress& rTarget ); 104 // rTarget ist ABSPOS Sprungmarke 105 ScRangeData(const ScRangeData& rScRangeData); 106 107 SC_DLLPUBLIC virtual ~ScRangeData(); 108 109 110 virtual ScDataObject* Clone() const; 111 112 sal_Bool operator== (const ScRangeData& rData) const; 113 114 void GetName( String& rName ) const { rName = aName; } 115 const String& GetName( void ) const { return aName; } 116 const String& GetUpperName( void ) const { return aUpperName; } 117 ScAddress GetPos() const { return aPos; } 118 // Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben 119 void SetIndex( sal_uInt16 nInd ) { nIndex = nInd; } 120 sal_uInt16 GetIndex() const { return nIndex; } 121 ScTokenArray* GetCode() { return pCode; } 122 sal_uInt16 GetErrCode(); 123 sal_Bool HasReferences() const; 124 void SetDocument( ScDocument* pDocument){ pDoc = pDocument; } 125 ScDocument* GetDocument() const { return pDoc; } 126 void SetType( RangeType nType ) { eType = nType; } 127 void AddType( RangeType nType ) { eType = eType|nType; } 128 RangeType GetType() const { return eType; } 129 sal_Bool HasType( RangeType nType ) const; 130 SC_DLLPUBLIC void GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const; 131 void UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress&, 132 const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ); 133 void UpdateReference( UpdateRefMode eUpdateRefMode, 134 const ScRange& r, 135 SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 136 sal_Bool IsModified() const { return bModified; } 137 138 SC_DLLPUBLIC void GuessPosition(); 139 140 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest ); 141 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ); 142 143 SC_DLLPUBLIC sal_Bool IsReference( ScRange& rRef ) const; 144 sal_Bool IsReference( ScRange& rRef, const ScAddress& rPos ) const; 145 sal_Bool IsValidReference( ScRange& rRef ) const; 146 147 //UNUSED2009-05 sal_Bool IsRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const; 148 sal_Bool IsRangeAtBlock( const ScRange& ) const; 149 150 void UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable); 151 void TransferTabRef( SCTAB nOldTab, SCTAB nNewTab ); 152 153 void ValidateTabRefs(); 154 155 void ReplaceRangeNamesInUse( const IndexMap& rMap ); 156 157 static void MakeValidName( String& rName ); 158 SC_DLLPUBLIC static sal_Bool IsNameValid( const String& rName, ScDocument* pDoc ); 159 160 SC_DLLPUBLIC void SetMaxRow(SCROW nRow); 161 SCROW GetMaxRow() const; 162 SC_DLLPUBLIC void SetMaxCol(SCCOL nCol); 163 SCCOL GetMaxCol() const; 164 }; 165 166 inline sal_Bool ScRangeData::HasType( RangeType nType ) const 167 { 168 return ( ( eType & nType ) == nType ); 169 } 170 171 extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* ); 172 173 #if defined( ICC ) && defined( OS2 ) 174 static int _Optlink ICCQsortNameCompare( const void* a, const void* b) 175 { return ScRangeData_QsortNameCompare(a,b); } 176 #endif 177 178 //------------------------------------------------------------------------ 179 180 class ScRangeName : public ScSortedCollection 181 { 182 private: 183 ScDocument* pDoc; 184 sal_uInt16 nSharedMaxIndex; 185 186 using ScSortedCollection::Clone; // calcwarnings: shouldn't be used 187 188 public: 189 ScRangeName(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False, 190 ScDocument* pDocument = NULL) : 191 ScSortedCollection ( nLim, nDel, bDup ), 192 pDoc ( pDocument ), 193 nSharedMaxIndex ( 1 ) {} // darf nicht 0 sein!! 194 195 ScRangeName(const ScRangeName& rScRangeName, ScDocument* pDocument); 196 197 virtual ScDataObject* Clone(ScDocument* pDocP) const 198 { return new ScRangeName(*this, pDocP); } 199 ScRangeData* operator[]( const sal_uInt16 nIndex) const 200 { return (ScRangeData*)At(nIndex); } 201 virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const; 202 virtual sal_Bool IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const; 203 204 //UNUSED2009-05 ScRangeData* GetRangeAtCursor( const ScAddress&, sal_Bool bStartOnly ) const; 205 SC_DLLPUBLIC ScRangeData* GetRangeAtBlock( const ScRange& ) const; 206 207 SC_DLLPUBLIC sal_Bool SearchName( const String& rName, sal_uInt16& rPos ) const; 208 // SearchNameUpper must be called with an upper-case search string 209 sal_Bool SearchNameUpper( const String& rUpperName, sal_uInt16& rPos ) const; 210 void UpdateReference(UpdateRefMode eUpdateRefMode, 211 const ScRange& rRange, 212 SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); 213 void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0); 214 void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest ); 215 void UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY ); 216 virtual sal_Bool Insert(ScDataObject* pScDataObject); 217 SC_DLLPUBLIC ScRangeData* FindIndex(sal_uInt16 nIndex); 218 sal_uInt16 GetSharedMaxIndex() { return nSharedMaxIndex; } 219 void SetSharedMaxIndex(sal_uInt16 nInd) { nSharedMaxIndex = nInd; } 220 sal_uInt16 GetEntryIndex(); 221 }; 222 223 #endif 224 225