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

196 lines
6.8 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-09 15:46:46 +00:00
#include "LegendItemConverter.hxx"
#include "SchWhichPairs.hxx"
#include "macros.hxx"
#include "ItemPropertyMap.hxx"
#include "GraphicPropertyItemConverter.hxx"
#include "CharacterPropertyItemConverter.hxx"
#include <com/sun/star/chart2/XLegend.hpp>
#include <com/sun/star/chart2/LegendPosition.hpp>
#include <com/sun/star/chart/ChartLegendExpansion.hpp>
2003-10-09 15:46:46 +00:00
#include <svl/intitem.hxx>
#include <svl/eitem.hxx>
2003-10-09 15:46:46 +00:00
#include <functional>
#include <algorithm>
#include <boost/checked_delete.hpp>
2003-10-09 15:46:46 +00:00
using namespace ::com::sun::star;
namespace chart
{
namespace wrapper
{
LegendItemConverter::LegendItemConverter(
const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertySet > & rPropertySet,
SfxItemPool& rItemPool,
SdrModel& rDrawModel,
const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
const awt::Size* pRefSize ) :
2003-10-09 15:46:46 +00:00
ItemConverter( rPropertySet, rItemPool )
{
m_aConverters.push_back( new GraphicPropertyItemConverter(
rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory,
2003-10-09 15:46:46 +00:00
GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
m_aConverters.push_back( new CharacterPropertyItemConverter(
rPropertySet, rItemPool, pRefSize,
"ReferencePageSize" ));
2003-10-09 15:46:46 +00:00
}
LegendItemConverter::~LegendItemConverter()
{
::std::for_each( m_aConverters.begin(), m_aConverters.end(), boost::checked_deleter<ItemConverter>());
2003-10-09 15:46:46 +00:00
}
void LegendItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
{
::std::for_each( m_aConverters.begin(), m_aConverters.end(),
FillItemSetFunc( rOutItemSet ));
2003-10-09 15:46:46 +00:00
// own items
ItemConverter::FillItemSet( rOutItemSet );
}
bool LegendItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
{
bool bResult = false;
::std::for_each( m_aConverters.begin(), m_aConverters.end(),
ApplyItemSetFunc( rItemSet, bResult ));
2003-10-09 15:46:46 +00:00
// own items
return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
}
const sal_uInt16 * LegendItemConverter::GetWhichPairs() const
2003-10-09 15:46:46 +00:00
{
// must span all used items!
return nLegendWhichPairs;
}
bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyNameWithMemberId & /*rOutProperty*/ ) const
2003-10-09 15:46:46 +00:00
{
// No own (non-special) properties
return false;
}
2011-02-15 13:28:01 +01:00
bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet& rInItemSet )
throw( uno::Exception )
2003-10-09 15:46:46 +00:00
{
bool bChanged = false;
switch( nWhichId )
{
case SCHATTR_LEGEND_SHOW:
2003-10-09 15:46:46 +00:00
{
const SfxPoolItem* pPoolItem = NULL;
if( rInItemSet.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SfxItemState::SET )
2003-10-14 13:45:06 +00:00
{
bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
bool bWasShown = true;
if( ! (GetPropertySet()->getPropertyValue( "Show" ) >>= bWasShown) ||
( bWasShown != bShow ))
{
GetPropertySet()->setPropertyValue( "Show" , uno::makeAny( bShow ));
bChanged = true;
}
}
}
break;
case SCHATTR_LEGEND_POS:
{
const SfxPoolItem* pPoolItem = NULL;
if( rInItemSet.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SfxItemState::SET )
{
chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
switch( eNewPos )
{
case chart2::LegendPosition_LINE_START:
case chart2::LegendPosition_LINE_END:
eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH;
break;
case chart2::LegendPosition_PAGE_START:
case chart2::LegendPosition_PAGE_END:
eExpansion = ::com::sun::star::chart::ChartLegendExpansion_WIDE;
break;
default:
break;
}
try
{
chart2::LegendPosition eOldPos;
if( ! ( GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eOldPos ) ||
( eOldPos != eNewPos ))
{
GetPropertySet()->setPropertyValue( "AnchorPosition" , uno::makeAny( eNewPos ));
GetPropertySet()->setPropertyValue( "Expansion" , uno::makeAny( eExpansion ));
GetPropertySet()->setPropertyValue( "RelativePosition" , uno::Any());
bChanged = true;
}
}
2011-11-29 02:06:57 +09:00
catch( const uno::Exception & ex )
{
ASSERT_EXCEPTION( ex );
}
}
2003-10-09 15:46:46 +00:00
}
break;
}
return bChanged;
}
void LegendItemConverter::FillSpecialItem(
sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
throw( uno::Exception )
2003-10-09 15:46:46 +00:00
{
switch( nWhichId )
{
case SCHATTR_LEGEND_SHOW:
2003-10-09 15:46:46 +00:00
{
bool bShow = true;
GetPropertySet()->getPropertyValue( "Show" ) >>= bShow;
rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) );
}
break;
case SCHATTR_LEGEND_POS:
{
chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END );
GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eLegendPos;
rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, eLegendPos ) );
2003-10-09 15:46:46 +00:00
}
break;
}
}
} // namespace wrapper
} // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */