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

Generated by: LCOV version 1.10