LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmliteme.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 16 66 24.2 %
Date: 2014-04-11 Functions: 5 10 50.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 <com/sun/star/util/MeasureUnit.hpp>
      21             : 
      22             : #include <hintids.hxx>
      23             : #include <rtl/ustring.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <tools/shl.hxx>
      26             : #include <xmloff/xmluconv.hxx>
      27             : #include "xmlexpit.hxx"
      28             : #include <xmloff/nmspmap.hxx>
      29             : #include <xmloff/xmltabe.hxx>
      30             : #include "xmlbrshe.hxx"
      31             : #include <editeng/tstpitem.hxx>
      32             : #include <editeng/brushitem.hxx>
      33             : #include <tools/fldunit.hxx>
      34             : #include <swmodule.hxx>
      35             : #include <doc.hxx>
      36             : #include "fmtornt.hxx"
      37             : #include <unomid.h>
      38             : #include "frmfmt.hxx"
      39             : #include "fmtfsize.hxx"
      40             : #include "swrect.hxx"
      41             : #include "xmlexp.hxx"
      42             : #include <editeng/memberids.hrc>
      43             : #include <comphelper/processfactory.hxx>
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace ::com::sun::star::uno;
      47             : using namespace ::xmloff::token;
      48             : 
      49             : extern SvXMLItemMapEntry aXMLTableItemMap[];
      50             : extern SvXMLItemMapEntry aXMLTableRowItemMap[];
      51             : extern SvXMLItemMapEntry aXMLTableCellItemMap[];
      52             : 
      53             : class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
      54             : {
      55             :     SwXMLBrushItemExport aBrushItemExport;
      56             : 
      57             : protected:
      58             : 
      59             :     sal_uInt32 nAbsWidth;
      60             : 
      61             :     void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
      62             :                        const OUString& rValue,
      63             :                        const SvXMLNamespaceMap& rNamespaceMap,
      64             :                        SvXMLAttributeList& rAttrList ) const;
      65             : 
      66             : public:
      67             : 
      68             :     SwXMLTableItemMapper_Impl(
      69             :             SvXMLItemMapEntriesRef rMapEntries,
      70             :             SwXMLExport& rExp );
      71             : 
      72             :     virtual ~SwXMLTableItemMapper_Impl();
      73             : 
      74             :     virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
      75             :                                     const SvXMLItemMapEntry& rEntry,
      76             :                                     const SfxPoolItem& rItem,
      77             :                                     const SvXMLUnitConverter& rUnitConverter,
      78             :                                     const SvXMLNamespaceMap& rNamespaceMap,
      79             :                                     const SfxItemSet *pSet = NULL ) const SAL_OVERRIDE;
      80             : 
      81             :     virtual void handleElementItem(
      82             :             SvXMLExport& rExport,
      83             :             const SvXMLItemMapEntry& rEntry,
      84             :             const SfxPoolItem& rItem,
      85             :             const SvXMLUnitConverter& rUnitConverter,
      86             :             const SfxItemSet& rSet,
      87             :             sal_uInt16 nFlags ) const SAL_OVERRIDE;
      88             : 
      89             :     inline void SetAbsWidth( sal_uInt32 nAbs );
      90             : };
      91             : 
      92          88 : SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
      93             :         SvXMLItemMapEntriesRef rMapEntries,
      94             :         SwXMLExport& rExp ) :
      95             :     SvXMLExportItemMapper( rMapEntries ),
      96             :     aBrushItemExport( rExp ),
      97          88 :     nAbsWidth( USHRT_MAX )
      98             : {
      99          88 : }
     100             : 
     101         176 : SwXMLTableItemMapper_Impl::~SwXMLTableItemMapper_Impl()
     102             : {
     103         176 : }
     104             : 
     105           0 : void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
     106             :         enum XMLTokenEnum eLName,
     107             :         const OUString& rValue,
     108             :         const SvXMLNamespaceMap& rNamespaceMap,
     109             :         SvXMLAttributeList& rAttrList ) const
     110             : {
     111             :     OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
     112           0 :                                                  GetXMLToken(eLName) ) );
     113           0 :     rAttrList.AddAttribute( sName, rValue );
     114           0 : }
     115             : 
     116           0 : void SwXMLTableItemMapper_Impl::handleSpecialItem(
     117             :         SvXMLAttributeList& rAttrList,
     118             :         const SvXMLItemMapEntry& rEntry,
     119             :         const SfxPoolItem& rItem,
     120             :         const SvXMLUnitConverter& rUnitConverter,
     121             :         const SvXMLNamespaceMap& rNamespaceMap,
     122             :         const SfxItemSet *pSet ) const
     123             : {
     124           0 :     switch( rEntry.nWhichId )
     125             :     {
     126             :     case RES_LR_SPACE:
     127             :         {
     128             :             const SfxPoolItem *pItem;
     129           0 :             if( pSet &&
     130             :                 SFX_ITEM_SET == pSet->GetItemState( RES_HORI_ORIENT, true,
     131           0 :                                                     &pItem ) )
     132             :             {
     133             :                 sal_Int16 eHoriOrient =
     134           0 :                     ((const SwFmtHoriOrient *)pItem)->GetHoriOrient();
     135           0 :                 bool bExport = false;
     136             :                 sal_uInt16 nMemberId =
     137           0 :                     static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
     138           0 :                 switch( nMemberId )
     139             :                 {
     140             :                 case MID_L_MARGIN:
     141           0 :                     bExport = text::HoriOrientation::NONE == eHoriOrient ||
     142           0 :                               text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
     143           0 :                     break;
     144             :                 case MID_R_MARGIN:
     145           0 :                     bExport = text::HoriOrientation::NONE == eHoriOrient;
     146           0 :                     break;
     147             :                 }
     148           0 :                 OUString sValue;
     149           0 :                 if( bExport && SvXMLExportItemMapper::QueryXMLValue(
     150           0 :                     rItem, sValue, nMemberId, rUnitConverter ) )
     151             :                 {
     152             :                     AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
     153           0 :                                   rNamespaceMap, rAttrList );
     154           0 :                 }
     155             :             }
     156             :         }
     157           0 :         break;
     158             : 
     159             :     case RES_FRM_SIZE:
     160             :         {
     161             :             sal_uInt16 nMemberId =
     162           0 :                 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
     163           0 :             switch( nMemberId )
     164             :             {
     165             :             case MID_FRMSIZE_WIDTH:
     166           0 :                 if( nAbsWidth )
     167             :                 {
     168           0 :                     OUStringBuffer sBuffer;
     169           0 :                     rUnitConverter.convertMeasureToXML( sBuffer, nAbsWidth );
     170             :                     AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
     171             :                                   sBuffer.makeStringAndClear(),
     172           0 :                                   rNamespaceMap, rAttrList );
     173             :                 }
     174           0 :                 break;
     175             :             case MID_FRMSIZE_REL_WIDTH:
     176             :                 {
     177           0 :                     OUString sValue;
     178           0 :                     if( SvXMLExportItemMapper::QueryXMLValue(
     179           0 :                         rItem, sValue, nMemberId, rUnitConverter ) )
     180             :                     {
     181             :                         AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
     182           0 :                                       sValue, rNamespaceMap, rAttrList );
     183           0 :                     }
     184             :                 }
     185           0 :                 break;
     186             :             }
     187             :         }
     188           0 :         break;
     189             :     }
     190           0 : }
     191             : 
     192             : /** this method is called for every item that has the
     193             :     MID_SW_FLAG_ELEMENT_EXPORT flag set */
     194           0 : void SwXMLTableItemMapper_Impl::handleElementItem(
     195             :         SvXMLExport& /*rExport*/,
     196             :         const SvXMLItemMapEntry& rEntry,
     197             :         const SfxPoolItem& rItem,
     198             :         const SvXMLUnitConverter& /*rUnitConverter*/,
     199             :         const SfxItemSet&,
     200             :         sal_uInt16 ) const
     201             : {
     202           0 :     switch( rEntry.nWhichId )
     203             :     {
     204             :     case RES_BACKGROUND:
     205             :         {
     206             :             ((SwXMLTableItemMapper_Impl *)this)->aBrushItemExport.exportXML(
     207           0 :                                                 (const SvxBrushItem&)rItem );
     208             :         }
     209           0 :         break;
     210             :     }
     211           0 : }
     212             : 
     213           0 : inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
     214             : {
     215           0 :     nAbsWidth = nAbs;
     216           0 : }
     217             : 
     218          88 : void SwXMLExport::_InitItemExport()
     219             : {
     220             :     pTwipUnitConv = new SvXMLUnitConverter(getComponentContext(),
     221          88 :         util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit());
     222             : 
     223          88 :     xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
     224          88 :     xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
     225          88 :     xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
     226             : 
     227          88 :     pTableItemMapper = new SwXMLTableItemMapper_Impl( xTableItemMap, *this );
     228          88 : }
     229             : 
     230          88 : void SwXMLExport::_FinitItemExport()
     231             : {
     232          88 :     delete pTableItemMapper;
     233          88 :     delete pTwipUnitConv;
     234          88 : }
     235             : 
     236           0 : void SwXMLExport::ExportTableFmt( const SwFrmFmt& rFmt, sal_uInt32 nAbsWidth )
     237             : {
     238             :     ((SwXMLTableItemMapper_Impl *)pTableItemMapper)
     239           0 :         ->SetAbsWidth( nAbsWidth );
     240           0 :     ExportFmt( rFmt, XML_TABLE );
     241           0 : }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10