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 ValidListType
= ::com::sun::star::sheet::TableValidationVisibility
;
31 struct RefUpdateContext
;
51 enum ScValidErrorStyle
60 // Entry for validation (only one condition exists)
63 class SC_DLLPUBLIC ScValidationData
: public ScConditionEntry
66 sal_uInt32 nKey
; // index in attributes
68 ScValidationMode eDataMode
;
71 ScValidErrorStyle eErrorStyle
;
72 sal_Int16 mnListType
; // selection list type: none, unsorted, sorted.
74 OUString aInputMessage
;
76 OUString aErrorMessage
;
78 bool DoMacro( const ScAddress
& rPos
, const OUString
& rInput
,
79 ScFormulaCell
* pCell
, Window
* pParent
) const;
81 bool DoScript( const ScAddress
& rPos
, const OUString
& rInput
,
82 ScFormulaCell
* pCell
, Window
* pParent
) const;
84 using ScConditionEntry::operator==;
87 ScValidationData( ScValidationMode eMode
, ScConditionMode eOper
,
88 const OUString
& rExpr1
, const OUString
& rExpr2
,
89 ScDocument
* pDocument
, const ScAddress
& rPos
,
90 const OUString
& rExprNmsp1
= EMPTY_OUSTRING
, const OUString
& rExprNmsp2
= EMPTY_OUSTRING
,
91 formula::FormulaGrammar::Grammar eGrammar1
= formula::FormulaGrammar::GRAM_DEFAULT
,
92 formula::FormulaGrammar::Grammar eGrammar2
= formula::FormulaGrammar::GRAM_DEFAULT
);
93 ScValidationData( ScValidationMode eMode
, ScConditionMode eOper
,
94 const ScTokenArray
* pArr1
, const ScTokenArray
* pArr2
,
95 ScDocument
* pDocument
, const ScAddress
& rPos
);
96 ScValidationData( const ScValidationData
& r
);
97 ScValidationData( ScDocument
* pDocument
, const ScValidationData
& r
);
98 virtual ~ScValidationData();
100 ScValidationData
* Clone() const // real copy
101 { return new ScValidationData( GetDocument(), *this ); }
102 ScValidationData
* Clone(ScDocument
* pNew
) const SAL_OVERRIDE
103 { return new ScValidationData( pNew
, *this ); }
107 void SetInput( const OUString
& rTitle
, const OUString
& rMsg
);
108 void SetError( const OUString
& rTitle
, const OUString
& rMsg
,
109 ScValidErrorStyle eStyle
);
111 bool GetInput( OUString
& rTitle
, OUString
& rMsg
) const
112 { rTitle
= aInputTitle
; rMsg
= aInputMessage
; return bShowInput
; }
113 bool GetErrMsg( OUString
& rTitle
, OUString
& rMsg
, ScValidErrorStyle
& rStyle
) const;
115 bool HasErrMsg() const { return bShowError
; }
117 ScValidationMode
GetDataMode() const { return eDataMode
; }
119 inline sal_Int16
GetListType() const { return mnListType
; }
120 inline void SetListType( sal_Int16 nListType
) { mnListType
= nListType
; }
122 /** Returns true, if the validation cell will show a selection list.
123 @descr Use this instead of GetListType() which returns the raw property
124 regardless of the validation type. */
125 bool HasSelectionList() const;
126 /** Tries to fill the passed collection with list validation entries.
127 @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
128 @param rStrings (out-param) The string list to fill with list validation entires.
129 @return true = rStrings has been filled with at least one entry. */
130 bool FillSelectionList(std::vector
<ScTypedStrData
>& rStrings
, const ScAddress
& rPos
) const;
132 // with string: during input, with cell: for detective / RC_FORCED
134 const OUString
& rTest
, const ScPatternAttr
& rPattern
, const ScAddress
& rPos
) const;
136 bool IsDataValid( ScRefCellValue
& rCell
, const ScAddress
& rPos
) const;
139 bool DoError( Window
* pParent
, const OUString
& rInput
, const ScAddress
& rPos
) const;
140 void DoCalcError( ScFormulaCell
* pCell
) const;
142 bool IsEmpty() const;
143 sal_uInt32
GetKey() const { return nKey
; }
144 void SetKey(sal_uInt32 nNew
) { nKey
= nNew
; } // only if not inserted!
146 bool EqualEntries( const ScValidationData
& r
) const; // for undo
148 // sort (using std::set) by index
149 // operator== only for sorting
150 bool operator ==( const ScValidationData
& r
) const { return nKey
== r
.nKey
; }
151 bool operator < ( const ScValidationData
& r
) const { return nKey
< r
.nKey
; }
154 /** Tries to fill the passed collection with list validation entries.
155 @descr Fills the list only if it is non-NULL,
156 @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
157 @param pCell can be NULL if it is not necessary to which element in the list is selected.
158 @param rPos the base address for relative references.
159 @param rTokArr Formula token array.
160 @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
161 @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
162 bool GetSelectionFromFormula(
163 std::vector
<ScTypedStrData
>* pStrings
, ScRefCellValue
& rCell
, const ScAddress
& rPos
,
164 const ScTokenArray
& rTokArr
, int& rMatch
) const;
166 /** Tests, if pCell is equal to what the passed token array represents. */
167 bool IsEqualToTokenArray( ScRefCellValue
& rCell
, const ScAddress
& rPos
, const ScTokenArray
& rTokArr
) const;
169 /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
170 bool IsListValid( ScRefCellValue
& rCell
, const ScAddress
& rPos
) const;
174 // list of contitions:
177 struct CompareScValidationDataPtr
179 bool operator()( ScValidationData
* const& lhs
, ScValidationData
* const& rhs
) const { return (*lhs
)<(*rhs
); }
182 class ScValidationDataList
185 typedef std::set
<ScValidationData
*, CompareScValidationDataPtr
> ScValidationDataListDataType
;
186 ScValidationDataListDataType maData
;
189 ScValidationDataList() {}
190 ScValidationDataList(const ScValidationDataList
& rList
);
191 ScValidationDataList(ScDocument
* pNewDoc
, const ScValidationDataList
& rList
);
192 ~ScValidationDataList() {}
194 typedef ScValidationDataListDataType::iterator iterator
;
195 typedef ScValidationDataListDataType::const_iterator const_iterator
;
198 const_iterator
begin() const;
200 const_iterator
end() const;
202 void InsertNew( ScValidationData
* pNew
)
203 { if (!maData
.insert(pNew
).second
) delete pNew
; }
205 ScValidationData
* GetData( sal_uInt32 nKey
);
208 void UpdateReference( sc::RefUpdateContext
& rCxt
);
209 void UpdateInsertTab( sc::RefUpdateInsertTabContext
& rCxt
);
210 void UpdateDeleteTab( sc::RefUpdateDeleteTabContext
& rCxt
);
211 void UpdateMoveTab( sc::RefUpdateMoveTabContext
& rCxt
);
213 bool operator==( const ScValidationDataList
& r
) const; // for ref-undo
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */