1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tp_Scale.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "tp_Scale.hxx"
36 #include "TabPages.hrc"
37 #include "Strings.hrc"
38 #include "chartview/ChartSfxItemIds.hxx"
39 #include "NoWarningThisInCTOR.hxx"
40 #include "AxisHelper.hxx"
42 #ifndef _SVX_SVXIDS_HRC
43 #include <svx/svxids.hrc>
45 #include <rtl/math.hxx>
46 // header for class SvxDoubleItem
47 #include <svx/chrtitem.hxx>
48 // header for class SfxBoolItem
49 #include <svtools/eitem.hxx>
50 // header for SfxInt32Item
51 #include <svtools/intitem.hxx>
53 // header for class WarningBox
54 #include <vcl/msgbox.hxx>
56 // header for class SvNumberformat
58 #ifndef _ZFORLIST_DECLARE_TABLE
59 #define _ZFORLIST_DECLARE_TABLE
61 #include <svtools/zformat.hxx>
64 #include <svtools/controldims.hrc>
66 #include <com/sun/star/chart2/AxisType.hpp>
68 using namespace ::com::sun::star
;
70 //.............................................................................
73 //.............................................................................
78 void lcl_shiftControls( Control
& rEdit
, Control
& rAuto
, long nNewXPos
)
80 Point
aPos( rEdit
.GetPosPixel() );
81 long nShift
= nNewXPos
- aPos
.X();
83 rEdit
.SetPosPixel(aPos
);
85 aPos
= rAuto
.GetPosPixel();
87 rAuto
.SetPosPixel(aPos
);
90 void lcl_placeControlsAtY( Control
& rTop
, Control
& rBottom
, long nNewYPos
)
92 Point
aPos( rTop
.GetPosPixel() );
93 long nShift
= nNewYPos
- aPos
.Y();
95 rTop
.SetPosPixel(aPos
);
97 aPos
= rBottom
.GetPosPixel();
99 rBottom
.SetPosPixel(aPos
);
104 ScaleTabPage::ScaleTabPage(Window
* pWindow
,const SfxItemSet
& rInAttrs
) :
105 SfxTabPage(pWindow
, SchResId(TP_SCALE
), rInAttrs
),
107 aFlScale(this, SchResId(FL_SCALE
)),
108 aTxtMin (this, SchResId (TXT_MIN
)),
109 aFmtFldMin(this, SchResId(EDT_MIN
)),
110 aCbxAutoMin(this, SchResId(CBX_AUTO_MIN
)),
111 aTxtMax(this, SchResId (TXT_MAX
)),
112 aFmtFldMax(this, SchResId(EDT_MAX
)),
113 aCbxAutoMax(this, SchResId(CBX_AUTO_MAX
)),
114 aTxtMain (this, SchResId (TXT_STEP_MAIN
)),
115 aFmtFldStepMain(this, SchResId(EDT_STEP_MAIN
)),
116 aCbxAutoStepMain(this, SchResId(CBX_AUTO_STEP_MAIN
)),
117 aTxtHelp (this, SchResId (TXT_STEP_HELP
)),
118 aMtStepHelp (this, SchResId (MT_STEPHELP
)),
119 aCbxAutoStepHelp(this, SchResId(CBX_AUTO_STEP_HELP
)),
121 aTxtOrigin (this, SchResId (TXT_ORIGIN
)),
122 aFmtFldOrigin(this, SchResId(EDT_ORIGIN
)),
123 aCbxAutoOrigin(this, SchResId(CBX_AUTO_ORIGIN
)),
125 aCbxLogarithm(this, SchResId(CBX_LOGARITHM
)),
126 aCbxReverse(this, SchResId(CBX_REVERSE
)),
133 nAxisType(chart2::AxisType::REALNUMBER
),
135 m_bShowAxisOrigin(false)
138 SetExchangeSupport();
140 aCbxAutoMin
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
141 aCbxAutoMax
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
142 aCbxAutoStepMain
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
143 aCbxAutoStepHelp
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
144 aCbxAutoOrigin
.SetClickHdl(LINK(this, ScaleTabPage
, EnableValueHdl
));
147 void ScaleTabPage::StateChanged( StateChangedType nType
)
149 TabPage::StateChanged( nType
);
151 if( nType
== STATE_CHANGE_INITSHOW
)
152 AdjustControlPositions();
155 void ScaleTabPage::AdjustControlPositions()
157 //optimize position of the controls
158 long nLabelWidth
= ::std::max( aTxtMin
.CalcMinimumSize().Width(), aTxtMax
.CalcMinimumSize().Width() );
159 nLabelWidth
= ::std::max( aTxtMain
.CalcMinimumSize().Width(), nLabelWidth
);
160 nLabelWidth
= ::std::max( aTxtHelp
.CalcMinimumSize().Width(), nLabelWidth
);
161 nLabelWidth
= ::std::max( aTxtOrigin
.CalcMinimumSize().Width(), nLabelWidth
);
164 long nLabelDistance
= aTxtMin
.LogicToPixel( Size(RSC_SP_CTRL_DESC_X
, 0), MapMode(MAP_APPFONT
) ).Width();
165 long nNewXPos
= aTxtMin
.GetPosPixel().X() + nLabelWidth
+ nLabelDistance
;
167 //ensure that the auto checkboxes are wide enough and have correct size for calculation
168 aCbxAutoMin
.SetSizePixel( aCbxAutoMin
.CalcMinimumSize() );
169 aCbxAutoMax
.SetSizePixel( aCbxAutoMax
.CalcMinimumSize() );
170 aCbxAutoStepMain
.SetSizePixel( aCbxAutoStepMain
.CalcMinimumSize() );
171 aCbxAutoStepHelp
.SetSizePixel( aCbxAutoStepHelp
.CalcMinimumSize() );
172 aCbxAutoOrigin
.SetSizePixel( aCbxAutoOrigin
.CalcMinimumSize() );
174 //ensure new pos is ok
175 long nWidthOfOtherControls
= aCbxAutoMin
.GetPosPixel().X() + aCbxAutoMin
.GetSizePixel().Width() - aFmtFldMin
.GetPosPixel().X();
176 long nDialogWidth
= GetSizePixel().Width();
178 long nLeftSpace
= nDialogWidth
- nNewXPos
- nWidthOfOtherControls
;
181 Size
aSize( aTxtMin
.GetSizePixel() );
182 aSize
.Width() = nLabelWidth
;
183 aTxtMin
.SetSizePixel(aSize
);
184 aTxtMax
.SetSizePixel(aSize
);
185 aTxtMain
.SetSizePixel(aSize
);
186 aTxtHelp
.SetSizePixel(aSize
);
187 aTxtOrigin
.SetSizePixel(aSize
);
189 lcl_shiftControls( aFmtFldMin
, aCbxAutoMin
, nNewXPos
);
190 lcl_shiftControls( aFmtFldMax
, aCbxAutoMax
, nNewXPos
);
191 lcl_shiftControls( aFmtFldStepMain
, aCbxAutoStepMain
, nNewXPos
);
192 lcl_shiftControls( aMtStepHelp
, aCbxAutoStepHelp
, nNewXPos
);
193 lcl_shiftControls( aFmtFldOrigin
, aCbxAutoOrigin
, nNewXPos
);
197 void ScaleTabPage::EnableControls()
199 bool bEnableForValueOrPercentAxis
= chart2::AxisType::REALNUMBER
== nAxisType
|| chart2::AxisType::PERCENT
== nAxisType
;
200 aFlScale
.Enable( bEnableForValueOrPercentAxis
);
201 aTxtMin
.Enable( bEnableForValueOrPercentAxis
);
202 aFmtFldMin
.Enable( bEnableForValueOrPercentAxis
);
203 aCbxAutoMin
.Enable( bEnableForValueOrPercentAxis
);
204 aTxtMax
.Enable( bEnableForValueOrPercentAxis
);
205 aFmtFldMax
.Enable( bEnableForValueOrPercentAxis
);
206 aCbxAutoMax
.Enable( bEnableForValueOrPercentAxis
);
207 aTxtMain
.Enable( bEnableForValueOrPercentAxis
);
208 aFmtFldStepMain
.Enable( bEnableForValueOrPercentAxis
);
209 aCbxAutoStepMain
.Enable( bEnableForValueOrPercentAxis
);
210 aTxtHelp
.Enable( bEnableForValueOrPercentAxis
);
211 aMtStepHelp
.Enable( bEnableForValueOrPercentAxis
);
212 aCbxAutoStepHelp
.Enable( bEnableForValueOrPercentAxis
);
213 aCbxLogarithm
.Enable( bEnableForValueOrPercentAxis
);
215 aTxtOrigin
.Show( m_bShowAxisOrigin
&& bEnableForValueOrPercentAxis
);
216 aFmtFldOrigin
.Show( m_bShowAxisOrigin
&& bEnableForValueOrPercentAxis
);
217 aCbxAutoOrigin
.Show( m_bShowAxisOrigin
&& bEnableForValueOrPercentAxis
);
219 long nNewYPos
= aTxtOrigin
.GetPosPixel().Y();
220 if( m_bShowAxisOrigin
)
221 nNewYPos
+= ( aTxtOrigin
.GetPosPixel().Y() - aTxtHelp
.GetPosPixel().Y() );
222 lcl_placeControlsAtY( aCbxLogarithm
, aCbxReverse
, nNewYPos
);
227 IMPL_LINK( ScaleTabPage
, EnableValueHdl
, CheckBox
*, pCbx
)
229 if (pCbx
== &aCbxAutoMin
)
231 aFmtFldMin
.Enable(!aCbxAutoMin
.IsChecked());
233 else if (pCbx
== &aCbxAutoMax
)
235 aFmtFldMax
.Enable(!aCbxAutoMax
.IsChecked());
237 else if (pCbx
== &aCbxAutoStepMain
)
239 aFmtFldStepMain
.Enable(!aCbxAutoStepMain
.IsChecked());
241 else if (pCbx
== &aCbxAutoStepHelp
)
244 aMtStepHelp
.Enable( ! aCbxAutoStepHelp
.IsChecked() );
246 else if (pCbx
== &aCbxAutoOrigin
)
248 aFmtFldOrigin
.Enable(!aCbxAutoOrigin
.IsChecked());
253 SfxTabPage
* ScaleTabPage::Create(Window
* pWindow
,const SfxItemSet
& rOutAttrs
)
255 return new ScaleTabPage(pWindow
, rOutAttrs
);
258 BOOL
ScaleTabPage::FillItemSet(SfxItemSet
& rOutAttrs
)
260 DBG_ASSERT( pNumFormatter
, "No NumberFormatter available" );
262 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN
,aCbxAutoMin
.IsChecked()));
263 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX
,aCbxAutoMax
.IsChecked()));
264 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP
,aCbxAutoStepHelp
.IsChecked()));
265 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN
,aCbxAutoOrigin
.IsChecked()));
266 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM
,aCbxLogarithm
.IsChecked()));
267 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_REVERSE
,aCbxReverse
.IsChecked()));
268 rOutAttrs
.Put(SvxDoubleItem(fMax
, SCHATTR_AXIS_MAX
));
269 rOutAttrs
.Put(SvxDoubleItem(fMin
, SCHATTR_AXIS_MIN
));
270 rOutAttrs
.Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP
, nStepHelp
));
271 rOutAttrs
.Put(SvxDoubleItem(fOrigin
, SCHATTR_AXIS_ORIGIN
));
273 rOutAttrs
.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN
,aCbxAutoStepMain
.IsChecked()));
274 rOutAttrs
.Put(SvxDoubleItem(fStepMain
,SCHATTR_AXIS_STEP_MAIN
));
279 void ScaleTabPage::Reset(const SfxItemSet
& rInAttrs
)
281 DBG_ASSERT( pNumFormatter
, "No NumberFormatter available" );
285 const SfxPoolItem
*pPoolItem
= NULL
;
286 nAxisType
=chart2::AxisType::REALNUMBER
;
287 if (rInAttrs
.GetItemState(SCHATTR_AXISTYPE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
289 nAxisType
= (int) ((const SfxInt32Item
*)pPoolItem
)->GetValue();
293 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_MIN
,TRUE
,&pPoolItem
) == SFX_ITEM_SET
)
294 aCbxAutoMin
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
296 if (rInAttrs
.GetItemState(SCHATTR_AXIS_MIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
298 fMin
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
299 aFmtFldMin
.SetValue( fMin
);
302 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_MAX
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
303 aCbxAutoMax
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
305 if (rInAttrs
.GetItemState(SCHATTR_AXIS_MAX
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
307 fMax
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
308 aFmtFldMax
.SetValue( fMax
);
311 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
312 aCbxAutoStepMain
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
314 if (rInAttrs
.GetItemState(SCHATTR_AXIS_STEP_MAIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
316 fStepMain
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
317 aFmtFldStepMain
.SetValue( fStepMain
);
319 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
320 aCbxAutoStepHelp
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
321 if (rInAttrs
.GetItemState(SCHATTR_AXIS_LOGARITHM
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
322 aCbxLogarithm
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
323 if (rInAttrs
.GetItemState(SCHATTR_AXIS_REVERSE
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
324 aCbxReverse
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
325 if (rInAttrs
.GetItemState(SCHATTR_AXIS_STEP_HELP
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
327 nStepHelp
= ((const SfxInt32Item
*)pPoolItem
)->GetValue();
328 aMtStepHelp
.SetValue( nStepHelp
);
330 if (rInAttrs
.GetItemState(SCHATTR_AXIS_AUTO_ORIGIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
331 aCbxAutoOrigin
.Check(((const SfxBoolItem
*)pPoolItem
)->GetValue());
332 if (rInAttrs
.GetItemState(SCHATTR_AXIS_ORIGIN
,TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
334 fOrigin
= ((const SvxDoubleItem
*)pPoolItem
)->GetValue();
335 aFmtFldOrigin
.SetValue( fOrigin
);
338 EnableValueHdl(&aCbxAutoMin
);
339 EnableValueHdl(&aCbxAutoMax
);
340 EnableValueHdl(&aCbxAutoStepMain
);
341 EnableValueHdl(&aCbxAutoStepHelp
);
342 EnableValueHdl(&aCbxAutoOrigin
);
345 int ScaleTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
349 DBG_ERROR( "No NumberFormatter available" );
353 sal_uInt32 nIndex
= pNumFormatter
->GetStandardIndex(LANGUAGE_SYSTEM
);
354 const SfxPoolItem
*pPoolItem
= NULL
;
355 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
356 nIndex
= static_cast< sal_uInt32
>( static_cast< const SfxInt32Item
* >(pPoolItem
)->GetValue());
359 OSL_ENSURE( false, "Using Standard Language" );
363 USHORT nErrStrId
= 0;
366 fMax
= aFmtFldMax
.GetValue();
367 fMin
= aFmtFldMin
.GetValue();
368 fOrigin
= aFmtFldOrigin
.GetValue();
369 fStepMain
= aFmtFldStepMain
.GetValue();
370 nStepHelp
= static_cast< sal_Int32
>( aMtStepHelp
.GetValue());
372 //do some reasonable automatic correction of user input if necessary
373 if (!aCbxAutoMax
.IsChecked() && !aCbxAutoMin
.IsChecked() &&
377 nErrStrId
= STR_MIN_GREATER_MAX
;
379 // check for entries in invalid ranges
380 if ( aCbxLogarithm
.IsChecked() &&
381 ( ( !aCbxAutoMin
.IsChecked() && fMin
<= 0.0 )
382 || ( !aCbxAutoMax
.IsChecked() && fMax
<= 0.0 ) ) )
385 nErrStrId
= STR_BAD_LOGARITHM
;
387 if (!aCbxAutoStepMain
.IsChecked() && fStepMain
<= 0)
389 pEdit
= &aFmtFldStepMain
;
390 nErrStrId
= STR_STEP_GT_ZERO
;
393 //check wich entries need user action
395 // check for entries that cannot be parsed for the current number format
396 if ( aFmtFldMin
.IsModified()
397 && !aCbxAutoMin
.IsChecked()
398 && !pNumFormatter
->IsNumberFormat(aFmtFldMin
.GetText(), nIndex
, fDummy
))
401 nErrStrId
= STR_INVALID_NUMBER
;
403 else if (aFmtFldMax
.IsModified() && !aCbxAutoMax
.IsChecked() &&
404 !pNumFormatter
->IsNumberFormat(aFmtFldMax
.GetText(),
408 nErrStrId
= STR_INVALID_NUMBER
;
410 else if (aFmtFldStepMain
.IsModified() && !aCbxAutoStepMain
.IsChecked() &&
411 !pNumFormatter
->IsNumberFormat(aFmtFldStepMain
.GetText(),
414 pEdit
= &aFmtFldStepMain
;
415 nErrStrId
= STR_STEP_GT_ZERO
;
417 else if (aFmtFldOrigin
.IsModified() && !aCbxAutoOrigin
.IsChecked() &&
418 !pNumFormatter
->IsNumberFormat(aFmtFldOrigin
.GetText(),
421 pEdit
= &aFmtFldOrigin
;
422 nErrStrId
= STR_INVALID_NUMBER
;
424 else if (!aCbxAutoStepMain
.IsChecked() && fStepMain
<= 0.0)
426 pEdit
= &aFmtFldStepMain
;
427 nErrStrId
= STR_STEP_GT_ZERO
;
430 if( ShowWarning( nErrStrId
, pEdit
) )
434 FillItemSet( *pItemSet
);
439 void ScaleTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
441 pNumFormatter
= pFormatter
;
442 aFmtFldMax
.SetFormatter( pNumFormatter
);
443 aFmtFldMin
.SetFormatter( pNumFormatter
);
444 aFmtFldStepMain
.SetFormatter( pNumFormatter
);
445 aFmtFldOrigin
.SetFormatter( pNumFormatter
);
447 // #101318#, #i6278# allow more decimal places than the output format. As
448 // the numbers shown in the edit fields are used for input, it makes more
449 // sense to display the values in the input format rather than the output
451 aFmtFldMax
.UseInputStringForFormatting();
452 aFmtFldMin
.UseInputStringForFormatting();
453 aFmtFldStepMain
.UseInputStringForFormatting();
454 aFmtFldOrigin
.UseInputStringForFormatting();
459 void ScaleTabPage::SetNumFormat()
461 const SfxPoolItem
*pPoolItem
= NULL
;
463 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
, TRUE
, &pPoolItem
) == SFX_ITEM_SET
)
465 ULONG nFmt
= (ULONG
)((const SfxInt32Item
*)pPoolItem
)->GetValue();
467 aFmtFldMax
.SetFormatKey( nFmt
);
468 aFmtFldMin
.SetFormatKey( nFmt
);
469 aFmtFldOrigin
.SetFormatKey( nFmt
);
473 short eType
= pNumFormatter
->GetType( nFmt
);
474 if( eType
== NUMBERFORMAT_DATE
)
476 // for intervals use standard format for dates (so you can enter a number of days)
477 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
479 nFmt
= pNumFormatter
->GetStandardIndex( pFormat
->GetLanguage());
481 nFmt
= pNumFormatter
->GetStandardIndex();
483 else if( eType
== NUMBERFORMAT_DATETIME
)
485 // for intervals use time format for date times
486 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
488 nFmt
= pNumFormatter
->GetStandardFormat( NUMBERFORMAT_TIME
, pFormat
->GetLanguage() );
490 nFmt
= pNumFormatter
->GetStandardFormat( NUMBERFORMAT_TIME
);
494 aFmtFldStepMain
.SetFormatKey( nFmt
);
498 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin
)
500 m_bShowAxisOrigin
= bShowOrigin
;
501 if( !AxisHelper::isAxisPositioningEnabled() )
502 m_bShowAxisOrigin
= true;
505 bool ScaleTabPage::ShowWarning( USHORT nResIdMessage
, Edit
* pControl
/* = NULL */ )
507 if( nResIdMessage
== 0 )
510 WarningBox( this, WinBits( WB_OK
), String( SchResId( nResIdMessage
))).Execute();
513 pControl
->GrabFocus();
514 pControl
->SetSelection( Selection( 0, SELECTION_MAX
));
519 //.............................................................................
521 //.............................................................................