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