1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "ChartModelHelper.hxx"
22 #include "DiagramHelper.hxx"
23 #include "AxisHelper.hxx"
24 #include "TitleHelper.hxx"
25 #include "LegendHelper.hxx"
26 #include "ObjectIdentifier.hxx"
28 #include "ChartTypeHelper.hxx"
29 #include "ChartController.hxx"
30 #include "RegressionCurveHelper.hxx"
31 #include "DataSeriesHelper.hxx"
32 #include "StatisticsHelper.hxx"
33 #include "ShapeController.hxx"
35 #include <vcl/svapp.hxx>
37 #include <com/sun/star/util/XModifyBroadcaster.hpp>
38 #include <com/sun/star/frame/XStorable.hpp>
39 #include <com/sun/star/chart2/XChartDocument.hpp>
40 #include <com/sun/star/chart2/XChartType.hpp>
41 #include <com/sun/star/chart2/XDataSeries.hpp>
42 #include <com/sun/star/chart2/XRegressionCurve.hpp>
43 #include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
45 // only needed until #i68864# is fixed
46 #include <com/sun/star/frame/XLayoutManager.hpp>
48 using namespace ::com::sun::star
;
50 using ::com::sun::star::uno::Reference
;
51 using ::com::sun::star::uno::Sequence
;
55 bool lcl_isStatusBarVisible( const Reference
< frame::XController
> & xController
)
57 bool bIsStatusBarVisible
= false;
58 // Status-Bar visible, workaround: this should not be necessary. @todo:
59 // remove when Issue #i68864# is fixed
62 Reference
< beans::XPropertySet
> xPropSet( xController
->getFrame(), uno::UNO_QUERY
);
65 uno::Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
66 xPropSet
->getPropertyValue( "LayoutManager" ) >>= xLayoutManager
;
67 if ( xLayoutManager
.is() )
68 bIsStatusBarVisible
= xLayoutManager
->isElementVisible( "private:resource/statusbar/statusbar" );
71 return bIsStatusBarVisible
;
74 } // anonymous namespace
82 /// Constants for moving the series.
84 static bool const MOVE_SERIES_FORWARD
= true;
85 static bool const MOVE_SERIES_BACKWARD
= false;
88 /** Represents the current state of the controller (needed for issue 63017).
90 You can set the state by calling update(). After this call the state is
91 preserved in this class until the next call to update().
93 This is useful, not to say necessary, for enabling and disabling of menu
94 entries (e.g. format>arrangement). As the status requests are sent very
95 frequently it would be impossible, from a performance point of view, to
96 query the current status every time directly at the model. So this class
97 serves as a cache for the state.
99 struct ControllerState
103 void update( const Reference
< frame::XController
> & xController
,
104 const Reference
< frame::XModel
> & xModel
);
106 // -- State variables -------
107 bool bHasSelectedObject
;
108 bool bIsPositionableObject
;
110 bool bIsDeleteableObjectSelected
;
111 bool bIsFormateableObjectSelected
;
113 // May the selected series be moved forward or backward (cf
114 // format>arrangement).
115 bool bMayMoveSeriesForward
;
116 bool bMayMoveSeriesBackward
;
119 bool bMayAddMenuTrendline
;
120 bool bMayAddTrendline
;
121 bool bMayAddTrendlineEquation
;
123 bool bMayAddMeanValue
;
124 bool bMayAddXErrorBars
;
125 bool bMayAddYErrorBars
;
127 bool bMayDeleteTrendline
;
128 bool bMayDeleteTrendlineEquation
;
129 bool bMayDeleteR2Value
;
130 bool bMayDeleteMeanValue
;
131 bool bMayDeleteXErrorBars
;
132 bool bMayDeleteYErrorBars
;
134 bool bMayFormatTrendline
;
135 bool bMayFormatTrendlineEquation
;
136 bool bMayFormatMeanValue
;
137 bool bMayFormatXErrorBars
;
138 bool bMayFormatYErrorBars
;
141 ControllerState::ControllerState() :
142 bHasSelectedObject( false ),
143 bIsPositionableObject( false ),
144 bIsTextObject(false),
145 bIsDeleteableObjectSelected(false),
146 bIsFormateableObjectSelected(false),
147 bMayMoveSeriesForward( false ),
148 bMayMoveSeriesBackward( false ),
149 bMayAddMenuTrendline( false ),
150 bMayAddTrendline( false ),
151 bMayAddTrendlineEquation( false ),
152 bMayAddR2Value( false ),
153 bMayAddMeanValue( false ),
154 bMayAddXErrorBars( false ),
155 bMayAddYErrorBars( false ),
156 bMayDeleteTrendline( false ),
157 bMayDeleteTrendlineEquation( false ),
158 bMayDeleteR2Value( false ),
159 bMayDeleteMeanValue( false ),
160 bMayDeleteXErrorBars( false ),
161 bMayDeleteYErrorBars( false ),
162 bMayFormatTrendline( false ),
163 bMayFormatTrendlineEquation( false ),
164 bMayFormatMeanValue( false ),
165 bMayFormatXErrorBars( false ),
166 bMayFormatYErrorBars( false )
169 void ControllerState::update(
170 const Reference
< frame::XController
> & xController
,
171 const Reference
< frame::XModel
> & xModel
)
173 Reference
< view::XSelectionSupplier
> xSelectionSupplier(
174 xController
, uno::UNO_QUERY
);
176 // Update ControllerState variables.
177 if( xSelectionSupplier
.is())
179 uno::Any
aSelObj( xSelectionSupplier
->getSelection() );
180 ObjectIdentifier
aSelOID( aSelObj
);
181 OUString
aSelObjCID( aSelOID
.getObjectCID() );
183 bHasSelectedObject
= aSelOID
.isValid();
185 ObjectType
aObjectType(ObjectIdentifier::getObjectType( aSelObjCID
));
187 bIsPositionableObject
= (OBJECTTYPE_DATA_POINT
!= aObjectType
) && aSelOID
.isDragableObject();
188 bIsTextObject
= OBJECTTYPE_TITLE
== aObjectType
;
190 uno::Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( xModel
));
191 bIsFormateableObjectSelected
= bHasSelectedObject
&& aSelOID
.isAutoGeneratedObject();
192 if( OBJECTTYPE_DIAGRAM
==aObjectType
|| OBJECTTYPE_DIAGRAM_WALL
==aObjectType
|| OBJECTTYPE_DIAGRAM_FLOOR
==aObjectType
)
193 bIsFormateableObjectSelected
= DiagramHelper::isSupportingFloorAndWall( xDiagram
);
195 uno::Reference
< chart2::XDataSeries
> xGivenDataSeries(
196 ObjectIdentifier::getDataSeriesForCID(
197 aSelObjCID
, xModel
) );
199 bIsDeleteableObjectSelected
= ChartController::isObjectDeleteable( aSelObj
);
201 bMayMoveSeriesForward
= (OBJECTTYPE_DATA_POINT
!=aObjectType
) && DiagramHelper::isSeriesMoveable(
202 ChartModelHelper::findDiagram( xModel
),
204 MOVE_SERIES_FORWARD
);
206 bMayMoveSeriesBackward
= (OBJECTTYPE_DATA_POINT
!=aObjectType
) && DiagramHelper::isSeriesMoveable(
207 ChartModelHelper::findDiagram( xModel
),
209 MOVE_SERIES_BACKWARD
);
211 bMayAddMenuTrendline
= false;
212 bMayAddTrendline
= false;
213 bMayAddTrendlineEquation
= false;
214 bMayAddR2Value
= false;
215 bMayAddMeanValue
= false;
216 bMayAddXErrorBars
= false;
217 bMayAddYErrorBars
= false;
218 bMayDeleteTrendline
= false;
219 bMayDeleteTrendlineEquation
= false;
220 bMayDeleteR2Value
= false;
221 bMayDeleteMeanValue
= false;
222 bMayDeleteXErrorBars
= false;
223 bMayDeleteYErrorBars
= false;
224 bMayFormatTrendline
= false;
225 bMayFormatTrendlineEquation
= false;
226 bMayFormatMeanValue
= false;
227 bMayFormatXErrorBars
= false;
228 bMayFormatYErrorBars
= false;
229 if( bHasSelectedObject
)
231 if( xGivenDataSeries
.is())
233 bMayAddMenuTrendline
= true;
234 sal_Int32 nDimensionCount
= DiagramHelper::getDimension( xDiagram
);
235 uno::Reference
< chart2::XChartType
> xFirstChartType(
236 DataSeriesHelper::getChartTypeOfSeries( xGivenDataSeries
, xDiagram
));
238 // trend lines/mean value line
239 if( (OBJECTTYPE_DATA_SERIES
== aObjectType
|| OBJECTTYPE_DATA_POINT
== aObjectType
)
240 && ChartTypeHelper::isSupportingRegressionProperties( xFirstChartType
, nDimensionCount
))
242 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt( xGivenDataSeries
, uno::UNO_QUERY
);
243 if( xRegCurveCnt
.is())
246 bMayAddTrendline
= true;
249 bMayFormatMeanValue
= bMayDeleteMeanValue
= RegressionCurveHelper::hasMeanValueLine( xRegCurveCnt
);
250 bMayAddMeanValue
= ! bMayDeleteMeanValue
;
255 if( (OBJECTTYPE_DATA_SERIES
== aObjectType
|| OBJECTTYPE_DATA_POINT
== aObjectType
)
256 && ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType
, nDimensionCount
))
258 bMayFormatXErrorBars
= bMayDeleteXErrorBars
= StatisticsHelper::hasErrorBars( xGivenDataSeries
, false );
259 bMayAddXErrorBars
= ! bMayDeleteXErrorBars
;
261 bMayFormatYErrorBars
= bMayDeleteYErrorBars
= StatisticsHelper::hasErrorBars( xGivenDataSeries
, true );
262 bMayAddYErrorBars
= ! bMayDeleteYErrorBars
;
266 if( aObjectType
== OBJECTTYPE_DATA_AVERAGE_LINE
)
267 bMayFormatMeanValue
= true;
269 if( aObjectType
== OBJECTTYPE_DATA_ERRORS_X
)
270 bMayFormatXErrorBars
= true;
272 if( aObjectType
== OBJECTTYPE_DATA_ERRORS_Y
)
273 bMayFormatYErrorBars
= true;
275 if( aObjectType
== OBJECTTYPE_DATA_CURVE
)
277 bMayFormatTrendline
= true;
278 bMayDeleteTrendline
= true;
279 uno::Reference
< chart2::XRegressionCurve
> xRegCurve(
280 ObjectIdentifier::getObjectPropertySet( aSelObjCID
, xModel
), uno::UNO_QUERY
);
282 // Trendline Equation
283 bMayFormatTrendlineEquation
= bMayDeleteTrendlineEquation
= RegressionCurveHelper::hasEquation( xRegCurve
);
284 bMayAddTrendlineEquation
= !bMayDeleteTrendlineEquation
;
286 else if( aObjectType
== OBJECTTYPE_DATA_CURVE_EQUATION
)
288 bMayFormatTrendlineEquation
= true;
289 bool bHasR2Value
= false;
292 uno::Reference
< beans::XPropertySet
> xEquationProperties(
293 ObjectIdentifier::getObjectPropertySet( aSelObjCID
, xModel
), uno::UNO_QUERY
);
294 if( xEquationProperties
.is() )
295 xEquationProperties
->getPropertyValue( "ShowCorrelationCoefficient" ) >>= bHasR2Value
;
297 catch(const uno::RuntimeException
& e
)
299 ASSERT_EXCEPTION( e
);
301 bMayAddR2Value
= !bHasR2Value
;
302 bMayDeleteR2Value
= bHasR2Value
;
308 /** Represents the current state of the model.
310 You can set the state by calling update(). After this call the state is
311 preserved in this class until the next call to update().
313 This is useful, not to say necessary, for enabling and disabling of menu
314 entries and toolbar icons. As the status requests are sent very frequently
315 it would be impossible, from a performance point of view, to query the
316 current status every time directly at the model. So this class serves as a
323 void update( const Reference
< frame::XModel
> & xModel
);
325 bool HasAnyAxis() const;
326 bool HasAnyGrid() const;
327 bool HasAnyTitle() const;
338 bool bHasSecondaryXAxisTitle
;
339 bool bHasSecondaryYAxisTitle
;
354 bool bHasAutoScaledText
;
359 bool bSupportsStatistics
;
363 ModelState::ModelState() :
366 bHasOwnData( false ),
367 bHasMainTitle( false ),
368 bHasSubTitle( false ),
369 bHasXAxisTitle( false ),
370 bHasYAxisTitle( false ),
371 bHasZAxisTitle( false ),
372 bHasSecondaryXAxisTitle( false ),
373 bHasSecondaryYAxisTitle( false ),
379 bHasMainXGrid( false ),
380 bHasMainYGrid( false ),
381 bHasMainZGrid( false ),
382 bHasHelpXGrid( false ),
383 bHasHelpYGrid( false ),
384 bHasHelpZGrid( false ),
385 bHasAutoScaledText( false ),
389 bSupportsStatistics( false ),
390 bSupportsAxes( false )
394 void ModelState::update( const Reference
< frame::XModel
> & xModel
)
396 Reference
< chart2::XChartDocument
> xChartDoc( xModel
, uno::UNO_QUERY
);
397 Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram( xModel
));
400 Reference
< frame::XStorable
> xStorable( xModel
, uno::UNO_QUERY
);
402 bIsReadOnly
= xStorable
->isReadonly();
404 sal_Int32 nDimensionCount
= DiagramHelper::getDimension( xDiagram
);
406 uno::Reference
< chart2::XChartType
> xFirstChartType( DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ) );
407 bSupportsStatistics
= ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType
, nDimensionCount
);
408 bSupportsAxes
= ChartTypeHelper::isSupportingMainAxis( xFirstChartType
, nDimensionCount
, 0 );
410 bIsThreeD
= (nDimensionCount
== 3);
411 bHasOwnData
= (xChartDoc
.is() && xChartDoc
->hasInternalDataProvider());
413 bHasMainTitle
= TitleHelper::getTitle( TitleHelper::MAIN_TITLE
, xModel
).is();
414 bHasSubTitle
= TitleHelper::getTitle( TitleHelper::SUB_TITLE
, xModel
).is();
415 bHasXAxisTitle
= TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE
, xModel
).is();
416 bHasYAxisTitle
= TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE
, xModel
).is();
417 bHasZAxisTitle
= TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE
, xModel
).is();
418 bHasSecondaryXAxisTitle
= TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE
, xModel
).is();
419 bHasSecondaryYAxisTitle
= TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE
, xModel
).is();
421 bHasXAxis
= bSupportsAxes
&& AxisHelper::getAxis( 0, true, xDiagram
).is();
422 bHasYAxis
= bSupportsAxes
&& AxisHelper::getAxis( 1, true, xDiagram
).is();
423 bHasZAxis
= bSupportsAxes
&& AxisHelper::getAxis( 2, true, xDiagram
).is();
424 bHasAAxis
= bSupportsAxes
&& AxisHelper::getAxis( 0, false, xDiagram
).is();
425 bHasBAxis
= bSupportsAxes
&& AxisHelper::getAxis( 1, false, xDiagram
).is();
427 bHasMainXGrid
= bSupportsAxes
&& AxisHelper::isGridShown( 0, 0, true, xDiagram
);
428 bHasMainYGrid
= bSupportsAxes
&& AxisHelper::isGridShown( 1, 0, true, xDiagram
);
429 bHasMainZGrid
= bSupportsAxes
&& AxisHelper::isGridShown( 2, 0, true, xDiagram
);
430 bHasHelpXGrid
= bSupportsAxes
&& AxisHelper::isGridShown( 0, 0, false, xDiagram
);
431 bHasHelpYGrid
= bSupportsAxes
&& AxisHelper::isGridShown( 1, 0, false, xDiagram
);
432 bHasHelpZGrid
= bSupportsAxes
&& AxisHelper::isGridShown( 2, 0, false, xDiagram
);
435 (ReferenceSizeProvider::getAutoResizeState( xChartDoc
) ==
436 ReferenceSizeProvider::AUTO_RESIZE_YES
);
438 bHasLegend
= LegendHelper::hasLegend( xDiagram
);
439 bHasWall
= DiagramHelper::isSupportingFloorAndWall( xDiagram
);
440 bHasFloor
= bHasWall
&& bIsThreeD
;
443 bool ModelState::HasAnyAxis() const
445 return bHasXAxis
|| bHasYAxis
|| bHasZAxis
|| bHasAAxis
|| bHasBAxis
;
448 bool ModelState::HasAnyGrid() const
450 return bHasMainXGrid
|| bHasMainYGrid
|| bHasMainZGrid
||
451 bHasHelpXGrid
|| bHasHelpYGrid
|| bHasHelpZGrid
;
454 bool ModelState::HasAnyTitle() const
456 return bHasMainTitle
|| bHasSubTitle
|| bHasXAxisTitle
|| bHasYAxisTitle
|| bHasZAxisTitle
|| bHasSecondaryXAxisTitle
|| bHasSecondaryYAxisTitle
;
461 ControllerCommandDispatch::ControllerCommandDispatch(
462 const Reference
< uno::XComponentContext
> & xContext
,
463 ChartController
* pController
, CommandDispatchContainer
* pContainer
) :
464 impl::ControllerCommandDispatch_Base( xContext
),
465 m_pChartController( pController
),
466 m_xController( Reference
< frame::XController
>( pController
) ),
467 m_xSelectionSupplier( Reference
< view::XSelectionSupplier
>( pController
) ),
468 m_xDispatch( Reference
< frame::XDispatch
>( pController
) ),
469 m_apModelState( new impl::ModelState() ),
470 m_apControllerState( new impl::ControllerState() ),
471 m_pDispatchContainer( pContainer
)
475 ControllerCommandDispatch::~ControllerCommandDispatch()
479 void ControllerCommandDispatch::initialize()
481 if( m_xController
.is())
483 Reference
< frame::XModel
> xModel( m_xController
->getModel());
484 Reference
< util::XModifyBroadcaster
> xModifyBroadcaster( xModel
, uno::UNO_QUERY
);
485 OSL_ASSERT( xModifyBroadcaster
.is());
486 if( xModifyBroadcaster
.is())
487 xModifyBroadcaster
->addModifyListener( this );
489 // Listen selection modifications (Arrangement feature - issue 63017).
490 if( m_xSelectionSupplier
.is() )
491 m_xSelectionSupplier
->addSelectionChangeListener( this );
493 if( m_apModelState
.get() && xModel
.is())
494 m_apModelState
->update( xModel
);
496 if( m_apControllerState
.get() && xModel
.is())
497 m_apControllerState
->update( m_xController
, xModel
);
499 updateCommandAvailability();
503 void ControllerCommandDispatch::fireStatusEventForURLImpl(
504 const OUString
& rURL
,
505 const Reference
< frame::XStatusListener
> & xSingleListener
)
507 ::std::map
< OUString
, uno::Any
>::const_iterator
aArgIt( m_aCommandArguments
.find( rURL
));
508 if( aArgIt
!= m_aCommandArguments
.end())
509 fireStatusEventForURL( rURL
, aArgIt
->second
, commandAvailable( rURL
), xSingleListener
);
511 fireStatusEventForURL( rURL
, uno::Any(), commandAvailable( rURL
), xSingleListener
);
514 void ControllerCommandDispatch::updateCommandAvailability()
516 bool bModelStateIsValid
= ( m_apModelState
.get() != 0 );
517 bool bControllerStateIsValid
= ( m_apControllerState
.get() != 0 );
518 // Model and controller states exist.
519 OSL_ASSERT( bModelStateIsValid
);
520 OSL_ASSERT( bControllerStateIsValid
);
523 bool bIsWritable
= bModelStateIsValid
&& (! m_apModelState
->bIsReadOnly
);
524 // paste is available
525 // @todo: determine correctly
526 bool bHasSuitableClipboardContent
= true;
528 bool bShapeContext
= m_pChartController
&& m_pChartController
->isShapeContext();
530 bool bEnableDataTableDialog
= false;
531 if ( m_xController
.is() )
533 Reference
< beans::XPropertySet
> xProps( m_xController
->getModel(), uno::UNO_QUERY
);
538 xProps
->getPropertyValue("EnableDataTableDialog") >>= bEnableDataTableDialog
;
540 catch( const uno::Exception
& e
)
542 ASSERT_EXCEPTION( e
);
548 m_aCommandAvailability
[ ".uno:Cut" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bIsDeleteableObjectSelected
;
549 m_aCommandAvailability
[ ".uno:Copy" ] = bControllerStateIsValid
&& m_apControllerState
->bHasSelectedObject
;
550 m_aCommandAvailability
[ ".uno:Paste" ] = bIsWritable
&& bHasSuitableClipboardContent
;
553 m_aCommandAvailability
[ ".uno:ToggleGridHorizontal" ] = bIsWritable
;
554 m_aCommandArguments
[ ".uno:ToggleGridHorizontal" ] = uno::makeAny( m_apModelState
->bHasMainYGrid
);
555 m_aCommandAvailability
[ ".uno:ToggleGridVertical" ] = bIsWritable
;
556 m_aCommandArguments
[ ".uno:ToggleGridVertical" ] = uno::makeAny( m_apModelState
->bHasMainXGrid
);
558 m_aCommandAvailability
[ ".uno:ToggleLegend" ] = bIsWritable
;
559 m_aCommandArguments
[ ".uno:ToggleLegend" ] = uno::makeAny( m_apModelState
->bHasLegend
);
561 m_aCommandAvailability
[ ".uno:NewArrangement" ] = bIsWritable
;
562 m_aCommandAvailability
[ ".uno:Update" ] = bIsWritable
;
563 m_aCommandAvailability
[ ".uno:DefaultColors" ] = bIsWritable
;
564 m_aCommandAvailability
[ ".uno:BarWidth" ] = bIsWritable
;
565 m_aCommandAvailability
[ ".uno:NumberOfLines" ] = bIsWritable
;
566 m_aCommandAvailability
[ ".uno:ArrangeRow" ] =
567 bShapeContext
|| ( bIsWritable
&& bControllerStateIsValid
&& ( m_apControllerState
->bMayMoveSeriesForward
|| m_apControllerState
->bMayMoveSeriesBackward
) );
570 m_aCommandAvailability
[ ".uno:InsertTitles" ] = m_aCommandAvailability
[ ".uno:InsertMenuTitles" ] = bIsWritable
;
571 m_aCommandAvailability
[ ".uno:InsertLegend" ] = m_aCommandAvailability
[ ".uno:InsertMenuLegend" ] = bIsWritable
;
572 m_aCommandAvailability
[ ".uno:DeleteLegend" ] = bIsWritable
;
573 m_aCommandAvailability
[ ".uno:InsertMenuDataLabels" ] = bIsWritable
;
574 m_aCommandAvailability
[ ".uno:InsertRemoveAxes" ] = m_aCommandAvailability
[ ".uno:InsertMenuAxes" ] = bIsWritable
&& m_apModelState
->bSupportsAxes
;
575 m_aCommandAvailability
[ ".uno:InsertMenuGrids" ] = bIsWritable
&& m_apModelState
->bSupportsAxes
;
576 m_aCommandAvailability
[ ".uno:InsertMenuTrendlines" ] = bIsWritable
&& m_apModelState
->bSupportsStatistics
&& m_apControllerState
->bMayAddMenuTrendline
;
577 m_aCommandAvailability
[ ".uno:InsertMenuMeanValues" ] = bIsWritable
&& m_apModelState
->bSupportsStatistics
;
578 m_aCommandAvailability
[ ".uno:InsertMenuXErrorBars" ] = bIsWritable
&& m_apModelState
->bSupportsStatistics
;
579 m_aCommandAvailability
[ ".uno:InsertMenuYErrorBars" ] = bIsWritable
&& m_apModelState
->bSupportsStatistics
;
580 m_aCommandAvailability
[ ".uno:InsertSymbol" ] = bIsWritable
&& m_apControllerState
->bIsTextObject
;
583 bool bFormatObjectAvailable
= bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bIsFormateableObjectSelected
;
584 m_aCommandAvailability
[ ".uno:FormatSelection" ] = bFormatObjectAvailable
;
585 m_aCommandAvailability
[ ".uno:FormatAxis" ] = bFormatObjectAvailable
;
586 m_aCommandAvailability
[ ".uno:FormatTitle" ] = bFormatObjectAvailable
;
587 m_aCommandAvailability
[ ".uno:FormatDataSeries" ] = bFormatObjectAvailable
;
588 m_aCommandAvailability
[ ".uno:FormatDataPoint" ] = bFormatObjectAvailable
;
589 m_aCommandAvailability
[ ".uno:FormatDataLabels" ] = bFormatObjectAvailable
;
590 m_aCommandAvailability
[ ".uno:FormatDataLabel" ] = bFormatObjectAvailable
;
591 m_aCommandAvailability
[ ".uno:FormatXErrorBars" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayFormatXErrorBars
;
592 m_aCommandAvailability
[ ".uno:FormatYErrorBars" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayFormatYErrorBars
;
593 m_aCommandAvailability
[ ".uno:FormatMeanValue" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayFormatMeanValue
;
594 m_aCommandAvailability
[ ".uno:FormatTrendline" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayFormatTrendline
;
595 m_aCommandAvailability
[ ".uno:FormatTrendlineEquation" ] = bFormatObjectAvailable
&& bControllerStateIsValid
&& m_apControllerState
->bMayFormatTrendlineEquation
;
596 m_aCommandAvailability
[ ".uno:FormatStockLoss" ] = bFormatObjectAvailable
;
597 m_aCommandAvailability
[ ".uno:FormatStockGain" ] = bFormatObjectAvailable
;
599 m_aCommandAvailability
[ ".uno:DiagramType" ] = bIsWritable
;
600 m_aCommandAvailability
[ ".uno:Legend" ] = bIsWritable
&& m_apModelState
->bHasLegend
;
601 m_aCommandAvailability
[ ".uno:DiagramWall" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasWall
;
602 m_aCommandAvailability
[ ".uno:DiagramArea" ] = bIsWritable
;
604 m_aCommandAvailability
[ ".uno:TransformDialog" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bHasSelectedObject
&& m_apControllerState
->bIsPositionableObject
;
607 m_aCommandAvailability
[ ".uno:View3D" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bIsThreeD
;
608 m_aCommandAvailability
[ ".uno:DiagramFloor" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasFloor
;
610 //some mor format commands with different ui text
611 m_aCommandAvailability
[ ".uno:FormatWall" ] = m_aCommandAvailability
[ ".uno:DiagramWall" ];
612 m_aCommandAvailability
[ ".uno:FormatFloor" ] = m_aCommandAvailability
[ ".uno:DiagramFloor" ];
613 m_aCommandAvailability
[ ".uno:FormatChartArea" ] = m_aCommandAvailability
[ ".uno:DiagramArea" ];
614 m_aCommandAvailability
[ ".uno:FormatLegend" ] = m_aCommandAvailability
[ ".uno:Legend" ];
616 // depending on own data
617 m_aCommandAvailability
[ ".uno:DataRanges" ] = bIsWritable
&& bModelStateIsValid
&& (! m_apModelState
->bHasOwnData
);
618 m_aCommandAvailability
[ ".uno:DiagramData" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasOwnData
&& bEnableDataTableDialog
;
621 m_aCommandAvailability
[ ".uno:MainTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasMainTitle
;
622 m_aCommandAvailability
[ ".uno:SubTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasSubTitle
;
623 m_aCommandAvailability
[ ".uno:XTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasXAxisTitle
;
624 m_aCommandAvailability
[ ".uno:YTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasYAxisTitle
;
625 m_aCommandAvailability
[ ".uno:ZTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasZAxisTitle
;
626 m_aCommandAvailability
[ ".uno:SecondaryXTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasSecondaryXAxisTitle
;
627 m_aCommandAvailability
[ ".uno:SecondaryYTitle" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasSecondaryYAxisTitle
;
628 m_aCommandAvailability
[ ".uno:AllTitles" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->HasAnyTitle();
631 m_aCommandAvailability
[ ".uno:ScaleText" ] = bIsWritable
&& bModelStateIsValid
;
632 m_aCommandArguments
[ ".uno:ScaleText" ] = uno::makeAny( m_apModelState
->bHasAutoScaledText
);
635 m_aCommandAvailability
[ ".uno:DiagramAxisX" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasXAxis
;
636 m_aCommandAvailability
[ ".uno:DiagramAxisY" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasYAxis
;
637 m_aCommandAvailability
[ ".uno:DiagramAxisZ" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasZAxis
;
638 m_aCommandAvailability
[ ".uno:DiagramAxisA" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasAAxis
;
639 m_aCommandAvailability
[ ".uno:DiagramAxisB" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasBAxis
;
640 m_aCommandAvailability
[ ".uno:DiagramAxisAll" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->HasAnyAxis();
643 // note: x and y are swapped in the commands!
644 m_aCommandAvailability
[ ".uno:DiagramGridYMain" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasMainXGrid
;
645 m_aCommandAvailability
[ ".uno:DiagramGridXMain" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasMainYGrid
;
646 m_aCommandAvailability
[ ".uno:DiagramGridZMain" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasMainZGrid
;
647 m_aCommandAvailability
[ ".uno:DiagramGridYHelp" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasHelpXGrid
;
648 m_aCommandAvailability
[ ".uno:DiagramGridXHelp" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasHelpYGrid
;
649 m_aCommandAvailability
[ ".uno:DiagramGridZHelp" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->bHasHelpZGrid
;
650 m_aCommandAvailability
[ ".uno:DiagramGridAll" ] = bIsWritable
&& bModelStateIsValid
&& m_apModelState
->HasAnyGrid();
652 // series arrangement
653 m_aCommandAvailability
[ ".uno:Forward" ] = ( bShapeContext
? isShapeControllerCommandAvailable( ".uno:Forward" ) :
654 ( bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayMoveSeriesForward
&& bEnableDataTableDialog
) );
655 m_aCommandAvailability
[ ".uno:Backward" ] = ( bShapeContext
? isShapeControllerCommandAvailable( ".uno:Backward" ) :
656 ( bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayMoveSeriesBackward
&& bEnableDataTableDialog
) );
658 m_aCommandAvailability
[ ".uno:InsertDataLabels" ] = bIsWritable
;
659 m_aCommandAvailability
[ ".uno:InsertDataLabel" ] = bIsWritable
;
660 m_aCommandAvailability
[ ".uno:InsertMeanValue" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayAddMeanValue
;
661 m_aCommandAvailability
[ ".uno:InsertTrendline" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayAddTrendline
;
662 m_aCommandAvailability
[ ".uno:InsertTrendlineEquation" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayAddTrendlineEquation
;
663 m_aCommandAvailability
[ ".uno:InsertTrendlineEquationAndR2" ] = m_aCommandAvailability
[ ".uno:InsertTrendlineEquation" ];
664 m_aCommandAvailability
[ ".uno:InsertR2Value" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayAddR2Value
;
665 m_aCommandAvailability
[ ".uno:DeleteR2Value" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayDeleteR2Value
;
667 m_aCommandAvailability
[ ".uno:InsertXErrorBars" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayAddXErrorBars
;
668 m_aCommandAvailability
[ ".uno:InsertYErrorBars" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayAddYErrorBars
;
670 m_aCommandAvailability
[ ".uno:DeleteDataLabels" ] = bIsWritable
;
671 m_aCommandAvailability
[ ".uno:DeleteDataLabel" ] = bIsWritable
;
672 m_aCommandAvailability
[ ".uno:DeleteTrendline" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayDeleteTrendline
;
673 m_aCommandAvailability
[ ".uno:DeleteTrendlineEquation" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayDeleteTrendlineEquation
;
674 m_aCommandAvailability
[ ".uno:DeleteMeanValue" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayDeleteMeanValue
;
675 m_aCommandAvailability
[ ".uno:DeleteXErrorBars" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayDeleteXErrorBars
;
676 m_aCommandAvailability
[ ".uno:DeleteYErrorBars" ] = bIsWritable
&& bControllerStateIsValid
&& m_apControllerState
->bMayDeleteYErrorBars
;
678 m_aCommandAvailability
[ ".uno:ResetDataPoint" ] = bIsWritable
;
679 m_aCommandAvailability
[ ".uno:ResetAllDataPoints" ] = bIsWritable
;
681 m_aCommandAvailability
[ ".uno:InsertAxis" ] = bIsWritable
;
682 m_aCommandAvailability
[ ".uno:DeleteAxis" ] = bIsWritable
;
683 m_aCommandAvailability
[ ".uno:InsertAxisTitle" ] = bIsWritable
;
684 m_aCommandAvailability
[ ".uno:FormatMajorGrid" ] = bIsWritable
;
685 m_aCommandAvailability
[ ".uno:InsertMajorGrid" ] = bIsWritable
;
686 m_aCommandAvailability
[ ".uno:DeleteMajorGrid" ] = bIsWritable
;
687 m_aCommandAvailability
[ ".uno:FormatMinorGrid" ] = bIsWritable
;
688 m_aCommandAvailability
[ ".uno:InsertMinorGrid" ] = bIsWritable
;
689 m_aCommandAvailability
[ ".uno:DeleteMinorGrid" ] = bIsWritable
;
692 bool ControllerCommandDispatch::commandAvailable( const OUString
& rCommand
)
694 ::std::map
< OUString
, bool >::const_iterator
aIt( m_aCommandAvailability
.find( rCommand
));
695 if( aIt
!= m_aCommandAvailability
.end())
697 OSL_FAIL( "commandAvailable: command not in availability map" );
701 bool ControllerCommandDispatch::isShapeControllerCommandAvailable( const OUString
& rCommand
)
703 ShapeController
* pShapeController(0);
706 if (m_pDispatchContainer
)
707 pShapeController
= m_pDispatchContainer
->getShapeController();
709 if ( pShapeController
)
711 FeatureState
aState( pShapeController
->getState( rCommand
) );
712 return aState
.bEnabled
;
717 void ControllerCommandDispatch::fireStatusEvent(
718 const OUString
& rURL
,
719 const Reference
< frame::XStatusListener
> & xSingleListener
/* = 0 */ )
721 bool bIsChartSelectorURL
= rURL
== ".uno:ChartElementSelector";
722 if( rURL
.isEmpty() || bIsChartSelectorURL
)
725 aArg
<<= m_xController
;
726 fireStatusEventForURL( ".uno:ChartElementSelector", aArg
, true, xSingleListener
);
730 for( ::std::map
< OUString
, bool >::const_iterator
aIt( m_aCommandAvailability
.begin());
731 aIt
!= m_aCommandAvailability
.end(); ++aIt
)
732 fireStatusEventForURLImpl( aIt
->first
, xSingleListener
);
733 else if( !bIsChartSelectorURL
)
734 fireStatusEventForURLImpl( rURL
, xSingleListener
);
736 // statusbar. Should be handled by base implementation
737 // @todo: remove if Issue 68864 is fixed
738 if( rURL
.isEmpty() || rURL
== ".uno:StatusBarVisible" )
740 bool bIsStatusBarVisible( lcl_isStatusBarVisible( m_xController
));
741 fireStatusEventForURL( ".uno:StatusBarVisible", uno::makeAny( bIsStatusBarVisible
), true, xSingleListener
);
745 // ____ XDispatch ____
746 void SAL_CALL
ControllerCommandDispatch::dispatch(
747 const util::URL
& URL
,
748 const Sequence
< beans::PropertyValue
>& Arguments
)
749 throw (uno::RuntimeException
, std::exception
)
751 if( commandAvailable( URL
.Complete
))
752 m_xDispatch
->dispatch( URL
, Arguments
);
755 // ____ WeakComponentImplHelperBase ____
756 /// is called when this is disposed
757 void SAL_CALL
ControllerCommandDispatch::disposing()
759 m_xController
.clear();
761 m_xSelectionSupplier
.clear();
764 // ____ XEventListener (base of XModifyListener) ____
765 void SAL_CALL
ControllerCommandDispatch::disposing( const lang::EventObject
& /* Source */ )
766 throw (uno::RuntimeException
, std::exception
)
768 m_xController
.clear();
770 m_xSelectionSupplier
.clear();
773 // ____ XModifyListener ____
774 void SAL_CALL
ControllerCommandDispatch::modified( const lang::EventObject
& aEvent
)
775 throw (uno::RuntimeException
, std::exception
)
777 bool bUpdateCommandAvailability
= false;
779 // Update the "ModelState" Struct.
780 if( m_apModelState
.get() && m_xController
.is())
782 m_apModelState
->update( m_xController
->getModel());
783 bUpdateCommandAvailability
= true;
786 // Update the "ControllerState" Struct.
787 if( m_apControllerState
.get() && m_xController
.is())
789 m_apControllerState
->update( m_xController
, m_xController
->getModel());
790 bUpdateCommandAvailability
= true;
793 if( bUpdateCommandAvailability
)
794 updateCommandAvailability();
796 CommandDispatch::modified( aEvent
);
799 // ____ XSelectionChangeListener ____
800 void SAL_CALL
ControllerCommandDispatch::selectionChanged( const lang::EventObject
& aEvent
)
801 throw (uno::RuntimeException
, std::exception
)
803 // Update the "ControllerState" Struct.
804 if( m_apControllerState
.get() && m_xController
.is())
806 m_apControllerState
->update( m_xController
, m_xController
->getModel());
807 updateCommandAvailability();
810 CommandDispatch::modified( aEvent
);
815 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */