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: validat.hxx,v $
10 * $Revision: 1.15.32.3 $
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_VALIDAT_HXX
32 #define SC_VALIDAT_HXX
34 #include "conditio.hxx"
35 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
38 namespace ValidListType
= ::com::sun::star::sheet::TableValidationVisibility
;
42 class TypedScStrCollection
;
56 enum ScValidErrorStyle
65 // Eintrag fuer Gueltigkeit (es gibt nur eine Bedingung)
68 class SC_DLLPUBLIC ScValidationData
: public ScConditionEntry
70 sal_uInt32 nKey
; // Index in Attributen
72 ScValidationMode eDataMode
;
75 ScValidErrorStyle eErrorStyle
;
76 sal_Int16 mnListType
; // selection list type: none, unsorted, sorted.
82 BOOL bIsUsed
; // temporaer beim Speichern
84 BOOL
DoMacro( const ScAddress
& rPos
, const String
& rInput
,
85 ScFormulaCell
* pCell
, Window
* pParent
) const;
87 BOOL
DoScript( const ScAddress
& rPos
, const String
& rInput
,
88 ScFormulaCell
* pCell
, Window
* pParent
) const;
90 using ScConditionEntry::operator==;
93 ScValidationData( ScValidationMode eMode
, ScConditionMode eOper
,
94 const String
& rExpr1
, const String
& rExpr2
,
95 ScDocument
* pDocument
, const ScAddress
& rPos
,
96 const formula::FormulaGrammar::Grammar eGrammar
= formula::FormulaGrammar::GRAM_DEFAULT
);
97 ScValidationData( ScValidationMode eMode
, ScConditionMode eOper
,
98 const ScTokenArray
* pArr1
, const ScTokenArray
* pArr2
,
99 ScDocument
* pDocument
, const ScAddress
& rPos
);
100 ScValidationData( const ScValidationData
& r
);
101 ScValidationData( ScDocument
* pDocument
, const ScValidationData
& r
);
102 virtual ~ScValidationData();
104 ScValidationData
* Clone() const // echte Kopie
105 { return new ScValidationData( GetDocument(), *this ); }
106 ScValidationData
* Clone(ScDocument
* pNew
) const
107 { return new ScValidationData( pNew
, *this ); }
111 void SetInput( const String
& rTitle
, const String
& rMsg
);
112 void SetError( const String
& rTitle
, const String
& rMsg
,
113 ScValidErrorStyle eStyle
);
115 BOOL
GetInput( String
& rTitle
, String
& rMsg
) const
116 { rTitle
= aInputTitle
; rMsg
= aInputMessage
; return bShowInput
; }
117 BOOL
GetErrMsg( String
& rTitle
, String
& rMsg
, ScValidErrorStyle
& rStyle
) const;
119 BOOL
HasErrMsg() const { return bShowError
; }
121 ScValidationMode
GetDataMode() const { return eDataMode
; }
123 inline sal_Int16
GetListType() const { return mnListType
; }
124 inline void SetListType( sal_Int16 nListType
) { mnListType
= nListType
; }
126 /** Returns true, if the validation cell will show a selection list.
127 @descr Use this instead of GetListType() which returns the raw property
128 regardless of the validation type. */
129 bool HasSelectionList() const;
130 /** Tries to fill the passed collection with list validation entries.
131 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
132 @param rStrings (out-param) The string list to fill with list validation entires.
133 @return true = rStrings has been filled with at least one entry. */
134 bool FillSelectionList( TypedScStrCollection
& rStrings
, const ScAddress
& rPos
) const;
136 // mit String: bei Eingabe, mit Zelle: fuer Detektiv / RC_FORCED
137 BOOL
IsDataValid( const String
& rTest
, const ScPatternAttr
& rPattern
,
138 const ScAddress
& rPos
) const;
139 BOOL
IsDataValid( ScBaseCell
* pCell
, const ScAddress
& rPos
) const;
142 BOOL
DoError( Window
* pParent
, const String
& rInput
, const ScAddress
& rPos
) const;
143 void DoCalcError( ScFormulaCell
* pCell
) const;
145 BOOL
IsEmpty() const;
146 sal_uInt32
GetKey() const { return nKey
; }
147 void SetKey(sal_uInt32 nNew
) { nKey
= nNew
; } // nur wenn nicht eingefuegt!
149 void SetUsed(BOOL bSet
) { bIsUsed
= bSet
; }
150 BOOL
IsUsed() const { return bIsUsed
; }
152 BOOL
EqualEntries( const ScValidationData
& r
) const; // fuer Undo
154 // sortiert (per PTRARR) nach Index
155 // operator== nur fuer die Sortierung
156 BOOL
operator ==( const ScValidationData
& r
) const { return nKey
== r
.nKey
; }
157 BOOL
operator < ( const ScValidationData
& r
) const { return nKey
< r
.nKey
; }
160 /** Tries to fill the passed collection with list validation entries.
161 @descr Fills the list only if it is non-NULL,
162 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
163 @param pCell can be NULL if it is not necessary to which element in the list is selected.
164 @param rPos the base address for relative references.
165 @param rTokArr Formula token array.
166 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
167 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
168 bool GetSelectionFromFormula( TypedScStrCollection
* pStrings
,
169 ScBaseCell
* pCell
, const ScAddress
& rPos
,
170 const ScTokenArray
& rTokArr
, int& rMatch
) const;
172 /** Tests, if pCell is equal to what the passed token array represents. */
173 bool IsEqualToTokenArray( ScBaseCell
* pCell
, const ScAddress
& rPos
, const ScTokenArray
& rTokArr
) const;
175 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
176 bool IsListValid( ScBaseCell
* pCell
, const ScAddress
& rPos
) const;
180 // Liste der Bedingungen:
183 typedef ScValidationData
* ScValidationDataPtr
;
185 SV_DECL_PTRARR_SORT(ScValidationEntries_Impl
, ScValidationDataPtr
,
186 SC_COND_GROW
, SC_COND_GROW
)
188 class ScValidationDataList
: public ScValidationEntries_Impl
191 ScValidationDataList() {}
192 ScValidationDataList(const ScValidationDataList
& rList
);
193 ScValidationDataList(ScDocument
* pNewDoc
, const ScValidationDataList
& rList
);
194 ~ScValidationDataList() {}
196 void InsertNew( ScValidationData
* pNew
)
197 { if (!Insert(pNew
)) delete pNew
; }
199 ScValidationData
* GetData( sal_uInt32 nKey
);
204 void UpdateReference( UpdateRefMode eUpdateRefMode
,
205 const ScRange
& rRange
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
206 void UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
);
208 /** Temporarily during save, returns RefManager's decision whether ALL
209 * references are marked now. */
210 bool MarkUsedExternalReferences() const;
212 BOOL
operator==( const ScValidationDataList
& r
) const; // fuer Ref-Undo