LCOV - code coverage report
Current view: top level - libreoffice/sw/source/filter/xml - xmlitemi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 107 53.3 %
Date: 2012-12-27 Functions: 13 15 86.7 %
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             : 
      21             : #include <rtl/ustring.hxx>
      22             : 
      23             : #include <com/sun/star/util/MeasureUnit.hpp>
      24             : 
      25             : #include <rsc/rscsfx.hxx>
      26             : 
      27             : #include <xmloff/i18nmap.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <xmloff/families.hxx>
      30             : #include <xmloff/xmlnmspe.hxx>
      31             : #include <xmloff/xmltoken.hxx>
      32             : 
      33             : #include <editeng/boxitem.hxx>
      34             : #include <editeng/fontitem.hxx>
      35             : #include <editeng/tstpitem.hxx>
      36             : #include <editeng/brshitem.hxx>
      37             : #include <editeng/langitem.hxx>
      38             : #include <editeng/memberids.hrc>
      39             : 
      40             : #include <svx/unomid.hxx>
      41             : 
      42             : #include <hintids.hxx>
      43             : #include <paratr.hxx>
      44             : #include <doc.hxx>
      45             : #include <unomid.h>
      46             : #include "xmlbrshi.hxx"
      47             : #include "xmlimp.hxx"
      48             : #include "xmlitmap.hxx"
      49             : #include "xmlimpit.hxx"
      50             : #include "xmlitem.hxx"
      51             : 
      52             : using ::rtl::OUString;
      53             : using namespace ::com::sun::star;
      54             : using namespace ::com::sun::star::uno;
      55             : 
      56             : extern SvXMLItemMapEntry aXMLTableItemMap[];
      57             : extern SvXMLItemMapEntry aXMLTableColItemMap[];
      58             : extern SvXMLItemMapEntry aXMLTableRowItemMap[];
      59             : extern SvXMLItemMapEntry aXMLTableCellItemMap[];
      60             : 
      61             : class SwXMLImportTableItemMapper_Impl: public SvXMLImportItemMapper
      62             : {
      63             : 
      64             : public:
      65             : 
      66             :     SwXMLImportTableItemMapper_Impl( SvXMLItemMapEntriesRef rMapEntries );
      67             :     virtual ~SwXMLImportTableItemMapper_Impl();
      68             : 
      69             :     virtual sal_Bool handleSpecialItem( const SvXMLItemMapEntry& rEntry,
      70             :                                 SfxPoolItem& rItem,
      71             :                                 SfxItemSet& rSet,
      72             :                                 const OUString& rValue,
      73             :                                 const SvXMLUnitConverter& rUnitConverter,
      74             :                                 const SvXMLNamespaceMap& rNamespaceMap );
      75             : 
      76             :     virtual sal_Bool
      77             :     handleNoItem(SvXMLItemMapEntry const& rEntry,
      78             :                  SfxItemSet & rSet,
      79             :                  ::rtl::OUString const& rValue,
      80             :                  SvXMLUnitConverter const& rUnitConverter,
      81             :                  SvXMLNamespaceMap const& rNamespaceMap);
      82             : 
      83             :     virtual void finished(SfxItemSet & rSet,
      84             :                           SvXMLUnitConverter const& rUnitConverter) const;
      85             : 
      86             :     virtual void setMapEntries( SvXMLItemMapEntriesRef rMapEntries );
      87             : 
      88             : private:
      89             :     void Reset();
      90             : 
      91             :     ::rtl::OUString m_FoMarginValue;
      92             :     enum { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };
      93             :     bool m_bHaveMargin[4];
      94             : };
      95             : 
      96          71 : SwXMLImportTableItemMapper_Impl::SwXMLImportTableItemMapper_Impl(
      97             :                                         SvXMLItemMapEntriesRef rMapEntries ) :
      98          71 :     SvXMLImportItemMapper( rMapEntries, RES_UNKNOWNATR_CONTAINER)
      99             : {
     100          71 :     Reset();
     101          71 : }
     102             : 
     103         142 : SwXMLImportTableItemMapper_Impl::~SwXMLImportTableItemMapper_Impl()
     104             : {
     105         142 : }
     106             : 
     107          90 : void SwXMLImportTableItemMapper_Impl::Reset()
     108             : {
     109          90 :     m_FoMarginValue = ::rtl::OUString();
     110         360 :     for (int i = 0; i < 3; ++i)
     111             :     {
     112         270 :         m_bHaveMargin[i] = false;
     113             :     }
     114          90 : }
     115             : 
     116          19 : void SwXMLImportTableItemMapper_Impl::setMapEntries(
     117             :         SvXMLItemMapEntriesRef rMapEntries )
     118             : {
     119          19 :     Reset();
     120          19 :     SvXMLImportItemMapper::setMapEntries(rMapEntries);
     121          19 : }
     122             : 
     123           1 : sal_Bool SwXMLImportTableItemMapper_Impl::handleSpecialItem(
     124             :                                         const SvXMLItemMapEntry& rEntry,
     125             :                                         SfxPoolItem& rItem,
     126             :                                         SfxItemSet& rItemSet,
     127             :                                         const OUString& rValue,
     128             :                                         const SvXMLUnitConverter& rUnitConv,
     129             :                                         const SvXMLNamespaceMap& )
     130             : {
     131           1 :     sal_Bool bRet = sal_False;
     132           1 :     sal_uInt16 nMemberId = static_cast< sal_Int16 >(rEntry.nMemberId & MID_SW_FLAG_MASK);
     133           1 :     switch( rItem.Which() )
     134             :     {
     135             :     case RES_LR_SPACE:
     136           0 :         switch (nMemberId)
     137             :         {
     138             :             case MID_L_MARGIN:
     139           0 :                 m_bHaveMargin[LEFT] = true;
     140           0 :                 break;
     141             :             case MID_R_MARGIN:
     142           0 :                 m_bHaveMargin[RIGHT] = true;
     143           0 :                 break;
     144             :         }
     145             :         bRet = SvXMLImportItemMapper::PutXMLValue(
     146           0 :                 rItem, rValue, nMemberId, rUnitConv);
     147           0 :         break;
     148             :     case RES_UL_SPACE:
     149           0 :         switch (nMemberId)
     150             :         {
     151             :             case MID_UP_MARGIN:
     152           0 :                 m_bHaveMargin[TOP] = true;
     153           0 :                 break;
     154             :             case MID_LO_MARGIN:
     155           0 :                 m_bHaveMargin[BOTTOM] = true;
     156           0 :                 break;
     157             :         }
     158             :         bRet = SvXMLImportItemMapper::PutXMLValue(
     159           0 :                 rItem, rValue, nMemberId, rUnitConv);
     160           0 :         break;
     161             :     case RES_FRM_SIZE:
     162           1 :         switch( nMemberId )
     163             :         {
     164             :         case MID_FRMSIZE_COL_WIDTH:
     165             :             // If the item is existing already, a relative value has been set
     166             :             // already that must be preserved.
     167           1 :             if( SFX_ITEM_SET != rItemSet.GetItemState( RES_FRM_SIZE,
     168           1 :                                                        sal_False ) )
     169             :                 bRet = SvXMLImportItemMapper::PutXMLValue(
     170           1 :                     rItem, rValue, nMemberId, rUnitConv );
     171           1 :             break;
     172             :         }
     173             :     }
     174             : 
     175           1 :     return bRet;
     176             : }
     177             : 
     178             : 
     179           0 : sal_Bool SwXMLImportTableItemMapper_Impl::handleNoItem(
     180             :      SvXMLItemMapEntry const& rEntry,
     181             :      SfxItemSet & rSet,
     182             :      ::rtl::OUString const& rValue,
     183             :      SvXMLUnitConverter const& rUnitConverter,
     184             :      SvXMLNamespaceMap const& rNamespaceMap)
     185             : {
     186           0 :     if ((XML_NAMESPACE_FO == rEntry.nNameSpace) &&
     187             :         (xmloff::token::XML_MARGIN == rEntry.eLocalName))
     188             :     {
     189           0 :         m_FoMarginValue = rValue;
     190           0 :         return true;
     191             :     }
     192             :     else
     193             :     {
     194             :         return SvXMLImportItemMapper::handleNoItem(
     195           0 :                 rEntry, rSet, rValue, rUnitConverter, rNamespaceMap);
     196             :     }
     197             : }
     198             : 
     199          19 : void SwXMLImportTableItemMapper_Impl::finished(
     200             :         SfxItemSet & rSet, SvXMLUnitConverter const& rUnitConverter) const
     201             : {
     202          19 :     if (!m_FoMarginValue.isEmpty())
     203             :     {
     204             :         sal_uInt16 const Ids[4][2] = {
     205             :             { RES_LR_SPACE, MID_L_MARGIN },
     206             :             { RES_LR_SPACE, MID_R_MARGIN },
     207             :             { RES_UL_SPACE, MID_UP_MARGIN },
     208             :             { RES_UL_SPACE, MID_LO_MARGIN },
     209           0 :         };
     210           0 :         for (int i = 0; i < 4; ++i)
     211             :         {
     212           0 :             if (m_bHaveMargin[i])
     213             :             {
     214           0 :                 continue; // already read fo:margin-top etc.
     215             :             }
     216             :             // first get item from itemset
     217           0 :             SfxPoolItem const* pItem = 0;
     218             :             SfxItemState eState =
     219           0 :                 rSet.GetItemState(Ids[i][0], sal_True, &pItem);
     220             : 
     221             :             // if not set, try the pool
     222           0 :             if ((SFX_ITEM_SET != eState) && (SFX_WHICH_MAX > Ids[i][0]))
     223             :             {
     224           0 :                 pItem = &rSet.GetPool()->GetDefaultItem(Ids[i][0]);
     225             :             }
     226             : 
     227             :             // do we have an item?
     228           0 :             if (eState >= SFX_ITEM_DEFAULT && pItem)
     229             :             {
     230           0 :                 SfxPoolItem *const pNewItem = pItem->Clone();
     231             :                 bool const bPut = PutXMLValue(
     232           0 :                         *pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
     233           0 :                 if (bPut)
     234             :                 {
     235           0 :                     rSet.Put(*pNewItem);
     236             :                 }
     237             :             }
     238             :             else
     239             :             {
     240             :                 OSL_ENSURE(false, "could not get item");
     241             :             }
     242             :         }
     243             :     }
     244          19 : }
     245             : 
     246             : // ---------------------------------------------------------------------
     247             : 
     248             : class SwXMLItemSetContext_Impl : public SvXMLItemSetContext
     249             : {
     250             :     SvXMLImportContextRef xBackground;
     251             : 
     252             :     using SvXMLItemSetContext::CreateChildContext;
     253             : 
     254             : public:
     255             :     SwXMLItemSetContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
     256             :                   const OUString& rLName,
     257             :                   const Reference< xml::sax::XAttributeList > & xAttrList,
     258             :                   SfxItemSet&  rItemSet,
     259             :                   SvXMLImportItemMapper & rIMapper,
     260             :                   const SvXMLUnitConverter& rUnitConv );
     261             :     virtual ~SwXMLItemSetContext_Impl();
     262             : 
     263             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
     264             :                    const ::rtl::OUString& rLocalName,
     265             :                    const ::uno::Reference< xml::sax::XAttributeList > & xAttrList,
     266             :                    SfxItemSet&  rItemSet,
     267             :                    const SvXMLItemMapEntry& rEntry,
     268             :                    const SvXMLUnitConverter& rUnitConv );
     269             : };
     270             : 
     271          19 : SwXMLItemSetContext_Impl::SwXMLItemSetContext_Impl(
     272             :                  SwXMLImport& rImport, sal_uInt16 nPrfx,
     273             :                  const OUString& rLName,
     274             :                  const Reference< xml::sax::XAttributeList > & xAttrList,
     275             :                  SfxItemSet&  _rItemSet,
     276             :                  SvXMLImportItemMapper & _rIMapper,
     277             :                  const SvXMLUnitConverter& _rUnitConv ) :
     278             :     SvXMLItemSetContext( rImport, nPrfx, rLName, xAttrList,
     279          19 :                          _rItemSet, _rIMapper, _rUnitConv )
     280             : {
     281          19 : }
     282             : 
     283          57 : SwXMLItemSetContext_Impl::~SwXMLItemSetContext_Impl()
     284             : {
     285          19 :     if( xBackground.Is() )
     286             :     {
     287             :         const SvxBrushItem& rItem =
     288           0 :             ((SwXMLBrushItemImportContext*)&xBackground)->GetItem();
     289           0 :         rItemSet.Put( rItem );
     290             :     }
     291          38 : }
     292             : 
     293           0 : SvXMLImportContext *SwXMLItemSetContext_Impl::CreateChildContext(
     294             :                    sal_uInt16 nPrefix,
     295             :                    const OUString& rLocalName,
     296             :                    const Reference< xml::sax::XAttributeList > & xAttrList,
     297             :                    SfxItemSet&  _rItemSet,
     298             :                    const SvXMLItemMapEntry& rEntry,
     299             :                    const SvXMLUnitConverter& _rUnitConv )
     300             : {
     301           0 :     SvXMLImportContext *pContext = 0;
     302             : 
     303           0 :     switch( rEntry.nWhichId )
     304             :     {
     305             :     case RES_BACKGROUND:
     306             :         {
     307             :             const SfxPoolItem *pItem;
     308           0 :             if( SFX_ITEM_SET == _rItemSet.GetItemState( RES_BACKGROUND,
     309           0 :                                                        sal_False, &pItem ) )
     310             :             {
     311             :                 pContext = new SwXMLBrushItemImportContext(
     312           0 :                                 GetImport(), nPrefix, rLocalName, xAttrList,
     313           0 :                                 _rUnitConv, *(const SvxBrushItem *)pItem );
     314             :             }
     315             :             else
     316             :             {
     317             :                 pContext = new SwXMLBrushItemImportContext(
     318           0 :                                 GetImport(), nPrefix, rLocalName, xAttrList,
     319           0 :                                 _rUnitConv, RES_BACKGROUND );
     320             :             }
     321           0 :             xBackground = pContext;
     322             :         }
     323           0 :         break;
     324             :     }
     325             : 
     326           0 :     if( !pContext )
     327             :         pContext = SvXMLItemSetContext::CreateChildContext( nPrefix, rLocalName,
     328             :                                                             xAttrList, _rItemSet,
     329           0 :                                                             rEntry, _rUnitConv );
     330             : 
     331           0 :     return pContext;
     332             : }
     333             : 
     334             : // ---------------------------------------------------------------------
     335             : 
     336          71 : void SwXMLImport::_InitItemImport()
     337             : {
     338             :     pTwipUnitConv = new SvXMLUnitConverter( getServiceFactory(),
     339          71 :             util::MeasureUnit::TWIP, util::MeasureUnit::TWIP );
     340             : 
     341          71 :     xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
     342          71 :     xTableColItemMap = new SvXMLItemMapEntries( aXMLTableColItemMap );
     343          71 :     xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
     344          71 :     xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
     345             : 
     346          71 :     pTableItemMapper = new SwXMLImportTableItemMapper_Impl( xTableItemMap );
     347          71 : }
     348             : 
     349          71 : void SwXMLImport::_FinitItemImport()
     350             : {
     351          71 :     delete pTableItemMapper;
     352          71 :     delete pTwipUnitConv;
     353          71 : }
     354             : 
     355          19 : SvXMLImportContext *SwXMLImport::CreateTableItemImportContext(
     356             :                   sal_uInt16 nPrefix,
     357             :                   const OUString& rLocalName,
     358             :                   const Reference< xml::sax::XAttributeList > & xAttrList,
     359             :                   sal_uInt16 nFamily,
     360             :                   SfxItemSet& rItemSet )
     361             : {
     362          19 :     SvXMLItemMapEntriesRef xItemMap;
     363             : 
     364          19 :     switch( nFamily )
     365             :     {
     366             :     case XML_STYLE_FAMILY_TABLE_TABLE:
     367           1 :         xItemMap = xTableItemMap;
     368           1 :         break;
     369             :     case XML_STYLE_FAMILY_TABLE_COLUMN:
     370           1 :         xItemMap = xTableColItemMap;
     371           1 :         break;
     372             :     case XML_STYLE_FAMILY_TABLE_ROW:
     373           0 :         xItemMap = xTableRowItemMap;
     374           0 :         break;
     375             :     case XML_STYLE_FAMILY_TABLE_CELL:
     376          17 :         xItemMap = xTableCellItemMap;
     377          17 :         break;
     378             :     }
     379             : 
     380          19 :     pTableItemMapper->setMapEntries( xItemMap );
     381             : 
     382             :     return new SwXMLItemSetContext_Impl( *this, nPrefix, rLocalName,
     383             :                                             xAttrList, rItemSet,
     384             :                                             GetTableItemMapper(),
     385          19 :                                             GetTwipUnitConverter() );
     386             : }
     387             : 
     388             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10