1*e3508121SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e3508121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e3508121SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e3508121SAndrew Rist * distributed with this work for additional information 6*e3508121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e3508121SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e3508121SAndrew Rist * "License"); you may not use this file except in compliance 9*e3508121SAndrew Rist * with the License. You may obtain a copy of the License at 10*e3508121SAndrew Rist * 11*e3508121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e3508121SAndrew Rist * 13*e3508121SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e3508121SAndrew Rist * software distributed under the License is distributed on an 15*e3508121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e3508121SAndrew Rist * KIND, either express or implied. See the License for the 17*e3508121SAndrew Rist * specific language governing permissions and limitations 18*e3508121SAndrew Rist * under the License. 19*e3508121SAndrew Rist * 20*e3508121SAndrew Rist *************************************************************/ 21*e3508121SAndrew Rist 22*e3508121SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef OOX_XLS_CONDFORMATBUFFER_HXX 25cdf0e10cSrcweir #define OOX_XLS_CONDFORMATBUFFER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/sheet/ConditionOperator.hpp> 28cdf0e10cSrcweir #include "oox/xls/formulaparser.hxx" 29cdf0e10cSrcweir #include "oox/xls/worksheethelper.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir namespace com { namespace sun { namespace star { 32cdf0e10cSrcweir namespace sheet { class XSheetConditionalEntries; } 33cdf0e10cSrcweir } } } 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace oox { 36cdf0e10cSrcweir namespace xls { 37cdf0e10cSrcweir 38cdf0e10cSrcweir // ============================================================================ 39cdf0e10cSrcweir 40cdf0e10cSrcweir /** Model for a single rule in a conditional formatting. */ 41cdf0e10cSrcweir struct CondFormatRuleModel 42cdf0e10cSrcweir { 43cdf0e10cSrcweir typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector; 44cdf0e10cSrcweir 45cdf0e10cSrcweir ApiTokenSequenceVector maFormulas; /// Formulas for rule conditions. 46cdf0e10cSrcweir ::rtl::OUString maText; /// Text for 'contains' rules. 47cdf0e10cSrcweir sal_Int32 mnPriority; /// Priority of this rule. 48cdf0e10cSrcweir sal_Int32 mnType; /// Type of the rule. 49cdf0e10cSrcweir sal_Int32 mnOperator; /// In cell-is rules: Comparison operator. 50cdf0e10cSrcweir sal_Int32 mnTimePeriod; /// In time-period rules: Type of time period. 51cdf0e10cSrcweir sal_Int32 mnRank; /// In top-10 rules: True = bottom, false = top. 52cdf0e10cSrcweir sal_Int32 mnStdDev; /// In average rules: Number of std deviations. 53cdf0e10cSrcweir sal_Int32 mnDxfId; /// Differential formatting identifier. 54cdf0e10cSrcweir bool mbStopIfTrue; /// True = stop evaluating rules, if this rule is true. 55cdf0e10cSrcweir bool mbBottom; /// In top-10 rules: True = bottom, false = top. 56cdf0e10cSrcweir bool mbPercent; /// In top-10 rules: True = percent, false = rank. 57cdf0e10cSrcweir bool mbAboveAverage; /// In average rules: True = above average, false = below. 58cdf0e10cSrcweir bool mbEqualAverage; /// In average rules: True = include average, false = exclude. 59cdf0e10cSrcweir 60cdf0e10cSrcweir explicit CondFormatRuleModel(); 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** Sets the passed BIFF operator for condition type cellIs. */ 63cdf0e10cSrcweir void setBiffOperator( sal_Int32 nOperator ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Sets the passed BIFF12 text comparison type and operator. */ 66cdf0e10cSrcweir void setBiff12TextType( sal_Int32 nOperator ); 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ============================================================================ 70cdf0e10cSrcweir 71cdf0e10cSrcweir class CondFormat; 72cdf0e10cSrcweir 73cdf0e10cSrcweir /** Represents a single rule in a conditional formatting. */ 74cdf0e10cSrcweir class CondFormatRule : public WorksheetHelper 75cdf0e10cSrcweir { 76cdf0e10cSrcweir public: 77cdf0e10cSrcweir explicit CondFormatRule( const CondFormat& rCondFormat ); 78cdf0e10cSrcweir 79cdf0e10cSrcweir /** Imports rule settings from the cfRule element. */ 80cdf0e10cSrcweir void importCfRule( const AttributeList& rAttribs ); 81cdf0e10cSrcweir /** Appends a new condition formula string. */ 82cdf0e10cSrcweir void appendFormula( const ::rtl::OUString& rFormula ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir /** Imports rule settings from a CFRULE record. */ 85cdf0e10cSrcweir void importCfRule( SequenceInputStream& rStrm ); 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** Imports rule settings from a CFRULE record. */ 88cdf0e10cSrcweir void importCfRule( BiffInputStream& rStrm, sal_Int32 nPriority ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** Creates a conditional formatting rule in the Calc document. */ 91cdf0e10cSrcweir void finalizeImport( 92cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetConditionalEntries >& rxEntries ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** Returns the priority of this rule. */ getPriority() const95cdf0e10cSrcweir inline sal_Int32 getPriority() const { return maModel.mnPriority; } 96cdf0e10cSrcweir 97cdf0e10cSrcweir private: 98cdf0e10cSrcweir const CondFormat& mrCondFormat; 99cdf0e10cSrcweir CondFormatRuleModel maModel; 100cdf0e10cSrcweir }; 101cdf0e10cSrcweir 102cdf0e10cSrcweir typedef ::boost::shared_ptr< CondFormatRule > CondFormatRuleRef; 103cdf0e10cSrcweir 104cdf0e10cSrcweir // ============================================================================ 105cdf0e10cSrcweir 106cdf0e10cSrcweir /** Model for a conditional formatting object. */ 107cdf0e10cSrcweir struct CondFormatModel 108cdf0e10cSrcweir { 109cdf0e10cSrcweir ApiCellRangeList maRanges; /// Cell ranges for this conditional format. 110cdf0e10cSrcweir bool mbPivot; /// Conditional formatting belongs to pivot table. 111cdf0e10cSrcweir 112cdf0e10cSrcweir explicit CondFormatModel(); 113cdf0e10cSrcweir }; 114cdf0e10cSrcweir 115cdf0e10cSrcweir // ============================================================================ 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** Represents a conditional formatting object with a list of affected cell ranges. */ 118cdf0e10cSrcweir class CondFormat : public WorksheetHelper 119cdf0e10cSrcweir { 120cdf0e10cSrcweir public: 121cdf0e10cSrcweir explicit CondFormat( const WorksheetHelper& rHelper ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir /** Imports settings from the conditionalFormatting element. */ 124cdf0e10cSrcweir void importConditionalFormatting( const AttributeList& rAttribs ); 125cdf0e10cSrcweir /** Imports a conditional formatting rule from the cfRule element. */ 126cdf0e10cSrcweir CondFormatRuleRef importCfRule( const AttributeList& rAttribs ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir /** Imports settings from the CONDFORMATTING record. */ 129cdf0e10cSrcweir void importCondFormatting( SequenceInputStream& rStrm ); 130cdf0e10cSrcweir /** Imports a conditional formatting rule from the CFRULE record. */ 131cdf0e10cSrcweir void importCfRule( SequenceInputStream& rStrm ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir /** Imports settings from the CFHEADER record. */ 134cdf0e10cSrcweir void importCfHeader( BiffInputStream& rStrm ); 135cdf0e10cSrcweir 136cdf0e10cSrcweir /** Creates the conditional formatting in the Calc document. */ 137cdf0e10cSrcweir void finalizeImport(); 138cdf0e10cSrcweir 139cdf0e10cSrcweir /** Returns the cell ranges this conditional formatting belongs to. */ getRanges() const140cdf0e10cSrcweir inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; } 141cdf0e10cSrcweir 142cdf0e10cSrcweir private: 143cdf0e10cSrcweir CondFormatRuleRef createRule(); 144cdf0e10cSrcweir void insertRule( CondFormatRuleRef xRule ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir private: 147cdf0e10cSrcweir typedef RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap; 148cdf0e10cSrcweir 149cdf0e10cSrcweir CondFormatModel maModel; /// Model of this conditional formatting. 150cdf0e10cSrcweir CondFormatRuleMap maRules; /// Maps formatting rules by priority. 151cdf0e10cSrcweir }; 152cdf0e10cSrcweir 153cdf0e10cSrcweir typedef ::boost::shared_ptr< CondFormat > CondFormatRef; 154cdf0e10cSrcweir 155cdf0e10cSrcweir // ============================================================================ 156cdf0e10cSrcweir 157cdf0e10cSrcweir class CondFormatBuffer : public WorksheetHelper 158cdf0e10cSrcweir { 159cdf0e10cSrcweir public: 160cdf0e10cSrcweir explicit CondFormatBuffer( const WorksheetHelper& rHelper ); 161cdf0e10cSrcweir 162cdf0e10cSrcweir /** Imports settings from the conditionalFormatting element. */ 163cdf0e10cSrcweir CondFormatRef importConditionalFormatting( const AttributeList& rAttribs ); 164cdf0e10cSrcweir /** Imports settings from the CONDFORMATTING record. */ 165cdf0e10cSrcweir CondFormatRef importCondFormatting( SequenceInputStream& rStrm ); 166cdf0e10cSrcweir /** Imports settings from the CFHEADER record. */ 167cdf0e10cSrcweir void importCfHeader( BiffInputStream& rStrm ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir /** Creates all conditional formattings in the Calc document. */ 170cdf0e10cSrcweir void finalizeImport(); 171cdf0e10cSrcweir 172cdf0e10cSrcweir /** Converts an OOXML condition operator token to the API constant. */ 173cdf0e10cSrcweir static ::com::sun::star::sheet::ConditionOperator 174cdf0e10cSrcweir convertToApiOperator( sal_Int32 nToken ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir private: 177cdf0e10cSrcweir CondFormatRef createCondFormat(); 178cdf0e10cSrcweir 179cdf0e10cSrcweir private: 180cdf0e10cSrcweir typedef RefVector< CondFormat > CondFormatVec; 181cdf0e10cSrcweir CondFormatVec maCondFormats; /// All conditional formattings in a sheet. 182cdf0e10cSrcweir }; 183cdf0e10cSrcweir 184cdf0e10cSrcweir // ============================================================================ 185cdf0e10cSrcweir 186cdf0e10cSrcweir } // namespace xls 187cdf0e10cSrcweir } // namespace oox 188cdf0e10cSrcweir 189cdf0e10cSrcweir #endif 190