2003-10-06 08:58:36 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 19:44:29 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2008-04-10 19:44:29 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2008-04-10 19:44:29 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2008-04-10 19:44:29 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2008-04-10 19:44:29 +00:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2003-10-06 08:58:36 +00:00
|
|
|
*
|
2008-04-10 19:44:29 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
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
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/itemprop.hxx>
|
|
|
|
#include <svl/itemiter.hxx>
|
2003-10-06 08:58:36 +00:00
|
|
|
// header for class SfxWhichIter
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/whiter.hxx>
|
2008-06-06 08:09:04 +00:00
|
|
|
#include <svx/svxids.hrc>
|
2003-10-06 08:58:36 +00:00
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2008-02-18 14:55:34 +00:00
|
|
|
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
|
|
|
{
|
2008-02-18 14:55:34 +00:00
|
|
|
stopAllComponentListening();
|
|
|
|
m_xPropertySet = xPropSet;
|
2003-10-06 08:58:36 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SfxItemPool & ItemConverter::GetItemPool() const
|
|
|
|
{
|
|
|
|
return m_rItemPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
SfxItemSet ItemConverter::CreateEmptyItemSet() const
|
|
|
|
{
|
|
|
|
return SfxItemSet( GetItemPool(), GetWhichPairs() );
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-05-22 17:00:55 +00:00
|
|
|
void ItemConverter::_disposing( const lang::EventObject& rSource )
|
2003-10-07 14:39:56 +00:00
|
|
|
{
|
2007-05-22 17:00:55 +00:00
|
|
|
if( rSource.Source == m_xPropertySet )
|
2003-10-07 14:39:56 +00:00
|
|
|
{
|
|
|
|
m_bIsValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-06 08:58:36 +00:00
|
|
|
void ItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
|
|
|
|
{
|
|
|
|
const USHORT * pRanges = rOutItemSet.GetRanges();
|
2007-05-22 17:00:55 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
USHORT nBeg = (*pRanges);
|
|
|
|
++pRanges;
|
|
|
|
USHORT nEnd = (*pRanges);
|
|
|
|
++pRanges;
|
|
|
|
|
|
|
|
OSL_ASSERT( nBeg <= nEnd );
|
|
|
|
for( USHORT nWhich = nBeg; nWhich <= nEnd; ++nWhich )
|
|
|
|
{
|
2007-05-22 17:00:55 +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
|
|
|
|
{
|
2007-05-22 17:00:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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(
|
2007-05-22 17:00:55 +00:00
|
|
|
" - unknown Property: " )) + aProperty.first,
|
2003-10-07 14:39:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemConverter::FillSpecialItem(
|
2007-07-25 07:41:02 +00:00
|
|
|
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(
|
2007-07-25 07:41:02 +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();
|
2007-05-22 17:00:55 +00:00
|
|
|
tPropertyNameWithMemberId aProperty;
|
2003-10-06 08:58:36 +00:00
|
|
|
uno::Any aValue;
|
|
|
|
|
|
|
|
while( pItem )
|
|
|
|
{
|
|
|
|
if( rItemSet.GetItemState( pItem->Which(), FALSE ) == SFX_ITEM_SET )
|
|
|
|
{
|
2007-05-22 17:00:55 +00:00
|
|
|
if( GetItemProperty( pItem->Which(), aProperty ))
|
2003-10-06 08:58:36 +00:00
|
|
|
{
|
2007-05-22 17:00:55 +00:00
|
|
|
pItem->QueryValue( aValue, aProperty.second /* nMemberId */ );
|
2003-10-06 08:58:36 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2007-05-22 17:00:55 +00:00
|
|
|
if( aValue != m_xPropertySet->getPropertyValue( aProperty.first ))
|
2003-10-06 08:58:36 +00:00
|
|
|
{
|
2007-05-22 17:00:55 +00:00
|
|
|
m_xPropertySet->setPropertyValue( aProperty.first, aValue );
|
2003-10-06 08:58:36 +00:00
|
|
|
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(
|
2007-05-22 17:00:55 +00:00
|
|
|
" - unknown Property: " )) + aProperty.first,
|
2003-10-07 14:39:56 +00:00
|
|
|
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))
|
2007-10-22 15:51:22 +00:00
|
|
|
{
|
2003-10-06 08:58:36 +00:00
|
|
|
if (rSourceSet.Get(nWhich) != rDestSet.Get(nWhich))
|
2008-06-06 08:09:04 +00:00
|
|
|
{
|
|
|
|
if( SID_CHAR_DLG_PREVIEW_STRING != nWhich )
|
|
|
|
{
|
|
|
|
rDestSet.InvalidateItem(nWhich);
|
|
|
|
}
|
|
|
|
}
|
2007-10-22 15:51:22 +00:00
|
|
|
}
|
|
|
|
else if( rSourceSet.GetItemState(nWhich, TRUE, &pPoolItem) == SFX_ITEM_DONTCARE )
|
|
|
|
rDestSet.InvalidateItem(nWhich);
|
2003-10-06 08:58:36 +00:00
|
|
|
|
|
|
|
nWhich = aIter.NextWhich ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-07 16:18:46 +00:00
|
|
|
} // namespace comphelper
|