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 <rtl/ustring.hxx>
31 : :
32 : : #include <com/sun/star/util/MeasureUnit.hpp>
33 : :
34 : : #include <rsc/rscsfx.hxx>
35 : :
36 : : #include <xmloff/i18nmap.hxx>
37 : : #include <xmloff/xmluconv.hxx>
38 : : #include <xmloff/families.hxx>
39 : : #include <xmloff/xmlnmspe.hxx>
40 : : #include <xmloff/xmltoken.hxx>
41 : :
42 : : #include <editeng/boxitem.hxx>
43 : : #include <editeng/fontitem.hxx>
44 : : #include <editeng/tstpitem.hxx>
45 : : #include <editeng/brshitem.hxx>
46 : : #include <editeng/langitem.hxx>
47 : : #include <editeng/memberids.hrc>
48 : :
49 : : #include <svx/unomid.hxx>
50 : :
51 : : #include <hintids.hxx>
52 : : #include <paratr.hxx>
53 : : #include <doc.hxx>
54 : : #include <unomid.h>
55 : : #include "xmlbrshi.hxx"
56 : : #include "xmlimp.hxx"
57 : : #include "xmlitmap.hxx"
58 : : #include "xmlimpit.hxx"
59 : : #include "xmlitem.hxx"
60 : :
61 : : using ::rtl::OUString;
62 : : using namespace ::com::sun::star;
63 : : using namespace ::com::sun::star::uno;
64 : :
65 : : extern SvXMLItemMapEntry aXMLTableItemMap[];
66 : : extern SvXMLItemMapEntry aXMLTableColItemMap[];
67 : : extern SvXMLItemMapEntry aXMLTableRowItemMap[];
68 : : extern SvXMLItemMapEntry aXMLTableCellItemMap[];
69 : :
70 : : class SwXMLImportTableItemMapper_Impl: public SvXMLImportItemMapper
71 : : {
72 : :
73 : : public:
74 : :
75 : : SwXMLImportTableItemMapper_Impl( SvXMLItemMapEntriesRef rMapEntries );
76 : : virtual ~SwXMLImportTableItemMapper_Impl();
77 : :
78 : : virtual sal_Bool handleSpecialItem( const SvXMLItemMapEntry& rEntry,
79 : : SfxPoolItem& rItem,
80 : : SfxItemSet& rSet,
81 : : const OUString& rValue,
82 : : const SvXMLUnitConverter& rUnitConverter,
83 : : const SvXMLNamespaceMap& rNamespaceMap );
84 : :
85 : : virtual sal_Bool
86 : : handleNoItem(SvXMLItemMapEntry const& rEntry,
87 : : SfxItemSet & rSet,
88 : : ::rtl::OUString const& rValue,
89 : : SvXMLUnitConverter const& rUnitConverter,
90 : : SvXMLNamespaceMap const& rNamespaceMap);
91 : :
92 : : virtual void finished(SfxItemSet & rSet,
93 : : SvXMLUnitConverter const& rUnitConverter) const;
94 : :
95 : : virtual void setMapEntries( SvXMLItemMapEntriesRef rMapEntries );
96 : :
97 : : private:
98 : : void Reset();
99 : :
100 : : ::rtl::OUString m_FoMarginValue;
101 : : enum { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };
102 : : bool m_bHaveMargin[4];
103 : : };
104 : :
105 : 266 : SwXMLImportTableItemMapper_Impl::SwXMLImportTableItemMapper_Impl(
106 : : SvXMLItemMapEntriesRef rMapEntries ) :
107 [ + - ]: 266 : SvXMLImportItemMapper( rMapEntries, RES_UNKNOWNATR_CONTAINER)
108 : : {
109 : 266 : Reset();
110 : 266 : }
111 : :
112 : 266 : SwXMLImportTableItemMapper_Impl::~SwXMLImportTableItemMapper_Impl()
113 : : {
114 [ - + ]: 532 : }
115 : :
116 : 323 : void SwXMLImportTableItemMapper_Impl::Reset()
117 : : {
118 : 323 : m_FoMarginValue = ::rtl::OUString();
119 [ + + ]: 1292 : for (int i = 0; i < 3; ++i)
120 : : {
121 : 969 : m_bHaveMargin[i] = false;
122 : : }
123 : 323 : }
124 : :
125 : 57 : void SwXMLImportTableItemMapper_Impl::setMapEntries(
126 : : SvXMLItemMapEntriesRef rMapEntries )
127 : : {
128 : 57 : Reset();
129 [ + - ]: 57 : SvXMLImportItemMapper::setMapEntries(rMapEntries);
130 : 57 : }
131 : :
132 : 3 : sal_Bool SwXMLImportTableItemMapper_Impl::handleSpecialItem(
133 : : const SvXMLItemMapEntry& rEntry,
134 : : SfxPoolItem& rItem,
135 : : SfxItemSet& rItemSet,
136 : : const OUString& rValue,
137 : : const SvXMLUnitConverter& rUnitConv,
138 : : const SvXMLNamespaceMap& )
139 : : {
140 : 3 : sal_Bool bRet = sal_False;
141 : 3 : sal_uInt16 nMemberId = static_cast< sal_Int16 >(rEntry.nMemberId & MID_SW_FLAG_MASK);
142 [ - - + - ]: 3 : switch( rItem.Which() )
143 : : {
144 : : case RES_LR_SPACE:
145 [ # # # ]: 0 : switch (nMemberId)
146 : : {
147 : : case MID_L_MARGIN:
148 : 0 : m_bHaveMargin[LEFT] = true;
149 : 0 : break;
150 : : case MID_R_MARGIN:
151 : 0 : m_bHaveMargin[RIGHT] = true;
152 : 0 : break;
153 : : }
154 : : bRet = SvXMLImportItemMapper::PutXMLValue(
155 : 0 : rItem, rValue, nMemberId, rUnitConv);
156 : 0 : break;
157 : : case RES_UL_SPACE:
158 [ # # # ]: 0 : switch (nMemberId)
159 : : {
160 : : case MID_UP_MARGIN:
161 : 0 : m_bHaveMargin[TOP] = true;
162 : 0 : break;
163 : : case MID_LO_MARGIN:
164 : 0 : m_bHaveMargin[BOTTOM] = true;
165 : 0 : break;
166 : : }
167 : : bRet = SvXMLImportItemMapper::PutXMLValue(
168 : 0 : rItem, rValue, nMemberId, rUnitConv);
169 : 0 : break;
170 : : case RES_FRM_SIZE:
171 [ + - ]: 3 : switch( nMemberId )
172 : : {
173 : : case MID_FRMSIZE_COL_WIDTH:
174 : : // If the item is existing already, a relative value has been set
175 : : // already that must be preserved.
176 [ + - ]: 3 : if( SFX_ITEM_SET != rItemSet.GetItemState( RES_FRM_SIZE,
177 : 3 : sal_False ) )
178 : : bRet = SvXMLImportItemMapper::PutXMLValue(
179 : 3 : rItem, rValue, nMemberId, rUnitConv );
180 : 3 : break;
181 : : }
182 : : }
183 : :
184 : 3 : return bRet;
185 : : }
186 : :
187 : :
188 : 0 : sal_Bool SwXMLImportTableItemMapper_Impl::handleNoItem(
189 : : SvXMLItemMapEntry const& rEntry,
190 : : SfxItemSet & rSet,
191 : : ::rtl::OUString const& rValue,
192 : : SvXMLUnitConverter const& rUnitConverter,
193 : : SvXMLNamespaceMap const& rNamespaceMap)
194 : : {
195 [ # # ][ # # ]: 0 : if ((XML_NAMESPACE_FO == rEntry.nNameSpace) &&
196 : : (xmloff::token::XML_MARGIN == rEntry.eLocalName))
197 : : {
198 : 0 : m_FoMarginValue = rValue;
199 : 0 : return true;
200 : : }
201 : : else
202 : : {
203 : : return SvXMLImportItemMapper::handleNoItem(
204 : 0 : rEntry, rSet, rValue, rUnitConverter, rNamespaceMap);
205 : : }
206 : : }
207 : :
208 : 57 : void SwXMLImportTableItemMapper_Impl::finished(
209 : : SfxItemSet & rSet, SvXMLUnitConverter const& rUnitConverter) const
210 : : {
211 [ - + ]: 57 : if (!m_FoMarginValue.isEmpty())
212 : : {
213 : : sal_uInt16 const Ids[4][2] = {
214 : : { RES_LR_SPACE, MID_L_MARGIN },
215 : : { RES_LR_SPACE, MID_R_MARGIN },
216 : : { RES_UL_SPACE, MID_UP_MARGIN },
217 : : { RES_UL_SPACE, MID_LO_MARGIN },
218 : 0 : };
219 [ # # ]: 0 : for (int i = 0; i < 4; ++i)
220 : : {
221 [ # # ]: 0 : if (m_bHaveMargin[i])
222 : : {
223 : 0 : continue; // already read fo:margin-top etc.
224 : : }
225 : : // first get item from itemset
226 : 0 : SfxPoolItem const* pItem = 0;
227 : : SfxItemState eState =
228 [ # # ]: 0 : rSet.GetItemState(Ids[i][0], sal_True, &pItem);
229 : :
230 : : // if not set, try the pool
231 [ # # ][ # # ]: 0 : if ((SFX_ITEM_SET != eState) && (SFX_WHICH_MAX > Ids[i][0]))
232 : : {
233 [ # # ]: 0 : pItem = &rSet.GetPool()->GetDefaultItem(Ids[i][0]);
234 : : }
235 : :
236 : : // do we have an item?
237 [ # # ][ # # ]: 0 : if (eState >= SFX_ITEM_DEFAULT && pItem)
238 : : {
239 [ # # ]: 0 : SfxPoolItem *const pNewItem = pItem->Clone();
240 : : bool const bPut = PutXMLValue(
241 [ # # ]: 0 : *pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
242 [ # # ]: 0 : if (bPut)
243 : : {
244 [ # # ]: 0 : rSet.Put(*pNewItem);
245 : : }
246 : : }
247 : : else
248 : : {
249 : : OSL_ENSURE(false, "could not get item");
250 : : }
251 : : }
252 : : }
253 : 57 : }
254 : :
255 : : // ---------------------------------------------------------------------
256 : :
257 : : class SwXMLItemSetContext_Impl : public SvXMLItemSetContext
258 : : {
259 : : SvXMLImportContextRef xBackground;
260 : :
261 : : using SvXMLItemSetContext::CreateChildContext;
262 : :
263 : : public:
264 : : SwXMLItemSetContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
265 : : const OUString& rLName,
266 : : const Reference< xml::sax::XAttributeList > & xAttrList,
267 : : SfxItemSet& rItemSet,
268 : : SvXMLImportItemMapper & rIMapper,
269 : : const SvXMLUnitConverter& rUnitConv );
270 : : virtual ~SwXMLItemSetContext_Impl();
271 : :
272 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
273 : : const ::rtl::OUString& rLocalName,
274 : : const ::uno::Reference< xml::sax::XAttributeList > & xAttrList,
275 : : SfxItemSet& rItemSet,
276 : : const SvXMLItemMapEntry& rEntry,
277 : : const SvXMLUnitConverter& rUnitConv );
278 : : };
279 : :
280 : 57 : SwXMLItemSetContext_Impl::SwXMLItemSetContext_Impl(
281 : : SwXMLImport& rImport, sal_uInt16 nPrfx,
282 : : const OUString& rLName,
283 : : const Reference< xml::sax::XAttributeList > & xAttrList,
284 : : SfxItemSet& _rItemSet,
285 : : SvXMLImportItemMapper & _rIMapper,
286 : : const SvXMLUnitConverter& _rUnitConv ) :
287 : : SvXMLItemSetContext( rImport, nPrfx, rLName, xAttrList,
288 : 57 : _rItemSet, _rIMapper, _rUnitConv )
289 : : {
290 : 57 : }
291 : :
292 [ + - ]: 57 : SwXMLItemSetContext_Impl::~SwXMLItemSetContext_Impl()
293 : : {
294 [ - + ]: 57 : if( xBackground.Is() )
295 : : {
296 : : const SvxBrushItem& rItem =
297 : 0 : ((SwXMLBrushItemImportContext*)&xBackground)->GetItem();
298 [ # # ]: 0 : rItemSet.Put( rItem );
299 : : }
300 [ - + ]: 114 : }
301 : :
302 : 0 : SvXMLImportContext *SwXMLItemSetContext_Impl::CreateChildContext(
303 : : sal_uInt16 nPrefix,
304 : : const OUString& rLocalName,
305 : : const Reference< xml::sax::XAttributeList > & xAttrList,
306 : : SfxItemSet& _rItemSet,
307 : : const SvXMLItemMapEntry& rEntry,
308 : : const SvXMLUnitConverter& _rUnitConv )
309 : : {
310 : 0 : SvXMLImportContext *pContext = 0;
311 : :
312 [ # # ]: 0 : switch( rEntry.nWhichId )
313 : : {
314 : : case RES_BACKGROUND:
315 : : {
316 : : const SfxPoolItem *pItem;
317 [ # # ]: 0 : if( SFX_ITEM_SET == _rItemSet.GetItemState( RES_BACKGROUND,
318 [ # # ]: 0 : sal_False, &pItem ) )
319 : : {
320 : : pContext = new SwXMLBrushItemImportContext(
321 : 0 : GetImport(), nPrefix, rLocalName, xAttrList,
322 [ # # ][ # # ]: 0 : _rUnitConv, *(const SvxBrushItem *)pItem );
323 : : }
324 : : else
325 : : {
326 : : pContext = new SwXMLBrushItemImportContext(
327 : 0 : GetImport(), nPrefix, rLocalName, xAttrList,
328 [ # # ][ # # ]: 0 : _rUnitConv, RES_BACKGROUND );
329 : : }
330 [ # # ]: 0 : xBackground = pContext;
331 : : }
332 : 0 : break;
333 : : }
334 : :
335 [ # # ]: 0 : if( !pContext )
336 : : pContext = SvXMLItemSetContext::CreateChildContext( nPrefix, rLocalName,
337 : : xAttrList, _rItemSet,
338 : 0 : rEntry, _rUnitConv );
339 : :
340 : 0 : return pContext;
341 : : }
342 : :
343 : : // ---------------------------------------------------------------------
344 : :
345 : 266 : void SwXMLImport::_InitItemImport()
346 : : {
347 : : pTwipUnitConv = new SvXMLUnitConverter( getServiceFactory(),
348 [ + - ][ + - ]: 266 : util::MeasureUnit::TWIP, util::MeasureUnit::TWIP );
349 : :
350 [ + - ]: 266 : xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
351 [ + - ]: 266 : xTableColItemMap = new SvXMLItemMapEntries( aXMLTableColItemMap );
352 [ + - ]: 266 : xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
353 [ + - ]: 266 : xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
354 : :
355 [ + - ][ + - ]: 266 : pTableItemMapper = new SwXMLImportTableItemMapper_Impl( xTableItemMap );
356 : 266 : }
357 : :
358 : 266 : void SwXMLImport::_FinitItemImport()
359 : : {
360 [ + - ]: 266 : delete pTableItemMapper;
361 [ + - ]: 266 : delete pTwipUnitConv;
362 : 266 : }
363 : :
364 : 57 : SvXMLImportContext *SwXMLImport::CreateTableItemImportContext(
365 : : sal_uInt16 nPrefix,
366 : : const OUString& rLocalName,
367 : : const Reference< xml::sax::XAttributeList > & xAttrList,
368 : : sal_uInt16 nFamily,
369 : : SfxItemSet& rItemSet )
370 : : {
371 : 57 : SvXMLItemMapEntriesRef xItemMap;
372 : :
373 [ + + - + : 57 : switch( nFamily )
- ]
374 : : {
375 : : case XML_STYLE_FAMILY_TABLE_TABLE:
376 [ + - ]: 3 : xItemMap = xTableItemMap;
377 : 3 : break;
378 : : case XML_STYLE_FAMILY_TABLE_COLUMN:
379 [ + - ]: 3 : xItemMap = xTableColItemMap;
380 : 3 : break;
381 : : case XML_STYLE_FAMILY_TABLE_ROW:
382 [ # # ]: 0 : xItemMap = xTableRowItemMap;
383 : 0 : break;
384 : : case XML_STYLE_FAMILY_TABLE_CELL:
385 [ + - ]: 51 : xItemMap = xTableCellItemMap;
386 : 51 : break;
387 : : }
388 : :
389 [ + - ][ + - ]: 57 : pTableItemMapper->setMapEntries( xItemMap );
390 : :
391 : : return new SwXMLItemSetContext_Impl( *this, nPrefix, rLocalName,
392 : : xAttrList, rItemSet,
393 : : GetTableItemMapper(),
394 [ + - ][ + - ]: 57 : GetTwipUnitConverter() );
[ + - ]
395 : : }
396 : :
397 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|