LCOV - code coverage report
Current view: top level - xmloff/source/style - xmlaustp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 119 155 76.8 %
Date: 2014-04-11 Functions: 17 20 85.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/XMLTextListAutoStylePool.hxx>
      29             : 
      30             : #include <xmloff/PageMasterStyleMap.hxx>
      31             : #include "PageMasterExportPropMapper.hxx"
      32             : #include "XMLBackgroundImageExport.hxx"
      33             : 
      34             : 
      35             : using namespace ::std;
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::xmloff::token;
      39             : 
      40             : 
      41             : namespace
      42             : {
      43           0 :     static void lcl_exportDataStyle( SvXMLExport& _rExport, const UniReference< XMLPropertySetMapper >& _rxMapper,
      44             :         const XMLPropertyState& _rProperty )
      45             :     {
      46             :         DBG_ASSERT( _rxMapper.is(), "xmloff::lcl_exportDataStyle: invalid property mapper!" );
      47             :         // obtain the data style name
      48           0 :         OUString sDataStyleName;
      49           0 :         _rProperty.maValue >>= sDataStyleName;
      50             :         DBG_ASSERT( !sDataStyleName.isEmpty(), "xmloff::lcl_exportDataStyle: invalid property value for the data style name!" );
      51             : 
      52             :         // add the attribute
      53             :         _rExport.AddAttribute(
      54           0 :             _rxMapper->GetEntryNameSpace( _rProperty.mnIndex ),
      55           0 :             _rxMapper->GetEntryXMLName( _rProperty.mnIndex ),
      56           0 :             sDataStyleName );
      57           0 :     }
      58             : }
      59             : 
      60        2430 : void SvXMLAutoStylePoolP::exportStyleAttributes(
      61             :         SvXMLAttributeList&,
      62             :         sal_Int32 nFamily,
      63             :         const vector< XMLPropertyState >& rProperties,
      64             :         const SvXMLExportPropertyMapper& rPropExp,
      65             :         const SvXMLUnitConverter&,
      66             :         const SvXMLNamespaceMap&
      67             :         ) const
      68             : {
      69        2430 :     if ( XML_STYLE_FAMILY_CONTROL_ID == nFamily )
      70             :     {   // it's a control-related style
      71           0 :         UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
      72             : 
      73           0 :         for (   vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
      74           0 :                 pProp != rProperties.end();
      75             :                 ++pProp
      76             :             )
      77             :         {
      78           0 :             if  (   ( pProp->mnIndex > -1 )
      79           0 :                 &&  ( CTF_FORMS_DATA_STYLE == aPropertyMapper->GetEntryContextId( pProp->mnIndex ) )
      80             :                 )
      81             :             {   // it's the data-style for a grid column
      82           0 :                 lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
      83             :             }
      84           0 :         }
      85             :     }
      86             : 
      87        2430 :     if( (XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily) || (XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily) )
      88             :     {   // it's a graphics style
      89          33 :         UniReference< XMLPropertySetMapper > aPropertyMapper = rPropExp.getPropertySetMapper();
      90             :         DBG_ASSERT(aPropertyMapper.is(), "SvXMLAutoStylePoolP::exportStyleAttributes: invalid property set mapper!");
      91             : 
      92          33 :         sal_Bool bFoundControlShapeDataStyle = sal_False;
      93          33 :         sal_Bool bFoundNumberingRulesName = sal_False;
      94             : 
      95        1014 :         for (   vector< XMLPropertyState >::const_iterator pProp = rProperties.begin();
      96         676 :                 pProp != rProperties.end();
      97             :                 ++pProp
      98             :             )
      99             :         {
     100         305 :             if (pProp->mnIndex > -1)
     101             :             {   // it's a valid property
     102         194 :                 switch( aPropertyMapper->GetEntryContextId(pProp->mnIndex) )
     103             :                 {
     104             :                 case CTF_SD_CONTROL_SHAPE_DATA_STYLE:
     105             :                     {   // it's the control shape data style property
     106             : 
     107           0 :                         if (bFoundControlShapeDataStyle)
     108             :                         {
     109             :                             OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the ControlShapeDataStyle context id!");
     110             :                             // already added the attribute for the first occurrence
     111           0 :                             break;
     112             :                         }
     113             : 
     114           0 :                         lcl_exportDataStyle( GetExport(), aPropertyMapper, *pProp );
     115             : 
     116             :                         // check if there is another property with the special context id we're handling here
     117           0 :                         bFoundControlShapeDataStyle = sal_True;
     118           0 :                         break;
     119             :                     }
     120             :                 case CTF_SD_NUMBERINGRULES_NAME:
     121             :                     {
     122           0 :                         if (bFoundNumberingRulesName)
     123             :                         {
     124             :                             OSL_FAIL("SvXMLAutoStylePoolP::exportStyleAttributes: found two properties with the numbering rules name context id!");
     125             :                             // already added the attribute for the first occurrence
     126           0 :                             break;
     127             :                         }
     128             : 
     129           0 :                         uno::Reference< container::XIndexReplace > xNumRule;
     130           0 :                         pProp->maValue >>= xNumRule;
     131           0 :                         if( xNumRule.is() && (xNumRule->getCount() > 0 ) )
     132             :                         {
     133           0 :                             const OUString sName(((XMLTextListAutoStylePool*)&GetExport().GetTextParagraphExport()->GetListAutoStylePool())->Add( xNumRule ));
     134             : 
     135           0 :                             GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_LIST_STYLE_NAME, GetExport().EncodeStyleName( sName ) );
     136             :                         }
     137             : 
     138           0 :                         bFoundNumberingRulesName = sal_True;
     139           0 :                         break;
     140             :                     }
     141             :                 }
     142             :             }
     143          33 :         }
     144             :     }
     145             : 
     146        2430 :     if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
     147             :     {
     148        1991 :         for( vector< XMLPropertyState >::const_iterator pProp = rProperties.begin(); pProp != rProperties.end(); ++pProp )
     149             :         {
     150        1930 :             if (pProp->mnIndex > -1)
     151             :             {
     152        1221 :                 UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
     153        1221 :                 sal_Int32 nIndex = pProp->mnIndex;
     154        1221 :                 sal_Int16 nContextID = aPropMapper->GetEntryContextId( nIndex );
     155        1221 :                 switch( nContextID )
     156             :                 {
     157             :                     case CTF_PM_PAGEUSAGE:
     158             :                     {
     159          25 :                         OUString sValue;
     160          25 :                         const XMLPropertyHandler* pPropHdl = aPropMapper->GetPropertyHandler( nIndex );
     161          50 :                         if( pPropHdl &&
     162          25 :                             pPropHdl->exportXML( sValue, pProp->maValue,
     163          75 :                                                  GetExport().GetMM100UnitConverter() ) &&
     164          25 :                             ( ! IsXMLToken( sValue, XML_ALL ) ) )
     165             :                         {
     166           4 :                             GetExport().AddAttribute( aPropMapper->GetEntryNameSpace( nIndex ), aPropMapper->GetEntryXMLName( nIndex ), sValue );
     167          25 :                         }
     168             :                     }
     169          25 :                     break;
     170        1221 :                 }
     171             :             }
     172             :         }
     173             :     }
     174        2430 : }
     175             : 
     176        2430 : void SvXMLAutoStylePoolP::exportStyleContent(
     177             :         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
     178             :         sal_Int32 nFamily,
     179             :         const vector< XMLPropertyState >& rProperties,
     180             :         const SvXMLExportPropertyMapper& rPropExp,
     181             :         const SvXMLUnitConverter&,
     182             :         const SvXMLNamespaceMap&
     183             :         ) const
     184             : {
     185        2430 :     if( nFamily == XML_STYLE_FAMILY_PAGE_MASTER )
     186             :     {
     187          61 :         sal_Int32       nHeaderStartIndex(-1);
     188          61 :         sal_Int32       nHeaderEndIndex(-1);
     189          61 :         sal_Int32       nFooterStartIndex(-1);
     190          61 :         sal_Int32       nFooterEndIndex(-1);
     191          61 :         sal_Bool        bHeaderStartIndex(sal_False);
     192          61 :         sal_Bool        bHeaderEndIndex(sal_False);
     193          61 :         sal_Bool        bFooterStartIndex(sal_False);
     194          61 :         sal_Bool        bFooterEndIndex(sal_False);
     195             : 
     196          61 :         UniReference< XMLPropertySetMapper > aPropMapper = rPropExp.getPropertySetMapper();
     197             : 
     198          61 :         sal_Int32 nIndex(0);
     199        8113 :         while(nIndex < aPropMapper->GetEntryCount())
     200             :         {
     201        7991 :             switch( aPropMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK )
     202             :             {
     203             :                 case CTF_PM_HEADERFLAG:
     204             :                 {
     205        1769 :                     if (!bHeaderStartIndex)
     206             :                     {
     207          61 :                         nHeaderStartIndex = nIndex;
     208          61 :                         bHeaderStartIndex = sal_True;
     209             :                     }
     210        1769 :                     if (bFooterStartIndex && !bFooterEndIndex)
     211             :                     {
     212           0 :                         nFooterEndIndex = nIndex;
     213           0 :                         bFooterEndIndex = sal_True;
     214             :                     }
     215             :                 }
     216        1769 :                 break;
     217             :                 case CTF_PM_FOOTERFLAG:
     218             :                 {
     219        1769 :                     if (!bFooterStartIndex)
     220             :                     {
     221          61 :                         nFooterStartIndex = nIndex;
     222          61 :                         bFooterStartIndex = sal_True;
     223             :                     }
     224        1769 :                     if (bHeaderStartIndex && !bHeaderEndIndex)
     225             :                     {
     226          61 :                         nHeaderEndIndex = nIndex;
     227          61 :                         bHeaderEndIndex = sal_True;
     228             :                     }
     229             :                 }
     230        1769 :                 break;
     231             :             }
     232        7991 :             nIndex++;
     233             :         }
     234          61 :         if (!bHeaderEndIndex)
     235           0 :             nHeaderEndIndex = nIndex;
     236          61 :         if (!bFooterEndIndex)
     237          61 :             nFooterEndIndex = nIndex;
     238             : 
     239             :         // export header style element
     240             :         {
     241             :             SvXMLElementExport aElem(
     242          61 :                 GetExport(), XML_NAMESPACE_STYLE, XML_HEADER_STYLE,
     243          61 :                 true, true );
     244             : 
     245             :             rPropExp.exportXML(
     246          61 :                 GetExport(), rProperties,
     247          61 :                 nHeaderStartIndex, nHeaderEndIndex, XML_EXPORT_FLAG_IGN_WS);
     248             :         }
     249             : 
     250             :         // export footer style
     251             :         {
     252             :             SvXMLElementExport aElem(
     253          61 :                 GetExport(), XML_NAMESPACE_STYLE, XML_FOOTER_STYLE,
     254          61 :                 true, true );
     255             : 
     256             :             rPropExp.exportXML(
     257          61 :                 GetExport(), rProperties,
     258          61 :                 nFooterStartIndex, nFooterEndIndex, XML_EXPORT_FLAG_IGN_WS);
     259          61 :         }
     260             :     }
     261        2430 : }
     262             : 
     263        1383 : SvXMLAutoStylePoolP::SvXMLAutoStylePoolP( SvXMLExport& rExport )
     264             : {
     265        1383 :     pImpl = new SvXMLAutoStylePoolP_Impl( rExport );
     266        1383 : }
     267             : 
     268        3351 : SvXMLAutoStylePoolP::~SvXMLAutoStylePoolP()
     269             : {
     270        1383 :     delete pImpl;
     271        1968 : }
     272             : 
     273        8935 : SvXMLExport& SvXMLAutoStylePoolP::GetExport() const
     274             : {
     275        8935 :     return pImpl->GetExport();
     276             : }
     277             : 
     278             : // TODO: romove this
     279        4019 : void SvXMLAutoStylePoolP::AddFamily(
     280             :         sal_Int32 nFamily,
     281             :         const OUString& rStrName,
     282             :         SvXMLExportPropertyMapper* pMapper,
     283             :         const OUString& aStrPrefix,
     284             :         bool bAsFamily )
     285             : {
     286        4019 :     UniReference <SvXMLExportPropertyMapper> xTmp = pMapper;
     287        4019 :     AddFamily( nFamily, rStrName, xTmp, aStrPrefix, bAsFamily );
     288        4019 : }
     289             : 
     290        8270 : void SvXMLAutoStylePoolP::AddFamily(
     291             :         sal_Int32 nFamily,
     292             :         const OUString& rStrName,
     293             :         const UniReference < SvXMLExportPropertyMapper > & rMapper,
     294             :         const OUString& rStrPrefix,
     295             :         bool bAsFamily )
     296             : {
     297        8270 :     pImpl->AddFamily( nFamily, rStrName, rMapper, rStrPrefix, bAsFamily );
     298        8270 : }
     299             : 
     300           0 : void  SvXMLAutoStylePoolP::SetFamilyPropSetMapper(
     301             :         sal_Int32 nFamily,
     302             :         const UniReference < SvXMLExportPropertyMapper > & rMapper )
     303             : {
     304           0 :     pImpl->SetFamilyPropSetMapper( nFamily, rMapper );
     305           0 : }
     306             : 
     307        9172 : void SvXMLAutoStylePoolP::RegisterName( sal_Int32 nFamily,
     308             :                                          const OUString& rName )
     309             : {
     310        9172 :     pImpl->RegisterName( nFamily, rName );
     311        9172 : }
     312             : 
     313          59 : void SvXMLAutoStylePoolP::GetRegisteredNames(
     314             :     uno::Sequence<sal_Int32>& rFamilies,
     315             :     uno::Sequence<OUString>& rNames )
     316             : {
     317          59 :     pImpl->GetRegisteredNames( rFamilies, rNames );
     318          59 : }
     319             : 
     320          59 : void SvXMLAutoStylePoolP::RegisterNames(
     321             :     uno::Sequence<sal_Int32>& aFamilies,
     322             :     uno::Sequence<OUString>& aNames )
     323             : {
     324             :     DBG_ASSERT( aFamilies.getLength() == aNames.getLength(),
     325             :                 "aFamilies != aNames" );
     326             : 
     327             :     // iterate over sequence(s) and call RegisterName(..) for each pair
     328          59 :     const sal_Int32* pFamilies = aFamilies.getConstArray();
     329          59 :     const OUString* pNames = aNames.getConstArray();
     330          59 :     sal_Int32 nCount = min( aFamilies.getLength(), aNames.getLength() );
     331        4584 :     for( sal_Int32 n = 0; n < nCount; n++ )
     332        4525 :         RegisterName( pFamilies[n], pNames[n] );
     333          59 : }
     334             : 
     335        2385 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
     336             :                                   const vector< XMLPropertyState >& rProperties )
     337             : {
     338        2385 :     OUString sEmpty;
     339        2385 :     OUString sName;
     340        2385 :     pImpl->Add(sName, nFamily, sEmpty, rProperties );
     341        2385 :     return sName;
     342             : }
     343             : 
     344         248 : OUString SvXMLAutoStylePoolP::Add( sal_Int32 nFamily,
     345             :                                   const OUString& rParent,
     346             :                                   const vector< XMLPropertyState >& rProperties, bool bDontSeek )
     347             : {
     348         248 :     OUString sName;
     349         248 :     pImpl->Add(sName, nFamily, rParent, rProperties, bDontSeek);
     350         248 :     return sName;
     351             : }
     352             : 
     353         140 : bool SvXMLAutoStylePoolP::Add(OUString& rName, sal_Int32 nFamily, const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
     354             : {
     355         140 :     return pImpl->Add(rName, nFamily, rParent, rProperties);
     356             : }
     357             : 
     358           0 : bool SvXMLAutoStylePoolP::AddNamed( const OUString& rName, sal_Int32 nFamily, const OUString& rParent,
     359             :                                         const ::std::vector< XMLPropertyState >& rProperties )
     360             : 
     361             : {
     362           0 :     return pImpl->AddNamed(rName, nFamily, rParent, rProperties);
     363             : }
     364             : 
     365         370 : OUString SvXMLAutoStylePoolP::Find( sal_Int32 nFamily,
     366             :                                    const OUString& rParent,
     367             :                                    const vector< XMLPropertyState >& rProperties ) const
     368             : {
     369         370 :     return pImpl->Find( nFamily, rParent, rProperties );
     370             : }
     371             : 
     372        2864 : void SvXMLAutoStylePoolP::exportXML( sal_Int32 nFamily,
     373             :     const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
     374             :     const SvXMLUnitConverter&,
     375             :     const SvXMLNamespaceMap&
     376             :     ) const
     377             : {
     378             :     pImpl->exportXML( nFamily,
     379        2864 :                       GetExport().GetDocHandler(),
     380        2864 :                       GetExport().GetMM100UnitConverter(),
     381        2864 :                       GetExport().GetNamespaceMap(),
     382        2864 :                       this);
     383        2864 : }
     384             : 
     385           6 : void SvXMLAutoStylePoolP::ClearEntries()
     386             : {
     387           6 :     pImpl->ClearEntries();
     388           6 : }
     389             : 
     390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10