xref: /trunk/main/sc/source/ui/miscdlgs/mtrindlg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #undef SC_DLLIMPLEMENTATION
32 
33 
34 
35 //------------------------------------------------------------------
36 
37 #include "mtrindlg.hxx"
38 #include "scresid.hxx"
39 #include "miscdlgs.hrc"
40 
41 
42 //==================================================================
43 
44 ScMetricInputDlg::ScMetricInputDlg( Window*         pParent,
45 									sal_uInt16			nResId,
46 									long			nCurrent,
47 									long			nDefault,
48 									FieldUnit       eFUnit,
49 									sal_uInt16          nDecimals,
50 									long            nMaximum,
51 									long            nMinimum,
52 									long            nFirst,
53                                     long            nLast )
54 
55 	:	ModalDialog     ( pParent, ScResId( nResId ) ),
56 		//
57 		aFtEditTitle    ( this, ScResId( FT_LABEL ) ),
58 		aEdValue        ( this, ScResId( ED_VALUE ) ),
59 		aBtnDefVal		( this, ScResId( BTN_DEFVAL ) ),
60 		aBtnOk          ( this, ScResId( BTN_OK ) ),
61 		aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
62 		aBtnHelp        ( this, ScResId( BTN_HELP ) )
63 {
64 	//SetText( rTitle );
65 	//
66 	//aFtEditTitle.SetText( rEditTitle );
67 	CalcPositions();
68 	aBtnDefVal.SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) );
69 	aEdValue.  SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl    ) );
70 
71     aEdValue.SetUnit            ( eFUnit );
72     aEdValue.SetDecimalDigits   ( nDecimals );
73     aEdValue.SetMax             ( aEdValue.Normalize( nMaximum ), FUNIT_TWIP );
74     aEdValue.SetMin             ( aEdValue.Normalize( nMinimum ), FUNIT_TWIP );
75     aEdValue.SetLast            ( aEdValue.Normalize( nLast ),    FUNIT_TWIP );
76     aEdValue.SetFirst           ( aEdValue.Normalize( nFirst ),   FUNIT_TWIP );
77     aEdValue.SetSpinSize        ( aEdValue.Normalize( 1 ) / 10 );
78     aEdValue.SetValue           ( aEdValue.Normalize( nDefault ), FUNIT_TWIP );
79     nDefaultValue =	sal::static_int_cast<long>( aEdValue.GetValue() );
80     aEdValue.SetValue           ( aEdValue.Normalize( nCurrent ), FUNIT_TWIP );
81     nCurrentValue =	sal::static_int_cast<long>( aEdValue.GetValue() );
82 	aBtnDefVal.Check( nCurrentValue == nDefaultValue );
83 
84 	FreeResource();
85 }
86 
87 //------------------------------------------------------------------------
88 
89 __EXPORT ScMetricInputDlg::~ScMetricInputDlg()
90 {
91 }
92 
93 //------------------------------------------------------------------------
94 
95 long ScMetricInputDlg::GetInputValue( FieldUnit eUnit ) const
96 {
97 /*
98 	mit Nachkommastellen:
99 
100 	double	nVal	= aEdValue.GetValue( eUnit );
101 	sal_uInt16	nDecs	= aEdValue.GetDecimalDigits();
102 	double	nFactor = 0.0;
103 
104 	// static long ImpPower10( sal_uInt16 nDecs )
105 	{
106 		nFactor = 1.0;
107 
108 		for ( sal_uInt16 i=0; i < nDecs; i++ )
109 			nFactor *= 10.0;
110 	}
111 
112 	return nVal / nFactor;
113 */
114 	// erstmal Nachkommastellen abschneiden - nich so doll...
115 
116     return sal::static_int_cast<long>( aEdValue.Denormalize( aEdValue.GetValue( eUnit ) ) );
117 }
118 
119 //------------------------------------------------------------------------
120 
121 void ScMetricInputDlg::CalcPositions()
122 {
123 	MapMode oldMode     = GetMapMode();
124 	SetMapMode( MAP_APPFONT );
125 
126 	Size    aDlgSize    = GetOutputSizePixel();
127 	Size    aFtSize     = aFtEditTitle.GetSizePixel();
128 	Point   aNewPos;
129 
130 	aFtSize.Width() = aFtEditTitle.GetTextWidth(aFtEditTitle.GetText());
131     // #95990# add mnemonic char width to fixed text width
132     aFtSize.Width() += aFtEditTitle.GetTextWidth(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("(W)")));
133 	aFtEditTitle.SetSizePixel( aFtSize );
134 
135 	aNewPos.Y()  = aEdValue.GetPosPixel().Y();
136 	aNewPos.X()  = aFtEditTitle.GetPosPixel().X();
137 	aNewPos.X() += aFtEditTitle.GetSizePixel().Width();
138     aNewPos.X() += LogicToPixel( Point(3,0) ).X();
139 	aEdValue.SetPosPixel( aNewPos );
140 
141 	aNewPos.Y()  = aBtnDefVal.GetPosPixel().Y();
142 	aBtnDefVal.SetPosPixel( aNewPos );
143 
144 	aNewPos.Y()  = aBtnOk.GetPosPixel().Y();
145 	aNewPos.X() += aEdValue.GetSizePixel().Width();
146 	aNewPos.X() += LogicToPixel( Point(6,0) ).X();
147 	aBtnOk.SetPosPixel( aNewPos );
148 	aNewPos.Y()  = aBtnCancel.GetPosPixel().Y();
149 	aBtnCancel.SetPosPixel( aNewPos );
150 	aNewPos.Y()  = aBtnHelp.GetPosPixel().Y();
151 	aBtnHelp.SetPosPixel( aNewPos );
152 
153 	aNewPos.X() += aBtnOk.GetSizePixel().Width();
154 	aNewPos.X() += LogicToPixel( Point(6,0) ).X();
155 	aDlgSize.Width() = aNewPos.X();
156 	SetOutputSizePixel( aDlgSize );
157 
158 	SetMapMode( oldMode );
159 }
160 
161 //------------------------------------------------------------------------
162 // Handler:
163 
164 IMPL_LINK( ScMetricInputDlg, SetDefValHdl, CheckBox *, EMPTYARG )
165 {
166 	if ( aBtnDefVal.IsChecked() )
167 	{
168         nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
169 		aEdValue.SetValue( nDefaultValue );
170 	}
171 	else
172 		aEdValue.SetValue( nCurrentValue );
173 	return 0;
174 }
175 
176 //------------------------------------------------------------------------
177 
178 IMPL_LINK_INLINE_START( ScMetricInputDlg, ModifyHdl, MetricField *, EMPTYARG )
179 {
180 	aBtnDefVal.Check( nDefaultValue == aEdValue.GetValue() );
181 	return 0;
182 }
183 IMPL_LINK_INLINE_END( ScMetricInputDlg, ModifyHdl, MetricField *, EMPTYARG )
184 
185 
186 
187