check IFrame "FrameURL" target
[LibreOffice.git] / sc / inc / validat.hxx
blobb0709dc0da14858d75cf4204250cbbaeac6fb46a
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 #pragma once
22 #include "conditio.hxx"
23 #include "scdllapi.h"
25 namespace weld { class Window; }
27 namespace sc {
29 struct RefUpdateContext;
33 class ScPatternAttr;
34 class ScTokenArray;
35 class ScTypedStrData;
36 struct ScValidationDataIsNumeric;
38 enum ScValidationMode
40 SC_VALID_ANY,
41 SC_VALID_WHOLE,
42 SC_VALID_DECIMAL,
43 SC_VALID_DATE,
44 SC_VALID_TIME,
45 SC_VALID_TEXTLEN,
46 SC_VALID_LIST,
47 SC_VALID_CUSTOM
50 enum ScValidErrorStyle
52 SC_VALERR_STOP,
53 SC_VALERR_WARNING,
54 SC_VALERR_INFO,
55 SC_VALERR_MACRO
58 // Entry for validation (only one condition exists)
60 class SC_DLLPUBLIC ScValidationData final : public ScConditionEntry
62 private:
63 sal_uInt32 nKey; // index in attributes
65 ScValidationMode eDataMode;
66 bool bShowInput;
67 bool bShowError;
68 ScValidErrorStyle eErrorStyle;
69 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
70 OUString aInputTitle;
71 OUString aInputMessage;
72 OUString aErrorTitle;
73 OUString aErrorMessage;
75 bool DoMacro( const ScAddress& rPos, const OUString& rInput,
76 ScFormulaCell* pCell, weld::Window* pParent ) const;
78 bool DoScript( const ScAddress& rPos, const OUString& rInput,
79 ScFormulaCell* pCell, weld::Window* pParent ) const;
81 using ScConditionEntry::operator==;
83 public:
84 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
85 const OUString& rExpr1, const OUString& rExpr2,
86 ScDocument& rDocument, const ScAddress& rPos,
87 const OUString& rExprNmsp1 = OUString(), const OUString& rExprNmsp2 = OUString(),
88 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
89 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
90 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
91 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
92 ScDocument& rDocument, const ScAddress& rPos );
93 ScValidationData( const ScValidationData& r );
94 ScValidationData( ScDocument& rDocument, const ScValidationData& r );
95 virtual ~ScValidationData() override;
97 ScValidationData* Clone() const // real copy
98 { return new ScValidationData( *GetDocument(), *this ); }
99 ScValidationData* Clone(ScDocument* pNew) const override
100 { return new ScValidationData( *pNew, *this ); }
102 void ResetInput();
103 void ResetError();
104 void SetInput( const OUString& rTitle, const OUString& rMsg );
105 void SetError( const OUString& rTitle, const OUString& rMsg,
106 ScValidErrorStyle eStyle );
108 bool GetInput( OUString& rTitle, OUString& rMsg ) const
109 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
110 bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
112 bool HasErrMsg() const { return bShowError; }
114 ScValidationMode GetDataMode() const { return eDataMode; }
116 sal_Int16 GetListType() const { return mnListType; }
117 void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
119 /** Returns true, if the validation cell will show a selection list.
120 @descr Use this instead of GetListType() which returns the raw property
121 regardless of the validation type. */
122 bool HasSelectionList() const;
123 /** Tries to fill the passed collection with list validation entries.
124 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
125 @param rStrings (out-param) The string list to fill with list validation entries.
126 @return true = rStrings has been filled with at least one entry. */
127 bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
129 // with string: during input, with cell: for detective / RC_FORCED
130 bool IsDataValid(
131 const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
133 // Custom validations (SC_VALID_CUSTOM) should be validated using this specific method.
134 // Take care that internally this method commits to the to be validated cell the new input,
135 // in order to be able to interpret the validating boolean formula on the new input.
136 // After the formula has been evaluated the original cell content is restored.
137 // At present is only used in ScInputHandler::EnterHandler: handling this case in the
138 // regular IsDataValid method would have been unsafe since it can be invoked
139 // by ScFormulaCell::InterpretTail.
141 struct CustomValidationPrivateAccess
143 // so IsDataValidCustom can be invoked only by ScInputHandler methods
144 friend class ScInputHandler;
145 private:
146 CustomValidationPrivateAccess() {}
149 bool IsDataValidCustom(
150 const OUString& rTest, const ScPatternAttr& rPattern,
151 const ScAddress& rPos, const CustomValidationPrivateAccess& ) const;
153 bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
155 // TRUE -> break
156 bool DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos) const;
157 void DoCalcError( ScFormulaCell* pCell ) const;
159 bool IsEmpty() const;
160 sal_uInt32 GetKey() const { return nKey; }
161 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
163 bool EqualEntries( const ScValidationData& r ) const; // for undo
165 // sort (using std::set) by index
166 bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
168 private:
169 /** Tries to fill the passed collection with list validation entries.
170 @descr Fills the list only if it is non-NULL,
171 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entries.
172 @param pCell can be NULL if it is not necessary to which element in the list is selected.
173 @param rPos the base address for relative references.
174 @param rTokArr Formula token array.
175 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
176 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
177 bool GetSelectionFromFormula(
178 std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
179 const ScTokenArray& rTokArr, int& rMatch) const;
181 /** Tests, if pCell is equal to what the passed token array represents. */
182 bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
184 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
185 bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
187 /** Tests, if string or numeric data has valid text length.
188 @param pDataNumeric
189 nullptr if string data to be tested, else for numeric data a
190 properly initialized ScValidationDataIsNumeric struct, see
191 implementation.
193 bool IsDataValidTextLen( const OUString& rTest, const ScAddress& rPos,
194 ScValidationDataIsNumeric* pDataNumeric ) const;
197 // list of conditions:
199 struct CompareScValidationDataPtr
201 bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); }
204 class ScValidationDataList
206 private:
207 typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType;
208 ScValidationDataListDataType maData;
210 public:
211 ScValidationDataList() {}
212 ScValidationDataList(const ScValidationDataList& rList);
213 ScValidationDataList(ScDocument& rNewDoc, const ScValidationDataList& rList);
215 typedef ScValidationDataListDataType::iterator iterator;
216 typedef ScValidationDataListDataType::const_iterator const_iterator;
218 iterator begin();
219 const_iterator begin() const;
220 iterator end();
221 const_iterator end() const;
223 void InsertNew( std::unique_ptr<ScValidationData> pNew )
224 { maData.insert(std::move(pNew)); }
226 ScValidationData* GetData( sal_uInt32 nKey );
228 void CompileXML();
229 void UpdateReference( sc::RefUpdateContext& rCxt );
230 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
231 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
232 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */