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