1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <rtl/ustring.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <xmloff/xmluconv.hxx>
#include <xmloff/families.hxx>
#include <xmloff/xmlnamespace.hxx>
#include <xmloff/xmltoken.hxx>
#include <editeng/memberids.h>
#include <svl/itemset.hxx>
#include <svl/itempool.hxx>
#include <hintids.hxx>
#include <unomid.h>
#include "xmlimp.hxx"
#include "xmlitmap.hxx"
#include "xmlimpit.hxx"
#include "xmlitem.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
namespace {
class SwXMLImportTableItemMapper_Impl: public SvXMLImportItemMapper
{
public:
explicit SwXMLImportTableItemMapper_Impl(const SvXMLItemMapEntriesRef& rMapEntries);
virtual bool handleSpecialItem( const SvXMLItemMapEntry& rEntry,
SfxPoolItem& rItem,
SfxItemSet& rSet,
const OUString& rValue,
const SvXMLUnitConverter& rUnitConverter ) override;
virtual bool
handleNoItem(SvXMLItemMapEntry const& rEntry,
SfxItemSet & rSet,
OUString const& rValue,
SvXMLUnitConverter const& rUnitConverter,
SvXMLNamespaceMap const& rNamespaceMap) override;
virtual void finished(SfxItemSet & rSet,
SvXMLUnitConverter const& rUnitConverter) const override;
virtual void setMapEntries( SvXMLItemMapEntriesRef rMapEntries ) override;
private:
void Reset();
OUString m_FoMarginValue;
enum { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };
bool m_bHaveMargin[4];
};
}
SwXMLImportTableItemMapper_Impl::SwXMLImportTableItemMapper_Impl(
const SvXMLItemMapEntriesRef& rMapEntries ) :
SvXMLImportItemMapper( rMapEntries )
{
Reset();
}
void SwXMLImportTableItemMapper_Impl::Reset()
{
m_FoMarginValue.clear();
for (int i = 0; i < 3; ++i)
{
m_bHaveMargin[i] = false;
}
}
void SwXMLImportTableItemMapper_Impl::setMapEntries(
SvXMLItemMapEntriesRef rMapEntries )
{
Reset();
SvXMLImportItemMapper::setMapEntries(rMapEntries);
}
bool SwXMLImportTableItemMapper_Impl::handleSpecialItem(
const SvXMLItemMapEntry& rEntry,
SfxPoolItem& rItem,
SfxItemSet& rItemSet,
const OUString& rValue,
const SvXMLUnitConverter& rUnitConv )
{
bool bRet = false;
sal_uInt16 nMemberId = static_cast< sal_Int16 >(rEntry.nMemberId & MID_SW_FLAG_MASK);
switch( rItem.Which() )
{
case RES_LR_SPACE:
switch (nMemberId)
{
case MID_L_MARGIN:
m_bHaveMargin[LEFT] = true;
break;
case MID_R_MARGIN:
m_bHaveMargin[RIGHT] = true;
break;
}
bRet = SvXMLImportItemMapper::PutXMLValue(
rItem, rValue, nMemberId, rUnitConv);
break;
case RES_UL_SPACE:
switch (nMemberId)
{
case MID_UP_MARGIN:
m_bHaveMargin[TOP] = true;
break;
case MID_LO_MARGIN:
m_bHaveMargin[BOTTOM] = true;
break;
}
bRet = SvXMLImportItemMapper::PutXMLValue(
rItem, rValue, nMemberId, rUnitConv);
break;
case RES_FRM_SIZE:
switch( nMemberId )
{
case MID_FRMSIZE_COL_WIDTH:
// If the item is existing already, a relative value has been set
// already that must be preserved.
if( SfxItemState::SET != rItemSet.GetItemState( RES_FRM_SIZE,
false ) )
bRet = SvXMLImportItemMapper::PutXMLValue(
rItem, rValue, nMemberId, rUnitConv );
break;
}
}
return bRet;
}
bool SwXMLImportTableItemMapper_Impl::handleNoItem(
SvXMLItemMapEntry const& rEntry,
SfxItemSet & rSet,
OUString const& rValue,
SvXMLUnitConverter const& rUnitConverter,
SvXMLNamespaceMap const& rNamespaceMap)
{
if ((XML_NAMESPACE_FO == rEntry.nNameSpace) &&
(xmloff::token::XML_MARGIN == rEntry.eLocalName))
{
m_FoMarginValue = rValue;
return true;
}
else
{
return SvXMLImportItemMapper::handleNoItem(
rEntry, rSet, rValue, rUnitConverter, rNamespaceMap);
}
}
void SwXMLImportTableItemMapper_Impl::finished(
SfxItemSet & rSet, SvXMLUnitConverter const& rUnitConverter) const
{
if (m_FoMarginValue.isEmpty())
return;
sal_uInt16 const Ids[4][2] = {
{ RES_LR_SPACE, MID_L_MARGIN },
{ RES_LR_SPACE, MID_R_MARGIN },
{ RES_UL_SPACE, MID_UP_MARGIN },
{ RES_UL_SPACE, MID_LO_MARGIN },
};
for (int i = 0; i < 4; ++i)
{
if (m_bHaveMargin[i])
{
continue; // already read fo:margin-top etc.
}
// first get item from itemset
SfxPoolItem const* pItem = nullptr;
SfxItemState eState =
rSet.GetItemState(Ids[i][0], true, &pItem);
// if not set, try the pool
if ((SfxItemState::SET != eState) && SfxItemPool::IsWhich(Ids[i][0]))
{
pItem = &rSet.GetPool()->GetDefaultItem(Ids[i][0]);
}
// do we have an item?
if (eState >= SfxItemState::DEFAULT && pItem)
{
std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
bool const bPut = PutXMLValue(
*pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
if (bPut)
{
rSet.Put(std::move(pNewItem));
}
}
else
{
OSL_ENSURE(false, "could not get item");
}
}
}
void SwXMLImport::InitItemImport()
{
m_pTwipUnitConv.reset( new SvXMLUnitConverter( GetComponentContext(),
util::MeasureUnit::TWIP, util::MeasureUnit::TWIP,
SvtSaveOptions::ODFSVER_LATEST_EXTENDED) );
m_xTableItemMap = new SvXMLItemMapEntries( aXMLTableItemMap );
m_xTableColItemMap = new SvXMLItemMapEntries( aXMLTableColItemMap );
m_xTableRowItemMap = new SvXMLItemMapEntries( aXMLTableRowItemMap );
m_xTableCellItemMap = new SvXMLItemMapEntries( aXMLTableCellItemMap );
m_pTableItemMapper.reset( new SwXMLImportTableItemMapper_Impl( m_xTableItemMap ) );
}
void SwXMLImport::FinitItemImport()
{
m_pTableItemMapper.reset();
m_pTwipUnitConv.reset();
}
SvXMLImportContext *SwXMLImport::CreateTableItemImportContext(
sal_Int32 nElement,
const Reference< xml::sax::XFastAttributeList > & xAttrList,
XmlStyleFamily nFamily,
SfxItemSet& rItemSet )
{
SvXMLItemMapEntriesRef xItemMap;
switch( nFamily )
{
case XmlStyleFamily::TABLE_TABLE:
xItemMap = m_xTableItemMap;
break;
case XmlStyleFamily::TABLE_COLUMN:
xItemMap = m_xTableColItemMap;
break;
case XmlStyleFamily::TABLE_ROW:
xItemMap = m_xTableRowItemMap;
break;
case XmlStyleFamily::TABLE_CELL:
xItemMap = m_xTableCellItemMap;
break;
default: break;
}
m_pTableItemMapper->setMapEntries( xItemMap );
return new SwXMLItemSetContext( *this, nElement,
xAttrList, rItemSet,
GetTableItemMapper(),
*m_pTwipUnitConv );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|