Files
libreoffice/chart2/source/controller/itemsetwrapper/ItemConverter.cxx

263 lines
8.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2003-10-06 08:58:36 +00:00
#include "ItemConverter.hxx"
#include "macros.hxx"
2003-10-06 08:58:36 +00:00
#include <com/sun/star/lang/XComponent.hpp>
#include <svl/itemprop.hxx>
#include <svl/itemiter.hxx>
2003-10-06 08:58:36 +00:00
// header for class SfxWhichIter
#include <svl/whiter.hxx>
#include <svx/svxids.hrc>
2003-10-06 08:58:36 +00:00
using namespace ::com::sun::star;
namespace comphelper
2003-10-06 08:58:36 +00:00
{
ItemConverter::ItemConverter(
const uno::Reference< beans::XPropertySet > & rPropertySet,
SfxItemPool& rItemPool ) :
m_xPropertySet( rPropertySet ),
m_xPropertySetInfo( NULL ),
m_rItemPool( rItemPool ),
m_bIsValid( true )
{
resetPropertySet( m_xPropertySet );
}
ItemConverter::~ItemConverter()
{
stopAllComponentListening();
}
void ItemConverter::resetPropertySet(
const uno::Reference< beans::XPropertySet > & xPropSet )
{
if( xPropSet.is())
2003-10-06 08:58:36 +00:00
{
stopAllComponentListening();
m_xPropertySet = xPropSet;
2003-10-06 08:58:36 +00:00
m_xPropertySetInfo = m_xPropertySet->getPropertySetInfo();
uno::Reference< lang::XComponent > xComp( m_xPropertySet, uno::UNO_QUERY );
if( xComp.is())
{
// method of base class ::utl::OEventListenerAdapter
startComponentListening( xComp );
}
2003-10-06 08:58:36 +00:00
}
}
SfxItemPool & ItemConverter::GetItemPool() const
{
return m_rItemPool;
}
SfxItemSet ItemConverter::CreateEmptyItemSet() const
{
return SfxItemSet( GetItemPool(), GetWhichPairs() );
}
uno::Reference< beans::XPropertySet > ItemConverter::GetPropertySet() const
2003-10-06 08:58:36 +00:00
{
return m_xPropertySet;
}
void ItemConverter::_disposing( const lang::EventObject& rSource )
{
if( rSource.Source == m_xPropertySet )
{
m_bIsValid = false;
}
}
2003-10-06 08:58:36 +00:00
void ItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
{
const sal_uInt16 * pRanges = rOutItemSet.GetRanges();
tPropertyNameWithMemberId aProperty;
2003-10-06 08:58:36 +00:00
SfxItemPool & rPool = GetItemPool();
OSL_ASSERT( pRanges != NULL );
OSL_ASSERT( m_xPropertySetInfo.is());
OSL_ASSERT( m_xPropertySet.is());
while( (*pRanges) != 0)
{
sal_uInt16 nBeg = (*pRanges);
2003-10-06 08:58:36 +00:00
++pRanges;
sal_uInt16 nEnd = (*pRanges);
2003-10-06 08:58:36 +00:00
++pRanges;
OSL_ASSERT( nBeg <= nEnd );
for( sal_uInt16 nWhich = nBeg; nWhich <= nEnd; ++nWhich )
2003-10-06 08:58:36 +00:00
{
if( GetItemProperty( nWhich, aProperty ))
2003-10-06 08:58:36 +00:00
{
// put the Property into the itemset
SfxPoolItem * pItem = rPool.GetDefaultItem( nWhich ).Clone();
if( pItem )
{
try
{
if( ! pItem->PutValue( m_xPropertySet->getPropertyValue( aProperty.first ),
aProperty.second // nMemberId
2003-10-06 08:58:36 +00:00
))
{
delete pItem;
}
else
{
rOutItemSet.Put( *pItem, nWhich );
delete pItem;
}
}
2011-11-29 02:06:57 +09:00
catch( const beans::UnknownPropertyException &ex )
2003-10-06 08:58:36 +00:00
{
delete pItem;
(void)ex;
OSL_FAIL(
::rtl::OUStringToOString(
ex.Message +
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
" - unknown Property: " )) + aProperty.first,
RTL_TEXTENCODING_ASCII_US ).getStr());
2003-10-06 08:58:36 +00:00
}
2011-11-29 02:06:57 +09:00
catch( const uno::Exception &ex )
{
ASSERT_EXCEPTION( ex );
}
2003-10-06 08:58:36 +00:00
}
}
else
{
try
{
FillSpecialItem( nWhich, rOutItemSet );
}
2011-11-29 02:06:57 +09:00
catch( const uno::Exception &ex )
{
ASSERT_EXCEPTION( ex );
}
2003-10-06 08:58:36 +00:00
}
}
}
}
void ItemConverter::FillSpecialItem(
sal_uInt16 /*nWhichId*/, SfxItemSet & /*rOutItemSet*/ ) const
throw( uno::Exception )
2003-10-06 08:58:36 +00:00
{
OSL_FAIL( "ItemConverter: Unhandled special item found!" );
2003-10-06 08:58:36 +00:00
}
bool ItemConverter::ApplySpecialItem(
sal_uInt16 /*nWhichId*/, const SfxItemSet & /*rItemSet*/ )
throw( uno::Exception )
2003-10-06 08:58:36 +00:00
{
OSL_FAIL( "ItemConverter: Unhandled special item found!" );
2003-10-06 08:58:36 +00:00
return false;
}
bool ItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
{
OSL_ASSERT( m_xPropertySet.is());
bool bItemsChanged = false;
SfxItemIter aIter( rItemSet );
const SfxPoolItem * pItem = aIter.FirstItem();
tPropertyNameWithMemberId aProperty;
2003-10-06 08:58:36 +00:00
uno::Any aValue;
while( pItem )
{
if( rItemSet.GetItemState( pItem->Which(), sal_False ) == SFX_ITEM_SET )
2003-10-06 08:58:36 +00:00
{
if( GetItemProperty( pItem->Which(), aProperty ))
2003-10-06 08:58:36 +00:00
{
pItem->QueryValue( aValue, aProperty.second /* nMemberId */ );
2003-10-06 08:58:36 +00:00
try
{
if( aValue != m_xPropertySet->getPropertyValue( aProperty.first ))
2003-10-06 08:58:36 +00:00
{
m_xPropertySet->setPropertyValue( aProperty.first, aValue );
2003-10-06 08:58:36 +00:00
bItemsChanged = true;
}
}
2011-11-29 02:06:57 +09:00
catch( const beans::UnknownPropertyException &ex )
2003-10-06 08:58:36 +00:00
{
(void)ex;
OSL_FAIL(
::rtl::OUStringToOString(
ex.Message +
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
" - unknown Property: " )) + aProperty.first,
RTL_TEXTENCODING_ASCII_US).getStr());
}
2011-11-29 02:06:57 +09:00
catch( const uno::Exception &ex )
{
(void)ex;
OSL_FAIL( ::rtl::OUStringToOString(
ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
2003-10-06 08:58:36 +00:00
}
}
else
{
bItemsChanged = ApplySpecialItem( pItem->Which(), rItemSet ) || bItemsChanged;
}
}
pItem = aIter.NextItem();
}
return bItemsChanged;
}
// --------------------------------------------------------------------------------
2003-10-06 08:58:36 +00:00
void ItemConverter::InvalidateUnequalItems( SfxItemSet &rDestSet, const SfxItemSet &rSourceSet )
{
SfxWhichIter aIter (rSourceSet);
sal_uInt16 nWhich = aIter.FirstWhich ();
2003-10-06 08:58:36 +00:00
const SfxPoolItem *pPoolItem = NULL;
while (nWhich)
{
if ((rSourceSet.GetItemState(nWhich, sal_True, &pPoolItem) == SFX_ITEM_SET) &&
(rDestSet.GetItemState(nWhich, sal_True, &pPoolItem) == SFX_ITEM_SET))
{
2003-10-06 08:58:36 +00:00
if (rSourceSet.Get(nWhich) != rDestSet.Get(nWhich))
{
if( SID_CHAR_DLG_PREVIEW_STRING != nWhich )
{
rDestSet.InvalidateItem(nWhich);
}
}
}
else if( rSourceSet.GetItemState(nWhich, sal_True, &pPoolItem) == SFX_ITEM_DONTCARE )
rDestSet.InvalidateItem(nWhich);
2003-10-06 08:58:36 +00:00
nWhich = aIter.NextWhich ();
}
}
} // namespace comphelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */