2003-10-06 08:58:36 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* $RCSfile: ItemConverter.cxx,v $
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2006-09-17 12:02:17 +00:00
|
|
|
* $Revision: 1.9 $
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2006-09-17 12:02:17 +00:00
|
|
|
* last change: $Author: obo $ $Date: 2006-09-17 13:02:17 $
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2005-09-07 23:29:26 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 12:02:17 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_chart2.hxx"
|
2003-10-06 08:58:36 +00:00
|
|
|
#include "ItemConverter.hxx"
|
2003-10-17 13:30:15 +00:00
|
|
|
#include "macros.hxx"
|
2003-10-06 08:58:36 +00:00
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _SFX_ITEMPROP_HXX
|
|
|
|
#include <svtools/itemprop.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SFXITEMITER_HXX
|
|
|
|
#include <svtools/itemiter.hxx>
|
|
|
|
#endif
|
|
|
|
// header for class SfxWhichIter
|
|
|
|
#ifndef _SFX_WHITER_HXX
|
|
|
|
#include <svtools/whiter.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
2003-10-07 16:18:46 +00:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( m_xPropertySet.is())
|
|
|
|
{
|
|
|
|
m_xPropertySetInfo = m_xPropertySet->getPropertySetInfo();
|
|
|
|
|
2003-10-07 14:39:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemConverter::~ItemConverter()
|
|
|
|
{
|
2003-10-07 14:39:56 +00:00
|
|
|
stopAllComponentListening();
|
2003-10-06 08:58:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SfxItemPool & ItemConverter::GetItemPool() const
|
|
|
|
{
|
|
|
|
return m_rItemPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
SfxItemSet ItemConverter::CreateEmptyItemSet() const
|
|
|
|
{
|
|
|
|
return SfxItemSet( GetItemPool(), GetWhichPairs() );
|
|
|
|
}
|
|
|
|
|
2003-10-07 10:39:34 +00:00
|
|
|
bool ItemConverter::IsValid() const
|
|
|
|
{
|
|
|
|
return m_bIsValid;
|
|
|
|
}
|
|
|
|
|
2003-10-07 14:39:56 +00:00
|
|
|
uno::Reference< beans::XPropertySet > ItemConverter::GetPropertySet() const
|
2003-10-06 08:58:36 +00:00
|
|
|
{
|
|
|
|
return m_xPropertySet;
|
|
|
|
}
|
|
|
|
|
2003-10-07 14:39:56 +00:00
|
|
|
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 USHORT * pRanges = rOutItemSet.GetRanges();
|
|
|
|
::rtl::OUString aPropName;
|
|
|
|
SfxItemPool & rPool = GetItemPool();
|
|
|
|
|
|
|
|
OSL_ASSERT( pRanges != NULL );
|
|
|
|
OSL_ASSERT( m_xPropertySetInfo.is());
|
|
|
|
OSL_ASSERT( m_xPropertySet.is());
|
|
|
|
|
|
|
|
while( (*pRanges) != 0)
|
|
|
|
{
|
|
|
|
USHORT nBeg = (*pRanges);
|
|
|
|
++pRanges;
|
|
|
|
USHORT nEnd = (*pRanges);
|
|
|
|
++pRanges;
|
|
|
|
|
|
|
|
OSL_ASSERT( nBeg <= nEnd );
|
|
|
|
for( USHORT nWhich = nBeg; nWhich <= nEnd; ++nWhich )
|
|
|
|
{
|
|
|
|
if( GetItemPropertyName( nWhich, aPropName ))
|
|
|
|
{
|
|
|
|
// put the Property into the itemset
|
|
|
|
SfxPoolItem * pItem = rPool.GetDefaultItem( nWhich ).Clone();
|
|
|
|
|
|
|
|
if( pItem )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( ! pItem->PutValue( m_xPropertySet->getPropertyValue( aPropName ),
|
|
|
|
0 // nMemberId
|
|
|
|
))
|
|
|
|
{
|
|
|
|
delete pItem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rOutItemSet.Put( *pItem, nWhich );
|
|
|
|
delete pItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException ex )
|
|
|
|
{
|
2003-10-17 13:30:15 +00:00
|
|
|
delete pItem;
|
2003-10-07 14:39:56 +00:00
|
|
|
OSL_ENSURE( false,
|
|
|
|
::rtl::OUStringToOString(
|
|
|
|
ex.Message +
|
|
|
|
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
" - unknown Property: " )) + aPropName,
|
|
|
|
RTL_TEXTENCODING_ASCII_US ).getStr());
|
2003-10-06 08:58:36 +00:00
|
|
|
}
|
2003-10-07 14:39:56 +00:00
|
|
|
catch( uno::Exception ex )
|
|
|
|
{
|
2003-10-17 13:30:15 +00:00
|
|
|
ASSERT_EXCEPTION( ex );
|
2003-10-07 14:39:56 +00:00
|
|
|
}
|
2003-10-06 08:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-10-17 13:30:15 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
FillSpecialItem( nWhich, rOutItemSet );
|
|
|
|
}
|
|
|
|
catch( uno::Exception ex )
|
|
|
|
{
|
|
|
|
ASSERT_EXCEPTION( ex );
|
|
|
|
}
|
2003-10-06 08:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemConverter::GetItemPropertyName(
|
|
|
|
USHORT nWhichId, ::rtl::OUString & rOutName ) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemConverter::FillSpecialItem(
|
|
|
|
USHORT nWhichId, SfxItemSet & rOutItemSet ) const
|
2003-10-17 13:30:15 +00:00
|
|
|
throw( uno::Exception )
|
2003-10-06 08:58:36 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE( false, "ItemConverter: Unhandled special item found!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemConverter::ApplySpecialItem(
|
2003-11-04 11:37:45 +00:00
|
|
|
USHORT nWhichId, const SfxItemSet & rItemSet )
|
2003-10-17 13:30:15 +00:00
|
|
|
throw( uno::Exception )
|
2003-10-06 08:58:36 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE( false, "ItemConverter: Unhandled special item found!" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
|
|
|
|
{
|
|
|
|
OSL_ASSERT( m_xPropertySet.is());
|
|
|
|
|
|
|
|
bool bItemsChanged = false;
|
|
|
|
SfxItemIter aIter( rItemSet );
|
|
|
|
const SfxPoolItem * pItem = aIter.FirstItem();
|
|
|
|
::rtl::OUString aPropName;
|
|
|
|
uno::Any aValue;
|
|
|
|
|
|
|
|
while( pItem )
|
|
|
|
{
|
|
|
|
if( rItemSet.GetItemState( pItem->Which(), FALSE ) == SFX_ITEM_SET )
|
|
|
|
{
|
|
|
|
if( GetItemPropertyName( pItem->Which(), aPropName ))
|
|
|
|
{
|
|
|
|
pItem->QueryValue( aValue, 0 /* nMemberId */ );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( aValue != m_xPropertySet->getPropertyValue( aPropName ))
|
|
|
|
{
|
|
|
|
m_xPropertySet->setPropertyValue( aPropName, aValue );
|
|
|
|
bItemsChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( beans::UnknownPropertyException ex )
|
|
|
|
{
|
2003-10-07 14:39:56 +00:00
|
|
|
OSL_ENSURE( false,
|
|
|
|
::rtl::OUStringToOString(
|
|
|
|
ex.Message +
|
|
|
|
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
" - unknown Property: " )) + aPropName,
|
|
|
|
RTL_TEXTENCODING_ASCII_US).getStr());
|
|
|
|
}
|
|
|
|
catch( uno::Exception ex )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( false, ::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-07 14:39:56 +00:00
|
|
|
// --------------------------------------------------------------------------------
|
2003-10-06 08:58:36 +00:00
|
|
|
|
|
|
|
//static
|
|
|
|
void ItemConverter::InvalidateUnequalItems( SfxItemSet &rDestSet, const SfxItemSet &rSourceSet )
|
|
|
|
{
|
|
|
|
SfxWhichIter aIter (rSourceSet);
|
|
|
|
USHORT nWhich = aIter.FirstWhich ();
|
|
|
|
const SfxPoolItem *pPoolItem = NULL;
|
|
|
|
|
|
|
|
while (nWhich)
|
|
|
|
{
|
|
|
|
if ((rSourceSet.GetItemState(nWhich, TRUE, &pPoolItem) == SFX_ITEM_SET) &&
|
|
|
|
(rDestSet.GetItemState(nWhich, TRUE, &pPoolItem) == SFX_ITEM_SET))
|
|
|
|
if (rSourceSet.Get(nWhich) != rDestSet.Get(nWhich))
|
|
|
|
rDestSet.InvalidateItem(nWhich);
|
|
|
|
|
|
|
|
nWhich = aIter.NextWhich ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-07 16:18:46 +00:00
|
|
|
} // namespace comphelper
|