1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmliteme.cxx,v $
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>
49 #include "fmtornt.hxx"
54 #include "fmtfsize.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
;
77 void AddAttribute( sal_uInt16 nPrefix
, enum XMLTokenEnum eLName
,
78 const OUString
& rValue
,
79 const SvXMLNamespaceMap
& rNamespaceMap
,
80 SvXMLAttributeList
& rAttrList
) const;
84 SwXMLTableItemMapper_Impl(
85 SvXMLItemMapEntriesRef rMapEntries
,
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(
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
)
144 const SfxPoolItem
*pItem
;
146 SFX_ITEM_SET
== pSet
->GetItemState( RES_HORI_ORIENT
, sal_True
,
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
);
157 bExport
= text::HoriOrientation::NONE
== eHoriOrient
||
158 text::HoriOrientation::LEFT_AND_WIDTH
== eHoriOrient
;
161 bExport
= text::HoriOrientation::NONE
== eHoriOrient
;
165 if( bExport
&& SvXMLExportItemMapper::QueryXMLValue(
166 rItem
, sValue
, nMemberId
, rUnitConverter
) )
168 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
, sValue
,
169 rNamespaceMap
, rAttrList
);
177 sal_uInt16 nMemberId
=
178 static_cast<sal_uInt16
>( rEntry
.nMemberId
& MID_SW_FLAG_MASK
);
181 case MID_FRMSIZE_WIDTH
:
184 OUStringBuffer sBuffer
;
185 rUnitConverter
.convertMeasure( sBuffer
, nAbsWidth
);
186 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
,
187 sBuffer
.makeStringAndClear(),
188 rNamespaceMap
, rAttrList
);
191 case MID_FRMSIZE_REL_WIDTH
:
194 if( SvXMLExportItemMapper::QueryXMLValue(
195 rItem
, sValue
, nMemberId
, rUnitConverter
) )
197 AddAttribute( rEntry
.nNameSpace
, rEntry
.eLocalName
,
198 sValue
, rNamespaceMap
, rAttrList
);
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*/,
218 switch( rEntry
.nWhichId
)
222 ((SwXMLTableItemMapper_Impl
*)this)->aBrushItemExport
.exportXML(
223 (const SvxBrushItem
&)rItem
);
229 inline void SwXMLTableItemMapper_Impl::SetAbsWidth( sal_uInt32 nAbs
)
234 // ----------------------------------------------------------------------------
236 void SwXMLExport::_InitItemExport()
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
);