Line data Source code
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 <comphelper/sequence.hxx>
15 : #include <com/sun/star/beans/PropertyValue.hpp>
16 :
17 275230 : TYPEINIT1_AUTOFACTORY(SfxGrabBagItem, SfxPoolItem);
18 :
19 : using namespace com::sun::star;
20 :
21 44087 : SfxGrabBagItem::SfxGrabBagItem()
22 : {
23 44087 : }
24 :
25 292 : SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich, const std::map<OUString, uno::Any>* pMap) :
26 292 : SfxPoolItem(nWhich)
27 : {
28 292 : if (pMap)
29 0 : m_aMap = *pMap;
30 292 : }
31 :
32 48436 : SfxGrabBagItem::SfxGrabBagItem(const SfxGrabBagItem& rItem) :
33 : SfxPoolItem(rItem),
34 48436 : m_aMap(rItem.m_aMap)
35 : {
36 48436 : }
37 :
38 185564 : SfxGrabBagItem::~SfxGrabBagItem()
39 : {
40 185564 : }
41 :
42 :
43 189997 : bool SfxGrabBagItem::operator==(const SfxPoolItem& rItem) const
44 : {
45 189997 : const SfxGrabBagItem* pItem = static_cast<const SfxGrabBagItem*>(&rItem);
46 :
47 189997 : return m_aMap == pItem->m_aMap;
48 : }
49 :
50 48390 : SfxPoolItem* SfxGrabBagItem::Clone(SfxItemPool* /*pPool*/) const
51 : {
52 48390 : return new SfxGrabBagItem(*this);
53 : }
54 :
55 82862 : bool SfxGrabBagItem::PutValue(const uno::Any& rVal, sal_uInt8 /*nMemberId*/)
56 : {
57 82862 : uno::Sequence<beans::PropertyValue> aValue;
58 82862 : if (rVal >>= aValue)
59 : {
60 82862 : m_aMap.clear();
61 82862 : comphelper::OSequenceIterator<beans::PropertyValue> i(aValue);
62 449453 : while (i.hasMoreElements())
63 : {
64 283729 : beans::PropertyValue aPropertyValue = i.nextElement().get<beans::PropertyValue>();
65 283729 : m_aMap[aPropertyValue.Name] = aPropertyValue.Value;
66 283729 : }
67 82862 : return true;
68 : }
69 :
70 : SAL_WARN("svl", "SfxGrabBagItem::PutValue: wrong type");
71 0 : return false;
72 : }
73 :
74 30324 : bool SfxGrabBagItem::QueryValue(uno::Any& rVal, sal_uInt8 /*nMemberId*/) const
75 : {
76 30324 : uno::Sequence<beans::PropertyValue> aValue(m_aMap.size());
77 30324 : beans::PropertyValue* pValue = aValue.getArray();
78 172423 : for (std::map<OUString, uno::Any>::const_iterator i = m_aMap.begin(); i != m_aMap.end(); ++i)
79 : {
80 142099 : pValue[0].Name = i->first;
81 142099 : pValue[0].Value = i->second;
82 142099 : ++pValue;
83 : }
84 30324 : rVal = uno::makeAny(aValue);
85 30324 : return true;
86 : }
87 :
88 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|