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