LibreOffice Module svl (master) 1
grabbagitem.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
10#include <svl/grabbagitem.hxx>
11#include <sal/config.h>
12
13#include <sal/log.hxx>
14#include <com/sun/star/beans/PropertyValue.hpp>
15#include <com/sun/star/uno/Sequence.hxx>
16
17using namespace com::sun::star;
18
20
22 : SfxPoolItem(nWhich)
23{
24}
25
27
29{
30 return SfxPoolItem::operator==(rItem)
31 && m_aMap == static_cast<const SfxGrabBagItem*>(&rItem)->m_aMap;
32}
33
35{
36 return new SfxGrabBagItem(*this);
37}
38
39bool SfxGrabBagItem::PutValue(const uno::Any& rVal, sal_uInt8 /*nMemberId*/)
40{
41 uno::Sequence<beans::PropertyValue> aValue;
42 if (rVal >>= aValue)
43 {
44 m_aMap.clear();
45 for (beans::PropertyValue const& aPropertyValue : std::as_const(aValue))
46 {
47 m_aMap[aPropertyValue.Name] = aPropertyValue.Value;
48 }
49 return true;
50 }
51
52 SAL_WARN("svl", "SfxGrabBagItem::PutValue: wrong type");
53 return false;
54}
55
56bool SfxGrabBagItem::QueryValue(uno::Any& rVal, sal_uInt8 /*nMemberId*/) const
57{
58 uno::Sequence<beans::PropertyValue> aValue(m_aMap.size());
59 beans::PropertyValue* pValue = aValue.getArray();
60 for (const auto& i : m_aMap)
61 {
62 pValue[0].Name = i.first;
63 pValue[0].Value = i.second;
64 ++pValue;
65 }
66 rVal <<= aValue;
67 return true;
68}
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Grab bag item provides a string-any map for keys with untyped values.
Definition: grabbagitem.hxx:20
SfxGrabBagItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: grabbagitem.cxx:34
bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: grabbagitem.cxx:39
bool operator==(const SfxPoolItem &rItem) const override
Definition: grabbagitem.cxx:28
std::map< OUString, css::uno::Any > m_aMap
Definition: grabbagitem.hxx:22
~SfxGrabBagItem() override
bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: grabbagitem.cxx:56
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
virtual bool operator==(const SfxPoolItem &) const =0
Definition: poolitem.cxx:478
#define SAL_WARN(area, stream)
int i
unsigned char sal_uInt8