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 
27 namespace oox::xls {
28 
29 using ::oox::core::ContextHandlerRef;
30 
32  WorksheetContextBase( rFragment ),
33  mxRule( xRule )
34 {
35 }
36 
38 {
39  switch( getCurrentElement() )
40  {
41  case XLS_TOKEN( cfRule ):
42  return (nElement == XLS_TOKEN( colorScale )) ? this : nullptr;
43  case XLS_TOKEN( colorScale ):
44  if (nElement == XLS_TOKEN( cfvo ))
45  return this;
46  else if (nElement == XLS_TOKEN( color ))
47  return this;
48  else
49  return nullptr;
50  }
51  return nullptr;
52 }
53 
55 {
56  switch( getCurrentElement() )
57  {
58  case XLS_TOKEN( cfvo ):
59  mxRule->getColorScale()->importCfvo( rAttribs );
60  break;
61  case XLS_TOKEN( color ):
62  mxRule->getColorScale()->importColor( rAttribs );
63  break;
64  }
65 }
66 
68  WorksheetContextBase( rFragment ),
69  mxRule( xRule )
70 {
71 }
72 
74 {
75  switch( getCurrentElement() )
76  {
77  case XLS_TOKEN( cfRule ):
78  return (nElement == XLS_TOKEN( dataBar )) ? this : nullptr;
79  case XLS_TOKEN( dataBar ):
80  if (nElement == XLS_TOKEN( cfvo ))
81  return this;
82  else if (nElement == XLS_TOKEN( color ))
83  return this;
84  else
85  return nullptr;
86  }
87  return nullptr;
88 }
89 
91 {
92  switch( getCurrentElement() )
93  {
94  case XLS_TOKEN( dataBar ):
95  mxRule->getDataBar()->importAttribs( rAttribs );
96  break;
97  case XLS_TOKEN( cfvo ):
98  mxRule->getDataBar()->importCfvo( rAttribs );
99  break;
100  case XLS_TOKEN( color ):
101  mxRule->getDataBar()->importColor( rAttribs );
102  break;
103  }
104 }
105 
107  WorksheetContextBase(rParent),
108  mpIconSet(pIconSet)
109 {
110 }
111 
113 {
114  switch( getCurrentElement() )
115  {
116  case XLS_TOKEN( cfRule ):
117  case XLS14_TOKEN( cfRule ):
118  return (nElement == XLS_TOKEN( iconSet ) || nElement == XLS14_TOKEN(iconSet)) ? this : nullptr;
119  case XLS_TOKEN( iconSet ):
120  case XLS14_TOKEN(iconSet):
121  if (nElement == XLS_TOKEN( cfvo ) ||
122  nElement == XLS14_TOKEN(cfvo) ||
123  nElement == XLS14_TOKEN(cfIcon))
124  return this;
125  else
126  return nullptr;
127  case XLS14_TOKEN(cfvo):
128  if (nElement == XM_TOKEN(f))
129  return this;
130  }
131  return nullptr;
132 }
133 
135 {
136  switch( getCurrentElement() )
137  {
138  case XLS_TOKEN( iconSet ):
139  case XLS14_TOKEN( iconSet ):
140  mpIconSet->importAttribs( rAttribs );
141  break;
142  case XLS_TOKEN( cfvo ):
143  case XLS14_TOKEN( cfvo ):
144  mpIconSet->importCfvo( rAttribs );
145  break;
146  case XLS14_TOKEN(cfIcon):
147  mpIconSet->importIcon(rAttribs);
148  break;
149  }
150 }
151 
152 void IconSetContext::onCharacters(const OUString& rChars)
153 {
154  maChars = rChars;
155 }
156 
158 {
159  switch(getCurrentElement())
160  {
161  case XM_TOKEN(f):
163  maChars = OUString();
164  break;
165  }
166 }
167 
169  WorksheetContextBase( rFragment )
170 {
171 }
172 
174 {
175  switch( getCurrentElement() )
176  {
177  case XLS_TOKEN( conditionalFormatting ):
178  return (nElement == XLS_TOKEN( cfRule )) ? this : nullptr;
179  case XLS_TOKEN( cfRule ):
180  if (nElement == XLS_TOKEN( formula ))
181  return this;
182  else if (nElement == XLS_TOKEN( colorScale ) )
183  return new ColorScaleContext( *this, mxRule );
184  else if (nElement == XLS_TOKEN( dataBar ) )
185  return new DataBarContext( *this, mxRule );
186  else if (nElement == XLS_TOKEN( iconSet ) )
187  return new IconSetContext(*this, mxRule->getIconSet());
188  else if (nElement == XLS_TOKEN( extLst ) )
189  return new ExtLstLocalContext( *this, mxRule->getDataBar()->getDataBarFormatData() );
190  else
191  return nullptr;
192  }
193  return nullptr;
194 }
195 
197 {
198  switch( getCurrentElement() )
199  {
200  case XLS_TOKEN( conditionalFormatting ):
201  if(mxCondFmt)
202  mxCondFmt->setReadyForFinalize();
203  break;
204  }
205 }
206 
208 {
209  switch( getCurrentElement() )
210  {
211  case XLS_TOKEN( conditionalFormatting ):
213  break;
214  case XLS_TOKEN( cfRule ):
215  if( mxCondFmt ) mxRule = mxCondFmt->importCfRule( rAttribs );
216  break;
217  }
218 }
219 
220 void CondFormatContext::onCharacters( const OUString& rChars )
221 {
222  if( isCurrentElement( XLS_TOKEN( formula ) ) && mxCondFmt && mxRule )
223  mxRule->appendFormula( rChars );
224 }
225 
227 {
228  switch( getCurrentElement() )
229  {
231  return (nRecId == BIFF12_ID_CFRULE) ? this : nullptr;
232  }
233  return nullptr;
234 }
235 
237 {
238  switch( getCurrentElement() )
239  {
242  break;
243  case BIFF12_ID_CFRULE:
244  if( mxCondFmt ) mxCondFmt->importCfRule( rStrm );
245  break;
246  }
247 }
248 
250 {
251  switch( getCurrentElement() )
252  {
254  if( mxCondFmt )
255  {
256  mxCondFmt->setReadyForFinalize();
257  }
258  break;
259  }
260 }
261 
262 } // namespace oox::xls
263 
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
CondFormatRef importConditionalFormatting(const AttributeList &rAttribs)
Imports settings from the conditionalFormatting element.
void importIcon(const AttributeList &rAttribs)
virtual void onStartElement(const AttributeList &rAttribs) override
bool isCurrentElement(sal_Int32 nElement) const
void importCfvo(const AttributeList &rAttribs)
virtual void onStartElement(const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual void onCharacters(const OUString &rChars) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Handle ExtLst entries in xlsx.
CondFormatBuffer & getCondFormats() const
Returns the conditional formatting in this sheet.
const sal_Int32 BIFF12_ID_CFRULE
Definition: biffhelper.hxx:55
virtual void onStartElement(const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
IconSetContext(WorksheetContextBase &rParent, IconSetRule *pIconSet)
virtual void onEndElement() override
virtual void onStartElement(const AttributeList &rAttribs) override
virtual void onStartRecord(SequenceInputStream &rStrm) override
std::shared_ptr< CondFormatRule > CondFormatRuleRef
virtual void onEndRecord() override
virtual void onCharacters(const OUString &rChars) override
sal_Int32 getCurrentElement() const
virtual void onEndElement() override
ColorScaleContext(CondFormatContext &rFragment, CondFormatRuleRef const &xRule)
Fragment handler derived from the WorksheetHelper helper class.
void importAttribs(const AttributeList &rAttribs)
virtual oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Context handler derived from the WorksheetHelper helper class.
CondFormatContext(WorksheetFragmentBase &rFragment)
void(* f)(TrueTypeTable *)
void importFormula(const OUString &rFormula)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
CondFormatRef importCondFormatting(SequenceInputStream &rStrm)
Imports settings from the CONDFORMATTING record.
const sal_Int32 BIFF12_ID_CONDFORMATTING
Definition: biffhelper.hxx:73
DataBarContext(CondFormatContext &rFormat, CondFormatRuleRef const &xRule)