LCOV - code coverage report
Current view: top level - xmloff/source/style - PageMasterImportContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 95 118 80.5 %
Date: 2014-11-03 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             : //UUUU
      32             : #include <xmlsdtypes.hxx>
      33             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      34             : #include <xmloff/xmlerror.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::xmloff::token;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::lang;
      40             : 
      41             : //UUUU
      42             : using namespace ::com::sun::star::beans;
      43             : 
      44        1514 : void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
      45             :                                         const OUString& rLocalName,
      46             :                                         const OUString& rValue )
      47             : {
      48             :     // TODO: use a map here
      49        1514 :     if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
      50             :     {
      51          58 :         sPageUsage = rValue;
      52             :     }
      53             :     else
      54             :     {
      55        1456 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
      56             :     }
      57        1514 : }
      58             : 
      59        4206 : TYPEINIT1( PageStyleContext, XMLPropStyleContext );
      60             : 
      61        1516 : PageStyleContext::PageStyleContext( SvXMLImport& rImport,
      62             :         sal_uInt16 nPrfx, const OUString& rLName,
      63             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList,
      64             :         SvXMLStylesContext& rStyles,
      65             :         bool bDefaultStyle) :
      66             :     XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
      67             :     sPageUsage(),
      68        1516 :     m_bIsFillStyleAlreadyConverted(false) //UUUU
      69             : {
      70        1516 : }
      71             : 
      72        3032 : PageStyleContext::~PageStyleContext()
      73             : {
      74        3032 : }
      75             : 
      76        3430 : SvXMLImportContext *PageStyleContext::CreateChildContext(
      77             :         sal_uInt16 nPrefix,
      78             :         const OUString& rLocalName,
      79             :         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      80             : {
      81        8796 :     if( XML_NAMESPACE_STYLE == nPrefix &&
      82        5892 :         ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
      83        2462 :          (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
      84             :     {
      85        1936 :         bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
      86             :         rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
      87        1936 :             GetStyles()->GetImportPropertyMapper( GetFamily() );
      88        1936 :         if( xImpPrMap.is() )
      89             :         {
      90        1936 :             const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
      91             :             sal_Int32 nFlag;
      92        1936 :             if (bHeader)
      93         968 :                 nFlag = CTF_PM_HEADERFLAG;
      94             :             else
      95         968 :                 nFlag = CTF_PM_FOOTERFLAG;
      96        1936 :             sal_Int32 nStartIndex (-1);
      97        1936 :             sal_Int32 nEndIndex (-1);
      98        1936 :             bool bFirst(false);
      99        1936 :             bool bEnd(false);
     100        1936 :             sal_Int32 nIndex = 0;
     101      325248 :             while ( nIndex < rMapper->GetEntryCount() && !bEnd)
     102             :             {
     103      321376 :                 if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
     104             :                 {
     105       94864 :                     if (!bFirst)
     106             :                     {
     107        1936 :                         bFirst = true;
     108        1936 :                         nStartIndex = nIndex;
     109             :                     }
     110             :                 }
     111      226512 :                 else if (bFirst)
     112             :                 {
     113         968 :                     bEnd = true;
     114         968 :                     nEndIndex = nIndex;
     115             :                 }
     116      321376 :                 nIndex++;
     117             :             }
     118        1936 :             if (!bEnd)
     119         968 :                 nEndIndex = nIndex;
     120        1936 :             return new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
     121        1936 :                             xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
     122           0 :         }
     123             :     }
     124             : 
     125        2988 :     if( XML_NAMESPACE_STYLE == nPrefix &&
     126        1494 :         IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
     127             :     {
     128             :         rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     129        1494 :             GetStyles()->GetImportPropertyMapper( GetFamily() );
     130        1494 :         if( xImpPrMap.is() )
     131             :         {
     132        1494 :             const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
     133        1494 :             sal_Int32 nEndIndex (-1);
     134        1494 :             bool bEnd(false);
     135        1494 :             sal_Int32 nIndex = 0;
     136             :             sal_Int16 nContextID;
     137      141930 :             while ( nIndex < rMapper->GetEntryCount() && !bEnd)
     138             :             {
     139      138942 :                 nContextID = rMapper->GetEntryContextId( nIndex );
     140      138942 :                 if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
     141             :                 {
     142        1494 :                     nEndIndex = nIndex;
     143        1494 :                     bEnd = true;
     144             :                 }
     145      138942 :                 nIndex++;
     146             :             }
     147        1494 :             if (!bEnd)
     148           0 :                 nEndIndex = nIndex;
     149        1494 :             PageContextType aType = Page;
     150        1494 :             return new PagePropertySetContext( GetImport(), nPrefix,
     151             :                                                     rLocalName, xAttrList,
     152             :                                                     XML_TYPE_PROP_PAGE_LAYOUT,
     153        1494 :                                                     GetProperties(),
     154        2988 :                                                     xImpPrMap, 0, nEndIndex, aType);
     155           0 :         }
     156             :     }
     157             : 
     158           0 :     return XMLPropStyleContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
     159             : }
     160             : 
     161        1462 : void PageStyleContext::FillPropertySet(const uno::Reference<beans::XPropertySet > & rPropSet)
     162             : {
     163             :     //UUUU need to filter out old fill definitions when the new ones are used. The new
     164             :     // ones are used when a FillStyle is defined
     165        1462 :     if(!m_bIsFillStyleAlreadyConverted && GetProperties().size())
     166             :     {
     167        1414 :         static ::rtl::OUString s_FillStyle(RTL_CONSTASCII_USTRINGPARAM("FillStyle"));
     168        1414 :         static ::rtl::OUString s_HeaderFillStyle(RTL_CONSTASCII_USTRINGPARAM("HeaderFillStyle"));
     169        1414 :         static ::rtl::OUString s_FooterFillStyle(RTL_CONSTASCII_USTRINGPARAM("FooterFillStyle"));
     170             : 
     171        1414 :         if(doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle))
     172             :         {
     173           0 :             deactivateOldFillStyleDefinitions(getStandardSet());
     174             :         }
     175             : 
     176        1414 :         if(doNewDrawingLayerFillStyleDefinitionsExist(s_HeaderFillStyle))
     177             :         {
     178           0 :             deactivateOldFillStyleDefinitions(getHeaderSet());
     179             :         }
     180             : 
     181        1414 :         if(doNewDrawingLayerFillStyleDefinitionsExist(s_FooterFillStyle))
     182             :         {
     183           0 :             deactivateOldFillStyleDefinitions(getFooterSet());
     184             :         }
     185             : 
     186        1414 :         m_bIsFillStyleAlreadyConverted = true;
     187             :     }
     188             : 
     189             :     //UUUU do not use XMLPropStyleContext::FillPropertySet, we need to handle this ourselves since
     190             :     // we have properties which use the MID_FLAG_NO_PROPERTY_IMPORT flag since they need some special
     191             :     // handling
     192        1462 :     rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper(GetFamily());
     193             : 
     194        1462 :     if(xImpPrMap.is())
     195             :     {
     196             :         // properties that need special handling because they need the used name to be translated first
     197             :         struct _ContextID_Index_Pair aContextIDs[] =
     198             :         {
     199             :             { CTF_PM_FILLGRADIENTNAME, -1 },
     200             :             { CTF_PM_FILLTRANSNAME, -1 },
     201             :             { CTF_PM_FILLHATCHNAME, -1 },
     202             :             { CTF_PM_FILLBITMAPNAME, -1 },
     203             : 
     204             :             // also need to special handling for header entries
     205             :             { CTF_PM_HEADERFILLGRADIENTNAME, -1 },
     206             :             { CTF_PM_HEADERFILLTRANSNAME, -1 },
     207             :             { CTF_PM_HEADERFILLHATCHNAME, -1 },
     208             :             { CTF_PM_HEADERFILLBITMAPNAME, -1 },
     209             : 
     210             :             // also need to special handling for footer entries
     211             :             { CTF_PM_FOOTERFILLGRADIENTNAME, -1 },
     212             :             { CTF_PM_FOOTERFILLTRANSNAME, -1 },
     213             :             { CTF_PM_FOOTERFILLHATCHNAME, -1 },
     214             :             { CTF_PM_FOOTERFILLBITMAPNAME, -1 },
     215             : 
     216             :             {-1, -1}
     217        1462 :         };
     218             : 
     219             :         // the style families associated with the same index modulo 4
     220             :         static sal_uInt16 aFamilies[] =
     221             :         {
     222             :             XML_STYLE_FAMILY_SD_GRADIENT_ID,
     223             :             XML_STYLE_FAMILY_SD_GRADIENT_ID,
     224             :             XML_STYLE_FAMILY_SD_HATCH_ID,
     225             :             XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
     226             :         };
     227             : 
     228             :         //UUUU Fill PropertySet, but let it handle special properties not itself
     229        1462 :         xImpPrMap->FillPropertySet(GetProperties(), rPropSet, aContextIDs);
     230             : 
     231             :         // get property set mapper
     232        1462 :         const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
     233        1462 :         Reference< XPropertySetInfo > xInfo;
     234             : 
     235             :         //UUUU handle special attributes which have MID_FLAG_NO_PROPERTY_IMPORT set
     236       19006 :         for(sal_uInt16 i = 0; aContextIDs[i].nContextID != -1; i++)
     237             :         {
     238       17544 :             sal_Int32 nIndex = aContextIDs[i].nIndex;
     239             : 
     240       17544 :             if(nIndex != -1)
     241             :             {
     242           0 :                 switch(aContextIDs[i].nContextID)
     243             :                 {
     244             :                     case CTF_PM_FILLGRADIENTNAME:
     245             :                     case CTF_PM_FILLTRANSNAME:
     246             :                     case CTF_PM_FILLHATCHNAME:
     247             :                     case CTF_PM_FILLBITMAPNAME:
     248             : 
     249             :                     case CTF_PM_HEADERFILLGRADIENTNAME:
     250             :                     case CTF_PM_HEADERFILLTRANSNAME:
     251             :                     case CTF_PM_HEADERFILLHATCHNAME:
     252             :                     case CTF_PM_HEADERFILLBITMAPNAME:
     253             : 
     254             :                     case CTF_PM_FOOTERFILLGRADIENTNAME:
     255             :                     case CTF_PM_FOOTERFILLTRANSNAME:
     256             :                     case CTF_PM_FOOTERFILLHATCHNAME:
     257             :                     case CTF_PM_FOOTERFILLBITMAPNAME:
     258             :                     {
     259           0 :                         struct XMLPropertyState& rState = GetProperties()[nIndex];
     260           0 :                         rtl::OUString sStyleName;
     261           0 :                         rState.maValue >>= sStyleName;
     262             : 
     263             :                         //UUUU translate the used name from ODF intern to the name used in the Model
     264           0 :                         sStyleName = GetImport().GetStyleDisplayName(aFamilies[i%4], sStyleName);
     265             : 
     266             :                         try
     267             :                         {
     268             :                             // set property
     269           0 :                             const rtl::OUString& rPropertyName = rMapper->GetEntryAPIName(rState.mnIndex);
     270             : 
     271           0 :                             if(!xInfo.is())
     272             :                             {
     273           0 :                                 xInfo = rPropSet->getPropertySetInfo();
     274             :                             }
     275             : 
     276           0 :                             if(xInfo->hasPropertyByName(rPropertyName))
     277             :                             {
     278           0 :                                 rPropSet->setPropertyValue(rPropertyName,Any(sStyleName));
     279             :                             }
     280             :                         }
     281           0 :                         catch(::com::sun::star::lang::IllegalArgumentException& e)
     282             :                         {
     283           0 :                             Sequence< rtl::OUString > aSeq(1);
     284           0 :                             aSeq[0] = sStyleName;
     285           0 :                             GetImport().SetError(
     286             :                                 XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
     287           0 :                                 aSeq,e.Message,NULL);
     288             :                         }
     289           0 :                         break;
     290             :                     }
     291             :                 }
     292             :             }
     293        1462 :         }
     294             :     }
     295             :     else
     296             :     {
     297             :         OSL_ENSURE(xImpPrMap.is(), "Got no SvXMLImportPropertyMapper (!)");
     298             :     }
     299             : 
     300             :     //UUUU old code, replaced by above stuff
     301             :     // XMLPropStyleContext::FillPropertySet(rPropSet);
     302             : 
     303        1462 :     if (!sPageUsage.isEmpty())
     304             :     {
     305          62 :         uno::Any aPageUsage;
     306         124 :         XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
     307          62 :         if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
     308         124 :             rPropSet->setPropertyValue("PageStyleLayout", aPageUsage);
     309        1462 :     }
     310        1462 : }
     311             : 
     312             : // text grid enhancement for better CJK support
     313             : //set default page layout style
     314          60 : void PageStyleContext::SetDefaults( )
     315             : {
     316          60 :     Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
     317          60 :     if (xFactory.is())
     318             :     {
     319          60 :         Reference < XInterface > xInt = xFactory->createInstance (
     320          60 :         OUString ( "com.sun.star.text.Defaults" ) );
     321         120 :         Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
     322          60 :         if ( xProperties.is() )
     323         120 :             FillPropertySet ( xProperties );
     324          60 :     }
     325          60 : }
     326             : 
     327             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10