1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SC_INC_VALIDAT_HXX
21 #define INCLUDED_SC_INC_VALIDAT_HXX
23 #include "conditio.hxx"
24 #include <com/sun/star/sheet/TableValidationVisibility.hpp>
27 namespace vcl
{ class Window
; }
28 namespace weld
{ class Window
; }
32 struct RefUpdateContext
;
52 enum ScValidErrorStyle
60 // Entry for validation (only one condition exists)
62 class SC_DLLPUBLIC ScValidationData
: public ScConditionEntry
65 sal_uInt32 nKey
; // index in attributes
67 ScValidationMode eDataMode
;
70 ScValidErrorStyle eErrorStyle
;
71 sal_Int16 mnListType
; // selection list type: none, unsorted, sorted.
73 OUString aInputMessage
;
75 OUString aErrorMessage
;
77 bool DoMacro( const ScAddress
& rPos
, const OUString
& rInput
,
78 ScFormulaCell
* pCell
, weld::Window
* pParent
) const;
80 bool DoScript( const ScAddress
& rPos
, const OUString
& rInput
,
81 ScFormulaCell
* pCell
, weld::Window
* pParent
) const;
83 using ScConditionEntry::operator==;
86 ScValidationData( ScValidationMode eMode
, ScConditionMode eOper
,
87 const OUString
& rExpr1
, const OUString
& rExpr2
,
88 ScDocument
* pDocument
, const ScAddress
& rPos
,
89 const OUString
& rExprNmsp1
= EMPTY_OUSTRING
, const OUString
& rExprNmsp2
= EMPTY_OUSTRING
,
90 formula::FormulaGrammar::Grammar eGrammar1
= formula::FormulaGrammar::GRAM_DEFAULT
,
91 formula::FormulaGrammar::Grammar eGrammar2
= formula::FormulaGrammar::GRAM_DEFAULT
);
92 ScValidationData( ScValidationMode eMode
, ScConditionMode eOper
,
93 const ScTokenArray
* pArr1
, const ScTokenArray
* pArr2
,
94 ScDocument
* pDocument
, const ScAddress
& rPos
);
95 ScValidationData( const ScValidationData
& r
);
96 ScValidationData( ScDocument
* pDocument
, const ScValidationData
& r
);
97 virtual ~ScValidationData() override
;
99 ScValidationData
* Clone() const // real copy
100 { return new ScValidationData( GetDocument(), *this ); }
101 ScValidationData
* Clone(ScDocument
* pNew
) const override
102 { return new ScValidationData( pNew
, *this ); }
106 void SetInput( const OUString
& rTitle
, const OUString
& rMsg
);
107 void SetError( const OUString
& rTitle
, const OUString
& rMsg
,
108 ScValidErrorStyle eStyle
);
110 bool GetInput( OUString
& rTitle
, OUString
& rMsg
) const
111 { rTitle
= aInputTitle
; rMsg
= aInputMessage
; return bShowInput
; }
112 bool GetErrMsg( OUString
& rTitle
, OUString
& rMsg
, ScValidErrorStyle
& rStyle
) const;
114 bool HasErrMsg() const { return bShowError
; }
116 ScValidationMode
GetDataMode() const { return eDataMode
; }
118 sal_Int16
GetListType() const { return mnListType
; }
119 void SetListType( sal_Int16 nListType
) { mnListType
= nListType
; }
121 /** Returns true, if the validation cell will show a selection list.
122 @descr Use this instead of GetListType() which returns the raw property
123 regardless of the validation type. */
124 bool HasSelectionList() const;
125 /** Tries to fill the passed collection with list validation entries.
126 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
127 @param rStrings (out-param) The string list to fill with list validation entires.
128 @return true = rStrings has been filled with at least one entry. */
129 bool FillSelectionList(std::vector
<ScTypedStrData
>& rStrings
, const ScAddress
& rPos
) const;
131 // with string: during input, with cell: for detective / RC_FORCED
133 const OUString
& rTest
, const ScPatternAttr
& rPattern
, const ScAddress
& rPos
) const;
135 bool IsDataValid( ScRefCellValue
& rCell
, const ScAddress
& rPos
) const;
138 bool DoError(weld::Window
* pParent
, const OUString
& rInput
, const ScAddress
& rPos
) const;
139 void DoCalcError( ScFormulaCell
* pCell
) const;
141 bool IsEmpty() const;
142 sal_uInt32
GetKey() const { return nKey
; }
143 void SetKey(sal_uInt32 nNew
) { nKey
= nNew
; } // only if not inserted!
145 bool EqualEntries( const ScValidationData
& r
) const; // for undo
147 // sort (using std::set) by index
148 bool operator < ( const ScValidationData
& r
) const { return nKey
< r
.nKey
; }
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;
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;
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;
170 // list of conditions:
172 struct CompareScValidationDataPtr
174 bool operator()( ScValidationData
* const& lhs
, ScValidationData
* const& rhs
) const { return (*lhs
)<(*rhs
); }
177 class ScValidationDataList
180 typedef std::set
<ScValidationData
*, CompareScValidationDataPtr
> ScValidationDataListDataType
;
181 ScValidationDataListDataType maData
;
184 ScValidationDataList() {}
185 ScValidationDataList(const ScValidationDataList
& rList
);
186 ScValidationDataList(ScDocument
* pNewDoc
, const ScValidationDataList
& rList
);
188 typedef ScValidationDataListDataType::iterator iterator
;
189 typedef ScValidationDataListDataType::const_iterator const_iterator
;
192 const_iterator
begin() const;
194 const_iterator
end() const;
196 void InsertNew( ScValidationData
* pNew
)
197 { if (!maData
.insert(pNew
).second
) delete pNew
; }
199 ScValidationData
* GetData( sal_uInt32 nKey
);
202 void UpdateReference( sc::RefUpdateContext
& rCxt
);
203 void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
204 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
205 void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */