diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2013-07-24 10:51:33 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2013-07-24 12:11:10 +0200 |
commit | f841985d9c80556001fbd6bd856eb84f49e805ab (patch) | |
tree | 48915582275ff2006433adc487e6a08487a6dd66 /svl | |
parent | 0e701dbaa7e2b1ec00ecfcb50d29252302d2d0bd (diff) |
svl: add an SfxGrabBagItem
The intention is that this can be used as a grab bag of properties which
are not handled properly, yet we want the roundtrip of them to alien
formats.
See
http://lists.freedesktop.org/archives/libreoffice/2013-July/054428.html
for more details.
Change-Id: I3781b3b3bf1380d30683039f037d9a4292ba2f4a
Diffstat (limited to 'svl')
-rw-r--r-- | svl/Library_svl.mk | 1 | ||||
-rw-r--r-- | svl/source/items/grabbagitem.cxx | 100 |
2 files changed, 101 insertions, 0 deletions
diff --git a/svl/Library_svl.mk b/svl/Library_svl.mk index 499b1054f56e..fd28a7abe0e2 100644 --- a/svl/Library_svl.mk +++ b/svl/Library_svl.mk @@ -73,6 +73,7 @@ $(eval $(call gb_Library_add_exception_objects,svl,\ svl/source/items/eitem \ svl/source/items/flagitem \ svl/source/items/globalnameitem \ + svl/source/items/grabbagitem \ svl/source/items/ilstitem \ svl/source/items/imageitm \ svl/source/items/intitem \ diff --git a/svl/source/items/grabbagitem.cxx b/svl/source/items/grabbagitem.cxx new file mode 100644 index 000000000000..23ab2bd06718 --- /dev/null +++ b/svl/source/items/grabbagitem.cxx @@ -0,0 +1,100 @@ +/* -*- 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/. + */ + +#include <svl/grabbagitem.hxx> +#include <svl/poolitem.hxx> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <comphelper/sequence.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> + +DBG_NAME(SfxGrabBagItem) + +TYPEINIT1_AUTOFACTORY(SfxGrabBagItem, SfxPoolItem); + +using namespace com::sun::star; + +SfxGrabBagItem::SfxGrabBagItem() +{ +} + +SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich, const std::map<OUString, uno::Any> *pMap) : + SfxPoolItem( nWhich ) +{ + if (pMap) + m_aMap = *pMap; +} + +SfxGrabBagItem::SfxGrabBagItem(const SfxGrabBagItem& rItem) : + SfxPoolItem(rItem), + m_aMap(rItem.m_aMap) +{ +} + +SfxGrabBagItem::~SfxGrabBagItem() +{ +} + +void SfxGrabBagItem::SetGrabBag(const std::map<OUString, uno::Any>& rMap) +{ + m_aMap = rMap; +} + +const std::map<OUString, uno::Any>& SfxGrabBagItem::GetGrabBag() const +{ + return m_aMap; +} + +int SfxGrabBagItem::operator==(const SfxPoolItem& rItem) const +{ + SfxGrabBagItem* pItem = (SfxGrabBagItem*)&rItem; + + return m_aMap == pItem->m_aMap; +} + +SfxPoolItem* SfxGrabBagItem::Clone(SfxItemPool * /*pPool*/) const +{ + return new SfxGrabBagItem(*this); +} + +bool SfxGrabBagItem::PutValue(const uno::Any& rVal, sal_uInt8 /*nMemberId*/) +{ + uno::Sequence<beans::PropertyValue> aValue; + if ( rVal >>= aValue ) + { + m_aMap.clear(); + comphelper::OSequenceIterator<beans::PropertyValue> i(aValue); + while (i.hasMoreElements()) + { + beans::PropertyValue aPropertyValue = i.nextElement().get<beans::PropertyValue>(); + m_aMap[aPropertyValue.Name] = aPropertyValue.Value; + } + return true; + } + + SAL_WARN("svl", "SfxGrabBagItem::PutValue: wrong type"); + return false; +} + +bool SfxGrabBagItem::QueryValue(uno::Any& rVal, sal_uInt8 /*nMemberId*/) const +{ + uno::Sequence<beans::PropertyValue> aValue(m_aMap.size()); + beans::PropertyValue* pValue = aValue.getArray(); + for (std::map<OUString, com::sun::star::uno::Any>::const_iterator i = m_aMap.begin(); i != m_aMap.end(); ++i) + { + pValue[0].Name = i->first; + pValue[0].Value = i->second; + ++pValue; + } + rVal = uno::makeAny(aValue); + return true; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |