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