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