xref: /trunk/main/chart2/source/controller/main/ChartController_Insert.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "ChartController.hxx"
31 
32 #include "dlg_InsertAxis_Grid.hxx"
33 #include "dlg_InsertDataLabel.hxx"
34 #include "dlg_InsertLegend.hxx"
35 #include "dlg_InsertTrendline.hxx"
36 #include "dlg_InsertErrorBars.hxx"
37 #include "dlg_InsertTitle.hxx"
38 #include "dlg_ObjectProperties.hxx"
39 
40 #include "ChartWindow.hxx"
41 #include "ChartModelHelper.hxx"
42 #include "AxisHelper.hxx"
43 #include "TitleHelper.hxx"
44 #include "DiagramHelper.hxx"
45 #include "macros.hxx"
46 #include "chartview/DrawModelWrapper.hxx"
47 #include "NumberFormatterWrapper.hxx"
48 #include "ViewElementListProvider.hxx"
49 #include "MultipleChartConverters.hxx"
50 #include "ControllerLockGuard.hxx"
51 #include "UndoGuard.hxx"
52 #include "ResId.hxx"
53 #include "Strings.hrc"
54 #include "ReferenceSizeProvider.hxx"
55 #include "ObjectIdentifier.hxx"
56 #include "RegressionCurveHelper.hxx"
57 #include "RegressionCurveItemConverter.hxx"
58 #include "StatisticsHelper.hxx"
59 #include "ErrorBarItemConverter.hxx"
60 #include "MultipleItemConverter.hxx"
61 #include "DataSeriesHelper.hxx"
62 #include "ObjectNameProvider.hxx"
63 #include "LegendHelper.hxx"
64 
65 #include <com/sun/star/chart2/XRegressionCurve.hpp>
66 #include <com/sun/star/chart/ErrorBarStyle.hpp>
67 #include <svx/ActionDescriptionProvider.hxx>
68 
69 //--------------------------------------
70 
71 // header for define RET_OK
72 #include <vcl/msgbox.hxx>
73 // header for class OUStringBuffer
74 #include <rtl/ustrbuf.hxx>
75 // header for class Application
76 #include <vcl/svapp.hxx>
77 // header for class ::vos::OGuard
78 #include <vos/mutex.hxx>
79 
80 
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::chart2;
83 using ::com::sun::star::uno::Reference;
84 using ::com::sun::star::uno::Sequence;
85 using ::rtl::OUString;
86 
87 //.............................................................................
88 
89 namespace
90 {
91 struct lcl_InsertMeanValueLine
92 {
93 public:
94     lcl_InsertMeanValueLine( const uno::Reference< uno::XComponentContext > & xContext ) :
95             m_xContext( xContext )
96     {}
97 
98     void operator()( const uno::Reference< chart2::XDataSeries > & xSeries )
99     {
100         uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
101             xSeries, uno::UNO_QUERY );
102         if( xRegCurveCnt.is())
103         {
104             ::chart::RegressionCurveHelper::addMeanValueLine(
105                 xRegCurveCnt, m_xContext, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
106         }
107     }
108 
109 private:
110     uno::Reference< uno::XComponentContext > m_xContext;
111 };
112 
113 } // anonymous namespace
114 
115 //.............................................................................
116 namespace chart
117 {
118 //.............................................................................
119 
120 void ChartController::executeDispatch_InsertAxes()
121 {
122     UndoGuard aUndoGuard(
123         ActionDescriptionProvider::createDescription(
124             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXES ))),
125         m_xUndoManager );
126 
127     try
128     {
129         InsertAxisOrGridDialogData aDialogInput;
130         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
131         AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_True );
132         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_True );
133 
134         ::vos::OGuard aGuard( Application::GetSolarMutex());
135         SchAxisDlg aDlg( m_pChartWindow, aDialogInput );
136         if( aDlg.Execute() == RET_OK )
137         {
138             // lock controllers till end of block
139             ControllerLockGuard aCLGuard( getModel() );
140 
141             InsertAxisOrGridDialogData aDialogOutput;
142             aDlg.getResult( aDialogOutput );
143             ::std::auto_ptr< ReferenceSizeProvider > mpRefSizeProvider(
144                 impl_createReferenceSizeProvider());
145             bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
146                 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
147                 , mpRefSizeProvider.get() );
148             if( bChanged )
149                 aUndoGuard.commit();
150         }
151     }
152     catch( uno::RuntimeException& e)
153     {
154         ASSERT_EXCEPTION( e );
155     }
156 }
157 
158 void ChartController::executeDispatch_InsertGrid()
159 {
160     UndoGuard aUndoGuard(
161         ActionDescriptionProvider::createDescription(
162             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRIDS ))),
163         m_xUndoManager );
164 
165     try
166     {
167         InsertAxisOrGridDialogData aDialogInput;
168         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
169         AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_False );
170         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_False );
171 
172         ::vos::OGuard aGuard( Application::GetSolarMutex());
173         SchGridDlg aDlg( m_pChartWindow, aDialogInput );//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
174         if( aDlg.Execute() == RET_OK )
175         {
176             // lock controllers till end of block
177             ControllerLockGuard aCLGuard( getModel() );
178             InsertAxisOrGridDialogData aDialogOutput;
179             aDlg.getResult( aDialogOutput );
180             bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
181                 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC );
182             if( bChanged )
183                 aUndoGuard.commit();
184         }
185     }
186     catch( uno::RuntimeException& e)
187     {
188         ASSERT_EXCEPTION( e );
189     }
190 }
191 
192 //-----------------------------------------------------------------------------
193 //-----------------------------------------------------------------------------
194 
195 void ChartController::executeDispatch_InsertTitles()
196 {
197     UndoGuard aUndoGuard(
198         ActionDescriptionProvider::createDescription(
199             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLES ))),
200         m_xUndoManager );
201 
202     try
203     {
204         TitleDialogData aDialogInput;
205         aDialogInput.readFromModel( getModel() );
206 
207         ::vos::OGuard aGuard( Application::GetSolarMutex());
208         SchTitleDlg aDlg( m_pChartWindow, aDialogInput );
209         if( aDlg.Execute() == RET_OK )
210         {
211             // lock controllers till end of block
212             ControllerLockGuard aCLGuard( getModel() );
213             TitleDialogData aDialogOutput( impl_createReferenceSizeProvider());
214             aDlg.getResult( aDialogOutput );
215             bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
216             if( bChanged )
217                 aUndoGuard.commit();
218         }
219     }
220     catch( uno::RuntimeException& e)
221     {
222         ASSERT_EXCEPTION( e );
223     }
224 }
225 
226 void ChartController::executeDispatch_DeleteLegend()
227 {
228     UndoGuard aUndoGuard(
229         ActionDescriptionProvider::createDescription(
230             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))),
231         m_xUndoManager );
232 
233     LegendHelper::hideLegend( getModel() );
234     aUndoGuard.commit();
235 }
236 
237 void ChartController::executeDispatch_InsertLegend()
238 {
239     UndoGuard aUndoGuard(
240         ActionDescriptionProvider::createDescription(
241             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
242         m_xUndoManager );
243 
244     Reference< chart2::XLegend > xLegend = LegendHelper::showLegend( getModel(), m_xCC );
245     aUndoGuard.commit();
246 }
247 
248 void ChartController::executeDispatch_OpenLegendDialog()
249 {
250     UndoGuard aUndoGuard(
251         ActionDescriptionProvider::createDescription(
252             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
253         m_xUndoManager );
254 
255     try
256     {
257         //prepare and open dialog
258         ::vos::OGuard aGuard( Application::GetSolarMutex());
259         SchLegendDlg aDlg( m_pChartWindow, m_xCC );
260         aDlg.init( getModel() );
261         if( aDlg.Execute() == RET_OK )
262         {
263             // lock controllers till end of block
264             ControllerLockGuard aCLGuard( getModel() );
265             bool bChanged = aDlg.writeToModel( getModel() );
266             if( bChanged )
267                 aUndoGuard.commit();
268         }
269     }
270     catch( uno::RuntimeException& e)
271     {
272         ASSERT_EXCEPTION( e );
273     }
274 }
275 
276 //-----------------------------------------------------------------------------
277 //-----------------------------------------------------------------------------
278 
279 void ChartController::executeDispatch_InsertMenu_DataLabels()
280 {
281     UndoGuard aUndoGuard(
282         ActionDescriptionProvider::createDescription(
283             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_DATALABELS ))),
284         m_xUndoManager );
285 
286     //if a series is selected insert labels for that series only:
287     uno::Reference< chart2::XDataSeries > xSeries(
288         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
289     if( xSeries.is() )
290     {
291         // add labels
292         DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
293 
294         rtl::OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
295         aChildParticle+=(C2U("="));
296         rtl::OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
297             ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
298 
299         bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
300         if( bSuccess )
301             aUndoGuard.commit();
302         return;
303     }
304 
305     try
306     {
307         wrapper::AllDataLabelItemConverter aItemConverter(
308             getModel(),
309             m_pDrawModelWrapper->GetItemPool(),
310             m_pDrawModelWrapper->getSdrModel(),
311             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
312         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
313         aItemConverter.FillItemSet( aItemSet );
314 
315         //prepare and open dialog
316         ::vos::OGuard aGuard( Application::GetSolarMutex());
317 
318         //get number formatter
319         uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
320         NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
321         SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
322 
323         DataLabelsDialog aDlg( m_pChartWindow, aItemSet, pNumberFormatter);
324 
325         if( aDlg.Execute() == RET_OK )
326         {
327             SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
328             aDlg.FillItemSet( aOutItemSet );
329             // lock controllers till end of block
330             ControllerLockGuard aCLGuard( getModel() );
331             bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
332             if( bChanged )
333                 aUndoGuard.commit();
334         }
335     }
336     catch( uno::RuntimeException& e)
337     {
338         ASSERT_EXCEPTION( e );
339     }
340 }
341 
342 void ChartController::executeDispatch_InsertMenu_YErrorBars()
343 {
344     //if a series is selected insert error bars for that series only:
345     uno::Reference< chart2::XDataSeries > xSeries(
346         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
347     if( xSeries.is())
348     {
349         executeDispatch_InsertYErrorBars();
350         return;
351     }
352 
353     //if no series is selected insert error bars for all series
354     UndoGuard aUndoGuard(
355         ActionDescriptionProvider::createDescription(
356             ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_ERRORS ) ),
357         m_xUndoManager );
358 
359     try
360     {
361         wrapper::AllSeriesStatisticsConverter aItemConverter(
362             getModel(), m_pDrawModelWrapper->GetItemPool() );
363         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
364         aItemConverter.FillItemSet( aItemSet );
365 
366         //prepare and open dialog
367         ::vos::OGuard aGuard( Application::GetSolarMutex());
368         InsertErrorBarsDialog aDlg(
369             m_pChartWindow, aItemSet,
370             uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ));
371         aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
372             InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rtl::OUString() ) );
373 
374         if( aDlg.Execute() == RET_OK )
375         {
376             SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
377             aDlg.FillItemSet( aOutItemSet );
378 
379             // lock controllers till end of block
380             ControllerLockGuard aCLGuard( getModel() );
381             bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
382             if( bChanged )
383                 aUndoGuard.commit();
384         }
385     }
386     catch( uno::RuntimeException& e)
387     {
388         ASSERT_EXCEPTION( e );
389     }
390 }
391 
392 void ChartController::executeDispatch_InsertMeanValue()
393 {
394     UndoGuard aUndoGuard(
395         ActionDescriptionProvider::createDescription(
396             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
397         m_xUndoManager );
398     lcl_InsertMeanValueLine( m_xCC ).operator()(
399         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
400     aUndoGuard.commit();
401 }
402 
403 void ChartController::executeDispatch_InsertMenu_MeanValues()
404 {
405     UndoGuard aUndoGuard(
406         ActionDescriptionProvider::createDescription(
407             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
408         m_xUndoManager );
409 
410     uno::Reference< chart2::XDataSeries > xSeries(
411         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
412     if( xSeries.is() )
413     {
414         //if a series is selected insert mean value only for that series:
415         lcl_InsertMeanValueLine( m_xCC ).operator()(xSeries);
416     }
417     else
418     {
419         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
420             DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
421         ::std::for_each( aSeries.begin(), aSeries.end(), lcl_InsertMeanValueLine( m_xCC ));
422     }
423     aUndoGuard.commit();
424 }
425 
426 void ChartController::executeDispatch_InsertMenu_Trendlines()
427 {
428     //if a series is selected insert only for that series:
429     uno::Reference< chart2::XDataSeries > xSeries(
430         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
431     if( xSeries.is())
432     {
433         executeDispatch_InsertTrendline();
434         return;
435     }
436 
437     UndoGuard aUndoGuard(
438         ActionDescriptionProvider::createDescription(
439             ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_CURVE ) ),
440         m_xUndoManager );
441 
442     try
443     {
444         wrapper::AllSeriesStatisticsConverter aItemConverter(
445             getModel(), m_pDrawModelWrapper->GetItemPool() );
446         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
447         aItemConverter.FillItemSet( aItemSet );
448 
449         //prepare and open dialog
450         ::vos::OGuard aGuard( Application::GetSolarMutex());
451         InsertTrendlineDialog aDlg( m_pChartWindow, aItemSet );
452         aDlg.adjustSize();
453 
454         if( aDlg.Execute() == RET_OK )
455         {
456             SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
457             aDlg.FillItemSet( aOutItemSet );
458 
459             // lock controllers till end of block
460             ControllerLockGuard aCLGuard( getModel() );
461             bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
462             if( bChanged )
463                 aUndoGuard.commit();
464         }
465     }
466     catch( uno::RuntimeException& e)
467     {
468         ASSERT_EXCEPTION( e );
469     }
470 }
471 
472 void ChartController::executeDispatch_InsertTrendline()
473 {
474     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
475         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
476     if( xRegCurveCnt.is())
477     {
478         UndoLiveUpdateGuard aUndoGuard(
479             ActionDescriptionProvider::createDescription(
480                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))),
481             m_xUndoManager );
482 
483         // add a linear curve
484         RegressionCurveHelper::addRegressionCurve(
485             RegressionCurveHelper::REGRESSION_TYPE_LINEAR, xRegCurveCnt, m_xCC );
486 
487         // get an appropriate item converter
488         uno::Reference< chart2::XRegressionCurve > xCurve(
489             RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ));
490         uno::Reference< beans::XPropertySet > xCurveProp( xCurve, uno::UNO_QUERY );
491         if( !xCurveProp.is())
492             return;
493         wrapper::RegressionCurveItemConverter aItemConverter(
494             xCurveProp, xRegCurveCnt, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
495             m_pDrawModelWrapper->getSdrModel(),
496             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
497 
498         // open dialog
499         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
500         aItemConverter.FillItemSet( aItemSet );
501         ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
502             ObjectIdentifier::createDataCurveCID(
503                 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
504                 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt, xCurve ), false ));
505         aDialogParameter.init( getModel() );
506         ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
507         ::vos::OGuard aGuard( Application::GetSolarMutex());
508         SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
509                               uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
510 
511         // note: when a user pressed "OK" but didn't change any settings in the
512         // dialog, the SfxTabDialog returns "Cancel"
513         if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
514         {
515             const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
516             if( pOutItemSet )
517             {
518                 ControllerLockGuard aCLGuard( getModel() );
519                 aItemConverter.ApplyItemSet( *pOutItemSet );
520             }
521             aUndoGuard.commit();
522         }
523     }
524 }
525 
526 void ChartController::executeDispatch_InsertYErrorBars()
527 {
528     uno::Reference< chart2::XDataSeries > xSeries(
529         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
530     if( xSeries.is())
531     {
532         UndoLiveUpdateGuard aUndoGuard(
533             ActionDescriptionProvider::createDescription(
534                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_ERROR_BARS ))),
535             m_xUndoManager );
536 
537         // add error bars with standard deviation
538         uno::Reference< beans::XPropertySet > xErrorBarProp(
539             StatisticsHelper::addErrorBars( xSeries, m_xCC, ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION ));
540 
541         // get an appropriate item converter
542         wrapper::ErrorBarItemConverter aItemConverter(
543             getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
544             m_pDrawModelWrapper->getSdrModel(),
545             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
546 
547         // open dialog
548         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
549         aItemConverter.FillItemSet( aItemSet );
550         ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
551             ObjectIdentifier::createClassifiedIdentifierWithParent(
552                 OBJECTTYPE_DATA_ERRORS, ::rtl::OUString(), m_aSelection.getSelectedCID()));
553         aDialogParameter.init( getModel() );
554         ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
555         ::vos::OGuard aGuard( Application::GetSolarMutex());
556         SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
557                               uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
558         aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
559             InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, m_aSelection.getSelectedCID()));
560 
561         // note: when a user pressed "OK" but didn't change any settings in the
562         // dialog, the SfxTabDialog returns "Cancel"
563         if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
564         {
565             const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
566             if( pOutItemSet )
567             {
568                 ControllerLockGuard aCLGuard( getModel() );
569                 aItemConverter.ApplyItemSet( *pOutItemSet );
570             }
571             aUndoGuard.commit();
572         }
573     }
574 }
575 
576 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
577 {
578     uno::Reference< chart2::XRegressionCurve > xRegCurve(
579         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
580     if( !xRegCurve.is() )
581     {
582         uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
583             ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
584         xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
585     }
586     if( xRegCurve.is())
587     {
588         uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
589         if( xEqProp.is())
590         {
591             // using assignment for broken gcc 3.3
592             UndoGuard aUndoGuard = UndoGuard(
593                 ActionDescriptionProvider::createDescription(
594                     ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
595                 m_xUndoManager );
596             xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( true ));
597             xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( bInsertR2 ));
598             aUndoGuard.commit();
599         }
600     }
601 }
602 
603 void ChartController::executeDispatch_InsertR2Value()
604 {
605     uno::Reference< beans::XPropertySet > xEqProp(
606         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
607     if( xEqProp.is())
608     {
609         UndoGuard aUndoGuard = UndoGuard(
610             ActionDescriptionProvider::createDescription(
611                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
612             m_xUndoManager );
613         xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( true ));
614         aUndoGuard.commit();
615     }
616 }
617 
618 void ChartController::executeDispatch_DeleteR2Value()
619 {
620     uno::Reference< beans::XPropertySet > xEqProp(
621         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
622     if( xEqProp.is())
623     {
624         UndoGuard aUndoGuard = UndoGuard(
625             ActionDescriptionProvider::createDescription(
626                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
627             m_xUndoManager );
628         xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
629         aUndoGuard.commit();
630     }
631 }
632 
633 void ChartController::executeDispatch_DeleteMeanValue()
634 {
635     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
636         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
637     if( xRegCurveCnt.is())
638     {
639         UndoGuard aUndoGuard(
640             ActionDescriptionProvider::createDescription(
641                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
642             m_xUndoManager );
643         RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
644         aUndoGuard.commit();
645     }
646 }
647 
648 void ChartController::executeDispatch_DeleteTrendline()
649 {
650     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
651         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
652     if( xRegCurveCnt.is())
653     {
654         UndoGuard aUndoGuard(
655             ActionDescriptionProvider::createDescription(
656                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
657             m_xUndoManager );
658         RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
659         aUndoGuard.commit();
660     }
661 }
662 
663 void ChartController::executeDispatch_DeleteTrendlineEquation()
664 {
665     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
666         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
667     if( xRegCurveCnt.is())
668     {
669         UndoGuard aUndoGuard(
670             ActionDescriptionProvider::createDescription(
671                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
672             m_xUndoManager );
673         RegressionCurveHelper::removeEquations( xRegCurveCnt );
674         aUndoGuard.commit();
675     }
676 }
677 
678 void ChartController::executeDispatch_DeleteYErrorBars()
679 {
680     uno::Reference< chart2::XDataSeries > xDataSeries(
681         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
682     if( xDataSeries.is())
683     {
684         UndoGuard aUndoGuard(
685             ActionDescriptionProvider::createDescription(
686                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
687             m_xUndoManager );
688         StatisticsHelper::removeErrorBars( xDataSeries );
689         aUndoGuard.commit();
690     }
691 }
692 
693 void ChartController::executeDispatch_InsertDataLabels()
694 {
695     uno::Reference< chart2::XDataSeries > xSeries(
696         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
697     if( xSeries.is() )
698     {
699         UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
700             String( SchResId( STR_OBJECT_DATALABELS ))),
701             m_xUndoManager );
702         DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
703         aUndoGuard.commit();
704     }
705 }
706 
707 void ChartController::executeDispatch_InsertDataLabel()
708 {
709     UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
710         String( SchResId( STR_OBJECT_LABEL ))),
711         m_xUndoManager );
712     DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
713     aUndoGuard.commit();
714 }
715 
716 void ChartController::executeDispatch_DeleteDataLabels()
717 {
718     uno::Reference< chart2::XDataSeries > xSeries(
719         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
720     if( xSeries.is() )
721     {
722         UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
723             String( SchResId( STR_OBJECT_DATALABELS ))),
724             m_xUndoManager );
725         DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
726         aUndoGuard.commit();
727     }
728 }
729 
730 void ChartController::executeDispatch_DeleteDataLabel()
731 {
732     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
733         String( SchResId( STR_OBJECT_LABEL ))),
734         m_xUndoManager );
735     DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
736     aUndoGuard.commit();
737 }
738 
739 void ChartController::executeDispatch_ResetAllDataPoints()
740 {
741     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
742         String( SchResId( STR_OBJECT_DATAPOINTS ))),
743         m_xUndoManager );
744     uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
745     if( xSeries.is() )
746         xSeries->resetAllDataPoints();
747     aUndoGuard.commit();
748 }
749 void ChartController::executeDispatch_ResetDataPoint()
750 {
751     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
752         String( SchResId( STR_OBJECT_DATAPOINT ))),
753         m_xUndoManager );
754     uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
755     if( xSeries.is() )
756     {
757         sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
758         xSeries->resetDataPoint( nPointIndex );
759     }
760     aUndoGuard.commit();
761 }
762 
763 void ChartController::executeDispatch_InsertAxisTitle()
764 {
765     try
766     {
767         uno::Reference< XTitle > xTitle;
768         {
769             UndoGuard aUndoGuard(
770             ActionDescriptionProvider::createDescription(
771                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLE ))),
772             m_xUndoManager );
773 
774             Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
775             sal_Int32 nDimensionIndex = -1;
776             sal_Int32 nCooSysIndex = -1;
777             sal_Int32 nAxisIndex = -1;
778             AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
779 
780             TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
781             if( nDimensionIndex==0 )
782                 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
783             else if( nDimensionIndex==1 )
784                 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
785             else
786                 eTitleType = TitleHelper::Z_AXIS_TITLE;
787 
788             ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
789             xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
790             aUndoGuard.commit();
791         }
792 
793         /*
794         if( xTitle.is() )
795         {
796             OUString aTitleCID = ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, getModel() );
797             select( uno::makeAny(aTitleCID) );
798             executeDispatch_EditText();
799         }
800         */
801     }
802     catch( uno::RuntimeException& e)
803     {
804         ASSERT_EXCEPTION( e );
805     }
806 }
807 
808 void ChartController::executeDispatch_InsertAxis()
809 {
810     UndoGuard aUndoGuard(
811         ActionDescriptionProvider::createDescription(
812             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXIS ))),
813         m_xUndoManager );
814 
815     try
816     {
817         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
818         if( xAxis.is() )
819         {
820             AxisHelper::makeAxisVisible( xAxis );
821             aUndoGuard.commit();
822         }
823     }
824     catch( uno::RuntimeException& e)
825     {
826         ASSERT_EXCEPTION( e );
827     }
828 }
829 
830 void ChartController::executeDispatch_DeleteAxis()
831 {
832     UndoGuard aUndoGuard(
833         ActionDescriptionProvider::createDescription(
834             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AXIS ))),
835         m_xUndoManager );
836 
837     try
838     {
839         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
840         if( xAxis.is() )
841         {
842             AxisHelper::makeAxisInvisible( xAxis );
843             aUndoGuard.commit();
844         }
845     }
846     catch( uno::RuntimeException& e)
847     {
848         ASSERT_EXCEPTION( e );
849     }
850 }
851 
852 void ChartController::executeDispatch_InsertMajorGrid()
853 {
854     UndoGuard aUndoGuard(
855         ActionDescriptionProvider::createDescription(
856             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
857         m_xUndoManager );
858 
859     try
860     {
861         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
862         if( xAxis.is() )
863         {
864             AxisHelper::makeGridVisible( xAxis->getGridProperties() );
865             aUndoGuard.commit();
866         }
867     }
868     catch( uno::RuntimeException& e)
869     {
870         ASSERT_EXCEPTION( e );
871     }
872 }
873 
874 void ChartController::executeDispatch_DeleteMajorGrid()
875 {
876     UndoGuard aUndoGuard(
877         ActionDescriptionProvider::createDescription(
878             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
879         m_xUndoManager );
880 
881     try
882     {
883         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
884         if( xAxis.is() )
885         {
886             AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
887             aUndoGuard.commit();
888         }
889     }
890     catch( uno::RuntimeException& e)
891     {
892         ASSERT_EXCEPTION( e );
893     }
894 }
895 
896 void ChartController::executeDispatch_InsertMinorGrid()
897 {
898     UndoGuard aUndoGuard(
899         ActionDescriptionProvider::createDescription(
900             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
901         m_xUndoManager );
902 
903     try
904     {
905         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
906         if( xAxis.is() )
907         {
908             Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
909             for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
910                 AxisHelper::makeGridVisible( aSubGrids[nN] );
911             aUndoGuard.commit();
912         }
913     }
914     catch( uno::RuntimeException& e)
915     {
916         ASSERT_EXCEPTION( e );
917     }
918 }
919 
920 void ChartController::executeDispatch_DeleteMinorGrid()
921 {
922     UndoGuard aUndoGuard(
923         ActionDescriptionProvider::createDescription(
924             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
925         m_xUndoManager );
926 
927     try
928     {
929         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
930         if( xAxis.is() )
931         {
932             Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
933             for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
934                 AxisHelper::makeGridInvisible( aSubGrids[nN] );
935             aUndoGuard.commit();
936         }
937     }
938     catch( uno::RuntimeException& e)
939     {
940         ASSERT_EXCEPTION( e );
941     }
942 }
943 
944 //.............................................................................
945 } //namespace chart
946 //.............................................................................
947