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