Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "ControllerCommandDispatch.hxx"
22 : #include "ChartModelHelper.hxx"
23 : #include "DiagramHelper.hxx"
24 : #include "AxisHelper.hxx"
25 : #include "TitleHelper.hxx"
26 : #include "LegendHelper.hxx"
27 : #include "ObjectIdentifier.hxx"
28 : #include "macros.hxx"
29 : #include "ChartTypeHelper.hxx"
30 : #include "ChartController.hxx"
31 : #include "RegressionCurveHelper.hxx"
32 : #include "DataSeriesHelper.hxx"
33 : #include "StatisticsHelper.hxx"
34 : #include "ShapeController.hxx"
35 :
36 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
37 : #include <com/sun/star/frame/XStorable.hpp>
38 : #include <com/sun/star/chart2/XChartDocument.hpp>
39 : #include <com/sun/star/chart2/XChartType.hpp>
40 : #include <com/sun/star/chart2/XDataSeries.hpp>
41 : #include <com/sun/star/chart2/XRegressionCurve.hpp>
42 : #include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
43 :
44 : // only needed until #i68864# is fixed
45 : #include <com/sun/star/frame/XLayoutManager.hpp>
46 :
47 : using namespace ::com::sun::star;
48 :
49 : using ::com::sun::star::uno::Reference;
50 : using ::com::sun::star::uno::Sequence;
51 :
52 : namespace
53 : {
54 772 : bool lcl_isStatusBarVisible( const Reference< frame::XController > & xController )
55 : {
56 772 : bool bIsStatusBarVisible = false;
57 : // Status-Bar visible, workaround: this should not be necessary. @todo:
58 : // remove when Issue #i68864# is fixed
59 772 : if( xController.is())
60 : {
61 772 : Reference< beans::XPropertySet > xPropSet( xController->getFrame(), uno::UNO_QUERY );
62 772 : if( xPropSet.is() )
63 : {
64 772 : uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
65 772 : xPropSet->getPropertyValue( "LayoutManager" ) >>= xLayoutManager;
66 772 : if ( xLayoutManager.is() )
67 772 : bIsStatusBarVisible = xLayoutManager->isElementVisible( "private:resource/statusbar/statusbar" );
68 772 : }
69 : }
70 772 : return bIsStatusBarVisible;
71 : }
72 :
73 : } // anonymous namespace
74 :
75 : namespace chart
76 : {
77 :
78 : // ----------------------------------------
79 :
80 : namespace impl
81 : {
82 :
83 : /// Constants for moving the series.
84 : enum EnumForward{
85 : MOVE_SERIES_FORWARD = true,
86 : MOVE_SERIES_BACKWARD = false
87 : };
88 :
89 : /** Represents the current state of the controller (needed for issue 63017).
90 :
91 : You can set the state by calling update(). After this call the state is
92 : preserved in this class until the next call to update().
93 :
94 : This is useful, not to say necessary, for enabling and disabling of menu
95 : entries (e.g. format>arrangement). As the status requests are sent very
96 : frequently it would be impossible, from a performance point of view, to
97 : query the current status every time directly at the model. So this class
98 : serves as a cache for the state.
99 : */
100 : struct ControllerState
101 : {
102 : ControllerState();
103 :
104 : void update( const Reference< frame::XController > & xController,
105 : const Reference< frame::XModel > & xModel );
106 :
107 : // -- State variables -------
108 : bool bHasSelectedObject;
109 : bool bIsPositionableObject;
110 : bool bIsTextObject;
111 : bool bIsDeleteableObjectSelected;
112 : bool bIsFormateableObjectSelected;
113 :
114 : // May the selected series be moved forward or backward (cf
115 : // format>arrangement).
116 : bool bMayMoveSeriesForward;
117 : bool bMayMoveSeriesBackward;
118 :
119 : // trendlines
120 : bool bMayAddMenuTrendline;
121 : bool bMayAddTrendline;
122 : bool bMayAddTrendlineEquation;
123 : bool bMayAddR2Value;
124 : bool bMayAddMeanValue;
125 : bool bMayAddXErrorBars;
126 : bool bMayAddYErrorBars;
127 :
128 : bool bMayDeleteTrendline;
129 : bool bMayDeleteTrendlineEquation;
130 : bool bMayDeleteR2Value;
131 : bool bMayDeleteMeanValue;
132 : bool bMayDeleteXErrorBars;
133 : bool bMayDeleteYErrorBars;
134 :
135 : bool bMayFormatTrendline;
136 : bool bMayFormatTrendlineEquation;
137 : bool bMayFormatMeanValue;
138 : bool bMayFormatXErrorBars;
139 : bool bMayFormatYErrorBars;
140 : };
141 :
142 :
143 17 : ControllerState::ControllerState() :
144 : bHasSelectedObject( false ),
145 : bIsPositionableObject( false ),
146 : bIsTextObject(false),
147 : bIsDeleteableObjectSelected(false),
148 : bIsFormateableObjectSelected(false),
149 : bMayMoveSeriesForward( false ),
150 : bMayMoveSeriesBackward( false ),
151 : bMayAddMenuTrendline( false ),
152 : bMayAddTrendline( false ),
153 : bMayAddTrendlineEquation( false ),
154 : bMayAddR2Value( false ),
155 : bMayAddMeanValue( false ),
156 : bMayAddXErrorBars( false ),
157 : bMayAddYErrorBars( false ),
158 : bMayDeleteTrendline( false ),
159 : bMayDeleteTrendlineEquation( false ),
160 : bMayDeleteR2Value( false ),
161 : bMayDeleteMeanValue( false ),
162 : bMayDeleteXErrorBars( false ),
163 : bMayDeleteYErrorBars( false ),
164 : bMayFormatTrendline( false ),
165 : bMayFormatTrendlineEquation( false ),
166 : bMayFormatMeanValue( false ),
167 : bMayFormatXErrorBars( false ),
168 17 : bMayFormatYErrorBars( false )
169 17 : {}
170 :
171 789 : void ControllerState::update(
172 : const Reference< frame::XController > & xController,
173 : const Reference< frame::XModel > & xModel )
174 : {
175 : Reference< view::XSelectionSupplier > xSelectionSupplier(
176 789 : xController, uno::UNO_QUERY );
177 :
178 : // Update ControllerState variables.
179 789 : if( xSelectionSupplier.is())
180 : {
181 789 : uno::Any aSelObj( xSelectionSupplier->getSelection() );
182 1578 : ObjectIdentifier aSelOID( aSelObj );
183 1578 : OUString aSelObjCID( aSelOID.getObjectCID() );
184 :
185 789 : bHasSelectedObject = aSelOID.isValid();
186 :
187 789 : ObjectType aObjectType(ObjectIdentifier::getObjectType( aSelObjCID ));
188 :
189 789 : bIsPositionableObject = (OBJECTTYPE_DATA_POINT != aObjectType) && aSelOID.isDragableObject();
190 789 : bIsTextObject = OBJECTTYPE_TITLE == aObjectType;
191 :
192 1578 : uno::Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
193 789 : bIsFormateableObjectSelected = bHasSelectedObject && aSelOID.isAutoGeneratedObject();
194 789 : if( OBJECTTYPE_DIAGRAM==aObjectType || OBJECTTYPE_DIAGRAM_WALL==aObjectType || OBJECTTYPE_DIAGRAM_FLOOR==aObjectType )
195 0 : bIsFormateableObjectSelected = DiagramHelper::isSupportingFloorAndWall( xDiagram );
196 :
197 : uno::Reference< chart2::XDataSeries > xGivenDataSeries(
198 : ObjectIdentifier::getDataSeriesForCID(
199 1578 : aSelObjCID, xModel ) );
200 :
201 789 : bIsDeleteableObjectSelected = ChartController::isObjectDeleteable( aSelObj );
202 :
203 2367 : bMayMoveSeriesForward = (OBJECTTYPE_DATA_POINT!=aObjectType) && DiagramHelper::isSeriesMoveable(
204 : ChartModelHelper::findDiagram( xModel ),
205 : xGivenDataSeries,
206 2367 : MOVE_SERIES_FORWARD );
207 :
208 2367 : bMayMoveSeriesBackward = (OBJECTTYPE_DATA_POINT!=aObjectType) && DiagramHelper::isSeriesMoveable(
209 : ChartModelHelper::findDiagram( xModel ),
210 : xGivenDataSeries,
211 2367 : MOVE_SERIES_BACKWARD );
212 :
213 789 : bMayAddMenuTrendline = false;
214 789 : bMayAddTrendline = false;
215 789 : bMayAddTrendlineEquation = false;
216 789 : bMayAddR2Value = false;
217 789 : bMayAddMeanValue = false;
218 789 : bMayAddXErrorBars = false;
219 789 : bMayAddYErrorBars = false;
220 789 : bMayDeleteTrendline = false;
221 789 : bMayDeleteTrendlineEquation = false;
222 789 : bMayDeleteR2Value = false;
223 789 : bMayDeleteMeanValue = false;
224 789 : bMayDeleteXErrorBars = false;
225 789 : bMayDeleteYErrorBars = false;
226 789 : bMayFormatTrendline = false;
227 789 : bMayFormatTrendlineEquation = false;
228 789 : bMayFormatMeanValue = false;
229 789 : bMayFormatXErrorBars = false;
230 789 : bMayFormatYErrorBars = false;
231 789 : if( bHasSelectedObject )
232 : {
233 0 : if( xGivenDataSeries.is())
234 : {
235 0 : bMayAddMenuTrendline = true;
236 0 : sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
237 : uno::Reference< chart2::XChartType > xFirstChartType(
238 0 : DataSeriesHelper::getChartTypeOfSeries( xGivenDataSeries, xDiagram ));
239 :
240 : // trend lines/mean value line
241 0 : if( (OBJECTTYPE_DATA_SERIES == aObjectType || OBJECTTYPE_DATA_POINT == aObjectType)
242 0 : && ChartTypeHelper::isSupportingRegressionProperties( xFirstChartType, nDimensionCount ))
243 : {
244 0 : uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xGivenDataSeries, uno::UNO_QUERY );
245 0 : if( xRegCurveCnt.is())
246 : {
247 : // Trendline
248 0 : bMayAddTrendline = true;
249 :
250 : // Mean Value
251 0 : bMayFormatMeanValue = bMayDeleteMeanValue = RegressionCurveHelper::hasMeanValueLine( xRegCurveCnt );
252 0 : bMayAddMeanValue = ! bMayDeleteMeanValue;
253 0 : }
254 : }
255 :
256 : // error bars
257 0 : if( (OBJECTTYPE_DATA_SERIES == aObjectType || OBJECTTYPE_DATA_POINT == aObjectType)
258 0 : && ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType, nDimensionCount ))
259 : {
260 0 : bMayFormatXErrorBars = bMayDeleteXErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries, false );
261 0 : bMayAddXErrorBars = ! bMayDeleteXErrorBars;
262 :
263 0 : bMayFormatYErrorBars = bMayDeleteYErrorBars = StatisticsHelper::hasErrorBars( xGivenDataSeries, true );
264 0 : bMayAddYErrorBars = ! bMayDeleteYErrorBars;
265 0 : }
266 : }
267 :
268 0 : if( aObjectType == OBJECTTYPE_DATA_AVERAGE_LINE )
269 0 : bMayFormatMeanValue = true;
270 :
271 0 : if( aObjectType == OBJECTTYPE_DATA_ERRORS_X)
272 0 : bMayFormatXErrorBars = true;
273 :
274 0 : if( aObjectType == OBJECTTYPE_DATA_ERRORS_Y )
275 0 : bMayFormatYErrorBars = true;
276 :
277 0 : if( aObjectType == OBJECTTYPE_DATA_CURVE )
278 : {
279 0 : bMayFormatTrendline = true;
280 0 : bMayDeleteTrendline = true;
281 : uno::Reference< chart2::XRegressionCurve > xRegCurve(
282 0 : ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ), uno::UNO_QUERY );
283 :
284 : // Trendline Equation
285 0 : bMayFormatTrendlineEquation = bMayDeleteTrendlineEquation = RegressionCurveHelper::hasEquation( xRegCurve );
286 0 : bMayAddTrendlineEquation = !bMayDeleteTrendlineEquation;
287 : }
288 0 : else if( aObjectType == OBJECTTYPE_DATA_CURVE_EQUATION )
289 : {
290 0 : bMayFormatTrendlineEquation = true;
291 0 : bool bHasR2Value = false;
292 : try
293 : {
294 : uno::Reference< beans::XPropertySet > xEquationProperties(
295 0 : ObjectIdentifier::getObjectPropertySet( aSelObjCID, xModel ), uno::UNO_QUERY );
296 0 : if( xEquationProperties.is() )
297 0 : xEquationProperties->getPropertyValue( "ShowCorrelationCoefficient" ) >>= bHasR2Value;
298 : }
299 0 : catch(const uno::RuntimeException& e)
300 : {
301 : ASSERT_EXCEPTION( e );
302 : }
303 0 : bMayAddR2Value = !bHasR2Value;
304 0 : bMayDeleteR2Value = bHasR2Value;
305 : }
306 789 : }
307 789 : }
308 789 : }
309 :
310 :
311 : /** Represents the current state of the model.
312 :
313 : You can set the state by calling update(). After this call the state is
314 : preserved in this class until the next call to update().
315 :
316 : This is useful, not to say necessary, for enabling and disabling of menu
317 : entries and toolbar icons. As the status requests are sent very frequently
318 : it would be impossible, from a performance point of view, to query the
319 : current status every time directly at the model. So this class serves as a
320 : cache for the state.
321 : */
322 : struct ModelState
323 : {
324 : ModelState();
325 :
326 : void update( const Reference< frame::XModel > & xModel );
327 :
328 : bool HasAnyAxis() const;
329 : bool HasAnyGrid() const;
330 : bool HasAnyTitle() const;
331 :
332 : bool bIsReadOnly;
333 : bool bIsThreeD;
334 : bool bHasOwnData;
335 :
336 : bool bHasMainTitle;
337 : bool bHasSubTitle;
338 : bool bHasXAxisTitle;
339 : bool bHasYAxisTitle;
340 : bool bHasZAxisTitle;
341 : bool bHasSecondaryXAxisTitle;
342 : bool bHasSecondaryYAxisTitle;
343 :
344 : bool bHasXAxis;
345 : bool bHasYAxis;
346 : bool bHasZAxis;
347 : bool bHasAAxis;
348 : bool bHasBAxis;
349 :
350 : bool bHasMainXGrid;
351 : bool bHasMainYGrid;
352 : bool bHasMainZGrid;
353 : bool bHasHelpXGrid;
354 : bool bHasHelpYGrid;
355 : bool bHasHelpZGrid;
356 :
357 : bool bHasAutoScaledText;
358 : bool bHasLegend;
359 : bool bHasWall;
360 : bool bHasFloor;
361 :
362 : bool bSupportsStatistics;
363 : bool bSupportsAxes;
364 : };
365 :
366 17 : ModelState::ModelState() :
367 : bIsReadOnly( true ),
368 : bIsThreeD( false ),
369 : bHasOwnData( false ),
370 : bHasMainTitle( false ),
371 : bHasSubTitle( false ),
372 : bHasXAxisTitle( false ),
373 : bHasYAxisTitle( false ),
374 : bHasZAxisTitle( false ),
375 : bHasSecondaryXAxisTitle( false ),
376 : bHasSecondaryYAxisTitle( false ),
377 : bHasXAxis( false ),
378 : bHasYAxis( false ),
379 : bHasZAxis( false ),
380 : bHasAAxis( false ),
381 : bHasBAxis( false ),
382 : bHasMainXGrid( false ),
383 : bHasMainYGrid( false ),
384 : bHasMainZGrid( false ),
385 : bHasHelpXGrid( false ),
386 : bHasHelpYGrid( false ),
387 : bHasHelpZGrid( false ),
388 : bHasAutoScaledText( false ),
389 : bHasLegend( false ),
390 : bHasWall( false ),
391 : bHasFloor( false ),
392 : bSupportsStatistics( false ),
393 17 : bSupportsAxes( false )
394 :
395 17 : {}
396 :
397 789 : void ModelState::update( const Reference< frame::XModel > & xModel )
398 : {
399 789 : Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
400 1578 : Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xModel ));
401 :
402 789 : bIsReadOnly = true;
403 1578 : Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY );
404 789 : if( xStorable.is())
405 789 : bIsReadOnly = xStorable->isReadonly();
406 :
407 789 : sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
408 :
409 1578 : uno::Reference< chart2::XChartType > xFirstChartType( DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) );
410 789 : bSupportsStatistics = ChartTypeHelper::isSupportingStatisticProperties( xFirstChartType, nDimensionCount );
411 789 : bSupportsAxes = ChartTypeHelper::isSupportingMainAxis( xFirstChartType, nDimensionCount, 0 );
412 :
413 789 : bIsThreeD = (nDimensionCount == 3);
414 789 : bHasOwnData = (xChartDoc.is() && xChartDoc->hasInternalDataProvider());
415 :
416 789 : bHasMainTitle = TitleHelper::getTitle( TitleHelper::MAIN_TITLE, xModel ).is();
417 789 : bHasSubTitle = TitleHelper::getTitle( TitleHelper::SUB_TITLE, xModel ).is();
418 789 : bHasXAxisTitle = TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, xModel ).is();
419 789 : bHasYAxisTitle = TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, xModel ).is();
420 789 : bHasZAxisTitle = TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE, xModel ).is();
421 789 : bHasSecondaryXAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xModel ).is();
422 789 : bHasSecondaryYAxisTitle = TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xModel ).is();
423 :
424 789 : bHasXAxis = bSupportsAxes && AxisHelper::getAxis( 0, true, xDiagram ).is();
425 789 : bHasYAxis = bSupportsAxes && AxisHelper::getAxis( 1, true, xDiagram ).is();
426 789 : bHasZAxis = bSupportsAxes && AxisHelper::getAxis( 2, true, xDiagram ).is();
427 789 : bHasAAxis = bSupportsAxes && AxisHelper::getAxis( 0, false, xDiagram ).is();
428 789 : bHasBAxis = bSupportsAxes && AxisHelper::getAxis( 1, false, xDiagram ).is();
429 :
430 789 : bHasMainXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, true, xDiagram );
431 789 : bHasMainYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, true, xDiagram );
432 789 : bHasMainZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, true, xDiagram );
433 789 : bHasHelpXGrid = bSupportsAxes && AxisHelper::isGridShown( 0, 0, false, xDiagram );
434 789 : bHasHelpYGrid = bSupportsAxes && AxisHelper::isGridShown( 1, 0, false, xDiagram );
435 789 : bHasHelpZGrid = bSupportsAxes && AxisHelper::isGridShown( 2, 0, false, xDiagram );
436 :
437 : bHasAutoScaledText =
438 789 : (ReferenceSizeProvider::getAutoResizeState( xChartDoc ) ==
439 789 : ReferenceSizeProvider::AUTO_RESIZE_YES);
440 :
441 789 : bHasLegend = LegendHelper::hasLegend( xDiagram );
442 789 : bHasWall = DiagramHelper::isSupportingFloorAndWall( xDiagram );
443 1578 : bHasFloor = bHasWall && bIsThreeD;
444 789 : }
445 :
446 789 : bool ModelState::HasAnyAxis() const
447 : {
448 789 : return bHasXAxis || bHasYAxis || bHasZAxis || bHasAAxis || bHasBAxis;
449 : }
450 :
451 789 : bool ModelState::HasAnyGrid() const
452 : {
453 719 : return bHasMainXGrid || bHasMainYGrid || bHasMainZGrid ||
454 1034 : bHasHelpXGrid || bHasHelpYGrid || bHasHelpZGrid;
455 : }
456 :
457 789 : bool ModelState::HasAnyTitle() const
458 : {
459 789 : return bHasMainTitle || bHasSubTitle || bHasXAxisTitle || bHasYAxisTitle || bHasZAxisTitle || bHasSecondaryXAxisTitle || bHasSecondaryYAxisTitle;
460 : }
461 :
462 : } // namespace impl
463 :
464 : // ----------------------------------------
465 : DBG_NAME(ControllerCommandDispatch)
466 :
467 17 : ControllerCommandDispatch::ControllerCommandDispatch(
468 : const Reference< uno::XComponentContext > & xContext,
469 : ChartController* pController, CommandDispatchContainer* pContainer ) :
470 : impl::ControllerCommandDispatch_Base( xContext ),
471 : m_pChartController( pController ),
472 17 : m_xController( Reference< frame::XController >( pController ) ),
473 17 : m_xSelectionSupplier( Reference< view::XSelectionSupplier >( pController ) ),
474 17 : m_xDispatch( Reference< frame::XDispatch >( pController ) ),
475 : m_apModelState( new impl::ModelState() ),
476 : m_apControllerState( new impl::ControllerState() ),
477 68 : m_pDispatchContainer( pContainer )
478 : {
479 : DBG_CTOR(ControllerCommandDispatch,NULL);
480 17 : }
481 :
482 34 : ControllerCommandDispatch::~ControllerCommandDispatch()
483 : {
484 :
485 : DBG_DTOR(ControllerCommandDispatch,NULL);
486 34 : }
487 :
488 17 : void ControllerCommandDispatch::initialize()
489 : {
490 17 : if( m_xController.is())
491 : {
492 17 : Reference< frame::XModel > xModel( m_xController->getModel());
493 34 : Reference< util::XModifyBroadcaster > xModifyBroadcaster( xModel, uno::UNO_QUERY );
494 : OSL_ASSERT( xModifyBroadcaster.is());
495 17 : if( xModifyBroadcaster.is())
496 17 : xModifyBroadcaster->addModifyListener( this );
497 :
498 : // Listen selection modifications (Arrangement feature - issue 63017).
499 17 : if( m_xSelectionSupplier.is() )
500 17 : m_xSelectionSupplier->addSelectionChangeListener( this );
501 :
502 17 : if( m_apModelState.get() && xModel.is())
503 17 : m_apModelState->update( xModel );
504 :
505 17 : if( m_apControllerState.get() && xModel.is())
506 17 : m_apControllerState->update( m_xController, xModel );
507 :
508 34 : updateCommandAvailability();
509 : }
510 17 : }
511 :
512 81247 : void ControllerCommandDispatch::fireStatusEventForURLImpl(
513 : const OUString & rURL,
514 : const Reference< frame::XStatusListener > & xSingleListener )
515 : {
516 81247 : ::std::map< OUString, uno::Any >::const_iterator aArgIt( m_aCommandArguments.find( rURL ));
517 81247 : if( aArgIt != m_aCommandArguments.end())
518 3156 : fireStatusEventForURL( rURL, aArgIt->second, commandAvailable( rURL ), xSingleListener );
519 : else
520 78091 : fireStatusEventForURL( rURL, uno::Any(), commandAvailable( rURL ), xSingleListener );
521 81247 : }
522 :
523 789 : void ControllerCommandDispatch::updateCommandAvailability()
524 : {
525 789 : bool bModelStateIsValid = ( m_apModelState.get() != 0 );
526 789 : bool bControllerStateIsValid = ( m_apControllerState.get() != 0 );
527 : // Model and controller states exist.
528 : OSL_ASSERT( bModelStateIsValid );
529 : OSL_ASSERT( bControllerStateIsValid );
530 :
531 : // read-only
532 789 : bool bIsWritable = bModelStateIsValid && (! m_apModelState->bIsReadOnly);
533 : // paste is available
534 : // @todo: determine correctly
535 789 : bool bHasSuitableClipboardContent = true;
536 :
537 789 : bool bShapeContext = ( m_pChartController ? m_pChartController->isShapeContext() : false );
538 :
539 789 : bool bDisableDataTableDialog = false;
540 789 : if ( m_xController.is() )
541 : {
542 789 : Reference< beans::XPropertySet > xProps( m_xController->getModel(), uno::UNO_QUERY );
543 789 : if ( xProps.is() )
544 : {
545 : try
546 : {
547 789 : xProps->getPropertyValue( "DisableDataTableDialog" ) >>= bDisableDataTableDialog;
548 : }
549 0 : catch( const uno::Exception& e )
550 : {
551 : ASSERT_EXCEPTION( e );
552 : }
553 789 : }
554 : }
555 :
556 : // edit commands
557 789 : m_aCommandAvailability[ ".uno:Cut" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsDeleteableObjectSelected;
558 789 : m_aCommandAvailability[ ".uno:Copy" ] = bControllerStateIsValid && m_apControllerState->bHasSelectedObject;
559 789 : m_aCommandAvailability[ ".uno:Paste" ] = bIsWritable && bHasSuitableClipboardContent;
560 :
561 : // toolbar commands
562 789 : m_aCommandAvailability[ ".uno:ToggleGridHorizontal" ] = bIsWritable;
563 789 : m_aCommandArguments[ ".uno:ToggleGridHorizontal" ] = uno::makeAny( m_apModelState->bHasMainYGrid );
564 789 : m_aCommandAvailability[ ".uno:ToggleGridVertical" ] = bIsWritable;
565 789 : m_aCommandArguments[ ".uno:ToggleGridVertical" ] = uno::makeAny( m_apModelState->bHasMainXGrid );
566 :
567 789 : m_aCommandAvailability[ ".uno:ToggleLegend" ] = bIsWritable;
568 789 : m_aCommandArguments[ ".uno:ToggleLegend" ] = uno::makeAny( m_apModelState->bHasLegend );
569 :
570 789 : m_aCommandAvailability[ ".uno:NewArrangement" ] = bIsWritable;
571 789 : m_aCommandAvailability[ ".uno:Update" ] = bIsWritable;
572 789 : m_aCommandAvailability[ ".uno:DefaultColors" ] = bIsWritable;
573 789 : m_aCommandAvailability[ ".uno:BarWidth" ] = bIsWritable;
574 789 : m_aCommandAvailability[ ".uno:NumberOfLines" ] = bIsWritable;
575 1578 : m_aCommandAvailability[ ".uno:ArrangeRow" ] =
576 789 : bShapeContext || ( bIsWritable && bControllerStateIsValid && ( m_apControllerState->bMayMoveSeriesForward || m_apControllerState->bMayMoveSeriesBackward ) );
577 :
578 : // insert objects
579 789 : m_aCommandAvailability[ ".uno:InsertTitles" ] = m_aCommandAvailability[ ".uno:InsertMenuTitles" ] = bIsWritable;
580 789 : m_aCommandAvailability[ ".uno:InsertLegend" ] = m_aCommandAvailability[ ".uno:InsertMenuLegend" ] = bIsWritable;
581 789 : m_aCommandAvailability[ ".uno:DeleteLegend" ] = bIsWritable;
582 789 : m_aCommandAvailability[ ".uno:InsertMenuDataLabels" ] = bIsWritable;
583 789 : m_aCommandAvailability[ ".uno:InsertRemoveAxes" ] = m_aCommandAvailability[ ".uno:InsertMenuAxes" ] = bIsWritable && m_apModelState->bSupportsAxes;
584 789 : m_aCommandAvailability[ ".uno:InsertMenuGrids" ] = bIsWritable && m_apModelState->bSupportsAxes;
585 789 : m_aCommandAvailability[ ".uno:InsertMenuTrendlines" ] = bIsWritable && m_apModelState->bSupportsStatistics && m_apControllerState->bMayAddMenuTrendline;
586 789 : m_aCommandAvailability[ ".uno:InsertMenuMeanValues" ] = bIsWritable && m_apModelState->bSupportsStatistics;
587 789 : m_aCommandAvailability[ ".uno:InsertMenuXErrorBars" ] = bIsWritable && m_apModelState->bSupportsStatistics;
588 789 : m_aCommandAvailability[ ".uno:InsertMenuYErrorBars" ] = bIsWritable && m_apModelState->bSupportsStatistics;
589 789 : m_aCommandAvailability[ ".uno:InsertSymbol" ] = bIsWritable && m_apControllerState->bIsTextObject;
590 :
591 : // format objects
592 789 : bool bFormatObjectAvailable = bIsWritable && bControllerStateIsValid && m_apControllerState->bIsFormateableObjectSelected;
593 789 : m_aCommandAvailability[ ".uno:FormatSelection" ] = bFormatObjectAvailable;
594 789 : m_aCommandAvailability[ ".uno:FormatAxis" ] = bFormatObjectAvailable;
595 789 : m_aCommandAvailability[ ".uno:FormatTitle" ] = bFormatObjectAvailable;
596 789 : m_aCommandAvailability[ ".uno:FormatDataSeries" ] = bFormatObjectAvailable;
597 789 : m_aCommandAvailability[ ".uno:FormatDataPoint" ] = bFormatObjectAvailable;
598 789 : m_aCommandAvailability[ ".uno:FormatDataLabels" ] = bFormatObjectAvailable;
599 789 : m_aCommandAvailability[ ".uno:FormatDataLabel" ] = bFormatObjectAvailable;
600 789 : m_aCommandAvailability[ ".uno:FormatXErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatXErrorBars;
601 789 : m_aCommandAvailability[ ".uno:FormatYErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatYErrorBars;
602 789 : m_aCommandAvailability[ ".uno:FormatMeanValue" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatMeanValue;
603 789 : m_aCommandAvailability[ ".uno:FormatTrendline" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendline;
604 789 : m_aCommandAvailability[ ".uno:FormatTrendlineEquation" ] = bFormatObjectAvailable && bControllerStateIsValid && m_apControllerState->bMayFormatTrendlineEquation;
605 789 : m_aCommandAvailability[ ".uno:FormatStockLoss" ] = bFormatObjectAvailable;
606 789 : m_aCommandAvailability[ ".uno:FormatStockGain" ] = bFormatObjectAvailable;
607 :
608 789 : m_aCommandAvailability[ ".uno:DiagramType" ] = bIsWritable;
609 789 : m_aCommandAvailability[ ".uno:Legend" ] = bIsWritable && m_apModelState->bHasLegend;
610 789 : m_aCommandAvailability[ ".uno:DiagramWall" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasWall;
611 789 : m_aCommandAvailability[ ".uno:DiagramArea" ] = bIsWritable;
612 :
613 789 : m_aCommandAvailability[ ".uno:TransformDialog" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bHasSelectedObject && m_apControllerState->bIsPositionableObject;
614 :
615 : // 3d commands
616 789 : m_aCommandAvailability[ ".uno:View3D" ] = bIsWritable && bModelStateIsValid && m_apModelState->bIsThreeD;
617 789 : m_aCommandAvailability[ ".uno:DiagramFloor" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasFloor;
618 :
619 : //some mor format commands with different ui text
620 789 : m_aCommandAvailability[ ".uno:FormatWall" ] = m_aCommandAvailability[ ".uno:DiagramWall" ];
621 789 : m_aCommandAvailability[ ".uno:FormatFloor" ] = m_aCommandAvailability[ ".uno:DiagramFloor" ];
622 789 : m_aCommandAvailability[ ".uno:FormatChartArea" ] = m_aCommandAvailability[ ".uno:DiagramArea" ];
623 789 : m_aCommandAvailability[ ".uno:FormatLegend" ] = m_aCommandAvailability[ ".uno:Legend" ];
624 :
625 : // depending on own data
626 789 : m_aCommandAvailability[ ".uno:DataRanges" ] = bIsWritable && bModelStateIsValid && (! m_apModelState->bHasOwnData);
627 789 : m_aCommandAvailability[ ".uno:DiagramData" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasOwnData && !bDisableDataTableDialog;
628 :
629 : // titles
630 789 : m_aCommandAvailability[ ".uno:MainTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainTitle;
631 789 : m_aCommandAvailability[ ".uno:SubTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSubTitle;
632 789 : m_aCommandAvailability[ ".uno:XTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxisTitle;
633 789 : m_aCommandAvailability[ ".uno:YTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxisTitle;
634 789 : m_aCommandAvailability[ ".uno:ZTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxisTitle;
635 789 : m_aCommandAvailability[ ".uno:SecondaryXTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryXAxisTitle;
636 789 : m_aCommandAvailability[ ".uno:SecondaryYTitle" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasSecondaryYAxisTitle;
637 789 : m_aCommandAvailability[ ".uno:AllTitles" ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyTitle();
638 :
639 : // text
640 789 : m_aCommandAvailability[ ".uno:ScaleText" ] = bIsWritable && bModelStateIsValid ;
641 789 : m_aCommandArguments[ ".uno:ScaleText" ] = uno::makeAny( m_apModelState->bHasAutoScaledText );
642 :
643 : // axes
644 789 : m_aCommandAvailability[ ".uno:DiagramAxisX" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasXAxis;
645 789 : m_aCommandAvailability[ ".uno:DiagramAxisY" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasYAxis;
646 789 : m_aCommandAvailability[ ".uno:DiagramAxisZ" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasZAxis;
647 789 : m_aCommandAvailability[ ".uno:DiagramAxisA" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasAAxis;
648 789 : m_aCommandAvailability[ ".uno:DiagramAxisB" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasBAxis;
649 789 : m_aCommandAvailability[ ".uno:DiagramAxisAll" ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyAxis();
650 :
651 : // grids
652 : // note: x and y are swapped in the commands!
653 789 : m_aCommandAvailability[ ".uno:DiagramGridYMain" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainXGrid;
654 789 : m_aCommandAvailability[ ".uno:DiagramGridXMain" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainYGrid;
655 789 : m_aCommandAvailability[ ".uno:DiagramGridZMain" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasMainZGrid;
656 789 : m_aCommandAvailability[ ".uno:DiagramGridYHelp" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpXGrid;
657 789 : m_aCommandAvailability[ ".uno:DiagramGridXHelp" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpYGrid;
658 789 : m_aCommandAvailability[ ".uno:DiagramGridZHelp" ] = bIsWritable && bModelStateIsValid && m_apModelState->bHasHelpZGrid;
659 789 : m_aCommandAvailability[ ".uno:DiagramGridAll" ] = bIsWritable && bModelStateIsValid && m_apModelState->HasAnyGrid();
660 :
661 : // series arrangement
662 1578 : m_aCommandAvailability[ ".uno:Forward" ] = ( bShapeContext ? isShapeControllerCommandAvailable( ".uno:Forward" ) :
663 789 : ( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesForward && !bDisableDataTableDialog ) );
664 1578 : m_aCommandAvailability[ ".uno:Backward" ] = ( bShapeContext ? isShapeControllerCommandAvailable( ".uno:Backward" ) :
665 789 : ( bIsWritable && bControllerStateIsValid && m_apControllerState->bMayMoveSeriesBackward && !bDisableDataTableDialog ) );
666 :
667 789 : m_aCommandAvailability[ ".uno:InsertDataLabels" ] = bIsWritable;
668 789 : m_aCommandAvailability[ ".uno:InsertDataLabel" ] = bIsWritable;
669 789 : m_aCommandAvailability[ ".uno:InsertMeanValue" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddMeanValue;
670 789 : m_aCommandAvailability[ ".uno:InsertTrendline" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendline;
671 789 : m_aCommandAvailability[ ".uno:InsertTrendlineEquation" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddTrendlineEquation;
672 789 : m_aCommandAvailability[ ".uno:InsertTrendlineEquationAndR2" ] = m_aCommandAvailability[ ".uno:InsertTrendlineEquation" ];
673 789 : m_aCommandAvailability[ ".uno:InsertR2Value" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddR2Value;
674 789 : m_aCommandAvailability[ ".uno:DeleteR2Value" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteR2Value;
675 :
676 789 : m_aCommandAvailability[ ".uno:InsertXErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddXErrorBars;
677 789 : m_aCommandAvailability[ ".uno:InsertYErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayAddYErrorBars;
678 :
679 789 : m_aCommandAvailability[ ".uno:DeleteDataLabels" ] = bIsWritable;
680 789 : m_aCommandAvailability[ ".uno:DeleteDataLabel" ] = bIsWritable;
681 789 : m_aCommandAvailability[ ".uno:DeleteTrendline" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendline;
682 789 : m_aCommandAvailability[ ".uno:DeleteTrendlineEquation" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteTrendlineEquation;
683 789 : m_aCommandAvailability[ ".uno:DeleteMeanValue" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteMeanValue;
684 789 : m_aCommandAvailability[ ".uno:DeleteXErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteXErrorBars;
685 789 : m_aCommandAvailability[ ".uno:DeleteYErrorBars" ] = bIsWritable && bControllerStateIsValid && m_apControllerState->bMayDeleteYErrorBars;
686 :
687 789 : m_aCommandAvailability[ ".uno:ResetDataPoint" ] = bIsWritable;
688 789 : m_aCommandAvailability[ ".uno:ResetAllDataPoints" ] = bIsWritable;
689 :
690 789 : m_aCommandAvailability[ ".uno:InsertAxis" ] = bIsWritable;
691 789 : m_aCommandAvailability[ ".uno:DeleteAxis" ] = bIsWritable;
692 789 : m_aCommandAvailability[ ".uno:InsertAxisTitle" ] = bIsWritable;
693 789 : m_aCommandAvailability[ ".uno:FormatMajorGrid" ] = bIsWritable;
694 789 : m_aCommandAvailability[ ".uno:InsertMajorGrid" ] = bIsWritable;
695 789 : m_aCommandAvailability[ ".uno:DeleteMajorGrid" ] = bIsWritable;
696 789 : m_aCommandAvailability[ ".uno:FormatMinorGrid" ] = bIsWritable;
697 789 : m_aCommandAvailability[ ".uno:InsertMinorGrid" ] = bIsWritable;
698 789 : m_aCommandAvailability[ ".uno:DeleteMinorGrid" ] = bIsWritable;
699 789 : }
700 :
701 81247 : bool ControllerCommandDispatch::commandAvailable( const OUString & rCommand )
702 : {
703 81247 : ::std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.find( rCommand ));
704 81247 : if( aIt != m_aCommandAvailability.end())
705 81247 : return aIt->second;
706 : OSL_FAIL( "commandAvailable: command not in availability map" );
707 0 : return false;
708 : }
709 :
710 0 : bool ControllerCommandDispatch::isShapeControllerCommandAvailable( const OUString& rCommand )
711 : {
712 0 : ShapeController* pShapeController = ( m_pDispatchContainer ? m_pDispatchContainer->getShapeController() : NULL );
713 0 : if ( pShapeController )
714 : {
715 0 : FeatureState aState( pShapeController->getState( rCommand ) );
716 0 : return aState.bEnabled;
717 : }
718 0 : return false;
719 : }
720 :
721 976 : void ControllerCommandDispatch::fireStatusEvent(
722 : const OUString & rURL,
723 : const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
724 : {
725 976 : bool bIsChartSelectorURL = rURL == ".uno:ChartElementSelector";
726 976 : if( rURL.isEmpty() || bIsChartSelectorURL )
727 : {
728 789 : uno::Any aArg;
729 789 : aArg <<= m_xController;
730 789 : fireStatusEventForURL( ".uno:ChartElementSelector", aArg, true, xSingleListener );
731 : }
732 :
733 976 : if( rURL.isEmpty() )
734 245496 : for( ::std::map< OUString, bool >::const_iterator aIt( m_aCommandAvailability.begin());
735 163664 : aIt != m_aCommandAvailability.end(); ++aIt )
736 81060 : fireStatusEventForURLImpl( aIt->first, xSingleListener );
737 204 : else if( !bIsChartSelectorURL )
738 187 : fireStatusEventForURLImpl( rURL, xSingleListener );
739 :
740 : // statusbar. Should be handled by base implementation
741 : // @todo: remove if Issue 68864 is fixed
742 976 : if( rURL.isEmpty() || rURL == ".uno:StatusBarVisible" )
743 : {
744 772 : bool bIsStatusBarVisible( lcl_isStatusBarVisible( m_xController ));
745 772 : fireStatusEventForURL( ".uno:StatusBarVisible", uno::makeAny( bIsStatusBarVisible ), true, xSingleListener );
746 : }
747 976 : }
748 :
749 : // ____ XDispatch ____
750 0 : void SAL_CALL ControllerCommandDispatch::dispatch(
751 : const util::URL& URL,
752 : const Sequence< beans::PropertyValue >& Arguments )
753 : throw (uno::RuntimeException)
754 : {
755 0 : if( commandAvailable( URL.Complete ))
756 0 : m_xDispatch->dispatch( URL, Arguments );
757 0 : }
758 :
759 : // ____ WeakComponentImplHelperBase ____
760 : /// is called when this is disposed
761 17 : void SAL_CALL ControllerCommandDispatch::disposing()
762 : {
763 17 : m_xController.clear();
764 17 : m_xDispatch.clear();
765 17 : m_xSelectionSupplier.clear();
766 17 : }
767 :
768 : // ____ XEventListener (base of XModifyListener) ____
769 17 : void SAL_CALL ControllerCommandDispatch::disposing( const lang::EventObject& /* Source */ )
770 : throw (uno::RuntimeException)
771 : {
772 17 : m_xController.clear();
773 17 : m_xDispatch.clear();
774 17 : m_xSelectionSupplier.clear();
775 17 : }
776 :
777 : // ____ XModifyListener ____
778 772 : void SAL_CALL ControllerCommandDispatch::modified( const lang::EventObject& aEvent )
779 : throw (uno::RuntimeException)
780 : {
781 772 : bool bUpdateCommandAvailability = false;
782 :
783 : // Update the "ModelState" Struct.
784 772 : if( m_apModelState.get() && m_xController.is())
785 : {
786 772 : m_apModelState->update( m_xController->getModel());
787 772 : bUpdateCommandAvailability = true;
788 : }
789 :
790 : // Update the "ControllerState" Struct.
791 772 : if( m_apControllerState.get() && m_xController.is())
792 : {
793 772 : m_apControllerState->update( m_xController, m_xController->getModel());
794 772 : bUpdateCommandAvailability = true;
795 : }
796 :
797 772 : if( bUpdateCommandAvailability )
798 772 : updateCommandAvailability();
799 :
800 772 : CommandDispatch::modified( aEvent );
801 772 : }
802 :
803 :
804 : // ____ XSelectionChangeListener ____
805 0 : void SAL_CALL ControllerCommandDispatch::selectionChanged( const lang::EventObject& aEvent )
806 : throw (uno::RuntimeException)
807 : {
808 : // Update the "ControllerState" Struct.
809 0 : if( m_apControllerState.get() && m_xController.is())
810 : {
811 0 : m_apControllerState->update( m_xController, m_xController->getModel());
812 0 : updateCommandAvailability();
813 : }
814 :
815 0 : CommandDispatch::modified( aEvent );
816 0 : }
817 :
818 33 : } // namespace chart
819 :
820 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|