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 //------------------------------------------------------------------------
71 class ScRangeData
: public ScDataObject
75 String aUpperName
; // #i62977# for faster searching (aName is never modified after ctor)
81 BOOL bModified
; // wird bei UpdateReference gesetzt/geloescht
83 // max row and column to use for wrapping of references. If -1 use the
84 // application's default.
88 friend class ScRangeName
;
89 ScRangeData( USHORT nIndex
);
91 typedef ::std::map
<sal_uInt16
, sal_uInt16
> IndexMap
;
93 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
95 const String
& rSymbol
,
96 const ScAddress
& rAdr
= ScAddress(),
97 RangeType nType
= RT_NAME
,
98 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
99 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
101 const ScTokenArray
& rArr
,
102 const ScAddress
& rAdr
= ScAddress(),
103 RangeType nType
= RT_NAME
);
104 SC_DLLPUBLIC
ScRangeData( ScDocument
* pDoc
,
106 const ScAddress
& rTarget
);
107 // rTarget ist ABSPOS Sprungmarke
108 ScRangeData(const ScRangeData
& rScRangeData
);
110 SC_DLLPUBLIC
virtual ~ScRangeData();
113 virtual ScDataObject
* Clone() const;
115 BOOL
operator== (const ScRangeData
& rData
) const;
117 void GetName( String
& rName
) const { rName
= aName
; }
118 const String
& GetName( void ) const { return aName
; }
119 const String
& GetUpperName( void ) const { return aUpperName
; }
120 ScAddress
GetPos() const { return aPos
; }
121 // Der Index muss eindeutig sein. Ist er 0, wird ein neuer Index vergeben
122 void SetIndex( USHORT nInd
) { nIndex
= nInd
; }
123 USHORT
GetIndex() const { return nIndex
; }
124 ScTokenArray
* GetCode() { return pCode
; }
126 BOOL
HasReferences() const;
127 void SetDocument( ScDocument
* pDocument
){ pDoc
= pDocument
; }
128 ScDocument
* GetDocument() const { return pDoc
; }
129 void SetType( RangeType nType
) { eType
= nType
; }
130 void AddType( RangeType nType
) { eType
= eType
|nType
; }
131 RangeType
GetType() const { return eType
; }
132 BOOL
HasType( RangeType nType
) const;
133 SC_DLLPUBLIC
void GetSymbol( String
& rSymbol
, const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
) const;
134 void UpdateSymbol( rtl::OUStringBuffer
& rBuffer
, const ScAddress
&,
135 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
136 void UpdateReference( UpdateRefMode eUpdateRefMode
,
138 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
139 BOOL
IsModified() const { return bModified
; }
141 SC_DLLPUBLIC
void GuessPosition();
143 void UpdateTranspose( const ScRange
& rSource
, const ScAddress
& rDest
);
144 void UpdateGrow( const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
146 SC_DLLPUBLIC BOOL
IsReference( ScRange
& rRef
) const;
147 BOOL
IsReference( ScRange
& rRef
, const ScAddress
& rPos
) const;
148 BOOL
IsValidReference( ScRange
& rRef
) const;
150 //UNUSED2009-05 BOOL IsRangeAtCursor( const ScAddress&, BOOL bStartOnly ) const;
151 BOOL
IsRangeAtBlock( const ScRange
& ) const;
153 void UpdateTabRef(SCTAB nOldTable
, USHORT nFlag
, SCTAB nNewTable
);
154 void TransferTabRef( SCTAB nOldTab
, SCTAB nNewTab
);
156 void ValidateTabRefs();
158 void ReplaceRangeNamesInUse( const IndexMap
& rMap
);
160 static void MakeValidName( String
& rName
);
161 SC_DLLPUBLIC
static BOOL
IsNameValid( const String
& rName
, ScDocument
* pDoc
);
163 SC_DLLPUBLIC
void SetMaxRow(SCROW nRow
);
164 SCROW
GetMaxRow() const;
165 SC_DLLPUBLIC
void SetMaxCol(SCCOL nCol
);
166 SCCOL
GetMaxCol() const;
169 inline BOOL
ScRangeData::HasType( RangeType nType
) const
171 return ( ( eType
& nType
) == nType
);
174 extern "C" int SAL_CALL
ScRangeData_QsortNameCompare( const void*, const void* );
176 #if defined( ICC ) && defined( OS2 )
177 static int _Optlink
ICCQsortNameCompare( const void* a
, const void* b
)
178 { return ScRangeData_QsortNameCompare(a
,b
); }
181 //------------------------------------------------------------------------
183 class ScRangeName
: public ScSortedCollection
187 USHORT nSharedMaxIndex
;
189 using ScSortedCollection::Clone
; // calcwarnings: shouldn't be used
192 ScRangeName(USHORT nLim
= 4, USHORT nDel
= 4, BOOL bDup
= FALSE
,
193 ScDocument
* pDocument
= NULL
) :
194 ScSortedCollection ( nLim
, nDel
, bDup
),
196 nSharedMaxIndex ( 1 ) {} // darf nicht 0 sein!!
198 ScRangeName(const ScRangeName
& rScRangeName
, ScDocument
* pDocument
);
200 virtual ScDataObject
* Clone(ScDocument
* pDocP
) const
201 { return new ScRangeName(*this, pDocP
); }
202 ScRangeData
* operator[]( const USHORT nIndex
) const
203 { return (ScRangeData
*)At(nIndex
); }
204 virtual short Compare(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const;
205 virtual BOOL
IsEqual(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const;
207 //UNUSED2009-05 ScRangeData* GetRangeAtCursor( const ScAddress&, BOOL bStartOnly ) const;
208 SC_DLLPUBLIC ScRangeData
* GetRangeAtBlock( const ScRange
& ) const;
210 SC_DLLPUBLIC BOOL
SearchName( const String
& rName
, USHORT
& rPos
) const;
211 // SearchNameUpper must be called with an upper-case search string
212 BOOL
SearchNameUpper( const String
& rUpperName
, USHORT
& rPos
) const;
213 void UpdateReference(UpdateRefMode eUpdateRefMode
,
214 const ScRange
& rRange
,
215 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
216 void UpdateTabRef(SCTAB nTable
, USHORT nFlag
, SCTAB nNewTable
= 0);
217 void UpdateTranspose( const ScRange
& rSource
, const ScAddress
& rDest
);
218 void UpdateGrow( const ScRange
& rArea
, SCCOL nGrowX
, SCROW nGrowY
);
219 virtual BOOL
Insert(ScDataObject
* pScDataObject
);
220 SC_DLLPUBLIC ScRangeData
* FindIndex(USHORT nIndex
);
221 USHORT
GetSharedMaxIndex() { return nSharedMaxIndex
; }
222 void SetSharedMaxIndex(USHORT nInd
) { nSharedMaxIndex
= nInd
; }
223 USHORT
GetEntryIndex();