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;
37 
39 {
48 };
49 
51 {
56 };
57 
58 // Entry for validation (only one condition exists)
59 
61 {
62 private:
63  sal_uInt32 nKey; // index in attributes
64 
66  bool bShowInput;
67  bool bShowError;
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, weld::Window* pParent ) const;
77 
78  bool DoScript( const ScAddress& rPos, const OUString& rInput,
79  ScFormulaCell* pCell, weld::Window* pParent ) const;
80 
81  using ScConditionEntry::operator==;
82 
83 public:
85  const OUString& rExpr1, const OUString& rExpr2,
86  ScDocument* pDocument, const ScAddress& rPos,
87  const OUString& rExprNmsp1 = EMPTY_OUSTRING, const OUString& rExprNmsp2 = EMPTY_OUSTRING,
91  const ScTokenArray* pArr1, const ScTokenArray* pArr2,
92  ScDocument* pDocument, const ScAddress& rPos );
94  ScValidationData( ScDocument* pDocument, const ScValidationData& r );
95  virtual ~ScValidationData() override;
96 
97  ScValidationData* Clone() const // real copy
98  { return new ScValidationData( GetDocument(), *this ); }
99  ScValidationData* Clone(ScDocument* pNew) const override
100  { 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  bool GetInput( OUString& rTitle, OUString& rMsg ) const
109  { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
110  bool GetErrMsg( OUString& rTitle, OUString& rMsg, ScValidErrorStyle& rStyle ) const;
111 
112  bool HasErrMsg() const { return bShowError; }
113 
114  ScValidationMode GetDataMode() const { return eDataMode; }
115 
116  sal_Int16 GetListType() const { return mnListType; }
117  void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
118 
122  bool HasSelectionList() const;
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  // Custom validations (SC_VALID_CUSTOM) should be validated using this specific method.
134  // Take care that internally this method commits to the to be validated cell the new input,
135  // in order to be able to interpret the validating boolean formula on the new input.
136  // After the formula has been evaluated the original cell content is restored.
137  // At present is only used in ScInputHandler::EnterHandler: handling this case in the
138  // regular IsDataValid method would have been unsafe since it can be invoked
139  // by ScFormulaCell::InterpretTail.
140 
142  {
143  // so IsDataValidCustom can be invoked only by ScInputHandler methods
144  friend class ScInputHandler;
145  private:
147  };
148 
149  bool IsDataValidCustom(
150  const OUString& rTest, const ScPatternAttr& rPattern,
151  const ScAddress& rPos, const CustomValidationPrivateAccess& ) const;
152 
153  bool IsDataValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
154 
155  // TRUE -> break
156  bool DoError(weld::Window* pParent, const OUString& rInput, const ScAddress& rPos) const;
157  void DoCalcError( ScFormulaCell* pCell ) const;
158 
159  bool IsEmpty() const;
160  sal_uInt32 GetKey() const { return nKey; }
161  void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
162 
163  bool EqualEntries( const ScValidationData& r ) const; // for undo
164 
165  // sort (using std::set) by index
166  bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
167 
168 private:
177  bool GetSelectionFromFormula(
178  std::vector<ScTypedStrData>* pStrings, ScRefCellValue& rCell, const ScAddress& rPos,
179  const ScTokenArray& rTokArr, int& rMatch) const;
180 
182  bool IsEqualToTokenArray( ScRefCellValue& rCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
183 
185  bool IsListValid( ScRefCellValue& rCell, const ScAddress& rPos ) const;
186 };
187 
188 // list of conditions:
189 
191 {
192  bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); }
193 };
194 
196 {
197 private:
198  typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType;
199  ScValidationDataListDataType maData;
200 
201 public:
204  ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
205 
206  typedef ScValidationDataListDataType::iterator iterator;
207  typedef ScValidationDataListDataType::const_iterator const_iterator;
208 
209  iterator begin();
210  const_iterator begin() const;
211  iterator end();
212  const_iterator end() const;
213 
214  void InsertNew( std::unique_ptr<ScValidationData> pNew )
215  { maData.insert(std::move(pNew)); }
216 
217  ScValidationData* GetData( sal_uInt32 nKey );
218 
219  void CompileXML();
224 };
225 
226 #endif
227 
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString aInputMessage
Definition: validat.hxx:71
#define EMPTY_OUSTRING
Definition: global.hxx:214
OUString aErrorTitle
Definition: validat.hxx:72
int SetError()
ScValidErrorStyle
Definition: validat.hxx:50
Context for reference update during shifting, moving or copying of cell ranges.
sal_uInt32 nKey
Definition: validat.hxx:63
ScValidationMode eDataMode
Definition: validat.hxx:65
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:192
OUString aInputTitle
Definition: validat.hxx:70
ScValidationDataListDataType::const_iterator const_iterator
Definition: validat.hxx:207
void SetListType(sal_Int16 nListType)
Definition: validat.hxx:117
ScValidErrorStyle eErrorStyle
Definition: validat.hxx:68
void UpdateMoveTab(sc::RefUpdateMoveTabContext &rCxt)
Definition: validat.cxx:1030
bool HasErrMsg() const
Definition: validat.hxx:112
void SetKey(sal_uInt32 nNew)
Definition: validat.hxx:161
ScConditionMode
Definition: conditio.hxx:61
ScValidationMode
Definition: validat.hxx:38
ScValidationDataListDataType maData
Definition: validat.hxx:199
ScValidationMode GetDataMode() const
Definition: validat.hxx:114
ScValidationData * GetData(sal_uInt32 nKey)
Definition: validat.cxx:994
void UpdateReference(sc::RefUpdateContext &rCxt)
Definition: validat.cxx:1012
OUString aErrorMessage
Definition: validat.hxx:73
std::set< std::unique_ptr< ScValidationData >, CompareScValidationDataPtr > ScValidationDataListDataType
Definition: validat.hxx:198
void InsertNew(std::unique_ptr< ScValidationData > pNew)
Definition: validat.hxx:214
void UpdateDeleteTab(sc::RefUpdateDeleteTabContext &rCxt)
Definition: validat.cxx:1024
bool operator<(const ScDPCollection::DBType &left, const ScDPCollection::DBType &right)
Definition: dpobject.cxx:3929
ScValidationDataListDataType::iterator iterator
Definition: validat.hxx:206
bool GetInput(OUString &rTitle, OUString &rMsg) const
Definition: validat.hxx:108
sal_Int16 GetListType() const
Definition: validat.hxx:116
void UpdateInsertTab(sc::RefUpdateInsertTabContext &rCxt)
Definition: validat.cxx:1018
ScValidationData * Clone(ScDocument *pNew) const override
Definition: validat.hxx:99
ScDocument * GetDocument() const
Definition: conditio.hxx:414
sal_uInt32 GetKey() const
Definition: validat.hxx:160
ScValidationData * Clone() const
Definition: validat.hxx:97
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int16 mnListType
Definition: validat.hxx:69