Bug Summary

File:home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx
Warning:line 468, column 57
The left operand of '!=' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name XMLStylesExportHelper.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SC_DLLIMPLEMENTATION -D SC_INFO_OSVERSION="LINUX" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/clew/source/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sc/source/core/inc -I /home/maarten/src/libreoffice/core/sc/source/filter/inc -I /home/maarten/src/libreoffice/core/sc/source/ui/inc -I /home/maarten/src/libreoffice/core/sc/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sc/sdi -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx
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 "XMLStylesExportHelper.hxx"
21#include <tools/lineend.hxx>
22#include <unonames.hxx>
23#include "xmlexprt.hxx"
24#include <document.hxx>
25#include <rangeutl.hxx>
26#include <xmloff/xmltoken.hxx>
27#include <xmloff/xmlnamespace.hxx>
28#include <xmloff/XMLEventExport.hxx>
29#include <xmloff/namespacemap.hxx>
30#include <com/sun/star/uno/Reference.h>
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <com/sun/star/sheet/XSheetCondition.hpp>
33#include <com/sun/star/sheet/TableValidationVisibility.hpp>
34#include <comphelper/extract.hxx>
35#include <comphelper/propertysequence.hxx>
36#include <sfx2/app.hxx>
37#include <o3tl/safeint.hxx>
38#include <osl/diagnose.h>
39
40using namespace com::sun::star;
41using namespace xmloff::token;
42
43ScMyValidation::ScMyValidation()
44 : sName(),
45 sErrorMessage(),
46 sErrorTitle(),
47 sInputMessage(),
48 sInputTitle(),
49 sFormula1(),
50 sFormula2(),
51 aAlertStyle(sheet::ValidationAlertStyle_STOP),
52 aValidationType(sheet::ValidationType_ANY),
53 aOperator(sheet::ConditionOperator_NONE),
54 nShowList(0),
55 bShowErrorMessage(false),
56 bShowInputMessage(false),
57 bIgnoreBlanks(false)
58{
59}
60
61bool ScMyValidation::IsEqual(const ScMyValidation& aVal) const
62{
63 return aVal.bIgnoreBlanks == bIgnoreBlanks &&
64 aVal.bShowInputMessage == bShowInputMessage &&
65 aVal.bShowErrorMessage == bShowErrorMessage &&
66 aVal.aBaseCell == aBaseCell &&
67 aVal.aAlertStyle == aAlertStyle &&
68 aVal.aValidationType == aValidationType &&
69 aVal.aOperator == aOperator &&
70 aVal.sErrorTitle == sErrorTitle &&
71 aVal.sInputTitle == sInputTitle &&
72 aVal.sErrorMessage == sErrorMessage &&
73 aVal.sInputMessage == sInputMessage &&
74 aVal.sFormula1 == sFormula1 &&
75 aVal.sFormula2 == sFormula2;
76}
77
78constexpr OUStringLiteral gsERRALSTY(u"" SC_UNONAME_ERRALSTY"ErrorAlertStyle");
79constexpr OUStringLiteral gsIGNOREBL(u"" SC_UNONAME_IGNOREBL"IgnoreBlankCells");
80constexpr OUStringLiteral gsSHOWLIST(u"" SC_UNONAME_SHOWLIST"ShowList");
81constexpr OUStringLiteral gsTYPE(u"" SC_UNONAME_TYPE"Type");
82constexpr OUStringLiteral gsSHOWINP(u"" SC_UNONAME_SHOWINP"ShowInputMessage");
83constexpr OUStringLiteral gsSHOWERR(u"" SC_UNONAME_SHOWERR"ShowErrorMessage");
84constexpr OUStringLiteral gsINPTITLE(u"" SC_UNONAME_INPTITLE"InputTitle");
85constexpr OUStringLiteral gsINPMESS(u"" SC_UNONAME_INPMESS"InputMessage");
86constexpr OUStringLiteral gsERRTITLE(u"" SC_UNONAME_ERRTITLE"ErrorTitle");
87constexpr OUStringLiteral gsERRMESS(u"" SC_UNONAME_ERRMESS"ErrorMessage");
88
89ScMyValidationsContainer::ScMyValidationsContainer()
90 : aValidationVec()
91{
92}
93
94ScMyValidationsContainer::~ScMyValidationsContainer()
95{
96}
97
98void ScMyValidationsContainer::AddValidation(const uno::Any& aTempAny,
99 sal_Int32& nValidationIndex)
100{
101 uno::Reference<beans::XPropertySet> xPropertySet(aTempAny, uno::UNO_QUERY);
102 if (!xPropertySet.is())
103 return;
104
105 OUString sErrorMessage;
106 xPropertySet->getPropertyValue(gsERRMESS) >>= sErrorMessage;
107 OUString sErrorTitle;
108 xPropertySet->getPropertyValue(gsERRTITLE) >>= sErrorTitle;
109 OUString sInputMessage;
110 xPropertySet->getPropertyValue(gsINPMESS) >>= sInputMessage;
111 OUString sInputTitle;
112 xPropertySet->getPropertyValue(gsINPTITLE) >>= sInputTitle;
113 bool bShowErrorMessage = ::cppu::any2bool(xPropertySet->getPropertyValue(gsSHOWERR));
114 bool bShowInputMessage = ::cppu::any2bool(xPropertySet->getPropertyValue(gsSHOWINP));
115 sheet::ValidationType aValidationType;
116 xPropertySet->getPropertyValue(gsTYPE) >>= aValidationType;
117 if (!bShowErrorMessage && !bShowInputMessage && aValidationType == sheet::ValidationType_ANY &&
118 sErrorMessage.isEmpty() && sErrorTitle.isEmpty() && sInputMessage.isEmpty() && sInputTitle.isEmpty())
119 return;
120
121 ScMyValidation aValidation;
122 aValidation.sErrorMessage = sErrorMessage;
123 aValidation.sErrorTitle = sErrorTitle;
124 aValidation.sInputMessage = sInputMessage;
125 aValidation.sInputTitle = sInputTitle;
126 aValidation.bShowErrorMessage = bShowErrorMessage;
127 aValidation.bShowInputMessage = bShowInputMessage;
128 aValidation.aValidationType = aValidationType;
129 aValidation.bIgnoreBlanks = ::cppu::any2bool(xPropertySet->getPropertyValue(gsIGNOREBL));
130 xPropertySet->getPropertyValue(gsSHOWLIST) >>= aValidation.nShowList;
131 xPropertySet->getPropertyValue(gsERRALSTY) >>= aValidation.aAlertStyle;
132 uno::Reference<sheet::XSheetCondition> xCondition(xPropertySet, uno::UNO_QUERY);
133 if (xCondition.is())
134 {
135 aValidation.sFormula1 = xCondition->getFormula1();
136 aValidation.sFormula2 = xCondition->getFormula2();
137 aValidation.aOperator = xCondition->getOperator();
138 table::CellAddress aCellAddress= xCondition->getSourcePosition();
139 aValidation.aBaseCell = ScAddress( static_cast<SCCOL>(aCellAddress.Column), static_cast<SCROW>(aCellAddress.Row), aCellAddress.Sheet );
140 }
141 //ScMyValidationRange aValidationRange;
142 bool bEqualFound(false);
143 sal_Int32 i(0);
144 sal_Int32 nCount(aValidationVec.size());
145 while (i < nCount && !bEqualFound)
146 {
147 bEqualFound = aValidationVec[i].IsEqual(aValidation);
148 if (!bEqualFound)
149 ++i;
150 }
151 if (bEqualFound)
152 nValidationIndex = i;
153 else
154 {
155 sal_Int32 nNameIndex(nCount + 1);
156 OUString sCount(OUString::number(nNameIndex));
157 aValidation.sName += "val";
158 aValidation.sName += sCount;
159 aValidationVec.push_back(aValidation);
160 nValidationIndex = nCount;
161 }
162}
163
164OUString ScMyValidationsContainer::GetCondition(ScXMLExport& rExport, const ScMyValidation& aValidation)
165{
166 /* ATTENTION! Should the condition to not write sheet::ValidationType_ANY
167 * ever be changed, adapt the conditional call of
168 * MarkUsedExternalReferences() in
169 * ScTableValidationObj::ScTableValidationObj() accordingly! */
170 OUString sCondition;
171 if (aValidation.aValidationType != sheet::ValidationType_ANY)
172 {
173 switch (aValidation.aValidationType)
174 {
175 //case sheet::ValidationType_CUSTOM
176 case sheet::ValidationType_DATE :
177 sCondition += "cell-content-is-date()";
178 break;
179 case sheet::ValidationType_DECIMAL :
180 sCondition += "cell-content-is-decimal-number()";
181 break;
182 case sheet::ValidationType_LIST :
183 sCondition += "cell-content-is-in-list(" + aValidation.sFormula1 + ")";
184 break;
185 case sheet::ValidationType_TEXT_LEN :
186 if (aValidation.aOperator != sheet::ConditionOperator_BETWEEN &&
187 aValidation.aOperator != sheet::ConditionOperator_NOT_BETWEEN)
188 sCondition += "cell-content-text-length()";
189 break;
190 case sheet::ValidationType_TIME :
191 sCondition += "cell-content-is-time()";
192 break;
193 case sheet::ValidationType_WHOLE :
194 sCondition += "cell-content-is-whole-number()";
195 break;
196 case sheet::ValidationType_CUSTOM :
197 sCondition += "is-true-formula(" + aValidation.sFormula1 + ")";
198 break;
199 default:
200 {
201 // added to avoid warnings
202 }
203 }
204 if (aValidation.aValidationType != sheet::ValidationType_LIST &&
205 aValidation.aValidationType != sheet::ValidationType_CUSTOM &&
206 (!aValidation.sFormula1.isEmpty() ||
207 ((aValidation.aOperator == sheet::ConditionOperator_BETWEEN ||
208 aValidation.aOperator == sheet::ConditionOperator_NOT_BETWEEN) &&
209 !aValidation.sFormula2.isEmpty())))
210 {
211 if (aValidation.aValidationType != sheet::ValidationType_TEXT_LEN)
212 sCondition += " and ";
213 if (aValidation.aOperator != sheet::ConditionOperator_BETWEEN &&
214 aValidation.aOperator != sheet::ConditionOperator_NOT_BETWEEN)
215 {
216 if (aValidation.aValidationType != sheet::ValidationType_TEXT_LEN)
217 sCondition += "cell-content()";
218 switch (aValidation.aOperator)
219 {
220 case sheet::ConditionOperator_EQUAL :
221 sCondition += "=";
222 break;
223 case sheet::ConditionOperator_GREATER :
224 sCondition += ">";
225 break;
226 case sheet::ConditionOperator_GREATER_EQUAL :
227 sCondition += ">=";
228 break;
229 case sheet::ConditionOperator_LESS :
230 sCondition += "<";
231 break;
232 case sheet::ConditionOperator_LESS_EQUAL :
233 sCondition += "<=";
234 break;
235 case sheet::ConditionOperator_NOT_EQUAL :
236 sCondition += "!=";
237 break;
238 default:
239 {
240 // added to avoid warnings
241 }
242 }
243 sCondition += aValidation.sFormula1;
244 }
245 else
246 {
247 if (aValidation.aValidationType == sheet::ValidationType_TEXT_LEN)
248 {
249 if (aValidation.aOperator == sheet::ConditionOperator_BETWEEN)
250 sCondition += "cell-content-text-length-is-between(";
251 else
252 sCondition += "cell-content-text-length-is-not-between(";
253 }
254 else
255 {
256 if (aValidation.aOperator == sheet::ConditionOperator_BETWEEN)
257 sCondition += "cell-content-is-between(";
258 else
259 sCondition += "cell-content-is-not-between(";
260 }
261 sCondition += aValidation.sFormula1 + "," + aValidation.sFormula2 + ")";
262 }
263 }
264 else
265 if (aValidation.aValidationType == sheet::ValidationType_TEXT_LEN)
266 sCondition.clear();
267 }
268 if (!sCondition.isEmpty())
269 {
270 const formula::FormulaGrammar::Grammar eGrammar = rExport.GetDocument()->GetStorageGrammar();
271 sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
272 sCondition = rExport.GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sCondition, false );
273 }
274
275 return sCondition;
276}
277
278OUString ScMyValidationsContainer::GetBaseCellAddress(const ScDocument* pDoc, const ScAddress& aCell)
279{
280 OUString sAddress;
281 ScRangeStringConverter::GetStringFromAddress( sAddress, aCell, pDoc, ::formula::FormulaGrammar::CONV_OOO );
282 return sAddress;
283}
284
285void ScMyValidationsContainer::WriteMessage(ScXMLExport& rExport,
286 const OUString& sTitle, const OUString& sOUMessage,
287 const bool bShowMessage, const bool bIsHelpMessage)
288{
289 if (!sTitle.isEmpty())
290 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TITLE, sTitle);
291 if (bShowMessage)
292 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_TRUE);
293 else
294 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_FALSE);
295 std::unique_ptr<SvXMLElementExport> pMessage;
296 if (bIsHelpMessage)
297 pMessage.reset(new SvXMLElementExport(rExport, XML_NAMESPACE_TABLE, XML_HELP_MESSAGE, true, true));
298 else
299 pMessage.reset(new SvXMLElementExport(rExport, XML_NAMESPACE_TABLE, XML_ERROR_MESSAGE, true, true));
300 if (sOUMessage.isEmpty())
301 return;
302
303 sal_Int32 i(0);
304 OUStringBuffer sTemp;
305 OUString sText(convertLineEnd(sOUMessage, LINEEND_LF));
306 bool bPrevCharWasSpace(true);
307 while(i < sText.getLength())
308 {
309 if( sText[i] == '\n')
310 {
311 SvXMLElementExport aElemP(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
312 rExport.GetTextParagraphExport()->exportCharacterData(sTemp.makeStringAndClear(), bPrevCharWasSpace);
313 bPrevCharWasSpace = true; // reset for start of next paragraph
314 }
315 else
316 sTemp.append(sText[i]);
317 ++i;
318 }
319 if (!sTemp.isEmpty())
320 {
321 SvXMLElementExport aElemP(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
322 rExport.GetTextParagraphExport()->exportCharacterData(sTemp.makeStringAndClear(), bPrevCharWasSpace);
323 }
324}
325
326void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
327{
328 if (aValidationVec.empty())
329 return;
330
331 SvXMLElementExport aElemVs(rExport, XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATIONS, true, true);
332 for (const auto& rValidation : aValidationVec)
333 {
334 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, rValidation.sName);
335 OUString sCondition(GetCondition(rExport, rValidation));
336 if (!sCondition.isEmpty())
337 {
338 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CONDITION, sCondition);
339 if (rValidation.bIgnoreBlanks)
340 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ALLOW_EMPTY_CELL, XML_TRUE);
341 else
342 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ALLOW_EMPTY_CELL, XML_FALSE);
343 if (rValidation.aValidationType == sheet::ValidationType_LIST)
344 {
345 switch (rValidation.nShowList)
346 {
347 case sheet::TableValidationVisibility::INVISIBLE:
348 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_LIST, XML_NO);
349 break;
350 case sheet::TableValidationVisibility::UNSORTED:
351 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_LIST, XML_UNSORTED);
352 break;
353 case sheet::TableValidationVisibility::SORTEDASCENDING:
354 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_LIST, XML_SORT_ASCENDING);
355 break;
356 default:
357 OSL_FAIL("unknown ListType")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "357" ": "), "%s", "unknown ListType"); } } while (false
)
;
358 }
359 }
360 }
361 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, GetBaseCellAddress(rExport.GetDocument(), rValidation.aBaseCell));
362 SvXMLElementExport aElemV(rExport, XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION, true, true);
363 if (rValidation.bShowInputMessage || !rValidation.sInputMessage.isEmpty() || !rValidation.sInputTitle.isEmpty())
364 {
365 WriteMessage(rExport, rValidation.sInputTitle, rValidation.sInputMessage, rValidation.bShowInputMessage, true);
366 }
367 if (rValidation.bShowErrorMessage || !rValidation.sErrorMessage.isEmpty() || !rValidation.sErrorTitle.isEmpty())
368 {
369 switch (rValidation.aAlertStyle)
370 {
371 case sheet::ValidationAlertStyle_INFO :
372 {
373 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MESSAGE_TYPE, XML_INFORMATION);
374 WriteMessage(rExport, rValidation.sErrorTitle, rValidation.sErrorMessage, rValidation.bShowErrorMessage, false);
375 }
376 break;
377 case sheet::ValidationAlertStyle_WARNING :
378 {
379 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MESSAGE_TYPE, XML_WARNING);
380 WriteMessage(rExport, rValidation.sErrorTitle, rValidation.sErrorMessage, rValidation.bShowErrorMessage, false);
381 }
382 break;
383 case sheet::ValidationAlertStyle_STOP :
384 {
385 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MESSAGE_TYPE, XML_STOP);
386 WriteMessage(rExport, rValidation.sErrorTitle, rValidation.sErrorMessage, rValidation.bShowErrorMessage, false);
387 }
388 break;
389 case sheet::ValidationAlertStyle_MACRO :
390 {
391 {
392 //rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, aItr->sErrorTitle);
393 if (rValidation.bShowErrorMessage)
394 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_EXECUTE, XML_TRUE);
395 else
396 rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_EXECUTE, XML_FALSE);
397 SvXMLElementExport aEMElem(rExport, XML_NAMESPACE_TABLE, XML_ERROR_MACRO, true, true);
398 }
399 {
400 // #i47525# for a script URL the type and the property name for the URL
401 // are both "Script", for a simple macro name the type is "StarBasic"
402 // and the property name is "MacroName".
403 bool bScriptURL = SfxApplication::IsXScriptURL( rValidation.sErrorTitle );
404
405 const OUString sScript("Script");
406 uno::Sequence<beans::PropertyValue> aSeq( comphelper::InitPropertySequence({
407 { "EventType", uno::Any(bScriptURL ? sScript : OUString("StarBasic")) },
408 { "Library", uno::Any(OUString()) },
409 { bScriptURL ? sScript : OUString("MacroName"), uno::Any(rValidation.sErrorTitle) }
410 }));
411 // 2) export the sequence
412 rExport.GetEventExport().ExportSingleEvent( aSeq, "OnError");
413 }
414 }
415 break;
416 default:
417 {
418 // added to avoid warnings
419 }
420 }
421 }
422 }
423}
424
425const OUString& ScMyValidationsContainer::GetValidationName(const sal_Int32 nIndex)
426{
427 OSL_ENSURE( o3tl::make_unsigned(nIndex) < aValidationVec.size(), "out of range" )do { if (true && (!(o3tl::make_unsigned(nIndex) < aValidationVec
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "427" ": "), "%s", "out of range"); } } while (false)
;
428 return aValidationVec[nIndex].sName;
429}
430
431sal_Int32 ScMyDefaultStyles::GetStyleNameIndex(const ScFormatRangeStyles* pCellStyles,
432 const sal_Int32 nTable, const sal_Int32 nPos,
433 const sal_Int32 i, bool& bIsAutoStyle)
434{
435 return pCellStyles->GetStyleNameIndex(nTable, i, nPos, bIsAutoStyle);
11
Calling 'ScFormatRangeStyles::GetStyleNameIndex'
18
Returning from 'ScFormatRangeStyles::GetStyleNameIndex'
19
Returning without writing to 'bIsAutoStyle'
436}
437
438void ScMyDefaultStyles::FillDefaultStyles(const sal_Int32 nTable,
439 const sal_Int32 nLastRow, const sal_Int32 nLastCol,
440 const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc)
441{
442 maColDefaults.clear();
443 maColDefaults.resize(nLastCol + 1);
444 if (!pDoc)
1
Assuming 'pDoc' is non-null
2
Taking false branch
445 return ;
446
447 SCTAB nTab = static_cast<SCTAB>(nTable);
448 pDoc->CreateColumnIfNotExists(nTab, nLastCol);
449 sal_Int32 nPos;
450 ScMyDefaultStyleList* pDefaults = &maColDefaults;
451 bool bPrevAutoStyle(false);
452 bool bIsAutoStyle;
3
'bIsAutoStyle' declared without an initial value
453 sal_Int32 nPrevIndex(0);
454 sal_Int32 nRepeat(0);
455 for (sal_Int32 i = nLastCol; i >= 0; --i)
4
Assuming 'i' is >= 0
5
Loop condition is true. Entering loop body
7
Assuming 'i' is >= 0
8
Loop condition is true. Entering loop body
456 {
457 pDoc->GetColDefault(nTab, static_cast<SCCOL>(i), static_cast<SCROW>(nLastRow), nPos);
458 if (!nRepeat
5.1
'nRepeat' is 0
8.1
'nRepeat' is 1
)
6
Taking true branch
9
Taking false branch
459 {
460 nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i, bPrevAutoStyle);
461 (*pDefaults)[i].nIndex = nPrevIndex;
462 (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
463 nRepeat = 1;
464 }
465 else
466 {
467 sal_Int32 nIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i, bIsAutoStyle);
10
Calling 'ScMyDefaultStyles::GetStyleNameIndex'
20
Returning from 'ScMyDefaultStyles::GetStyleNameIndex'
468 if ((nIndex
20.1
'nIndex' is equal to 'nPrevIndex'
!= nPrevIndex) || (bIsAutoStyle != bPrevAutoStyle))
21
The left operand of '!=' is a garbage value
469 {
470 nRepeat = 1;
471 nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i, bPrevAutoStyle);
472 (*pDefaults)[i].nIndex = nPrevIndex;
473 (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
474 }
475 else
476 {
477 (*pDefaults)[i].nIndex = nPrevIndex;
478 (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
479 ++nRepeat;
480 if (nRepeat > 1)
481 (*pDefaults)[i].nRepeat = nRepeat;
482 }
483 }
484 }
485}
486
487ScMyRowFormatRange::ScMyRowFormatRange()
488 : nStartColumn(0),
489 nRepeatColumns(0),
490 nRepeatRows(0),
491 nIndex(-1),
492 nValidationIndex(-1),
493 bIsAutoStyle(true)
494{
495}
496
497bool ScMyRowFormatRange::operator< (const ScMyRowFormatRange& rRange) const
498{
499 return (nStartColumn < rRange.nStartColumn);
500}
501
502ScRowFormatRanges::ScRowFormatRanges()
503 : aRowFormatRanges(),
504 pColDefaults(nullptr),
505 nSize(0)
506{
507}
508
509ScRowFormatRanges::ScRowFormatRanges(const ScRowFormatRanges* pRanges)
510 : aRowFormatRanges(pRanges->aRowFormatRanges),
511 pColDefaults(pRanges->pColDefaults),
512 nSize(pRanges->nSize)
513{
514}
515
516ScRowFormatRanges::~ScRowFormatRanges()
517{
518}
519
520void ScRowFormatRanges::Clear()
521{
522 aRowFormatRanges.clear();
523 nSize = 0;
524}
525
526void ScRowFormatRanges::AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
527 const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange)
528{
529 sal_Int32 nIndex(-1);
530 if ((nPrevIndex != rFormatRange.nIndex) ||
531 (bPrevAutoStyle != rFormatRange.bIsAutoStyle))
532 nIndex = rFormatRange.nIndex;
533
534 bool bInserted(false);
535 if (!aRowFormatRanges.empty())
536 {
537 ScMyRowFormatRange& rRange(aRowFormatRanges.back());
538 if ((nPrevStartCol == (rRange.nStartColumn + rRange.nRepeatColumns))
539 && (rRange.bIsAutoStyle == rFormatRange.bIsAutoStyle) && (rRange.nIndex == nIndex)
540 && (rRange.nValidationIndex == rFormatRange.nValidationIndex))
541 {
542 if (rFormatRange.nRepeatRows < rRange.nRepeatRows)
543 rRange.nRepeatRows = rFormatRange.nRepeatRows;
544 rRange.nRepeatColumns += nRepeat;
545 bInserted = true;
546 }
547 }
548 if (!bInserted)
549 {
550 ScMyRowFormatRange aRange;
551 aRange.nStartColumn = nPrevStartCol;
552 aRange.nRepeatColumns = nRepeat;
553 aRange.nRepeatRows = rFormatRange.nRepeatRows;
554 aRange.nValidationIndex = rFormatRange.nValidationIndex;
555 aRange.bIsAutoStyle = rFormatRange.bIsAutoStyle;
556 aRange.nIndex = nIndex;
557 aRowFormatRanges.push_back(aRange);
558 ++nSize;
559 }
560}
561
562void ScRowFormatRanges::AddRange(const ScMyRowFormatRange& rFormatRange)
563{
564 OSL_ENSURE(pColDefaults, "no column defaults")do { if (true && (!(pColDefaults))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "564" ": "), "%s", "no column defaults"); } } while (false
)
;
565 if (!pColDefaults)
566 return;
567 sal_Int32 nPrevIndex = -1;
568 bool bPrevAutoStyle = true;
569
570 sal_uInt32 nPrevStartCol(rFormatRange.nStartColumn);
571 OSL_ENSURE( static_cast<size_t>(nPrevStartCol) < pColDefaults->size(), "nPrevStartCol out of bounds")do { if (true && (!(static_cast<size_t>(nPrevStartCol
) < pColDefaults->size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "571" ": "), "%s", "nPrevStartCol out of bounds"); } } while
(false)
;
572 sal_uInt32 nRepeat;
573 if (static_cast<size_t>(nPrevStartCol) < pColDefaults->size())
574 {
575 nRepeat = (*pColDefaults)[nPrevStartCol].nRepeat;
576 nPrevIndex = (*pColDefaults)[nPrevStartCol].nIndex;
577 bPrevAutoStyle = (*pColDefaults)[nPrevStartCol].bIsAutoStyle;
578 }
579 else
580 {
581 /* Again, this is to prevent out-of-bounds accesses, so FIXME
582 * elsewhere! */
583 if (pColDefaults->empty())
584 {
585 nRepeat = 1;
586 nPrevIndex = -1;
587 bPrevAutoStyle = false;
588 }
589 else
590 {
591 nRepeat = (*pColDefaults)[pColDefaults->size()-1].nRepeat;
592 nPrevIndex = (*pColDefaults)[pColDefaults->size()-1].nIndex;
593 bPrevAutoStyle = (*pColDefaults)[pColDefaults->size()-1].bIsAutoStyle;
594 }
595 }
596 sal_uInt32 nEnd = nPrevStartCol + rFormatRange.nRepeatColumns;
597 for(sal_uInt32 i = nPrevStartCol + nRepeat; i < nEnd && i < pColDefaults->size(); i += (*pColDefaults)[i].nRepeat)
598 {
599 OSL_ENSURE(sal_uInt32(nPrevStartCol + nRepeat) <= nEnd, "something went wrong")do { if (true && (!(sal_uInt32(nPrevStartCol + nRepeat
) <= nEnd))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "599" ": "), "%s", "something went wrong"); } } while (false
)
;
600 if ((nPrevIndex != (*pColDefaults)[i].nIndex) ||
601 (bPrevAutoStyle != (*pColDefaults)[i].bIsAutoStyle))
602 {
603 AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
604 nPrevStartCol = i;
605 nRepeat = (*pColDefaults)[i].nRepeat;
606 nPrevIndex = (*pColDefaults)[i].nIndex;
607 bPrevAutoStyle = (*pColDefaults)[i].bIsAutoStyle;
608 }
609 else
610 nRepeat += (*pColDefaults)[i].nRepeat;
611 }
612 if (sal_uInt32(nPrevStartCol + nRepeat) > nEnd)
613 nRepeat = nEnd - nPrevStartCol;
614 AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
615
616}
617
618bool ScRowFormatRanges::GetNext(ScMyRowFormatRange& aFormatRange)
619{
620 ScMyRowFormatRangesList::iterator aItr(aRowFormatRanges.begin());
621 if (aItr != aRowFormatRanges.end())
622 {
623 aFormatRange = *aItr;
624 aRowFormatRanges.erase(aItr);
625 --nSize;
626 return true;
627 }
628 return false;
629}
630
631sal_Int32 ScRowFormatRanges::GetMaxRows() const
632{
633 sal_Int32 nMaxRows(0);
634 if (!aRowFormatRanges.empty())
635 {
636 auto aItr = std::min_element(aRowFormatRanges.begin(), aRowFormatRanges.end(),
637 [](const ScMyRowFormatRange& a, const ScMyRowFormatRange& b) { return a.nRepeatRows < b.nRepeatRows; });
638 nMaxRows = (*aItr).nRepeatRows;
639 }
640 else
641 {
642 OSL_FAIL("no ranges found")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "642" ": "), "%s", "no ranges found"); } } while (false)
;
643 }
644 return nMaxRows;
645}
646
647void ScRowFormatRanges::Sort()
648{
649 aRowFormatRanges.sort();
650}
651
652ScMyFormatRange::ScMyFormatRange()
653 : nStyleNameIndex(-1)
654 , nValidationIndex(-1)
655 , nNumberFormat(0)
656 , bIsAutoStyle(true)
657{
658}
659
660bool ScMyFormatRange::operator<(const ScMyFormatRange& rRange) const
661{
662 if (aRangeAddress.StartRow < rRange.aRangeAddress.StartRow)
663 return true;
664 else
665 if (aRangeAddress.StartRow == rRange.aRangeAddress.StartRow)
666 return (aRangeAddress.StartColumn < rRange.aRangeAddress.StartColumn);
667 else
668 return false;
669}
670
671ScFormatRangeStyles::ScFormatRangeStyles()
672 : aTables(),
673 aStyleNames(),
674 aAutoStyleNames(),
675 pColDefaults(nullptr)
676{
677}
678
679ScFormatRangeStyles::~ScFormatRangeStyles()
680{
681}
682
683void ScFormatRangeStyles::AddNewTable(const sal_Int32 nTable)
684{
685 sal_Int32 nSize = aTables.size() - 1;
686 if (nTable > nSize)
687 for (sal_Int32 i = nSize; i < nTable; ++i)
688 {
689 aTables.emplace_back();
690 }
691}
692
693bool ScFormatRangeStyles::AddStyleName(OUString const & rString, sal_Int32& rIndex, const bool bIsAutoStyle)
694{
695 if (bIsAutoStyle)
696 {
697 aAutoStyleNames.push_back(rString);
698 rIndex = aAutoStyleNames.size() - 1;
699 return true;
700 }
701 else
702 {
703 sal_Int32 nCount(aStyleNames.size());
704 bool bFound(false);
705 sal_Int32 i(nCount - 1);
706 while ((i >= 0) && (!bFound))
707 {
708 if (aStyleNames.at(i) == rString)
709 bFound = true;
710 else
711 i--;
712 }
713 if (bFound)
714 {
715 rIndex = i;
716 return false;
717 }
718 else
719 {
720 aStyleNames.push_back(rString);
721 rIndex = aStyleNames.size() - 1;
722 return true;
723 }
724 }
725}
726
727sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix, bool& bIsAutoStyle)
728{
729 sal_Int32 nPrefixLength(rPrefix.getLength());
730 OUString sTemp(rString.copy(nPrefixLength));
731 sal_Int32 nIndex(sTemp.toInt32());
732 if (nIndex > 0 && o3tl::make_unsigned(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1) == rString)
733 {
734 bIsAutoStyle = true;
735 return nIndex - 1;
736 }
737 else
738 {
739 sal_Int32 i(0);
740 bool bFound(false);
741 while (!bFound && o3tl::make_unsigned(i) < aStyleNames.size())
742 {
743 if (aStyleNames[i] == rString)
744 bFound = true;
745 else
746 ++i;
747 }
748 if (bFound)
749 {
750 bIsAutoStyle = false;
751 return i;
752 }
753 else
754 {
755 i = 0;
756 while (!bFound && o3tl::make_unsigned(i) < aAutoStyleNames.size())
757 {
758 if (aAutoStyleNames[i] == rString)
759 bFound = true;
760 else
761 ++i;
762 }
763 if (bFound)
764 {
765 bIsAutoStyle = true;
766 return i;
767 }
768 else
769 return -1;
770 }
771 }
772}
773
774sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
775 const sal_Int32 nColumn, const sal_Int32 nRow, bool& bIsAutoStyle) const
776{
777 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "777" ": "), "%s", "wrong table"); } } while (false)
;
12
Assuming the condition is true
13
Taking false branch
14
Loop condition is false. Exiting loop
778 if (o3tl::make_unsigned(nTable) >= aTables.size())
15
Assuming the condition is true
16
Taking true branch
779 return -1;
17
Returning without writing to 'bIsAutoStyle'
780 for (const ScMyFormatRange & rFormatRange : aTables[nTable])
781 {
782 if ((rFormatRange.aRangeAddress.StartColumn <= nColumn) &&
783 (rFormatRange.aRangeAddress.EndColumn >= nColumn) &&
784 (rFormatRange.aRangeAddress.StartRow <= nRow) &&
785 (rFormatRange.aRangeAddress.EndRow >= nRow))
786 {
787 bIsAutoStyle = rFormatRange.bIsAutoStyle;
788 return rFormatRange.nStyleNameIndex;
789 }
790 }
791 return -1;
792}
793
794sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
795 bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow)
796{
797 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "797" ": "), "%s", "wrong table"); } } while (false)
;
798 if (o3tl::make_unsigned(nTable) >= aTables.size())
799 return -1;
800 ScMyFormatRangeAddresses& rFormatRanges(aTables[nTable]);
801 ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
802 ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
803 while (aItr != aEndItr)
804 {
805 if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
806 ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
807 ((*aItr).aRangeAddress.StartRow <= nRow) &&
808 ((*aItr).aRangeAddress.EndRow >= nRow))
809 {
810 bIsAutoStyle = aItr->bIsAutoStyle;
811 nValidationIndex = aItr->nValidationIndex;
812 nNumberFormat = aItr->nNumberFormat;
813 OSL_ENSURE( o3tl::make_unsigned(nColumn) < pColDefaults->size(), "nColumn out of bounds")do { if (true && (!(o3tl::make_unsigned(nColumn) <
pColDefaults->size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "813" ": "), "%s", "nColumn out of bounds"); } } while (
false)
;
814 if (o3tl::make_unsigned(nColumn) < pColDefaults->size() &&
815 ((*pColDefaults)[nColumn].nIndex != -1) &&
816 ((*pColDefaults)[nColumn].nIndex == (*aItr).nStyleNameIndex) &&
817 ((*pColDefaults)[nColumn].bIsAutoStyle == (*aItr).bIsAutoStyle))
818 return -1;
819 else
820 return (*aItr).nStyleNameIndex;
821 }
822 else
823 {
824 if ((*aItr).aRangeAddress.EndRow < nRemoveBeforeRow)
825 aItr = rFormatRanges.erase(aItr);
826 else
827 ++aItr;
828 }
829 }
830 return -1;
831}
832
833void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
834 const sal_Int32 nTable, ScRowFormatRanges* pRowFormatRanges)
835{
836 sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
837 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "837" ": "), "%s", "wrong table"); } } while (false)
;
838 ScMyFormatRangeAddresses& rFormatRanges(aTables[nTable]);
839 ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
840 ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
841 sal_Int32 nColumns = 0;
842 while (aItr != aEndItr && nColumns < nTotalColumns)
843 {
844 if (((*aItr).aRangeAddress.StartRow <= nRow) &&
845 ((*aItr).aRangeAddress.EndRow >= nRow))
846 {
847 if ((((*aItr).aRangeAddress.StartColumn <= nStartColumn) &&
848 ((*aItr).aRangeAddress.EndColumn >= nStartColumn)) ||
849 (((*aItr).aRangeAddress.StartColumn <= nEndColumn) &&
850 ((*aItr).aRangeAddress.EndColumn >= nEndColumn)) ||
851 (((*aItr).aRangeAddress.StartColumn >= nStartColumn) &&
852 ((*aItr).aRangeAddress.EndColumn <= nEndColumn)))
853 {
854 ScMyRowFormatRange aRange;
855 aRange.nIndex = aItr->nStyleNameIndex;
856 aRange.nValidationIndex = aItr->nValidationIndex;
857 aRange.bIsAutoStyle = aItr->bIsAutoStyle;
858 if ((aItr->aRangeAddress.StartColumn < nStartColumn) &&
859 (aItr->aRangeAddress.EndColumn >= nStartColumn))
860 {
861 if (aItr->aRangeAddress.EndColumn >= nEndColumn)
862 aRange.nRepeatColumns = nTotalColumns;
863 else
864 aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - nStartColumn + 1;
865 aRange.nStartColumn = nStartColumn;
866 }
867 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
868 (aItr->aRangeAddress.EndColumn <= nEndColumn))
869 {
870 aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - aItr->aRangeAddress.StartColumn + 1;
871 aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
872 }
873 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
874 (aItr->aRangeAddress.StartColumn <= nEndColumn) &&
875 (aItr->aRangeAddress.EndColumn > nEndColumn))
876 {
877 aRange.nRepeatColumns = nEndColumn - aItr->aRangeAddress.StartColumn + 1;
878 aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
879 }
880 aRange.nRepeatRows = aItr->aRangeAddress.EndRow - nRow + 1;
881 pRowFormatRanges->AddRange(aRange);
882 nColumns += aRange.nRepeatColumns;
883 }
884 ++aItr;
885 }
886 else
887 if(aItr->aRangeAddress.EndRow < nRow)
888 aItr = rFormatRanges.erase(aItr);
889 else
890 ++aItr;
891 }
892 pRowFormatRanges->Sort();
893}
894
895void ScFormatRangeStyles::AddRangeStyleName(const table::CellRangeAddress& rCellRangeAddress,
896 const sal_Int32 nStringIndex, const bool bIsAutoStyle, const sal_Int32 nValidationIndex,
897 const sal_Int32 nNumberFormat)
898{
899 ScMyFormatRange aFormatRange;
900 aFormatRange.aRangeAddress = rCellRangeAddress;
901 aFormatRange.nStyleNameIndex = nStringIndex;
902 aFormatRange.nValidationIndex = nValidationIndex;
903 aFormatRange.nNumberFormat = nNumberFormat;
904 aFormatRange.bIsAutoStyle = bIsAutoStyle;
905 OSL_ENSURE(o3tl::make_unsigned(rCellRangeAddress.Sheet) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(rCellRangeAddress
.Sheet) < aTables.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "905" ": "), "%s", "wrong table"); } } while (false)
;
906 ScMyFormatRangeAddresses& rFormatRanges(aTables[rCellRangeAddress.Sheet]);
907 rFormatRanges.push_back(aFormatRange);
908}
909
910OUString & ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
911{
912 if (bIsAutoStyle)
913 return aAutoStyleNames[nIndex];
914 else
915 return aStyleNames[nIndex];
916}
917
918void ScFormatRangeStyles::Sort()
919{
920 for (auto & rTable : aTables)
921 rTable.sort();
922}
923
924ScColumnRowStylesBase::ScColumnRowStylesBase()
925 : aStyleNames()
926{
927}
928
929ScColumnRowStylesBase::~ScColumnRowStylesBase()
930{
931}
932
933sal_Int32 ScColumnRowStylesBase::AddStyleName(const OUString & rString)
934{
935 aStyleNames.push_back(rString);
936 return aStyleNames.size() - 1;
937}
938
939sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix)
940{
941 sal_Int32 nPrefixLength(rPrefix.getLength());
942 OUString sTemp(rString.copy(nPrefixLength));
943 sal_Int32 nIndex(sTemp.toInt32());
944 if (nIndex > 0 && o3tl::make_unsigned(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1) == rString)
945 return nIndex - 1;
946 else
947 {
948 sal_Int32 i(0);
949 bool bFound(false);
950 while (!bFound && o3tl::make_unsigned(i) < aStyleNames.size())
951 {
952 if (aStyleNames.at(i) == rString)
953 bFound = true;
954 else
955 ++i;
956 }
957 if (bFound)
958 return i;
959 else
960 return -1;
961 }
962}
963
964OUString& ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
965{
966 return aStyleNames[nIndex];
967}
968
969ScColumnStyles::ScColumnStyles()
970 : ScColumnRowStylesBase(),
971 aTables()
972{
973}
974
975ScColumnStyles::~ScColumnStyles()
976{
977}
978
979void ScColumnStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
980{
981 sal_Int32 nSize(aTables.size() - 1);
982 if (nTable > nSize)
983 for (sal_Int32 i = nSize; i < nTable; ++i)
984 {
985 ScMyColumnStyleVec aFieldsVec(nFields + 1, ScColumnStyle());
986 aTables.push_back(aFieldsVec);
987 }
988}
989
990sal_Int32 ScColumnStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
991 bool& bIsVisible)
992{
993 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "993" ": "), "%s", "wrong table"); } } while (false)
;
994 if (o3tl::make_unsigned(nField) < aTables[nTable].size())
995 {
996 bIsVisible = aTables[nTable][nField].bIsVisible;
997 return aTables[nTable][nField].nIndex;
998 }
999 else
1000 {
1001 bIsVisible = aTables[nTable][aTables[nTable].size() - 1].bIsVisible;
1002 return aTables[nTable][aTables[nTable].size() - 1].nIndex;
1003 }
1004}
1005
1006void ScColumnStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
1007 const sal_Int32 nStringIndex, const bool bIsVisible)
1008{
1009 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "1009" ": "), "%s", "wrong table"); } } while (false)
;
1010 OSL_ENSURE(aTables[nTable].size() >= o3tl::make_unsigned(nField), "wrong field")do { if (true && (!(aTables[nTable].size() >= o3tl
::make_unsigned(nField)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "1010" ": "), "%s", "wrong field"); } } while (false)
;
1011 ScColumnStyle aStyle;
1012 aStyle.nIndex = nStringIndex;
1013 aStyle.bIsVisible = bIsVisible;
1014 if (aTables[nTable].size() == static_cast<sal_uInt32>(nField))
1015 aTables[nTable].push_back(aStyle);
1016 aTables[nTable][nField] = aStyle;
1017}
1018
1019ScRowStyles::Cache::Cache() :
1020 mnTable(-1), mnStart(-1), mnEnd(-1), mnStyle(-1) {}
1021
1022bool ScRowStyles::Cache::hasCache(sal_Int32 nTable, sal_Int32 nField) const
1023{
1024 return mnTable == nTable && mnStart <= nField && nField < mnEnd;
1025}
1026
1027ScRowStyles::ScRowStyles()
1028 : ScColumnRowStylesBase()
1029{
1030}
1031
1032ScRowStyles::~ScRowStyles()
1033{
1034}
1035
1036void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
1037{
1038 sal_Int32 nSize(aTables.size() - 1);
1039 if (nTable > nSize)
1040 for (sal_Int32 i = nSize; i < nTable; ++i)
1041 {
1042 aTables.push_back(std::make_unique<StylesType>(0, nFields+1, -1));
1043 }
1044}
1045
1046sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
1047{
1048 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "1048" ": "), "%s", "wrong table"); } } while (false)
;
1049 if (o3tl::make_unsigned(nTable) >= aTables.size())
1050 return -1;
1051
1052 if (maCache.hasCache(nTable, nField))
1053 // Cache hit !
1054 return maCache.mnStyle;
1055
1056 StylesType& r = *aTables[nTable];
1057 if (!r.is_tree_valid())
1058 r.build_tree();
1059 sal_Int32 nStyle(0);
1060 sal_Int32 nStart(0), nEnd(0);
1061 if (r.search_tree(nField, nStyle, &nStart, &nEnd).second)
1062 {
1063 // Cache this value for better performance.
1064 maCache.mnTable = nTable;
1065 maCache.mnStart = nStart;
1066 maCache.mnEnd = nEnd;
1067 maCache.mnStyle = nStyle;
1068 return nStyle;
1069 }
1070
1071 return -1;
1072}
1073
1074void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
1075 const sal_Int32 nStringIndex)
1076{
1077 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "1077" ": "), "%s", "wrong table"); } } while (false)
;
1078 StylesType& r = *aTables[nTable];
1079 r.insert_back(nField, nField+1, nStringIndex);
1080}
1081
1082void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField,
1083 const sal_Int32 nStringIndex, const sal_Int32 nEndField)
1084{
1085 OSL_ENSURE( nStartField <= nEndField, "bad field range")do { if (true && (!(nStartField <= nEndField))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "1085" ": "), "%s", "bad field range"); } } while (false
)
;
1086 OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table")do { if (true && (!(o3tl::make_unsigned(nTable) < aTables
.size()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN)
, ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/xml/XMLStylesExportHelper.cxx"
":" "1086" ": "), "%s", "wrong table"); } } while (false)
;
1087 StylesType& r = *aTables[nTable];
1088 r.insert_back(nStartField, nEndField+1, nStringIndex);
1089}
1090
1091/* vim:set shiftwidth=4 softtabstop=4 expandtab: */