Revert "tdf#110987: type detection, binary Office formats > templates"
[LibreOffice.git] / sc / inc / validat.hxx
blob64e0d2520feb777e418af76bbd7dee54c654298d
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 vcl { class Window; }
27 namespace weld { class Window; }
29 namespace sc {
31 struct RefUpdateContext;
35 class ScPatternAttr;
36 class ScTokenArray;
37 class ScTypedStrData;
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 : 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* pDocument, 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* pDocument, const ScAddress& rPos );
94 ScValidationData( const ScValidationData& r );
95 ScValidationData( ScDocument* pDocument, 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;
189 // list of conditions:
191 struct CompareScValidationDataPtr
193 bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); }
196 class ScValidationDataList
198 private:
199 typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType;
200 ScValidationDataListDataType maData;
202 public:
203 ScValidationDataList() {}
204 ScValidationDataList(const ScValidationDataList& rList);
205 ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
207 typedef ScValidationDataListDataType::iterator iterator;
208 typedef ScValidationDataListDataType::const_iterator const_iterator;
210 iterator begin();
211 const_iterator begin() const;
212 iterator end();
213 const_iterator end() const;
215 void InsertNew( std::unique_ptr<ScValidationData> pNew )
216 { maData.insert(std::move(pNew)); }
218 ScValidationData* GetData( sal_uInt32 nKey );
220 void CompileXML();
221 void UpdateReference( sc::RefUpdateContext& rCxt );
222 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
223 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
224 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
227 #endif
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */