LibreOffice Module sc (master) 1
validat.hxx
Go to the documentation of this file.
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#pragma once
21
22#include "conditio.hxx"
23#include "scdllapi.h"
24
25namespace weld { class Window; }
26
27namespace sc {
28
29struct RefUpdateContext;
30
31}
32
33namespace vcl { class ILibreOfficeKitNotifier; }
34
35class ScPatternAttr;
36class ScTokenArray;
37class ScTypedStrData;
39
41{
50};
51
53{
58};
59
60// Entry for validation (only one condition exists)
61
63{
64private:
65 sal_uInt32 nKey; // index in attributes
66
71 sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
72 OUString aInputTitle;
73 OUString aInputMessage;
74 OUString aErrorTitle;
75 OUString aErrorMessage;
76
77 bool DoMacro( const ScAddress& rPos, const OUString& rInput,
78 ScFormulaCell* pCell, weld::Window* pParent ) const;
79
80 bool DoScript( const ScAddress& rPos, const OUString& rInput,
81 ScFormulaCell* pCell, weld::Window* pParent ) const;
82
83 using ScConditionEntry::operator==;
84
86
87public:
89 const OUString& rExpr1, const OUString& rExpr2,
90 ScDocument& rDocument, const ScAddress& rPos,
91 const OUString& rExprNmsp1 = OUString(), const OUString& rExprNmsp2 = OUString(),
95 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
96 ScDocument& rDocument, const ScAddress& rPos );
98 ScValidationData( ScDocument& rDocument, const ScValidationData& r );
99 virtual ~ScValidationData() override;
100
101 ScValidationData* Clone() const // real copy
102 { return new ScValidationData( *GetDocument(), *this ); }
103 ScValidationData* Clone(ScDocument* pNew) const override
104 { return new ScValidationData( *pNew, *this ); }
105
106 void ResetInput();
107 void ResetError();
108 void SetInput( const OUString& rTitle, const OUString& rMsg );
109 void SetError( const OUString& rTitle, const OUString& rMsg,
110 ScValidErrorStyle eStyle );
111
112 bool GetInput( OUString& rTitle, OUString& rMsg ) const
113 { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
114 bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
115
116 bool HasErrMsg() const { return bShowError; }
117
118 ScValidationMode GetDataMode() const { return eDataMode; }
119
120 sal_Int16 GetListType() const { return mnListType; }
121 void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
122
126 bool HasSelectionList() const;
131 bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
132
133 // with string: during input, with cell: for detective / RC_FORCED
134 bool IsDataValid(
135 const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
136
137 // Custom validations (SC_VALID_CUSTOM) should be validated using this specific method.
138 // Take care that internally this method commits to the to be validated cell the new input,
139 // in order to be able to interpret the validating boolean formula on the new input.
140 // After the formula has been evaluated the original cell content is restored.
141 // At present is only used in ScInputHandler::EnterHandler: handling this case in the
142 // regular IsDataValid method would have been unsafe since it can be invoked
143 // by ScFormulaCell::InterpretTail.
144
146 {
147 // so IsDataValidCustom can be invoked only by ScInputHandler methods
148 friend class ScInputHandler;
149 private:
151 };
152
153 bool IsDataValidCustom(
154 const OUString& rTest, const ScPatternAttr& rPattern,
155 const ScAddress& rPos, const CustomValidationPrivateAccess& ) const;
156
157 bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
158
160 bool isFormulaResultsValidatable(const OUString& rTest, const ScAddress& rPos, SvNumberFormatter* pFormatter,
161 OUString& rStrResult, double& nVal, sal_uInt32& nFormat, bool& bIsVal) const;
162
163 // TRUE -> break
164 bool DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos) const;
165 void DoCalcError( ScFormulaCell* pCell ) const;
166
167 bool IsEmpty() const;
168 sal_uInt32 GetKey() const { return nKey; }
169 void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
170
171 bool EqualEntries( const ScValidationData& r ) const; // for undo
172
173 // sort (using std::set) by index
174 bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
175
176private:
185 bool GetSelectionFromFormula(
186 std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
187 const ScTokenArray& rTokArr, int& rMatch) const;
188
190 bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
191
193 bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
194
201 bool IsDataValidTextLen( std::u16string_view rTest, const ScAddress& rPos,
202 ScValidationDataIsNumeric* pDataNumeric ) const;
203};
204
205// list of conditions:
206
208{
209 bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); }
210};
211
213{
214private:
215 typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType;
217
218public:
222
223 typedef ScValidationDataListDataType::iterator iterator;
224 typedef ScValidationDataListDataType::const_iterator const_iterator;
225
226 iterator begin();
227 const_iterator begin() const;
228 iterator end();
229 const_iterator end() const;
230
231 void InsertNew( std::unique_ptr<ScValidationData> pNew )
232 { maData.insert(std::move(pNew)); }
233
234 ScValidationData* GetData( sal_uInt32 nKey );
235
236 void CompileXML();
241};
242
243/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocument * GetDocument() const
Definition: conditio.hxx:413
ScValidationDataListDataType::iterator iterator
Definition: validat.hxx:223
ScValidationDataListDataType maData
Definition: validat.hxx:216
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)
Definition: validat.cxx:1152
void UpdateReference(sc::RefUpdateContext &rCxt)
Definition: validat.cxx:1140
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt)
Definition: validat.cxx:1158
void InsertNew(std::unique_ptr< ScValidationData > pNew)
Definition: validat.hxx:231
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt)
Definition: validat.cxx:1146
ScValidationData * GetData(sal_uInt32 nKey)
Definition: validat.cxx:1122
std::set< std::unique_ptr< ScValidationData >, CompareScValidationDataPtr > ScValidationDataListDataType
Definition: validat.hxx:215
ScValidationDataListDataType::const_iterator const_iterator
Definition: validat.hxx:224
void SetListType(sal_Int16 nListType)
Definition: validat.hxx:121
sal_Int16 mnListType
Definition: validat.hxx:71
ScValidationData * Clone(ScDocument *pNew) const override
Definition: validat.hxx:103
OUString aErrorTitle
Definition: validat.hxx:74
sal_uInt32 GetKey() const
Definition: validat.hxx:168
OUString aInputTitle
Definition: validat.hxx:72
ScValidationMode GetDataMode() const
Definition: validat.hxx:118
DECL_STATIC_LINK(ScValidationData, InstallLOKNotifierHdl, void *, vcl::ILibreOfficeKitNotifier *)
sal_Int16 GetListType() const
Definition: validat.hxx:120
bool GetInput(OUString &rTitle, OUString &rMsg) const
Definition: validat.hxx:112
ScValidationMode eDataMode
Definition: validat.hxx:67
ScValidErrorStyle eErrorStyle
Definition: validat.hxx:70
OUString aErrorMessage
Definition: validat.hxx:75
ScValidationData * Clone() const
Definition: validat.hxx:101
void SetKey(sal_uInt32 nNew)
Definition: validat.hxx:169
OUString aInputMessage
Definition: validat.hxx:73
sal_uInt32 nKey
Definition: validat.hxx:65
bool HasErrMsg() const
Definition: validat.hxx:116
ScConditionMode
Definition: conditio.hxx:60
bool operator<(const ScDPCollection::DBType &left, const ScDPCollection::DBType &right)
Definition: dpobject.cxx:3969
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
bool operator()(std::unique_ptr< ScValidationData > const &lhs, std::unique_ptr< ScValidationData > const &rhs) const
Definition: validat.hxx:209
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:108
To test numeric data text length in IsDataValidTextLen().
Definition: validat.cxx:494
Context for reference update during shifting, moving or copying of cell ranges.
ScValidationMode
Definition: validat.hxx:41
@ SC_VALID_TEXTLEN
Definition: validat.hxx:47
@ SC_VALID_TIME
Definition: validat.hxx:46
@ SC_VALID_CUSTOM
Definition: validat.hxx:49
@ SC_VALID_ANY
Definition: validat.hxx:42
@ SC_VALID_DECIMAL
Definition: validat.hxx:44
@ SC_VALID_WHOLE
Definition: validat.hxx:43
@ SC_VALID_DATE
Definition: validat.hxx:45
@ SC_VALID_LIST
Definition: validat.hxx:48
ScValidErrorStyle
Definition: validat.hxx:53
@ SC_VALERR_MACRO
Definition: validat.hxx:57
@ SC_VALERR_STOP
Definition: validat.hxx:54
@ SC_VALERR_WARNING
Definition: validat.hxx:55
@ SC_VALERR_INFO
Definition: validat.hxx:56
int SetError()