LCOV - code coverage report
Current view: top level - sc/inc - conditio.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 23 82.6 %
Date: 2012-08-25 Functions: 17 22 77.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 50.0 %

           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_CONDITIO_HXX
      30                 :            : #define SC_CONDITIO_HXX
      31                 :            : 
      32                 :            : #include "global.hxx"
      33                 :            : #include "address.hxx"
      34                 :            : #include "formula/grammar.hxx"
      35                 :            : #include "scdllapi.h"
      36                 :            : #include "rangelst.hxx"
      37                 :            : 
      38                 :            : #include <boost/ptr_container/ptr_set.hpp>
      39                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      40                 :            : 
      41                 :            : class ScBaseCell;
      42                 :            : class ScFormulaCell;
      43                 :            : class ScTokenArray;
      44                 :            : 
      45                 :            : 
      46                 :            : #define SC_COND_GROW 16
      47                 :            : 
      48                 :            : //  nOptions Flags
      49                 :            : #define SC_COND_NOBLANKS    1
      50                 :            : 
      51                 :            : #define DUMP_FORMAT_INFO 1
      52                 :            : 
      53                 :            : 
      54                 :            : // ordering of ScConditionMode and ScQueryOp is equal,
      55                 :            : // to facilitate the merging of both in the future
      56                 :            : 
      57                 :            : enum ScConditionMode
      58                 :            : {
      59                 :            :     SC_COND_EQUAL, //done
      60                 :            :     SC_COND_LESS, //done
      61                 :            :     SC_COND_GREATER,
      62                 :            :     SC_COND_EQLESS,
      63                 :            :     SC_COND_EQGREATER,
      64                 :            :     SC_COND_NOTEQUAL, //done
      65                 :            :     SC_COND_BETWEEN,
      66                 :            :     SC_COND_NOTBETWEEN,
      67                 :            :     SC_COND_DUPLICATE,
      68                 :            :     SC_COND_NOTDUPLICATE,
      69                 :            :     SC_COND_DIRECT,
      70                 :            :     SC_COND_NONE
      71                 :            : };
      72                 :            : 
      73                 :            : class ScConditionalFormat;
      74                 :            : struct ScDataBarInfo;
      75                 :            : 
      76                 :            : namespace condformat
      77                 :            : {
      78                 :            : 
      79                 :            : enum ScFormatEntryType
      80                 :            : {
      81                 :            :     CONDITION,
      82                 :            :     COLORSCALE,
      83                 :            :     DATABAR
      84                 :            : };
      85                 :            : 
      86                 :            : }
      87                 :            : 
      88                 :      10177 : struct ScCondFormatData
      89                 :            : {
      90                 :      10177 :     ScCondFormatData():
      91                 :            :         pColorScale(NULL),
      92                 :      10177 :         pDataBar(NULL) {}
      93                 :            : 
      94                 :            :     Color* pColorScale;
      95                 :            :     ScDataBarInfo* pDataBar;
      96                 :            :     rtl::OUString aStyleName;
      97                 :            : };
      98                 :            : 
      99                 :            : class SC_DLLPUBLIC ScFormatEntry
     100                 :            : {
     101                 :            : public:
     102                 :            :     ScFormatEntry(ScDocument* pDoc);
     103         [ -  + ]:        197 :     virtual ~ScFormatEntry() {}
     104                 :            : 
     105                 :            :     virtual condformat::ScFormatEntryType GetType() const = 0;
     106                 :            :     virtual void UpdateReference( UpdateRefMode eUpdateRefMode,
     107                 :            :                                 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ) = 0;
     108                 :            :     virtual void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos ) = 0;
     109                 :            : 
     110                 :            :     virtual ScFormatEntry* Clone( ScDocument* pDoc = NULL ) const = 0;
     111                 :            : 
     112                 :            :     virtual void SetParent( ScConditionalFormat* pNew ) = 0;
     113                 :            : 
     114                 :            : #if DUMP_FORMAT_INFO
     115                 :            :     virtual void dumpInfo() const = 0;
     116                 :            : #endif
     117                 :            : protected:
     118                 :            :     ScDocument* mpDoc;
     119                 :            : 
     120                 :            : };
     121                 :            : 
     122                 :            : class SC_DLLPUBLIC ScConditionEntry : public ScFormatEntry
     123                 :            : {
     124                 :            :                                         // stored data:
     125                 :            :     ScConditionMode     eOp;
     126                 :            :     sal_uInt16              nOptions;
     127                 :            :     double              nVal1;          // input or calculated
     128                 :            :     double              nVal2;
     129                 :            :     String              aStrVal1;       // input or calculated
     130                 :            :     String              aStrVal2;
     131                 :            :     String              aStrNmsp1;      // namespace to be used on (re)compilation, e.g. in XML import
     132                 :            :     String              aStrNmsp2;      // namespace to be used on (re)compilation, e.g. in XML import
     133                 :            :     formula::FormulaGrammar::Grammar eTempGrammar1;  // grammar to be used on (re)compilation, e.g. in XML import
     134                 :            :     formula::FormulaGrammar::Grammar eTempGrammar2;  // grammar to be used on (re)compilation, e.g. in XML import
     135                 :            :     bool                bIsStr1;        // for recognition of empty strings
     136                 :            :     bool                bIsStr2;
     137                 :            :     ScTokenArray*       pFormula1;      // entered formula
     138                 :            :     ScTokenArray*       pFormula2;
     139                 :            :     ScAddress           aSrcPos;        // source position for formulas
     140                 :            :                                         // temporary data:
     141                 :            :     String              aSrcString;     // formula source position as text during XML import
     142                 :            :     ScFormulaCell*      pFCell1;
     143                 :            :     ScFormulaCell*      pFCell2;
     144                 :            :     bool                bRelRef1;
     145                 :            :     bool                bRelRef2;
     146                 :            :     bool                bFirstRun;
     147                 :            : 
     148                 :            :     void    MakeCells( const ScAddress& rPos );
     149                 :            :     void    Compile( const String& rExpr1, const String& rExpr2,
     150                 :            :                         const String& rExprNmsp1, const String& rExprNmsp2,
     151                 :            :                         formula::FormulaGrammar::Grammar eGrammar1,
     152                 :            :                         formula::FormulaGrammar::Grammar eGrammar2,
     153                 :            :                         bool bTextToReal );
     154                 :            :     void    Interpret( const ScAddress& rPos );
     155                 :            : 
     156                 :            :     bool    IsValid( double nArg, const ScAddress& rAddr ) const;
     157                 :            :     bool    IsValidStr( const String& rArg, const ScAddress& rAddr ) const;
     158                 :            : 
     159                 :            : public:
     160                 :            :             ScConditionEntry( ScConditionMode eOper,
     161                 :            :                                 const String& rExpr1, const String& rExpr2,
     162                 :            :                                 ScDocument* pDocument, const ScAddress& rPos,
     163                 :            :                                 const String& rExprNmsp1, const String& rExprNmsp2,
     164                 :            :                                 formula::FormulaGrammar::Grammar eGrammar1,
     165                 :            :                                 formula::FormulaGrammar::Grammar eGrammar2 );
     166                 :            :             ScConditionEntry( ScConditionMode eOper,
     167                 :            :                                 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
     168                 :            :                                 ScDocument* pDocument, const ScAddress& rPos );
     169                 :            :             ScConditionEntry( const ScConditionEntry& r );  // flat copy of formulas
     170                 :            :             // true copy of formulas (for Ref-Undo):
     171                 :            :             ScConditionEntry( ScDocument* pDocument, const ScConditionEntry& r );
     172                 :            :     virtual ~ScConditionEntry();
     173                 :            : 
     174                 :            :     int             operator== ( const ScConditionEntry& r ) const;
     175                 :            : 
     176                 :         68 :     virtual void SetParent( ScConditionalFormat* pNew )  { pCondFormat = pNew; }
     177                 :            : 
     178                 :            :     bool            IsCellValid( ScBaseCell* pCell, const ScAddress& rPos ) const;
     179                 :            : 
     180                 :         45 :     ScConditionMode GetOperation() const        { return eOp; }
     181                 :         45 :     bool            IsIgnoreBlank() const       { return ( nOptions & SC_COND_NOBLANKS ) == 0; }
     182                 :            :     void            SetIgnoreBlank(bool bSet);
     183                 :          0 :     ScAddress       GetSrcPos() const           { return aSrcPos; }
     184                 :            : 
     185                 :            :     ScAddress       GetValidSrcPos() const;     // adjusted to allow textual representation of expressions
     186                 :            : 
     187                 :            :     void            SetSrcString( const String& rNew );     // for XML import
     188                 :            : 
     189                 :            :     void            SetFormula1( const ScTokenArray& rArray );
     190                 :            :     void            SetFormula2( const ScTokenArray& rArray );
     191                 :            : 
     192                 :            :     String          GetExpression( const ScAddress& rCursor, sal_uInt16 nPos, sal_uLong nNumFmt = 0,
     193                 :            :                                     const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     194                 :            : 
     195                 :            :     ScTokenArray*   CreateTokenArry( sal_uInt16 nPos ) const;
     196                 :            : 
     197                 :            :     void            CompileAll();
     198                 :            :     void            CompileXML();
     199                 :            :     void            UpdateReference( UpdateRefMode eUpdateRefMode,
     200                 :            :                                 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     201                 :            :     void            UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
     202                 :            : 
     203                 :            :     void            SourceChanged( const ScAddress& rChanged );
     204                 :            : 
     205                 :            :     bool            MarkUsedExternalReferences() const;
     206                 :            : 
     207                 :       5482 :     virtual condformat::ScFormatEntryType GetType() const { return condformat::CONDITION; }
     208                 :            : 
     209                 :            :     virtual ScFormatEntry* Clone(ScDocument* pDoc = NULL) const;
     210                 :            : 
     211                 :            :     static ScConditionMode GetModeFromApi(sal_Int32 nOperator);
     212                 :            : 
     213                 :            : #if DUMP_FORMAT_INFO
     214                 :          0 :     virtual void dumpInfo() const {}
     215                 :            : #endif
     216                 :            : 
     217                 :            : protected:
     218                 :            :     virtual void    DataChanged( const ScRange* pModified ) const;
     219                 :         54 :     ScDocument*     GetDocument() const     { return mpDoc; }
     220                 :            :     ScConditionalFormat*    pCondFormat;
     221                 :            : };
     222                 :            : 
     223                 :            : //
     224                 :            : //  single entry for conditional formatting
     225                 :            : //
     226                 :            : 
     227                 :            : class SC_DLLPUBLIC ScCondFormatEntry : public ScConditionEntry
     228                 :            : {
     229                 :            :     String                  aStyleName;
     230                 :            : 
     231                 :            :     using ScConditionEntry::operator==;
     232                 :            : 
     233                 :            : public:
     234                 :            :             ScCondFormatEntry( ScConditionMode eOper,
     235                 :            :                                 const String& rExpr1, const String& rExpr2,
     236                 :            :                                 ScDocument* pDocument, const ScAddress& rPos,
     237                 :            :                                 const String& rStyle,
     238                 :            :                                 const String& rExprNmsp1 = EMPTY_STRING,
     239                 :            :                                 const String& rExprNmsp2 = EMPTY_STRING,
     240                 :            :                                 formula::FormulaGrammar::Grammar eGrammar1 = formula::FormulaGrammar::GRAM_DEFAULT,
     241                 :            :                                 formula::FormulaGrammar::Grammar eGrammar2 = formula::FormulaGrammar::GRAM_DEFAULT );
     242                 :            :             ScCondFormatEntry( ScConditionMode eOper,
     243                 :            :                                 const ScTokenArray* pArr1, const ScTokenArray* pArr2,
     244                 :            :                                 ScDocument* pDocument, const ScAddress& rPos,
     245                 :            :                                 const String& rStyle );
     246                 :            :             ScCondFormatEntry( const ScCondFormatEntry& r );
     247                 :            :             ScCondFormatEntry( ScDocument* pDocument, const ScCondFormatEntry& r );
     248                 :            :     virtual ~ScCondFormatEntry();
     249                 :            : 
     250                 :            :     int             operator== ( const ScCondFormatEntry& r ) const;
     251                 :            : 
     252                 :       4127 :     const String&   GetStyle() const        { return aStyleName; }
     253                 :          0 :     void            UpdateStyleName(const String& rNew)  { aStyleName=rNew; }
     254                 :            :     virtual ScFormatEntry* Clone(ScDocument* pDoc) const;
     255                 :            : 
     256                 :            : protected:
     257                 :            :     virtual void    DataChanged( const ScRange* pModified ) const;
     258                 :            : };
     259                 :            : 
     260                 :            : //
     261                 :            : //  complete conditional formatting
     262                 :            : //
     263                 :            : 
     264                 :            : class SC_DLLPUBLIC ScConditionalFormat
     265                 :            : {
     266                 :            :     ScDocument*         pDoc;
     267                 :            :     sal_uInt32          nKey;               // Index in attributes
     268                 :            : 
     269                 :            :     typedef boost::ptr_vector<ScFormatEntry> CondFormatContainer;
     270                 :            :     CondFormatContainer maEntries;
     271                 :            :     bool                bIsUsed;            // temporary at Save
     272                 :            :     ScRangeList maRanges;            // Ranges for conditional format
     273                 :            : 
     274                 :            : public:
     275                 :            :             ScConditionalFormat(sal_uInt32 nNewKey, ScDocument* pDocument);
     276                 :            :             ScConditionalFormat(const ScConditionalFormat& r);
     277                 :            :             ~ScConditionalFormat();
     278                 :            : 
     279                 :            :     // true copy of formulas (for Ref-Undo / between documents)
     280                 :            :     ScConditionalFormat* Clone(ScDocument* pNewDoc = NULL) const;
     281                 :            : 
     282                 :            :     void            AddEntry( ScFormatEntry* pNew );
     283                 :            :     void            AddRange( const ScRangeList& rRanges );
     284                 :         51 :     const ScRangeList&  GetRange() const  { return maRanges; }
     285                 :            : 
     286                 :          0 :     bool IsEmpty() const         { return maEntries.empty(); }
     287                 :      10310 :     size_t size() const           { return maEntries.size(); }
     288                 :            : 
     289                 :            :     void            CompileAll();
     290                 :            :     void            CompileXML();
     291                 :            :     void            UpdateReference( UpdateRefMode eUpdateRefMode,
     292                 :            :                                 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     293                 :            :     void            UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
     294                 :            :     void            RenameCellStyle( const String& rOld, const String& rNew );
     295                 :            : 
     296                 :            :     void            SourceChanged( const ScAddress& rAddr );
     297                 :            : 
     298                 :            :     const ScFormatEntry* GetEntry( sal_uInt16 nPos ) const;
     299                 :            : 
     300                 :            :     const String&   GetCellStyle( ScBaseCell* pCell, const ScAddress& rPos ) const;
     301                 :            : 
     302                 :            :     ScCondFormatData GetData( ScBaseCell* pCell, const ScAddress& rPos ) const;
     303                 :            : 
     304                 :            :     bool            EqualEntries( const ScConditionalFormat& r ) const;
     305                 :            : 
     306                 :            :     void            DoRepaint( const ScRange* pModified );
     307                 :            : 
     308                 :      24565 :     sal_uInt32      GetKey() const          { return nKey; }
     309                 :         53 :     void            SetKey(sal_uInt32 nNew) { nKey = nNew; }    // only if not inserted!
     310                 :            : 
     311                 :            :     void            SetUsed(bool bSet)      { bIsUsed = bSet; }
     312                 :            :     bool            IsUsed() const          { return bIsUsed; }
     313                 :            : 
     314                 :            :     bool            MarkUsedExternalReferences() const;
     315                 :            : 
     316                 :            : #if DUMP_FORMAT_INFO
     317                 :            :     void dumpInfo() const;
     318                 :            : #endif
     319                 :            : 
     320                 :            :     //  sorted (via PTRARR) by Index
     321                 :            :     //  operator== only for sorting
     322                 :            :     bool operator ==( const ScConditionalFormat& r ) const  { return nKey == r.nKey; }
     323                 :        117 :     bool operator < ( const ScConditionalFormat& r ) const  { return nKey <  r.nKey; }
     324                 :            : };
     325                 :            : 
     326                 :            : //
     327                 :            : //  List of areas and formats:
     328                 :            : //
     329                 :            : 
     330                 :            : class SC_DLLPUBLIC ScConditionalFormatList
     331                 :            : {
     332                 :            : private:
     333                 :            :     boost::ptr_set<ScConditionalFormat> maConditionalFormats;
     334                 :            :     typedef boost::ptr_set<ScConditionalFormat> ConditionalFormatContainer;
     335                 :            : public:
     336                 :       1939 :     ScConditionalFormatList() {}
     337                 :            :     ScConditionalFormatList(const ScConditionalFormatList& rList);
     338                 :            :     ScConditionalFormatList(ScDocument* pDoc, const ScConditionalFormatList& rList);
     339                 :       1771 :     ~ScConditionalFormatList() {}
     340                 :            : 
     341                 :         41 :     void    InsertNew( ScConditionalFormat* pNew )
     342                 :         41 :                 { maConditionalFormats.insert(pNew); }
     343                 :            : 
     344                 :            :     ScConditionalFormat* GetFormat( sal_uInt32 nKey );
     345                 :            : 
     346                 :            :     void    CompileAll();
     347                 :            :     void    CompileXML();
     348                 :            :     void    UpdateReference( UpdateRefMode eUpdateRefMode,
     349                 :            :                                 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     350                 :            :     void    RenameCellStyle( const String& rOld, const String& rNew );
     351                 :            :     void    UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
     352                 :            : 
     353                 :            :     void    SourceChanged( const ScAddress& rAddr );
     354                 :            : 
     355                 :            :     bool    operator==( const ScConditionalFormatList& r ) const;       // for Ref-Undo
     356                 :            : 
     357                 :            :     typedef ConditionalFormatContainer::iterator iterator;
     358                 :            :     typedef ConditionalFormatContainer::const_iterator const_iterator;
     359                 :            : 
     360                 :            :     iterator begin();
     361                 :            :     const_iterator begin() const;
     362                 :            :     iterator end();
     363                 :            :     const_iterator end() const;
     364                 :            : 
     365                 :            :     size_t size() const;
     366                 :            : 
     367                 :            :     void erase(sal_uLong nIndex);
     368                 :            : };
     369                 :            : 
     370                 :            : // see http://www.boost.org/doc/libs/1_49_0/libs/ptr_container/doc/tutorial.html#cloneability
     371                 :            : //for MSVC we need:
     372                 :            : inline ScFormatEntry* new_clone( const ScFormatEntry& rFormat )
     373                 :            : {
     374                 :            :     return rFormat.Clone();
     375                 :            : }
     376                 :            : 
     377                 :            : #endif
     378                 :            : 
     379                 :            : 
     380                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10