1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "dlg_InsertErrorBars.hxx"
28 #include "dlg_InsertErrorBars.hrc"
29 #include "res_ErrorBar.hxx"
30 #include "ResourceIds.hrc"
31 #include "ResId.hxx"
32 #include "Strings.hrc"
33 #include "chartview/ExplicitValueProvider.hxx"
34 #include "ChartModelHelper.hxx"
35 #include "ObjectIdentifier.hxx"
36 #include "DiagramHelper.hxx"
37 #include "AxisHelper.hxx"
38 #include "ObjectNameProvider.hxx"
39
40 #include <com/sun/star/chart2/XAxis.hpp>
41 #include <com/sun/star/chart2/XDiagram.hpp>
42
43 using ::rtl::OUString;
44 using ::com::sun::star::uno::Reference;
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::chart2;
47
48 //.............................................................................
49 namespace chart
50 {
51 //.............................................................................
52
InsertErrorBarsDialog(Window * pParent,const SfxItemSet & rMyAttrs,const uno::Reference<chart2::XChartDocument> & xChartDocument,ErrorBarResources::tErrorBarType eType)53 InsertErrorBarsDialog::InsertErrorBarsDialog(
54 Window* pParent, const SfxItemSet& rMyAttrs,
55 const uno::Reference< chart2::XChartDocument > & xChartDocument,
56 ErrorBarResources::tErrorBarType eType /* = ErrorBarResources::ERROR_BAR_Y */ ) :
57 ModalDialog( pParent, SchResId( DLG_DATA_YERRORBAR )),
58 rInAttrs( rMyAttrs ),
59 aBtnOK( this, SchResId( BTN_OK )),
60 aBtnCancel( this, SchResId( BTN_CANCEL )),
61 aBtnHelp( this, SchResId( BTN_HELP )),
62 m_apErrorBarResources( new ErrorBarResources(
63 this, this, rInAttrs,
64 /* bNoneAvailable = */ true, eType ))
65 {
66 FreeResource();
67 this->SetText( ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_ERRORS ) );
68
69 m_apErrorBarResources->SetChartDocumentForRangeChoosing( xChartDocument );
70 }
71
~InsertErrorBarsDialog()72 InsertErrorBarsDialog::~InsertErrorBarsDialog()
73 {
74 }
75
FillItemSet(SfxItemSet & rOutAttrs)76 void InsertErrorBarsDialog::FillItemSet(SfxItemSet& rOutAttrs)
77 {
78 m_apErrorBarResources->FillItemSet(rOutAttrs);
79 }
80
DataChanged(const DataChangedEvent & rDCEvt)81 void InsertErrorBarsDialog::DataChanged( const DataChangedEvent& rDCEvt )
82 {
83 ModalDialog::DataChanged( rDCEvt );
84
85 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
86 m_apErrorBarResources->FillValueSets();
87 }
88
SetAxisMinorStepWidthForErrorBarDecimals(double fMinorStepWidth)89 void InsertErrorBarsDialog::SetAxisMinorStepWidthForErrorBarDecimals( double fMinorStepWidth )
90 {
91 m_apErrorBarResources->SetAxisMinorStepWidthForErrorBarDecimals( fMinorStepWidth );
92 }
93
getAxisMinorStepWidthForErrorBarDecimals(const Reference<frame::XModel> & xChartModel,const Reference<uno::XInterface> & xChartView,const OUString & rSelectedObjectCID)94 double InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals(
95 const Reference< frame::XModel >& xChartModel,
96 const Reference< uno::XInterface >& xChartView,
97 const OUString& rSelectedObjectCID )
98 {
99 double fStepWidth = 0.001;
100
101 ExplicitValueProvider* pExplicitValueProvider( ExplicitValueProvider::getExplicitValueProvider(xChartView) );
102 if( pExplicitValueProvider )
103 {
104 Reference< XAxis > xAxis;
105 Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
106 Reference< XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedObjectCID, xChartModel );
107 xAxis = DiagramHelper::getAttachedAxis( xSeries, xDiagram );
108 if(!xAxis.is())
109 xAxis = AxisHelper::getAxis( 1/*nDimensionIndex*/, true/*bMainAxis*/, xDiagram );
110 if(xAxis.is())
111 {
112 ExplicitScaleData aExplicitScale;
113 ExplicitIncrementData aExplicitIncrement;
114 pExplicitValueProvider->getExplicitValuesForAxis( xAxis,aExplicitScale, aExplicitIncrement );
115
116 fStepWidth = aExplicitIncrement.Distance;
117 if( !aExplicitIncrement.SubIncrements.empty() && aExplicitIncrement.SubIncrements[0].IntervalCount>0 )
118 fStepWidth=fStepWidth/double(aExplicitIncrement.SubIncrements[0].IntervalCount);
119 else
120 fStepWidth/=10;
121 }
122 }
123
124 return fStepWidth;
125 }
126
127 //.............................................................................
128 } //namespace chart
129 //.............................................................................
130