build fix
[LibreOffice.git] / sc / inc / validat.hxx
blob6f67becea43bb2084e0afe7ce9b3d82c6b2fb125
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 <com/sun/star/sheet/TableValidationVisibility.hpp>
25 #include "scdllapi.h"
28 namespace sc {
30 struct RefUpdateContext;
34 class ScPatternAttr;
35 class ScTokenArray;
36 class ScTypedStrData;
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 : 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, vcl::Window* pParent ) const;
78 bool DoScript( const ScAddress& rPos, const OUString& rInput,
79 ScFormulaCell* pCell, vcl::Window* pParent ) const;
81 using ScConditionEntry::operator==;
83 public:
84 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
85 const OUString& rExpr1, const OUString& rExpr2,
86 ScDocument* pDocument, const ScAddress& rPos,
87 const OUString& rExprNmsp1 = EMPTY_OUSTRING, const OUString& rExprNmsp2 = EMPTY_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* pDocument, const ScAddress& rPos );
93 ScValidationData( const ScValidationData& r );
94 ScValidationData( ScDocument* pDocument, 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 inline sal_Int16 GetListType() const { return mnListType; }
117 inline 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 entires.
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 bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
135 // TRUE -> break
136 bool DoError( vcl::Window* pParent, const OUString& rInput, const ScAddress& rPos ) const;
137 void DoCalcError( ScFormulaCell* pCell ) const;
139 bool IsEmpty() const;
140 sal_uInt32 GetKey() const { return nKey; }
141 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
143 bool EqualEntries( const ScValidationData& r ) const; // for undo
145 // sort (using std::set) by index
146 bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
148 private:
149 /** Tries to fill the passed collection with list validation entries.
150 @descr Fills the list only if it is non-NULL,
151 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
152 @param pCell can be NULL if it is not necessary to which element in the list is selected.
153 @param rPos the base address for relative references.
154 @param rTokArr Formula token array.
155 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
156 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
157 bool GetSelectionFromFormula(
158 std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
159 const ScTokenArray& rTokArr, int& rMatch) const;
161 /** Tests, if pCell is equal to what the passed token array represents. */
162 bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
164 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
165 bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
168 // list of conditions:
170 struct CompareScValidationDataPtr
172 bool operator()( ScValidationData* const& lhs, ScValidationData* const& rhs ) const { return (*lhs)<(*rhs); }
175 class ScValidationDataList
177 private:
178 typedef std::set<ScValidationData*, CompareScValidationDataPtr> ScValidationDataListDataType;
179 ScValidationDataListDataType maData;
181 public:
182 ScValidationDataList() {}
183 ScValidationDataList(const ScValidationDataList& rList);
184 ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
185 ~ScValidationDataList() {}
187 typedef ScValidationDataListDataType::iterator iterator;
188 typedef ScValidationDataListDataType::const_iterator const_iterator;
190 iterator begin();
191 const_iterator begin() const;
192 iterator end();
193 const_iterator end() const;
195 void InsertNew( ScValidationData* pNew )
196 { if (!maData.insert(pNew).second) delete pNew; }
198 ScValidationData* GetData( sal_uInt32 nKey );
200 void CompileXML();
201 void UpdateReference( sc::RefUpdateContext& rCxt );
202 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
203 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
204 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
206 void clear();
210 #endif
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */