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,
67  const SvXMLNamespaceMap& rNamespaceMap ) override;
68 
69  virtual bool
70  handleNoItem(SvXMLItemMapEntry const& rEntry,
71  SfxItemSet & rSet,
72  OUString const& rValue,
73  SvXMLUnitConverter const& rUnitConverter,
74  SvXMLNamespaceMap const& rNamespaceMap) override;
75 
76  virtual void finished(SfxItemSet & rSet,
77  SvXMLUnitConverter const& rUnitConverter) const override;
78 
79  virtual void setMapEntries( SvXMLItemMapEntriesRef rMapEntries ) override;
80 
81 private:
82  void Reset();
83 
84  OUString m_FoMarginValue;
85  enum { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };
86  bool m_bHaveMargin[4];
87 };
88 
90  const SvXMLItemMapEntriesRef& rMapEntries ) :
91  SvXMLImportItemMapper( rMapEntries )
92 {
93  Reset();
94 }
95 
97 {
98  m_FoMarginValue.clear();
99  for (int i = 0; i < 3; ++i)
100  {
101  m_bHaveMargin[i] = false;
102  }
103 }
104 
106  SvXMLItemMapEntriesRef rMapEntries )
107 {
108  Reset();
110 }
111 
113  const SvXMLItemMapEntry& rEntry,
114  SfxPoolItem& rItem,
115  SfxItemSet& rItemSet,
116  const OUString& rValue,
117  const SvXMLUnitConverter& rUnitConv,
118  const SvXMLNamespaceMap& )
119 {
120  bool bRet = false;
121  sal_uInt16 nMemberId = static_cast< sal_Int16 >(rEntry.nMemberId & MID_SW_FLAG_MASK);
122  switch( rItem.Which() )
123  {
124  case RES_LR_SPACE:
125  switch (nMemberId)
126  {
127  case MID_L_MARGIN:
128  m_bHaveMargin[LEFT] = true;
129  break;
130  case MID_R_MARGIN:
131  m_bHaveMargin[RIGHT] = true;
132  break;
133  }
135  rItem, rValue, nMemberId, rUnitConv);
136  break;
137  case RES_UL_SPACE:
138  switch (nMemberId)
139  {
140  case MID_UP_MARGIN:
141  m_bHaveMargin[TOP] = true;
142  break;
143  case MID_LO_MARGIN:
144  m_bHaveMargin[BOTTOM] = true;
145  break;
146  }
148  rItem, rValue, nMemberId, rUnitConv);
149  break;
150  case RES_FRM_SIZE:
151  switch( nMemberId )
152  {
154  // If the item is existing already, a relative value has been set
155  // already that must be preserved.
156  if( SfxItemState::SET != rItemSet.GetItemState( RES_FRM_SIZE,
157  false ) )
159  rItem, rValue, nMemberId, rUnitConv );
160  break;
161  }
162  }
163 
164  return bRet;
165 }
166 
168  SvXMLItemMapEntry const& rEntry,
169  SfxItemSet & rSet,
170  OUString const& rValue,
171  SvXMLUnitConverter const& rUnitConverter,
172  SvXMLNamespaceMap const& rNamespaceMap)
173 {
174  if ((XML_NAMESPACE_FO == rEntry.nNameSpace) &&
176  {
177  m_FoMarginValue = rValue;
178  return true;
179  }
180  else
181  {
183  rEntry, rSet, rValue, rUnitConverter, rNamespaceMap);
184  }
185 }
186 
188  SfxItemSet & rSet, SvXMLUnitConverter const& rUnitConverter) const
189 {
190  if (!m_FoMarginValue.isEmpty())
191  {
192  sal_uInt16 const Ids[4][2] = {
197  };
198  for (int i = 0; i < 4; ++i)
199  {
200  if (m_bHaveMargin[i])
201  {
202  continue; // already read fo:margin-top etc.
203  }
204  // first get item from itemset
205  SfxPoolItem const* pItem = nullptr;
206  SfxItemState eState =
207  rSet.GetItemState(Ids[i][0], true, &pItem);
208 
209  // if not set, try the pool
210  if ((SfxItemState::SET != eState) && SfxItemPool::IsWhich(Ids[i][0]))
211  {
212  pItem = &rSet.GetPool()->GetDefaultItem(Ids[i][0]);
213  }
214 
215  // do we have an item?
216  if (eState >= SfxItemState::DEFAULT && pItem)
217  {
218  std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
219  bool const bPut = PutXMLValue(
220  *pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
221  if (bPut)
222  {
223  rSet.Put(std::move(pNewItem));
224  }
225  }
226  else
227  {
228  OSL_ENSURE(false, "could not get item");
229  }
230  }
231  }
232 }
233 
235 {
237 
239 
240 public:
241  SwXMLItemSetContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
242  const OUString& rLName,
243  const Reference< xml::sax::XAttributeList > & xAttrList,
246  const SvXMLUnitConverter& rUnitConv );
247  virtual ~SwXMLItemSetContext_Impl() override;
248 
249  virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
250  const OUString& rLocalName,
251  const ::uno::Reference< xml::sax::XAttributeList > & xAttrList,
253  const SvXMLItemMapEntry& rEntry,
254  const SvXMLUnitConverter& rUnitConv ) override;
255 };
256 
258  SwXMLImport& rImport, sal_uInt16 nPrfx,
259  const OUString& rLName,
260  const Reference< xml::sax::XAttributeList > & xAttrList,
261  SfxItemSet& _rItemSet,
262  SvXMLImportItemMapper & _rIMapper,
263  const SvXMLUnitConverter& _rUnitConv ) :
264  SvXMLItemSetContext( rImport, nPrfx, rLName, xAttrList,
265  _rItemSet, _rIMapper, _rUnitConv )
266 {
267 }
268 
270 {
271  if( xBackground.is() )
272  {
273  const SvxBrushItem& rItem =
274  static_cast<SwXMLBrushItemImportContext*>(xBackground.get())->GetItem();
275  rItemSet.Put( rItem );
276  }
277 }
278 
280  sal_uInt16 nPrefix,
281  const OUString& rLocalName,
282  const Reference< xml::sax::XAttributeList > & xAttrList,
283  SfxItemSet& _rItemSet,
284  const SvXMLItemMapEntry& rEntry,
285  const SvXMLUnitConverter& _rUnitConv )
286 {
287  SvXMLImportContextRef xContext;
288 
289  switch( rEntry.nWhichId )
290  {
291  case RES_BACKGROUND:
292  {
293  const SfxPoolItem *pItem;
294  if( SfxItemState::SET == _rItemSet.GetItemState( RES_BACKGROUND,
295  false, &pItem ) )
296  {
297  xContext = new SwXMLBrushItemImportContext(
298  GetImport(), nPrefix, rLocalName, xAttrList,
299  _rUnitConv, *static_cast<const SvxBrushItem *>(pItem) );
300  }
301  else
302  {
303  xContext = new SwXMLBrushItemImportContext(
304  GetImport(), nPrefix, rLocalName, xAttrList,
305  _rUnitConv, RES_BACKGROUND );
306  }
307  xBackground = xContext;
308  }
309  break;
310  }
311 
312  if (!xContext)
313  xContext = SvXMLItemSetContext::CreateChildContext( nPrefix, rLocalName,
314  xAttrList, _rItemSet,
315  rEntry, _rUnitConv );
316 
317  return xContext;
318 }
319 
321 {
323  util::MeasureUnit::TWIP, util::MeasureUnit::TWIP ) );
324 
329 
331 }
332 
334 {
335  m_pTableItemMapper.reset();
336  m_pTwipUnitConv.reset();
337 }
338 
340  sal_uInt16 nPrefix,
341  const OUString& rLocalName,
342  const Reference< xml::sax::XAttributeList > & xAttrList,
343  sal_uInt16 nFamily,
344  SfxItemSet& rItemSet )
345 {
346  SvXMLItemMapEntriesRef xItemMap;
347 
348  switch( nFamily )
349  {
351  xItemMap = m_xTableItemMap;
352  break;
354  xItemMap = m_xTableColItemMap;
355  break;
357  xItemMap = m_xTableRowItemMap;
358  break;
360  xItemMap = m_xTableCellItemMap;
361  break;
362  }
363 
364  m_pTableItemMapper->setMapEntries( xItemMap );
365 
366  return new SwXMLItemSetContext_Impl( *this, nPrefix, rLocalName,
367  xAttrList, rItemSet,
369  *m_pTwipUnitConv );
370 }
371 
372 /* 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:167
SwXMLImportTableItemMapper_Impl(const SvXMLItemMapEntriesRef &rMapEntries)
Definition: xmlitemi.cxx:89
#define RES_FRM_SIZE
Definition: hintids.hxx:194
std::unique_ptr< SvXMLUnitConverter > m_pTwipUnitConv
Definition: xmlimp.hxx:66
virtual ~SwXMLItemSetContext_Impl() override
Definition: xmlitemi.cxx:269
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:159
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:204
SvXMLImport & GetImport()
SvXMLItemMapEntriesRef m_xTableCellItemMap
Definition: xmlimp.hxx:79
#define XML_STYLE_FAMILY_TABLE_CELL
SvXMLImportContextRef xBackground
Definition: xmlitemi.cxx:236
#define XML_STYLE_FAMILY_TABLE_TABLE
SvXMLItemMapEntry const aXMLTableColItemMap[]
Definition: xmlitemm.cxx:124
const SvXMLImportItemMapper & GetTableItemMapper() const
Definition: xmlimp.hxx:196
SvXMLItemMapEntriesRef m_xTableRowItemMap
Definition: xmlimp.hxx:78
virtual void finished(SfxItemSet &rSet, SvXMLUnitConverter const &rUnitConverter) const override
This method is called when all attributes have benn processed.
Definition: xmlitemi.cxx:187
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:339
#define MID_SW_FLAG_MASK
Definition: xmlitmap.hxx:28
#define XML_STYLE_FAMILY_TABLE_ROW
#define RES_UL_SPACE
Definition: hintids.hxx:197
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:76
const SvXMLUnitConverter & rUnitConv
Definition: xmlitem.hxx:38
#define RES_BACKGROUND
Definition: hintids.hxx:210
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:279
#define MID_L_MARGIN
virtual bool handleSpecialItem(const SvXMLItemMapEntry &rEntry, SfxPoolItem &rItem, SfxItemSet &rSet, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) override
this method is called for every item that has the MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set ...
Definition: xmlitemi.cxx:112
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
std::unique_ptr< SvXMLImportItemMapper > m_pTableItemMapper
Definition: xmlimp.hxx:67
void FinitItemImport()
Definition: xmlitemi.cxx:333
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:105
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:244
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
SfxItemPool * GetPool() const
#define RES_LR_SPACE
Definition: hintids.hxx:196
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemState
css::uno::Reference< css::uno::XComponentContext > const & GetComponentContext() const
void InitItemImport()
Definition: xmlitemi.cxx:320
#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:257
SvXMLItemMapEntriesRef m_xTableColItemMap
Definition: xmlimp.hxx:77
SvXMLItemMapEntry const aXMLTableCellItemMap[]
Definition: xmlitemm.cxx:203
sal_uInt16 const nNameSpace
Definition: xmlitmap.hxx:41
SfxItemSet & rItemSet
Definition: xmlitem.hxx:36
#define MID_FRMSIZE_COL_WIDTH
Definition: unomid.h:81
const SvXMLImportItemMapper & rIMapper
Definition: xmlitem.hxx:37
SvXMLItemMapEntry const aXMLTableRowItemMap[]
Definition: xmlitemm.cxx:131
sal_uInt16 Which() const
static bool IsWhich(sal_uInt16 nId)
#define MID_UP_MARGIN