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

Generated by: LCOV version 1.11