1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ItemConverter.hxx"
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <osl/diagnose.h>
24 #include <svl/itemprop.hxx>
25 #include <svl/itemiter.hxx>
26 #include <svl/whiter.hxx>
27 #include <svx/svxids.hrc>
29 using namespace ::com::sun::star
;
31 namespace chart
{ namespace wrapper
{
33 ItemConverter::ItemConverter(
34 const uno::Reference
< beans::XPropertySet
> & rPropertySet
,
35 SfxItemPool
& rItemPool
) :
36 m_xPropertySet( rPropertySet
),
37 m_xPropertySetInfo( NULL
),
38 m_rItemPool( rItemPool
),
41 resetPropertySet( m_xPropertySet
);
44 ItemConverter::~ItemConverter()
46 stopAllComponentListening();
49 void ItemConverter::resetPropertySet(
50 const uno::Reference
< beans::XPropertySet
> & xPropSet
)
54 stopAllComponentListening();
55 m_xPropertySet
= xPropSet
;
56 m_xPropertySetInfo
= m_xPropertySet
->getPropertySetInfo();
58 uno::Reference
< lang::XComponent
> xComp( m_xPropertySet
, uno::UNO_QUERY
);
61 // method of base class ::utl::OEventListenerAdapter
62 startComponentListening( xComp
);
67 SfxItemSet
ItemConverter::CreateEmptyItemSet() const
69 return SfxItemSet( GetItemPool(), GetWhichPairs() );
72 void ItemConverter::_disposing( const lang::EventObject
& rSource
)
74 if( rSource
.Source
== m_xPropertySet
)
80 void ItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
82 const sal_uInt16
* pRanges
= rOutItemSet
.GetRanges();
83 tPropertyNameWithMemberId aProperty
;
84 SfxItemPool
& rPool
= GetItemPool();
86 assert(pRanges
!= NULL
);
87 OSL_ASSERT( m_xPropertySetInfo
.is());
88 OSL_ASSERT( m_xPropertySet
.is());
90 while( (*pRanges
) != 0)
92 sal_uInt16 nBeg
= (*pRanges
);
94 sal_uInt16 nEnd
= (*pRanges
);
97 OSL_ASSERT( nBeg
<= nEnd
);
98 for( sal_uInt16 nWhich
= nBeg
; nWhich
<= nEnd
; ++nWhich
)
100 if( GetItemProperty( nWhich
, aProperty
))
102 // put the Property into the itemset
103 SfxPoolItem
* pItem
= rPool
.GetDefaultItem( nWhich
).Clone();
109 if( ! pItem
->PutValue( m_xPropertySet
->getPropertyValue( aProperty
.first
),
110 aProperty
.second
// nMemberId
117 rOutItemSet
.Put( *pItem
, nWhich
);
121 catch( const beans::UnknownPropertyException
&ex
)
128 " - unknown Property: " + aProperty
.first
,
129 RTL_TEXTENCODING_ASCII_US
).getStr());
131 catch( const uno::Exception
&ex
)
133 ASSERT_EXCEPTION( ex
);
141 FillSpecialItem( nWhich
, rOutItemSet
);
143 catch( const uno::Exception
&ex
)
145 ASSERT_EXCEPTION( ex
);
152 void ItemConverter::FillSpecialItem(
153 sal_uInt16
/*nWhichId*/, SfxItemSet
& /*rOutItemSet*/ ) const
154 throw (uno::Exception
, std::exception
)
156 OSL_FAIL( "ItemConverter: Unhandled special item found!" );
159 bool ItemConverter::ApplySpecialItem(
160 sal_uInt16
/*nWhichId*/, const SfxItemSet
& /*rItemSet*/ )
161 throw( uno::Exception
)
163 OSL_FAIL( "ItemConverter: Unhandled special item found!" );
167 bool ItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
169 OSL_ASSERT( m_xPropertySet
.is());
171 bool bItemsChanged
= false;
172 SfxItemIter
aIter( rItemSet
);
173 const SfxPoolItem
* pItem
= aIter
.FirstItem();
174 tPropertyNameWithMemberId aProperty
;
179 if( rItemSet
.GetItemState( pItem
->Which(), false ) == SfxItemState::SET
)
181 if( GetItemProperty( pItem
->Which(), aProperty
))
183 pItem
->QueryValue( aValue
, aProperty
.second
/* nMemberId */ );
187 if( aValue
!= m_xPropertySet
->getPropertyValue( aProperty
.first
))
189 m_xPropertySet
->setPropertyValue( aProperty
.first
, aValue
);
190 bItemsChanged
= true;
193 catch( const beans::UnknownPropertyException
&ex
)
199 " - unknown Property: " + aProperty
.first
,
200 RTL_TEXTENCODING_ASCII_US
).getStr());
202 catch( const uno::Exception
&ex
)
205 OSL_FAIL( OUStringToOString(
206 ex
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr());
211 bItemsChanged
= ApplySpecialItem( pItem
->Which(), rItemSet
) || bItemsChanged
;
214 pItem
= aIter
.NextItem();
217 return bItemsChanged
;
220 void ItemConverter::InvalidateUnequalItems( SfxItemSet
&rDestSet
, const SfxItemSet
&rSourceSet
)
222 SfxWhichIter
aIter (rSourceSet
);
223 sal_uInt16 nWhich
= aIter
.FirstWhich ();
224 const SfxPoolItem
*pPoolItem
= NULL
;
228 if ((rSourceSet
.GetItemState(nWhich
, true, &pPoolItem
) == SfxItemState::SET
) &&
229 (rDestSet
.GetItemState(nWhich
, true, &pPoolItem
) == SfxItemState::SET
))
231 if (rSourceSet
.Get(nWhich
) != rDestSet
.Get(nWhich
))
233 if( SID_CHAR_DLG_PREVIEW_STRING
!= nWhich
)
235 rDestSet
.InvalidateItem(nWhich
);
239 else if( rSourceSet
.GetItemState(nWhich
, true, &pPoolItem
) == SfxItemState::DONTCARE
)
240 rDestSet
.InvalidateItem(nWhich
);
242 nWhich
= aIter
.NextWhich ();
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */