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_scui.hxx" 26 27 28 29 30 //------------------------------------------------------------------ 31 32 #include "mtrindlg.hxx" 33 #include "scresid.hxx" 34 #include "miscdlgs.hrc" 35 36 37 //================================================================== 38 39 ScMetricInputDlg::ScMetricInputDlg( Window* pParent, 40 sal_uInt16 nResId, 41 long nCurrent, 42 long nDefault, 43 FieldUnit eFUnit, 44 sal_uInt16 nDecimals, 45 long nMaximum, 46 long nMinimum, 47 long nFirst, 48 long nLast ) 49 50 : ModalDialog ( pParent, ScResId( nResId ) ), 51 // 52 aFtEditTitle ( this, ScResId( FT_LABEL ) ), 53 aEdValue ( this, ScResId( ED_VALUE ) ), 54 aBtnDefVal ( this, ScResId( BTN_DEFVAL ) ), 55 aBtnOk ( this, ScResId( BTN_OK ) ), 56 aBtnCancel ( this, ScResId( BTN_CANCEL ) ), 57 aBtnHelp ( this, ScResId( BTN_HELP ) ) 58 { 59 //SetText( rTitle ); 60 // 61 //aFtEditTitle.SetText( rEditTitle ); 62 CalcPositions(); 63 aBtnDefVal.SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) ); 64 aEdValue. SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl ) ); 65 66 aEdValue.SetUnit ( eFUnit ); 67 aEdValue.SetDecimalDigits ( nDecimals ); 68 aEdValue.SetMax ( aEdValue.Normalize( nMaximum ), FUNIT_TWIP ); 69 aEdValue.SetMin ( aEdValue.Normalize( nMinimum ), FUNIT_TWIP ); 70 aEdValue.SetLast ( aEdValue.Normalize( nLast ), FUNIT_TWIP ); 71 aEdValue.SetFirst ( aEdValue.Normalize( nFirst ), FUNIT_TWIP ); 72 aEdValue.SetSpinSize ( aEdValue.Normalize( 1 ) / 10 ); 73 aEdValue.SetValue ( aEdValue.Normalize( nDefault ), FUNIT_TWIP ); 74 nDefaultValue = sal::static_int_cast<long>( aEdValue.GetValue() ); 75 aEdValue.SetValue ( aEdValue.Normalize( nCurrent ), FUNIT_TWIP ); 76 nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() ); 77 aBtnDefVal.Check( nCurrentValue == nDefaultValue ); 78 79 FreeResource(); 80 } 81 82 //------------------------------------------------------------------------ 83 84 __EXPORT ScMetricInputDlg::~ScMetricInputDlg() 85 { 86 } 87 88 //------------------------------------------------------------------------ 89 90 long ScMetricInputDlg::GetInputValue( FieldUnit eUnit ) const 91 { 92 /* 93 mit Nachkommastellen: 94 95 double nVal = aEdValue.GetValue( eUnit ); 96 sal_uInt16 nDecs = aEdValue.GetDecimalDigits(); 97 double nFactor = 0.0; 98 99 // static long ImpPower10( sal_uInt16 nDecs ) 100 { 101 nFactor = 1.0; 102 103 for ( sal_uInt16 i=0; i < nDecs; i++ ) 104 nFactor *= 10.0; 105 } 106 107 return nVal / nFactor; 108 */ 109 // erstmal Nachkommastellen abschneiden - nich so doll... 110 111 return sal::static_int_cast<long>( aEdValue.Denormalize( aEdValue.GetValue( eUnit ) ) ); 112 } 113 114 //------------------------------------------------------------------------ 115 116 void ScMetricInputDlg::CalcPositions() 117 { 118 MapMode oldMode = GetMapMode(); 119 SetMapMode( MAP_APPFONT ); 120 121 Size aDlgSize = GetOutputSizePixel(); 122 Size aFtSize = aFtEditTitle.GetSizePixel(); 123 Point aNewPos; 124 125 aFtSize.Width() = aFtEditTitle.GetTextWidth(aFtEditTitle.GetText()); 126 // #95990# add mnemonic char width to fixed text width 127 aFtSize.Width() += aFtEditTitle.GetTextWidth(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("(W)"))); 128 aFtEditTitle.SetSizePixel( aFtSize ); 129 130 aNewPos.Y() = aEdValue.GetPosPixel().Y(); 131 aNewPos.X() = aFtEditTitle.GetPosPixel().X(); 132 aNewPos.X() += aFtEditTitle.GetSizePixel().Width(); 133 aNewPos.X() += LogicToPixel( Point(3,0) ).X(); 134 aEdValue.SetPosPixel( aNewPos ); 135 136 aNewPos.Y() = aBtnDefVal.GetPosPixel().Y(); 137 aBtnDefVal.SetPosPixel( aNewPos ); 138 139 aNewPos.Y() = aBtnOk.GetPosPixel().Y(); 140 aNewPos.X() += aEdValue.GetSizePixel().Width(); 141 aNewPos.X() += LogicToPixel( Point(6,0) ).X(); 142 aBtnOk.SetPosPixel( aNewPos ); 143 aNewPos.Y() = aBtnCancel.GetPosPixel().Y(); 144 aBtnCancel.SetPosPixel( aNewPos ); 145 aNewPos.Y() = aBtnHelp.GetPosPixel().Y(); 146 aBtnHelp.SetPosPixel( aNewPos ); 147 148 aNewPos.X() += aBtnOk.GetSizePixel().Width(); 149 aNewPos.X() += LogicToPixel( Point(6,0) ).X(); 150 aDlgSize.Width() = aNewPos.X(); 151 SetOutputSizePixel( aDlgSize ); 152 153 SetMapMode( oldMode ); 154 } 155 156 //------------------------------------------------------------------------ 157 // Handler: 158 159 IMPL_LINK( ScMetricInputDlg, SetDefValHdl, CheckBox *, EMPTYARG ) 160 { 161 if ( aBtnDefVal.IsChecked() ) 162 { 163 nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() ); 164 aEdValue.SetValue( nDefaultValue ); 165 } 166 else 167 aEdValue.SetValue( nCurrentValue ); 168 return 0; 169 } 170 171 //------------------------------------------------------------------------ 172 173 IMPL_LINK_INLINE_START( ScMetricInputDlg, ModifyHdl, MetricField *, EMPTYARG ) 174 { 175 aBtnDefVal.Check( nDefaultValue == aEdValue.GetValue() ); 176 return 0; 177 } 178 IMPL_LINK_INLINE_END( ScMetricInputDlg, ModifyHdl, MetricField *, EMPTYARG ) 179