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