LCOV - code coverage report
Current view: top level - sc/source/filter/xml - xmlstyli.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 405 521 77.7 %
Date: 2014-11-03 Functions: 56 73 76.7 %
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 "xmlstyli.hxx"
      21             : #include <xmloff/nmspmap.hxx>
      22             : #include <xmloff/xmlnmspe.hxx>
      23             : #include <xmloff/xmlimppr.hxx>
      24             : #include <xmloff/families.hxx>
      25             : #include <xmloff/xmlnumfi.hxx>
      26             : #include <xmloff/XMLGraphicsDefaultStyle.hxx>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      29             : #include <com/sun/star/container/XNameContainer.hpp>
      30             : #include <com/sun/star/sheet/XSheetConditionalEntries.hpp>
      31             : #include <com/sun/star/table/BorderLine2.hpp>
      32             : #include <comphelper/extract.hxx>
      33             : #include <xmloff/xmlprcon.hxx>
      34             : #include <xmloff/xmluconv.hxx>
      35             : #include "XMLTableHeaderFooterContext.hxx"
      36             : #include "XMLConverter.hxx"
      37             : #include "XMLTableShapeImportHelper.hxx"
      38             : #include "sheetdata.hxx"
      39             : #include "xmlannoi.hxx"
      40             : #include "textuno.hxx"
      41             : #include "cellsuno.hxx"
      42             : 
      43             : #include "docuno.hxx"
      44             : #include "unonames.hxx"
      45             : #include "document.hxx"
      46             : #include "conditio.hxx"
      47             : #include <svl/intitem.hxx>
      48             : #include "rangelst.hxx"
      49             : #include "rangeutl.hxx"
      50             : #include "docfunc.hxx"
      51             : #include "markdata.hxx"
      52             : #include "docpool.hxx"
      53             : #include "scitems.hxx"
      54             : #include "patattr.hxx"
      55             : 
      56             : #define XML_LINE_LEFT 0
      57             : #define XML_LINE_RIGHT 1
      58             : #define XML_LINE_TOP 2
      59             : #define XML_LINE_BOTTOM 3
      60             : 
      61             : #define XML_LINE_TLBR 0
      62             : #define XML_LINE_BLTR 1
      63             : 
      64             : using namespace ::com::sun::star;
      65             : using namespace ::com::sun::star::xml::sax;
      66             : using namespace ::com::sun::star::style;
      67             : using namespace ::com::sun::star::frame;
      68             : using namespace ::com::sun::star::beans;
      69             : using namespace ::com::sun::star::container;
      70             : using namespace xmloff::token;
      71             : using namespace ::formula;
      72             : 
      73             : using com::sun::star::uno::Reference;
      74             : using com::sun::star::uno::UNO_QUERY;
      75             : 
      76         470 : ScXMLCellImportPropertyMapper::ScXMLCellImportPropertyMapper(
      77             :         const rtl::Reference< XMLPropertySetMapper >& rMapper,
      78             :         SvXMLImport& rImportP) :
      79         470 :     SvXMLImportPropertyMapper( rMapper, rImportP )
      80             : {
      81         470 : }
      82             : 
      83         940 : ScXMLCellImportPropertyMapper::~ScXMLCellImportPropertyMapper()
      84             : {
      85         940 : }
      86             : 
      87        4484 : void ScXMLCellImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
      88             : {
      89             :     static const sal_Int16 aPaddingCTF[4] = { CTF_SC_LEFTPADDING, CTF_SC_RIGHTPADDING,
      90             :                                             CTF_SC_TOPPADDING, CTF_SC_BOTTOMPADDING };
      91             :     static const sal_Int16 aBorderCTF[4] = { CTF_SC_LEFTBORDER, CTF_SC_RIGHTBORDER,
      92             :                                             CTF_SC_TOPBORDER, CTF_SC_BOTTOMBORDER };
      93             : 
      94        4484 :     SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
      95        4484 :     XMLPropertyState* pAllPaddingProperty(NULL);
      96        4484 :     XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL };
      97        4484 :     XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL };
      98        4484 :     XMLPropertyState* pAllBorderProperty = NULL;
      99        4484 :     XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL };
     100        4484 :     XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL };
     101        4484 :     XMLPropertyState* pAllBorderWidthProperty = NULL;
     102        4484 :     XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL };
     103        4484 :     XMLPropertyState* pDiagBorders[2] = { 0 };
     104        4484 :     XMLPropertyState* pOldDiagBorderWidths[2] = { 0 };      // old attribute names without "s"
     105        4484 :     XMLPropertyState* pDiagBorderWidths[2] = { 0 };
     106             : 
     107        4484 :     ::std::vector< XMLPropertyState >::iterator endproperty(rProperties.end());
     108       53478 :     for (::std::vector< XMLPropertyState >::iterator aIter =  rProperties.begin();
     109             :         aIter != endproperty; ++aIter)
     110             :     {
     111       48994 :         XMLPropertyState*property = &(*aIter);
     112       48994 :         if (property->mnIndex != -1)
     113             :         {
     114       48782 :             sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
     115       48782 :             switch (nContextID)
     116             :             {
     117         714 :                 case CTF_SC_ALLPADDING                  : pAllPaddingProperty = &*property; break;
     118         174 :                 case CTF_SC_LEFTPADDING                 : pPadding[XML_LINE_LEFT] = &*property; break;
     119         174 :                 case CTF_SC_RIGHTPADDING                : pPadding[XML_LINE_RIGHT] = &*property; break;
     120         174 :                 case CTF_SC_TOPPADDING                  : pPadding[XML_LINE_TOP] = &*property; break;
     121         174 :                 case CTF_SC_BOTTOMPADDING               : pPadding[XML_LINE_BOTTOM] = &*property; break;
     122         112 :                 case CTF_SC_ALLBORDER                   : pAllBorderProperty = &*property; break;
     123         398 :                 case CTF_SC_LEFTBORDER                  : pBorders[XML_LINE_LEFT] = &*property; break;
     124         398 :                 case CTF_SC_RIGHTBORDER                 : pBorders[XML_LINE_RIGHT] = &*property; break;
     125         398 :                 case CTF_SC_TOPBORDER                   : pBorders[XML_LINE_TOP] = &*property; break;
     126         398 :                 case CTF_SC_BOTTOMBORDER                : pBorders[XML_LINE_BOTTOM] = &*property; break;
     127          24 :                 case CTF_SC_ALLBORDERWIDTH              : pAllBorderWidthProperty = &*property; break;
     128           0 :                 case CTF_SC_LEFTBORDERWIDTH             : pBorderWidths[XML_LINE_LEFT] = &*property; break;
     129           0 :                 case CTF_SC_RIGHTBORDERWIDTH            : pBorderWidths[XML_LINE_RIGHT] = &*property; break;
     130           0 :                 case CTF_SC_TOPBORDERWIDTH              : pBorderWidths[XML_LINE_TOP] = &*property; break;
     131           0 :                 case CTF_SC_BOTTOMBORDERWIDTH           : pBorderWidths[XML_LINE_BOTTOM] = &*property; break;
     132          90 :                 case CTF_SC_DIAGONALTLBR                : pDiagBorders[XML_LINE_TLBR] = &*property; break;
     133          90 :                 case CTF_SC_DIAGONALBLTR                : pDiagBorders[XML_LINE_BLTR] = &*property; break;
     134           0 :                 case CTF_SC_DIAGONALTLBRWIDTH           : pOldDiagBorderWidths[XML_LINE_TLBR] = &*property; break;
     135           0 :                 case CTF_SC_DIAGONALTLBRWIDTHS          : pDiagBorderWidths[XML_LINE_TLBR] = &*property; break;
     136           0 :                 case CTF_SC_DIAGONALBLTRWIDTH           : pOldDiagBorderWidths[XML_LINE_BLTR] = &*property; break;
     137           0 :                 case CTF_SC_DIAGONALBLTRWIDTHS          : pDiagBorderWidths[XML_LINE_BLTR] = &*property; break;
     138             :             }
     139             :         }
     140             :     }
     141             :     sal_uInt16 i;
     142             : 
     143             :     // #i27594#; copy Value, but don't insert
     144        4484 :     if (pAllBorderWidthProperty)
     145          24 :         pAllBorderWidthProperty->mnIndex = -1;
     146        4484 :     if (pAllBorderProperty)
     147         112 :         pAllBorderProperty->mnIndex = -1;
     148        4484 :     if (pAllPaddingProperty)
     149         714 :         pAllPaddingProperty->mnIndex = -1;
     150             : 
     151       22420 :     for (i = 0; i < 4; ++i)
     152             :     {
     153       17936 :         if (pAllPaddingProperty && !pPadding[i])
     154        2856 :             pNewPadding[i] = new XMLPropertyState(maPropMapper->FindEntryIndex(aPaddingCTF[i]), pAllPaddingProperty->maValue);
     155       17936 :         if (pAllBorderProperty && !pBorders[i])
     156             :         {
     157         448 :             pNewBorders[i] = new XMLPropertyState(maPropMapper->FindEntryIndex(aBorderCTF[i]), pAllBorderProperty->maValue);
     158         448 :             pBorders[i] = pNewBorders[i];
     159             :         }
     160       17936 :         if( !pBorderWidths[i] )
     161       17936 :             pBorderWidths[i] = pAllBorderWidthProperty;
     162             :         else
     163           0 :             pBorderWidths[i]->mnIndex = -1;
     164       17936 :         if( pBorders[i] )
     165             :         {
     166        2040 :             table::BorderLine2 aBorderLine;
     167        2040 :             pBorders[i]->maValue >>= aBorderLine;
     168        2040 :             if( pBorderWidths[i] )
     169             :             {
     170             :                 // Merge style:border-line-width values to fo:border values. Do
     171             :                 // not override fo:border line width or line style with an
     172             :                 // empty value!
     173          96 :                 table::BorderLine2 aBorderLineWidth;
     174          96 :                 pBorderWidths[i]->maValue >>= aBorderLineWidth;
     175          96 :                 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
     176          96 :                 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
     177          96 :                 aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
     178          96 :                 pBorders[i]->maValue <<= aBorderLine;
     179             :             }
     180             :         }
     181             :     }
     182       13452 :     for( i = 0; i < 2; ++i )
     183             :     {
     184        8968 :         if( pDiagBorders[i] && ( pDiagBorderWidths[i] || pOldDiagBorderWidths[i] ) )
     185             :         {
     186           0 :             table::BorderLine2 aBorderLine;
     187           0 :             pDiagBorders[i]->maValue >>= aBorderLine;
     188           0 :             table::BorderLine2 aBorderLineWidth;
     189           0 :             if (pDiagBorderWidths[i])
     190           0 :                 pDiagBorderWidths[i]->maValue >>= aBorderLineWidth;     // prefer new attribute
     191             :             else
     192           0 :                 pOldDiagBorderWidths[i]->maValue >>= aBorderLineWidth;
     193           0 :             aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth;
     194           0 :             aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth;
     195           0 :             aBorderLine.LineDistance = aBorderLineWidth.LineDistance;
     196           0 :             pDiagBorders[i]->maValue <<= aBorderLine;
     197           0 :             if (pDiagBorderWidths[i])
     198           0 :                 pDiagBorderWidths[i]->mnIndex = -1;
     199           0 :             if (pOldDiagBorderWidths[i])
     200           0 :                 pOldDiagBorderWidths[i]->mnIndex = -1;      // reset mnIndex for old and new attribute if both are present
     201             :         }
     202             :     }
     203             : 
     204       22420 :     for (i = 0; i < 4; ++i)
     205             :     {
     206       17936 :         if (pNewPadding[i])
     207             :         {
     208        2856 :             rProperties.push_back(*pNewPadding[i]);
     209        2856 :             delete pNewPadding[i];
     210             :         }
     211       17936 :         if (pNewBorders[i])
     212             :         {
     213         448 :             rProperties.push_back(*pNewBorders[i]);
     214         448 :             delete pNewBorders[i];
     215             :         }
     216             :     }
     217        4484 : }
     218             : 
     219         322 : ScXMLRowImportPropertyMapper::ScXMLRowImportPropertyMapper(
     220             :         const rtl::Reference< XMLPropertySetMapper >& rMapper,
     221             :         SvXMLImport& rImportP) :
     222         322 :     SvXMLImportPropertyMapper( rMapper, rImportP )
     223             : {
     224         322 : }
     225             : 
     226         644 : ScXMLRowImportPropertyMapper::~ScXMLRowImportPropertyMapper()
     227             : {
     228         644 : }
     229             : 
     230         542 : void ScXMLRowImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const
     231             : {
     232         542 :     SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex);
     233         542 :     XMLPropertyState* pHeight(NULL);
     234         542 :     XMLPropertyState* pOptimalHeight(NULL);
     235         542 :     XMLPropertyState* pPageBreak(NULL);
     236         542 :     ::std::vector< XMLPropertyState >::iterator endproperty(rProperties.end());
     237        1992 :     for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin();
     238             :         aIter != endproperty; ++aIter)
     239             :     {
     240        1450 :         XMLPropertyState* property = &(*aIter);
     241        1450 :         if (property->mnIndex != -1)
     242             :         {
     243        1450 :             sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex);
     244        1450 :             switch (nContextID)
     245             :             {
     246         528 :                 case CTF_SC_ROWHEIGHT                   : pHeight = property; break;
     247         456 :                 case CTF_SC_ROWOPTIMALHEIGHT            : pOptimalHeight = property; break;
     248         466 :                 case CTF_SC_ROWBREAKBEFORE              : pPageBreak = property; break;
     249             :             }
     250             :         }
     251             :     }
     252         542 :     if (pPageBreak)
     253             :     {
     254         466 :         if(!(::cppu::any2bool(pPageBreak->maValue)))
     255         466 :             pPageBreak->mnIndex = -1;
     256             :     }
     257         542 :     if (pOptimalHeight)
     258             :     {
     259         456 :         if (::cppu::any2bool(pOptimalHeight->maValue))
     260             :         {
     261         406 :             if (pHeight)
     262             :             {
     263             :                 // set the stored height, but keep "optimal" flag:
     264             :                 // pass the height value as OptimalHeight property (only allowed while loading!)
     265         406 :                 pOptimalHeight->maValue = pHeight->maValue;
     266         406 :                 pHeight->mnIndex = -1;
     267             :             }
     268             :             else
     269           0 :                 pOptimalHeight->mnIndex = -1;
     270             :         }
     271             :     }
     272          86 :     else if (pHeight)
     273             :     {
     274          72 :         rProperties.push_back(XMLPropertyState(maPropMapper->FindEntryIndex(CTF_SC_ROWOPTIMALHEIGHT), css::uno::Any(false)));
     275             :     }
     276             :     // don't access pointers to rProperties elements after push_back!
     277         542 : }
     278             : 
     279        3556 : class XMLTableCellPropsContext : public SvXMLPropertySetContext
     280             : {
     281             :     using SvXMLPropertySetContext::CreateChildContext;
     282             :     public:
     283             :         XMLTableCellPropsContext(
     284             :              SvXMLImport& rImport, sal_uInt16 nPrfx,
     285             :              const OUString& rLName,
     286             :              const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     287             :              sal_uInt32 nFamily,
     288             :              ::std::vector< XMLPropertyState > &rProps,
     289             :              const rtl::Reference < SvXMLImportPropertyMapper > &rMap);
     290             : 
     291             :         virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
     292             :             const OUString& rLocalName,
     293             :             const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     294             :            ::std::vector< XMLPropertyState > &rProperties,
     295             :            const XMLPropertyState& rProp ) SAL_OVERRIDE;
     296             : };
     297             : 
     298        1778 : XMLTableCellPropsContext::XMLTableCellPropsContext(
     299             :              SvXMLImport& rImport, sal_uInt16 nPrfx,
     300             :              const OUString& rLName,
     301             :              const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     302             :              sal_uInt32 nFamily,
     303             :              ::std::vector< XMLPropertyState > &rProps,
     304             :              const rtl::Reference < SvXMLImportPropertyMapper > &rMap)
     305             :           : SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
     306        1778 :                rProps, rMap )
     307             : {
     308        1778 : }
     309             : 
     310           0 : SvXMLImportContext* XMLTableCellPropsContext::CreateChildContext( sal_uInt16 nPrefix,
     311             :             const OUString& rLocalName,
     312             :             const uno::Reference< xml::sax::XAttributeList >& xAttrList,
     313             :            ::std::vector< XMLPropertyState > &rProperties,
     314             :            const XMLPropertyState& rProp )
     315             : {
     316             :     // no need for a custom context or indeed a SvXMLTokenMap to grab just the
     317             :     // single attribute ( href ) that we are interested in.
     318             :     // still though, we will check namesspaces etc.
     319           0 :     if ( ( XML_NAMESPACE_STYLE == nPrefix) &&
     320           0 :         IsXMLToken(rLocalName, XML_HYPERLINK ) )
     321             :     {
     322           0 :         OUString sURL;
     323           0 :         for ( int i=0; i<xAttrList->getLength(); ++i )
     324             :         {
     325           0 :             OUString aLocalName;
     326           0 :             OUString sName = xAttrList->getNameByIndex(i);
     327           0 :             sal_uInt16 nPrfx = GetImport().GetNamespaceMap().GetKeyByAttrName( sName,
     328           0 :                                                             &aLocalName );
     329           0 :             if ( nPrfx == XML_NAMESPACE_XLINK )
     330             :             {
     331           0 :                 if ( IsXMLToken( aLocalName, XML_HREF ) )
     332             :                 {
     333           0 :                     sURL = xAttrList->getValueByIndex(i);
     334           0 :                     break;
     335             :                 }
     336             :             }
     337           0 :         }
     338           0 :         if ( !sURL.isEmpty() )
     339             :         {
     340           0 :             XMLPropertyState aProp( rProp );
     341           0 :             aProp.maValue <<=  sURL;
     342           0 :             rProperties.push_back( aProp );
     343           0 :         }
     344             :     }
     345           0 :     return SvXMLPropertySetContext::CreateChildContext( nPrefix, rLocalName, xAttrList, rProperties, rProp );
     346             : }
     347             : 
     348             : class ScXMLMapContext : public SvXMLImportContext
     349             : {
     350             :     OUString msApplyStyle;
     351             :     OUString msCondition;
     352             :     OUString msBaseCell;
     353             : 
     354         198 :     ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
     355             : public:
     356             : 
     357             :     ScXMLMapContext(
     358             :             SvXMLImport& rImport, sal_uInt16 nPrfx,
     359             :             const OUString& rLName,
     360             :             const uno::Reference< xml::sax::XAttributeList > & xAttrList );
     361             :     virtual ~ScXMLMapContext();
     362             : 
     363             :     ScCondFormatEntry* CreateConditionEntry();
     364             : };
     365             : 
     366          66 : ScXMLMapContext::ScXMLMapContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
     367             :             const OUString& rLName, const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     368          66 :     : SvXMLImportContext( rImport, nPrfx, rLName )
     369             : {
     370          66 :     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     371         264 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
     372             :     {
     373         198 :         const OUString& rAttrName(xAttrList->getNameByIndex( i ));
     374         396 :         OUString aLocalName;
     375         198 :         sal_uInt16 nPrefix(GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
     376         396 :         const OUString& rValue(xAttrList->getValueByIndex( i ));
     377             : 
     378             :         // TODO: use a map here
     379         198 :         if( XML_NAMESPACE_STYLE == nPrefix )
     380             :         {
     381         198 :             if( IsXMLToken(aLocalName, XML_CONDITION ) )
     382          66 :                 msCondition = rValue;
     383         132 :             else if( IsXMLToken(aLocalName, XML_APPLY_STYLE_NAME ) )
     384          66 :                 msApplyStyle = GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL, rValue);
     385          66 :             else if ( IsXMLToken(aLocalName, XML_BASE_CELL_ADDRESS ) )
     386          66 :                 msBaseCell = rValue;
     387             :         }
     388         198 :     }
     389          66 : }
     390             : 
     391          66 : ScCondFormatEntry* ScXMLMapContext::CreateConditionEntry()
     392             : {
     393         132 :     OUString aCondition, aConditionNmsp;
     394          66 :     FormulaGrammar::Grammar eGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
     395          66 :     GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eGrammar, msCondition );
     396          66 :     bool bHasNmsp = aCondition.getLength() < msCondition.getLength();
     397             : 
     398             :     // parse a condition from the attribute string
     399         132 :     ScXMLConditionParseResult aParseResult;
     400          66 :     ScXMLConditionHelper::parseCondition( aParseResult, aCondition, 0 );
     401             : 
     402          66 :     if( !bHasNmsp )
     403             :     {
     404             :         // the attribute does not contain a namespace: try to find a namespace of an external grammar
     405          66 :         FormulaGrammar::Grammar eNewGrammar = FormulaGrammar::GRAM_UNSPECIFIED;
     406          66 :         GetScImport().ExtractFormulaNamespaceGrammar( aCondition, aConditionNmsp, eNewGrammar, aCondition, true );
     407          66 :         if( eNewGrammar != FormulaGrammar::GRAM_EXTERNAL )
     408          66 :             eGrammar = eNewGrammar;
     409             :     }
     410             : 
     411          66 :     ScConditionMode eMode = ScConditionEntry::GetModeFromApi(aParseResult.meOperator);
     412         132 :     OUString aNmsp1, aNmsp2;
     413          66 :     ScDocument* pDoc = GetScImport().GetDocument();
     414             : 
     415             :     ScCondFormatEntry* pEntry =  new ScCondFormatEntry(eMode, aParseResult.maOperand1, aParseResult.maOperand2, pDoc, ScAddress(), msApplyStyle,
     416          66 :                                                     aNmsp1, aNmsp2, eGrammar, eGrammar);
     417             : 
     418          66 :     pEntry->SetSrcString(msBaseCell);
     419         132 :     return pEntry;
     420             : }
     421             : 
     422         132 : ScXMLMapContext::~ScXMLMapContext()
     423             : {
     424         132 : }
     425             : 
     426       15510 : void XMLTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
     427             :                                         const OUString& rLocalName,
     428             :                                         const OUString& rValue )
     429             : {
     430             :     // TODO: use a map here
     431       15510 :     if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
     432         996 :         sDataStyleName = rValue;
     433       14514 :     else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
     434         324 :         sPageStyle = rValue;
     435             :     else
     436       14190 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
     437       15510 : }
     438             : 
     439           0 : TYPEINIT1( XMLTableStyleContext, XMLPropStyleContext );
     440             : 
     441        6150 : XMLTableStyleContext::XMLTableStyleContext( ScXMLImport& rImport,
     442             :         sal_uInt16 nPrfx, const OUString& rLName,
     443             :         const uno::Reference< XAttributeList > & xAttrList,
     444             :         SvXMLStylesContext& rStyles, sal_uInt16 nFamily, bool bDefaultStyle ) :
     445             :     XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
     446             :     sDataStyleName(),
     447             :     pStyles(&rStyles),
     448             :     nNumberFormat(-1),
     449             :     nLastSheet(-1),
     450             :     bParentSet(false),
     451             :     mpCondFormat(NULL),
     452        6150 :     mbDeleteCondFormat(true)
     453             : {
     454        6150 : }
     455             : 
     456       18450 : XMLTableStyleContext::~XMLTableStyleContext()
     457             : {
     458        6150 :     if(mbDeleteCondFormat)
     459        6150 :         delete mpCondFormat;
     460       12300 : }
     461             : 
     462        7316 : SvXMLImportContext *XMLTableStyleContext::CreateChildContext(
     463             :         sal_uInt16 nPrefix,
     464             :         const OUString& rLocalName,
     465             :         const uno::Reference< XAttributeList > & xAttrList )
     466             : {
     467        7316 :     SvXMLImportContext *pContext(NULL);
     468             : 
     469       14632 :     if( (XML_NAMESPACE_STYLE == nPrefix) &&
     470        7316 :         IsXMLToken(rLocalName, XML_MAP ) )
     471             :     {
     472          66 :         if(!mpCondFormat)
     473          18 :             mpCondFormat = new ScConditionalFormat( 0, GetScImport().GetDocument() );
     474          66 :         ScXMLMapContext* pMapContext = new ScXMLMapContext(GetImport(), nPrefix, rLocalName, xAttrList);
     475          66 :         pContext = pMapContext;
     476          66 :         mpCondFormat->AddEntry(pMapContext->CreateConditionEntry());
     477             :     }
     478       14500 :     else if ( ( XML_NAMESPACE_STYLE == nPrefix) &&
     479        7250 :         IsXMLToken(rLocalName, XML_TABLE_CELL_PROPERTIES ) )
     480             :     {
     481             :         rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     482        1778 :             ((SvXMLStylesContext *)GetStyles())->GetImportPropertyMapper(
     483        1778 :                 GetFamily() );
     484        1778 :         if( xImpPrMap.is() )
     485        1778 :             pContext = new XMLTableCellPropsContext( GetImport(), nPrefix,
     486             :                 rLocalName, xAttrList,
     487             :                 XML_TYPE_PROP_TABLE_CELL,
     488        1778 :                 GetProperties(),
     489        3556 :                 xImpPrMap );
     490             :     }
     491             : 
     492        7316 :     if (!pContext)
     493             :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
     494        5472 :                                                            xAttrList );
     495        7316 :     return pContext;
     496             : }
     497             : 
     498        1722 : void XMLTableStyleContext::ApplyCondFormat( const uno::Sequence<table::CellRangeAddress>& xCellRanges )
     499             : {
     500        1722 :     if(!mpCondFormat || GetScImport().HasNewCondFormatData())
     501        3444 :         return;
     502             : 
     503           0 :     ScRangeList aRangeList;
     504           0 :     sal_Int32 nRanges = xCellRanges.getLength();
     505           0 :     for(sal_Int32 i = 0; i < nRanges; ++i)
     506             :     {
     507           0 :         table::CellRangeAddress aAddress = xCellRanges[i];
     508           0 :         ScRange aRange( aAddress.StartColumn, aAddress.StartRow, aAddress.Sheet, aAddress.EndColumn, aAddress.EndRow, aAddress.Sheet );
     509           0 :         aRangeList.Join( aRange, false );
     510             :     }
     511             : 
     512           0 :     ScDocument* pDoc = GetScImport().GetDocument();
     513           0 :     SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
     514           0 :     ScConditionalFormatList* pFormatList = pDoc->GetCondFormList(nTab);
     515           0 :     for(ScConditionalFormatList::iterator itr = pFormatList->begin(), itrEnd = pFormatList->end();
     516             :                     itr != itrEnd; ++itr)
     517             :     {
     518           0 :         if(itr->EqualEntries(*mpCondFormat))
     519             :         {
     520           0 :             ScRangeList& rRangeList = itr->GetRangeList();
     521           0 :             sal_uInt32 nCondId = itr->GetKey();
     522           0 :             size_t n = aRangeList.size();
     523           0 :             for(size_t i = 0; i < n; ++i)
     524             :             {
     525           0 :                 const ScRange* pRange = aRangeList[i];
     526           0 :                 rRangeList.Join(*pRange);
     527             :             }
     528             : 
     529           0 :             pDoc->AddCondFormatData( aRangeList, nTab, nCondId );
     530           0 :             return;
     531             :         }
     532             :     }
     533             : 
     534           0 :     if(mpCondFormat && mbDeleteCondFormat)
     535             :     {
     536           0 :         sal_uLong nIndex = pDoc->AddCondFormat(mpCondFormat, nTab );
     537           0 :         mpCondFormat->SetKey(nIndex);
     538           0 :         mpCondFormat->AddRange(aRangeList);
     539             : 
     540           0 :         pDoc->AddCondFormatData( aRangeList, nTab, nIndex );
     541           0 :         mbDeleteCondFormat = false;
     542           0 :     }
     543             : 
     544             : }
     545             : 
     546       12950 : void XMLTableStyleContext::FillPropertySet(
     547             :     const uno::Reference< XPropertySet > & rPropSet )
     548             : {
     549       12950 :     if (!IsDefaultStyle())
     550             :     {
     551       12628 :         if (GetFamily() == XML_STYLE_FAMILY_TABLE_CELL)
     552             :         {
     553        3228 :             if (!bParentSet)
     554             :             {
     555        3050 :                 AddProperty(CTF_SC_CELLSTYLE, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL, GetParentName() )));
     556        3050 :                 bParentSet = true;
     557             :             }
     558        3228 :             sal_Int32 nNumFmt = GetNumberFormat();
     559        3228 :             if (nNumFmt >= 0)
     560        1070 :                 AddProperty(CTF_SC_NUMBERFORMAT, uno::makeAny(nNumFmt));
     561             :         }
     562        9400 :         else if (GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE)
     563             :         {
     564         578 :             if (!sPageStyle.isEmpty())
     565         570 :                 AddProperty(CTF_SC_MASTERPAGENAME, uno::makeAny(GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sPageStyle )));
     566             :         }
     567             :     }
     568       12950 :     XMLPropStyleContext::FillPropertySet(rPropSet);
     569       12950 : }
     570             : 
     571         322 : void XMLTableStyleContext::SetDefaults()
     572             : {
     573         322 :     if ((GetFamily() == XML_STYLE_FAMILY_TABLE_CELL) && GetImport().GetModel().is())
     574             :     {
     575         322 :         uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetImport().GetModel(), uno::UNO_QUERY);
     576         322 :         if (xMultiServiceFactory.is())
     577             :         {
     578         322 :             uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance("com.sun.star.sheet.Defaults"), uno::UNO_QUERY);
     579         322 :             if (xProperties.is())
     580         322 :                 FillPropertySet(xProperties);
     581         322 :         }
     582             :     }
     583         322 : }
     584             : 
     585        4690 : void XMLTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
     586             : {
     587        4690 :     XMLPropertyState* property = FindProperty(nContextID);
     588        4690 :     if (property)
     589         326 :         property->mnIndex = -1; // #i46996# remove old property, so it isn't double
     590        4690 :     sal_Int32 nIndex(static_cast<XMLTableStylesContext *>(pStyles)->GetIndex(nContextID));
     591             :     OSL_ENSURE(nIndex != -1, "Property not found in Map");
     592        4690 :     XMLPropertyState aPropState(nIndex, rValue);
     593        4690 :     GetProperties().push_back(aPropState); // has to be insertes in a sort order later
     594        4690 : }
     595             : 
     596        4690 : XMLPropertyState* XMLTableStyleContext::FindProperty(const sal_Int16 nContextID)
     597             : {
     598        4690 :     XMLPropertyState* pRet = NULL;
     599        4690 :     rtl::Reference < XMLPropertySetMapper > xPrMap;
     600             :     rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     601        9380 :         pStyles->GetImportPropertyMapper( GetFamily() );
     602             :     OSL_ENSURE( xImpPrMap.is(), "There is the import prop mapper" );
     603        4690 :     if( xImpPrMap.is() )
     604        4690 :         xPrMap = xImpPrMap->getPropertySetMapper();
     605        4690 :     if( xPrMap.is() )
     606             :     {
     607        4690 :         ::std::vector< XMLPropertyState >::iterator endproperty(GetProperties().end());
     608        4690 :         ::std::vector< XMLPropertyState >::iterator aIter(GetProperties().begin());
     609       52978 :         while(!pRet && aIter != endproperty)
     610             :         {
     611       43598 :             XMLPropertyState* property = &(*aIter);
     612       43598 :             if (property->mnIndex != -1 && xPrMap->GetEntryContextId(property->mnIndex) == nContextID)
     613             :             {
     614         326 :                 pRet = property;
     615             :             }
     616             :             else
     617       43272 :                 ++aIter;
     618             :         }
     619             :     }
     620        9380 :     return pRet;
     621             : }
     622             : 
     623        5188 : sal_Int32 XMLTableStyleContext::GetNumberFormat()
     624             : {
     625        5188 :     if (nNumberFormat < 0 && !sDataStyleName.isEmpty())
     626             :     {
     627             :         const SvXMLNumFormatContext* pStyle = static_cast<const SvXMLNumFormatContext*>(
     628         994 :             pStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, sDataStyleName, true));
     629             : 
     630         994 :         if (!pStyle)
     631             :         {
     632           0 :             XMLTableStylesContext* pMyStyles = static_cast<XMLTableStylesContext*>(GetScImport().GetStyles());
     633           0 :             if (pMyStyles)
     634             :                 pStyle = static_cast<const SvXMLNumFormatContext*>(
     635           0 :                     pMyStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, sDataStyleName, true));
     636             :             else
     637             :             {
     638             :                 OSL_FAIL("not possible to get style");
     639             :             }
     640             :         }
     641         994 :         if (pStyle)
     642         994 :             nNumberFormat = const_cast<SvXMLNumFormatContext*>(pStyle)->GetKey();
     643             :     }
     644        5188 :     return nNumberFormat;
     645             : }
     646             : 
     647        7290 : SvXMLStyleContext *XMLTableStylesContext::CreateStyleStyleChildContext(
     648             :         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
     649             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     650             : {
     651             :     SvXMLStyleContext *pStyle;
     652             :     // use own wrapper for text and paragraph, to record style usage
     653        7290 :     if (nFamily == XML_STYLE_FAMILY_TEXT_PARAGRAPH || nFamily == XML_STYLE_FAMILY_TEXT_TEXT)
     654        1352 :         pStyle = new ScCellTextStyleContext( GetImport(), nPrefix, rLocalName,
     655        1352 :                                             xAttrList, *this, nFamily );
     656             :     else
     657             :         pStyle = SvXMLStylesContext::CreateStyleStyleChildContext(
     658        5938 :                     nFamily, nPrefix, rLocalName, xAttrList );
     659             : 
     660        7290 :     if (!pStyle)
     661             :     {
     662        5828 :         switch( nFamily )
     663             :         {
     664             :         case XML_STYLE_FAMILY_TABLE_CELL:
     665             :         case XML_STYLE_FAMILY_TABLE_COLUMN:
     666             :         case XML_STYLE_FAMILY_TABLE_ROW:
     667             :         case XML_STYLE_FAMILY_TABLE_TABLE:
     668             :             pStyle = new XMLTableStyleContext( GetScImport(), nPrefix, rLocalName,
     669        5828 :                                                xAttrList, *this, nFamily );
     670        5828 :             break;
     671             :         }
     672             :     }
     673             : 
     674        7290 :     return pStyle;
     675             : }
     676             : 
     677         674 : SvXMLStyleContext *XMLTableStylesContext::CreateDefaultStyleStyleChildContext(
     678             :         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
     679             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     680             : {
     681             :     SvXMLStyleContext *pStyle(SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily, nPrefix,
     682             :                                                             rLocalName,
     683         674 :                                                             xAttrList ));
     684         674 :     if (!pStyle)
     685             :     {
     686         674 :         switch( nFamily )
     687             :         {
     688             :             case XML_STYLE_FAMILY_TABLE_CELL:
     689             :                 pStyle = new XMLTableStyleContext( GetScImport(), nPrefix, rLocalName,
     690         322 :                                             xAttrList, *this, nFamily, true);
     691         322 :             break;
     692             :             case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
     693         128 :                 pStyle = new XMLGraphicsDefaultStyle( GetScImport(), nPrefix, rLocalName,
     694         128 :                                             xAttrList, *this);
     695         128 :             break;
     696             :         }
     697             :     }
     698             : 
     699         674 :     return pStyle;
     700             : }
     701             : 
     702         910 : XMLTableStylesContext::XMLTableStylesContext( SvXMLImport& rImport,
     703             :         sal_uInt16 nPrfx ,
     704             :         const OUString& rLName ,
     705             :         const uno::Reference< XAttributeList > & xAttrList,
     706             :         const bool bTempAutoStyles ) :
     707             :     SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
     708             :     sCellStyleServiceName( OUString( "com.sun.star.style.CellStyle" )),
     709             :     sColumnStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME )),
     710             :     sRowStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME )),
     711             :     sTableStyleServiceName( OUString( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME )),
     712             :     nNumberFormatIndex(-1),
     713             :     nConditionalFormatIndex(-1),
     714             :     nCellStyleIndex(-1),
     715             :     nMasterPageNameIndex(-1),
     716         910 :     bAutoStyles(bTempAutoStyles)
     717             : {
     718         910 : }
     719             : 
     720        1820 : XMLTableStylesContext::~XMLTableStylesContext()
     721             : {
     722        1820 : }
     723             : 
     724         910 : void XMLTableStylesContext::EndElement()
     725             : {
     726         910 :     SvXMLStylesContext::EndElement();
     727         910 :     if (bAutoStyles)
     728         586 :         GetImport().GetTextImport()->SetAutoStyles( this );
     729             :     else
     730         324 :         GetScImport().InsertStyles();
     731         910 : }
     732             : 
     733             : rtl::Reference < SvXMLImportPropertyMapper >
     734       35104 :     XMLTableStylesContext::GetImportPropertyMapper(
     735             :                     sal_uInt16 nFamily ) const
     736             : {
     737       35104 :     rtl::Reference < SvXMLImportPropertyMapper > xMapper(SvXMLStylesContext::GetImportPropertyMapper(nFamily));
     738             : 
     739       35104 :     if (!xMapper.is())
     740             :     {
     741       27492 :         switch( nFamily )
     742             :         {
     743             :             case XML_STYLE_FAMILY_TABLE_CELL:
     744             :             {
     745       14440 :                 if( !xCellImpPropMapper.is() )
     746             :                 {
     747        1880 :                     ((XMLTableStylesContext *)this)->xCellImpPropMapper =
     748        1880 :                         new ScXMLCellImportPropertyMapper( GetScImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     749         470 :                     xCellImpPropMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(const_cast<SvXMLImport&>(GetImport())));
     750             :                 }
     751       14440 :                 xMapper = xCellImpPropMapper;
     752             :             }
     753       14440 :             break;
     754             :             case XML_STYLE_FAMILY_TABLE_COLUMN:
     755             :             {
     756        4212 :                 if( !xColumnImpPropMapper.is() )
     757        1288 :                     ((XMLTableStylesContext *)this)->xColumnImpPropMapper =
     758        1288 :                         new SvXMLImportPropertyMapper( GetScImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     759        4212 :                 xMapper = xColumnImpPropMapper;
     760             :             }
     761        4212 :              break;
     762             :             case XML_STYLE_FAMILY_TABLE_ROW:
     763             :             {
     764        7042 :                 if( !xRowImpPropMapper.is() )
     765        1288 :                     ((XMLTableStylesContext *)this)->xRowImpPropMapper =
     766        1288 :                         new ScXMLRowImportPropertyMapper( GetScImport().GetRowStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     767        7042 :                 xMapper = xRowImpPropMapper;
     768             :             }
     769        7042 :              break;
     770             :             case XML_STYLE_FAMILY_TABLE_TABLE:
     771             :             {
     772        1798 :                 if( !xTableImpPropMapper.is() )
     773        1288 :                     ((XMLTableStylesContext *)this)->xTableImpPropMapper =
     774        1288 :                         new SvXMLImportPropertyMapper( GetScImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
     775        1798 :                 xMapper = xTableImpPropMapper;
     776             :             }
     777        1798 :              break;
     778             :         }
     779             :     }
     780             : 
     781       35104 :     return xMapper;
     782             : }
     783             : 
     784             : uno::Reference < XNameContainer >
     785        3852 :         XMLTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
     786             : {
     787        3852 :     uno::Reference < XNameContainer > xStyles(SvXMLStylesContext::GetStylesContainer(nFamily));
     788        3852 :     if (!xStyles.is())
     789             :     {
     790        3852 :         OUString sName;
     791        3852 :         switch( nFamily )
     792             :         {
     793             :             case XML_STYLE_FAMILY_TABLE_TABLE:
     794             :             {
     795           0 :                 if( xTableStyles.is() )
     796           0 :                     xStyles.set(xTableStyles);
     797             :                 else
     798           0 :                     sName =
     799           0 :                         OUString( OUString( "TableStyles" ));
     800             :             }
     801           0 :             break;
     802             :             case XML_STYLE_FAMILY_TABLE_CELL:
     803             :             {
     804        3012 :                 if( xCellStyles.is() )
     805        2744 :                     xStyles.set(xCellStyles);
     806             :                 else
     807         536 :                     sName =
     808         268 :                         OUString( OUString( "CellStyles" ));
     809             :             }
     810        3012 :             break;
     811             :             case XML_STYLE_FAMILY_TABLE_COLUMN:
     812             :             {
     813           0 :                 if( xColumnStyles.is() )
     814           0 :                     xStyles.set(xColumnStyles);
     815             :                 else
     816           0 :                     sName =
     817           0 :                         OUString( OUString( "ColumnStyles" ));
     818             :             }
     819           0 :             break;
     820             :             case XML_STYLE_FAMILY_TABLE_ROW:
     821             :             {
     822           0 :                 if( xRowStyles.is() )
     823           0 :                     xStyles.set(xRowStyles);
     824             :                 else
     825           0 :                     sName =
     826           0 :                         OUString( OUString( "RowStyles" ));
     827             :             }
     828           0 :             break;
     829             :         }
     830        3852 :         if( !xStyles.is() && !sName.isEmpty() && GetScImport().GetModel().is() )
     831             :         {
     832             :             uno::Reference< XStyleFamiliesSupplier > xFamiliesSupp(
     833         268 :                                             GetScImport().GetModel(), UNO_QUERY );
     834         268 :             if (xFamiliesSupp.is())
     835             :             {
     836         268 :                 uno::Reference< XNameAccess > xFamilies(xFamiliesSupp->getStyleFamilies());
     837             : 
     838             :                 try
     839             :                 {
     840         268 :                     xStyles.set(xFamilies->getByName( sName ), uno::UNO_QUERY);
     841             :                 }
     842           0 :                 catch ( uno::Exception& )
     843             :                 {
     844             :                     // #i97680# Named table/column/row styles aren't supported, getByName will throw an exception.
     845             :                     // For better interoperability, these styles should then be handled as automatic styles.
     846             :                     // For now, NULL is returned (and the style is ignored).
     847             :                 }
     848         268 :                 switch( nFamily )
     849             :                 {
     850             :                 case XML_STYLE_FAMILY_TABLE_TABLE:
     851           0 :                     ((XMLTableStylesContext *)this)->xTableStyles.set(xStyles);
     852           0 :                     break;
     853             :                 case XML_STYLE_FAMILY_TABLE_CELL:
     854         268 :                     ((XMLTableStylesContext *)this)->xCellStyles.set(xStyles);
     855         268 :                     break;
     856             :                 case XML_STYLE_FAMILY_TABLE_COLUMN:
     857           0 :                     ((XMLTableStylesContext *)this)->xColumnStyles.set(xStyles);
     858           0 :                     break;
     859             :                 case XML_STYLE_FAMILY_TABLE_ROW:
     860           0 :                     ((XMLTableStylesContext *)this)->xRowStyles.set(xStyles);
     861           0 :                     break;
     862         268 :                 }
     863         268 :             }
     864        3852 :         }
     865             :     }
     866             : 
     867        3852 :     return xStyles;
     868             : }
     869             : 
     870         176 : OUString XMLTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
     871             : {
     872         176 :     OUString sServiceName(SvXMLStylesContext::GetServiceName(nFamily));
     873         176 :     if (sServiceName.isEmpty())
     874             :     {
     875         176 :         switch( nFamily )
     876             :         {
     877             :         case XML_STYLE_FAMILY_TABLE_COLUMN:
     878           0 :             sServiceName = sColumnStyleServiceName;
     879           0 :             break;
     880             :         case XML_STYLE_FAMILY_TABLE_ROW:
     881           0 :             sServiceName = sRowStyleServiceName;
     882           0 :             break;
     883             :         case XML_STYLE_FAMILY_TABLE_CELL:
     884         176 :             sServiceName = sCellStyleServiceName;
     885         176 :             break;
     886             :         case XML_STYLE_FAMILY_TABLE_TABLE:
     887           0 :             sServiceName = sTableStyleServiceName;
     888           0 :             break;
     889             :         }
     890             :     }
     891         176 :     return sServiceName;
     892             : }
     893             : 
     894        4690 : sal_Int32 XMLTableStylesContext::GetIndex(const sal_Int16 nContextID)
     895             : {
     896        4690 :     if (nContextID == CTF_SC_CELLSTYLE)
     897             :     {
     898        3050 :         if (nCellStyleIndex == -1)
     899             :             nCellStyleIndex =
     900         414 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
     901        3050 :         return nCellStyleIndex;
     902             :     }
     903        1640 :     else if (nContextID == CTF_SC_NUMBERFORMAT)
     904             :     {
     905        1070 :         if (nNumberFormatIndex == -1)
     906             :             nNumberFormatIndex =
     907         366 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
     908        1070 :         return nNumberFormatIndex;
     909             :     }
     910         570 :     else if (nContextID == CTF_SC_IMPORT_MAP)
     911             :     {
     912           0 :         if (nConditionalFormatIndex == -1)
     913             :             nConditionalFormatIndex =
     914           0 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_CELL)->getPropertySetMapper()->FindEntryIndex(nContextID);
     915           0 :         return nConditionalFormatIndex;
     916             :     }
     917         570 :     else if (nContextID == CTF_SC_MASTERPAGENAME)
     918             :     {
     919         570 :         if (nMasterPageNameIndex == -1)
     920             :                 nMasterPageNameIndex =
     921         316 :                 GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
     922         570 :         return nMasterPageNameIndex;
     923             :     }
     924             :     else
     925           0 :         return -1;
     926             : }
     927             : 
     928           0 : TYPEINIT1( ScXMLMasterStylesContext, SvXMLStylesContext );
     929             : 
     930        1468 : bool ScXMLMasterStylesContext::InsertStyleFamily( sal_uInt16 ) const
     931             : {
     932        1468 :     return true;
     933             : }
     934             : 
     935         322 : ScXMLMasterStylesContext::ScXMLMasterStylesContext(
     936             :         SvXMLImport& rImport,
     937             :         sal_uInt16 nPrfx, const OUString& rLName,
     938             :         const uno::Reference< XAttributeList > & xAttrList ) :
     939         322 :     SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList )
     940             : {
     941         322 : }
     942             : 
     943         644 : ScXMLMasterStylesContext::~ScXMLMasterStylesContext()
     944             : {
     945         644 : }
     946             : 
     947         734 : SvXMLStyleContext *ScXMLMasterStylesContext::CreateStyleChildContext(
     948             :         sal_uInt16 nPrefix,
     949             :         const OUString& rLocalName,
     950             :         const uno::Reference< XAttributeList > & xAttrList )
     951             : {
     952         734 :     SvXMLStyleContext *pContext(0);
     953             : 
     954        1468 :     if( (XML_NAMESPACE_STYLE == nPrefix) &&
     955        1468 :         IsXMLToken(rLocalName, XML_MASTER_PAGE) &&
     956         734 :          InsertStyleFamily( XML_STYLE_FAMILY_MASTER_PAGE ) )
     957             :         pContext = new ScMasterPageContext(
     958         734 :                         GetImport(), nPrefix, rLocalName, xAttrList,
     959         734 :                         !GetImport().GetTextImport()->IsInsertMode() );
     960             : 
     961             :     // any other style will be ignored here!
     962             : 
     963         734 :     return pContext;
     964             : }
     965             : 
     966           0 : SvXMLStyleContext *ScXMLMasterStylesContext::CreateStyleStyleChildContext(
     967             :         sal_uInt16 /* nFamily */,
     968             :         sal_uInt16 /* nPrefix */,
     969             :         const OUString& /* rLocalName */,
     970             :         const uno::Reference< XAttributeList > & /* xAttrList */ )
     971             : {
     972           0 :     return 0;
     973             : }
     974             : 
     975         322 : void ScXMLMasterStylesContext::EndElement()
     976             : {
     977         322 :     FinishStyles(true);
     978         322 : }
     979             : 
     980           0 : TYPEINIT1( ScMasterPageContext, XMLTextMasterPageContext );
     981             : 
     982         734 : ScMasterPageContext::ScMasterPageContext( SvXMLImport& rImport,
     983             :         sal_uInt16 nPrfx, const OUString& rLName,
     984             :         const uno::Reference< XAttributeList > & xAttrList,
     985             :         bool bOverwrite ) :
     986             :     XMLTextMasterPageContext( rImport, nPrfx, rLName, xAttrList, bOverwrite ),
     987             :     bContainsRightHeader(false),
     988         734 :     bContainsRightFooter(false)
     989             : {
     990         734 : }
     991             : 
     992        1468 : ScMasterPageContext::~ScMasterPageContext()
     993             : {
     994        1468 : }
     995             : 
     996        2244 : SvXMLImportContext *ScMasterPageContext::CreateChildContext(
     997             :         sal_uInt16 nPrefix,
     998             :         const OUString& rLocalName,
     999             :         const uno::Reference< XAttributeList > & xAttrList )
    1000             : {
    1001        2244 :     return XMLTextMasterPageContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
    1002             : }
    1003             : 
    1004        2244 : SvXMLImportContext *ScMasterPageContext::CreateHeaderFooterContext(
    1005             :             sal_uInt16 nPrefix,
    1006             :             const OUString& rLocalName,
    1007             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
    1008             :             const bool bFooter,
    1009             :             const bool bLeft,
    1010             :             const bool /*bFirst*/ )
    1011             : {
    1012        2244 :     if (!bLeft)
    1013             :     {
    1014        1152 :         if (bFooter)
    1015         576 :             bContainsRightFooter = true;
    1016             :         else
    1017         576 :             bContainsRightHeader = true;
    1018             :     }
    1019        2244 :     if (!xPropSet.is())
    1020         576 :         xPropSet.set(GetStyle(), UNO_QUERY );
    1021        2244 :     return new XMLTableHeaderFooterContext( GetImport(),
    1022             :                                                 nPrefix, rLocalName,
    1023             :                                                 xAttrList,
    1024             :                                                 xPropSet,
    1025        2244 :                                                 bFooter, bLeft );
    1026             : }
    1027             : 
    1028         316 : void ScMasterPageContext::ClearContent(const OUString& rContent)
    1029             : {
    1030         316 :     if (!xPropSet.is())
    1031         158 :         xPropSet.set(GetStyle(), UNO_QUERY );
    1032             : 
    1033         316 :     if (xPropSet.is())
    1034             :     {
    1035         316 :         uno::Reference < sheet::XHeaderFooterContent > xHeaderFooterContent(xPropSet->getPropertyValue( rContent ), uno::UNO_QUERY);
    1036         316 :         if (xHeaderFooterContent.is())
    1037             :         {
    1038         316 :             xHeaderFooterContent->getLeftText()->setString(sEmpty);
    1039         316 :             xHeaderFooterContent->getCenterText()->setString(sEmpty);
    1040         316 :             xHeaderFooterContent->getRightText()->setString(sEmpty);
    1041         316 :             xPropSet->setPropertyValue( rContent, uno::makeAny(xHeaderFooterContent) );
    1042         316 :         }
    1043             :     }
    1044         316 : }
    1045             : 
    1046         734 : void ScMasterPageContext::Finish( bool bOverwrite )
    1047             : {
    1048         734 :     XMLTextMasterPageContext::Finish(bOverwrite);
    1049         734 :     if (!bContainsRightFooter)
    1050         158 :         ClearContent(OUString(SC_UNO_PAGE_RIGHTFTRCON));
    1051         734 :     if (!bContainsRightHeader)
    1052         158 :         ClearContent(OUString(SC_UNO_PAGE_RIGHTHDRCON));
    1053         734 : }
    1054             : 
    1055        1352 : ScCellTextStyleContext::ScCellTextStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
    1056             :             const OUString& rLName, const uno::Reference<xml::sax::XAttributeList> & xAttrList,
    1057             :             SvXMLStylesContext& rStyles, sal_uInt16 nFamily, bool bDefaultStyle ) :
    1058             :     XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ),
    1059        1352 :     nLastSheet(-1)
    1060             : {
    1061        1352 : }
    1062             : 
    1063        2704 : ScCellTextStyleContext::~ScCellTextStyleContext()
    1064             : {
    1065        2704 : }
    1066             : 
    1067         494 : void ScCellTextStyleContext::FillPropertySet( const uno::Reference<beans::XPropertySet>& xPropSet )
    1068             : {
    1069         494 :     XMLTextStyleContext::FillPropertySet( xPropSet );
    1070             : 
    1071         494 :     ScXMLImport& rXMLImport = GetScImport();
    1072             : 
    1073         494 :     ScCellTextCursor* pCellImp = ScCellTextCursor::getImplementation( xPropSet );
    1074         494 :     if (pCellImp)
    1075             :     {
    1076           0 :         ScAddress aPos = pCellImp->GetCellObj().GetPosition();
    1077           0 :         if ( aPos.Tab() != nLastSheet )
    1078             :         {
    1079           0 :             ESelection aSel = pCellImp->GetSelection();
    1080             : 
    1081           0 :             ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
    1082           0 :             pSheetData->AddTextStyle( GetName(), aPos, aSel );
    1083             : 
    1084           0 :             nLastSheet = aPos.Tab();
    1085             :         }
    1086             :     }
    1087         494 :     else if ( rXMLImport.GetTables().GetCurrentSheet() != nLastSheet )
    1088             :     {
    1089         434 :         ScDrawTextCursor* pDrawImp = ScDrawTextCursor::getImplementation( xPropSet );
    1090         434 :         if (pDrawImp)
    1091             :         {
    1092          34 :             XMLTableShapeImportHelper* pTableShapeImport = static_cast<XMLTableShapeImportHelper*>(GetScImport().GetShapeImport().get());
    1093          34 :             ScXMLAnnotationContext* pAnnotationContext = pTableShapeImport->GetAnnotationContext();
    1094          34 :             if (pAnnotationContext)
    1095             :             {
    1096          34 :                 pAnnotationContext->AddContentStyle( GetFamily(), GetName(), pDrawImp->GetSelection() );
    1097          34 :                 nLastSheet = rXMLImport.GetTables().GetCurrentSheet();
    1098             :             }
    1099             :         }
    1100             : 
    1101             :         // if it's a different shape, BlockSheet is called from XMLTableShapeImportHelper::finishShape
    1102             :         // formatted text in page headers/footers can be ignored
    1103             :     }
    1104         722 : }
    1105             : 
    1106             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10