Update ooo320-m1
[ooovba.git] / chart2 / source / controller / main / ControllerCommandDispatch.cxx
bloba024330721ece27f91a9a4a125094d17c6bdd727
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ControllerCommandDispatch.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "ControllerCommandDispatch.hxx"
35 #include "ChartModelHelper.hxx"
36 #include "DiagramHelper.hxx"
37 #include "AxisHelper.hxx"
38 #include "TitleHelper.hxx"
39 #include "LegendHelper.hxx"
40 #include "ObjectIdentifier.hxx"
41 #include "macros.hxx"
42 #include "ChartTypeHelper.hxx"
43 #include "DiagramHelper.hxx"
44 #include "ChartController.hxx"
45 #include "RegressionCurveHelper.hxx"
46 #include "DataSeriesHelper.hxx"
47 #include "StatisticsHelper.hxx"
49 #include <com/sun/star/util/XModifyBroadcaster.hpp>
50 #include <com/sun/star/frame/XStorable.hpp>
51 #include <com/sun/star/chart2/XChartDocument.hpp>
52 #include <com/sun/star/chart2/XChartType.hpp>
53 #include <com/sun/star/chart2/XDataSeries.hpp>
54 #include <com/sun/star/chart2/XRegressionCurve.hpp>
55 #include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
57 // only needed until #i68864# is fixed
58 #include <com/sun/star/frame/XLayoutManager.hpp>
60 using namespace ::com::sun::star;
62 using ::com::sun::star::uno::Reference;
63 using ::com::sun::star::uno::Sequence;
64 using ::rtl::OUString;
66 namespace
68 bool lcl_isStatusBarVisible( const Reference< frame::XController > & xController )
70 bool bIsStatusBarVisible = false;
71 // Status-Bar visible, workaround: this should not be necessary. @todo:
72 // remove when Issue #i68864# is fixed
73 if( xController.is())
75 Reference< beans::XPropertySet > xPropSet( xController->getFrame(), uno::UNO_QUERY );
76 if( xPropSet.is() )
78 uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
79 xPropSet->getPropertyValue( C2U( "LayoutManager" ) ) >>= xLayoutManager;
80 if ( xLayoutManager.is() )
81 bIsStatusBarVisible = xLayoutManager->isElementVisible( C2U("private:resource/statusbar/statusbar"));
84 return bIsStatusBarVisible;
87 } // anonymous namespace
89 namespace chart
92 // ----------------------------------------
94 namespace impl
97 /// Constants for moving the series.
98 enum EnumForward{
99 MOVE_SERIES_FORWARD = true,
100 MOVE_SERIES_BACKWARD = false
103 /** Represents the current state of the controller (needed for issue 63017).
105 You can set the state by calling update(). After this call the state is
106 preserved in this class until the next call to update().
108 This is useful, not to say necessary, for enabling and disabling of menu
109 entries (e.g. format>arrangement). As the status requests are sent very
110 frequently it would be impossible, from a performance point of view, to
111 query the current status every time directly at the model. So this class
112 serves as a cache for the state.
114 struct ControllerState
116 ControllerState();
118 void update( const Reference< frame::XController > & xController,
119 const Reference< frame::XModel > & xModel );
121 // -- State variables -------
122 bool bHasSelectedObject;
123 bool bIsPositionableObject;
124 bool bIsTextObject;
125 bool bIsDeleteableObjectSelected;
126 bool bIsFormateableObjectSelected;
128 // May the selected series be moved forward or backward (cf
129 // format>arrangement).
130 bool bMayMoveSeriesForward;
131 bool bMayMoveSeriesBackward;
133 // trendlines
134 bool bMayAddTrendline;
135 bool bMayAddTrendlineEquation;
136 bool bMayAddR2Value;
137 bool bMayAddMeanValue;
138 bool bMayAddYErrorBars;
140 bool bMayDeleteTrendline;
141 bool bMayDeleteTrendlineEquation;
142 bool bMayDeleteR2Value;
143 bool bMayDeleteMeanValue;
144 bool bMayDeleteYErrorBars;
146 bool bMayFormatTrendline;
147 bool bMayFormatTrendlineEquation;
148 bool bMayFormatMeanValue;
149 bool bMayFormatYErrorBars;
153 ControllerState::ControllerState() :
154 bHasSelectedObject( false ),
155 bIsPositionableObject( false ),
156 bIsTextObject(false),
157 bIsDeleteableObjectSelected(false),
158 bIsFormateableObjectSelected(false),
159 bMayMoveSeriesForward( false ),
160 bMayMoveSeriesBackward( false ),
161 bMayAddTrendline( false ),
162 bMayAddTrendlineEquation( false ),
163 bMayAddR2Value( false ),
164 bMayAddMeanValue( false ),
165 bMayAddYErrorBars( false ),
166 bMayDeleteTrendline( false ),
167 bMayDeleteTrendlineEquation( false ),
168 bMayDeleteR2Value( false ),
169 bMayDeleteMeanValue( false ),
170 bMayDeleteYErrorBars( false ),
171 bMayFormatTrendline( false ),
172 bMayFormatTrendlineEquation( false ),
173 bMayFormatMeanValue( false ),
174 bMayFormatYErrorBars( false )
177 void ControllerState::update(
178 const Reference< frame::XController > & xController,
179 const Reference< frame::XModel > & xModel )
181 Reference< view::XSelectionSupplier > xSelectionSupplier(
182 xController, uno::UNO_QUERY );
184 OUString aSelObjCID;
186 // Update ControllerState variables.
187 if( xSelectionSupplier.is())
189 uno::Any aSelObj( xSelectionSupplier->getSelection() );
191 bHasSelectedObject = ((aSelObj >>= aSelObjCID) && aSelObjCID.getLength() > 0);
193 ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
195 bIsPositionableObject = (OBJECTTYPE_DATA_POINT != aObjectType) && ObjectIdentifier::isDragableObject( aSelObjCID );
196 bIsTextObject = OBJECTTYPE_TITLE == aObjectType;
198 uno::Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
199 bIsFormateableObjectSelected = bHasSelectedObject;
200 if( OBJECTTYPE_DIAGRAM==aObjectType || OBJECTTYPE_DIAGRAM_WALL==aObjectType || OBJECTTYPE_DIAGRAM_FLOOR==aObjectType )
201 bIsFormateableObjectSelected = DiagramHelper::isSupportingFloorAndWall( xDiagram );
203 uno::Reference< chart2::XDataSeries > xGivenDataSeries(
204 ObjectIdentifier::getDataSeriesForCID(
205 aSelObjCID, xModel ) );
207 bIsDeleteableObjectSelected = ChartController::isObjectDeleteable( aSelObj );
209 bMayMoveSeriesForward = (OBJECTTYPE_DATA_POINT!=aObjectType) && DiagramHelper::isSeriesMoveable(
210 ChartModelHelper::findDiagram( xModel ),
211 xGivenDataSeries,
212 MOVE_SERIES_FORWARD );
214 bMayMoveSeriesBackward = (OBJECTTYPE_DATA_POINT!=aObjectType) && DiagramHelper::isSeriesMoveable(
215 ChartModelHelper::findDiagram( xModel ),
216 xGivenDataSeries,
217 MOVE_SERIES_BACKWARD );
219 bMayAddTrendline = false;
220 bMayAddTrendlineEquation = false;
221 bMayAddR2Value = false;
222 bMayAddMeanValue = false;
223 bMayAddYErrorBars = false;
224 bMayDeleteTrendline = false;
225 bMayDeleteTrendlineEquation = false;
226 bMayDeleteR2Value = false;
227 bMayDeleteMeanValue = false;
228 bMayDeleteYErrorBars = false;
229 bMayFormatTrendline = false;
230 bMayFormatTrendlineEquation = false;
231 bMayFormatMeanValue = false;
232 bMayFormatYErrorBars = false;
233 if( bHasSelectedObject )
235 if( xGivenDataSeries.is())
237 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
238 uno::Reference< chart2::XChartType > xFirstChartType(
239 DataSeriesHelper::getChartTypeOfSeries( xGivenDataSeries, xDiagram ));
241 // trend lines/mean value line
242 if( (OBJECTTYPE_DATA_SERIES == aObjectType || OBJECTTYPE_DATA_POINT == aObjectType)
243 && ChartTypeHelper::isSupportingRegressionProperties( xFirstChartType, nDimensionCount ))
245 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
246 xGivenDataSeries, uno::UNO_QUERY );
247 if( xRegCurveCnt.is())
249 uno::Reference< chart2::XRegressionCurve > xRegCurve( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
250 bMayFormatTrendline = bMayDeleteTrendline = xRegCurve.is();
251 bMayFormatMeanValue = bMayDeleteMeanValue = RegressionCurveHelper::hasMeanValueLine( xRegCurveCnt );
252 bMayAddTrendline = ! bMayDeleteTrendline;
253 bMayAddMeanValue = ! bMayDeleteMeanValue;
254 bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve );
255 bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation;
259 // error bars
260 if( (OBJECTTYPE_DATA_SERIES == aObjectType || OBJECTTYPE_DATA_POINT == aObjectType)
261 && ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType, nDimensionCount ))
263 bMayFormatYErrorBars = bMayDeleteYErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries );
264 bMayAddYErrorBars = ! bMayDeleteYErrorBars;
268 if( aObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
269 bMayFormatMeanValue = true;
271 if( aObjectType == OBJECTTYPE_DATA_ERRORS_Y || aObjectType == OBJECTTYPE_DATA_ERRORS )
272 bMayFormatYErrorBars = true;
274 if( aObjectType == OBJECTTYPE_DATA_CURVE )
276 bMayFormatTrendline = true;
277 uno::Reference< chart2::XRegressionCurve > xRegCurve(
278 ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ), uno::UNO_QUERY );
279 bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve );
280 bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation;
282 else if( aObjectType == OBJECTTYPE_DATA_CURVE_EQUATION )
284 bMayFormatTrendlineEquation = true;
285 bool bHasR2Value = false;
288 uno::Reference< beans::XPropertySet > xEqProp(
289 ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ), uno::UNO_QUERY );
290 if( xEqProp.is())
291 xEqProp->getPropertyValue( C2U("ShowCorrelationCoefficient") ) >>= bHasR2Value;
293 catch( uno::RuntimeException& e)
295 ASSERT_EXCEPTION( e );
297 bMayAddR2Value = !bHasR2Value;
298 bMayDeleteR2Value = bHasR2Value;
305 /** Represents the current state of the model.
307 You can set the state by calling update(). After this call the state is
308 preserved in this class until the next call to update().
310 This is useful, not to say necessary, for enabling and disabling of menu
311 entries and toolbar icons. As the status requests are sent very frequently
312 it would be impossible, from a performance point of view, to query the
313 current status every time directly at the model. So this class serves as a
314 cache for the state.
316 struct ModelState
318 ModelState();
320 void update( const Reference< frame::XModel > & xModel );
322 bool HasAnyAxis() const;
323 bool HasAnyGrid() const;
324 bool HasAnyTitle() const;
326 bool bIsReadOnly;
327 bool bIsThreeD;
328 bool bHasOwnData;
330 bool bHasMainTitle;
331 bool bHasSubTitle;
332 bool bHasXAxisTitle;
333 bool bHasYAxisTitle;
334 bool bHasZAxisTitle;
335 bool bHasSecondaryXAxisTitle;
336 bool bHasSecondaryYAxisTitle;
338 bool bHasXAxis;
339 bool bHasYAxis;
340 bool bHasZAxis;
341 bool bHasAAxis;
342 bool bHasBAxis;
344 bool bHasMainXGrid;
345 bool bHasMainYGrid;
346 bool bHasMainZGrid;
347 bool bHasHelpXGrid;
348 bool bHasHelpYGrid;
349 bool bHasHelpZGrid;
351 bool bHasAutoScaledText;
352 bool bHasLegend;
353 bool bHasWall;
354 bool bHasFloor;
356 bool bSupportsStatistics;
357 bool bSupportsAxes;
360 ModelState::ModelState() :
361 bIsReadOnly( true ),
362 bIsThreeD( false ),
363 bHasOwnData( false ),
364 bHasMainTitle( false ),
365 bHasSubTitle( false ),
366 bHasXAxisTitle( false ),
367 bHasYAxisTitle( false ),
368 bHasZAxisTitle( false ),
369 bHasSecondaryXAxisTitle( false ),
370 bHasSecondaryYAxisTitle( false ),
371 bHasXAxis( false ),
372 bHasYAxis( false ),
373 bHasZAxis( false ),
374 bHasAAxis( false ),
375 bHasBAxis( false ),
376 bHasMainXGrid( false ),
377 bHasMainYGrid( false ),
378 bHasMainZGrid( false ),
379 bHasHelpXGrid( false ),
380 bHasHelpYGrid( false ),
381 bHasHelpZGrid( false ),
382 bHasAutoScaledText( false ),
383 bHasLegend( false ),
384 bHasWall( false ),
385 bHasFloor( false ),
386 bSupportsStatistics( false ),
387 bSupportsAxes( false )
391 void ModelState::update( const Reference< frame::XModel > & xModel )
393 Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
394 Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
396 bIsReadOnly = true;
397 Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY );
398 if( xStorable.is())
399 bIsReadOnly = xStorable->isReadonly();
401 sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
403 uno::Reference< chart2::XChartType > xFirstChartType( DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) );
404 bSupportsStatistics = ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType, nDimensionCount );
405 bSupportsAxes = ChartTypeHelper::isSupportingMainAxis( xFirstChartType, nDimensionCount, 0 );
407 bIsThreeD = (nDimensionCount == 3);
408 bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider());
410 bHasMainTitle = TitleHelper::getTitle( TitleHelper::MAIN_TITLE, xModel ).is();
411 bHasSubTitle = TitleHelper::getTitle( TitleHelper::SUB_TITLE, xModel ).is();
412 bHasXAxisTitle = TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, xModel ).is();
413 bHasYAxisTitle = TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, xModel ).is();
414 bHasZAxisTitle = TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE, xModel ).is();
415 bHasSecondaryXAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xModel ).is();
416 bHasSecondaryYAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xModel ).is();
418 bHasXAxis = bSupportsAxes && AxisHelper::getAxis( 0, true, xDiagram ).is();
419 bHasYAxis = bSupportsAxes && AxisHelper::getAxis( 1, true, xDiagram ).is();
420 bHasZAxis = bSupportsAxes && AxisHelper::getAxis( 2, true, xDiagram ).is();
421 bHasAAxis = bSupportsAxes && AxisHelper::getAxis( 0, false, xDiagram ).is();
422 bHasBAxis = bSupportsAxes && AxisHelper::getAxis( 1, false, xDiagram ).is();
424 bHasMainXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, true, xDiagram );
425 bHasMainYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, true, xDiagram );
426 bHasMainZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, true, xDiagram );
427 bHasHelpXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, false, xDiagram );
428 bHasHelpYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, false, xDiagram );
429 bHasHelpZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, false, xDiagram );
431 bHasAutoScaledText =
432 (ReferenceSizeProvider::getAutoResizeState( xChartDoc ) ==
433 ReferenceSizeProvider::AUTO_RESIZE_YES);
435 bHasLegend = LegendHelper::hasLegend( xDiagram );
436 bHasWall = DiagramHelper::isSupportingFloorAndWall( xDiagram );
437 bHasFloor = bHasWall && bIsThreeD;
440 bool ModelState::HasAnyAxis() const
442 return bHasXAxis || bHasYAxis || bHasZAxis || bHasAAxis || bHasBAxis;
445 bool ModelState::HasAnyGrid() const
447 return bHasMainXGrid || bHasMainYGrid || bHasMainZGrid ||
448 bHasHelpXGrid || bHasHelpYGrid || bHasHelpZGrid;
451 bool ModelState::HasAnyTitle() const
453 return bHasMainTitle || bHasSubTitle || bHasXAxisTitle || bHasYAxisTitle || bHasZAxisTitle || bHasSecondaryXAxisTitle || bHasSecondaryYAxisTitle;
456 } // namespace impl
458 // ----------------------------------------
459 DBG_NAME(ControllerCommandDispatch)
461 ControllerCommandDispatch::ControllerCommandDispatch(
462 const Reference< uno::XComponentContext > & xContext,
463 const Reference< frame::XController > & xController ) :
464 impl::ControllerCommandDispatch_Base( xContext ),
465 m_xController( xController ),
466 m_xSelectionSupplier( xController, uno::UNO_QUERY ),
467 m_xDispatch( xController, uno::UNO_QUERY ),
468 m_apModelState( new impl::ModelState() ),
469 m_apControllerState( new impl::ControllerState() )
471 DBG_CTOR(ControllerCommandDispatch,NULL);
474 ControllerCommandDispatch::~ControllerCommandDispatch()
477 DBG_DTOR(ControllerCommandDispatch,NULL);
480 void ControllerCommandDispatch::initialize()
482 if( m_xController.is())
484 Reference< frame::XModel > xModel( m_xController->getModel());
485 Reference< util::XModifyBroadcaster > xModifyBroadcaster( xModel, uno::UNO_QUERY );
486 OSL_ASSERT( xModifyBroadcaster.is());
487 if( xModifyBroadcaster.is())
488 xModifyBroadcaster->addModifyListener( this );
490 // Listen selection modifications (Arrangement feature - issue 63017).
491 if( m_xSelectionSupplier.is() )
492 m_xSelectionSupplier->addSelectionChangeListener( this );
494 if( m_apModelState.get() && xModel.is())
495 m_apModelState->update( xModel );
497 if( m_apControllerState.get() && xModel.is())
498 m_apControllerState->update( m_xController, xModel );
500 updateCommandAvailability();
504 void ControllerCommandDispatch::fireStatusEventForURLImpl(
505 const OUString & rURL,
506 const Reference< frame::XStatusListener > & xSingleListener )
508 ::std::map< OUString, uno::Any >::const_iterator aArgIt( m_aCommandArguments.find( rURL ));
509 if( aArgIt != m_aCommandArguments.end())
510 fireStatusEventForURL( rURL, aArgIt->second, commandAvailable( rURL ), xSingleListener );
511 else
512 fireStatusEventForURL( rURL, uno::Any(), commandAvailable( rURL ), xSingleListener );
515 void ControllerCommandDispatch::updateCommandAvailability()
517 bool bModelStateIsValid = ( m_apModelState.get() != 0 );
518 bool bControllerStateIsValid = ( m_apControllerState.get() != 0 );
519 // Model and controller states exist.
520 OSL_ASSERT( bModelStateIsValid );
521 OSL_ASSERT( bControllerStateIsValid );
523 // read-only
524 bool bIsWritable = bModelStateIsValid && (! m_apModelState->bIsReadOnly);
525 // paste is available
526 // @todo: determine correctly
527 bool bHasSuitableClipboardContent = true;
529 // edit commands
530 m_aCommandAvailability[ C2U(".uno:Cut")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsDeleteableObjectSelected;
531 m_aCommandAvailability[ C2U(".uno:Copy")] = bControllerStateIsValid && m_apControllerState->bHasSelectedObject;
532 m_aCommandAvailability[ C2U(".uno:Paste")] = bIsWritable && bHasSuitableClipboardContent;
534 // toolbar commands
535 m_aCommandAvailability[ C2U(".uno:ToggleGridHorizontal")] = bIsWritable;
536 m_aCommandArguments[ C2U(".uno:ToggleGridHorizontal")] = uno::makeAny( m_apModelState->bHasMainYGrid );
538 m_aCommandAvailability[ C2U(".uno:ToggleLegend")] = bIsWritable;
539 m_aCommandArguments[ C2U(".uno:ToggleLegend")] = uno::makeAny( m_apModelState->bHasLegend );
541 m_aCommandAvailability[ C2U(".uno:NewArrangement")] = bIsWritable;
542 m_aCommandAvailability[ C2U(".uno:Update")] = bIsWritable;
543 m_aCommandAvailability[ C2U(".uno:DefaultColors")] = bIsWritable;
544 m_aCommandAvailability[ C2U(".uno:BarWidth")] = bIsWritable;
545 m_aCommandAvailability[ C2U(".uno:NumberOfLines")] = bIsWritable;
546 m_aCommandAvailability[ C2U(".uno:ArrangeRow")] = m_apControllerState->bMayMoveSeriesForward || m_apControllerState->bMayMoveSeriesBackward;
548 // insert objects
549 m_aCommandAvailability[ C2U(".uno:InsertTitles")] = m_aCommandAvailability[ C2U(".uno:InsertMenuTitles")] = bIsWritable;
550 m_aCommandAvailability[ C2U(".uno:InsertLegend")] = m_aCommandAvailability[ C2U(".uno:InsertMenuLegend")] = bIsWritable;
551 m_aCommandAvailability[ C2U(".uno:DeleteLegend")] = bIsWritable;
552 m_aCommandAvailability[ C2U(".uno:InsertMenuDataLabels")] = bIsWritable;
553 m_aCommandAvailability[ C2U(".uno:InsertRemoveAxes")] = m_aCommandAvailability[ C2U(".uno:InsertMenuAxes")] = bIsWritable && m_apModelState->bSupportsAxes;
554 m_aCommandAvailability[ C2U(".uno:InsertMenuGrids")] = bIsWritable && m_apModelState->bSupportsAxes;
555 m_aCommandAvailability[ C2U(".uno:InsertMenuTrendlines")] = bIsWritable && m_apModelState->bSupportsStatistics;
556 m_aCommandAvailability[ C2U(".uno:InsertMenuMeanValues")] = bIsWritable && m_apModelState->bSupportsStatistics;
557 m_aCommandAvailability[ C2U(".uno:InsertMenuYErrorBars")] = bIsWritable && m_apModelState->bSupportsStatistics;
558 m_aCommandAvailability[ C2U(".uno:InsertSymbol")] = bIsWritable && m_apControllerState->bIsTextObject;
560 // format objects
561 bool bFormatObjectAvailable = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsFormateableObjectSelected;
562 m_aCommandAvailability[ C2U(".uno:FormatSelection")] = bFormatObjectAvailable;
563 m_aCommandAvailability[ C2U(".uno:FormatAxis")] = bFormatObjectAvailable;
564 m_aCommandAvailability[ C2U(".uno:FormatTitle")] = bFormatObjectAvailable;
565 m_aCommandAvailability[ C2U(".uno:FormatDataSeries")] = bFormatObjectAvailable;
566 m_aCommandAvailability[ C2U(".uno:FormatDataPoint")] = bFormatObjectAvailable;
567 m_aCommandAvailability[ C2U(".uno:FormatDataLabels")] = bFormatObjectAvailable;
568 m_aCommandAvailability[ C2U(".uno:FormatDataLabel")] = bFormatObjectAvailable;
569 m_aCommandAvailability[ C2U(".uno:FormatYErrorBars")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatYErrorBars;
570 m_aCommandAvailability[ C2U(".uno:FormatMeanValue")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatMeanValue;
571 m_aCommandAvailability[ C2U(".uno:FormatTrendline")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendline;
572 m_aCommandAvailability[ C2U(".uno:FormatTrendlineEquation")] = bFormatObjectAvailable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendlineEquation;
573 m_aCommandAvailability[ C2U(".uno:FormatStockLoss")] = bFormatObjectAvailable;
574 m_aCommandAvailability[ C2U(".uno:FormatStockGain")] = bFormatObjectAvailable;
576 m_aCommandAvailability[ C2U(".uno:DiagramType")] = bIsWritable;
577 m_aCommandAvailability[ C2U(".uno:Legend")] = bIsWritable && m_apModelState->bHasLegend;
578 m_aCommandAvailability[ C2U(".uno:DiagramWall")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasWall;
579 m_aCommandAvailability[ C2U(".uno:DiagramArea")] = bIsWritable;
580 m_aCommandAvailability[ C2U(".uno:TransformDialog")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bHasSelectedObject && m_apControllerState->bIsPositionableObject;
582 // 3d commands
583 m_aCommandAvailability[ C2U(".uno:View3D")] = bIsWritable && bModelStateIsValid && m_apModelState->bIsThreeD;
584 m_aCommandAvailability[ C2U(".uno:DiagramFloor")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasFloor;
586 //some mor format commands with different ui text
587 m_aCommandAvailability[ C2U(".uno:FormatWall")] = m_aCommandAvailability[ C2U(".uno:DiagramWall")];
588 m_aCommandAvailability[ C2U(".uno:FormatFloor")] = m_aCommandAvailability[ C2U(".uno:DiagramFloor")];
589 m_aCommandAvailability[ C2U(".uno:FormatChartArea")] = m_aCommandAvailability[ C2U(".uno:DiagramArea")];
590 m_aCommandAvailability[ C2U(".uno:FormatLegend")] = m_aCommandAvailability[ C2U(".uno:Legend")];
592 // depending on own data
593 m_aCommandAvailability[ C2U(".uno:DataRanges")] = bIsWritable && bModelStateIsValid && (! m_apModelState->bHasOwnData);
594 m_aCommandAvailability[ C2U(".uno:DiagramData")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData;
596 // titles
597 m_aCommandAvailability[ C2U(".uno:MainTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainTitle;
598 m_aCommandAvailability[ C2U(".uno:SubTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSubTitle;
599 m_aCommandAvailability[ C2U(".uno:XTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxisTitle;
600 m_aCommandAvailability[ C2U(".uno:YTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxisTitle;
601 m_aCommandAvailability[ C2U(".uno:ZTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxisTitle;
602 m_aCommandAvailability[ C2U(".uno:SecondaryXTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryXAxisTitle;
603 m_aCommandAvailability[ C2U(".uno:SecondaryYTitle")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryYAxisTitle;
604 m_aCommandAvailability[ C2U(".uno:AllTitles")] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyTitle();
606 // text
607 m_aCommandAvailability[ C2U(".uno:ScaleText")] = bIsWritable && bModelStateIsValid ;
608 m_aCommandArguments[ C2U(".uno:ScaleText")] = uno::makeAny( m_apModelState->bHasAutoScaledText );
610 // axes
611 m_aCommandAvailability[ C2U(".uno:DiagramAxisX")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxis;
612 m_aCommandAvailability[ C2U(".uno:DiagramAxisY")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxis;
613 m_aCommandAvailability[ C2U(".uno:DiagramAxisZ")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxis;
614 m_aCommandAvailability[ C2U(".uno:DiagramAxisA")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasAAxis;
615 m_aCommandAvailability[ C2U(".uno:DiagramAxisB")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasBAxis;
616 m_aCommandAvailability[ C2U(".uno:DiagramAxisAll")] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyAxis();
618 // grids
619 // note: x and y are swapped in the commands!
620 m_aCommandAvailability[ C2U(".uno:DiagramGridYMain")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainXGrid;
621 m_aCommandAvailability[ C2U(".uno:DiagramGridXMain")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainYGrid;
622 m_aCommandAvailability[ C2U(".uno:DiagramGridZMain")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainZGrid;
623 m_aCommandAvailability[ C2U(".uno:DiagramGridYHelp")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpXGrid;
624 m_aCommandAvailability[ C2U(".uno:DiagramGridXHelp")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpYGrid;
625 m_aCommandAvailability[ C2U(".uno:DiagramGridZHelp")] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpZGrid;
626 m_aCommandAvailability[ C2U(".uno:DiagramGridAll")] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyGrid();
628 // series arrangement
629 m_aCommandAvailability[ C2U(".uno:Forward")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesForward;
630 m_aCommandAvailability[ C2U(".uno:Backward")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesBackward;
632 m_aCommandAvailability[ C2U(".uno:InsertDataLabels")] = bIsWritable;
633 m_aCommandAvailability[ C2U(".uno:InsertDataLabel")] = bIsWritable;
634 m_aCommandAvailability[ C2U(".uno:InsertMeanValue")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddMeanValue;
635 m_aCommandAvailability[ C2U(".uno:InsertTrendline")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendline;
636 m_aCommandAvailability[ C2U(".uno:InsertTrendlineEquation")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendlineEquation;
637 m_aCommandAvailability[ C2U(".uno:InsertTrendlineEquationAndR2")] = m_aCommandAvailability[ C2U(".uno:InsertTrendlineEquation")];
638 m_aCommandAvailability[ C2U(".uno:InsertR2Value")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value;
639 m_aCommandAvailability[ C2U(".uno:DeleteR2Value")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteR2Value;
641 m_aCommandAvailability[ C2U(".uno:InsertYErrorBars")] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddYErrorBars;
643 m_aCommandAvailability[ C2U(".uno:DeleteDataLabels")] = bIsWritable;
644 m_aCommandAvailability[ C2U(".uno:DeleteDataLabel") ] = bIsWritable;
645 m_aCommandAvailability[ C2U(".uno:DeleteTrendline") ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendline;
646 m_aCommandAvailability[ C2U(".uno:DeleteTrendlineEquation") ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendlineEquation;
647 m_aCommandAvailability[ C2U(".uno:DeleteMeanValue") ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteMeanValue;
648 m_aCommandAvailability[ C2U(".uno:DeleteYErrorBars") ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteYErrorBars;
650 m_aCommandAvailability[ C2U(".uno:ResetDataPoint") ] = bIsWritable;
651 m_aCommandAvailability[ C2U(".uno:ResetAllDataPoints") ] = bIsWritable;
653 m_aCommandAvailability[ C2U(".uno:InsertAxis") ] = bIsWritable;
654 m_aCommandAvailability[ C2U(".uno:DeleteAxis") ] = bIsWritable;
655 m_aCommandAvailability[ C2U(".uno:InsertAxisTitle") ] = bIsWritable;
656 m_aCommandAvailability[ C2U(".uno:FormatMajorGrid") ] = bIsWritable;
657 m_aCommandAvailability[ C2U(".uno:InsertMajorGrid") ] = bIsWritable;
658 m_aCommandAvailability[ C2U(".uno:DeleteMajorGrid") ] = bIsWritable;
659 m_aCommandAvailability[ C2U(".uno:FormatMinorGrid") ] = bIsWritable;
660 m_aCommandAvailability[ C2U(".uno:InsertMinorGrid") ] = bIsWritable;
661 m_aCommandAvailability[ C2U(".uno:DeleteMinorGrid") ] = bIsWritable;
664 bool ControllerCommandDispatch::commandAvailable( const OUString & rCommand )
666 ::std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.find( rCommand ));
667 if( aIt != m_aCommandAvailability.end())
668 return aIt->second;
669 OSL_ENSURE( false, "commandAvailable: command not in availability map" );
670 return false;
673 void ControllerCommandDispatch::fireStatusEvent(
674 const OUString & rURL,
675 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
677 bool bIsChartSelectorURL = rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:ChartElementSelector") );
678 if( rURL.getLength() == 0 || bIsChartSelectorURL )
680 uno::Any aArg;
681 aArg <<= m_xController;
682 fireStatusEventForURL( C2U(".uno:ChartElementSelector"), aArg, true, xSingleListener );
685 if( rURL.getLength() == 0 )
686 for( ::std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.begin());
687 aIt != m_aCommandAvailability.end(); ++aIt )
688 fireStatusEventForURLImpl( aIt->first, xSingleListener );
689 else if( !bIsChartSelectorURL )
690 fireStatusEventForURLImpl( rURL, xSingleListener );
692 // statusbar. Should be handled by base implementation
693 // @todo: remove if Issue 68864 is fixed
694 if( rURL.getLength() == 0 ||
695 rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:StatusBarVisible")))
697 bool bIsStatusBarVisible( lcl_isStatusBarVisible( m_xController ));
698 fireStatusEventForURL( C2U(".uno:StatusBarVisible"), uno::makeAny( bIsStatusBarVisible ), true, xSingleListener );
702 // ____ XDispatch ____
703 void SAL_CALL ControllerCommandDispatch::dispatch(
704 const util::URL& URL,
705 const Sequence< beans::PropertyValue >& Arguments )
706 throw (uno::RuntimeException)
708 if( commandAvailable( URL.Complete ))
709 m_xDispatch->dispatch( URL, Arguments );
712 // ____ WeakComponentImplHelperBase ____
713 /// is called when this is disposed
714 void SAL_CALL ControllerCommandDispatch::disposing()
716 m_xController.clear();
717 m_xDispatch.clear();
718 m_xSelectionSupplier.clear();
721 // ____ XEventListener (base of XModifyListener) ____
722 void SAL_CALL ControllerCommandDispatch::disposing( const lang::EventObject& /* Source */ )
723 throw (uno::RuntimeException)
725 m_xController.clear();
726 m_xDispatch.clear();
727 m_xSelectionSupplier.clear();
730 // ____ XModifyListener ____
731 void SAL_CALL ControllerCommandDispatch::modified( const lang::EventObject& aEvent )
732 throw (uno::RuntimeException)
734 bool bUpdateCommandAvailability = false;
736 // Update the "ModelState" Struct.
737 if( m_apModelState.get() && m_xController.is())
739 m_apModelState->update( m_xController->getModel());
740 bUpdateCommandAvailability = true;
743 // Update the "ControllerState" Struct.
744 if( m_apControllerState.get() && m_xController.is())
746 m_apControllerState->update( m_xController, m_xController->getModel());
747 bUpdateCommandAvailability = true;
750 if( bUpdateCommandAvailability )
751 updateCommandAvailability();
753 CommandDispatch::modified( aEvent );
757 // ____ XSelectionChangeListener ____
758 void SAL_CALL ControllerCommandDispatch::selectionChanged( const lang::EventObject& aEvent )
759 throw (uno::RuntimeException)
761 // Update the "ControllerState" Struct.
762 if( m_apControllerState.get() && m_xController.is())
764 m_apControllerState->update( m_xController, m_xController->getModel());
765 updateCommandAvailability();
768 CommandDispatch::modified( aEvent );
771 } // namespace chart