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