LibreOffice Module sw (master)  1
xmlitemi.cxx
Go to the documentation of this file.
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 #include <rtl/ustring.hxx>
21 #include <osl/diagnose.h>
22 
23 #include <com/sun/star/util/MeasureUnit.hpp>
24 
25 #include <svl/style.hxx>
26 
27 #include <xmloff/i18nmap.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/families.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/xmltoken.hxx>
32 
33 #include <editeng/boxitem.hxx>
34 #include <editeng/fontitem.hxx>
35 #include <editeng/tstpitem.hxx>
36 #include <editeng/brushitem.hxx>
37 #include <editeng/langitem.hxx>
38 #include <editeng/memberids.h>
39 
40 #include <svx/unomid.hxx>
41 
42 #include <hintids.hxx>
43 #include <paratr.hxx>
44 #include <doc.hxx>
45 #include <unomid.h>
46 #include "xmlbrshi.hxx"
47 #include "xmlimp.hxx"
48 #include "xmlitmap.hxx"
49 #include "xmlimpit.hxx"
50 #include "xmlitem.hxx"
51 
52 using namespace ::com::sun::star;
53 using namespace ::com::sun::star::uno;
54 
56 {
57 
58 public:
59 
60  explicit SwXMLImportTableItemMapper_Impl(const SvXMLItemMapEntriesRef& rMapEntries);
61 
62  virtual bool handleSpecialItem( const SvXMLItemMapEntry& rEntry,
63  SfxPoolItem& rItem,
64  SfxItemSet& rSet,
65  const OUString& rValue,
66  const SvXMLUnitConverter& rUnitConverter ) override;
67 
68  virtual bool
69  handleNoItem(SvXMLItemMapEntry const& rEntry,
70  SfxItemSet & rSet,
71  OUString const& rValue,
72  SvXMLUnitConverter const& rUnitConverter,
73  SvXMLNamespaceMap const& rNamespaceMap) override;
74 
75  virtual void finished(SfxItemSet & rSet,
76  SvXMLUnitConverter const& rUnitConverter) const override;
77 
78  virtual void setMapEntries( SvXMLItemMapEntriesRef rMapEntries ) override;
79 
80 private:
81  void Reset();
82 
83  OUString m_FoMarginValue;
84  enum { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };
85  bool m_bHaveMargin[4];
86 };
87 
89  const SvXMLItemMapEntriesRef& rMapEntries ) :
90  SvXMLImportItemMapper( rMapEntries )
91 {
92  Reset();
93 }
94 
96 {
97  m_FoMarginValue.clear();
98  for (int i = 0; i < 3; ++i)
99  {
100  m_bHaveMargin[i] = false;
101  }
102 }
103 
105  SvXMLItemMapEntriesRef rMapEntries )
106 {
107  Reset();
109 }
110 
112  const SvXMLItemMapEntry& rEntry,
113  SfxPoolItem& rItem,
114  SfxItemSet& rItemSet,
115  const OUString& rValue,
116  const SvXMLUnitConverter& rUnitConv )
117 {
118  bool bRet = false;
119  sal_uInt16 nMemberId = static_cast< sal_Int16 >(rEntry.nMemberId & MID_SW_FLAG_MASK);
120  switch( rItem.Which() )
121  {
122  case RES_LR_SPACE:
123  switch (nMemberId)
124  {
125  case MID_L_MARGIN:
126  m_bHaveMargin[LEFT] = true;
127  break;
128  case MID_R_MARGIN:
129  m_bHaveMargin[RIGHT] = true;
130  break;
131  }
133  rItem, rValue, nMemberId, rUnitConv);
134  break;
135  case RES_UL_SPACE:
136  switch (nMemberId)
137  {
138  case MID_UP_MARGIN:
139  m_bHaveMargin[TOP] = true;
140  break;
141  case MID_LO_MARGIN:
142  m_bHaveMargin[BOTTOM] = true;
143  break;
144  }
146  rItem, rValue, nMemberId, rUnitConv);
147  break;
148  case RES_FRM_SIZE:
149  switch( nMemberId )
150  {
152  // If the item is existing already, a relative value has been set
153  // already that must be preserved.
154  if( SfxItemState::SET != rItemSet.GetItemState( RES_FRM_SIZE,
155  false ) )
157  rItem, rValue, nMemberId, rUnitConv );
158  break;
159  }
160  }
161 
162  return bRet;
163 }
164 
166  SvXMLItemMapEntry const& rEntry,
167  SfxItemSet & rSet,
168  OUString const& rValue,
169  SvXMLUnitConverter const& rUnitConverter,
170  SvXMLNamespaceMap const& rNamespaceMap)
171 {
172  if ((XML_NAMESPACE_FO == rEntry.nNameSpace) &&
174  {
175  m_FoMarginValue = rValue;
176  return true;
177  }
178  else
179  {
181  rEntry, rSet, rValue, rUnitConverter, rNamespaceMap);
182  }
183 }
184 
186  SfxItemSet & rSet, SvXMLUnitConverter const& rUnitConverter) const
187 {
188  if (!m_FoMarginValue.isEmpty())
189  {
190  sal_uInt16 const Ids[4][2] = {
195  };
196  for (int i = 0; i < 4; ++i)
197  {
198  if (m_bHaveMargin[i])
199  {
200  continue; // already read fo:margin-top etc.
201  }
202  // first get item from itemset
203  SfxPoolItem const* pItem = nullptr;
204  SfxItemState eState =
205  rSet.GetItemState(Ids[i][0], true, &pItem);
206 
207  // if not set, try the pool
208  if ((SfxItemState::SET != eState) && SfxItemPool::IsWhich(Ids[i][0]))
209  {
210  pItem = &rSet.GetPool()->GetDefaultItem(Ids[i][0]);
211  }
212 
213  // do we have an item?
214  if (eState >= SfxItemState::DEFAULT && pItem)
215  {
216  std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
217  bool const bPut = PutXMLValue(
218  *pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
219  if (bPut)
220  {
221  rSet.Put(std::move(pNewItem));
222  }
223  }
224  else
225  {
226  OSL_ENSURE(false, "could not get item");
227  }
228  }
229  }
230 }
231 
233 {
235 
237 
238 public:
239  SwXMLItemSetContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
240  const OUString& rLName,
241  const Reference< xml::sax::XAttributeList > & xAttrList,
244  const SvXMLUnitConverter& rUnitConv );
245  virtual ~SwXMLItemSetContext_Impl() override;
246 
247  virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
248  const OUString& rLocalName,
249  const ::uno::Reference< xml::sax::XAttributeList > & xAttrList,
251  const SvXMLItemMapEntry& rEntry,
252  const SvXMLUnitConverter& rUnitConv ) override;
253 };
254 
256  SwXMLImport& rImport, sal_uInt16 nPrfx,
257  const OUString& rLName,
258  const Reference< xml::sax::XAttributeList > & xAttrList,
259  SfxItemSet& _rItemSet,
260  SvXMLImportItemMapper & _rIMapper,
261  const SvXMLUnitConverter& _rUnitConv ) :
262  SvXMLItemSetContext( rImport, nPrfx, rLName, xAttrList,
263  _rItemSet, _rIMapper, _rUnitConv )
264 {
265 }
266 
268 {
269  if( xBackground.is() )
270  {
271  const SvxBrushItem& rItem =
272  static_cast<SwXMLBrushItemImportContext*>(xBackground.get())->GetItem();
273  rItemSet.Put( rItem );
274  }
275 }
276 
278  sal_uInt16 nPrefix,
279  const OUString& rLocalName,
280  const Reference< xml::sax::XAttributeList > & xAttrList,
281  SfxItemSet& _rItemSet,
282  const SvXMLItemMapEntry& rEntry,
283  const SvXMLUnitConverter& _rUnitConv )
284 {
285  SvXMLImportContextRef xContext;
286 
287  switch( rEntry.nWhichId )
288  {
289  case RES_BACKGROUND:
290  {
291  const SfxPoolItem *pItem;
292  if( SfxItemState::SET == _rItemSet.GetItemState( RES_BACKGROUND,
293  false, &pItem ) )
294  {
295  xContext = new SwXMLBrushItemImportContext(
296  GetImport(), nPrefix, rLocalName, xAttrList,
297  _rUnitConv, *static_cast<const SvxBrushItem *>(pItem) );
298  }
299  else
300  {
301  xContext = new SwXMLBrushItemImportContext(
302  GetImport(), nPrefix, rLocalName, xAttrList,
303  _rUnitConv, RES_BACKGROUND );
304  }
305  xBackground = xContext;
306  }
307  break;
308  }
309 
310  if (!xContext)
311  xContext = SvXMLItemSetContext::CreateChildContext( nPrefix, rLocalName,
312  xAttrList, _rItemSet,
313  rEntry, _rUnitConv );
314 
315  return xContext;
316 }
317 
319 {
321  util::MeasureUnit::TWIP, util::MeasureUnit::TWIP ) );
322 
327 
329 }
330 
332 {
333  m_pTableItemMapper.reset();
334  m_pTwipUnitConv.reset();
335 }
336 
338  sal_uInt16 nPrefix,
339  const OUString& rLocalName,
340  const Reference< xml::sax::XAttributeList > & xAttrList,
341  sal_uInt16 nFamily,
342  SfxItemSet& rItemSet )
343 {
344  SvXMLItemMapEntriesRef xItemMap;
345 
346  switch( nFamily )
347  {
349  xItemMap = m_xTableItemMap;
350  break;
352  xItemMap = m_xTableColItemMap;
353  break;
355  xItemMap = m_xTableRowItemMap;
356  break;
358  xItemMap = m_xTableCellItemMap;
359  break;
360  }
361 
362  m_pTableItemMapper->setMapEntries( xItemMap );
363 
364  return new SwXMLItemSetContext_Impl( *this, nPrefix, rLocalName,
365  xAttrList, rItemSet,
367  *m_pTwipUnitConv );
368 }
369 
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool handleNoItem(SvXMLItemMapEntry const &rEntry, SfxItemSet &rSet, OUString const &rValue, SvXMLUnitConverter const &rUnitConverter, SvXMLNamespaceMap const &rNamespaceMap) override
Definition: xmlitemi.cxx:165
SwXMLImportTableItemMapper_Impl(const SvXMLItemMapEntriesRef &rMapEntries)
Definition: xmlitemi.cxx:88
#define RES_FRM_SIZE
Definition: hintids.hxx:196
std::unique_ptr< SvXMLUnitConverter > m_pTwipUnitConv
Definition: xmlimp.hxx:64
virtual ~SwXMLItemSetContext_Impl() override
Definition: xmlitemi.cxx:267
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
SvXMLItemMapEntry const aXMLTableItemMap[]
Definition: xmlitemm.cxx:44
sal_uInt16 nWhichId
Definition: xmlitmap.hxx:43
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
Extracts pool item of type nWhich from rAttr.
Definition: atrstck.cxx:157
virtual bool handleNoItem(const SvXMLItemMapEntry &rEntry, SfxItemSet &rSet, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap)
this method is called for every item that has the MID_SW_FLAG_NO_ITEM_IMPORT flag set ...
Definition: xmlimpit.cxx:202
SvXMLImport & GetImport()
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlimp.hxx:77
#define XML_STYLE_FAMILY_TABLE_CELL
SvXMLImportContextRef xBackground
Definition: xmlitemi.cxx:234
#define XML_STYLE_FAMILY_TABLE_TABLE
SvXMLItemMapEntry const aXMLTableColItemMap[]
Definition: xmlitemm.cxx:124
const SvXMLImportItemMapper & GetTableItemMapper() const
Definition: xmlimp.hxx:194
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlimp.hxx:76
virtual void finished(SfxItemSet &rSet, SvXMLUnitConverter const &rUnitConverter) const override
This method is called when all attributes have benn processed.
Definition: xmlitemi.cxx:185
SvXMLImportContext * CreateTableItemImportContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, sal_uInt16 nSubFamily, SfxItemSet &rItemSet)
Definition: xmlitemi.cxx:337
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:28
virtual bool handleSpecialItem(const SvXMLItemMapEntry &rEntry, SfxPoolItem &rItem, SfxItemSet &rSet, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter) override
this method is called for every item that has the MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set ...
Definition: xmlitemi.cxx:111
#define XML_STYLE_FAMILY_TABLE_ROW
#define RES_UL_SPACE
Definition: hintids.hxx:199
this class manages an array of SvXMLItemMapEntry.
Definition: xmlitmap.hxx:65
virtual void setMapEntries(SvXMLItemMapEntriesRef rMapEntries)
Definition: xmlimpit.cxx:76
SvXMLItemMapEntriesRef m_xTableItemMap
Definition: xmlimp.hxx:74
const SvXMLUnitConverter & rUnitConv
Definition: xmlitem.hxx:36
#define RES_BACKGROUND
Definition: hintids.hxx:212
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const ::uno::Reference< xml::sax::XAttributeList > &xAttrList, SfxItemSet &rItemSet, const SvXMLItemMapEntry &rEntry, const SvXMLUnitConverter &rUnitConv) override
Definition: xmlitemi.cxx:277
#define MID_L_MARGIN
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
std::unique_ptr< SvXMLImportItemMapper > m_pTableItemMapper
Definition: xmlimp.hxx:65
void FinitItemImport()
Definition: xmlitemi.cxx:331
enum::xmloff::token::XMLTokenEnum const eLocalName
Definition: xmlitmap.hxx:45
int i
#define MID_R_MARGIN
virtual void setMapEntries(SvXMLItemMapEntriesRef rMapEntries) override
Definition: xmlitemi.cxx:104
static bool PutXMLValue(SfxPoolItem &rItem, const OUString &rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter &rUnitConverter)
This method is called for every item that should be set based upon an XML attribute value...
Definition: xmlimpit.cxx:242
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
#define RES_LR_SPACE
Definition: hintids.hxx:198
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemState
css::uno::Reference< css::uno::XComponentContext > const & GetComponentContext() const
void InitItemImport()
Definition: xmlitemi.cxx:318
#define XML_STYLE_FAMILY_TABLE_COLUMN
#define MID_LO_MARGIN
sal_uInt32 const nMemberId
Definition: xmlitmap.hxx:48
SwXMLItemSetContext_Impl(SwXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const Reference< xml::sax::XAttributeList > &xAttrList, SfxItemSet &rItemSet, SvXMLImportItemMapper &rIMapper, const SvXMLUnitConverter &rUnitConv)
Definition: xmlitemi.cxx:255
SvXMLItemMapEntriesRef m_xTableColItemMap
Definition: xmlimp.hxx:75
SvXMLItemMapEntry const aXMLTableCellItemMap[]
Definition: xmlitemm.cxx:203
sal_uInt16 const nNameSpace
Definition: xmlitmap.hxx:41
SfxItemSet & rItemSet
Definition: xmlitem.hxx:34
#define MID_FRMSIZE_COL_WIDTH
Definition: unomid.h:81
const SvXMLImportItemMapper & rIMapper
Definition: xmlitem.hxx:35
SvXMLItemMapEntry const aXMLTableRowItemMap[]
Definition: xmlitemm.cxx:131
sal_uInt16 Which() const
static bool IsWhich(sal_uInt16 nId)
#define MID_UP_MARGIN