tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / main / ControllerCommandDispatch.cxx
blobc732fae2c49af837a1417d63c843ed00eaaf07d2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ControllerCommandDispatch.hxx"
21 #include <ChartModel.hxx>
22 #include <Diagram.hxx>
23 #include <Axis.hxx>
24 #include <AxisHelper.hxx>
25 #include <TitleHelper.hxx>
26 #include <LegendHelper.hxx>
27 #include <ObjectIdentifier.hxx>
28 #include <ChartType.hxx>
29 #include <ChartTypeHelper.hxx>
30 #include <ChartController.hxx>
31 #include <RegressionCurveHelper.hxx>
32 #include <DataSeries.hxx>
33 #include <DataSeriesHelper.hxx>
34 #include <StatisticsHelper.hxx>
35 #include <ReferenceSizeProvider.hxx>
36 #include "ShapeController.hxx"
38 #include <vcl/svapp.hxx>
39 #include <sal/log.hxx>
40 #include <comphelper/diagnose_ex.hxx>
41 #include <comphelper/lok.hxx>
42 #include <sfx2/viewsh.hxx>
43 #include <sfx2/objsh.hxx>
45 #include <com/sun/star/chart2/XRegressionCurve.hpp>
46 #include <com/sun/star/chart2/XDataProviderAccess.hpp>
48 // only needed until #i68864# is fixed
49 #include <com/sun/star/frame/XLayoutManager.hpp>
51 using namespace ::com::sun::star;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::Sequence;
56 namespace
58 bool lcl_isStatusBarVisible( const Reference< frame::XController > & xController )
60 bool bIsStatusBarVisible = false;
61 // Status-Bar visible, workaround: this should not be necessary. @todo:
62 // remove when Issue #i68864# is fixed
63 if( xController.is())
65 Reference< beans::XPropertySet > xPropSet( xController->getFrame(), uno::UNO_QUERY );
66 if( xPropSet.is() )
68 uno::Reference< css::frame::XLayoutManager > xLayoutManager;
69 xPropSet->getPropertyValue( u"LayoutManager"_ustr ) >>= xLayoutManager;
70 if ( xLayoutManager.is() )
71 bIsStatusBarVisible = xLayoutManager->isElementVisible( u"private:resource/statusbar/statusbar"_ustr );
74 return bIsStatusBarVisible;
77 } // anonymous namespace
79 namespace chart
82 namespace impl
85 /// Constants for moving the series.
86 namespace {
87 bool const MOVE_SERIES_FORWARD = true;
88 bool const MOVE_SERIES_BACKWARD = false;
91 /** Represents the current state of the controller (needed for issue 63017).
93 You can set the state by calling update(). After this call the state is
94 preserved in this class until the next call to update().
96 This is useful, not to say necessary, for enabling and disabling of menu
97 entries (e.g. format>arrangement). As the status requests are sent very
98 frequently it would be impossible, from a performance point of view, to
99 query the current status every time directly at the model. So this class
100 serves as a cache for the state.
102 struct ControllerState
104 ControllerState();
106 void update( const Reference< frame::XController > & xController,
107 const rtl::Reference<::chart::ChartModel> & xModel );
109 // -- State variables -------
110 bool bHasSelectedObject;
111 bool bIsPositionableObject;
112 bool bIsTextObject;
113 bool bIsDeleteableObjectSelected;
114 bool bIsFormateableObjectSelected;
116 // May the selected series be moved forward or backward (cf
117 // format>arrangement).
118 bool bMayMoveSeriesForward;
119 bool bMayMoveSeriesBackward;
121 // trendlines
122 bool bMayAddMenuTrendline;
123 bool bMayAddTrendline;
124 bool bMayAddTrendlineEquation;
125 bool bMayAddR2Value;
126 bool bMayAddMeanValue;
127 bool bMayAddXErrorBars;
128 bool bMayAddYErrorBars;
130 bool bMayDeleteTrendline;
131 bool bMayDeleteTrendlineEquation;
132 bool bMayDeleteR2Value;
133 bool bMayDeleteMeanValue;
134 bool bMayDeleteXErrorBars;
135 bool bMayDeleteYErrorBars;
137 bool bMayFormatTrendline;
138 bool bMayFormatTrendlineEquation;
139 bool bMayFormatMeanValue;
140 bool bMayFormatXErrorBars;
141 bool bMayFormatYErrorBars;
144 ControllerState::ControllerState() :
145 bHasSelectedObject( false ),
146 bIsPositionableObject( false ),
147 bIsTextObject(false),
148 bIsDeleteableObjectSelected(false),
149 bIsFormateableObjectSelected(false),
150 bMayMoveSeriesForward( false ),
151 bMayMoveSeriesBackward( false ),
152 bMayAddMenuTrendline( false ),
153 bMayAddTrendline( false ),
154 bMayAddTrendlineEquation( false ),
155 bMayAddR2Value( false ),
156 bMayAddMeanValue( false ),
157 bMayAddXErrorBars( false ),
158 bMayAddYErrorBars( false ),
159 bMayDeleteTrendline( false ),
160 bMayDeleteTrendlineEquation( false ),
161 bMayDeleteR2Value( false ),
162 bMayDeleteMeanValue( false ),
163 bMayDeleteXErrorBars( false ),
164 bMayDeleteYErrorBars( false ),
165 bMayFormatTrendline( false ),
166 bMayFormatTrendlineEquation( false ),
167 bMayFormatMeanValue( false ),
168 bMayFormatXErrorBars( false ),
169 bMayFormatYErrorBars( false )
172 void ControllerState::update(
173 const Reference< frame::XController > & xController,
174 const rtl::Reference<::chart::ChartModel> & xModel )
176 Reference< view::XSelectionSupplier > xSelectionSupplier(
177 xController, uno::UNO_QUERY );
179 // Update ControllerState variables.
180 if( !xSelectionSupplier.is())
181 return;
183 uno::Any aSelObj( xSelectionSupplier->getSelection() );
184 ObjectIdentifier aSelOID( aSelObj );
185 const OUString& aSelObjCID( aSelOID.getObjectCID() );
187 bHasSelectedObject = aSelOID.isValid();
189 ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
191 bIsPositionableObject = (aObjectType != OBJECTTYPE_DATA_POINT) && aSelOID.isDragableObject();
192 bIsTextObject = aObjectType == OBJECTTYPE_TITLE;
194 rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
195 bIsFormateableObjectSelected = bHasSelectedObject && aSelOID.isAutoGeneratedObject();
196 if( aObjectType==OBJECTTYPE_DIAGRAM || aObjectType==OBJECTTYPE_DIAGRAM_WALL || aObjectType==OBJECTTYPE_DIAGRAM_FLOOR )
197 bIsFormateableObjectSelected = xDiagram->isSupportingFloorAndWall();
199 rtl::Reference< DataSeries > xGivenDataSeries =
200 ObjectIdentifier::getDataSeriesForCID(
201 aSelObjCID, xModel );
203 bIsDeleteableObjectSelected = ChartController::isObjectDeleteable( aSelObj );
205 bMayMoveSeriesForward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram && xDiagram->isSeriesMoveable(
206 xGivenDataSeries,
207 MOVE_SERIES_FORWARD );
209 bMayMoveSeriesBackward = (aObjectType!=OBJECTTYPE_DATA_POINT) && xDiagram && xDiagram->isSeriesMoveable(
210 xGivenDataSeries,
211 MOVE_SERIES_BACKWARD );
213 bMayAddMenuTrendline = false;
214 bMayAddTrendline = false;
215 bMayAddTrendlineEquation = false;
216 bMayAddR2Value = false;
217 bMayAddMeanValue = false;
218 bMayAddXErrorBars = false;
219 bMayAddYErrorBars = false;
220 bMayDeleteTrendline = false;
221 bMayDeleteTrendlineEquation = false;
222 bMayDeleteR2Value = false;
223 bMayDeleteMeanValue = false;
224 bMayDeleteXErrorBars = false;
225 bMayDeleteYErrorBars = false;
226 bMayFormatTrendline = false;
227 bMayFormatTrendlineEquation = false;
228 bMayFormatMeanValue = false;
229 bMayFormatXErrorBars = false;
230 bMayFormatYErrorBars = false;
231 if( !bHasSelectedObject )
232 return;
234 if( xGivenDataSeries.is())
236 bMayAddMenuTrendline = true;
237 sal_Int32 nDimensionCount = xDiagram->getDimension();
238 rtl::Reference< ::chart::ChartType > xFirstChartType(
239 DataSeriesHelper::getChartTypeOfSeries( xGivenDataSeries, xDiagram ));
241 // trend lines/mean value line
242 if( (aObjectType == OBJECTTYPE_DATA_SERIES || aObjectType == OBJECTTYPE_DATA_POINT)
243 && ChartTypeHelper::isSupportingRegressionProperties( xFirstChartType, nDimensionCount ))
245 // Trendline
246 bMayAddTrendline = true;
248 // Mean Value
249 bMayFormatMeanValue = bMayDeleteMeanValue = RegressionCurveHelper::hasMeanValueLine( xGivenDataSeries );
250 bMayAddMeanValue = ! bMayDeleteMeanValue;
253 // error bars
254 if( (aObjectType == OBJECTTYPE_DATA_SERIES || aObjectType == OBJECTTYPE_DATA_POINT)
255 && ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType, nDimensionCount ))
257 bMayFormatXErrorBars = bMayDeleteXErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries, false );
258 bMayAddXErrorBars = ! bMayDeleteXErrorBars;
260 bMayFormatYErrorBars = bMayDeleteYErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries );
261 bMayAddYErrorBars = ! bMayDeleteYErrorBars;
265 if( aObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
266 bMayFormatMeanValue = true;
268 if( aObjectType == OBJECTTYPE_DATA_ERRORS_X)
269 bMayFormatXErrorBars = true;
271 if( aObjectType == OBJECTTYPE_DATA_ERRORS_Y )
272 bMayFormatYErrorBars = true;
274 if( aObjectType == OBJECTTYPE_DATA_CURVE )
276 bMayFormatTrendline = true;
277 bMayDeleteTrendline = true;
278 uno::Reference< chart2::XRegressionCurve > xRegCurve(
279 ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ), uno::UNO_QUERY );
281 // Trendline Equation
282 bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve );
283 bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation;
284 bMayAddR2Value = RegressionCurveHelper::MayHaveCorrelationCoefficient( xRegCurve ) && bMayAddTrendlineEquation;
286 else if( aObjectType == OBJECTTYPE_DATA_CURVE_EQUATION )
288 bMayFormatTrendlineEquation = true;
289 bool bHasR2Value = false;
290 bool bMayHaveR2 = true;
293 uno::Reference< beans::XPropertySet > xEquationProperties =
294 ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel );
295 if( xEquationProperties.is() )
297 xEquationProperties->getPropertyValue( u"ShowCorrelationCoefficient"_ustr ) >>= bHasR2Value;
298 xEquationProperties->getPropertyValue( u"MayHaveCorrelationCoefficient"_ustr ) >>= bMayHaveR2;
301 catch(const uno::RuntimeException&)
303 TOOLS_WARN_EXCEPTION("chart2", "" );
305 bMayAddR2Value = !bHasR2Value && bMayHaveR2;
306 bMayDeleteR2Value = bHasR2Value;
310 /** Represents the current state of the model.
312 You can set the state by calling update(). After this call the state is
313 preserved in this class until the next call to update().
315 This is useful, not to say necessary, for enabling and disabling of menu
316 entries and toolbar icons. As the status requests are sent very frequently
317 it would be impossible, from a performance point of view, to query the
318 current status every time directly at the model. So this class serves as a
319 cache for the state.
321 struct ModelState
323 ModelState();
325 void update( const rtl::Reference<::chart::ChartModel> & xModel );
327 bool HasAnyAxis() const;
328 bool HasAnyGrid() const;
329 bool HasAnyTitle() const;
331 bool bIsReadOnly;
332 bool bIsThreeD;
333 bool bHasOwnData;
334 bool bHasDataFromPivotTable;
336 bool bHasMainTitle;
337 bool bHasSubTitle;
338 bool bHasXAxisTitle;
339 bool bHasYAxisTitle;
340 bool bHasZAxisTitle;
341 bool bHasSecondaryXAxisTitle;
342 bool bHasSecondaryYAxisTitle;
344 bool bHasXAxis;
345 bool bHasYAxis;
346 bool bHasZAxis;
347 bool bHasAAxis;
348 bool bHasBAxis;
350 bool bHasMainXGrid;
351 bool bHasMainYGrid;
352 bool bHasMainZGrid;
353 bool bHasHelpXGrid;
354 bool bHasHelpYGrid;
355 bool bHasHelpZGrid;
357 bool bHasAutoScaledText;
358 bool bHasLegend;
359 bool bHasWall;
360 bool bHasFloor;
362 bool bSupportsStatistics;
363 bool bSupportsAxes;
365 bool bDataTable = false;
368 ModelState::ModelState() :
369 bIsReadOnly(true),
370 bIsThreeD(false),
371 bHasOwnData(false),
372 bHasDataFromPivotTable(false),
373 bHasMainTitle(false),
374 bHasSubTitle(false),
375 bHasXAxisTitle(false),
376 bHasYAxisTitle(false),
377 bHasZAxisTitle(false),
378 bHasSecondaryXAxisTitle(false),
379 bHasSecondaryYAxisTitle(false),
380 bHasXAxis(false),
381 bHasYAxis(false),
382 bHasZAxis(false),
383 bHasAAxis(false),
384 bHasBAxis(false),
385 bHasMainXGrid(false),
386 bHasMainYGrid(false),
387 bHasMainZGrid(false),
388 bHasHelpXGrid(false),
389 bHasHelpYGrid(false),
390 bHasHelpZGrid(false),
391 bHasAutoScaledText(false),
392 bHasLegend(false),
393 bHasWall(false),
394 bHasFloor(false),
395 bSupportsStatistics(false),
396 bSupportsAxes(false)
399 void ModelState::update( const rtl::Reference<::chart::ChartModel> & xModel )
401 rtl::Reference< Diagram > xDiagram = xModel->getFirstChartDiagram();
403 bIsReadOnly = xModel->isReadonly();
405 sal_Int32 nDimensionCount = 0;
406 if (xDiagram)
407 nDimensionCount = xDiagram->getDimension();
409 rtl::Reference< ChartType > xFirstChartType;
410 if (xDiagram)
411 xFirstChartType = xDiagram->getChartTypeByIndex( 0 );
412 bSupportsStatistics = ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType, nDimensionCount );
413 bSupportsAxes = ChartTypeHelper::isSupportingMainAxis( xFirstChartType, nDimensionCount, 0 );
415 bIsThreeD = (nDimensionCount == 3);
416 if (xModel.is())
418 bHasOwnData = xModel->hasInternalDataProvider();
419 bHasDataFromPivotTable = !bHasOwnData && xModel->isDataFromPivotTable();
422 bHasMainTitle = TitleHelper::getTitle( TitleHelper::MAIN_TITLE, xModel ).is();
423 bHasSubTitle = TitleHelper::getTitle( TitleHelper::SUB_TITLE, xModel ).is();
424 bHasXAxisTitle = TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, xModel ).is();
425 bHasYAxisTitle = TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, xModel ).is();
426 bHasZAxisTitle = TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE, xModel ).is();
427 bHasSecondaryXAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xModel ).is();
428 bHasSecondaryYAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xModel ).is();
430 bHasXAxis = bSupportsAxes && AxisHelper::getAxis( 0, true, xDiagram ).is();
431 bHasYAxis = bSupportsAxes && AxisHelper::getAxis( 1, true, xDiagram ).is();
432 bHasZAxis = bSupportsAxes && AxisHelper::getAxis( 2, true, xDiagram ).is();
433 bHasAAxis = bSupportsAxes && AxisHelper::getAxis( 0, false, xDiagram ).is();
434 bHasBAxis = bSupportsAxes && AxisHelper::getAxis( 1, false, xDiagram ).is();
436 bHasMainXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, true, xDiagram );
437 bHasMainYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, true, xDiagram );
438 bHasMainZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, true, xDiagram );
439 bHasHelpXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, false, xDiagram );
440 bHasHelpYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, false, xDiagram );
441 bHasHelpZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, false, xDiagram );
443 bHasAutoScaledText =
444 (ReferenceSizeProvider::getAutoResizeState( xModel ) ==
445 ReferenceSizeProvider::AUTO_RESIZE_YES);
447 bHasLegend = LegendHelper::hasLegend( xDiagram );
448 bHasWall = xDiagram && xDiagram->isSupportingFloorAndWall();
449 bHasFloor = bHasWall && bIsThreeD;
451 bDataTable = xDiagram.is() && xDiagram->getDataTable().is();
454 bool ModelState::HasAnyAxis() const
456 return bHasXAxis || bHasYAxis || bHasZAxis || bHasAAxis || bHasBAxis;
459 bool ModelState::HasAnyGrid() const
461 return bHasMainXGrid || bHasMainYGrid || bHasMainZGrid ||
462 bHasHelpXGrid || bHasHelpYGrid || bHasHelpZGrid;
465 bool ModelState::HasAnyTitle() const
467 return bHasMainTitle || bHasSubTitle || bHasXAxisTitle || bHasYAxisTitle || bHasZAxisTitle || bHasSecondaryXAxisTitle || bHasSecondaryYAxisTitle;
470 } // namespace impl
472 ControllerCommandDispatch::ControllerCommandDispatch(
473 const Reference< uno::XComponentContext > & xContext,
474 ChartController* pController, CommandDispatchContainer* pContainer ) :
475 impl::ControllerCommandDispatch_Base( xContext ),
476 m_xChartController( pController ),
477 m_xSelectionSupplier( Reference< view::XSelectionSupplier >( pController ) ),
478 m_xDispatch( Reference< frame::XDispatch >( pController ) ),
479 m_apModelState( new impl::ModelState() ),
480 m_apControllerState( new impl::ControllerState() ),
481 m_pDispatchContainer( pContainer )
485 ControllerCommandDispatch::~ControllerCommandDispatch()
489 void ControllerCommandDispatch::initialize()
491 if( !m_xChartController.is())
492 return;
494 rtl::Reference<::chart::ChartModel> xModel( m_xChartController->getChartModel());
495 OSL_ASSERT( xModel.is());
496 if( xModel.is())
497 xModel->addModifyListener( this );
499 // Listen selection modifications (Arrangement feature - issue 63017).
500 if( m_xSelectionSupplier.is() )
501 m_xSelectionSupplier->addSelectionChangeListener( this );
503 if( m_apModelState && xModel.is())
504 m_apModelState->update( xModel );
506 if( m_apControllerState && xModel.is())
507 m_apControllerState->update( m_xChartController, xModel );
509 updateCommandAvailability();
512 void ControllerCommandDispatch::fireStatusEventForURLImpl(
513 const OUString & rURL,
514 const Reference< frame::XStatusListener > & xSingleListener )
516 std::map< OUString, uno::Any >::const_iterator aArgIt( m_aCommandArguments.find( rURL ));
517 if( aArgIt != m_aCommandArguments.end())
518 fireStatusEventForURL( rURL, aArgIt->second, commandAvailable( rURL ), xSingleListener );
519 else
520 fireStatusEventForURL( rURL, uno::Any(), commandAvailable( rURL ), xSingleListener );
523 void ControllerCommandDispatch::updateCommandAvailability()
525 bool bModelStateIsValid = (m_apModelState != nullptr);
526 bool bControllerStateIsValid = (m_apControllerState != nullptr);
527 // Model and controller states exist.
528 OSL_ASSERT( bModelStateIsValid );
529 OSL_ASSERT( bControllerStateIsValid );
531 // read-only
532 bool bIsWritable = bModelStateIsValid && (! m_apModelState->bIsReadOnly);
533 bool bShapeContext = m_xChartController.is() && m_xChartController->isShapeContext();
534 bool bIsTextEdit = m_xChartController.is() && m_xChartController->IsTextEdit();
536 bool bEnableDataTableDialog = false;
537 bool bCanCreateDataProvider = false;
539 if ( m_xChartController.is() )
541 Reference< beans::XPropertySet > xProps( m_xChartController->getModel(), uno::UNO_QUERY );
542 if ( xProps.is() )
546 xProps->getPropertyValue(u"EnableDataTableDialog"_ustr) >>= bEnableDataTableDialog;
548 catch( const uno::Exception& )
550 TOOLS_WARN_EXCEPTION("chart2", "" );
554 rtl::Reference< ChartModel > xChartModel = m_xChartController->getChartModel();
555 OSL_ENSURE(xChartModel.is(), "Invalid XChartDocument");
556 if ( xChartModel.is() )
558 css::uno::Reference< css::chart2::XDataProviderAccess > xCreatorDoc(xChartModel->getParent(), uno::UNO_QUERY);
559 bCanCreateDataProvider = xCreatorDoc.is();
563 // edit commands
564 m_aCommandAvailability[ u".uno:Cut"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsDeleteableObjectSelected;
565 m_aCommandAvailability[ u".uno:Copy"_ustr ] = bControllerStateIsValid && m_apControllerState->bHasSelectedObject;
566 m_aCommandAvailability[ u".uno:Paste"_ustr ] = bIsWritable;
568 // toolbar commands
569 m_aCommandAvailability[ u".uno:ToggleGridHorizontal"_ustr ] = bIsWritable;
570 m_aCommandArguments[ u".uno:ToggleGridHorizontal"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasMainYGrid;
571 m_aCommandAvailability[ u".uno:ToggleGridVertical"_ustr ] = bIsWritable;
572 m_aCommandArguments[ u".uno:ToggleGridVertical"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasMainXGrid;
574 m_aCommandAvailability[ u".uno:ToggleLegend"_ustr ] = bIsWritable;
575 m_aCommandArguments[ u".uno:ToggleLegend"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasLegend;
577 m_aCommandAvailability[ u".uno:NewArrangement"_ustr ] = bIsWritable;
578 m_aCommandAvailability[ u".uno:Update"_ustr ] = bIsWritable;
579 m_aCommandAvailability[ u".uno:DefaultColors"_ustr ] = bIsWritable;
580 m_aCommandAvailability[ u".uno:BarWidth"_ustr ] = bIsWritable;
581 m_aCommandAvailability[ u".uno:NumberOfLines"_ustr ] = bIsWritable;
582 m_aCommandAvailability[ u".uno:ArrangeRow"_ustr ] =
583 bShapeContext || ( bIsWritable && bControllerStateIsValid && ( m_apControllerState->bMayMoveSeriesForward || m_apControllerState->bMayMoveSeriesBackward ) );
585 // insert objects
586 m_aCommandAvailability[ u".uno:InsertTitles"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuTitles"_ustr ] = bIsWritable;
587 m_aCommandAvailability[ u".uno:InsertLegend"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuLegend"_ustr ] = bIsWritable;
588 m_aCommandAvailability[ u".uno:DeleteLegend"_ustr ] = bIsWritable;
589 m_aCommandAvailability[ u".uno:InsertMenuDataLabels"_ustr ] = bIsWritable;
590 m_aCommandAvailability[ u".uno:InsertRemoveAxes"_ustr ] = m_aCommandAvailability[ u".uno:InsertMenuAxes"_ustr ] = bIsWritable && m_apModelState->bSupportsAxes;
591 m_aCommandAvailability[ u".uno:InsertMenuGrids"_ustr ] = bIsWritable && m_apModelState->bSupportsAxes;
592 m_aCommandAvailability[ u".uno:InsertMenuTrendlines"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics && bControllerStateIsValid && m_apControllerState->bMayAddMenuTrendline;
593 m_aCommandAvailability[ u".uno:InsertMenuMeanValues"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics;
594 m_aCommandAvailability[ u".uno:InsertMenuXErrorBars"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics;
595 m_aCommandAvailability[ u".uno:InsertMenuYErrorBars"_ustr ] = bIsWritable && m_apModelState->bSupportsStatistics;
596 m_aCommandAvailability[ u".uno:InsertSymbol"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsTextObject;
597 m_aCommandAvailability[ u".uno:InsertMenuDataTable"_ustr ] = bIsWritable;
599 // format objects
600 bool bFormatObjectAvailable = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsFormateableObjectSelected;
601 m_aCommandAvailability[ u".uno:FormatSelection"_ustr ] = bFormatObjectAvailable && !bIsTextEdit;
602 m_aCommandAvailability[ u".uno:FontDialog"_ustr ] = (bShapeContext ? isShapeControllerCommandAvailable(u".uno:FontDialog"_ustr) :
603 bFormatObjectAvailable) && bIsTextEdit;
604 m_aCommandAvailability[ u".uno:FormatAxis"_ustr ] = bFormatObjectAvailable;
605 m_aCommandAvailability[ u".uno:FormatTitle"_ustr ] = bFormatObjectAvailable && !bIsTextEdit;
606 m_aCommandAvailability[ u".uno:FormatDataSeries"_ustr ] = bFormatObjectAvailable;
607 m_aCommandAvailability[ u".uno:FormatDataPoint"_ustr ] = bFormatObjectAvailable;
608 m_aCommandAvailability[ u".uno:FormatDataLabels"_ustr ] = bFormatObjectAvailable;
609 m_aCommandAvailability[ u".uno:FormatDataLabel"_ustr ] = bFormatObjectAvailable;
610 m_aCommandAvailability[ u".uno:FormatXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatXErrorBars;
611 m_aCommandAvailability[ u".uno:FormatYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatYErrorBars;
612 m_aCommandAvailability[ u".uno:FormatMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatMeanValue;
613 m_aCommandAvailability[ u".uno:FormatTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendline;
614 m_aCommandAvailability[ u".uno:FormatTrendlineEquation"_ustr ] = bFormatObjectAvailable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendlineEquation;
615 m_aCommandAvailability[ u".uno:FormatStockLoss"_ustr ] = bFormatObjectAvailable;
616 m_aCommandAvailability[ u".uno:FormatStockGain"_ustr ] = bFormatObjectAvailable;
618 m_aCommandAvailability[ u".uno:DiagramType"_ustr ] = bIsWritable;
619 m_aCommandAvailability[ u".uno:Legend"_ustr ] = bIsWritable && m_apModelState->bHasLegend;
620 m_aCommandAvailability[ u".uno:DiagramWall"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasWall;
621 m_aCommandAvailability[ u".uno:DiagramArea"_ustr ] = bIsWritable;
623 m_aCommandAvailability[ u".uno:TransformDialog"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bHasSelectedObject && m_apControllerState->bIsPositionableObject;
625 // 3d commands
626 m_aCommandAvailability[ u".uno:View3D"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bIsThreeD;
627 m_aCommandAvailability[ u".uno:DiagramFloor"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasFloor;
629 //some more format commands with different ui text
630 m_aCommandAvailability[ u".uno:FormatWall"_ustr ] = m_aCommandAvailability[ u".uno:DiagramWall"_ustr ];
631 m_aCommandAvailability[ u".uno:FormatFloor"_ustr ] = m_aCommandAvailability[ u".uno:DiagramFloor"_ustr ];
632 m_aCommandAvailability[ u".uno:FormatChartArea"_ustr ] = m_aCommandAvailability[ u".uno:DiagramArea"_ustr ];
633 m_aCommandAvailability[ u".uno:FormatLegend"_ustr ] = m_aCommandAvailability[ u".uno:Legend"_ustr ];
635 // depending on own data and ability to create new data provider
636 m_aCommandAvailability[u".uno:DataRanges"_ustr] = bIsWritable && bModelStateIsValid && !m_apModelState->bHasDataFromPivotTable
637 && ((m_apModelState->bHasOwnData && bCanCreateDataProvider) || !m_apModelState->bHasOwnData);
638 m_aCommandAvailability[ u".uno:DiagramData"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData && bEnableDataTableDialog;
640 // titles
641 m_aCommandAvailability[ u".uno:MainTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainTitle;
642 m_aCommandAvailability[ u".uno:SubTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSubTitle;
643 m_aCommandAvailability[ u".uno:XTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxisTitle;
644 m_aCommandAvailability[ u".uno:YTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxisTitle;
645 m_aCommandAvailability[ u".uno:ZTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxisTitle;
646 m_aCommandAvailability[ u".uno:SecondaryXTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryXAxisTitle;
647 m_aCommandAvailability[ u".uno:SecondaryYTitle"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryYAxisTitle;
648 m_aCommandAvailability[ u".uno:AllTitles"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyTitle();
650 // text
651 m_aCommandAvailability[ u".uno:ScaleText"_ustr ] = bIsWritable && bModelStateIsValid ;
652 m_aCommandArguments[ u".uno:ScaleText"_ustr ] <<= bModelStateIsValid && m_apModelState->bHasAutoScaledText;
654 // axes
655 m_aCommandAvailability[ u".uno:DiagramAxisX"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxis;
656 m_aCommandAvailability[ u".uno:DiagramAxisY"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxis;
657 m_aCommandAvailability[ u".uno:DiagramAxisZ"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxis;
658 m_aCommandAvailability[ u".uno:DiagramAxisA"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasAAxis;
659 m_aCommandAvailability[ u".uno:DiagramAxisB"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasBAxis;
660 m_aCommandAvailability[ u".uno:DiagramAxisAll"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyAxis();
662 // grids
663 // note: x and y are swapped in the commands!
664 m_aCommandAvailability[ u".uno:DiagramGridYMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainXGrid;
665 m_aCommandAvailability[ u".uno:DiagramGridXMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainYGrid;
666 m_aCommandAvailability[ u".uno:DiagramGridZMain"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainZGrid;
667 m_aCommandAvailability[ u".uno:DiagramGridYHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpXGrid;
668 m_aCommandAvailability[ u".uno:DiagramGridXHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpYGrid;
669 m_aCommandAvailability[ u".uno:DiagramGridZHelp"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpZGrid;
670 m_aCommandAvailability[ u".uno:DiagramGridAll"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyGrid();
672 // series arrangement
673 m_aCommandAvailability[ u".uno:Forward"_ustr ] = ( bShapeContext ? isShapeControllerCommandAvailable( u".uno:Forward"_ustr ) :
674 ( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesForward && bEnableDataTableDialog ) );
675 m_aCommandAvailability[ u".uno:Backward"_ustr ] = ( bShapeContext ? isShapeControllerCommandAvailable( u".uno:Backward"_ustr ) :
676 ( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesBackward && bEnableDataTableDialog ) );
678 m_aCommandAvailability[ u".uno:InsertDataLabels"_ustr ] = bIsWritable;
679 m_aCommandAvailability[ u".uno:InsertDataLabel"_ustr ] = bIsWritable;
680 m_aCommandAvailability[ u".uno:InsertMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddMeanValue;
681 m_aCommandAvailability[ u".uno:InsertTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendline;
682 const bool bInsertTrendlineEquation = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendlineEquation;
683 m_aCommandAvailability[ u".uno:InsertTrendlineEquation"_ustr ] = bInsertTrendlineEquation;
684 m_aCommandAvailability[ u".uno:InsertTrendlineEquationAndR2"_ustr ] = bInsertTrendlineEquation && m_apControllerState->bMayAddR2Value;
685 m_aCommandAvailability[ u".uno:InsertR2Value"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value
686 && !m_apControllerState->bMayAddTrendlineEquation;
687 m_aCommandAvailability[ u".uno:DeleteR2Value"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteR2Value;
689 m_aCommandAvailability[ u".uno:InsertXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddXErrorBars;
690 m_aCommandAvailability[ u".uno:InsertYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddYErrorBars;
692 m_aCommandAvailability[ u".uno:DeleteDataLabels"_ustr ] = bIsWritable;
693 m_aCommandAvailability[ u".uno:DeleteDataLabel"_ustr ] = bIsWritable;
694 m_aCommandAvailability[ u".uno:DeleteTrendline"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendline;
695 m_aCommandAvailability[ u".uno:DeleteTrendlineEquation"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendlineEquation;
696 m_aCommandAvailability[ u".uno:DeleteMeanValue"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteMeanValue;
697 m_aCommandAvailability[ u".uno:DeleteXErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteXErrorBars;
698 m_aCommandAvailability[ u".uno:DeleteYErrorBars"_ustr ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteYErrorBars;
700 m_aCommandAvailability[ u".uno:ResetDataPoint"_ustr ] = bIsWritable;
701 m_aCommandAvailability[ u".uno:ResetAllDataPoints"_ustr ] = bIsWritable;
703 m_aCommandAvailability[ u".uno:InsertAxis"_ustr ] = bIsWritable;
704 m_aCommandAvailability[ u".uno:DeleteAxis"_ustr ] = bIsWritable;
705 m_aCommandAvailability[ u".uno:InsertAxisTitle"_ustr ] = bIsWritable;
706 m_aCommandAvailability[ u".uno:FormatMajorGrid"_ustr ] = bIsWritable;
707 m_aCommandAvailability[ u".uno:InsertMajorGrid"_ustr ] = bIsWritable;
708 m_aCommandAvailability[ u".uno:DeleteMajorGrid"_ustr ] = bIsWritable;
709 m_aCommandAvailability[ u".uno:FormatMinorGrid"_ustr ] = bIsWritable;
710 m_aCommandAvailability[ u".uno:InsertMinorGrid"_ustr ] = bIsWritable;
711 m_aCommandAvailability[ u".uno:DeleteMinorGrid"_ustr ] = bIsWritable;
713 // data table
714 m_aCommandAvailability[ u".uno:InsertDataTable"_ustr ] = bIsWritable && bModelStateIsValid && !m_apModelState->bDataTable;
715 m_aCommandAvailability[ u".uno:DeleteDataTable"_ustr ] = bIsWritable && bModelStateIsValid && m_apModelState->bDataTable;
718 bool ControllerCommandDispatch::commandAvailable( const OUString & rCommand )
720 std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.find( rCommand ));
721 if( aIt != m_aCommandAvailability.end())
722 return aIt->second;
723 SAL_WARN("chart2", "commandAvailable: command not in availability map:" << rCommand);
724 return false;
727 bool ControllerCommandDispatch::isShapeControllerCommandAvailable( const OUString& rCommand )
729 ShapeController* pShapeController(nullptr);
731 SolarMutexGuard g;
732 if (m_pDispatchContainer)
733 pShapeController = m_pDispatchContainer->getShapeController();
735 if ( pShapeController )
737 FeatureState aState( pShapeController->getState( rCommand ) );
738 return aState.bEnabled;
740 return false;
743 void ControllerCommandDispatch::fireStatusEvent(
744 const OUString & rURL,
745 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
747 bool bIsChartSelectorURL = rURL == ".uno:ChartElementSelector";
748 if( rURL.isEmpty() || bIsChartSelectorURL )
750 uno::Any aArg;
751 aArg <<= Reference< frame::XController >(m_xChartController);
752 fireStatusEventForURL( u".uno:ChartElementSelector"_ustr, aArg, true, xSingleListener );
755 if( rURL.isEmpty() )
757 for (auto const& elem : m_aCommandAvailability)
758 fireStatusEventForURLImpl( elem.first, xSingleListener );
760 else if( !bIsChartSelectorURL )
761 fireStatusEventForURLImpl( rURL, xSingleListener );
763 // statusbar. Should be handled by base implementation
764 // @todo: remove if Issue 68864 is fixed
765 if( rURL.isEmpty() || rURL == ".uno:StatusBarVisible" )
767 bool bIsStatusBarVisible( lcl_isStatusBarVisible( m_xChartController ));
768 fireStatusEventForURL( u".uno:StatusBarVisible"_ustr, uno::Any( bIsStatusBarVisible ), true, xSingleListener );
772 // ____ XDispatch ____
773 void SAL_CALL ControllerCommandDispatch::dispatch(
774 const util::URL& URL,
775 const Sequence< beans::PropertyValue >& Arguments )
777 if( commandAvailable( URL.Complete ))
778 m_xDispatch->dispatch( URL, Arguments );
781 // ____ WeakComponentImplHelperBase ____
782 /// is called when this is disposed
783 void ControllerCommandDispatch::disposing(std::unique_lock<std::mutex>& /*rGuard*/)
785 m_xChartController.clear();
786 m_xDispatch.clear();
787 m_xSelectionSupplier.clear();
790 // ____ XEventListener (base of XModifyListener) ____
791 void SAL_CALL ControllerCommandDispatch::disposing( const lang::EventObject& /* Source */ )
793 m_xChartController.clear();
794 m_xDispatch.clear();
795 m_xSelectionSupplier.clear();
798 // ____ XModifyListener ____
799 void SAL_CALL ControllerCommandDispatch::modified( const lang::EventObject& aEvent )
801 bool bUpdateCommandAvailability = false;
803 // Update the "ModelState" Struct.
804 if( m_apModelState && m_xChartController.is())
806 m_apModelState->update( m_xChartController->getChartModel());
807 bUpdateCommandAvailability = true;
810 // Update the "ControllerState" Struct.
811 if( m_apControllerState && m_xChartController.is())
813 m_apControllerState->update( m_xChartController, m_xChartController->getChartModel());
814 bUpdateCommandAvailability = true;
817 if( bUpdateCommandAvailability )
818 updateCommandAvailability();
820 if (comphelper::LibreOfficeKit::isActive())
822 if (SfxViewShell* pViewShell = SfxViewShell::Current())
823 if (SfxObjectShell* pObjSh = pViewShell->GetObjectShell())
824 pObjSh->SetModified();
827 CommandDispatch::modified( aEvent );
830 // ____ XSelectionChangeListener ____
831 void SAL_CALL ControllerCommandDispatch::selectionChanged( const lang::EventObject& aEvent )
833 // Update the "ControllerState" Struct.
834 if( m_apControllerState && m_xChartController.is())
836 m_apControllerState->update( m_xChartController, m_xChartController->getChartModel());
837 updateCommandAvailability();
840 CommandDispatch::modified( aEvent );
843 } // namespace chart
845 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */