LCOV - code coverage report
Current view: top level - xmloff/source/style - xmlaustp.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 122 155 78.7 %
Date: 2014-11-03 Functions: 18 20 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/container/XIndexReplace.hpp>
      21             : #include <tools/debug.hxx>
      22             : #include "impastpl.hxx"
      23             : #include <xmloff/xmlaustp.hxx>
      24             : #include <xmloff/families.hxx>
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <xmloff/xmlexp.hxx>
      28             : #include <xmloff/xmlprhdl.hxx>
      29             : #include <xmloff/XMLTextListAutoStylePool.hxx>
      30             : 
      31             : #include <xmloff/PageMasterStyleMap.hxx>
      32             : #include "PageMasterExportPropMapper.hxx"
      33             : #include "XMLBackgroundImageExport.hxx"
      34             : 
      35             : 
      36             : using namespace ::std;
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::xmloff::token;
      40             : 
      41             : 
      42             : namespace
      43             : {
      44           0 :     static void lcl_exportDataStyle( SvXMLExport& _rExport, const rtl::Reference< XMLPropertySetMapper >& _rxMapper,
      45             :         const XMLPropertyState& _rProperty )
      46             :     {
      47             :         DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" );
      48             :         // obtain the data style name
      49           0 :         OUString sDataStyleName;
      50           0 :         _rProperty.maValue >>= sDataStyleName;
      51             :         DBG_ASSERT( !sDataStyleName.isEmpty(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" );
      52             : 
      53             :         // add the attribute
      54             :         _rExport.AddAttribute(
      55           0 :             _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
      56           0 :             _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
      57           0 :             sDataStyleName );
      58           0 :     }
      59             : }
      60             : 
      61        7074 : void SvXMLAutoStylePoolP::exportStyleAttributes(
      62             :         SvXMLAttributeList&,
      63             :         sal_Int32 nFamily,
      64             :         const vector< XMLPropertyState >& rProperties,
      65             :         const SvXMLExportPropertyMapper& rPropExp,
      66             :         const SvXMLUnitConverter&,
      67             :         const SvXMLNamespaceMap&
      68             :         ) const
      69             : {
      70        7074 :     if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
      71             :     {   // it's a control-related style
      72           0 :         rtl::Reference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
      73             : 
      74           0 :         for (   vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
      75           0 :                 pProp != rProperties.end();
      76             :                 ++pProp
      77             :             )
      78             :         {
      79           0 :             if  (   ( pProp->mnIndex > -1 )
      80           0 :                 &&  ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
      81             :                 )
      82             :             {   // it's the data-style for a grid column
      83           0 :                 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
      84             :             }
      85           0 :         }
      86             :     }
      87             : 
      88        7074 :     if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
      89             :     {   // it's a graphics style
      90          82 :         rtl::Reference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
      91             :         DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!");
      92             : 
      93          82 :         bool bFoundControlShapeDataStyle = false;
      94          82 :         bool bFoundNumberingRulesName = false;
      95             : 
      96        3036 :         for (   vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
      97        2024 :                 pProp != rProperties.end();
      98             :                 ++pProp
      99             :             )
     100             :         {
     101         930 :             if (pProp->mnIndex > -1)
     102             :             {   // it's a valid property
     103         560 :                 switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
     104             :                 {
     105             :                 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
     106             :                     {   // it's the control shape data style property
     107             : 
     108           0 :                         if (bFoundControlShapeDataStyle)
     109             :                         {
     110             :                             OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
     111             :                             // already added the attribute for the first occurrence
     112           0 :                             break;
     113             :                         }
     114             : 
     115           0 :                         lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
     116             : 
     117             :                         // check if there is another property with the special context id we're handling here
     118           0 :                         bFoundControlShapeDataStyle = true;
     119           0 :                         break;
     120             :                     }
     121             :                 case CTF_SD_NUMBERINGRULES_NAME:
     122             :                     {
     123           0 :                         if (bFoundNumberingRulesName)
     124             :                         {
     125             :                             OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
     126             :                             // already added the attribute for the first occurrence
     127           0 :                             break;
     128             :                         }
     129             : 
     130           0 :                         uno::Reference< container::XIndexReplace > xNumRule;
     131           0 :                         pProp->maValue >>= xNumRule;
     132           0 :                         if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
     133             :                         {
     134           0 :                             const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
     135             : 
     136           0 :                             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
     137             :                         }
     138             : 
     139           0 :                         bFoundNumberingRulesName = true;
     140           0 :                         break;
     141             :                     }
     142             :                 }
     143             :             }
     144          82 :         }
     145             :     }
     146             : 
     147        7074 :     if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
     148             :     {
     149        5284 :         for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp )
     150             :         {
     151        5114 :             if (pProp->mnIndex > -1)
     152             :             {
     153        3138 :                 rtl::Reference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
     154        3138 :                 sal_Int32 nIndex = pProp->mnIndex;
     155        3138 :                 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
     156        3138 :                 switch( nContextID )
     157             :                 {
     158             :                     case CTF_PM_PAGEUSAGE:
     159             :                     {
     160          70 :                         OUString sValue;
     161          70 :                         const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
     162         140 :                         if( pPropHdl &&
     163          70 :                             pPropHdl->exportXML( sValue, pProp->maValue,
     164         210 :                                                  GetExport().GetMM100UnitConverter() ) &&
     165          70 :                             ( ! IsXMLToken( sValue, XML_ALL ) ) )
     166             :                         {
     167           8 :                             GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
     168          70 :                         }
     169             :                     }
     170          70 :                     break;
     171        3138 :                 }
     172             :             }
     173             :         }
     174             :     }
     175        7074 : }
     176             : 
     177        7074 : void SvXMLAutoStylePoolP::exportStyleContent(
     178             :         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
     179             :         sal_Int32 nFamily,
     180             :         const vector< XMLPropertyState >& rProperties,
     181             :         const SvXMLExportPropertyMapper& rPropExp,
     182             :         const SvXMLUnitConverter&,
     183             :         const SvXMLNamespaceMap&
     184             :         ) const
     185             : {
     186        7074 :     if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
     187             :     {
     188         170 :         sal_Int32       nHeaderStartIndex(-1);
     189         170 :         sal_Int32       nHeaderEndIndex(-1);
     190         170 :         sal_Int32       nFooterStartIndex(-1);
     191         170 :         sal_Int32       nFooterEndIndex(-1);
     192         170 :         bool        bHeaderStartIndex(false);
     193         170 :         bool        bHeaderEndIndex(false);
     194         170 :         bool        bFooterStartIndex(false);
     195         170 :         bool        bFooterEndIndex(false);
     196             : 
     197         170 :         rtl::Reference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
     198             : 
     199         170 :         sal_Int32 nIndex(0);
     200       32640 :         while(nIndex < aPropMapper->GetEntryCount())
     201             :         {
     202       32300 :             switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
     203             :             {
     204             :                 case CTF_PM_HEADERFLAG:
     205             :                 {
     206        8330 :                     if (!bHeaderStartIndex)
     207             :                     {
     208         170 :                         nHeaderStartIndex = nIndex;
     209         170 :                         bHeaderStartIndex = true;
     210             :                     }
     211        8330 :                     if (bFooterStartIndex && !bFooterEndIndex)
     212             :                     {
     213           0 :                         nFooterEndIndex = nIndex;
     214           0 :                         bFooterEndIndex = true;
     215             :                     }
     216             :                 }
     217        8330 :                 break;
     218             :                 case CTF_PM_FOOTERFLAG:
     219             :                 {
     220        8330 :                     if (!bFooterStartIndex)
     221             :                     {
     222         170 :                         nFooterStartIndex = nIndex;
     223         170 :                         bFooterStartIndex = true;
     224             :                     }
     225        8330 :                     if (bHeaderStartIndex && !bHeaderEndIndex)
     226             :                     {
     227         170 :                         nHeaderEndIndex = nIndex;
     228         170 :                         bHeaderEndIndex = true;
     229             :                     }
     230             :                 }
     231        8330 :                 break;
     232             :             }
     233       32300 :             nIndex++;
     234             :         }
     235         170 :         if (!bHeaderEndIndex)
     236           0 :             nHeaderEndIndex = nIndex;
     237         170 :         if (!bFooterEndIndex)
     238         170 :             nFooterEndIndex = nIndex;
     239             : 
     240             :         // export header style element
     241             :         {
     242             :             SvXMLElementExport aElem(
     243         170 :                 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
     244         170 :                 true, true );
     245             : 
     246             :             rPropExp.exportXML(
     247         170 :                 GetExport(), rProperties,
     248         170 :                 nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS);
     249             :         }
     250             : 
     251             :         // export footer style
     252             :         {
     253             :             SvXMLElementExport aElem(
     254         170 :                 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
     255         170 :                 true, true );
     256             : 
     257             :             rPropExp.exportXML(
     258         170 :                 GetExport(), rProperties,
     259         170 :                 nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS);
     260         170 :         }
     261             :     }
     262        7074 : }
     263             : 
     264        4002 : SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
     265             : {
     266        4002 :     pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
     267        4002 : }
     268             : 
     269        9714 : SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
     270             : {
     271        4002 :     delete pImpl;
     272        5712 : }
     273             : 
     274       23050 : SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
     275             : {
     276       23050 :     return pImpl->GetExport();
     277             : }
     278             : 
     279             : // TODO: romove this
     280       10932 : void SvXMLAutoStylePoolP::AddFamily(
     281             :         sal_Int32 nFamily,
     282             :         const OUString& rStrName,
     283             :         SvXMLExportPropertyMapper* pMapper,
     284             :         const OUString& aStrPrefix,
     285             :         bool bAsFamily )
     286             : {
     287       10932 :     rtl::Reference <SvXMLExportPropertyMapper> xTmp = pMapper;
     288       10932 :     AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
     289       10932 : }
     290             : 
     291       23008 : void SvXMLAutoStylePoolP::AddFamily(
     292             :         sal_Int32 nFamily,
     293             :         const OUString& rStrName,
     294             :         const rtl::Reference < SvXMLExportPropertyMapper > & rMapper,
     295             :         const OUString& rStrPrefix,
     296             :         bool bAsFamily )
     297             : {
     298       23008 :     pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
     299       23008 : }
     300             : 
     301           4 : void  SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
     302             :         sal_Int32 nFamily,
     303             :         const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
     304             : {
     305           4 :     pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
     306           4 : }
     307             : 
     308       21968 : void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
     309             :                                          const OUString& rName )
     310             : {
     311       21968 :     pImpl->RegisterName( nFamily, rName );
     312       21968 : }
     313             : 
     314         126 : void SvXMLAutoStylePoolP::GetRegisteredNames(
     315             :     uno::Sequence<sal_Int32>& rFamilies,
     316             :     uno::Sequence<OUString>& rNames )
     317             : {
     318         126 :     pImpl->GetRegisteredNames( rFamilies, rNames );
     319         126 : }
     320             : 
     321         126 : void SvXMLAutoStylePoolP::RegisterNames(
     322             :     uno::Sequence<sal_Int32>& aFamilies,
     323             :     uno::Sequence<OUString>& aNames )
     324             : {
     325             :     DBG_ASSERT( aFamilies.getLength() == aNames.getLength(),
     326             :                 "aFamilies != aNames" );
     327             : 
     328             :     // iterate over sequence(s) and call RegisterName(..) for each pair
     329         126 :     const sal_Int32* pFamilies = aFamilies.getConstArray();
     330         126 :     const OUString* pNames = aNames.getConstArray();
     331         126 :     sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
     332       10982 :     for( sal_Int32 n = 0; n < nCount; n++ )
     333       10856 :         RegisterName( pFamilies[n], pNames[n] );
     334         126 : }
     335             : 
     336        6940 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
     337             :                                   const vector< XMLPropertyState >& rProperties )
     338             : {
     339        6940 :     OUString sEmpty;
     340        6940 :     OUString sName;
     341        6940 :     pImpl->Add(sName, nFamily, sEmpty, rProperties );
     342        6940 :     return sName;
     343             : }
     344             : 
     345         644 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
     346             :                                   const OUString& rParent,
     347             :                                   const vector< XMLPropertyState >& rProperties, bool bDontSeek )
     348             : {
     349         644 :     OUString sName;
     350         644 :     pImpl->Add(sName, nFamily, rParent, rProperties, bDontSeek);
     351         644 :     return sName;
     352             : }
     353             : 
     354         340 : bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
     355             : {
     356         340 :     return pImpl->Add(rName, nFamily, rParent, rProperties);
     357             : }
     358             : 
     359           0 : bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
     360             :                                         const ::std::vector< XMLPropertyState >& rProperties )
     361             : 
     362             : {
     363           0 :     return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
     364             : }
     365             : 
     366         888 : OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
     367             :                                    const OUString& rParent,
     368             :                                    const vector< XMLPropertyState >& rProperties ) const
     369             : {
     370         888 :     return pImpl->Find( nFamily, rParent, rProperties );
     371             : }
     372             : 
     373        7374 : void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
     374             :     const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
     375             :     const SvXMLUnitConverter&,
     376             :     const SvXMLNamespaceMap&
     377             :     ) const
     378             : {
     379             :     pImpl->exportXML( nFamily,
     380        7374 :                       GetExport().GetDocHandler(),
     381        7374 :                       GetExport().GetMM100UnitConverter(),
     382        7374 :                       GetExport().GetNamespaceMap(),
     383        7374 :                       this);
     384        7374 : }
     385             : 
     386          14 : void SvXMLAutoStylePoolP::ClearEntries()
     387             : {
     388          14 :     pImpl->ClearEntries();
     389          14 : }
     390             : 
     391             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10