LCOV - code coverage report
Current view: top level - sw/source/filter/xml - xmliteme.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 65 24.6 %
Date: 2012-08-25 Functions: 5 10 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 81 17.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/util/MeasureUnit.hpp>
      31                 :            : 
      32                 :            : #include <hintids.hxx>
      33                 :            : #include <rtl/ustring.hxx>
      34                 :            : #include <rtl/ustrbuf.hxx>
      35                 :            : #include <tools/shl.hxx>
      36                 :            : #include <xmloff/xmluconv.hxx>
      37                 :            : #include "xmlexpit.hxx"
      38                 :            : #include <xmloff/nmspmap.hxx>
      39                 :            : #include <xmloff/xmltabe.hxx>
      40                 :            : #include "xmlbrshe.hxx"
      41                 :            : #include <editeng/tstpitem.hxx>
      42                 :            : #include <editeng/brshitem.hxx>
      43                 :            : #include <tools/fldunit.hxx>
      44                 :            : #include <swmodule.hxx>
      45                 :            : #include <doc.hxx>
      46                 :            : #include "fmtornt.hxx"
      47                 :            : #include <unomid.h>
      48                 :            : #include "frmfmt.hxx"
      49                 :            : #include "fmtfsize.hxx"
      50                 :            : #include "swrect.hxx"
      51                 :            : #include "xmlexp.hxx"
      52                 :            : #include <editeng/memberids.hrc>
      53                 :            : 
      54                 :            : using ::rtl::OUString;
      55                 :            : using ::rtl::OUStringBuffer;
      56                 :            : using namespace ::com::sun::star;
      57                 :            : using namespace ::com::sun::star::uno;
      58                 :            : using namespace ::xmloff::token;
      59                 :            : 
      60                 :            : extern SvXMLItemMapEntry aXMLTableItemMap[];
      61                 :            : extern SvXMLItemMapEntry aXMLTableRowItemMap[];
      62                 :            : extern SvXMLItemMapEntry aXMLTableCellItemMap[];
      63                 :            : 
      64                 :            : 
      65                 :            : class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
      66                 :            : {
      67                 :            :     SwXMLBrushItemExport aBrushItemExport;
      68                 :            : 
      69                 :            : protected:
      70                 :            : 
      71                 :            :     sal_uInt32 nAbsWidth;
      72                 :            : 
      73                 :            :     void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
      74                 :            :                        const OUString& rValue,
      75                 :            :                        const SvXMLNamespaceMap& rNamespaceMap,
      76                 :            :                        SvXMLAttributeList& rAttrList ) const;
      77                 :            : 
      78                 :            : public:
      79                 :            : 
      80                 :            :     SwXMLTableItemMapper_Impl(
      81                 :            :             SvXMLItemMapEntriesRef rMapEntries,
      82                 :            :             SwXMLExport& rExp );
      83                 :            : 
      84                 :            :     virtual ~SwXMLTableItemMapper_Impl();
      85                 :            : 
      86                 :            :     virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
      87                 :            :                                     const SvXMLItemMapEntry& rEntry,
      88                 :            :                                     const SfxPoolItem& rItem,
      89                 :            :                                     const SvXMLUnitConverter& rUnitConverter,
      90                 :            :                                     const SvXMLNamespaceMap& rNamespaceMap,
      91                 :            :                                     const SfxItemSet *pSet = NULL ) const;
      92                 :            : 
      93                 :            :     virtual void handleElementItem(
      94                 :            :             SvXMLExport& rExport,
      95                 :            :             const SvXMLItemMapEntry& rEntry,
      96                 :            :             const SfxPoolItem& rItem,
      97                 :            :             const SvXMLUnitConverter& rUnitConverter,
      98                 :            :             const SfxItemSet& rSet,
      99                 :            :             sal_uInt16 nFlags ) const;
     100                 :            : 
     101                 :            :     inline void SetAbsWidth( sal_uInt32 nAbs );
     102                 :            : };
     103                 :            : 
     104                 :         92 : SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
     105                 :            :         SvXMLItemMapEntriesRef rMapEntries,
     106                 :            :         SwXMLExport& rExp ) :
     107                 :            :     SvXMLExportItemMapper( rMapEntries ),
     108                 :            :     aBrushItemExport( rExp ),
     109 [ +  - ][ +  - ]:         92 :     nAbsWidth( USHRT_MAX )
     110                 :            : {
     111                 :         92 : }
     112                 :            : 
     113         [ +  - ]:         92 : SwXMLTableItemMapper_Impl::~SwXMLTableItemMapper_Impl()
     114                 :            : {
     115         [ -  + ]:        184 : }
     116                 :            : 
     117                 :          0 : void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
     118                 :            :         enum XMLTokenEnum eLName,
     119                 :            :         const OUString& rValue,
     120                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     121                 :            :         SvXMLAttributeList& rAttrList ) const
     122                 :            : {
     123                 :            :     OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
     124 [ #  # ][ #  # ]:          0 :                                                  GetXMLToken(eLName) ) );
     125         [ #  # ]:          0 :     rAttrList.AddAttribute( sName, rValue );
     126                 :          0 : }
     127                 :            : 
     128                 :          0 : void SwXMLTableItemMapper_Impl::handleSpecialItem(
     129                 :            :         SvXMLAttributeList& rAttrList,
     130                 :            :         const SvXMLItemMapEntry& rEntry,
     131                 :            :         const SfxPoolItem& rItem,
     132                 :            :         const SvXMLUnitConverter& rUnitConverter,
     133                 :            :         const SvXMLNamespaceMap& rNamespaceMap,
     134                 :            :         const SfxItemSet *pSet ) const
     135                 :            : {
     136      [ #  #  # ]:          0 :     switch( rEntry.nWhichId )
     137                 :            :     {
     138                 :            :     case RES_LR_SPACE:
     139                 :            :         {
     140                 :            :             const SfxPoolItem *pItem;
     141 [ #  # ][ #  # ]:          0 :             if( pSet &&
                 [ #  # ]
     142                 :            :                 SFX_ITEM_SET == pSet->GetItemState( RES_HORI_ORIENT, sal_True,
     143         [ #  # ]:          0 :                                                     &pItem ) )
     144                 :            :             {
     145                 :            :                 sal_Int16 eHoriOrient =
     146                 :          0 :                     ((const SwFmtHoriOrient *)pItem)->GetHoriOrient();
     147                 :          0 :                 sal_Bool bExport = sal_False;
     148                 :            :                 sal_uInt16 nMemberId =
     149                 :          0 :                     static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
     150      [ #  #  # ]:          0 :                 switch( nMemberId )
     151                 :            :                 {
     152                 :            :                 case MID_L_MARGIN:
     153                 :            :                     bExport = text::HoriOrientation::NONE == eHoriOrient ||
     154 [ #  # ][ #  # ]:          0 :                               text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
     155                 :          0 :                     break;
     156                 :            :                 case MID_R_MARGIN:
     157                 :          0 :                     bExport = text::HoriOrientation::NONE == eHoriOrient;
     158                 :          0 :                     break;
     159                 :            :                 }
     160                 :          0 :                 OUString sValue;
     161 [ #  # ][ #  # ]:          0 :                 if( bExport && SvXMLExportItemMapper::QueryXMLValue(
                 [ #  # ]
     162         [ #  # ]:          0 :                     rItem, sValue, nMemberId, rUnitConverter ) )
     163                 :            :                 {
     164                 :            :                     AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
     165         [ #  # ]:          0 :                                   rNamespaceMap, rAttrList );
     166                 :          0 :                 }
     167                 :            :             }
     168                 :            :         }
     169                 :          0 :         break;
     170                 :            : 
     171                 :            :     case RES_FRM_SIZE:
     172                 :            :         {
     173                 :            :             sal_uInt16 nMemberId =
     174                 :          0 :                 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
     175      [ #  #  # ]:          0 :             switch( nMemberId )
     176                 :            :             {
     177                 :            :             case MID_FRMSIZE_WIDTH:
     178         [ #  # ]:          0 :                 if( nAbsWidth )
     179                 :            :                 {
     180                 :          0 :                     OUStringBuffer sBuffer;
     181         [ #  # ]:          0 :                     rUnitConverter.convertMeasureToXML( sBuffer, nAbsWidth );
     182                 :            :                     AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
     183                 :            :                                   sBuffer.makeStringAndClear(),
     184 [ #  # ][ #  # ]:          0 :                                   rNamespaceMap, rAttrList );
     185                 :            :                 }
     186                 :          0 :                 break;
     187                 :            :             case MID_FRMSIZE_REL_WIDTH:
     188                 :            :                 {
     189                 :          0 :                     OUString sValue;
     190         [ #  # ]:          0 :                     if( SvXMLExportItemMapper::QueryXMLValue(
     191         [ #  # ]:          0 :                         rItem, sValue, nMemberId, rUnitConverter ) )
     192                 :            :                     {
     193                 :            :                         AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
     194         [ #  # ]:          0 :                                       sValue, rNamespaceMap, rAttrList );
     195                 :          0 :                     }
     196                 :            :                 }
     197                 :          0 :                 break;
     198                 :            :             }
     199                 :            :         }
     200                 :          0 :         break;
     201                 :            :     }
     202                 :          0 : }
     203                 :            : 
     204                 :            : /** this method is called for every item that has the
     205                 :            :     MID_SW_FLAG_ELEMENT_EXPORT flag set */
     206                 :          0 : void SwXMLTableItemMapper_Impl::handleElementItem(
     207                 :            :         SvXMLExport& /*rExport*/,
     208                 :            :         const SvXMLItemMapEntry& rEntry,
     209                 :            :         const SfxPoolItem& rItem,
     210                 :            :         const SvXMLUnitConverter& /*rUnitConverter*/,
     211                 :            :         const SfxItemSet&,
     212                 :            :         sal_uInt16 ) const
     213                 :            : {
     214         [ #  # ]:          0 :     switch( rEntry.nWhichId )
     215                 :            :     {
     216                 :            :     case RES_BACKGROUND:
     217                 :            :         {
     218                 :            :             ((SwXMLTableItemMapper_Impl *)this)->aBrushItemExport.exportXML(
     219                 :          0 :                                                 (const SvxBrushItem&)rItem );
     220                 :            :         }
     221                 :          0 :         break;
     222                 :            :     }
     223                 :          0 : }
     224                 :            : 
     225                 :          0 : inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
     226                 :            : {
     227                 :          0 :     nAbsWidth = nAbs;
     228                 :          0 : }
     229                 :            : 
     230                 :            : // ----------------------------------------------------------------------------
     231                 :            : 
     232                 :         92 : void SwXMLExport::_InitItemExport()
     233                 :            : {
     234                 :            :     pTwipUnitConv = new SvXMLUnitConverter(getServiceFactory(),
     235 [ +  - ][ +  - ]:         92 :         util::MeasureUnit::TWIP, GetMM100UnitConverter().GetXMLMeasureUnit());
                 [ +  - ]
     236                 :            : 
     237         [ +  - ]:         92 :     xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
     238         [ +  - ]:         92 :     xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
     239         [ +  - ]:         92 :     xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
     240                 :            : 
     241 [ +  - ][ +  - ]:         92 :     pTableItemMapper = new SwXMLTableItemMapper_Impl( xTableItemMap, *this );
     242                 :         92 : }
     243                 :            : 
     244                 :         92 : void SwXMLExport::_FinitItemExport()
     245                 :            : {
     246         [ +  - ]:         92 :     delete pTableItemMapper;
     247         [ +  - ]:         92 :     delete pTwipUnitConv;
     248                 :         92 : }
     249                 :            : 
     250                 :          0 : void SwXMLExport::ExportTableFmt( const SwFrmFmt& rFmt, sal_uInt32 nAbsWidth )
     251                 :            : {
     252                 :            :     ((SwXMLTableItemMapper_Impl *)pTableItemMapper)
     253                 :          0 :         ->SetAbsWidth( nAbsWidth );
     254                 :          0 :     ExportFmt( rFmt, XML_TABLE );
     255                 :          0 : }
     256                 :            : 
     257                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10