Kaydet (Commit) f841985d authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst 0e701dba
/* -*- 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 <map>
#include "svl/svldllapi.h"
#include <tools/rtti.hxx>
#include <svl/poolitem.hxx>
#include <com/sun/star/uno/Any.hxx>
/// Grab bag item provides a string-any map for interim interop purposes.
class SVL_DLLPUBLIC SfxGrabBagItem : public SfxPoolItem
{
private:
std::map<OUString, com::sun::star::uno::Any> m_aMap;
public:
TYPEINFO();
SfxGrabBagItem();
SfxGrabBagItem(sal_uInt16 nWhich, const std::map<OUString, com::sun::star::uno::Any> *pMap = 0);
SfxGrabBagItem(const SfxGrabBagItem& rItem);
~SfxGrabBagItem();
void SetGrabBag(const std::map<OUString, com::sun::star::uno::Any>& rMap);
const std::map<OUString, com::sun::star::uno::Any>& 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: */
......@@ -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 \
......
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment