LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/oox - condformatbuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 137 503 27.2 %
Date: 2012-12-27 Functions: 18 44 40.9 %
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             : #include "condformatbuffer.hxx"
      21             : 
      22             : #include <com/sun/star/beans/PropertyValue.hpp>
      23             : #include <com/sun/star/container/XIndexAccess.hpp>
      24             : #include <com/sun/star/container/XNameContainer.hpp>
      25             : #include <com/sun/star/sheet/ConditionOperator2.hpp>
      26             : #include <com/sun/star/sheet/XSheetCellRanges.hpp>
      27             : #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
      28             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      29             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      30             : #include <com/sun/star/sheet/XSpreadsheets.hpp>
      31             : #include <com/sun/star/style/XStyle.hpp>
      32             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      33             : #include <com/sun/star/table/CellAddress.hpp>
      34             : #include <com/sun/star/table/CellRangeAddress.hpp>
      35             : #include <com/sun/star/table/XCellRange.hpp>
      36             : #include <rtl/ustrbuf.hxx>
      37             : #include <svl/intitem.hxx>
      38             : #include "oox/helper/attributelist.hxx"
      39             : #include "oox/helper/containerhelper.hxx"
      40             : #include "oox/helper/propertyset.hxx"
      41             : #include "oox/token/properties.hxx"
      42             : #include "addressconverter.hxx"
      43             : #include "biffinputstream.hxx"
      44             : #include "stylesbuffer.hxx"
      45             : #include "themebuffer.hxx"
      46             : 
      47             : #include "colorscale.hxx"
      48             : #include "conditio.hxx"
      49             : #include "document.hxx"
      50             : #include "convuno.hxx"
      51             : #include "docfunc.hxx"
      52             : #include "tokenarray.hxx"
      53             : #include "tokenuno.hxx"
      54             : 
      55             : namespace oox {
      56             : namespace xls {
      57             : 
      58             : // ============================================================================
      59             : 
      60             : using namespace ::com::sun::star::beans;
      61             : using namespace ::com::sun::star::container;
      62             : using namespace ::com::sun::star::sheet;
      63             : using namespace ::com::sun::star::style;
      64             : using namespace ::com::sun::star::table;
      65             : using namespace ::com::sun::star::uno;
      66             : 
      67             : using ::rtl::OUString;
      68             : using ::rtl::OUStringBuffer;
      69             : 
      70             : // ============================================================================
      71             : 
      72             : namespace {
      73             : 
      74             : const sal_Int32 BIFF12_CFRULE_TYPE_CELLIS           = 1;
      75             : const sal_Int32 BIFF12_CFRULE_TYPE_EXPRESSION       = 2;
      76             : const sal_Int32 BIFF12_CFRULE_TYPE_COLORSCALE       = 3;
      77             : const sal_Int32 BIFF12_CFRULE_TYPE_DATABAR          = 4;
      78             : const sal_Int32 BIFF12_CFRULE_TYPE_TOPTEN           = 5;
      79             : const sal_Int32 BIFF12_CFRULE_TYPE_ICONSET          = 6;
      80             : 
      81             : const sal_Int32 BIFF12_CFRULE_SUB_CELLIS            = 0;
      82             : const sal_Int32 BIFF12_CFRULE_SUB_EXPRESSION        = 1;
      83             : const sal_Int32 BIFF12_CFRULE_SUB_COLORSCALE        = 2;
      84             : const sal_Int32 BIFF12_CFRULE_SUB_DATABAR           = 3;
      85             : const sal_Int32 BIFF12_CFRULE_SUB_ICONSET           = 4;
      86             : const sal_Int32 BIFF12_CFRULE_SUB_TOPTEN            = 5;
      87             : const sal_Int32 BIFF12_CFRULE_SUB_UNIQUE            = 7;
      88             : const sal_Int32 BIFF12_CFRULE_SUB_TEXT              = 8;
      89             : const sal_Int32 BIFF12_CFRULE_SUB_BLANK             = 9;
      90             : const sal_Int32 BIFF12_CFRULE_SUB_NOTBLANK          = 10;
      91             : const sal_Int32 BIFF12_CFRULE_SUB_ERROR             = 11;
      92             : const sal_Int32 BIFF12_CFRULE_SUB_NOTERROR          = 12;
      93             : const sal_Int32 BIFF12_CFRULE_SUB_TODAY             = 15;
      94             : const sal_Int32 BIFF12_CFRULE_SUB_TOMORROW          = 16;
      95             : const sal_Int32 BIFF12_CFRULE_SUB_YESTERDAY         = 17;
      96             : const sal_Int32 BIFF12_CFRULE_SUB_LAST7DAYS         = 18;
      97             : const sal_Int32 BIFF12_CFRULE_SUB_LASTMONTH         = 19;
      98             : const sal_Int32 BIFF12_CFRULE_SUB_NEXTMONTH         = 20;
      99             : const sal_Int32 BIFF12_CFRULE_SUB_THISWEEK          = 21;
     100             : const sal_Int32 BIFF12_CFRULE_SUB_NEXTWEEK          = 22;
     101             : const sal_Int32 BIFF12_CFRULE_SUB_LASTWEEK          = 23;
     102             : const sal_Int32 BIFF12_CFRULE_SUB_THISMONTH         = 24;
     103             : const sal_Int32 BIFF12_CFRULE_SUB_ABOVEAVERAGE      = 25;
     104             : const sal_Int32 BIFF12_CFRULE_SUB_BELOWAVERAGE      = 26;
     105             : const sal_Int32 BIFF12_CFRULE_SUB_DUPLICATE         = 27;
     106             : const sal_Int32 BIFF12_CFRULE_SUB_EQABOVEAVERAGE    = 29;
     107             : const sal_Int32 BIFF12_CFRULE_SUB_EQBELOWAVERAGE    = 30;
     108             : 
     109             : const sal_Int32 BIFF12_CFRULE_TIMEOP_TODAY          = 0;
     110             : const sal_Int32 BIFF12_CFRULE_TIMEOP_YESTERDAY      = 1;
     111             : const sal_Int32 BIFF12_CFRULE_TIMEOP_LAST7DAYS      = 2;
     112             : const sal_Int32 BIFF12_CFRULE_TIMEOP_THISWEEK       = 3;
     113             : const sal_Int32 BIFF12_CFRULE_TIMEOP_LASTWEEK       = 4;
     114             : const sal_Int32 BIFF12_CFRULE_TIMEOP_LASTMONTH      = 5;
     115             : const sal_Int32 BIFF12_CFRULE_TIMEOP_TOMORROW       = 6;
     116             : const sal_Int32 BIFF12_CFRULE_TIMEOP_NEXTWEEK       = 7;
     117             : const sal_Int32 BIFF12_CFRULE_TIMEOP_NEXTMONTH      = 8;
     118             : const sal_Int32 BIFF12_CFRULE_TIMEOP_THISMONTH      = 9;
     119             : 
     120             : const sal_uInt16 BIFF12_CFRULE_STOPIFTRUE           = 0x0002;
     121             : const sal_uInt16 BIFF12_CFRULE_ABOVEAVERAGE         = 0x0004;
     122             : const sal_uInt16 BIFF12_CFRULE_BOTTOM               = 0x0008;
     123             : const sal_uInt16 BIFF12_CFRULE_PERCENT              = 0x0010;
     124             : 
     125             : // ----------------------------------------------------------------------------
     126             : 
     127             : template< typename Type >
     128             : void lclAppendProperty( ::std::vector< PropertyValue >& orProps, const OUString& rPropName, const Type& rValue )
     129             : {
     130             :     orProps.push_back( PropertyValue() );
     131             :     orProps.back().Name = rPropName;
     132             :     orProps.back().Value <<= rValue;
     133             : }
     134             : 
     135             : //------------------------------------------------------------------------------
     136             : 
     137           0 : void SetCfvoData( ColorScaleRuleModelEntry* pEntry, const AttributeList& rAttribs )
     138             : {
     139           0 :     rtl::OUString aType = rAttribs.getString( XML_type, rtl::OUString() );
     140             : 
     141           0 :     double nVal = rAttribs.getDouble( XML_val, 0.0 );
     142           0 :     pEntry->mnVal = nVal;
     143           0 :     if (aType == "num")
     144             :     {
     145             :         // nothing to do
     146             :     }
     147           0 :     else if( aType == "min" )
     148             :     {
     149           0 :         pEntry->mbMin = true;
     150             :     }
     151           0 :     else if( aType == "max" )
     152             :     {
     153           0 :         pEntry->mbMax = true;
     154             :     }
     155           0 :     else if( aType == "percent" )
     156             :     {
     157           0 :         pEntry->mbPercent = true;
     158             :     }
     159           0 :     else if( aType == "percentile" )
     160             :     {
     161           0 :         pEntry->mbPercentile = true;
     162             :     }
     163           0 :     else if( aType == "formula" )
     164             :     {
     165           0 :         rtl::OUString aFormula = rAttribs.getString( XML_val, rtl::OUString() );
     166           0 :         pEntry->maFormula = aFormula;
     167           0 :     }
     168             : 
     169           0 : }
     170             : 
     171             : }
     172             : 
     173           0 : ColorScaleRule::ColorScaleRule( const CondFormat& rFormat ):
     174             :     WorksheetHelper( rFormat ),
     175             :     mnCfvo(0),
     176           0 :     mnCol(0)
     177             : {
     178           0 : }
     179             : 
     180           0 : void ColorScaleRule::importCfvo( const AttributeList& rAttribs )
     181             : {
     182           0 :     if(mnCfvo >= maColorScaleRuleEntries.size())
     183           0 :         maColorScaleRuleEntries.push_back(ColorScaleRuleModelEntry());
     184             : 
     185           0 :     SetCfvoData( &maColorScaleRuleEntries[mnCfvo], rAttribs );
     186             : 
     187           0 :     ++mnCfvo;
     188           0 : }
     189             : 
     190             : namespace {
     191             : 
     192           0 : ::Color RgbToRgbComponents( sal_Int32& nRgb )
     193             : {
     194           0 :     sal_Int32 ornR = (nRgb >> 16) & 0xFF;
     195           0 :     sal_Int32 ornG = (nRgb >> 8) & 0xFF;
     196           0 :     sal_Int32 ornB = nRgb & 0xFF;
     197             : 
     198           0 :     return ::Color(ornR, ornG, ornB);
     199             : }
     200             : 
     201             : }
     202             : 
     203           0 : void ColorScaleRule::importColor( const AttributeList& rAttribs )
     204             : {
     205           0 :     sal_Int32 nColor = 0;
     206           0 :     if( rAttribs.hasAttribute( XML_rgb ) )
     207           0 :         nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
     208           0 :     else if( rAttribs.hasAttribute( XML_theme ) )
     209             :     {
     210           0 :         sal_uInt32 nThemeIndex = rAttribs.getUnsigned( XML_theme, 0 );
     211           0 :         nColor = getTheme().getColorByToken( nThemeIndex );
     212             :     }
     213             : 
     214           0 :     ::Color aColor = RgbToRgbComponents( nColor );
     215             : 
     216           0 :     if(mnCol >= maColorScaleRuleEntries.size())
     217           0 :         maColorScaleRuleEntries.push_back(ColorScaleRuleModelEntry());
     218             : 
     219           0 :     maColorScaleRuleEntries[mnCol].maColor = aColor;
     220           0 :     ++mnCol;
     221           0 : }
     222             : 
     223             : namespace {
     224             : 
     225           0 : ScColorScaleEntry* ConvertToModel( const ColorScaleRuleModelEntry& rEntry, ScDocument* pDoc, const ScAddress& rAddr )
     226             : {
     227           0 :         ScColorScaleEntry* pEntry = new ScColorScaleEntry(rEntry.mnVal, rEntry.maColor);
     228             : 
     229           0 :         if(rEntry.mbMin)
     230           0 :             pEntry->SetType(COLORSCALE_MIN);
     231           0 :         if(rEntry.mbMax)
     232           0 :             pEntry->SetType(COLORSCALE_MAX);
     233           0 :         if(rEntry.mbPercent)
     234           0 :             pEntry->SetType(COLORSCALE_PERCENT);
     235           0 :         if(rEntry.mbPercentile)
     236           0 :             pEntry->SetType(COLORSCALE_PERCENTILE);
     237             : 
     238           0 :         if(!rEntry.maFormula.isEmpty())
     239             :         {
     240           0 :             pEntry->SetType(COLORSCALE_FORMULA);
     241           0 :             pEntry->SetFormula(rEntry.maFormula, pDoc, rAddr, formula::FormulaGrammar::GRAM_ENGLISH_XL_A1);
     242             :         }
     243             : 
     244           0 :         return pEntry;
     245             : }
     246             : 
     247             : }
     248             : 
     249           0 : void ColorScaleRule::AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr )
     250             : {
     251           0 :     for(size_t i = 0; i < maColorScaleRuleEntries.size(); ++i)
     252             :     {
     253           0 :         const ColorScaleRuleModelEntry& rEntry = maColorScaleRuleEntries[i];
     254             : 
     255           0 :         ScColorScaleEntry* pEntry = ConvertToModel( rEntry, pDoc, rAddr );
     256             : 
     257           0 :         pFormat->AddEntry( pEntry );
     258             :     }
     259           0 : }
     260             : 
     261             : // ============================================================================
     262             : 
     263           0 : DataBarRule::DataBarRule( const CondFormat& rFormat ):
     264             :     WorksheetHelper( rFormat ),
     265           0 :     mpFormat(new ScDataBarFormatData)
     266             : {
     267           0 :     mpFormat->meAxisPosition = databar::NONE;
     268           0 : }
     269             : 
     270           0 : void DataBarRule::importColor( const AttributeList& rAttribs )
     271             : {
     272           0 :     sal_Int32 nColor = 0;
     273           0 :     if( rAttribs.hasAttribute( XML_rgb ) )
     274           0 :         nColor = rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT );
     275           0 :     else if( rAttribs.hasAttribute( XML_theme ) )
     276             :     {
     277           0 :         sal_uInt32 nThemeIndex = rAttribs.getUnsigned( XML_theme, 0 );
     278           0 :         nColor = getTheme().getColorByToken( nThemeIndex );
     279             :     }
     280             : 
     281           0 :     ::Color aColor = RgbToRgbComponents( nColor );
     282             : 
     283           0 :     mpFormat->maPositiveColor = aColor;
     284           0 : }
     285             : 
     286           0 : void DataBarRule::importCfvo( const AttributeList& rAttribs )
     287             : {
     288             :     ColorScaleRuleModelEntry* pEntry;
     289           0 :     if(!mpLowerLimit)
     290             :     {
     291           0 :         mpLowerLimit.reset(new ColorScaleRuleModelEntry);
     292           0 :         pEntry = mpLowerLimit.get();
     293             :     }
     294             :     else
     295             :     {
     296           0 :         mpUpperLimit.reset(new ColorScaleRuleModelEntry);
     297           0 :         pEntry = mpUpperLimit.get();
     298             :     }
     299             : 
     300           0 :     SetCfvoData( pEntry, rAttribs );
     301           0 : }
     302             : 
     303           0 : void DataBarRule::importAttribs( const AttributeList& rAttribs )
     304             : {
     305           0 :     mpFormat->mbOnlyBar = !rAttribs.getBool( XML_showValue, true );
     306           0 : }
     307             : 
     308           0 : void DataBarRule::SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr )
     309             : {
     310           0 :     ScColorScaleEntry* pUpperEntry = ConvertToModel( *mpUpperLimit.get(), pDoc, rAddr);
     311           0 :     ScColorScaleEntry* pLowerEntry = ConvertToModel( *mpLowerLimit.get(), pDoc, rAddr);
     312             : 
     313           0 :     mpFormat->mpUpperLimit.reset( pUpperEntry );
     314           0 :     mpFormat->mpLowerLimit.reset( pLowerEntry );
     315           0 :     pFormat->SetDataBarData(mpFormat);
     316           0 : }
     317             : 
     318             : // ============================================================================
     319             : 
     320           0 : IconSetRule::IconSetRule( const CondFormat& rFormat ):
     321             :     WorksheetHelper( rFormat ),
     322           0 :     mpFormatData( new ScIconSetFormatData )
     323             : {
     324           0 : }
     325             : 
     326           0 : void IconSetRule::importCfvo( const AttributeList& rAttribs )
     327             : {
     328           0 :     ColorScaleRuleModelEntry aNewEntry;
     329           0 :     SetCfvoData(&aNewEntry, rAttribs);
     330             : 
     331           0 :     maEntries.push_back(aNewEntry);
     332           0 : }
     333             : 
     334           0 : void IconSetRule::importAttribs( const AttributeList& rAttribs )
     335             : {
     336           0 :     maIconSetType = rAttribs.getString( XML_iconSet, rtl::OUString("3TrafficLights1") );
     337           0 : }
     338             : 
     339           0 : void IconSetRule::SetData( ScIconSetFormat* pFormat, ScDocument* pDoc, const ScAddress& rPos )
     340             : {
     341           0 :     for(size_t i = 0; i < maEntries.size(); ++i)
     342             :     {
     343           0 :         ScColorScaleEntry* pModelEntry = ConvertToModel( maEntries[i], pDoc, rPos );
     344           0 :         mpFormatData->maEntries.push_back(pModelEntry);
     345             :     }
     346             : 
     347           0 :     ScIconSetType eIconSetType = IconSet_3TrafficLights1;
     348           0 :     ScIconSetMap* pIconSetMap = ScIconSetFormat::getIconSetMap();
     349           0 :     for(size_t i = 0; pIconSetMap[i].pName; ++i)
     350             :     {
     351           0 :         if(rtl::OUString::createFromAscii(pIconSetMap[i].pName) == maIconSetType)
     352             :         {
     353           0 :             eIconSetType = pIconSetMap[i].eType;
     354           0 :             break;
     355             :         }
     356             :     }
     357           0 :     mpFormatData->eIconSetType = eIconSetType;
     358           0 :     pFormat->SetIconSetData(mpFormatData);
     359           0 : }
     360             : 
     361             : // ============================================================================
     362             : 
     363          36 : CondFormatRuleModel::CondFormatRuleModel() :
     364             :     mnPriority( -1 ),
     365             :     mnType( XML_TOKEN_INVALID ),
     366             :     mnOperator( XML_TOKEN_INVALID ),
     367             :     mnTimePeriod( XML_TOKEN_INVALID ),
     368             :     mnRank( 0 ),
     369             :     mnStdDev( 0 ),
     370             :     mnDxfId( -1 ),
     371             :     mbStopIfTrue( false ),
     372             :     mbBottom( false ),
     373             :     mbPercent( false ),
     374             :     mbAboveAverage( true ),
     375          36 :     mbEqualAverage( false )
     376             : {
     377          36 : }
     378             : 
     379           0 : void CondFormatRuleModel::setBiffOperator( sal_Int32 nOperator )
     380             : {
     381             :     static const sal_Int32 spnOperators[] = {
     382             :         XML_TOKEN_INVALID, XML_between, XML_notBetween, XML_equal, XML_notEqual,
     383             :         XML_greaterThan, XML_lessThan, XML_greaterThanOrEqual, XML_lessThanOrEqual };
     384           0 :     mnOperator = STATIC_ARRAY_SELECT( spnOperators, nOperator, XML_TOKEN_INVALID );
     385           0 : }
     386             : 
     387           0 : void CondFormatRuleModel::setBiff12TextType( sal_Int32 nOperator )
     388             : {
     389             :     // note: type XML_notContainsText vs. operator XML_notContains
     390             :     static const sal_Int32 spnTypes[] = { XML_containsText, XML_notContainsText, XML_beginsWith, XML_endsWith };
     391           0 :     mnType = STATIC_ARRAY_SELECT( spnTypes, nOperator, XML_TOKEN_INVALID );
     392             :     static const sal_Int32 spnOperators[] = { XML_containsText, XML_notContains, XML_beginsWith, XML_endsWith };
     393           0 :     mnOperator = STATIC_ARRAY_SELECT( spnOperators, nOperator, XML_TOKEN_INVALID );
     394           0 : }
     395             : 
     396             : // ============================================================================
     397             : 
     398          36 : CondFormatRule::CondFormatRule( const CondFormat& rCondFormat, ScConditionalFormat* pFormat ) :
     399             :     WorksheetHelper( rCondFormat ),
     400             :     mrCondFormat( rCondFormat ),
     401          36 :     mpFormat(pFormat)
     402             : {
     403          36 : }
     404             : 
     405          36 : void CondFormatRule::importCfRule( const AttributeList& rAttribs )
     406             : {
     407          36 :     maModel.maText         = rAttribs.getString( XML_text, OUString() );
     408          36 :     maModel.mnPriority     = rAttribs.getInteger( XML_priority, -1 );
     409          36 :     maModel.mnType         = rAttribs.getToken( XML_type, XML_TOKEN_INVALID );
     410          36 :     maModel.mnOperator     = rAttribs.getToken( XML_operator, XML_TOKEN_INVALID );
     411          36 :     maModel.mnTimePeriod   = rAttribs.getToken( XML_timePeriod, XML_TOKEN_INVALID );
     412          36 :     maModel.mnRank         = rAttribs.getInteger( XML_rank, 0 );
     413          36 :     maModel.mnStdDev       = rAttribs.getInteger( XML_stdDev, 0 );
     414          36 :     maModel.mnDxfId        = rAttribs.getInteger( XML_dxfId, -1 );
     415          36 :     maModel.mbStopIfTrue   = rAttribs.getBool( XML_stopIfTrue, false );
     416          36 :     maModel.mbBottom       = rAttribs.getBool( XML_bottom, false );
     417          36 :     maModel.mbPercent      = rAttribs.getBool( XML_percent, false );
     418          36 :     maModel.mbAboveAverage = rAttribs.getBool( XML_aboveAverage, true );
     419          36 :     maModel.mbEqualAverage = rAttribs.getBool( XML_equalAverage, false );
     420             : 
     421          36 :     if(maModel.mnType == XML_colorScale)
     422             :     {
     423             :         //import the remaining values
     424             : 
     425             :     }
     426          36 : }
     427             : 
     428          19 : void CondFormatRule::appendFormula( const OUString& rFormula )
     429             : {
     430          19 :     CellAddress aBaseAddr = mrCondFormat.getRanges().getBaseAddress();
     431          19 :     ApiTokenSequence aTokens = getFormulaParser().importFormula( aBaseAddr, rFormula );
     432          19 :     maModel.maFormulas.push_back( aTokens );
     433          19 : }
     434             : 
     435           0 : void CondFormatRule::importCfRule( SequenceInputStream& rStrm )
     436             : {
     437             :     sal_Int32 nType, nSubType, nOperator, nFmla1Size, nFmla2Size, nFmla3Size;
     438             :     sal_uInt16 nFlags;
     439           0 :     rStrm >> nType >> nSubType >> maModel.mnDxfId >> maModel.mnPriority >> nOperator;
     440           0 :     rStrm.skip( 8 );
     441           0 :     rStrm >> nFlags >> nFmla1Size >> nFmla2Size >> nFmla3Size >> maModel.maText;
     442             : 
     443             :     /*  Import the formulas. For no obvious reason, the sizes of the formulas
     444             :         are already stored before. Nevertheless the following formulas contain
     445             :         their own sizes. */
     446             : 
     447             :     // first formula
     448             :     OSL_ENSURE( (nFmla1Size >= 0) || ((nFmla2Size == 0) && (nFmla3Size == 0)), "CondFormatRule::importCfRule - missing first formula" );
     449             :     OSL_ENSURE( (nFmla1Size > 0) == (rStrm.getRemaining() >= 8), "CondFormatRule::importCfRule - formula size mismatch" );
     450           0 :     if( rStrm.getRemaining() >= 8 )
     451             :     {
     452           0 :         CellAddress aBaseAddr = mrCondFormat.getRanges().getBaseAddress();
     453           0 :         ApiTokenSequence aTokens = getFormulaParser().importFormula( aBaseAddr, FORMULATYPE_CONDFORMAT, rStrm );
     454           0 :         maModel.maFormulas.push_back( aTokens );
     455             : 
     456             :         // second formula
     457             :         OSL_ENSURE( (nFmla2Size >= 0) || (nFmla3Size == 0), "CondFormatRule::importCfRule - missing second formula" );
     458             :         OSL_ENSURE( (nFmla2Size > 0) == (rStrm.getRemaining() >= 8), "CondFormatRule::importCfRule - formula size mismatch" );
     459           0 :         if( rStrm.getRemaining() >= 8 )
     460             :         {
     461           0 :             aTokens = getFormulaParser().importFormula( aBaseAddr, FORMULATYPE_CONDFORMAT, rStrm );
     462           0 :             maModel.maFormulas.push_back( aTokens );
     463             : 
     464             :             // third formula
     465             :             OSL_ENSURE( (nFmla3Size > 0) == (rStrm.getRemaining() >= 8), "CondFormatRule::importCfRule - formula size mismatch" );
     466           0 :             if( rStrm.getRemaining() >= 8 )
     467             :             {
     468           0 :                 aTokens = getFormulaParser().importFormula( aBaseAddr, FORMULATYPE_CONDFORMAT, rStrm );
     469           0 :                 maModel.maFormulas.push_back( aTokens );
     470             :             }
     471           0 :         }
     472             :     }
     473             : 
     474             :     // flags
     475           0 :     maModel.mbStopIfTrue   = getFlag( nFlags, BIFF12_CFRULE_STOPIFTRUE );
     476           0 :     maModel.mbBottom       = getFlag( nFlags, BIFF12_CFRULE_BOTTOM );
     477           0 :     maModel.mbPercent      = getFlag( nFlags, BIFF12_CFRULE_PERCENT );
     478           0 :     maModel.mbAboveAverage = getFlag( nFlags, BIFF12_CFRULE_ABOVEAVERAGE );
     479             :     // no flag for equalAverage, must be determined from subtype below...
     480             : 
     481             :     // Convert the type/operator settings. This is a real mess...
     482           0 :     switch( nType )
     483             :     {
     484             :         case BIFF12_CFRULE_TYPE_CELLIS:
     485             :             OSL_ENSURE( nSubType == BIFF12_CFRULE_SUB_CELLIS, "CondFormatRule::importCfRule - rule type/subtype mismatch" );
     486           0 :             maModel.mnType = XML_cellIs;
     487           0 :             maModel.setBiffOperator( nOperator );
     488             :             OSL_ENSURE( maModel.mnOperator != XML_TOKEN_INVALID, "CondFormatRule::importCfRule - unknown operator" );
     489           0 :         break;
     490             :         case BIFF12_CFRULE_TYPE_EXPRESSION:
     491             :             // here we have to look at the subtype to find the real type...
     492           0 :             switch( nSubType )
     493             :             {
     494             :                 case BIFF12_CFRULE_SUB_EXPRESSION:
     495             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     496           0 :                     maModel.mnType = XML_expression;
     497           0 :                 break;
     498             :                 case BIFF12_CFRULE_SUB_UNIQUE:
     499             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     500           0 :                     maModel.mnType = XML_uniqueValues;
     501           0 :                 break;
     502             :                 case BIFF12_CFRULE_SUB_TEXT:
     503           0 :                     maModel.setBiff12TextType( nOperator );
     504             :                     OSL_ENSURE( maModel.mnType != XML_TOKEN_INVALID, "CondFormatRule::importCfRule - unexpected operator value" );
     505           0 :                 break;
     506             :                 case BIFF12_CFRULE_SUB_BLANK:
     507             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     508           0 :                     maModel.mnType = XML_containsBlanks;
     509           0 :                 break;
     510             :                 case BIFF12_CFRULE_SUB_NOTBLANK:
     511             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     512           0 :                     maModel.mnType = XML_notContainsBlanks;
     513           0 :                 break;
     514             :                 case BIFF12_CFRULE_SUB_ERROR:
     515             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     516           0 :                     maModel.mnType = XML_containsErrors;
     517           0 :                 break;
     518             :                 case BIFF12_CFRULE_SUB_NOTERROR:
     519             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     520           0 :                     maModel.mnType = XML_notContainsErrors;
     521           0 :                 break;
     522             :                 case BIFF12_CFRULE_SUB_TODAY:
     523             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_TODAY, "CondFormatRule::importCfRule - unexpected time operator value" );
     524           0 :                     maModel.mnType = XML_timePeriod;
     525           0 :                     maModel.mnTimePeriod = XML_today;
     526           0 :                 break;
     527             :                 case BIFF12_CFRULE_SUB_TOMORROW:
     528             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_TOMORROW, "CondFormatRule::importCfRule - unexpected time operator value" );
     529           0 :                     maModel.mnType = XML_timePeriod;
     530           0 :                     maModel.mnTimePeriod = XML_tomorrow;
     531           0 :                 break;
     532             :                 case BIFF12_CFRULE_SUB_YESTERDAY:
     533             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_YESTERDAY, "CondFormatRule::importCfRule - unexpected time operator value" );
     534           0 :                     maModel.mnType = XML_timePeriod;
     535           0 :                     maModel.mnTimePeriod = XML_yesterday;
     536           0 :                 break;
     537             :                 case BIFF12_CFRULE_SUB_LAST7DAYS:
     538             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_LAST7DAYS, "CondFormatRule::importCfRule - unexpected time operator value" );
     539           0 :                     maModel.mnType = XML_timePeriod;
     540           0 :                     maModel.mnTimePeriod = XML_last7Days;
     541           0 :                 break;
     542             :                 case BIFF12_CFRULE_SUB_LASTMONTH:
     543             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_LASTMONTH, "CondFormatRule::importCfRule - unexpected time operator value" );
     544           0 :                     maModel.mnType = XML_timePeriod;
     545           0 :                     maModel.mnTimePeriod = XML_lastMonth;
     546           0 :                 break;
     547             :                 case BIFF12_CFRULE_SUB_NEXTMONTH:
     548             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_NEXTMONTH, "CondFormatRule::importCfRule - unexpected time operator value" );
     549           0 :                     maModel.mnType = XML_timePeriod;
     550           0 :                     maModel.mnTimePeriod = XML_nextMonth;
     551           0 :                 break;
     552             :                 case BIFF12_CFRULE_SUB_THISWEEK:
     553             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_THISWEEK, "CondFormatRule::importCfRule - unexpected time operator value" );
     554           0 :                     maModel.mnType = XML_timePeriod;
     555           0 :                     maModel.mnTimePeriod = XML_thisWeek;
     556           0 :                 break;
     557             :                 case BIFF12_CFRULE_SUB_NEXTWEEK:
     558             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_NEXTWEEK, "CondFormatRule::importCfRule - unexpected time operator value" );
     559           0 :                     maModel.mnType = XML_timePeriod;
     560           0 :                     maModel.mnTimePeriod = XML_nextWeek;
     561           0 :                 break;
     562             :                 case BIFF12_CFRULE_SUB_LASTWEEK:
     563             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_LASTWEEK, "CondFormatRule::importCfRule - unexpected time operator value" );
     564           0 :                     maModel.mnType = XML_timePeriod;
     565           0 :                     maModel.mnTimePeriod = XML_lastWeek;
     566           0 :                 break;
     567             :                 case BIFF12_CFRULE_SUB_THISMONTH:
     568             :                     OSL_ENSURE( nOperator == BIFF12_CFRULE_TIMEOP_THISMONTH, "CondFormatRule::importCfRule - unexpected time operator value" );
     569           0 :                     maModel.mnType = XML_timePeriod;
     570           0 :                     maModel.mnTimePeriod = XML_thisMonth;
     571           0 :                 break;
     572             :                 case BIFF12_CFRULE_SUB_ABOVEAVERAGE:
     573             :                     OSL_ENSURE( maModel.mbAboveAverage, "CondFormatRule::importCfRule - wrong above-average flag" );
     574           0 :                     maModel.mnType = XML_aboveAverage;
     575           0 :                     maModel.mnStdDev = nOperator;     // operator field used for standard deviation
     576           0 :                     maModel.mbAboveAverage = true;
     577           0 :                     maModel.mbEqualAverage = false;   // does not exist as real flag...
     578           0 :                 break;
     579             :                 case BIFF12_CFRULE_SUB_BELOWAVERAGE:
     580             :                     OSL_ENSURE( !maModel.mbAboveAverage, "CondFormatRule::importCfRule - wrong above-average flag" );
     581           0 :                     maModel.mnType = XML_aboveAverage;
     582           0 :                     maModel.mnStdDev = nOperator;     // operator field used for standard deviation
     583           0 :                     maModel.mbAboveAverage = false;
     584           0 :                     maModel.mbEqualAverage = false;   // does not exist as real flag...
     585           0 :                 break;
     586             :                 case BIFF12_CFRULE_SUB_DUPLICATE:
     587             :                     OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     588           0 :                     maModel.mnType = XML_duplicateValues;
     589           0 :                 break;
     590             :                 case BIFF12_CFRULE_SUB_EQABOVEAVERAGE:
     591             :                     OSL_ENSURE( maModel.mbAboveAverage, "CondFormatRule::importCfRule - wrong above-average flag" );
     592           0 :                     maModel.mnType = XML_aboveAverage;
     593           0 :                     maModel.mnStdDev = nOperator;     // operator field used for standard deviation
     594           0 :                     maModel.mbAboveAverage = true;
     595           0 :                     maModel.mbEqualAverage = true;    // does not exist as real flag...
     596           0 :                 break;
     597             :                 case BIFF12_CFRULE_SUB_EQBELOWAVERAGE:
     598             :                     OSL_ENSURE( !maModel.mbAboveAverage, "CondFormatRule::importCfRule - wrong above-average flag" );
     599           0 :                     maModel.mnType = XML_aboveAverage;
     600           0 :                     maModel.mnStdDev = nOperator;     // operator field used for standard deviation
     601           0 :                     maModel.mbAboveAverage = false;
     602           0 :                     maModel.mbEqualAverage = true;    // does not exist as real flag...
     603           0 :                 break;
     604             :             }
     605           0 :         break;
     606             :         case BIFF12_CFRULE_TYPE_COLORSCALE:
     607             :             OSL_ENSURE( nSubType == BIFF12_CFRULE_SUB_COLORSCALE, "CondFormatRule::importCfRule - rule type/subtype mismatch" );
     608             :             OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     609           0 :             maModel.mnType = XML_colorScale;
     610           0 :         break;
     611             :         case BIFF12_CFRULE_TYPE_DATABAR:
     612             :             OSL_ENSURE( nSubType == BIFF12_CFRULE_SUB_DATABAR, "CondFormatRule::importCfRule - rule type/subtype mismatch" );
     613             :             OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     614           0 :             maModel.mnType = XML_dataBar;
     615           0 :         break;
     616             :         case BIFF12_CFRULE_TYPE_TOPTEN:
     617             :             OSL_ENSURE( nSubType == BIFF12_CFRULE_SUB_TOPTEN, "CondFormatRule::importCfRule - rule type/subtype mismatch" );
     618           0 :             maModel.mnType = XML_top10;
     619           0 :             maModel.mnRank = nOperator;   // operator field used for rank value
     620           0 :         break;
     621             :         case BIFF12_CFRULE_TYPE_ICONSET:
     622             :             OSL_ENSURE( nSubType == BIFF12_CFRULE_SUB_ICONSET, "CondFormatRule::importCfRule - rule type/subtype mismatch" );
     623             :             OSL_ENSURE( nOperator == 0, "CondFormatRule::importCfRule - unexpected operator value" );
     624           0 :             maModel.mnType = XML_iconSet;
     625           0 :         break;
     626             :         default:
     627             :             OSL_FAIL( "CondFormatRule::importCfRule - unknown rule type" );
     628             :     }
     629           0 : }
     630             : 
     631          36 : void CondFormatRule::finalizeImport()
     632             : {
     633          36 :     ScConditionMode eOperator = SC_COND_NONE;
     634             : 
     635             :     /*  Replacement formula for unsupported rule types (text comparison rules,
     636             :         time period rules, cell type rules). The replacement formulas below may
     637             :         contain several placeholders:
     638             :         - '#B' will be replaced by the current relative base address (may occur
     639             :             several times).
     640             :         - '#R' will be replaced by the entire range list of the conditional
     641             :             formatting (absolute addresses).
     642             :         - '#T' will be replaced by the quoted comparison text.
     643             :         - '#L' will be replaced by the length of the comparison text (from
     644             :             the 'text' attribute) used in text comparison rules.
     645             :         - '#K' will be replaced by the rank (from the 'rank' attribute) used in
     646             :             top-10 rules.
     647             :         - '#M' will be replaced by the top/bottom flag (from the 'bottom'
     648             :             attribute) used in the RANK function in top-10 rules.
     649             :         - '#C' will be replaced by one of the comparison operators <, >, <=, or
     650             :             >=, according to the 'aboveAverage' and 'equalAverage' flags.
     651             :      */
     652          36 :     OUString aReplaceFormula;
     653             : 
     654          36 :     switch( maModel.mnType )
     655             :     {
     656             :         case XML_cellIs:
     657          10 :             eOperator = static_cast<ScConditionMode>(CondFormatBuffer::convertToInternalOperator( maModel.mnOperator ));
     658          10 :         break;
     659             :         case XML_duplicateValues:
     660           0 :             eOperator = SC_COND_DUPLICATE;
     661           0 :         break;
     662             :         case XML_uniqueValues:
     663           0 :             eOperator = SC_COND_NOTDUPLICATE;
     664           0 :         break;
     665             :         case XML_expression:
     666           2 :             eOperator = SC_COND_DIRECT;
     667           2 :         break;
     668             :         case XML_containsText:
     669             :             OSL_ENSURE( maModel.mnOperator == XML_containsText, "CondFormatRule::finalizeImport - unexpected operator" );
     670           0 :             eOperator = SC_COND_CONTAINS_TEXT;
     671           0 :         break;
     672             :         case XML_notContainsText:
     673             :             // note: type XML_notContainsText vs. operator XML_notContains
     674             :             OSL_ENSURE( maModel.mnOperator == XML_notContains, "CondFormatRule::finalizeImport - unexpected operator" );
     675           0 :             eOperator = SC_COND_NOT_CONTAINS_TEXT;
     676           0 :         break;
     677             :         case XML_beginsWith:
     678             :             OSL_ENSURE( maModel.mnOperator == XML_beginsWith, "CondFormatRule::finalizeImport - unexpected operator" );
     679           0 :             eOperator = SC_COND_BEGINS_WITH;
     680           0 :         break;
     681             :         case XML_endsWith:
     682             :             OSL_ENSURE( maModel.mnOperator == XML_endsWith, "CondFormatRule::finalizeImport - unexpected operator" );
     683           0 :             eOperator = SC_COND_ENDS_WITH;
     684           0 :         break;
     685             :         case XML_timePeriod:
     686           0 :         break;
     687             :         case XML_containsBlanks:
     688           0 :             aReplaceFormula = "LEN(TRIM(#B))=0";
     689           0 :         break;
     690             :         case XML_notContainsBlanks:
     691           0 :             aReplaceFormula = "LEN(TRIM(#B))>0";
     692           0 :         break;
     693             :         case XML_containsErrors:
     694           0 :             eOperator = SC_COND_ERROR;
     695           0 :         break;
     696             :         case XML_notContainsErrors:
     697           0 :             eOperator = SC_COND_NOERROR;
     698           0 :         break;
     699             :         case XML_top10:
     700          12 :             if(maModel.mbPercent)
     701             :             {
     702           6 :                 if(maModel.mbBottom)
     703           3 :                     eOperator = SC_COND_BOTTOM_PERCENT;
     704             :                 else
     705           3 :                     eOperator = SC_COND_TOP_PERCENT;
     706             :             }
     707             :             else
     708             :             {
     709           6 :                 if(maModel.mbBottom)
     710           3 :                     eOperator = SC_COND_BOTTOM10;
     711             :                 else
     712           3 :                     eOperator = SC_COND_TOP10;
     713             :             }
     714          12 :         break;
     715             :         case XML_aboveAverage:
     716          12 :             if(maModel.mbAboveAverage)
     717           6 :                 eOperator = SC_COND_ABOVE_AVERAGE;
     718             :             else
     719           6 :                 eOperator = SC_COND_BELOW_AVERAGE;
     720          12 :         break;
     721             :         case XML_colorScale:
     722           0 :         break;
     723             :     }
     724             : 
     725          36 :     if( !aReplaceFormula.isEmpty() )
     726             :     {
     727           0 :         OUString aAddress, aRanges, aText, aComp;
     728           0 :         sal_Int32 nStrPos = aReplaceFormula.getLength();
     729           0 :         while( (nStrPos = aReplaceFormula.lastIndexOf( '#', nStrPos )) >= 0 )
     730             :         {
     731           0 :             switch( aReplaceFormula[ nStrPos + 1 ] )
     732             :             {
     733             :                 case 'B':       // current base address
     734           0 :                     if( aAddress.isEmpty() )
     735           0 :                         aAddress = FormulaProcessorBase::generateAddress2dString( mrCondFormat.getRanges().getBaseAddress(), false );
     736           0 :                     aReplaceFormula = aReplaceFormula.replaceAt( nStrPos, 2, aAddress );
     737           0 :                 break;
     738             :                 default:
     739             :                     OSL_FAIL( "CondFormatRule::finalizeImport - unknown placeholder" );
     740             :             }
     741             :         }
     742             : 
     743             :         // set the replacement formula
     744           0 :         maModel.maFormulas.clear();
     745           0 :         appendFormula( aReplaceFormula );
     746           0 :         eOperator = SC_COND_DIRECT;
     747             :     }
     748             : 
     749          36 :     CellAddress aBaseAddr = mrCondFormat.getRanges().getBaseAddress();
     750          36 :     ScAddress aPos;
     751          36 :     ScUnoConversion::FillScAddress( aPos, aBaseAddr );
     752             : 
     753          36 :     if( eOperator == SC_COND_ERROR || eOperator == SC_COND_NOERROR )
     754             :     {
     755           0 :         ScDocument& rDoc = getScDocument();
     756           0 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     757           0 :         ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, NULL, NULL, &rDoc, aPos, aStyleName );
     758           0 :         mpFormat->AddEntry(pNewEntry);
     759             :     }
     760          36 :     else if( eOperator == SC_COND_BEGINS_WITH || eOperator == SC_COND_ENDS_WITH ||
     761             :             eOperator == SC_COND_CONTAINS_TEXT || eOperator == SC_COND_NOT_CONTAINS_TEXT )
     762             :     {
     763           0 :         ScDocument& rDoc = getScDocument();
     764           0 :         ScTokenArray aTokenArray;
     765           0 :         aTokenArray.AddString(maModel.maText);
     766           0 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     767           0 :         ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, &aTokenArray, NULL, &rDoc, aPos, aStyleName );
     768           0 :         mpFormat->AddEntry(pNewEntry);
     769             :     }
     770          36 :     else if( (eOperator != SC_COND_NONE) && !maModel.maFormulas.empty() )
     771             :     {
     772          16 :         ScDocument& rDoc = getScDocument();
     773          16 :         boost::scoped_ptr<ScTokenArray> pTokenArray2;
     774          16 :         if( maModel.maFormulas.size() >= 2)
     775             :         {
     776           3 :             pTokenArray2.reset(new ScTokenArray());
     777           3 :             ScTokenConversion::ConvertToTokenArray( rDoc, *pTokenArray2.get(), maModel.maFormulas[ 1 ] );
     778             :         }
     779             : 
     780          16 :         ScTokenArray aTokenArray;
     781          16 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     782          16 :         ScTokenConversion::ConvertToTokenArray( rDoc, aTokenArray, maModel.maFormulas[ 0 ] );
     783             :         ScCondFormatEntry* pNewEntry = new ScCondFormatEntry(eOperator,
     784          16 :                                             &aTokenArray, pTokenArray2.get(), &rDoc, aPos, aStyleName);
     785          16 :         mpFormat->AddEntry(pNewEntry);
     786             :     }
     787          20 :     else if ( eOperator == SC_COND_TOP10 || eOperator == SC_COND_BOTTOM10 ||
     788             :             eOperator == SC_COND_TOP_PERCENT || eOperator == SC_COND_BOTTOM_PERCENT )
     789             :     {
     790          12 :         ScDocument& rDoc = getScDocument();
     791          12 :         ScTokenArray aTokenArray;
     792          12 :         aTokenArray.AddDouble( maModel.mnRank );
     793          12 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     794          12 :         ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, &aTokenArray, NULL, &rDoc, aPos, aStyleName );
     795          12 :         mpFormat->AddEntry(pNewEntry);
     796             :     }
     797           8 :     else if( eOperator == SC_COND_ABOVE_AVERAGE || eOperator == SC_COND_BELOW_AVERAGE )
     798             :     {
     799           8 :         ScDocument& rDoc = getScDocument();
     800           8 :         ScTokenArray aTokenArrayEqual;
     801           8 :         aTokenArrayEqual.AddDouble( maModel.mbEqualAverage );
     802           8 :         ScTokenArray aTokenArrayDev;
     803           8 :         aTokenArrayDev.AddDouble( maModel.mnStdDev );
     804           8 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     805           8 :         ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, &aTokenArrayEqual, &aTokenArrayDev, &rDoc, aPos, aStyleName );
     806           8 :         mpFormat->AddEntry(pNewEntry);
     807             :     }
     808           0 :     else if( eOperator == SC_COND_DUPLICATE || eOperator == SC_COND_NOTDUPLICATE )
     809             :     {
     810           0 :         ScDocument& rDoc = getScDocument();
     811           0 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     812           0 :         ScCondFormatEntry* pNewEntry = new ScCondFormatEntry( eOperator, NULL, NULL, &rDoc, aPos, aStyleName );
     813           0 :         mpFormat->AddEntry(pNewEntry);
     814             :     }
     815           0 :     else if( maModel.mnType == XML_timePeriod )
     816             :     {
     817           0 :         condformat::ScCondFormatDateType eDateType = condformat::TODAY;
     818           0 :         switch( maModel.mnTimePeriod )
     819             :         {
     820             :             case XML_yesterday:
     821           0 :                 eDateType = condformat::YESTERDAY;
     822           0 :                 break;
     823             :             case XML_today:
     824           0 :                 eDateType = condformat::TODAY;
     825           0 :                 break;
     826             :             case XML_tomorrow:
     827           0 :                 eDateType = condformat::TOMORROW;
     828           0 :                 break;
     829             :             case XML_last7Days:
     830           0 :                 eDateType = condformat::LAST7DAYS;
     831           0 :                 break;
     832             :             case XML_lastWeek:
     833           0 :                 eDateType = condformat::LASTWEEK;
     834           0 :                 break;
     835             :             case XML_thisWeek:
     836           0 :                 eDateType = condformat::THISWEEK;
     837           0 :                 break;
     838             :             case XML_nextWeek:
     839           0 :                 eDateType = condformat::NEXTWEEK;
     840           0 :                 break;
     841             :             case XML_lastMonth:
     842           0 :                 eDateType = condformat::LASTMONTH;
     843           0 :                 break;
     844             :             case XML_thisMonth:
     845           0 :                 eDateType = condformat::THISMONTH;
     846           0 :                 break;
     847             :             case XML_nextMonth:
     848           0 :                 eDateType = condformat::NEXTMONTH;
     849           0 :                 break;
     850             :             default:
     851             :                 SAL_WARN("sc", "CondFormatRule::finalizeImport - unknown time period type" );
     852             :         }
     853             : 
     854           0 :         ScDocument& rDoc = getScDocument();
     855           0 :         ScCondDateFormatEntry* pFormatEntry = new ScCondDateFormatEntry(&rDoc);
     856           0 :         pFormatEntry->SetDateType(eDateType);
     857           0 :         OUString aStyleName = getStyles().createDxfStyle( maModel.mnDxfId );
     858           0 :         pFormatEntry->SetStyleName( aStyleName );
     859             : 
     860           0 :         mpFormat->AddEntry(pFormatEntry);
     861             :     }
     862           0 :     else if( mpColor )
     863             :     {
     864           0 :         ScDocument& rDoc = getScDocument();
     865           0 :         ScColorScaleFormat* pFormatEntry = new ScColorScaleFormat(&rDoc);
     866             : 
     867           0 :         mpFormat->AddEntry(pFormatEntry);
     868             : 
     869           0 :         mpColor->AddEntries( pFormatEntry, &rDoc, aPos );
     870             :     }
     871           0 :     else if (mpDataBar)
     872             :     {
     873           0 :         ScDocument& rDoc = getScDocument();
     874           0 :         ScDataBarFormat* pFormatEntry = new ScDataBarFormat(&rDoc);
     875             : 
     876           0 :         mpFormat->AddEntry(pFormatEntry);
     877           0 :         mpDataBar->SetData( pFormatEntry, &rDoc, aPos );
     878             : 
     879             :     }
     880           0 :     else if(mpIconSet)
     881             :     {
     882           0 :         ScDocument& rDoc = getScDocument();
     883           0 :         ScIconSetFormat* pFormatEntry = new ScIconSetFormat(&rDoc);
     884             : 
     885           0 :         mpFormat->AddEntry(pFormatEntry);
     886           0 :         mpIconSet->SetData( pFormatEntry, &rDoc, aPos );
     887          36 :     }
     888          36 : }
     889             : 
     890           0 : ColorScaleRule* CondFormatRule::getColorScale()
     891             : {
     892           0 :     if(!mpColor)
     893           0 :         mpColor.reset( new ColorScaleRule(mrCondFormat) );
     894             : 
     895           0 :     return mpColor.get();
     896             : }
     897             : 
     898           0 : DataBarRule* CondFormatRule::getDataBar()
     899             : {
     900           0 :     if(!mpDataBar)
     901           0 :         mpDataBar.reset( new DataBarRule(mrCondFormat) );
     902             : 
     903           0 :     return mpDataBar.get();
     904             : }
     905             : 
     906           0 : IconSetRule* CondFormatRule::getIconSet()
     907             : {
     908           0 :     if(!mpIconSet)
     909           0 :         mpIconSet.reset( new IconSetRule(mrCondFormat) );
     910             : 
     911           0 :     return mpIconSet.get();
     912             : }
     913             : 
     914             : // ============================================================================
     915             : 
     916          28 : CondFormatModel::CondFormatModel() :
     917          28 :     mbPivot( false )
     918             : {
     919          28 : }
     920             : 
     921             : // ============================================================================
     922             : 
     923          28 : CondFormat::CondFormat( const WorksheetHelper& rHelper ) :
     924             :     WorksheetHelper( rHelper ),
     925          28 :     mpFormat(NULL)
     926             : {
     927          28 : }
     928             : 
     929          28 : void CondFormat::importConditionalFormatting( const AttributeList& rAttribs )
     930             : {
     931          28 :     getAddressConverter().convertToCellRangeList( maModel.maRanges, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), true );
     932          28 :     maModel.mbPivot = rAttribs.getBool( XML_pivot, false );
     933          28 :     mpFormat = new ScConditionalFormat(0, &getScDocument());
     934          28 : }
     935             : 
     936          36 : CondFormatRuleRef CondFormat::importCfRule( const AttributeList& rAttribs )
     937             : {
     938          36 :     CondFormatRuleRef xRule = createRule();
     939          36 :     xRule->importCfRule( rAttribs );
     940          36 :     insertRule( xRule );
     941          36 :     return xRule;
     942             : }
     943             : 
     944           0 : void CondFormat::importCondFormatting( SequenceInputStream& rStrm )
     945             : {
     946           0 :     BinRangeList aRanges;
     947           0 :     rStrm.skip( 8 );
     948           0 :     rStrm >> aRanges;
     949           0 :     getAddressConverter().convertToCellRangeList( maModel.maRanges, aRanges, getSheetIndex(), true );
     950           0 :     mpFormat = new ScConditionalFormat(0, &getScDocument());
     951           0 : }
     952             : 
     953           0 : void CondFormat::importCfRule( SequenceInputStream& rStrm )
     954             : {
     955           0 :     CondFormatRuleRef xRule = createRule();
     956           0 :     xRule->importCfRule( rStrm );
     957           0 :     insertRule( xRule );
     958           0 : }
     959             : 
     960          28 : void CondFormat::finalizeImport()
     961             : {
     962          28 :     ScDocument& rDoc = getScDocument();
     963          28 :     maRules.forEachMem( &CondFormatRule::finalizeImport );
     964          28 :     SCTAB nTab = maModel.maRanges.getBaseAddress().Sheet;
     965          28 :     sal_Int32 nIndex = getScDocument().AddCondFormat(mpFormat, nTab);
     966             : 
     967          28 :     ScRangeList aList;
     968          56 :     for( ApiCellRangeList::const_iterator itr = maModel.maRanges.begin(); itr != maModel.maRanges.end(); ++itr)
     969             :     {
     970          28 :         ScRange aRange;
     971          28 :         ScUnoConversion::FillScRange(aRange, *itr);
     972          28 :         aList.Append(aRange);
     973             :     }
     974          28 :     rDoc.AddCondFormatData( aList, nTab, nIndex );
     975          28 :     mpFormat->AddRange(aList);
     976          28 : }
     977             : 
     978          36 : CondFormatRuleRef CondFormat::createRule()
     979             : {
     980          36 :     return CondFormatRuleRef( new CondFormatRule( *this, mpFormat ) );
     981             : }
     982             : 
     983          36 : void CondFormat::insertRule( CondFormatRuleRef xRule )
     984             : {
     985          36 :     if( xRule.get() && (xRule->getPriority() > 0) )
     986             :     {
     987             :         OSL_ENSURE( maRules.find( xRule->getPriority() ) == maRules.end(), "CondFormat::insertRule - multiple rules with equal priority" );
     988          36 :         maRules[ xRule->getPriority() ] = xRule;
     989             :     }
     990          36 : }
     991             : 
     992             : // ============================================================================
     993             : 
     994          25 : CondFormatBuffer::CondFormatBuffer( const WorksheetHelper& rHelper ) :
     995          25 :     WorksheetHelper( rHelper )
     996             : {
     997          25 : }
     998             : 
     999          28 : CondFormatRef CondFormatBuffer::importConditionalFormatting( const AttributeList& rAttribs )
    1000             : {
    1001          28 :     CondFormatRef xCondFmt = createCondFormat();
    1002          28 :     xCondFmt->importConditionalFormatting( rAttribs );
    1003          28 :     return xCondFmt;
    1004             : }
    1005             : 
    1006           0 : CondFormatRef CondFormatBuffer::importCondFormatting( SequenceInputStream& rStrm )
    1007             : {
    1008           0 :     CondFormatRef xCondFmt = createCondFormat();
    1009           0 :     xCondFmt->importCondFormatting( rStrm );
    1010           0 :     return xCondFmt;
    1011             : }
    1012             : 
    1013           0 : sal_Int32 CondFormatBuffer::convertToApiOperator( sal_Int32 nToken )
    1014             : {
    1015           0 :     switch( nToken )
    1016             :     {
    1017           0 :         case XML_between:               return ConditionOperator2::BETWEEN;
    1018           0 :         case XML_equal:                 return ConditionOperator2::EQUAL;
    1019           0 :         case XML_greaterThan:           return ConditionOperator2::GREATER;
    1020           0 :         case XML_greaterThanOrEqual:    return ConditionOperator2::GREATER_EQUAL;
    1021           0 :         case XML_lessThan:              return ConditionOperator2::LESS;
    1022           0 :         case XML_lessThanOrEqual:       return ConditionOperator2::LESS_EQUAL;
    1023           0 :         case XML_notBetween:            return ConditionOperator2::NOT_BETWEEN;
    1024           0 :         case XML_notEqual:              return ConditionOperator2::NOT_EQUAL;
    1025           0 :         case XML_duplicateValues:       return ConditionOperator2::DUPLICATE;
    1026             :     }
    1027           0 :     return ConditionOperator2::NONE;
    1028             : }
    1029             : 
    1030          10 : sal_Int32 CondFormatBuffer::convertToInternalOperator( sal_Int32 nToken )
    1031             : {
    1032          10 :     switch( nToken )
    1033             :     {
    1034           1 :         case XML_between:               return SC_COND_BETWEEN;
    1035           2 :         case XML_equal:                 return SC_COND_EQUAL;
    1036           2 :         case XML_greaterThan:           return SC_COND_GREATER;
    1037           2 :         case XML_greaterThanOrEqual:    return SC_COND_EQGREATER;
    1038           1 :         case XML_lessThan:              return SC_COND_LESS;
    1039           0 :         case XML_lessThanOrEqual:       return SC_COND_EQLESS;
    1040           2 :         case XML_notBetween:            return SC_COND_NOTBETWEEN;
    1041           0 :         case XML_notEqual:              return SC_COND_NOTEQUAL;
    1042           0 :         case XML_duplicateValues:       return SC_COND_DUPLICATE;
    1043           0 :         case XML_uniqueValues:          return SC_COND_NOTDUPLICATE;
    1044             :     }
    1045           0 :     return ConditionOperator2::NONE;
    1046             : }
    1047             : 
    1048             : // private --------------------------------------------------------------------
    1049             : 
    1050          28 : CondFormatRef CondFormatBuffer::createCondFormat()
    1051             : {
    1052          28 :     CondFormatRef xCondFmt( new CondFormat( *this ) );
    1053          28 :     maCondFormats.push_back( xCondFmt );
    1054          28 :     return xCondFmt;
    1055             : }
    1056             : 
    1057             : // ============================================================================
    1058             : 
    1059             : } // namespace xls
    1060           9 : } // namespace oox
    1061             : 
    1062             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10