sync master with lastest vba changes
[ooovba.git] / sc / inc / validat.hxx
blob1a4086cc56316ac80ddf93fe87cd0c139f609dc4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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>
36 #include "scdllapi.h"
38 namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
40 class ScPatternAttr;
41 class ScTokenArray;
42 class TypedScStrCollection;
44 enum ScValidationMode
46 SC_VALID_ANY,
47 SC_VALID_WHOLE,
48 SC_VALID_DECIMAL,
49 SC_VALID_DATE,
50 SC_VALID_TIME,
51 SC_VALID_TEXTLEN,
52 SC_VALID_LIST,
53 SC_VALID_CUSTOM
56 enum ScValidErrorStyle
58 SC_VALERR_STOP,
59 SC_VALERR_WARNING,
60 SC_VALERR_INFO,
61 SC_VALERR_MACRO
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;
73 BOOL bShowInput;
74 BOOL bShowError;
75 ScValidErrorStyle eErrorStyle;
76 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
77 String aInputTitle;
78 String aInputMessage;
79 String aErrorTitle;
80 String aErrorMessage;
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==;
92 public:
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 ); }
109 void ResetInput();
110 void ResetError();
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;
141 // TRUE -> Abbruch
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; }
159 private:
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
190 public:
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 );
201 void ResetUsed();
203 void CompileXML();
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
215 #endif