LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - XMLStylesExportHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 248 694 35.7 %
Date: 2012-12-27 Functions: 45 65 69.2 %
Legend: Lines: hit not hit

          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             :         aVal.bShowImputMessage == bShowImputMessage &&
      65             :         aVal.bShowErrorMessage == bShowErrorMessage &&
      66             :         aVal.aBaseCell.Sheet == aBaseCell.Sheet &&
      67             :         aVal.aBaseCell.Column == aBaseCell.Column &&
      68             :         aVal.aBaseCell.Row == aBaseCell.Row &&
      69             :         aVal.aAlertStyle == aAlertStyle &&
      70             :         aVal.aValidationType == aValidationType &&
      71             :         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           2 : ScMyValidationsContainer::ScMyValidationsContainer()
      84             :     : aValidationVec(),
      85             :     sEmptyString(),
      86             :     sERRALSTY(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRALSTY)),
      87             :     sIGNOREBL(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_IGNOREBL)),
      88             :     sSHOWLIST(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWLIST)),
      89             :     sTYPE(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_TYPE)),
      90             :     sSHOWINP(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWINP)),
      91             :     sSHOWERR(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWERR)),
      92             :     sINPTITLE(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPTITLE)),
      93             :     sINPMESS(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPMESS)),
      94             :     sERRTITLE(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRTITLE)),
      95             :     sERRMESS(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRMESS)),
      96             :     sOnError(RTL_CONSTASCII_USTRINGPARAM("OnError")),
      97             :     sEventType(RTL_CONSTASCII_USTRINGPARAM("EventType")),
      98             :     sStarBasic(RTL_CONSTASCII_USTRINGPARAM("StarBasic")),
      99             :     sScript(RTL_CONSTASCII_USTRINGPARAM("Script")),
     100             :     sLibrary(RTL_CONSTASCII_USTRINGPARAM("Library")),
     101           2 :     sMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName"))
     102             : {
     103           2 : }
     104             : 
     105           2 : ScMyValidationsContainer::~ScMyValidationsContainer()
     106             : {
     107           2 : }
     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 :         rtl::OUString sErrorMessage;
     117           0 :         xPropertySet->getPropertyValue(sERRMESS) >>= sErrorMessage;
     118           0 :         rtl::OUString sErrorTitle;
     119           0 :         xPropertySet->getPropertyValue(sERRTITLE) >>= sErrorTitle;
     120           0 :         rtl::OUString sImputMessage;
     121           0 :         xPropertySet->getPropertyValue(sINPMESS) >>= sImputMessage;
     122           0 :         rtl::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 :                 rtl::OUString sCount(rtl::OUString::valueOf(nNameIndex));
     166           0 :                 rtl::OUString sPrefix(RTL_CONSTASCII_USTRINGPARAM("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 : rtl::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 :     rtl::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 += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-date()"));
     192           0 :             break;
     193             :             case sheet::ValidationType_DECIMAL :
     194           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-decimal-number()"));
     195           0 :             break;
     196             :             case sheet::ValidationType_LIST :
     197           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-in-list("));
     198           0 :                 sCondition += aValidation.sFormula1;
     199           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
     200           0 :             break;
     201             :             case sheet::ValidationType_TEXT_LEN :
     202           0 :                 if (aValidation.aOperator != sheet::ConditionOperator_BETWEEN &&
     203             :                     aValidation.aOperator != sheet::ConditionOperator_NOT_BETWEEN)
     204           0 :                     sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-text-length()"));
     205           0 :             break;
     206             :             case sheet::ValidationType_TIME :
     207           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-time()"));
     208           0 :             break;
     209             :             case sheet::ValidationType_WHOLE :
     210           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("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             :             (aValidation.aOperator == sheet::ConditionOperator_BETWEEN &&
     220             :             aValidation.aOperator == sheet::ConditionOperator_NOT_BETWEEN &&
     221           0 :             !aValidation.sFormula2.isEmpty())))
     222             :         {
     223           0 :             if (aValidation.aValidationType != sheet::ValidationType_TEXT_LEN)
     224           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" and "));
     225           0 :             if (aValidation.aOperator != sheet::ConditionOperator_BETWEEN &&
     226             :                 aValidation.aOperator != sheet::ConditionOperator_NOT_BETWEEN)
     227             :             {
     228           0 :                 if (aValidation.aValidationType != sheet::ValidationType_TEXT_LEN)
     229           0 :                     sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content()"));
     230           0 :                 switch (aValidation.aOperator)
     231             :                 {
     232             :                     case sheet::ConditionOperator_EQUAL :
     233           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("="));
     234           0 :                     break;
     235             :                     case sheet::ConditionOperator_GREATER :
     236           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(">"));
     237           0 :                     break;
     238             :                     case sheet::ConditionOperator_GREATER_EQUAL :
     239           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(">="));
     240           0 :                     break;
     241             :                     case sheet::ConditionOperator_LESS :
     242           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<"));
     243           0 :                     break;
     244             :                     case sheet::ConditionOperator_LESS_EQUAL :
     245           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("<="));
     246           0 :                     break;
     247             :                     case sheet::ConditionOperator_NOT_EQUAL :
     248           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("!="));
     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 += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-text-length-is-between("));
     263             :                     else
     264           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-text-length-is-not-between("));
     265             :                 }
     266             :                 else
     267             :                 {
     268           0 :                     if (aValidation.aOperator == sheet::ConditionOperator_BETWEEN)
     269           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-between("));
     270             :                     else
     271           0 :                         sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("cell-content-is-not-between("));
     272             :                 }
     273           0 :                 sCondition += aValidation.sFormula1;
     274           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","));
     275           0 :                 sCondition += aValidation.sFormula2;
     276           0 :                 sCondition += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
     277             :             }
     278             :         }
     279             :         else
     280           0 :             if (aValidation.aValidationType == sheet::ValidationType_TEXT_LEN)
     281           0 :                 sCondition = rtl::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 : rtl::OUString ScMyValidationsContainer::GetBaseCellAddress(ScDocument* pDoc, const table::CellAddress& aCell)
     294             : {
     295           0 :     rtl::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 rtl::OUString& sTitle, const rtl::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 :         rtl::OUStringBuffer sTemp;
     319           0 :         rtl::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.getLength())
     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           2 : void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
     343             : {
     344           2 :     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 :             rtl::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           2 : }
     446             : 
     447           0 : const rtl::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           2 : 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           2 :     if (bRow)
     460             :         return pCellStyles->GetStyleNameIndex(nTable, nPos, i,
     461           0 :                                 bIsAutoStyle);
     462             :     else
     463             :         return pCellStyles->GetStyleNameIndex(nTable, i, nPos,
     464           2 :                                 bIsAutoStyle);
     465             : }
     466             : 
     467           4 : 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           4 :     if (pDoc)
     473             :     {
     474           4 :         SCTAB nTab = static_cast<SCTAB>(nTable);
     475             :         sal_Int32 nPos;
     476             :         sal_Int32 nLast;
     477             :         ScMyDefaultStyleList* pDefaults;
     478           4 :         if (bRow)
     479             :         {
     480           2 :             pDefaults = pRowDefaults;
     481           2 :             nLast = nLastRow;
     482             :         }
     483             :         else
     484             :         {
     485           2 :             pDefaults = pColDefaults;
     486           2 :             nLast = nLastCol;
     487             :         }
     488           4 :         bool bPrevAutoStyle(false);
     489             :         bool bIsAutoStyle;
     490             :         bool bResult;
     491           4 :         sal_Int32 nPrevIndex(0);
     492             :         sal_Int32 nIndex;
     493           4 :         sal_Int32 nRepeat(0);
     494           4 :         sal_Int32 nEmptyRepeat(0);
     495           8 :         for (sal_Int32 i = nLast; i >= 0; --i)
     496             :         {
     497           4 :             if (bRow)
     498             :             {
     499             :                 SCCOL nCol;
     500             :                 bResult = pDoc->GetRowDefault(nTab,
     501           2 :                     static_cast<SCROW>(i), static_cast<SCCOL>(nLastCol), nCol);
     502           2 :                 nPos = static_cast<sal_Int32>(nCol);
     503             :             }
     504             :             else
     505             :             {
     506             :                 SCROW nRow;
     507             :                 bResult = pDoc->GetColDefault(nTab,
     508           2 :                     static_cast<SCCOL>(i), static_cast<SCROW>(nLastRow), nRow);
     509           2 :                 nPos = static_cast<sal_Int32>(nRow);
     510             :             }
     511           4 :             if (bResult)
     512             :             {
     513           2 :                 nEmptyRepeat = 0;
     514           2 :                 if (!nRepeat)
     515             :                 {
     516             :                     nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i,
     517           2 :                                                 bRow, bPrevAutoStyle);
     518           2 :                     (*pDefaults)[i].nIndex = nPrevIndex;
     519           2 :                     (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
     520           2 :                     nRepeat = 1;
     521             :                 }
     522             :                 else
     523             :                 {
     524             :                     nIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i,
     525           0 :                                             bRow, bIsAutoStyle);
     526           0 :                     if ((nIndex != nPrevIndex) || (bIsAutoStyle != bPrevAutoStyle))
     527             :                     {
     528           0 :                         nRepeat = 1;
     529             :                         nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i,
     530           0 :                                                 bRow, bPrevAutoStyle);
     531           0 :                         (*pDefaults)[i].nIndex = nPrevIndex;
     532           0 :                         (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
     533             :                     }
     534             :                     else
     535             :                     {
     536           0 :                         (*pDefaults)[i].nIndex = nPrevIndex;
     537           0 :                         (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
     538           0 :                         ++nRepeat;
     539           0 :                         if (nRepeat > 1)
     540           0 :                             (*pDefaults)[i].nRepeat = nRepeat;
     541             :                     }
     542             :                 }
     543             :             }
     544             :             else
     545             :             {
     546           2 :                 nRepeat = 0;
     547           2 :                 if (!nEmptyRepeat)
     548           2 :                     nEmptyRepeat = 1;
     549             :                 else
     550             :                 {
     551           0 :                     ++nEmptyRepeat;
     552           0 :                     if (nEmptyRepeat > 1)
     553           0 :                         (*pDefaults)[i].nRepeat = nEmptyRepeat;
     554             :                 }
     555             :             }
     556             :         }
     557             :     }
     558           4 : }
     559             : 
     560           2 : void ScMyDefaultStyles::FillDefaultStyles(const sal_Int32 nTable,
     561             :     const sal_Int32 nLastRow, const sal_Int32 nLastCol,
     562             :     const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc)
     563             : {
     564           2 :     if (pRowDefaults)
     565           0 :         delete pRowDefaults;
     566           2 :     pRowDefaults = new ScMyDefaultStyleList(nLastRow + 1);
     567           2 :      FillDefaultStyles(nTable, nLastRow, nLastCol, pCellStyles, pDoc, true);
     568           2 :     if (pColDefaults)
     569           0 :         delete pColDefaults;
     570           2 :     pColDefaults = new ScMyDefaultStyleList(nLastCol + 1);
     571           2 :      FillDefaultStyles(nTable, nLastRow, nLastCol, pCellStyles, pDoc, false);
     572           2 : }
     573             : 
     574           2 : ScMyDefaultStyles::~ScMyDefaultStyles()
     575             : {
     576           2 :     if (pRowDefaults)
     577           2 :         delete pRowDefaults;
     578           2 :     if (pColDefaults)
     579           2 :         delete pColDefaults;
     580           2 : }
     581             : 
     582           4 : ScMyRowFormatRange::ScMyRowFormatRange()
     583             :     : nStartColumn(0),
     584             :     nRepeatColumns(0),
     585             :     nRepeatRows(0),
     586             :     nIndex(-1),
     587             :     nValidationIndex(-1),
     588           4 :     bIsAutoStyle(true)
     589             : {
     590           4 : }
     591             : 
     592           0 : bool ScMyRowFormatRange::operator< (const ScMyRowFormatRange& rRange) const
     593             : {
     594           0 :     return (nStartColumn < rRange.nStartColumn);
     595             : }
     596             : 
     597           2 : ScRowFormatRanges::ScRowFormatRanges()
     598             :     : aRowFormatRanges(),
     599             :     pRowDefaults(NULL),
     600             :     pColDefaults(NULL),
     601           2 :     nSize(0)
     602             : {
     603           2 : }
     604             : 
     605           0 : ScRowFormatRanges::ScRowFormatRanges(const ScRowFormatRanges* pRanges)
     606             :     : aRowFormatRanges(pRanges->aRowFormatRanges),
     607             :     pRowDefaults(pRanges->pRowDefaults),
     608             :     pColDefaults(pRanges->pColDefaults),
     609           0 :     nSize(pRanges->nSize)
     610             : {
     611           0 : }
     612             : 
     613           2 : ScRowFormatRanges::~ScRowFormatRanges()
     614             : {
     615           2 : }
     616             : 
     617           8 : void ScRowFormatRanges::Clear()
     618             : {
     619           8 :     aRowFormatRanges.clear();
     620           8 :     nSize = 0;
     621           8 : }
     622             : 
     623           0 : void ScRowFormatRanges::AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
     624             :     const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange)
     625             : {
     626           0 :     sal_Int32 nIndex(-1);
     627           0 :     if ((nPrevIndex != rFormatRange.nIndex) ||
     628             :         (bPrevAutoStyle != rFormatRange.bIsAutoStyle))
     629           0 :         nIndex = rFormatRange.nIndex;
     630             : 
     631           0 :     bool bInserted(false);
     632           0 :     if (!aRowFormatRanges.empty())
     633             :     {
     634           0 :         ScMyRowFormatRange* pRange(&aRowFormatRanges.back());
     635           0 :         if (pRange)
     636             :         {
     637           0 :             if ((nPrevStartCol == (pRange->nStartColumn + pRange->nRepeatColumns)) &&
     638             :                 (pRange->bIsAutoStyle == rFormatRange.bIsAutoStyle) &&
     639             :                 (pRange->nIndex == nIndex) &&
     640             :                 (pRange->nValidationIndex == rFormatRange.nValidationIndex))
     641             :             {
     642           0 :                 if (rFormatRange.nRepeatRows < pRange->nRepeatRows)
     643           0 :                     pRange->nRepeatRows = rFormatRange.nRepeatRows;
     644           0 :                 pRange->nRepeatColumns += nRepeat;
     645           0 :                 bInserted = true;
     646             :             }
     647             :         }
     648             :     }
     649           0 :     if (!bInserted)
     650             :     {
     651           0 :         ScMyRowFormatRange aRange;
     652           0 :         aRange.nStartColumn = nPrevStartCol;
     653           0 :         aRange.nRepeatColumns = nRepeat;
     654           0 :         aRange.nRepeatRows = rFormatRange.nRepeatRows;
     655           0 :         aRange.nValidationIndex = rFormatRange.nValidationIndex;
     656           0 :         aRange.bIsAutoStyle = rFormatRange.bIsAutoStyle;
     657           0 :         aRange.nIndex = nIndex;
     658           0 :         aRowFormatRanges.push_back(aRange);
     659           0 :         ++nSize;
     660             :     }
     661           0 : }
     662             : 
     663           0 : void ScRowFormatRanges::AddRange(ScMyRowFormatRange& rFormatRange,
     664             :     const sal_Int32 nRow)
     665             : {
     666             :     OSL_ENSURE(pRowDefaults, "no row defaults");
     667           0 :     if (!pRowDefaults)
     668           0 :         return;
     669             :     OSL_ENSURE(pColDefaults, "no column defaults");
     670           0 :     if (!pColDefaults)
     671           0 :         return;
     672             :     sal_Int32 nPrevIndex;
     673             :     bool bPrevAutoStyle;
     674             :     OSL_ENSURE( static_cast<size_t>(nRow) < pRowDefaults->size(), "nRow out of bounds");
     675           0 :     if (!(static_cast<size_t>(nRow) < pRowDefaults->size()))
     676             :     {
     677             :         /* This is only to prevent out-of-bounds accesses, once reached here
     678             :          * there's something else going wrong, so FIXME there! */
     679           0 :         if (pRowDefaults->empty())
     680             :         {
     681           0 :             nPrevIndex = -1;
     682           0 :             bPrevAutoStyle = false;
     683             :         }
     684             :         else
     685             :         {
     686           0 :             nPrevIndex = (*pRowDefaults)[pRowDefaults->size()-1].nIndex;
     687           0 :             bPrevAutoStyle = (*pRowDefaults)[pRowDefaults->size()-1].bIsAutoStyle;
     688             :         }
     689             :     }
     690             :     else
     691             :     {
     692           0 :         nPrevIndex = (*pRowDefaults)[nRow].nIndex;
     693           0 :         bPrevAutoStyle = (*pRowDefaults)[nRow].bIsAutoStyle;
     694             :     }
     695           0 :     sal_uInt32 nEnd (rFormatRange.nRepeatRows + nRow - 1);
     696           0 :     sal_uInt32 i(nRow + 1);
     697           0 :     bool bReady(false);
     698           0 :     while ((i < nEnd) && !bReady && (i < pRowDefaults->size()))
     699             :     {
     700           0 :         if ((nPrevIndex != (*pRowDefaults)[i].nIndex) ||
     701           0 :             (bPrevAutoStyle != (*pRowDefaults)[i].bIsAutoStyle))
     702           0 :             bReady = true;
     703             :         else
     704           0 :             i += (*pRowDefaults)[i].nRepeat;
     705             :     }
     706           0 :     if (i > nEnd)
     707           0 :         i = nEnd;
     708           0 :     if (bReady)
     709           0 :         rFormatRange.nRepeatRows = i - nRow + 1;
     710           0 :     if (nPrevIndex == -1)
     711             :     {
     712           0 :         sal_uInt32 nPrevStartCol(rFormatRange.nStartColumn);
     713             :         OSL_ENSURE( static_cast<size_t>(nPrevStartCol) < pColDefaults->size(), "nPrevStartCol out of bounds");
     714             :         sal_uInt32 nRepeat;
     715           0 :         if (static_cast<size_t>(nPrevStartCol) < pColDefaults->size())
     716             :         {
     717           0 :             nRepeat = (*pColDefaults)[nPrevStartCol].nRepeat;
     718           0 :             nPrevIndex = (*pColDefaults)[nPrevStartCol].nIndex;
     719           0 :             bPrevAutoStyle = (*pColDefaults)[nPrevStartCol].bIsAutoStyle;
     720             :         }
     721             :         else
     722             :         {
     723             :             /* Again, this is to prevent out-of-bounds accesses, so FIXME
     724             :              * elsewhere! */
     725           0 :             if (pColDefaults->empty())
     726             :             {
     727           0 :                 nRepeat = 1;
     728           0 :                 nPrevIndex = -1;
     729           0 :                 bPrevAutoStyle = false;
     730             :             }
     731             :             else
     732             :             {
     733           0 :                 nRepeat = (*pColDefaults)[pColDefaults->size()-1].nRepeat;
     734           0 :                 nPrevIndex = (*pColDefaults)[pColDefaults->size()-1].nIndex;
     735           0 :                 bPrevAutoStyle = (*pColDefaults)[pColDefaults->size()-1].bIsAutoStyle;
     736             :             }
     737             :         }
     738           0 :         nEnd = nPrevStartCol + rFormatRange.nRepeatColumns;
     739           0 :         for(i = nPrevStartCol + nRepeat; i < nEnd && i < pColDefaults->size(); i += (*pColDefaults)[i].nRepeat)
     740             :         {
     741             :             OSL_ENSURE(sal_uInt32(nPrevStartCol + nRepeat) <= nEnd, "something wents wrong");
     742           0 :             if ((nPrevIndex != (*pColDefaults)[i].nIndex) ||
     743           0 :                 (bPrevAutoStyle != (*pColDefaults)[i].bIsAutoStyle))
     744             :             {
     745           0 :                 AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
     746           0 :                 nPrevStartCol = i;
     747           0 :                 nRepeat = (*pColDefaults)[i].nRepeat;
     748           0 :                 nPrevIndex = (*pColDefaults)[i].nIndex;
     749           0 :                 bPrevAutoStyle = (*pColDefaults)[i].bIsAutoStyle;
     750             :             }
     751             :             else
     752           0 :                 nRepeat += (*pColDefaults)[i].nRepeat;
     753             :         }
     754           0 :         if (sal_uInt32(nPrevStartCol + nRepeat) > nEnd)
     755           0 :             nRepeat = nEnd - nPrevStartCol;
     756           0 :         AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
     757             :     }
     758           0 :     else if ((nPrevIndex == rFormatRange.nIndex) &&
     759             :         (bPrevAutoStyle == rFormatRange.bIsAutoStyle))
     760             :     {
     761           0 :         rFormatRange.nIndex = -1;
     762           0 :         aRowFormatRanges.push_back(rFormatRange);
     763           0 :         ++nSize;
     764             :     }
     765             : }
     766             : 
     767           4 : bool ScRowFormatRanges::GetNext(ScMyRowFormatRange& aFormatRange)
     768             : {
     769           4 :     ScMyRowFormatRangesList::iterator aItr(aRowFormatRanges.begin());
     770           4 :     if (aItr != aRowFormatRanges.end())
     771             :     {
     772           0 :         aFormatRange = (*aItr);
     773           0 :         aRowFormatRanges.erase(aItr);
     774           0 :         --nSize;
     775           0 :         return true;
     776             :     }
     777           4 :     return false;
     778             : }
     779             : 
     780           0 : sal_Int32 ScRowFormatRanges::GetMaxRows() const
     781             : {
     782           0 :     ScMyRowFormatRangesList::const_iterator aItr(aRowFormatRanges.begin());
     783           0 :     ScMyRowFormatRangesList::const_iterator aEndItr(aRowFormatRanges.end());
     784           0 :     sal_Int32 nMaxRows = MAXROW + 1;
     785           0 :     if (aItr != aEndItr)
     786             :     {
     787           0 :         while (aItr != aEndItr)
     788             :         {
     789           0 :             if ((*aItr).nRepeatRows < nMaxRows)
     790           0 :                 nMaxRows = (*aItr).nRepeatRows;
     791           0 :             ++aItr;
     792             :         }
     793             :     }
     794             :     else
     795             :     {
     796             :         OSL_FAIL("no ranges found");
     797             :     }
     798           0 :     return nMaxRows;
     799             : }
     800             : 
     801           0 : sal_Int32 ScRowFormatRanges::GetSize() const
     802             : {
     803           0 :     return nSize;
     804             : }
     805             : 
     806           4 : void ScRowFormatRanges::Sort()
     807             : {
     808           4 :     aRowFormatRanges.sort();
     809           4 : }
     810             : 
     811             : // ============================================================================
     812           2 : ScMyFormatRange::ScMyFormatRange()
     813             :     : nStyleNameIndex(-1),
     814             :     nValidationIndex(-1),
     815           2 :     bIsAutoStyle(true)
     816             : {
     817           2 : }
     818             : 
     819           0 : bool ScMyFormatRange::operator<(const ScMyFormatRange& rRange) const
     820             : {
     821           0 :     if (aRangeAddress.StartRow < rRange.aRangeAddress.StartRow)
     822           0 :         return true;
     823             :     else
     824           0 :         if (aRangeAddress.StartRow == rRange.aRangeAddress.StartRow)
     825           0 :             return (aRangeAddress.StartColumn < rRange.aRangeAddress.StartColumn);
     826             :         else
     827           0 :             return false;
     828             : }
     829             : 
     830           8 : ScFormatRangeStyles::ScFormatRangeStyles()
     831             :     : aTables(),
     832             :     aStyleNames(),
     833             :     aAutoStyleNames(),
     834             :     pRowDefaults(0),
     835           8 :     pColDefaults(0)
     836             : {
     837           8 : }
     838             : 
     839          16 : ScFormatRangeStyles::~ScFormatRangeStyles()
     840             : {
     841           8 :     ScMyOUStringVec::iterator i(aStyleNames.begin());
     842           8 :     ScMyOUStringVec::iterator endi(aStyleNames.end());
     843          18 :     while (i != endi)
     844             :     {
     845           2 :         delete *i;
     846           2 :         ++i;
     847             :     }
     848           8 :     i = aAutoStyleNames.begin();
     849           8 :     endi = aAutoStyleNames.end();
     850          16 :     while (i != endi)
     851             :     {
     852           0 :         delete *i;
     853           0 :         ++i;
     854             :     }
     855           8 :     ScMyFormatRangeListVec::iterator j(aTables.begin());
     856           8 :     ScMyFormatRangeListVec::iterator endj(aTables.end());
     857          20 :     while (j != endj)
     858             :     {
     859           4 :         delete *j;
     860           4 :         ++j;
     861             :     }
     862           8 : }
     863             : 
     864           4 : void ScFormatRangeStyles::AddNewTable(const sal_Int32 nTable)
     865             : {
     866           4 :     sal_Int32 nSize = aTables.size() - 1;
     867           4 :     if (nTable > nSize)
     868           8 :         for (sal_Int32 i = nSize; i < nTable; ++i)
     869             :         {
     870           4 :             ScMyFormatRangeAddresses* aRangeAddresses(new ScMyFormatRangeAddresses);
     871           4 :             aTables.push_back(aRangeAddresses);
     872             :         }
     873           4 : }
     874             : 
     875           2 : bool ScFormatRangeStyles::AddStyleName(rtl::OUString* rpString, sal_Int32& rIndex, const bool bIsAutoStyle)
     876             : {
     877           2 :     if (bIsAutoStyle)
     878             :     {
     879           0 :         aAutoStyleNames.push_back(rpString);
     880           0 :         rIndex = aAutoStyleNames.size() - 1;
     881           0 :         return true;
     882             :     }
     883             :     else
     884             :     {
     885           2 :         sal_Int32 nCount(aStyleNames.size());
     886           2 :         bool bFound(false);
     887           2 :         sal_Int32 i(nCount - 1);
     888           4 :         while ((i >= 0) && (!bFound))
     889             :         {
     890           0 :             if (aStyleNames.at(i)->equals(*rpString))
     891           0 :                 bFound = true;
     892             :             else
     893           0 :                 i--;
     894             :         }
     895           2 :         if (bFound)
     896             :         {
     897           0 :             rIndex = i;
     898           0 :             return false;
     899             :         }
     900             :         else
     901             :         {
     902           2 :             aStyleNames.push_back(rpString);
     903           2 :             rIndex = aStyleNames.size() - 1;
     904           2 :             return true;
     905             :         }
     906             :     }
     907             : }
     908             : 
     909           0 : sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const rtl::OUString& rString, const rtl::OUString& rPrefix, bool& bIsAutoStyle)
     910             : {
     911           0 :     sal_Int32 nPrefixLength(rPrefix.getLength());
     912           0 :     rtl::OUString sTemp(rString.copy(nPrefixLength));
     913           0 :     sal_Int32 nIndex(sTemp.toInt32());
     914           0 :     if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1)->equals(rString))
     915             :     {
     916           0 :         bIsAutoStyle = true;
     917           0 :         return nIndex - 1;
     918             :     }
     919             :     else
     920             :     {
     921           0 :         sal_Int32 i(0);
     922           0 :         bool bFound(false);
     923           0 :         while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
     924             :         {
     925           0 :             if (aStyleNames[i]->equals(rString))
     926           0 :                 bFound = true;
     927             :             else
     928           0 :                 ++i;
     929             :         }
     930           0 :         if (bFound)
     931             :         {
     932           0 :             bIsAutoStyle = false;
     933           0 :             return i;
     934             :         }
     935             :         else
     936             :         {
     937           0 :             i = 0;
     938           0 :             while (!bFound && static_cast<size_t>(i) < aAutoStyleNames.size())
     939             :             {
     940           0 :                 if (aAutoStyleNames[i]->equals(rString))
     941           0 :                     bFound = true;
     942             :                 else
     943           0 :                     ++i;
     944             :             }
     945           0 :             if (bFound)
     946             :             {
     947           0 :                 bIsAutoStyle = true;
     948           0 :                 return i;
     949             :             }
     950             :             else
     951           0 :                 return -1;
     952             :         }
     953           0 :     }
     954             : }
     955             : 
     956           2 : sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
     957             :     const sal_Int32 nColumn, const sal_Int32 nRow, bool& bIsAutoStyle) const
     958             : {
     959             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
     960           2 :     if (!(static_cast<size_t>(nTable) < aTables.size()))
     961           0 :         return -1;
     962           2 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
     963           2 :     ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
     964           2 :     ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
     965           4 :     while (aItr != aEndItr)
     966             :     {
     967           8 :         if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
     968           2 :             ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
     969           2 :             ((*aItr).aRangeAddress.StartRow <= nRow) &&
     970           2 :             ((*aItr).aRangeAddress.EndRow >= nRow))
     971             :         {
     972           2 :             bIsAutoStyle = aItr->bIsAutoStyle;
     973           2 :             return (*aItr).nStyleNameIndex;
     974             :         }
     975             :         else
     976           0 :             ++aItr;
     977             :     }
     978           0 :     return -1;
     979             : }
     980             : 
     981           2 : sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
     982             :     bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow)
     983             : {
     984             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
     985           2 :     if (!(static_cast<size_t>(nTable) < aTables.size()))
     986           0 :         return -1;
     987           2 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
     988           2 :     ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
     989           2 :     ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
     990           4 :     while (aItr != aEndItr)
     991             :     {
     992           8 :         if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
     993           2 :             ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
     994           2 :             ((*aItr).aRangeAddress.StartRow <= nRow) &&
     995           2 :             ((*aItr).aRangeAddress.EndRow >= nRow))
     996             :         {
     997           2 :             bIsAutoStyle = aItr->bIsAutoStyle;
     998           2 :             nValidationIndex = aItr->nValidationIndex;
     999           2 :             nNumberFormat = aItr->nNumberFormat;
    1000             :             /* out-of-bounds is an error elsewhere, so FIXME there! */
    1001             :             OSL_ENSURE( static_cast<size_t>(nRow) < pRowDefaults->size(), "nRow out of bounds");
    1002           4 :             if (static_cast<size_t>(nRow) < pRowDefaults->size() &&
    1003           2 :                     ((*pRowDefaults)[nRow].nIndex != -1))
    1004             :             {
    1005           0 :                 if (((*pRowDefaults)[nRow].nIndex == (*aItr).nStyleNameIndex) &&
    1006           0 :                     ((*pRowDefaults)[nRow].bIsAutoStyle == (*aItr).bIsAutoStyle))
    1007           0 :                     return -1;
    1008             :                 else
    1009           0 :                     return (*aItr).nStyleNameIndex;
    1010             :             }
    1011             :             else
    1012             :             {
    1013             :                 OSL_ENSURE( static_cast<size_t>(nColumn) < pColDefaults->size(), "nColumn out of bounds");
    1014          12 :                 if (static_cast<size_t>(nColumn) < pColDefaults->size() &&
    1015           2 :                         ((*pColDefaults)[nColumn].nIndex != -1) &&
    1016           4 :                         ((*pColDefaults)[nColumn].nIndex == (*aItr).nStyleNameIndex) &&
    1017           4 :                         ((*pColDefaults)[nColumn].bIsAutoStyle == (*aItr).bIsAutoStyle))
    1018           2 :                     return -1;
    1019             :                 else
    1020           0 :                     return (*aItr).nStyleNameIndex;
    1021             :             }
    1022             :         }
    1023             :         else
    1024             :         {
    1025           0 :             if ((*aItr).aRangeAddress.EndRow < nRemoveBeforeRow)
    1026           0 :                 aItr = pFormatRanges->erase(aItr);
    1027             :             else
    1028           0 :                 ++aItr;
    1029             :         }
    1030             :     }
    1031           0 :     return -1;
    1032             : }
    1033             : 
    1034           4 : void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
    1035             :                     const sal_Int32 nTable, ScRowFormatRanges* pRowFormatRanges)
    1036             : {
    1037           4 :     sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
    1038             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1039           4 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
    1040           4 :     ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
    1041           4 :     ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
    1042           4 :     sal_Int32 nColumns = 0;
    1043           8 :     while (aItr != aEndItr && nColumns < nTotalColumns)
    1044             :     {
    1045             : #if OSL_DEBUG_LEVEL > 1
    1046             :         table::CellRangeAddress aTempRangeAddress((*aItr).aRangeAddress);
    1047             : #endif
    1048           0 :         if (((*aItr).aRangeAddress.StartRow <= nRow) &&
    1049           0 :             ((*aItr).aRangeAddress.EndRow >= nRow))
    1050             :         {
    1051           0 :             if ((((*aItr).aRangeAddress.StartColumn <= nStartColumn) &&
    1052           0 :                 ((*aItr).aRangeAddress.EndColumn >= nStartColumn)) ||
    1053           0 :                 (((*aItr).aRangeAddress.StartColumn <= nEndColumn) &&
    1054           0 :                 ((*aItr).aRangeAddress.EndColumn >= nEndColumn)) ||
    1055           0 :                 (((*aItr).aRangeAddress.StartColumn >= nStartColumn) &&
    1056           0 :                 ((*aItr).aRangeAddress.EndColumn <= nEndColumn)))
    1057             :             {
    1058           0 :                 ScMyRowFormatRange aRange;
    1059           0 :                 aRange.nIndex = aItr->nStyleNameIndex;
    1060           0 :                 aRange.nValidationIndex = aItr->nValidationIndex;
    1061           0 :                 aRange.bIsAutoStyle = aItr->bIsAutoStyle;
    1062           0 :                 if ((aItr->aRangeAddress.StartColumn < nStartColumn) &&
    1063           0 :                     (aItr->aRangeAddress.EndColumn >= nStartColumn))
    1064             :                 {
    1065           0 :                     if (aItr->aRangeAddress.EndColumn >= nEndColumn)
    1066           0 :                         aRange.nRepeatColumns = nTotalColumns;
    1067             :                     else
    1068           0 :                         aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - nStartColumn + 1;
    1069           0 :                     aRange.nStartColumn = nStartColumn;
    1070             :                 }
    1071           0 :                 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
    1072           0 :                     (aItr->aRangeAddress.EndColumn <= nEndColumn))
    1073             :                 {
    1074           0 :                     aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - aItr->aRangeAddress.StartColumn + 1;
    1075           0 :                     aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
    1076             :                 }
    1077           0 :                 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
    1078           0 :                     (aItr->aRangeAddress.StartColumn <= nEndColumn) &&
    1079           0 :                     (aItr->aRangeAddress.EndColumn > nEndColumn))
    1080             :                 {
    1081           0 :                     aRange.nRepeatColumns = nEndColumn - aItr->aRangeAddress.StartColumn + 1;
    1082           0 :                     aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
    1083             :                 }
    1084           0 :                 aRange.nRepeatRows = aItr->aRangeAddress.EndRow - nRow + 1;
    1085           0 :                 pRowFormatRanges->AddRange(aRange, nRow);
    1086           0 :                 nColumns += aRange.nRepeatColumns;
    1087             :             }
    1088           0 :             ++aItr;
    1089             :         }
    1090             :         else
    1091           0 :             if(aItr->aRangeAddress.EndRow < nRow)
    1092           0 :                 aItr = pFormatRanges->erase(aItr);
    1093             :             else
    1094           0 :                 ++aItr;
    1095             :     }
    1096           4 :     pRowFormatRanges->Sort();
    1097           4 : }
    1098             : 
    1099           2 : void ScFormatRangeStyles::AddRangeStyleName(const table::CellRangeAddress aCellRangeAddress,
    1100             :     const sal_Int32 nStringIndex, const bool bIsAutoStyle, const sal_Int32 nValidationIndex,
    1101             :     const sal_Int32 nNumberFormat)
    1102             : {
    1103           2 :     ScMyFormatRange aFormatRange;
    1104           2 :     aFormatRange.aRangeAddress = aCellRangeAddress;
    1105           2 :     aFormatRange.nStyleNameIndex = nStringIndex;
    1106           2 :     aFormatRange.nValidationIndex = nValidationIndex;
    1107           2 :     aFormatRange.nNumberFormat = nNumberFormat;
    1108           2 :     aFormatRange.bIsAutoStyle = bIsAutoStyle;
    1109             :     OSL_ENSURE(static_cast<size_t>(aCellRangeAddress.Sheet) < aTables.size(), "wrong table");
    1110           2 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[aCellRangeAddress.Sheet]);
    1111           2 :     pFormatRanges->push_back(aFormatRange);
    1112           2 : }
    1113             : 
    1114           2 : rtl::OUString* ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
    1115             : {
    1116           2 :     if (bIsAutoStyle)
    1117           0 :         return aAutoStyleNames[nIndex];
    1118             :     else
    1119           2 :         return aStyleNames[nIndex];
    1120             : }
    1121             : 
    1122           2 : void ScFormatRangeStyles::Sort()
    1123             : {
    1124           2 :     sal_Int32 nTables = aTables.size();
    1125           4 :     for (sal_Int16 i = 0; i < nTables; ++i)
    1126           2 :         if (!aTables[i]->empty())
    1127           2 :             aTables[i]->sort();
    1128           2 : }
    1129             : 
    1130             : //===========================================================================
    1131             : 
    1132           4 : ScColumnRowStylesBase::ScColumnRowStylesBase()
    1133           4 :     : aStyleNames()
    1134             : {
    1135           4 : }
    1136             : 
    1137           8 : ScColumnRowStylesBase::~ScColumnRowStylesBase()
    1138             : {
    1139           4 :     ScMyOUStringVec::iterator i(aStyleNames.begin());
    1140           4 :     ScMyOUStringVec::iterator endi(aStyleNames.end());
    1141          12 :     while (i != endi)
    1142             :     {
    1143           4 :         delete *i;
    1144           4 :         ++i;
    1145             :     }
    1146           4 : }
    1147             : 
    1148           4 : sal_Int32 ScColumnRowStylesBase::AddStyleName(rtl::OUString* pString)
    1149             : {
    1150           4 :     aStyleNames.push_back(pString);
    1151           4 :     return aStyleNames.size() - 1;
    1152             : }
    1153             : 
    1154           0 : sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const rtl::OUString& rString, const rtl::OUString& rPrefix)
    1155             : {
    1156           0 :     sal_Int32 nPrefixLength(rPrefix.getLength());
    1157           0 :     rtl::OUString sTemp(rString.copy(nPrefixLength));
    1158           0 :     sal_Int32 nIndex(sTemp.toInt32());
    1159           0 :     if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1)->equals(rString))
    1160           0 :         return nIndex - 1;
    1161             :     else
    1162             :     {
    1163           0 :         sal_Int32 i(0);
    1164           0 :         bool bFound(false);
    1165           0 :         while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
    1166             :         {
    1167           0 :             if (aStyleNames.at(i)->equals(rString))
    1168           0 :                 bFound = true;
    1169             :             else
    1170           0 :                 ++i;
    1171             :         }
    1172           0 :         if (bFound)
    1173           0 :             return i;
    1174             :         else
    1175           0 :             return -1;
    1176           0 :     }
    1177             : }
    1178             : 
    1179           4 : rtl::OUString* ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
    1180             : {
    1181           4 :     if ( nIndex < 0 || nIndex >= sal::static_int_cast<sal_Int32>( aStyleNames.size() ) )
    1182             :     {
    1183             :         // should no longer happen, use first style then
    1184             :         OSL_FAIL("GetStyleNameByIndex: invalid index");
    1185           0 :         return aStyleNames[0];
    1186             :     }
    1187             : 
    1188           4 :     return aStyleNames[nIndex];
    1189             : }
    1190             : 
    1191             : //===========================================================================
    1192             : 
    1193           2 : ScColumnStyles::ScColumnStyles()
    1194             :     : ScColumnRowStylesBase(),
    1195           2 :     aTables()
    1196             : {
    1197           2 : }
    1198             : 
    1199           4 : ScColumnStyles::~ScColumnStyles()
    1200             : {
    1201           4 : }
    1202             : 
    1203           2 : void ScColumnStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
    1204             : {
    1205           2 :     sal_Int32 nSize(aTables.size() - 1);
    1206           2 :     if (nTable > nSize)
    1207           4 :         for (sal_Int32 i = nSize; i < nTable; ++i)
    1208             :         {
    1209           2 :             ScMyColumnStyleVec aFieldsVec(nFields + 1, ScColumnStyle());
    1210           2 :             aTables.push_back(aFieldsVec);
    1211           2 :         }
    1212           2 : }
    1213             : 
    1214           2 : sal_Int32 ScColumnStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
    1215             :     bool& bIsVisible)
    1216             : {
    1217             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1218           2 :     if (static_cast<size_t>(nField) < aTables[nTable].size())
    1219             :     {
    1220           2 :         bIsVisible = aTables[nTable][nField].bIsVisible;
    1221           2 :         return aTables[nTable][nField].nIndex;
    1222             :     }
    1223             :     else
    1224             :     {
    1225           0 :         bIsVisible = aTables[nTable][aTables[nTable].size() - 1].bIsVisible;
    1226           0 :         return aTables[nTable][aTables[nTable].size() - 1].nIndex;
    1227             :     }
    1228             : }
    1229             : 
    1230        2048 : void ScColumnStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
    1231             :     const sal_Int32 nStringIndex, const bool bIsVisible)
    1232             : {
    1233             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1234             :     OSL_ENSURE(aTables[nTable].size() >= static_cast<sal_uInt32>(nField), "wrong field");
    1235        2048 :     ScColumnStyle aStyle;
    1236        2048 :     aStyle.nIndex = nStringIndex;
    1237        2048 :     aStyle.bIsVisible = bIsVisible;
    1238        2048 :     if (aTables[nTable].size() == static_cast<sal_uInt32>(nField))
    1239        2046 :         aTables[nTable].push_back(aStyle);
    1240        2048 :     aTables[nTable][nField] = aStyle;
    1241        2048 : }
    1242             : 
    1243           0 : rtl::OUString* ScColumnStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
    1244             : {
    1245             :     bool bTemp;
    1246           0 :     return GetStyleNameByIndex(GetStyleNameIndex(nTable, nField, bTemp));
    1247             : }
    1248             : 
    1249             : //===========================================================================
    1250             : 
    1251           2 : ScRowStyles::Cache::Cache() :
    1252           2 :     mnTable(-1), mnStart(-1), mnEnd(-1), mnStyle(-1) {}
    1253             : 
    1254           2 : bool ScRowStyles::Cache::hasCache(sal_Int32 nTable, sal_Int32 nField) const
    1255             : {
    1256           2 :     return mnTable == nTable && mnStart <= nField && nField < mnEnd;
    1257             : }
    1258             : 
    1259           2 : ScRowStyles::ScRowStyles()
    1260           2 :     : ScColumnRowStylesBase()
    1261             : {
    1262           2 : }
    1263             : 
    1264           4 : ScRowStyles::~ScRowStyles()
    1265             : {
    1266           4 : }
    1267             : 
    1268           2 : void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
    1269             : {
    1270           2 :     sal_Int32 nSize(aTables.size() - 1);
    1271           2 :     if (nTable > nSize)
    1272           4 :         for (sal_Int32 i = nSize; i < nTable; ++i)
    1273             :         {
    1274           2 :             aTables.push_back(new StylesType(0, nFields+1, -1));
    1275             :         }
    1276           2 : }
    1277             : 
    1278           2 : sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
    1279             : {
    1280             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1281           2 :     if (!(static_cast<size_t>(nTable) < aTables.size()))
    1282           0 :         return -1;
    1283             : 
    1284           2 :     if (maCache.hasCache(nTable, nField))
    1285             :         // Cache hit !
    1286           0 :         return maCache.mnStyle;
    1287             : 
    1288           2 :     StylesType& r = aTables[nTable];
    1289           2 :     if (!r.is_tree_valid())
    1290           2 :         r.build_tree();
    1291             :     sal_Int32 nStyle;
    1292             :     sal_Int32 nStart, nEnd;
    1293           2 :     if (r.search_tree(nField, nStyle, &nStart, &nEnd))
    1294             :     {
    1295             :         // Cache this value for better performance.
    1296           2 :         maCache.mnTable = nTable;
    1297           2 :         maCache.mnStart = nStart;
    1298           2 :         maCache.mnEnd = nEnd;
    1299           2 :         maCache.mnStyle = nStyle;
    1300           2 :         return nStyle;
    1301             :     }
    1302             : 
    1303           0 :     return -1;
    1304             : }
    1305             : 
    1306           2 : void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
    1307             :     const sal_Int32 nStringIndex)
    1308             : {
    1309             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1310           2 :     StylesType& r = aTables[nTable];
    1311           2 :     r.insert_back(nField, nField+1, nStringIndex);
    1312           2 : }
    1313             : 
    1314           2 : void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField,
    1315             :         const sal_Int32 nStringIndex, const sal_Int32 nEndField)
    1316             : {
    1317             :     OSL_ENSURE( nStartField <= nEndField, "bad field range");
    1318             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1319           2 :     StylesType& r = aTables[nTable];
    1320           2 :     r.insert_back(nStartField, nEndField+1, nStringIndex);
    1321           2 : }
    1322             : 
    1323           0 : rtl::OUString* ScRowStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
    1324             : {
    1325           0 :     return GetStyleNameByIndex(GetStyleNameIndex(nTable, nField));
    1326          15 : }
    1327             : 
    1328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10