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