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