bump product version to 4.1.6.2
[LibreOffice.git] / sc / inc / validat.hxx
blob85737a3a989f7013b65cff71d6525d0ae1423aef
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 SC_VALIDAT_HXX
21 #define SC_VALIDAT_HXX
23 #include "conditio.hxx"
24 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
25 #include "scdllapi.h"
27 namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
29 class ScPatternAttr;
30 class ScTokenArray;
31 class ScTypedStrData;
32 class ScCellIterator;
34 enum ScValidationMode
36 SC_VALID_ANY,
37 SC_VALID_WHOLE,
38 SC_VALID_DECIMAL,
39 SC_VALID_DATE,
40 SC_VALID_TIME,
41 SC_VALID_TEXTLEN,
42 SC_VALID_LIST,
43 SC_VALID_CUSTOM
46 enum ScValidErrorStyle
48 SC_VALERR_STOP,
49 SC_VALERR_WARNING,
50 SC_VALERR_INFO,
51 SC_VALERR_MACRO
55 // Entry for validation (only one condition exists)
58 class SC_DLLPUBLIC ScValidationData : public ScConditionEntry
60 sal_uInt32 nKey; // index in attributes
62 ScValidationMode eDataMode;
63 sal_Bool bShowInput;
64 sal_Bool bShowError;
65 ScValidErrorStyle eErrorStyle;
66 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
67 String aInputTitle;
68 String aInputMessage;
69 String aErrorTitle;
70 String aErrorMessage;
72 sal_Bool bIsUsed; // temporary during saving
74 sal_Bool DoMacro( const ScAddress& rPos, const String& rInput,
75 ScFormulaCell* pCell, Window* pParent ) const;
77 sal_Bool DoScript( const ScAddress& rPos, const String& rInput,
78 ScFormulaCell* pCell, Window* pParent ) const;
80 using ScConditionEntry::operator==;
82 public:
83 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
84 const String& rExpr1, const String& rExpr2,
85 ScDocument* pDocument, const ScAddress& rPos,
86 const String& rExprNmsp1 = EMPTY_STRING, const String& rExprNmsp2 = EMPTY_STRING,
87 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
88 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
89 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
90 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
91 ScDocument* pDocument, const ScAddress& rPos );
92 ScValidationData( const ScValidationData& r );
93 ScValidationData( ScDocument* pDocument, const ScValidationData& r );
94 virtual ~ScValidationData();
96 ScValidationData* Clone() const // real copy
97 { return new ScValidationData( GetDocument(), *this ); }
98 ScValidationData* Clone(ScDocument* pNew) const
99 { return new ScValidationData( pNew, *this ); }
101 void ResetInput();
102 void ResetError();
103 void SetInput( const String& rTitle, const String& rMsg );
104 void SetError( const String& rTitle, const String& rMsg,
105 ScValidErrorStyle eStyle );
107 sal_Bool GetInput( String& rTitle, String& rMsg ) const
108 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
109 sal_Bool GetErrMsg( String& rTitle, String& rMsg, ScValidErrorStyle& rStyle ) const;
111 sal_Bool HasErrMsg() const { return bShowError; }
113 ScValidationMode GetDataMode() const { return eDataMode; }
115 inline sal_Int16 GetListType() const { return mnListType; }
116 inline void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
118 /** Returns true, if the validation cell will show a selection list.
119 @descr Use this instead of GetListType() which returns the raw property
120 regardless of the validation type. */
121 bool HasSelectionList() const;
122 /** Tries to fill the passed collection with list validation entries.
123 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
124 @param rStrings (out-param) The string list to fill with list validation entires.
125 @return true = rStrings has been filled with at least one entry. */
126 bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
128 // with string: during input, with cell: for detective / RC_FORCED
129 bool IsDataValid(
130 const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
132 bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
134 // TRUE -> break
135 sal_Bool DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
136 void DoCalcError( ScFormulaCell* pCell ) const;
138 sal_Bool IsEmpty() const;
139 sal_uInt32 GetKey() const { return nKey; }
140 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
142 void SetUsed(sal_Bool bSet) { bIsUsed = bSet; }
143 sal_Bool IsUsed() const { return bIsUsed; }
145 sal_Bool EqualEntries( const ScValidationData& r ) const; // for undo
147 // sort (using std::set) by index
148 // operator== only for sorting
149 bool operator ==( const ScValidationData& r ) const { return nKey == r.nKey; }
150 bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
152 private:
153 /** Tries to fill the passed collection with list validation entries.
154 @descr Fills the list only if it is non-NULL,
155 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
156 @param pCell can be NULL if it is not necessary to which element in the list is selected.
157 @param rPos the base address for relative references.
158 @param rTokArr Formula token array.
159 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
160 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
161 bool GetSelectionFromFormula(
162 std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
163 const ScTokenArray& rTokArr, int& rMatch) const;
165 /** Tests, if pCell is equal to what the passed token array represents. */
166 bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
168 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
169 bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
173 // list of contitions:
176 struct CompareScValidationDataPtr
178 bool operator()( ScValidationData* const& lhs, ScValidationData* const& rhs ) const { return (*lhs)<(*rhs); }
181 class ScValidationDataList : public std::set<ScValidationData*, CompareScValidationDataPtr>
183 public:
184 ScValidationDataList() {}
185 ScValidationDataList(const ScValidationDataList& rList);
186 ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
187 ~ScValidationDataList() {}
189 void InsertNew( ScValidationData* pNew )
190 { if (!insert(pNew).second) delete pNew; }
192 ScValidationData* GetData( sal_uInt32 nKey );
194 void CompileXML();
195 void UpdateReference( UpdateRefMode eUpdateRefMode,
196 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
197 void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
199 sal_Bool operator==( const ScValidationDataList& r ) const; // for ref-undo
202 #endif
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */