update dev300-m58
[ooovba.git] / sw / source / filter / xml / xmliteme.cxx
blob63ca631f1af5eca24eb5c0cb635091d5bef1d953
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmliteme.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <rtl/ustring.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <tools/shl.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include "xmlexpit.hxx"
41 #include <xmloff/nmspmap.hxx>
42 #include <xmloff/xmltabe.hxx>
43 #include "xmlbrshe.hxx"
44 #include <svx/tstpitem.hxx>
45 #include <svx/brshitem.hxx>
46 #include <vcl/fldunit.hxx>
47 #include <swmodule.hxx>
48 #include <doc.hxx>
49 #include "fmtornt.hxx"
50 #ifndef _UNOMID_H
51 #include <unomid.h>
52 #endif
53 #include "frmfmt.hxx"
54 #include "fmtfsize.hxx"
55 #include "swrect.hxx"
56 #include "xmlexp.hxx"
58 using ::rtl::OUString;
59 using ::rtl::OUStringBuffer;
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::xmloff::token;
64 extern SvXMLItemMapEntry aXMLTableItemMap[];
65 extern SvXMLItemMapEntry aXMLTableRowItemMap[];
66 extern SvXMLItemMapEntry aXMLTableCellItemMap[];
69 class SwXMLTableItemMapper_Impl: public SvXMLExportItemMapper
71 SwXMLBrushItemExport aBrushItemExport;
73 protected:
75 sal_uInt32 nAbsWidth;
77 void AddAttribute( sal_uInt16 nPrefix, enum XMLTokenEnum eLName,
78 const OUString& rValue,
79 const SvXMLNamespaceMap& rNamespaceMap,
80 SvXMLAttributeList& rAttrList ) const;
82 public:
84 SwXMLTableItemMapper_Impl(
85 SvXMLItemMapEntriesRef rMapEntries,
86 SwXMLExport& rExp );
88 virtual ~SwXMLTableItemMapper_Impl();
90 virtual void handleSpecialItem( SvXMLAttributeList& rAttrList,
91 const SvXMLItemMapEntry& rEntry,
92 const SfxPoolItem& rItem,
93 const SvXMLUnitConverter& rUnitConverter,
94 const SvXMLNamespaceMap& rNamespaceMap,
95 const SfxItemSet *pSet = NULL ) const;
97 virtual void handleElementItem(
98 SvXMLExport& rExport,
99 const SvXMLItemMapEntry& rEntry,
100 const SfxPoolItem& rItem,
101 const SvXMLUnitConverter& rUnitConverter,
102 const SfxItemSet& rSet,
103 sal_uInt16 nFlags ) const;
105 inline void SetAbsWidth( sal_uInt32 nAbs );
108 SwXMLTableItemMapper_Impl::SwXMLTableItemMapper_Impl(
109 SvXMLItemMapEntriesRef rMapEntries,
110 SwXMLExport& rExp ) :
111 SvXMLExportItemMapper( rMapEntries ),
112 aBrushItemExport( rExp ),
113 nAbsWidth( USHRT_MAX )
117 SwXMLTableItemMapper_Impl::~SwXMLTableItemMapper_Impl()
121 void SwXMLTableItemMapper_Impl::AddAttribute( sal_uInt16 nPrefix,
122 enum XMLTokenEnum eLName,
123 const OUString& rValue,
124 const SvXMLNamespaceMap& rNamespaceMap,
125 SvXMLAttributeList& rAttrList ) const
127 OUString sName( rNamespaceMap.GetQNameByKey( nPrefix,
128 GetXMLToken(eLName) ) );
129 rAttrList.AddAttribute( sName, rValue );
132 void SwXMLTableItemMapper_Impl::handleSpecialItem(
133 SvXMLAttributeList& rAttrList,
134 const SvXMLItemMapEntry& rEntry,
135 const SfxPoolItem& rItem,
136 const SvXMLUnitConverter& rUnitConverter,
137 const SvXMLNamespaceMap& rNamespaceMap,
138 const SfxItemSet *pSet ) const
140 switch( rEntry.nWhichId )
142 case RES_LR_SPACE:
144 const SfxPoolItem *pItem;
145 if( pSet &&
146 SFX_ITEM_SET == pSet->GetItemState( RES_HORI_ORIENT, sal_True,
147 &pItem ) )
149 sal_Int16 eHoriOrient =
150 ((const SwFmtHoriOrient *)pItem)->GetHoriOrient();
151 sal_Bool bExport = sal_False;
152 sal_uInt16 nMemberId =
153 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
154 switch( nMemberId )
156 case MID_L_MARGIN:
157 bExport = text::HoriOrientation::NONE == eHoriOrient ||
158 text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient;
159 break;
160 case MID_R_MARGIN:
161 bExport = text::HoriOrientation::NONE == eHoriOrient;
162 break;
164 OUString sValue;
165 if( bExport && SvXMLExportItemMapper::QueryXMLValue(
166 rItem, sValue, nMemberId, rUnitConverter ) )
168 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName, sValue,
169 rNamespaceMap, rAttrList );
173 break;
175 case RES_FRM_SIZE:
177 sal_uInt16 nMemberId =
178 static_cast<sal_uInt16>( rEntry.nMemberId & MID_SW_FLAG_MASK );
179 switch( nMemberId )
181 case MID_FRMSIZE_WIDTH:
182 if( nAbsWidth )
184 OUStringBuffer sBuffer;
185 rUnitConverter.convertMeasure( sBuffer, nAbsWidth );
186 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
187 sBuffer.makeStringAndClear(),
188 rNamespaceMap, rAttrList );
190 break;
191 case MID_FRMSIZE_REL_WIDTH:
193 OUString sValue;
194 if( SvXMLExportItemMapper::QueryXMLValue(
195 rItem, sValue, nMemberId, rUnitConverter ) )
197 AddAttribute( rEntry.nNameSpace, rEntry.eLocalName,
198 sValue, rNamespaceMap, rAttrList );
201 break;
204 break;
208 /** this method is called for every item that has the
209 MID_SW_FLAG_ELEMENT_EXPORT flag set */
210 void SwXMLTableItemMapper_Impl::handleElementItem(
211 SvXMLExport& /*rExport*/,
212 const SvXMLItemMapEntry& rEntry,
213 const SfxPoolItem& rItem,
214 const SvXMLUnitConverter& /*rUnitConverter*/,
215 const SfxItemSet&,
216 sal_uInt16 ) const
218 switch( rEntry.nWhichId )
220 case RES_BACKGROUND:
222 ((SwXMLTableItemMapper_Impl *)this)->aBrushItemExport.exportXML(
223 (const SvxBrushItem&)rItem );
225 break;
229 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs )
231 nAbsWidth = nAbs;
234 // ----------------------------------------------------------------------------
236 void SwXMLExport::_InitItemExport()
238 // #110680#
239 pTwipUnitConv = new SvXMLUnitConverter( MAP_TWIP,
240 GetMM100UnitConverter().getXMLMeasureUnit(), getServiceFactory() );
242 xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
243 xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
244 xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
246 pTableItemMapper = new SwXMLTableItemMapper_Impl( xTableItemMap, *this );
249 void SwXMLExport::_FinitItemExport()
251 delete pTableItemMapper;
252 delete pTwipUnitConv;
255 void SwXMLExport::ExportTableFmt( const SwFrmFmt& rFmt, sal_uInt32 nAbsWidth )
257 ((SwXMLTableItemMapper_Impl *)pTableItemMapper)
258 ->SetAbsWidth( nAbsWidth );
259 ExportFmt( rFmt, XML_TABLE );