1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ItemConverter.cxx,v $
10 * $Revision: 1.15.24.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ItemConverter.hxx"
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <svtools/itemprop.hxx>
37 #include <svtools/itemiter.hxx>
38 // header for class SfxWhichIter
39 #include <svtools/whiter.hxx>
40 #include <svx/svxids.hrc>
42 using namespace ::com::sun::star
;
47 ItemConverter::ItemConverter(
48 const uno::Reference
< beans::XPropertySet
> & rPropertySet
,
49 SfxItemPool
& rItemPool
) :
50 m_xPropertySet( rPropertySet
),
51 m_xPropertySetInfo( NULL
),
52 m_rItemPool( rItemPool
),
55 resetPropertySet( m_xPropertySet
);
58 ItemConverter::~ItemConverter()
60 stopAllComponentListening();
63 void ItemConverter::resetPropertySet(
64 const uno::Reference
< beans::XPropertySet
> & xPropSet
)
68 stopAllComponentListening();
69 m_xPropertySet
= xPropSet
;
70 m_xPropertySetInfo
= m_xPropertySet
->getPropertySetInfo();
72 uno::Reference
< lang::XComponent
> xComp( m_xPropertySet
, uno::UNO_QUERY
);
75 // method of base class ::utl::OEventListenerAdapter
76 startComponentListening( xComp
);
81 SfxItemPool
& ItemConverter::GetItemPool() const
86 SfxItemSet
ItemConverter::CreateEmptyItemSet() const
88 return SfxItemSet( GetItemPool(), GetWhichPairs() );
91 uno::Reference
< beans::XPropertySet
> ItemConverter::GetPropertySet() const
93 return m_xPropertySet
;
96 void ItemConverter::_disposing( const lang::EventObject
& rSource
)
98 if( rSource
.Source
== m_xPropertySet
)
104 void ItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
106 const USHORT
* pRanges
= rOutItemSet
.GetRanges();
107 tPropertyNameWithMemberId aProperty
;
108 SfxItemPool
& rPool
= GetItemPool();
110 OSL_ASSERT( pRanges
!= NULL
);
111 OSL_ASSERT( m_xPropertySetInfo
.is());
112 OSL_ASSERT( m_xPropertySet
.is());
114 while( (*pRanges
) != 0)
116 USHORT nBeg
= (*pRanges
);
118 USHORT nEnd
= (*pRanges
);
121 OSL_ASSERT( nBeg
<= nEnd
);
122 for( USHORT nWhich
= nBeg
; nWhich
<= nEnd
; ++nWhich
)
124 if( GetItemProperty( nWhich
, aProperty
))
126 // put the Property into the itemset
127 SfxPoolItem
* pItem
= rPool
.GetDefaultItem( nWhich
).Clone();
133 if( ! pItem
->PutValue( m_xPropertySet
->getPropertyValue( aProperty
.first
),
134 aProperty
.second
// nMemberId
141 rOutItemSet
.Put( *pItem
, nWhich
);
145 catch( beans::UnknownPropertyException ex
)
149 ::rtl::OUStringToOString(
151 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
152 " - unknown Property: " )) + aProperty
.first
,
153 RTL_TEXTENCODING_ASCII_US
).getStr());
155 catch( uno::Exception ex
)
157 ASSERT_EXCEPTION( ex
);
165 FillSpecialItem( nWhich
, rOutItemSet
);
167 catch( uno::Exception ex
)
169 ASSERT_EXCEPTION( ex
);
176 void ItemConverter::FillSpecialItem(
177 USHORT
/*nWhichId*/, SfxItemSet
& /*rOutItemSet*/ ) const
178 throw( uno::Exception
)
180 OSL_ENSURE( false, "ItemConverter: Unhandled special item found!" );
183 bool ItemConverter::ApplySpecialItem(
184 USHORT
/*nWhichId*/, const SfxItemSet
& /*rItemSet*/ )
185 throw( uno::Exception
)
187 OSL_ENSURE( false, "ItemConverter: Unhandled special item found!" );
191 bool ItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
193 OSL_ASSERT( m_xPropertySet
.is());
195 bool bItemsChanged
= false;
196 SfxItemIter
aIter( rItemSet
);
197 const SfxPoolItem
* pItem
= aIter
.FirstItem();
198 tPropertyNameWithMemberId aProperty
;
203 if( rItemSet
.GetItemState( pItem
->Which(), FALSE
) == SFX_ITEM_SET
)
205 if( GetItemProperty( pItem
->Which(), aProperty
))
207 pItem
->QueryValue( aValue
, aProperty
.second
/* nMemberId */ );
211 if( aValue
!= m_xPropertySet
->getPropertyValue( aProperty
.first
))
213 m_xPropertySet
->setPropertyValue( aProperty
.first
, aValue
);
214 bItemsChanged
= true;
217 catch( beans::UnknownPropertyException ex
)
220 ::rtl::OUStringToOString(
222 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
223 " - unknown Property: " )) + aProperty
.first
,
224 RTL_TEXTENCODING_ASCII_US
).getStr());
226 catch( uno::Exception ex
)
228 OSL_ENSURE( false, ::rtl::OUStringToOString(
229 ex
.Message
, RTL_TEXTENCODING_ASCII_US
).getStr());
234 bItemsChanged
= ApplySpecialItem( pItem
->Which(), rItemSet
) || bItemsChanged
;
237 pItem
= aIter
.NextItem();
240 return bItemsChanged
;
243 // --------------------------------------------------------------------------------
246 void ItemConverter::InvalidateUnequalItems( SfxItemSet
&rDestSet
, const SfxItemSet
&rSourceSet
)
248 SfxWhichIter
aIter (rSourceSet
);
249 USHORT nWhich
= aIter
.FirstWhich ();
250 const SfxPoolItem
*pPoolItem
= NULL
;
254 if ((rSourceSet
.GetItemState(nWhich
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
) &&
255 (rDestSet
.GetItemState(nWhich
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
))
257 if (rSourceSet
.Get(nWhich
) != rDestSet
.Get(nWhich
))
259 if( SID_CHAR_DLG_PREVIEW_STRING
!= nWhich
)
261 rDestSet
.InvalidateItem(nWhich
);
265 else if( rSourceSet
.GetItemState(nWhich
, TRUE
, &pPoolItem
) == SFX_ITEM_DONTCARE
)
266 rDestSet
.InvalidateItem(nWhich
);
268 nWhich
= aIter
.NextWhich ();
272 } // namespace comphelper