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

Generated by: LCOV version 1.10