1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scui.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir //------------------------------------------------------------------
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "mtrindlg.hxx"
33cdf0e10cSrcweir #include "scresid.hxx"
34cdf0e10cSrcweir #include "miscdlgs.hrc"
35cdf0e10cSrcweir
36cdf0e10cSrcweir
37cdf0e10cSrcweir //==================================================================
38cdf0e10cSrcweir
ScMetricInputDlg(Window * pParent,sal_uInt16 nResId,long nCurrent,long nDefault,FieldUnit eFUnit,sal_uInt16 nDecimals,long nMaximum,long nMinimum,long nFirst,long nLast)39cdf0e10cSrcweir ScMetricInputDlg::ScMetricInputDlg( Window* pParent,
40cdf0e10cSrcweir sal_uInt16 nResId,
41cdf0e10cSrcweir long nCurrent,
42cdf0e10cSrcweir long nDefault,
43cdf0e10cSrcweir FieldUnit eFUnit,
44cdf0e10cSrcweir sal_uInt16 nDecimals,
45cdf0e10cSrcweir long nMaximum,
46cdf0e10cSrcweir long nMinimum,
47cdf0e10cSrcweir long nFirst,
48cdf0e10cSrcweir long nLast )
49cdf0e10cSrcweir
50cdf0e10cSrcweir : ModalDialog ( pParent, ScResId( nResId ) ),
51cdf0e10cSrcweir //
52cdf0e10cSrcweir aFtEditTitle ( this, ScResId( FT_LABEL ) ),
53cdf0e10cSrcweir aEdValue ( this, ScResId( ED_VALUE ) ),
54cdf0e10cSrcweir aBtnDefVal ( this, ScResId( BTN_DEFVAL ) ),
55cdf0e10cSrcweir aBtnOk ( this, ScResId( BTN_OK ) ),
56cdf0e10cSrcweir aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
57cdf0e10cSrcweir aBtnHelp ( this, ScResId( BTN_HELP ) )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir //SetText( rTitle );
60cdf0e10cSrcweir //
61cdf0e10cSrcweir //aFtEditTitle.SetText( rEditTitle );
62cdf0e10cSrcweir CalcPositions();
63cdf0e10cSrcweir aBtnDefVal.SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) );
64cdf0e10cSrcweir aEdValue. SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl ) );
65cdf0e10cSrcweir
66cdf0e10cSrcweir aEdValue.SetUnit ( eFUnit );
67cdf0e10cSrcweir aEdValue.SetDecimalDigits ( nDecimals );
68cdf0e10cSrcweir aEdValue.SetMax ( aEdValue.Normalize( nMaximum ), FUNIT_TWIP );
69cdf0e10cSrcweir aEdValue.SetMin ( aEdValue.Normalize( nMinimum ), FUNIT_TWIP );
70cdf0e10cSrcweir aEdValue.SetLast ( aEdValue.Normalize( nLast ), FUNIT_TWIP );
71cdf0e10cSrcweir aEdValue.SetFirst ( aEdValue.Normalize( nFirst ), FUNIT_TWIP );
72cdf0e10cSrcweir aEdValue.SetSpinSize ( aEdValue.Normalize( 1 ) / 10 );
73cdf0e10cSrcweir aEdValue.SetValue ( aEdValue.Normalize( nDefault ), FUNIT_TWIP );
74cdf0e10cSrcweir nDefaultValue = sal::static_int_cast<long>( aEdValue.GetValue() );
75cdf0e10cSrcweir aEdValue.SetValue ( aEdValue.Normalize( nCurrent ), FUNIT_TWIP );
76cdf0e10cSrcweir nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
77cdf0e10cSrcweir aBtnDefVal.Check( nCurrentValue == nDefaultValue );
78cdf0e10cSrcweir
79cdf0e10cSrcweir FreeResource();
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir //------------------------------------------------------------------------
83cdf0e10cSrcweir
~ScMetricInputDlg()84cdf0e10cSrcweir __EXPORT ScMetricInputDlg::~ScMetricInputDlg()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir //------------------------------------------------------------------------
89cdf0e10cSrcweir
GetInputValue(FieldUnit eUnit) const90cdf0e10cSrcweir long ScMetricInputDlg::GetInputValue( FieldUnit eUnit ) const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir /*
93cdf0e10cSrcweir mit Nachkommastellen:
94cdf0e10cSrcweir
95cdf0e10cSrcweir double nVal = aEdValue.GetValue( eUnit );
96cdf0e10cSrcweir sal_uInt16 nDecs = aEdValue.GetDecimalDigits();
97cdf0e10cSrcweir double nFactor = 0.0;
98cdf0e10cSrcweir
99cdf0e10cSrcweir // static long ImpPower10( sal_uInt16 nDecs )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir nFactor = 1.0;
102cdf0e10cSrcweir
103cdf0e10cSrcweir for ( sal_uInt16 i=0; i < nDecs; i++ )
104cdf0e10cSrcweir nFactor *= 10.0;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir return nVal / nFactor;
108cdf0e10cSrcweir */
109cdf0e10cSrcweir // erstmal Nachkommastellen abschneiden - nich so doll...
110cdf0e10cSrcweir
111cdf0e10cSrcweir return sal::static_int_cast<long>( aEdValue.Denormalize( aEdValue.GetValue( eUnit ) ) );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114cdf0e10cSrcweir //------------------------------------------------------------------------
115cdf0e10cSrcweir
CalcPositions()116cdf0e10cSrcweir void ScMetricInputDlg::CalcPositions()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir MapMode oldMode = GetMapMode();
119cdf0e10cSrcweir SetMapMode( MAP_APPFONT );
120cdf0e10cSrcweir
121cdf0e10cSrcweir Size aDlgSize = GetOutputSizePixel();
122cdf0e10cSrcweir Size aFtSize = aFtEditTitle.GetSizePixel();
123cdf0e10cSrcweir Point aNewPos;
124cdf0e10cSrcweir
125cdf0e10cSrcweir aFtSize.Width() = aFtEditTitle.GetTextWidth(aFtEditTitle.GetText());
126cdf0e10cSrcweir // #95990# add mnemonic char width to fixed text width
127cdf0e10cSrcweir aFtSize.Width() += aFtEditTitle.GetTextWidth(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("(W)")));
128cdf0e10cSrcweir aFtEditTitle.SetSizePixel( aFtSize );
129cdf0e10cSrcweir
130cdf0e10cSrcweir aNewPos.Y() = aEdValue.GetPosPixel().Y();
131cdf0e10cSrcweir aNewPos.X() = aFtEditTitle.GetPosPixel().X();
132cdf0e10cSrcweir aNewPos.X() += aFtEditTitle.GetSizePixel().Width();
133cdf0e10cSrcweir aNewPos.X() += LogicToPixel( Point(3,0) ).X();
134cdf0e10cSrcweir aEdValue.SetPosPixel( aNewPos );
135cdf0e10cSrcweir
136cdf0e10cSrcweir aNewPos.Y() = aBtnDefVal.GetPosPixel().Y();
137cdf0e10cSrcweir aBtnDefVal.SetPosPixel( aNewPos );
138cdf0e10cSrcweir
139cdf0e10cSrcweir aNewPos.Y() = aBtnOk.GetPosPixel().Y();
140cdf0e10cSrcweir aNewPos.X() += aEdValue.GetSizePixel().Width();
141cdf0e10cSrcweir aNewPos.X() += LogicToPixel( Point(6,0) ).X();
142cdf0e10cSrcweir aBtnOk.SetPosPixel( aNewPos );
143cdf0e10cSrcweir aNewPos.Y() = aBtnCancel.GetPosPixel().Y();
144cdf0e10cSrcweir aBtnCancel.SetPosPixel( aNewPos );
145cdf0e10cSrcweir aNewPos.Y() = aBtnHelp.GetPosPixel().Y();
146cdf0e10cSrcweir aBtnHelp.SetPosPixel( aNewPos );
147cdf0e10cSrcweir
148cdf0e10cSrcweir aNewPos.X() += aBtnOk.GetSizePixel().Width();
149cdf0e10cSrcweir aNewPos.X() += LogicToPixel( Point(6,0) ).X();
150cdf0e10cSrcweir aDlgSize.Width() = aNewPos.X();
151cdf0e10cSrcweir SetOutputSizePixel( aDlgSize );
152cdf0e10cSrcweir
153cdf0e10cSrcweir SetMapMode( oldMode );
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir //------------------------------------------------------------------------
157cdf0e10cSrcweir // Handler:
158cdf0e10cSrcweir
IMPL_LINK(ScMetricInputDlg,SetDefValHdl,CheckBox *,EMPTYARG)159cdf0e10cSrcweir IMPL_LINK( ScMetricInputDlg, SetDefValHdl, CheckBox *, EMPTYARG )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir if ( aBtnDefVal.IsChecked() )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
164cdf0e10cSrcweir aEdValue.SetValue( nDefaultValue );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir else
167cdf0e10cSrcweir aEdValue.SetValue( nCurrentValue );
168cdf0e10cSrcweir return 0;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
171cdf0e10cSrcweir //------------------------------------------------------------------------
172cdf0e10cSrcweir
IMPL_LINK_INLINE_START(ScMetricInputDlg,ModifyHdl,MetricField *,EMPTYARG)173cdf0e10cSrcweir IMPL_LINK_INLINE_START( ScMetricInputDlg, ModifyHdl, MetricField *, EMPTYARG )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir aBtnDefVal.Check( nDefaultValue == aEdValue.GetValue() );
176cdf0e10cSrcweir return 0;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir IMPL_LINK_INLINE_END( ScMetricInputDlg, ModifyHdl, MetricField *, EMPTYARG )
179cdf0e10cSrcweir
180cdf0e10cSrcweir
181cdf0e10cSrcweir
182