fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / ItemConverter.cxx
bloba5acbc5be764a9ac76cd475f8801fff5b2f5612f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
21 #include "macros.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 ),
39 m_bIsValid( true )
41 resetPropertySet( m_xPropertySet );
44 ItemConverter::~ItemConverter()
46 stopAllComponentListening();
49 void ItemConverter::resetPropertySet(
50 const uno::Reference< beans::XPropertySet > & xPropSet )
52 if( xPropSet.is())
54 stopAllComponentListening();
55 m_xPropertySet = xPropSet;
56 m_xPropertySetInfo = m_xPropertySet->getPropertySetInfo();
58 uno::Reference< lang::XComponent > xComp( m_xPropertySet, uno::UNO_QUERY );
59 if( xComp.is())
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 )
76 m_bIsValid = false;
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);
93 ++pRanges;
94 sal_uInt16 nEnd = (*pRanges);
95 ++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();
105 if( pItem )
109 if( ! pItem->PutValue( m_xPropertySet->getPropertyValue( aProperty.first ),
110 aProperty.second // nMemberId
113 delete pItem;
115 else
117 rOutItemSet.Put( *pItem, nWhich );
118 delete pItem;
121 catch( const beans::UnknownPropertyException &ex )
123 delete pItem;
124 (void)ex;
125 OSL_FAIL(
126 OUStringToOString(
127 ex.Message +
128 " - unknown Property: " + aProperty.first,
129 RTL_TEXTENCODING_ASCII_US ).getStr());
131 catch( const uno::Exception &ex )
133 ASSERT_EXCEPTION( ex );
137 else
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!" );
164 return false;
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;
175 uno::Any aValue;
177 while( pItem )
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 )
195 (void)ex;
196 OSL_FAIL(
197 OUStringToOString(
198 ex.Message +
199 " - unknown Property: " + aProperty.first,
200 RTL_TEXTENCODING_ASCII_US).getStr());
202 catch( const uno::Exception &ex )
204 (void)ex;
205 OSL_FAIL( OUStringToOString(
206 ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
209 else
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;
226 while (nWhich)
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: */