Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_INC_VALIDAT_HXX
21 : #define INCLUDED_SC_INC_VALIDAT_HXX
22 :
23 : #include "conditio.hxx"
24 : #include <com/sun/star/sheet/TableValidationVisibility.hpp>
25 : #include "scdllapi.h"
26 :
27 :
28 : namespace sc {
29 :
30 : struct RefUpdateContext;
31 :
32 : }
33 :
34 : class ScPatternAttr;
35 : class ScTokenArray;
36 : class ScTypedStrData;
37 :
38 : enum ScValidationMode
39 : {
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
48 : };
49 :
50 : enum ScValidErrorStyle
51 : {
52 : SC_VALERR_STOP,
53 : SC_VALERR_WARNING,
54 : SC_VALERR_INFO,
55 : SC_VALERR_MACRO
56 : };
57 :
58 : // Entry for validation (only one condition exists)
59 :
60 : class SC_DLLPUBLIC ScValidationData : public ScConditionEntry
61 : {
62 : private:
63 : sal_uInt32 nKey; // index in attributes
64 :
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;
74 :
75 : bool DoMacro( const ScAddress& rPos, const OUString& rInput,
76 : ScFormulaCell* pCell, vcl::Window* pParent ) const;
77 :
78 : bool DoScript( const ScAddress& rPos, const OUString& rInput,
79 : ScFormulaCell* pCell, vcl::Window* pParent ) const;
80 :
81 : using ScConditionEntry::operator==;
82 :
83 : public:
84 : ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
85 : const OUString& rExpr1, const OUString& rExpr2,
86 : ScDocument* pDocument, const ScAddress& rPos,
87 68 : 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();
96 :
97 0 : ScValidationData* Clone() const // real copy
98 0 : { return new ScValidationData( GetDocument(), *this ); }
99 56 : ScValidationData* Clone(ScDocument* pNew) const SAL_OVERRIDE
100 56 : { return new ScValidationData( pNew, *this ); }
101 :
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 );
107 :
108 96 : bool GetInput( OUString& rTitle, OUString& rMsg ) const
109 96 : { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
110 : bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
111 :
112 0 : bool HasErrMsg() const { return bShowError; }
113 :
114 96 : ScValidationMode GetDataMode() const { return eDataMode; }
115 :
116 96 : inline sal_Int16 GetListType() const { return mnListType; }
117 70 : inline void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
118 :
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;
128 :
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;
132 :
133 : bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
134 :
135 : // TRUE -> break
136 : bool DoError( vcl::Window* pParent, const OUString& rInput, const ScAddress& rPos ) const;
137 : void DoCalcError( ScFormulaCell* pCell ) const;
138 :
139 : bool IsEmpty() const;
140 682 : sal_uInt32 GetKey() const { return nKey; }
141 34 : void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
142 :
143 : bool EqualEntries( const ScValidationData& r ) const; // for undo
144 :
145 : // sort (using std::set) by index
146 : // operator== only for sorting
147 : bool operator ==( const ScValidationData& r ) const { return nKey == r.nKey; }
148 186 : bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
149 :
150 : private:
151 : /** Tries to fill the passed collection with list validation entries.
152 : @descr Fills the list only if it is non-NULL,
153 : @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
154 : @param pCell can be NULL if it is not necessary to which element in the list is selected.
155 : @param rPos the base address for relative references.
156 : @param rTokArr Formula token array.
157 : @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
158 : @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
159 : bool GetSelectionFromFormula(
160 : std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
161 : const ScTokenArray& rTokArr, int& rMatch) const;
162 :
163 : /** Tests, if pCell is equal to what the passed token array represents. */
164 : bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
165 :
166 : /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
167 : bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
168 : };
169 :
170 : // list of contitions:
171 :
172 : struct CompareScValidationDataPtr
173 : {
174 186 : bool operator()( ScValidationData* const& lhs, ScValidationData* const& rhs ) const { return (*lhs)<(*rhs); }
175 : };
176 :
177 : class ScValidationDataList
178 : {
179 : private:
180 : typedef std::set<ScValidationData*, CompareScValidationDataPtr> ScValidationDataListDataType;
181 : ScValidationDataListDataType maData;
182 :
183 : public:
184 14 : ScValidationDataList() {}
185 : ScValidationDataList(const ScValidationDataList& rList);
186 : ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
187 18 : ~ScValidationDataList() {}
188 :
189 : typedef ScValidationDataListDataType::iterator iterator;
190 : typedef ScValidationDataListDataType::const_iterator const_iterator;
191 :
192 : iterator begin();
193 : const_iterator begin() const;
194 : iterator end();
195 : const_iterator end() const;
196 :
197 56 : void InsertNew( ScValidationData* pNew )
198 56 : { if (!maData.insert(pNew).second) delete pNew; }
199 :
200 : ScValidationData* GetData( sal_uInt32 nKey );
201 :
202 : void CompileXML();
203 : void UpdateReference( sc::RefUpdateContext& rCxt );
204 : void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
205 : void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
206 : void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
207 :
208 : bool operator==( const ScValidationDataList& r ) const; // for ref-undo
209 :
210 : void clear();
211 :
212 : };
213 :
214 : #endif
215 :
216 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|