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 #ifndef INCLUDED_SC_INC_VALIDAT_HXX
21 #define INCLUDED_SC_INC_VALIDAT_HXX
22 
23 #include "conditio.hxx"
24 #include "scdllapi.h"
25 
26 namespace weld { class Window; }
27 
28 namespace sc {
29 
30 struct RefUpdateContext;
31 
32 }
33 
34 class ScPatternAttr;
35 class ScTokenArray;
36 class ScTypedStrData;
38 
40 {
49 };
50 
52 {
57 };
58 
59 // Entry for validation (only one condition exists)
60 
62 {
63 private:
64  sal_uInt32 nKey; // index in attributes
65 
67  bool bShowInput;
68  bool bShowError;
70  sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
71  OUString aInputTitle;
72  OUString aInputMessage;
73  OUString aErrorTitle;
74  OUString aErrorMessage;
75 
76  bool DoMacro( const ScAddress& rPos, const OUString& rInput,
77  ScFormulaCell* pCell, weld::Window* pParent ) const;
78 
79  bool DoScript( const ScAddress& rPos, const OUString& rInput,
80  ScFormulaCell* pCell, weld::Window* pParent ) const;
81 
82  using ScConditionEntry::operator==;
83 
84 public:
86  const OUString& rExpr1, const OUString& rExpr2,
87  ScDocument& rDocument, const ScAddress& rPos,
88  const OUString& rExprNmsp1 = EMPTY_OUSTRING, const OUString& rExprNmsp2 = EMPTY_OUSTRING,
92  const ScTokenArray* pArr1, const ScTokenArray* pArr2,
93  ScDocument& rDocument, const ScAddress& rPos );
95  ScValidationData( ScDocument& rDocument, const ScValidationData& r );
96  virtual ~ScValidationData() override;
97 
98  ScValidationData* Clone() const // real copy
99  { return new ScValidationData( *GetDocument(), *this ); }
100  ScValidationData* Clone(ScDocument* pNew) const override
101  { return new ScValidationData( *pNew, *this ); }
102 
103  void ResetInput();
104  void ResetError();
105  void SetInput( const OUString& rTitle, const OUString& rMsg );
106  void SetError( const OUString& rTitle, const OUString& rMsg,
107  ScValidErrorStyle eStyle );
108 
109  bool GetInput( OUString& rTitle, OUString& rMsg ) const
110  { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
111  bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
112 
113  bool HasErrMsg() const { return bShowError; }
114 
115  ScValidationMode GetDataMode() const { return eDataMode; }
116 
117  sal_Int16 GetListType() const { return mnListType; }
118  void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
119 
123  bool HasSelectionList() const;
128  bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
129 
130  // with string: during input, with cell: for detective / RC_FORCED
131  bool IsDataValid(
132  const OUString& rTest, const ScPatternAttr& rPattern, const ScAddress& rPos ) const;
133 
134  // Custom validations (SC_VALID_CUSTOM) should be validated using this specific method.
135  // Take care that internally this method commits to the to be validated cell the new input,
136  // in order to be able to interpret the validating boolean formula on the new input.
137  // After the formula has been evaluated the original cell content is restored.
138  // At present is only used in ScInputHandler::EnterHandler: handling this case in the
139  // regular IsDataValid method would have been unsafe since it can be invoked
140  // by ScFormulaCell::InterpretTail.
141 
143  {
144  // so IsDataValidCustom can be invoked only by ScInputHandler methods
145  friend class ScInputHandler;
146  private:
148  };
149 
150  bool IsDataValidCustom(
151  const OUString& rTest, const ScPatternAttr& rPattern,
152  const ScAddress& rPos, const CustomValidationPrivateAccess& ) const;
153 
154  bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
155 
156  // TRUE -> break
157  bool DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos) const;
158  void DoCalcError( ScFormulaCell* pCell ) const;
159 
160  bool IsEmpty() const;
161  sal_uInt32 GetKey() const { return nKey; }
162  void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
163 
164  bool EqualEntries( const ScValidationData& r ) const; // for undo
165 
166  // sort (using std::set) by index
167  bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
168 
169 private:
178  bool GetSelectionFromFormula(
179  std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
180  const ScTokenArray& rTokArr, int& rMatch) const;
181 
183  bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
184 
186  bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
187 
194  bool IsDataValidTextLen( const OUString& rTest, const ScAddress& rPos,
195  ScValidationDataIsNumeric* pDataNumeric ) const;
196 };
197 
198 // list of conditions:
199 
201 {
202  bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); }
203 };
204 
206 {
207 private:
208  typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType;
209  ScValidationDataListDataType maData;
210 
211 public:
214  ScValidationDataList(ScDocument& rNewDoc, const ScValidationDataList& rList);
215 
216  typedef ScValidationDataListDataType::iterator iterator;
217  typedef ScValidationDataListDataType::const_iterator const_iterator;
218 
219  iterator begin();
220  const_iterator begin() const;
221  iterator end();
222  const_iterator end() const;
223 
224  void InsertNew( std::unique_ptr<ScValidationData> pNew )
225  { maData.insert(std::move(pNew)); }
226 
227  ScValidationData* GetData( sal_uInt32 nKey );
228 
229  void CompileXML();
234 };
235 
236 #endif
237 
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString aInputMessage
Definition: validat.hxx:72
#define EMPTY_OUSTRING
Definition: global.hxx:214
OUString aErrorTitle
Definition: validat.hxx:73
int SetError()
ScValidErrorStyle
Definition: validat.hxx:51
Context for reference update during shifting, moving or copying of cell ranges.
sal_uInt32 nKey
Definition: validat.hxx:64
ScValidationMode eDataMode
Definition: validat.hxx:66
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
bool operator()(std::unique_ptr< ScValidationData > const &lhs, std::unique_ptr< ScValidationData > const &rhs) const
Definition: validat.hxx:202
OUString aInputTitle
Definition: validat.hxx:71
ScValidationDataListDataType::const_iterator const_iterator
Definition: validat.hxx:217
void SetListType(sal_Int16 nListType)
Definition: validat.hxx:118
ScValidErrorStyle eErrorStyle
Definition: validat.hxx:69
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt)
Definition: validat.cxx:1069
bool HasErrMsg() const
Definition: validat.hxx:113
void SetKey(sal_uInt32 nNew)
Definition: validat.hxx:162
ScConditionMode
Definition: conditio.hxx:61
ScValidationMode
Definition: validat.hxx:39
ScValidationDataListDataType maData
Definition: validat.hxx:209
ScValidationMode GetDataMode() const
Definition: validat.hxx:115
ScValidationData * GetData(sal_uInt32 nKey)
Definition: validat.cxx:1033
void UpdateReference(sc::RefUpdateContext &rCxt)
Definition: validat.cxx:1051
OUString aErrorMessage
Definition: validat.hxx:74
To test numeric data text length in IsDataValidTextLen().
Definition: validat.cxx:484
std::set< std::unique_ptr< ScValidationData >, CompareScValidationDataPtr > ScValidationDataListDataType
Definition: validat.hxx:208
void InsertNew(std::unique_ptr< ScValidationData > pNew)
Definition: validat.hxx:224
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)
Definition: validat.cxx:1063
bool operator<(const ScDPCollection::DBType &left, const ScDPCollection::DBType &right)
Definition: dpobject.cxx:3929
ScValidationDataListDataType::iterator iterator
Definition: validat.hxx:216
bool GetInput(OUString &rTitle, OUString &rMsg) const
Definition: validat.hxx:109
sal_Int16 GetListType() const
Definition: validat.hxx:117
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt)
Definition: validat.cxx:1057
ScValidationData * Clone(ScDocument *pNew) const override
Definition: validat.hxx:100
ScDocument * GetDocument() const
Definition: conditio.hxx:414
sal_uInt32 GetKey() const
Definition: validat.hxx:161
ScValidationData * Clone() const
Definition: validat.hxx:98
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int16 mnListType
Definition: validat.hxx:70