LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/inc - validat.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 19 84.2 %
Date: 2013-07-09 Functions: 12 14 85.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10