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

Generated by: LCOV version 1.10