1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rangenam.hxx,v $
10 * $Revision: 1.16.32.1 $
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_RANGENAM_HXX
32 #define SC_RANGENAM_HXX
34 #include "global.hxx" // -> enum UpdateRefMode
35 #include "address.hxx"
36 #include "collect.hxx"
37 #include "formula/grammar.hxx"
42 //------------------------------------------------------------------------
51 //------------------------------------------------------------------------
53 typedef USHORT RangeType
;
55 #define RT_NAME ((RangeType)0x0000)
56 #define RT_DATABASE ((RangeType)0x0001)
57 #define RT_CRITERIA ((RangeType)0x0002)
58 #define RT_PRINTAREA ((RangeType)0x0004)
59 #define RT_COLHEADER ((RangeType)0x0008)
60 #define RT_ROWHEADER ((RangeType)0x0010)
61 #define RT_ABSAREA ((RangeType)0x0020)
62 #define RT_REFAREA ((RangeType)0x0040)
63 #define RT_ABSPOS ((RangeType)0x0080)
64 #define RT_SHARED ((RangeType)0x0100)
65 #define RT_SHAREDMOD ((RangeType)0x0200)
67 //------------------------------------------------------------------------
72 class ScRangeData
: public ScDataObject
76 String aUpperName
; // #i62977# for faster searching (aName is never modified after ctor)
82 BOOL bModified
; // wird bei UpdateReference gesetzt/geloescht
84 // max row and column to use for wrapping of references. If -1 use the
85 // application's default.
89 friend class ScRangeName
;
90 ScRangeData( USHORT nIndex
);
92 typedef ::std::map
<sal_uInt16
, sal_uInt16
> IndexMap
;
94 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
96 const String
& rSymbol
,
97 const ScAddress
& rAdr
= ScAddress(),
98 RangeType nType
= RT_NAME
,
99 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
100 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
102 const ScTokenArray
& rArr
,
103 const ScAddress
& rAdr
= ScAddress(),
104 RangeType nType
= RT_NAME
);
105 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
107 const ScAddress
& rTarget
);
108 // rTarget ist ABSPOS Sprungmarke
109 ScRangeData(const ScRangeData
& rScRangeData
);
111 SC_DLLPUBLIC
virtual ~ScRangeData();
114 virtual ScDataObject
* Clone() const;
116 BOOL
operator== (const ScRangeData
& rData
) const;
118 void GetName( String
& rName
) const { rName
= aName
; }
119 const String
& GetName( void ) const { return aName
; }
120 const String
& GetUpperName( void ) const { return aUpperName
; }
121 ScAddress
GetPos() const { return aPos
; }
122 // Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben
123 void SetIndex( USHORT nInd
) { nIndex
= nInd
; }
124 USHORT
GetIndex() const { return nIndex
; }
125 ScTokenArray
* GetCode() { return pCode
; }
127 BOOL
HasReferences() const;
128 void SetDocument( ScDocument
* pDocument
){ pDoc
= pDocument
; }
129 ScDocument
* GetDocument() const { return pDoc
; }
130 void SetType( RangeType nType
) { eType
= nType
; }
131 void AddType( RangeType nType
) { eType
= eType
|nType
; }
132 RangeType
GetType() const { return eType
; }
133 BOOL
HasType( RangeType nType
) const;
134 SC_DLLPUBLIC
void GetSymbol( String
& rSymbol
, const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
) const;
135 void UpdateSymbol( rtl::OUStringBuffer
& rBuffer
, const ScAddress
&,
136 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
137 void UpdateReference( UpdateRefMode eUpdateRefMode
,
139 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
140 BOOL
IsModified() const { return bModified
; }
142 SC_DLLPUBLIC
void GuessPosition();
144 void UpdateTranspose( const ScRange
& rSource
, const ScAddress
& rDest
);
145 void UpdateGrow( const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
147 SC_DLLPUBLIC BOOL
IsReference( ScRange
& rRef
) const;
148 BOOL
IsReference( ScRange
& rRef
, const ScAddress
& rPos
) const;
149 BOOL
IsValidReference( ScRange
& rRef
) const;
151 //UNUSED2009-05 BOOL IsRangeAtCursor( const ScAddress&, BOOL bStartOnly ) const;
152 BOOL
IsRangeAtBlock( const ScRange
& ) const;
154 void UpdateTabRef(SCTAB nOldTable
, USHORT nFlag
, SCTAB nNewTable
);
155 void TransferTabRef( SCTAB nOldTab
, SCTAB nNewTab
);
157 void ValidateTabRefs();
159 void ReplaceRangeNamesInUse( const ScIndexMap
& rMap
);
160 void ReplaceRangeNamesInUse( const IndexMap
& rMap
);
162 static void MakeValidName( String
& rName
);
163 SC_DLLPUBLIC
static BOOL
IsNameValid( const String
& rName
, ScDocument
* pDoc
);
165 SC_DLLPUBLIC
void SetMaxRow(SCROW nRow
);
166 SCROW
GetMaxRow() const;
167 SC_DLLPUBLIC
void SetMaxCol(SCCOL nCol
);
168 SCCOL
GetMaxCol() const;
171 inline BOOL
ScRangeData::HasType( RangeType nType
) const
173 return ( ( eType
& nType
) == nType
);
176 extern "C" int SAL_CALL
ScRangeData_QsortNameCompare( const void*, const void* );
178 #if defined( ICC ) && defined( OS2 )
179 static int _Optlink
ICCQsortNameCompare( const void* a
, const void* b
)
180 { return ScRangeData_QsortNameCompare(a
,b
); }
183 //------------------------------------------------------------------------
185 class ScRangeName
: public ScSortedCollection
189 USHORT nSharedMaxIndex
;
191 using ScSortedCollection::Clone
; // calcwarnings: shouldn't be used
194 ScRangeName(USHORT nLim
= 4, USHORT nDel
= 4, BOOL bDup
= FALSE
,
195 ScDocument
* pDocument
= NULL
) :
196 ScSortedCollection ( nLim
, nDel
, bDup
),
198 nSharedMaxIndex ( 1 ) {} // darf nicht 0 sein!!
200 ScRangeName(const ScRangeName
& rScRangeName
, ScDocument
* pDocument
);
202 virtual ScDataObject
* Clone(ScDocument
* pDocP
) const
203 { return new ScRangeName(*this, pDocP
); }
204 ScRangeData
* operator[]( const USHORT nIndex
) const
205 { return (ScRangeData
*)At(nIndex
); }
206 virtual short Compare(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const;
207 virtual BOOL
IsEqual(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const;
209 //UNUSED2009-05 ScRangeData* GetRangeAtCursor( const ScAddress&, BOOL bStartOnly ) const;
210 SC_DLLPUBLIC ScRangeData
* GetRangeAtBlock( const ScRange
& ) const;
212 SC_DLLPUBLIC BOOL
SearchName( const String
& rName
, USHORT
& rPos
) const;
213 // SearchNameUpper must be called with an upper-case search string
214 BOOL
SearchNameUpper( const String
& rUpperName
, USHORT
& rPos
) const;
215 void UpdateReference(UpdateRefMode eUpdateRefMode
,
216 const ScRange
& rRange
,
217 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
218 void UpdateTabRef(SCTAB nTable
, USHORT nFlag
, SCTAB nNewTable
= 0);
219 void UpdateTranspose( const ScRange
& rSource
, const ScAddress
& rDest
);
220 void UpdateGrow( const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
221 virtual BOOL
Insert(ScDataObject
* pScDataObject
);
222 SC_DLLPUBLIC ScRangeData
* FindIndex(USHORT nIndex
);
223 USHORT
GetSharedMaxIndex() { return nSharedMaxIndex
; }
224 void SetSharedMaxIndex(USHORT nInd
) { nSharedMaxIndex
= nInd
; }
225 USHORT
GetEntryIndex();