1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef OOX_XLS_CONDFORMATBUFFER_HXX 29 #define OOX_XLS_CONDFORMATBUFFER_HXX 30 31 #include <com/sun/star/sheet/ConditionOperator.hpp> 32 #include "oox/xls/formulaparser.hxx" 33 #include "oox/xls/worksheethelper.hxx" 34 35 namespace com { namespace sun { namespace star { 36 namespace sheet { class XSheetConditionalEntries; } 37 } } } 38 39 namespace oox { 40 namespace xls { 41 42 // ============================================================================ 43 44 /** Model for a single rule in a conditional formatting. */ 45 struct CondFormatRuleModel 46 { 47 typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector; 48 49 ApiTokenSequenceVector maFormulas; /// Formulas for rule conditions. 50 ::rtl::OUString maText; /// Text for 'contains' rules. 51 sal_Int32 mnPriority; /// Priority of this rule. 52 sal_Int32 mnType; /// Type of the rule. 53 sal_Int32 mnOperator; /// In cell-is rules: Comparison operator. 54 sal_Int32 mnTimePeriod; /// In time-period rules: Type of time period. 55 sal_Int32 mnRank; /// In top-10 rules: True = bottom, false = top. 56 sal_Int32 mnStdDev; /// In average rules: Number of std deviations. 57 sal_Int32 mnDxfId; /// Differential formatting identifier. 58 bool mbStopIfTrue; /// True = stop evaluating rules, if this rule is true. 59 bool mbBottom; /// In top-10 rules: True = bottom, false = top. 60 bool mbPercent; /// In top-10 rules: True = percent, false = rank. 61 bool mbAboveAverage; /// In average rules: True = above average, false = below. 62 bool mbEqualAverage; /// In average rules: True = include average, false = exclude. 63 64 explicit CondFormatRuleModel(); 65 66 /** Sets the passed BIFF operator for condition type cellIs. */ 67 void setBiffOperator( sal_Int32 nOperator ); 68 69 /** Sets the passed BIFF12 text comparison type and operator. */ 70 void setBiff12TextType( sal_Int32 nOperator ); 71 }; 72 73 // ============================================================================ 74 75 class CondFormat; 76 77 /** Represents a single rule in a conditional formatting. */ 78 class CondFormatRule : public WorksheetHelper 79 { 80 public: 81 explicit CondFormatRule( const CondFormat& rCondFormat ); 82 83 /** Imports rule settings from the cfRule element. */ 84 void importCfRule( const AttributeList& rAttribs ); 85 /** Appends a new condition formula string. */ 86 void appendFormula( const ::rtl::OUString& rFormula ); 87 88 /** Imports rule settings from a CFRULE record. */ 89 void importCfRule( SequenceInputStream& rStrm ); 90 91 /** Imports rule settings from a CFRULE record. */ 92 void importCfRule( BiffInputStream& rStrm, sal_Int32 nPriority ); 93 94 /** Creates a conditional formatting rule in the Calc document. */ 95 void finalizeImport( 96 const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSheetConditionalEntries >& rxEntries ); 97 98 /** Returns the priority of this rule. */ 99 inline sal_Int32 getPriority() const { return maModel.mnPriority; } 100 101 private: 102 const CondFormat& mrCondFormat; 103 CondFormatRuleModel maModel; 104 }; 105 106 typedef ::boost::shared_ptr< CondFormatRule > CondFormatRuleRef; 107 108 // ============================================================================ 109 110 /** Model for a conditional formatting object. */ 111 struct CondFormatModel 112 { 113 ApiCellRangeList maRanges; /// Cell ranges for this conditional format. 114 bool mbPivot; /// Conditional formatting belongs to pivot table. 115 116 explicit CondFormatModel(); 117 }; 118 119 // ============================================================================ 120 121 /** Represents a conditional formatting object with a list of affected cell ranges. */ 122 class CondFormat : public WorksheetHelper 123 { 124 public: 125 explicit CondFormat( const WorksheetHelper& rHelper ); 126 127 /** Imports settings from the conditionalFormatting element. */ 128 void importConditionalFormatting( const AttributeList& rAttribs ); 129 /** Imports a conditional formatting rule from the cfRule element. */ 130 CondFormatRuleRef importCfRule( const AttributeList& rAttribs ); 131 132 /** Imports settings from the CONDFORMATTING record. */ 133 void importCondFormatting( SequenceInputStream& rStrm ); 134 /** Imports a conditional formatting rule from the CFRULE record. */ 135 void importCfRule( SequenceInputStream& rStrm ); 136 137 /** Imports settings from the CFHEADER record. */ 138 void importCfHeader( BiffInputStream& rStrm ); 139 140 /** Creates the conditional formatting in the Calc document. */ 141 void finalizeImport(); 142 143 /** Returns the cell ranges this conditional formatting belongs to. */ 144 inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; } 145 146 private: 147 CondFormatRuleRef createRule(); 148 void insertRule( CondFormatRuleRef xRule ); 149 150 private: 151 typedef RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap; 152 153 CondFormatModel maModel; /// Model of this conditional formatting. 154 CondFormatRuleMap maRules; /// Maps formatting rules by priority. 155 }; 156 157 typedef ::boost::shared_ptr< CondFormat > CondFormatRef; 158 159 // ============================================================================ 160 161 class CondFormatBuffer : public WorksheetHelper 162 { 163 public: 164 explicit CondFormatBuffer( const WorksheetHelper& rHelper ); 165 166 /** Imports settings from the conditionalFormatting element. */ 167 CondFormatRef importConditionalFormatting( const AttributeList& rAttribs ); 168 /** Imports settings from the CONDFORMATTING record. */ 169 CondFormatRef importCondFormatting( SequenceInputStream& rStrm ); 170 /** Imports settings from the CFHEADER record. */ 171 void importCfHeader( BiffInputStream& rStrm ); 172 173 /** Creates all conditional formattings in the Calc document. */ 174 void finalizeImport(); 175 176 /** Converts an OOXML condition operator token to the API constant. */ 177 static ::com::sun::star::sheet::ConditionOperator 178 convertToApiOperator( sal_Int32 nToken ); 179 180 private: 181 CondFormatRef createCondFormat(); 182 183 private: 184 typedef RefVector< CondFormat > CondFormatVec; 185 CondFormatVec maCondFormats; /// All conditional formattings in a sheet. 186 }; 187 188 // ============================================================================ 189 190 } // namespace xls 191 } // namespace oox 192 193 #endif 194