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