Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "XMLStylesExportHelper.hxx"
30 : : #include "global.hxx"
31 : : #include "unonames.hxx"
32 : : #include "XMLConverter.hxx"
33 : : #include "xmlexprt.hxx"
34 : : #include "document.hxx"
35 : : #include "rangeutl.hxx"
36 : : #include <xmloff/xmltoken.hxx>
37 : : #include <xmloff/xmlnmspe.hxx>
38 : : #include <xmloff/XMLEventExport.hxx>
39 : : #include <xmloff/nmspmap.hxx>
40 : : #include <com/sun/star/uno/Reference.h>
41 : : #include <com/sun/star/beans/XPropertySet.hpp>
42 : : #include <com/sun/star/sheet/XSheetCondition.hpp>
43 : : #include <com/sun/star/sheet/TableValidationVisibility.hpp>
44 : : #include <comphelper/extract.hxx>
45 : : #include <sfx2/app.hxx>
46 : :
47 : : #include <algorithm>
48 : :
49 : : using namespace com::sun::star;
50 : : using namespace xmloff::token;
51 : :
52 : 0 : ScMyValidation::ScMyValidation()
53 : : : sName(),
54 : : sErrorMessage(),
55 : : sErrorTitle(),
56 : : sImputMessage(),
57 : : sImputTitle(),
58 : : sFormula1(),
59 : : sFormula2(),
60 : : bShowErrorMessage(false),
61 : : bShowImputMessage(false),
62 : 0 : bIgnoreBlanks(false)
63 : : {
64 : 0 : }
65 : :
66 : 0 : ScMyValidation::~ScMyValidation()
67 : : {
68 : 0 : }
69 : :
70 : 0 : bool ScMyValidation::IsEqual(const ScMyValidation& aVal) const
71 : : {
72 [ # # ][ # # ]: 0 : if (aVal.bIgnoreBlanks == bIgnoreBlanks &&
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # # # #
# # # #
# ][ # # ]
73 : : aVal.bShowImputMessage == bShowImputMessage &&
74 : : aVal.bShowErrorMessage == bShowErrorMessage &&
75 : : aVal.aBaseCell.Sheet == aBaseCell.Sheet &&
76 : : aVal.aBaseCell.Column == aBaseCell.Column &&
77 : : aVal.aBaseCell.Row == aBaseCell.Row &&
78 : : aVal.aAlertStyle == aAlertStyle &&
79 : : aVal.aValidationType == aValidationType &&
80 : : aVal.aOperator == aOperator &&
81 : 0 : aVal.sErrorTitle == sErrorTitle &&
82 : 0 : aVal.sImputTitle == sImputTitle &&
83 : 0 : aVal.sErrorMessage == sErrorMessage &&
84 : 0 : aVal.sImputMessage == sImputMessage &&
85 : 0 : aVal.sFormula1 == sFormula1 &&
86 : 0 : aVal.sFormula2 == sFormula2)
87 : 0 : return true;
88 : : else
89 : 0 : return false;
90 : : }
91 : :
92 : 6 : ScMyValidationsContainer::ScMyValidationsContainer()
93 : : : aValidationVec(),
94 : : sEmptyString(),
95 : : sERRALSTY(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRALSTY)),
96 : : sIGNOREBL(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_IGNOREBL)),
97 : : sSHOWLIST(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWLIST)),
98 : : sTYPE(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_TYPE)),
99 : : sSHOWINP(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWINP)),
100 : : sSHOWERR(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWERR)),
101 : : sINPTITLE(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPTITLE)),
102 : : sINPMESS(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPMESS)),
103 : : sERRTITLE(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRTITLE)),
104 : : sERRMESS(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRMESS)),
105 : : sOnError(RTL_CONSTASCII_USTRINGPARAM("OnError")),
106 : : sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
107 : : sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic")),
108 : : sScript(RTL_CONSTASCII_USTRINGPARAM("Script")),
109 : : sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
110 [ + - ][ + - ]: 6 : sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName"))
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
111 : : {
112 : 6 : }
113 : :
114 : 6 : ScMyValidationsContainer::~ScMyValidationsContainer()
115 : : {
116 : 6 : }
117 : :
118 : 0 : bool ScMyValidationsContainer::AddValidation(const uno::Any& aTempAny,
119 : : sal_Int32& nValidationIndex)
120 : : {
121 : 0 : bool bAdded(false);
122 [ # # ]: 0 : uno::Reference<beans::XPropertySet> xPropertySet(aTempAny, uno::UNO_QUERY);
123 [ # # ]: 0 : if (xPropertySet.is())
124 : : {
125 : 0 : rtl::OUString sErrorMessage;
126 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sERRMESS) >>= sErrorMessage;
127 : 0 : rtl::OUString sErrorTitle;
128 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sERRTITLE) >>= sErrorTitle;
129 : 0 : rtl::OUString sImputMessage;
130 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sINPMESS) >>= sImputMessage;
131 : 0 : rtl::OUString sImputTitle;
132 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sINPTITLE) >>= sImputTitle;
133 [ # # ][ # # ]: 0 : bool bShowErrorMessage = ::cppu::any2bool(xPropertySet->getPropertyValue(sSHOWERR));
[ # # ]
134 [ # # ][ # # ]: 0 : bool bShowImputMessage = ::cppu::any2bool(xPropertySet->getPropertyValue(sSHOWINP));
[ # # ]
135 : : sheet::ValidationType aValidationType;
136 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sTYPE) >>= aValidationType;
[ # # ]
137 [ # # ][ # # : 0 : if (bShowErrorMessage || bShowImputMessage || aValidationType != sheet::ValidationType_ANY ||
# # # # #
# # # ]
[ # # ][ # # ]
138 : 0 : !sErrorMessage.isEmpty() || !sErrorTitle.isEmpty() || !sImputMessage.isEmpty() || !sImputTitle.isEmpty())
139 : : {
140 : 0 : ScMyValidation aValidation;
141 : 0 : aValidation.sErrorMessage = sErrorMessage;
142 : 0 : aValidation.sErrorTitle = sErrorTitle;
143 : 0 : aValidation.sImputMessage = sImputMessage;
144 : 0 : aValidation.sImputTitle = sImputTitle;
145 : 0 : aValidation.bShowErrorMessage = bShowErrorMessage;
146 : 0 : aValidation.bShowImputMessage = bShowImputMessage;
147 : 0 : aValidation.aValidationType = aValidationType;
148 [ # # ][ # # ]: 0 : aValidation.bIgnoreBlanks = ::cppu::any2bool(xPropertySet->getPropertyValue(sIGNOREBL));
[ # # ]
149 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sSHOWLIST) >>= aValidation.nShowList;
150 [ # # ][ # # ]: 0 : xPropertySet->getPropertyValue(sERRALSTY) >>= aValidation.aAlertStyle;
[ # # ]
151 [ # # ]: 0 : uno::Reference<sheet::XSheetCondition> xCondition(xPropertySet, uno::UNO_QUERY);
152 [ # # ]: 0 : if (xCondition.is())
153 : : {
154 [ # # ][ # # ]: 0 : aValidation.sFormula1 = xCondition->getFormula1();
155 [ # # ][ # # ]: 0 : aValidation.sFormula2 = xCondition->getFormula2();
156 [ # # ][ # # ]: 0 : aValidation.aOperator = xCondition->getOperator();
157 [ # # ][ # # ]: 0 : aValidation.aBaseCell = xCondition->getSourcePosition();
158 : : }
159 : : //ScMyValidationRange aValidationRange;
160 : 0 : bool bEqualFound(false);
161 : 0 : sal_Int32 i(0);
162 : 0 : sal_Int32 nCount(aValidationVec.size());
163 [ # # ][ # # ]: 0 : while (i < nCount && !bEqualFound)
[ # # ]
164 : : {
165 : 0 : bEqualFound = aValidationVec[i].IsEqual(aValidation);
166 [ # # ]: 0 : if (!bEqualFound)
167 : 0 : ++i;
168 : : }
169 [ # # ]: 0 : if (bEqualFound)
170 : 0 : nValidationIndex = i;
171 : : else
172 : : {
173 : 0 : sal_Int32 nNameIndex(nCount + 1);
174 : 0 : rtl::OUString sCount(rtl::OUString::valueOf(nNameIndex));
175 [ # # ]: 0 : rtl::OUString sPrefix(RTL_CONSTASCII_USTRINGPARAM("val"));
176 : 0 : aValidation.sName += sPrefix;
177 : 0 : aValidation.sName += sCount;
178 [ # # ]: 0 : aValidationVec.push_back(aValidation);
179 : 0 : nValidationIndex = nCount;
180 : 0 : bAdded = true;
181 : 0 : }
182 : 0 : }
183 : : }
184 : 0 : return bAdded;
185 : : }
186 : :
187 : 0 : rtl::OUString ScMyValidationsContainer::GetCondition(ScXMLExport& rExport, const ScMyValidation& aValidation)
188 : : {
189 : : /* ATTENTION! Should the condition to not write sheet::ValidationType_ANY
190 : : * ever be changed, adapt the conditional call of
191 : : * MarkUsedExternalReferences() in
192 : : * ScTableValidationObj::ScTableValidationObj() accordingly! */
193 : 0 : rtl::OUString sCondition;
194 [ # # ]: 0 : if (aValidation.aValidationType != sheet::ValidationType_ANY)
195 : : {
196 [ # # # # : 0 : switch (aValidation.aValidationType)
# # # ]
197 : : {
198 : : //case sheet::ValidationType_CUSTOM
199 : : case sheet::ValidationType_DATE :
200 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-date()"));
201 : 0 : break;
202 : : case sheet::ValidationType_DECIMAL :
203 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-decimal-number()"));
204 : 0 : break;
205 : : case sheet::ValidationType_LIST :
206 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-in-list("));
207 : 0 : sCondition += aValidation.sFormula1;
208 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
209 : 0 : break;
210 : : case sheet::ValidationType_TEXT_LEN :
211 [ # # ][ # # ]: 0 : if (aValidation.aOperator != sheet::ConditionOperator_BETWEEN &&
212 : : aValidation.aOperator != sheet::ConditionOperator_NOT_BETWEEN)
213 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-text-length()"));
214 : 0 : break;
215 : : case sheet::ValidationType_TIME :
216 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-time()"));
217 : 0 : break;
218 : : case sheet::ValidationType_WHOLE :
219 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-whole-number()"));
220 : 0 : break;
221 : : default:
222 : : {
223 : : // added to avoid warnings
224 : : }
225 : : }
226 [ # # # # ]: 0 : if (aValidation.aValidationType != sheet::ValidationType_LIST &&
[ # # ]
[ # # # # ]
[ # # ]
227 : 0 : (!aValidation.sFormula1.isEmpty() ||
228 : : (aValidation.aOperator == sheet::ConditionOperator_BETWEEN &&
229 : : aValidation.aOperator == sheet::ConditionOperator_NOT_BETWEEN &&
230 : 0 : !aValidation.sFormula2.isEmpty())))
231 : : {
232 [ # # ]: 0 : if (aValidation.aValidationType != sheet::ValidationType_TEXT_LEN)
233 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" and "));
234 [ # # ][ # # ]: 0 : if (aValidation.aOperator != sheet::ConditionOperator_BETWEEN &&
235 : : aValidation.aOperator != sheet::ConditionOperator_NOT_BETWEEN)
236 : : {
237 [ # # ]: 0 : if (aValidation.aValidationType != sheet::ValidationType_TEXT_LEN)
238 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content()"));
239 [ # # # # : 0 : switch (aValidation.aOperator)
# # # ]
240 : : {
241 : : case sheet::ConditionOperator_EQUAL :
242 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("="));
243 : 0 : break;
244 : : case sheet::ConditionOperator_GREATER :
245 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(">"));
246 : 0 : break;
247 : : case sheet::ConditionOperator_GREATER_EQUAL :
248 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(">="));
249 : 0 : break;
250 : : case sheet::ConditionOperator_LESS :
251 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<"));
252 : 0 : break;
253 : : case sheet::ConditionOperator_LESS_EQUAL :
254 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<="));
255 : 0 : break;
256 : : case sheet::ConditionOperator_NOT_EQUAL :
257 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("!="));
258 : 0 : break;
259 : : default:
260 : : {
261 : : // added to avoid warnings
262 : : }
263 : : }
264 : 0 : sCondition += aValidation.sFormula1;
265 : : }
266 : : else
267 : : {
268 [ # # ]: 0 : if (aValidation.aValidationType == sheet::ValidationType_TEXT_LEN)
269 : : {
270 [ # # ]: 0 : if (aValidation.aOperator == sheet::ConditionOperator_BETWEEN)
271 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-text-length-is-between("));
272 : : else
273 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-text-length-is-not-between("));
274 : : }
275 : : else
276 : : {
277 [ # # ]: 0 : if (aValidation.aOperator == sheet::ConditionOperator_BETWEEN)
278 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-between("));
279 : : else
280 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-not-between("));
281 : : }
282 : 0 : sCondition += aValidation.sFormula1;
283 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
284 : 0 : sCondition += aValidation.sFormula2;
285 [ # # ]: 0 : sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
286 : : }
287 : : }
288 : : else
289 [ # # ]: 0 : if (aValidation.aValidationType == sheet::ValidationType_TEXT_LEN)
290 : 0 : sCondition = rtl::OUString();
291 : : }
292 [ # # ]: 0 : if (!sCondition.isEmpty())
293 : : {
294 : 0 : const formula::FormulaGrammar::Grammar eGrammar = rExport.GetDocument()->GetStorageGrammar();
295 [ # # ]: 0 : sal_uInt16 nNamespacePrefix = (eGrammar == formula::FormulaGrammar::GRAM_ODFF ? XML_NAMESPACE_OF : XML_NAMESPACE_OOOC);
296 [ # # ]: 0 : sCondition = rExport.GetNamespaceMap().GetQNameByKey( nNamespacePrefix, sCondition, false );
297 : : }
298 : :
299 : 0 : return sCondition;
300 : : }
301 : :
302 : 0 : rtl::OUString ScMyValidationsContainer::GetBaseCellAddress(ScDocument* pDoc, const table::CellAddress& aCell)
303 : : {
304 : 0 : rtl::OUString sAddress;
305 [ # # ]: 0 : ScRangeStringConverter::GetStringFromAddress( sAddress, aCell, pDoc, ::formula::FormulaGrammar::CONV_OOO );
306 : 0 : return sAddress;
307 : : }
308 : :
309 : 0 : void ScMyValidationsContainer::WriteMessage(ScXMLExport& rExport,
310 : : const rtl::OUString& sTitle, const rtl::OUString& sOUMessage,
311 : : const bool bShowMessage, const bool bIsHelpMessage)
312 : : {
313 [ # # ]: 0 : if (!sTitle.isEmpty())
314 : 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_TITLE, sTitle);
315 [ # # ]: 0 : if (bShowMessage)
316 : 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_TRUE);
317 : : else
318 : 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY, XML_FALSE);
319 : 0 : SvXMLElementExport* pMessage(NULL);
320 [ # # ]: 0 : if (bIsHelpMessage)
321 [ # # ]: 0 : pMessage = new SvXMLElementExport(rExport, XML_NAMESPACE_TABLE, XML_HELP_MESSAGE, true, true);
322 : : else
323 [ # # ]: 0 : pMessage = new SvXMLElementExport(rExport, XML_NAMESPACE_TABLE, XML_ERROR_MESSAGE, true, true);
324 [ # # ]: 0 : if (!sOUMessage.isEmpty())
325 : : {
326 : 0 : sal_Int32 i(0);
327 : 0 : rtl::OUStringBuffer sTemp;
328 [ # # ]: 0 : rtl::OUString sText(convertLineEnd(sOUMessage, LINEEND_LF));
329 : 0 : bool bPrevCharWasSpace(true);
330 [ # # ]: 0 : while(i < sText.getLength())
331 : : {
332 [ # # ]: 0 : if ((sText[i] == '\n'))
333 : : {
334 [ # # ]: 0 : SvXMLElementExport aElemP(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
335 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->exportText(sTemp.makeStringAndClear(), bPrevCharWasSpace);
[ # # ][ # # ]
[ # # ][ # # ]
336 : : }
337 : : else
338 [ # # ]: 0 : sTemp.append(sText[i]);
339 : 0 : ++i;
340 : : }
341 [ # # ]: 0 : if (sTemp.getLength())
342 : : {
343 [ # # ]: 0 : SvXMLElementExport aElemP(rExport, XML_NAMESPACE_TEXT, XML_P, true, false);
344 [ # # ][ # # ]: 0 : rExport.GetTextParagraphExport()->exportText(sTemp.makeStringAndClear(), bPrevCharWasSpace);
[ # # ][ # # ]
[ # # ][ # # ]
345 : 0 : }
346 : : }
347 [ # # ]: 0 : if (pMessage)
348 [ # # ]: 0 : delete pMessage;
349 : 0 : }
350 : :
351 : 4 : void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
352 : : {
353 [ - + ]: 4 : if (!aValidationVec.empty())
354 : : {
355 [ # # ]: 0 : SvXMLElementExport aElemVs(rExport, XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATIONS, true, true);
356 : 0 : ScMyValidationVec::iterator aItr(aValidationVec.begin());
357 : 0 : ScMyValidationVec::iterator aEndItr(aValidationVec.end());
358 [ # # ][ # # ]: 0 : while (aItr != aEndItr)
359 : : {
360 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, aItr->sName);
361 [ # # ]: 0 : rtl::OUString sCondition(GetCondition(rExport, *aItr));
362 [ # # ]: 0 : if (!sCondition.isEmpty())
363 : : {
364 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_CONDITION, sCondition);
365 [ # # ]: 0 : if (aItr->bIgnoreBlanks)
366 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ALLOW_EMPTY_CELL, XML_TRUE);
367 : : else
368 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_ALLOW_EMPTY_CELL, XML_FALSE);
369 [ # # ]: 0 : if (aItr->aValidationType == sheet::ValidationType_LIST)
370 : : {
371 [ # # # # ]: 0 : switch (aItr->nShowList)
372 : : {
373 : : case sheet::TableValidationVisibility::INVISIBLE:
374 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_LIST, XML_NO);
375 : 0 : break;
376 : : case sheet::TableValidationVisibility::UNSORTED:
377 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_LIST, XML_UNSORTED);
378 : 0 : break;
379 : : case sheet::TableValidationVisibility::SORTEDASCENDING:
380 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DISPLAY_LIST, XML_SORTED_ASCENDING);
381 : 0 : break;
382 : : default:
383 : : OSL_FAIL("unknown ListType");
384 : : }
385 : : }
386 : : }
387 [ # # ][ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_BASE_CELL_ADDRESS, GetBaseCellAddress(rExport.GetDocument(), aItr->aBaseCell));
388 [ # # ]: 0 : SvXMLElementExport aElemV(rExport, XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION, true, true);
389 [ # # ][ # # ]: 0 : if (aItr->bShowImputMessage || !aItr->sImputMessage.isEmpty() || !aItr->sImputTitle.isEmpty())
[ # # ][ # # ]
390 : : {
391 [ # # ]: 0 : WriteMessage(rExport, aItr->sImputTitle, aItr->sImputMessage, aItr->bShowImputMessage, true);
392 : : }
393 [ # # ][ # # ]: 0 : if (aItr->bShowErrorMessage || !aItr->sErrorMessage.isEmpty() || !aItr->sErrorTitle.isEmpty())
[ # # ][ # # ]
394 : : {
395 [ # # # # : 0 : switch (aItr->aAlertStyle)
# ]
396 : : {
397 : : case sheet::ValidationAlertStyle_INFO :
398 : : {
399 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MESSAGE_TYPE, XML_INFORMATION);
400 [ # # ]: 0 : WriteMessage(rExport, aItr->sErrorTitle, aItr->sErrorMessage, aItr->bShowErrorMessage, false);
401 : : }
402 : 0 : break;
403 : : case sheet::ValidationAlertStyle_WARNING :
404 : : {
405 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MESSAGE_TYPE, XML_WARNING);
406 [ # # ]: 0 : WriteMessage(rExport, aItr->sErrorTitle, aItr->sErrorMessage, aItr->bShowErrorMessage, false);
407 : : }
408 : 0 : break;
409 : : case sheet::ValidationAlertStyle_STOP :
410 : : {
411 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_MESSAGE_TYPE, XML_STOP);
412 [ # # ]: 0 : WriteMessage(rExport, aItr->sErrorTitle, aItr->sErrorMessage, aItr->bShowErrorMessage, false);
413 : : }
414 : 0 : break;
415 : : case sheet::ValidationAlertStyle_MACRO :
416 : : {
417 : : {
418 : : //rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, aItr->sErrorTitle);
419 [ # # ]: 0 : if (aItr->bShowErrorMessage)
420 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_EXECUTE, XML_TRUE);
421 : : else
422 [ # # ]: 0 : rExport.AddAttribute(XML_NAMESPACE_TABLE, XML_EXECUTE, XML_FALSE);
423 [ # # ][ # # ]: 0 : SvXMLElementExport aEMElem(rExport, XML_NAMESPACE_TABLE, XML_ERROR_MACRO, true, true);
424 : : }
425 : : {
426 : : // #i47525# for a script URL the type and the property name for the URL
427 : : // are both "Script", for a simple macro name the type is "StarBasic"
428 : : // and the property name is "MacroName".
429 [ # # ][ # # ]: 0 : bool bScriptURL = SfxApplication::IsXScriptURL( aItr->sErrorTitle );
[ # # ]
430 : :
431 [ # # ]: 0 : uno::Sequence<beans::PropertyValue> aSeq(3);
432 [ # # ]: 0 : beans::PropertyValue* pArr(aSeq.getArray());
433 : 0 : pArr[0].Name = sEventType;
434 [ # # ][ # # ]: 0 : pArr[0].Value <<= bScriptURL ? sScript : sStarBasic;
435 : 0 : pArr[1].Name = sLibrary;
436 [ # # ]: 0 : pArr[1].Value <<= sEmptyString;
437 [ # # ]: 0 : pArr[2].Name = bScriptURL ? sScript : sMacroName;
438 [ # # ]: 0 : pArr[2].Value <<= aItr->sErrorTitle;
439 : :
440 : : // 2) export the sequence
441 [ # # ][ # # ]: 0 : rExport.GetEventExport().ExportSingleEvent( aSeq, sOnError);
[ # # ]
442 : : }
443 : : }
444 : 0 : break;
445 : : default:
446 : : {
447 : : // added to avoid warnings
448 : : }
449 : : }
450 : : }
451 : 0 : ++aItr;
452 [ # # ][ # # ]: 0 : }
453 : : }
454 : 4 : }
455 : :
456 : 0 : const rtl::OUString& ScMyValidationsContainer::GetValidationName(const sal_Int32 nIndex)
457 : : {
458 : : OSL_ENSURE( static_cast<size_t>(nIndex) < aValidationVec.size(), "out of range" );
459 : 0 : return aValidationVec[nIndex].sName;
460 : : }
461 : :
462 : : //==============================================================================
463 : :
464 : 4 : sal_Int32 ScMyDefaultStyles::GetStyleNameIndex(const ScFormatRangeStyles* pCellStyles,
465 : : const sal_Int32 nTable, const sal_Int32 nPos,
466 : : const sal_Int32 i, const bool bRow, bool& bIsAutoStyle)
467 : : {
468 [ - + ]: 4 : if (bRow)
469 : : return pCellStyles->GetStyleNameIndex(nTable, nPos, i,
470 : 0 : bIsAutoStyle);
471 : : else
472 : : return pCellStyles->GetStyleNameIndex(nTable, i, nPos,
473 : 4 : bIsAutoStyle);
474 : : }
475 : :
476 : 8 : void ScMyDefaultStyles::FillDefaultStyles(const sal_Int32 nTable,
477 : : const sal_Int32 nLastRow, const sal_Int32 nLastCol,
478 : : const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc,
479 : : const bool bRow)
480 : : {
481 [ + - ]: 8 : if (pDoc)
482 : : {
483 : 8 : SCTAB nTab = static_cast<SCTAB>(nTable);
484 : : sal_Int32 nPos;
485 : : sal_Int32 nLast;
486 : : ScMyDefaultStyleList* pDefaults;
487 [ + + ]: 8 : if (bRow)
488 : : {
489 : 4 : pDefaults = pRowDefaults;
490 : 4 : nLast = nLastRow;
491 : : }
492 : : else
493 : : {
494 : 4 : pDefaults = pColDefaults;
495 : 4 : nLast = nLastCol;
496 : : }
497 : 8 : bool bPrevAutoStyle(false);
498 : : bool bIsAutoStyle;
499 : : bool bResult;
500 : 8 : sal_Int32 nPrevIndex(0);
501 : : sal_Int32 nIndex;
502 : 8 : sal_Int32 nRepeat(0);
503 : 8 : sal_Int32 nEmptyRepeat(0);
504 [ + + ]: 16 : for (sal_Int32 i = nLast; i >= 0; --i)
505 : : {
506 [ + + ]: 8 : if (bRow)
507 : : {
508 : : SCCOL nCol;
509 : : bResult = pDoc->GetRowDefault(nTab,
510 [ + - ]: 4 : static_cast<SCROW>(i), static_cast<SCCOL>(nLastCol), nCol);
511 : 4 : nPos = static_cast<sal_Int32>(nCol);
512 : : }
513 : : else
514 : : {
515 : : SCROW nRow;
516 : : bResult = pDoc->GetColDefault(nTab,
517 [ + - ]: 4 : static_cast<SCCOL>(i), static_cast<SCROW>(nLastRow), nRow);
518 : 4 : nPos = static_cast<sal_Int32>(nRow);
519 : : }
520 [ + + ]: 8 : if (bResult)
521 : : {
522 : 4 : nEmptyRepeat = 0;
523 [ + - ]: 4 : if (!nRepeat)
524 : : {
525 : : nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i,
526 [ + - ]: 4 : bRow, bPrevAutoStyle);
527 : 4 : (*pDefaults)[i].nIndex = nPrevIndex;
528 : 4 : (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
529 : 4 : nRepeat = 1;
530 : : }
531 : : else
532 : : {
533 : : nIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i,
534 [ # # ]: 0 : bRow, bIsAutoStyle);
535 [ # # ][ # # ]: 0 : if ((nIndex != nPrevIndex) || (bIsAutoStyle != bPrevAutoStyle))
536 : : {
537 : 0 : nRepeat = 1;
538 : : nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i,
539 [ # # ]: 0 : bRow, bPrevAutoStyle);
540 : 0 : (*pDefaults)[i].nIndex = nPrevIndex;
541 : 0 : (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
542 : : }
543 : : else
544 : : {
545 : 0 : (*pDefaults)[i].nIndex = nPrevIndex;
546 : 0 : (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
547 : 0 : ++nRepeat;
548 [ # # ]: 0 : if (nRepeat > 1)
549 : 4 : (*pDefaults)[i].nRepeat = nRepeat;
550 : : }
551 : : }
552 : : }
553 : : else
554 : : {
555 : 4 : nRepeat = 0;
556 [ + - ]: 4 : if (!nEmptyRepeat)
557 : 4 : nEmptyRepeat = 1;
558 : : else
559 : : {
560 : 0 : ++nEmptyRepeat;
561 [ # # ]: 0 : if (nEmptyRepeat > 1)
562 : 0 : (*pDefaults)[i].nRepeat = nEmptyRepeat;
563 : : }
564 : : }
565 : : }
566 : : }
567 : 8 : }
568 : :
569 : 4 : void ScMyDefaultStyles::FillDefaultStyles(const sal_Int32 nTable,
570 : : const sal_Int32 nLastRow, const sal_Int32 nLastCol,
571 : : const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc)
572 : : {
573 [ - + ]: 4 : if (pRowDefaults)
574 [ # # ]: 0 : delete pRowDefaults;
575 [ + - ]: 4 : pRowDefaults = new ScMyDefaultStyleList(nLastRow + 1);
576 : 4 : FillDefaultStyles(nTable, nLastRow, nLastCol, pCellStyles, pDoc, true);
577 [ - + ]: 4 : if (pColDefaults)
578 [ # # ]: 0 : delete pColDefaults;
579 [ + - ]: 4 : pColDefaults = new ScMyDefaultStyleList(nLastCol + 1);
580 : 4 : FillDefaultStyles(nTable, nLastRow, nLastCol, pCellStyles, pDoc, false);
581 : 4 : }
582 : :
583 : 6 : ScMyDefaultStyles::~ScMyDefaultStyles()
584 : : {
585 [ + + ]: 6 : if (pRowDefaults)
586 [ + - ]: 4 : delete pRowDefaults;
587 [ + + ]: 6 : if (pColDefaults)
588 [ + - ]: 4 : delete pColDefaults;
589 : 6 : }
590 : :
591 : 12 : ScMyRowFormatRange::ScMyRowFormatRange()
592 : : : nStartColumn(0),
593 : : nRepeatColumns(0),
594 : : nRepeatRows(0),
595 : : nIndex(-1),
596 : : nValidationIndex(-1),
597 : 12 : bIsAutoStyle(true)
598 : : {
599 : 12 : }
600 : :
601 : 0 : bool ScMyRowFormatRange::operator< (const ScMyRowFormatRange& rRange) const
602 : : {
603 : 0 : return (nStartColumn < rRange.nStartColumn);
604 : : }
605 : :
606 : 6 : ScRowFormatRanges::ScRowFormatRanges()
607 : : : aRowFormatRanges(),
608 : : pRowDefaults(NULL),
609 : : pColDefaults(NULL),
610 : 6 : nSize(0)
611 : : {
612 : 6 : }
613 : :
614 : 0 : ScRowFormatRanges::ScRowFormatRanges(const ScRowFormatRanges* pRanges)
615 : : : aRowFormatRanges(pRanges->aRowFormatRanges),
616 : : pRowDefaults(pRanges->pRowDefaults),
617 : : pColDefaults(pRanges->pColDefaults),
618 : 0 : nSize(pRanges->nSize)
619 : : {
620 : 0 : }
621 : :
622 : 6 : ScRowFormatRanges::~ScRowFormatRanges()
623 : : {
624 : 6 : }
625 : :
626 : 8 : void ScRowFormatRanges::Clear()
627 : : {
628 : 8 : aRowFormatRanges.clear();
629 : 8 : nSize = 0;
630 : 8 : }
631 : :
632 : 4 : void ScRowFormatRanges::AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
633 : : const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange)
634 : : {
635 : 4 : sal_Int32 nIndex(-1);
636 [ + - ][ - + ]: 4 : if ((nPrevIndex != rFormatRange.nIndex) ||
637 : : (bPrevAutoStyle != rFormatRange.bIsAutoStyle))
638 : 0 : nIndex = rFormatRange.nIndex;
639 : :
640 : 4 : bool bInserted(false);
641 [ - + ]: 4 : if (!aRowFormatRanges.empty())
642 : : {
643 : 0 : ScMyRowFormatRange* pRange(&aRowFormatRanges.back());
644 [ # # ]: 0 : if (pRange)
645 : : {
646 [ # # ][ # # ]: 0 : if ((nPrevStartCol == (pRange->nStartColumn + pRange->nRepeatColumns)) &&
[ # # ][ # # ]
647 : : (pRange->bIsAutoStyle == rFormatRange.bIsAutoStyle) &&
648 : : (pRange->nIndex == nIndex) &&
649 : : (pRange->nValidationIndex == rFormatRange.nValidationIndex))
650 : : {
651 [ # # ]: 0 : if (rFormatRange.nRepeatRows < pRange->nRepeatRows)
652 : 0 : pRange->nRepeatRows = rFormatRange.nRepeatRows;
653 : 0 : pRange->nRepeatColumns += nRepeat;
654 : 0 : bInserted = true;
655 : : }
656 : : }
657 : : }
658 [ + - ]: 4 : if (!bInserted)
659 : : {
660 : 4 : ScMyRowFormatRange aRange;
661 : 4 : aRange.nStartColumn = nPrevStartCol;
662 : 4 : aRange.nRepeatColumns = nRepeat;
663 : 4 : aRange.nRepeatRows = rFormatRange.nRepeatRows;
664 : 4 : aRange.nValidationIndex = rFormatRange.nValidationIndex;
665 : 4 : aRange.bIsAutoStyle = rFormatRange.bIsAutoStyle;
666 : 4 : aRange.nIndex = nIndex;
667 [ + - ]: 4 : aRowFormatRanges.push_back(aRange);
668 : 4 : ++nSize;
669 : : }
670 : 4 : }
671 : :
672 : 4 : void ScRowFormatRanges::AddRange(ScMyRowFormatRange& rFormatRange,
673 : : const sal_Int32 nRow)
674 : : {
675 : : OSL_ENSURE(pRowDefaults, "no row defaults");
676 [ - + ]: 4 : if (!pRowDefaults)
677 : 0 : return;
678 : : OSL_ENSURE(pColDefaults, "no column defaults");
679 [ - + ]: 4 : if (!pColDefaults)
680 : 0 : return;
681 : : sal_Int32 nPrevIndex;
682 : : bool bPrevAutoStyle;
683 : : OSL_ENSURE( static_cast<size_t>(nRow) < pRowDefaults->size(), "nRow out of bounds");
684 [ - + ]: 4 : if (!(static_cast<size_t>(nRow) < pRowDefaults->size()))
685 : : {
686 : : /* This is only to prevent out-of-bounds accesses, once reached here
687 : : * there's something else going wrong, so FIXME there! */
688 [ # # ]: 0 : if (pRowDefaults->empty())
689 : : {
690 : 0 : nPrevIndex = -1;
691 : 0 : bPrevAutoStyle = false;
692 : : }
693 : : else
694 : : {
695 : 0 : nPrevIndex = (*pRowDefaults)[pRowDefaults->size()-1].nIndex;
696 : 0 : bPrevAutoStyle = (*pRowDefaults)[pRowDefaults->size()-1].bIsAutoStyle;
697 : : }
698 : : }
699 : : else
700 : : {
701 : 4 : nPrevIndex = (*pRowDefaults)[nRow].nIndex;
702 : 4 : bPrevAutoStyle = (*pRowDefaults)[nRow].bIsAutoStyle;
703 : : }
704 : 4 : sal_uInt32 nEnd (rFormatRange.nRepeatRows + nRow - 1);
705 : 4 : sal_uInt32 i(nRow + 1);
706 : 4 : bool bReady(false);
707 [ + - ][ + - ]: 4 : while ((i < nEnd) && !bReady && (i < pRowDefaults->size()))
[ - + ][ - + ]
708 : : {
709 [ # # # # ]: 0 : if ((nPrevIndex != (*pRowDefaults)[i].nIndex) ||
[ # # ]
710 : 0 : (bPrevAutoStyle != (*pRowDefaults)[i].bIsAutoStyle))
711 : 0 : bReady = true;
712 : : else
713 : 0 : i += (*pRowDefaults)[i].nRepeat;
714 : : }
715 [ - + ]: 4 : if (i > nEnd)
716 : 0 : i = nEnd;
717 [ - + ]: 4 : if (bReady)
718 : 0 : rFormatRange.nRepeatRows = i - nRow + 1;
719 [ + - ]: 4 : if (nPrevIndex == -1)
720 : : {
721 : 4 : sal_uInt32 nPrevStartCol(rFormatRange.nStartColumn);
722 : : OSL_ENSURE( static_cast<size_t>(nPrevStartCol) < pColDefaults->size(), "nPrevStartCol out of bounds");
723 : : sal_uInt32 nRepeat;
724 [ + - ]: 4 : if (static_cast<size_t>(nPrevStartCol) < pColDefaults->size())
725 : : {
726 : 4 : nRepeat = (*pColDefaults)[nPrevStartCol].nRepeat;
727 : 4 : nPrevIndex = (*pColDefaults)[nPrevStartCol].nIndex;
728 : 4 : bPrevAutoStyle = (*pColDefaults)[nPrevStartCol].bIsAutoStyle;
729 : : }
730 : : else
731 : : {
732 : : /* Again, this is to prevent out-of-bounds accesses, so FIXME
733 : : * elsewhere! */
734 [ # # ]: 0 : if (pColDefaults->empty())
735 : : {
736 : 0 : nRepeat = 1;
737 : 0 : nPrevIndex = -1;
738 : 0 : bPrevAutoStyle = false;
739 : : }
740 : : else
741 : : {
742 : 0 : nRepeat = (*pColDefaults)[pColDefaults->size()-1].nRepeat;
743 : 0 : nPrevIndex = (*pColDefaults)[pColDefaults->size()-1].nIndex;
744 : 0 : bPrevAutoStyle = (*pColDefaults)[pColDefaults->size()-1].bIsAutoStyle;
745 : : }
746 : : }
747 : 4 : nEnd = nPrevStartCol + rFormatRange.nRepeatColumns;
748 [ - + ][ # # ]: 4 : for(i = nPrevStartCol + nRepeat; i < nEnd && i < pColDefaults->size(); i += (*pColDefaults)[i].nRepeat)
[ - + ]
749 : : {
750 : : OSL_ENSURE(sal_uInt32(nPrevStartCol + nRepeat) <= nEnd, "something wents wrong");
751 [ # # # # ]: 0 : if ((nPrevIndex != (*pColDefaults)[i].nIndex) ||
[ # # ]
752 : 0 : (bPrevAutoStyle != (*pColDefaults)[i].bIsAutoStyle))
753 : : {
754 : 0 : AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
755 : 0 : nPrevStartCol = i;
756 : 0 : nRepeat = (*pColDefaults)[i].nRepeat;
757 : 0 : nPrevIndex = (*pColDefaults)[i].nIndex;
758 : 0 : bPrevAutoStyle = (*pColDefaults)[i].bIsAutoStyle;
759 : : }
760 : : else
761 : 0 : nRepeat += (*pColDefaults)[i].nRepeat;
762 : : }
763 [ - + ]: 4 : if (sal_uInt32(nPrevStartCol + nRepeat) > nEnd)
764 : 0 : nRepeat = nEnd - nPrevStartCol;
765 : 4 : AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
766 : : }
767 [ # # ][ # # ]: 0 : else if ((nPrevIndex == rFormatRange.nIndex) &&
768 : : (bPrevAutoStyle == rFormatRange.bIsAutoStyle))
769 : : {
770 : 0 : rFormatRange.nIndex = -1;
771 : 0 : aRowFormatRanges.push_back(rFormatRange);
772 : 4 : ++nSize;
773 : : }
774 : : }
775 : :
776 : 8 : bool ScRowFormatRanges::GetNext(ScMyRowFormatRange& aFormatRange)
777 : : {
778 : 8 : ScMyRowFormatRangesList::iterator aItr(aRowFormatRanges.begin());
779 [ + + ]: 8 : if (aItr != aRowFormatRanges.end())
780 : : {
781 : 4 : aFormatRange = (*aItr);
782 [ + - ]: 4 : aRowFormatRanges.erase(aItr);
783 : 4 : --nSize;
784 : 4 : return true;
785 : : }
786 : 8 : return false;
787 : : }
788 : :
789 : 0 : sal_Int32 ScRowFormatRanges::GetMaxRows() const
790 : : {
791 : 0 : ScMyRowFormatRangesList::const_iterator aItr(aRowFormatRanges.begin());
792 : 0 : ScMyRowFormatRangesList::const_iterator aEndItr(aRowFormatRanges.end());
793 : 0 : sal_Int32 nMaxRows = MAXROW + 1;
794 [ # # ]: 0 : if (aItr != aEndItr)
795 : : {
796 [ # # ]: 0 : while (aItr != aEndItr)
797 : : {
798 [ # # ]: 0 : if ((*aItr).nRepeatRows < nMaxRows)
799 : 0 : nMaxRows = (*aItr).nRepeatRows;
800 : 0 : ++aItr;
801 : : }
802 : : }
803 : : else
804 : : {
805 : : OSL_FAIL("no ranges found");
806 : : }
807 : 0 : return nMaxRows;
808 : : }
809 : :
810 : 0 : sal_Int32 ScRowFormatRanges::GetSize() const
811 : : {
812 : 0 : return nSize;
813 : : }
814 : :
815 : 4 : void ScRowFormatRanges::Sort()
816 : : {
817 : 4 : aRowFormatRanges.sort();
818 : 4 : }
819 : :
820 : : // ============================================================================
821 : 4 : ScMyFormatRange::ScMyFormatRange()
822 : : : nStyleNameIndex(-1),
823 : : nValidationIndex(-1),
824 : 4 : bIsAutoStyle(true)
825 : : {
826 : 4 : }
827 : :
828 : 0 : bool ScMyFormatRange::operator<(const ScMyFormatRange& rRange) const
829 : : {
830 [ # # ]: 0 : if (aRangeAddress.StartRow < rRange.aRangeAddress.StartRow)
831 : 0 : return true;
832 : : else
833 [ # # ]: 0 : if (aRangeAddress.StartRow == rRange.aRangeAddress.StartRow)
834 : 0 : return (aRangeAddress.StartColumn < rRange.aRangeAddress.StartColumn);
835 : : else
836 : 0 : return false;
837 : : }
838 : :
839 : 22 : ScFormatRangeStyles::ScFormatRangeStyles()
840 : : : aTables(),
841 : : aStyleNames(),
842 : : aAutoStyleNames(),
843 : : pRowDefaults(0),
844 [ + - ][ + - ]: 22 : pColDefaults(0)
845 : : {
846 : 22 : }
847 : :
848 : 22 : ScFormatRangeStyles::~ScFormatRangeStyles()
849 : : {
850 : 22 : ScMyOUStringVec::iterator i(aStyleNames.begin());
851 : 22 : ScMyOUStringVec::iterator endi(aStyleNames.end());
852 [ + - ][ + + ]: 26 : while (i != endi)
853 : : {
854 [ + - ]: 4 : delete *i;
855 : 4 : ++i;
856 : : }
857 : 22 : i = aAutoStyleNames.begin();
858 : 22 : endi = aAutoStyleNames.end();
859 [ + - ][ - + ]: 22 : while (i != endi)
860 : : {
861 [ # # ]: 0 : delete *i;
862 : 0 : ++i;
863 : : }
864 : 22 : ScMyFormatRangeListVec::iterator j(aTables.begin());
865 : 22 : ScMyFormatRangeListVec::iterator endj(aTables.end());
866 [ + - ][ + + ]: 30 : while (j != endj)
867 : : {
868 [ + - ]: 8 : delete *j;
869 : 8 : ++j;
870 : : }
871 : 22 : }
872 : :
873 : 8 : void ScFormatRangeStyles::AddNewTable(const sal_Int32 nTable)
874 : : {
875 : 8 : sal_Int32 nSize = aTables.size() - 1;
876 [ + - ]: 8 : if (nTable > nSize)
877 [ + + ]: 16 : for (sal_Int32 i = nSize; i < nTable; ++i)
878 : : {
879 [ + - ][ + - ]: 8 : ScMyFormatRangeAddresses* aRangeAddresses(new ScMyFormatRangeAddresses);
880 [ + - ]: 8 : aTables.push_back(aRangeAddresses);
881 : : }
882 : 8 : }
883 : :
884 : 4 : bool ScFormatRangeStyles::AddStyleName(rtl::OUString* rpString, sal_Int32& rIndex, const bool bIsAutoStyle)
885 : : {
886 [ - + ]: 4 : if (bIsAutoStyle)
887 : : {
888 : 0 : aAutoStyleNames.push_back(rpString);
889 : 0 : rIndex = aAutoStyleNames.size() - 1;
890 : 0 : return true;
891 : : }
892 : : else
893 : : {
894 : 4 : sal_Int32 nCount(aStyleNames.size());
895 : 4 : bool bFound(false);
896 : 4 : sal_Int32 i(nCount - 1);
897 [ - + ][ # # ]: 4 : while ((i >= 0) && (!bFound))
[ - + ]
898 : : {
899 [ # # ]: 0 : if (aStyleNames.at(i)->equals(*rpString))
900 : 0 : bFound = true;
901 : : else
902 : 0 : i--;
903 : : }
904 [ - + ]: 4 : if (bFound)
905 : : {
906 : 0 : rIndex = i;
907 : 0 : return false;
908 : : }
909 : : else
910 : : {
911 : 4 : aStyleNames.push_back(rpString);
912 : 4 : rIndex = aStyleNames.size() - 1;
913 : 4 : return true;
914 : : }
915 : : }
916 : : }
917 : :
918 : 0 : sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const rtl::OUString& rString, const rtl::OUString& rPrefix, bool& bIsAutoStyle)
919 : : {
920 : 0 : sal_Int32 nPrefixLength(rPrefix.getLength());
921 : 0 : rtl::OUString sTemp(rString.copy(nPrefixLength));
922 : 0 : sal_Int32 nIndex(sTemp.toInt32());
923 [ # # ][ # # ]: 0 : if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1)->equals(rString))
[ # # ][ # # ]
[ # # ]
924 : : {
925 : 0 : bIsAutoStyle = true;
926 : 0 : return nIndex - 1;
927 : : }
928 : : else
929 : : {
930 : 0 : sal_Int32 i(0);
931 : 0 : bool bFound(false);
932 [ # # ][ # # ]: 0 : while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
[ # # ]
933 : : {
934 [ # # ]: 0 : if (aStyleNames[i]->equals(rString))
935 : 0 : bFound = true;
936 : : else
937 : 0 : ++i;
938 : : }
939 [ # # ]: 0 : if (bFound)
940 : : {
941 : 0 : bIsAutoStyle = false;
942 : 0 : return i;
943 : : }
944 : : else
945 : : {
946 : 0 : i = 0;
947 [ # # ][ # # ]: 0 : while (!bFound && static_cast<size_t>(i) < aAutoStyleNames.size())
[ # # ]
948 : : {
949 [ # # ]: 0 : if (aAutoStyleNames[i]->equals(rString))
950 : 0 : bFound = true;
951 : : else
952 : 0 : ++i;
953 : : }
954 [ # # ]: 0 : if (bFound)
955 : : {
956 : 0 : bIsAutoStyle = true;
957 : 0 : return i;
958 : : }
959 : : else
960 : 0 : return -1;
961 : : }
962 : 0 : }
963 : : }
964 : :
965 : 4 : sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
966 : : const sal_Int32 nColumn, const sal_Int32 nRow, bool& bIsAutoStyle) const
967 : : {
968 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
969 [ - + ]: 4 : if (!(static_cast<size_t>(nTable) < aTables.size()))
970 : 0 : return -1;
971 : 4 : ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
972 : 4 : ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
973 : 4 : ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
974 [ + - ]: 4 : while (aItr != aEndItr)
975 : : {
976 [ + - + - : 16 : if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
+ - + - ]
[ + - ]
977 : 4 : ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
978 : 4 : ((*aItr).aRangeAddress.StartRow <= nRow) &&
979 : 4 : ((*aItr).aRangeAddress.EndRow >= nRow))
980 : : {
981 : 4 : bIsAutoStyle = aItr->bIsAutoStyle;
982 : 4 : return (*aItr).nStyleNameIndex;
983 : : }
984 : : else
985 : 0 : ++aItr;
986 : : }
987 : 4 : return -1;
988 : : }
989 : :
990 : 0 : sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
991 : : bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow)
992 : : {
993 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
994 [ # # ]: 0 : if (!(static_cast<size_t>(nTable) < aTables.size()))
995 : 0 : return -1;
996 : 0 : ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
997 : 0 : ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
998 : 0 : ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
999 [ # # ]: 0 : while (aItr != aEndItr)
1000 : : {
1001 [ # # # # : 0 : if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
# # # # ]
[ # # ]
1002 : 0 : ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
1003 : 0 : ((*aItr).aRangeAddress.StartRow <= nRow) &&
1004 : 0 : ((*aItr).aRangeAddress.EndRow >= nRow))
1005 : : {
1006 : 0 : bIsAutoStyle = aItr->bIsAutoStyle;
1007 : 0 : nValidationIndex = aItr->nValidationIndex;
1008 : 0 : nNumberFormat = aItr->nNumberFormat;
1009 : : /* out-of-bounds is an error elsewhere, so FIXME there! */
1010 : : OSL_ENSURE( static_cast<size_t>(nRow) < pRowDefaults->size(), "nRow out of bounds");
1011 [ # # ]: 0 : if (static_cast<size_t>(nRow) < pRowDefaults->size() &&
[ # # # # ]
1012 : 0 : ((*pRowDefaults)[nRow].nIndex != -1))
1013 : : {
1014 [ # # # # ]: 0 : if (((*pRowDefaults)[nRow].nIndex == (*aItr).nStyleNameIndex) &&
[ # # ]
1015 : 0 : ((*pRowDefaults)[nRow].bIsAutoStyle == (*aItr).bIsAutoStyle))
1016 : 0 : return -1;
1017 : : else
1018 : 0 : return (*aItr).nStyleNameIndex;
1019 : : }
1020 : : else
1021 : : {
1022 : : OSL_ENSURE( static_cast<size_t>(nColumn) < pColDefaults->size(), "nColumn out of bounds");
1023 [ # # # # : 0 : if (static_cast<size_t>(nColumn) < pColDefaults->size() &&
# # # # ]
[ # # ]
1024 : 0 : ((*pColDefaults)[nColumn].nIndex != -1) &&
1025 : 0 : ((*pColDefaults)[nColumn].nIndex == (*aItr).nStyleNameIndex) &&
1026 : 0 : ((*pColDefaults)[nColumn].bIsAutoStyle == (*aItr).bIsAutoStyle))
1027 : 0 : return -1;
1028 : : else
1029 : 0 : return (*aItr).nStyleNameIndex;
1030 : : }
1031 : : }
1032 : : else
1033 : : {
1034 [ # # ]: 0 : if ((*aItr).aRangeAddress.EndRow < nRemoveBeforeRow)
1035 [ # # ]: 0 : aItr = pFormatRanges->erase(aItr);
1036 : : else
1037 : 0 : ++aItr;
1038 : : }
1039 : : }
1040 : 0 : return -1;
1041 : : }
1042 : :
1043 : 4 : void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
1044 : : const sal_Int32 nTable, ScRowFormatRanges* pRowFormatRanges)
1045 : : {
1046 : 4 : sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
1047 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
1048 : 4 : ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
1049 : 4 : ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
1050 : 4 : ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
1051 : 4 : sal_Int32 nColumns = 0;
1052 [ + + ][ + - ]: 8 : while (aItr != aEndItr && nColumns < nTotalColumns)
[ + + ]
1053 : : {
1054 : : #if OSL_DEBUG_LEVEL > 1
1055 : : table::CellRangeAddress aTempRangeAddress((*aItr).aRangeAddress);
1056 : : #endif
1057 [ + - + - ]: 8 : if (((*aItr).aRangeAddress.StartRow <= nRow) &&
[ + - ]
1058 : 4 : ((*aItr).aRangeAddress.EndRow >= nRow))
1059 : : {
1060 [ + - - + : 8 : if ((((*aItr).aRangeAddress.StartColumn <= nStartColumn) &&
# # # # #
# # # ]
[ + - ]
1061 : 4 : ((*aItr).aRangeAddress.EndColumn >= nStartColumn)) ||
1062 : 0 : (((*aItr).aRangeAddress.StartColumn <= nEndColumn) &&
1063 : 0 : ((*aItr).aRangeAddress.EndColumn >= nEndColumn)) ||
1064 : 0 : (((*aItr).aRangeAddress.StartColumn >= nStartColumn) &&
1065 : 0 : ((*aItr).aRangeAddress.EndColumn <= nEndColumn)))
1066 : : {
1067 : 4 : ScMyRowFormatRange aRange;
1068 : 4 : aRange.nIndex = aItr->nStyleNameIndex;
1069 : 4 : aRange.nValidationIndex = aItr->nValidationIndex;
1070 : 4 : aRange.bIsAutoStyle = aItr->bIsAutoStyle;
1071 [ - + ]: 4 : if ((aItr->aRangeAddress.StartColumn < nStartColumn) &&
[ - + # # ]
1072 : 0 : (aItr->aRangeAddress.EndColumn >= nStartColumn))
1073 : : {
1074 [ # # ]: 0 : if (aItr->aRangeAddress.EndColumn >= nEndColumn)
1075 : 0 : aRange.nRepeatColumns = nTotalColumns;
1076 : : else
1077 : 0 : aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - nStartColumn + 1;
1078 : 0 : aRange.nStartColumn = nStartColumn;
1079 : : }
1080 [ + - - + ]: 8 : else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
[ - + ]
1081 : 4 : (aItr->aRangeAddress.EndColumn <= nEndColumn))
1082 : : {
1083 : 0 : aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - aItr->aRangeAddress.StartColumn + 1;
1084 : 0 : aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
1085 : : }
1086 [ + - + - : 12 : else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
+ - ][ + - ]
1087 : 4 : (aItr->aRangeAddress.StartColumn <= nEndColumn) &&
1088 : 4 : (aItr->aRangeAddress.EndColumn > nEndColumn))
1089 : : {
1090 : 4 : aRange.nRepeatColumns = nEndColumn - aItr->aRangeAddress.StartColumn + 1;
1091 : 4 : aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
1092 : : }
1093 : 4 : aRange.nRepeatRows = aItr->aRangeAddress.EndRow - nRow + 1;
1094 [ + - ]: 4 : pRowFormatRanges->AddRange(aRange, nRow);
1095 : 4 : nColumns += aRange.nRepeatColumns;
1096 : : }
1097 : 4 : ++aItr;
1098 : : }
1099 : : else
1100 [ # # ]: 0 : if(aItr->aRangeAddress.EndRow < nRow)
1101 [ # # ]: 0 : aItr = pFormatRanges->erase(aItr);
1102 : : else
1103 : 0 : ++aItr;
1104 : : }
1105 [ + - ]: 4 : pRowFormatRanges->Sort();
1106 : 4 : }
1107 : :
1108 : 4 : void ScFormatRangeStyles::AddRangeStyleName(const table::CellRangeAddress aCellRangeAddress,
1109 : : const sal_Int32 nStringIndex, const bool bIsAutoStyle, const sal_Int32 nValidationIndex,
1110 : : const sal_Int32 nNumberFormat)
1111 : : {
1112 : 4 : ScMyFormatRange aFormatRange;
1113 : 4 : aFormatRange.aRangeAddress = aCellRangeAddress;
1114 : 4 : aFormatRange.nStyleNameIndex = nStringIndex;
1115 : 4 : aFormatRange.nValidationIndex = nValidationIndex;
1116 : 4 : aFormatRange.nNumberFormat = nNumberFormat;
1117 : 4 : aFormatRange.bIsAutoStyle = bIsAutoStyle;
1118 : : OSL_ENSURE(static_cast<size_t>(aCellRangeAddress.Sheet) < aTables.size(), "wrong table");
1119 : 4 : ScMyFormatRangeAddresses* pFormatRanges(aTables[aCellRangeAddress.Sheet]);
1120 [ + - ]: 4 : pFormatRanges->push_back(aFormatRange);
1121 : 4 : }
1122 : :
1123 : 4 : rtl::OUString* ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
1124 : : {
1125 [ - + ]: 4 : if (bIsAutoStyle)
1126 : 0 : return aAutoStyleNames[nIndex];
1127 : : else
1128 : 4 : return aStyleNames[nIndex];
1129 : : }
1130 : :
1131 : 4 : void ScFormatRangeStyles::Sort()
1132 : : {
1133 : 4 : sal_Int32 nTables = aTables.size();
1134 [ + + ]: 8 : for (sal_Int16 i = 0; i < nTables; ++i)
1135 [ + - ]: 4 : if (!aTables[i]->empty())
1136 : 4 : aTables[i]->sort();
1137 : 4 : }
1138 : :
1139 : : //===========================================================================
1140 : :
1141 : 12 : ScColumnRowStylesBase::ScColumnRowStylesBase()
1142 : 12 : : aStyleNames()
1143 : : {
1144 : 12 : }
1145 : :
1146 : 12 : ScColumnRowStylesBase::~ScColumnRowStylesBase()
1147 : : {
1148 : 12 : ScMyOUStringVec::iterator i(aStyleNames.begin());
1149 : 12 : ScMyOUStringVec::iterator endi(aStyleNames.end());
1150 [ + - ][ + + ]: 20 : while (i != endi)
1151 : : {
1152 [ + - ]: 8 : delete *i;
1153 : 8 : ++i;
1154 : : }
1155 [ - + ]: 12 : }
1156 : :
1157 : 8 : sal_Int32 ScColumnRowStylesBase::AddStyleName(rtl::OUString* pString)
1158 : : {
1159 : 8 : aStyleNames.push_back(pString);
1160 : 8 : return aStyleNames.size() - 1;
1161 : : }
1162 : :
1163 : 0 : sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const rtl::OUString& rString, const rtl::OUString& rPrefix)
1164 : : {
1165 : 0 : sal_Int32 nPrefixLength(rPrefix.getLength());
1166 : 0 : rtl::OUString sTemp(rString.copy(nPrefixLength));
1167 : 0 : sal_Int32 nIndex(sTemp.toInt32());
1168 [ # # ][ # # ]: 0 : if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1)->equals(rString))
[ # # ][ # # ]
[ # # ]
1169 : 0 : return nIndex - 1;
1170 : : else
1171 : : {
1172 : 0 : sal_Int32 i(0);
1173 : 0 : bool bFound(false);
1174 [ # # ][ # # ]: 0 : while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
[ # # ]
1175 : : {
1176 [ # # ][ # # ]: 0 : if (aStyleNames.at(i)->equals(rString))
1177 : 0 : bFound = true;
1178 : : else
1179 : 0 : ++i;
1180 : : }
1181 [ # # ]: 0 : if (bFound)
1182 : 0 : return i;
1183 : : else
1184 : 0 : return -1;
1185 : 0 : }
1186 : : }
1187 : :
1188 : 8 : rtl::OUString* ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
1189 : : {
1190 [ + - ][ - + ]: 8 : if ( nIndex < 0 || nIndex >= sal::static_int_cast<sal_Int32>( aStyleNames.size() ) )
[ - + ]
1191 : : {
1192 : : // should no longer happen, use first style then
1193 : : OSL_FAIL("GetStyleNameByIndex: invalid index");
1194 : 0 : return aStyleNames[0];
1195 : : }
1196 : :
1197 : 8 : return aStyleNames[nIndex];
1198 : : }
1199 : :
1200 : : //===========================================================================
1201 : :
1202 : 6 : ScColumnStyles::ScColumnStyles()
1203 : : : ScColumnRowStylesBase(),
1204 [ + - ]: 6 : aTables()
1205 : : {
1206 : 6 : }
1207 : :
1208 : 6 : ScColumnStyles::~ScColumnStyles()
1209 : : {
1210 [ - + ]: 12 : }
1211 : :
1212 : 4 : void ScColumnStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
1213 : : {
1214 : 4 : sal_Int32 nSize(aTables.size() - 1);
1215 [ + - ]: 4 : if (nTable > nSize)
1216 [ + + ]: 8 : for (sal_Int32 i = nSize; i < nTable; ++i)
1217 : : {
1218 [ + - ]: 4 : ScMyColumnStyleVec aFieldsVec(nFields + 1, ScColumnStyle());
1219 [ + - ]: 4 : aTables.push_back(aFieldsVec);
1220 : 4 : }
1221 : 4 : }
1222 : :
1223 : 4 : sal_Int32 ScColumnStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
1224 : : bool& bIsVisible)
1225 : : {
1226 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
1227 [ + - ]: 4 : if (static_cast<size_t>(nField) < aTables[nTable].size())
1228 : : {
1229 : 4 : bIsVisible = aTables[nTable][nField].bIsVisible;
1230 : 4 : return aTables[nTable][nField].nIndex;
1231 : : }
1232 : : else
1233 : : {
1234 : 0 : bIsVisible = aTables[nTable][aTables[nTable].size() - 1].bIsVisible;
1235 : 4 : return aTables[nTable][aTables[nTable].size() - 1].nIndex;
1236 : : }
1237 : : }
1238 : :
1239 : 4096 : void ScColumnStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
1240 : : const sal_Int32 nStringIndex, const bool bIsVisible)
1241 : : {
1242 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
1243 : : OSL_ENSURE(aTables[nTable].size() >= static_cast<sal_uInt32>(nField), "wrong field");
1244 : 4096 : ScColumnStyle aStyle;
1245 : 4096 : aStyle.nIndex = nStringIndex;
1246 : 4096 : aStyle.bIsVisible = bIsVisible;
1247 [ + + ]: 4096 : if (aTables[nTable].size() == static_cast<sal_uInt32>(nField))
1248 [ + - ]: 4092 : aTables[nTable].push_back(aStyle);
1249 : 4096 : aTables[nTable][nField] = aStyle;
1250 : 4096 : }
1251 : :
1252 : 0 : rtl::OUString* ScColumnStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
1253 : : {
1254 : : bool bTemp;
1255 [ # # ][ # # ]: 0 : return GetStyleNameByIndex(GetStyleNameIndex(nTable, nField, bTemp));
1256 : : }
1257 : :
1258 : : //===========================================================================
1259 : :
1260 : 6 : ScRowStyles::Cache::Cache() :
1261 : 6 : mnTable(-1), mnStart(-1), mnEnd(-1), mnStyle(-1) {}
1262 : :
1263 : 4 : bool ScRowStyles::Cache::hasCache(sal_Int32 nTable, sal_Int32 nField) const
1264 : : {
1265 [ - + ][ # # ]: 4 : return mnTable == nTable && mnStart <= nField && nField < mnEnd;
[ # # ]
1266 : : }
1267 : :
1268 : 6 : ScRowStyles::ScRowStyles()
1269 [ + - ]: 6 : : ScColumnRowStylesBase()
1270 : : {
1271 : 6 : }
1272 : :
1273 [ + - ]: 6 : ScRowStyles::~ScRowStyles()
1274 : : {
1275 [ - + ]: 12 : }
1276 : :
1277 : 4 : void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
1278 : : {
1279 : 4 : sal_Int32 nSize(aTables.size() - 1);
1280 [ + - ]: 4 : if (nTable > nSize)
1281 [ + + ]: 8 : for (sal_Int32 i = nSize; i < nTable; ++i)
1282 : : {
1283 [ + - ]: 4 : aTables.push_back(new StylesType(0, nFields+1, -1));
1284 : : }
1285 : 4 : }
1286 : :
1287 : 4 : sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
1288 : : {
1289 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
1290 [ - + ]: 4 : if (!(static_cast<size_t>(nTable) < aTables.size()))
1291 : 0 : return -1;
1292 : :
1293 [ - + ]: 4 : if (maCache.hasCache(nTable, nField))
1294 : : // Cache hit !
1295 : 0 : return maCache.mnStyle;
1296 : :
1297 [ + - ]: 4 : StylesType& r = aTables[nTable];
1298 [ + - ]: 4 : if (!r.is_tree_valid())
1299 [ + - ]: 4 : r.build_tree();
1300 : : sal_Int32 nStyle;
1301 : : sal_Int32 nStart, nEnd;
1302 [ + - ][ + - ]: 4 : if (r.search_tree(nField, nStyle, &nStart, &nEnd))
1303 : : {
1304 : : // Cache this value for better performance.
1305 : 4 : maCache.mnTable = nTable;
1306 : 4 : maCache.mnStart = nStart;
1307 : 4 : maCache.mnEnd = nEnd;
1308 : 4 : maCache.mnStyle = nStyle;
1309 : 4 : return nStyle;
1310 : : }
1311 : :
1312 : 4 : return -1;
1313 : : }
1314 : :
1315 : 4 : void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
1316 : : const sal_Int32 nStringIndex)
1317 : : {
1318 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
1319 : 4 : StylesType& r = aTables[nTable];
1320 : 4 : r.insert_back(nField, nField+1, nStringIndex);
1321 : 4 : }
1322 : :
1323 : 4 : void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField,
1324 : : const sal_Int32 nStringIndex, const sal_Int32 nEndField)
1325 : : {
1326 : : OSL_ENSURE( nStartField <= nEndField, "bad field range");
1327 : : OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
1328 : 4 : StylesType& r = aTables[nTable];
1329 : 4 : r.insert_back(nStartField, nEndField+1, nStringIndex);
1330 : 4 : }
1331 : :
1332 : 0 : rtl::OUString* ScRowStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
1333 : : {
1334 : 0 : return GetStyleNameByIndex(GetStyleNameIndex(nTable, nField));
1335 [ + - ][ + - ]: 153 : }
1336 : :
1337 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|