diff --git a/include/svl/grabbagitem.hxx b/include/svl/grabbagitem.hxx new file mode 100644 index 000000000000..f32e8e5a51a2 --- /dev/null +++ b/include/svl/grabbagitem.hxx @@ -0,0 +1,44 @@ +/* -*- 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/. + */ +#ifndef _SFXGRABBAGITEM_HXX +#define _SFXGRABBAGITEM_HXX + +#include + +#include "svl/svldllapi.h" +#include +#include +#include + +/// Grab bag item provides a string-any map for interim interop purposes. +class SVL_DLLPUBLIC SfxGrabBagItem : public SfxPoolItem +{ +private: + std::map m_aMap; + +public: + TYPEINFO(); + + SfxGrabBagItem(); + SfxGrabBagItem(sal_uInt16 nWhich, const std::map *pMap = 0); + SfxGrabBagItem(const SfxGrabBagItem& rItem); + ~SfxGrabBagItem(); + + void SetGrabBag(const std::map& rMap); + const std::map& GetGrabBag() const; + + virtual int operator==(const SfxPoolItem&) const; + virtual SfxPoolItem* Clone(SfxItemPool *pPool = 0) const; + + virtual bool PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0); + virtual bool QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId = 0) const; +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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 +#include +#include +#include +#include + +#include + +DBG_NAME(SfxGrabBagItem) + +TYPEINIT1_AUTOFACTORY(SfxGrabBagItem, SfxPoolItem); + +using namespace com::sun::star; + +SfxGrabBagItem::SfxGrabBagItem() +{ +} + +SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich, const std::map *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& rMap) +{ + m_aMap = rMap; +} + +const std::map& 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 aValue; + if ( rVal >>= aValue ) + { + m_aMap.clear(); + comphelper::OSequenceIterator i(aValue); + while (i.hasMoreElements()) + { + beans::PropertyValue aPropertyValue = i.nextElement().get(); + 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 aValue(m_aMap.size()); + beans::PropertyValue* pValue = aValue.getArray(); + for (std::map::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: */