Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_VALIDAT_HXX
30 : : #define SC_VALIDAT_HXX
31 : :
32 : : #include "conditio.hxx"
33 : : #include <com/sun/star/sheet/TableValidationVisibility.hpp>
34 : : #include "scdllapi.h"
35 : :
36 : : namespace ValidListType = ::com::sun::star::sheet::TableValidationVisibility;
37 : :
38 : : class ScPatternAttr;
39 : : class ScTokenArray;
40 : : class ScTypedStrData;
41 : :
42 : : enum ScValidationMode
43 : : {
44 : : SC_VALID_ANY,
45 : : SC_VALID_WHOLE,
46 : : SC_VALID_DECIMAL,
47 : : SC_VALID_DATE,
48 : : SC_VALID_TIME,
49 : : SC_VALID_TEXTLEN,
50 : : SC_VALID_LIST,
51 : : SC_VALID_CUSTOM
52 : : };
53 : :
54 : : enum ScValidErrorStyle
55 : : {
56 : : SC_VALERR_STOP,
57 : : SC_VALERR_WARNING,
58 : : SC_VALERR_INFO,
59 : : SC_VALERR_MACRO
60 : : };
61 : :
62 : : //
63 : : // Entry for validation (only one condition exists)
64 : : //
65 : :
66 : : class SC_DLLPUBLIC ScValidationData : public ScConditionEntry
67 : : {
68 : : sal_uInt32 nKey; // index in attributes
69 : :
70 : : ScValidationMode eDataMode;
71 : : sal_Bool bShowInput;
72 : : sal_Bool bShowError;
73 : : ScValidErrorStyle eErrorStyle;
74 : : sal_Int16 mnListType; // selection list type: none, unsorted, sorted.
75 : : String aInputTitle;
76 : : String aInputMessage;
77 : : String aErrorTitle;
78 : : String aErrorMessage;
79 : :
80 : : sal_Bool bIsUsed; // temporary during saving
81 : :
82 : : sal_Bool DoMacro( const ScAddress& rPos, const String& rInput,
83 : : ScFormulaCell* pCell, Window* pParent ) const;
84 : :
85 : : sal_Bool DoScript( const ScAddress& rPos, const String& rInput,
86 : : ScFormulaCell* pCell, Window* pParent ) const;
87 : :
88 : : using ScConditionEntry::operator==;
89 : :
90 : : public:
91 : : ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
92 : : const String& rExpr1, const String& rExpr2,
93 : : ScDocument* pDocument, const ScAddress& rPos,
94 [ + - ][ + - ]: 54 : const String& rExprNmsp1 = EMPTY_STRING, const String& rExprNmsp2 = EMPTY_STRING,
95 : : formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
96 : : formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
97 : : ScValidationData( ScValidationMode eMode, ScConditionMode eOper,
98 : : const ScTokenArray* pArr1, const ScTokenArray* pArr2,
99 : : ScDocument* pDocument, const ScAddress& rPos );
100 : : ScValidationData( const ScValidationData& r );
101 : : ScValidationData( ScDocument* pDocument, const ScValidationData& r );
102 : : virtual ~ScValidationData();
103 : :
104 : 0 : ScValidationData* Clone() const // real copy
105 [ # # ]: 0 : { return new ScValidationData( GetDocument(), *this ); }
106 : 12 : ScValidationData* Clone(ScDocument* pNew) const
107 [ + - ]: 12 : { return new ScValidationData( pNew, *this ); }
108 : :
109 : : void ResetInput();
110 : : void ResetError();
111 : : void SetInput( const String& rTitle, const String& rMsg );
112 : : void SetError( const String& rTitle, const String& rMsg,
113 : : ScValidErrorStyle eStyle );
114 : :
115 : 45 : sal_Bool GetInput( String& rTitle, String& rMsg ) const
116 : 45 : { rTitle = aInputTitle; rMsg = aInputMessage; return bShowInput; }
117 : : sal_Bool GetErrMsg( String& rTitle, String& rMsg, ScValidErrorStyle& rStyle ) const;
118 : :
119 : 0 : sal_Bool HasErrMsg() const { return bShowError; }
120 : :
121 : 45 : ScValidationMode GetDataMode() const { return eDataMode; }
122 : :
123 : 45 : inline sal_Int16 GetListType() const { return mnListType; }
124 : 60 : inline void SetListType( sal_Int16 nListType ) { mnListType = nListType; }
125 : :
126 : : /** Returns true, if the validation cell will show a selection list.
127 : : @descr Use this instead of GetListType() which returns the raw property
128 : : regardless of the validation type. */
129 : : bool HasSelectionList() const;
130 : : /** Tries to fill the passed collection with list validation entries.
131 : : @descr Fills the list only, if this is a list validation and IsShowList() is enabled.
132 : : @param rStrings (out-param) The string list to fill with list validation entires.
133 : : @return true = rStrings has been filled with at least one entry. */
134 : : bool FillSelectionList(std::vector<ScTypedStrData>& rStrings, const ScAddress& rPos) const;
135 : :
136 : : // with string: during input, with cell: for detective / RC_FORCED
137 : : sal_Bool IsDataValid( const String& rTest, const ScPatternAttr& rPattern,
138 : : const ScAddress& rPos ) const;
139 : : sal_Bool IsDataValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
140 : :
141 : : // TRUE -> break
142 : : sal_Bool DoError( Window* pParent, const String& rInput, const ScAddress& rPos ) const;
143 : : void DoCalcError( ScFormulaCell* pCell ) const;
144 : :
145 : : sal_Bool IsEmpty() const;
146 : 480 : sal_uInt32 GetKey() const { return nKey; }
147 : 12 : void SetKey(sal_uInt32 nNew) { nKey = nNew; } // only if not inserted!
148 : :
149 : : void SetUsed(sal_Bool bSet) { bIsUsed = bSet; }
150 : : sal_Bool IsUsed() const { return bIsUsed; }
151 : :
152 : : sal_Bool EqualEntries( const ScValidationData& r ) const; // for undo
153 : :
154 : : // sort (using std::set) by index
155 : : // operator== only for sorting
156 : : bool operator ==( const ScValidationData& r ) const { return nKey == r.nKey; }
157 : 9 : bool operator < ( const ScValidationData& r ) const { return nKey < r.nKey; }
158 : :
159 : : private:
160 : : /** Tries to fill the passed collection with list validation entries.
161 : : @descr Fills the list only if it is non-NULL,
162 : : @param pStrings (out-param) Optionally NULL, string list to fill with list validation entires.
163 : : @param pCell can be NULL if it is not necessary to which element in the list is selected.
164 : : @param rPos the base address for relative references.
165 : : @param rTokArr Formula token array.
166 : : @param rMatch (out-param) the index of the first item that matched, -1 if nothing matched.
167 : : @return true = Cell range found, rRange is valid, or an error entry stuffed into the list if pCell==NULL. */
168 : : bool GetSelectionFromFormula(
169 : : std::vector<ScTypedStrData>* pStrings, ScBaseCell* pCell, const ScAddress& rPos,
170 : : const ScTokenArray& rTokArr, int& rMatch) const;
171 : :
172 : : /** Tests, if pCell is equal to what the passed token array represents. */
173 : : bool IsEqualToTokenArray( ScBaseCell* pCell, const ScAddress& rPos, const ScTokenArray& rTokArr ) const;
174 : :
175 : : /** Tests, if contents of pCell occur in cell range referenced by own formula, or in a string list. */
176 : : bool IsListValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
177 : : };
178 : :
179 : : //
180 : : // list of contitions:
181 : : //
182 : :
183 : : struct CompareScValidationDataPtr
184 : : {
185 : 9 : bool operator()( ScValidationData* const& lhs, ScValidationData* const& rhs ) const { return (*lhs)<(*rhs); }
186 : : };
187 : :
188 : : class ScValidationDataList : public std::set<ScValidationData*, CompareScValidationDataPtr>
189 : : {
190 : : public:
191 : 9 : ScValidationDataList() {}
192 : : ScValidationDataList(const ScValidationDataList& rList);
193 : : ScValidationDataList(ScDocument* pNewDoc, const ScValidationDataList& rList);
194 : 9 : ~ScValidationDataList() {}
195 : :
196 : 12 : void InsertNew( ScValidationData* pNew )
197 [ - + ][ # # ]: 12 : { if (!insert(pNew).second) delete pNew; }
198 : :
199 : : ScValidationData* GetData( sal_uInt32 nKey );
200 : :
201 : : void CompileXML();
202 : : void UpdateReference( UpdateRefMode eUpdateRefMode,
203 : : const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
204 : : void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
205 : :
206 : : sal_Bool operator==( const ScValidationDataList& r ) const; // for ref-undo
207 : : };
208 : :
209 : : #endif
210 : :
211 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|