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 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
|
/* -*- 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 <sal/config.h>
#include <ControllerCommandDispatch.hxx>
#include <ChartModel.hxx>
#include <Diagram.hxx>
#include <Axis.hxx>
#include <AxisHelper.hxx>
#include <TitleHelper.hxx>
#include <LegendHelper.hxx>
#include <ObjectIdentifier.hxx>
#include <ChartType.hxx>
#include <ChartController.hxx>
#include <RegressionCurveHelper.hxx>
#include <DataSeries.hxx>
#include <DataSeriesHelper.hxx>
#include <StatisticsHelper.hxx>
#include <ReferenceSizeProvider.hxx>
#include <RegressionCurveModel.hxx>
#include "ShapeController.hxx"
#include <CharacterProperties.hxx>
#include <vcl/svapp.hxx>
#include <sal/log.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/lok.hxx>
#include <sfx2/viewsh.hxx>
#include <sfx2/objsh.hxx>
#include <com/sun/star/chart2/XDataProviderAccess.hpp>
#include <com/sun/star/frame/status/FontHeight.hpp>
using namespace ::com::sun::star;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
namespace
{
uno::Any getPropertyIfSame(std::vector<Reference<beans::XPropertySet>>& xProperties,
const OUString& aPropName)
{
if (xProperties.size() < 1)
return {};
if (!xProperties[0])
return {};
uno::Any aValue = xProperties[0]->getPropertyValue(aPropName);
for (std::size_t i = 1; i < xProperties.size(); i++)
{
if (xProperties[i] && aValue != xProperties[i]->getPropertyValue(aPropName))
return {};
}
return aValue;
}
} // anonymous namespace
namespace chart
{
namespace impl
{
/// Constants for moving the series.
namespace {
bool const MOVE_SERIES_FORWARD = true;
bool const MOVE_SERIES_BACKWARD = false;
}
/** Represents the current state of the controller (needed for issue 63017).
You can set the state by calling update(). After this call the state is
preserved in this class until the next call to update().
This is useful, not to say necessary, for enabling and disabling of menu
entries (e.g. format>arrangement). As the status requests are sent very
frequently it would be impossible, from a performance point of view, to
query the current status every time directly at the model. So this class
serves as a cache for the state.
*/
struct ControllerState
{
ControllerState();
void update( const Reference< frame::XController > & xController,
const rtl::Reference<::chart::ChartModel> & xModel );
// -- State variables -------
bool bHasSelectedObject;
bool bIsPositionableObject;
bool bIsTextObject;
bool bIsDeleteableObjectSelected;
bool bIsFormateableObjectSelected;
// May the selected series be moved forward or backward (cf
// format>arrangement).
bool bMayMoveSeriesForward;
bool bMayMoveSeriesBackward;
// trendlines
bool bMayAddMenuTrendline;
bool bMayAddTrendline;
bool bMayAddTrendlineEquation;
bool bMayAddR2Value;
bool bMayAddMeanValue;
bool bMayAddXErrorBars;
bool bMayAddYErrorBars;
bool bMayDeleteTrendline;
bool bMayDeleteTrendlineEquation;
bool bMayDeleteR2Value;
bool bMayDeleteMeanValue;
bool bMayDeleteXErrorBars;
bool bMayDeleteYErrorBars;
bool bMayFormatTrendline;
bool bMayFormatTrendlineEquation;
bool bMayFormatMeanValue;
bool bMayFormatXErrorBars;
bool bMayFormatYErrorBars;
};
ControllerState::ControllerState() :
bHasSelectedObject( false ),
bIsPositionableObject( false ),
bIsTextObject(false),
bIsDeleteableObjectSelected(false),
bIsFormateableObjectSelected(false),
bMayMoveSeriesForward( false ),
bMayMoveSeriesBackward( false ),
bMayAddMenuTrendline( false ),
bMayAddTrendline( false ),
bMayAddTrendlineEquation( false ),
bMayAddR2Value( false ),
bMayAddMeanValue( false ),
bMayAddXErrorBars( false ),
bMayAddYErrorBars( false ),
bMayDeleteTrendline( false ),
bMayDeleteTrendlineEquation( false ),
bMayDeleteR2Value( false ),
bMayDeleteMeanValue( false ),
bMayDeleteXErrorBars( false ),
bMayDeleteYErrorBars( false ),
bMayFormatTrendline( false ),
bMayFormatTrendlineEquation( false ),
bMayFormatMeanValue( false ),
bMayFormatXErrorBars( false ),
bMayFormatYErrorBars( false )
{}
void ControllerState::update(
const Reference< frame::XController > & xController,
const rtl::Reference<::chart::ChartModel> & xModel )
{
Reference< view::XSelectionSupplier > xSelectionSupplier(
xController, uno::UNO_QUERY );
// Update ControllerState variables.
if( !xSelectionSupplier.is())
return;
uno::Any aSelObj( xSelectionSupplier->getSelection() );
ObjectIdentifier aSelOID( aSelObj );
const OUString& aSelObjCID( aSelOID.getObjectCID() );
bHasSelectedObject = aSelOID.isValid();
ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
bIsPositionableObject = (aObjectType != OBJECTTYPE_DATA_POINT) && aSelOID.isDragableObject();
bIsTextObject = aObjectType == OBJECTTYPE_TITLE;
rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
bIsFormateableObjectSelected = bHasSelectedObject && aSelOID.isAutoGeneratedObject();
if( aObjectType==OBJECTTYPE_DIAGRAM || aObjectType==OBJECTTYPE_DIAGRAM_WALL || aObjectType==OBJECTTYPE_DIAGRAM_FLOOR )
bIsFormateableObjectSelected = xDiagram->isSupportingFloorAndWall();
rtl::Reference< DataSeries > xGivenDataSeries =
ObjectIdentifier::getDataSeriesForCID(
aSelObjCID, xModel );
bIsDeleteableObjectSelected = ChartController::isObjectDeleteable( aSelObj );
bMayMoveSeriesForward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram && xDiagram->isSeriesMoveable(
xGivenDataSeries,
MOVE_SERIES_FORWARD );
bMayMoveSeriesBackward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram && xDiagram->isSeriesMoveable(
xGivenDataSeries,
MOVE_SERIES_BACKWARD );
bMayAddMenuTrendline = false;
bMayAddTrendline = false;
bMayAddTrendlineEquation = false;
bMayAddR2Value = false;
bMayAddMeanValue = false;
bMayAddXErrorBars = false;
bMayAddYErrorBars = false;
bMayDeleteTrendline = false;
bMayDeleteTrendlineEquation = false;
bMayDeleteR2Value = false;
bMayDeleteMeanValue = false;
bMayDeleteXErrorBars = false;
bMayDeleteYErrorBars = false;
bMayFormatTrendline = false;
bMayFormatTrendlineEquation = false;
bMayFormatMeanValue = false;
bMayFormatXErrorBars = false;
bMayFormatYErrorBars = false;
if( !bHasSelectedObject )
return;
if( xGivenDataSeries.is())
{
bMayAddMenuTrendline = true;
sal_Int32 nDimensionCount = xDiagram->getDimension();
rtl::Reference< ::chart::ChartType > xFirstChartType(
DataSeriesHelper::getChartTypeOfSeries( xGivenDataSeries, xDiagram ));
// trend lines/mean value line
if( (aObjectType == OBJECTTYPE_DATA_SERIES || aObjectType == OBJECTTYPE_DATA_POINT)
&& xFirstChartType.is() ? xFirstChartType->isSupportingRegressionProperties(nDimensionCount) : true)
{
// Trendline
bMayAddTrendline = true;
// Mean Value
bMayFormatMeanValue = bMayDeleteMeanValue = RegressionCurveHelper::hasMeanValueLine( xGivenDataSeries );
bMayAddMeanValue = ! bMayDeleteMeanValue;
}
// error bars
if( (aObjectType == OBJECTTYPE_DATA_SERIES || aObjectType == OBJECTTYPE_DATA_POINT)
&& xFirstChartType.is() ? xFirstChartType->isSupportingStatisticProperties(nDimensionCount) : true)
{
bMayFormatXErrorBars = bMayDeleteXErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries, false );
bMayAddXErrorBars = ! bMayDeleteXErrorBars;
bMayFormatYErrorBars = bMayDeleteYErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries );
bMayAddYErrorBars = ! bMayDeleteYErrorBars;
}
}
if( aObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
bMayFormatMeanValue = true;
if( aObjectType == OBJECTTYPE_DATA_ERRORS_X)
bMayFormatXErrorBars = true;
if( aObjectType == OBJECTTYPE_DATA_ERRORS_Y )
bMayFormatYErrorBars = true;
if( aObjectType == OBJECTTYPE_DATA_CURVE )
{
bMayFormatTrendline = true;
bMayDeleteTrendline = true;
rtl::Reference< RegressionCurveModel > xRegCurve(
dynamic_cast<RegressionCurveModel*>(ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ).get()) );
// Trendline Equation
bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve );
bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation;
bMayAddR2Value = RegressionCurveHelper::MayHaveCorrelationCoefficient( xRegCurve ) && bMayAddTrendlineEquation;
}
else if( aObjectType == OBJECTTYPE_DATA_CURVE_EQUATION )
{
bMayFormatTrendlineEquation = true;
bool bHasR2Value = false;
bool bMayHaveR2 = true;
try
{
uno::Reference< beans::XPropertySet > xEquationProperties =
ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel );
if( xEquationProperties.is() )
{
xEquationProperties->getPropertyValue( u"ShowCorrelationCoefficient"_ustr ) >>= bHasR2Value;
xEquationProperties->getPropertyValue( u"MayHaveCorrelationCoefficient"_ustr ) >>= bMayHaveR2;
}
}
catch(const uno::RuntimeException&)
{
TOOLS_WARN_EXCEPTION("chart2", "" );
}
bMayAddR2Value = !bHasR2Value && bMayHaveR2;
bMayDeleteR2Value = bHasR2Value;
}
}
/** Represents the current state of the model.
You can set the state by calling update(). After this call the state is
preserved in this class until the next call to update().
This is useful, not to say necessary, for enabling and disabling of menu
entries and toolbar icons. As the status requests are sent very frequently
it would be impossible, from a performance point of view, to query the
current status every time directly at the model. So this class serves as a
cache for the state.
*/
struct ModelState
{
ModelState();
void update( const rtl::Reference<::chart::ChartModel> & xModel );
bool HasAnyAxis() const;
bool HasAnyGrid() const;
bool HasAnyTitle() const;
bool bIsReadOnly;
bool bIsThreeD;
bool bHasOwnData;
bool bHasDataFromPivotTable;
bool bHasMainTitle;
bool bHasSubTitle;
bool bHasXAxisTitle;
bool bHasYAxisTitle;
bool bHasZAxisTitle;
bool bHasSecondaryXAxisTitle;
bool bHasSecondaryYAxisTitle;
bool bHasXAxis;
bool bHasYAxis;
bool bHasZAxis;
bool bHasAAxis;
bool bHasBAxis;
bool bHasMainXGrid;
bool bHasMainYGrid;
bool bHasMainZGrid;
bool bHasHelpXGrid;
bool bHasHelpYGrid;
bool bHasHelpZGrid;
bool bHasAutoScaledText;
bool bHasLegend;
bool bHasWall;
bool bHasFloor;
bool bSupportsStatistics;
bool bSupportsAxes;
bool bDataTable = false;
};
ModelState::ModelState() :
bIsReadOnly(true),
bIsThreeD(false),
bHasOwnData(false),
bHasDataFromPivotTable(false),
bHasMainTitle(false),
bHasSubTitle(false),
bHasXAxisTitle(false),
bHasYAxisTitle(false),
bHasZAxisTitle(false),
bHasSecondaryXAxisTitle(false),
bHasSecondaryYAxisTitle(false),
bHasXAxis(false),
bHasYAxis(false),
bHasZAxis(false),
bHasAAxis(false),
bHasBAxis(false),
bHasMainXGrid(false),
bHasMainYGrid(false),
bHasMainZGrid(false),
bHasHelpXGrid(false),
bHasHelpYGrid(false),
bHasHelpZGrid(false),
bHasAutoScaledText(false),
bHasLegend(false),
bHasWall(false),
bHasFloor(false),
bSupportsStatistics(false),
bSupportsAxes(false)
{}
void ModelState::update( const rtl::Reference<::chart::ChartModel> & xModel )
{
rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
bIsReadOnly = xModel->isReadonly();
sal_Int32 nDimensionCount = 0;
if (xDiagram)
nDimensionCount = xDiagram->getDimension();
rtl::Reference<ChartType> xFirstChartType;
if (xDiagram)
xFirstChartType = xDiagram->getChartTypeByIndex( 0 );
bSupportsStatistics = xFirstChartType.is() ? xFirstChartType->isSupportingStatisticProperties(nDimensionCount) : true;
bSupportsAxes = xFirstChartType.is() ? xFirstChartType->isSupportingMainAxis(nDimensionCount, 0) : true;
bIsThreeD = (nDimensionCount == 3);
if (xModel.is())
{
bHasOwnData = xModel->hasInternalDataProvider();
bHasDataFromPivotTable = !bHasOwnData && xModel->isDataFromPivotTable();
}
bHasMainTitle = TitleHelper::getTitle( TitleHelper::MAIN_TITLE, xModel ).is();
bHasSubTitle = TitleHelper::getTitle( TitleHelper::SUB_TITLE, xModel ).is();
bHasXAxisTitle = TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, xModel ).is();
bHasYAxisTitle = TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, xModel ).is();
bHasZAxisTitle = TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE, xModel ).is();
bHasSecondaryXAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xModel ).is();
bHasSecondaryYAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xModel ).is();
bHasXAxis = bSupportsAxes && AxisHelper::getAxis( 0, true, xDiagram ).is();
bHasYAxis = bSupportsAxes && AxisHelper::getAxis( 1, true, xDiagram ).is();
bHasZAxis = bSupportsAxes && AxisHelper::getAxis( 2, true, xDiagram ).is();
bHasAAxis = bSupportsAxes && AxisHelper::getAxis( 0, false, xDiagram ).is();
bHasBAxis = bSupportsAxes && AxisHelper::getAxis( 1, false, xDiagram ).is();
bHasMainXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, true, xDiagram );
bHasMainYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, true, xDiagram );
bHasMainZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, true, xDiagram );
bHasHelpXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, false, xDiagram );
bHasHelpYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, false, xDiagram );
bHasHelpZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, false, xDiagram );
bHasAutoScaledText =
(ReferenceSizeProvider::getAutoResizeState( xModel ) ==
ReferenceSizeProvider::AUTO_RESIZE_YES);
bHasLegend = LegendHelper::hasLegend( xDiagram );
bHasWall = xDiagram && xDiagram->isSupportingFloorAndWall();
bHasFloor = bHasWall && bIsThreeD;
bDataTable = xDiagram.is() && xDiagram->getDataTable().is();
}
bool ModelState::HasAnyAxis() const
{
return bHasXAxis || bHasYAxis || bHasZAxis || bHasAAxis || bHasBAxis;
}
bool ModelState::HasAnyGrid() const
{
return bHasMainXGrid || bHasMainYGrid || bHasMainZGrid ||
bHasHelpXGrid || bHasHelpYGrid || bHasHelpZGrid;
}
bool ModelState::HasAnyTitle() const
{
return bHasMainTitle || bHasSubTitle || bHasXAxisTitle || bHasYAxisTitle || bHasZAxisTitle || bHasSecondaryXAxisTitle || bHasSecondaryYAxisTitle;
}
} // namespace impl
ControllerCommandDispatch::ControllerCommandDispatch(
const Reference< uno::XComponentContext > & xContext,
ChartController* pController, CommandDispatchContainer* pContainer ) :
impl::ControllerCommandDispatch_Base( xContext ),
m_xChartController( pController ),
m_xSelectionSupplier( Reference< view::XSelectionSupplier >( pController ) ),
m_xDispatch( Reference< frame::XDispatch >( pController ) ),
m_apModelState( new impl::ModelState() ),
m_apControllerState( new impl::ControllerState() ),
m_pDispatchContainer( pContainer )
{
}
ControllerCommandDispatch::~ControllerCommandDispatch()
{
}
void ControllerCommandDispatch::initialize()
{
if( !m_xChartController.is())
return;
rtl::Reference<::chart::ChartModel> xModel( m_xChartController->getChartModel());
OSL_ASSERT( xModel.is());
if( xModel.is())
xModel->addModifyListener( this );
// Listen selection modifications (Arrangement feature - issue 63017).
if( m_xSelectionSupplier.is() )
m_xSelectionSupplier->addSelectionChangeListener( this );
if( m_apModelState && xModel.is())
m_apModelState->update( xModel );
if( m_apControllerState && xModel.is())
m_apControllerState->update( m_xChartController, xModel );
updateCommandAvailability();
}
void ControllerCommandDispatch::fireStatusEventForURLImpl(
const OUString & rURL,
const Reference< frame::XStatusListener > & xSingleListener )
{
std::map< OUString, uno::Any >::const_iterator aArgIt( m_aCommandArguments.find( rURL ));
if( aArgIt != m_aCommandArguments.end())
fireStatusEventForURL( rURL, aArgIt->second, commandAvailable( rURL ), xSingleListener );
else
fireStatusEventForURL( rURL, uno::Any(), commandAvailable( rURL ), xSingleListener );
}
void ControllerCommandDispatch::updateCommandAvailability()
{
bool bModelStateIsValid = (m_apModelState != nullptr);
bool bControllerStateIsValid = (m_apControllerState != nullptr);
// Model and controller states exist.
OSL_ASSERT( bModelStateIsValid );
OSL_ASSERT( bControllerStateIsValid );
// read-only
bool bIsWritable = bModelStateIsValid && (! m_apModelState->bIsReadOnly);
bool bShapeContext = m_xChartController.is() && m_xChartController->isShapeContext();
bool bIsTextEdit = m_xChartController.is() && m_xChartController->IsTextEdit();
bool bEnableDataTableDialog = false;
bool bCanCreateDataProvider = false;
if ( m_xChartController.is() )
{
Reference< beans::XPropertySet > xProps( m_xChartController->getModel(), uno::UNO_QUERY );
if ( xProps.is() )
{
try
{
xProps->getPropertyValue(u"EnableDataTableDialog"_ustr) >>= bEnableDataTableDialog;
}
catch( const uno::Exception& )
{
TOOLS_WARN_EXCEPTION("chart2", "" );
}
}
rtl::Reference< ChartModel > xChartModel = m_xChartController->getChartModel();
OSL_ENSURE(xChartModel.is(), "Invalid XChartDocument");
if ( xChartModel.is() )
{
css::uno::Reference< css::chart2::XDataProviderAccess > xCreatorDoc(xChartModel->getParent(), uno::UNO_QUERY);
bCanCreateDataProvider = xCreatorDoc.is();
}
}
// edit commands
m_aCommandAvailability[ u".uno:Cut"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsDeleteableObjectSelected;
m_aCommandAvailability[ u".uno:Copy"_ustr ] = bControllerStateIsValid && m_apControllerState->bHasSelectedObject;
m_aCommandAvailability[ u".uno:Paste"_ustr ] = bIsWritable;
// toolbar commands
m_aCommandAvailability[ u".uno:ToggleGridHorizontal"_ustr ] = bIsWritable;
m_aCommandArguments[ u".uno:ToggleGridHorizontal"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasMainYGrid;
m_aCommandAvailability[ u".uno:ToggleGridVertical"_ustr ] = bIsWritable;
m_aCommandArguments[ u".uno:ToggleGridVertical"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasMainXGrid;
m_aCommandAvailability[ u".uno:ToggleLegend"_ustr ] = bIsWritable;
m_aCommandArguments[ u".uno:ToggleLegend"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasLegend;
m_aCommandAvailability[ u".uno:NewArrangement"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:Update"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DefaultColors"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:BarWidth"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:NumberOfLines"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:ArrangeRow"_ustr ] =
bShapeContext || ( bIsWritable && bControllerStateIsValid && ( m_apControllerState->bMayMoveSeriesForward || m_apControllerState->bMayMoveSeriesBackward ) );
// insert objects
m_aCommandAvailability[ u".uno:InsertTitles"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuTitles"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertLegend"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuLegend"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DeleteLegend"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertMenuDataLabels"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertRemoveAxes"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuAxes"_ustr ] = bIsWritable && m_apModelState->bSupportsAxes;
m_aCommandAvailability[ u".uno:InsertMenuGrids"_ustr ] = bIsWritable && m_apModelState->bSupportsAxes;
m_aCommandAvailability[ u".uno:InsertMenuTrendlines"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics && bControllerStateIsValid && m_apControllerState->bMayAddMenuTrendline;
m_aCommandAvailability[ u".uno:InsertMenuMeanValues"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics;
m_aCommandAvailability[ u".uno:InsertMenuXErrorBars"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics;
m_aCommandAvailability[ u".uno:InsertMenuYErrorBars"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics;
m_aCommandAvailability[ u".uno:InsertSymbol"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsTextObject;
m_aCommandAvailability[ u".uno:InsertMenuDataTable"_ustr ] = bIsWritable;
// format objects
bool bFormatObjectAvailable = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsFormateableObjectSelected;
m_aCommandAvailability[ u".uno:FormatSelection"_ustr ] = bFormatObjectAvailable && !bIsTextEdit;
m_aCommandAvailability[ u".uno:FontDialog"_ustr ] = (bShapeContext ? isShapeControllerCommandAvailable(u".uno:FontDialog"_ustr) :
bFormatObjectAvailable) && bIsTextEdit;
m_aCommandAvailability[ u".uno:FormatAxis"_ustr ] = bFormatObjectAvailable;
m_aCommandAvailability[ u".uno:FormatTitle"_ustr ] = bFormatObjectAvailable && !bIsTextEdit;
m_aCommandAvailability[ u".uno:FormatDataSeries"_ustr ] = bFormatObjectAvailable;
m_aCommandAvailability[ u".uno:FormatDataPoint"_ustr ] = bFormatObjectAvailable;
m_aCommandAvailability[ u".uno:FormatDataLabels"_ustr ] = bFormatObjectAvailable;
m_aCommandAvailability[ u".uno:FormatDataLabel"_ustr ] = bFormatObjectAvailable;
m_aCommandAvailability[ u".uno:FormatXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatXErrorBars;
m_aCommandAvailability[ u".uno:FormatYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatYErrorBars;
m_aCommandAvailability[ u".uno:FormatMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatMeanValue;
m_aCommandAvailability[ u".uno:FormatTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendline;
m_aCommandAvailability[ u".uno:FormatTrendlineEquation"_ustr ] = bFormatObjectAvailable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendlineEquation;
m_aCommandAvailability[ u".uno:FormatStockLoss"_ustr ] = bFormatObjectAvailable;
m_aCommandAvailability[ u".uno:FormatStockGain"_ustr ] = bFormatObjectAvailable;
if (comphelper::LibreOfficeKit::isActive())
{
m_aCommandAvailability[u".uno:FillColor"_ustr] = bFormatObjectAvailable;
m_aCommandAvailability[u".uno:XLineColor"_ustr] = bFormatObjectAvailable;
m_aCommandAvailability[u".uno:LineWidth"_ustr] = bFormatObjectAvailable;
m_aCommandAvailability[u".uno:FillGradient"_ustr] = bFormatObjectAvailable;
}
m_aCommandAvailability[ u".uno:DiagramType"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:Legend"_ustr ] = bIsWritable && m_apModelState->bHasLegend;
m_aCommandAvailability[ u".uno:DiagramWall"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasWall;
m_aCommandAvailability[ u".uno:DiagramArea"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:TransformDialog"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bHasSelectedObject && m_apControllerState->bIsPositionableObject;
// 3d commands
m_aCommandAvailability[ u".uno:View3D"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bIsThreeD;
m_aCommandAvailability[ u".uno:DiagramFloor"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasFloor;
//some more format commands with different ui text
m_aCommandAvailability[ u".uno:FormatWall"_ustr ] = m_aCommandAvailability[ u".uno:DiagramWall"_ustr ];
m_aCommandAvailability[ u".uno:FormatFloor"_ustr ] = m_aCommandAvailability[ u".uno:DiagramFloor"_ustr ];
m_aCommandAvailability[ u".uno:FormatChartArea"_ustr ] = m_aCommandAvailability[ u".uno:DiagramArea"_ustr ];
m_aCommandAvailability[ u".uno:FormatLegend"_ustr ] = m_aCommandAvailability[ u".uno:Legend"_ustr ];
// depending on own data and ability to create new data provider
m_aCommandAvailability[u".uno:DataRanges"_ustr] = bIsWritable && bModelStateIsValid && !m_apModelState->bHasDataFromPivotTable
&& ((m_apModelState->bHasOwnData && bCanCreateDataProvider) || !m_apModelState->bHasOwnData);
m_aCommandAvailability[ u".uno:DiagramData"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData && bEnableDataTableDialog;
// titles
m_aCommandAvailability[ u".uno:MainTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainTitle;
m_aCommandAvailability[ u".uno:SubTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSubTitle;
m_aCommandAvailability[ u".uno:XTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxisTitle;
m_aCommandAvailability[ u".uno:YTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxisTitle;
m_aCommandAvailability[ u".uno:ZTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxisTitle;
m_aCommandAvailability[ u".uno:SecondaryXTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryXAxisTitle;
m_aCommandAvailability[ u".uno:SecondaryYTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryYAxisTitle;
m_aCommandAvailability[ u".uno:AllTitles"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyTitle();
// text
m_aCommandAvailability[ u".uno:ScaleText"_ustr ] = bIsWritable && bModelStateIsValid ;
m_aCommandArguments[ u".uno:ScaleText"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasAutoScaledText;
bool bTitleIsInEditMode = false;
try
{
OUString aObjectCID2 = m_xChartController->getSelectionMember().getSelectedCID();
if (!aObjectCID2.isEmpty())
if (ObjectIdentifier::getObjectType(aObjectCID2) == OBJECTTYPE_TITLE)
if (m_xChartController->GetDrawViewWrapper())
if (m_xChartController->GetDrawViewWrapper()->GetTextEditOutlinerView())
bTitleIsInEditMode = true;
}
catch (const uno::Exception&) { TOOLS_WARN_EXCEPTION("chart2", ""); }
bool bEnableUnoCommands = bIsWritable && bModelStateIsValid && !bTitleIsInEditMode;
m_aCommandAvailability[u".uno:Bold"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Strikeout"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:CharFontName"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:FontHeight"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Italic"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Underline"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Shadowed"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Color"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:FontColor"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Grow"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Shrink"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:SuperScript"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:SubScript"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:Spacing"_ustr] = bEnableUnoCommands;
m_aCommandAvailability[u".uno:ResetAttributes"_ustr] = bEnableUnoCommands;
if (!bTitleIsInEditMode)
{
// at default they are not filled in the sidebar
m_aCommandArguments[u".uno:CharFontName"_ustr] <<= false;
m_aCommandArguments[u".uno:FontHeight"_ustr] <<= false;
m_aCommandArguments[u".uno:Bold"_ustr] <<= false;
m_aCommandArguments[u".uno:Strikeout"_ustr] <<= false;
m_aCommandArguments[u".uno:Italic"_ustr] <<= false;
m_aCommandArguments[u".uno:Underline"_ustr] <<= false;
m_aCommandArguments[u".uno:Shadowed"_ustr] <<= false;
m_aCommandArguments[u".uno:Color"_ustr] <<= false;
m_aCommandArguments[u".uno:FontColor"_ustr] <<= false;
m_aCommandArguments[u".uno:SuperScript"_ustr] <<= false;
m_aCommandArguments[u".uno:SubScript"_ustr] <<= false;
m_aCommandArguments[u".uno:Spacing"_ustr] <<= false;
m_aCommandArguments[u".uno:ResetAttributes"_ustr] <<= false;
}
// They are filled based on the text properties.. if there are only 1
// but only those properties that are true for the whole text
try
{
// if title is selected, and in edit mode, then the font panel should be disabled
// enable the uno commands only if the title is not in edit mode
// Todo: enable font panel here if the panel will be able to handle edited title.
OUString aObjectCID = m_xChartController->getSelectionMember().getSelectedCID();
if (!aObjectCID.isEmpty() && !bTitleIsInEditMode)
{
// If the selected is not title, then we should check the text properties..
// or the selected text properties?
std::vector<Reference<beans::XPropertySet>> xProperties;
xProperties.emplace(xProperties.end(),
ObjectIdentifier::getObjectPropertySet(
aObjectCID, m_xChartController->getChartModel()));
if (ObjectIdentifier::getObjectType(aObjectCID) == OBJECTTYPE_TITLE)
{
Reference<chart2::XTitle> xTitle(xProperties[0], uno::UNO_QUERY);
if (xTitle.is())
{
const Sequence<Reference<chart2::XFormattedString>> aStrings(xTitle->getText());
xProperties.pop_back();
for (const auto& aString : aStrings)
{
Reference<beans::XPropertySet> xTitlePropSet(aString, uno::UNO_QUERY);
xProperties.push_back(xTitlePropSet);
}
}
}
Reference<beans::XMultiPropertySet> aMObjProps(xProperties[0], uno::UNO_QUERY);
if (aMObjProps)
{
awt::FontDescriptor aFont
= CharacterProperties::createFontDescriptorFromPropertySet(aMObjProps);
if (!aFont.Name.isEmpty())
{
if (getPropertyIfSame(xProperties, u"CharFontName"_ustr).hasValue())
{
m_aCommandArguments[u".uno:CharFontName"_ustr] <<= aFont;
}
}
}
if (frame::status::FontHeight aFontHeight;
getPropertyIfSame(xProperties, u"CharHeight"_ustr) >>= aFontHeight.Height)
{
// another type is needed here, so
m_aCommandArguments[u".uno:FontHeight"_ustr] <<= aFontHeight;
}
if (float nFontWeight;
getPropertyIfSame(xProperties, u"CharWeight"_ustr) >>= nFontWeight)
{
bool bFontWeight = (nFontWeight > 100.0);
m_aCommandArguments[u".uno:Bold"_ustr] <<= bFontWeight;
}
if (awt::FontSlant nFontItalic;
getPropertyIfSame(xProperties, u"CharPosture"_ustr) >>= nFontItalic)
{
bool bItalic = (nFontItalic == awt::FontSlant_ITALIC);
m_aCommandArguments[u".uno:Italic"_ustr] <<= bItalic;
}
if (sal_Int16 nFontStrikeout;
getPropertyIfSame(xProperties, u"CharStrikeout"_ustr) >>= nFontStrikeout)
{
bool bFontStrikeout = (nFontStrikeout > 0);
m_aCommandArguments[u".uno:Strikeout"_ustr] <<= bFontStrikeout;
}
if (sal_Int16 nFontUnderline;
getPropertyIfSame(xProperties, u"CharUnderline"_ustr) >>= nFontUnderline)
{
bool bFontUnderline = (nFontUnderline > 0);
m_aCommandArguments[u".uno:Underline"_ustr] <<= bFontUnderline;
}
if (bool bShadowed; getPropertyIfSame(xProperties, u"CharShadowed"_ustr) >>= bShadowed)
{
m_aCommandArguments[u".uno:Shadowed"_ustr] <<= bShadowed;
}
// Font color is not set in panel... it is just enabled to use
m_aCommandArguments[u".uno:Color"_ustr] <<= false;
m_aCommandArguments[u".uno:FontColor"_ustr] <<= false;
if (sal_Int32 nCharEscapement;
getPropertyIfSame(xProperties, u"CharEscapement"_ustr) >>= nCharEscapement)
{
m_aCommandArguments[u".uno:SuperScript"_ustr] <<= (nCharEscapement > 0);
m_aCommandArguments[u".uno:SubScript"_ustr] <<= (nCharEscapement < 0);
}
// Font Spacing is not set in panel... it is just enabled to use
m_aCommandArguments[u".uno:Spacing"_ustr] <<= false;
}
}
catch (const uno::Exception&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
// axes
m_aCommandAvailability[ u".uno:DiagramAxisX"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxis;
m_aCommandAvailability[ u".uno:DiagramAxisY"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxis;
m_aCommandAvailability[ u".uno:DiagramAxisZ"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxis;
m_aCommandAvailability[ u".uno:DiagramAxisA"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasAAxis;
m_aCommandAvailability[ u".uno:DiagramAxisB"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasBAxis;
m_aCommandAvailability[ u".uno:DiagramAxisAll"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyAxis();
// grids
// note: x and y are swapped in the commands!
m_aCommandAvailability[ u".uno:DiagramGridYMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainXGrid;
m_aCommandAvailability[ u".uno:DiagramGridXMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainYGrid;
m_aCommandAvailability[ u".uno:DiagramGridZMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainZGrid;
m_aCommandAvailability[ u".uno:DiagramGridYHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpXGrid;
m_aCommandAvailability[ u".uno:DiagramGridXHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpYGrid;
m_aCommandAvailability[ u".uno:DiagramGridZHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpZGrid;
m_aCommandAvailability[ u".uno:DiagramGridAll"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyGrid();
// series arrangement
m_aCommandAvailability[ u".uno:Forward"_ustr ] = ( bShapeContext ? isShapeControllerCommandAvailable( u".uno:Forward"_ustr ) :
( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesForward && bEnableDataTableDialog ) );
m_aCommandAvailability[ u".uno:Backward"_ustr ] = ( bShapeContext ? isShapeControllerCommandAvailable( u".uno:Backward"_ustr ) :
( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesBackward && bEnableDataTableDialog ) );
m_aCommandAvailability[ u".uno:InsertDataLabels"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertDataLabel"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddMeanValue;
m_aCommandAvailability[ u".uno:InsertTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendline;
const bool bInsertTrendlineEquation = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendlineEquation;
m_aCommandAvailability[ u".uno:InsertTrendlineEquation"_ustr ] = bInsertTrendlineEquation;
m_aCommandAvailability[ u".uno:InsertTrendlineEquationAndR2"_ustr ] = bInsertTrendlineEquation && m_apControllerState->bMayAddR2Value;
m_aCommandAvailability[ u".uno:InsertR2Value"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value
&& !m_apControllerState->bMayAddTrendlineEquation;
m_aCommandAvailability[ u".uno:DeleteR2Value"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteR2Value;
m_aCommandAvailability[ u".uno:InsertXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddXErrorBars;
m_aCommandAvailability[ u".uno:InsertYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddYErrorBars;
m_aCommandAvailability[ u".uno:DeleteDataLabels"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DeleteDataLabel"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DeleteTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendline;
m_aCommandAvailability[ u".uno:DeleteTrendlineEquation"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendlineEquation;
m_aCommandAvailability[ u".uno:DeleteMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteMeanValue;
m_aCommandAvailability[ u".uno:DeleteXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteXErrorBars;
m_aCommandAvailability[ u".uno:DeleteYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteYErrorBars;
m_aCommandAvailability[ u".uno:ResetDataPoint"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:ResetAllDataPoints"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertAxis"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DeleteAxis"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertAxisTitle"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:FormatMajorGrid"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertMajorGrid"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DeleteMajorGrid"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:FormatMinorGrid"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:InsertMinorGrid"_ustr ] = bIsWritable;
m_aCommandAvailability[ u".uno:DeleteMinorGrid"_ustr ] = bIsWritable;
// data table
m_aCommandAvailability[ u".uno:InsertDataTable"_ustr ] = bIsWritable && bModelStateIsValid && !m_apModelState->bDataTable;
m_aCommandAvailability[ u".uno:DeleteDataTable"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bDataTable;
}
bool ControllerCommandDispatch::commandAvailable(const OUString& rCommand) const
{
std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.find( rCommand ));
if( aIt != m_aCommandAvailability.end())
return aIt->second;
SAL_WARN("chart2", "commandAvailable: command not in availability map:" << rCommand);
return false;
}
bool ControllerCommandDispatch::commandHandled(const OUString& rCommand) const
{
return m_aCommandAvailability.contains(rCommand);
}
bool ControllerCommandDispatch::isShapeControllerCommandAvailable( const OUString& rCommand )
{
ShapeController* pShapeController(nullptr);
{
SolarMutexGuard g;
if (m_pDispatchContainer)
pShapeController = m_pDispatchContainer->getShapeController();
}
if ( pShapeController )
{
FeatureState aState( pShapeController->getState( rCommand ) );
return aState.bEnabled;
}
return false;
}
void ControllerCommandDispatch::fireStatusEvent(
const OUString & rURL,
const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
{
if (rURL.isEmpty() || rURL == ".uno:ChartElementSelector")
{
uno::Any aArg;
aArg <<= Reference< frame::XController >(m_xChartController);
fireStatusEventForURL( u".uno:ChartElementSelector"_ustr, aArg, true, xSingleListener );
}
if( rURL.isEmpty() )
{
for (auto const& elem : m_aCommandAvailability)
fireStatusEventForURLImpl( elem.first, xSingleListener );
}
else if (m_aCommandAvailability.contains(rURL))
fireStatusEventForURLImpl( rURL, xSingleListener );
}
// ____ XDispatch ____
void SAL_CALL ControllerCommandDispatch::dispatch(
const util::URL& URL,
const Sequence< beans::PropertyValue >& Arguments )
{
if( commandAvailable( URL.Complete ))
m_xDispatch->dispatch( URL, Arguments );
}
// ____ WeakComponentImplHelperBase ____
/// is called when this is disposed
void ControllerCommandDispatch::disposing(std::unique_lock<std::mutex>& /*rGuard*/)
{
m_xChartController.clear();
m_xDispatch.clear();
m_xSelectionSupplier.clear();
}
// ____ XEventListener (base of XModifyListener) ____
void SAL_CALL ControllerCommandDispatch::disposing( const lang::EventObject& /* Source */ )
{
m_xChartController.clear();
m_xDispatch.clear();
m_xSelectionSupplier.clear();
}
// ____ XModifyListener ____
void SAL_CALL ControllerCommandDispatch::modified( const lang::EventObject& aEvent )
{
bool bUpdateCommandAvailability = false;
// Update the "ModelState" Struct.
if( m_apModelState && m_xChartController.is())
{
m_apModelState->update( m_xChartController->getChartModel());
bUpdateCommandAvailability = true;
}
// Update the "ControllerState" Struct.
if( m_apControllerState && m_xChartController.is())
{
m_apControllerState->update( m_xChartController, m_xChartController->getChartModel());
bUpdateCommandAvailability = true;
}
if( bUpdateCommandAvailability )
updateCommandAvailability();
if (comphelper::LibreOfficeKit::isActive())
{
if (SfxViewShell* pViewShell = SfxViewShell::Current())
if (SfxObjectShell* pObjSh = pViewShell->GetObjectShell())
pObjSh->SetModified();
}
CommandDispatch::modified( aEvent );
}
// ____ XSelectionChangeListener ____
void SAL_CALL ControllerCommandDispatch::selectionChanged( const lang::EventObject& aEvent )
{
// Update the "ControllerState" Struct.
if( m_apControllerState && m_xChartController.is())
{
m_apControllerState->update( m_xChartController, m_xChartController->getChartModel());
updateCommandAvailability();
}
CommandDispatch::modified( aEvent );
}
} // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|