Branch data 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 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include <svl/itemprop.hxx>
22 : : #include <svl/itempool.hxx>
23 : : #include <svl/itemset.hxx>
24 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
25 : : #include <boost/unordered_map.hpp>
26 : : /*************************************************************************
27 : : UNO III Implementation
28 : : *************************************************************************/
29 : : using namespace com::sun::star;
30 : : using namespace com::sun::star::beans;
31 : : using namespace com::sun::star::lang;
32 : : using namespace com::sun::star::uno;
33 : :
34 : : struct equalOUString
35 : : {
36 : 2599609 : bool operator()(const ::rtl::OUString& r1, const ::rtl::OUString& r2) const
37 : : {
38 : 2599609 : return r1.equals( r2 );
39 : : }
40 : : };
41 : :
42 : : typedef ::boost::unordered_map< ::rtl::OUString,
43 : : SfxItemPropertySimpleEntry,
44 : : ::rtl::OUStringHash,
45 : : equalOUString > SfxItemPropertyHashMap_t;
46 : :
47 [ + - ]: 10298 : class SfxItemPropertyMap_Impl : public SfxItemPropertyHashMap_t
48 : : {
49 : : public:
50 : : mutable uno::Sequence< beans::Property > m_aPropSeq;
51 : :
52 [ + - ][ + - ]: 9378 : SfxItemPropertyMap_Impl(){}
53 : : SfxItemPropertyMap_Impl( const SfxItemPropertyMap_Impl* pSource );
54 : : };
55 : :
56 [ + - ][ + - ]: 1160 : SfxItemPropertyMap_Impl::SfxItemPropertyMap_Impl( const SfxItemPropertyMap_Impl* pSource )
57 : : {
58 [ + - ]: 1160 : this->SfxItemPropertyHashMap_t::operator=( *pSource );
59 [ + - ]: 1160 : m_aPropSeq = pSource->m_aPropSeq;
60 : 1160 : }
61 : :
62 : 9378 : SfxItemPropertyMap::SfxItemPropertyMap( const SfxItemPropertyMapEntry* pEntries ) :
63 [ + - ]: 9378 : m_pImpl( new SfxItemPropertyMap_Impl )
64 : : {
65 [ + + ]: 222422 : while( pEntries->pName )
66 : : {
67 [ + - ]: 213044 : ::rtl::OUString sEntry(pEntries->pName, pEntries->nNameLen, RTL_TEXTENCODING_ASCII_US );
68 [ + - ]: 213044 : (*m_pImpl) [ sEntry ] = pEntries;
69 : 213044 : ++pEntries;
70 : 213044 : }
71 : 9378 : }
72 : :
73 : 1160 : SfxItemPropertyMap::SfxItemPropertyMap( const SfxItemPropertyMap& rSource ) :
74 [ + - ]: 1160 : m_pImpl( new SfxItemPropertyMap_Impl( rSource.m_pImpl ) )
75 : : {
76 : 1160 : }
77 : :
78 : 10298 : SfxItemPropertyMap::~SfxItemPropertyMap()
79 : : {
80 [ + - ]: 10298 : delete m_pImpl;
81 : 10298 : }
82 : :
83 : 2490364 : const SfxItemPropertySimpleEntry* SfxItemPropertyMap::getByName( const ::rtl::OUString &rName ) const
84 : : {
85 [ + - ]: 2490364 : SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName);
86 [ + + ][ + - ]: 2490364 : if( aIter == m_pImpl->end() )
87 : 40698 : return 0;
88 [ + - ]: 2490364 : return &aIter->second;
89 : : }
90 : :
91 : 899 : uno::Sequence<beans::Property> SfxItemPropertyMap::getProperties() const
92 : : {
93 [ + + ]: 899 : if( !m_pImpl->m_aPropSeq.getLength() )
94 : : {
95 [ + - ]: 376 : m_pImpl->m_aPropSeq.realloc( m_pImpl->size() );
96 [ + - ]: 376 : beans::Property* pPropArray = m_pImpl->m_aPropSeq.getArray();
97 : 376 : sal_uInt32 n = 0;
98 [ + - ]: 376 : SfxItemPropertyHashMap_t::const_iterator aIt = m_pImpl->begin();
99 [ + - ][ + + ]: 25547 : while( aIt != m_pImpl->end() )
100 : : //for ( const SfxItemPropertyMap *pMap = _pMap; pMap->pName; ++pMap )
101 : : {
102 [ + - ]: 25171 : const SfxItemPropertySimpleEntry* pEntry = &(*aIt).second;
103 [ + - ]: 25171 : pPropArray[n].Name = (*aIt).first;
104 : 25171 : pPropArray[n].Handle = pEntry->nWID;
105 [ + - ]: 25171 : if(pEntry->pType)
106 : 25171 : pPropArray[n].Type = *pEntry->pType;
107 : 25171 : pPropArray[n].Attributes =
108 : 25171 : sal::static_int_cast< sal_Int16 >(pEntry->nFlags);
109 : 25171 : n++;
110 : 25171 : ++aIt;
111 : : }
112 : : }
113 : :
114 : 899 : return m_pImpl->m_aPropSeq;
115 : : }
116 : :
117 : 3685 : beans::Property SfxItemPropertyMap::getPropertyByName( const ::rtl::OUString rName ) const
118 : : throw( beans::UnknownPropertyException )
119 : : {
120 [ + - ]: 3685 : SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName);
121 [ + + ][ + - ]: 3685 : if( aIter == m_pImpl->end() )
122 [ + - ]: 6 : throw UnknownPropertyException();
123 [ + - ]: 3679 : const SfxItemPropertySimpleEntry* pEntry = &aIter->second;
124 : 3679 : beans::Property aProp;
125 : 3679 : aProp.Name = rName;
126 : 3679 : aProp.Handle = pEntry->nWID;
127 [ + - ]: 3679 : if(pEntry->pType)
128 : 3679 : aProp.Type = *pEntry->pType;
129 : 3679 : aProp.Attributes = sal::static_int_cast< sal_Int16 >(pEntry->nFlags);
130 : 3679 : return aProp;
131 : : }
132 : :
133 : 232885 : sal_Bool SfxItemPropertyMap::hasPropertyByName( const ::rtl::OUString& rName ) const
134 : : {
135 [ + - ]: 232885 : SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName);
136 [ + - ]: 232885 : return aIter != m_pImpl->end();
137 : : }
138 : :
139 : 378 : void SfxItemPropertyMap::mergeProperties( const uno::Sequence< beans::Property >& rPropSeq )
140 : : {
141 : 378 : const beans::Property* pPropArray = rPropSeq.getConstArray();
142 : 378 : sal_uInt32 nElements = rPropSeq.getLength();
143 [ + + ]: 47451 : for( sal_uInt32 nElement = 0; nElement < nElements; ++nElement )
144 : : {
145 : : SfxItemPropertySimpleEntry aTemp(
146 : 47073 : sal::static_int_cast< sal_Int16 >( pPropArray[nElement].Handle ), //nWID
147 : 47073 : &pPropArray[nElement].Type, //pType
148 : 47073 : pPropArray[nElement].Attributes, //nFlags
149 : 47073 : 0 ); //nMemberId
150 [ + - ]: 47073 : (*m_pImpl)[pPropArray[nElement].Name] = aTemp;
151 : : }
152 : 378 : }
153 : :
154 : 817 : PropertyEntryVector_t SfxItemPropertyMap::getPropertyEntries() const
155 : : {
156 [ + - ]: 817 : PropertyEntryVector_t aRet;
157 [ + - ]: 817 : aRet.reserve(m_pImpl->size());
158 : :
159 [ + - ]: 817 : SfxItemPropertyHashMap_t::const_iterator aIt = m_pImpl->begin();
160 [ + - ][ + + ]: 69278 : while( aIt != m_pImpl->end() )
161 : : {
162 [ + - ]: 68461 : const SfxItemPropertySimpleEntry* pEntry = &(*aIt).second;
163 [ + - ][ + - ]: 68461 : aRet.push_back( SfxItemPropertyNamedEntry( (*aIt).first, * pEntry ) );
[ + - ][ + - ]
[ + - ]
164 : 68461 : ++aIt;
165 : : }
166 : 817 : return aRet;
167 : : }
168 : :
169 : 0 : sal_uInt32 SfxItemPropertyMap::getSize() const
170 : : {
171 : 0 : return m_pImpl->size();
172 : : }
173 : :
174 : 7723 : SfxItemPropertySet::~SfxItemPropertySet()
175 : : {
176 [ - + ]: 7723 : }
177 : :
178 : 22 : sal_Bool SfxItemPropertySet::FillItem(SfxItemSet&, sal_uInt16, sal_Bool) const
179 : : {
180 : 22 : return sal_False;
181 : : }
182 : :
183 : 13354 : void SfxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry& rEntry,
184 : : const SfxItemSet& rSet, Any& rAny ) const
185 : : throw(RuntimeException)
186 : : {
187 : : // get the SfxPoolItem
188 : 13354 : const SfxPoolItem* pItem = 0;
189 [ + - ]: 13354 : SfxItemState eState = rSet.GetItemState( rEntry.nWID, sal_True, &pItem );
190 [ + + ][ + - ]: 13354 : if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID )
191 [ + - ]: 3978 : pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID);
192 : : // return item values as uno::Any
193 [ + + ][ + - ]: 13354 : if(eState >= SFX_ITEM_DEFAULT && pItem)
194 : : {
195 [ + - ]: 13348 : pItem->QueryValue( rAny, rEntry.nMemberId );
196 : : }
197 : : else
198 : : {
199 [ + - ]: 6 : SfxItemSet aSet(*rSet.GetPool(), rEntry.nWID, rEntry.nWID);
200 [ + - ][ - + ]: 6 : if(FillItem(aSet, rEntry.nWID, sal_True))
201 : : {
202 [ # # ]: 0 : const SfxPoolItem& rItem = aSet.Get(rEntry.nWID);
203 [ # # ]: 0 : rItem.QueryValue( rAny, rEntry.nMemberId );
204 : : }
205 [ - + ]: 6 : else if(0 == (rEntry.nFlags & PropertyAttribute::MAYBEVOID))
206 [ # # ][ + - ]: 6 : throw RuntimeException();
207 : : }
208 : :
209 : :
210 : : // convert general SfxEnumItem values to specific values
211 [ + - ]: 13988 : if( rEntry.pType && TypeClass_ENUM == rEntry.pType->getTypeClass() &&
[ + + - + ]
[ - + ]
212 : 634 : rAny.getValueTypeClass() == TypeClass_LONG )
213 : : {
214 : 0 : sal_Int32 nTmp = *(sal_Int32*)rAny.getValue();
215 : 0 : rAny.setValue( &nTmp, *rEntry.pType );
216 : : }
217 : 13354 : }
218 : :
219 : 829 : void SfxItemPropertySet::getPropertyValue( const rtl::OUString &rName,
220 : : const SfxItemSet& rSet, Any& rAny ) const
221 : : throw(RuntimeException, UnknownPropertyException)
222 : : {
223 : : // detect which-id
224 : 829 : const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName );
225 [ - + ]: 829 : if ( !pEntry )
226 [ # # ]: 0 : throw UnknownPropertyException();
227 : 829 : getPropertyValue( *pEntry,rSet, rAny );
228 : 829 : }
229 : :
230 : 24 : Any SfxItemPropertySet::getPropertyValue( const rtl::OUString &rName,
231 : : const SfxItemSet& rSet ) const
232 : : throw(RuntimeException, UnknownPropertyException)
233 : : {
234 : 24 : Any aVal;
235 [ + - ]: 24 : getPropertyValue( rName,rSet, aVal );
236 : 24 : return aVal;
237 : : }
238 : :
239 : 56397 : void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEntry,
240 : : const Any& aVal,
241 : : SfxItemSet& rSet ) const
242 : : throw(RuntimeException,
243 : : IllegalArgumentException)
244 : : {
245 : : // get the SfxPoolItem
246 : 56397 : const SfxPoolItem* pItem = 0;
247 : 56397 : SfxPoolItem *pNewItem = 0;
248 [ + - ]: 56397 : SfxItemState eState = rSet.GetItemState( rEntry.nWID, sal_True, &pItem );
249 [ + + ][ + - ]: 56397 : if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID )
250 [ + - ]: 21284 : pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID);
251 : : //maybe there's another way to find an Item
252 [ + + ]: 56397 : if(eState < SFX_ITEM_DEFAULT)
253 : : {
254 [ + - ]: 16 : SfxItemSet aSet(*rSet.GetPool(), rEntry.nWID, rEntry.nWID);
255 [ + - ][ - + ]: 16 : if(FillItem(aSet, rEntry.nWID, sal_False))
256 : : {
257 [ # # ]: 0 : const SfxPoolItem &rItem = aSet.Get(rEntry.nWID);
258 [ # # ]: 0 : pNewItem = rItem.Clone();
259 [ + - ]: 16 : }
260 : : }
261 [ + - ][ + - ]: 56397 : if(!pNewItem && pItem)
262 : : {
263 [ + - ]: 56397 : pNewItem = pItem->Clone();
264 : : }
265 [ + - ]: 56397 : if(pNewItem)
266 : : {
267 [ + - ][ + + ]: 56397 : if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) )
268 : : {
269 [ + - ][ + - ]: 19 : DELETEZ(pNewItem);
270 [ + - ]: 19 : throw IllegalArgumentException();
271 : : }
272 : : // apply new item
273 [ + - ]: 56378 : rSet.Put( *pNewItem, rEntry.nWID );
274 [ + - ][ + - ]: 56378 : delete pNewItem;
275 : : }
276 : 56378 : }
277 : :
278 : 4015 : void SfxItemPropertySet::setPropertyValue( const rtl::OUString &rName,
279 : : const Any& aVal,
280 : : SfxItemSet& rSet ) const
281 : : throw(RuntimeException,
282 : : IllegalArgumentException,
283 : : UnknownPropertyException)
284 : : {
285 : 4015 : const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName );
286 [ - + ]: 4015 : if ( !pEntry )
287 : : {
288 [ # # ]: 0 : throw UnknownPropertyException();
289 : : }
290 : 4015 : setPropertyValue(*pEntry, aVal, rSet);
291 : 4015 : }
292 : :
293 : 26550 : PropertyState SfxItemPropertySet::getPropertyState(const SfxItemPropertySimpleEntry& rEntry, const SfxItemSet& rSet) const
294 : : throw()
295 : : {
296 : 26550 : PropertyState eRet = PropertyState_DIRECT_VALUE;
297 : 26550 : sal_uInt16 nWhich = rEntry.nWID;
298 : :
299 : : // item state holen
300 : 26550 : SfxItemState eState = rSet.GetItemState( nWhich, sal_False );
301 : : // item-Wert als UnoAny zurueckgeben
302 [ + + ]: 26550 : if(eState == SFX_ITEM_DEFAULT)
303 : 23405 : eRet = PropertyState_DEFAULT_VALUE;
304 [ + + ]: 3145 : else if(eState < SFX_ITEM_DEFAULT)
305 : 216 : eRet = PropertyState_AMBIGUOUS_VALUE;
306 : 26550 : return eRet;
307 : : }
308 : 1604 : PropertyState SfxItemPropertySet::getPropertyState(
309 : : const rtl::OUString& rName, const SfxItemSet& rSet) const
310 : : throw(UnknownPropertyException)
311 : : {
312 : 1604 : PropertyState eRet = PropertyState_DIRECT_VALUE;
313 : :
314 : : // which-id ermitteln
315 [ + - ]: 1604 : const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName );
316 [ + - ][ - + ]: 1604 : if( !pEntry || !pEntry->nWID )
317 : : {
318 [ # # ]: 0 : throw UnknownPropertyException();
319 : : }
320 : 1604 : sal_uInt16 nWhich = pEntry->nWID;
321 : :
322 : : // item holen
323 : 1604 : const SfxPoolItem* pItem = 0;
324 [ + - ]: 1604 : SfxItemState eState = rSet.GetItemState( nWhich, sal_False, &pItem );
325 [ + + ][ + - ]: 1604 : if(!pItem && nWhich != rSet.GetPool()->GetSlotId(nWhich))
[ + + ][ + + ]
326 [ + - ]: 452 : pItem = &rSet.GetPool()->GetDefaultItem(nWhich);
327 : : // item-Wert als UnoAny zurueckgeben
328 [ + + ]: 1604 : if(eState == SFX_ITEM_DEFAULT)
329 : 1480 : eRet = PropertyState_DEFAULT_VALUE;
330 [ - + ]: 124 : else if(eState < SFX_ITEM_DEFAULT)
331 : 0 : eRet = PropertyState_AMBIGUOUS_VALUE;
332 : 1604 : return eRet;
333 : : }
334 : :
335 : : Reference<XPropertySetInfo>
336 : 3773 : SfxItemPropertySet::getPropertySetInfo() const
337 : : {
338 [ + + ]: 3773 : if( !m_xInfo.is() )
339 [ + - ][ + - ]: 676 : m_xInfo = new SfxItemPropertySetInfo( m_aMap );
340 : 3773 : return m_xInfo;
341 : : }
342 : :
343 : : struct SfxItemPropertySetInfo_Impl
344 : : {
345 : : SfxItemPropertyMap* m_pOwnMap;
346 : : };
347 : :
348 : 1160 : SfxItemPropertySetInfo::SfxItemPropertySetInfo(const SfxItemPropertyMap &rMap ) :
349 [ + - ]: 1160 : m_pImpl( new SfxItemPropertySetInfo_Impl )
350 : : {
351 [ + - ][ + - ]: 1160 : m_pImpl->m_pOwnMap = new SfxItemPropertyMap( rMap );
352 : 1160 : }
353 : :
354 : 66 : SfxItemPropertySetInfo::SfxItemPropertySetInfo(const SfxItemPropertyMapEntry *pEntries ) :
355 [ + - ]: 66 : m_pImpl( new SfxItemPropertySetInfo_Impl )
356 : : {
357 [ + - ][ + - ]: 66 : m_pImpl->m_pOwnMap = new SfxItemPropertyMap( pEntries );
358 : 66 : }
359 : :
360 : : Sequence< Property > SAL_CALL
361 : 885 : SfxItemPropertySetInfo::getProperties( )
362 : : throw(RuntimeException)
363 : : {
364 : 885 : return m_pImpl->m_pOwnMap->getProperties();
365 : : }
366 : :
367 : 1220 : SfxItemPropertySetInfo::~SfxItemPropertySetInfo()
368 : : {
369 [ + - ][ + - ]: 1220 : delete m_pImpl->m_pOwnMap;
370 : 1220 : delete m_pImpl;
371 [ - + ]: 2440 : }
372 : :
373 : : Property SAL_CALL
374 : 3289 : SfxItemPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
375 : : throw(UnknownPropertyException, RuntimeException)
376 : : {
377 [ + + ]: 3289 : return m_pImpl->m_pOwnMap->getPropertyByName( rName );
378 : : }
379 : :
380 : : sal_Bool SAL_CALL
381 : 220954 : SfxItemPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
382 : : throw(RuntimeException)
383 : : {
384 : 220954 : return m_pImpl->m_pOwnMap->hasPropertyByName( rName );
385 : : }
386 : :
387 : 378 : SfxExtItemPropertySetInfo::SfxExtItemPropertySetInfo(
388 : : const SfxItemPropertyMapEntry *pMap,
389 : : const Sequence<Property>& rPropSeq ) :
390 [ + - ]: 378 : aExtMap( pMap )
391 : : {
392 [ + - ]: 378 : aExtMap.mergeProperties( rPropSeq );
393 : 378 : }
394 : :
395 [ + - ]: 338 : SfxExtItemPropertySetInfo::~SfxExtItemPropertySetInfo()
396 : : {
397 [ - + ]: 676 : }
398 : :
399 : : Sequence< Property > SAL_CALL
400 : 14 : SfxExtItemPropertySetInfo::getProperties( ) throw(RuntimeException)
401 : : {
402 : 14 : return aExtMap.getProperties();
403 : : }
404 : :
405 : : Property SAL_CALL
406 : 396 : SfxExtItemPropertySetInfo::getPropertyByName( const rtl::OUString& rPropertyName )
407 : : throw(UnknownPropertyException, RuntimeException)
408 : : {
409 [ + - ]: 396 : return aExtMap.getPropertyByName( rPropertyName );
410 : : }
411 : :
412 : : sal_Bool SAL_CALL
413 : 11931 : SfxExtItemPropertySetInfo::hasPropertyByName( const rtl::OUString& rPropertyName )
414 : : throw(RuntimeException)
415 : : {
416 : 11931 : return aExtMap.hasPropertyByName( rPropertyName );
417 : : }
418 : :
419 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|