/* -*- 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 . */ #include "res_LegendPosition.hxx" #include "ChartModelHelper.hxx" #include "macros.hxx" #include "LegendHelper.hxx" #include "ChartModel.hxx" #include #include #include //itemset stuff #include "chartview/ChartSfxItemIds.hxx" #include #include namespace chart { using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; LegendPositionResources::LegendPositionResources(VclBuilderContainer& rParent) : m_xCC() //unused in this scenario , m_pCbxShow( NULL ) //unused in this scenario, assumed to be visible { rParent.get(m_pRbtLeft, "left"); rParent.get(m_pRbtRight, "right"); rParent.get(m_pRbtTop, "top"); rParent.get(m_pRbtBottom, "bottom"); impl_setRadioButtonToggleHdl(); } LegendPositionResources::LegendPositionResources(VclBuilderContainer& rParent, const uno::Reference< uno::XComponentContext >& xCC) : m_xCC(xCC) { rParent.get(m_pCbxShow, "show"); rParent.get(m_pRbtLeft, "left"); rParent.get(m_pRbtRight, "right"); rParent.get(m_pRbtTop, "top"); rParent.get(m_pRbtBottom, "bottom"); m_pCbxShow->SetToggleHdl( LINK( this, LegendPositionResources, PositionEnableHdl ) ); impl_setRadioButtonToggleHdl(); } void LegendPositionResources::impl_setRadioButtonToggleHdl() { m_pRbtLeft->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); m_pRbtTop->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); m_pRbtRight->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); m_pRbtBottom->SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); } LegendPositionResources::~LegendPositionResources() { } void LegendPositionResources::writeToResources( const uno::Reference< frame::XModel >& xChartModel ) { try { uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartModel ); uno::Reference< beans::XPropertySet > xProp( xDiagram->getLegend(), uno::UNO_QUERY ); if( xProp.is() ) { //show bool bShowLegend = false; xProp->getPropertyValue( "Show" ) >>= bShowLegend; if (m_pCbxShow) m_pCbxShow->Check( bShowLegend ); PositionEnableHdl(0); //position chart2::LegendPosition ePos; xProp->getPropertyValue( "AnchorPosition" ) >>= ePos; switch( ePos ) { case chart2::LegendPosition_LINE_START: m_pRbtLeft->Check(); break; case chart2::LegendPosition_LINE_END: m_pRbtRight->Check(); break; case chart2::LegendPosition_PAGE_START: m_pRbtTop->Check(); break; case chart2::LegendPosition_PAGE_END: m_pRbtBottom->Check(); break; case chart2::LegendPosition_CUSTOM: default: m_pRbtRight->Check(); break; } } } catch( const uno::Exception & ex ) { ASSERT_EXCEPTION( ex ); } } void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference< frame::XModel >& xChartModel ) const { try { bool bShowLegend = m_pCbxShow && m_pCbxShow->IsChecked(); ChartModel* pModel = dynamic_cast(xChartModel.get()); uno::Reference< beans::XPropertySet > xProp( LegendHelper::getLegend( *pModel,m_xCC,bShowLegend ), uno::UNO_QUERY ); if( xProp.is() ) { //show xProp->setPropertyValue( "Show" , uno::makeAny( bShowLegend )); //position chart2::LegendPosition eNewPos; ::com::sun::star::chart::ChartLegendExpansion eExp = ::com::sun::star::chart::ChartLegendExpansion_HIGH; if( m_pRbtLeft->IsChecked() ) eNewPos = chart2::LegendPosition_LINE_START; else if( m_pRbtRight->IsChecked() ) { eNewPos = chart2::LegendPosition_LINE_END; } else if( m_pRbtTop->IsChecked() ) { eNewPos = chart2::LegendPosition_PAGE_START; eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE; } else if( m_pRbtBottom->IsChecked() ) { eNewPos = chart2::LegendPosition_PAGE_END; eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE; } xProp->setPropertyValue( "AnchorPosition" , uno::makeAny( eNewPos )); xProp->setPropertyValue( "Expansion" , uno::makeAny( eExp )); xProp->setPropertyValue( "RelativePosition" , uno::Any()); } } catch( const uno::Exception & ex ) { ASSERT_EXCEPTION( ex ); } } IMPL_LINK_NOARG(LegendPositionResources, PositionEnableHdl) { bool bEnable = m_pCbxShow ? m_pCbxShow->IsChecked() : true; m_pRbtLeft->Enable( bEnable ); m_pRbtTop->Enable( bEnable ); m_pRbtRight->Enable( bEnable ); m_pRbtBottom->Enable( bEnable ); m_aChangeLink.Call(NULL); return 0; } void LegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs ) { const SfxPoolItem* pPoolItem = NULL; if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, true, &pPoolItem ) == SFX_ITEM_SET ) { sal_Int32 nLegendPosition = ((const SfxInt32Item*)pPoolItem)->GetValue(); switch( nLegendPosition ) { case chart2::LegendPosition_LINE_START: m_pRbtLeft->Check(true); break; case chart2::LegendPosition_PAGE_START: m_pRbtTop->Check(true); break; case chart2::LegendPosition_LINE_END: m_pRbtRight->Check(true); break; case chart2::LegendPosition_PAGE_END: m_pRbtBottom->Check(true); break; default: break; } } if( m_pCbxShow && rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, true, &pPoolItem ) == SFX_ITEM_SET ) { bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); m_pCbxShow->Check(bShow); } } void LegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const { sal_Int32 nLegendPosition = chart2::LegendPosition_CUSTOM; if( m_pRbtLeft->IsChecked() ) nLegendPosition = chart2::LegendPosition_LINE_START; else if( m_pRbtTop->IsChecked() ) nLegendPosition = chart2::LegendPosition_PAGE_START; else if( m_pRbtRight->IsChecked() ) nLegendPosition = chart2::LegendPosition_LINE_END; else if( m_pRbtBottom->IsChecked() ) nLegendPosition = chart2::LegendPosition_PAGE_END; rOutAttrs.Put(SfxInt32Item(SCHATTR_LEGEND_POS, nLegendPosition )); rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, m_pCbxShow ? m_pCbxShow->IsChecked() : true) ); } IMPL_LINK( LegendPositionResources, PositionChangeHdl, RadioButton*, pRadio ) { //for each radio click ther are coming two change events //first uncheck of previous button -> ignore that call //the second call gives the check of the new button if( pRadio && pRadio->IsChecked() ) m_aChangeLink.Call(NULL); return 0; } void LegendPositionResources::SetChangeHdl( const Link& rLink ) { m_aChangeLink = rLink; } } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */