update dev300-m57
[ooovba.git] / sc / inc / validat.hxx
blobc48652df6a50971a9b70a9f1d740fa69bea1e3f3
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>
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 String& rExprNmsp1 = EMPTY_STRING, const String& rExprNmsp2 = EMPTY_STRING,
97 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
98 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
99 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
100 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
101 ScDocument* pDocument, const ScAddress& rPos );
102 ScValidationData( const ScValidationData& r );
103 ScValidationData( ScDocument* pDocument, const ScValidationData& r );
104 virtual ~ScValidationData();
106 ScValidationData* Clone() const // echte Kopie
107 { return new ScValidationData( GetDocument(), *this ); }
108 ScValidationData* Clone(ScDocument* pNew) const
109 { return new ScValidationData( pNew, *this ); }
111 void ResetInput();
112 void ResetError();
113 void SetInput( const String& rTitle, const String& rMsg );
114 void SetError( const String& rTitle, const String& rMsg,
115 ScValidErrorStyle eStyle );
117 BOOL GetInput( String& rTitle, String& rMsg ) const
118 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
119 BOOL GetErrMsg( String& rTitle, String& rMsg, ScValidErrorStyle& rStyle ) const;
121 BOOL HasErrMsg() const { return bShowError; }
123 ScValidationMode GetDataMode() const { return eDataMode; }
125 inline sal_Int16 GetListType() const { return mnListType; }
126 inline void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
128 /** Returns true, if the validation cell will show a selection list.
129 @descr Use this instead of GetListType() which returns the raw property
130 regardless of the validation type. */
131 bool HasSelectionList() const;
132 /** Tries to fill the passed collection with list validation entries.
133 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
134 @param rStrings (out-param) The string list to fill with list validation entires.
135 @return true = rStrings has been filled with at least one entry. */
136 bool FillSelectionList( TypedScStrCollection& rStrings, const ScAddress& rPos ) const;
138 // mit String: bei Eingabe, mit Zelle: fuer Detektiv / RC_FORCED
139 BOOL IsDataValid( const String& rTest, const ScPatternAttr& rPattern,
140 const ScAddress& rPos ) const;
141 BOOL IsDataValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
143 // TRUE -> Abbruch
144 BOOL DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
145 void DoCalcError( ScFormulaCell* pCell ) const;
147 BOOL IsEmpty() const;
148 sal_uInt32 GetKey() const { return nKey; }
149 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // nur wenn nicht eingefuegt!
151 void SetUsed(BOOL bSet) { bIsUsed = bSet; }
152 BOOL IsUsed() const { return bIsUsed; }
154 BOOL EqualEntries( const ScValidationData& r ) const; // fuer Undo
156 // sortiert (per PTRARR) nach Index
157 // operator== nur fuer die Sortierung
158 BOOL operator ==( const ScValidationData& r ) const { return nKey == r.nKey; }
159 BOOL operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
161 private:
162 /** Tries to fill the passed collection with list validation entries.
163 @descr Fills the list only if it is non-NULL,
164 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
165 @param pCell can be NULL if it is not necessary to which element in the list is selected.
166 @param rPos the base address for relative references.
167 @param rTokArr Formula token array.
168 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
169 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
170 bool GetSelectionFromFormula( TypedScStrCollection* pStrings,
171 ScBaseCell* pCell, const ScAddress& rPos,
172 const ScTokenArray& rTokArr, int& rMatch ) const;
174 /** Tests, if pCell is equal to what the passed token array represents. */
175 bool IsEqualToTokenArray( ScBaseCell* pCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
177 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
178 bool IsListValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
182 // Liste der Bedingungen:
185 typedef ScValidationData* ScValidationDataPtr;
187 SV_DECL_PTRARR_SORT(ScValidationEntries_Impl, ScValidationDataPtr,
188 SC_COND_GROW, SC_COND_GROW)
190 class ScValidationDataList : public ScValidationEntries_Impl
192 public:
193 ScValidationDataList() {}
194 ScValidationDataList(const ScValidationDataList& rList);
195 ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
196 ~ScValidationDataList() {}
198 void InsertNew( ScValidationData* pNew )
199 { if (!Insert(pNew)) delete pNew; }
201 ScValidationData* GetData( sal_uInt32 nKey );
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