LibreOffice Module sc (master)  1
extlstcontext.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 
10 #include <memory>
11 #include <extlstcontext.hxx>
12 #include <worksheethelper.hxx>
15 #include <oox/token/namespaces.hxx>
16 #include <oox/token/tokens.hxx>
17 #include <colorscale.hxx>
18 #include <condformatbuffer.hxx>
19 #include <condformatcontext.hxx>
20 #include <document.hxx>
21 #include <worksheetfragment.hxx>
22 #include <workbookfragment.hxx>
23 #include <stylesbuffer.hxx>
24 #include <stylesfragment.hxx>
25 
26 #include <rangeutl.hxx>
27 #include <sal/log.hxx>
28 
29 using ::oox::core::ContextHandlerRef;
30 using ::oox::xls::CondFormatBuffer;
31 
32 sal_Int32 rStyleIdx = 0;
33 
34 namespace oox::xls {
35 
37  WorksheetContextBase( rFragment ),
38  mpTarget( pTarget ),
39  mbFirstEntry(true)
40 {
41 }
42 
44 {
45  return this;
46 }
47 
49 {
50  switch( getCurrentElement() )
51  {
52  case XLS14_TOKEN( dataBar ):
53  {
55  xRule->importDataBar( rAttribs );
56  break;
57  }
58  case XLS14_TOKEN( negativeFillColor ):
59  {
61  xRule->importNegativeFillColor( rAttribs );
62  break;
63  }
64  case XLS14_TOKEN( axisColor ):
65  {
67  xRule->importAxisColor( rAttribs );
68  break;
69  }
70  case XLS14_TOKEN( cfvo ):
71  {
73  xRule->importCfvo( rAttribs );
74  xRule->getModel().mbIsLower = mbFirstEntry;
75  mbFirstEntry = false;
76  break;
77  }
78  default:
79  break;
80  }
81 }
82 
84  : WorksheetContextBase(rFragment)
85  , nPriority(-1)
86  , eOperator(ScConditionMode::NONE)
87  , isPreviousElementF(false)
88 {
89 }
90 
92 {
93  if (mpCurrentRule)
94  {
95  ScFormatEntry& rFormat = **maEntries.rbegin();
97  ScIconSetFormat& rIconSet = static_cast<ScIconSetFormat&>(rFormat);
98  ScDocument& rDoc = getScDocument();
99  SCTAB nTab = getSheetIndex();
100  ScAddress aPos(0, 0, nTab);
101  mpCurrentRule->SetData(&rIconSet, &rDoc, aPos);
102  mpCurrentRule.reset();
103  }
104  if (nElement == XLS14_TOKEN(cfRule))
105  {
106  OUString aType = rAttribs.getString(XML_type, OUString());
107  OUString aId = rAttribs.getString(XML_id, OUString());
108  nPriority = rAttribs.getInteger( XML_priority, -1 );
109  maPriorities.push_back(nPriority);
110 
111  if (aType == "dataBar")
112  {
113  // an ext entry does not need to have an existing corresponding entry
114  ExtLst::const_iterator aExt = getExtLst().find( aId );
115  if(aExt == getExtLst().end())
116  return nullptr;
117 
118  ScDataBarFormatData* pInfo = aExt->second;
119  if (!pInfo)
120  {
121  return nullptr;
122  }
123  return new ExtCfRuleContext( *this, pInfo );
124  }
125  else if (aType == "iconSet")
126  {
127  ScDocument& rDoc = getScDocument();
128  mpCurrentRule.reset(new IconSetRule(*this));
129  maEntries.push_back(std::make_unique<ScIconSetFormat>(&rDoc));
130  return new IconSetContext(*this, mpCurrentRule.get());
131  }
132  else if (aType == "cellIs")
133  {
134  sal_Int32 aToken = rAttribs.getToken( XML_operator, XML_TOKEN_INVALID );
136  return this;
137  }
138  else
139  {
140  SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType);
141  }
142  }
143  else if (nElement == XLS14_TOKEN( dxf ))
144  {
145  return new DxfContext( *this, getStyles().createExtDxf() );
146  }
147  else if (nElement == XM_TOKEN( sqref ) || nElement == XM_TOKEN( f ))
148  {
149  return this;
150  }
151 
152  return nullptr;
153 }
154 
156 {
157 }
158 
159 void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters)
160 {
161  switch (getCurrentElement())
162  {
163  case XM_TOKEN(f):
164  {
165  aChars = rCharacters;
166  isPreviousElementF = true;
167  }
168  break;
169  case XM_TOKEN(sqref):
170  {
171  aChars = rCharacters;
172  }
173  break;
174  }
175 
176 }
177 
179 {
180  switch (getCurrentElement())
181  {
182  case XM_TOKEN(f):
183  {
184  rFormulas.push_back(aChars);
185  }
186  break;
187  case XLS14_TOKEN( cfRule ):
188  {
190  }
191  break;
192  case XM_TOKEN(sqref):
193  {
194  ScRangeList aRange;
195  ScDocument& rDoc = getScDocument();
197  if (!bSuccess || aRange.empty())
198  break;
199 
200  SCTAB nTab = getSheetIndex();
201  for (size_t i = 0; i < aRange.size(); ++i)
202  {
203  aRange[i].aStart.SetTab(nTab);
204  aRange[i].aEnd.SetTab(nTab);
205  }
206 
207  if (isPreviousElementF) // sqref can be alone in some cases.
208  {
209  for (const OUString& rFormula : rFormulas)
210  {
211  ScAddress rPos = aRange.GetTopLeftCorner();
213  ScCondFormatEntry* pEntry = new ScCondFormatEntry(eOperator, rFormula, "", rDoc,
214  rPos, rStyle, "", "",
218  maEntries.push_back(std::unique_ptr<ScFormatEntry>(pEntry));
219  rStyleIdx++;
220  }
221 
222  assert(rFormulas.size() == maPriorities.size());
223  rFormulas.clear();
224  }
225 
226  std::vector< std::unique_ptr<ExtCfCondFormat> >& rExtFormats = getCondFormats().importExtCondFormat();
227  rExtFormats.push_back(std::make_unique<ExtCfCondFormat>(aRange, maEntries, &maPriorities));
228 
229  maPriorities.clear();
230  isPreviousElementF = false;
231  }
232  break;
233  default:
234  break;
235  }
236 }
237 
239  WorksheetContextBase(rFragment),
240  mpTarget(pTarget)
241 {
242 }
243 
245 {
246  switch( getCurrentElement() )
247  {
248  case XLS_TOKEN( extLst ):
249  if(nElement == XLS_TOKEN( ext ))
250  return this;
251  else
252  return nullptr;
253  break;
254  case XLS_TOKEN( ext ):
255  if (nElement == XLS14_TOKEN( id ))
256  return this;
257  else
258  return nullptr;
259  }
260  return nullptr;
261 }
262 
264 {
265  switch( getCurrentElement() )
266  {
267  case XLS14_TOKEN( id ):
268  break;
269  }
270 }
271 
272 void ExtLstLocalContext::onCharacters( const OUString& rChars )
273 {
274  if (getCurrentElement() == XLS14_TOKEN( id ))
275  {
276  getExtLst().insert( std::pair< OUString, ScDataBarFormatData*>(rChars, mpTarget) );
277  }
278 }
279 
281  WorksheetContextBase(rFragment)
282 {
283 }
284 
285 ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
286 {
287  switch (nElement)
288  {
289  case XLS14_TOKEN(conditionalFormatting): return new ExtConditionalFormattingContext(*this);
290  case XLS14_TOKEN(dataValidations): return new ExtDataValidationsContext(*this);
291  }
292  return this;
293 }
294 
296 {
297 }
298 
300  WorksheetContextBase(rFragment)
301 {
302 }
303 
305 {
306  if (nElement == XLS_TOKEN( ext ))
307  return new ExtGlobalContext( *this );
308 
309  return this;
310 }
311 
313  WorkbookContextBase(rFragment)
314 {
315 }
316 
318 {
319  if (nElement == LOEXT_TOKEN(extCalcPr))
320  {
321  ScDocument& rDoc = getScDocument();
322  sal_Int32 nToken = rAttribs.getToken( XML_stringRefSyntax, XML_CalcA1 );
323  ScCalcConfig aCalcConfig = rDoc.GetCalcConfig();
324 
325  switch( nToken )
326  {
327  case XML_CalcA1:
329  break;
330  case XML_ExcelA1:
332  break;
333  case XML_ExcelR1C1:
335  break;
336  case XML_CalcA1ExcelA1:
338  break;
339  default:
341  break;
342  }
343  rDoc.SetCalcConfig(aCalcConfig);
344  }
345 
346  return this;
347 }
348 
350 {
351 }
352 
354  WorkbookContextBase(rFragment)
355 {
356 }
357 
359 {
360  if (nElement == XLS_TOKEN( ext ))
361  return new ExtGlobalWorkbookContext( *this );
362 
363  return this;
364 }
365 
366 } //namespace oox::xls
367 
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void onCharacters(const OUString &rChars) override
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::vector< std::unique_ptr< ScFormatEntry > > maEntries
virtual void onStartElement(const AttributeList &rAttribs) override
OUString aId
OptValue< OUString > getString(sal_Int32 nAttrToken) const
ScDataBarFormatData * mpTarget
ScDataBarFormatData * mpTarget
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
A single ext entry.
std::vector< std::unique_ptr< ExtCfCondFormat > > & importExtCondFormat()
NONE
virtual void onStartElement(const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
void forEachMem(FuncType pFunc) const
CondFormatBuffer & getCondFormats() const
Returns the conditional formatting in this sheet.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const RefVector< Dxf > & getExtDxfs() const
ScConditionMode
Definition: conditio.hxx:61
ExtCfRuleContext(WorksheetContextBase &rFragment, ScDataBarFormatData *pDataBar)
T * mpTarget
ExtLstGlobalContext(WorksheetFragment &rFragment)
ScAddress GetTopLeftCorner() const
Definition: rangelst.cxx:1157
bool empty() const
Definition: rangelst.hxx:89
int i
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual void onCharacters(const OUString &rCharacters) override
virtual void onStartElement(const AttributeList &rAttribs) override
ExtLstGlobalWorkbookContext(WorkbookFragment &rFragment)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
sal_Int32 getCurrentElement() const
size_t size() const
Definition: rangelst.hxx:90
XML_TOKEN_INVALID
ExtCfDataBarRuleRef createExtCfDataBarRule(ScDataBarFormatData *pTarget)
sal_Int32 rStyleIdx
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
enumrange< T >::Iterator end(enumrange< T >)
static ScConditionMode convertToInternalOperator(sal_Int32 nToken)
Configuration options for formula interpreter.
Definition: calcconfig.hxx:43
Context handler derived from the WorkbookHelper helper class.
void finalizeImport()
Final processing after import of all style settings.
ExtGlobalContext(WorksheetContextBase &rFragment)
DefTokenId nToken
Definition: qproform.cxx:400
ExtConditionalFormattingContext(WorksheetContextBase &rFragment)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
Context handler derived from the WorksheetHelper helper class.
const ScCalcConfig & GetCalcConfig() const
Definition: document.hxx:2523
SCTAB getSheetIndex() const
Returns the index of the current sheet.
ExtLstLocalContext(WorksheetContextBase &rFragment, ScDataBarFormatData *pTarget)
std::unique_ptr< IconSetRule > mpCurrentRule
static bool GetRangeListFromString(ScRangeList &rRangeList, const OUString &rRangeListStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
Definition: rangeutl.cxx:526
std::shared_ptr< ExtCfDataBarRule > ExtCfDataBarRuleRef
OUString createExtDxfStyle(sal_Int32 nDxfId) const
virtual void onStartElement(const AttributeList &rAttribs) override
virtual Type GetType() const =0
#define SAL_WARN(area, stream)
void(* f)(TrueTypeTable *)
SC_DLLPUBLIC void SetCalcConfig(const ScCalcConfig &rConfig)
Definition: document10.cxx:200
ExtGlobalWorkbookContext(WorkbookContextBase &rFragment)
virtual void onStartElement(const AttributeList &rAttribs) override
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
sal_Int16 SCTAB
Definition: types.hxx:23
void SetStringRefSyntax(formula::FormulaGrammar::AddressConvention eConv)
Definition: calcconfig.cxx:170