LibreOffice Module sc (master) 1
condformatcontext.cxx
Go to the documentation of this file.
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 <condformatcontext.hxx>
21#include <extlstcontext.hxx>
22
23#include <biffhelper.hxx>
24#include <condformatbuffer.hxx>
25#include <oox/token/namespaces.hxx>
26#include <utility>
27
28namespace oox::xls {
29
30using ::oox::core::ContextHandlerRef;
31
33 WorksheetContextBase( rFragment ),
34 mxRule(std::move( xRule ))
35{
36}
37
39{
40 switch( getCurrentElement() )
41 {
42 case XLS_TOKEN( cfRule ):
43 return (nElement == XLS_TOKEN( colorScale )) ? this : nullptr;
44 case XLS_TOKEN( colorScale ):
45 if (nElement == XLS_TOKEN( cfvo ))
46 return this;
47 else if (nElement == XLS_TOKEN( color ))
48 return this;
49 else
50 return nullptr;
51 }
52 return nullptr;
53}
54
56{
57 switch( getCurrentElement() )
58 {
59 case XLS_TOKEN( cfvo ):
60 mxRule->getColorScale()->importCfvo( rAttribs );
61 break;
62 case XLS_TOKEN( color ):
63 mxRule->getColorScale()->importColor( rAttribs );
64 break;
65 }
66}
67
69 WorksheetContextBase( rFragment ),
70 mxRule(std::move( xRule ))
71{
72}
73
75{
76 switch( getCurrentElement() )
77 {
78 case XLS_TOKEN( cfRule ):
79 return (nElement == XLS_TOKEN( dataBar )) ? this : nullptr;
80 case XLS_TOKEN( dataBar ):
81 if (nElement == XLS_TOKEN( cfvo ))
82 return this;
83 else if (nElement == XLS_TOKEN( color ))
84 return this;
85 else
86 return nullptr;
87 }
88 return nullptr;
89}
90
92{
93 switch( getCurrentElement() )
94 {
95 case XLS_TOKEN( dataBar ):
96 mxRule->getDataBar()->importAttribs( rAttribs );
97 break;
98 case XLS_TOKEN( cfvo ):
99 mxRule->getDataBar()->importCfvo( rAttribs );
100 break;
101 case XLS_TOKEN( color ):
102 mxRule->getDataBar()->importColor( rAttribs );
103 break;
104 }
105}
106
108 WorksheetContextBase(rParent),
109 mpIconSet(pIconSet)
110{
111}
112
114{
115 switch( getCurrentElement() )
116 {
117 case XLS_TOKEN( cfRule ):
118 case XLS14_TOKEN( cfRule ):
119 return (nElement == XLS_TOKEN( iconSet ) || nElement == XLS14_TOKEN(iconSet)) ? this : nullptr;
120 case XLS_TOKEN( iconSet ):
121 case XLS14_TOKEN(iconSet):
122 if (nElement == XLS_TOKEN( cfvo ) ||
123 nElement == XLS14_TOKEN(cfvo) ||
124 nElement == XLS14_TOKEN(cfIcon))
125 return this;
126 else
127 return nullptr;
128 case XLS14_TOKEN(cfvo):
129 if (nElement == XM_TOKEN(f))
130 return this;
131 }
132 return nullptr;
133}
134
136{
137 switch( getCurrentElement() )
138 {
139 case XLS_TOKEN( iconSet ):
140 case XLS14_TOKEN( iconSet ):
141 mpIconSet->importAttribs( rAttribs );
142 break;
143 case XLS_TOKEN( cfvo ):
144 case XLS14_TOKEN( cfvo ):
145 mpIconSet->importCfvo( rAttribs );
146 break;
147 case XLS14_TOKEN(cfIcon):
148 mpIconSet->importIcon(rAttribs);
149 break;
150 }
151}
152
153void IconSetContext::onCharacters(const OUString& rChars)
154{
155 maChars = rChars;
156}
157
159{
160 switch(getCurrentElement())
161 {
162 case XM_TOKEN(f):
164 maChars = OUString();
165 break;
166 }
167}
168
170 WorksheetContextBase( rFragment )
171{
172}
173
175{
176 switch( getCurrentElement() )
177 {
178 case XLS_TOKEN( conditionalFormatting ):
179 return (nElement == XLS_TOKEN( cfRule )) ? this : nullptr;
180 case XLS_TOKEN( cfRule ):
181 if (nElement == XLS_TOKEN( formula ))
182 return this;
183 else if (nElement == XLS_TOKEN( colorScale ) )
184 return new ColorScaleContext( *this, mxRule );
185 else if (nElement == XLS_TOKEN( dataBar ) )
186 return new DataBarContext( *this, mxRule );
187 else if (nElement == XLS_TOKEN( iconSet ) )
188 return new IconSetContext(*this, mxRule->getIconSet());
189 else if (nElement == XLS_TOKEN( extLst ) )
190 return new ExtLstLocalContext( *this, mxRule->getDataBar()->getDataBarFormatData() );
191 else
192 return nullptr;
193 }
194 return nullptr;
195}
196
198{
199 switch( getCurrentElement() )
200 {
201 case XLS_TOKEN( conditionalFormatting ):
202 if(mxCondFmt)
203 mxCondFmt->setReadyForFinalize();
204 break;
205 case XLS_TOKEN( cfRule ):
206 if (mxCondFmt && mxRule)
207 {
208 ScRangeList aRanges = mxCondFmt->getRanges();
209 if ((aRanges.size() == 1 && aRanges.GetCellCount() == 1) ||
210 !getCondFormats().insertRule(mxCondFmt, mxRule))
211 mxCondFmt->insertRule(mxRule);
212 }
213 break;
214 }
215}
216
218{
219 switch( getCurrentElement() )
220 {
221 case XLS_TOKEN( conditionalFormatting ):
223 break;
224 case XLS_TOKEN( cfRule ):
225 if( mxCondFmt ) mxRule = mxCondFmt->importCfRule( rAttribs );
226 break;
227 }
228}
229
230void CondFormatContext::onCharacters( const OUString& rChars )
231{
232 if( isCurrentElement( XLS_TOKEN( formula ) ) && mxCondFmt && mxRule )
233 mxRule->appendFormula( rChars );
234}
235
237{
238 switch( getCurrentElement() )
239 {
241 return (nRecId == BIFF12_ID_CFRULE) ? this : nullptr;
242 }
243 return nullptr;
244}
245
247{
248 switch( getCurrentElement() )
249 {
252 break;
253 case BIFF12_ID_CFRULE:
254 if( mxCondFmt ) mxCondFmt->importCfRule( rStrm );
255 break;
256 }
257}
258
260{
261 switch( getCurrentElement() )
262 {
264 if( mxCondFmt )
265 {
266 mxCondFmt->setReadyForFinalize();
267 }
268 break;
269 }
270}
271
272} // namespace oox::xls
273
274/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt64 GetCellCount() const
Definition: rangelst.cxx:1087
size_t size() const
Definition: rangelst.hxx:89
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
ColorScaleContext(CondFormatContext &rFragment, CondFormatRuleRef xRule)
virtual void onStartElement(const AttributeList &rAttribs) override
CondFormatRef importConditionalFormatting(const AttributeList &rAttribs)
Imports settings from the conditionalFormatting element.
CondFormatRef importCondFormatting(SequenceInputStream &rStrm)
Imports settings from the CONDFORMATTING record.
CondFormatContext(WorksheetFragmentBase &rFragment)
virtual void onStartElement(const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual void onCharacters(const OUString &rChars) override
virtual void onStartRecord(SequenceInputStream &rStrm) override
virtual void onEndRecord() override
virtual void onEndElement() override
virtual void onStartElement(const AttributeList &rAttribs) override
DataBarContext(CondFormatContext &rFormat, CondFormatRuleRef xRule)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Handle ExtLst entries in xlsx.
virtual void onStartElement(const AttributeList &rAttribs) override
virtual void onCharacters(const OUString &rChars) override
IconSetContext(WorksheetContextBase &rParent, IconSetRule *pIconSet)
virtual void onEndElement() override
virtual oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
void importIcon(const AttributeList &rAttribs)
void importFormula(const OUString &rFormula)
void importAttribs(const AttributeList &rAttribs)
void importCfvo(const AttributeList &rAttribs)
Context handler derived from the WorksheetHelper helper class.
Fragment handler derived from the WorksheetHelper helper class.
CondFormatBuffer & getCondFormats() const
Returns the conditional formatting in this sheet.
void SvStream & rStrm
const sal_Int32 BIFF12_ID_CFRULE
Definition: biffhelper.hxx:54
std::shared_ptr< CondFormatRule > CondFormatRuleRef
const sal_Int32 BIFF12_ID_CONDFORMATTING
Definition: biffhelper.hxx:72