Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / validat.hxx
blobc66c92916089b546e2559b2be23b121f8b9c5f72
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 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
60 // Entry for validation (only one condition exists)
63 class SC_DLLPUBLIC ScValidationData : public ScConditionEntry
65 private:
66 sal_uInt32 nKey; // index in attributes
68 ScValidationMode eDataMode;
69 bool bShowInput;
70 bool bShowError;
71 ScValidErrorStyle eErrorStyle;
72 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
73 OUString aInputTitle;
74 OUString aInputMessage;
75 OUString aErrorTitle;
76 OUString aErrorMessage;
78 bool bIsUsed; // temporary during saving
80 bool DoMacro( const ScAddress& rPos, const OUString& rInput,
81 ScFormulaCell* pCell, Window* pParent ) const;
83 bool DoScript( const ScAddress& rPos, const OUString& rInput,
84 ScFormulaCell* pCell, Window* pParent ) const;
86 using ScConditionEntry::operator==;
88 public:
89 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
90 const OUString& rExpr1, const OUString& rExpr2,
91 ScDocument* pDocument, const ScAddress& rPos,
92 const OUString& rExprNmsp1 = EMPTY_OUSTRING, const OUString& rExprNmsp2 = EMPTY_OUSTRING,
93 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
94 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
95 ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
96 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
97 ScDocument* pDocument, const ScAddress& rPos );
98 ScValidationData( const ScValidationData& r );
99 ScValidationData( ScDocument* pDocument, const ScValidationData& r );
100 virtual ~ScValidationData();
102 ScValidationData* Clone() const // real copy
103 { return new ScValidationData( GetDocument(), *this ); }
104 ScValidationData* Clone(ScDocument* pNew) const
105 { return new ScValidationData( pNew, *this ); }
107 void ResetInput();
108 void ResetError();
109 void SetInput( const OUString& rTitle, const OUString& rMsg );
110 void SetError( const OUString& rTitle, const OUString& rMsg,
111 ScValidErrorStyle eStyle );
113 bool GetInput( OUString& rTitle, OUString& rMsg ) const
114 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
115 bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
117 bool HasErrMsg() const { return bShowError; }
119 ScValidationMode GetDataMode() const { return eDataMode; }
121 inline sal_Int16 GetListType() const { return mnListType; }
122 inline void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
124 /** Returns true, if the validation cell will show a selection list.
125 @descr Use this instead of GetListType() which returns the raw property
126 regardless of the validation type. */
127 bool HasSelectionList() const;
128 /** Tries to fill the passed collection with list validation entries.
129 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
130 @param rStrings (out-param) The string list to fill with list validation entires.
131 @return true = rStrings has been filled with at least one entry. */
132 bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
134 // with string: during input, with cell: for detective / RC_FORCED
135 bool IsDataValid(
136 const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
138 bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
140 // TRUE -> break
141 bool DoError( Window* pParent, const OUString& rInput, const ScAddress& rPos ) const;
142 void DoCalcError( ScFormulaCell* pCell ) const;
144 bool IsEmpty() const;
145 sal_uInt32 GetKey() const { return nKey; }
146 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
148 void SetUsed(bool bSet) { bIsUsed = bSet; }
149 bool IsUsed() const { return bIsUsed; }
151 bool EqualEntries( const ScValidationData& r ) const; // for undo
153 // sort (using std::set) by index
154 // operator== only for sorting
155 bool operator ==( const ScValidationData& r ) const { return nKey == r.nKey; }
156 bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
158 private:
159 /** Tries to fill the passed collection with list validation entries.
160 @descr Fills the list only if it is non-NULL,
161 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
162 @param pCell can be NULL if it is not necessary to which element in the list is selected.
163 @param rPos the base address for relative references.
164 @param rTokArr Formula token array.
165 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
166 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
167 bool GetSelectionFromFormula(
168 std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
169 const ScTokenArray& rTokArr, int& rMatch) const;
171 /** Tests, if pCell is equal to what the passed token array represents. */
172 bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
174 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
175 bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
179 // list of contitions:
182 struct CompareScValidationDataPtr
184 bool operator()( ScValidationData* const& lhs, ScValidationData* const& rhs ) const { return (*lhs)<(*rhs); }
187 class ScValidationDataList
189 private:
190 typedef std::set<ScValidationData*, CompareScValidationDataPtr> ScValidationDataListDataType;
191 ScValidationDataListDataType maData;
193 public:
194 ScValidationDataList() {}
195 ScValidationDataList(const ScValidationDataList& rList);
196 ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
197 ~ScValidationDataList() {}
199 typedef ScValidationDataListDataType::iterator iterator;
200 typedef ScValidationDataListDataType::const_iterator const_iterator;
202 iterator begin();
203 const_iterator begin() const;
204 iterator end();
205 const_iterator end() const;
207 void InsertNew( ScValidationData* pNew )
208 { if (!maData.insert(pNew).second) delete pNew; }
210 ScValidationData* GetData( sal_uInt32 nKey );
212 void CompileXML();
213 void UpdateReference( sc::RefUpdateContext& rCxt );
214 void UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt );
215 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext& rCxt );
216 void UpdateMoveTab( sc::RefUpdateMoveTabContext& rCxt );
218 bool operator==( const ScValidationDataList& r ) const; // for ref-undo
220 void clear();
224 #endif
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */