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 "dlg_InsertTrendline.hrc" 32*cdf0e10cSrcweir #include "res_Trendline.hxx" 33*cdf0e10cSrcweir #include "res_Trendline_IDs.hrc" 34*cdf0e10cSrcweir #include "ResId.hxx" 35*cdf0e10cSrcweir #include "Strings.hrc" 36*cdf0e10cSrcweir #include "Bitmaps.hrc" 37*cdf0e10cSrcweir #include "Bitmaps_HC.hrc" 38*cdf0e10cSrcweir #include "chartview/ChartSfxItemIds.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <vector> 41*cdf0e10cSrcweir #include <algorithm> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // macro for selecting a normal or high contrast bitmap the stack variable 44*cdf0e10cSrcweir // bIsHighContrast must exist and reflect the correct state 45*cdf0e10cSrcweir #define SELECT_IMAGE(name) Image( SchResId( bIsHighContrast ? name ## _HC : name )) 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir namespace 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir template< class T > 50*cdf0e10cSrcweir long lcl_getRightEdge( T & rControl ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir return rControl.CalcMinimumSize().Width() + rControl.GetPosPixel().X() - rControl.GetParent()->GetPosPixel().X(); 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir template< class T > 56*cdf0e10cSrcweir void lcl_AdjustControlSize( T & rControl ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir Size aSize( rControl.GetSizePixel()); 59*cdf0e10cSrcweir aSize.setWidth( rControl.CalcMinimumSize().Width()); 60*cdf0e10cSrcweir rControl.SetSizePixel( aSize ); 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir void lcl_AdjustControlSize( Control & rControl, long nRightEdge ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir Size aSize( rControl.GetSizePixel()); 66*cdf0e10cSrcweir Point aPosition( rControl.GetPosPixel()); 67*cdf0e10cSrcweir aSize.setWidth( nRightEdge - aPosition.getX()); 68*cdf0e10cSrcweir rControl.SetSizePixel( aSize ); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir } // anonymous namespace 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir namespace chart 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir enum StatTrendLine 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir TRENDLINE_NONE, 79*cdf0e10cSrcweir TRENDLINE_LINE, 80*cdf0e10cSrcweir TRENDLINE_LOG, 81*cdf0e10cSrcweir TRENDLINE_EXP, 82*cdf0e10cSrcweir TRENDLINE_POW 83*cdf0e10cSrcweir }; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir TrendlineResources::TrendlineResources( Window * pParent, const SfxItemSet& rInAttrs, bool bNoneAvailable ) : 86*cdf0e10cSrcweir m_aFLType( pParent, SchResId( FL_TYPE )), 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir m_aRBNone( pParent, SchResId( RB_NONE )), 89*cdf0e10cSrcweir m_aRBLinear( pParent, SchResId( RB_LINEAR )), 90*cdf0e10cSrcweir m_aRBLogarithmic( pParent, SchResId( RB_LOGARITHMIC )), 91*cdf0e10cSrcweir m_aRBExponential( pParent, SchResId( RB_EXPONENTIAL )), 92*cdf0e10cSrcweir m_aRBPower( pParent, SchResId( RB_POWER )), 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir m_aFINone( pParent, SchResId( FI_NONE )), 95*cdf0e10cSrcweir m_aFILinear( pParent, SchResId( FI_LINEAR )), 96*cdf0e10cSrcweir m_aFILogarithmic( pParent, SchResId( FI_LOGARITHMIC )), 97*cdf0e10cSrcweir m_aFIExponential( pParent, SchResId( FI_EXPONENTIAL )), 98*cdf0e10cSrcweir m_aFIPower( pParent, SchResId( FI_POWER )), 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir m_aFLEquation( pParent, SchResId( FL_EQUATION )), 101*cdf0e10cSrcweir m_aCBShowEquation( pParent, SchResId( CB_SHOW_EQUATION )), 102*cdf0e10cSrcweir m_aCBShowCorrelationCoeff( pParent, SchResId( CB_SHOW_CORRELATION_COEFF )), 103*cdf0e10cSrcweir m_eTrendLineType( CHREGRESS_NONE ), 104*cdf0e10cSrcweir m_bNoneAvailable( bNoneAvailable ), 105*cdf0e10cSrcweir m_bTrendLineUnique( true ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir FillValueSets(); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir if( m_bNoneAvailable ) 110*cdf0e10cSrcweir m_aRBNone.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine )); 111*cdf0e10cSrcweir else 112*cdf0e10cSrcweir m_aRBNone.Hide(); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir m_aRBLinear.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine )); 115*cdf0e10cSrcweir m_aRBLogarithmic.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine )); 116*cdf0e10cSrcweir m_aRBExponential.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine )); 117*cdf0e10cSrcweir m_aRBPower.SetClickHdl( LINK(this, TrendlineResources, SelectTrendLine )); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir Reset( rInAttrs ); 120*cdf0e10cSrcweir UpdateControlStates(); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir TrendlineResources::~TrendlineResources() 124*cdf0e10cSrcweir {} 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir long TrendlineResources::adjustControlSizes() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir // calculate right edge 129*cdf0e10cSrcweir ::std::vector< long > aControlRightEdges; 130*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aRBNone )); 131*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aRBLinear )); 132*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aRBLogarithmic )); 133*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aRBExponential )); 134*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aRBPower )); 135*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aCBShowEquation )); 136*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( m_aCBShowCorrelationCoeff )); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir lcl_AdjustControlSize( m_aRBNone ); 139*cdf0e10cSrcweir lcl_AdjustControlSize( m_aRBLinear ); 140*cdf0e10cSrcweir lcl_AdjustControlSize( m_aRBLogarithmic ); 141*cdf0e10cSrcweir lcl_AdjustControlSize( m_aRBExponential ); 142*cdf0e10cSrcweir lcl_AdjustControlSize( m_aRBPower ); 143*cdf0e10cSrcweir lcl_AdjustControlSize( m_aCBShowEquation ); 144*cdf0e10cSrcweir lcl_AdjustControlSize( m_aCBShowCorrelationCoeff ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Note: FixedLine has no CalcMinimumSize, workaround: use a FixedText 147*cdf0e10cSrcweir FixedText aDummyTextCtrl( m_aFLType.GetParent()); 148*cdf0e10cSrcweir aDummyTextCtrl.SetText( m_aFLType.GetText()); 149*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( aDummyTextCtrl )); 150*cdf0e10cSrcweir aDummyTextCtrl.SetText( m_aFLEquation.GetText()); 151*cdf0e10cSrcweir aControlRightEdges.push_back( lcl_getRightEdge( aDummyTextCtrl )); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir long nRightEdgeOfControls = *(::std::max_element( aControlRightEdges.begin(), aControlRightEdges.end())); 154*cdf0e10cSrcweir // leave some more space after the longest text 155*cdf0e10cSrcweir nRightEdgeOfControls += m_aFLType.LogicToPixel( Size( 6, 0 ), MapMode( MAP_APPFONT )).getWidth(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir lcl_AdjustControlSize( m_aFLType, nRightEdgeOfControls ); 158*cdf0e10cSrcweir lcl_AdjustControlSize( m_aFLEquation, nRightEdgeOfControls ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir return nRightEdgeOfControls; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir IMPL_LINK( TrendlineResources, SelectTrendLine, RadioButton *, pRadioButton ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir if( pRadioButton == &m_aRBLinear ) 166*cdf0e10cSrcweir m_eTrendLineType = CHREGRESS_LINEAR; 167*cdf0e10cSrcweir else if( pRadioButton == &m_aRBLogarithmic ) 168*cdf0e10cSrcweir m_eTrendLineType = CHREGRESS_LOG; 169*cdf0e10cSrcweir else if( pRadioButton == &m_aRBExponential ) 170*cdf0e10cSrcweir m_eTrendLineType = CHREGRESS_EXP; 171*cdf0e10cSrcweir else if( pRadioButton == &m_aRBPower ) 172*cdf0e10cSrcweir m_eTrendLineType = CHREGRESS_POWER; 173*cdf0e10cSrcweir else if( pRadioButton == &m_aRBNone ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir OSL_ASSERT( m_bNoneAvailable ); 176*cdf0e10cSrcweir m_eTrendLineType = CHREGRESS_NONE; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir m_bTrendLineUnique = true; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir UpdateControlStates(); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir return 0; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void TrendlineResources::Reset( const SfxItemSet& rInAttrs ) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir const SfxPoolItem *pPoolItem = NULL; 188*cdf0e10cSrcweir SfxItemState aState = SFX_ITEM_UNKNOWN; 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_TYPE, sal_True, &pPoolItem ); 191*cdf0e10cSrcweir m_bTrendLineUnique = ( aState != SFX_ITEM_DONTCARE ); 192*cdf0e10cSrcweir if( aState == SFX_ITEM_SET ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir const SvxChartRegressItem * pItem = dynamic_cast< const SvxChartRegressItem * >( pPoolItem ); 195*cdf0e10cSrcweir if( pItem ) 196*cdf0e10cSrcweir m_eTrendLineType = pItem->GetValue(); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SHOW_EQUATION, sal_True, &pPoolItem ); 200*cdf0e10cSrcweir if( aState == SFX_ITEM_DONTCARE ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir m_aCBShowEquation.EnableTriState( sal_True ); 203*cdf0e10cSrcweir m_aCBShowEquation.SetState( STATE_DONTKNOW ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir else 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir m_aCBShowEquation.EnableTriState( sal_False ); 208*cdf0e10cSrcweir if( aState == SFX_ITEM_SET ) 209*cdf0e10cSrcweir m_aCBShowEquation.Check( static_cast< const SfxBoolItem * >( pPoolItem )->GetValue()); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir aState = rInAttrs.GetItemState( SCHATTR_REGRESSION_SHOW_COEFF, sal_True, &pPoolItem ); 213*cdf0e10cSrcweir if( aState == SFX_ITEM_DONTCARE ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir m_aCBShowCorrelationCoeff.EnableTriState( sal_True ); 216*cdf0e10cSrcweir m_aCBShowCorrelationCoeff.SetState( STATE_DONTKNOW ); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir else 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir m_aCBShowCorrelationCoeff.EnableTriState( sal_False ); 221*cdf0e10cSrcweir if( aState == SFX_ITEM_SET ) 222*cdf0e10cSrcweir m_aCBShowCorrelationCoeff.Check( static_cast< const SfxBoolItem * >( pPoolItem )->GetValue()); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir if( m_bTrendLineUnique ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir switch( m_eTrendLineType ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir case CHREGRESS_LINEAR : 230*cdf0e10cSrcweir m_aRBLinear.Check(); 231*cdf0e10cSrcweir break; 232*cdf0e10cSrcweir case CHREGRESS_LOG : 233*cdf0e10cSrcweir m_aRBLogarithmic.Check(); 234*cdf0e10cSrcweir break; 235*cdf0e10cSrcweir case CHREGRESS_EXP : 236*cdf0e10cSrcweir m_aRBExponential.Check(); 237*cdf0e10cSrcweir break; 238*cdf0e10cSrcweir case CHREGRESS_POWER : 239*cdf0e10cSrcweir m_aRBPower.Check(); 240*cdf0e10cSrcweir break; 241*cdf0e10cSrcweir case CHREGRESS_NONE: 242*cdf0e10cSrcweir OSL_ASSERT( m_bNoneAvailable ); 243*cdf0e10cSrcweir m_aRBNone.Check(); 244*cdf0e10cSrcweir break; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir sal_Bool TrendlineResources::FillItemSet(SfxItemSet& rOutAttrs) const 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir if( m_bTrendLineUnique ) 252*cdf0e10cSrcweir rOutAttrs.Put( SvxChartRegressItem( m_eTrendLineType, SCHATTR_REGRESSION_TYPE )); 253*cdf0e10cSrcweir if( m_aCBShowEquation.GetState() != STATE_DONTKNOW ) 254*cdf0e10cSrcweir rOutAttrs.Put( SfxBoolItem( SCHATTR_REGRESSION_SHOW_EQUATION, m_aCBShowEquation.IsChecked() )); 255*cdf0e10cSrcweir if( m_aCBShowCorrelationCoeff.GetState() != STATE_DONTKNOW ) 256*cdf0e10cSrcweir rOutAttrs.Put( SfxBoolItem( SCHATTR_REGRESSION_SHOW_COEFF, m_aCBShowCorrelationCoeff.IsChecked() )); 257*cdf0e10cSrcweir return sal_True; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir void TrendlineResources::FillValueSets() 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir bool bIsHighContrast = ( true && m_aFLType.GetSettings().GetStyleSettings().GetHighContrastMode() ); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir if( m_bNoneAvailable ) 265*cdf0e10cSrcweir m_aFINone.SetImage( SELECT_IMAGE( BMP_REGRESSION_NONE )); 266*cdf0e10cSrcweir m_aFILinear.SetImage( SELECT_IMAGE( BMP_REGRESSION_LINEAR )); 267*cdf0e10cSrcweir m_aFILogarithmic.SetImage( SELECT_IMAGE( BMP_REGRESSION_LOG )); 268*cdf0e10cSrcweir m_aFIExponential.SetImage( SELECT_IMAGE( BMP_REGRESSION_EXP )); 269*cdf0e10cSrcweir m_aFIPower.SetImage( SELECT_IMAGE( BMP_REGRESSION_POWER )); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir void TrendlineResources::UpdateControlStates() 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir if( m_bNoneAvailable ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir bool bEnableEquationControls = !m_bTrendLineUnique || (m_eTrendLineType != CHREGRESS_NONE); 277*cdf0e10cSrcweir m_aCBShowEquation.Enable( bEnableEquationControls ); 278*cdf0e10cSrcweir m_aCBShowCorrelationCoeff.Enable( bEnableEquationControls ); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir } // namespace chart 283