1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "res_LegendPosition.hxx" 32*cdf0e10cSrcweir #include "ResourceIds.hrc" 33*cdf0e10cSrcweir #include "Strings.hrc" 34*cdf0e10cSrcweir #include "res_LegendPosition_IDs.hrc" 35*cdf0e10cSrcweir #include "ResId.hxx" 36*cdf0e10cSrcweir #include "ChartModelHelper.hxx" 37*cdf0e10cSrcweir #include "macros.hxx" 38*cdf0e10cSrcweir #include "LegendHelper.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #ifndef _SVT_CONTROLDIMS_HRC_ 41*cdf0e10cSrcweir #include <svtools/controldims.hrc> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <com/sun/star/chart2/LegendPosition.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/chart/ChartLegendExpansion.hpp> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //itemset stuff 47*cdf0e10cSrcweir #include "chartview/ChartSfxItemIds.hxx" 48*cdf0e10cSrcweir #include <svl/intitem.hxx> 49*cdf0e10cSrcweir #include <svl/eitem.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //............................................................................. 52*cdf0e10cSrcweir namespace chart 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir //............................................................................. 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir using namespace ::com::sun::star; 57*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir LegendPositionResources::LegendPositionResources( Window* pWindow ) 60*cdf0e10cSrcweir : m_xCC() //unused in this scenario 61*cdf0e10cSrcweir , m_aCbxShow( pWindow ) //unused in this scenario 62*cdf0e10cSrcweir , m_aRbtLeft( pWindow, SchResId(RBT_LEFT) ) 63*cdf0e10cSrcweir , m_aRbtRight( pWindow, SchResId(RBT_RIGHT) ) 64*cdf0e10cSrcweir , m_aRbtTop( pWindow, SchResId(RBT_TOP) ) 65*cdf0e10cSrcweir , m_aRbtBottom( pWindow, SchResId(RBT_BOTTOM) ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir m_aCbxShow.Check();//legend is assumed to be visible in this scenario 68*cdf0e10cSrcweir impl_setRadioButtonToggleHdl(); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir LegendPositionResources::LegendPositionResources( Window* pWindow, const uno::Reference< uno::XComponentContext >& xCC ) 72*cdf0e10cSrcweir : m_xCC( xCC ) 73*cdf0e10cSrcweir , m_aCbxShow( pWindow, SchResId(CBX_SHOWLEGEND) ) 74*cdf0e10cSrcweir , m_aRbtLeft( pWindow, SchResId(RBT_LEFT) ) 75*cdf0e10cSrcweir , m_aRbtRight( pWindow, SchResId(RBT_RIGHT) ) 76*cdf0e10cSrcweir , m_aRbtTop( pWindow, SchResId(RBT_TOP) ) 77*cdf0e10cSrcweir , m_aRbtBottom( pWindow, SchResId(RBT_BOTTOM) ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir m_aCbxShow.SetToggleHdl( LINK( this, LegendPositionResources, PositionEnableHdl ) ); 80*cdf0e10cSrcweir impl_setRadioButtonToggleHdl(); 81*cdf0e10cSrcweir m_aCbxShow.SetAccessibleRelationMemberOf(&m_aCbxShow); 82*cdf0e10cSrcweir m_aRbtLeft.SetAccessibleRelationMemberOf(&m_aCbxShow); 83*cdf0e10cSrcweir m_aRbtRight.SetAccessibleRelationMemberOf(&m_aCbxShow); 84*cdf0e10cSrcweir m_aRbtTop.SetAccessibleRelationMemberOf(&m_aCbxShow); 85*cdf0e10cSrcweir m_aRbtBottom.SetAccessibleRelationMemberOf(&m_aCbxShow); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void LegendPositionResources::impl_setRadioButtonToggleHdl() 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir m_aRbtLeft.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); 91*cdf0e10cSrcweir m_aRbtTop.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); 92*cdf0e10cSrcweir m_aRbtRight.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); 93*cdf0e10cSrcweir m_aRbtBottom.SetToggleHdl( LINK( this, LegendPositionResources, PositionChangeHdl ) ); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir LegendPositionResources::~LegendPositionResources() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void LegendPositionResources::writeToResources( const uno::Reference< frame::XModel >& xChartModel ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir try 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram( xChartModel ); 105*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xDiagram->getLegend(), uno::UNO_QUERY ); 106*cdf0e10cSrcweir if( xProp.is() ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir //show 109*cdf0e10cSrcweir sal_Bool bShowLegend = sal_False; 110*cdf0e10cSrcweir xProp->getPropertyValue( C2U("Show") ) >>= bShowLegend; 111*cdf0e10cSrcweir m_aCbxShow.Check( bShowLegend ); 112*cdf0e10cSrcweir PositionEnableHdl(0); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir //position 115*cdf0e10cSrcweir chart2::LegendPosition ePos; 116*cdf0e10cSrcweir xProp->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos; 117*cdf0e10cSrcweir switch( ePos ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir case chart2::LegendPosition_LINE_START: 120*cdf0e10cSrcweir m_aRbtLeft.Check(); 121*cdf0e10cSrcweir break; 122*cdf0e10cSrcweir case chart2::LegendPosition_LINE_END: 123*cdf0e10cSrcweir m_aRbtRight.Check(); 124*cdf0e10cSrcweir break; 125*cdf0e10cSrcweir case chart2::LegendPosition_PAGE_START: 126*cdf0e10cSrcweir m_aRbtTop.Check(); 127*cdf0e10cSrcweir break; 128*cdf0e10cSrcweir case chart2::LegendPosition_PAGE_END: 129*cdf0e10cSrcweir m_aRbtBottom.Check(); 130*cdf0e10cSrcweir break; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir case chart2::LegendPosition_CUSTOM: 133*cdf0e10cSrcweir default: 134*cdf0e10cSrcweir m_aRbtRight.Check(); 135*cdf0e10cSrcweir break; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir catch( uno::Exception & ex ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Reference< frame::XModel >& xChartModel ) const 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir try 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir sal_Bool bShowLegend = static_cast<sal_Bool>(m_aCbxShow.IsChecked()); 150*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( LegendHelper::getLegend( xChartModel,m_xCC,bShowLegend ), uno::UNO_QUERY ); 151*cdf0e10cSrcweir if( xProp.is() ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir //show 154*cdf0e10cSrcweir xProp->setPropertyValue( C2U("Show"), uno::makeAny( bShowLegend )); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //position 157*cdf0e10cSrcweir chart2::LegendPosition eNewPos; 158*cdf0e10cSrcweir ::com::sun::star::chart::ChartLegendExpansion eExp = ::com::sun::star::chart::ChartLegendExpansion_HIGH; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir if( m_aRbtLeft.IsChecked() ) 161*cdf0e10cSrcweir eNewPos = chart2::LegendPosition_LINE_START; 162*cdf0e10cSrcweir else if( m_aRbtRight.IsChecked() ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir eNewPos = chart2::LegendPosition_LINE_END; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir else if( m_aRbtTop.IsChecked() ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir eNewPos = chart2::LegendPosition_PAGE_START; 169*cdf0e10cSrcweir eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir else if( m_aRbtBottom.IsChecked() ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir eNewPos = chart2::LegendPosition_PAGE_END; 174*cdf0e10cSrcweir eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir xProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos )); 178*cdf0e10cSrcweir xProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp )); 179*cdf0e10cSrcweir xProp->setPropertyValue( C2U( "RelativePosition" ), uno::Any()); 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir catch( uno::Exception & ex ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir IMPL_LINK( LegendPositionResources, PositionEnableHdl, void*, EMPTYARG ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir sal_Bool bEnable = m_aCbxShow.IsChecked(); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir m_aRbtLeft.Enable( bEnable ); 193*cdf0e10cSrcweir m_aRbtTop.Enable( bEnable ); 194*cdf0e10cSrcweir m_aRbtRight.Enable( bEnable ); 195*cdf0e10cSrcweir m_aRbtBottom.Enable( bEnable ); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir m_aChangeLink.Call(NULL); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir return 0; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir void LegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir const SfxPoolItem* pPoolItem = NULL; 205*cdf0e10cSrcweir if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, sal_True, &pPoolItem ) == SFX_ITEM_SET ) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir sal_Int32 nLegendPosition = ((const SfxInt32Item*)pPoolItem)->GetValue(); 208*cdf0e10cSrcweir switch( nLegendPosition ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir case chart2::LegendPosition_LINE_START: 211*cdf0e10cSrcweir m_aRbtLeft.Check(sal_True); 212*cdf0e10cSrcweir break; 213*cdf0e10cSrcweir case chart2::LegendPosition_PAGE_START: 214*cdf0e10cSrcweir m_aRbtTop.Check(sal_True); 215*cdf0e10cSrcweir break; 216*cdf0e10cSrcweir case chart2::LegendPosition_LINE_END: 217*cdf0e10cSrcweir m_aRbtRight.Check(sal_True); 218*cdf0e10cSrcweir break; 219*cdf0e10cSrcweir case chart2::LegendPosition_PAGE_END: 220*cdf0e10cSrcweir m_aRbtBottom.Check(sal_True); 221*cdf0e10cSrcweir break; 222*cdf0e10cSrcweir default: 223*cdf0e10cSrcweir break; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir if( rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, sal_True, &pPoolItem ) == SFX_ITEM_SET ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); 230*cdf0e10cSrcweir m_aCbxShow.Check(bShow); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir void LegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir sal_Int32 nLegendPosition = chart2::LegendPosition_CUSTOM; 237*cdf0e10cSrcweir if( m_aRbtLeft.IsChecked() ) 238*cdf0e10cSrcweir nLegendPosition = chart2::LegendPosition_LINE_START; 239*cdf0e10cSrcweir else if( m_aRbtTop.IsChecked() ) 240*cdf0e10cSrcweir nLegendPosition = chart2::LegendPosition_PAGE_START; 241*cdf0e10cSrcweir else if( m_aRbtRight.IsChecked() ) 242*cdf0e10cSrcweir nLegendPosition = chart2::LegendPosition_LINE_END; 243*cdf0e10cSrcweir else if( m_aRbtBottom.IsChecked() ) 244*cdf0e10cSrcweir nLegendPosition = chart2::LegendPosition_PAGE_END; 245*cdf0e10cSrcweir rOutAttrs.Put(SfxInt32Item(SCHATTR_LEGEND_POS, nLegendPosition )); 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, m_aCbxShow.IsChecked()) ); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir IMPL_LINK( LegendPositionResources, PositionChangeHdl, RadioButton*, pRadio ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir //for each radio click ther are coming two change events 253*cdf0e10cSrcweir //first uncheck of previous button -> ignore that call 254*cdf0e10cSrcweir //the second call gives the check of the new button 255*cdf0e10cSrcweir if( pRadio && pRadio->IsChecked() ) 256*cdf0e10cSrcweir m_aChangeLink.Call(NULL); 257*cdf0e10cSrcweir return 0; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir void LegendPositionResources::SetChangeHdl( const Link& rLink ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir m_aChangeLink = rLink; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void LegendPositionResources::SetAccessibleRelationMemberOf(Window* pMemberOf) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir m_aRbtLeft.SetAccessibleRelationMemberOf(pMemberOf); 268*cdf0e10cSrcweir m_aRbtRight.SetAccessibleRelationMemberOf(pMemberOf); 269*cdf0e10cSrcweir m_aRbtTop.SetAccessibleRelationMemberOf(pMemberOf); 270*cdf0e10cSrcweir m_aRbtBottom.SetAccessibleRelationMemberOf(pMemberOf); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir //............................................................................. 274*cdf0e10cSrcweir } //namespace chart 275*cdf0e10cSrcweir //............................................................................. 276*cdf0e10cSrcweir 277