merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_SeriesToAxis.cxx
blobfbe2f4bf1907275ee4c43b048c6e93bbb47b8e90
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "tp_SeriesToAxis.hxx"
31 #include "tp_SeriesToAxis.hrc"
33 #include "ResId.hxx"
34 #include "chartview/ChartSfxItemIds.hxx"
35 #include "NoWarningThisInCTOR.hxx"
37 // header for class SfxBoolItem
38 #include <svl/eitem.hxx>
39 // header for SfxInt32Item
40 #include <svl/intitem.hxx>
41 //SfxIntegerListItem
42 #include <svl/ilstitem.hxx>
43 #include <svtools/controldims.hrc>
45 #include <com/sun/star/chart/MissingValueTreatment.hpp>
47 //.............................................................................
48 namespace chart
50 //.............................................................................
52 SchOptionTabPage::SchOptionTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
53 SfxTabPage(pWindow, SchResId(TP_OPTIONS), rInAttrs),
54 aGrpAxis(this, SchResId(GRP_OPT_AXIS)),
55 aRbtAxis1(this,SchResId(RBT_OPT_AXIS_1)),
56 aRbtAxis2(this,SchResId(RBT_OPT_AXIS_2)),
58 aGrpBar(this, SchResId(GB_BAR)),
59 aFTGap(this,SchResId(FT_GAP)),
60 aMTGap(this,SchResId(MT_GAP)),
61 aFTOverlap(this,SchResId(FT_OVERLAP)),
62 aMTOverlap(this,SchResId(MT_OVERLAP)),
63 aCBConnect(this,SchResId(CB_CONNECTOR)),
64 aCBAxisSideBySide(this,SchResId(CB_BARS_SIDE_BY_SIDE)),
65 m_aFL_PlotOptions(this,SchResId(FL_PLOT_OPTIONS)),
66 m_aFT_MissingValues(this,SchResId(FT_MISSING_VALUES)),
67 m_aRB_DontPaint(this,SchResId(RB_DONT_PAINT)),
68 m_aRB_AssumeZero(this,SchResId(RB_ASSUME_ZERO)),
69 m_aRB_ContinueLine(this,SchResId(RB_CONTINUE_LINE)),
70 m_aCBIncludeHiddenCells(this,SchResId(CB_INCLUDE_HIDDEN_CELLS)),
71 m_bProvidesSecondaryYAxis(true),
72 m_bProvidesOverlapAndGapWidth(false)
74 FreeResource();
76 aRbtAxis1.SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
77 aRbtAxis2.SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
80 SchOptionTabPage::~SchOptionTabPage()
84 IMPL_LINK( SchOptionTabPage, EnableHdl, RadioButton *, EMPTYARG )
86 if( m_nAllSeriesAxisIndex == 0 )
87 aCBAxisSideBySide.Enable( aRbtAxis2.IsChecked());
88 else if( m_nAllSeriesAxisIndex == 1 )
89 aCBAxisSideBySide.Enable( aRbtAxis1.IsChecked());
91 return 0;
94 SfxTabPage* SchOptionTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
96 return new SchOptionTabPage(pWindow, rOutAttrs);
99 BOOL SchOptionTabPage::FillItemSet(SfxItemSet& rOutAttrs)
101 if(aRbtAxis2.IsChecked())
102 rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_SECONDARY_Y));
103 else
104 rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_PRIMARY_Y));
106 if(aMTGap.IsVisible())
107 rOutAttrs.Put(SfxInt32Item(SCHATTR_BAR_GAPWIDTH,static_cast< sal_Int32 >( aMTGap.GetValue())));
109 if(aMTOverlap.IsVisible())
110 rOutAttrs.Put(SfxInt32Item(SCHATTR_BAR_OVERLAP,static_cast< sal_Int32 >( aMTOverlap.GetValue())));
112 if(aCBConnect.IsVisible())
113 rOutAttrs.Put(SfxBoolItem(SCHATTR_BAR_CONNECT,aCBConnect.IsChecked()));
115 // model property is "group bars per axis", UI feature is the other way
116 // round: "show bars side by side"
117 if(aCBAxisSideBySide.IsVisible())
118 rOutAttrs.Put(SfxBoolItem(SCHATTR_GROUP_BARS_PER_AXIS, ! aCBAxisSideBySide.IsChecked()));
120 if(m_aRB_DontPaint.IsChecked())
121 rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP));
122 else if(m_aRB_AssumeZero.IsChecked())
123 rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::USE_ZERO));
124 else if(m_aRB_ContinueLine.IsChecked())
125 rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::CONTINUE));
127 if (m_aCBIncludeHiddenCells.IsVisible())
128 rOutAttrs.Put(SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, m_aCBIncludeHiddenCells.IsChecked()));
130 return TRUE;
133 void SchOptionTabPage::Reset(const SfxItemSet& rInAttrs)
135 const SfxPoolItem *pPoolItem = NULL;
137 aRbtAxis1.Check(TRUE);
138 aRbtAxis2.Check(FALSE);
139 if (rInAttrs.GetItemState(SCHATTR_AXIS,TRUE, &pPoolItem) == SFX_ITEM_SET)
141 long nVal=((const SfxInt32Item*)pPoolItem)->GetValue();
142 if(nVal==CHART_AXIS_SECONDARY_Y)
144 aRbtAxis2.Check(TRUE);
145 aRbtAxis1.Check(FALSE);
149 long nTmp;
150 if (rInAttrs.GetItemState(SCHATTR_BAR_GAPWIDTH, TRUE, &pPoolItem) == SFX_ITEM_SET)
152 nTmp = (long)((const SfxInt32Item*)pPoolItem)->GetValue();
153 aMTGap.SetValue(nTmp);
156 if (rInAttrs.GetItemState(SCHATTR_BAR_OVERLAP, TRUE, &pPoolItem) == SFX_ITEM_SET)
158 nTmp = (long)((const SfxInt32Item*)pPoolItem)->GetValue();
159 aMTOverlap.SetValue(nTmp);
162 if (rInAttrs.GetItemState(SCHATTR_BAR_CONNECT, TRUE, &pPoolItem) == SFX_ITEM_SET)
164 BOOL bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
165 aCBConnect.Check(bCheck);
168 if (rInAttrs.GetItemState(SCHATTR_AXIS_FOR_ALL_SERIES, TRUE, &pPoolItem) == SFX_ITEM_SET)
170 m_nAllSeriesAxisIndex = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
171 aCBAxisSideBySide.Disable();
173 if (rInAttrs.GetItemState(SCHATTR_GROUP_BARS_PER_AXIS, TRUE, &pPoolItem) == SFX_ITEM_SET)
175 // model property is "group bars per axis", UI feature is the other way
176 // round: "show bars side by side"
177 BOOL bCheck = ! static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
178 aCBAxisSideBySide.Check( bCheck );
180 else
182 aCBAxisSideBySide.Show(FALSE);
186 //missing value treatment
188 ::com::sun::star::uno::Sequence < sal_Int32 > aMissingValueTreatments;
189 if( rInAttrs.GetItemState(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS, TRUE, &pPoolItem) == SFX_ITEM_SET )
190 aMissingValueTreatments =((const SfxIntegerListItem*)pPoolItem)->GetConstSequence();
192 if ( aMissingValueTreatments.getLength()>1 && rInAttrs.GetItemState(SCHATTR_MISSING_VALUE_TREATMENT,TRUE, &pPoolItem) == SFX_ITEM_SET)
194 m_aRB_DontPaint.Enable(FALSE);
195 m_aRB_AssumeZero.Enable(FALSE);
196 m_aRB_ContinueLine.Enable(FALSE);
198 for( sal_Int32 nN =0; nN<aMissingValueTreatments.getLength(); nN++ )
200 sal_Int32 nVal = aMissingValueTreatments[nN];
201 if(nVal==::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
202 m_aRB_DontPaint.Enable(TRUE);
203 else if(nVal==::com::sun::star::chart::MissingValueTreatment::USE_ZERO)
204 m_aRB_AssumeZero.Enable(TRUE);
205 else if(nVal==::com::sun::star::chart::MissingValueTreatment::CONTINUE)
206 m_aRB_ContinueLine.Enable(TRUE);
209 long nVal=((const SfxInt32Item*)pPoolItem)->GetValue();
210 if(nVal==::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
211 m_aRB_DontPaint.Check(TRUE);
212 else if(nVal==::com::sun::star::chart::MissingValueTreatment::USE_ZERO)
213 m_aRB_AssumeZero.Check(TRUE);
214 else if(nVal==::com::sun::star::chart::MissingValueTreatment::CONTINUE)
215 m_aRB_ContinueLine.Check(TRUE);
217 else
219 m_aFT_MissingValues.Show(FALSE);
220 m_aRB_DontPaint.Show(FALSE);
221 m_aRB_AssumeZero.Show(FALSE);
222 m_aRB_ContinueLine.Show(FALSE);
226 // Include hidden cells
227 if (rInAttrs.GetItemState(SCHATTR_INCLUDE_HIDDEN_CELLS, TRUE, &pPoolItem) == SFX_ITEM_SET)
229 bool bVal = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
230 m_aCBIncludeHiddenCells.Check(bVal);
232 else
234 m_aCBIncludeHiddenCells.Show(FALSE);
235 if(!m_aFT_MissingValues.IsVisible())
236 m_aFL_PlotOptions.Show(FALSE);
239 AdaptControlPositionsAndVisibility();
242 void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
244 m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
245 m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
246 m_bProvidesBarConnectors = bProvidesBarConnectors;
248 AdaptControlPositionsAndVisibility();
251 void lcl_offsetControl(Control& rCtrl, long nXOffset, long nYOffset )
253 Point aPos = rCtrl.GetPosPixel();
254 rCtrl.SetPosPixel( Point(aPos.getX() + nXOffset, aPos.getY() + nYOffset) );
257 void lcl_optimzeRadioButtonSize( RadioButton& rCtrl )
259 rCtrl.SetSizePixel( rCtrl.CalcMinimumSize() );
262 void SchOptionTabPage::AdaptControlPositionsAndVisibility()
264 aRbtAxis1.Show(m_bProvidesSecondaryYAxis);
265 aRbtAxis2.Show(m_bProvidesSecondaryYAxis);
266 aGrpAxis.Show(m_bProvidesSecondaryYAxis);
268 aMTGap.Show(m_bProvidesOverlapAndGapWidth);
269 aFTGap.Show(m_bProvidesOverlapAndGapWidth);
271 aMTOverlap.Show(m_bProvidesOverlapAndGapWidth);
272 aFTOverlap.Show(m_bProvidesOverlapAndGapWidth);
274 aCBConnect.Show(m_bProvidesBarConnectors);
276 if( !aMTGap.IsVisible() && !aMTOverlap.IsVisible() )
278 aGrpBar.Show(FALSE);
279 Point aPos;
280 if( !aRbtAxis1.IsVisible() && !aRbtAxis2.IsVisible() )
281 aPos = aGrpAxis.GetPosPixel();
282 else
283 aPos = aGrpBar.GetPosPixel();
285 long nYOffset = aPos.getY() - m_aFL_PlotOptions.GetPosPixel().getY();
286 lcl_offsetControl(m_aFL_PlotOptions, 0, nYOffset);
287 lcl_offsetControl(m_aFT_MissingValues, 0, nYOffset);
288 lcl_offsetControl(m_aRB_DontPaint, 0, nYOffset);
289 lcl_offsetControl(m_aRB_AssumeZero, 0, nYOffset);
290 lcl_offsetControl(m_aRB_ContinueLine, 0, nYOffset);
291 lcl_offsetControl(m_aCBIncludeHiddenCells, 0, nYOffset);
294 m_aFT_MissingValues.SetSizePixel( m_aFT_MissingValues.CalcMinimumSize() );
295 lcl_optimzeRadioButtonSize( m_aRB_DontPaint );
296 lcl_optimzeRadioButtonSize( m_aRB_AssumeZero );
297 lcl_optimzeRadioButtonSize( m_aRB_ContinueLine );
299 Size aControlDistance( m_aFT_MissingValues.LogicToPixel( Size(RSC_SP_CTRL_DESC_X,RSC_SP_CTRL_GROUP_Y), MapMode(MAP_APPFONT) ) );
300 long nXOffset = m_aFT_MissingValues.GetPosPixel().getX() + m_aFT_MissingValues.GetSizePixel().getWidth() + aControlDistance.getWidth() - m_aRB_DontPaint.GetPosPixel().getX();
301 lcl_offsetControl(m_aRB_DontPaint, nXOffset, 0);
302 lcl_offsetControl(m_aRB_AssumeZero, nXOffset, 0);
303 lcl_offsetControl(m_aRB_ContinueLine, nXOffset, 0);
305 if( !m_aFT_MissingValues.IsVisible() )
307 //for example for stock charts
308 m_aCBIncludeHiddenCells.SetPosPixel( m_aFT_MissingValues.GetPosPixel() );
311 //.............................................................................
312 } //namespace chart
313 //.............................................................................