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