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: mtrindlg.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_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include "mtrindlg.hxx"
41 #include "scresid.hxx"
42 #include "miscdlgs.hrc"
45 //==================================================================
47 ScMetricInputDlg::ScMetricInputDlg( Window
* pParent
,
58 : ModalDialog ( pParent
, ScResId( nResId
) ),
60 aFtEditTitle ( this, ScResId( FT_LABEL
) ),
61 aEdValue ( this, ScResId( ED_VALUE
) ),
62 aBtnDefVal ( this, ScResId( BTN_DEFVAL
) ),
63 aBtnOk ( this, ScResId( BTN_OK
) ),
64 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
65 aBtnHelp ( this, ScResId( BTN_HELP
) )
69 //aFtEditTitle.SetText( rEditTitle );
71 aBtnDefVal
.SetClickHdl ( LINK( this, ScMetricInputDlg
, SetDefValHdl
) );
72 aEdValue
. SetModifyHdl( LINK( this, ScMetricInputDlg
, ModifyHdl
) );
74 aEdValue
.SetUnit ( eFUnit
);
75 aEdValue
.SetDecimalDigits ( nDecimals
);
76 aEdValue
.SetMax ( aEdValue
.Normalize( nMaximum
), FUNIT_TWIP
);
77 aEdValue
.SetMin ( aEdValue
.Normalize( nMinimum
), FUNIT_TWIP
);
78 aEdValue
.SetLast ( aEdValue
.Normalize( nLast
), FUNIT_TWIP
);
79 aEdValue
.SetFirst ( aEdValue
.Normalize( nFirst
), FUNIT_TWIP
);
80 aEdValue
.SetSpinSize ( aEdValue
.Normalize( 1 ) / 10 );
81 aEdValue
.SetValue ( aEdValue
.Normalize( nDefault
), FUNIT_TWIP
);
82 nDefaultValue
= sal::static_int_cast
<long>( aEdValue
.GetValue() );
83 aEdValue
.SetValue ( aEdValue
.Normalize( nCurrent
), FUNIT_TWIP
);
84 nCurrentValue
= sal::static_int_cast
<long>( aEdValue
.GetValue() );
85 aBtnDefVal
.Check( nCurrentValue
== nDefaultValue
);
90 //------------------------------------------------------------------------
92 __EXPORT
ScMetricInputDlg::~ScMetricInputDlg()
96 //------------------------------------------------------------------------
98 long ScMetricInputDlg::GetInputValue( FieldUnit eUnit
) const
101 mit Nachkommastellen:
103 double nVal = aEdValue.GetValue( eUnit );
104 USHORT nDecs = aEdValue.GetDecimalDigits();
105 double nFactor = 0.0;
107 // static long ImpPower10( USHORT nDecs )
111 for ( USHORT i=0; i < nDecs; i++ )
115 return nVal / nFactor;
117 // erstmal Nachkommastellen abschneiden - nich so doll...
119 return sal::static_int_cast
<long>( aEdValue
.Denormalize( aEdValue
.GetValue( eUnit
) ) );
122 //------------------------------------------------------------------------
124 void ScMetricInputDlg::CalcPositions()
126 MapMode oldMode
= GetMapMode();
127 SetMapMode( MAP_APPFONT
);
129 Size aDlgSize
= GetOutputSizePixel();
130 Size aFtSize
= aFtEditTitle
.GetSizePixel();
133 aFtSize
.Width() = aFtEditTitle
.GetTextWidth(aFtEditTitle
.GetText());
134 // #95990# add mnemonic char width to fixed text width
135 aFtSize
.Width() += aFtEditTitle
.GetTextWidth(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("(W)")));
136 aFtEditTitle
.SetSizePixel( aFtSize
);
138 aNewPos
.Y() = aEdValue
.GetPosPixel().Y();
139 aNewPos
.X() = aFtEditTitle
.GetPosPixel().X();
140 aNewPos
.X() += aFtEditTitle
.GetSizePixel().Width();
141 aNewPos
.X() += LogicToPixel( Point(3,0) ).X();
142 aEdValue
.SetPosPixel( aNewPos
);
144 aNewPos
.Y() = aBtnDefVal
.GetPosPixel().Y();
145 aBtnDefVal
.SetPosPixel( aNewPos
);
147 aNewPos
.Y() = aBtnOk
.GetPosPixel().Y();
148 aNewPos
.X() += aEdValue
.GetSizePixel().Width();
149 aNewPos
.X() += LogicToPixel( Point(6,0) ).X();
150 aBtnOk
.SetPosPixel( aNewPos
);
151 aNewPos
.Y() = aBtnCancel
.GetPosPixel().Y();
152 aBtnCancel
.SetPosPixel( aNewPos
);
153 aNewPos
.Y() = aBtnHelp
.GetPosPixel().Y();
154 aBtnHelp
.SetPosPixel( aNewPos
);
156 aNewPos
.X() += aBtnOk
.GetSizePixel().Width();
157 aNewPos
.X() += LogicToPixel( Point(6,0) ).X();
158 aDlgSize
.Width() = aNewPos
.X();
159 SetOutputSizePixel( aDlgSize
);
161 SetMapMode( oldMode
);
164 //------------------------------------------------------------------------
167 IMPL_LINK( ScMetricInputDlg
, SetDefValHdl
, CheckBox
*, EMPTYARG
)
169 if ( aBtnDefVal
.IsChecked() )
171 nCurrentValue
= sal::static_int_cast
<long>( aEdValue
.GetValue() );
172 aEdValue
.SetValue( nDefaultValue
);
175 aEdValue
.SetValue( nCurrentValue
);
179 //------------------------------------------------------------------------
181 IMPL_LINK_INLINE_START( ScMetricInputDlg
, ModifyHdl
, MetricField
*, EMPTYARG
)
183 aBtnDefVal
.Check( nDefaultValue
== aEdValue
.GetValue() );
186 IMPL_LINK_INLINE_END( ScMetricInputDlg
, ModifyHdl
, MetricField
*, EMPTYARG
)