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 #include "tp_SeriesToAxis.hxx"
27 #include "tp_SeriesToAxis.hrc"
28 
29 #include "ResId.hxx"
30 #include "chartview/ChartSfxItemIds.hxx"
31 #include "NoWarningThisInCTOR.hxx"
32 
33 // header for class SfxBoolItem
34 #include <svl/eitem.hxx>
35 // header for SfxInt32Item
36 #include <svl/intitem.hxx>
37 //SfxIntegerListItem
38 #include <svl/ilstitem.hxx>
39 #include <svtools/controldims.hrc>
40 
41 #include <com/sun/star/chart/MissingValueTreatment.hpp>
42 
43 //.............................................................................
44 namespace chart
45 {
46 //.............................................................................
47 
SchOptionTabPage(Window * pWindow,const SfxItemSet & rInAttrs)48 SchOptionTabPage::SchOptionTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
49 	SfxTabPage(pWindow, SchResId(TP_OPTIONS), rInAttrs),
50 	aGrpAxis(this, SchResId(GRP_OPT_AXIS)),
51 	aRbtAxis1(this,SchResId(RBT_OPT_AXIS_1)),
52 	aRbtAxis2(this,SchResId(RBT_OPT_AXIS_2)),
53 
54 	aGrpBar(this, SchResId(GB_BAR)),
55 	aFTGap(this,SchResId(FT_GAP)),
56 	aMTGap(this,SchResId(MT_GAP)),
57 	aFTOverlap(this,SchResId(FT_OVERLAP)),
58 	aMTOverlap(this,SchResId(MT_OVERLAP)),
59 	aCBConnect(this,SchResId(CB_CONNECTOR)),
60     aCBAxisSideBySide(this,SchResId(CB_BARS_SIDE_BY_SIDE)),
61     m_aFL_PlotOptions(this,SchResId(FL_PLOT_OPTIONS)),
62     m_aFT_MissingValues(this,SchResId(FT_MISSING_VALUES)),
63     m_aRB_DontPaint(this,SchResId(RB_DONT_PAINT)),
64     m_aRB_AssumeZero(this,SchResId(RB_ASSUME_ZERO)),
65     m_aRB_ContinueLine(this,SchResId(RB_CONTINUE_LINE)),
66     m_aCBIncludeHiddenCells(this,SchResId(CB_INCLUDE_HIDDEN_CELLS)),
67     m_bProvidesSecondaryYAxis(true),
68     m_bProvidesOverlapAndGapWidth(false)
69 {
70 	FreeResource();
71 
72     aRbtAxis1.SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
73     aRbtAxis2.SetClickHdl( LINK( this, SchOptionTabPage, EnableHdl ));
74 }
75 
~SchOptionTabPage()76 SchOptionTabPage::~SchOptionTabPage()
77 {
78 }
79 
IMPL_LINK(SchOptionTabPage,EnableHdl,RadioButton *,EMPTYARG)80 IMPL_LINK( SchOptionTabPage, EnableHdl, RadioButton *, EMPTYARG )
81 {
82     if( m_nAllSeriesAxisIndex == 0 )
83         aCBAxisSideBySide.Enable( aRbtAxis2.IsChecked());
84     else if( m_nAllSeriesAxisIndex == 1 )
85         aCBAxisSideBySide.Enable( aRbtAxis1.IsChecked());
86 
87     return 0;
88 }
89 
Create(Window * pWindow,const SfxItemSet & rOutAttrs)90 SfxTabPage* SchOptionTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
91 {
92 	return new SchOptionTabPage(pWindow, rOutAttrs);
93 }
94 
FillItemSet(SfxItemSet & rOutAttrs)95 sal_Bool SchOptionTabPage::FillItemSet(SfxItemSet& rOutAttrs)
96 {
97 	if(aRbtAxis2.IsChecked())
98 		rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_SECONDARY_Y));
99 	else
100 		rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS,CHART_AXIS_PRIMARY_Y));
101 
102 	if(aMTGap.IsVisible())
103 		rOutAttrs.Put(SfxInt32Item(SCHATTR_BAR_GAPWIDTH,static_cast< sal_Int32 >( aMTGap.GetValue())));
104 
105 	if(aMTOverlap.IsVisible())
106 		rOutAttrs.Put(SfxInt32Item(SCHATTR_BAR_OVERLAP,static_cast< sal_Int32 >( aMTOverlap.GetValue())));
107 
108 	if(aCBConnect.IsVisible())
109 		rOutAttrs.Put(SfxBoolItem(SCHATTR_BAR_CONNECT,aCBConnect.IsChecked()));
110 
111     // model property is "group bars per axis", UI feature is the other way
112     // round: "show bars side by side"
113     if(aCBAxisSideBySide.IsVisible())
114         rOutAttrs.Put(SfxBoolItem(SCHATTR_GROUP_BARS_PER_AXIS, ! aCBAxisSideBySide.IsChecked()));
115 
116     if(m_aRB_DontPaint.IsChecked())
117         rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP));
118     else if(m_aRB_AssumeZero.IsChecked())
119         rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::USE_ZERO));
120     else if(m_aRB_ContinueLine.IsChecked())
121         rOutAttrs.Put(SfxInt32Item(SCHATTR_MISSING_VALUE_TREATMENT,::com::sun::star::chart::MissingValueTreatment::CONTINUE));
122 
123     if (m_aCBIncludeHiddenCells.IsVisible())
124         rOutAttrs.Put(SfxBoolItem(SCHATTR_INCLUDE_HIDDEN_CELLS, m_aCBIncludeHiddenCells.IsChecked()));
125 
126 	return sal_True;
127 }
128 
Reset(const SfxItemSet & rInAttrs)129 void SchOptionTabPage::Reset(const SfxItemSet& rInAttrs)
130 {
131 	const SfxPoolItem *pPoolItem = NULL;
132 
133 	aRbtAxis1.Check(sal_True);
134 	aRbtAxis2.Check(sal_False);
135 	if (rInAttrs.GetItemState(SCHATTR_AXIS,sal_True, &pPoolItem) == SFX_ITEM_SET)
136 	{
137 		long nVal=((const SfxInt32Item*)pPoolItem)->GetValue();
138 		if(nVal==CHART_AXIS_SECONDARY_Y)
139 		{
140 			aRbtAxis2.Check(sal_True);
141 			aRbtAxis1.Check(sal_False);
142 		}
143 	}
144 
145 	long nTmp;
146 	if (rInAttrs.GetItemState(SCHATTR_BAR_GAPWIDTH, sal_True, &pPoolItem) == SFX_ITEM_SET)
147 	{
148 		nTmp = (long)((const SfxInt32Item*)pPoolItem)->GetValue();
149 		aMTGap.SetValue(nTmp);
150 	}
151 
152 	if (rInAttrs.GetItemState(SCHATTR_BAR_OVERLAP, sal_True, &pPoolItem) == SFX_ITEM_SET)
153 	{
154 		nTmp = (long)((const SfxInt32Item*)pPoolItem)->GetValue();
155 		aMTOverlap.SetValue(nTmp);
156 	}
157 
158 	if (rInAttrs.GetItemState(SCHATTR_BAR_CONNECT, sal_True, &pPoolItem) == SFX_ITEM_SET)
159 	{
160 		sal_Bool bCheck = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
161 		aCBConnect.Check(bCheck);
162 	}
163 
164     if (rInAttrs.GetItemState(SCHATTR_AXIS_FOR_ALL_SERIES, sal_True, &pPoolItem) == SFX_ITEM_SET)
165     {
166         m_nAllSeriesAxisIndex = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
167         aCBAxisSideBySide.Disable();
168     }
169     if (rInAttrs.GetItemState(SCHATTR_GROUP_BARS_PER_AXIS, sal_True, &pPoolItem) == SFX_ITEM_SET)
170     {
171         // model property is "group bars per axis", UI feature is the other way
172         // round: "show bars side by side"
173 		sal_Bool bCheck = ! static_cast< const SfxBoolItem * >( pPoolItem )->GetValue();
174         aCBAxisSideBySide.Check( bCheck );
175     }
176     else
177     {
178         aCBAxisSideBySide.Show(sal_False);
179     }
180 
181 
182     //missing value treatment
183     {
184         ::com::sun::star::uno::Sequence < sal_Int32 > aMissingValueTreatments;
185         if( rInAttrs.GetItemState(SCHATTR_AVAILABLE_MISSING_VALUE_TREATMENTS, sal_True, &pPoolItem) == SFX_ITEM_SET )
186             aMissingValueTreatments =((const SfxIntegerListItem*)pPoolItem)->GetConstSequence();
187 
188         if ( aMissingValueTreatments.getLength()>1 && rInAttrs.GetItemState(SCHATTR_MISSING_VALUE_TREATMENT,sal_True, &pPoolItem) == SFX_ITEM_SET)
189         {
190             m_aRB_DontPaint.Enable(sal_False);
191             m_aRB_AssumeZero.Enable(sal_False);
192             m_aRB_ContinueLine.Enable(sal_False);
193 
194             for( sal_Int32 nN =0; nN<aMissingValueTreatments.getLength(); nN++ )
195             {
196                 sal_Int32 nVal = aMissingValueTreatments[nN];
197                 if(nVal==::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
198                     m_aRB_DontPaint.Enable(sal_True);
199                 else if(nVal==::com::sun::star::chart::MissingValueTreatment::USE_ZERO)
200                     m_aRB_AssumeZero.Enable(sal_True);
201                 else if(nVal==::com::sun::star::chart::MissingValueTreatment::CONTINUE)
202                     m_aRB_ContinueLine.Enable(sal_True);
203             }
204 
205             long nVal=((const SfxInt32Item*)pPoolItem)->GetValue();
206             if(nVal==::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP)
207                 m_aRB_DontPaint.Check(sal_True);
208             else if(nVal==::com::sun::star::chart::MissingValueTreatment::USE_ZERO)
209                 m_aRB_AssumeZero.Check(sal_True);
210             else if(nVal==::com::sun::star::chart::MissingValueTreatment::CONTINUE)
211                 m_aRB_ContinueLine.Check(sal_True);
212         }
213         else
214         {
215             m_aFT_MissingValues.Show(sal_False);
216             m_aRB_DontPaint.Show(sal_False);
217             m_aRB_AssumeZero.Show(sal_False);
218             m_aRB_ContinueLine.Show(sal_False);
219         }
220     }
221 
222     // Include hidden cells
223     if (rInAttrs.GetItemState(SCHATTR_INCLUDE_HIDDEN_CELLS, sal_True, &pPoolItem) == SFX_ITEM_SET)
224     {
225         bool bVal = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
226         m_aCBIncludeHiddenCells.Check(bVal);
227     }
228     else
229     {
230         m_aCBIncludeHiddenCells.Show(sal_False);
231         if(!m_aFT_MissingValues.IsVisible())
232             m_aFL_PlotOptions.Show(sal_False);
233     }
234 
235     AdaptControlPositionsAndVisibility();
236 }
237 
Init(bool bProvidesSecondaryYAxis,bool bProvidesOverlapAndGapWidth,bool bProvidesBarConnectors)238 void SchOptionTabPage::Init( bool bProvidesSecondaryYAxis, bool bProvidesOverlapAndGapWidth, bool bProvidesBarConnectors )
239 {
240     m_bProvidesSecondaryYAxis = bProvidesSecondaryYAxis;
241     m_bProvidesOverlapAndGapWidth = bProvidesOverlapAndGapWidth;
242     m_bProvidesBarConnectors = bProvidesBarConnectors;
243 
244     AdaptControlPositionsAndVisibility();
245 }
246 
lcl_offsetControl(Control & rCtrl,long nXOffset,long nYOffset)247 void lcl_offsetControl(Control& rCtrl, long nXOffset, long nYOffset )
248 {
249     Point aPos = rCtrl.GetPosPixel();
250     rCtrl.SetPosPixel( Point(aPos.getX() + nXOffset, aPos.getY() + nYOffset) );
251 }
252 
lcl_optimzeRadioButtonSize(RadioButton & rCtrl)253 void lcl_optimzeRadioButtonSize( RadioButton& rCtrl )
254 {
255     rCtrl.SetSizePixel( rCtrl.CalcMinimumSize() );
256 }
257 
AdaptControlPositionsAndVisibility()258 void SchOptionTabPage::AdaptControlPositionsAndVisibility()
259 {
260     aRbtAxis1.Show(m_bProvidesSecondaryYAxis);
261     aRbtAxis2.Show(m_bProvidesSecondaryYAxis);
262     aGrpAxis.Show(m_bProvidesSecondaryYAxis);
263 
264 	aMTGap.Show(m_bProvidesOverlapAndGapWidth);
265 	aFTGap.Show(m_bProvidesOverlapAndGapWidth);
266 
267 	aMTOverlap.Show(m_bProvidesOverlapAndGapWidth);
268 	aFTOverlap.Show(m_bProvidesOverlapAndGapWidth);
269 
270     aCBConnect.Show(m_bProvidesBarConnectors);
271 
272     if( !aMTGap.IsVisible() && !aMTOverlap.IsVisible() )
273     {
274 		aGrpBar.Show(sal_False);
275 		Point aPos;
276 		if( !aRbtAxis1.IsVisible() && !aRbtAxis2.IsVisible() )
277 			aPos = aGrpAxis.GetPosPixel();
278 	    else
279             aPos = aGrpBar.GetPosPixel();
280 
281         long nYOffset = aPos.getY() - m_aFL_PlotOptions.GetPosPixel().getY();
282         lcl_offsetControl(m_aFL_PlotOptions,       0, nYOffset);
283         lcl_offsetControl(m_aFT_MissingValues,     0, nYOffset);
284         lcl_offsetControl(m_aRB_DontPaint,         0, nYOffset);
285         lcl_offsetControl(m_aRB_AssumeZero,        0, nYOffset);
286         lcl_offsetControl(m_aRB_ContinueLine,      0, nYOffset);
287         lcl_offsetControl(m_aCBIncludeHiddenCells, 0, nYOffset);
288     }
289 
290     m_aFT_MissingValues.SetSizePixel( m_aFT_MissingValues.CalcMinimumSize() );
291     lcl_optimzeRadioButtonSize( m_aRB_DontPaint );
292     lcl_optimzeRadioButtonSize( m_aRB_AssumeZero );
293     lcl_optimzeRadioButtonSize( m_aRB_ContinueLine );
294 
295     Size aControlDistance( m_aFT_MissingValues.LogicToPixel( Size(RSC_SP_CTRL_DESC_X,RSC_SP_CTRL_GROUP_Y), MapMode(MAP_APPFONT) ) );
296     long nXOffset = m_aFT_MissingValues.GetPosPixel().getX() + m_aFT_MissingValues.GetSizePixel().getWidth() + aControlDistance.getWidth() - m_aRB_DontPaint.GetPosPixel().getX();
297     lcl_offsetControl(m_aRB_DontPaint,         nXOffset, 0);
298     lcl_offsetControl(m_aRB_AssumeZero,        nXOffset, 0);
299     lcl_offsetControl(m_aRB_ContinueLine,      nXOffset, 0);
300 
301     if( !m_aFT_MissingValues.IsVisible() )
302     {
303         //for example for stock charts
304         m_aCBIncludeHiddenCells.SetPosPixel( m_aFT_MissingValues.GetPosPixel() );
305     }
306 }
307 //.............................................................................
308 } //namespace chart
309 //.............................................................................
310