nss: upgrade to release 3.73
[LibreOffice.git] / sc / inc / validat.hxx
blob7ab014f0f92f8a293491e60c3aa996febdf91f36
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_INC_VALIDAT_HXX
21 #define INCLUDED_SC_INC_VALIDAT_HXX
23 #include "conditio.hxx"
24 #include "scdllapi.h"
26 namespace weld { class Window; }
28 namespace sc {
30 struct RefUpdateContext;
34 class ScPatternAttr;
35 class ScTokenArray;
36 class ScTypedStrData;
37 struct ScValidationDataIsNumeric;
39 enum ScValidationMode
41 SC_VALID_ANY,
42 SC_VALID_WHOLE,
43 SC_VALID_DECIMAL,
44 SC_VALID_DATE,
45 SC_VALID_TIME,
46 SC_VALID_TEXTLEN,
47 SC_VALID_LIST,
48 SC_VALID_CUSTOM
51 enum ScValidErrorStyle
53 SC_VALERR_STOP,
54 SC_VALERR_WARNING,
55 SC_VALERR_INFO,
56 SC_VALERR_MACRO
59 // Entry for validation (only one condition exists)
61 class SC_DLLPUBLIC ScValidationData final : public ScConditionEntry
63 private:
64 sal_uInt32 nKey; // index in attributes
66 ScValidationMode eDataMode;
67 bool bShowInput;
68 bool bShowError;
69 ScValidErrorStyle eErrorStyle;
70 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
71 OUString aInputTitle;
72 OUString aInputMessage;
73 OUString aErrorTitle;
74 OUString aErrorMessage;
76 bool DoMacro( const ScAddress& rPos, const OUString& rInput,
77 ScFormulaCell* pCell, weld::Window* pParent ) const;
79 bool DoScript( const ScAddress& rPos, const OUString& rInput,
80 ScFormulaCell* pCell, weld::Window* pParent ) const;
82 using ScConditionEntry::operator==;
84 public:
85 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
86 const OUString& rExpr1, const OUString& rExpr2,
87 ScDocument& rDocument, const ScAddress& rPos,
88 const OUString& rExprNmsp1 = EMPTY_OUSTRING, const OUString& rExprNmsp2 = EMPTY_OUSTRING,
89 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
90 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
91 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
92 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
93 ScDocument& rDocument, const ScAddress& rPos );
94 ScValidationData( const ScValidationData& r );
95 ScValidationData( ScDocument& rDocument, const ScValidationData& r );
96 virtual ~ScValidationData() override;
98 ScValidationData* Clone() const // real copy
99 { return new ScValidationData( *GetDocument(), *this ); }
100 ScValidationData* Clone(ScDocument* pNew) const override
101 { return new ScValidationData( *pNew, *this ); }
103 void ResetInput();
104 void ResetError();
105 void SetInput( const OUString& rTitle, const OUString& rMsg );
106 void SetError( const OUString& rTitle, const OUString& rMsg,
107 ScValidErrorStyle eStyle );
109 bool GetInput( OUString& rTitle, OUString& rMsg ) const
110 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
111 bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
113 bool HasErrMsg() const { return bShowError; }
115 ScValidationMode GetDataMode() const { return eDataMode; }
117 sal_Int16 GetListType() const { return mnListType; }
118 void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
120 /** Returns true, if the validation cell will show a selection list.
121 @descr Use this instead of GetListType() which returns the raw property
122 regardless of the validation type. */
123 bool HasSelectionList() const;
124 /** Tries to fill the passed collection with list validation entries.
125 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
126 @param rStrings (out-param) The string list to fill with list validation entries.
127 @return true = rStrings has been filled with at least one entry. */
128 bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
130 // with string: during input, with cell: for detective / RC_FORCED
131 bool IsDataValid(
132 const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
134 // Custom validations (SC_VALID_CUSTOM) should be validated using this specific method.
135 // Take care that internally this method commits to the to be validated cell the new input,
136 // in order to be able to interpret the validating boolean formula on the new input.
137 // After the formula has been evaluated the original cell content is restored.
138 // At present is only used in ScInputHandler::EnterHandler: handling this case in the
139 // regular IsDataValid method would have been unsafe since it can be invoked
140 // by ScFormulaCell::InterpretTail.
142 struct CustomValidationPrivateAccess
144 // so IsDataValidCustom can be invoked only by ScInputHandler methods
145 friend class ScInputHandler;
146 private:
147 CustomValidationPrivateAccess() {}
150 bool IsDataValidCustom(
151 const OUString& rTest, const ScPatternAttr& rPattern,
152 const ScAddress& rPos, const CustomValidationPrivateAccess& ) const;
154 bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
156 // TRUE -> break
157 bool DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos) const;
158 void DoCalcError( ScFormulaCell* pCell ) const;
160 bool IsEmpty() const;
161 sal_uInt32 GetKey() const { return nKey; }
162 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
164 bool EqualEntries( const ScValidationData& r ) const; // for undo
166 // sort (using std::set) by index
167 bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
169 private:
170 /** Tries to fill the passed collection with list validation entries.
171 @descr Fills the list only if it is non-NULL,
172 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entries.
173 @param pCell can be NULL if it is not necessary to which element in the list is selected.
174 @param rPos the base address for relative references.
175 @param rTokArr Formula token array.
176 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
177 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
178 bool GetSelectionFromFormula(
179 std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
180 const ScTokenArray& rTokArr, int& rMatch) const;
182 /** Tests, if pCell is equal to what the passed token array represents. */
183 bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
185 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
186 bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
188 /** Tests, if string or numeric data has valid text length.
189 @param pDataNumeric
190 nullptr if string data to be tested, else for numeric data a
191 properly initialized ScValidationDataIsNumeric struct, see
192 implementation.
194 bool IsDataValidTextLen( const OUString& rTest, const ScAddress& rPos,
195 ScValidationDataIsNumeric* pDataNumeric ) const;
198 // list of conditions:
200 struct CompareScValidationDataPtr
202 bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); }
205 class ScValidationDataList
207 private:
208 typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType;
209 ScValidationDataListDataType maData;
211 public:
212 ScValidationDataList() {}
213 ScValidationDataList(const ScValidationDataList& rList);
214 ScValidationDataList(ScDocument& rNewDoc, const ScValidationDataList& rList);
216 typedef ScValidationDataListDataType::iterator iterator;
217 typedef ScValidationDataListDataType::const_iterator const_iterator;
219 iterator begin();
220 const_iterator begin() const;
221 iterator end();
222 const_iterator end() const;
224 void InsertNew( std::unique_ptr<ScValidationData> pNew )
225 { maData.insert(std::move(pNew)); }
227 ScValidationData* GetData( sal_uInt32 nKey );
229 void CompileXML();
230 void UpdateReference( sc::RefUpdateContext& rCxt );
231 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
232 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
233 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
236 #endif
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */