LCOV - code coverage report
Current view: top level - sc/source/filter/xml - XMLStylesImportHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 269 0.0 %
Date: 2014-04-14 Functions: 0 25 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 "XMLStylesImportHelper.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include <com/sun/star/util/NumberFormat.hpp>
      23             : 
      24             : using namespace com::sun::star;
      25             : using ::std::list;
      26             : 
      27           0 : void ScMyStyleNumberFormats::AddStyleNumberFormat(const OUString& rStyleName, const sal_Int32 nNumberFormat)
      28             : {
      29           0 :     aSet.insert(ScMyStyleNumberFormat(rStyleName, nNumberFormat));
      30           0 : }
      31             : 
      32           0 : sal_Int32 ScMyStyleNumberFormats::GetStyleNumberFormat(const OUString& rStyleName)
      33             : {
      34           0 :     ScMyStyleNumberFormat aStyleNumberFormat(rStyleName);
      35           0 :     ScMyStyleNumberFormatSet::iterator aItr(aSet.find(aStyleNumberFormat));
      36           0 :     if (aItr == aSet.end())
      37           0 :         return -1;
      38             :     else
      39           0 :         return aItr->nNumberFormat;
      40             : }
      41             : 
      42           0 : ScMyStyleRanges::ScMyStyleRanges() :
      43           0 :     pCurrencyList(NULL)
      44             : {
      45           0 : }
      46             : 
      47           0 : ScMyStyleRanges::~ScMyStyleRanges()
      48             : {
      49           0 :     delete pCurrencyList;
      50           0 : }
      51             : 
      52           0 : void ScMyStyleRanges::AddRange(const ScRange& rRange, const sal_Int16 nType)
      53             : {
      54           0 :     switch (nType)
      55             :     {
      56             :         case util::NumberFormat::NUMBER:
      57             :         {
      58           0 :             if (!mpNumberList)
      59           0 :                 mpNumberList.reset(new ScSimpleRangeList);
      60           0 :             mpNumberList->addRange(rRange);
      61             :         }
      62           0 :         break;
      63             :         case util::NumberFormat::TEXT:
      64             :         {
      65           0 :             if (!mpTextList)
      66           0 :                 mpTextList.reset(new ScSimpleRangeList);
      67           0 :             mpTextList->addRange(rRange);
      68             :         }
      69           0 :         break;
      70             :         case util::NumberFormat::TIME:
      71             :         {
      72           0 :             if (!mpTimeList)
      73           0 :                 mpTimeList.reset(new ScSimpleRangeList);
      74           0 :             mpTimeList->addRange(rRange);
      75             :         }
      76           0 :         break;
      77             :         case util::NumberFormat::DATETIME:
      78             :         {
      79           0 :             if (!mpDateTimeList)
      80           0 :                 mpDateTimeList.reset(new ScSimpleRangeList);
      81           0 :             mpDateTimeList->addRange(rRange);
      82             :         }
      83           0 :         break;
      84             :         case util::NumberFormat::PERCENT:
      85             :         {
      86           0 :             if (!mpPercentList)
      87           0 :                 mpPercentList.reset(new ScSimpleRangeList);
      88           0 :             mpPercentList->addRange(rRange);
      89             :         }
      90           0 :         break;
      91             :         case util::NumberFormat::LOGICAL:
      92             :         {
      93           0 :             if (!mpLogicalList)
      94           0 :                 mpLogicalList.reset(new ScSimpleRangeList);
      95           0 :             mpLogicalList->addRange(rRange);
      96             :         }
      97           0 :         break;
      98             :         case util::NumberFormat::UNDEFINED:
      99             :         {
     100           0 :             if (!mpUndefinedList)
     101           0 :                 mpUndefinedList.reset(new ScSimpleRangeList);
     102           0 :             mpUndefinedList->addRange(rRange);
     103             :         }
     104           0 :         break;
     105             :         default:
     106             :         {
     107             :             OSL_FAIL("wrong type");
     108             :         }
     109           0 :         break;
     110             :     }
     111           0 : }
     112             : 
     113           0 : void ScMyStyleRanges::AddCurrencyRange(const ScRange& rRange, const OUString* pCurrency)
     114             : {
     115           0 :     if (!pCurrencyList)
     116           0 :         pCurrencyList = new ScMyCurrencyStylesSet();
     117           0 :     ScMyCurrencyStyle aStyle;
     118           0 :     if (pCurrency)
     119           0 :         aStyle.sCurrency = *pCurrency;
     120           0 :     ScMyCurrencyStylesSet::iterator aItr(pCurrencyList->find(aStyle));
     121           0 :     if (aItr == pCurrencyList->end())
     122             :     {
     123           0 :         std::pair<ScMyCurrencyStylesSet::iterator, bool> aPair(pCurrencyList->insert(aStyle));
     124           0 :         if (aPair.second)
     125             :         {
     126           0 :             aItr = aPair.first;
     127           0 :             aItr->mpRanges->addRange(rRange);
     128             :         }
     129             :     }
     130             :     else
     131           0 :         aItr->mpRanges->addRange(rRange);
     132           0 : }
     133             : 
     134           0 : void ScMyStyleRanges::InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* /*pDoc*/)
     135             : {
     136           0 :     if (mpTextList)
     137           0 :         mpTextList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     138           0 :     if (mpNumberList)
     139           0 :         mpNumberList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     140           0 :     if (mpTimeList)
     141           0 :         mpTimeList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     142           0 :     if (mpDateTimeList)
     143           0 :         mpDateTimeList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     144           0 :     if (mpPercentList)
     145           0 :         mpPercentList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     146           0 :     if (mpLogicalList)
     147           0 :         mpLogicalList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     148           0 :     if (mpUndefinedList)
     149           0 :         mpUndefinedList->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     150             : 
     151           0 :     if (pCurrencyList)
     152             :     {
     153           0 :         ScMyCurrencyStylesSet::iterator aItr(pCurrencyList->begin());
     154           0 :         ScMyCurrencyStylesSet::iterator aEndItr(pCurrencyList->end());
     155           0 :         while (aItr != aEndItr)
     156             :         {
     157           0 :             aItr->mpRanges->insertCol(static_cast<SCCOL>(nCol), static_cast<SCTAB>(nTab));
     158           0 :             ++aItr;
     159             :         }
     160             :     }
     161           0 : }
     162             : 
     163           0 : void ScMyStyleRanges::SetStylesToRanges(const list<ScRange>& rRanges,
     164             :     const OUString* pStyleName, const sal_Int16 nCellType,
     165             :     const OUString* pCurrency, ScXMLImport& rImport)
     166             : {
     167           0 :     list<ScRange>::const_iterator itr = rRanges.begin(), itrEnd = rRanges.end();
     168           0 :     for (; itr != itrEnd; ++itr)
     169           0 :         rImport.SetStyleToRange(*itr, pStyleName, nCellType, pCurrency);
     170           0 : }
     171             : 
     172           0 : void ScMyStyleRanges::SetStylesToRanges(const OUString* pStyleName, ScXMLImport& rImport)
     173             : {
     174           0 :     if (mpNumberList)
     175             :     {
     176           0 :         list<ScRange> aList;
     177           0 :         mpNumberList->getRangeList(aList);
     178           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::NUMBER, NULL, rImport);
     179           0 :         mpNumberList->clear();
     180             :     }
     181           0 :     if (mpTextList)
     182             :     {
     183           0 :         list<ScRange> aList;
     184           0 :         mpTextList->getRangeList(aList);
     185           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::TEXT, NULL, rImport);
     186           0 :         mpTextList->clear();
     187             :     }
     188           0 :     if (mpTimeList)
     189             :     {
     190           0 :         list<ScRange> aList;
     191           0 :         mpTimeList->getRangeList(aList);
     192           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::TIME, NULL, rImport);
     193           0 :         mpTimeList->clear();
     194             :     }
     195           0 :     if (mpDateTimeList)
     196             :     {
     197           0 :         list<ScRange> aList;
     198           0 :         mpDateTimeList->getRangeList(aList);
     199           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::DATETIME, NULL, rImport);
     200           0 :         mpDateTimeList->clear();
     201             :     }
     202           0 :     if (mpPercentList)
     203             :     {
     204           0 :         list<ScRange> aList;
     205           0 :         mpPercentList->getRangeList(aList);
     206           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::PERCENT, NULL, rImport);
     207           0 :         mpPercentList->clear();
     208             :     }
     209           0 :     if (mpLogicalList)
     210             :     {
     211           0 :         list<ScRange> aList;
     212           0 :         mpLogicalList->getRangeList(aList);
     213           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::LOGICAL, NULL, rImport);
     214           0 :         mpLogicalList->clear();
     215             :     }
     216           0 :     if (mpUndefinedList)
     217             :     {
     218           0 :         list<ScRange> aList;
     219           0 :         mpUndefinedList->getRangeList(aList);
     220           0 :         SetStylesToRanges(aList, pStyleName, util::NumberFormat::UNDEFINED, NULL, rImport);
     221           0 :         mpUndefinedList->clear();
     222             :     }
     223           0 :     if (pCurrencyList)
     224             :     {
     225           0 :         ScMyCurrencyStylesSet::iterator aItr(pCurrencyList->begin());
     226           0 :         ScMyCurrencyStylesSet::iterator aEndItr(pCurrencyList->end());
     227           0 :         while (aItr != aEndItr)
     228             :         {
     229           0 :             list<ScRange> aList;
     230           0 :             aItr->mpRanges->getRangeList(aList);
     231           0 :             SetStylesToRanges(aList, pStyleName, util::NumberFormat::CURRENCY, &aItr->sCurrency, rImport);
     232           0 :             ++aItr;
     233           0 :         }
     234             :     }
     235           0 : }
     236             : 
     237           0 : ScMyStylesImportHelper::ScMyStylesImportHelper(ScXMLImport& rTempImport)
     238             :     :
     239           0 :     aRowDefaultStyle(aCellStyles.end()),
     240             :     rImport(rTempImport),
     241             :     pStyleName(NULL),
     242             :     pPrevStyleName(NULL),
     243             :     pCurrency(NULL),
     244             :     pPrevCurrency(NULL),
     245           0 :     bPrevRangeAdded(true)
     246             : {
     247           0 : }
     248             : 
     249           0 : ScMyStylesImportHelper::~ScMyStylesImportHelper()
     250             : {
     251           0 :     delete pPrevStyleName;
     252           0 :     delete pPrevCurrency;
     253           0 :     delete pStyleName;
     254           0 :     delete pCurrency;
     255           0 : }
     256             : 
     257           0 : void ScMyStylesImportHelper::ResetAttributes()
     258             : {
     259           0 :     delete pPrevStyleName;
     260           0 :     delete pPrevCurrency;
     261           0 :     pPrevStyleName = pStyleName;
     262           0 :     pPrevCurrency = pCurrency;
     263           0 :     nPrevCellType = nCellType;
     264           0 :     pStyleName = NULL;
     265           0 :     pCurrency = NULL;
     266           0 :     nCellType = 0;
     267           0 : }
     268             : 
     269           0 : ScMyStylesSet::iterator ScMyStylesImportHelper::GetIterator(const OUString* pStyleNameP)
     270             : {
     271           0 :     ScMyStyle aStyle;
     272           0 :     if (pStyleNameP)
     273           0 :         aStyle.sStyleName = *pStyleNameP;
     274             :     else
     275             :     {
     276             :         OSL_FAIL("here is no stylename given");
     277             :     }
     278           0 :     ScMyStylesSet::iterator aItr(aCellStyles.find(aStyle));
     279           0 :     if (aItr == aCellStyles.end())
     280             :     {
     281           0 :         std::pair<ScMyStylesSet::iterator, bool> aPair(aCellStyles.insert(aStyle));
     282           0 :         if (aPair.second)
     283           0 :             aItr = aPair.first;
     284             :         else
     285             :         {
     286             :             OSL_FAIL("not possible to insert style");
     287           0 :             return aCellStyles.end();
     288             :         }
     289             :     }
     290           0 :     return aItr;
     291             : }
     292             : 
     293           0 : void ScMyStylesImportHelper::AddDefaultRange(const ScRange& rRange)
     294             : {
     295             :     OSL_ENSURE(aRowDefaultStyle != aCellStyles.end(), "no row default style");
     296           0 :     if (aRowDefaultStyle->sStyleName.isEmpty())
     297             :     {
     298           0 :         SCCOL nStartCol(rRange.aStart.Col());
     299           0 :         SCCOL nEndCol(rRange.aEnd.Col());
     300           0 :         if (aColDefaultStyles.size() > sal::static_int_cast<sal_uInt32>(nStartCol))
     301             :         {
     302           0 :             ScMyStylesSet::iterator aPrevItr(aColDefaultStyles[nStartCol]);
     303             :             OSL_ENSURE(aColDefaultStyles.size() > sal::static_int_cast<sal_uInt32>(nEndCol), "to much columns");
     304           0 :             for (SCCOL i = nStartCol + 1; (i <= nEndCol) && (i < sal::static_int_cast<SCCOL>(aColDefaultStyles.size())); ++i)
     305             :             {
     306           0 :                 if (aPrevItr != aColDefaultStyles[i])
     307             :                 {
     308             :                     OSL_ENSURE(aPrevItr != aCellStyles.end(), "no column default style");
     309           0 :                     ScRange aRange(rRange);
     310           0 :                     aRange.aStart.SetCol(nStartCol);
     311           0 :                     aRange.aEnd.SetCol(i - 1);
     312           0 :                     delete pPrevStyleName;
     313           0 :                     pPrevStyleName = new OUString(aPrevItr->sStyleName);
     314           0 :                     AddSingleRange(aRange);
     315           0 :                     nStartCol = i;
     316           0 :                     aPrevItr = aColDefaultStyles[i];
     317             :                 }
     318             :             }
     319           0 :             if (aPrevItr != aCellStyles.end())
     320             :             {
     321           0 :                 ScRange aRange(rRange);
     322           0 :                 aRange.aStart.SetCol(nStartCol);
     323           0 :                 delete pPrevStyleName;
     324           0 :                 pPrevStyleName = new OUString(aPrevItr->sStyleName);
     325           0 :                 AddSingleRange(aRange);
     326             :             }
     327             :             else
     328             :             {
     329             :                 OSL_FAIL("no column default style");
     330             :             }
     331             :         }
     332             :         else
     333             :         {
     334             :             OSL_FAIL("too much columns");
     335             :         }
     336             :     }
     337             :     else
     338             :     {
     339           0 :         delete pPrevStyleName;
     340           0 :         pPrevStyleName = new OUString(aRowDefaultStyle->sStyleName);
     341           0 :         AddSingleRange(rRange);
     342             :     }
     343           0 : }
     344             : 
     345           0 : void ScMyStylesImportHelper::AddSingleRange(const ScRange& rRange)
     346             : {
     347           0 :     ScMyStylesSet::iterator aItr(GetIterator(pPrevStyleName));
     348           0 :     if (aItr != aCellStyles.end())
     349             :     {
     350           0 :         if (nPrevCellType != util::NumberFormat::CURRENCY)
     351           0 :             aItr->xRanges->AddRange(rRange, nPrevCellType);
     352             :         else
     353           0 :             aItr->xRanges->AddCurrencyRange(rRange, pPrevCurrency);
     354             :     }
     355           0 : }
     356             : 
     357           0 : void ScMyStylesImportHelper::AddRange()
     358             : {
     359           0 :     if (pPrevStyleName && !pPrevStyleName->isEmpty())
     360           0 :         AddSingleRange(aPrevRange);
     361             :     else
     362           0 :         AddDefaultRange(aPrevRange);
     363           0 :     ResetAttributes();
     364           0 : }
     365             : 
     366           0 : void ScMyStylesImportHelper::AddColumnStyle(const OUString& sStyleName, const sal_Int32 nColumn, const sal_Int32 nRepeat)
     367             : {
     368             :     (void)nColumn;  // avoid warning in product version
     369             :     OSL_ENSURE(static_cast<sal_uInt32>(nColumn) == aColDefaultStyles.size(), "some columns are absent");
     370           0 :     ScMyStylesSet::iterator aItr(GetIterator(&sStyleName));
     371             :     OSL_ENSURE(aItr != aCellStyles.end(), "no column default style");
     372           0 :     aColDefaultStyles.reserve(aColDefaultStyles.size() + nRepeat);
     373           0 :     for (sal_Int32 i = 0; i < nRepeat; ++i)
     374           0 :         aColDefaultStyles.push_back(aItr);
     375           0 : }
     376             : 
     377           0 : void ScMyStylesImportHelper::SetRowStyle(const OUString& sStyleName)
     378             : {
     379           0 :     aRowDefaultStyle = GetIterator(&sStyleName);
     380           0 : }
     381             : 
     382           0 : void ScMyStylesImportHelper::SetAttributes(OUString* pStyleNameP,
     383             :     OUString* pCurrencyP, const sal_Int16 nCellTypeP)
     384             : {
     385           0 :     delete this->pStyleName;
     386           0 :     delete this->pCurrency;
     387           0 :     this->pStyleName = pStyleNameP;
     388           0 :     this->pCurrency = pCurrencyP;
     389           0 :     this->nCellType = nCellTypeP;
     390           0 : }
     391             : 
     392           0 : void ScMyStylesImportHelper::AddRange(const ScRange& rRange)
     393             : {
     394           0 :     if (!bPrevRangeAdded)
     395             :     {
     396           0 :         bool bAddRange(false);
     397           0 :         if (nCellType == nPrevCellType &&
     398           0 :             IsEqual(pStyleName, pPrevStyleName) &&
     399           0 :             IsEqual(pCurrency, pPrevCurrency))
     400             :         {
     401           0 :             if (rRange.aStart.Row() == aPrevRange.aStart.Row())
     402             :             {
     403           0 :                 if (rRange.aEnd.Row() == aPrevRange.aEnd.Row())
     404             :                 {
     405             :                     OSL_ENSURE(aPrevRange.aEnd.Col() + 1 == rRange.aStart.Col(), "something wents wrong");
     406           0 :                     aPrevRange.aEnd.SetCol(rRange.aEnd.Col());
     407             :                 }
     408             :                 else
     409           0 :                     bAddRange = true;
     410             :             }
     411             :             else
     412             :             {
     413           0 :                 if (rRange.aStart.Col() == aPrevRange.aStart.Col() &&
     414           0 :                     rRange.aEnd.Col() == aPrevRange.aEnd.Col())
     415             :                 {
     416             :                     OSL_ENSURE(aPrevRange.aEnd.Row() + 1 == rRange.aStart.Row(), "something wents wrong");
     417           0 :                     aPrevRange.aEnd.SetRow(rRange.aEnd.Row());
     418             :                 }
     419             :                 else
     420           0 :                     bAddRange = true;
     421             :             }
     422             :         }
     423             :         else
     424           0 :             bAddRange = true;
     425           0 :         if (bAddRange)
     426             :         {
     427           0 :             AddRange();
     428           0 :             aPrevRange = rRange;
     429             :         }
     430             :     }
     431             :     else
     432             :     {
     433           0 :         aPrevRange = rRange;
     434           0 :         ResetAttributes();
     435           0 :         bPrevRangeAdded = false;
     436             :     }
     437           0 : }
     438             : 
     439           0 : void ScMyStylesImportHelper::AddCell(const ScAddress& rAddress)
     440             : {
     441           0 :     ScRange aScRange( rAddress, rAddress );
     442           0 :     AddRange(aScRange);
     443           0 : }
     444             : 
     445           0 : void ScMyStylesImportHelper::InsertCol(const sal_Int32 nCol, const sal_Int32 nTab, ScDocument* pDoc)
     446             : {
     447           0 :     ScXMLImport::MutexGuard aGuard(rImport);
     448           0 :     ScMyStylesSet::iterator aItr(aCellStyles.begin());
     449           0 :     ScMyStylesSet::iterator aEndItr(aCellStyles.end());
     450           0 :     while (aItr != aEndItr)
     451             :     {
     452           0 :         aItr->xRanges->InsertCol(nCol, nTab, pDoc);
     453           0 :         ++aItr;
     454           0 :     }
     455           0 : }
     456             : 
     457           0 : void ScMyStylesImportHelper::EndTable()
     458             : {
     459           0 :     if (!bPrevRangeAdded)
     460             :     {
     461           0 :         AddRange();
     462           0 :         bPrevRangeAdded = true;
     463             :     }
     464           0 : }
     465             : 
     466           0 : void ScMyStylesImportHelper::SetStylesToRanges()
     467             : {
     468           0 :     ScMyStylesSet::iterator aItr(aCellStyles.begin());
     469           0 :     ScMyStylesSet::iterator aEndItr(aCellStyles.end());
     470           0 :     while (aItr != aEndItr)
     471             :     {
     472           0 :         aItr->xRanges->SetStylesToRanges(&aItr->sStyleName, rImport);
     473           0 :         ++aItr;
     474             :     }
     475           0 :     aColDefaultStyles.clear();
     476           0 :     aCellStyles.clear();
     477           0 : }
     478             : 
     479             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10