Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / miscdlgs / mtrindlg.cxx
blob0829670029b6264461095077f2d4e2a965de4b28
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #undef SC_DLLIMPLEMENTATION
25 //------------------------------------------------------------------
27 #include "mtrindlg.hxx"
28 #include "scresid.hxx"
29 #include "miscdlgs.hrc"
32 //==================================================================
34 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 )
45 : ModalDialog ( pParent, ScResId( nResId ) ),
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 aBtnHelp ( this, ScResId( BTN_HELP ) )
54 //SetText( rTitle );
56 //aFtEditTitle.SetText( rEditTitle );
57 CalcPositions();
58 aBtnDefVal.SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) );
59 aEdValue. SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl ) );
61 aEdValue.SetUnit ( eFUnit );
62 aEdValue.SetDecimalDigits ( nDecimals );
63 aEdValue.SetMax ( aEdValue.Normalize( nMaximum ), FUNIT_TWIP );
64 aEdValue.SetMin ( aEdValue.Normalize( nMinimum ), FUNIT_TWIP );
65 aEdValue.SetLast ( aEdValue.Normalize( nLast ), FUNIT_TWIP );
66 aEdValue.SetFirst ( aEdValue.Normalize( nFirst ), FUNIT_TWIP );
67 aEdValue.SetSpinSize ( aEdValue.Normalize( 1 ) / 10 );
68 aEdValue.SetValue ( aEdValue.Normalize( nDefault ), FUNIT_TWIP );
69 nDefaultValue = sal::static_int_cast<long>( aEdValue.GetValue() );
70 aEdValue.SetValue ( aEdValue.Normalize( nCurrent ), FUNIT_TWIP );
71 nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
72 aBtnDefVal.Check( nCurrentValue == nDefaultValue );
74 FreeResource();
77 //------------------------------------------------------------------------
79 ScMetricInputDlg::~ScMetricInputDlg()
83 //------------------------------------------------------------------------
85 long ScMetricInputDlg::GetInputValue( FieldUnit eUnit ) const
88 mit Nachkommastellen:
90 double nVal = aEdValue.GetValue( eUnit );
91 sal_uInt16 nDecs = aEdValue.GetDecimalDigits();
92 double nFactor = 0.0;
94 // static long ImpPower10( sal_uInt16 nDecs )
96 nFactor = 1.0;
98 for ( sal_uInt16 i=0; i < nDecs; i++ )
99 nFactor *= 10.0;
102 return nVal / nFactor;
104 // erstmal Nachkommastellen abschneiden - nich so doll...
106 return sal::static_int_cast<long>( aEdValue.Denormalize( aEdValue.GetValue( eUnit ) ) );
109 //------------------------------------------------------------------------
111 void ScMetricInputDlg::CalcPositions()
113 MapMode oldMode = GetMapMode();
114 SetMapMode( MAP_APPFONT );
116 Size aDlgSize = GetOutputSizePixel();
117 Size aFtSize = aFtEditTitle.GetSizePixel();
118 Point aNewPos;
120 aFtSize.Width() = aFtEditTitle.GetTextWidth(aFtEditTitle.GetText());
121 // add mnemonic char width to fixed text width
122 aFtSize.Width() += aFtEditTitle.GetTextWidth(OUString("(W)"));
123 aFtEditTitle.SetSizePixel( aFtSize );
125 aNewPos.Y() = aEdValue.GetPosPixel().Y();
126 aNewPos.X() = aFtEditTitle.GetPosPixel().X();
127 aNewPos.X() += aFtEditTitle.GetSizePixel().Width();
128 aNewPos.X() += LogicToPixel( Point(3,0) ).X();
129 aEdValue.SetPosPixel( aNewPos );
131 aNewPos.Y() = aBtnDefVal.GetPosPixel().Y();
132 aBtnDefVal.SetPosPixel( aNewPos );
134 aNewPos.Y() = aBtnOk.GetPosPixel().Y();
135 aNewPos.X() += aEdValue.GetSizePixel().Width();
136 aNewPos.X() += LogicToPixel( Point(6,0) ).X();
137 aBtnOk.SetPosPixel( aNewPos );
138 aNewPos.Y() = aBtnCancel.GetPosPixel().Y();
139 aBtnCancel.SetPosPixel( aNewPos );
140 aNewPos.Y() = aBtnHelp.GetPosPixel().Y();
141 aBtnHelp.SetPosPixel( aNewPos );
143 aNewPos.X() += aBtnOk.GetSizePixel().Width();
144 aNewPos.X() += LogicToPixel( Point(6,0) ).X();
145 aDlgSize.Width() = aNewPos.X();
146 SetOutputSizePixel( aDlgSize );
148 SetMapMode( oldMode );
151 //------------------------------------------------------------------------
152 // Handler:
154 IMPL_LINK_NOARG(ScMetricInputDlg, SetDefValHdl)
156 if ( aBtnDefVal.IsChecked() )
158 nCurrentValue = sal::static_int_cast<long>( aEdValue.GetValue() );
159 aEdValue.SetValue( nDefaultValue );
161 else
162 aEdValue.SetValue( nCurrentValue );
163 return 0;
166 //------------------------------------------------------------------------
168 IMPL_LINK_NOARG_INLINE_START(ScMetricInputDlg, ModifyHdl)
170 aBtnDefVal.Check( nDefaultValue == aEdValue.GetValue() );
171 return 0;
173 IMPL_LINK_NOARG_INLINE_END(ScMetricInputDlg, ModifyHdl)
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */