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