merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / dialogs / res_ErrorBar.cxx
blob01c074db5dcdea24f6014d0e82eaf70500d1cd67
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: res_ErrorBar.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "res_ErrorBar.hxx"
35 #include "res_ErrorBar_IDs.hrc"
36 #include "ResId.hxx"
37 #include "Strings.hrc"
38 #include "Bitmaps.hrc"
39 #include "Bitmaps_HC.hrc"
40 #include "RangeSelectionHelper.hxx"
41 // for RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR
42 #include "TabPageNotifiable.hxx"
44 #include <rtl/math.hxx>
45 #include <vcl/dialog.hxx>
46 #include <svtools/stritem.hxx>
48 using namespace ::com::sun::star;
50 namespace
52 void lcl_enableRangeChoosing( bool bEnable, Dialog * pDialog )
54 if( pDialog )
56 pDialog->Show( bEnable ? FALSE : TRUE );
57 pDialog->SetModalInputMode( bEnable ? FALSE : TRUE );
61 sal_uInt16 lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind )
63 sal_uInt16 nResult = 0;
64 switch( eErrorKind )
66 // for these cases select the default in the list box
67 case CHERROR_NONE:
68 case CHERROR_PERCENT:
69 case CHERROR_CONST:
70 case CHERROR_RANGE:
71 nResult = CHART_LB_FUNCTION_STD_DEV;
72 break;
73 case CHERROR_VARIANT:
74 nResult = CHART_LB_FUNCTION_VARIANCE;
75 break;
76 case CHERROR_SIGMA:
77 nResult = CHART_LB_FUNCTION_STD_DEV;
78 break;
79 case CHERROR_BIGERROR:
80 nResult = CHART_LB_FUNCTION_ERROR_MARGIN;
81 break;
82 case CHERROR_STDERROR:
83 nResult = CHART_LB_FUNCTION_STD_ERROR;
84 break;
86 return nResult;
88 } // anonymous namespace
91 //.............................................................................
92 namespace chart
94 //.............................................................................
96 // macro for selecting a normal or high contrast bitmap the stack variable
97 // bIsHighContrast must exist and reflect the correct state
98 #define SELECT_IMAGE(name) Image( SchResId( bIsHighContrast ? name ## _HC : name ))
100 enum StatIndicator
102 INDICATE_BOTH,
103 INDICATE_UP,
104 INDICATE_DOWN
107 ErrorBarResources::ErrorBarResources( Window* pParent, Dialog * pParentDialog,
108 const SfxItemSet& rInAttrs, bool bNoneAvailable,
109 tErrorBarType eType /* = ERROR_BAR_Y */ ) :
111 m_aFlErrorCategory( pParent, SchResId( FL_ERROR )),
112 m_aRbNone( pParent, SchResId( RB_NONE )),
113 m_aRbConst( pParent, SchResId( RB_CONST )),
114 m_aRbPercent( pParent, SchResId( RB_PERCENT )),
115 m_aRbFunction( pParent, SchResId( RB_FUNCTION )),
116 m_aRbRange( pParent, SchResId( RB_RANGE )),
117 m_aLbFunction( pParent, SchResId( LB_FUNCTION )),
119 m_aFlParameters( pParent, SchResId( FL_PARAMETERS )),
120 m_aFtPositive( pParent, SchResId( FT_POSITIVE )),
121 m_aMfPositive( pParent, SchResId( MF_POSITIVE )),
122 m_aEdRangePositive( pParent, SchResId( ED_RANGE_POSITIVE )),
123 m_aIbRangePositive( pParent, SchResId( IB_RANGE_POSITIVE )),
124 m_aFtNegative( pParent, SchResId( FT_NEGATIVE )),
125 m_aMfNegative( pParent, SchResId( MF_NEGATIVE )),
126 m_aEdRangeNegative( pParent, SchResId( ED_RANGE_NEGATIVE )),
127 m_aIbRangeNegative( pParent, SchResId( IB_RANGE_NEGATIVE )),
128 m_aCbSyncPosNeg( pParent, SchResId( CB_SYN_POS_NEG )),
130 m_aFlIndicate( pParent, SchResId( FL_INDICATE )),
131 m_aRbBoth( pParent, SchResId( RB_BOTH )),
132 m_aRbPositive( pParent, SchResId( RB_POSITIVE )),
133 m_aRbNegative( pParent, SchResId( RB_NEGATIVE )),
134 m_aFiBoth( pParent, SchResId( FI_BOTH )),
135 m_aFiPositive( pParent, SchResId( FI_POSITIVE )),
136 m_aFiNegative( pParent, SchResId( FI_NEGATIVE )),
138 m_eErrorKind( CHERROR_NONE ),
139 m_eIndicate( CHINDICATE_BOTH ),
140 m_bErrorKindUnique( true ),
141 m_bIndicatorUnique( true ),
142 m_bPlusUnique( true ),
143 m_bMinusUnique( true ),
144 m_bRangePosUnique( true ),
145 m_bRangeNegUnique( true ),
146 m_bNoneAvailable( bNoneAvailable ),
147 m_eErrorBarType( eType ),
148 m_nConstDecimalDigits( 1 ),
149 m_nConstSpinSize( 1 ),
150 m_pParentWindow( pParent ),
151 m_pParentDialog( pParentDialog ),
152 m_pCurrentRangeChoosingField( 0 ),
153 m_bHasInternalDataProvider( true )
155 if( m_bNoneAvailable )
156 m_aRbNone.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
157 else
158 m_aRbNone.Hide();
160 m_aRbConst.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
161 m_aRbPercent.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
162 m_aRbFunction.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
163 m_aRbRange.SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
164 m_aLbFunction.SetSelectHdl( LINK( this, ErrorBarResources, CategoryChosen ));
166 m_aCbSyncPosNeg.Check( FALSE );
167 m_aCbSyncPosNeg.SetToggleHdl( LINK( this, ErrorBarResources, SynchronizePosAndNeg ));
169 m_aMfPositive.SetModifyHdl( LINK( this, ErrorBarResources, PosValueChanged ));
170 m_aEdRangePositive.SetModifyHdl( LINK( this, ErrorBarResources, RangeChanged ));
171 m_aEdRangeNegative.SetModifyHdl( LINK( this, ErrorBarResources, RangeChanged ));
173 m_aRbPositive.SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
174 m_aRbNegative.SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
175 m_aRbBoth.SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
177 m_aIbRangePositive.SetClickHdl( LINK( this, ErrorBarResources, ChooseRange ));
178 m_aIbRangeNegative.SetClickHdl( LINK( this, ErrorBarResources, ChooseRange ));
179 m_aIbRangePositive.SetQuickHelpText( String( SchResId( STR_TIP_SELECT_RANGE )));
180 m_aIbRangeNegative.SetQuickHelpText( String( SchResId( STR_TIP_SELECT_RANGE )));
182 FillValueSets();
183 Reset( rInAttrs );
186 ErrorBarResources::~ErrorBarResources()
190 void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType )
192 if( m_eErrorBarType != eNewType )
194 m_eErrorBarType = eNewType;
195 FillValueSets();
199 void ErrorBarResources::SetChartDocumentForRangeChoosing(
200 const uno::Reference< chart2::XChartDocument > & xChartDocument )
202 if( xChartDocument.is())
203 m_bHasInternalDataProvider = xChartDocument->hasInternalDataProvider();
204 m_apRangeSelectionHelper.reset( new RangeSelectionHelper( xChartDocument ));
206 // has internal data provider => rename "cell range" to "from data"
207 OSL_ASSERT( m_apRangeSelectionHelper.get());
208 if( m_bHasInternalDataProvider )
210 m_aRbRange.SetText( String( SchResId( STR_CONTROLTEXT_ERROR_BARS_FROM_DATA )));
213 if( m_aRbRange.IsChecked())
215 isRangeFieldContentValid( m_aEdRangePositive );
216 isRangeFieldContentValid( m_aEdRangeNegative );
220 void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
222 if( fMinorStepWidth < 0 )
223 fMinorStepWidth = -fMinorStepWidth;
225 sal_Int32 nExponent = static_cast< sal_Int32 >( ::rtl::math::approxFloor( log10( fMinorStepWidth )));
226 if( nExponent <= 0 )
228 // one digit precision more
229 m_nConstDecimalDigits = static_cast< sal_uInt16 >( (-nExponent) + 1 );
230 m_nConstSpinSize = 10;
232 else
234 m_nConstDecimalDigits = 0;
235 m_nConstSpinSize = static_cast< sal_Int64 >( pow( 10.0, (int)nExponent ));
239 void ErrorBarResources::UpdateControlStates()
241 // function
242 bool bIsFunction = m_aRbFunction.IsChecked();
243 m_aLbFunction.Enable( bIsFunction );
245 // range buttons
246 bool bShowRange = ( m_aRbRange.IsChecked());
247 bool bCanChooseRange =
248 ( bShowRange &&
249 m_apRangeSelectionHelper.get() &&
250 m_apRangeSelectionHelper->hasRangeSelection());
252 m_aMfPositive.Show( ! bShowRange );
253 m_aMfNegative.Show( ! bShowRange );
255 // use range but without range chooser => hide controls
256 m_aEdRangePositive.Show( bShowRange && ! m_bHasInternalDataProvider );
257 m_aIbRangePositive.Show( bCanChooseRange );
258 m_aEdRangeNegative.Show( bShowRange && ! m_bHasInternalDataProvider );
259 m_aIbRangeNegative.Show( bCanChooseRange );
261 bool bShowPosNegAndSync = ! (bShowRange && m_bHasInternalDataProvider);
262 m_aFtPositive.Show( bShowPosNegAndSync );
263 m_aFtNegative.Show( bShowPosNegAndSync );
264 m_aCbSyncPosNeg.Show( bShowPosNegAndSync );
265 m_aFlParameters.Show( bShowPosNegAndSync );
267 // unit for metric fields
268 bool bIsErrorMargin(
269 ( m_aRbFunction.IsChecked()) &&
270 ( m_aLbFunction.GetSelectEntryPos() == CHART_LB_FUNCTION_ERROR_MARGIN ));
271 bool bIsPercentage( m_aRbPercent.IsChecked() || bIsErrorMargin );
272 String aCustomUnit;
274 if( bIsPercentage )
276 aCustomUnit = String( RTL_CONSTASCII_USTRINGPARAM( " %" ));
277 m_aMfPositive.SetDecimalDigits( 1 );
278 m_aMfPositive.SetSpinSize( 10 );
279 m_aMfNegative.SetDecimalDigits( 1 );
280 m_aMfNegative.SetSpinSize( 10 );
282 else
284 m_aMfPositive.SetDecimalDigits( m_nConstDecimalDigits );
285 m_aMfPositive.SetSpinSize( m_nConstSpinSize );
286 m_aMfNegative.SetDecimalDigits( m_nConstDecimalDigits );
287 m_aMfNegative.SetSpinSize( m_nConstSpinSize );
289 m_aMfPositive.SetCustomUnitText( aCustomUnit );
290 m_aMfNegative.SetCustomUnitText( aCustomUnit );
292 // positive and negative value fields
293 bool bPosEnabled = ( m_aRbPositive.IsChecked() || m_aRbBoth.IsChecked());
294 bool bNegEnabled = ( m_aRbNegative.IsChecked() || m_aRbBoth.IsChecked());
295 if( !( bPosEnabled || bNegEnabled ))
297 // all three controls are not checked -> ambiguous state
298 bPosEnabled = true;
299 bNegEnabled = true;
302 // functions with only one parameter
303 bool bOneParameterCategory =
304 bIsErrorMargin || m_aRbPercent.IsChecked();
305 if( bOneParameterCategory )
307 m_aCbSyncPosNeg.Check();
310 if( m_aCbSyncPosNeg.IsChecked())
312 bPosEnabled = true;
313 bNegEnabled = false;
316 // all functions except error margin take no arguments
317 if( m_aRbFunction.IsChecked() &&
318 ( m_aLbFunction.GetSelectEntryPos() != CHART_LB_FUNCTION_ERROR_MARGIN ))
320 bPosEnabled = false;
321 bNegEnabled = false;
324 // enable/disable pos/neg fields
325 m_aFtPositive.Enable( bPosEnabled );
326 m_aFtNegative.Enable( bNegEnabled );
327 if( bShowRange )
329 m_aEdRangePositive.Enable( bPosEnabled );
330 m_aIbRangePositive.Enable( bPosEnabled );
331 m_aEdRangeNegative.Enable( bNegEnabled );
332 m_aIbRangeNegative.Enable( bNegEnabled );
334 else
336 m_aMfPositive.Enable( bPosEnabled );
337 m_aMfNegative.Enable( bNegEnabled );
340 m_aCbSyncPosNeg.Enable(
341 !bOneParameterCategory &&
342 ( bPosEnabled || bNegEnabled ));
344 // mark invalid entries in the range fields
345 if( bShowRange && ! m_bHasInternalDataProvider )
347 isRangeFieldContentValid( m_aEdRangePositive );
348 isRangeFieldContentValid( m_aEdRangeNegative );
352 IMPL_LINK( ErrorBarResources, CategoryChosen, void *, )
354 m_bErrorKindUnique = true;
355 SvxChartKindError eOldError = m_eErrorKind;
357 if( m_aRbNone.IsChecked())
358 m_eErrorKind = CHERROR_NONE;
359 else if( m_aRbConst.IsChecked())
360 m_eErrorKind = CHERROR_CONST;
361 else if( m_aRbPercent.IsChecked())
362 m_eErrorKind = CHERROR_PERCENT;
363 else if( m_aRbRange.IsChecked())
364 m_eErrorKind = CHERROR_RANGE;
365 else if( m_aRbFunction.IsChecked())
367 if( m_aLbFunction.GetSelectEntryCount() == 1 )
369 switch( m_aLbFunction.GetSelectEntryPos())
371 case CHART_LB_FUNCTION_STD_ERROR:
372 m_eErrorKind = CHERROR_STDERROR; break;
373 case CHART_LB_FUNCTION_STD_DEV:
374 m_eErrorKind = CHERROR_SIGMA; break;
375 case CHART_LB_FUNCTION_VARIANCE:
376 m_eErrorKind = CHERROR_VARIANT; break;
377 case CHART_LB_FUNCTION_ERROR_MARGIN:
378 m_eErrorKind = CHERROR_BIGERROR; break;
379 default:
380 m_bErrorKindUnique = false;
383 else
384 m_bErrorKindUnique = false;
386 else
388 OSL_ENSURE( false, "Unknown category chosen" );
389 m_bErrorKindUnique = false;
392 // changed to range
393 if( m_eErrorKind == CHERROR_RANGE &&
394 eOldError != CHERROR_RANGE )
396 m_aCbSyncPosNeg.Check(
397 (m_aEdRangePositive.GetText().Len() > 0) &&
398 m_aEdRangePositive.GetText().Equals(
399 m_aEdRangeNegative.GetText()));
401 // changed from range
402 else if( m_eErrorKind != CHERROR_RANGE &&
403 eOldError == CHERROR_RANGE )
405 m_aCbSyncPosNeg.Check(
406 m_aMfPositive.GetValue() == m_aMfNegative.GetValue());
409 UpdateControlStates();
410 return 0;
413 IMPL_LINK( ErrorBarResources, SynchronizePosAndNeg, void *, EMPTYARG )
415 UpdateControlStates();
416 PosValueChanged( 0 );
417 return 0;
420 IMPL_LINK( ErrorBarResources, PosValueChanged, void *, EMPTYARG )
422 if( m_aCbSyncPosNeg.IsChecked())
424 if( m_aRbRange.IsChecked())
426 m_aEdRangeNegative.SetText( m_aEdRangePositive.GetText());
427 m_bRangeNegUnique = m_bRangePosUnique;
429 else
430 m_aMfNegative.SetValue( m_aMfPositive.GetValue());
433 return 0;
436 IMPL_LINK( ErrorBarResources, IndicatorChanged, void *, EMPTYARG )
438 m_bIndicatorUnique = true;
439 if( m_aRbBoth.IsChecked())
440 m_eIndicate = CHINDICATE_BOTH;
441 else if( m_aRbPositive.IsChecked())
442 m_eIndicate = CHINDICATE_UP;
443 else if( m_aRbNegative.IsChecked())
444 m_eIndicate = CHINDICATE_DOWN;
445 else
446 m_bIndicatorUnique = false;
448 UpdateControlStates();
449 return 0;
452 IMPL_LINK( ErrorBarResources, ChooseRange, RangeSelectionButton *, pButton )
454 OSL_ASSERT( m_apRangeSelectionHelper.get());
455 if( ! m_apRangeSelectionHelper.get())
456 return 0;
457 OSL_ASSERT( m_pCurrentRangeChoosingField == 0 );
459 ::rtl::OUString aUIString;
460 if( pButton == &m_aIbRangePositive )
462 m_pCurrentRangeChoosingField = &m_aEdRangePositive;
463 aUIString = ::rtl::OUString( String( SchResId( STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS )));
465 else
467 m_pCurrentRangeChoosingField = &m_aEdRangeNegative;
468 aUIString = ::rtl::OUString( String( SchResId( STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS )));
471 OSL_ASSERT( m_pParentDialog );
472 if( m_pParentDialog )
474 lcl_enableRangeChoosing( true, m_pParentDialog );
475 m_apRangeSelectionHelper->chooseRange(
476 m_pCurrentRangeChoosingField->GetText(),
477 aUIString, *this );
479 else
480 m_pCurrentRangeChoosingField = 0;
482 return 0;
485 IMPL_LINK( ErrorBarResources, RangeChanged, Edit *, pEdit )
487 if( pEdit == & m_aEdRangePositive )
489 m_bRangePosUnique = true;
490 PosValueChanged( 0 );
492 else
494 m_bRangeNegUnique = true;
497 isRangeFieldContentValid( *pEdit );
499 return 0;
502 void ErrorBarResources::Reset(const SfxItemSet& rInAttrs)
504 const SfxPoolItem *pPoolItem = NULL;
505 SfxItemState aState = SFX_ITEM_UNKNOWN;
507 // category
508 m_eErrorKind = CHERROR_NONE;
509 aState = rInAttrs.GetItemState( SCHATTR_STAT_KIND_ERROR, TRUE, &pPoolItem );
510 m_bErrorKindUnique = ( aState != SFX_ITEM_DONTCARE );
512 if( aState == SFX_ITEM_SET )
513 m_eErrorKind = ((const SvxChartKindErrorItem*) pPoolItem)->GetValue();
515 m_aLbFunction.SelectEntryPos( lcl_getLbEntryPosByErrorKind( m_eErrorKind ));
517 if( m_bErrorKindUnique )
519 switch( m_eErrorKind )
521 case CHERROR_NONE:
522 m_aRbNone.Check();
523 break;
524 case CHERROR_PERCENT:
525 m_aRbPercent.Check();
526 break;
527 case CHERROR_CONST:
528 m_aRbConst.Check();
529 break;
530 case CHERROR_STDERROR:
531 case CHERROR_VARIANT:
532 case CHERROR_SIGMA:
533 case CHERROR_BIGERROR:
534 m_aRbFunction.Check();
535 break;
536 case CHERROR_RANGE:
537 m_aRbRange.Check();
538 break;
541 else
543 m_aRbNone.Check( FALSE );
544 m_aRbConst.Check( FALSE );
545 m_aRbPercent.Check( FALSE );
546 m_aRbFunction.Check( FALSE );
549 // parameters
550 aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTPLUS, TRUE, &pPoolItem );
551 m_bPlusUnique = ( aState != SFX_ITEM_DONTCARE );
552 double fPlusValue = 0.0;
553 if( aState == SFX_ITEM_SET )
555 fPlusValue = ((const SvxDoubleItem*) pPoolItem)->GetValue();
556 sal_Int32 nPlusValue = static_cast< sal_Int32 >( fPlusValue * pow(10.0,m_aMfPositive.GetDecimalDigits()) );
557 m_aMfPositive.SetValue( nPlusValue );
560 aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTMINUS, TRUE, &pPoolItem );
561 m_bMinusUnique = ( aState != SFX_ITEM_DONTCARE );
562 double fMinusValue = 0.0;
563 if( aState == SFX_ITEM_SET )
565 fMinusValue = ((const SvxDoubleItem*) pPoolItem)->GetValue();
566 sal_Int32 nMinusValue = static_cast< sal_Int32 >( fMinusValue * pow(10.0,m_aMfNegative.GetDecimalDigits()) );
567 m_aMfNegative.SetValue( nMinusValue );
569 if( m_eErrorKind != CHERROR_RANGE &&
570 fPlusValue == fMinusValue )
571 m_aCbSyncPosNeg.Check();
574 // indicator
575 aState = rInAttrs.GetItemState( SCHATTR_STAT_INDICATE, TRUE, &pPoolItem );
576 m_bIndicatorUnique = ( aState != SFX_ITEM_DONTCARE );
577 if( aState == SFX_ITEM_SET)
578 m_eIndicate = ((const SvxChartIndicateItem * ) pPoolItem)->GetValue();
580 if( m_bIndicatorUnique )
582 switch( m_eIndicate )
584 case CHINDICATE_NONE :
585 // no longer used, use both as default
586 m_eIndicate = CHINDICATE_BOTH;
587 // fall-through intended to BOTH
588 case CHINDICATE_BOTH :
589 m_aRbBoth.Check(); break;
590 case CHINDICATE_UP :
591 m_aRbPositive.Check(); break;
592 case CHINDICATE_DOWN :
593 m_aRbNegative.Check(); break;
596 else
598 m_aRbBoth.Check( FALSE );
599 m_aRbPositive.Check( FALSE );
600 m_aRbNegative.Check( FALSE );
603 // ranges
604 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_POS, TRUE, &pPoolItem );
605 m_bRangePosUnique = ( aState != SFX_ITEM_DONTCARE );
606 if( aState == SFX_ITEM_SET )
608 String sRangePositive = (static_cast< const SfxStringItem * >( pPoolItem ))->GetValue();
609 m_aEdRangePositive.SetText( sRangePositive );
612 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_NEG, TRUE, &pPoolItem );
613 m_bRangeNegUnique = ( aState != SFX_ITEM_DONTCARE );
614 if( aState == SFX_ITEM_SET )
616 String sRangeNegative = (static_cast< const SfxStringItem * >( pPoolItem ))->GetValue();
617 m_aEdRangeNegative.SetText( sRangeNegative );
618 if( m_eErrorKind == CHERROR_RANGE &&
619 sRangeNegative.Len() > 0 &&
620 sRangeNegative.Equals( m_aEdRangePositive.GetText()))
621 m_aCbSyncPosNeg.Check();
624 UpdateControlStates();
627 BOOL ErrorBarResources::FillItemSet(SfxItemSet& rOutAttrs) const
629 if( m_bErrorKindUnique )
630 rOutAttrs.Put( SvxChartKindErrorItem( m_eErrorKind, SCHATTR_STAT_KIND_ERROR ));
631 if( m_bIndicatorUnique )
632 rOutAttrs.Put( SvxChartIndicateItem( m_eIndicate, SCHATTR_STAT_INDICATE ));
634 if( m_bErrorKindUnique )
636 if( m_eErrorKind == CHERROR_RANGE )
638 String aPosRange;
639 String aNegRange;
640 if( m_bHasInternalDataProvider )
642 // the strings aPosRange/aNegRange have to be set to a non-empty
643 // arbitrary string to generate error-bar sequences
644 aPosRange.Assign( sal_Unicode('x'));
645 aNegRange = aPosRange;
647 else
649 aPosRange = m_aEdRangePositive.GetText();
650 if( m_aCbSyncPosNeg.IsChecked())
651 aNegRange = aPosRange;
652 else
653 aNegRange = m_aEdRangeNegative.GetText();
656 if( m_bRangePosUnique )
657 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS, aPosRange ));
658 if( m_bRangeNegUnique )
659 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG, aNegRange ));
661 else if( m_eErrorKind == CHERROR_CONST ||
662 m_eErrorKind == CHERROR_PERCENT ||
663 m_eErrorKind == CHERROR_BIGERROR )
665 double fPosValue = static_cast< double >( m_aMfPositive.GetValue()) /
666 pow( 10.0, m_aMfPositive.GetDecimalDigits());
667 double fNegValue = 0.0;
669 if( m_aCbSyncPosNeg.IsChecked())
670 fNegValue = fPosValue;
671 else
672 fNegValue = static_cast< double >( m_aMfNegative.GetValue()) /
673 pow( 10.0, m_aMfNegative.GetDecimalDigits());
675 rOutAttrs.Put( SvxDoubleItem( fPosValue, SCHATTR_STAT_CONSTPLUS ));
676 rOutAttrs.Put( SvxDoubleItem( fNegValue, SCHATTR_STAT_CONSTMINUS ));
680 return TRUE;
683 void ErrorBarResources::FillValueSets()
685 bool bIsHighContrast = ( true && m_aRbConst.GetDisplayBackground().GetColor().IsDark() );
687 // do not scale images, show then centered
688 // m_aFiPositive.SetStyle( (m_aFiPositive.GetStyle() & (~WB_SCALE)) | WB_CENTER );
689 // m_aFiNegative.SetStyle( (m_aFiNegative.GetStyle() & (~WB_SCALE)) | WB_CENTER );
690 // m_aFiBoth.SetStyle( (m_aFiBoth.GetStyle() & (~WB_SCALE)) | WB_CENTER );
692 if( m_eErrorBarType == ERROR_BAR_Y )
694 m_aFiNegative.SetImage( SELECT_IMAGE( BMP_INDICATE_DOWN ));
695 m_aFiPositive.SetImage( SELECT_IMAGE( BMP_INDICATE_UP ));
696 m_aFiBoth.SetImage( SELECT_IMAGE( BMP_INDICATE_BOTH_VERTI ));
698 else if( m_eErrorBarType == ERROR_BAR_X )
700 m_aFiNegative.SetImage( SELECT_IMAGE( BMP_INDICATE_LEFT ));
701 m_aFiPositive.SetImage( SELECT_IMAGE( BMP_INDICATE_RIGHT ));
702 m_aFiBoth.SetImage( SELECT_IMAGE( BMP_INDICATE_BOTH_HORI ));
706 void ErrorBarResources::listeningFinished(
707 const ::rtl::OUString & rNewRange )
709 OSL_ASSERT( m_apRangeSelectionHelper.get());
710 if( ! m_apRangeSelectionHelper.get())
711 return;
713 // rNewRange becomes invalid after removing the listener
714 ::rtl::OUString aRange( rNewRange );
716 // m_rDialogModel.startControllerLockTimer();
718 // stop listening
719 m_apRangeSelectionHelper->stopRangeListening();
721 // change edit field
722 if( m_pParentWindow )
724 m_pParentWindow->ToTop();
725 m_pParentWindow->GrabFocus();
728 if( m_pCurrentRangeChoosingField )
730 m_pCurrentRangeChoosingField->SetText( String( aRange ));
731 m_pCurrentRangeChoosingField->GrabFocus();
732 PosValueChanged( 0 );
735 m_pCurrentRangeChoosingField = 0;
737 UpdateControlStates();
738 OSL_ASSERT( m_pParentDialog );
739 if( m_pParentDialog )
740 lcl_enableRangeChoosing( false, m_pParentDialog );
743 void ErrorBarResources::disposingRangeSelection()
745 OSL_ASSERT( m_apRangeSelectionHelper.get());
746 if( m_apRangeSelectionHelper.get())
747 m_apRangeSelectionHelper->stopRangeListening( false );
750 bool ErrorBarResources::isRangeFieldContentValid( Edit & rEdit )
752 ::rtl::OUString aRange( rEdit.GetText());
753 bool bIsValid = ( aRange.getLength() == 0 ) ||
754 ( m_apRangeSelectionHelper.get() &&
755 m_apRangeSelectionHelper->verifyCellRange( aRange ));
757 if( bIsValid || !rEdit.IsEnabled())
759 rEdit.SetControlForeground();
760 rEdit.SetControlBackground();
762 else
764 rEdit.SetControlBackground( RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR );
765 rEdit.SetControlForeground( RANGE_SELECTION_INVALID_RANGE_FOREGROUND_COLOR );
768 return bIsValid;
771 //.............................................................................
772 } //namespace chart
773 //.............................................................................