xref: /aoo42x/main/sc/inc/validat.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_VALIDAT_HXX
25 #define SC_VALIDAT_HXX
26 
27 #include "conditio.hxx"
28 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
29 #include "scdllapi.h"
30 
31 namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
32 
33 class ScPatternAttr;
34 class ScTokenArray;
35 class TypedScStrCollection;
36 
37 enum ScValidationMode
38 {
39 	SC_VALID_ANY,
40 	SC_VALID_WHOLE,
41 	SC_VALID_DECIMAL,
42 	SC_VALID_DATE,
43 	SC_VALID_TIME,
44 	SC_VALID_TEXTLEN,
45 	SC_VALID_LIST,
46 	SC_VALID_CUSTOM
47 };
48 
49 enum ScValidErrorStyle
50 {
51 	SC_VALERR_STOP,
52 	SC_VALERR_WARNING,
53 	SC_VALERR_INFO,
54 	SC_VALERR_MACRO
55 };
56 
57 //
58 //	Eintrag fuer Gueltigkeit (es gibt nur eine Bedingung)
59 //
60 
61 class SC_DLLPUBLIC ScValidationData : public ScConditionEntry
62 {
63 	sal_uInt32			nKey;				// Index in Attributen
64 
65 	ScValidationMode	eDataMode;
66 	sal_Bool				bShowInput;
67 	sal_Bool				bShowError;
68 	ScValidErrorStyle	eErrorStyle;
69     sal_Int16           mnListType;         // selection list type: none, unsorted, sorted.
70 	String				aInputTitle;
71 	String				aInputMessage;
72 	String				aErrorTitle;
73 	String				aErrorMessage;
74 
75 	sal_Bool				bIsUsed;			// temporaer beim Speichern
76 
77 	sal_Bool			DoMacro( const ScAddress& rPos, const String& rInput,
78 								ScFormulaCell* pCell, Window* pParent ) const;
79 
80 	sal_Bool			DoScript( const ScAddress& rPos, const String& rInput,
81 								ScFormulaCell* pCell, Window* pParent ) const;
82 
83     using ScConditionEntry::operator==;
84 
85 public:
86 			ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
87 								const String& rExpr1, const String& rExpr2,
88 								ScDocument* pDocument, const ScAddress& rPos,
89                                 const String& rExprNmsp1 = EMPTY_STRING, const String& rExprNmsp2 = EMPTY_STRING,
90                                 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
91                                 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
92 			ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
93 								const ScTokenArray* pArr1, const ScTokenArray* pArr2,
94 								ScDocument* pDocument, const ScAddress& rPos );
95 			ScValidationData( const ScValidationData& r );
96 			ScValidationData( ScDocument* pDocument, const ScValidationData& r );
97 	virtual	~ScValidationData();
98 
Clone() const99 	ScValidationData* Clone() const		// echte Kopie
100 					{ return new ScValidationData( GetDocument(), *this ); }
Clone(ScDocument * pNew) const101 	ScValidationData* Clone(ScDocument* pNew) const
102 					{ return new ScValidationData( pNew, *this ); }
103 
104 	void			ResetInput();
105 	void			ResetError();
106 	void			SetInput( const String& rTitle, const String& rMsg );
107 	void			SetError( const String& rTitle, const String& rMsg,
108 								ScValidErrorStyle eStyle );
109 
GetInput(String & rTitle,String & rMsg) const110 	sal_Bool			GetInput( String& rTitle, String& rMsg ) const
111 						{ rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
112 	sal_Bool			GetErrMsg( String& rTitle, String& rMsg, ScValidErrorStyle& rStyle ) const;
113 
HasErrMsg() const114 	sal_Bool			HasErrMsg() const		{ return bShowError; }
115 
GetDataMode() const116 	ScValidationMode GetDataMode() const	{ return eDataMode; }
117 
GetListType() const118     inline sal_Int16 GetListType() const                { return mnListType; }
SetListType(sal_Int16 nListType)119     inline void     SetListType( sal_Int16 nListType )  { mnListType = nListType; }
120 
121     /** Returns true, if the validation cell will show a selection list.
122         @descr  Use this instead of GetListType() which returns the raw property
123         regardless of the validation type. */
124     bool            HasSelectionList() const;
125     /** Tries to fill the passed collection with list validation entries.
126         @descr  Fills the list only, if this is a list validation and IsShowList() is enabled.
127         @param rStrings  (out-param) The string list to fill with list validation entires.
128         @return  true = rStrings has been filled with at least one entry. */
129     bool            FillSelectionList( TypedScStrCollection& rStrings, const ScAddress& rPos ) const;
130 
131 					//	mit String: bei Eingabe, mit Zelle: fuer Detektiv / RC_FORCED
132 	sal_Bool			IsDataValid( const String& rTest, const ScPatternAttr& rPattern,
133 									const ScAddress& rPos ) const;
134 	sal_Bool			IsDataValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
135 
136 					// sal_True -> Abbruch
137 	sal_Bool			DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
138 	void			DoCalcError( ScFormulaCell* pCell ) const;
139 
140 	sal_Bool			IsEmpty() const;
GetKey() const141 	sal_uInt32		GetKey() const			{ return nKey; }
SetKey(sal_uInt32 nNew)142 	void			SetKey(sal_uInt32 nNew)	{ nKey = nNew; }	// nur wenn nicht eingefuegt!
143 
SetUsed(sal_Bool bSet)144 	void			SetUsed(sal_Bool bSet)		{ bIsUsed = bSet; }
IsUsed() const145 	sal_Bool			IsUsed() const			{ return bIsUsed; }
146 
147 	sal_Bool			EqualEntries( const ScValidationData& r ) const;	// fuer Undo
148 
149 	//	sortiert (per PTRARR) nach Index
150 	//	operator== nur fuer die Sortierung
operator ==(const ScValidationData & r) const151 	sal_Bool operator ==( const ScValidationData& r ) const	{ return nKey == r.nKey; }
operator <(const ScValidationData & r) const152 	sal_Bool operator < ( const ScValidationData& r ) const	{ return nKey <  r.nKey; }
153 
154 private:
155     /** Tries to fill the passed collection with list validation entries.
156         @descr  Fills the list only if it is non-NULL,
157         @param pStrings  (out-param) Optionally NULL, string list to fill with list validation entires.
158         @param pCell     can be NULL if it is not necessary to which element in the list is selected.
159         @param rPos      the base address for relative references.
160         @param rTokArr   Formula token array.
161         @param rMatch    (out-param) the index of the first item that matched, -1 if nothing matched.
162         @return  true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
163     bool            GetSelectionFromFormula( TypedScStrCollection* pStrings,
164                                              ScBaseCell* pCell, const ScAddress& rPos,
165                                              const ScTokenArray& rTokArr, int& rMatch ) const;
166 
167     /** Tests, if pCell is equal to what the passed token array represents. */
168     bool            IsEqualToTokenArray( ScBaseCell* pCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
169 
170     /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
171     bool            IsListValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
172 };
173 
174 //
175 //	Liste der Bedingungen:
176 //
177 
178 typedef ScValidationData* ScValidationDataPtr;
179 
180 SV_DECL_PTRARR_SORT(ScValidationEntries_Impl, ScValidationDataPtr,
181                         SC_COND_GROW, SC_COND_GROW)
182 
183 class ScValidationDataList : public ScValidationEntries_Impl
184 {
185 public:
ScValidationDataList()186 		ScValidationDataList() {}
187 		ScValidationDataList(const ScValidationDataList& rList);
188 		ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
~ScValidationDataList()189 		~ScValidationDataList() {}
190 
InsertNew(ScValidationData * pNew)191 	void	InsertNew( ScValidationData* pNew )
192 				{ if (!Insert(pNew)) delete pNew; }
193 
194 	ScValidationData* GetData( sal_uInt32 nKey );
195 
196 	void	CompileXML();
197 	void	UpdateReference( UpdateRefMode eUpdateRefMode,
198 								const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
199     void    UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
200 
201     /** Temporarily during save, returns RefManager's decision whether ALL
202      *  references are marked now. */
203     bool    MarkUsedExternalReferences() const;
204 
205 	sal_Bool	operator==( const ScValidationDataList& r ) const;		// fuer Ref-Undo
206 };
207 
208 #endif
209 
210