update dev300-m58
[ooovba.git] / chart2 / source / controller / dialogs / tp_SeriesToAxis.cxx
blob7812b8b97ab32df9b12ad1b913cf2a5e176fd50b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tp_SeriesToAxis.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "tp_SeriesToAxis.hxx"
34 #include "tp_SeriesToAxis.hrc"
36 #include "ResId.hxx"
37 #include "chartview/ChartSfxItemIds.hxx"
38 #include "NoWarningThisInCTOR.hxx"
40 // header for class SfxBoolItem
41 #include <svtools/eitem.hxx>
42 // header for SfxInt32Item
43 #include <svtools/intitem.hxx>
44 //SfxIntegerListItem
45 #include <svtools/ilstitem.hxx>
46 #include <svtools/controldims.hrc>
48 #include <com/sun/star/chart/MissingValueTreatment.hpp>
50 //.............................................................................
51 namespace chart
53 //.............................................................................
55 SchOptionTabPage::SchOptionTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
56 SfxTabPage(pWindow, SchResId(TP_OPTIONS), rInAttrs),
57 aGrpAxis(this, SchResId(GRP_OPT_AXIS)),
58 aRbtAxis1(this,SchResId(RBT_OPT_AXIS_1)),
59 aRbtAxis2(this,SchResId(RBT_OPT_AXIS_2)),
61 aGrpBar(this, SchResId(GB_BAR)),
62 aFTGap(this,SchResId(FT_GAP)),
63 aMTGap(this,SchResId(MT_GAP)),
64 aFTOverlap(this,SchResId(FT_OVERLAP)),
65 aMTOverlap(this,SchResId(MT_OVERLAP)),
66 aCBConnect(this,SchResId(CB_CONNECTOR)),
67 aCBAxisSideBySide(this,SchResId(CB_BARS_SIDE_BY_SIDE)),
68 m_aFL_PlotOptions(this,SchResId(FL_PLOT_OPTIONS)),
69 m_aFT_MissingValues(this,SchResId(FT_MISSING_VALUES)),
70 m_aRB_DontPaint(this,SchResId(RB_DONT_PAINT)),
71 m_aRB_AssumeZero(this,SchResId(RB_ASSUME_ZERO)),
72 m_aRB_ContinueLine(this,SchResId(RB_CONTINUE_LINE)),
73 m_aCBIncludeHiddenCells(this,SchResId(CB_INCLUDE_HIDDEN_CELLS)),
74 m_bProvidesSecondaryYAxis(true),
75 m_bProvidesOverlapAndGapWidth(false)
77 FreeResource();
79 aRbtAxis1.SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
80 aRbtAxis2.SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
83 SchOptionTabPage::~SchOptionTabPage()
87 IMPL_LINK( SchOptionTabPage, EnableHdl, RadioButton *, EMPTYARG )
89 if( m_nAllSeriesAxisIndex == 0 )
90 aCBAxisSideBySide.Enable( aRbtAxis2.IsChecked());
91 else if( m_nAllSeriesAxisIndex == 1 )
92 aCBAxisSideBySide.Enable( aRbtAxis1.IsChecked());
94 return 0;
97 SfxTabPage* SchOptionTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
99 return new SchOptionTabPage(pWindow, rOutAttrs);
102 BOOL SchOptionTabPage::FillItemSet(SfxItemSet& rOutAttrs)
104 if(aRbtAxis2.IsChecked())
105 rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_SECONDARY_Y));
106 else
107 rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_PRIMARY_Y));
109 if(aMTGap.IsVisible())
110 rOutAttrs.Put(SfxInt32Item(SCHATTR_BAR_GAPWIDTH,static_cast< sal_Int32 >( aMTGap.GetValue())));
112 if(aMTOverlap.IsVisible())
113 rOutAttrs.Put(SfxInt32Item(SCHATTR_BAR_OVERLAP,static_cast< sal_Int32 >( aMTOverlap.GetValue())));
115 if(aCBConnect.IsVisible())
116 rOutAttrs.Put(SfxBoolItem(SCHATTR_BAR_CONNECT,aCBConnect.IsChecked()));
118 // model property is "group bars per axis", UI feature is the other way
119 // round: "show bars side by side"
120 if(aCBAxisSideBySide.IsVisible())
121 rOutAttrs.Put(SfxBoolItem(SCHATTR_GROUP_BARS_PER_AXIS, ! aCBAxisSideBySide.IsChecked()));
123 if(m_aRB_DontPaint.IsChecked())
124 rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP));
125 else if(m_aRB_AssumeZero.IsChecked())
126 rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::USE_ZERO));
127 else if(m_aRB_ContinueLine.IsChecked())
128 rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::CONTINUE));
130 if (m_aCBIncludeHiddenCells.IsVisible())
131 rOutAttrs.Put(SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, m_aCBIncludeHiddenCells.IsChecked()));
133 return TRUE;
136 void SchOptionTabPage::Reset(const SfxItemSet& rInAttrs)
138 const SfxPoolItem *pPoolItem = NULL;
140 aRbtAxis1.Check(TRUE);
141 aRbtAxis2.Check(FALSE);
142 if (rInAttrs.GetItemState(SCHATTR_AXIS,TRUE, &pPoolItem) == SFX_ITEM_SET)
144 long nVal=((const SfxInt32Item*)pPoolItem)->GetValue();
145 if(nVal==CHART_AXIS_SECONDARY_Y)
147 aRbtAxis2.Check(TRUE);
148 aRbtAxis1.Check(FALSE);
152 long nTmp;
153 if (rInAttrs.GetItemState(SCHATTR_BAR_GAPWIDTH, TRUE, &pPoolItem) == SFX_ITEM_SET)
155 nTmp = (long)((const SfxInt32Item*)pPoolItem)->GetValue();
156 aMTGap.SetValue(nTmp);
159 if (rInAttrs.GetItemState(SCHATTR_BAR_OVERLAP, TRUE, &pPoolItem) == SFX_ITEM_SET)
161 nTmp = (long)((const SfxInt32Item*)pPoolItem)->GetValue();
162 aMTOverlap.SetValue(nTmp);
165 if (rInAttrs.GetItemState(SCHATTR_BAR_CONNECT, TRUE, &pPoolItem) == SFX_ITEM_SET)
167 BOOL bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
168 aCBConnect.Check(bCheck);
171 if (rInAttrs.GetItemState(SCHATTR_AXIS_FOR_ALL_SERIES, TRUE, &pPoolItem) == SFX_ITEM_SET)
173 m_nAllSeriesAxisIndex = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
174 aCBAxisSideBySide.Disable();
176 if (rInAttrs.GetItemState(SCHATTR_GROUP_BARS_PER_AXIS, TRUE, &pPoolItem) == SFX_ITEM_SET)
178 // model property is "group bars per axis", UI feature is the other way
179 // round: "show bars side by side"
180 BOOL bCheck = ! static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
181 aCBAxisSideBySide.Check( bCheck );
183 else
185 aCBAxisSideBySide.Show(FALSE);
189 //missing value treatment
191 ::com::sun::star::uno::Sequence < sal_Int32 > aMissingValueTreatments;
192 if( rInAttrs.GetItemState(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS, TRUE, &pPoolItem) == SFX_ITEM_SET )
193 aMissingValueTreatments =((const SfxIntegerListItem*)pPoolItem)->GetConstSequence();
195 if ( aMissingValueTreatments.getLength()>1 && rInAttrs.GetItemState(SCHATTR_MISSING_VALUE_TREATMENT,TRUE, &pPoolItem) == SFX_ITEM_SET)
197 m_aRB_DontPaint.Enable(FALSE);
198 m_aRB_AssumeZero.Enable(FALSE);
199 m_aRB_ContinueLine.Enable(FALSE);
201 for( sal_Int32 nN =0; nN<aMissingValueTreatments.getLength(); nN++ )
203 sal_Int32 nVal = aMissingValueTreatments[nN];
204 if(nVal==::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
205 m_aRB_DontPaint.Enable(TRUE);
206 else if(nVal==::com::sun::star::chart::MissingValueTreatment::USE_ZERO)
207 m_aRB_AssumeZero.Enable(TRUE);
208 else if(nVal==::com::sun::star::chart::MissingValueTreatment::CONTINUE)
209 m_aRB_ContinueLine.Enable(TRUE);
212 long nVal=((const SfxInt32Item*)pPoolItem)->GetValue();
213 if(nVal==::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
214 m_aRB_DontPaint.Check(TRUE);
215 else if(nVal==::com::sun::star::chart::MissingValueTreatment::USE_ZERO)
216 m_aRB_AssumeZero.Check(TRUE);
217 else if(nVal==::com::sun::star::chart::MissingValueTreatment::CONTINUE)
218 m_aRB_ContinueLine.Check(TRUE);
220 else
222 m_aFT_MissingValues.Show(FALSE);
223 m_aRB_DontPaint.Show(FALSE);
224 m_aRB_AssumeZero.Show(FALSE);
225 m_aRB_ContinueLine.Show(FALSE);
229 // Include hidden cells
230 if (rInAttrs.GetItemState(SCHATTR_INCLUDE_HIDDEN_CELLS, TRUE, &pPoolItem) == SFX_ITEM_SET)
232 bool bVal = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
233 m_aCBIncludeHiddenCells.Check(bVal);
235 else
237 m_aCBIncludeHiddenCells.Show(FALSE);
238 if(!m_aFT_MissingValues.IsVisible())
239 m_aFL_PlotOptions.Show(FALSE);
242 AdaptControlPositionsAndVisibility();
245 void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
247 m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
248 m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
249 m_bProvidesBarConnectors = bProvidesBarConnectors;
251 AdaptControlPositionsAndVisibility();
254 void lcl_offsetControl(Control& rCtrl, long nXOffset, long nYOffset )
256 Point aPos = rCtrl.GetPosPixel();
257 rCtrl.SetPosPixel( Point(aPos.getX() + nXOffset, aPos.getY() + nYOffset) );
260 void lcl_optimzeRadioButtonSize( RadioButton& rCtrl )
262 rCtrl.SetSizePixel( rCtrl.CalcMinimumSize() );
265 void SchOptionTabPage::AdaptControlPositionsAndVisibility()
267 aRbtAxis1.Show(m_bProvidesSecondaryYAxis);
268 aRbtAxis2.Show(m_bProvidesSecondaryYAxis);
269 aGrpAxis.Show(m_bProvidesSecondaryYAxis);
271 aMTGap.Show(m_bProvidesOverlapAndGapWidth);
272 aFTGap.Show(m_bProvidesOverlapAndGapWidth);
274 aMTOverlap.Show(m_bProvidesOverlapAndGapWidth);
275 aFTOverlap.Show(m_bProvidesOverlapAndGapWidth);
277 aCBConnect.Show(m_bProvidesBarConnectors);
279 if( !aMTGap.IsVisible() && !aMTOverlap.IsVisible() )
281 aGrpBar.Show(FALSE);
282 Point aPos;
283 if( !aRbtAxis1.IsVisible() && !aRbtAxis2.IsVisible() )
284 aPos = aGrpAxis.GetPosPixel();
285 else
286 aPos = aGrpBar.GetPosPixel();
288 long nYOffset = aPos.getY() - m_aFL_PlotOptions.GetPosPixel().getY();
289 lcl_offsetControl(m_aFL_PlotOptions, 0, nYOffset);
290 lcl_offsetControl(m_aFT_MissingValues, 0, nYOffset);
291 lcl_offsetControl(m_aRB_DontPaint, 0, nYOffset);
292 lcl_offsetControl(m_aRB_AssumeZero, 0, nYOffset);
293 lcl_offsetControl(m_aRB_ContinueLine, 0, nYOffset);
294 lcl_offsetControl(m_aCBIncludeHiddenCells, 0, nYOffset);
297 m_aFT_MissingValues.SetSizePixel( m_aFT_MissingValues.CalcMinimumSize() );
298 lcl_optimzeRadioButtonSize( m_aRB_DontPaint );
299 lcl_optimzeRadioButtonSize( m_aRB_AssumeZero );
300 lcl_optimzeRadioButtonSize( m_aRB_ContinueLine );
302 Size aControlDistance( m_aFT_MissingValues.LogicToPixel( Size(RSC_SP_CTRL_DESC_X,RSC_SP_CTRL_GROUP_Y), MapMode(MAP_APPFONT) ) );
303 long nXOffset = m_aFT_MissingValues.GetPosPixel().getX() + m_aFT_MissingValues.GetSizePixel().getWidth() + aControlDistance.getWidth() - m_aRB_DontPaint.GetPosPixel().getX();
304 lcl_offsetControl(m_aRB_DontPaint, nXOffset, 0);
305 lcl_offsetControl(m_aRB_AssumeZero, nXOffset, 0);
306 lcl_offsetControl(m_aRB_ContinueLine, nXOffset, 0);
308 if( !m_aFT_MissingValues.IsVisible() )
310 //for example for stock charts
311 m_aCBIncludeHiddenCells.SetPosPixel( m_aFT_MissingValues.GetPosPixel() );
314 //.............................................................................
315 } //namespace chart
316 //.............................................................................