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