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_Scale.hxx"
27 #include "tp_Scale.hrc"
28 
29 #include "ResId.hxx"
30 #include "Strings.hrc"
31 #include "chartview/ChartSfxItemIds.hxx"
32 #include "NoWarningThisInCTOR.hxx"
33 #include "AxisHelper.hxx"
34 
35 #ifndef _SVX_SVXIDS_HRC
36 #include <svx/svxids.hrc>
37 #endif
38 #include <rtl/math.hxx>
39 // header for class SvxDoubleItem
40 #include <svx/chrtitem.hxx>
41 // header for class SfxBoolItem
42 #include <svl/eitem.hxx>
43 // header for SfxInt32Item
44 #include <svl/intitem.hxx>
45 
46 // header for class WarningBox
47 #include <vcl/msgbox.hxx>
48 
49 // header for class SvNumberformat
50 #ifndef _ZFORMAT_HXX
51 #ifndef _ZFORLIST_DECLARE_TABLE
52 #define _ZFORLIST_DECLARE_TABLE
53 #endif
54 #include <svl/zformat.hxx>
55 #endif
56 
57 #include <svtools/controldims.hrc>
58 
59 #include <com/sun/star/chart2/AxisType.hpp>
60 
61 using namespace ::com::sun::star;
62 
63 //.............................................................................
64 namespace chart
65 {
66 //.............................................................................
67 
68 namespace
69 {
70 
lcl_placeControlAtX(Control & rControl,long nNewXPos)71 void lcl_placeControlAtX( Control& rControl, long nNewXPos )
72 {
73     Point aPos( rControl.GetPosPixel() );
74     aPos.X() = nNewXPos;
75     rControl.SetPosPixel(aPos);
76 }
77 
lcl_placeControlAtY(Control & rControl,long nNewYPos)78 void lcl_placeControlAtY( Control& rControl, long nNewYPos )
79 {
80     Point aPos( rControl.GetPosPixel() );
81     aPos.Y() = nNewYPos;
82     rControl.SetPosPixel(aPos);
83 }
84 
lcl_shiftControls(Control & rEdit,Control & rAuto,long nNewXPos)85 void lcl_shiftControls( Control& rEdit, Control& rAuto, long nNewXPos )
86 {
87     Point aPos( rEdit.GetPosPixel() );
88     long nShift = nNewXPos - aPos.X();
89     aPos.X() = nNewXPos;
90     rEdit.SetPosPixel(aPos);
91 
92     aPos = rAuto.GetPosPixel();
93     aPos.X() += nShift;
94     rAuto.SetPosPixel(aPos);
95 }
96 
lcl_getLabelDistance(Control & rControl)97 long lcl_getLabelDistance( Control& rControl )
98 {
99     return rControl.LogicToPixel( Size(RSC_SP_CTRL_DESC_X, 0), MapMode(MAP_APPFONT) ).Width();
100 }
101 
lcl_setValue(FormattedField & rFmtField,double fValue)102 void lcl_setValue( FormattedField& rFmtField, double fValue )
103 {
104     rFmtField.SetValue( fValue );
105     rFmtField.SetDefaultValue( fValue );
106 }
107 
108 }
109 
ScaleTabPage(Window * pWindow,const SfxItemSet & rInAttrs)110 ScaleTabPage::ScaleTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
111 	SfxTabPage(pWindow, SchResId(TP_SCALE), rInAttrs),
112 
113 	aFlScale(this, SchResId(FL_SCALE)),
114 
115     aCbxReverse(this, SchResId(CBX_REVERSE)),
116     aCbxLogarithm(this, SchResId(CBX_LOGARITHM)),
117 
118     m_aTxt_AxisType(this, SchResId (TXT_AXIS_TYPE)),
119     m_aLB_AxisType(this, SchResId(LB_AXIS_TYPE)),
120 
121 	aTxtMin (this, SchResId (TXT_MIN)),
122 	aFmtFldMin(this, SchResId(EDT_MIN)),
123 	aCbxAutoMin(this, SchResId(CBX_AUTO_MIN)),
124 
125 	aTxtMax(this, SchResId (TXT_MAX)),
126 	aFmtFldMax(this, SchResId(EDT_MAX)),
127 	aCbxAutoMax(this, SchResId(CBX_AUTO_MAX)),
128 
129     m_aTxt_TimeResolution(this, SchResId (TXT_TIME_RESOLUTION)),
130 	m_aLB_TimeResolution(this, SchResId(LB_TIME_RESOLUTION)),
131 	m_aCbx_AutoTimeResolution(this, SchResId(CBX_AUTO_TIME_RESOLUTION)),
132 
133 	aTxtMain (this, SchResId (TXT_STEP_MAIN)),
134 	aFmtFldStepMain(this, SchResId(EDT_STEP_MAIN)),
135 	m_aMt_MainDateStep(this, SchResId(MT_MAIN_DATE_STEP)),
136     m_aLB_MainTimeUnit(this, SchResId(LB_MAIN_TIME_UNIT)),
137     aCbxAutoStepMain(this, SchResId(CBX_AUTO_STEP_MAIN)),
138 
139 	aTxtHelpCount (this, SchResId (TXT_STEP_HELP_COUNT)),
140     aTxtHelp (this, SchResId (TXT_STEP_HELP)),
141     aMtStepHelp (this, SchResId (MT_STEPHELP)),
142 	m_aLB_HelpTimeUnit(this, SchResId(LB_HELP_TIME_UNIT)),
143     aCbxAutoStepHelp(this, SchResId(CBX_AUTO_STEP_HELP)),
144 
145     aTxtOrigin (this, SchResId (TXT_ORIGIN)),
146 	aFmtFldOrigin(this, SchResId(EDT_ORIGIN)),
147 	aCbxAutoOrigin(this, SchResId(CBX_AUTO_ORIGIN)),
148 
149 	fMin(0.0),
150 	fMax(0.0),
151 	fStepMain(0.0),
152 	nStepHelp(0),
153 	fOrigin(0.0),
154     m_nTimeResolution(1),
155     m_nMainTimeUnit(1),
156     m_nHelpTimeUnit(1),
157     m_nAxisType(chart2::AxisType::REALNUMBER),
158     m_bAllowDateAxis(false),
159 	pNumFormatter(NULL),
160     m_bShowAxisOrigin(false)
161 {
162 	FreeResource();
163 	SetExchangeSupport();
164 
165     aCbxAutoMin.SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
166     aCbxAutoMax.SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
167     aCbxAutoStepMain.SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
168     aCbxAutoStepHelp.SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
169     aCbxAutoOrigin.SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
170     m_aCbx_AutoTimeResolution.SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
171 
172     m_aLB_AxisType.SetDropDownLineCount(3);
173     m_aLB_AxisType.SetSelectHdl(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
174 
175     m_aLB_TimeResolution.SetDropDownLineCount(3);
176     m_aLB_MainTimeUnit.SetDropDownLineCount(3);
177     m_aLB_HelpTimeUnit.SetDropDownLineCount(3);
178 
179     aFmtFldMin.SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
180     aFmtFldMax.SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
181     aFmtFldStepMain.SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
182     aFmtFldOrigin.SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
183 }
184 
IMPL_LINK(ScaleTabPage,FmtFieldModifiedHdl,FormattedField *,pFmtFied)185 IMPL_LINK( ScaleTabPage, FmtFieldModifiedHdl, FormattedField*, pFmtFied )
186 {
187     if( pFmtFied )
188         pFmtFied->SetDefaultValue( pFmtFied->GetValue() );
189     return 0;
190 }
191 
StateChanged(StateChangedType nType)192 void ScaleTabPage::StateChanged( StateChangedType nType )
193 {
194     TabPage::StateChanged( nType );
195 
196     if( nType == STATE_CHANGE_INITSHOW )
197         AdjustControlPositions();
198 }
199 
AdjustControlPositions()200 void ScaleTabPage::AdjustControlPositions()
201 {
202     //optimize position of the controls
203     long nLabelWidth = ::std::max( aTxtMin.CalcMinimumSize().Width(), aTxtMax.CalcMinimumSize().Width() );
204     nLabelWidth = ::std::max( aTxtMain.CalcMinimumSize().Width(), nLabelWidth );
205     nLabelWidth = ::std::max( aTxtHelp.CalcMinimumSize().Width(), nLabelWidth );
206     nLabelWidth = ::std::max( aTxtHelpCount.CalcMinimumSize().Width(), nLabelWidth );
207     nLabelWidth = ::std::max( aTxtOrigin.CalcMinimumSize().Width(), nLabelWidth );
208     nLabelWidth = ::std::max( m_aTxt_TimeResolution.CalcMinimumSize().Width(), nLabelWidth );
209     nLabelWidth = ::std::max( m_aTxt_AxisType.CalcMinimumSize().Width(), nLabelWidth );
210     nLabelWidth+=1;
211 
212     long nLabelDistance = lcl_getLabelDistance(aTxtMin);
213     long nNewXPos = aTxtMin.GetPosPixel().X() + nLabelWidth + nLabelDistance;
214 
215     //ensure that the auto checkboxes are wide enough and have correct size for calculation
216     aCbxAutoMin.SetSizePixel( aCbxAutoMin.CalcMinimumSize() );
217     aCbxAutoMax.SetSizePixel( aCbxAutoMax.CalcMinimumSize() );
218     aCbxAutoStepMain.SetSizePixel( aCbxAutoStepMain.CalcMinimumSize() );
219     aCbxAutoStepHelp.SetSizePixel( aCbxAutoStepHelp.CalcMinimumSize() );
220     aCbxAutoOrigin.SetSizePixel( aCbxAutoOrigin.CalcMinimumSize() );
221     m_aCbx_AutoTimeResolution.SetSizePixel( m_aCbx_AutoTimeResolution.CalcMinimumSize() );
222 
223     //ensure new pos is ok
224     long nWidthOfOtherControls = m_aLB_MainTimeUnit.GetPosPixel().X() + m_aLB_MainTimeUnit.GetSizePixel().Width() - aFmtFldMin.GetPosPixel().X();
225     long nDialogWidth = GetSizePixel().Width();
226 
227     long nLeftSpace = nDialogWidth - nNewXPos - nWidthOfOtherControls;
228     if(nLeftSpace>=0)
229     {
230         Size aSize( aTxtMin.GetSizePixel() );
231         aSize.Width() = nLabelWidth;
232         aTxtMin.SetSizePixel(aSize);
233         aTxtMax.SetSizePixel(aSize);
234         aTxtMain.SetSizePixel(aSize);
235         aTxtHelp.SetSizePixel(aSize);
236         aTxtHelpCount.SetSizePixel(aSize);
237         aTxtOrigin.SetSizePixel(aSize);
238         m_aTxt_TimeResolution.SetSizePixel(aSize);
239         m_aTxt_AxisType.SetSizePixel(aSize);
240 
241         long nOrgAutoCheckX = aCbxAutoMin.GetPosPixel().X();
242         lcl_placeControlAtX( aCbxAutoStepMain, nOrgAutoCheckX );
243         lcl_placeControlAtX( aCbxAutoStepHelp, nOrgAutoCheckX );
244 
245         lcl_shiftControls( aFmtFldMin, aCbxAutoMin, nNewXPos );
246         lcl_shiftControls( aFmtFldMax, aCbxAutoMax, nNewXPos );
247         lcl_shiftControls( aFmtFldStepMain, aCbxAutoStepMain, nNewXPos );
248         lcl_placeControlAtX( m_aMt_MainDateStep, aFmtFldStepMain.GetPosPixel().X() );
249         lcl_shiftControls( aMtStepHelp, aCbxAutoStepHelp, nNewXPos );
250         lcl_shiftControls( aFmtFldOrigin, aCbxAutoOrigin, nNewXPos );
251         lcl_shiftControls( m_aLB_TimeResolution, m_aCbx_AutoTimeResolution, nNewXPos );
252         lcl_placeControlAtX( m_aLB_AxisType, nNewXPos );
253 
254         nNewXPos = aCbxAutoStepMain.GetPosPixel().X() + aCbxAutoStepMain.GetSizePixel().Width() + nLabelDistance;
255         lcl_placeControlAtX( m_aLB_MainTimeUnit, nNewXPos );
256         lcl_placeControlAtX( m_aLB_HelpTimeUnit, nNewXPos );
257     }
258     PlaceIntervalControlsAccordingToAxisType();
259 }
260 
PlaceIntervalControlsAccordingToAxisType()261 void ScaleTabPage::PlaceIntervalControlsAccordingToAxisType()
262 {
263     long nMinX = std::min( aCbxAutoStepMain.GetPosPixel().X(), m_aLB_MainTimeUnit.GetPosPixel().X() );
264     long nLabelDistance = lcl_getLabelDistance(aTxtMin);
265     long nListWidth = m_aLB_MainTimeUnit.GetSizePixel().Width();
266 
267     if( chart2::AxisType::DATE == m_nAxisType )
268     {
269         lcl_placeControlAtX( m_aLB_MainTimeUnit, nMinX );
270         lcl_placeControlAtX( m_aLB_HelpTimeUnit, nMinX );
271         long nSecondX = nMinX + nListWidth + nLabelDistance;
272         lcl_placeControlAtX( aCbxAutoStepMain, nSecondX );
273         lcl_placeControlAtX( aCbxAutoStepHelp, nSecondX );
274 
275         long nOne = m_aMt_MainDateStep.LogicToPixel( Size(0, 1), MapMode(MAP_APPFONT) ).Height();
276 
277         long nYMajor = m_aMt_MainDateStep.GetPosPixel().Y();
278         lcl_placeControlAtY( aCbxAutoStepMain , nYMajor+(3*nOne));
279         lcl_placeControlAtY( aTxtMain , nYMajor+nOne+nOne);
280 
281         long nYMinor = m_aLB_HelpTimeUnit.GetPosPixel().Y();
282         lcl_placeControlAtY( aMtStepHelp , nYMinor );
283         lcl_placeControlAtY( aCbxAutoStepHelp , nYMinor+(3*nOne));
284     }
285     else
286     {
287         lcl_placeControlAtX( aCbxAutoStepMain, nMinX );
288         lcl_placeControlAtX( aCbxAutoStepHelp, nMinX );
289         long nSecondX = nMinX + aCbxAutoStepMain.GetSizePixel().Width() + nLabelDistance;
290         long nSecondXMax = GetSizePixel().Width() - nListWidth;
291         if( nSecondX > nSecondXMax )
292             nSecondX = nSecondXMax;
293         lcl_placeControlAtX( m_aLB_MainTimeUnit, nSecondX );
294         lcl_placeControlAtX( m_aLB_HelpTimeUnit, nSecondX );
295     }
296 }
297 
EnableControls()298 void ScaleTabPage::EnableControls()
299 {
300     bool bValueAxis = chart2::AxisType::REALNUMBER == m_nAxisType || chart2::AxisType::PERCENT == m_nAxisType || chart2::AxisType::DATE == m_nAxisType;
301     bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
302 
303     m_aTxt_AxisType.Show(m_bAllowDateAxis);
304     m_aLB_AxisType.Show(m_bAllowDateAxis);
305 
306     aCbxLogarithm.Show( bValueAxis && !bDateAxis );
307     aTxtMin.Show( bValueAxis );
308     aFmtFldMin.Show( bValueAxis );
309     aCbxAutoMin.Show( bValueAxis );
310     aTxtMax.Show( bValueAxis );
311     aFmtFldMax.Show( bValueAxis );
312     aCbxAutoMax.Show( bValueAxis );
313     aTxtMain.Show( bValueAxis );
314     aFmtFldStepMain.Show( bValueAxis );
315     aCbxAutoStepMain.Show( bValueAxis );
316     aTxtHelp.Show( bValueAxis );
317     aTxtHelpCount.Show( bValueAxis );
318     aMtStepHelp.Show( bValueAxis );
319     aCbxAutoStepHelp.Show( bValueAxis );
320 
321     aTxtOrigin.Show( m_bShowAxisOrigin && bValueAxis );
322     aFmtFldOrigin.Show( m_bShowAxisOrigin && bValueAxis );
323     aCbxAutoOrigin.Show( m_bShowAxisOrigin && bValueAxis );
324 
325     aTxtHelpCount.Show( bValueAxis && !bDateAxis );
326     aTxtHelp.Show( bDateAxis );
327 
328     m_aTxt_TimeResolution.Show( bDateAxis );
329 	m_aLB_TimeResolution.Show( bDateAxis );
330 	m_aCbx_AutoTimeResolution.Show( bDateAxis );
331 
332     bool bWasDateAxis = m_aMt_MainDateStep.IsVisible();
333     if( bWasDateAxis != bDateAxis )
334     {
335         //transport value from one to other control
336         if( bWasDateAxis )
337             lcl_setValue( aFmtFldStepMain, m_aMt_MainDateStep.GetValue() );
338         else
339             m_aMt_MainDateStep.SetValue( static_cast<sal_Int32>(aFmtFldStepMain.GetValue()) );
340     }
341     aFmtFldStepMain.Show( bValueAxis && !bDateAxis );
342     m_aMt_MainDateStep.Show( bDateAxis );
343 
344     m_aLB_MainTimeUnit.Show( bDateAxis );
345     m_aLB_HelpTimeUnit.Show( bDateAxis );
346 
347     EnableValueHdl(&aCbxAutoMin);
348 	EnableValueHdl(&aCbxAutoMax);
349 	EnableValueHdl(&aCbxAutoStepMain);
350 	EnableValueHdl(&aCbxAutoStepHelp);
351 	EnableValueHdl(&aCbxAutoOrigin);
352     EnableValueHdl(&m_aCbx_AutoTimeResolution);
353 }
354 
IMPL_LINK(ScaleTabPage,EnableValueHdl,CheckBox *,pCbx)355 IMPL_LINK( ScaleTabPage, EnableValueHdl, CheckBox *, pCbx )
356 {
357     bool bEnable = pCbx && !pCbx->IsChecked() && pCbx->IsEnabled();
358 	if (pCbx == &aCbxAutoMin)
359 	{
360 		aFmtFldMin.Enable( bEnable );
361 	}
362 	else if (pCbx == &aCbxAutoMax)
363 	{
364 		aFmtFldMax.Enable( bEnable );
365 	}
366 	else if (pCbx == &aCbxAutoStepMain)
367 	{
368 		aFmtFldStepMain.Enable( bEnable );
369         m_aMt_MainDateStep.Enable( bEnable );
370         m_aLB_MainTimeUnit.Enable( bEnable );
371 	}
372 	else if (pCbx == &aCbxAutoStepHelp)
373 	{
374         aMtStepHelp.Enable( bEnable );
375         m_aLB_HelpTimeUnit.Enable( bEnable );
376 	}
377     else if (pCbx == &m_aCbx_AutoTimeResolution)
378 	{
379         m_aLB_TimeResolution.Enable( bEnable );
380 	}
381 	else if (pCbx == &aCbxAutoOrigin)
382 	{
383 		aFmtFldOrigin.Enable( bEnable );
384 	}
385 	return 0;
386 }
387 
388 enum AxisTypeListBoxEntry
389 {
390     TYPE_AUTO=0,
391     TYPE_TEXT=1,
392     TYPE_DATE=2
393 };
394 
IMPL_LINK(ScaleTabPage,SelectAxisTypeHdl,void *,EMPTYARG)395 IMPL_LINK( ScaleTabPage, SelectAxisTypeHdl, void *, EMPTYARG )
396 {
397     sal_uInt16 nPos = m_aLB_AxisType.GetSelectEntryPos();
398     if( nPos==TYPE_DATE )
399         m_nAxisType = chart2::AxisType::DATE;
400     else
401         m_nAxisType = chart2::AxisType::CATEGORY;
402     if( chart2::AxisType::DATE == m_nAxisType )
403         aCbxLogarithm.Check(false);
404     EnableControls();
405     PlaceIntervalControlsAccordingToAxisType();
406     SetNumFormat();
407     return 0;
408 }
409 
Create(Window * pWindow,const SfxItemSet & rOutAttrs)410 SfxTabPage* ScaleTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
411 {
412     return new ScaleTabPage(pWindow, rOutAttrs);
413 }
414 
FillItemSet(SfxItemSet & rOutAttrs)415 sal_Bool ScaleTabPage::FillItemSet(SfxItemSet& rOutAttrs)
416 {
417 	DBG_ASSERT( pNumFormatter, "No NumberFormatter available" );
418 
419     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
420     if(m_bAllowDateAxis)
421         rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, TYPE_AUTO==m_aLB_AxisType.GetSelectEntryPos()));
422 
423     bool bAutoScale = false;
424     if( m_nAxisType==chart2::AxisType::CATEGORY )
425         bAutoScale = true;//reset scaling for category charts
426 
427     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN		 ,bAutoScale || aCbxAutoMin.IsChecked()));
428 	rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX		 ,bAutoScale || aCbxAutoMax.IsChecked()));
429 	rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || aCbxAutoStepHelp.IsChecked()));
430 	rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN   ,bAutoScale || aCbxAutoOrigin.IsChecked()));
431 	rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM     ,aCbxLogarithm.IsChecked()));
432     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_REVERSE       ,aCbxReverse.IsChecked()));
433 	rOutAttrs.Put(SvxDoubleItem(fMax	 , SCHATTR_AXIS_MAX));
434 	rOutAttrs.Put(SvxDoubleItem(fMin	 , SCHATTR_AXIS_MIN));
435 	rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
436 	rOutAttrs.Put(SvxDoubleItem(fOrigin	 , SCHATTR_AXIS_ORIGIN));
437 
438 	rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || aCbxAutoStepMain.IsChecked()));
439 	rOutAttrs.Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
440 
441     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_aCbx_AutoTimeResolution.IsChecked()));
442 	rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution));
443 
444     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
445     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
446 
447     return sal_True;
448 }
449 
Reset(const SfxItemSet & rInAttrs)450 void ScaleTabPage::Reset(const SfxItemSet& rInAttrs)
451 {
452 	DBG_ASSERT( pNumFormatter, "No NumberFormatter available" );
453     if(!pNumFormatter)
454         return;
455 
456 	const SfxPoolItem *pPoolItem = NULL;
457     if (rInAttrs.GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS, sal_True, &pPoolItem) == SFX_ITEM_SET)
458         m_bAllowDateAxis = (bool) ((const SfxBoolItem*)pPoolItem)->GetValue();
459     m_nAxisType=chart2::AxisType::REALNUMBER;
460     if (rInAttrs.GetItemState(SCHATTR_AXISTYPE, sal_True, &pPoolItem) == SFX_ITEM_SET)
461         m_nAxisType = (int) ((const SfxInt32Item*)pPoolItem)->GetValue();
462     if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
463         m_nAxisType=chart2::AxisType::CATEGORY;
464     if( m_bAllowDateAxis )
465     {
466         bool bAutoDateAxis = false;
467         if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS, sal_True, &pPoolItem) == SFX_ITEM_SET)
468             bAutoDateAxis = (bool) ((const SfxBoolItem*)pPoolItem)->GetValue();
469 
470         sal_uInt16 nPos = 0;
471         if( m_nAxisType==chart2::AxisType::DATE )
472             nPos=TYPE_DATE;
473         else if( bAutoDateAxis )
474             nPos=TYPE_AUTO;
475         else
476             nPos=TYPE_TEXT;
477         m_aLB_AxisType.SelectEntryPos( nPos );
478     }
479 
480     if( m_bAllowDateAxis )
481         aCbxReverse.SetHelpId("chart2:CheckBox:TP_SCALE:CBX_REVERSE:MayBeDateAxis");
482     else if( m_nAxisType==chart2::AxisType::CATEGORY || m_nAxisType==chart2::AxisType::SERIES )
483         aCbxReverse.SetHelpId("chart2:CheckBox:TP_SCALE:CBX_REVERSE:Category");
484 
485     PlaceIntervalControlsAccordingToAxisType();
486 
487     aCbxAutoMin.Check( true );
488     aCbxAutoMax.Check( true );
489     aCbxAutoStepMain.Check( true );
490     aCbxAutoStepHelp.Check( true );
491     aCbxAutoOrigin.Check( true );
492     m_aCbx_AutoTimeResolution.Check( true );
493 
494 	if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MIN,sal_True,&pPoolItem) == SFX_ITEM_SET)
495 		aCbxAutoMin.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
496 
497 	if (rInAttrs.GetItemState(SCHATTR_AXIS_MIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
498 	{
499 		fMin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
500 		lcl_setValue( aFmtFldMin, fMin );
501 	}
502 
503 	if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MAX,sal_True, &pPoolItem) == SFX_ITEM_SET)
504 		aCbxAutoMax.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
505 
506 	if (rInAttrs.GetItemState(SCHATTR_AXIS_MAX,sal_True, &pPoolItem) == SFX_ITEM_SET)
507 	{
508 		fMax = ((const SvxDoubleItem*)pPoolItem)->GetValue();
509 		lcl_setValue( aFmtFldMax, fMax );
510 	}
511 
512 	if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
513 		aCbxAutoStepMain.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
514 
515 	if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_MAIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
516 	{
517 		fStepMain = ((const SvxDoubleItem*)pPoolItem)->GetValue();
518 		lcl_setValue( aFmtFldStepMain, fStepMain );
519         m_aMt_MainDateStep.SetValue( static_cast<sal_Int32>(fStepMain) );
520 	}
521 	if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,sal_True, &pPoolItem) == SFX_ITEM_SET)
522 		aCbxAutoStepHelp.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
523 	if (rInAttrs.GetItemState(SCHATTR_AXIS_LOGARITHM,sal_True, &pPoolItem) == SFX_ITEM_SET)
524 		aCbxLogarithm.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
525     if (rInAttrs.GetItemState(SCHATTR_AXIS_REVERSE,sal_True, &pPoolItem) == SFX_ITEM_SET)
526         aCbxReverse.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
527 	if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_HELP,sal_True, &pPoolItem) == SFX_ITEM_SET)
528 	{
529 		nStepHelp = ((const SfxInt32Item*)pPoolItem)->GetValue();
530         aMtStepHelp.SetValue( nStepHelp );
531 	}
532 	if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
533 		aCbxAutoOrigin.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
534 	if (rInAttrs.GetItemState(SCHATTR_AXIS_ORIGIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
535 	{
536 		fOrigin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
537 		lcl_setValue( aFmtFldOrigin, fOrigin );
538 	}
539 
540     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,sal_True, &pPoolItem) == SFX_ITEM_SET)
541 		m_aCbx_AutoTimeResolution.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
542 	if (rInAttrs.GetItemState(SCHATTR_AXIS_TIME_RESOLUTION,sal_True, &pPoolItem) == SFX_ITEM_SET)
543 	{
544 		m_nTimeResolution = ((const SfxInt32Item*)pPoolItem)->GetValue();
545         m_aLB_TimeResolution.SelectEntryPos( m_nTimeResolution );
546 	}
547 
548     if (rInAttrs.GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT,sal_True, &pPoolItem) == SFX_ITEM_SET)
549 	{
550 		m_nMainTimeUnit = ((const SfxInt32Item*)pPoolItem)->GetValue();
551         m_aLB_MainTimeUnit.SelectEntryPos( m_nMainTimeUnit );
552 	}
553     if (rInAttrs.GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT,sal_True, &pPoolItem) == SFX_ITEM_SET)
554 	{
555 		m_nHelpTimeUnit = ((const SfxInt32Item*)pPoolItem)->GetValue();
556         m_aLB_HelpTimeUnit.SelectEntryPos( m_nHelpTimeUnit );
557 	}
558 
559 	EnableControls();
560     SetNumFormat();
561 }
562 
DeactivatePage(SfxItemSet * pItemSet)563 int ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
564 {
565     if( !pNumFormatter )
566     {
567         DBG_ERROR( "No NumberFormatter available" );
568         return LEAVE_PAGE;
569     }
570 
571     bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
572 
573 	sal_uInt32 nIndex = pNumFormatter->GetStandardIndex(LANGUAGE_SYSTEM);
574 	const SfxPoolItem *pPoolItem = NULL;
575     if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, sal_True, &pPoolItem ) == SFX_ITEM_SET )
576 		nIndex = static_cast< sal_uInt32 >( static_cast< const SfxInt32Item* >(pPoolItem)->GetValue());
577     else
578     {
579         OSL_ENSURE( false, "Using Standard Language" );
580     }
581 
582 	Control* pControl = NULL;
583 	sal_uInt16 nErrStrId = 0;
584 	double fDummy;
585 
586 	fMax = aFmtFldMax.GetValue();
587 	fMin = aFmtFldMin.GetValue();
588 	fOrigin = aFmtFldOrigin.GetValue();
589     fStepMain = bDateAxis ? m_aMt_MainDateStep.GetValue() : aFmtFldStepMain.GetValue();
590     nStepHelp = static_cast< sal_Int32 >( aMtStepHelp.GetValue());
591     m_nTimeResolution = m_aLB_TimeResolution.GetSelectEntryPos();
592     m_nMainTimeUnit = m_aLB_MainTimeUnit.GetSelectEntryPos();
593     m_nHelpTimeUnit = m_aLB_HelpTimeUnit.GetSelectEntryPos();
594 
595     if( chart2::AxisType::REALNUMBER != m_nAxisType )
596         aCbxLogarithm.Show( false );
597 
598     //check which entries need user action
599 
600     if ( aCbxLogarithm.IsChecked() &&
601             ( ( !aCbxAutoMin.IsChecked() && fMin <= 0.0 )
602              || ( !aCbxAutoMax.IsChecked() && fMax <= 0.0 ) ) )
603     {
604         pControl = &aFmtFldMin;
605         nErrStrId = STR_BAD_LOGARITHM;
606     }
607     else if (!aCbxAutoMax.IsChecked() && !aCbxAutoMin.IsChecked() &&
608 			 fMin >= fMax)
609 	{
610         pControl = &aFmtFldMin;
611         nErrStrId = STR_MIN_GREATER_MAX;
612 	}
613     else if (!aCbxAutoStepMain.IsChecked() && fStepMain <= 0)
614 	{
615         pControl = &aFmtFldStepMain;
616 		nErrStrId = STR_STEP_GT_ZERO;
617 	}
618     // check for entries that cannot be parsed for the current number format
619 	else if ( aFmtFldMin.IsModified()
620 		&& !aCbxAutoMin.IsChecked()
621 		&& !pNumFormatter->IsNumberFormat(aFmtFldMin.GetText(), nIndex, fDummy))
622 	{
623 		pControl = &aFmtFldMin;
624 		nErrStrId = STR_INVALID_NUMBER;
625 	}
626 	else if (aFmtFldMax.IsModified() && !aCbxAutoMax.IsChecked() &&
627 			 !pNumFormatter->IsNumberFormat(aFmtFldMax.GetText(),
628 											nIndex, fDummy))
629 	{
630 		pControl = &aFmtFldMax;
631 		nErrStrId = STR_INVALID_NUMBER;
632 	}
633 	else if ( !bDateAxis && aFmtFldStepMain.IsModified() && !aCbxAutoStepMain.IsChecked() &&
634 			 !pNumFormatter->IsNumberFormat(aFmtFldStepMain.GetText(),
635 											nIndex, fDummy))
636 	{
637 		pControl = &aFmtFldStepMain;
638 		nErrStrId = STR_STEP_GT_ZERO;
639 	}
640     else if (aFmtFldOrigin.IsModified() && !aCbxAutoOrigin.IsChecked() &&
641 			 !pNumFormatter->IsNumberFormat(aFmtFldOrigin.GetText(),
642 											nIndex, fDummy))
643 	{
644 		pControl = &aFmtFldOrigin;
645 		nErrStrId = STR_INVALID_NUMBER;
646 	}
647     else if (!aCbxAutoStepMain.IsChecked() && fStepMain <= 0.0)
648 	{
649 	    pControl = &aFmtFldStepMain;
650 	    nErrStrId = STR_STEP_GT_ZERO;
651 	}
652     else if( bDateAxis )
653     {
654         if( !aCbxAutoStepMain.IsChecked() && !aCbxAutoStepHelp.IsChecked() )
655         {
656             if( m_nHelpTimeUnit > m_nMainTimeUnit )
657             {
658                 pControl = &m_aLB_MainTimeUnit;
659 		        nErrStrId = STR_INVALID_INTERVALS;
660             }
661             else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
662             {
663                 pControl = &m_aLB_MainTimeUnit;
664 		        nErrStrId = STR_INVALID_INTERVALS;
665             }
666         }
667         if( !nErrStrId && !m_aCbx_AutoTimeResolution.IsChecked() )
668         {
669             if( (!aCbxAutoStepMain.IsChecked() && m_nTimeResolution > m_nMainTimeUnit )
670                 ||
671                 (!aCbxAutoStepHelp.IsChecked() && m_nTimeResolution > m_nHelpTimeUnit )
672                 )
673             {
674                 pControl = &m_aLB_TimeResolution;
675 		        nErrStrId = STR_INVALID_TIME_UNIT;
676             }
677         }
678     }
679 
680     if( ShowWarning( nErrStrId, pControl ) )
681 		return KEEP_PAGE;
682 
683     if( pItemSet )
684 		FillItemSet( *pItemSet );
685 
686     return LEAVE_PAGE;
687 }
688 
SetNumFormatter(SvNumberFormatter * pFormatter)689 void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
690 {
691 	pNumFormatter = pFormatter;
692 	aFmtFldMax.SetFormatter( pNumFormatter );
693 	aFmtFldMin.SetFormatter( pNumFormatter );
694 	aFmtFldStepMain.SetFormatter( pNumFormatter );
695 	aFmtFldOrigin.SetFormatter( pNumFormatter );
696 
697     // #101318#, #i6278# allow more decimal places than the output format.  As
698     // the numbers shown in the edit fields are used for input, it makes more
699     // sense to display the values in the input format rather than the output
700     // format.
701     aFmtFldMax.UseInputStringForFormatting();
702     aFmtFldMin.UseInputStringForFormatting();
703     aFmtFldStepMain.UseInputStringForFormatting();
704     aFmtFldOrigin.UseInputStringForFormatting();
705 
706 	SetNumFormat();
707 }
708 
SetNumFormat()709 void ScaleTabPage::SetNumFormat()
710 {
711 	const SfxPoolItem *pPoolItem = NULL;
712 
713     if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, sal_True, &pPoolItem ) == SFX_ITEM_SET )
714 	{
715 		sal_uLong nFmt = (sal_uLong)((const SfxInt32Item*)pPoolItem)->GetValue();
716 
717 		aFmtFldMax.SetFormatKey( nFmt );
718 		aFmtFldMin.SetFormatKey( nFmt );
719 		aFmtFldOrigin.SetFormatKey( nFmt );
720 
721         if( pNumFormatter )
722         {
723 		    short eType = pNumFormatter->GetType( nFmt );
724             if( eType == NUMBERFORMAT_DATE )
725 		    {
726                 // for intervals use standard format for dates (so you can enter a number of days)
727 			    const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
728 			    if( pFormat )
729 				    nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
730                 else
731                     nFmt = pNumFormatter->GetStandardIndex();
732 		    }
733             else if( eType == NUMBERFORMAT_DATETIME )
734 		    {
735                 // for intervals use time format for date times
736 			    const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
737 			    if( pFormat )
738 				    nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_TIME, pFormat->GetLanguage() );
739                 else
740                     nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_TIME );
741 		    }
742 
743             if( chart2::AxisType::DATE == m_nAxisType && ( eType != NUMBERFORMAT_DATE && eType != NUMBERFORMAT_DATETIME) )
744             {
745                 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
746 			    if( pFormat )
747 				    nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_DATE, pFormat->GetLanguage() );
748                 else
749                     nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_DATE );
750 
751 		        aFmtFldMax.SetFormatKey( nFmt );
752 		        aFmtFldMin.SetFormatKey( nFmt );
753 		        aFmtFldOrigin.SetFormatKey( nFmt );
754             }
755         }
756 
757 		aFmtFldStepMain.SetFormatKey( nFmt );
758 	}
759 }
760 
ShowAxisOrigin(bool bShowOrigin)761 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
762 {
763     m_bShowAxisOrigin = bShowOrigin;
764     if( !AxisHelper::isAxisPositioningEnabled() )
765         m_bShowAxisOrigin = true;
766 }
767 
ShowWarning(sal_uInt16 nResIdMessage,Control * pControl)768 bool ScaleTabPage::ShowWarning( sal_uInt16 nResIdMessage, Control* pControl /* = NULL */ )
769 {
770     if( nResIdMessage == 0 )
771         return false;
772 
773     WarningBox( this, WinBits( WB_OK ), String( SchResId( nResIdMessage ))).Execute();
774     if( pControl )
775     {
776         pControl->GrabFocus();
777         Edit* pEdit = dynamic_cast<Edit*>(pControl);
778         if(pEdit)
779             pEdit->SetSelection( Selection( 0, SELECTION_MAX ));
780     }
781     return true;
782 }
783 
784 //.............................................................................
785 } //namespace chart
786 //.............................................................................
787