| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <sal/config.h> |
| 21 |
|
| 22 |
#include <ControllerCommandDispatch.hxx> |
| 23 |
#include <ChartModel.hxx> |
| 24 |
#include <Diagram.hxx> |
| 25 |
#include <Axis.hxx> |
| 26 |
#include <AxisHelper.hxx> |
| 27 |
#include <TitleHelper.hxx> |
| 28 |
#include <LegendHelper.hxx> |
| 29 |
#include <ObjectIdentifier.hxx> |
| 30 |
#include <ChartType.hxx> |
| 31 |
#include <ChartController.hxx> |
| 32 |
#include <RegressionCurveHelper.hxx> |
| 33 |
#include <DataSeries.hxx> |
| 34 |
#include <DataSeriesHelper.hxx> |
| 35 |
#include <StatisticsHelper.hxx> |
| 36 |
#include <ReferenceSizeProvider.hxx> |
| 37 |
#include <RegressionCurveModel.hxx> |
| 38 |
#include "ShapeController.hxx" |
| 39 |
#include <CharacterProperties.hxx> |
| 40 |
|
| 41 |
#include <vcl/svapp.hxx> |
| 42 |
#include <sal/log.hxx> |
| 43 |
#include <comphelper/diagnose_ex.hxx> |
| 44 |
#include <comphelper/lok.hxx> |
| 45 |
#include <sfx2/viewsh.hxx> |
| 46 |
#include <sfx2/objsh.hxx> |
| 47 |
|
| 48 |
#include <com/sun/star/chart2/XDataProviderAccess.hpp> |
| 49 |
#include <com/sun/star/frame/status/FontHeight.hpp> |
| 50 |
|
| 51 |
using namespace ::com::sun::star; |
| 52 |
|
| 53 |
using ::com::sun::star::uno::Reference; |
| 54 |
using ::com::sun::star::uno::Sequence; |
| 55 |
|
| 56 |
namespace |
| 57 |
{ |
| 58 |
uno::Any getPropertyIfSame(std::vector<Reference<beans::XPropertySet>>& xProperties, |
| 59 |
const OUString& aPropName) |
| 60 |
{ |
| 61 |
if (xProperties.size() < 1) |
| 62 |
return {}; |
| 63 |
|
| 64 |
if (!xProperties[0]) |
| 65 |
return {}; |
| 66 |
|
| 67 |
uno::Any aValue = xProperties[0]->getPropertyValue(aPropName); |
| 68 |
for (std::size_t i = 1; i < xProperties.size(); i++) |
| 69 |
{ |
| 70 |
if (xProperties[i] && aValue != xProperties[i]->getPropertyValue(aPropName)) |
| 71 |
return {}; |
| 72 |
} |
| 73 |
return aValue; |
| 74 |
} |
| 75 |
|
| 76 |
} // anonymous namespace |
| 77 |
|
| 78 |
namespace chart |
| 79 |
{ |
| 80 |
|
| 81 |
namespace impl |
| 82 |
{ |
| 83 |
|
| 84 |
/// Constants for moving the series. |
| 85 |
namespace { |
| 86 |
bool const MOVE_SERIES_FORWARD = true; |
| 87 |
bool const MOVE_SERIES_BACKWARD = false; |
| 88 |
} |
| 89 |
|
| 90 |
/** Represents the current state of the controller (needed for issue 63017). |
| 91 |
|
| 92 |
You can set the state by calling update(). After this call the state is |
| 93 |
preserved in this class until the next call to update(). |
| 94 |
|
| 95 |
This is useful, not to say necessary, for enabling and disabling of menu |
| 96 |
entries (e.g. format>arrangement). As the status requests are sent very |
| 97 |
frequently it would be impossible, from a performance point of view, to |
| 98 |
query the current status every time directly at the model. So this class |
| 99 |
serves as a cache for the state. |
| 100 |
*/ |
| 101 |
struct ControllerState |
| 102 |
{ |
| 103 |
ControllerState(); |
| 104 |
|
| 105 |
void update( const Reference< frame::XController > & xController, |
| 106 |
const rtl::Reference<::chart::ChartModel> & xModel ); |
| 107 |
|
| 108 |
// -- State variables ------- |
| 109 |
bool bHasSelectedObject; |
| 110 |
bool bIsPositionableObject; |
| 111 |
bool bIsTextObject; |
| 112 |
bool bIsDeleteableObjectSelected; |
| 113 |
bool bIsFormateableObjectSelected; |
| 114 |
|
| 115 |
// May the selected series be moved forward or backward (cf |
| 116 |
// format>arrangement). |
| 117 |
bool bMayMoveSeriesForward; |
| 118 |
bool bMayMoveSeriesBackward; |
| 119 |
|
| 120 |
// trendlines |
| 121 |
bool bMayAddMenuTrendline; |
| 122 |
bool bMayAddTrendline; |
| 123 |
bool bMayAddTrendlineEquation; |
| 124 |
bool bMayAddR2Value; |
| 125 |
bool bMayAddMeanValue; |
| 126 |
bool bMayAddXErrorBars; |
| 127 |
bool bMayAddYErrorBars; |
| 128 |
|
| 129 |
bool bMayDeleteTrendline; |
| 130 |
bool bMayDeleteTrendlineEquation; |
| 131 |
bool bMayDeleteR2Value; |
| 132 |
bool bMayDeleteMeanValue; |
| 133 |
bool bMayDeleteXErrorBars; |
| 134 |
bool bMayDeleteYErrorBars; |
| 135 |
|
| 136 |
bool bMayFormatTrendline; |
| 137 |
bool bMayFormatTrendlineEquation; |
| 138 |
bool bMayFormatMeanValue; |
| 139 |
bool bMayFormatXErrorBars; |
| 140 |
bool bMayFormatYErrorBars; |
| 141 |
}; |
| 142 |
|
| 143 |
ControllerState::ControllerState() : |
| 144 |
bHasSelectedObject( false ), |
| 145 |
bIsPositionableObject( false ), |
| 146 |
bIsTextObject(false), |
| 147 |
bIsDeleteableObjectSelected(false), |
| 148 |
bIsFormateableObjectSelected(false), |
| 149 |
bMayMoveSeriesForward( false ), |
| 150 |
bMayMoveSeriesBackward( false ), |
| 151 |
bMayAddMenuTrendline( false ), |
| 152 |
bMayAddTrendline( false ), |
| 153 |
bMayAddTrendlineEquation( false ), |
| 154 |
bMayAddR2Value( false ), |
| 155 |
bMayAddMeanValue( false ), |
| 156 |
bMayAddXErrorBars( false ), |
| 157 |
bMayAddYErrorBars( false ), |
| 158 |
bMayDeleteTrendline( false ), |
| 159 |
bMayDeleteTrendlineEquation( false ), |
| 160 |
bMayDeleteR2Value( false ), |
| 161 |
bMayDeleteMeanValue( false ), |
| 162 |
bMayDeleteXErrorBars( false ), |
| 163 |
bMayDeleteYErrorBars( false ), |
| 164 |
bMayFormatTrendline( false ), |
| 165 |
bMayFormatTrendlineEquation( false ), |
| 166 |
bMayFormatMeanValue( false ), |
| 167 |
bMayFormatXErrorBars( false ), |
| 168 |
bMayFormatYErrorBars( false ) |
| 169 |
{} |
| 170 |
|
| 171 |
void ControllerState::update( |
| 172 |
const Reference< frame::XController > & xController, |
| 173 |
const rtl::Reference<::chart::ChartModel> & xModel ) |
| 174 |
{ |
| 175 |
if (!xModel) |
| 176 |
return; |
| 177 |
|
| 178 |
Reference< view::XSelectionSupplier > xSelectionSupplier( |
| 179 |
xController, uno::UNO_QUERY ); |
| 180 |
|
| 181 |
// Update ControllerState variables. |
| 182 |
if( !xSelectionSupplier.is()) |
| 183 |
return; |
| 184 |
|
| 185 |
uno::Any aSelObj( xSelectionSupplier->getSelection() ); |
| 186 |
ObjectIdentifier aSelOID( aSelObj ); |
| 187 |
const OUString& aSelObjCID( aSelOID.getObjectCID() ); |
| 188 |
|
| 189 |
bHasSelectedObject = aSelOID.isValid(); |
| 190 |
|
| 191 |
ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID )); |
| 192 |
|
| 193 |
bIsPositionableObject = (aObjectType != OBJECTTYPE_DATA_POINT) && aSelOID.isDragableObject(); |
| 194 |
bIsTextObject = aObjectType == OBJECTTYPE_TITLE; |
| 195 |
|
| 196 |
rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram(); |
| 197 |
bIsFormateableObjectSelected = bHasSelectedObject && aSelOID.isAutoGeneratedObject(); |
| 198 |
if( aObjectType==OBJECTTYPE_DIAGRAM || aObjectType==OBJECTTYPE_DIAGRAM_WALL || aObjectType==OBJECTTYPE_DIAGRAM_FLOOR ) |
| 199 |
bIsFormateableObjectSelected = xDiagram->isSupportingFloorAndWall(); |
| 200 |
|
| 201 |
rtl::Reference< DataSeries > xGivenDataSeries = |
| 202 |
ObjectIdentifier::getDataSeriesForCID( |
| 203 |
aSelObjCID, xModel ); |
| 204 |
|
| 205 |
bIsDeleteableObjectSelected = ChartController::isObjectDeleteable( aSelObj ); |
| 206 |
|
| 207 |
bMayMoveSeriesForward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram && xDiagram->isSeriesMoveable( |
| 208 |
xGivenDataSeries, |
| 209 |
MOVE_SERIES_FORWARD ); |
| 210 |
|
| 211 |
bMayMoveSeriesBackward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram && xDiagram->isSeriesMoveable( |
| 212 |
xGivenDataSeries, |
| 213 |
MOVE_SERIES_BACKWARD ); |
| 214 |
|
| 215 |
bMayAddMenuTrendline = false; |
| 216 |
bMayAddTrendline = false; |
| 217 |
bMayAddTrendlineEquation = false; |
| 218 |
bMayAddR2Value = false; |
| 219 |
bMayAddMeanValue = false; |
| 220 |
bMayAddXErrorBars = false; |
| 221 |
bMayAddYErrorBars = false; |
| 222 |
bMayDeleteTrendline = false; |
| 223 |
bMayDeleteTrendlineEquation = false; |
| 224 |
bMayDeleteR2Value = false; |
| 225 |
bMayDeleteMeanValue = false; |
| 226 |
bMayDeleteXErrorBars = false; |
| 227 |
bMayDeleteYErrorBars = false; |
| 228 |
bMayFormatTrendline = false; |
| 229 |
bMayFormatTrendlineEquation = false; |
| 230 |
bMayFormatMeanValue = false; |
| 231 |
bMayFormatXErrorBars = false; |
| 232 |
bMayFormatYErrorBars = false; |
| 233 |
if( !bHasSelectedObject ) |
| 234 |
return; |
| 235 |
|
| 236 |
if( xGivenDataSeries.is()) |
| 237 |
{ |
| 238 |
bMayAddMenuTrendline = true; |
| 239 |
sal_Int32 nDimensionCount = xDiagram->getDimension(); |
| 240 |
rtl::Reference< ::chart::ChartType > xFirstChartType( |
| 241 |
DataSeriesHelper::getChartTypeOfSeries( xGivenDataSeries, xDiagram )); |
| 242 |
|
| 243 |
// trend lines/mean value line |
| 244 |
if( (aObjectType == OBJECTTYPE_DATA_SERIES || aObjectType == OBJECTTYPE_DATA_POINT) |
| 245 |
&& xFirstChartType.is() ? xFirstChartType->isSupportingRegressionProperties(nDimensionCount) : true) |
| 246 |
{ |
| 247 |
// Trendline |
| 248 |
bMayAddTrendline = true; |
| 249 |
|
| 250 |
// Mean Value |
| 251 |
bMayFormatMeanValue = bMayDeleteMeanValue = RegressionCurveHelper::hasMeanValueLine( xGivenDataSeries ); |
| 252 |
bMayAddMeanValue = ! bMayDeleteMeanValue; |
| 253 |
} |
| 254 |
|
| 255 |
// error bars |
| 256 |
if( (aObjectType == OBJECTTYPE_DATA_SERIES || aObjectType == OBJECTTYPE_DATA_POINT) |
| 257 |
&& xFirstChartType.is() ? xFirstChartType->isSupportingStatisticProperties(nDimensionCount) : true) |
| 258 |
{ |
| 259 |
bMayFormatXErrorBars = bMayDeleteXErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries, false ); |
| 260 |
bMayAddXErrorBars = ! bMayDeleteXErrorBars; |
| 261 |
|
| 262 |
bMayFormatYErrorBars = bMayDeleteYErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries ); |
| 263 |
bMayAddYErrorBars = ! bMayDeleteYErrorBars; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
if( aObjectType == OBJECTTYPE_DATA_AVERAGE_LINE ) |
| 268 |
bMayFormatMeanValue = true; |
| 269 |
|
| 270 |
if( aObjectType == OBJECTTYPE_DATA_ERRORS_X) |
| 271 |
bMayFormatXErrorBars = true; |
| 272 |
|
| 273 |
if( aObjectType == OBJECTTYPE_DATA_ERRORS_Y ) |
| 274 |
bMayFormatYErrorBars = true; |
| 275 |
|
| 276 |
if( aObjectType == OBJECTTYPE_DATA_CURVE ) |
| 277 |
{ |
| 278 |
bMayFormatTrendline = true; |
| 279 |
bMayDeleteTrendline = true; |
| 280 |
rtl::Reference< RegressionCurveModel > xRegCurve( |
| 281 |
dynamic_cast<RegressionCurveModel*>(ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ).get()) ); |
| 282 |
|
| 283 |
// Trendline Equation |
| 284 |
bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve ); |
| 285 |
bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation; |
| 286 |
bMayAddR2Value = RegressionCurveHelper::MayHaveCorrelationCoefficient( xRegCurve ) && bMayAddTrendlineEquation; |
| 287 |
} |
| 288 |
else if( aObjectType == OBJECTTYPE_DATA_CURVE_EQUATION ) |
| 289 |
{ |
| 290 |
bMayFormatTrendlineEquation = true; |
| 291 |
bool bHasR2Value = false; |
| 292 |
bool bMayHaveR2 = true; |
| 293 |
try |
| 294 |
{ |
| 295 |
uno::Reference< beans::XPropertySet > xEquationProperties = |
| 296 |
ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ); |
| 297 |
if( xEquationProperties.is() ) |
| 298 |
{ |
| 299 |
xEquationProperties->getPropertyValue( u"ShowCorrelationCoefficient"_ustr ) >>= bHasR2Value; |
| 300 |
xEquationProperties->getPropertyValue( u"MayHaveCorrelationCoefficient"_ustr ) >>= bMayHaveR2; |
| 301 |
} |
| 302 |
} |
| 303 |
catch(const uno::RuntimeException&) |
| 304 |
{ |
| 305 |
TOOLS_WARN_EXCEPTION("chart2", "" ); |
| 306 |
} |
| 307 |
bMayAddR2Value = !bHasR2Value && bMayHaveR2; |
| 308 |
bMayDeleteR2Value = bHasR2Value; |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
/** Represents the current state of the model. |
| 313 |
|
| 314 |
You can set the state by calling update(). After this call the state is |
| 315 |
preserved in this class until the next call to update(). |
| 316 |
|
| 317 |
This is useful, not to say necessary, for enabling and disabling of menu |
| 318 |
entries and toolbar icons. As the status requests are sent very frequently |
| 319 |
it would be impossible, from a performance point of view, to query the |
| 320 |
current status every time directly at the model. So this class serves as a |
| 321 |
cache for the state. |
| 322 |
*/ |
| 323 |
struct ModelState |
| 324 |
{ |
| 325 |
ModelState(); |
| 326 |
|
| 327 |
void update( const rtl::Reference<::chart::ChartModel> & xModel ); |
| 328 |
|
| 329 |
bool HasAnyAxis() const; |
| 330 |
bool HasAnyGrid() const; |
| 331 |
bool HasAnyTitle() const; |
| 332 |
|
| 333 |
bool bIsReadOnly; |
| 334 |
bool bIsThreeD; |
| 335 |
bool bHasOwnData; |
| 336 |
bool bHasDataFromPivotTable; |
| 337 |
|
| 338 |
bool bHasMainTitle; |
| 339 |
bool bHasSubTitle; |
| 340 |
bool bHasXAxisTitle; |
| 341 |
bool bHasYAxisTitle; |
| 342 |
bool bHasZAxisTitle; |
| 343 |
bool bHasSecondaryXAxisTitle; |
| 344 |
bool bHasSecondaryYAxisTitle; |
| 345 |
|
| 346 |
bool bHasXAxis; |
| 347 |
bool bHasYAxis; |
| 348 |
bool bHasZAxis; |
| 349 |
bool bHasAAxis; |
| 350 |
bool bHasBAxis; |
| 351 |
|
| 352 |
bool bHasMainXGrid; |
| 353 |
bool bHasMainYGrid; |
| 354 |
bool bHasMainZGrid; |
| 355 |
bool bHasHelpXGrid; |
| 356 |
bool bHasHelpYGrid; |
| 357 |
bool bHasHelpZGrid; |
| 358 |
|
| 359 |
bool bHasAutoScaledText; |
| 360 |
bool bHasLegend; |
| 361 |
bool bHasWall; |
| 362 |
bool bHasFloor; |
| 363 |
|
| 364 |
bool bSupportsStatistics; |
| 365 |
bool bSupportsAxes; |
| 366 |
|
| 367 |
bool bDataTable = false; |
| 368 |
}; |
| 369 |
|
| 370 |
ModelState::ModelState() : |
| 371 |
bIsReadOnly(true), |
| 372 |
bIsThreeD(false), |
| 373 |
bHasOwnData(false), |
| 374 |
bHasDataFromPivotTable(false), |
| 375 |
bHasMainTitle(false), |
| 376 |
bHasSubTitle(false), |
| 377 |
bHasXAxisTitle(false), |
| 378 |
bHasYAxisTitle(false), |
| 379 |
bHasZAxisTitle(false), |
| 380 |
bHasSecondaryXAxisTitle(false), |
| 381 |
bHasSecondaryYAxisTitle(false), |
| 382 |
bHasXAxis(false), |
| 383 |
bHasYAxis(false), |
| 384 |
bHasZAxis(false), |
| 385 |
bHasAAxis(false), |
| 386 |
bHasBAxis(false), |
| 387 |
bHasMainXGrid(false), |
| 388 |
bHasMainYGrid(false), |
| 389 |
bHasMainZGrid(false), |
| 390 |
bHasHelpXGrid(false), |
| 391 |
bHasHelpYGrid(false), |
| 392 |
bHasHelpZGrid(false), |
| 393 |
bHasAutoScaledText(false), |
| 394 |
bHasLegend(false), |
| 395 |
bHasWall(false), |
| 396 |
bHasFloor(false), |
| 397 |
bSupportsStatistics(false), |
| 398 |
bSupportsAxes(false) |
| 399 |
{} |
| 400 |
|
| 401 |
void ModelState::update( const rtl::Reference<::chart::ChartModel> & xModel ) |
| 402 |
{ |
| 403 |
rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram(); |
| 404 |
|
| 405 |
bIsReadOnly = xModel->isReadonly(); |
| 406 |
|
| 407 |
sal_Int32 nDimensionCount = 0; |
| 408 |
if (xDiagram) |
| 409 |
nDimensionCount = xDiagram->getDimension(); |
| 410 |
|
| 411 |
rtl::Reference<ChartType> xFirstChartType; |
| 412 |
if (xDiagram) |
| 413 |
xFirstChartType = xDiagram->getChartTypeByIndex( 0 ); |
| 414 |
bSupportsStatistics = xFirstChartType.is() ? xFirstChartType->isSupportingStatisticProperties(nDimensionCount) : true; |
| 415 |
bSupportsAxes = xFirstChartType.is() ? xFirstChartType->isSupportingMainAxis(nDimensionCount, 0) : true; |
| 416 |
|
| 417 |
bIsThreeD = (nDimensionCount == 3); |
| 418 |
if (xModel.is()) |
| 419 |
{ |
| 420 |
bHasOwnData = xModel->hasInternalDataProvider(); |
| 421 |
bHasDataFromPivotTable = !bHasOwnData && xModel->isDataFromPivotTable(); |
| 422 |
} |
| 423 |
|
| 424 |
bHasMainTitle = TitleHelper::getTitle( TitleHelper::MAIN_TITLE, xModel ).is(); |
| 425 |
bHasSubTitle = TitleHelper::getTitle( TitleHelper::SUB_TITLE, xModel ).is(); |
| 426 |
bHasXAxisTitle = TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, xModel ).is(); |
| 427 |
bHasYAxisTitle = TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, xModel ).is(); |
| 428 |
bHasZAxisTitle = TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE, xModel ).is(); |
| 429 |
bHasSecondaryXAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xModel ).is(); |
| 430 |
bHasSecondaryYAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xModel ).is(); |
| 431 |
|
| 432 |
bHasXAxis = bSupportsAxes && AxisHelper::getAxis( 0, true, xDiagram ).is(); |
| 433 |
bHasYAxis = bSupportsAxes && AxisHelper::getAxis( 1, true, xDiagram ).is(); |
| 434 |
bHasZAxis = bSupportsAxes && AxisHelper::getAxis( 2, true, xDiagram ).is(); |
| 435 |
bHasAAxis = bSupportsAxes && AxisHelper::getAxis( 0, false, xDiagram ).is(); |
| 436 |
bHasBAxis = bSupportsAxes && AxisHelper::getAxis( 1, false, xDiagram ).is(); |
| 437 |
|
| 438 |
bHasMainXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, true, xDiagram ); |
| 439 |
bHasMainYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, true, xDiagram ); |
| 440 |
bHasMainZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, true, xDiagram ); |
| 441 |
bHasHelpXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, false, xDiagram ); |
| 442 |
bHasHelpYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, false, xDiagram ); |
| 443 |
bHasHelpZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, false, xDiagram ); |
| 444 |
|
| 445 |
bHasAutoScaledText = |
| 446 |
(ReferenceSizeProvider::getAutoResizeState( xModel ) == |
| 447 |
ReferenceSizeProvider::AUTO_RESIZE_YES); |
| 448 |
|
| 449 |
bHasLegend = LegendHelper::hasLegend( xDiagram ); |
| 450 |
bHasWall = xDiagram && xDiagram->isSupportingFloorAndWall(); |
| 451 |
bHasFloor = bHasWall && bIsThreeD; |
| 452 |
|
| 453 |
bDataTable = xDiagram.is() && xDiagram->getDataTable().is(); |
| 454 |
} |
| 455 |
|
| 456 |
bool ModelState::HasAnyAxis() const |
| 457 |
{ |
| 458 |
return bHasXAxis || bHasYAxis || bHasZAxis || bHasAAxis || bHasBAxis; |
| 459 |
} |
| 460 |
|
| 461 |
bool ModelState::HasAnyGrid() const |
| 462 |
{ |
| 463 |
return bHasMainXGrid || bHasMainYGrid || bHasMainZGrid || |
| 464 |
bHasHelpXGrid || bHasHelpYGrid || bHasHelpZGrid; |
| 465 |
} |
| 466 |
|
| 467 |
bool ModelState::HasAnyTitle() const |
| 468 |
{ |
| 469 |
return bHasMainTitle || bHasSubTitle || bHasXAxisTitle || bHasYAxisTitle || bHasZAxisTitle || bHasSecondaryXAxisTitle || bHasSecondaryYAxisTitle; |
| 470 |
} |
| 471 |
|
| 472 |
} // namespace impl |
| 473 |
|
| 474 |
ControllerCommandDispatch::ControllerCommandDispatch( |
| 475 |
const Reference< uno::XComponentContext > & xContext, |
| 476 |
ChartController* pController, CommandDispatchContainer* pContainer ) : |
| 477 |
impl::ControllerCommandDispatch_Base( xContext ), |
| 478 |
m_xChartController( pController ), |
| 479 |
m_xSelectionSupplier( Reference< view::XSelectionSupplier >( pController ) ), |
| 480 |
m_xDispatch( Reference< frame::XDispatch >( pController ) ), |
| 481 |
m_apModelState( new impl::ModelState() ), |
| 482 |
m_apControllerState( new impl::ControllerState() ), |
| 483 |
m_pDispatchContainer( pContainer ) |
| 484 |
{ |
| 485 |
} |
| 486 |
|
| 487 |
ControllerCommandDispatch::~ControllerCommandDispatch() |
| 488 |
{ |
| 489 |
} |
| 490 |
|
| 491 |
void ControllerCommandDispatch::initialize() |
| 492 |
{ |
| 493 |
if( !m_xChartController.is()) |
| 494 |
return; |
| 495 |
|
| 496 |
rtl::Reference<::chart::ChartModel> xModel( m_xChartController->getChartModel()); |
| 497 |
OSL_ASSERT( xModel.is()); |
| 498 |
if( xModel.is()) |
| 499 |
xModel->addModifyListener( this ); |
| 500 |
|
| 501 |
// Listen selection modifications (Arrangement feature - issue 63017). |
| 502 |
if( m_xSelectionSupplier.is() ) |
| 503 |
m_xSelectionSupplier->addSelectionChangeListener( this ); |
| 504 |
|
| 505 |
if( m_apModelState && xModel.is()) |
| 506 |
m_apModelState->update( xModel ); |
| 507 |
|
| 508 |
if( m_apControllerState && xModel.is()) |
| 509 |
m_apControllerState->update( m_xChartController, xModel ); |
| 510 |
|
| 511 |
updateCommandAvailability(); |
| 512 |
} |
| 513 |
|
| 514 |
void ControllerCommandDispatch::fireStatusEventForURLImpl( |
| 515 |
const OUString & rURL, |
| 516 |
const Reference< frame::XStatusListener > & xSingleListener ) |
| 517 |
{ |
| 518 |
std::map< OUString, uno::Any >::const_iterator aArgIt( m_aCommandArguments.find( rURL )); |
| 519 |
if( aArgIt != m_aCommandArguments.end()) |
| 520 |
fireStatusEventForURL( rURL, aArgIt->second, commandAvailable( rURL ), xSingleListener ); |
| 521 |
else |
| 522 |
fireStatusEventForURL( rURL, uno::Any(), commandAvailable( rURL ), xSingleListener ); |
| 523 |
} |
| 524 |
|
| 525 |
void ControllerCommandDispatch::updateCommandAvailability() |
| 526 |
{ |
| 527 |
bool bModelStateIsValid = (m_apModelState != nullptr); |
| 528 |
bool bControllerStateIsValid = (m_apControllerState != nullptr); |
| 529 |
// Model and controller states exist. |
| 530 |
OSL_ASSERT( bModelStateIsValid ); |
| 531 |
OSL_ASSERT( bControllerStateIsValid ); |
| 532 |
|
| 533 |
// read-only |
| 534 |
bool bIsWritable = bModelStateIsValid && (! m_apModelState->bIsReadOnly); |
| 535 |
bool bShapeContext = m_xChartController.is() && m_xChartController->isShapeContext(); |
| 536 |
bool bIsTextEdit = m_xChartController.is() && m_xChartController->IsTextEdit(); |
| 537 |
|
| 538 |
bool bEnableDataTableDialog = false; |
| 539 |
bool bCanCreateDataProvider = false; |
| 540 |
|
| 541 |
if ( m_xChartController.is() ) |
| 542 |
{ |
| 543 |
Reference< beans::XPropertySet > xProps( m_xChartController->getModel(), uno::UNO_QUERY ); |
| 544 |
if ( xProps.is() ) |
| 545 |
{ |
| 546 |
try |
| 547 |
{ |
| 548 |
xProps->getPropertyValue(u"EnableDataTableDialog"_ustr) >>= bEnableDataTableDialog; |
| 549 |
} |
| 550 |
catch( const uno::Exception& ) |
| 551 |
{ |
| 552 |
TOOLS_WARN_EXCEPTION("chart2", "" ); |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
rtl::Reference< ChartModel > xChartModel = m_xChartController->getChartModel(); |
| 557 |
OSL_ENSURE(xChartModel.is(), "Invalid XChartDocument"); |
| 558 |
if ( xChartModel.is() ) |
| 559 |
{ |
| 560 |
css::uno::Reference< css::chart2::XDataProviderAccess > xCreatorDoc(xChartModel->getParent(), uno::UNO_QUERY); |
| 561 |
bCanCreateDataProvider = xCreatorDoc.is(); |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
// edit commands |
| 566 |
m_aCommandAvailability[ u".uno:Cut"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsDeleteableObjectSelected; |
| 567 |
m_aCommandAvailability[ u".uno:Copy"_ustr ] = bControllerStateIsValid && m_apControllerState->bHasSelectedObject; |
| 568 |
m_aCommandAvailability[ u".uno:Paste"_ustr ] = bIsWritable; |
| 569 |
|
| 570 |
// toolbar commands |
| 571 |
m_aCommandAvailability[ u".uno:ToggleGridHorizontal"_ustr ] = bIsWritable; |
| 572 |
m_aCommandArguments[ u".uno:ToggleGridHorizontal"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasMainYGrid; |
| 573 |
m_aCommandAvailability[ u".uno:ToggleGridVertical"_ustr ] = bIsWritable; |
| 574 |
m_aCommandArguments[ u".uno:ToggleGridVertical"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasMainXGrid; |
| 575 |
|
| 576 |
m_aCommandAvailability[ u".uno:ToggleLegend"_ustr ] = bIsWritable; |
| 577 |
m_aCommandArguments[ u".uno:ToggleLegend"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasLegend; |
| 578 |
|
| 579 |
m_aCommandAvailability[ u".uno:NewArrangement"_ustr ] = bIsWritable; |
| 580 |
m_aCommandAvailability[ u".uno:Update"_ustr ] = bIsWritable; |
| 581 |
m_aCommandAvailability[ u".uno:DefaultColors"_ustr ] = bIsWritable; |
| 582 |
m_aCommandAvailability[ u".uno:BarWidth"_ustr ] = bIsWritable; |
| 583 |
m_aCommandAvailability[ u".uno:NumberOfLines"_ustr ] = bIsWritable; |
| 584 |
m_aCommandAvailability[ u".uno:ArrangeRow"_ustr ] = |
| 585 |
bShapeContext || ( bIsWritable && bControllerStateIsValid && ( m_apControllerState->bMayMoveSeriesForward || m_apControllerState->bMayMoveSeriesBackward ) ); |
| 586 |
|
| 587 |
// insert objects |
| 588 |
m_aCommandAvailability[ u".uno:InsertTitles"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuTitles"_ustr ] = bIsWritable; |
| 589 |
m_aCommandAvailability[ u".uno:InsertLegend"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuLegend"_ustr ] = bIsWritable; |
| 590 |
m_aCommandAvailability[ u".uno:DeleteLegend"_ustr ] = bIsWritable; |
| 591 |
m_aCommandAvailability[ u".uno:InsertMenuDataLabels"_ustr ] = bIsWritable; |
| 592 |
m_aCommandAvailability[ u".uno:InsertRemoveAxes"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuAxes"_ustr ] = bIsWritable && m_apModelState->bSupportsAxes; |
| 593 |
m_aCommandAvailability[ u".uno:InsertMenuGrids"_ustr ] = bIsWritable && m_apModelState->bSupportsAxes; |
| 594 |
m_aCommandAvailability[ u".uno:InsertMenuTrendlines"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics && bControllerStateIsValid && m_apControllerState->bMayAddMenuTrendline; |
| 595 |
m_aCommandAvailability[ u".uno:InsertMenuMeanValues"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics; |
| 596 |
m_aCommandAvailability[ u".uno:InsertMenuXErrorBars"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics; |
| 597 |
m_aCommandAvailability[ u".uno:InsertMenuYErrorBars"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics; |
| 598 |
m_aCommandAvailability[ u".uno:InsertSymbol"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsTextObject; |
| 599 |
m_aCommandAvailability[ u".uno:InsertMenuDataTable"_ustr ] = bIsWritable; |
| 600 |
|
| 601 |
// format objects |
| 602 |
bool bFormatObjectAvailable = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsFormateableObjectSelected; |
| 603 |
m_aCommandAvailability[ u".uno:FormatSelection"_ustr ] = bFormatObjectAvailable && !bIsTextEdit; |
| 604 |
m_aCommandAvailability[ u".uno:FontDialog"_ustr ] = (bShapeContext ? isShapeControllerCommandAvailable(u".uno:FontDialog"_ustr) : |
| 605 |
bFormatObjectAvailable) && bIsTextEdit; |
| 606 |
m_aCommandAvailability[ u".uno:FormatAxis"_ustr ] = bFormatObjectAvailable; |
| 607 |
m_aCommandAvailability[ u".uno:FormatTitle"_ustr ] = bFormatObjectAvailable && !bIsTextEdit; |
| 608 |
m_aCommandAvailability[ u".uno:FormatDataSeries"_ustr ] = bFormatObjectAvailable; |
| 609 |
m_aCommandAvailability[ u".uno:FormatDataPoint"_ustr ] = bFormatObjectAvailable; |
| 610 |
m_aCommandAvailability[ u".uno:FormatDataLabels"_ustr ] = bFormatObjectAvailable; |
| 611 |
m_aCommandAvailability[ u".uno:FormatDataLabel"_ustr ] = bFormatObjectAvailable; |
| 612 |
m_aCommandAvailability[ u".uno:FormatXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatXErrorBars; |
| 613 |
m_aCommandAvailability[ u".uno:FormatYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatYErrorBars; |
| 614 |
m_aCommandAvailability[ u".uno:FormatMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatMeanValue; |
| 615 |
m_aCommandAvailability[ u".uno:FormatTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendline; |
| 616 |
m_aCommandAvailability[ u".uno:FormatTrendlineEquation"_ustr ] = bFormatObjectAvailable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendlineEquation; |
| 617 |
m_aCommandAvailability[ u".uno:FormatStockLoss"_ustr ] = bFormatObjectAvailable; |
| 618 |
m_aCommandAvailability[ u".uno:FormatStockGain"_ustr ] = bFormatObjectAvailable; |
| 619 |
if (comphelper::LibreOfficeKit::isActive()) |
| 620 |
{ |
| 621 |
m_aCommandAvailability[u".uno:FillColor"_ustr] = bFormatObjectAvailable; |
| 622 |
m_aCommandAvailability[u".uno:XLineColor"_ustr] = bFormatObjectAvailable; |
| 623 |
m_aCommandAvailability[u".uno:LineWidth"_ustr] = bFormatObjectAvailable; |
| 624 |
m_aCommandAvailability[u".uno:FillGradient"_ustr] = bFormatObjectAvailable; |
| 625 |
} |
| 626 |
|
| 627 |
m_aCommandAvailability[ u".uno:DiagramType"_ustr ] = bIsWritable; |
| 628 |
m_aCommandAvailability[ u".uno:Legend"_ustr ] = bIsWritable && m_apModelState->bHasLegend; |
| 629 |
m_aCommandAvailability[ u".uno:DiagramWall"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasWall; |
| 630 |
m_aCommandAvailability[ u".uno:DiagramArea"_ustr ] = bIsWritable; |
| 631 |
|
| 632 |
m_aCommandAvailability[ u".uno:TransformDialog"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bHasSelectedObject && m_apControllerState->bIsPositionableObject; |
| 633 |
|
| 634 |
// 3d commands |
| 635 |
m_aCommandAvailability[ u".uno:View3D"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bIsThreeD; |
| 636 |
m_aCommandAvailability[ u".uno:DiagramFloor"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasFloor; |
| 637 |
|
| 638 |
//some more format commands with different ui text |
| 639 |
m_aCommandAvailability[ u".uno:FormatWall"_ustr ] = m_aCommandAvailability[ u".uno:DiagramWall"_ustr ]; |
| 640 |
m_aCommandAvailability[ u".uno:FormatFloor"_ustr ] = m_aCommandAvailability[ u".uno:DiagramFloor"_ustr ]; |
| 641 |
m_aCommandAvailability[ u".uno:FormatChartArea"_ustr ] = m_aCommandAvailability[ u".uno:DiagramArea"_ustr ]; |
| 642 |
m_aCommandAvailability[ u".uno:FormatLegend"_ustr ] = m_aCommandAvailability[ u".uno:Legend"_ustr ]; |
| 643 |
|
| 644 |
// depending on own data and ability to create new data provider |
| 645 |
m_aCommandAvailability[u".uno:DataRanges"_ustr] = bIsWritable && bModelStateIsValid && !m_apModelState->bHasDataFromPivotTable |
| 646 |
&& ((m_apModelState->bHasOwnData && bCanCreateDataProvider) || !m_apModelState->bHasOwnData); |
| 647 |
m_aCommandAvailability[ u".uno:DiagramData"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData && bEnableDataTableDialog; |
| 648 |
|
| 649 |
// titles |
| 650 |
m_aCommandAvailability[ u".uno:MainTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainTitle; |
| 651 |
m_aCommandAvailability[ u".uno:SubTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSubTitle; |
| 652 |
m_aCommandAvailability[ u".uno:XTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxisTitle; |
| 653 |
m_aCommandAvailability[ u".uno:YTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxisTitle; |
| 654 |
m_aCommandAvailability[ u".uno:ZTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxisTitle; |
| 655 |
m_aCommandAvailability[ u".uno:SecondaryXTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryXAxisTitle; |
| 656 |
m_aCommandAvailability[ u".uno:SecondaryYTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryYAxisTitle; |
| 657 |
m_aCommandAvailability[ u".uno:AllTitles"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyTitle(); |
| 658 |
|
| 659 |
// text |
| 660 |
m_aCommandAvailability[ u".uno:ScaleText"_ustr ] = bIsWritable && bModelStateIsValid ; |
| 661 |
m_aCommandArguments[ u".uno:ScaleText"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasAutoScaledText; |
| 662 |
|
| 663 |
bool bTitleIsInEditMode = false; |
| 664 |
try |
| 665 |
{ |
| 666 |
OUString aObjectCID2 = m_xChartController->getSelectionMember().getSelectedCID(); |
| 667 |
if (!aObjectCID2.isEmpty()) |
| 668 |
if (ObjectIdentifier::getObjectType(aObjectCID2) == OBJECTTYPE_TITLE) |
| 669 |
if (m_xChartController->GetDrawViewWrapper()) |
| 670 |
if (m_xChartController->GetDrawViewWrapper()->GetTextEditOutlinerView()) |
| 671 |
bTitleIsInEditMode = true; |
| 672 |
} |
| 673 |
catch (const uno::Exception&) { TOOLS_WARN_EXCEPTION("chart2", ""); } |
| 674 |
|
| 675 |
bool bEnableUnoCommands = bIsWritable && bModelStateIsValid && !bTitleIsInEditMode; |
| 676 |
m_aCommandAvailability[u".uno:Bold"_ustr] = bEnableUnoCommands; |
| 677 |
m_aCommandAvailability[u".uno:Strikeout"_ustr] = bEnableUnoCommands; |
| 678 |
m_aCommandAvailability[u".uno:CharFontName"_ustr] = bEnableUnoCommands; |
| 679 |
m_aCommandAvailability[u".uno:FontHeight"_ustr] = bEnableUnoCommands; |
| 680 |
m_aCommandAvailability[u".uno:Italic"_ustr] = bEnableUnoCommands; |
| 681 |
m_aCommandAvailability[u".uno:Underline"_ustr] = bEnableUnoCommands; |
| 682 |
m_aCommandAvailability[u".uno:Shadowed"_ustr] = bEnableUnoCommands; |
| 683 |
m_aCommandAvailability[u".uno:Color"_ustr] = bEnableUnoCommands; |
| 684 |
m_aCommandAvailability[u".uno:FontColor"_ustr] = bEnableUnoCommands; |
| 685 |
m_aCommandAvailability[u".uno:Grow"_ustr] = bEnableUnoCommands; |
| 686 |
m_aCommandAvailability[u".uno:Shrink"_ustr] = bEnableUnoCommands; |
| 687 |
m_aCommandAvailability[u".uno:SuperScript"_ustr] = bEnableUnoCommands; |
| 688 |
m_aCommandAvailability[u".uno:SubScript"_ustr] = bEnableUnoCommands; |
| 689 |
m_aCommandAvailability[u".uno:Spacing"_ustr] = bEnableUnoCommands; |
| 690 |
m_aCommandAvailability[u".uno:ResetAttributes"_ustr] = bEnableUnoCommands; |
| 691 |
|
| 692 |
if (!bTitleIsInEditMode) |
| 693 |
{ |
| 694 |
// at default they are not filled in the sidebar |
| 695 |
m_aCommandArguments[u".uno:CharFontName"_ustr] <<= false; |
| 696 |
m_aCommandArguments[u".uno:FontHeight"_ustr] <<= false; |
| 697 |
m_aCommandArguments[u".uno:Bold"_ustr] <<= false; |
| 698 |
m_aCommandArguments[u".uno:Strikeout"_ustr] <<= false; |
| 699 |
m_aCommandArguments[u".uno:Italic"_ustr] <<= false; |
| 700 |
m_aCommandArguments[u".uno:Underline"_ustr] <<= false; |
| 701 |
m_aCommandArguments[u".uno:Shadowed"_ustr] <<= false; |
| 702 |
m_aCommandArguments[u".uno:Color"_ustr] <<= false; |
| 703 |
m_aCommandArguments[u".uno:FontColor"_ustr] <<= false; |
| 704 |
m_aCommandArguments[u".uno:SuperScript"_ustr] <<= false; |
| 705 |
m_aCommandArguments[u".uno:SubScript"_ustr] <<= false; |
| 706 |
m_aCommandArguments[u".uno:Spacing"_ustr] <<= false; |
| 707 |
m_aCommandArguments[u".uno:ResetAttributes"_ustr] <<= false; |
| 708 |
} |
| 709 |
|
| 710 |
// They are filled based on the text properties.. if there are only 1 |
| 711 |
// but only those properties that are true for the whole text |
| 712 |
try |
| 713 |
{ |
| 714 |
// if title is selected, and in edit mode, then the font panel should be disabled |
| 715 |
// enable the uno commands only if the title is not in edit mode |
| 716 |
// Todo: enable font panel here if the panel will be able to handle edited title. |
| 717 |
OUString aObjectCID = m_xChartController->getSelectionMember().getSelectedCID(); |
| 718 |
if (!aObjectCID.isEmpty() && !bTitleIsInEditMode) |
| 719 |
{ |
| 720 |
// If the selected is not title, then we should check the text properties.. |
| 721 |
// or the selected text properties? |
| 722 |
std::vector<Reference<beans::XPropertySet>> xProperties; |
| 723 |
xProperties.emplace(xProperties.end(), |
| 724 |
ObjectIdentifier::getObjectPropertySet( |
| 725 |
aObjectCID, m_xChartController->getChartModel())); |
| 726 |
|
| 727 |
if (ObjectIdentifier::getObjectType(aObjectCID) == OBJECTTYPE_TITLE) |
| 728 |
{ |
| 729 |
Reference<chart2::XTitle> xTitle(xProperties[0], uno::UNO_QUERY); |
| 730 |
if (xTitle.is()) |
| 731 |
{ |
| 732 |
const Sequence<Reference<chart2::XFormattedString>> aStrings(xTitle->getText()); |
| 733 |
xProperties.pop_back(); |
| 734 |
for (const auto& aString : aStrings) |
| 735 |
{ |
| 736 |
Reference<beans::XPropertySet> xTitlePropSet(aString, uno::UNO_QUERY); |
| 737 |
xProperties.push_back(xTitlePropSet); |
| 738 |
} |
| 739 |
} |
| 740 |
} |
| 741 |
|
| 742 |
Reference<beans::XMultiPropertySet> aMObjProps(xProperties[0], uno::UNO_QUERY); |
| 743 |
if (aMObjProps) |
| 744 |
{ |
| 745 |
awt::FontDescriptor aFont |
| 746 |
= CharacterProperties::createFontDescriptorFromPropertySet(aMObjProps); |
| 747 |
|
| 748 |
if (!aFont.Name.isEmpty()) |
| 749 |
{ |
| 750 |
if (getPropertyIfSame(xProperties, u"CharFontName"_ustr).hasValue()) |
| 751 |
{ |
| 752 |
m_aCommandArguments[u".uno:CharFontName"_ustr] <<= aFont; |
| 753 |
} |
| 754 |
} |
| 755 |
} |
| 756 |
if (frame::status::FontHeight aFontHeight; |
| 757 |
getPropertyIfSame(xProperties, u"CharHeight"_ustr) >>= aFontHeight.Height) |
| 758 |
{ |
| 759 |
// another type is needed here, so |
| 760 |
m_aCommandArguments[u".uno:FontHeight"_ustr] <<= aFontHeight; |
| 761 |
} |
| 762 |
|
| 763 |
if (float nFontWeight; |
| 764 |
getPropertyIfSame(xProperties, u"CharWeight"_ustr) >>= nFontWeight) |
| 765 |
{ |
| 766 |
bool bFontWeight = (nFontWeight > 100.0); |
| 767 |
m_aCommandArguments[u".uno:Bold"_ustr] <<= bFontWeight; |
| 768 |
} |
| 769 |
|
| 770 |
if (awt::FontSlant nFontItalic; |
| 771 |
getPropertyIfSame(xProperties, u"CharPosture"_ustr) >>= nFontItalic) |
| 772 |
{ |
| 773 |
bool bItalic = (nFontItalic == awt::FontSlant_ITALIC); |
| 774 |
m_aCommandArguments[u".uno:Italic"_ustr] <<= bItalic; |
| 775 |
} |
| 776 |
|
| 777 |
if (sal_Int16 nFontStrikeout; |
| 778 |
getPropertyIfSame(xProperties, u"CharStrikeout"_ustr) >>= nFontStrikeout) |
| 779 |
{ |
| 780 |
bool bFontStrikeout = (nFontStrikeout > 0); |
| 781 |
m_aCommandArguments[u".uno:Strikeout"_ustr] <<= bFontStrikeout; |
| 782 |
} |
| 783 |
|
| 784 |
if (sal_Int16 nFontUnderline; |
| 785 |
getPropertyIfSame(xProperties, u"CharUnderline"_ustr) >>= nFontUnderline) |
| 786 |
{ |
| 787 |
bool bFontUnderline = (nFontUnderline > 0); |
| 788 |
m_aCommandArguments[u".uno:Underline"_ustr] <<= bFontUnderline; |
| 789 |
} |
| 790 |
|
| 791 |
if (bool bShadowed; getPropertyIfSame(xProperties, u"CharShadowed"_ustr) >>= bShadowed) |
| 792 |
{ |
| 793 |
m_aCommandArguments[u".uno:Shadowed"_ustr] <<= bShadowed; |
| 794 |
} |
| 795 |
|
| 796 |
// Font color is not set in panel... it is just enabled to use |
| 797 |
m_aCommandArguments[u".uno:Color"_ustr] <<= false; |
| 798 |
m_aCommandArguments[u".uno:FontColor"_ustr] <<= false; |
| 799 |
|
| 800 |
if (sal_Int32 nCharEscapement; |
| 801 |
getPropertyIfSame(xProperties, u"CharEscapement"_ustr) >>= nCharEscapement) |
| 802 |
{ |
| 803 |
m_aCommandArguments[u".uno:SuperScript"_ustr] <<= (nCharEscapement > 0); |
| 804 |
m_aCommandArguments[u".uno:SubScript"_ustr] <<= (nCharEscapement < 0); |
| 805 |
} |
| 806 |
|
| 807 |
// Font Spacing is not set in panel... it is just enabled to use |
| 808 |
m_aCommandArguments[u".uno:Spacing"_ustr] <<= false; |
| 809 |
} |
| 810 |
} |
| 811 |
catch (const uno::Exception&) |
| 812 |
{ |
| 813 |
TOOLS_WARN_EXCEPTION("chart2", ""); |
| 814 |
} |
| 815 |
|
| 816 |
// axes |
| 817 |
m_aCommandAvailability[ u".uno:DiagramAxisX"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxis; |
| 818 |
m_aCommandAvailability[ u".uno:DiagramAxisY"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxis; |
| 819 |
m_aCommandAvailability[ u".uno:DiagramAxisZ"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxis; |
| 820 |
m_aCommandAvailability[ u".uno:DiagramAxisA"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasAAxis; |
| 821 |
m_aCommandAvailability[ u".uno:DiagramAxisB"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasBAxis; |
| 822 |
m_aCommandAvailability[ u".uno:DiagramAxisAll"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyAxis(); |
| 823 |
|
| 824 |
// grids |
| 825 |
// note: x and y are swapped in the commands! |
| 826 |
m_aCommandAvailability[ u".uno:DiagramGridYMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainXGrid; |
| 827 |
m_aCommandAvailability[ u".uno:DiagramGridXMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainYGrid; |
| 828 |
m_aCommandAvailability[ u".uno:DiagramGridZMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainZGrid; |
| 829 |
m_aCommandAvailability[ u".uno:DiagramGridYHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpXGrid; |
| 830 |
m_aCommandAvailability[ u".uno:DiagramGridXHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpYGrid; |
| 831 |
m_aCommandAvailability[ u".uno:DiagramGridZHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpZGrid; |
| 832 |
m_aCommandAvailability[ u".uno:DiagramGridAll"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyGrid(); |
| 833 |
|
| 834 |
// series arrangement |
| 835 |
m_aCommandAvailability[ u".uno:Forward"_ustr ] = ( bShapeContext ? isShapeControllerCommandAvailable( u".uno:Forward"_ustr ) : |
| 836 |
( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesForward && bEnableDataTableDialog ) ); |
| 837 |
m_aCommandAvailability[ u".uno:Backward"_ustr ] = ( bShapeContext ? isShapeControllerCommandAvailable( u".uno:Backward"_ustr ) : |
| 838 |
( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesBackward && bEnableDataTableDialog ) ); |
| 839 |
|
| 840 |
m_aCommandAvailability[ u".uno:InsertDataLabels"_ustr ] = bIsWritable; |
| 841 |
m_aCommandAvailability[ u".uno:InsertDataLabel"_ustr ] = bIsWritable; |
| 842 |
m_aCommandAvailability[ u".uno:InsertMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddMeanValue; |
| 843 |
m_aCommandAvailability[ u".uno:InsertTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendline; |
| 844 |
const bool bInsertTrendlineEquation = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendlineEquation; |
| 845 |
m_aCommandAvailability[ u".uno:InsertTrendlineEquation"_ustr ] = bInsertTrendlineEquation; |
| 846 |
m_aCommandAvailability[ u".uno:InsertTrendlineEquationAndR2"_ustr ] = bInsertTrendlineEquation && m_apControllerState->bMayAddR2Value; |
| 847 |
m_aCommandAvailability[ u".uno:InsertR2Value"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value |
| 848 |
&& !m_apControllerState->bMayAddTrendlineEquation; |
| 849 |
m_aCommandAvailability[ u".uno:DeleteR2Value"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteR2Value; |
| 850 |
|
| 851 |
m_aCommandAvailability[ u".uno:InsertXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddXErrorBars; |
| 852 |
m_aCommandAvailability[ u".uno:InsertYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddYErrorBars; |
| 853 |
|
| 854 |
m_aCommandAvailability[ u".uno:DeleteDataLabels"_ustr ] = bIsWritable; |
| 855 |
m_aCommandAvailability[ u".uno:DeleteDataLabel"_ustr ] = bIsWritable; |
| 856 |
m_aCommandAvailability[ u".uno:DeleteTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendline; |
| 857 |
m_aCommandAvailability[ u".uno:DeleteTrendlineEquation"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendlineEquation; |
| 858 |
m_aCommandAvailability[ u".uno:DeleteMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteMeanValue; |
| 859 |
m_aCommandAvailability[ u".uno:DeleteXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteXErrorBars; |
| 860 |
m_aCommandAvailability[ u".uno:DeleteYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteYErrorBars; |
| 861 |
|
| 862 |
m_aCommandAvailability[ u".uno:ResetDataPoint"_ustr ] = bIsWritable; |
| 863 |
m_aCommandAvailability[ u".uno:ResetAllDataPoints"_ustr ] = bIsWritable; |
| 864 |
|
| 865 |
m_aCommandAvailability[ u".uno:InsertAxis"_ustr ] = bIsWritable; |
| 866 |
m_aCommandAvailability[ u".uno:DeleteAxis"_ustr ] = bIsWritable; |
| 867 |
m_aCommandAvailability[ u".uno:InsertAxisTitle"_ustr ] = bIsWritable; |
| 868 |
m_aCommandAvailability[ u".uno:FormatMajorGrid"_ustr ] = bIsWritable; |
| 869 |
m_aCommandAvailability[ u".uno:InsertMajorGrid"_ustr ] = bIsWritable; |
| 870 |
m_aCommandAvailability[ u".uno:DeleteMajorGrid"_ustr ] = bIsWritable; |
| 871 |
m_aCommandAvailability[ u".uno:FormatMinorGrid"_ustr ] = bIsWritable; |
| 872 |
m_aCommandAvailability[ u".uno:InsertMinorGrid"_ustr ] = bIsWritable; |
| 873 |
m_aCommandAvailability[ u".uno:DeleteMinorGrid"_ustr ] = bIsWritable; |
| 874 |
|
| 875 |
// data table |
| 876 |
m_aCommandAvailability[ u".uno:InsertDataTable"_ustr ] = bIsWritable && bModelStateIsValid && !m_apModelState->bDataTable; |
| 877 |
m_aCommandAvailability[ u".uno:DeleteDataTable"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bDataTable; |
| 878 |
} |
| 879 |
|
| 880 |
bool ControllerCommandDispatch::commandAvailable(const OUString& rCommand) const |
| 881 |
{ |
| 882 |
std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.find( rCommand )); |
| 883 |
if( aIt != m_aCommandAvailability.end()) |
| 884 |
return aIt->second; |
| 885 |
SAL_WARN("chart2", "commandAvailable: command not in availability map:" << rCommand); |
| 886 |
return false; |
| 887 |
} |
| 888 |
|
| 889 |
bool ControllerCommandDispatch::commandHandled(const OUString& rCommand) const |
| 890 |
{ |
| 891 |
return m_aCommandAvailability.contains(rCommand); |
| 892 |
} |
| 893 |
|
| 894 |
bool ControllerCommandDispatch::isShapeControllerCommandAvailable( const OUString& rCommand ) |
| 895 |
{ |
| 896 |
ShapeController* pShapeController(nullptr); |
| 897 |
{ |
| 898 |
SolarMutexGuard g; |
| 899 |
if (m_pDispatchContainer) |
| 900 |
pShapeController = m_pDispatchContainer->getShapeController(); |
| 901 |
} |
| 902 |
if ( pShapeController ) |
| 903 |
{ |
| 904 |
FeatureState aState( pShapeController->getState( rCommand ) ); |
| 905 |
return aState.bEnabled; |
| 906 |
} |
| 907 |
return false; |
| 908 |
} |
| 909 |
|
| 910 |
void ControllerCommandDispatch::fireStatusEvent( |
| 911 |
const OUString & rURL, |
| 912 |
const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ ) |
| 913 |
{ |
| 914 |
if (rURL.isEmpty() || rURL == ".uno:ChartElementSelector") |
| 915 |
{ |
| 916 |
uno::Any aArg; |
| 917 |
aArg <<= Reference< frame::XController >(m_xChartController); |
| 918 |
fireStatusEventForURL( u".uno:ChartElementSelector"_ustr, aArg, true, xSingleListener ); |
| 919 |
} |
| 920 |
|
| 921 |
if( rURL.isEmpty() ) |
| 922 |
{ |
| 923 |
for (auto const& elem : m_aCommandAvailability) |
| 924 |
fireStatusEventForURLImpl( elem.first, xSingleListener ); |
| 925 |
} |
| 926 |
else if (m_aCommandAvailability.contains(rURL)) |
| 927 |
fireStatusEventForURLImpl( rURL, xSingleListener ); |
| 928 |
} |
| 929 |
|
| 930 |
// ____ XDispatch ____ |
| 931 |
void SAL_CALL ControllerCommandDispatch::dispatch( |
| 932 |
const util::URL& URL, |
| 933 |
const Sequence< beans::PropertyValue >& Arguments ) |
| 934 |
{ |
| 935 |
if( commandAvailable( URL.Complete )) |
| 936 |
m_xDispatch->dispatch( URL, Arguments ); |
| 937 |
} |
| 938 |
|
| 939 |
// ____ WeakComponentImplHelperBase ____ |
| 940 |
/// is called when this is disposed |
| 941 |
void ControllerCommandDispatch::disposing(std::unique_lock<std::mutex>& /*rGuard*/) |
| 942 |
{ |
| 943 |
m_xChartController.clear(); |
| 944 |
m_xDispatch.clear(); |
| 945 |
m_xSelectionSupplier.clear(); |
| 946 |
} |
| 947 |
|
| 948 |
// ____ XEventListener (base of XModifyListener) ____ |
| 949 |
void SAL_CALL ControllerCommandDispatch::disposing( const lang::EventObject& /* Source */ ) |
| 950 |
{ |
| 951 |
m_xChartController.clear(); |
| 952 |
m_xDispatch.clear(); |
| 953 |
m_xSelectionSupplier.clear(); |
| 954 |
} |
| 955 |
|
| 956 |
// ____ XModifyListener ____ |
| 957 |
void SAL_CALL ControllerCommandDispatch::modified( const lang::EventObject& aEvent ) |
| 958 |
{ |
| 959 |
bool bUpdateCommandAvailability = false; |
| 960 |
|
| 961 |
// Update the "ModelState" Struct. |
| 962 |
if( m_apModelState && m_xChartController.is()) |
| 963 |
{ |
| 964 |
m_apModelState->update( m_xChartController->getChartModel()); |
| 965 |
bUpdateCommandAvailability = true; |
| 966 |
} |
| 967 |
|
| 968 |
// Update the "ControllerState" Struct. |
| 969 |
if( m_apControllerState && m_xChartController.is()) |
| 970 |
{ |
| 971 |
m_apControllerState->update( m_xChartController, m_xChartController->getChartModel()); |
| 972 |
bUpdateCommandAvailability = true; |
| 973 |
} |
| 974 |
|
| 975 |
if( bUpdateCommandAvailability ) |
| 976 |
updateCommandAvailability(); |
| 977 |
|
| 978 |
if (comphelper::LibreOfficeKit::isActive()) |
| 979 |
{ |
| 980 |
if (SfxViewShell* pViewShell = SfxViewShell::Current()) |
| 981 |
if (SfxObjectShell* pObjSh = pViewShell->GetObjectShell()) |
| 982 |
pObjSh->SetModified(); |
| 983 |
} |
| 984 |
|
| 985 |
CommandDispatch::modified( aEvent ); |
| 986 |
} |
| 987 |
|
| 988 |
// ____ XSelectionChangeListener ____ |
| 989 |
void SAL_CALL ControllerCommandDispatch::selectionChanged( const lang::EventObject& aEvent ) |
| 990 |
{ |
| 991 |
// Update the "ControllerState" Struct. |
| 992 |
if( m_apControllerState && m_xChartController.is()) |
| 993 |
{ |
| 994 |
m_apControllerState->update( m_xChartController, m_xChartController->getChartModel()); |
| 995 |
updateCommandAvailability(); |
| 996 |
} |
| 997 |
|
| 998 |
CommandDispatch::modified( aEvent ); |
| 999 |
} |
| 1000 |
|
| 1001 |
} // namespace chart |
| 1002 |
|
| 1003 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |