Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #undef SC_DLLIMPLEMENTATION
22 :
23 :
24 :
25 : //------------------------------------------------------------------
26 :
27 : #include "mtrindlg.hxx"
28 : #include "scresid.hxx"
29 : #include "miscdlgs.hrc"
30 :
31 :
32 : //==================================================================
33 :
34 0 : ScMetricInputDlg::ScMetricInputDlg( Window* pParent,
35 : sal_uInt16 nResId,
36 : long nCurrent,
37 : long nDefault,
38 : FieldUnit eFUnit,
39 : sal_uInt16 nDecimals,
40 : long nMaximum,
41 : long nMinimum,
42 : long nFirst,
43 : long nLast )
44 :
45 : : ModalDialog ( pParent, ScResId( nResId ) ),
46 : //
47 : aFtEditTitle ( this, ScResId( FT_LABEL ) ),
48 : aEdValue ( this, ScResId( ED_VALUE ) ),
49 : aBtnDefVal ( this, ScResId( BTN_DEFVAL ) ),
50 : aBtnOk ( this, ScResId( BTN_OK ) ),
51 : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
52 0 : aBtnHelp ( this, ScResId( BTN_HELP ) )
53 : {
54 : //SetText( rTitle );
55 : //
56 : //aFtEditTitle.SetText( rEditTitle );
57 0 : CalcPositions();
58 0 : aBtnDefVal.SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) );
59 0 : aEdValue. SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl ) );
60 :
61 0 : aEdValue.SetUnit ( eFUnit );
62 0 : aEdValue.SetDecimalDigits ( nDecimals );
63 0 : aEdValue.SetMax ( aEdValue.Normalize( nMaximum ), FUNIT_TWIP );
64 0 : aEdValue.SetMin ( aEdValue.Normalize( nMinimum ), FUNIT_TWIP );
65 0 : aEdValue.SetLast ( aEdValue.Normalize( nLast ), FUNIT_TWIP );
66 0 : aEdValue.SetFirst ( aEdValue.Normalize( nFirst ), FUNIT_TWIP );
67 0 : aEdValue.SetSpinSize ( aEdValue.Normalize( 1 ) / 10 );
68 0 : aEdValue.SetValue ( aEdValue.Normalize( nDefault ), FUNIT_TWIP );
69 0 : nDefaultValue = sal::static_int_cast<long>( aEdValue.GetValue() );
70 0 : aEdValue.SetValue ( aEdValue.Normalize( nCurrent ), FUNIT_TWIP );
71 0 : nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
72 0 : aBtnDefVal.Check( nCurrentValue == nDefaultValue );
73 :
74 0 : FreeResource();
75 0 : }
76 :
77 : //------------------------------------------------------------------------
78 :
79 0 : ScMetricInputDlg::~ScMetricInputDlg()
80 : {
81 0 : }
82 :
83 : //------------------------------------------------------------------------
84 :
85 0 : long ScMetricInputDlg::GetInputValue( FieldUnit eUnit ) const
86 : {
87 : /*
88 : mit Nachkommastellen:
89 :
90 : double nVal = aEdValue.GetValue( eUnit );
91 : sal_uInt16 nDecs = aEdValue.GetDecimalDigits();
92 : double nFactor = 0.0;
93 :
94 : // static long ImpPower10( sal_uInt16 nDecs )
95 : {
96 : nFactor = 1.0;
97 :
98 : for ( sal_uInt16 i=0; i < nDecs; i++ )
99 : nFactor *= 10.0;
100 : }
101 :
102 : return nVal / nFactor;
103 : */
104 : // erstmal Nachkommastellen abschneiden - nich so doll...
105 :
106 0 : return sal::static_int_cast<long>( aEdValue.Denormalize( aEdValue.GetValue( eUnit ) ) );
107 : }
108 :
109 : //------------------------------------------------------------------------
110 :
111 0 : void ScMetricInputDlg::CalcPositions()
112 : {
113 0 : MapMode oldMode = GetMapMode();
114 0 : SetMapMode( MAP_APPFONT );
115 :
116 0 : Size aDlgSize = GetOutputSizePixel();
117 0 : Size aFtSize = aFtEditTitle.GetSizePixel();
118 0 : Point aNewPos;
119 :
120 0 : aFtSize.Width() = aFtEditTitle.GetTextWidth(aFtEditTitle.GetText());
121 : // add mnemonic char width to fixed text width
122 0 : aFtSize.Width() += aFtEditTitle.GetTextWidth(rtl::OUString("(W)"));
123 0 : aFtEditTitle.SetSizePixel( aFtSize );
124 :
125 0 : aNewPos.Y() = aEdValue.GetPosPixel().Y();
126 0 : aNewPos.X() = aFtEditTitle.GetPosPixel().X();
127 0 : aNewPos.X() += aFtEditTitle.GetSizePixel().Width();
128 0 : aNewPos.X() += LogicToPixel( Point(3,0) ).X();
129 0 : aEdValue.SetPosPixel( aNewPos );
130 :
131 0 : aNewPos.Y() = aBtnDefVal.GetPosPixel().Y();
132 0 : aBtnDefVal.SetPosPixel( aNewPos );
133 :
134 0 : aNewPos.Y() = aBtnOk.GetPosPixel().Y();
135 0 : aNewPos.X() += aEdValue.GetSizePixel().Width();
136 0 : aNewPos.X() += LogicToPixel( Point(6,0) ).X();
137 0 : aBtnOk.SetPosPixel( aNewPos );
138 0 : aNewPos.Y() = aBtnCancel.GetPosPixel().Y();
139 0 : aBtnCancel.SetPosPixel( aNewPos );
140 0 : aNewPos.Y() = aBtnHelp.GetPosPixel().Y();
141 0 : aBtnHelp.SetPosPixel( aNewPos );
142 :
143 0 : aNewPos.X() += aBtnOk.GetSizePixel().Width();
144 0 : aNewPos.X() += LogicToPixel( Point(6,0) ).X();
145 0 : aDlgSize.Width() = aNewPos.X();
146 0 : SetOutputSizePixel( aDlgSize );
147 :
148 0 : SetMapMode( oldMode );
149 0 : }
150 :
151 : //------------------------------------------------------------------------
152 : // Handler:
153 :
154 0 : IMPL_LINK_NOARG(ScMetricInputDlg, SetDefValHdl)
155 : {
156 0 : if ( aBtnDefVal.IsChecked() )
157 : {
158 0 : nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
159 0 : aEdValue.SetValue( nDefaultValue );
160 : }
161 : else
162 0 : aEdValue.SetValue( nCurrentValue );
163 0 : return 0;
164 : }
165 :
166 : //------------------------------------------------------------------------
167 :
168 0 : IMPL_LINK_NOARG_INLINE_START(ScMetricInputDlg, ModifyHdl)
169 : {
170 0 : aBtnDefVal.Check( nDefaultValue == aEdValue.GetValue() );
171 0 : return 0;
172 : }
173 0 : IMPL_LINK_NOARG_INLINE_END(ScMetricInputDlg, ModifyHdl)
174 :
175 :
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|