LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/dialogs - res_ErrorBar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 355 0.0 %
Date: 2012-12-17 Functions: 0 27 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "res_ErrorBar.hxx"
      22             : #include "res_ErrorBar_IDs.hrc"
      23             : #include "ResId.hxx"
      24             : #include "Strings.hrc"
      25             : #include "Bitmaps.hrc"
      26             : #include "RangeSelectionHelper.hxx"
      27             : // for RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR
      28             : #include "TabPageNotifiable.hxx"
      29             : #include "macros.hxx"
      30             : 
      31             : #include <rtl/math.hxx>
      32             : #include <vcl/dialog.hxx>
      33             : #include <svl/stritem.hxx>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : 
      37             : namespace
      38             : {
      39           0 : void lcl_enableRangeChoosing( bool bEnable, Dialog * pDialog )
      40             : {
      41           0 :     if( pDialog )
      42             :     {
      43           0 :         pDialog->Show( bEnable ? sal_False : sal_True );
      44           0 :         pDialog->SetModalInputMode( bEnable ? sal_False : sal_True );
      45             :     }
      46           0 : }
      47             : 
      48           0 : sal_uInt16 lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind )
      49             : {
      50           0 :     sal_uInt16 nResult = 0;
      51           0 :     switch( eErrorKind )
      52             :     {
      53             :         // for these cases select the default in the list box
      54             :         case CHERROR_NONE:
      55             :         case CHERROR_PERCENT:
      56             :         case CHERROR_CONST:
      57             :         case CHERROR_RANGE:
      58           0 :             nResult = CHART_LB_FUNCTION_STD_DEV;
      59           0 :             break;
      60             :         case CHERROR_VARIANT:
      61           0 :             nResult = CHART_LB_FUNCTION_VARIANCE;
      62           0 :             break;
      63             :         case CHERROR_SIGMA:
      64           0 :             nResult = CHART_LB_FUNCTION_STD_DEV;
      65           0 :             break;
      66             :         case CHERROR_BIGERROR:
      67           0 :             nResult = CHART_LB_FUNCTION_ERROR_MARGIN;
      68           0 :             break;
      69             :         case CHERROR_STDERROR:
      70           0 :             nResult = CHART_LB_FUNCTION_STD_ERROR;
      71           0 :             break;
      72             :     }
      73           0 :     return nResult;
      74             : }
      75             : } // anonymous namespace
      76             : 
      77             : 
      78             : //.............................................................................
      79             : namespace chart
      80             : {
      81             : //.............................................................................
      82             : 
      83             : enum StatIndicator
      84             : {
      85             :     INDICATE_BOTH,
      86             :     INDICATE_UP,
      87             :     INDICATE_DOWN
      88             : };
      89             : 
      90           0 : ErrorBarResources::ErrorBarResources( Window* pParent, Dialog * pParentDialog,
      91             :                                       const SfxItemSet& rInAttrs, bool bNoneAvailable,
      92             :                                       tErrorBarType eType /* = ERROR_BAR_Y */ ) :
      93             : 
      94             :         m_aFlErrorCategory( pParent, SchResId( FL_ERROR )),
      95             :         m_aRbNone( pParent, SchResId( RB_NONE )),
      96             :         m_aRbConst( pParent, SchResId( RB_CONST )),
      97             :         m_aRbPercent( pParent, SchResId( RB_PERCENT )),
      98             :         m_aRbFunction( pParent, SchResId( RB_FUNCTION )),
      99             :         m_aRbRange( pParent, SchResId( RB_RANGE )),
     100             :         m_aLbFunction( pParent, SchResId( LB_FUNCTION )),
     101             : 
     102             :         m_aFlParameters( pParent, SchResId( FL_PARAMETERS )),
     103             :         m_aFtPositive( pParent, SchResId( FT_POSITIVE )),
     104             :         m_aMfPositive( pParent, SchResId( MF_POSITIVE )),
     105             :         m_aEdRangePositive( pParent, SchResId( ED_RANGE_POSITIVE )),
     106             :         m_aIbRangePositive( pParent, SchResId( IB_RANGE_POSITIVE )),
     107             :         m_aFtNegative( pParent, SchResId( FT_NEGATIVE )),
     108             :         m_aMfNegative( pParent, SchResId( MF_NEGATIVE )),
     109             :         m_aEdRangeNegative( pParent, SchResId( ED_RANGE_NEGATIVE )),
     110             :         m_aIbRangeNegative( pParent, SchResId( IB_RANGE_NEGATIVE )),
     111             :         m_aCbSyncPosNeg( pParent, SchResId( CB_SYN_POS_NEG )),
     112             : 
     113             :         m_aFlIndicate( pParent, SchResId( FL_INDICATE )),
     114             :         m_aRbBoth( pParent, SchResId( RB_BOTH )),
     115             :         m_aRbPositive( pParent, SchResId( RB_POSITIVE )),
     116             :         m_aRbNegative( pParent, SchResId( RB_NEGATIVE )),
     117             :         m_aFiBoth( pParent, SchResId( FI_BOTH )),
     118             :         m_aFiPositive( pParent, SchResId( FI_POSITIVE )),
     119             :         m_aFiNegative( pParent, SchResId( FI_NEGATIVE )),
     120             : 
     121             :         m_eErrorKind( CHERROR_NONE ),
     122             :         m_eIndicate( CHINDICATE_BOTH ),
     123             :         m_bErrorKindUnique( true ),
     124             :         m_bIndicatorUnique( true ),
     125             :         m_bPlusUnique( true ),
     126             :         m_bMinusUnique( true ),
     127             :         m_bRangePosUnique( true ),
     128             :         m_bRangeNegUnique( true ),
     129             :         m_bNoneAvailable( bNoneAvailable ),
     130             :         m_eErrorBarType( eType ),
     131             :         m_nConstDecimalDigits( 1 ),
     132             :         m_nConstSpinSize( 1 ),
     133             :         m_pParentWindow( pParent ),
     134             :         m_pParentDialog( pParentDialog ),
     135             :         m_pCurrentRangeChoosingField( 0 ),
     136             :         m_bHasInternalDataProvider( true ),
     137           0 :         m_bDisableDataTableDialog( false )
     138             : {
     139           0 :     if( m_bNoneAvailable )
     140           0 :         m_aRbNone.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
     141             :     else
     142           0 :         m_aRbNone.Hide();
     143             : 
     144           0 :     m_aRbConst.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
     145           0 :     m_aRbPercent.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
     146           0 :     m_aRbFunction.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
     147           0 :     m_aRbRange.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
     148           0 :     m_aLbFunction.SetSelectHdl( LINK( this, ErrorBarResources, CategoryChosen ));
     149             : 
     150           0 :     m_aCbSyncPosNeg.Check( sal_False );
     151           0 :     m_aCbSyncPosNeg.SetToggleHdl( LINK( this, ErrorBarResources, SynchronizePosAndNeg ));
     152             : 
     153           0 :     m_aMfPositive.SetModifyHdl( LINK( this, ErrorBarResources, PosValueChanged ));
     154           0 :     m_aEdRangePositive.SetModifyHdl( LINK( this, ErrorBarResources, RangeChanged ));
     155           0 :     m_aEdRangeNegative.SetModifyHdl( LINK( this, ErrorBarResources, RangeChanged ));
     156             : 
     157           0 :     m_aRbPositive.SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
     158           0 :     m_aRbNegative.SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
     159           0 :     m_aRbBoth.SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
     160             : 
     161           0 :     m_aIbRangePositive.SetClickHdl( LINK( this, ErrorBarResources, ChooseRange ));
     162           0 :     m_aIbRangeNegative.SetClickHdl( LINK( this, ErrorBarResources, ChooseRange ));
     163           0 :     m_aIbRangePositive.SetQuickHelpText( String( SchResId( STR_TIP_SELECT_RANGE )));
     164           0 :     m_aIbRangeNegative.SetQuickHelpText( String( SchResId( STR_TIP_SELECT_RANGE )));
     165             : 
     166           0 :     FillValueSets();
     167           0 :     Reset( rInAttrs );
     168           0 : }
     169             : 
     170           0 : ErrorBarResources::~ErrorBarResources()
     171             : {
     172           0 : }
     173             : 
     174           0 : void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType )
     175             : {
     176           0 :     if( m_eErrorBarType != eNewType )
     177             :     {
     178           0 :         m_eErrorBarType = eNewType;
     179           0 :         FillValueSets();
     180             :     }
     181           0 : }
     182             : 
     183           0 : void ErrorBarResources::SetChartDocumentForRangeChoosing(
     184             :     const uno::Reference< chart2::XChartDocument > & xChartDocument )
     185             : {
     186           0 :     if( xChartDocument.is())
     187             :     {
     188           0 :         m_bHasInternalDataProvider = xChartDocument->hasInternalDataProvider();
     189           0 :         uno::Reference< beans::XPropertySet > xProps( xChartDocument, uno::UNO_QUERY );
     190           0 :         if ( xProps.is() )
     191             :         {
     192             :             try
     193             :             {
     194           0 :                 xProps->getPropertyValue( "DisableDataTableDialog" ) >>= m_bDisableDataTableDialog;
     195             :             }
     196           0 :             catch( const uno::Exception& e )
     197             :             {
     198             :                 ASSERT_EXCEPTION( e );
     199             :             }
     200           0 :         }
     201             :     }
     202           0 :     m_apRangeSelectionHelper.reset( new RangeSelectionHelper( xChartDocument ));
     203             : 
     204             :     // has internal data provider => rename "cell range" to "from data"
     205             :     OSL_ASSERT( m_apRangeSelectionHelper.get());
     206           0 :     if( m_bHasInternalDataProvider )
     207             :     {
     208           0 :         m_aRbRange.SetText( String( SchResId( STR_CONTROLTEXT_ERROR_BARS_FROM_DATA )));
     209             :     }
     210             : 
     211           0 :     if( m_aRbRange.IsChecked())
     212             :     {
     213           0 :         isRangeFieldContentValid( m_aEdRangePositive );
     214           0 :         isRangeFieldContentValid( m_aEdRangeNegative );
     215             :     }
     216           0 : }
     217             : 
     218           0 : void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
     219             : {
     220           0 :     if( fMinorStepWidth < 0 )
     221           0 :         fMinorStepWidth = -fMinorStepWidth;
     222             : 
     223           0 :     sal_Int32 nExponent = static_cast< sal_Int32 >( ::rtl::math::approxFloor( log10( fMinorStepWidth )));
     224           0 :     if( nExponent <= 0 )
     225             :     {
     226             :         // one digit precision more
     227           0 :         m_nConstDecimalDigits = static_cast< sal_uInt16 >( (-nExponent) + 1 );
     228           0 :         m_nConstSpinSize = 10;
     229             :     }
     230             :     else
     231             :     {
     232           0 :         m_nConstDecimalDigits = 0;
     233           0 :         m_nConstSpinSize = static_cast< sal_Int64 >( pow( 10.0, (int)nExponent ));
     234             :     }
     235           0 : }
     236             : 
     237           0 : void ErrorBarResources::UpdateControlStates()
     238             : {
     239             :     // function
     240           0 :     bool bIsFunction = m_aRbFunction.IsChecked();
     241           0 :     m_aLbFunction.Enable( bIsFunction );
     242             : 
     243             :     // range buttons
     244           0 :     m_aRbRange.Enable( !m_bHasInternalDataProvider || !m_bDisableDataTableDialog );
     245           0 :     bool bShowRange = ( m_aRbRange.IsChecked());
     246             :     bool bCanChooseRange =
     247             :         ( bShowRange &&
     248           0 :           m_apRangeSelectionHelper.get() &&
     249           0 :           m_apRangeSelectionHelper->hasRangeSelection());
     250             : 
     251           0 :     m_aMfPositive.Show( ! bShowRange );
     252           0 :     m_aMfNegative.Show( ! bShowRange );
     253             : 
     254             :     // use range but without range chooser => hide controls
     255           0 :     m_aEdRangePositive.Show( bShowRange && ! m_bHasInternalDataProvider );
     256           0 :     m_aIbRangePositive.Show( bCanChooseRange );
     257           0 :     m_aEdRangeNegative.Show( bShowRange && ! m_bHasInternalDataProvider );
     258           0 :     m_aIbRangeNegative.Show( bCanChooseRange );
     259             : 
     260           0 :     bool bShowPosNegAndSync = ! (bShowRange && m_bHasInternalDataProvider);
     261           0 :     m_aFtPositive.Show( bShowPosNegAndSync );
     262           0 :     m_aFtNegative.Show( bShowPosNegAndSync );
     263           0 :     m_aCbSyncPosNeg.Show( bShowPosNegAndSync );
     264           0 :     m_aFlParameters.Show( bShowPosNegAndSync );
     265             : 
     266             :     // unit for metric fields
     267             :     bool bIsErrorMargin(
     268           0 :         ( m_aRbFunction.IsChecked()) &&
     269           0 :         ( m_aLbFunction.GetSelectEntryPos() == CHART_LB_FUNCTION_ERROR_MARGIN ));
     270           0 :     bool bIsPercentage( m_aRbPercent.IsChecked() || bIsErrorMargin );
     271           0 :     String aCustomUnit;
     272             : 
     273           0 :     if( bIsPercentage )
     274             :     {
     275           0 :         aCustomUnit = String( RTL_CONSTASCII_USTRINGPARAM( " %" ));
     276           0 :         m_aMfPositive.SetDecimalDigits( 1 );
     277           0 :         m_aMfPositive.SetSpinSize( 10 );
     278           0 :         m_aMfNegative.SetDecimalDigits( 1 );
     279           0 :         m_aMfNegative.SetSpinSize( 10 );
     280             :     }
     281             :     else
     282             :     {
     283           0 :         m_aMfPositive.SetDecimalDigits( m_nConstDecimalDigits );
     284           0 :         m_aMfPositive.SetSpinSize( m_nConstSpinSize );
     285           0 :         m_aMfNegative.SetDecimalDigits( m_nConstDecimalDigits );
     286           0 :         m_aMfNegative.SetSpinSize( m_nConstSpinSize );
     287             :     }
     288           0 :     m_aMfPositive.SetCustomUnitText( aCustomUnit );
     289           0 :     m_aMfNegative.SetCustomUnitText( aCustomUnit );
     290             : 
     291             :     // positive and negative value fields
     292           0 :     bool bPosEnabled = ( m_aRbPositive.IsChecked() || m_aRbBoth.IsChecked());
     293           0 :     bool bNegEnabled = ( m_aRbNegative.IsChecked() || m_aRbBoth.IsChecked());
     294           0 :     if( !( bPosEnabled || bNegEnabled ))
     295             :     {
     296             :         // all three controls are not checked -> ambiguous state
     297           0 :         bPosEnabled = true;
     298           0 :         bNegEnabled = true;
     299             :     }
     300             : 
     301             :     // functions with only one parameter
     302             :     bool bOneParameterCategory =
     303           0 :         bIsErrorMargin || m_aRbPercent.IsChecked();
     304           0 :     if( bOneParameterCategory )
     305             :     {
     306           0 :         m_aCbSyncPosNeg.Check();
     307             :     }
     308             : 
     309           0 :     if( m_aCbSyncPosNeg.IsChecked())
     310             :     {
     311           0 :         bPosEnabled = true;
     312           0 :         bNegEnabled = false;
     313             :     }
     314             : 
     315             :     // all functions except error margin take no arguments
     316           0 :     if( m_aRbFunction.IsChecked() &&
     317           0 :         ( m_aLbFunction.GetSelectEntryPos() != CHART_LB_FUNCTION_ERROR_MARGIN ))
     318             :     {
     319           0 :         bPosEnabled = false;
     320           0 :         bNegEnabled = false;
     321             :     }
     322             : 
     323             :     // enable/disable pos/neg fields
     324           0 :     m_aFtPositive.Enable( bPosEnabled );
     325           0 :     m_aFtNegative.Enable( bNegEnabled );
     326           0 :     if( bShowRange )
     327             :     {
     328           0 :         m_aEdRangePositive.Enable( bPosEnabled );
     329           0 :         m_aIbRangePositive.Enable( bPosEnabled );
     330           0 :         m_aEdRangeNegative.Enable( bNegEnabled );
     331           0 :         m_aIbRangeNegative.Enable( bNegEnabled );
     332             :     }
     333             :     else
     334             :     {
     335           0 :         m_aMfPositive.Enable( bPosEnabled );
     336           0 :         m_aMfNegative.Enable( bNegEnabled );
     337             :     }
     338             : 
     339             :     m_aCbSyncPosNeg.Enable(
     340           0 :         !bOneParameterCategory &&
     341           0 :         ( bPosEnabled || bNegEnabled ));
     342             : 
     343             :     // mark invalid entries in the range fields
     344           0 :     if( bShowRange && ! m_bHasInternalDataProvider )
     345             :     {
     346           0 :         isRangeFieldContentValid( m_aEdRangePositive );
     347           0 :         isRangeFieldContentValid( m_aEdRangeNegative );
     348           0 :     }
     349           0 : }
     350             : 
     351           0 : IMPL_LINK( ErrorBarResources, CategoryChosen, void *,  )
     352             : {
     353           0 :     m_bErrorKindUnique = true;
     354           0 :     SvxChartKindError eOldError = m_eErrorKind;
     355             : 
     356           0 :     if( m_aRbNone.IsChecked())
     357           0 :         m_eErrorKind = CHERROR_NONE;
     358           0 :     else if( m_aRbConst.IsChecked())
     359           0 :         m_eErrorKind = CHERROR_CONST;
     360           0 :     else if( m_aRbPercent.IsChecked())
     361           0 :         m_eErrorKind = CHERROR_PERCENT;
     362           0 :     else if( m_aRbRange.IsChecked())
     363           0 :         m_eErrorKind = CHERROR_RANGE;
     364           0 :     else if( m_aRbFunction.IsChecked())
     365             :     {
     366           0 :         if( m_aLbFunction.GetSelectEntryCount() == 1 )
     367             :         {
     368           0 :             switch( m_aLbFunction.GetSelectEntryPos())
     369             :             {
     370             :                 case CHART_LB_FUNCTION_STD_ERROR:
     371           0 :                     m_eErrorKind = CHERROR_STDERROR; break;
     372             :                 case CHART_LB_FUNCTION_STD_DEV:
     373           0 :                     m_eErrorKind = CHERROR_SIGMA; break;
     374             :                 case CHART_LB_FUNCTION_VARIANCE:
     375           0 :                     m_eErrorKind = CHERROR_VARIANT; break;
     376             :                 case CHART_LB_FUNCTION_ERROR_MARGIN:
     377           0 :                     m_eErrorKind = CHERROR_BIGERROR; break;
     378             :                 default:
     379           0 :                     m_bErrorKindUnique = false;
     380             :             }
     381             :         }
     382             :         else
     383           0 :             m_bErrorKindUnique = false;
     384             :     }
     385             :     else
     386             :     {
     387             :         OSL_FAIL( "Unknown category chosen" );
     388           0 :         m_bErrorKindUnique = false;
     389             :     }
     390             : 
     391             :     // changed to range
     392           0 :     if( m_eErrorKind == CHERROR_RANGE &&
     393             :         eOldError != CHERROR_RANGE )
     394             :     {
     395             :         m_aCbSyncPosNeg.Check(
     396           0 :             (m_aEdRangePositive.GetText().Len() > 0) &&
     397             :             m_aEdRangePositive.GetText().Equals(
     398           0 :                 m_aEdRangeNegative.GetText()));
     399             :     }
     400             :     // changed from range
     401           0 :     else if( m_eErrorKind != CHERROR_RANGE &&
     402             :         eOldError == CHERROR_RANGE )
     403             :     {
     404             :         m_aCbSyncPosNeg.Check(
     405           0 :             m_aMfPositive.GetValue() == m_aMfNegative.GetValue());
     406             :     }
     407             : 
     408           0 :     UpdateControlStates();
     409           0 :     return 0;
     410             : }
     411             : 
     412           0 : IMPL_LINK_NOARG(ErrorBarResources, SynchronizePosAndNeg)
     413             : {
     414           0 :     UpdateControlStates();
     415           0 :     PosValueChanged( 0 );
     416           0 :     return 0;
     417             : }
     418             : 
     419           0 : IMPL_LINK_NOARG(ErrorBarResources, PosValueChanged)
     420             : {
     421           0 :     if( m_aCbSyncPosNeg.IsChecked())
     422             :     {
     423           0 :         if( m_aRbRange.IsChecked())
     424             :         {
     425           0 :             m_aEdRangeNegative.SetText( m_aEdRangePositive.GetText());
     426           0 :             m_bRangeNegUnique = m_bRangePosUnique;
     427             :         }
     428             :         else
     429           0 :             m_aMfNegative.SetValue( m_aMfPositive.GetValue());
     430             :     }
     431             : 
     432           0 :     return 0;
     433             : }
     434             : 
     435           0 : IMPL_LINK_NOARG(ErrorBarResources, IndicatorChanged)
     436             : {
     437           0 :     m_bIndicatorUnique = true;
     438           0 :     if( m_aRbBoth.IsChecked())
     439           0 :         m_eIndicate = CHINDICATE_BOTH;
     440           0 :     else if( m_aRbPositive.IsChecked())
     441           0 :         m_eIndicate = CHINDICATE_UP;
     442           0 :     else if( m_aRbNegative.IsChecked())
     443           0 :         m_eIndicate = CHINDICATE_DOWN;
     444             :     else
     445           0 :         m_bIndicatorUnique = false;
     446             : 
     447           0 :     UpdateControlStates();
     448           0 :     return 0;
     449             : }
     450             : 
     451           0 : IMPL_LINK( ErrorBarResources, ChooseRange, RangeSelectionButton *, pButton )
     452             : {
     453             :     OSL_ASSERT( m_apRangeSelectionHelper.get());
     454           0 :     if( ! m_apRangeSelectionHelper.get())
     455           0 :         return 0;
     456             :     OSL_ASSERT( m_pCurrentRangeChoosingField == 0 );
     457             : 
     458           0 :     OUString aUIString;
     459           0 :     if( pButton == &m_aIbRangePositive )
     460             :     {
     461           0 :         m_pCurrentRangeChoosingField = &m_aEdRangePositive;
     462           0 :         aUIString = String( SchResId( STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS ));
     463             :     }
     464             :     else
     465             :     {
     466           0 :         m_pCurrentRangeChoosingField = &m_aEdRangeNegative;
     467           0 :         aUIString = String( SchResId( STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS ));
     468             :     }
     469             : 
     470             :     OSL_ASSERT( m_pParentDialog );
     471           0 :     if( m_pParentDialog )
     472             :     {
     473           0 :         lcl_enableRangeChoosing( true, m_pParentDialog );
     474             :         m_apRangeSelectionHelper->chooseRange(
     475           0 :             m_pCurrentRangeChoosingField->GetText(),
     476           0 :             aUIString, *this );
     477             :     }
     478             :     else
     479           0 :         m_pCurrentRangeChoosingField = 0;
     480             : 
     481           0 :     return 0;
     482             : }
     483             : 
     484           0 : IMPL_LINK( ErrorBarResources, RangeChanged, Edit *, pEdit )
     485             : {
     486           0 :     if( pEdit == & m_aEdRangePositive )
     487             :     {
     488           0 :         m_bRangePosUnique = true;
     489           0 :         PosValueChanged( 0 );
     490             :     }
     491             :     else
     492             :     {
     493           0 :         m_bRangeNegUnique = true;
     494             :     }
     495             : 
     496           0 :     isRangeFieldContentValid( *pEdit );
     497             : 
     498           0 :     return 0;
     499             : }
     500             : 
     501           0 : void ErrorBarResources::Reset(const SfxItemSet& rInAttrs)
     502             : {
     503           0 :     const SfxPoolItem *pPoolItem = NULL;
     504           0 :     SfxItemState aState = SFX_ITEM_UNKNOWN;
     505             : 
     506             :     // category
     507           0 :      m_eErrorKind = CHERROR_NONE;
     508           0 :     aState = rInAttrs.GetItemState( SCHATTR_STAT_KIND_ERROR, sal_True, &pPoolItem );
     509           0 :     m_bErrorKindUnique = ( aState != SFX_ITEM_DONTCARE );
     510             : 
     511           0 :     if( aState == SFX_ITEM_SET )
     512           0 :         m_eErrorKind = ((const SvxChartKindErrorItem*) pPoolItem)->GetValue();
     513             : 
     514           0 :     m_aLbFunction.SelectEntryPos( lcl_getLbEntryPosByErrorKind( m_eErrorKind ));
     515             : 
     516           0 :     if( m_bErrorKindUnique )
     517             :     {
     518           0 :         switch( m_eErrorKind )
     519             :         {
     520             :             case CHERROR_NONE:
     521           0 :                 m_aRbNone.Check();
     522           0 :                 break;
     523             :             case CHERROR_PERCENT:
     524           0 :                 m_aRbPercent.Check();
     525           0 :                 break;
     526             :             case CHERROR_CONST:
     527           0 :                 m_aRbConst.Check();
     528           0 :                 break;
     529             :             case CHERROR_STDERROR:
     530             :             case CHERROR_VARIANT:
     531             :             case CHERROR_SIGMA:
     532             :             case CHERROR_BIGERROR:
     533           0 :                 m_aRbFunction.Check();
     534           0 :                 break;
     535             :             case CHERROR_RANGE:
     536           0 :                 m_aRbRange.Check();
     537           0 :                 break;
     538             :         }
     539             :     }
     540             :     else
     541             :     {
     542           0 :         m_aRbNone.Check( sal_False );
     543           0 :         m_aRbConst.Check( sal_False );
     544           0 :         m_aRbPercent.Check( sal_False );
     545           0 :         m_aRbFunction.Check( sal_False );
     546             :     }
     547             : 
     548             :     // parameters
     549           0 :     aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTPLUS, sal_True, &pPoolItem );
     550           0 :     m_bPlusUnique = ( aState != SFX_ITEM_DONTCARE );
     551           0 :     double fPlusValue = 0.0;
     552           0 :     if( aState == SFX_ITEM_SET )
     553             :     {
     554           0 :         fPlusValue = ((const SvxDoubleItem*) pPoolItem)->GetValue();
     555           0 :         sal_Int32 nPlusValue = static_cast< sal_Int32 >( fPlusValue * pow(10.0,m_aMfPositive.GetDecimalDigits()) );
     556           0 :         m_aMfPositive.SetValue( nPlusValue );
     557             :     }
     558             : 
     559           0 :     aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTMINUS, sal_True, &pPoolItem );
     560           0 :     m_bMinusUnique = ( aState != SFX_ITEM_DONTCARE );
     561           0 :     if( aState == SFX_ITEM_SET )
     562             :     {
     563           0 :         double fMinusValue = ((const SvxDoubleItem*) pPoolItem)->GetValue();
     564           0 :         sal_Int32 nMinusValue = static_cast< sal_Int32 >( fMinusValue * pow(10.0,m_aMfNegative.GetDecimalDigits()) );
     565           0 :         m_aMfNegative.SetValue( nMinusValue );
     566             : 
     567           0 :         if( m_eErrorKind != CHERROR_RANGE &&
     568             :             fPlusValue == fMinusValue )
     569           0 :             m_aCbSyncPosNeg.Check();
     570             :     }
     571             : 
     572             :     // indicator
     573           0 :     aState = rInAttrs.GetItemState( SCHATTR_STAT_INDICATE, sal_True, &pPoolItem );
     574           0 :     m_bIndicatorUnique = ( aState != SFX_ITEM_DONTCARE );
     575           0 :     if( aState == SFX_ITEM_SET)
     576           0 :         m_eIndicate = ((const SvxChartIndicateItem * ) pPoolItem)->GetValue();
     577             : 
     578           0 :     if( m_bIndicatorUnique )
     579             :     {
     580           0 :         switch( m_eIndicate )
     581             :         {
     582             :             case CHINDICATE_NONE :
     583             :                 // no longer used, use both as default
     584           0 :                 m_eIndicate = CHINDICATE_BOTH;
     585             :                 // fall-through intended to BOTH
     586             :             case CHINDICATE_BOTH :
     587           0 :                 m_aRbBoth.Check(); break;
     588             :             case CHINDICATE_UP :
     589           0 :                 m_aRbPositive.Check(); break;
     590             :             case CHINDICATE_DOWN :
     591           0 :                 m_aRbNegative.Check(); break;
     592             :         }
     593             :     }
     594             :     else
     595             :     {
     596           0 :         m_aRbBoth.Check( sal_False );
     597           0 :         m_aRbPositive.Check( sal_False );
     598           0 :         m_aRbNegative.Check( sal_False );
     599             :     }
     600             : 
     601             :     // ranges
     602           0 :     aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_POS, sal_True, &pPoolItem );
     603           0 :     m_bRangePosUnique = ( aState != SFX_ITEM_DONTCARE );
     604           0 :     if( aState == SFX_ITEM_SET )
     605             :     {
     606           0 :         String sRangePositive = (static_cast< const SfxStringItem * >( pPoolItem ))->GetValue();
     607           0 :         m_aEdRangePositive.SetText( sRangePositive );
     608             :     }
     609             : 
     610           0 :     aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_NEG, sal_True, &pPoolItem );
     611           0 :     m_bRangeNegUnique = ( aState != SFX_ITEM_DONTCARE );
     612           0 :     if( aState == SFX_ITEM_SET )
     613             :     {
     614           0 :         String sRangeNegative = (static_cast< const SfxStringItem * >( pPoolItem ))->GetValue();
     615           0 :         m_aEdRangeNegative.SetText( sRangeNegative );
     616           0 :         if( m_eErrorKind == CHERROR_RANGE &&
     617           0 :             sRangeNegative.Len() > 0 &&
     618           0 :             sRangeNegative.Equals( m_aEdRangePositive.GetText()))
     619           0 :             m_aCbSyncPosNeg.Check();
     620             :     }
     621             : 
     622           0 :     UpdateControlStates();
     623           0 : }
     624             : 
     625           0 : sal_Bool ErrorBarResources::FillItemSet(SfxItemSet& rOutAttrs) const
     626             : {
     627           0 :     if( m_bErrorKindUnique )
     628           0 :         rOutAttrs.Put( SvxChartKindErrorItem( m_eErrorKind, SCHATTR_STAT_KIND_ERROR ));
     629           0 :     if( m_bIndicatorUnique )
     630           0 :         rOutAttrs.Put( SvxChartIndicateItem( m_eIndicate, SCHATTR_STAT_INDICATE ));
     631             : 
     632           0 :     if( m_bErrorKindUnique )
     633             :     {
     634           0 :         if( m_eErrorKind == CHERROR_RANGE )
     635             :         {
     636           0 :             String aPosRange;
     637           0 :             String aNegRange;
     638           0 :             if( m_bHasInternalDataProvider )
     639             :             {
     640             :                 // the strings aPosRange/aNegRange have to be set to a non-empty
     641             :                 // arbitrary string to generate error-bar sequences
     642           0 :                 aPosRange.Assign( sal_Unicode('x'));
     643           0 :                 aNegRange = aPosRange;
     644             :             }
     645             :             else
     646             :             {
     647           0 :                 aPosRange = m_aEdRangePositive.GetText();
     648           0 :                 if( m_aCbSyncPosNeg.IsChecked())
     649           0 :                     aNegRange = aPosRange;
     650             :                 else
     651           0 :                     aNegRange = m_aEdRangeNegative.GetText();
     652             :             }
     653             : 
     654           0 :             if( m_bRangePosUnique )
     655           0 :                 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS, aPosRange ));
     656           0 :             if( m_bRangeNegUnique )
     657           0 :                 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG, aNegRange ));
     658             :         }
     659           0 :         else if( m_eErrorKind == CHERROR_CONST ||
     660             :                  m_eErrorKind == CHERROR_PERCENT ||
     661             :                  m_eErrorKind == CHERROR_BIGERROR )
     662             :         {
     663           0 :             double fPosValue = static_cast< double >( m_aMfPositive.GetValue()) /
     664           0 :                 pow( 10.0, m_aMfPositive.GetDecimalDigits());
     665           0 :             double fNegValue = 0.0;
     666             : 
     667           0 :             if( m_aCbSyncPosNeg.IsChecked())
     668           0 :                 fNegValue = fPosValue;
     669             :             else
     670           0 :                 fNegValue = static_cast< double >( m_aMfNegative.GetValue()) /
     671           0 :                     pow( 10.0, m_aMfNegative.GetDecimalDigits());
     672             : 
     673           0 :             rOutAttrs.Put( SvxDoubleItem( fPosValue, SCHATTR_STAT_CONSTPLUS ));
     674           0 :             rOutAttrs.Put( SvxDoubleItem( fNegValue, SCHATTR_STAT_CONSTMINUS ));
     675             :         }
     676             :     }
     677             : 
     678           0 :     rOutAttrs.Put( SfxBoolItem( SCHATTR_STAT_ERRORBAR_TYPE , m_eErrorBarType == ERROR_BAR_Y ));
     679             : 
     680           0 :     return sal_True;
     681             : }
     682             : 
     683           0 : void ErrorBarResources::FillValueSets()
     684             : {
     685           0 :     if( m_eErrorBarType == ERROR_BAR_Y )
     686             :     {
     687           0 :         m_aFiNegative.SetImage( Image( SchResId( BMP_INDICATE_DOWN       ) ) );
     688           0 :         m_aFiPositive.SetImage( Image( SchResId( BMP_INDICATE_UP         ) ) );
     689           0 :         m_aFiBoth.SetImage(     Image( SchResId( BMP_INDICATE_BOTH_VERTI ) ) );
     690             :     }
     691           0 :     else if( m_eErrorBarType == ERROR_BAR_X )
     692             :     {
     693           0 :         m_aFiNegative.SetImage( Image( SchResId( BMP_INDICATE_LEFT      ) ) );
     694           0 :         m_aFiPositive.SetImage( Image( SchResId( BMP_INDICATE_RIGHT     ) ) );
     695           0 :         m_aFiBoth.SetImage(     Image( SchResId( BMP_INDICATE_BOTH_HORI ) ) );
     696             :     }
     697           0 : }
     698             : 
     699           0 : void ErrorBarResources::listeningFinished(
     700             :     const OUString & rNewRange )
     701             : {
     702             :     OSL_ASSERT( m_apRangeSelectionHelper.get());
     703           0 :     if( ! m_apRangeSelectionHelper.get())
     704           0 :         return;
     705             : 
     706             :     // rNewRange becomes invalid after removing the listener
     707           0 :     OUString aRange( rNewRange );
     708             : 
     709             :     // stop listening
     710           0 :     m_apRangeSelectionHelper->stopRangeListening();
     711             : 
     712             :     // change edit field
     713           0 :     if( m_pParentWindow )
     714             :     {
     715           0 :         m_pParentWindow->ToTop();
     716           0 :         m_pParentWindow->GrabFocus();
     717             :     }
     718             : 
     719           0 :     if( m_pCurrentRangeChoosingField )
     720             :     {
     721           0 :         m_pCurrentRangeChoosingField->SetText( String( aRange ));
     722           0 :         m_pCurrentRangeChoosingField->GrabFocus();
     723           0 :         PosValueChanged( 0 );
     724             :     }
     725             : 
     726           0 :     m_pCurrentRangeChoosingField = 0;
     727             : 
     728           0 :     UpdateControlStates();
     729             :     OSL_ASSERT( m_pParentDialog );
     730           0 :     if( m_pParentDialog )
     731           0 :         lcl_enableRangeChoosing( false, m_pParentDialog );
     732             : }
     733             : 
     734           0 : void ErrorBarResources::disposingRangeSelection()
     735             : {
     736             :     OSL_ASSERT( m_apRangeSelectionHelper.get());
     737           0 :     if( m_apRangeSelectionHelper.get())
     738           0 :         m_apRangeSelectionHelper->stopRangeListening( false );
     739           0 : }
     740             : 
     741           0 : bool ErrorBarResources::isRangeFieldContentValid( Edit & rEdit )
     742             : {
     743           0 :     OUString aRange( rEdit.GetText());
     744           0 :     bool bIsValid = ( aRange.isEmpty() ) ||
     745           0 :         ( m_apRangeSelectionHelper.get() &&
     746           0 :           m_apRangeSelectionHelper->verifyCellRange( aRange ));
     747             : 
     748           0 :     if( bIsValid || !rEdit.IsEnabled())
     749             :     {
     750           0 :         rEdit.SetControlForeground();
     751           0 :         rEdit.SetControlBackground();
     752             :     }
     753             :     else
     754             :     {
     755           0 :         rEdit.SetControlBackground( RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR );
     756           0 :         rEdit.SetControlForeground( RANGE_SELECTION_INVALID_RANGE_FOREGROUND_COLOR );
     757             :     }
     758             : 
     759           0 :     return bIsValid;
     760             : }
     761             : 
     762             : //.............................................................................
     763             : } //namespace chart
     764             : //.............................................................................
     765             : 
     766             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10