Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / miscdlgs / mtrindlg.cxx
blob869ffc8060f141d590d4b78fc9c32c534a883cd5
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "mtrindlg.hxx"
23 #include "scresid.hxx"
24 #include "miscdlgs.hrc"
26 ScMetricInputDlg::ScMetricInputDlg( vcl::Window* pParent,
27 const OString& sDialogName,
28 long nCurrent,
29 long nDefault,
30 FieldUnit eFUnit,
31 sal_uInt16 nDecimals,
32 long nMaximum,
33 long nMinimum,
34 long nFirst,
35 long nLast )
37 : ModalDialog(pParent, OStringToOUString(sDialogName, RTL_TEXTENCODING_UTF8),
38 OStringToOUString("modules/scalc/ui/" +
39 sDialogName.toAsciiLowerCase() + ".ui", RTL_TEXTENCODING_UTF8))
41 get(m_pEdValue, "value");
42 get(m_pBtnDefVal, "default");
44 m_pBtnDefVal->SetClickHdl ( LINK( this, ScMetricInputDlg, SetDefValHdl ) );
45 m_pEdValue->SetModifyHdl( LINK( this, ScMetricInputDlg, ModifyHdl ) );
47 m_pEdValue->SetUnit ( eFUnit );
48 m_pEdValue->SetDecimalDigits ( nDecimals );
49 m_pEdValue->SetMax ( m_pEdValue->Normalize( nMaximum ), FUNIT_TWIP );
50 m_pEdValue->SetMin ( m_pEdValue->Normalize( nMinimum ), FUNIT_TWIP );
51 m_pEdValue->SetLast ( m_pEdValue->Normalize( nLast ), FUNIT_TWIP );
52 m_pEdValue->SetFirst ( m_pEdValue->Normalize( nFirst ), FUNIT_TWIP );
53 m_pEdValue->SetSpinSize ( m_pEdValue->Normalize( 1 ) / 10 );
54 m_pEdValue->SetValue ( m_pEdValue->Normalize( nDefault ), FUNIT_TWIP );
55 nDefaultValue = sal::static_int_cast<long>( m_pEdValue->GetValue() );
56 m_pEdValue->SetValue ( m_pEdValue->Normalize( nCurrent ), FUNIT_TWIP );
57 nCurrentValue = sal::static_int_cast<long>( m_pEdValue->GetValue() );
58 m_pBtnDefVal->Check( nCurrentValue == nDefaultValue );
61 ScMetricInputDlg::~ScMetricInputDlg()
63 disposeOnce();
66 void ScMetricInputDlg::dispose()
68 m_pEdValue.clear();
69 m_pBtnDefVal.clear();
70 ModalDialog::dispose();
73 long ScMetricInputDlg::GetInputValue() const
76 with decimal digits
78 double nVal = m_pEdValue->GetValue( eUnit );
79 sal_uInt16 nDecs = m_pEdValue->GetDecimalDigits();
80 double nFactor = 0.0;
82 // static long ImpPower10( sal_uInt16 nDecs )
84 nFactor = 1.0;
86 for ( sal_uInt16 i=0; i < nDecs; i++ )
87 nFactor *= 10.0;
90 return nVal / nFactor;
92 // first cut off the decimal digits - not that great...
94 return sal::static_int_cast<long>( m_pEdValue->Denormalize( m_pEdValue->GetValue( FUNIT_TWIP ) ) );
97 // Handler:
99 IMPL_LINK_NOARG_TYPED(ScMetricInputDlg, SetDefValHdl, Button*, void)
101 if ( m_pBtnDefVal->IsChecked() )
103 nCurrentValue = sal::static_int_cast<long>( m_pEdValue->GetValue() );
104 m_pEdValue->SetValue( nDefaultValue );
106 else
107 m_pEdValue->SetValue( nCurrentValue );
110 IMPL_LINK_NOARG_TYPED(ScMetricInputDlg, ModifyHdl, Edit&, void)
112 m_pBtnDefVal->Check( nDefaultValue == m_pEdValue->GetValue() );
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */