merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / inc / validat.hxx
blob1bff57055f820e61bc293b0f52dfe39dac79d08d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SC_VALIDAT_HXX
29 #define SC_VALIDAT_HXX
31 #include "conditio.hxx"
32 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
33 #include "scdllapi.h"
35 namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
37 class ScPatternAttr;
38 class ScTokenArray;
39 class TypedScStrCollection;
41 enum ScValidationMode
43 SC_VALID_ANY,
44 SC_VALID_WHOLE,
45 SC_VALID_DECIMAL,
46 SC_VALID_DATE,
47 SC_VALID_TIME,
48 SC_VALID_TEXTLEN,
49 SC_VALID_LIST,
50 SC_VALID_CUSTOM
53 enum ScValidErrorStyle
55 SC_VALERR_STOP,
56 SC_VALERR_WARNING,
57 SC_VALERR_INFO,
58 SC_VALERR_MACRO
62 // Eintrag fuer Gueltigkeit (es gibt nur eine Bedingung)
65 class SC_DLLPUBLIC ScValidationData : public ScConditionEntry
67 sal_uInt32 nKey; // Index in Attributen
69 ScValidationMode eDataMode;
70 BOOL bShowInput;
71 BOOL bShowError;
72 ScValidErrorStyle eErrorStyle;
73 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
74 String aInputTitle;
75 String aInputMessage;
76 String aErrorTitle;
77 String aErrorMessage;
79 BOOL bIsUsed; // temporaer beim Speichern
81 BOOL DoMacro( const ScAddress& rPos, const String& rInput,
82 ScFormulaCell* pCell, Window* pParent ) const;
84 BOOL DoScript( const ScAddress& rPos, const String& rInput,
85 ScFormulaCell* pCell, Window* pParent ) const;
87 using ScConditionEntry::operator==;
89 public:
90 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
91 const String& rExpr1, const String& rExpr2,
92 ScDocument* pDocument, const ScAddress& rPos,
93 const String& rExprNmsp1 = EMPTY_STRING, const String& rExprNmsp2 = EMPTY_STRING,
94 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
95 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
96 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
97 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
98 ScDocument* pDocument, const ScAddress& rPos );
99 ScValidationData( const ScValidationData& r );
100 ScValidationData( ScDocument* pDocument, const ScValidationData& r );
101 virtual ~ScValidationData();
103 ScValidationData* Clone() const // echte Kopie
104 { return new ScValidationData( GetDocument(), *this ); }
105 ScValidationData* Clone(ScDocument* pNew) const
106 { return new ScValidationData( pNew, *this ); }
108 void ResetInput();
109 void ResetError();
110 void SetInput( const String& rTitle, const String& rMsg );
111 void SetError( const String& rTitle, const String& rMsg,
112 ScValidErrorStyle eStyle );
114 BOOL GetInput( String& rTitle, String& rMsg ) const
115 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
116 BOOL GetErrMsg( String& rTitle, String& rMsg, ScValidErrorStyle& rStyle ) const;
118 BOOL HasErrMsg() const { return bShowError; }
120 ScValidationMode GetDataMode() const { return eDataMode; }
122 inline sal_Int16 GetListType() const { return mnListType; }
123 inline void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
125 /** Returns true, if the validation cell will show a selection list.
126 @descr Use this instead of GetListType() which returns the raw property
127 regardless of the validation type. */
128 bool HasSelectionList() const;
129 /** Tries to fill the passed collection with list validation entries.
130 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
131 @param rStrings (out-param) The string list to fill with list validation entires.
132 @return true = rStrings has been filled with at least one entry. */
133 bool FillSelectionList( TypedScStrCollection& rStrings, const ScAddress& rPos ) const;
135 // mit String: bei Eingabe, mit Zelle: fuer Detektiv / RC_FORCED
136 BOOL IsDataValid( const String& rTest, const ScPatternAttr& rPattern,
137 const ScAddress& rPos ) const;
138 BOOL IsDataValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
140 // TRUE -> Abbruch
141 BOOL DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
142 void DoCalcError( ScFormulaCell* pCell ) const;
144 BOOL IsEmpty() const;
145 sal_uInt32 GetKey() const { return nKey; }
146 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // nur wenn nicht eingefuegt!
148 void SetUsed(BOOL bSet) { bIsUsed = bSet; }
149 BOOL IsUsed() const { return bIsUsed; }
151 BOOL EqualEntries( const ScValidationData& r ) const; // fuer Undo
153 // sortiert (per PTRARR) nach Index
154 // operator== nur fuer die Sortierung
155 BOOL operator ==( const ScValidationData& r ) const { return nKey == r.nKey; }
156 BOOL operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
158 private:
159 /** Tries to fill the passed collection with list validation entries.
160 @descr Fills the list only if it is non-NULL,
161 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
162 @param pCell can be NULL if it is not necessary to which element in the list is selected.
163 @param rPos the base address for relative references.
164 @param rTokArr Formula token array.
165 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
166 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
167 bool GetSelectionFromFormula( TypedScStrCollection* pStrings,
168 ScBaseCell* pCell, const ScAddress& rPos,
169 const ScTokenArray& rTokArr, int& rMatch ) const;
171 /** Tests, if pCell is equal to what the passed token array represents. */
172 bool IsEqualToTokenArray( ScBaseCell* pCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
174 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
175 bool IsListValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
179 // Liste der Bedingungen:
182 typedef ScValidationData* ScValidationDataPtr;
184 SV_DECL_PTRARR_SORT(ScValidationEntries_Impl, ScValidationDataPtr,
185 SC_COND_GROW, SC_COND_GROW)
187 class ScValidationDataList : public ScValidationEntries_Impl
189 public:
190 ScValidationDataList() {}
191 ScValidationDataList(const ScValidationDataList& rList);
192 ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
193 ~ScValidationDataList() {}
195 void InsertNew( ScValidationData* pNew )
196 { if (!Insert(pNew)) delete pNew; }
198 ScValidationData* GetData( sal_uInt32 nKey );
200 void CompileXML();
201 void UpdateReference( UpdateRefMode eUpdateRefMode,
202 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
203 void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
205 /** Temporarily during save, returns RefManager's decision whether ALL
206 * references are marked now. */
207 bool MarkUsedExternalReferences() const;
209 BOOL operator==( const ScValidationDataList& r ) const; // fuer Ref-Undo
212 #endif