LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextMasterPageContext.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 123 0.0 %
Date: 2014-04-14 Functions: 0 12 0.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/style/XStyle.hpp>
      21             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      22             : #include <com/sun/star/style/PageStyleLayout.hpp>
      23             : #include <com/sun/star/beans/XMultiPropertyStates.hpp>
      24             : #include <xmloff/nmspmap.hxx>
      25             : #include <xmloff/xmlnmspe.hxx>
      26             : #include <xmloff/xmltoken.hxx>
      27             : #include <xmloff/XMLTextMasterPageContext.hxx>
      28             : #include "XMLTextHeaderFooterContext.hxx"
      29             : #include <xmloff/xmlimp.hxx>
      30             : #include "PageMasterImportContext.hxx"
      31             : 
      32             : 
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::com::sun::star::xml::sax;
      37             : using namespace ::com::sun::star::style;
      38             : using namespace ::com::sun::star::text;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::container;
      41             : using namespace ::com::sun::star::lang;
      42             : using namespace ::xmloff::token;
      43             : 
      44           0 : Reference < XStyle > XMLTextMasterPageContext::Create()
      45             : {
      46           0 :     Reference < XStyle > xNewStyle;
      47             : 
      48           0 :     Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(),
      49           0 :                                                     UNO_QUERY );
      50           0 :     if( xFactory.is() )
      51             :     {
      52             :         Reference < XInterface > xIfc =
      53           0 :             xFactory->createInstance("com.sun.star.style.PageStyle");
      54           0 :         if( xIfc.is() )
      55           0 :             xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY );
      56             :     }
      57             : 
      58           0 :     return xNewStyle;
      59             : }
      60           0 : TYPEINIT1( XMLTextMasterPageContext, SvXMLStyleContext );
      61             : 
      62           0 : XMLTextMasterPageContext::XMLTextMasterPageContext( SvXMLImport& rImport,
      63             :         sal_uInt16 nPrfx, const OUString& rLName,
      64             :         const Reference< XAttributeList > & xAttrList,
      65             :         bool bOverwrite )
      66             : :   SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_MASTER_PAGE )
      67             : ,   sIsPhysical( "IsPhysical" )
      68             : ,   sPageStyleLayout( "PageStyleLayout" )
      69             : ,   sFollowStyle( "FollowStyle" )
      70             : ,   bInsertHeader( false )
      71             : ,   bInsertFooter( false )
      72             : ,   bInsertHeaderLeft( false )
      73             : ,   bInsertFooterLeft( false )
      74             : ,   bInsertHeaderFirst( false )
      75             : ,   bInsertFooterFirst( false )
      76             : ,   bHeaderInserted( false )
      77             : ,   bFooterInserted( false )
      78             : ,   bHeaderLeftInserted( false )
      79             : ,   bFooterLeftInserted( false )
      80             : ,   bHeaderFirstInserted( false )
      81           0 : ,   bFooterFirstInserted( false )
      82             : {
      83           0 :     OUString sName, sDisplayName;
      84           0 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      85           0 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      86             :     {
      87           0 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      88           0 :         OUString aLocalName;
      89           0 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
      90           0 :         if( XML_NAMESPACE_STYLE == nPrefix )
      91             :         {
      92           0 :             if( IsXMLToken( aLocalName, XML_NAME ) )
      93             :             {
      94           0 :                 sName = xAttrList->getValueByIndex( i );
      95             :             }
      96           0 :             else if( IsXMLToken( aLocalName, XML_DISPLAY_NAME ) )
      97             :             {
      98           0 :                 sDisplayName = xAttrList->getValueByIndex( i );
      99             :             }
     100           0 :             else if( IsXMLToken( aLocalName, XML_NEXT_STYLE_NAME ) )
     101             :             {
     102           0 :                 sFollow = xAttrList->getValueByIndex( i );
     103             :             }
     104           0 :             else if( IsXMLToken( aLocalName, XML_PAGE_LAYOUT_NAME ) )
     105             :             {
     106           0 :                 sPageMasterName = xAttrList->getValueByIndex( i );
     107             :             }
     108             :         }
     109           0 :     }
     110             : 
     111           0 :     if( !sDisplayName.isEmpty() )
     112             :     {
     113             :         rImport.AddStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sName,
     114           0 :                                      sDisplayName );
     115             :     }
     116             :     else
     117             :     {
     118           0 :         sDisplayName = sName;
     119             :     }
     120             : 
     121           0 :     if( sDisplayName.isEmpty() )
     122           0 :         return;
     123             : 
     124             :     Reference < XNameContainer > xPageStyles =
     125           0 :             GetImport().GetTextImport()->GetPageStyles();
     126           0 :     if( !xPageStyles.is() )
     127           0 :         return;
     128             : 
     129           0 :     Any aAny;
     130           0 :     sal_Bool bNew = sal_False;
     131           0 :     if( xPageStyles->hasByName( sDisplayName ) )
     132             :     {
     133           0 :         aAny = xPageStyles->getByName( sDisplayName );
     134           0 :         aAny >>= xStyle;
     135             :     }
     136             :     else
     137             :     {
     138           0 :         xStyle = Create();
     139           0 :         if( !xStyle.is() )
     140           0 :             return;
     141             : 
     142           0 :         aAny <<= xStyle;
     143           0 :         xPageStyles->insertByName( sDisplayName, aAny );
     144           0 :         bNew = sal_True;
     145             :     }
     146             : 
     147           0 :     Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
     148             :     Reference< XPropertySetInfo > xPropSetInfo =
     149           0 :                 xPropSet->getPropertySetInfo();
     150           0 :     if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) )
     151             :     {
     152           0 :         aAny = xPropSet->getPropertyValue( sIsPhysical );
     153           0 :         bNew = !*(sal_Bool *)aAny.getValue();
     154             :     }
     155           0 :     SetNew( bNew );
     156             : 
     157           0 :     if( bOverwrite || bNew )
     158             :     {
     159             :         Reference < XMultiPropertyStates > xMultiStates( xPropSet,
     160           0 :                                                          UNO_QUERY );
     161             :         OSL_ENSURE( xMultiStates.is(),
     162             :                     "text page style does not support multi property set" );
     163           0 :         if( xMultiStates.is() )
     164           0 :             xMultiStates->setAllPropertiesToDefault();
     165             : 
     166           0 :         bInsertHeader = bInsertFooter = true;
     167           0 :         bInsertHeaderLeft = bInsertFooterLeft = true;
     168           0 :         bInsertHeaderFirst = bInsertFooterFirst = true;
     169           0 :     }
     170             : }
     171             : 
     172           0 : XMLTextMasterPageContext::~XMLTextMasterPageContext()
     173             : {
     174           0 : }
     175             : 
     176           0 : SvXMLImportContext *XMLTextMasterPageContext::CreateChildContext(
     177             :         sal_uInt16 nPrefix,
     178             :         const OUString& rLocalName,
     179             :         const Reference< XAttributeList > & xAttrList )
     180             : {
     181           0 :     SvXMLImportContext *pContext = 0;
     182             : 
     183             :     const SvXMLTokenMap& rTokenMap =
     184           0 :         GetImport().GetTextImport()->GetTextMasterPageElemTokenMap();
     185             : 
     186           0 :     sal_Bool bInsert = sal_False, bFooter = sal_False, bLeft = sal_False, bFirst = sal_False;
     187           0 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     188             :     {
     189             :     case XML_TOK_TEXT_MP_HEADER:
     190           0 :         if( bInsertHeader && !bHeaderInserted )
     191             :         {
     192           0 :             bInsert = sal_True;
     193           0 :             bHeaderInserted = true;
     194             :         }
     195           0 :         break;
     196             :     case XML_TOK_TEXT_MP_FOOTER:
     197           0 :         if( bInsertFooter && !bFooterInserted )
     198             :         {
     199           0 :             bInsert = bFooter = sal_True;
     200           0 :             bFooterInserted = true;
     201             :         }
     202           0 :         break;
     203             :     case XML_TOK_TEXT_MP_HEADER_LEFT:
     204           0 :         if( bInsertHeaderLeft && bHeaderInserted && !bHeaderLeftInserted )
     205           0 :             bInsert = bLeft = sal_True;
     206           0 :         break;
     207             :     case XML_TOK_TEXT_MP_FOOTER_LEFT:
     208           0 :         if( bInsertFooterLeft && bFooterInserted && !bFooterLeftInserted )
     209           0 :             bInsert = bFooter = bLeft = sal_True;
     210           0 :         break;
     211             :     case XML_TOK_TEXT_MP_HEADER_FIRST:
     212           0 :         if( bInsertHeaderFirst && bHeaderInserted && !bHeaderFirstInserted )
     213           0 :             bInsert = bFirst = sal_True;
     214           0 :         break;
     215             :     case XML_TOK_TEXT_MP_FOOTER_FIRST:
     216           0 :         if( bInsertFooterFirst && bFooterInserted && !bFooterFirstInserted )
     217           0 :             bInsert = bFooter = bFirst = sal_True;
     218           0 :         break;
     219             :     }
     220             : 
     221           0 :     if( bInsert && xStyle.is() )
     222             :     {
     223             :         pContext = CreateHeaderFooterContext( nPrefix, rLocalName,
     224             :                                                     xAttrList,
     225           0 :                                                     bFooter, bLeft, bFirst );
     226             :     }
     227             :     else
     228             :     {
     229             :         pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
     230           0 :                                                           xAttrList );
     231             :     }
     232             : 
     233           0 :     return pContext;
     234             : }
     235             : 
     236           0 : SvXMLImportContext *XMLTextMasterPageContext::CreateHeaderFooterContext(
     237             :             sal_uInt16 nPrefix,
     238             :             const OUString& rLocalName,
     239             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
     240             :             const bool bFooter,
     241             :             const bool bLeft,
     242             :             const bool bFirst )
     243             : {
     244           0 :     Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
     245           0 :     return new XMLTextHeaderFooterContext( GetImport(),
     246             :                                                 nPrefix, rLocalName,
     247             :                                                 xAttrList,
     248             :                                                 xPropSet,
     249           0 :                                                 bFooter, bLeft, bFirst );
     250             : }
     251             : 
     252           0 : void XMLTextMasterPageContext::Finish( bool bOverwrite )
     253             : {
     254           0 :     if( xStyle.is() && (IsNew() || bOverwrite) )
     255             :     {
     256           0 :         Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
     257           0 :         if( !sPageMasterName.isEmpty() )
     258             :         {
     259             :             XMLPropStyleContext* pStyle =
     260           0 :                 GetImport().GetTextImport()->FindPageMaster( sPageMasterName );
     261           0 :             if (pStyle)
     262             :             {
     263           0 :                 pStyle->FillPropertySet(xPropSet);
     264             :             }
     265             :         }
     266             : 
     267             :         Reference < XNameContainer > xPageStyles =
     268           0 :             GetImport().GetTextImport()->GetPageStyles();
     269           0 :         if( !xPageStyles.is() )
     270           0 :             return;
     271             : 
     272             :         Reference< XPropertySetInfo > xPropSetInfo =
     273           0 :             xPropSet->getPropertySetInfo();
     274           0 :         if( xPropSetInfo->hasPropertyByName( sFollowStyle ) )
     275             :         {
     276             :             OUString sDisplayFollow(
     277           0 :                 GetImport().GetStyleDisplayName(
     278           0 :                         XML_STYLE_FAMILY_MASTER_PAGE, sFollow ) );
     279           0 :             if( sDisplayFollow.isEmpty() ||
     280           0 :                 !xPageStyles->hasByName( sDisplayFollow ) )
     281           0 :                 sDisplayFollow = xStyle->getName();
     282             : 
     283           0 :             Any aAny = xPropSet->getPropertyValue( sFollowStyle );
     284           0 :             OUString sCurrFollow;
     285           0 :             aAny >>= sCurrFollow;
     286           0 :             if( sCurrFollow != sDisplayFollow )
     287             :             {
     288           0 :                 aAny <<= sDisplayFollow;
     289           0 :                 xPropSet->setPropertyValue( sFollowStyle, aAny );
     290           0 :             }
     291             :         }
     292             : 
     293           0 :         if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
     294             :         {
     295           0 :             xPropSet->setPropertyValue( "Hidden", uno::makeAny( IsHidden( ) ) );
     296           0 :         }
     297             :     }
     298             : }
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10