fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / res_ErrorBar.cxx
bloba49be4491672d80e7a42c296bdfd8464b984b5b8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "res_ErrorBar.hxx"
21 #include "ResId.hxx"
22 #include "Bitmaps.hrc"
23 #include "RangeSelectionHelper.hxx"
24 #include "TabPageNotifiable.hxx"
25 #include "macros.hxx"
27 #include <rtl/math.hxx>
28 #include <vcl/dialog.hxx>
29 #include <svl/stritem.hxx>
31 #define CHART_LB_FUNCTION_STD_ERROR 0
32 #define CHART_LB_FUNCTION_STD_DEV 1
33 #define CHART_LB_FUNCTION_VARIANCE 2
34 #define CHART_LB_FUNCTION_ERROR_MARGIN 3
36 using namespace ::com::sun::star;
38 namespace
40 void lcl_enableRangeChoosing( bool bEnable, Dialog * pDialog )
42 if( pDialog )
44 pDialog->Show( !bEnable );
45 pDialog->SetModalInputMode( !bEnable );
49 sal_uInt16 lcl_getLbEntryPosByErrorKind( SvxChartKindError eErrorKind )
51 sal_uInt16 nResult = 0;
52 switch( eErrorKind )
54 // for these cases select the default in the list box
55 case CHERROR_NONE:
56 case CHERROR_PERCENT:
57 case CHERROR_CONST:
58 case CHERROR_RANGE:
59 nResult = CHART_LB_FUNCTION_STD_DEV;
60 break;
61 case CHERROR_VARIANT:
62 nResult = CHART_LB_FUNCTION_VARIANCE;
63 break;
64 case CHERROR_SIGMA:
65 nResult = CHART_LB_FUNCTION_STD_DEV;
66 break;
67 case CHERROR_BIGERROR:
68 nResult = CHART_LB_FUNCTION_ERROR_MARGIN;
69 break;
70 case CHERROR_STDERROR:
71 nResult = CHART_LB_FUNCTION_STD_ERROR;
72 break;
74 return nResult;
76 } // anonymous namespace
78 namespace chart
81 ErrorBarResources::ErrorBarResources( VclBuilderContainer* pParent, Dialog * pParentDialog,
82 const SfxItemSet& rInAttrs, bool bNoneAvailable,
83 tErrorBarType eType /* = ERROR_BAR_Y */ ) :
84 m_eErrorKind( CHERROR_NONE ),
85 m_eIndicate( CHINDICATE_BOTH ),
86 m_bErrorKindUnique( true ),
87 m_bIndicatorUnique( true ),
88 m_bPlusUnique( true ),
89 m_bMinusUnique( true ),
90 m_bRangePosUnique( true ),
91 m_bRangeNegUnique( true ),
92 m_bNoneAvailable( bNoneAvailable ),
93 m_eErrorBarType( eType ),
94 m_nConstDecimalDigits( 1 ),
95 m_nConstSpinSize( 1 ),
96 m_fPlusValue(0.0),
97 m_fMinusValue(0.0),
98 m_pParentDialog( pParentDialog ),
99 m_pCurrentRangeChoosingField( 0 ),
100 m_bHasInternalDataProvider( true ),
101 m_bEnableDataTableDialog( true )
103 pParent->get(m_pRbNone,"RB_NONE");
104 pParent->get(m_pRbConst, "RB_CONST");
105 pParent->get(m_pRbPercent, "RB_PERCENT");
106 pParent->get(m_pRbFunction, "RB_FUNCTION");
107 pParent->get(m_pRbRange, "RB_RANGE");
108 pParent->get(m_pLbFunction, "LB_FUNCTION");
110 pParent->get(m_pFlParameters, "framePARAMETERS");
111 pParent->get(m_pBxPositive, "boxPOSITIVE");
112 pParent->get(m_pMfPositive, "MF_POSITIVE");
113 pParent->get(m_pEdRangePositive, "ED_RANGE_POSITIVE");
114 pParent->get(m_pIbRangePositive, "IB_RANGE_POSITIVE");
115 pParent->get(m_pBxNegative, "boxNEGATIVE");
116 pParent->get(m_pMfNegative, "MF_NEGATIVE");
117 pParent->get(m_pEdRangeNegative, "ED_RANGE_NEGATIVE");
118 pParent->get(m_pIbRangeNegative, "IB_RANGE_NEGATIVE");
119 pParent->get(m_pCbSyncPosNeg, "CB_SYN_POS_NEG");
121 pParent->get(m_pRbBoth, "RB_BOTH");
122 pParent->get(m_pRbPositive, "RB_POSITIVE");
123 pParent->get(m_pRbNegative, "RB_NEGATIVE");
124 pParent->get(m_pFiBoth, "FI_BOTH");
125 pParent->get(m_pFiPositive, "FI_POSITIVE");
126 pParent->get(m_pFiNegative, "FI_NEGATIVE");
128 pParent->get(m_pUIStringPos, "STR_DATA_SELECT_RANGE_FOR_POSITIVE_ERRORBARS");
129 pParent->get(m_pUIStringNeg, "STR_DATA_SELECT_RANGE_FOR_NEGATIVE_ERRORBARS");
130 pParent->get(m_pUIStringRbRange, "STR_CONTROLTEXT_ERROR_BARS_FROM_DATA");
132 if( m_bNoneAvailable )
133 m_pRbNone->SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
134 else
135 m_pRbNone->Hide();
137 m_pRbConst->SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
138 m_pRbPercent->SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
139 m_pRbFunction->SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
140 m_pRbRange->SetClickHdl( LINK( this, ErrorBarResources, CategoryChosen ));
141 m_pLbFunction->SetSelectHdl( LINK( this, ErrorBarResources, CategoryChosen ));
143 m_pCbSyncPosNeg->Check( false );
144 m_pCbSyncPosNeg->SetToggleHdl( LINK( this, ErrorBarResources, SynchronizePosAndNeg ));
146 m_pMfPositive->SetModifyHdl( LINK( this, ErrorBarResources, PosValueChanged ));
147 m_pEdRangePositive->SetModifyHdl( LINK( this, ErrorBarResources, RangeChanged ));
148 m_pEdRangeNegative->SetModifyHdl( LINK( this, ErrorBarResources, RangeChanged ));
150 m_pRbPositive->SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
151 m_pRbNegative->SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
152 m_pRbBoth->SetClickHdl( LINK( this, ErrorBarResources, IndicatorChanged ));
154 m_pIbRangePositive->SetClickHdl( LINK( this, ErrorBarResources, ChooseRange ));
155 m_pIbRangeNegative->SetClickHdl( LINK( this, ErrorBarResources, ChooseRange ));
157 FillValueSets();
158 Reset( rInAttrs );
161 ErrorBarResources::~ErrorBarResources()
165 void ErrorBarResources::SetErrorBarType( tErrorBarType eNewType )
167 if( m_eErrorBarType != eNewType )
169 m_eErrorBarType = eNewType;
170 FillValueSets();
174 void ErrorBarResources::SetChartDocumentForRangeChoosing(
175 const uno::Reference< chart2::XChartDocument > & xChartDocument )
177 if( xChartDocument.is())
179 m_bHasInternalDataProvider = xChartDocument->hasInternalDataProvider();
180 uno::Reference< beans::XPropertySet > xProps( xChartDocument, uno::UNO_QUERY );
181 if ( xProps.is() )
185 xProps->getPropertyValue("EnableDataTableDialog") >>= m_bEnableDataTableDialog;
187 catch( const uno::Exception& e )
189 ASSERT_EXCEPTION( e );
193 m_apRangeSelectionHelper.reset( new RangeSelectionHelper( xChartDocument ));
195 // has internal data provider => rename "cell range" to "from data"
196 OSL_ASSERT( m_apRangeSelectionHelper.get());
197 if( m_bHasInternalDataProvider )
199 m_pRbRange->SetText(m_pUIStringRbRange->GetText());
202 if( m_pRbRange->IsChecked())
204 isRangeFieldContentValid( *m_pEdRangePositive );
205 isRangeFieldContentValid( *m_pEdRangeNegative );
209 void ErrorBarResources::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
211 if( fMinorStepWidth < 0 )
212 fMinorStepWidth = -fMinorStepWidth;
214 sal_Int32 nExponent = static_cast< sal_Int32 >( ::rtl::math::approxFloor( log10( fMinorStepWidth )));
215 if( nExponent <= 0 )
217 // one digit precision more
218 m_nConstDecimalDigits = static_cast< sal_uInt16 >( (-nExponent) + 1 );
219 m_nConstSpinSize = 10;
221 else
223 m_nConstDecimalDigits = 0;
224 m_nConstSpinSize = static_cast< sal_Int64 >( pow( 10.0, (int)nExponent ));
228 void ErrorBarResources::UpdateControlStates()
230 // function
231 bool bIsFunction = m_pRbFunction->IsChecked();
232 m_pLbFunction->Enable( bIsFunction );
234 // range buttons
235 m_pRbRange->Enable( !m_bHasInternalDataProvider || m_bEnableDataTableDialog );
236 bool bShowRange = ( m_pRbRange->IsChecked());
237 bool bCanChooseRange =
238 ( bShowRange &&
239 m_apRangeSelectionHelper.get() &&
240 m_apRangeSelectionHelper->hasRangeSelection());
242 m_pMfPositive->Show( ! bShowRange );
243 m_pMfNegative->Show( ! bShowRange );
245 // use range but without range chooser => hide controls
246 m_pEdRangePositive->Show( bShowRange && ! m_bHasInternalDataProvider );
247 m_pIbRangePositive->Show( bCanChooseRange );
248 m_pEdRangeNegative->Show( bShowRange && ! m_bHasInternalDataProvider );
249 m_pIbRangeNegative->Show( bCanChooseRange );
251 bool bShowPosNegAndSync = ! (bShowRange && m_bHasInternalDataProvider);
252 m_pFlParameters->Show( bShowPosNegAndSync );
254 // unit for metric fields
255 bool bIsErrorMargin(
256 ( m_pRbFunction->IsChecked()) &&
257 ( m_pLbFunction->GetSelectEntryPos() == CHART_LB_FUNCTION_ERROR_MARGIN ));
258 bool bIsPercentage( m_pRbPercent->IsChecked() || bIsErrorMargin );
259 OUString aCustomUnit;
261 if( bIsPercentage )
263 aCustomUnit = " %";
264 m_pMfPositive->SetDecimalDigits( 1 );
265 m_pMfPositive->SetSpinSize( 10 );
266 m_pMfNegative->SetDecimalDigits( 1 );
267 m_pMfNegative->SetSpinSize( 10 );
269 else
271 m_pMfPositive->SetDecimalDigits( m_nConstDecimalDigits );
272 m_pMfPositive->SetSpinSize( m_nConstSpinSize );
273 m_pMfNegative->SetDecimalDigits( m_nConstDecimalDigits );
274 m_pMfNegative->SetSpinSize( m_nConstSpinSize );
277 sal_Int32 nPlusValue = static_cast< sal_Int32 >( m_fPlusValue * pow(10.0,m_pMfPositive->GetDecimalDigits()) );
278 sal_Int32 nMinusValue = static_cast< sal_Int32 >( m_fMinusValue * pow(10.0,m_pMfNegative->GetDecimalDigits()) );
280 m_pMfPositive->SetValue( nPlusValue );
281 m_pMfNegative->SetValue( nMinusValue );
283 m_pMfPositive->SetCustomUnitText( aCustomUnit );
284 m_pMfNegative->SetCustomUnitText( aCustomUnit );
286 // positive and negative value fields
287 bool bPosEnabled = ( m_pRbPositive->IsChecked() || m_pRbBoth->IsChecked());
288 bool bNegEnabled = ( m_pRbNegative->IsChecked() || m_pRbBoth->IsChecked());
289 if( !( bPosEnabled || bNegEnabled ))
291 // all three controls are not checked -> ambiguous state
292 bPosEnabled = true;
293 bNegEnabled = true;
296 // functions with only one parameter
297 bool bOneParameterCategory =
298 bIsErrorMargin || m_pRbPercent->IsChecked();
299 if( bOneParameterCategory )
301 m_pCbSyncPosNeg->Check();
304 if( m_pCbSyncPosNeg->IsChecked())
306 bPosEnabled = true;
307 bNegEnabled = false;
310 // all functions except error margin take no arguments
311 if( m_pRbFunction->IsChecked() && ( m_pLbFunction->GetSelectEntryPos() != CHART_LB_FUNCTION_ERROR_MARGIN ))
313 bPosEnabled = false;
314 bNegEnabled = false;
317 // enable/disable pos/neg fields
318 m_pBxPositive->Enable( bPosEnabled );
319 m_pBxNegative->Enable( bNegEnabled );
320 if( bShowRange )
322 m_pEdRangePositive->Enable( bPosEnabled );
323 m_pIbRangePositive->Enable( bPosEnabled );
324 m_pEdRangeNegative->Enable( bNegEnabled );
325 m_pIbRangeNegative->Enable( bNegEnabled );
327 else
329 m_pMfPositive->Enable( bPosEnabled );
330 m_pMfNegative->Enable( bNegEnabled );
333 m_pCbSyncPosNeg->Enable( !bOneParameterCategory && ( bPosEnabled || bNegEnabled ));
335 // mark invalid entries in the range fields
336 if( bShowRange && ! m_bHasInternalDataProvider )
338 isRangeFieldContentValid( *m_pEdRangePositive );
339 isRangeFieldContentValid( *m_pEdRangeNegative );
343 IMPL_LINK_NOARG( ErrorBarResources, CategoryChosen )
345 m_bErrorKindUnique = true;
346 SvxChartKindError eOldError = m_eErrorKind;
348 if( m_pRbNone->IsChecked())
349 m_eErrorKind = CHERROR_NONE;
350 else if( m_pRbConst->IsChecked())
351 m_eErrorKind = CHERROR_CONST;
352 else if( m_pRbPercent->IsChecked())
353 m_eErrorKind = CHERROR_PERCENT;
354 else if( m_pRbRange->IsChecked())
355 m_eErrorKind = CHERROR_RANGE;
356 else if( m_pRbFunction->IsChecked())
358 if( m_pLbFunction->GetSelectEntryCount() == 1 )
360 switch( m_pLbFunction->GetSelectEntryPos())
362 case CHART_LB_FUNCTION_STD_ERROR:
363 m_eErrorKind = CHERROR_STDERROR; break;
364 case CHART_LB_FUNCTION_STD_DEV:
365 m_eErrorKind = CHERROR_SIGMA; break;
366 case CHART_LB_FUNCTION_VARIANCE:
367 m_eErrorKind = CHERROR_VARIANT; break;
368 case CHART_LB_FUNCTION_ERROR_MARGIN:
369 m_eErrorKind = CHERROR_BIGERROR; break;
370 default:
371 m_bErrorKindUnique = false;
374 else
375 m_bErrorKindUnique = false;
377 else
379 OSL_FAIL( "Unknown category chosen" );
380 m_bErrorKindUnique = false;
383 // changed to range
384 if( m_eErrorKind == CHERROR_RANGE &&
385 eOldError != CHERROR_RANGE )
387 m_pCbSyncPosNeg->Check(
388 (!m_pEdRangePositive->GetText().isEmpty()) &&
389 m_pEdRangePositive->GetText() == m_pEdRangeNegative->GetText());
391 // changed from range
392 else if( m_eErrorKind != CHERROR_RANGE &&
393 eOldError == CHERROR_RANGE )
395 m_pCbSyncPosNeg->Check( m_pMfPositive->GetValue() == m_pMfNegative->GetValue());
398 UpdateControlStates();
399 return 0;
402 IMPL_LINK_NOARG(ErrorBarResources, SynchronizePosAndNeg)
404 UpdateControlStates();
405 PosValueChanged( 0 );
406 return 0;
409 IMPL_LINK_NOARG(ErrorBarResources, PosValueChanged)
411 if( m_pCbSyncPosNeg->IsChecked())
413 if( m_pRbRange->IsChecked())
415 m_pEdRangeNegative->SetText( m_pEdRangePositive->GetText());
416 m_bRangeNegUnique = m_bRangePosUnique;
418 else
419 m_pMfNegative->SetValue( m_pMfPositive->GetValue());
422 return 0;
425 IMPL_LINK_NOARG(ErrorBarResources, IndicatorChanged)
427 m_bIndicatorUnique = true;
428 if( m_pRbBoth->IsChecked())
429 m_eIndicate = CHINDICATE_BOTH;
430 else if( m_pRbPositive->IsChecked())
431 m_eIndicate = CHINDICATE_UP;
432 else if( m_pRbNegative->IsChecked())
433 m_eIndicate = CHINDICATE_DOWN;
434 else
435 m_bIndicatorUnique = false;
437 UpdateControlStates();
438 return 0;
441 IMPL_LINK( ErrorBarResources, ChooseRange, PushButton*, pButton )
443 OSL_ASSERT( m_apRangeSelectionHelper.get());
444 if( ! m_apRangeSelectionHelper.get())
445 return 0;
446 OSL_ASSERT( m_pCurrentRangeChoosingField == nullptr );
448 OUString aUIString;
450 if( pButton == m_pIbRangePositive )
452 m_pCurrentRangeChoosingField = m_pEdRangePositive;
453 aUIString = m_pUIStringPos->GetText();
455 else
457 m_pCurrentRangeChoosingField = m_pEdRangeNegative;
458 aUIString = m_pUIStringNeg->GetText();
461 assert( m_pParentDialog );
462 if( m_pParentDialog )
464 lcl_enableRangeChoosing( true, m_pParentDialog );
465 m_apRangeSelectionHelper->chooseRange(
466 m_pCurrentRangeChoosingField->GetText(),
467 aUIString, *this );
469 else
470 m_pCurrentRangeChoosingField = 0;
472 return 0;
475 IMPL_LINK( ErrorBarResources, RangeChanged, Edit *, pEdit )
477 if( pEdit == m_pEdRangePositive )
479 m_bRangePosUnique = true;
480 PosValueChanged( 0 );
482 else
484 m_bRangeNegUnique = true;
487 isRangeFieldContentValid( *pEdit );
489 return 0;
492 void ErrorBarResources::Reset(const SfxItemSet& rInAttrs)
494 const SfxPoolItem *pPoolItem = NULL;
495 SfxItemState aState = SfxItemState::UNKNOWN;
497 // category
498 m_eErrorKind = CHERROR_NONE;
499 aState = rInAttrs.GetItemState( SCHATTR_STAT_KIND_ERROR, true, &pPoolItem );
500 m_bErrorKindUnique = ( aState != SfxItemState::DONTCARE );
502 if( aState == SfxItemState::SET )
503 m_eErrorKind = static_cast<const SvxChartKindErrorItem*>(pPoolItem)->GetValue();
505 m_pLbFunction->SelectEntryPos( lcl_getLbEntryPosByErrorKind( m_eErrorKind ));
507 if( m_bErrorKindUnique )
509 switch( m_eErrorKind )
511 case CHERROR_NONE:
512 m_pRbNone->Check();
513 break;
514 case CHERROR_PERCENT:
515 m_pRbPercent->Check();
516 break;
517 case CHERROR_CONST:
518 m_pRbConst->Check();
519 break;
520 case CHERROR_STDERROR:
521 case CHERROR_VARIANT:
522 case CHERROR_SIGMA:
523 case CHERROR_BIGERROR:
524 m_pRbFunction->Check();
525 break;
526 case CHERROR_RANGE:
527 m_pRbRange->Check();
528 break;
531 else
533 m_pRbNone->Check( false );
534 m_pRbConst->Check( false );
535 m_pRbPercent->Check( false );
536 m_pRbFunction->Check( false );
539 // parameters
540 aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTPLUS, true, &pPoolItem );
541 m_bPlusUnique = ( aState != SfxItemState::DONTCARE );
542 if( aState == SfxItemState::SET )
544 m_fPlusValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
547 aState = rInAttrs.GetItemState( SCHATTR_STAT_CONSTMINUS, true, &pPoolItem );
548 m_bMinusUnique = ( aState != SfxItemState::DONTCARE );
549 if( aState == SfxItemState::SET )
551 m_fMinusValue = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
553 if( m_eErrorKind != CHERROR_RANGE &&
554 m_fPlusValue == m_fMinusValue )
555 m_pCbSyncPosNeg->Check();
558 // indicator
559 aState = rInAttrs.GetItemState( SCHATTR_STAT_INDICATE, true, &pPoolItem );
560 m_bIndicatorUnique = ( aState != SfxItemState::DONTCARE );
561 if( aState == SfxItemState::SET)
562 m_eIndicate = static_cast<const SvxChartIndicateItem *>(pPoolItem)->GetValue();
564 if( m_bIndicatorUnique )
566 switch( m_eIndicate )
568 case CHINDICATE_NONE :
569 // no longer used, use both as default
570 m_eIndicate = CHINDICATE_BOTH;
571 // fall-through intended to BOTH
572 case CHINDICATE_BOTH :
573 m_pRbBoth->Check(); break;
574 case CHINDICATE_UP :
575 m_pRbPositive->Check(); break;
576 case CHINDICATE_DOWN :
577 m_pRbNegative->Check(); break;
580 else
582 m_pRbBoth->Check( false );
583 m_pRbPositive->Check( false );
584 m_pRbNegative->Check( false );
587 // ranges
588 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_POS, true, &pPoolItem );
589 m_bRangePosUnique = ( aState != SfxItemState::DONTCARE );
590 if( aState == SfxItemState::SET )
592 OUString sRangePositive = (static_cast< const SfxStringItem * >( pPoolItem ))->GetValue();
593 m_pEdRangePositive->SetText( sRangePositive );
596 aState = rInAttrs.GetItemState( SCHATTR_STAT_RANGE_NEG, true, &pPoolItem );
597 m_bRangeNegUnique = ( aState != SfxItemState::DONTCARE );
598 if( aState == SfxItemState::SET )
600 OUString sRangeNegative = (static_cast< const SfxStringItem * >( pPoolItem ))->GetValue();
601 m_pEdRangeNegative->SetText( sRangeNegative );
602 if( m_eErrorKind == CHERROR_RANGE &&
603 !sRangeNegative.isEmpty() &&
604 sRangeNegative == m_pEdRangePositive->GetText() )
605 m_pCbSyncPosNeg->Check();
608 UpdateControlStates();
611 bool ErrorBarResources::FillItemSet(SfxItemSet& rOutAttrs) const
613 if( m_bErrorKindUnique )
614 rOutAttrs.Put( SvxChartKindErrorItem( m_eErrorKind, SCHATTR_STAT_KIND_ERROR ));
615 if( m_bIndicatorUnique )
616 rOutAttrs.Put( SvxChartIndicateItem( m_eIndicate, SCHATTR_STAT_INDICATE ));
618 if( m_bErrorKindUnique )
620 if( m_eErrorKind == CHERROR_RANGE )
622 OUString aPosRange;
623 OUString aNegRange;
624 if( m_bHasInternalDataProvider )
626 // the strings aPosRange/aNegRange have to be set to a non-empty
627 // arbitrary string to generate error-bar sequences
628 aPosRange = "x";
629 aNegRange = aPosRange;
631 else
633 aPosRange = m_pEdRangePositive->GetText();
634 if( m_pCbSyncPosNeg->IsChecked())
635 aNegRange = aPosRange;
636 else
637 aNegRange = m_pEdRangeNegative->GetText();
640 if( m_bRangePosUnique )
641 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_POS, aPosRange ));
642 if( m_bRangeNegUnique )
643 rOutAttrs.Put( SfxStringItem( SCHATTR_STAT_RANGE_NEG, aNegRange ));
645 else if( m_eErrorKind == CHERROR_CONST ||
646 m_eErrorKind == CHERROR_PERCENT ||
647 m_eErrorKind == CHERROR_BIGERROR )
649 double fPosValue = static_cast< double >( m_pMfPositive->GetValue()) /
650 pow( 10.0, m_pMfPositive->GetDecimalDigits());
651 double fNegValue = 0.0;
653 if( m_pCbSyncPosNeg->IsChecked())
654 fNegValue = fPosValue;
655 else
656 fNegValue = static_cast< double >( m_pMfNegative->GetValue()) /
657 pow( 10.0, m_pMfNegative->GetDecimalDigits());
659 rOutAttrs.Put( SvxDoubleItem( fPosValue, SCHATTR_STAT_CONSTPLUS ));
660 rOutAttrs.Put( SvxDoubleItem( fNegValue, SCHATTR_STAT_CONSTMINUS ));
664 rOutAttrs.Put( SfxBoolItem( SCHATTR_STAT_ERRORBAR_TYPE , m_eErrorBarType == ERROR_BAR_Y ));
666 return true;
669 void ErrorBarResources::FillValueSets()
671 if( m_eErrorBarType == ERROR_BAR_Y )
673 m_pFiNegative->SetImage( Image( SchResId( BMP_INDICATE_DOWN ) ) );
674 m_pFiPositive->SetImage( Image( SchResId( BMP_INDICATE_UP ) ) );
675 m_pFiBoth->SetImage( Image( SchResId( BMP_INDICATE_BOTH_VERTI ) ) );
677 else if( m_eErrorBarType == ERROR_BAR_X )
679 m_pFiNegative->SetImage( Image( SchResId( BMP_INDICATE_LEFT ) ) );
680 m_pFiPositive->SetImage( Image( SchResId( BMP_INDICATE_RIGHT ) ) );
681 m_pFiBoth->SetImage( Image( SchResId( BMP_INDICATE_BOTH_HORI ) ) );
685 void ErrorBarResources::listeningFinished(
686 const OUString & rNewRange )
688 OSL_ASSERT( m_apRangeSelectionHelper.get());
689 if( ! m_apRangeSelectionHelper.get())
690 return;
692 // rNewRange becomes invalid after removing the listener
693 OUString aRange( rNewRange );
695 // stop listening
696 m_apRangeSelectionHelper->stopRangeListening();
698 // change edit field
699 // if( m_pParentWindow )
700 // {
701 // m_pParentWindow->ToTop();
702 // m_pParentWindow->GrabFocus();
703 // }
705 if( m_pCurrentRangeChoosingField )
707 m_pCurrentRangeChoosingField->SetText( aRange );
708 m_pCurrentRangeChoosingField->GrabFocus();
709 PosValueChanged( 0 );
712 m_pCurrentRangeChoosingField = 0;
714 UpdateControlStates();
715 OSL_ASSERT( m_pParentDialog );
716 if( m_pParentDialog )
717 lcl_enableRangeChoosing( false, m_pParentDialog );
720 void ErrorBarResources::disposingRangeSelection()
722 OSL_ASSERT( m_apRangeSelectionHelper.get());
723 if( m_apRangeSelectionHelper.get())
724 m_apRangeSelectionHelper->stopRangeListening( false );
727 bool ErrorBarResources::isRangeFieldContentValid( Edit & rEdit )
729 OUString aRange( rEdit.GetText());
730 bool bIsValid = ( aRange.isEmpty() ) ||
731 ( m_apRangeSelectionHelper.get() &&
732 m_apRangeSelectionHelper->verifyCellRange( aRange ));
734 if( bIsValid || !rEdit.IsEnabled())
736 rEdit.SetControlForeground();
737 rEdit.SetControlBackground();
739 else
741 rEdit.SetControlBackground( RANGE_SELECTION_INVALID_RANGE_BACKGROUND_COLOR );
742 rEdit.SetControlForeground( RANGE_SELECTION_INVALID_RANGE_FOREGROUND_COLOR );
745 return bIsValid;
748 } //namespace chart
750 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */