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 OOX_XLS_CONDFORMATBUFFER_HXX
30 : : #define OOX_XLS_CONDFORMATBUFFER_HXX
31 : :
32 : : #include <com/sun/star/sheet/ConditionOperator2.hpp>
33 : : #include "formulaparser.hxx"
34 : : #include "worksheethelper.hxx"
35 : : #include <boost/scoped_ptr.hpp>
36 : : #include <tools/color.hxx>
37 : :
38 : : namespace com { namespace sun { namespace star {
39 : : namespace sheet { class XSheetConditionalEntries; }
40 : : } } }
41 : : class ScColorScaleFormat;
42 : : class ScDataBarFormat;
43 : : struct ScDataBarFormatData;
44 : : class ScConditionalFormat;
45 : :
46 : : namespace oox {
47 : : namespace xls {
48 : :
49 : : class CondFormat;
50 : :
51 : : // ============================================================================
52 : :
53 : : /** Model for a single rule in a conditional formatting. */
54 : 0 : struct CondFormatRuleModel
55 : : {
56 : : typedef ::std::vector< ApiTokenSequence > ApiTokenSequenceVector;
57 : :
58 : : ApiTokenSequenceVector maFormulas; /// Formulas for rule conditions.
59 : : ::rtl::OUString maText; /// Text for 'contains' rules.
60 : : sal_Int32 mnPriority; /// Priority of this rule.
61 : : sal_Int32 mnType; /// Type of the rule.
62 : : sal_Int32 mnOperator; /// In cell-is rules: Comparison operator.
63 : : sal_Int32 mnTimePeriod; /// In time-period rules: Type of time period.
64 : : sal_Int32 mnRank; /// In top-10 rules: True = bottom, false = top.
65 : : sal_Int32 mnStdDev; /// In average rules: Number of std deviations.
66 : : sal_Int32 mnDxfId; /// Differential formatting identifier.
67 : : bool mbStopIfTrue; /// True = stop evaluating rules, if this rule is true.
68 : : bool mbBottom; /// In top-10 rules: True = bottom, false = top.
69 : : bool mbPercent; /// In top-10 rules: True = percent, false = rank.
70 : : bool mbAboveAverage; /// In average rules: True = above average, false = below.
71 : : bool mbEqualAverage; /// In average rules: True = include average, false = exclude.
72 : :
73 : : explicit CondFormatRuleModel();
74 : :
75 : : /** Sets the passed BIFF operator for condition type cellIs. */
76 : : void setBiffOperator( sal_Int32 nOperator );
77 : :
78 : : /** Sets the passed BIFF12 text comparison type and operator. */
79 : : void setBiff12TextType( sal_Int32 nOperator );
80 : : };
81 : :
82 : 0 : struct ColorScaleRuleModelEntry
83 : : {
84 : : ::Color maColor;
85 : : double mnVal;
86 : :
87 : : bool mbMin;
88 : : bool mbMax;
89 : : bool mbPercent;
90 : : bool mbPercentile;
91 : : rtl::OUString maFormula;
92 : :
93 : 0 : ColorScaleRuleModelEntry():
94 : : maColor(),
95 : : mnVal(0),
96 : : mbMin(false),
97 : : mbMax(false),
98 : : mbPercent(false),
99 : 0 : mbPercentile(false) {}
100 : : };
101 : :
102 [ # # ]: 0 : class ColorScaleRule : public WorksheetHelper
103 : : {
104 : : public:
105 : : ColorScaleRule( const CondFormat& rFormat );
106 : :
107 : : void importCfvo( const AttributeList& rAttribs );
108 : : void importColor( const AttributeList& rAttribs );
109 : :
110 : : void AddEntries( ScColorScaleFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
111 : :
112 : : private:
113 : : const CondFormat& mrCondFormat;
114 : : std::vector< ColorScaleRuleModelEntry > maColorScaleRuleEntries;
115 : :
116 : : sal_uInt32 mnCfvo;
117 : : sal_uInt32 mnCol;
118 : : };
119 : :
120 [ # # ][ # # ]: 0 : class DataBarRule : public WorksheetHelper
[ # # ]
121 : : {
122 : : public:
123 : : DataBarRule( const CondFormat& rFormat );
124 : : void importCfvo( const AttributeList& rAttribs );
125 : : void importColor( const AttributeList& rAttribs );
126 : : void importAttribs( const AttributeList& rAttribs );
127 : :
128 : : void SetData( ScDataBarFormat* pFormat, ScDocument* pDoc, const ScAddress& rAddr );
129 : :
130 : 0 : ScDataBarFormatData* getDataBarFormatData() { return mpFormat; }
131 : :
132 : : private:
133 : : const CondFormat& mrCondFormat;
134 : : ScDataBarFormatData* mpFormat;
135 : :
136 : : boost::scoped_ptr<ColorScaleRuleModelEntry> mpUpperLimit;
137 : : boost::scoped_ptr<ColorScaleRuleModelEntry> mpLowerLimit;
138 : : };
139 : :
140 : :
141 : : // ============================================================================
142 : :
143 : :
144 : : /** Represents a single rule in a conditional formatting. */
145 [ # # ][ # # ]: 0 : class CondFormatRule : public WorksheetHelper
[ # # ]
146 : : {
147 : : public:
148 : : explicit CondFormatRule( const CondFormat& rCondFormat, ScConditionalFormat* pFormat );
149 : :
150 : : /** Imports rule settings from the cfRule element. */
151 : : void importCfRule( const AttributeList& rAttribs );
152 : : /** Appends a new condition formula string. */
153 : : void appendFormula( const ::rtl::OUString& rFormula );
154 : :
155 : : /** Imports rule settings from a CFRULE record. */
156 : : void importCfRule( SequenceInputStream& rStrm );
157 : :
158 : : /** Creates a conditional formatting rule in the Calc document. */
159 : : void finalizeImport();
160 : :
161 : : /** Returns the priority of this rule. */
162 : 0 : inline sal_Int32 getPriority() const { return maModel.mnPriority; }
163 : :
164 : : ColorScaleRule* getColorScale();
165 : : DataBarRule* getDataBar();
166 : :
167 : : private:
168 : : const CondFormat& mrCondFormat;
169 : : CondFormatRuleModel maModel;
170 : : ScConditionalFormat* mpFormat;
171 : : boost::scoped_ptr<ColorScaleRule> mpColor;
172 : : boost::scoped_ptr<DataBarRule> mpDataBar;
173 : : };
174 : :
175 : : typedef ::boost::shared_ptr< CondFormatRule > CondFormatRuleRef;
176 : :
177 : : // ============================================================================
178 : :
179 : : /** Model for a conditional formatting object. */
180 : 0 : struct CondFormatModel
181 : : {
182 : : ApiCellRangeList maRanges; /// Cell ranges for this conditional format.
183 : : bool mbPivot; /// Conditional formatting belongs to pivot table.
184 : :
185 : : explicit CondFormatModel();
186 : : };
187 : :
188 : : // ============================================================================
189 : :
190 : : /** Represents a conditional formatting object with a list of affected cell ranges. */
191 [ # # ]: 0 : class CondFormat : public WorksheetHelper
192 : : {
193 : : public:
194 : : explicit CondFormat( const WorksheetHelper& rHelper );
195 : :
196 : : /** Imports settings from the conditionalFormatting element. */
197 : : void importConditionalFormatting( const AttributeList& rAttribs );
198 : : /** Imports a conditional formatting rule from the cfRule element. */
199 : : CondFormatRuleRef importCfRule( const AttributeList& rAttribs );
200 : :
201 : : /** Imports settings from the CONDFORMATTING record. */
202 : : void importCondFormatting( SequenceInputStream& rStrm );
203 : : /** Imports a conditional formatting rule from the CFRULE record. */
204 : : void importCfRule( SequenceInputStream& rStrm );
205 : :
206 : : /** Creates the conditional formatting in the Calc document. */
207 : : void finalizeImport();
208 : :
209 : : /** Returns the cell ranges this conditional formatting belongs to. */
210 : 0 : inline const ApiCellRangeList& getRanges() const { return maModel.maRanges; }
211 : :
212 : : private:
213 : : CondFormatRuleRef createRule();
214 : : void insertRule( CondFormatRuleRef xRule );
215 : :
216 : : private:
217 : : typedef RefMap< sal_Int32, CondFormatRule > CondFormatRuleMap;
218 : :
219 : : CondFormatModel maModel; /// Model of this conditional formatting.
220 : : CondFormatRuleMap maRules; /// Maps formatting rules by priority.
221 : : ScConditionalFormat* mpFormat;
222 : : };
223 : :
224 : : typedef ::boost::shared_ptr< CondFormat > CondFormatRef;
225 : :
226 : : // ============================================================================
227 : :
228 [ - + ]: 60 : class CondFormatBuffer : public WorksheetHelper
229 : : {
230 : : public:
231 : : explicit CondFormatBuffer( const WorksheetHelper& rHelper );
232 : :
233 : : /** Imports settings from the conditionalFormatting element. */
234 : : CondFormatRef importConditionalFormatting( const AttributeList& rAttribs );
235 : : /** Imports settings from the CONDFORMATTING record. */
236 : : CondFormatRef importCondFormatting( SequenceInputStream& rStrm );
237 : :
238 : : /** Converts an OOXML condition operator token to the API constant. */
239 : : static sal_Int32 convertToApiOperator( sal_Int32 nToken );
240 : :
241 : : private:
242 : : CondFormatRef createCondFormat();
243 : :
244 : : private:
245 : : typedef RefVector< CondFormat > CondFormatVec;
246 : : CondFormatVec maCondFormats; /// All conditional formatting in a sheet.
247 : : };
248 : :
249 : : // ============================================================================
250 : :
251 : : } // namespace xls
252 : : } // namespace oox
253 : :
254 : : #endif
255 : :
256 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|