LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - xmlstyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 376 392 95.9 %
Date: 2013-07-09 Functions: 52 62 83.9 %
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 <com/sun/star/xml/sax/SAXParseException.hpp>
      21             : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
      22             : #include <com/sun/star/xml/sax/SAXException.hpp>
      23             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      24             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      25             : #include <com/sun/star/xml/sax/XLocator.hpp>
      26             : #include <com/sun/star/container/XNameContainer.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      29             : #include <com/sun/star/style/XAutoStylesSupplier.hpp>
      30             : #include <com/sun/star/style/XAutoStyleFamily.hpp>
      31             : #include "PageMasterPropMapper.hxx"
      32             : #include <tools/debug.hxx>
      33             : #include <svl/itemset.hxx>
      34             : #include <xmloff/nmspmap.hxx>
      35             : #include "xmloff/xmlnmspe.hxx"
      36             : #include <xmloff/xmltoken.hxx>
      37             : 
      38             : #include <xmloff/families.hxx>
      39             : #include <xmloff/xmlimp.hxx>
      40             : #include <xmloff/xmlnumi.hxx>
      41             : #include <xmloff/xmlimppr.hxx>
      42             : #include <xmloff/xmlstyle.hxx>
      43             : #include <xmloff/txtstyli.hxx>
      44             : #include <xmloff/txtprmap.hxx>
      45             : #include <xmloff/xmlnumfi.hxx>
      46             : #include "XMLChartStyleContext.hxx"
      47             : #include "XMLChartPropertySetMapper.hxx"
      48             : #include <xmloff/XMLShapeStyleContext.hxx>
      49             : #include "FillStyleContext.hxx"
      50             : #include "XMLFootnoteConfigurationImportContext.hxx"
      51             : #include "XMLIndexBibliographyConfigurationContext.hxx"
      52             : #include "XMLLineNumberingImportContext.hxx"
      53             : #include "PageMasterImportContext.hxx"
      54             : #include "PageMasterImportPropMapper.hxx"
      55             : 
      56             : #include <set>
      57             : #include <vector>
      58             : 
      59             : using namespace ::com::sun::star;
      60             : using namespace ::com::sun::star::uno;
      61             : using namespace ::com::sun::star::container;
      62             : using namespace ::com::sun::star::style;
      63             : using namespace ::xmloff::token;
      64             : 
      65             : // ---------------------------------------------------------------------
      66             : 
      67             : static SvXMLTokenMapEntry aStyleStylesElemTokenMap[] =
      68             : {
      69             :     { XML_NAMESPACE_STYLE,  XML_STYLE,          XML_TOK_STYLE_STYLE                },
      70             :     { XML_NAMESPACE_STYLE,  XML_PAGE_LAYOUT,    XML_TOK_STYLE_PAGE_MASTER          },
      71             :     { XML_NAMESPACE_TEXT,   XML_LIST_STYLE,     XML_TOK_TEXT_LIST_STYLE            },
      72             :     { XML_NAMESPACE_TEXT,   XML_OUTLINE_STYLE,  XML_TOK_TEXT_OUTLINE               },
      73             :     { XML_NAMESPACE_STYLE,  XML_DEFAULT_STYLE,  XML_TOK_STYLE_DEFAULT_STYLE        },
      74             :     { XML_NAMESPACE_DRAW,   XML_GRADIENT,       XML_TOK_STYLES_GRADIENTSTYLES      },
      75             :     { XML_NAMESPACE_DRAW,   XML_HATCH,          XML_TOK_STYLES_HATCHSTYLES         },
      76             :     { XML_NAMESPACE_DRAW,   XML_FILL_IMAGE,     XML_TOK_STYLES_BITMAPSTYLES        },
      77             :     { XML_NAMESPACE_DRAW,   XML_OPACITY,        XML_TOK_STYLES_TRANSGRADIENTSTYLES },
      78             :     { XML_NAMESPACE_DRAW,   XML_MARKER,         XML_TOK_STYLES_MARKERSTYLES        },
      79             :     { XML_NAMESPACE_DRAW,   XML_STROKE_DASH,    XML_TOK_STYLES_DASHSTYLES        },
      80             :     { XML_NAMESPACE_TEXT,   XML_NOTES_CONFIGURATION,    XML_TOK_TEXT_NOTE_CONFIG },
      81             :     { XML_NAMESPACE_TEXT,   XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
      82             :     { XML_NAMESPACE_TEXT,   XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
      83             :     { XML_NAMESPACE_STYLE,  XML_DEFAULT_PAGE_LAYOUT,    XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT        },
      84             :     XML_TOKEN_MAP_END
      85             : };
      86             : 
      87        3240 : const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
      88             : {
      89        3240 :     if( !mpStyleStylesElemTokenMap )
      90             :         mpStyleStylesElemTokenMap =
      91         422 :             new SvXMLTokenMap( aStyleStylesElemTokenMap );
      92             : 
      93        3240 :     return *mpStyleStylesElemTokenMap;
      94             : }
      95             : 
      96             : // ---------------------------------------------------------------------
      97             : 
      98        8184 : void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
      99             :                                       const OUString& rLocalName,
     100             :                                       const OUString& rValue )
     101             : {
     102             :     // TODO: use a map here
     103        8184 :     if( XML_NAMESPACE_STYLE == nPrefixKey )
     104             :     {
     105        7304 :         if( IsXMLToken( rLocalName, XML_FAMILY ) )
     106             :         {
     107          71 :             if( IsXMLToken( rValue, XML_PARAGRAPH ) )
     108           0 :                 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
     109          71 :             else if( IsXMLToken( rValue, XML_TEXT ) )
     110           0 :                 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
     111             :         }
     112        7233 :         else if( IsXMLToken( rLocalName, XML_NAME ) )
     113             :         {
     114        5134 :             maName = rValue;
     115             :         }
     116        2099 :         else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
     117             :         {
     118         296 :             maDisplayName = rValue;
     119             :         }
     120        1803 :         else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
     121             :         {
     122        1281 :             maParentName = rValue;
     123             :         }
     124         522 :         else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
     125             :         {
     126          82 :             maFollow = rValue;
     127             :         }
     128         440 :         else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
     129             :         {
     130           0 :             maHelpFile = rValue;
     131             :         }
     132         440 :         else if( IsXMLToken( rLocalName, XML_HELP_ID ) )
     133             :         {
     134           0 :             sal_Int32 nTmp = rValue.toInt32();
     135             :             mnHelpId =
     136             :                 (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX
     137           0 :                                                         : (sal_uInt16)nTmp );
     138             :         }
     139         440 :         else if( IsXMLToken( rLocalName, XML_HIDDEN ) )
     140             :         {
     141           0 :             mbHidden = rValue.toBoolean();
     142             :         }
     143             :     }
     144        8184 : }
     145             : 
     146         740 : TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
     147             : 
     148        5671 : SvXMLStyleContext::SvXMLStyleContext(
     149             :         SvXMLImport& rImp, sal_uInt16 nPrfx,
     150             :         const OUString& rLName,
     151             :         const uno::Reference< xml::sax::XAttributeList >&,
     152             :         sal_uInt16 nFam, sal_Bool bDefault ) :
     153             :     SvXMLImportContext( rImp, nPrfx, rLName ),
     154             :     mbHidden( sal_False ),
     155             :     mnHelpId( UCHAR_MAX ),
     156             :     mnFamily( nFam ),
     157             :     mbValid( sal_True ),
     158             :     mbNew( sal_True ),
     159        5671 :     mbDefaultStyle( bDefault )
     160             : {
     161        5671 : }
     162             : 
     163        5671 : SvXMLStyleContext::~SvXMLStyleContext()
     164             : {
     165        5671 : }
     166             : 
     167           0 : SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
     168             :                                                            const OUString& rLocalName,
     169             :                                                            const uno::Reference< xml::sax::XAttributeList > & )
     170             : {
     171           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     172             : }
     173             : 
     174        5197 : void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     175             : {
     176        5197 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     177       19984 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
     178             :     {
     179       14787 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
     180       29574 :         OUString aLocalName;
     181       14787 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
     182       29574 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     183             : 
     184       14787 :         SetAttribute( nPrefix, aLocalName, rValue );
     185       14787 :     }
     186        5197 : }
     187             : 
     188           0 : void SvXMLStyleContext::SetDefaults()
     189             : {
     190           0 : }
     191             : 
     192         183 : void SvXMLStyleContext::CreateAndInsert( sal_Bool /*bOverwrite*/ )
     193             : {
     194         183 : }
     195             : 
     196        1649 : void SvXMLStyleContext::CreateAndInsertLate( sal_Bool /*bOverwrite*/ )
     197             : {
     198        1649 : }
     199             : 
     200         669 : void SvXMLStyleContext::Finish( sal_Bool /*bOverwrite*/ )
     201             : {
     202         669 : }
     203             : 
     204        5249 : sal_Bool SvXMLStyleContext::IsTransient() const
     205             : {
     206        5249 :     return sal_False;
     207             : }
     208             : 
     209             : // ---------------------------------------------------------------------
     210             : 
     211       15582 : class SvXMLStyleIndex_Impl
     212             : {
     213             :     OUString              sName;
     214             :     sal_uInt16            nFamily;
     215             :     const SvXMLStyleContext *pStyle;
     216             : 
     217             : public:
     218             : 
     219        5812 :     SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
     220             :         sName( rName ),
     221             :         nFamily( nFam ),
     222        5812 :         pStyle ( 0 )
     223             :     {
     224        5812 :     }
     225             : 
     226        9770 :     SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
     227        9770 :         sName( pStl->GetName() ),
     228        9770 :         nFamily( pStl->GetFamily() ),
     229       19540 :         pStyle ( pStl )
     230             :     {
     231        9770 :     }
     232             : 
     233       52248 :     const OUString& GetName() const { return sName; }
     234      140014 :     sal_uInt16 GetFamily() const { return nFamily; }
     235        5137 :     const SvXMLStyleContext *GetStyle() const { return pStyle; }
     236             : };
     237             : 
     238             : struct SvXMLStyleIndexCmp_Impl
     239             : {
     240       39644 :     bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
     241             :     {
     242             :         sal_Int32 nRet;
     243             : 
     244       39644 :         if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
     245        9281 :             nRet = -1;
     246       30363 :         else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
     247        4239 :             nRet = 1;
     248             :         else
     249       26124 :             nRet = r1.GetName().compareTo( r2.GetName() );
     250             : 
     251       39644 :         return nRet < 0;
     252             :     }
     253             : };
     254             : 
     255             : 
     256             : class SvXMLStylesContext_Impl
     257             : {
     258             :     typedef std::vector<SvXMLStyleContext*> StylesType;
     259             :     typedef std::set<SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl> IndicesType;
     260             : 
     261             :     StylesType aStyles;
     262             :     mutable IndicesType* pIndices;
     263             :     bool bAutomaticStyle;
     264             : 
     265             : #ifdef DBG_UTIL
     266             :     mutable sal_uInt32 nIndexCreated;
     267             : #endif
     268             : 
     269        6608 :     void FlushIndex() { delete pIndices; pIndices = 0; }
     270             : 
     271             : public:
     272             :     SvXMLStylesContext_Impl( bool bAuto );
     273             :     ~SvXMLStylesContext_Impl();
     274             : 
     275        2588 :     size_t GetStyleCount() const { return aStyles.size(); }
     276             : 
     277             :     const SvXMLStyleContext *GetStyle( size_t i ) const
     278             :     {
     279             :         return i < aStyles.size() ? aStyles[ i ] : 0;
     280             :     }
     281             : 
     282        8774 :     SvXMLStyleContext *GetStyle( size_t i )
     283             :     {
     284        8774 :         return i < aStyles.size() ? aStyles[ i ] : 0;
     285             :     }
     286             : 
     287             :     inline void AddStyle( SvXMLStyleContext *pStyle );
     288             :     void Clear();
     289             : 
     290             :     const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily,
     291             :                                                     const OUString& rName,
     292             :                                                     sal_Bool bCreateIndex ) const;
     293        2563 :     sal_Bool IsAutomaticStyle() const { return bAutomaticStyle; }
     294             : };
     295             : 
     296         845 : SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) :
     297             :     pIndices( 0 ),
     298         845 :     bAutomaticStyle( bAuto )
     299             : #ifdef DBG_UTIL
     300             : ,   nIndexCreated( 0 )
     301             : #endif
     302         845 : {}
     303             : 
     304        1690 : SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
     305             : {
     306         845 :     delete pIndices;
     307             : 
     308        1001 :     for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
     309             :     {
     310         156 :         SvXMLStyleContext *pStyle = aStyles[ i ];
     311         156 :         pStyle->ReleaseRef();
     312             :     }
     313         845 :     aStyles.clear();
     314         845 : }
     315             : 
     316        5575 : inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
     317             : {
     318        5575 :     aStyles.push_back( pStyle );
     319        5575 :     pStyle->AddRef();
     320             : 
     321        5575 :     FlushIndex();
     322        5575 : }
     323             : 
     324        1033 : void SvXMLStylesContext_Impl::Clear()
     325             : {
     326        1033 :     FlushIndex();
     327             : 
     328        6452 :     for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
     329             :     {
     330        5419 :         SvXMLStyleContext *pStyle = aStyles[ i ];
     331        5419 :         pStyle->ReleaseRef();
     332             :     }
     333        1033 :     aStyles.clear();
     334        1033 : }
     335             : 
     336        7955 : const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( sal_uInt16 nFamily,
     337             :                                                                          const OUString& rName,
     338             :                                                                          sal_Bool bCreateIndex ) const
     339             : {
     340        7955 :     const SvXMLStyleContext *pStyle = 0;
     341             : 
     342        7955 :     if( !pIndices && bCreateIndex && !aStyles.empty() )
     343             :     {
     344             : #ifdef DBG_UTIL
     345             :         DBG_ASSERT( 0==nIndexCreated,
     346             :                     "Performance warning: sdbcx::Index created multiple times" );
     347             : #endif
     348         481 :         pIndices = new IndicesType(aStyles.begin(), aStyles.end());
     349             :         SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff", "Here is a duplicate Style");
     350             : #ifdef DBG_UTIL
     351             :         ++nIndexCreated;
     352             : #endif
     353             :     }
     354             : 
     355        7955 :     if( pIndices )
     356             :     {
     357        5812 :         SvXMLStyleIndex_Impl aIndex( nFamily, rName );
     358        5812 :         IndicesType::iterator aFind = pIndices->find(aIndex);
     359        5812 :         if( aFind != pIndices->end() )
     360        5137 :             pStyle = aFind->GetStyle();
     361             :     }
     362             :     else
     363             :     {
     364       24512 :         for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
     365             :         {
     366       22369 :             const SvXMLStyleContext *pS = aStyles[ i ];
     367       30766 :             if( pS->GetFamily() == nFamily &&
     368        8397 :                 pS->GetName() == rName )
     369        2051 :                 pStyle = pS;
     370             :         }
     371             :     }
     372        7955 :     return pStyle;
     373             : }
     374             : 
     375             : // ---------------------------------------------------------------------
     376             : 
     377           0 : TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
     378             : 
     379        2588 : sal_uInt32 SvXMLStylesContext::GetStyleCount() const
     380             : {
     381        2588 :     return mpImpl->GetStyleCount();
     382             : }
     383             : 
     384        6924 : SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
     385             : {
     386        6924 :     return mpImpl->GetStyle( i );
     387             : }
     388             : 
     389        1850 : const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
     390             : {
     391        1850 :     return mpImpl->GetStyle( i );
     392             : }
     393             : 
     394        2563 : sal_Bool SvXMLStylesContext::IsAutomaticStyle() const
     395             : {
     396        2563 :     return mpImpl->IsAutomaticStyle();
     397             : }
     398             : 
     399        3810 : SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix,
     400             :                                                                 const OUString& rLocalName,
     401             :                                                                 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     402             : {
     403        3810 :     SvXMLStyleContext *pStyle = NULL;
     404             : 
     405        3810 :     if(GetImport().GetDataStylesImport())
     406             :     {
     407        3474 :         pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
     408        6948 :                                                rLocalName, xAttrList, *this);
     409             :     }
     410             : 
     411        3810 :     if (!pStyle)
     412             :     {
     413        3240 :         const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
     414        3240 :         sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
     415        3240 :         switch( nToken )
     416             :         {
     417             :             case XML_TOK_STYLE_STYLE:
     418             :             case XML_TOK_STYLE_DEFAULT_STYLE:
     419             :             {
     420        2697 :                 sal_uInt16 nFamily = 0;
     421        2697 :                 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     422        5331 :                 for( sal_Int16 i=0; i < nAttrCount; i++ )
     423             :                 {
     424        5331 :                     const OUString& rAttrName = xAttrList->getNameByIndex( i );
     425        7965 :                     OUString aLocalName;
     426             :                     sal_uInt16 nPrefix =
     427        5331 :                         GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     428        5331 :                                                                     &aLocalName );
     429       10662 :                     if( XML_NAMESPACE_STYLE == nPrefix &&
     430        5331 :                         IsXMLToken( aLocalName, XML_FAMILY ) )
     431             :                     {
     432        2697 :                         const OUString& rValue = xAttrList->getValueByIndex( i );
     433        2697 :                         nFamily = GetFamily( rValue );
     434        2697 :                         break;
     435             :                     }
     436        2634 :                 }
     437             :                 pStyle = XML_TOK_STYLE_STYLE==nToken
     438             :                     ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
     439        2396 :                                                     rLocalName, xAttrList )
     440             :                     : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
     441        5093 :                                                     rLocalName, xAttrList );
     442             :             }
     443        2697 :             break;
     444             :             case XML_TOK_STYLE_PAGE_MASTER:
     445             :             case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
     446             :             {
     447             :                 //there is not page family in ODF now, so I specify one for it
     448             :                 sal_Bool bDefaultStyle  = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken
     449         228 :                     ? sal_True: sal_False;
     450         228 :                 pStyle = new PageStyleContext( GetImport(), p_nPrefix,
     451         228 :                                                     rLocalName, xAttrList, *this, bDefaultStyle );
     452             :             }
     453         228 :             break;
     454             :             case XML_TOK_TEXT_LIST_STYLE:
     455          45 :                 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
     456          45 :                                                     rLocalName, xAttrList );
     457          45 :                 break;
     458             :             case XML_TOK_TEXT_OUTLINE:
     459          51 :                 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
     460          51 :                                                     rLocalName, xAttrList, sal_True );
     461          51 :                 break;
     462             :             case XML_TOK_TEXT_NOTE_CONFIG:
     463         102 :                 pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
     464             :                                                                    p_nPrefix,
     465             :                                                                    rLocalName,
     466         102 :                                                                    xAttrList);
     467         102 :                 break;
     468             : 
     469             :             case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
     470             :                 pStyle = new XMLIndexBibliographyConfigurationContext(
     471           2 :                     GetImport(), p_nPrefix, rLocalName, xAttrList);
     472           2 :                 break;
     473             : 
     474             :             case XML_TOK_TEXT_LINENUMBERING_CONFIG:
     475             :                 pStyle = new XMLLineNumberingImportContext(
     476          51 :                     GetImport(), p_nPrefix, rLocalName, xAttrList);
     477          51 :                 break;
     478             : 
     479             :             //
     480             :             // FillStyles
     481             :             //
     482             :             case XML_TOK_STYLES_GRADIENTSTYLES:
     483             :             {
     484          18 :                 pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
     485          18 :                 break;
     486             :             }
     487             :             case XML_TOK_STYLES_HATCHSTYLES:
     488             :             {
     489          14 :                 pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
     490          14 :                 break;
     491             :             }
     492             :             case XML_TOK_STYLES_BITMAPSTYLES:
     493             :             {
     494           6 :                 pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
     495           6 :                 break;
     496             :             }
     497             :             case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
     498             :             {
     499           6 :                 pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
     500           6 :                 break;
     501             :             }
     502             :             case XML_TOK_STYLES_MARKERSTYLES:
     503             :             {
     504          19 :                 pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
     505          19 :                 break;
     506             :             }
     507             :             case XML_TOK_STYLES_DASHSTYLES:
     508             :             {
     509           1 :                 pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
     510           1 :                 break;
     511             :             }
     512             :         }
     513             :     }
     514             : 
     515        3810 :     return pStyle;
     516             : }
     517             : 
     518        1700 : SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
     519             :         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
     520             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     521             : {
     522        1700 :     SvXMLStyleContext *pStyle = 0;
     523             : 
     524        1700 :     switch( nFamily )
     525             :     {
     526             :         case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
     527             :         case XML_STYLE_FAMILY_TEXT_TEXT:
     528             :         case XML_STYLE_FAMILY_TEXT_SECTION:
     529         168 :             pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
     530         168 :                                               xAttrList, *this, nFamily );
     531         168 :             break;
     532             : 
     533             :         case XML_STYLE_FAMILY_TEXT_RUBY:
     534           7 :             pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
     535           7 :                                               xAttrList, *this, nFamily );
     536           7 :             break;
     537             :         case XML_STYLE_FAMILY_SCH_CHART_ID:
     538         195 :             pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
     539         195 :                                                xAttrList, *this, nFamily );
     540         195 :             break;
     541             : 
     542             :         case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
     543             :         case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
     544             :         case XML_STYLE_FAMILY_SD_POOL_ID:
     545         259 :             pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
     546         259 :                                                xAttrList, *this, nFamily );
     547             :     }
     548             : 
     549        1700 :     return pStyle;
     550             : }
     551             : 
     552          92 : SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
     553             :         sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
     554             :         const uno::Reference< xml::sax::XAttributeList > & )
     555             : {
     556          92 :     return 0;
     557             : }
     558             : 
     559             : 
     560        2983 : sal_Bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
     561             : {
     562        2983 :     return sal_True;
     563             : }
     564             : 
     565        2697 : sal_uInt16 SvXMLStylesContext::GetFamily( const OUString& rValue ) const
     566             : {
     567        2697 :     sal_uInt16 nFamily = 0U;
     568        2697 :     if( IsXMLToken( rValue, XML_PARAGRAPH ) )
     569             :     {
     570         628 :         nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
     571             :     }
     572        2069 :     else if( IsXMLToken( rValue, XML_TEXT ) )
     573             :     {
     574         146 :         nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
     575             :     }
     576        1923 :     else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
     577             :     {
     578           0 :         nFamily = XML_STYLE_FAMILY_DATA_STYLE;
     579             :     }
     580        1923 :     else if ( IsXMLToken( rValue, XML_SECTION ) )
     581             :     {
     582          10 :         nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
     583             :     }
     584        1913 :     else if( IsXMLToken( rValue, XML_TABLE ) )
     585             :     {
     586         132 :         nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
     587             :     }
     588        1781 :     else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
     589         228 :         nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
     590        1553 :     else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
     591         193 :         nFamily = XML_STYLE_FAMILY_TABLE_ROW;
     592        1360 :     else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
     593         756 :         nFamily = XML_STYLE_FAMILY_TABLE_CELL;
     594         604 :     else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
     595             :     {
     596         304 :         nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
     597             :     }
     598         300 :     else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
     599             :     {
     600          76 :         nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
     601             :     }
     602         224 :     else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
     603             :     {
     604           0 :         nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
     605             :     }
     606         224 :     else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
     607             :     {
     608          22 :         nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
     609             :     }
     610         202 :     else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
     611             :     {
     612         195 :         nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
     613             :     }
     614           7 :     else if ( IsXMLToken( rValue, XML_RUBY ) )
     615             :     {
     616           7 :         nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
     617             :     }
     618             : 
     619        2697 :     return nFamily;
     620             : }
     621             : 
     622       13154 : UniReference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
     623             :                         sal_uInt16 nFamily ) const
     624             : {
     625       13154 :     UniReference < SvXMLImportPropertyMapper > xMapper;
     626             : 
     627       13154 :     switch( nFamily )
     628             :     {
     629             :     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
     630        2357 :         if( !mxParaImpPropMapper.is() )
     631             :         {
     632         108 :             SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
     633         108 :             pThis->mxParaImpPropMapper =
     634         108 :                 pThis->GetImport().GetTextImport()
     635         216 :                      ->GetParaImportPropertySetMapper();
     636             :         }
     637        2357 :         xMapper = mxParaImpPropMapper;
     638        2357 :         break;
     639             :     case XML_STYLE_FAMILY_TEXT_TEXT:
     640         448 :         if( !mxTextImpPropMapper.is() )
     641             :         {
     642          47 :             SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
     643          47 :             pThis->mxTextImpPropMapper =
     644          47 :                 pThis->GetImport().GetTextImport()
     645          94 :                      ->GetTextImportPropertySetMapper();
     646             :         }
     647         448 :         xMapper = mxTextImpPropMapper;
     648         448 :         break;
     649             : 
     650             :     case XML_STYLE_FAMILY_TEXT_SECTION:
     651             :         // don't cache section mapper, as it's rarely used
     652             :         // *sigh*, cast to non-const, because this is a const method,
     653             :         // but SvXMLImport::GetTextImport() isn't.
     654          44 :         xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
     655          44 :             GetSectionImportPropertySetMapper();
     656          44 :         break;
     657             : 
     658             :     case XML_STYLE_FAMILY_TEXT_RUBY:
     659             :         // don't cache section mapper, as it's rarely used
     660             :         // *sigh*, cast to non-const, because this is a const method,
     661             :         // but SvXMLImport::GetTextImport() isn't.
     662          19 :         xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
     663          19 :             GetRubyImportPropertySetMapper();
     664          19 :         break;
     665             : 
     666             :     case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
     667             :     case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
     668             :     case XML_STYLE_FAMILY_SD_POOL_ID:
     669        1716 :         if(!mxShapeImpPropMapper.is())
     670             :         {
     671         120 :             UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
     672         120 :             ((SvXMLStylesContext*)this)->mxShapeImpPropMapper =
     673         120 :                 aImpHelper->GetPropertySetMapper();
     674             :         }
     675        1716 :         xMapper = mxShapeImpPropMapper;
     676        1716 :         break;
     677             :     case XML_STYLE_FAMILY_SCH_CHART_ID:
     678         968 :         if( ! mxChartImpPropMapper.is() )
     679             :         {
     680          22 :             XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper();
     681          22 :             mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
     682             :         }
     683         968 :         xMapper = mxChartImpPropMapper;
     684         968 :         break;
     685             :     case XML_STYLE_FAMILY_PAGE_MASTER:
     686         902 :         if( ! mxPageImpPropMapper.is() )
     687             :         {
     688             :             XMLPropertySetMapper *pPropMapper =
     689         130 :                 new XMLPageMasterPropSetMapper();
     690         520 :             mxPageImpPropMapper =
     691             :                 new PageMasterImportPropertyMapper( pPropMapper,
     692         390 :                                     ((SvXMLStylesContext*)this)->GetImport() );
     693             :         }
     694         902 :         xMapper = mxPageImpPropMapper;
     695         902 :         break;
     696             :     }
     697             : 
     698       13154 :     return xMapper;
     699             : }
     700             : 
     701         129 : Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
     702             : {
     703         129 :     Reference < XAutoStyleFamily > xAutoStyles;
     704         129 :     if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
     705             :     {
     706         129 :         bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
     707         129 :         OUString sName;
     708         129 :         if( !bPara && mxTextAutoStyles.is() )
     709           5 :             xAutoStyles = mxTextAutoStyles;
     710         124 :         else if( bPara && mxParaAutoStyles.is() )
     711          76 :             xAutoStyles = mxParaAutoStyles;
     712             :         else
     713             :         {
     714          48 :             sName = bPara ? OUString( "ParagraphStyles" ): OUString( "CharacterStyles" );
     715          48 :             Reference< XAutoStylesSupplier > xAutoStylesSupp(   GetImport().GetModel(), UNO_QUERY );
     716          96 :             Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
     717          48 :             if (xAutoStyleFamilies->hasByName(sName))
     718             :             {
     719          48 :                 Any aAny = xAutoStyleFamilies->getByName( sName );
     720          48 :                 xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
     721          48 :                 if( bPara )
     722          31 :                     ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles;
     723             :                 else
     724          17 :                     ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles;
     725          48 :             }
     726         129 :         }
     727             :     }
     728         129 :     return xAutoStyles;
     729             : }
     730             : 
     731        1918 : Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
     732             :                                                 sal_uInt16 nFamily ) const
     733             : {
     734        1918 :     Reference < XNameContainer > xStyles;
     735        3836 :     OUString sName;
     736        1918 :     switch( nFamily )
     737             :     {
     738             :     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
     739         866 :         if( mxParaStyles.is() )
     740         815 :             xStyles = mxParaStyles;
     741             :         else
     742          51 :             sName = "ParagraphStyles";
     743         866 :         break;
     744             : 
     745             :     case XML_STYLE_FAMILY_TEXT_TEXT:
     746         196 :         if( mxTextStyles.is() )
     747         175 :             xStyles = mxTextStyles;
     748             :         else
     749          21 :             sName = "CharacterStyles";
     750         196 :         break;
     751             :     }
     752        1918 :     if( !xStyles.is() && !sName.isEmpty() )
     753             :     {
     754             :         Reference< XStyleFamiliesSupplier > xFamiliesSupp(
     755          72 :                                         GetImport().GetModel(), UNO_QUERY );
     756          72 :         if ( xFamiliesSupp.is() )
     757             :         {
     758          72 :             Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
     759          72 :             if (xFamilies->hasByName(sName))
     760             :             {
     761          72 :                 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
     762             : 
     763          72 :                 switch( nFamily )
     764             :                 {
     765             :                 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
     766          51 :                     ((SvXMLStylesContext *)this)->mxParaStyles = xStyles;
     767          51 :                     break;
     768             : 
     769             :                 case XML_STYLE_FAMILY_TEXT_TEXT:
     770          21 :                     ((SvXMLStylesContext *)this)->mxTextStyles = xStyles;
     771          21 :                     break;
     772             :                 }
     773          72 :             }
     774          72 :         }
     775             :     }
     776             : 
     777        3836 :     return xStyles;
     778             : }
     779             : 
     780         172 : OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
     781             : {
     782         172 :     OUString sServiceName;
     783         172 :     switch( nFamily )
     784             :     {
     785             :     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
     786          49 :         sServiceName = msParaStyleServiceName;
     787          49 :         break;
     788             :     case XML_STYLE_FAMILY_TEXT_TEXT:
     789          70 :         sServiceName = msTextStyleServiceName;
     790          70 :         break;
     791             :     }
     792             : 
     793         172 :     return sServiceName;
     794             : }
     795             : 
     796             : 
     797         845 : SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
     798             :                                         const OUString& rLName,
     799             :                                         const uno::Reference< xml::sax::XAttributeList > &, sal_Bool bAuto ) :
     800             :     SvXMLImportContext( rImport, nPrfx, rLName ),
     801             :     msParaStyleServiceName( "com.sun.star.style.ParagraphStyle" ),
     802             :     msTextStyleServiceName( "com.sun.star.style.CharacterStyle" ),
     803         845 :     mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
     804        1690 :     mpStyleStylesElemTokenMap( 0 )
     805             : {
     806         845 : }
     807             : 
     808             : 
     809        1734 : SvXMLStylesContext::~SvXMLStylesContext()
     810             : {
     811         845 :     delete mpStyleStylesElemTokenMap;
     812         845 :     delete mpImpl;
     813         889 : }
     814             : 
     815        5313 : SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
     816             :                                                             const OUString& rLocalName,
     817             :                                                             const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     818             : {
     819        5313 :     SvXMLImportContext *pContext = 0;
     820             : 
     821             :     SvXMLStyleContext *pStyle =
     822        5313 :         CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
     823        5313 :     if( pStyle )
     824             :     {
     825        5313 :         if( !pStyle->IsTransient() )
     826        5249 :             mpImpl->AddStyle( pStyle );
     827        5313 :         pContext = pStyle;
     828             :     }
     829             :     else
     830             :     {
     831           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix,
     832           0 :                                            rLocalName );
     833             :     }
     834             : 
     835        5313 :     return pContext;
     836             : }
     837             : 
     838         542 : void SvXMLStylesContext::EndElement()
     839             : {
     840         542 : }
     841             : 
     842         326 : void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
     843             : {
     844         326 :     mpImpl->AddStyle( &rNew );
     845         326 : }
     846             : 
     847        1033 : void SvXMLStylesContext::Clear()
     848             : {
     849        1033 :     mpImpl->Clear();
     850        1033 : }
     851             : 
     852         103 : void SvXMLStylesContext::CopyAutoStylesToDoc()
     853             : {
     854         103 :     sal_uInt32 nCount = GetStyleCount();
     855             :     sal_uInt32 i;
     856         406 :     for( i = 0; i < nCount; i++ )
     857             :     {
     858         303 :         SvXMLStyleContext *pStyle = GetStyle( i );
     859         736 :         if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
     860         463 :             pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH  &&
     861         182 :             pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
     862         152 :             continue;
     863         151 :         pStyle->CreateAndInsert( sal_False );
     864             :     }
     865         103 : }
     866             : 
     867         128 : void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite,
     868             :                                           sal_Bool bFinish )
     869             : {
     870             :     // pass 1: create text, paragraph and frame styles
     871         128 :     sal_uInt32 nCount = GetStyleCount();
     872             :     sal_uInt32 i;
     873             : 
     874        2155 :     for( i = 0; i < nCount; i++ )
     875             :     {
     876        2027 :         SvXMLStyleContext *pStyle = GetStyle( i );
     877        2027 :         if( !pStyle )
     878           0 :             continue;
     879             : 
     880        2027 :         if (pStyle->IsDefaultStyle())
     881         297 :             pStyle->SetDefaults();
     882        1730 :         else if( InsertStyleFamily( pStyle->GetFamily() ) )
     883        1730 :             pStyle->CreateAndInsert( bOverwrite );
     884             :     }
     885             : 
     886             :     // pass 2: create list styles (they require char styles)
     887        2155 :     for( i=0; i<nCount; i++ )
     888             :     {
     889        2027 :         SvXMLStyleContext *pStyle = GetStyle( i );
     890        2027 :         if( !pStyle || pStyle->IsDefaultStyle())
     891         297 :             continue;
     892             : 
     893        1730 :         if( InsertStyleFamily( pStyle->GetFamily() ) )
     894        1730 :             pStyle->CreateAndInsertLate( bOverwrite );
     895             :     }
     896             : 
     897             :     // pass3: finish creation of styles
     898         128 :     if( bFinish )
     899          76 :         FinishStyles( bOverwrite );
     900         128 : }
     901             : 
     902         269 : void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite )
     903             : {
     904         269 :     sal_uInt32 nCount = GetStyleCount();
     905        2682 :     for( sal_uInt32 i=0; i<nCount; i++ )
     906             :     {
     907        2413 :         SvXMLStyleContext *pStyle = GetStyle( i );
     908        2413 :         if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
     909         297 :             continue;
     910             : 
     911        2116 :         if( InsertStyleFamily( pStyle->GetFamily() ) )
     912        2116 :             pStyle->Finish( bOverwrite );
     913             :     }
     914         269 : }
     915             : 
     916             : 
     917        7955 : const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
     918             :                                   sal_uInt16 nFamily,
     919             :                                   const OUString& rName,
     920             :                                   sal_Bool bCreateIndex ) const
     921             : {
     922        7955 :     return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
     923             : }
     924             : 
     925             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10