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