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_Scale.hxx"
33 #include "TabPages.hrc"
34 #include "Strings.hrc"
35 #include "chartview/ChartSfxItemIds.hxx"
36 #include "NoWarningThisInCTOR.hxx"
37 #include "AxisHelper.hxx"
39 #ifndef _SVX_SVXIDS_HRC
40 #include <svx/svxids.hrc>
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>
50 // header for class WarningBox
51 #include <vcl/msgbox.hxx>
53 // header for class SvNumberformat
55 #ifndef _ZFORLIST_DECLARE_TABLE
56 #define _ZFORLIST_DECLARE_TABLE
58 #include <svl/zformat.hxx>
61 #include <svtools/controldims.hrc>
63 #include <com/sun/star/chart2/AxisType.hpp>
65 using namespace ::com::sun::star
;
67 //.............................................................................
70 //.............................................................................
75 void lcl_shiftControls( Control
& rEdit
, Control
& rAuto
, long nNewXPos
)
77 Point
aPos( rEdit
.GetPosPixel() );
78 long nShift
= nNewXPos
- aPos
.X();
80 rEdit
.SetPosPixel(aPos
);
82 aPos
= rAuto
.GetPosPixel();
84 rAuto
.SetPosPixel(aPos
);
87 void lcl_placeControlsAtY( Control
& rTop
, Control
& rBottom
, long nNewYPos
)
89 Point
aPos( rTop
.GetPosPixel() );
90 long nShift
= nNewYPos
- aPos
.Y();
92 rTop
.SetPosPixel(aPos
);
94 aPos
= rBottom
.GetPosPixel();
96 rBottom
.SetPosPixel(aPos
);
101 ScaleTabPage::ScaleTabPage(Window
* pWindow
,const SfxItemSet
& rInAttrs
) :
102 SfxTabPage(pWindow
, SchResId(TP_SCALE
), rInAttrs
),
104 aFlScale(this, SchResId(FL_SCALE
)),
105 aTxtMin (this, SchResId (TXT_MIN
)),
106 aFmtFldMin(this, SchResId(EDT_MIN
)),
107 aCbxAutoMin(this, SchResId(CBX_AUTO_MIN
)),
108 aTxtMax(this, SchResId (TXT_MAX
)),
109 aFmtFldMax(this, SchResId(EDT_MAX
)),
110 aCbxAutoMax(this, SchResId(CBX_AUTO_MAX
)),
111 aTxtMain (this, SchResId (TXT_STEP_MAIN
)),
112 aFmtFldStepMain(this, SchResId(EDT_STEP_MAIN
)),
113 aCbxAutoStepMain(this, SchResId(CBX_AUTO_STEP_MAIN
)),
114 aTxtHelp (this, SchResId (TXT_STEP_HELP
)),
115 aMtStepHelp (this, SchResId (MT_STEPHELP
)),
116 aCbxAutoStepHelp(this, SchResId(CBX_AUTO_STEP_HELP
)),
118 aTxtOrigin (this, SchResId (TXT_ORIGIN
)),
119 aFmtFldOrigin(this, SchResId(EDT_ORIGIN
)),
120 aCbxAutoOrigin(this, SchResId(CBX_AUTO_ORIGIN
)),
122 aCbxLogarithm(this, SchResId(CBX_LOGARITHM
)),
123 aCbxReverse(this, SchResId(CBX_REVERSE
)),
130 nAxisType(chart2::AxisType::REALNUMBER
),
132 m_bShowAxisOrigin(false)
135 SetExchangeSupport();
137 aCbxAutoMin
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
138 aCbxAutoMax
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
139 aCbxAutoStepMain
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
140 aCbxAutoStepHelp
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
141 aCbxAutoOrigin
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
144 void ScaleTabPage::StateChanged( StateChangedType nType
)
146 TabPage::StateChanged( nType
);
148 if( nType
== STATE_CHANGE_INITSHOW
)
149 AdjustControlPositions();
152 void ScaleTabPage::AdjustControlPositions()
154 //optimize position of the controls
155 long nLabelWidth
= ::std::max( aTxtMin
.CalcMinimumSize().Width(), aTxtMax
.CalcMinimumSize().Width() );
156 nLabelWidth
= ::std::max( aTxtMain
.CalcMinimumSize().Width(), nLabelWidth
);
157 nLabelWidth
= ::std::max( aTxtHelp
.CalcMinimumSize().Width(), nLabelWidth
);
158 nLabelWidth
= ::std::max( aTxtOrigin
.CalcMinimumSize().Width(), nLabelWidth
);
161 long nLabelDistance
= aTxtMin
.LogicToPixel( Size(RSC_SP_CTRL_DESC_X
, 0), MapMode(MAP_APPFONT
) ).Width();
162 long nNewXPos
= aTxtMin
.GetPosPixel().X() + nLabelWidth
+ nLabelDistance
;
164 //ensure that the auto checkboxes are wide enough and have correct size for calculation
165 aCbxAutoMin
.SetSizePixel( aCbxAutoMin
.CalcMinimumSize() );
166 aCbxAutoMax
.SetSizePixel( aCbxAutoMax
.CalcMinimumSize() );
167 aCbxAutoStepMain
.SetSizePixel( aCbxAutoStepMain
.CalcMinimumSize() );
168 aCbxAutoStepHelp
.SetSizePixel( aCbxAutoStepHelp
.CalcMinimumSize() );
169 aCbxAutoOrigin
.SetSizePixel( aCbxAutoOrigin
.CalcMinimumSize() );
171 //ensure new pos is ok
172 long nWidthOfOtherControls
= aCbxAutoMin
.GetPosPixel().X() + aCbxAutoMin
.GetSizePixel().Width() - aFmtFldMin
.GetPosPixel().X();
173 long nDialogWidth
= GetSizePixel().Width();
175 long nLeftSpace
= nDialogWidth
- nNewXPos
- nWidthOfOtherControls
;
178 Size
aSize( aTxtMin
.GetSizePixel() );
179 aSize
.Width() = nLabelWidth
;
180 aTxtMin
.SetSizePixel(aSize
);
181 aTxtMax
.SetSizePixel(aSize
);
182 aTxtMain
.SetSizePixel(aSize
);
183 aTxtHelp
.SetSizePixel(aSize
);
184 aTxtOrigin
.SetSizePixel(aSize
);
186 lcl_shiftControls( aFmtFldMin
, aCbxAutoMin
, nNewXPos
);
187 lcl_shiftControls( aFmtFldMax
, aCbxAutoMax
, nNewXPos
);
188 lcl_shiftControls( aFmtFldStepMain
, aCbxAutoStepMain
, nNewXPos
);
189 lcl_shiftControls( aMtStepHelp
, aCbxAutoStepHelp
, nNewXPos
);
190 lcl_shiftControls( aFmtFldOrigin
, aCbxAutoOrigin
, nNewXPos
);
194 void ScaleTabPage::EnableControls()
196 bool bEnableForValueOrPercentAxis
= chart2::AxisType::REALNUMBER
== nAxisType
|| chart2::AxisType::PERCENT
== nAxisType
;
197 aFlScale
.Enable( bEnableForValueOrPercentAxis
);
198 aTxtMin
.Enable( bEnableForValueOrPercentAxis
);
199 aFmtFldMin
.Enable( bEnableForValueOrPercentAxis
);
200 aCbxAutoMin
.Enable( bEnableForValueOrPercentAxis
);
201 aTxtMax
.Enable( bEnableForValueOrPercentAxis
);
202 aFmtFldMax
.Enable( bEnableForValueOrPercentAxis
);
203 aCbxAutoMax
.Enable( bEnableForValueOrPercentAxis
);
204 aTxtMain
.Enable( bEnableForValueOrPercentAxis
);
205 aFmtFldStepMain
.Enable( bEnableForValueOrPercentAxis
);
206 aCbxAutoStepMain
.Enable( bEnableForValueOrPercentAxis
);
207 aTxtHelp
.Enable( bEnableForValueOrPercentAxis
);
208 aMtStepHelp
.Enable( bEnableForValueOrPercentAxis
);
209 aCbxAutoStepHelp
.Enable( bEnableForValueOrPercentAxis
);
210 aCbxLogarithm
.Enable( bEnableForValueOrPercentAxis
);
212 aTxtOrigin
.Show( m_bShowAxisOrigin
&& bEnableForValueOrPercentAxis
);
213 aFmtFldOrigin
.Show( m_bShowAxisOrigin
&& bEnableForValueOrPercentAxis
);
214 aCbxAutoOrigin
.Show( m_bShowAxisOrigin
&& bEnableForValueOrPercentAxis
);
216 long nNewYPos
= aTxtOrigin
.GetPosPixel().Y();
217 if( m_bShowAxisOrigin
)
218 nNewYPos
+= ( aTxtOrigin
.GetPosPixel().Y() - aTxtHelp
.GetPosPixel().Y() );
219 lcl_placeControlsAtY( aCbxLogarithm
, aCbxReverse
, nNewYPos
);
224 IMPL_LINK( ScaleTabPage
, EnableValueHdl
, CheckBox
*, pCbx
)
226 if (pCbx
== &aCbxAutoMin
)
228 aFmtFldMin
.Enable(!aCbxAutoMin
.IsChecked());
230 else if (pCbx
== &aCbxAutoMax
)
232 aFmtFldMax
.Enable(!aCbxAutoMax
.IsChecked());
234 else if (pCbx
== &aCbxAutoStepMain
)
236 aFmtFldStepMain
.Enable(!aCbxAutoStepMain
.IsChecked());
238 else if (pCbx
== &aCbxAutoStepHelp
)
241 aMtStepHelp
.Enable( ! aCbxAutoStepHelp
.IsChecked() );
243 else if (pCbx
== &aCbxAutoOrigin
)
245 aFmtFldOrigin
.Enable(!aCbxAutoOrigin
.IsChecked());
250 SfxTabPage
* ScaleTabPage::Create(Window
* pWindow
,const SfxItemSet
& rOutAttrs
)
252 return new ScaleTabPage(pWindow
, rOutAttrs
);
255 BOOL
ScaleTabPage::FillItemSet(SfxItemSet
& rOutAttrs
)
257 DBG_ASSERT( pNumFormatter
, "No NumberFormatter available" );
259 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN
,aCbxAutoMin
.IsChecked()));
260 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX
,aCbxAutoMax
.IsChecked()));
261 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP
,aCbxAutoStepHelp
.IsChecked()));
262 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN
,aCbxAutoOrigin
.IsChecked()));
263 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM
,aCbxLogarithm
.IsChecked()));
264 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_REVERSE
,aCbxReverse
.IsChecked()));
265 rOutAttrs
.Put(SvxDoubleItem(fMax
, SCHATTR_AXIS_MAX
));
266 rOutAttrs
.Put(SvxDoubleItem(fMin
, SCHATTR_AXIS_MIN
));
267 rOutAttrs
.Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP
, nStepHelp
));
268 rOutAttrs
.Put(SvxDoubleItem(fOrigin
, SCHATTR_AXIS_ORIGIN
));
270 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN
,aCbxAutoStepMain
.IsChecked()));
271 rOutAttrs
.Put(SvxDoubleItem(fStepMain
,SCHATTR_AXIS_STEP_MAIN
));
276 void ScaleTabPage::Reset(const SfxItemSet
& rInAttrs
)
278 DBG_ASSERT( pNumFormatter
, "No NumberFormatter available" );
282 const SfxPoolItem
*pPoolItem
= NULL
;
283 nAxisType
=chart2::AxisType::REALNUMBER
;
284 if (rInAttrs
.GetItemState(SCHATTR_AXISTYPE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
286 nAxisType
= (int) ((const SfxInt32Item
*)pPoolItem
)->GetValue();
290 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_MIN
,TRUE
,&pPoolItem
) == SFX_ITEM_SET
)
291 aCbxAutoMin
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
293 if (rInAttrs
.GetItemState(SCHATTR_AXIS_MIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
295 fMin
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
296 aFmtFldMin
.SetValue( fMin
);
299 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_MAX
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
300 aCbxAutoMax
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
302 if (rInAttrs
.GetItemState(SCHATTR_AXIS_MAX
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
304 fMax
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
305 aFmtFldMax
.SetValue( fMax
);
308 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
309 aCbxAutoStepMain
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
311 if (rInAttrs
.GetItemState(SCHATTR_AXIS_STEP_MAIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
313 fStepMain
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
314 aFmtFldStepMain
.SetValue( fStepMain
);
316 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
317 aCbxAutoStepHelp
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
318 if (rInAttrs
.GetItemState(SCHATTR_AXIS_LOGARITHM
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
319 aCbxLogarithm
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
320 if (rInAttrs
.GetItemState(SCHATTR_AXIS_REVERSE
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
321 aCbxReverse
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
322 if (rInAttrs
.GetItemState(SCHATTR_AXIS_STEP_HELP
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
324 nStepHelp
= ((const SfxInt32Item
*)pPoolItem
)->GetValue();
325 aMtStepHelp
.SetValue( nStepHelp
);
327 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_ORIGIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
328 aCbxAutoOrigin
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
329 if (rInAttrs
.GetItemState(SCHATTR_AXIS_ORIGIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
331 fOrigin
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
332 aFmtFldOrigin
.SetValue( fOrigin
);
335 EnableValueHdl(&aCbxAutoMin
);
336 EnableValueHdl(&aCbxAutoMax
);
337 EnableValueHdl(&aCbxAutoStepMain
);
338 EnableValueHdl(&aCbxAutoStepHelp
);
339 EnableValueHdl(&aCbxAutoOrigin
);
342 int ScaleTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
346 DBG_ERROR( "No NumberFormatter available" );
350 sal_uInt32 nIndex
= pNumFormatter
->GetStandardIndex(LANGUAGE_SYSTEM
);
351 const SfxPoolItem
*pPoolItem
= NULL
;
352 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
353 nIndex
= static_cast< sal_uInt32
>( static_cast< const SfxInt32Item
* >(pPoolItem
)->GetValue());
356 OSL_ENSURE( false, "Using Standard Language" );
360 USHORT nErrStrId
= 0;
363 fMax
= aFmtFldMax
.GetValue();
364 fMin
= aFmtFldMin
.GetValue();
365 fOrigin
= aFmtFldOrigin
.GetValue();
366 fStepMain
= aFmtFldStepMain
.GetValue();
367 nStepHelp
= static_cast< sal_Int32
>( aMtStepHelp
.GetValue());
369 //do some reasonable automatic correction of user input if necessary
370 if (!aCbxAutoMax
.IsChecked() && !aCbxAutoMin
.IsChecked() &&
374 nErrStrId
= STR_MIN_GREATER_MAX
;
376 // check for entries in invalid ranges
377 if ( aCbxLogarithm
.IsChecked() &&
378 ( ( !aCbxAutoMin
.IsChecked() && fMin
<= 0.0 )
379 || ( !aCbxAutoMax
.IsChecked() && fMax
<= 0.0 ) ) )
382 nErrStrId
= STR_BAD_LOGARITHM
;
384 if (!aCbxAutoStepMain
.IsChecked() && fStepMain
<= 0)
386 pEdit
= &aFmtFldStepMain
;
387 nErrStrId
= STR_STEP_GT_ZERO
;
390 //check wich entries need user action
392 // check for entries that cannot be parsed for the current number format
393 if ( aFmtFldMin
.IsModified()
394 && !aCbxAutoMin
.IsChecked()
395 && !pNumFormatter
->IsNumberFormat(aFmtFldMin
.GetText(), nIndex
, fDummy
))
398 nErrStrId
= STR_INVALID_NUMBER
;
400 else if (aFmtFldMax
.IsModified() && !aCbxAutoMax
.IsChecked() &&
401 !pNumFormatter
->IsNumberFormat(aFmtFldMax
.GetText(),
405 nErrStrId
= STR_INVALID_NUMBER
;
407 else if (aFmtFldStepMain
.IsModified() && !aCbxAutoStepMain
.IsChecked() &&
408 !pNumFormatter
->IsNumberFormat(aFmtFldStepMain
.GetText(),
411 pEdit
= &aFmtFldStepMain
;
412 nErrStrId
= STR_STEP_GT_ZERO
;
414 else if (aFmtFldOrigin
.IsModified() && !aCbxAutoOrigin
.IsChecked() &&
415 !pNumFormatter
->IsNumberFormat(aFmtFldOrigin
.GetText(),
418 pEdit
= &aFmtFldOrigin
;
419 nErrStrId
= STR_INVALID_NUMBER
;
421 else if (!aCbxAutoStepMain
.IsChecked() && fStepMain
<= 0.0)
423 pEdit
= &aFmtFldStepMain
;
424 nErrStrId
= STR_STEP_GT_ZERO
;
427 if( ShowWarning( nErrStrId
, pEdit
) )
431 FillItemSet( *pItemSet
);
436 void ScaleTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
438 pNumFormatter
= pFormatter
;
439 aFmtFldMax
.SetFormatter( pNumFormatter
);
440 aFmtFldMin
.SetFormatter( pNumFormatter
);
441 aFmtFldStepMain
.SetFormatter( pNumFormatter
);
442 aFmtFldOrigin
.SetFormatter( pNumFormatter
);
444 // #101318#, #i6278# allow more decimal places than the output format. As
445 // the numbers shown in the edit fields are used for input, it makes more
446 // sense to display the values in the input format rather than the output
448 aFmtFldMax
.UseInputStringForFormatting();
449 aFmtFldMin
.UseInputStringForFormatting();
450 aFmtFldStepMain
.UseInputStringForFormatting();
451 aFmtFldOrigin
.UseInputStringForFormatting();
456 void ScaleTabPage::SetNumFormat()
458 const SfxPoolItem
*pPoolItem
= NULL
;
460 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
462 ULONG nFmt
= (ULONG
)((const SfxInt32Item
*)pPoolItem
)->GetValue();
464 aFmtFldMax
.SetFormatKey( nFmt
);
465 aFmtFldMin
.SetFormatKey( nFmt
);
466 aFmtFldOrigin
.SetFormatKey( nFmt
);
470 short eType
= pNumFormatter
->GetType( nFmt
);
471 if( eType
== NUMBERFORMAT_DATE
)
473 // for intervals use standard format for dates (so you can enter a number of days)
474 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
476 nFmt
= pNumFormatter
->GetStandardIndex( pFormat
->GetLanguage());
478 nFmt
= pNumFormatter
->GetStandardIndex();
480 else if( eType
== NUMBERFORMAT_DATETIME
)
482 // for intervals use time format for date times
483 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
485 nFmt
= pNumFormatter
->GetStandardFormat( NUMBERFORMAT_TIME
, pFormat
->GetLanguage() );
487 nFmt
= pNumFormatter
->GetStandardFormat( NUMBERFORMAT_TIME
);
491 aFmtFldStepMain
.SetFormatKey( nFmt
);
495 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin
)
497 m_bShowAxisOrigin
= bShowOrigin
;
498 if( !AxisHelper::isAxisPositioningEnabled() )
499 m_bShowAxisOrigin
= true;
502 bool ScaleTabPage::ShowWarning( USHORT nResIdMessage
, Edit
* pControl
/* = NULL */ )
504 if( nResIdMessage
== 0 )
507 WarningBox( this, WinBits( WB_OK
), String( SchResId( nResIdMessage
))).Execute();
510 pControl
->GrabFocus();
511 pControl
->SetSelection( Selection( 0, SELECTION_MAX
));
516 //.............................................................................
518 //.............................................................................