LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlcelli.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 708 0.0 %
Date: 2014-04-14 Functions: 0 41 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 "xmlcelli.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "xmltabi.hxx"
      23             : #include "xmlstyli.hxx"
      24             : #include "xmlannoi.hxx"
      25             : #include "global.hxx"
      26             : #include "document.hxx"
      27             : #include "cellsuno.hxx"
      28             : #include "docuno.hxx"
      29             : #include "unonames.hxx"
      30             : #include "postit.hxx"
      31             : #include "sheetdata.hxx"
      32             : #include "docsh.hxx"
      33             : #include "cellform.hxx"
      34             : #include "validat.hxx"
      35             : #include "patattr.hxx"
      36             : #include "scitems.hxx"
      37             : #include "docpool.hxx"
      38             : 
      39             : #include "XMLTableShapeImportHelper.hxx"
      40             : #include "XMLStylesImportHelper.hxx"
      41             : #include "celltextparacontext.hxx"
      42             : 
      43             : #include "arealink.hxx"
      44             : #include <sfx2/linkmgr.hxx>
      45             : #include "convuno.hxx"
      46             : #include "XMLConverter.hxx"
      47             : #include "scerrors.hxx"
      48             : #include "editutil.hxx"
      49             : #include "formulacell.hxx"
      50             : #include "editattributemap.hxx"
      51             : #include "stringutil.hxx"
      52             : #include "tokenarray.hxx"
      53             : #include "scmatrix.hxx"
      54             : #include "documentimport.hxx"
      55             : #include <datastream.hxx>
      56             : #include <rangeutl.hxx>
      57             : 
      58             : #include <xmloff/xmltkmap.hxx>
      59             : #include <xmloff/xmltoken.hxx>
      60             : #include <xmloff/nmspmap.hxx>
      61             : #include <xmloff/xmluconv.hxx>
      62             : #include <xmloff/families.hxx>
      63             : #include <xmloff/numehelp.hxx>
      64             : #include <xmloff/xmlnmspe.hxx>
      65             : #include "xmloff/prstylei.hxx"
      66             : #include <svl/zforlist.hxx>
      67             : #include <svx/svdocapt.hxx>
      68             : #include <editeng/outlobj.hxx>
      69             : #include <editeng/editobj.hxx>
      70             : #include "editeng/wghtitem.hxx"
      71             : #include "editeng/colritem.hxx"
      72             : #include "editeng/fhgtitem.hxx"
      73             : #include "editeng/postitem.hxx"
      74             : #include "editeng/fontitem.hxx"
      75             : #include "editeng/udlnitem.hxx"
      76             : #include "editeng/wrlmitem.hxx"
      77             : #include "editeng/crossedoutitem.hxx"
      78             : #include "editeng/charreliefitem.hxx"
      79             : #include "editeng/charscaleitem.hxx"
      80             : #include "editeng/contouritem.hxx"
      81             : #include "editeng/shdditem.hxx"
      82             : #include "editeng/kernitem.hxx"
      83             : #include "editeng/autokernitem.hxx"
      84             : #include "editeng/escapementitem.hxx"
      85             : #include "editeng/emphasismarkitem.hxx"
      86             : #include "editeng/langitem.hxx"
      87             : #include <svx/unoapi.hxx>
      88             : #include <svl/languageoptions.hxx>
      89             : #include <svtools/miscopt.hxx>
      90             : #include <sax/tools/converter.hxx>
      91             : 
      92             : #include <com/sun/star/frame/XModel.hpp>
      93             : #include <com/sun/star/text/XText.hpp>
      94             : #include <com/sun/star/sheet/XSpreadsheets.hpp>
      95             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      96             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      97             : 
      98             : #include <com/sun/star/sheet/XSheetCondition.hpp>
      99             : #include <com/sun/star/table/XCellRange.hpp>
     100             : #include <com/sun/star/table/CellAddress.hpp>
     101             : #include <com/sun/star/util/NumberFormat.hpp>
     102             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
     103             : #include <com/sun/star/util/XNumberFormatTypes.hpp>
     104             : #include <com/sun/star/util/Date.hpp>
     105             : #include <com/sun/star/lang/Locale.hpp>
     106             : #include <com/sun/star/text/ControlCharacter.hpp>
     107             : #include <com/sun/star/table/XCell.hpp>
     108             : #include <com/sun/star/document/XActionLockable.hpp>
     109             : 
     110             : #include <com/sun/star/sheet/ValidationType.hpp>
     111             : #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
     112             : #include <com/sun/star/sheet/ConditionOperator.hpp>
     113             : 
     114             : #include <rtl/ustrbuf.hxx>
     115             : #include <tools/date.hxx>
     116             : #include <i18nlangtag/lang.h>
     117             : #include <comphelper/extract.hxx>
     118             : 
     119             : using namespace com::sun::star;
     120             : using namespace xmloff::token;
     121             : 
     122           0 : ScXMLTableRowCellContext::ParaFormat::ParaFormat(ScEditEngineDefaulter& rEditEngine) :
     123           0 :     maItemSet(rEditEngine.GetEmptyItemSet()) {}
     124             : 
     125           0 : ScXMLTableRowCellContext::Field::Field(SvxFieldData* pData) : mpData(pData) {}
     126             : 
     127           0 : ScXMLTableRowCellContext::Field::~Field()
     128             : {
     129           0 :     delete mpData;
     130           0 : }
     131             : 
     132           0 : ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
     133             :                                       sal_uInt16 nPrfx,
     134             :                                       const OUString& rLName,
     135             :                                       const ::com::sun::star::uno::Reference<
     136             :                                       ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
     137             :                                       const bool bTempIsCovered,
     138             :                                       const sal_Int32 nTempRepeatedRows ) :
     139             :     ScXMLImportContext(rImport, nPrfx, rLName),
     140           0 :     mpEditEngine(GetScImport().GetEditEngine()),
     141             :     mnCurParagraph(0),
     142             :     pDetectiveObjVec(NULL),
     143             :     pCellRangeSource(NULL),
     144             :     fValue(0.0),
     145             :     nMergedRows(1),
     146             :     nMatrixRows(0),
     147             :     nRepeatedRows(nTempRepeatedRows),
     148             :     nMergedCols(1),
     149             :     nMatrixCols(0),
     150             :     nColsRepeated(1),
     151             :     rXMLImport((ScXMLImport&)rImport),
     152             :     eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
     153             :     nCellType(util::NumberFormat::TEXT),
     154             :     bIsMerged(false),
     155             :     bIsMatrix(false),
     156             :     bIsCovered(bTempIsCovered),
     157             :     bIsEmpty(true),
     158             :     mbNewValueType(false),
     159             :     mbErrorValue(false),
     160             :     bIsFirstTextImport(false),
     161             :     bSolarMutexLocked(false),
     162             :     bFormulaTextResult(false),
     163             :     mbPossibleErrorCell(false),
     164             :     mbCheckWithCompilerForError(false),
     165             :     mbEditEngineHasText(false),
     166             :     mbHasFormatRuns(false),
     167           0 :     mbHasStyle(false)
     168             : {
     169           0 :     rtl::math::setNan(&fValue); // NaN by default
     170             : 
     171           0 :     rXMLImport.SetRemoveLastChar(false);
     172           0 :     rXMLImport.GetTables().AddColumn(bTempIsCovered);
     173           0 :     const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     174           0 :     OUString aLocalName;
     175           0 :     OUString* pStyleName = NULL;
     176           0 :     OUString* pCurrencySymbol = NULL;
     177           0 :     const SvXMLTokenMap& rTokenMap = rImport.GetTableRowCellAttrTokenMap();
     178           0 :     for (sal_Int16 i = 0; i < nAttrCount; ++i)
     179             :     {
     180           0 :         sal_uInt16 nAttrPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(
     181           0 :             xAttrList->getNameByIndex(i), &aLocalName);
     182             : 
     183           0 :         const OUString& sValue = xAttrList->getValueByIndex(i);
     184           0 :         sal_uInt16 nToken = rTokenMap.Get(nAttrPrefix, aLocalName);
     185           0 :         switch (nToken)
     186             :         {
     187             :             case XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME:
     188           0 :                 pStyleName = new OUString(sValue);
     189           0 :                 mbHasStyle = true;
     190           0 :             break;
     191             :             case XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME:
     192             :                 OSL_ENSURE(!maContentValidationName, "here should be only one Validation Name");
     193           0 :                 if (!sValue.isEmpty())
     194           0 :                     maContentValidationName.reset(sValue);
     195           0 :             break;
     196             :             case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS:
     197           0 :                 bIsMerged = true;
     198           0 :                 nMergedRows = static_cast<SCROW>(sValue.toInt32());
     199           0 :             break;
     200             :             case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS:
     201           0 :                 bIsMerged = true;
     202           0 :                 nMergedCols = static_cast<SCCOL>(sValue.toInt32());
     203           0 :             break;
     204             :             case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS:
     205           0 :                 bIsMatrix = true;
     206           0 :                 nMatrixCols = static_cast<SCCOL>(sValue.toInt32());
     207           0 :             break;
     208             :             case XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS:
     209           0 :                 bIsMatrix = true;
     210           0 :                 nMatrixRows = static_cast<SCROW>(sValue.toInt32());
     211           0 :             break;
     212             :             case XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED:
     213             :                 nColsRepeated = static_cast<SCCOL>(std::min<sal_Int32>( MAXCOLCOUNT,
     214           0 :                             std::max( sValue.toInt32(), static_cast<sal_Int32>(1) ) ));
     215           0 :             break;
     216             :             case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE:
     217           0 :                 nCellType = GetScImport().GetCellType(sValue);
     218           0 :                 bIsEmpty = false;
     219           0 :             break;
     220             :             case XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE:
     221           0 :                 if(sValue == "error")
     222           0 :                     mbErrorValue = true;
     223             :                 else
     224           0 :                     nCellType = GetScImport().GetCellType(sValue);
     225           0 :                 bIsEmpty = false;
     226           0 :                 mbNewValueType = true;
     227           0 :             break;
     228             :             case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE:
     229             :             {
     230           0 :                 if (!sValue.isEmpty())
     231             :                 {
     232           0 :                     ::sax::Converter::convertDouble(fValue, sValue);
     233           0 :                     bIsEmpty = false;
     234             : 
     235             :                     //if office:value="0", let's get the text:p in case this is
     236             :                     //a special case in HasSpecialCaseFormulaText(). If it
     237             :                     //turns out not to be a special case, we'll use the 0 value.
     238           0 :                     if(fValue == 0.0)
     239           0 :                         bFormulaTextResult = true;
     240             :                 }
     241             :             }
     242           0 :             break;
     243             :             case XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE:
     244             :             {
     245           0 :                 if (!sValue.isEmpty() && rXMLImport.SetNullDateOnUnitConverter())
     246             :                 {
     247           0 :                     rXMLImport.GetMM100UnitConverter().convertDateTime(fValue, sValue);
     248           0 :                     bIsEmpty = false;
     249             :                 }
     250             :             }
     251           0 :             break;
     252             :             case XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE:
     253             :             {
     254           0 :                 if (!sValue.isEmpty())
     255             :                 {
     256           0 :                     ::sax::Converter::convertDuration(fValue, sValue);
     257           0 :                     bIsEmpty = false;
     258             :                 }
     259             :             }
     260           0 :             break;
     261             :             case XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE:
     262             :             {
     263           0 :                 if (!sValue.isEmpty())
     264             :                 {
     265             :                     OSL_ENSURE(!maStringValue, "here should be only one string value");
     266           0 :                     maStringValue.reset(sValue);
     267           0 :                     bIsEmpty = false;
     268             :                 }
     269             :             }
     270           0 :             break;
     271             :             case XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE:
     272             :             {
     273           0 :                 if (!sValue.isEmpty())
     274             :                 {
     275           0 :                     if ( IsXMLToken(sValue, XML_TRUE) )
     276           0 :                         fValue = 1.0;
     277           0 :                     else if ( IsXMLToken(sValue, XML_FALSE) )
     278           0 :                         fValue = 0.0;
     279             :                     else
     280           0 :                         ::sax::Converter::convertDouble(fValue, sValue);
     281           0 :                     bIsEmpty = false;
     282             :                 }
     283             :             }
     284           0 :             break;
     285             :             case XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA:
     286             :             {
     287           0 :                 if (!sValue.isEmpty())
     288             :                 {
     289             :                     OSL_ENSURE(!maFormula, "here should be only one formula");
     290           0 :                     OUString aFormula, aFormulaNmsp;
     291           0 :                     rXMLImport.ExtractFormulaNamespaceGrammar( aFormula, aFormulaNmsp, eGrammar, sValue );
     292           0 :                     maFormula.reset( FormulaWithNamespace(aFormula, aFormulaNmsp) );
     293             :                 }
     294             :             }
     295           0 :             break;
     296             :             case XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY:
     297           0 :                 pCurrencySymbol = new OUString(sValue);
     298           0 :             break;
     299             :             default:
     300             :                 ;
     301             :         }
     302           0 :     }
     303           0 :     if (maFormula)
     304             :     {
     305           0 :         if (nCellType == util::NumberFormat::TEXT)
     306           0 :             bFormulaTextResult = true;
     307           0 :         if(nCellType == util::NumberFormat::DATETIME)
     308           0 :             nCellType = util::NumberFormat::UNDEFINED;
     309             :         //if bIsEmpty is true at this point, then there is no office value.
     310             :         //we must get the text:p (even if it is empty) in case this a special
     311             :         //case in HasSpecialCaseFormulaText().
     312           0 :         if(bIsEmpty)
     313           0 :             bFormulaTextResult = true;
     314             :     }
     315           0 :     rXMLImport.GetStylesImportHelper()->SetAttributes(pStyleName, pCurrencySymbol, nCellType);
     316           0 : }
     317             : 
     318           0 : ScXMLTableRowCellContext::~ScXMLTableRowCellContext()
     319             : {
     320           0 :     delete pDetectiveObjVec;
     321           0 :     delete pCellRangeSource;
     322           0 : }
     323             : 
     324           0 : void ScXMLTableRowCellContext::LockSolarMutex()
     325             : {
     326           0 :     if (!bSolarMutexLocked)
     327             :     {
     328           0 :         GetScImport().LockSolarMutex();
     329           0 :         bSolarMutexLocked = true;
     330             :     }
     331           0 : }
     332             : 
     333           0 : void ScXMLTableRowCellContext::UnlockSolarMutex()
     334             : {
     335           0 :     if (bSolarMutexLocked)
     336             :     {
     337           0 :         GetScImport().UnlockSolarMutex();
     338           0 :         bSolarMutexLocked = false;
     339             :     }
     340           0 : }
     341             : 
     342             : namespace {
     343             : 
     344           0 : bool cellExists( const ScAddress& rCellPos )
     345             : {
     346           0 :     return( rCellPos.Col() >= 0 && rCellPos.Row() >= 0 &&
     347           0 :             rCellPos.Col() <= MAXCOL && rCellPos.Row() <= MAXROW );
     348             : }
     349             : 
     350             : }
     351             : 
     352           0 : void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OUString& rStyleName)
     353             : {
     354           0 :     sal_Int32 nBegin = maParagraph.getLength();
     355           0 :     sal_Int32 nEnd = nBegin + rSpan.getLength();
     356           0 :     maParagraph.append(rSpan);
     357             : 
     358           0 :     PushFormat(nBegin, nEnd, rStyleName);
     359           0 : }
     360             : 
     361           0 : void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData, const OUString& rStyleName)
     362             : {
     363           0 :     mbHasFormatRuns = true;
     364           0 :     maFields.push_back(new Field(pData));
     365           0 :     Field& rField = maFields.back();
     366             : 
     367           0 :     sal_Int32 nPos = maParagraph.getLength();
     368           0 :     maParagraph.append('\1'); // Placeholder text for inserted field item.
     369           0 :     rField.maSelection.nStartPara = mnCurParagraph;
     370           0 :     rField.maSelection.nEndPara = mnCurParagraph;
     371           0 :     rField.maSelection.nStartPos = nPos;
     372           0 :     rField.maSelection.nEndPos = nPos+1;
     373             : 
     374           0 :     PushFormat(nPos, nPos+1, rStyleName);
     375           0 : }
     376             : 
     377           0 : void ScXMLTableRowCellContext::PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName)
     378             : {
     379           0 :     if (rStyleName.isEmpty())
     380           0 :         return;
     381             : 
     382             :     // Get the style information from xmloff.
     383           0 :     UniReference<XMLPropertySetMapper> xMapper = GetImport().GetTextImport()->GetTextImportPropertySetMapper()->getPropertySetMapper();
     384           0 :     if (!xMapper.is())
     385             :         // We can't do anything without the mapper.
     386           0 :         return;
     387             : 
     388           0 :     sal_Int32 nEntryCount = xMapper->GetEntryCount();
     389             : 
     390           0 :     SvXMLStylesContext* pAutoStyles = GetImport().GetAutoStyles();
     391             : 
     392             :     // Style name for text span corresponds with the name of an automatic style.
     393             :     const XMLPropStyleContext* pStyle = dynamic_cast<const XMLPropStyleContext*>(
     394           0 :         pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TEXT_TEXT, rStyleName));
     395             : 
     396           0 :     if (!pStyle)
     397             :         // No style by that name found.
     398           0 :         return;
     399             : 
     400           0 :     const std::vector<XMLPropertyState>& rProps = pStyle->GetProperties();
     401           0 :     if (rProps.empty())
     402           0 :         return;
     403             : 
     404           0 :     const ScXMLEditAttributeMap& rEditAttrMap = GetScImport().GetEditAttributeMap();
     405             : 
     406           0 :     mbHasFormatRuns = true;
     407           0 :     maFormats.push_back(new ParaFormat(*mpEditEngine));
     408           0 :     ParaFormat& rFmt = maFormats.back();
     409           0 :     rFmt.maSelection.nStartPara = rFmt.maSelection.nEndPara = mnCurParagraph;
     410           0 :     rFmt.maSelection.nStartPos = nBegin;
     411           0 :     rFmt.maSelection.nEndPos = nEnd;
     412             : 
     413             :     // Store the used text styles for export.
     414           0 :     ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
     415           0 :     ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
     416           0 :     pSheetData->AddTextStyle(rStyleName, aCellPos, rFmt.maSelection);
     417             : 
     418           0 :     boost::scoped_ptr<SfxPoolItem> pPoolItem;
     419           0 :     sal_uInt16 nLastItemID = EE_CHAR_END + 1;
     420             : 
     421           0 :     std::vector<XMLPropertyState>::const_iterator it = rProps.begin(), itEnd = rProps.end();
     422           0 :     for (; it != itEnd; ++it)
     423             :     {
     424           0 :         if (it->mnIndex == -1 || it->mnIndex >= nEntryCount)
     425           0 :             continue;
     426             : 
     427           0 :         const OUString& rName = xMapper->GetEntryAPIName(it->mnIndex);
     428           0 :         const ScXMLEditAttributeMap::Entry* pEntry = rEditAttrMap.getEntryByAPIName(rName);
     429           0 :         if (!pEntry)
     430           0 :             continue;
     431             : 
     432           0 :         if (nLastItemID != pEntry->mnItemID && pPoolItem)
     433             :         {
     434             :             // Flush the last item when the item ID changes.
     435           0 :             rFmt.maItemSet.Put(*pPoolItem);
     436           0 :             pPoolItem.reset();
     437             :         }
     438             : 
     439           0 :         switch (pEntry->mnItemID)
     440             :         {
     441             :             case EE_CHAR_FONTINFO:
     442             :             case EE_CHAR_FONTINFO_CJK:
     443             :             case EE_CHAR_FONTINFO_CTL:
     444             :             {
     445             :                 // Font properties need to be consolidated into a single item.
     446           0 :                 if (!pPoolItem)
     447           0 :                     pPoolItem.reset(new SvxFontItem(pEntry->mnItemID));
     448             : 
     449           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     450             :             }
     451           0 :             break;
     452             :             case EE_CHAR_WEIGHT:
     453             :             case EE_CHAR_WEIGHT_CJK:
     454             :             case EE_CHAR_WEIGHT_CTL:
     455             :             {
     456           0 :                 if (!pPoolItem)
     457           0 :                     pPoolItem.reset(new SvxWeightItem(WEIGHT_NORMAL, pEntry->mnItemID));
     458             : 
     459           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     460             :             }
     461           0 :             break;
     462             :             case EE_CHAR_FONTHEIGHT:
     463             :             case EE_CHAR_FONTHEIGHT_CJK:
     464             :             case EE_CHAR_FONTHEIGHT_CTL:
     465             :             {
     466           0 :                 if (!pPoolItem)
     467           0 :                     pPoolItem.reset(new SvxFontHeightItem(240, 100, pEntry->mnItemID));
     468             : 
     469           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     470             :             }
     471           0 :             break;
     472             :             case EE_CHAR_ITALIC:
     473             :             case EE_CHAR_ITALIC_CJK:
     474             :             case EE_CHAR_ITALIC_CTL:
     475             :             {
     476           0 :                 if (!pPoolItem)
     477           0 :                     pPoolItem.reset(new SvxPostureItem(ITALIC_NONE, pEntry->mnItemID));
     478             : 
     479           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     480             :             }
     481           0 :             break;
     482             :             case EE_CHAR_UNDERLINE:
     483             :             {
     484           0 :                 if (!pPoolItem)
     485           0 :                     pPoolItem.reset(new SvxUnderlineItem(UNDERLINE_NONE, pEntry->mnItemID));
     486             : 
     487           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     488             :             }
     489           0 :             break;
     490             :             case EE_CHAR_OVERLINE:
     491             :             {
     492           0 :                 if (!pPoolItem)
     493           0 :                     pPoolItem.reset(new SvxOverlineItem(UNDERLINE_NONE, pEntry->mnItemID));
     494             : 
     495           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     496             :             }
     497           0 :             break;
     498             :             case EE_CHAR_COLOR:
     499             :             {
     500           0 :                 if (!pPoolItem)
     501           0 :                     pPoolItem.reset(new SvxColorItem(pEntry->mnItemID));
     502             : 
     503           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     504             :             }
     505           0 :             break;
     506             :             case EE_CHAR_WLM:
     507             :             {
     508           0 :                 if (!pPoolItem)
     509           0 :                     pPoolItem.reset(new SvxWordLineModeItem(false, pEntry->mnItemID));
     510             : 
     511           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     512             :             }
     513           0 :             break;
     514             :             case EE_CHAR_STRIKEOUT:
     515             :             {
     516           0 :                 if (!pPoolItem)
     517           0 :                     pPoolItem.reset(new SvxCrossedOutItem(STRIKEOUT_NONE, pEntry->mnItemID));
     518             : 
     519           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     520             :             }
     521           0 :             break;
     522             :             case EE_CHAR_RELIEF:
     523             :             {
     524           0 :                 if (!pPoolItem)
     525           0 :                     pPoolItem.reset(new SvxCharReliefItem(RELIEF_NONE, pEntry->mnItemID));
     526             : 
     527           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     528             :             }
     529           0 :             break;
     530             :             case EE_CHAR_OUTLINE:
     531             :             {
     532           0 :                 if (!pPoolItem)
     533           0 :                     pPoolItem.reset(new SvxContourItem(false, pEntry->mnItemID));
     534             : 
     535           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     536             :             }
     537           0 :             break;
     538             :             case EE_CHAR_SHADOW:
     539             :             {
     540           0 :                 if (!pPoolItem)
     541           0 :                     pPoolItem.reset(new SvxShadowedItem(false, pEntry->mnItemID));
     542             : 
     543           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     544             :             }
     545           0 :             break;
     546             :             case EE_CHAR_KERNING:
     547             :             {
     548           0 :                 if (!pPoolItem)
     549           0 :                     pPoolItem.reset(new SvxKerningItem(0, pEntry->mnItemID));
     550             : 
     551           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     552             :             }
     553           0 :             break;
     554             :             case EE_CHAR_PAIRKERNING:
     555             :             {
     556           0 :                 if (!pPoolItem)
     557           0 :                     pPoolItem.reset(new SvxAutoKernItem(false, pEntry->mnItemID));
     558             : 
     559           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     560             :             }
     561           0 :             break;
     562             :             case EE_CHAR_FONTWIDTH:
     563             :             {
     564           0 :                 if (!pPoolItem)
     565           0 :                     pPoolItem.reset(new SvxCharScaleWidthItem(100, pEntry->mnItemID));
     566             : 
     567           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     568             :             }
     569           0 :             break;
     570             :             case EE_CHAR_ESCAPEMENT:
     571             :             {
     572           0 :                 if (!pPoolItem)
     573           0 :                     pPoolItem.reset(new SvxEscapementItem(pEntry->mnItemID));
     574             : 
     575           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     576             :             }
     577           0 :             break;
     578             :             case EE_CHAR_EMPHASISMARK:
     579             :             {
     580           0 :                 if (!pPoolItem)
     581           0 :                     pPoolItem.reset(new SvxEmphasisMarkItem(EMPHASISMARK_NONE, pEntry->mnItemID));
     582             : 
     583           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     584             :             }
     585           0 :             break;
     586             :             case EE_CHAR_LANGUAGE:
     587             :             case EE_CHAR_LANGUAGE_CJK:
     588             :             case EE_CHAR_LANGUAGE_CTL:
     589             :             {
     590           0 :                 if (!pPoolItem)
     591           0 :                     pPoolItem.reset(new SvxLanguageItem(LANGUAGE_DONTKNOW, pEntry->mnItemID));
     592             : 
     593           0 :                 pPoolItem->PutValue(it->maValue, pEntry->mnFlag);
     594             :             }
     595           0 :             break;
     596             :             default:
     597             :                 ;
     598             :         }
     599             : 
     600           0 :         nLastItemID = pEntry->mnItemID;
     601             :     }
     602             : 
     603           0 :     if (pPoolItem)
     604           0 :         rFmt.maItemSet.Put(*pPoolItem);
     605             : }
     606             : 
     607           0 : OUString ScXMLTableRowCellContext::GetFirstParagraph() const
     608             : {
     609           0 :     if (!maFirstParagraph)
     610           0 :         return mpEditEngine->GetText(0);
     611             : 
     612           0 :     return *maFirstParagraph;
     613             : }
     614             : 
     615           0 : void ScXMLTableRowCellContext::PushParagraphFieldDate(const OUString& rStyleName)
     616             : {
     617           0 :     PushParagraphField(new SvxDateField, rStyleName);
     618           0 : }
     619             : 
     620           0 : void ScXMLTableRowCellContext::PushParagraphFieldSheetName(const OUString& rStyleName)
     621             : {
     622           0 :     SCTAB nTab = GetScImport().GetTables().GetCurrentCellPos().Tab();
     623           0 :     PushParagraphField(new SvxTableField(nTab), rStyleName);
     624           0 : }
     625             : 
     626           0 : void ScXMLTableRowCellContext::PushParagraphFieldDocTitle(const OUString& rStyleName)
     627             : {
     628           0 :     PushParagraphField(new SvxFileField, rStyleName);
     629           0 : }
     630             : 
     631           0 : void ScXMLTableRowCellContext::PushParagraphFieldURL(
     632             :     const OUString& rURL, const OUString& rRep, const OUString& rStyleName)
     633             : {
     634           0 :     OUString aAbsURL = GetScImport().GetAbsoluteReference(rURL);
     635           0 :     PushParagraphField(new SvxURLField(aAbsURL, rRep, SVXURLFORMAT_REPR), rStyleName);
     636           0 : }
     637             : 
     638           0 : void ScXMLTableRowCellContext::PushParagraphEnd()
     639             : {
     640             :     // EditEngine always has at least one paragraph even when its content is empty.
     641             : 
     642           0 :     if (mbEditEngineHasText)
     643             :     {
     644           0 :         if (maFirstParagraph)
     645             :         {
     646             :             // Flush the cached first paragraph first.
     647           0 :             mpEditEngine->Clear();
     648           0 :             mpEditEngine->SetText(*maFirstParagraph);
     649           0 :             maFirstParagraph.reset();
     650             :         }
     651           0 :         mpEditEngine->InsertParagraph(mpEditEngine->GetParagraphCount(), maParagraph.makeStringAndClear());
     652             :     }
     653           0 :     else if (mbHasFormatRuns)
     654             :     {
     655           0 :         mpEditEngine->Clear();
     656           0 :         mpEditEngine->SetText(maParagraph.makeStringAndClear());
     657           0 :         mbEditEngineHasText = true;
     658             :     }
     659           0 :     else if (mnCurParagraph == 0)
     660             :     {
     661           0 :         maFirstParagraph.reset(maParagraph.makeStringAndClear());
     662           0 :         mbEditEngineHasText = true;
     663             :     }
     664             : 
     665           0 :     ++mnCurParagraph;
     666           0 : }
     667             : 
     668           0 : SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPrefix,
     669             :                                             const OUString& rLName,
     670             :                                             const ::com::sun::star::uno::Reference<
     671             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     672             : {
     673           0 :     SvXMLImportContext *pContext = 0;
     674             : 
     675           0 :     const SvXMLTokenMap& rTokenMap = rXMLImport.GetTableRowCellElemTokenMap();
     676           0 :     bool bTextP(false);
     677           0 :     switch( rTokenMap.Get( nPrefix, rLName ) )
     678             :     {
     679             :         case XML_TOK_TABLE_ROW_CELL_P:
     680             :         {
     681           0 :             bIsEmpty = false;
     682           0 :             bTextP = true;
     683             : 
     684           0 :             pContext = new ScXMLCellTextParaContext(rXMLImport, nPrefix, rLName, *this);
     685             :         }
     686           0 :         break;
     687             :         case XML_TOK_TABLE_ROW_CELL_TABLE:
     688             :         {
     689             :             SAL_WARN("sc", "ScXMLTableRowCellContext::CreateChildContext: subtables are not supported");
     690             :         }
     691           0 :         break;
     692             :         case XML_TOK_TABLE_ROW_CELL_ANNOTATION:
     693             :         {
     694           0 :             bIsEmpty = false;
     695             :             OSL_ENSURE( !mxAnnotationData.get(), "ScXMLTableRowCellContext::CreateChildContext - multiple annotations in one cell" );
     696           0 :             mxAnnotationData.reset( new ScXMLAnnotationData );
     697             :             pContext = new ScXMLAnnotationContext( rXMLImport, nPrefix, rLName,
     698           0 :                                                     xAttrList, *mxAnnotationData, this);
     699             :         }
     700           0 :         break;
     701             :         case XML_TOK_TABLE_ROW_CELL_DETECTIVE:
     702             :         {
     703           0 :             bIsEmpty = false;
     704           0 :             if (!pDetectiveObjVec)
     705           0 :                 pDetectiveObjVec = new ScMyImpDetectiveObjVec();
     706             :             pContext = new ScXMLDetectiveContext(
     707           0 :                 rXMLImport, nPrefix, rLName, pDetectiveObjVec );
     708             :         }
     709           0 :         break;
     710             :         case XML_TOK_TABLE_ROW_CELL_CELL_RANGE_SOURCE:
     711             :         {
     712           0 :             bIsEmpty = false;
     713           0 :             if (!pCellRangeSource)
     714           0 :                 pCellRangeSource = new ScMyImpCellRangeSource();
     715             :             pContext = new ScXMLCellRangeSourceContext(
     716           0 :                 rXMLImport, nPrefix, rLName, xAttrList, pCellRangeSource );
     717             :         }
     718           0 :         break;
     719             :     }
     720             : 
     721           0 :     if (!pContext && !bTextP)
     722             :     {
     723           0 :         ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
     724           0 :         uno::Reference<drawing::XShapes> xShapes (rXMLImport.GetTables().GetCurrentXShapes());
     725           0 :         if (xShapes.is())
     726             :         {
     727           0 :             if (aCellPos.Col() > MAXCOL)
     728           0 :                 aCellPos.SetCol(MAXCOL);
     729           0 :             if (aCellPos.Row() > MAXROW)
     730           0 :                 aCellPos.SetRow(MAXROW);
     731             :             XMLTableShapeImportHelper* pTableShapeImport =
     732           0 :                     static_cast< XMLTableShapeImportHelper* >( rXMLImport.GetShapeImport().get() );
     733           0 :             pTableShapeImport->SetOnTable(false);
     734           0 :             com::sun::star::table::CellAddress aCellAddress;
     735           0 :             ScUnoConversion::FillApiAddress( aCellAddress, aCellPos );
     736           0 :             pTableShapeImport->SetCell(aCellAddress);
     737             :             pContext = rXMLImport.GetShapeImport()->CreateGroupChildContext(
     738           0 :                 rXMLImport, nPrefix, rLName, xAttrList, xShapes);
     739           0 :             if (pContext)
     740             :             {
     741           0 :                 bIsEmpty = false;
     742           0 :                 rXMLImport.ProgressBarIncrement(false);
     743             :             }
     744           0 :         }
     745             :     }
     746             : 
     747           0 :     if( !pContext )
     748           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     749             : 
     750           0 :     return pContext;
     751             : }
     752             : 
     753           0 : void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScAddress, const SCCOL nCols, const SCROW nRows )
     754             : {
     755           0 :     SCCOL mergeToCol = rScAddress.Col() + nCols;
     756           0 :     SCROW mergeToRow = rScAddress.Row() + nRows;
     757           0 :     bool bInBounds = rScAddress.Col() <= MAXCOL && rScAddress.Row() <= MAXROW &&
     758           0 :                        mergeToCol <= MAXCOL && mergeToRow <= MAXROW;
     759           0 :     if( bInBounds )
     760             :     {
     761           0 :         rXMLImport.GetDocument()->DoMerge( rScAddress.Tab(),
     762           0 :             rScAddress.Col(), rScAddress.Row(), mergeToCol, mergeToRow );
     763             :     }
     764           0 : }
     765             : 
     766             : namespace {
     767             : 
     768           0 : ScValidationMode validationTypeToMode( const sheet::ValidationType eVType )
     769             : {
     770             :     ScValidationMode eMode;
     771           0 :     switch( eVType )
     772             :     {
     773           0 :         case sheet::ValidationType_WHOLE:               eMode = SC_VALID_WHOLE;     break;
     774           0 :         case sheet::ValidationType_DECIMAL:             eMode = SC_VALID_DECIMAL;   break;
     775           0 :         case sheet::ValidationType_DATE:                eMode = SC_VALID_DATE;      break;
     776           0 :         case sheet::ValidationType_TIME:                eMode = SC_VALID_TIME;      break;
     777           0 :         case sheet::ValidationType_TEXT_LEN:            eMode = SC_VALID_TEXTLEN;   break;
     778           0 :         case sheet::ValidationType_LIST:                eMode = SC_VALID_LIST;      break;
     779           0 :         case sheet::ValidationType_CUSTOM:              eMode = SC_VALID_CUSTOM;    break;
     780           0 :         default:                                        eMode = SC_VALID_ANY;       break;
     781             :     }
     782           0 :     return eMode;
     783             : }
     784             : 
     785           0 : ScValidErrorStyle validAlertToValidError( const sheet::ValidationAlertStyle eVAlertStyle )
     786             : {
     787             :     ScValidErrorStyle eVErrStyle;
     788           0 :     switch( eVAlertStyle )
     789             :     {
     790           0 :         case sheet::ValidationAlertStyle_STOP:          eVErrStyle = SC_VALERR_STOP;      break;
     791           0 :         case sheet::ValidationAlertStyle_WARNING:       eVErrStyle = SC_VALERR_WARNING;   break;
     792           0 :         case sheet::ValidationAlertStyle_MACRO:         eVErrStyle = SC_VALERR_MACRO;     break;
     793           0 :         default:                                        eVErrStyle = SC_VALERR_INFO;      break;
     794             :         //should INFO be the default?  seems to be the most unobtrusive choice.
     795             :     }
     796           0 :     return eVErrStyle;
     797             : }
     798             : 
     799             : }
     800             : 
     801           0 : void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange )
     802             : {
     803           0 :     if (maContentValidationName)
     804             :     {
     805           0 :         ScDocument* pDoc = rXMLImport.GetDocument();
     806           0 :         ScMyImportValidation aValidation;
     807           0 :         aValidation.eGrammar1 = aValidation.eGrammar2 = pDoc->GetStorageGrammar();
     808           0 :         if( rXMLImport.GetValidation(*maContentValidationName, aValidation) )
     809             :         {
     810             :             ScValidationData aScValidationData(
     811             :                 validationTypeToMode(aValidation.aValidationType),
     812             :                 ScConditionEntry::GetModeFromApi(static_cast<sal_Int32>(aValidation.aOperator)),
     813             :                 aValidation.sFormula1, aValidation.sFormula2, pDoc, ScAddress(),
     814             :                 aValidation.sFormulaNmsp1, aValidation.sFormulaNmsp2,
     815             :                 aValidation.eGrammar1, aValidation.eGrammar2
     816           0 :             );
     817             : 
     818           0 :             aScValidationData.SetIgnoreBlank( aValidation.bIgnoreBlanks );
     819           0 :             aScValidationData.SetListType( aValidation.nShowList );
     820             : 
     821             :             // set strings for error / input even if disabled (and disable afterwards)
     822           0 :             aScValidationData.SetInput( aValidation.sImputTitle, aValidation.sImputMessage );
     823           0 :             if( !aValidation.bShowImputMessage )
     824           0 :                 aScValidationData.ResetInput();
     825           0 :             aScValidationData.SetError( aValidation.sErrorTitle, aValidation.sErrorMessage, validAlertToValidError(aValidation.aAlertStyle) );
     826           0 :             if( !aValidation.bShowErrorMessage )
     827           0 :                 aScValidationData.ResetError();
     828             : 
     829           0 :             if( !aValidation.sBaseCellAddress.isEmpty() )
     830           0 :                 aScValidationData.SetSrcString( aValidation.sBaseCellAddress );
     831             : 
     832           0 :             sal_uLong nIndex = pDoc->AddValidationEntry( aScValidationData );
     833             : 
     834           0 :             ScPatternAttr aPattern( pDoc->GetPool() );
     835           0 :             aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
     836           0 :             if( rScRange.aStart == rScRange.aEnd )  //for a single cell
     837             :             {
     838           0 :                 pDoc->ApplyPattern( rScRange.aStart.Col(), rScRange.aStart.Row(),
     839           0 :                                     rScRange.aStart.Tab(), aPattern );
     840             :             }
     841             :             else  //for repeating cells
     842             :             {
     843           0 :                 pDoc->ApplyPatternAreaTab( rScRange.aStart.Col(), rScRange.aStart.Row(),
     844           0 :                                        rScRange.aEnd.Col(), rScRange.aEnd.Row(),
     845           0 :                                        rScRange.aStart.Tab(), aPattern );
     846             :             }
     847             : 
     848             :             // is the below still needed?
     849             :             // For now, any sheet with validity is blocked from stream-copying.
     850             :             // Later, the validation names could be stored along with the style names.
     851           0 :             ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
     852           0 :             pSheetData->BlockSheet( GetScImport().GetTables().GetCurrentSheet() );
     853           0 :         }
     854             :     }
     855           0 : }
     856             : 
     857           0 : void ScXMLTableRowCellContext::SetContentValidation( const ScAddress& rCellPos )
     858             : {
     859           0 :     SetContentValidation( ScRange(rCellPos, rCellPos) );
     860           0 : }
     861             : 
     862           0 : void ScXMLTableRowCellContext::SetAnnotation(const ScAddress& rPos)
     863             : {
     864           0 :     ScDocument* pDoc = rXMLImport.GetDocument();
     865           0 :     if( !pDoc || !mxAnnotationData.get() )
     866           0 :         return;
     867             : 
     868           0 :     LockSolarMutex();
     869             : 
     870           0 :     ScPostIt* pNote = 0;
     871             : 
     872           0 :     uno::Reference< drawing::XShapes > xShapes = rXMLImport.GetTables().GetCurrentXShapes();
     873           0 :     uno::Reference< container::XIndexAccess > xShapesIA( xShapes, uno::UNO_QUERY );
     874           0 :     sal_Int32 nOldShapeCount = xShapesIA.is() ? xShapesIA->getCount() : 0;
     875             : 
     876             :     OSL_ENSURE( !mxAnnotationData->mxShape.is() || mxAnnotationData->mxShapes.is(),
     877             :         "ScXMLTableRowCellContext::SetAnnotation - shape without drawing page" );
     878           0 :     if( mxAnnotationData->mxShape.is() && mxAnnotationData->mxShapes.is() )
     879             :     {
     880             :         OSL_ENSURE( mxAnnotationData->mxShapes.get() == xShapes.get(), "ScXMLTableRowCellContext::SetAnnotation - diffenet drawing pages" );
     881           0 :         SdrObject* pObject = ::GetSdrObjectFromXShape( mxAnnotationData->mxShape );
     882             :         OSL_ENSURE( pObject, "ScXMLTableRowCellContext::SetAnnotation - cannot get SdrObject from shape" );
     883             : 
     884             :         /*  Try to reuse the drawing object already created (but only if the
     885             :             note is visible, and the object is a caption object). */
     886           0 :         if( mxAnnotationData->mbShown && mxAnnotationData->mbUseShapePos )
     887             :         {
     888           0 :             if( SdrCaptionObj* pCaption = dynamic_cast< SdrCaptionObj* >( pObject ) )
     889             :             {
     890             :                 OSL_ENSURE( !pCaption->GetLogicRect().IsEmpty(), "ScXMLTableRowCellContext::SetAnnotation - invalid caption rectangle" );
     891             :                 // create the cell note with the caption object
     892           0 :                 pNote = ScNoteUtil::CreateNoteFromCaption( *pDoc, rPos, *pCaption, true );
     893             :                 // forget pointer to object (do not create note again below)
     894           0 :                 pObject = 0;
     895             :             }
     896             :         }
     897             : 
     898             :         // drawing object has not been used to create a note -> use shape data
     899           0 :         if( pObject )
     900             :         {
     901             :             // rescue settings from drawing object before the shape is removed
     902           0 :             ::std::auto_ptr< SfxItemSet > xItemSet( new SfxItemSet( pObject->GetMergedItemSet() ) );
     903           0 :             ::std::auto_ptr< OutlinerParaObject > xOutlinerObj;
     904           0 :             if( OutlinerParaObject* pOutlinerObj = pObject->GetOutlinerParaObject() )
     905           0 :                 xOutlinerObj.reset( new OutlinerParaObject( *pOutlinerObj ) );
     906           0 :             Rectangle aCaptionRect;
     907           0 :             if( mxAnnotationData->mbUseShapePos )
     908           0 :                 aCaptionRect = pObject->GetLogicRect();
     909             :             // remove the shape from the drawing page, this invalidates pObject
     910           0 :             mxAnnotationData->mxShapes->remove( mxAnnotationData->mxShape );
     911           0 :             pObject = 0;
     912             :             // update current number of existing objects
     913           0 :             if( xShapesIA.is() )
     914           0 :                 nOldShapeCount = xShapesIA->getCount();
     915             : 
     916             :             // an outliner object is required (empty note captions not allowed)
     917           0 :             if( xOutlinerObj.get() )
     918             :             {
     919             :                 // create cell note with all data from drawing object
     920             :                 pNote = ScNoteUtil::CreateNoteFromObjectData( *pDoc, rPos,
     921             :                     xItemSet.release(), xOutlinerObj.release(),
     922           0 :                     aCaptionRect, mxAnnotationData->mbShown, false );
     923           0 :             }
     924             :         }
     925             :     }
     926           0 :     else if( !mxAnnotationData->maSimpleText.isEmpty() )
     927             :     {
     928             :         // create note from simple text
     929             :         pNote = ScNoteUtil::CreateNoteFromString( *pDoc, rPos,
     930           0 :             mxAnnotationData->maSimpleText, mxAnnotationData->mbShown, false );
     931             :     }
     932             : 
     933             :     // set author and date
     934           0 :     if( pNote )
     935             :     {
     936             :         double fDate;
     937           0 :         rXMLImport.GetMM100UnitConverter().convertDateTime( fDate, mxAnnotationData->maCreateDate );
     938           0 :         SvNumberFormatter* pNumForm = pDoc->GetFormatTable();
     939           0 :         sal_uInt32 nfIndex = pNumForm->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM );
     940           0 :         OUString aDate;
     941           0 :         Color* pColor = 0;
     942           0 :         Color** ppColor = &pColor;
     943           0 :         pNumForm->GetOutputString( fDate, nfIndex, aDate, ppColor );
     944           0 :         pNote->SetDate( aDate );
     945           0 :         pNote->SetAuthor( mxAnnotationData->maAuthor );
     946             :     }
     947             : 
     948             :     // register a shape that has been newly created in the ScNoteUtil functions
     949           0 :     if( xShapesIA.is() && (nOldShapeCount < xShapesIA->getCount()) )
     950             :     {
     951           0 :         uno::Reference< drawing::XShape > xShape;
     952           0 :         rXMLImport.GetShapeImport()->shapeWithZIndexAdded( xShape, xShapesIA->getCount() );
     953             :     }
     954             : 
     955             :     // store the style names for stream copying
     956           0 :     ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
     957           0 :     pSheetData->HandleNoteStyles( mxAnnotationData->maStyleName, mxAnnotationData->maTextStyle, rPos );
     958             : 
     959           0 :     std::vector<ScXMLAnnotationStyleEntry>::const_iterator aIter = mxAnnotationData->maContentStyles.begin();
     960           0 :     std::vector<ScXMLAnnotationStyleEntry>::const_iterator aEnd = mxAnnotationData->maContentStyles.end();
     961           0 :     while (aIter != aEnd)
     962             :     {
     963           0 :         pSheetData->AddNoteContentStyle( aIter->mnFamily, aIter->maName, rPos, aIter->maSelection );
     964           0 :         ++aIter;
     965           0 :     }
     966             : }
     967             : 
     968             : // core implementation
     969           0 : void ScXMLTableRowCellContext::SetDetectiveObj( const ScAddress& rPosition )
     970             : {
     971           0 :     if( cellExists(rPosition) && pDetectiveObjVec && pDetectiveObjVec->size() )
     972             :     {
     973           0 :         LockSolarMutex();
     974           0 :         ScDetectiveFunc aDetFunc( rXMLImport.GetDocument(), rPosition.Tab() );
     975           0 :         uno::Reference<container::XIndexAccess> xShapesIndex (rXMLImport.GetTables().GetCurrentXShapes(), uno::UNO_QUERY); // make draw page
     976           0 :         ScMyImpDetectiveObjVec::iterator aItr(pDetectiveObjVec->begin());
     977           0 :         ScMyImpDetectiveObjVec::iterator aEndItr(pDetectiveObjVec->end());
     978           0 :         while(aItr != aEndItr)
     979             :         {
     980           0 :             aDetFunc.InsertObject( aItr->eObjType, rPosition, aItr->aSourceRange, aItr->bHasError );
     981           0 :             if (xShapesIndex.is())
     982             :             {
     983           0 :                 sal_Int32 nShapes = xShapesIndex->getCount();
     984           0 :                 uno::Reference < drawing::XShape > xShape;
     985           0 :                 rXMLImport.GetShapeImport()->shapeWithZIndexAdded(xShape, nShapes);
     986             :             }
     987           0 :             ++aItr;
     988           0 :         }
     989             :     }
     990           0 : }
     991             : 
     992             : // core implementation
     993           0 : void ScXMLTableRowCellContext::SetCellRangeSource( const ScAddress& rPosition )
     994             : {
     995           0 :     if( cellExists(rPosition) && pCellRangeSource  && !pCellRangeSource->sSourceStr.isEmpty() &&
     996           0 :         !pCellRangeSource->sFilterName.isEmpty() && !pCellRangeSource->sURL.isEmpty() )
     997             :     {
     998           0 :         ScDocument* pDoc = rXMLImport.GetDocument();
     999           0 :         if (pDoc)
    1000             :         {
    1001           0 :             LockSolarMutex();
    1002           0 :             ScRange aDestRange( rPosition.Col(), rPosition.Row(), rPosition.Tab(),
    1003           0 :                 rPosition.Col() + static_cast<SCCOL>(pCellRangeSource->nColumns - 1),
    1004           0 :                 rPosition.Row() + static_cast<SCROW>(pCellRangeSource->nRows - 1), rPosition.Tab() );
    1005           0 :             OUString sFilterName( pCellRangeSource->sFilterName );
    1006           0 :             OUString sSourceStr( pCellRangeSource->sSourceStr );
    1007             :             ScAreaLink* pLink = new ScAreaLink( pDoc->GetDocumentShell(), pCellRangeSource->sURL,
    1008           0 :                 sFilterName, pCellRangeSource->sFilterOptions, sSourceStr, aDestRange, pCellRangeSource->nRefresh );
    1009           0 :             sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
    1010           0 :             pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, pCellRangeSource->sURL, &sFilterName, &sSourceStr );
    1011             :         }
    1012             :     }
    1013           0 : }
    1014             : 
    1015           0 : void ScXMLTableRowCellContext::SetFormulaCell(ScFormulaCell* pFCell) const
    1016             : {
    1017           0 :     if(pFCell)
    1018             :     {
    1019           0 :         if(mbErrorValue)
    1020             :         {
    1021             :             // don't do anything here
    1022             :             // we need to recalc anyway
    1023             :         }
    1024           0 :         else if( bFormulaTextResult && maStringValue )
    1025             :         {
    1026           0 :             if( !IsPossibleErrorString() )
    1027             :             {
    1028           0 :                 pFCell->SetHybridString( *maStringValue );
    1029           0 :                 pFCell->ResetDirty();
    1030             :             }
    1031             :         }
    1032           0 :         else if (!rtl::math::isNan(fValue))
    1033             :         {
    1034           0 :             pFCell->SetHybridDouble(fValue);
    1035           0 :             pFCell->ResetDirty();
    1036             :         }
    1037             :     }
    1038           0 : }
    1039             : 
    1040           0 : void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
    1041             :         const SCCOL nCurrentCol, const ::boost::optional< OUString >& pOUText )
    1042             : {
    1043           0 :     bool bDoIncrement = true;
    1044             :     //matrix reference cells that contain text formula results;
    1045             :     //cell was already put in document, just need to set text here.
    1046           0 :     if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) )
    1047             :     {
    1048           0 :         bDoIncrement = rXMLImport.GetDocument()->GetCellType(rCurrentPos) == CELLTYPE_FORMULA;
    1049           0 :         if ( bDoIncrement )
    1050             :         {
    1051           0 :             ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCurrentPos);
    1052           0 :             OUString aCellString;
    1053           0 :             if (maStringValue)
    1054           0 :                 aCellString = *maStringValue;
    1055           0 :             else if (mbEditEngineHasText)
    1056           0 :                 aCellString = GetFirstParagraph();
    1057           0 :             else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
    1058           0 :                 aCellString = *pOUText;
    1059             :             else
    1060           0 :                 bDoIncrement = false;
    1061             : 
    1062           0 :             if(mbErrorValue)
    1063           0 :                 bDoIncrement = false;
    1064             : 
    1065           0 :             if(!aCellString.isEmpty())
    1066             :             {
    1067           0 :                 if (bDoIncrement && !IsPossibleErrorString())
    1068             :                 {
    1069           0 :                     pFCell->SetHybridString( aCellString );
    1070           0 :                     pFCell->ResetDirty();
    1071             :                 }
    1072             :                 else
    1073             :                 {
    1074           0 :                     ScAddress aTopLeftMatrixCell;
    1075           0 :                     if(pFCell->GetMatrixOrigin(aTopLeftMatrixCell))
    1076             :                     {
    1077           0 :                         ScFormulaCell* pMatrixCell = rXMLImport.GetDocument()->GetFormulaCell(aTopLeftMatrixCell);
    1078           0 :                         if (pMatrixCell)
    1079           0 :                             pMatrixCell->SetDirty();
    1080             :                     }
    1081             :                     else
    1082             :                         SAL_WARN("sc", "matrix cell without matrix");
    1083             :                 }
    1084           0 :             }
    1085             :         }
    1086             :     }
    1087             :     else //regular text cells
    1088             :     {
    1089           0 :         ScDocumentImport& rDoc = rXMLImport.GetDoc();
    1090           0 :         if (maStringValue)
    1091             :         {
    1092           0 :             rDoc.setStringCell(rCurrentPos, *maStringValue);
    1093           0 :             bDoIncrement = true;
    1094             :         }
    1095           0 :         else if (mbEditEngineHasText)
    1096             :         {
    1097           0 :             if (maFirstParagraph)
    1098             :             {
    1099             :                 // This is a normal text without format runs.
    1100           0 :                 rDoc.setStringCell(rCurrentPos, *maFirstParagraph);
    1101             :             }
    1102             :             else
    1103             :             {
    1104             :                 // This text either has format runs, has field(s), or consists of multiple lines.
    1105             :                 {
    1106           0 :                     ParaFormatsType::const_iterator it = maFormats.begin(), itEnd = maFormats.end();
    1107           0 :                     for (; it != itEnd; ++it)
    1108           0 :                         mpEditEngine->QuickSetAttribs(it->maItemSet, it->maSelection);
    1109             :                 }
    1110             : 
    1111             :                 {
    1112           0 :                     FieldsType::const_iterator it = maFields.begin(), itEnd = maFields.end();
    1113           0 :                     for (; it != itEnd; ++it)
    1114           0 :                         mpEditEngine->QuickInsertField(SvxFieldItem(*it->mpData, EE_FEATURE_FIELD), it->maSelection);
    1115             :                 }
    1116             : 
    1117             :                 // This edit engine uses the SfxItemPool instance returned
    1118             :                 // from pDoc->GetEditPool() to create the text object, which
    1119             :                 // is a prerequisite for using this constructor of ScEditCell.
    1120           0 :                 rDoc.setEditCell(rCurrentPos, mpEditEngine->CreateTextObject());
    1121             :             }
    1122           0 :             bDoIncrement = true;
    1123             :         }
    1124           0 :         else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
    1125             :         {
    1126           0 :             rDoc.setStringCell(rCurrentPos, *pOUText);
    1127           0 :             bDoIncrement = true;
    1128             :         }
    1129             :         else
    1130           0 :             bDoIncrement = false;
    1131             :     }
    1132             : 
    1133             :     // #i56027# This is about setting simple text, not edit cells,
    1134             :     // so ProgressBarIncrement must be called with bEditCell = FALSE.
    1135             :     // Formatted text that is put into the cell by the child context
    1136             :     // is handled in AddCellsToTable() (bIsEmpty is true then).
    1137           0 :     if (bDoIncrement)
    1138           0 :         rXMLImport.ProgressBarIncrement(false);
    1139           0 : }
    1140             : 
    1141           0 : void ScXMLTableRowCellContext::PutValueCell( const ScAddress& rCurrentPos )
    1142             : {
    1143             :     //matrix reference cells that contain value formula results;
    1144             :     //cell was already put in document, just need to set value here.
    1145           0 :     if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) )
    1146             :     {
    1147           0 :         if (rXMLImport.GetDocument()->GetCellType(rCurrentPos) == CELLTYPE_FORMULA)
    1148             :         {
    1149           0 :             ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCurrentPos);
    1150           0 :             SetFormulaCell(pFCell);
    1151           0 :             if (pFCell)
    1152           0 :                 pFCell->SetNeedNumberFormat( true );
    1153             :         }
    1154             :     }
    1155             :     else  //regular value cell
    1156             :     {
    1157             :         // #i62435# Initialize the value cell's script type if the default
    1158             :         // style's number format is latin-only. If the cell uses a different
    1159             :         // format, the script type will be reset when the style is applied.
    1160             : 
    1161           0 :         rXMLImport.GetDoc().setNumericCell(rCurrentPos, fValue);
    1162             :     }
    1163           0 :     rXMLImport.ProgressBarIncrement(false);
    1164           0 : }
    1165             : 
    1166             : namespace {
    1167             : 
    1168           0 : bool isEmptyOrNote( ScDocument* pDoc, const ScAddress& rCurrentPos )
    1169             : {
    1170           0 :     CellType eType = pDoc->GetCellType(rCurrentPos);
    1171           0 :     return (eType == CELLTYPE_NONE);
    1172             : }
    1173             : 
    1174             : }
    1175             : 
    1176           0 : void ScXMLTableRowCellContext::AddTextAndValueCell( const ScAddress& rCellPos,
    1177             :         const ::boost::optional< OUString >& pOUText, ScAddress& rCurrentPos )
    1178             : {
    1179           0 :     ScMyTables& rTables = rXMLImport.GetTables();
    1180           0 :     bool bWasEmpty = bIsEmpty;
    1181           0 :     for (SCCOL i = 0; i < nColsRepeated; ++i)
    1182             :     {
    1183           0 :         rCurrentPos.SetCol( rCellPos.Col() + i );
    1184             : 
    1185             :         // it makes no sense to import data after the last supported column
    1186             :         // fdo#58539 & gnome#627150
    1187           0 :         if(rCurrentPos.Col() > MAXCOL)
    1188           0 :             break;
    1189             : 
    1190           0 :         if (i > 0)
    1191           0 :             rTables.AddColumn(false);
    1192           0 :         if (!bIsEmpty)
    1193             :         {
    1194           0 :             for (SCROW j = 0; j < nRepeatedRows; ++j)
    1195             :             {
    1196           0 :                 rCurrentPos.SetRow( rCellPos.Row() + j );
    1197             : 
    1198             :                 // it makes no sense to import data after last supported row
    1199             :                 // fdo#58539 & gnome#627150
    1200           0 :                 if(rCurrentPos.Row() > MAXROW)
    1201           0 :                     break;
    1202             : 
    1203           0 :                 if( (rCurrentPos.Col() == 0) && (j > 0) )
    1204             :                 {
    1205           0 :                     rTables.AddRow();
    1206           0 :                     rTables.AddColumn(false);
    1207             :                 }
    1208           0 :                 if( cellExists(rCurrentPos) )
    1209             :                 {
    1210           0 :                     if(  ( !(bIsCovered) || isEmptyOrNote(rXMLImport.GetDocument(), rCurrentPos) )  )
    1211             :                     {
    1212           0 :                         switch (nCellType)
    1213             :                         {
    1214             :                             case util::NumberFormat::TEXT:
    1215             :                             {
    1216           0 :                                 PutTextCell( rCurrentPos, i, pOUText );
    1217             :                             }
    1218           0 :                             break;
    1219             :                             case util::NumberFormat::NUMBER:
    1220             :                             case util::NumberFormat::PERCENT:
    1221             :                             case util::NumberFormat::CURRENCY:
    1222             :                             case util::NumberFormat::TIME:
    1223             :                             case util::NumberFormat::DATETIME:
    1224             :                             case util::NumberFormat::LOGICAL:
    1225             :                             {
    1226           0 :                                 PutValueCell( rCurrentPos );
    1227             :                             }
    1228           0 :                             break;
    1229             :                             default:
    1230             :                             {
    1231             :                                 OSL_FAIL("no cell type given");
    1232             :                             }
    1233           0 :                             break;
    1234             :                         }
    1235             :                     }
    1236             : 
    1237           0 :                     SetAnnotation( rCurrentPos );
    1238           0 :                     SetDetectiveObj( rCurrentPos );
    1239           0 :                     SetCellRangeSource( rCurrentPos );
    1240             :                 }
    1241             :                 else
    1242             :                 {
    1243           0 :                     if (!bWasEmpty || mxAnnotationData.get())
    1244             :                     {
    1245           0 :                         if (rCurrentPos.Row() > MAXROW)
    1246           0 :                             rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
    1247             :                         else
    1248           0 :                             rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
    1249             :                     }
    1250             :                 }
    1251             :             }
    1252             :         }
    1253             :         else
    1254             :         {
    1255           0 :             if ((i == 0) && (rCellPos.Col() == 0))
    1256             :             {
    1257           0 :                 for (sal_Int32 j = 1; j < nRepeatedRows; ++j)
    1258             :                 {
    1259           0 :                     rTables.AddRow();
    1260           0 :                     rTables.AddColumn(false);
    1261             :                 }
    1262             :             }
    1263             :         }
    1264             :     }
    1265           0 : }
    1266             : 
    1267           0 : bool ScXMLTableRowCellContext::HasSpecialContent() const
    1268             : {
    1269           0 :     return (mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource);
    1270             : }
    1271             : 
    1272           0 : bool ScXMLTableRowCellContext::CellsAreRepeated() const
    1273             : {
    1274           0 :     return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
    1275             : }
    1276             : 
    1277             : namespace {
    1278             : 
    1279             : // from ScCellObj::GetOutputString_Imp().  all of it may not be necessary.
    1280           0 : OUString getOutputString( ScDocument* pDoc, const ScAddress& aCellPos )
    1281             : {
    1282           0 :     if (!pDoc)
    1283           0 :         return OUString();
    1284             : 
    1285           0 :     CellType eType = pDoc->GetCellType(aCellPos);
    1286           0 :     switch (eType)
    1287             :     {
    1288             :         case CELLTYPE_NONE:
    1289           0 :             return OUString();
    1290             :         case CELLTYPE_EDIT:
    1291             :         {
    1292             :             //  GetString an der EditCell macht Leerzeichen aus Umbruechen,
    1293             :             //  hier werden die Umbrueche aber gebraucht
    1294           0 :             const EditTextObject* pData = pDoc->GetEditText(aCellPos);
    1295           0 :             if (pData)
    1296             :             {
    1297           0 :                 EditEngine& rEngine = pDoc->GetEditEngine();
    1298           0 :                 rEngine.SetText(*pData);
    1299           0 :                 return rEngine.GetText(LINEEND_LF);
    1300             :             }
    1301             :             //  Edit-Zellen auch nicht per NumberFormatter formatieren
    1302             :             //  (passend zur Ausgabe)
    1303             :         }
    1304           0 :         break;
    1305             :         default:
    1306             :         {
    1307             :             //  wie in GetString am Dokument (column)
    1308             :             Color* pColor;
    1309           0 :             sal_uLong nNumFmt = pDoc->GetNumberFormat(aCellPos);
    1310             :             return ScCellFormat::GetString(
    1311           0 :                 *pDoc, aCellPos, nNumFmt, &pColor, *pDoc->GetFormatTable());
    1312             :         }
    1313             :     }
    1314             : 
    1315           0 :     return OUString();
    1316             : }
    1317             : 
    1318             : }
    1319             : 
    1320           0 : void ScXMLTableRowCellContext::AddNonFormulaCell( const ScAddress& rCellPos )
    1321             : {
    1322           0 :     ::boost::optional< OUString > pOUText;
    1323             : 
    1324           0 :     if( nCellType == util::NumberFormat::TEXT )
    1325             :     {
    1326           0 :         if( cellExists(rCellPos) && CellsAreRepeated() )
    1327           0 :             pOUText.reset( getOutputString(rXMLImport.GetDocument(), rCellPos) );
    1328             : 
    1329           0 :         if (!mbEditEngineHasText && !pOUText && !maStringValue)
    1330           0 :             bIsEmpty = true;
    1331             :     }
    1332             : 
    1333           0 :     ScAddress aCurrentPos( rCellPos );
    1334           0 :     if( HasSpecialContent() )
    1335           0 :         bIsEmpty = false;
    1336             : 
    1337           0 :     AddTextAndValueCell( rCellPos, pOUText, aCurrentPos );
    1338             : 
    1339           0 :     if( CellsAreRepeated() )
    1340             :     {
    1341           0 :         SCCOL nStartCol( rCellPos.Col() < MAXCOL ? rCellPos.Col() : MAXCOL );
    1342           0 :         SCROW nStartRow( rCellPos.Row() < MAXROW ? rCellPos.Row() : MAXROW );
    1343           0 :         SCCOL nEndCol( rCellPos.Col() + nColsRepeated - 1 < MAXCOL ? rCellPos.Col() + nColsRepeated - 1 : MAXCOL );
    1344           0 :         SCROW nEndRow( rCellPos.Row() + nRepeatedRows - 1 < MAXROW ? rCellPos.Row() + nRepeatedRows - 1 : MAXROW );
    1345           0 :         ScRange aScRange( nStartCol, nStartRow, rCellPos.Tab(), nEndCol, nEndRow, rCellPos.Tab() );
    1346           0 :         SetContentValidation( aScRange );
    1347           0 :         rXMLImport.GetStylesImportHelper()->AddRange( aScRange );
    1348             :     }
    1349           0 :     else if( cellExists(rCellPos) )
    1350             :     {
    1351           0 :         rXMLImport.GetStylesImportHelper()->AddCell(rCellPos);
    1352           0 :         SetContentValidation( rCellPos );
    1353           0 :     }
    1354           0 : }
    1355             : 
    1356           0 : void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
    1357             : {
    1358           0 :     ScDocument* pDoc = rXMLImport.GetDocument();
    1359           0 :     ScDocumentImport& rDoc = rXMLImport.GetDoc();
    1360             : 
    1361           0 :     OUString aText = maFormula->first;
    1362           0 :     OUString aFormulaNmsp = maFormula->second;
    1363             : 
    1364             :     ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard (
    1365           0 :             new ScExternalRefManager::ApiGuard(pDoc));
    1366             : 
    1367           0 :     if ( !aText.isEmpty() )
    1368             :     {
    1369           0 :         if ( aText[0] == '=' && aText.getLength() > 1 )
    1370             :         {
    1371             :             // temporary formula string as string tokens
    1372           0 :             boost::scoped_ptr<ScTokenArray> pCode(new ScTokenArray);
    1373           0 :             pCode->AddStringXML( aText );
    1374           0 :             if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
    1375           0 :                 pCode->AddStringXML( aFormulaNmsp );
    1376             : 
    1377           0 :             rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
    1378           0 :             ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, *pCode, eGrammar, MM_NONE);
    1379           0 :             SetFormulaCell(pNewCell);
    1380           0 :             rDoc.setFormulaCell(rCellPos, pNewCell);
    1381             : 
    1382             :             // Re-calculate to get number format only when style is not set.
    1383           0 :             pNewCell->SetNeedNumberFormat(!mbHasStyle);
    1384             :         }
    1385           0 :         else if ( aText[0] == '\'' && aText.getLength() > 1 )
    1386             :         {
    1387             :             //  for bEnglish, "'" at the beginning is always interpreted as text
    1388             :             //  marker and stripped
    1389           0 :             rDoc.setStringCell(rCellPos, aText.copy(1));
    1390             :         }
    1391             :         else
    1392             :         {
    1393           0 :             SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
    1394           0 :             sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
    1395             :             double fVal;
    1396           0 :             if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
    1397           0 :                 rDoc.setNumericCell(rCellPos, fVal);
    1398             :             //the (english) number format will not be set
    1399             :             //search matching local format and apply it
    1400             :             else
    1401           0 :                 rDoc.setStringCell(rCellPos, aText);
    1402             :         }
    1403           0 :     }
    1404           0 : }
    1405             : 
    1406           0 : void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
    1407             : {
    1408           0 :     if( cellExists(rCellPos) )
    1409             :     {
    1410           0 :         SetContentValidation( rCellPos );
    1411             :         SAL_WARN_IF((nColsRepeated != 1) || (nRepeatedRows != 1), "sc", "repeated cells with formula not possible now");
    1412           0 :         rXMLImport.GetStylesImportHelper()->AddCell(rCellPos);
    1413             : 
    1414             :         //add matrix
    1415           0 :         if(bIsMatrix)
    1416             :         {
    1417           0 :             if (nMatrixCols > 0 && nMatrixRows > 0)
    1418             :             {
    1419             :                 //matrix cells are put in the document, but we must set the
    1420             :                 //value/text of each matrix cell later
    1421           0 :                 rXMLImport.GetTables().AddMatrixRange(
    1422           0 :                         rCellPos.Col(), rCellPos.Row(),
    1423           0 :                         std::min<SCCOL>(rCellPos.Col() + nMatrixCols - 1, MAXCOL),
    1424           0 :                         std::min<SCROW>(rCellPos.Row() + nMatrixRows - 1, MAXROW),
    1425           0 :                         maFormula->first, maFormula->second, eGrammar);
    1426             : 
    1427             :                 // Set the value/text of the top-left matrix position in its
    1428             :                 // cached result.  For import, we only need to set the correct
    1429             :                 // matrix geometry and the value type of the top-left element.
    1430           0 :                 ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCellPos);
    1431           0 :                 if (pFCell)
    1432             :                 {
    1433           0 :                     ScMatrixRef pMat(new ScMatrix(nMatrixCols, nMatrixRows));
    1434           0 :                     if (bFormulaTextResult && maStringValue)
    1435             :                     {
    1436           0 :                         if (!IsPossibleErrorString())
    1437             :                         {
    1438             :                             pFCell->SetResultMatrix(
    1439           0 :                                 nMatrixCols, nMatrixRows, pMat, new formula::FormulaStringToken(*maStringValue));
    1440           0 :                             pFCell->ResetDirty();
    1441             :                         }
    1442             :                     }
    1443           0 :                     else if (!rtl::math::isNan(fValue))
    1444             :                     {
    1445             :                         pFCell->SetResultMatrix(
    1446           0 :                             nMatrixCols, nMatrixRows, pMat, new formula::FormulaDoubleToken(fValue));
    1447           0 :                         pFCell->ResetDirty();
    1448           0 :                     }
    1449             :                 }
    1450             :             }
    1451             :         }
    1452             :         else
    1453           0 :             PutFormulaCell( rCellPos );
    1454             : 
    1455           0 :         SetAnnotation( rCellPos );
    1456           0 :         SetDetectiveObj( rCellPos );
    1457           0 :         SetCellRangeSource( rCellPos );
    1458           0 :         rXMLImport.ProgressBarIncrement(false);
    1459             :     }
    1460             :     else
    1461             :     {
    1462           0 :         if (rCellPos.Row() > MAXROW)
    1463           0 :             rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
    1464             :         else
    1465           0 :             rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
    1466             :     }
    1467           0 : }
    1468             : 
    1469             : //There are cases where a formula cell is exported with an office:value of 0 or
    1470             : //no office:value at all, but the formula cell will have a text:p value which
    1471             : //contains the intended formula result.
    1472             : //These cases include when a formula result:
    1473             : // - is blank
    1474             : // - has a constant error value beginning with "#" (such as "#VALUE!" or "#N/A")
    1475             : // - has an "Err:[###]" (where "[###]" is an error number)
    1476             : // Libreoffice 4.1+ with ODF1.2 extended write however calcext:value-type="error" in that case
    1477           0 : void ScXMLTableRowCellContext::HasSpecialCaseFormulaText()
    1478             : {
    1479           0 :     if (!mbEditEngineHasText || mbNewValueType)
    1480           0 :         return;
    1481             : 
    1482           0 :     OUString aStr = GetFirstParagraph();
    1483             : 
    1484           0 :     if (aStr.isEmpty() || aStr.startsWith("Err:"))
    1485           0 :         mbPossibleErrorCell = true;
    1486           0 :     else if (aStr.startsWith("#"))
    1487           0 :         mbCheckWithCompilerForError = true;
    1488             : }
    1489             : 
    1490           0 : bool ScXMLTableRowCellContext::IsPossibleErrorString() const
    1491             : {
    1492           0 :     if(mbNewValueType && !mbErrorValue)
    1493           0 :         return false;
    1494           0 :     else if(mbNewValueType && mbErrorValue)
    1495           0 :         return true;
    1496           0 :     return mbPossibleErrorCell || ( mbCheckWithCompilerForError && GetScImport().IsFormulaErrorConstant(*maStringValue) );
    1497             : }
    1498             : 
    1499             : 
    1500           0 : void ScXMLTableRowCellContext::EndElement()
    1501             : {
    1502           0 :     HasSpecialCaseFormulaText();
    1503           0 :     if( bFormulaTextResult && (mbPossibleErrorCell || mbCheckWithCompilerForError) )
    1504             :     {
    1505           0 :         maStringValue.reset(GetFirstParagraph());
    1506           0 :         nCellType = util::NumberFormat::TEXT;
    1507             :     }
    1508             : 
    1509           0 :     ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
    1510           0 :     if( aCellPos.Col() > 0 && nRepeatedRows > 1 )
    1511           0 :         aCellPos.SetRow( aCellPos.Row() - (nRepeatedRows - 1) );
    1512           0 :     if( bIsMerged )
    1513           0 :         DoMerge( aCellPos, nMergedCols - 1, nMergedRows - 1 );
    1514             : 
    1515           0 :     if (maFormula)
    1516           0 :         AddFormulaCell(aCellPos);
    1517             :     else
    1518           0 :         AddNonFormulaCell(aCellPos);
    1519             : 
    1520           0 :     UnlockSolarMutex(); //if LockSolarMutex got used, we presumably need to ensure an UnlockSolarMutex
    1521             : 
    1522           0 :     bIsMerged = false;
    1523           0 :     nMergedCols = 1;
    1524           0 :     nMergedRows = 1;
    1525           0 :     nColsRepeated = 1;
    1526           0 : }
    1527             : 
    1528             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10