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 
83 namespace {
84  bool IsSpecificTextCondMode(ScConditionMode eMode)
85  {
86  switch (eMode)
87  {
92  return true;
93  default:
94  break;
95  }
96  return false;
97  }
98 }
99 
101  : WorksheetContextBase(rFragment)
102  , nFormulaCount(0)
103  , nPriority(-1)
104  , eOperator(ScConditionMode::NONE)
105  , isPreviousElementF(false)
106 {
107 }
108 
110 {
111  if (mpCurrentRule)
112  {
113  ScFormatEntry& rFormat = **maEntries.rbegin();
115  ScIconSetFormat& rIconSet = static_cast<ScIconSetFormat&>(rFormat);
116  ScDocument& rDoc = getScDocument();
117  SCTAB nTab = getSheetIndex();
118  ScAddress aPos(0, 0, nTab);
119  mpCurrentRule->SetData(&rIconSet, &rDoc, aPos);
120  mpCurrentRule.reset();
121  }
122  if (nElement == XLS14_TOKEN(cfRule))
123  {
124  OUString aType = rAttribs.getString(XML_type, OUString());
125  OUString aId = rAttribs.getString(XML_id, OUString());
126  nPriority = rAttribs.getInteger( XML_priority, -1 );
127  maPriorities.push_back(nPriority);
128 
129  if (aType == "dataBar")
130  {
131  // an ext entry does not need to have an existing corresponding entry
132  ExtLst::const_iterator aExt = getExtLst().find( aId );
133  if(aExt == getExtLst().end())
134  return nullptr;
135 
136  ScDataBarFormatData* pInfo = aExt->second;
137  if (!pInfo)
138  {
139  return nullptr;
140  }
141  return new ExtCfRuleContext( *this, pInfo );
142  }
143  else if (aType == "iconSet")
144  {
145  ScDocument& rDoc = getScDocument();
146  mpCurrentRule.reset(new IconSetRule(*this));
147  maEntries.push_back(std::make_unique<ScIconSetFormat>(&rDoc));
148  return new IconSetContext(*this, mpCurrentRule.get());
149  }
150  else if (aType == "cellIs")
151  {
152  sal_Int32 aToken = rAttribs.getToken( XML_operator, XML_TOKEN_INVALID );
154  return this;
155  }
156  else if (aType == "containsText")
157  {
159  return this;
160  }
161  else if (aType == "notContainsText")
162  {
164  return this;
165  }
166  else if (aType == "beginsWith")
167  {
169  return this;
170  }
171  else if (aType == "endsWith")
172  {
174  return this;
175  }
176  else if (aType == "expression")
177  {
179  return this;
180  }
181  else
182  {
183  SAL_WARN("sc", "unhandled XLS14_TOKEN(cfRule) with type: " << aType);
184  }
185  }
186  else if (nElement == XLS14_TOKEN( dxf ))
187  {
188  return new DxfContext( *this, getStyles().createExtDxf() );
189  }
190  else if (nElement == XM_TOKEN( sqref ) || nElement == XM_TOKEN( f ))
191  {
192  if(nElement == XM_TOKEN( f ))
193  nFormulaCount++;
194  return this;
195  }
196 
197  return nullptr;
198 }
199 
201 {
202 }
203 
204 void ExtConditionalFormattingContext::onCharacters(const OUString& rCharacters)
205 {
206  switch (getCurrentElement())
207  {
208  case XM_TOKEN(f):
209  {
210  aChars = rCharacters;
211  isPreviousElementF = true;
212  }
213  break;
214  case XM_TOKEN(sqref):
215  {
216  aChars = rCharacters;
217  }
218  break;
219  }
220 
221 }
222 
224 {
225  switch (getCurrentElement())
226  {
227  case XM_TOKEN(f):
228  {
229  if(!IsSpecificTextCondMode(eOperator) || nFormulaCount == 2)
230  rFormulas.push_back(aChars);
231  }
232  break;
233  case XLS14_TOKEN( cfRule ):
234  {
236  nFormulaCount = 0;
237  }
238  break;
239  case XM_TOKEN(sqref):
240  {
241  ScRangeList aRange;
242  ScDocument& rDoc = getScDocument();
244  if (!bSuccess || aRange.empty())
245  break;
246 
247  SCTAB nTab = getSheetIndex();
248  for (size_t i = 0; i < aRange.size(); ++i)
249  {
250  aRange[i].aStart.SetTab(nTab);
251  aRange[i].aEnd.SetTab(nTab);
252  }
253 
254  if (isPreviousElementF) // sqref can be alone in some cases.
255  {
256  for (const OUString& rFormula : rFormulas)
257  {
258  ScAddress rPos = aRange.GetTopLeftCorner();
260  ScCondFormatEntry* pEntry = new ScCondFormatEntry(eOperator, rFormula, "", rDoc,
261  rPos, rStyle, "", "",
265  maEntries.push_back(std::unique_ptr<ScFormatEntry>(pEntry));
266  rStyleIdx++;
267  }
268 
269  assert(rFormulas.size() == maPriorities.size());
270  rFormulas.clear();
271  }
272 
273  std::vector< std::unique_ptr<ExtCfCondFormat> >& rExtFormats = getCondFormats().importExtCondFormat();
274  rExtFormats.push_back(std::make_unique<ExtCfCondFormat>(aRange, maEntries, &maPriorities));
275 
276  maPriorities.clear();
277  isPreviousElementF = false;
278  }
279  break;
280  default:
281  break;
282  }
283 }
284 
286  WorksheetContextBase(rFragment),
287  mpTarget(pTarget)
288 {
289 }
290 
292 {
293  switch( getCurrentElement() )
294  {
295  case XLS_TOKEN( extLst ):
296  if(nElement == XLS_TOKEN( ext ))
297  return this;
298  else
299  return nullptr;
300  break;
301  case XLS_TOKEN( ext ):
302  if (nElement == XLS14_TOKEN( id ))
303  return this;
304  else
305  return nullptr;
306  }
307  return nullptr;
308 }
309 
311 {
312  switch( getCurrentElement() )
313  {
314  case XLS14_TOKEN( id ):
315  break;
316  }
317 }
318 
319 void ExtLstLocalContext::onCharacters( const OUString& rChars )
320 {
321  if (getCurrentElement() == XLS14_TOKEN( id ))
322  {
323  getExtLst().insert( std::pair< OUString, ScDataBarFormatData*>(rChars, mpTarget) );
324  }
325 }
326 
328  WorksheetContextBase(rFragment)
329 {
330 }
331 
332 ContextHandlerRef ExtGlobalContext::onCreateContext( sal_Int32 nElement, const AttributeList& /*rAttribs*/ )
333 {
334  switch (nElement)
335  {
336  case XLS14_TOKEN(conditionalFormatting): return new ExtConditionalFormattingContext(*this);
337  case XLS14_TOKEN(dataValidations): return new ExtDataValidationsContext(*this);
338  }
339  return this;
340 }
341 
343 {
344 }
345 
347  WorksheetContextBase(rFragment)
348 {
349 }
350 
352 {
353  if (nElement == XLS_TOKEN( ext ))
354  return new ExtGlobalContext( *this );
355 
356  return this;
357 }
358 
360  WorkbookContextBase(rFragment)
361 {
362 }
363 
365 {
366  if (nElement == LOEXT_TOKEN(extCalcPr))
367  {
368  ScDocument& rDoc = getScDocument();
369  sal_Int32 nToken = rAttribs.getToken( XML_stringRefSyntax, XML_CalcA1 );
370  ScCalcConfig aCalcConfig = rDoc.GetCalcConfig();
371 
372  switch( nToken )
373  {
374  case XML_CalcA1:
376  break;
377  case XML_ExcelA1:
379  break;
380  case XML_ExcelR1C1:
382  break;
383  case XML_CalcA1ExcelA1:
385  break;
386  default:
388  break;
389  }
390  rDoc.SetCalcConfig(aCalcConfig);
391  }
392 
393  return this;
394 }
395 
397 {
398 }
399 
401  WorkbookContextBase(rFragment)
402 {
403 }
404 
406 {
407  if (nElement == XLS_TOKEN( ext ))
408  return new ExtGlobalWorkbookContext( *this );
409 
410  return this;
411 }
412 
413 } //namespace oox::xls
414 
415 /* 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:1155
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:44
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:399
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:2520
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:199
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:165