LCOV - code coverage report
Current view: top level - xmloff/source/style - PageMasterImportContext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 82 84 97.6 %
Date: 2014-04-11 Functions: 10 12 83.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 "PageMasterImportContext.hxx"
      21             : #include <xmloff/xmlnmspe.hxx>
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include "PageMasterPropHdl.hxx"
      24             : #include "PagePropertySetContext.hxx"
      25             : #include "PageHeaderFooterContext.hxx"
      26             : #include "PageMasterPropMapper.hxx"
      27             : #include "PageMasterImportPropMapper.hxx"
      28             : #include <xmloff/PageMasterStyleMap.hxx>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::xmloff::token;
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::lang;
      35             : 
      36         449 : void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
      37             :                                         const OUString& rLocalName,
      38             :                                         const OUString& rValue )
      39             : {
      40             :     // TODO: use a map here
      41         449 :     if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
      42             :     {
      43          28 :         sPageUsage = rValue;
      44             :     }
      45             :     else
      46             :     {
      47         421 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
      48             :     }
      49         449 : }
      50             : 
      51        1335 : TYPEINIT1( PageStyleContext, XMLPropStyleContext );
      52             : 
      53         447 : PageStyleContext::PageStyleContext( SvXMLImport& rImport,
      54             :         sal_uInt16 nPrfx, const OUString& rLName,
      55             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList,
      56             :         SvXMLStylesContext& rStyles,
      57             :         sal_Bool bDefaultStyle) :
      58             :     XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
      59         447 :     sPageUsage()
      60             : {
      61         447 : }
      62             : 
      63         894 : PageStyleContext::~PageStyleContext()
      64             : {
      65         894 : }
      66             : 
      67        1192 : SvXMLImportContext *PageStyleContext::CreateChildContext(
      68             :         sal_uInt16 nPrefix,
      69             :         const OUString& rLocalName,
      70             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      71             : {
      72        1192 :     SvXMLImportContext *pContext = NULL;
      73             : 
      74        3140 :     if( XML_NAMESPACE_STYLE == nPrefix &&
      75        2006 :         ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
      76         814 :          (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
      77             :     {
      78         756 :         sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
      79             :         UniReference < SvXMLImportPropertyMapper > xImpPrMap =
      80         756 :             GetStyles()->GetImportPropertyMapper( GetFamily() );
      81         756 :         if( xImpPrMap.is() )
      82             :         {
      83         756 :             const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
      84             :             sal_Int32 nFlag;
      85         756 :             if (bHeader)
      86         378 :                 nFlag = CTF_PM_HEADERFLAG;
      87             :             else
      88         378 :                 nFlag = CTF_PM_FOOTERFLAG;
      89         756 :             sal_Int32 nStartIndex (-1);
      90         756 :             sal_Int32 nEndIndex (-1);
      91         756 :             bool bFirst(false);
      92         756 :             bool bEnd(false);
      93         756 :             sal_Int32 nIndex = 0;
      94       89964 :             while ( nIndex < rMapper->GetEntryCount() && !bEnd)
      95             :             {
      96       88452 :                 if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
      97             :                 {
      98       21924 :                     if (!bFirst)
      99             :                     {
     100         756 :                         bFirst = true;
     101         756 :                         nStartIndex = nIndex;
     102             :                     }
     103             :                 }
     104       66528 :                 else if (bFirst)
     105             :                 {
     106         378 :                     bEnd = true;
     107         378 :                     nEndIndex = nIndex;
     108             :                 }
     109       88452 :                 nIndex++;
     110             :             }
     111         756 :             if (!bEnd)
     112         378 :                 nEndIndex = nIndex;
     113         756 :             pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
     114         756 :                             xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
     115         756 :         }
     116             :     }
     117        2384 :     if( XML_NAMESPACE_STYLE == nPrefix &&
     118        1192 :         IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
     119             :     {
     120             :         UniReference < SvXMLImportPropertyMapper > xImpPrMap =
     121         436 :             GetStyles()->GetImportPropertyMapper( GetFamily() );
     122         436 :         if( xImpPrMap.is() )
     123             :         {
     124         436 :             const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
     125         436 :             sal_Int32 nEndIndex (-1);
     126         436 :             bool bEnd(false);
     127         436 :             sal_Int32 nIndex = 0;
     128             :             sal_Int16 nContextID;
     129       33136 :             while ( nIndex < rMapper->GetEntryCount() && !bEnd)
     130             :             {
     131       32264 :                 nContextID = rMapper->GetEntryContextId( nIndex );
     132       32264 :                 if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
     133             :                 {
     134         436 :                     nEndIndex = nIndex;
     135         436 :                     bEnd = true;
     136             :                 }
     137       32264 :                 nIndex++;
     138             :             }
     139         436 :             if (!bEnd)
     140           0 :                 nEndIndex = nIndex;
     141         436 :             PageContextType aType = Page;
     142         436 :             pContext = new PagePropertySetContext( GetImport(), nPrefix,
     143             :                                                     rLocalName, xAttrList,
     144             :                                                     XML_TYPE_PROP_PAGE_LAYOUT,
     145         436 :                                                     GetProperties(),
     146         872 :                                                     xImpPrMap, 0, nEndIndex, aType);
     147         436 :         }
     148             :     }
     149             : 
     150        1192 :     if (!pContext)
     151             :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
     152           0 :                                                            xAttrList );
     153        1192 :     return pContext;
     154             : }
     155             : 
     156         471 : void PageStyleContext::FillPropertySet(
     157             :             const uno::Reference<beans::XPropertySet > & rPropSet )
     158             : {
     159         471 :     XMLPropStyleContext::FillPropertySet(rPropSet);
     160         471 :     if (!sPageUsage.isEmpty())
     161             :     {
     162          30 :         uno::Any aPageUsage;
     163          60 :         XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
     164          30 :         if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
     165          60 :             rPropSet->setPropertyValue("PageStyleLayout", aPageUsage);
     166             :     }
     167         471 : }
     168             : 
     169             : // text grid enhancement for better CJK support
     170             : //set default page layout style
     171          26 : void PageStyleContext::SetDefaults( )
     172             : {
     173          26 :     Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
     174          26 :     if (xFactory.is())
     175             :     {
     176          26 :         Reference < XInterface > xInt = xFactory->createInstance (
     177          26 :         OUString ( "com.sun.star.text.Defaults" ) );
     178          52 :         Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
     179          26 :         if ( xProperties.is() )
     180          52 :             FillPropertySet ( xProperties );
     181          26 :     }
     182          26 : }
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10