LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLStylesExportHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 648 0.0 %
Date: 2014-04-14 Functions: 0 63 0.0 %
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           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           0 : 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           0 :     sMacroName("MacroName")
     102             : {
     103           0 : }
     104             : 
     105           0 : ScMyValidationsContainer::~ScMyValidationsContainer()
     106             : {
     107           0 : }
     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::number(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 += "cell-content-is-date()";
     192           0 :             break;
     193             :             case sheet::ValidationType_DECIMAL :
     194           0 :                 sCondition += "cell-content-is-decimal-number()";
     195           0 :             break;
     196             :             case sheet::ValidationType_LIST :
     197           0 :                 sCondition += "cell-content-is-in-list(";
     198           0 :                 sCondition += aValidation.sFormula1;
     199           0 :                 sCondition += ")";
     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 += "cell-content-text-length()";
     205           0 :             break;
     206             :             case sheet::ValidationType_TIME :
     207           0 :                 sCondition += "cell-content-is-time()";
     208           0 :             break;
     209             :             case sheet::ValidationType_WHOLE :
     210           0 :                 sCondition += "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 += " 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 += "cell-content()";
     230           0 :                 switch (aValidation.aOperator)
     231             :                 {
     232             :                     case sheet::ConditionOperator_EQUAL :
     233           0 :                         sCondition += "=";
     234           0 :                     break;
     235             :                     case sheet::ConditionOperator_GREATER :
     236           0 :                         sCondition += ">";
     237           0 :                     break;
     238             :                     case sheet::ConditionOperator_GREATER_EQUAL :
     239           0 :                         sCondition += ">=";
     240           0 :                     break;
     241             :                     case sheet::ConditionOperator_LESS :
     242           0 :                         sCondition += "<";
     243           0 :                     break;
     244             :                     case sheet::ConditionOperator_LESS_EQUAL :
     245           0 :                         sCondition += "<=";
     246           0 :                     break;
     247             :                     case sheet::ConditionOperator_NOT_EQUAL :
     248           0 :                         sCondition += "!=";
     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 += "cell-content-text-length-is-between(";
     263             :                     else
     264           0 :                         sCondition += "cell-content-text-length-is-not-between(";
     265             :                 }
     266             :                 else
     267             :                 {
     268           0 :                     if (aValidation.aOperator == sheet::ConditionOperator_BETWEEN)
     269           0 :                         sCondition += "cell-content-is-between(";
     270             :                     else
     271           0 :                         sCondition += "cell-content-is-not-between(";
     272             :                 }
     273           0 :                 sCondition += aValidation.sFormula1;
     274           0 :                 sCondition += ",";
     275           0 :                 sCondition += aValidation.sFormula2;
     276           0 :                 sCondition += ")";
     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           0 : void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
     343             : {
     344           0 :     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_SORT_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           0 : }
     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           0 : sal_Int32 ScMyDefaultStyles::GetStyleNameIndex(const ScFormatRangeStyles* pCellStyles,
     454             :     const sal_Int32 nTable, const sal_Int32 nPos,
     455             :     const sal_Int32 i, bool& bIsAutoStyle)
     456             : {
     457           0 :     return pCellStyles->GetStyleNameIndex(nTable, i, nPos, bIsAutoStyle);
     458             : }
     459             : 
     460           0 : void ScMyDefaultStyles::FillDefaultStyles(const sal_Int32 nTable,
     461             :     const sal_Int32 nLastRow, const sal_Int32 nLastCol,
     462             :     const ScFormatRangeStyles* pCellStyles, ScDocument* pDoc)
     463             : {
     464           0 :     maColDefaults.clear();
     465           0 :     maColDefaults.resize(nLastCol + 1);
     466           0 :     if (!pDoc)
     467           0 :         return ;
     468             : 
     469           0 :     SCTAB nTab = static_cast<SCTAB>(nTable);
     470             :     sal_Int32 nPos;
     471           0 :     ScMyDefaultStyleList* pDefaults = &maColDefaults;
     472           0 :     bool bPrevAutoStyle(false);
     473             :     bool bIsAutoStyle;
     474           0 :     sal_Int32 nPrevIndex(0);
     475           0 :     sal_Int32 nRepeat(0);
     476           0 :     for (sal_Int32 i = nLastCol; i >= 0; --i)
     477             :     {
     478           0 :         pDoc->GetColDefault(nTab, static_cast<SCCOL>(i), static_cast<SCROW>(nLastRow), nPos);
     479           0 :         if (!nRepeat)
     480             :         {
     481           0 :             nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i, bPrevAutoStyle);
     482           0 :             (*pDefaults)[i].nIndex = nPrevIndex;
     483           0 :             (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
     484           0 :             nRepeat = 1;
     485             :         }
     486             :         else
     487             :         {
     488           0 :             sal_Int32 nIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i, bIsAutoStyle);
     489           0 :             if ((nIndex != nPrevIndex) || (bIsAutoStyle != bPrevAutoStyle))
     490             :             {
     491           0 :                 nRepeat = 1;
     492           0 :                 nPrevIndex = GetStyleNameIndex(pCellStyles, nTab, nPos, i, bPrevAutoStyle);
     493           0 :                 (*pDefaults)[i].nIndex = nPrevIndex;
     494           0 :                 (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
     495             :             }
     496             :             else
     497             :             {
     498           0 :                 (*pDefaults)[i].nIndex = nPrevIndex;
     499           0 :                 (*pDefaults)[i].bIsAutoStyle = bPrevAutoStyle;
     500           0 :                 ++nRepeat;
     501           0 :                 if (nRepeat > 1)
     502           0 :                     (*pDefaults)[i].nRepeat = nRepeat;
     503             :             }
     504             :         }
     505             :     }
     506             : }
     507             : 
     508           0 : ScMyRowFormatRange::ScMyRowFormatRange()
     509             :     : nStartColumn(0),
     510             :     nRepeatColumns(0),
     511             :     nRepeatRows(0),
     512             :     nIndex(-1),
     513             :     nValidationIndex(-1),
     514           0 :     bIsAutoStyle(true)
     515             : {
     516           0 : }
     517             : 
     518           0 : bool ScMyRowFormatRange::operator< (const ScMyRowFormatRange& rRange) const
     519             : {
     520           0 :     return (nStartColumn < rRange.nStartColumn);
     521             : }
     522             : 
     523           0 : ScRowFormatRanges::ScRowFormatRanges()
     524             :     : aRowFormatRanges(),
     525             :     pColDefaults(NULL),
     526           0 :     nSize(0)
     527             : {
     528           0 : }
     529             : 
     530           0 : ScRowFormatRanges::ScRowFormatRanges(const ScRowFormatRanges* pRanges)
     531             :     : aRowFormatRanges(pRanges->aRowFormatRanges),
     532             :     pColDefaults(pRanges->pColDefaults),
     533           0 :     nSize(pRanges->nSize)
     534             : {
     535           0 : }
     536             : 
     537           0 : ScRowFormatRanges::~ScRowFormatRanges()
     538             : {
     539           0 : }
     540             : 
     541           0 : void ScRowFormatRanges::Clear()
     542             : {
     543           0 :     aRowFormatRanges.clear();
     544           0 :     nSize = 0;
     545           0 : }
     546             : 
     547           0 : void ScRowFormatRanges::AddRange(const sal_Int32 nPrevStartCol, const sal_Int32 nRepeat, const sal_Int32 nPrevIndex,
     548             :     const bool bPrevAutoStyle, const ScMyRowFormatRange& rFormatRange)
     549             : {
     550           0 :     sal_Int32 nIndex(-1);
     551           0 :     if ((nPrevIndex != rFormatRange.nIndex) ||
     552           0 :         (bPrevAutoStyle != rFormatRange.bIsAutoStyle))
     553           0 :         nIndex = rFormatRange.nIndex;
     554             : 
     555           0 :     bool bInserted(false);
     556           0 :     if (!aRowFormatRanges.empty())
     557             :     {
     558           0 :         ScMyRowFormatRange* pRange(&aRowFormatRanges.back());
     559           0 :         if (pRange)
     560             :         {
     561           0 :             if ((nPrevStartCol == (pRange->nStartColumn + pRange->nRepeatColumns)) &&
     562           0 :                 (pRange->bIsAutoStyle == rFormatRange.bIsAutoStyle) &&
     563           0 :                 (pRange->nIndex == nIndex) &&
     564           0 :                 (pRange->nValidationIndex == rFormatRange.nValidationIndex))
     565             :             {
     566           0 :                 if (rFormatRange.nRepeatRows < pRange->nRepeatRows)
     567           0 :                     pRange->nRepeatRows = rFormatRange.nRepeatRows;
     568           0 :                 pRange->nRepeatColumns += nRepeat;
     569           0 :                 bInserted = true;
     570             :             }
     571             :         }
     572             :     }
     573           0 :     if (!bInserted)
     574             :     {
     575           0 :         ScMyRowFormatRange aRange;
     576           0 :         aRange.nStartColumn = nPrevStartCol;
     577           0 :         aRange.nRepeatColumns = nRepeat;
     578           0 :         aRange.nRepeatRows = rFormatRange.nRepeatRows;
     579           0 :         aRange.nValidationIndex = rFormatRange.nValidationIndex;
     580           0 :         aRange.bIsAutoStyle = rFormatRange.bIsAutoStyle;
     581           0 :         aRange.nIndex = nIndex;
     582           0 :         aRowFormatRanges.push_back(aRange);
     583           0 :         ++nSize;
     584             :     }
     585           0 : }
     586             : 
     587           0 : void ScRowFormatRanges::AddRange(ScMyRowFormatRange& rFormatRange)
     588             : {
     589             :     OSL_ENSURE(pColDefaults, "no column defaults");
     590           0 :     if (!pColDefaults)
     591           0 :         return;
     592           0 :     sal_Int32 nPrevIndex = -1;
     593           0 :     bool bPrevAutoStyle = true;
     594             :     {
     595           0 :         sal_uInt32 nPrevStartCol(rFormatRange.nStartColumn);
     596             :         OSL_ENSURE( static_cast<size_t>(nPrevStartCol) < pColDefaults->size(), "nPrevStartCol out of bounds");
     597             :         sal_uInt32 nRepeat;
     598           0 :         if (static_cast<size_t>(nPrevStartCol) < pColDefaults->size())
     599             :         {
     600           0 :             nRepeat = (*pColDefaults)[nPrevStartCol].nRepeat;
     601           0 :             nPrevIndex = (*pColDefaults)[nPrevStartCol].nIndex;
     602           0 :             bPrevAutoStyle = (*pColDefaults)[nPrevStartCol].bIsAutoStyle;
     603             :         }
     604             :         else
     605             :         {
     606             :             /* Again, this is to prevent out-of-bounds accesses, so FIXME
     607             :              * elsewhere! */
     608           0 :             if (pColDefaults->empty())
     609             :             {
     610           0 :                 nRepeat = 1;
     611           0 :                 nPrevIndex = -1;
     612           0 :                 bPrevAutoStyle = false;
     613             :             }
     614             :             else
     615             :             {
     616           0 :                 nRepeat = (*pColDefaults)[pColDefaults->size()-1].nRepeat;
     617           0 :                 nPrevIndex = (*pColDefaults)[pColDefaults->size()-1].nIndex;
     618           0 :                 bPrevAutoStyle = (*pColDefaults)[pColDefaults->size()-1].bIsAutoStyle;
     619             :             }
     620             :         }
     621           0 :         sal_uInt32 nEnd = nPrevStartCol + rFormatRange.nRepeatColumns;
     622           0 :         for(sal_uInt32 i = nPrevStartCol + nRepeat; i < nEnd && i < pColDefaults->size(); i += (*pColDefaults)[i].nRepeat)
     623             :         {
     624             :             OSL_ENSURE(sal_uInt32(nPrevStartCol + nRepeat) <= nEnd, "something wents wrong");
     625           0 :             if ((nPrevIndex != (*pColDefaults)[i].nIndex) ||
     626           0 :                 (bPrevAutoStyle != (*pColDefaults)[i].bIsAutoStyle))
     627             :             {
     628           0 :                 AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
     629           0 :                 nPrevStartCol = i;
     630           0 :                 nRepeat = (*pColDefaults)[i].nRepeat;
     631           0 :                 nPrevIndex = (*pColDefaults)[i].nIndex;
     632           0 :                 bPrevAutoStyle = (*pColDefaults)[i].bIsAutoStyle;
     633             :             }
     634             :             else
     635           0 :                 nRepeat += (*pColDefaults)[i].nRepeat;
     636             :         }
     637           0 :         if (sal_uInt32(nPrevStartCol + nRepeat) > nEnd)
     638           0 :             nRepeat = nEnd - nPrevStartCol;
     639           0 :         AddRange(nPrevStartCol, nRepeat, nPrevIndex, bPrevAutoStyle, rFormatRange);
     640             :     }
     641             : }
     642             : 
     643           0 : bool ScRowFormatRanges::GetNext(ScMyRowFormatRange& aFormatRange)
     644             : {
     645           0 :     ScMyRowFormatRangesList::iterator aItr(aRowFormatRanges.begin());
     646           0 :     if (aItr != aRowFormatRanges.end())
     647             :     {
     648           0 :         aFormatRange = (*aItr);
     649           0 :         aRowFormatRanges.erase(aItr);
     650           0 :         --nSize;
     651           0 :         return true;
     652             :     }
     653           0 :     return false;
     654             : }
     655             : 
     656           0 : sal_Int32 ScRowFormatRanges::GetMaxRows() const
     657             : {
     658           0 :     ScMyRowFormatRangesList::const_iterator aItr(aRowFormatRanges.begin());
     659           0 :     ScMyRowFormatRangesList::const_iterator aEndItr(aRowFormatRanges.end());
     660           0 :     sal_Int32 nMaxRows = MAXROW + 1;
     661           0 :     if (aItr != aEndItr)
     662             :     {
     663           0 :         while (aItr != aEndItr)
     664             :         {
     665           0 :             if ((*aItr).nRepeatRows < nMaxRows)
     666           0 :                 nMaxRows = (*aItr).nRepeatRows;
     667           0 :             ++aItr;
     668             :         }
     669             :     }
     670             :     else
     671             :     {
     672             :         OSL_FAIL("no ranges found");
     673             :     }
     674           0 :     return nMaxRows;
     675             : }
     676             : 
     677           0 : sal_Int32 ScRowFormatRanges::GetSize() const
     678             : {
     679           0 :     return nSize;
     680             : }
     681             : 
     682           0 : void ScRowFormatRanges::Sort()
     683             : {
     684           0 :     aRowFormatRanges.sort();
     685           0 : }
     686             : 
     687             : 
     688           0 : ScMyFormatRange::ScMyFormatRange()
     689             :     : nStyleNameIndex(-1),
     690             :     nValidationIndex(-1),
     691           0 :     bIsAutoStyle(true)
     692             : {
     693           0 : }
     694             : 
     695           0 : bool ScMyFormatRange::operator<(const ScMyFormatRange& rRange) const
     696             : {
     697           0 :     if (aRangeAddress.StartRow < rRange.aRangeAddress.StartRow)
     698           0 :         return true;
     699             :     else
     700           0 :         if (aRangeAddress.StartRow == rRange.aRangeAddress.StartRow)
     701           0 :             return (aRangeAddress.StartColumn < rRange.aRangeAddress.StartColumn);
     702             :         else
     703           0 :             return false;
     704             : }
     705             : 
     706           0 : ScFormatRangeStyles::ScFormatRangeStyles()
     707             :     : aTables(),
     708             :     aStyleNames(),
     709             :     aAutoStyleNames(),
     710           0 :     pColDefaults(0)
     711             : {
     712           0 : }
     713             : 
     714           0 : ScFormatRangeStyles::~ScFormatRangeStyles()
     715             : {
     716           0 :     ScMyOUStringVec::iterator i(aStyleNames.begin());
     717           0 :     ScMyOUStringVec::iterator endi(aStyleNames.end());
     718           0 :     while (i != endi)
     719             :     {
     720           0 :         delete *i;
     721           0 :         ++i;
     722             :     }
     723           0 :     i = aAutoStyleNames.begin();
     724           0 :     endi = aAutoStyleNames.end();
     725           0 :     while (i != endi)
     726             :     {
     727           0 :         delete *i;
     728           0 :         ++i;
     729             :     }
     730           0 :     ScMyFormatRangeListVec::iterator j(aTables.begin());
     731           0 :     ScMyFormatRangeListVec::iterator endj(aTables.end());
     732           0 :     while (j != endj)
     733             :     {
     734           0 :         delete *j;
     735           0 :         ++j;
     736             :     }
     737           0 : }
     738             : 
     739           0 : void ScFormatRangeStyles::AddNewTable(const sal_Int32 nTable)
     740             : {
     741           0 :     sal_Int32 nSize = aTables.size() - 1;
     742           0 :     if (nTable > nSize)
     743           0 :         for (sal_Int32 i = nSize; i < nTable; ++i)
     744             :         {
     745           0 :             ScMyFormatRangeAddresses* aRangeAddresses(new ScMyFormatRangeAddresses);
     746           0 :             aTables.push_back(aRangeAddresses);
     747             :         }
     748           0 : }
     749             : 
     750           0 : bool ScFormatRangeStyles::AddStyleName(OUString* rpString, sal_Int32& rIndex, const bool bIsAutoStyle)
     751             : {
     752           0 :     if (bIsAutoStyle)
     753             :     {
     754           0 :         aAutoStyleNames.push_back(rpString);
     755           0 :         rIndex = aAutoStyleNames.size() - 1;
     756           0 :         return true;
     757             :     }
     758             :     else
     759             :     {
     760           0 :         sal_Int32 nCount(aStyleNames.size());
     761           0 :         bool bFound(false);
     762           0 :         sal_Int32 i(nCount - 1);
     763           0 :         while ((i >= 0) && (!bFound))
     764             :         {
     765           0 :             if (aStyleNames.at(i)->equals(*rpString))
     766           0 :                 bFound = true;
     767             :             else
     768           0 :                 i--;
     769             :         }
     770           0 :         if (bFound)
     771             :         {
     772           0 :             rIndex = i;
     773           0 :             return false;
     774             :         }
     775             :         else
     776             :         {
     777           0 :             aStyleNames.push_back(rpString);
     778           0 :             rIndex = aStyleNames.size() - 1;
     779           0 :             return true;
     780             :         }
     781             :     }
     782             : }
     783             : 
     784           0 : sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix, bool& bIsAutoStyle)
     785             : {
     786           0 :     sal_Int32 nPrefixLength(rPrefix.getLength());
     787           0 :     OUString sTemp(rString.copy(nPrefixLength));
     788           0 :     sal_Int32 nIndex(sTemp.toInt32());
     789           0 :     if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1)->equals(rString))
     790             :     {
     791           0 :         bIsAutoStyle = true;
     792           0 :         return nIndex - 1;
     793             :     }
     794             :     else
     795             :     {
     796           0 :         sal_Int32 i(0);
     797           0 :         bool bFound(false);
     798           0 :         while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
     799             :         {
     800           0 :             if (aStyleNames[i]->equals(rString))
     801           0 :                 bFound = true;
     802             :             else
     803           0 :                 ++i;
     804             :         }
     805           0 :         if (bFound)
     806             :         {
     807           0 :             bIsAutoStyle = false;
     808           0 :             return i;
     809             :         }
     810             :         else
     811             :         {
     812           0 :             i = 0;
     813           0 :             while (!bFound && static_cast<size_t>(i) < aAutoStyleNames.size())
     814             :             {
     815           0 :                 if (aAutoStyleNames[i]->equals(rString))
     816           0 :                     bFound = true;
     817             :                 else
     818           0 :                     ++i;
     819             :             }
     820           0 :             if (bFound)
     821             :             {
     822           0 :                 bIsAutoStyle = true;
     823           0 :                 return i;
     824             :             }
     825             :             else
     826           0 :                 return -1;
     827             :         }
     828           0 :     }
     829             : }
     830             : 
     831           0 : sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
     832             :     const sal_Int32 nColumn, const sal_Int32 nRow, bool& bIsAutoStyle) const
     833             : {
     834             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
     835           0 :     if (!(static_cast<size_t>(nTable) < aTables.size()))
     836           0 :         return -1;
     837           0 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
     838           0 :     ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
     839           0 :     ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
     840           0 :     while (aItr != aEndItr)
     841             :     {
     842           0 :         if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
     843           0 :             ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
     844           0 :             ((*aItr).aRangeAddress.StartRow <= nRow) &&
     845           0 :             ((*aItr).aRangeAddress.EndRow >= nRow))
     846             :         {
     847           0 :             bIsAutoStyle = aItr->bIsAutoStyle;
     848           0 :             return (*aItr).nStyleNameIndex;
     849             :         }
     850             :         else
     851           0 :             ++aItr;
     852             :     }
     853           0 :     return -1;
     854             : }
     855             : 
     856           0 : sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
     857             :     bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow)
     858             : {
     859             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
     860           0 :     if (!(static_cast<size_t>(nTable) < aTables.size()))
     861           0 :         return -1;
     862           0 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
     863           0 :     ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
     864           0 :     ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
     865           0 :     while (aItr != aEndItr)
     866             :     {
     867           0 :         if (((*aItr).aRangeAddress.StartColumn <= nColumn) &&
     868           0 :             ((*aItr).aRangeAddress.EndColumn >= nColumn) &&
     869           0 :             ((*aItr).aRangeAddress.StartRow <= nRow) &&
     870           0 :             ((*aItr).aRangeAddress.EndRow >= nRow))
     871             :         {
     872           0 :             bIsAutoStyle = aItr->bIsAutoStyle;
     873           0 :             nValidationIndex = aItr->nValidationIndex;
     874           0 :             nNumberFormat = aItr->nNumberFormat;
     875             :             OSL_ENSURE( static_cast<size_t>(nColumn) < pColDefaults->size(), "nColumn out of bounds");
     876           0 :             if (static_cast<size_t>(nColumn) < pColDefaults->size() &&
     877           0 :                     ((*pColDefaults)[nColumn].nIndex != -1) &&
     878           0 :                     ((*pColDefaults)[nColumn].nIndex == (*aItr).nStyleNameIndex) &&
     879           0 :                     ((*pColDefaults)[nColumn].bIsAutoStyle == (*aItr).bIsAutoStyle))
     880           0 :                 return -1;
     881             :             else
     882           0 :                 return (*aItr).nStyleNameIndex;
     883             :         }
     884             :         else
     885             :         {
     886           0 :             if ((*aItr).aRangeAddress.EndRow < nRemoveBeforeRow)
     887           0 :                 aItr = pFormatRanges->erase(aItr);
     888             :             else
     889           0 :                 ++aItr;
     890             :         }
     891             :     }
     892           0 :     return -1;
     893             : }
     894             : 
     895           0 : void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sal_Int32 nEndColumn, const sal_Int32 nRow,
     896             :                     const sal_Int32 nTable, ScRowFormatRanges* pRowFormatRanges)
     897             : {
     898           0 :     sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
     899             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
     900           0 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[nTable]);
     901           0 :     ScMyFormatRangeAddresses::iterator aItr(pFormatRanges->begin());
     902           0 :     ScMyFormatRangeAddresses::iterator aEndItr(pFormatRanges->end());
     903           0 :     sal_Int32 nColumns = 0;
     904           0 :     while (aItr != aEndItr && nColumns < nTotalColumns)
     905             :     {
     906             : #if OSL_DEBUG_LEVEL > 1
     907             :         table::CellRangeAddress aTempRangeAddress((*aItr).aRangeAddress);
     908             : #endif
     909           0 :         if (((*aItr).aRangeAddress.StartRow <= nRow) &&
     910           0 :             ((*aItr).aRangeAddress.EndRow >= nRow))
     911             :         {
     912           0 :             if ((((*aItr).aRangeAddress.StartColumn <= nStartColumn) &&
     913           0 :                 ((*aItr).aRangeAddress.EndColumn >= nStartColumn)) ||
     914           0 :                 (((*aItr).aRangeAddress.StartColumn <= nEndColumn) &&
     915           0 :                 ((*aItr).aRangeAddress.EndColumn >= nEndColumn)) ||
     916           0 :                 (((*aItr).aRangeAddress.StartColumn >= nStartColumn) &&
     917           0 :                 ((*aItr).aRangeAddress.EndColumn <= nEndColumn)))
     918             :             {
     919           0 :                 ScMyRowFormatRange aRange;
     920           0 :                 aRange.nIndex = aItr->nStyleNameIndex;
     921           0 :                 aRange.nValidationIndex = aItr->nValidationIndex;
     922           0 :                 aRange.bIsAutoStyle = aItr->bIsAutoStyle;
     923           0 :                 if ((aItr->aRangeAddress.StartColumn < nStartColumn) &&
     924           0 :                     (aItr->aRangeAddress.EndColumn >= nStartColumn))
     925             :                 {
     926           0 :                     if (aItr->aRangeAddress.EndColumn >= nEndColumn)
     927           0 :                         aRange.nRepeatColumns = nTotalColumns;
     928             :                     else
     929           0 :                         aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - nStartColumn + 1;
     930           0 :                     aRange.nStartColumn = nStartColumn;
     931             :                 }
     932           0 :                 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
     933           0 :                     (aItr->aRangeAddress.EndColumn <= nEndColumn))
     934             :                 {
     935           0 :                     aRange.nRepeatColumns = aItr->aRangeAddress.EndColumn - aItr->aRangeAddress.StartColumn + 1;
     936           0 :                     aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
     937             :                 }
     938           0 :                 else if ((aItr->aRangeAddress.StartColumn >= nStartColumn) &&
     939           0 :                     (aItr->aRangeAddress.StartColumn <= nEndColumn) &&
     940           0 :                     (aItr->aRangeAddress.EndColumn > nEndColumn))
     941             :                 {
     942           0 :                     aRange.nRepeatColumns = nEndColumn - aItr->aRangeAddress.StartColumn + 1;
     943           0 :                     aRange.nStartColumn = aItr->aRangeAddress.StartColumn;
     944             :                 }
     945           0 :                 aRange.nRepeatRows = aItr->aRangeAddress.EndRow - nRow + 1;
     946           0 :                 pRowFormatRanges->AddRange(aRange);
     947           0 :                 nColumns += aRange.nRepeatColumns;
     948             :             }
     949           0 :             ++aItr;
     950             :         }
     951             :         else
     952           0 :             if(aItr->aRangeAddress.EndRow < nRow)
     953           0 :                 aItr = pFormatRanges->erase(aItr);
     954             :             else
     955           0 :                 ++aItr;
     956             :     }
     957           0 :     pRowFormatRanges->Sort();
     958           0 : }
     959             : 
     960           0 : void ScFormatRangeStyles::AddRangeStyleName(const table::CellRangeAddress aCellRangeAddress,
     961             :     const sal_Int32 nStringIndex, const bool bIsAutoStyle, const sal_Int32 nValidationIndex,
     962             :     const sal_Int32 nNumberFormat)
     963             : {
     964           0 :     ScMyFormatRange aFormatRange;
     965           0 :     aFormatRange.aRangeAddress = aCellRangeAddress;
     966           0 :     aFormatRange.nStyleNameIndex = nStringIndex;
     967           0 :     aFormatRange.nValidationIndex = nValidationIndex;
     968           0 :     aFormatRange.nNumberFormat = nNumberFormat;
     969           0 :     aFormatRange.bIsAutoStyle = bIsAutoStyle;
     970             :     OSL_ENSURE(static_cast<size_t>(aCellRangeAddress.Sheet) < aTables.size(), "wrong table");
     971           0 :     ScMyFormatRangeAddresses* pFormatRanges(aTables[aCellRangeAddress.Sheet]);
     972           0 :     pFormatRanges->push_back(aFormatRange);
     973           0 : }
     974             : 
     975           0 : OUString* ScFormatRangeStyles::GetStyleNameByIndex(const sal_Int32 nIndex, const bool bIsAutoStyle)
     976             : {
     977           0 :     if (bIsAutoStyle)
     978           0 :         return aAutoStyleNames[nIndex];
     979             :     else
     980           0 :         return aStyleNames[nIndex];
     981             : }
     982             : 
     983           0 : void ScFormatRangeStyles::Sort()
     984             : {
     985           0 :     sal_Int32 nTables = aTables.size();
     986           0 :     for (sal_Int16 i = 0; i < nTables; ++i)
     987           0 :         if (!aTables[i]->empty())
     988           0 :             aTables[i]->sort();
     989           0 : }
     990             : 
     991           0 : ScColumnRowStylesBase::ScColumnRowStylesBase()
     992           0 :     : aStyleNames()
     993             : {
     994           0 : }
     995             : 
     996           0 : ScColumnRowStylesBase::~ScColumnRowStylesBase()
     997             : {
     998           0 :     ScMyOUStringVec::iterator i(aStyleNames.begin());
     999           0 :     ScMyOUStringVec::iterator endi(aStyleNames.end());
    1000           0 :     while (i != endi)
    1001             :     {
    1002           0 :         delete *i;
    1003           0 :         ++i;
    1004             :     }
    1005           0 : }
    1006             : 
    1007           0 : sal_Int32 ScColumnRowStylesBase::AddStyleName(OUString* pString)
    1008             : {
    1009           0 :     aStyleNames.push_back(pString);
    1010           0 :     return aStyleNames.size() - 1;
    1011             : }
    1012             : 
    1013           0 : sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, const OUString& rPrefix)
    1014             : {
    1015           0 :     sal_Int32 nPrefixLength(rPrefix.getLength());
    1016           0 :     OUString sTemp(rString.copy(nPrefixLength));
    1017           0 :     sal_Int32 nIndex(sTemp.toInt32());
    1018           0 :     if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1)->equals(rString))
    1019           0 :         return nIndex - 1;
    1020             :     else
    1021             :     {
    1022           0 :         sal_Int32 i(0);
    1023           0 :         bool bFound(false);
    1024           0 :         while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
    1025             :         {
    1026           0 :             if (aStyleNames.at(i)->equals(rString))
    1027           0 :                 bFound = true;
    1028             :             else
    1029           0 :                 ++i;
    1030             :         }
    1031           0 :         if (bFound)
    1032           0 :             return i;
    1033             :         else
    1034           0 :             return -1;
    1035           0 :     }
    1036             : }
    1037             : 
    1038           0 : OUString* ScColumnRowStylesBase::GetStyleNameByIndex(const sal_Int32 nIndex)
    1039             : {
    1040           0 :     if ( nIndex < 0 || nIndex >= sal::static_int_cast<sal_Int32>( aStyleNames.size() ) )
    1041             :     {
    1042             :         // should no longer happen, use first style then
    1043             :         OSL_FAIL("GetStyleNameByIndex: invalid index");
    1044           0 :         return aStyleNames[0];
    1045             :     }
    1046             : 
    1047           0 :     return aStyleNames[nIndex];
    1048             : }
    1049             : 
    1050           0 : ScColumnStyles::ScColumnStyles()
    1051             :     : ScColumnRowStylesBase(),
    1052           0 :     aTables()
    1053             : {
    1054           0 : }
    1055             : 
    1056           0 : ScColumnStyles::~ScColumnStyles()
    1057             : {
    1058           0 : }
    1059             : 
    1060           0 : void ScColumnStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
    1061             : {
    1062           0 :     sal_Int32 nSize(aTables.size() - 1);
    1063           0 :     if (nTable > nSize)
    1064           0 :         for (sal_Int32 i = nSize; i < nTable; ++i)
    1065             :         {
    1066           0 :             ScMyColumnStyleVec aFieldsVec(nFields + 1, ScColumnStyle());
    1067           0 :             aTables.push_back(aFieldsVec);
    1068           0 :         }
    1069           0 : }
    1070             : 
    1071           0 : sal_Int32 ScColumnStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
    1072             :     bool& bIsVisible)
    1073             : {
    1074             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1075           0 :     if (static_cast<size_t>(nField) < aTables[nTable].size())
    1076             :     {
    1077           0 :         bIsVisible = aTables[nTable][nField].bIsVisible;
    1078           0 :         return aTables[nTable][nField].nIndex;
    1079             :     }
    1080             :     else
    1081             :     {
    1082           0 :         bIsVisible = aTables[nTable][aTables[nTable].size() - 1].bIsVisible;
    1083           0 :         return aTables[nTable][aTables[nTable].size() - 1].nIndex;
    1084             :     }
    1085             : }
    1086             : 
    1087           0 : void ScColumnStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
    1088             :     const sal_Int32 nStringIndex, const bool bIsVisible)
    1089             : {
    1090             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1091             :     OSL_ENSURE(aTables[nTable].size() >= static_cast<sal_uInt32>(nField), "wrong field");
    1092           0 :     ScColumnStyle aStyle;
    1093           0 :     aStyle.nIndex = nStringIndex;
    1094           0 :     aStyle.bIsVisible = bIsVisible;
    1095           0 :     if (aTables[nTable].size() == static_cast<sal_uInt32>(nField))
    1096           0 :         aTables[nTable].push_back(aStyle);
    1097           0 :     aTables[nTable][nField] = aStyle;
    1098           0 : }
    1099             : 
    1100           0 : OUString* ScColumnStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
    1101             : {
    1102             :     bool bTemp;
    1103           0 :     return GetStyleNameByIndex(GetStyleNameIndex(nTable, nField, bTemp));
    1104             : }
    1105             : 
    1106           0 : ScRowStyles::Cache::Cache() :
    1107           0 :     mnTable(-1), mnStart(-1), mnEnd(-1), mnStyle(-1) {}
    1108             : 
    1109           0 : bool ScRowStyles::Cache::hasCache(sal_Int32 nTable, sal_Int32 nField) const
    1110             : {
    1111           0 :     return mnTable == nTable && mnStart <= nField && nField < mnEnd;
    1112             : }
    1113             : 
    1114           0 : ScRowStyles::ScRowStyles()
    1115           0 :     : ScColumnRowStylesBase()
    1116             : {
    1117           0 : }
    1118             : 
    1119           0 : ScRowStyles::~ScRowStyles()
    1120             : {
    1121           0 : }
    1122             : 
    1123           0 : void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
    1124             : {
    1125           0 :     sal_Int32 nSize(aTables.size() - 1);
    1126           0 :     if (nTable > nSize)
    1127           0 :         for (sal_Int32 i = nSize; i < nTable; ++i)
    1128             :         {
    1129           0 :             aTables.push_back(new StylesType(0, nFields+1, -1));
    1130             :         }
    1131           0 : }
    1132             : 
    1133           0 : sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
    1134             : {
    1135             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1136           0 :     if (!(static_cast<size_t>(nTable) < aTables.size()))
    1137           0 :         return -1;
    1138             : 
    1139           0 :     if (maCache.hasCache(nTable, nField))
    1140             :         // Cache hit !
    1141           0 :         return maCache.mnStyle;
    1142             : 
    1143           0 :     StylesType& r = aTables[nTable];
    1144           0 :     if (!r.is_tree_valid())
    1145           0 :         r.build_tree();
    1146           0 :     sal_Int32 nStyle(0);
    1147           0 :     sal_Int32 nStart(0), nEnd(0);
    1148           0 :     if (r.search_tree(nField, nStyle, &nStart, &nEnd).second)
    1149             :     {
    1150             :         // Cache this value for better performance.
    1151           0 :         maCache.mnTable = nTable;
    1152           0 :         maCache.mnStart = nStart;
    1153           0 :         maCache.mnEnd = nEnd;
    1154           0 :         maCache.mnStyle = nStyle;
    1155           0 :         return nStyle;
    1156             :     }
    1157             : 
    1158           0 :     return -1;
    1159             : }
    1160             : 
    1161           0 : void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
    1162             :     const sal_Int32 nStringIndex)
    1163             : {
    1164             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1165           0 :     StylesType& r = aTables[nTable];
    1166           0 :     r.insert_back(nField, nField+1, nStringIndex);
    1167           0 : }
    1168             : 
    1169           0 : void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nStartField,
    1170             :         const sal_Int32 nStringIndex, const sal_Int32 nEndField)
    1171             : {
    1172             :     OSL_ENSURE( nStartField <= nEndField, "bad field range");
    1173             :     OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
    1174           0 :     StylesType& r = aTables[nTable];
    1175           0 :     r.insert_back(nStartField, nEndField+1, nStringIndex);
    1176           0 : }
    1177             : 
    1178           0 : OUString* ScRowStyles::GetStyleName(const sal_Int32 nTable, const sal_Int32 nField)
    1179             : {
    1180           0 :     return GetStyleNameByIndex(GetStyleNameIndex(nTable, nField));
    1181           0 : }
    1182             : 
    1183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10