1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 ScMetricInputDlg::ScMetricInputDlg( weld::Window
* pParent
,
25 const OUString
& sDialogName
,
33 : GenericDialogController(pParent
, "modules/scalc/ui/" + sDialogName
.toAsciiLowerCase() + ".ui", sDialogName
)
34 , m_xEdValue(m_xBuilder
->weld_metric_spin_button(u
"value"_ustr
, FieldUnit::CM
))
35 , m_xBtnDefVal(m_xBuilder
->weld_check_button(u
"default"_ustr
))
37 m_xBtnDefVal
->connect_toggled(LINK(this, ScMetricInputDlg
, SetDefValHdl
));
38 m_xEdValue
->connect_value_changed(LINK( this, ScMetricInputDlg
, ModifyHdl
));
40 m_xEdValue
->set_unit(eFUnit
);
41 m_xEdValue
->set_digits(nDecimals
);
42 m_xEdValue
->set_range(m_xEdValue
->normalize(nMinimum
),
43 m_xEdValue
->normalize(nMaximum
), FieldUnit::TWIP
);
45 sal_Int64
nMin(0), nMax(0);
46 m_xEdValue
->get_range(nMin
, nMax
, FieldUnit::TWIP
);
48 auto nIncrement
= m_xEdValue
->normalize(1);
49 m_xEdValue
->set_increments(nIncrement
/ 10, nIncrement
, FieldUnit::NONE
);
50 m_xEdValue
->set_value(m_xEdValue
->normalize(nDefault
), FieldUnit::TWIP
);
51 nDefaultValue
= m_xEdValue
->get_value(FieldUnit::NONE
);
52 m_xEdValue
->set_value(m_xEdValue
->normalize(nCurrent
), FieldUnit::TWIP
);
53 nCurrentValue
= m_xEdValue
->get_value(FieldUnit::NONE
);
54 m_xBtnDefVal
->set_active(nCurrentValue
== nDefaultValue
);
57 ScMetricInputDlg::~ScMetricInputDlg()
61 int ScMetricInputDlg::GetInputValue() const
66 double nVal = m_xEdValue->GetValue( eUnit );
67 sal_uInt16 nDecs = m_xEdValue->GetDecimalDigits();
70 // static long ImpPower10( sal_uInt16 nDecs )
74 for ( sal_uInt16 i=0; i < nDecs; i++ )
78 return nVal / nFactor;
80 // first cut off the decimal digits - not that great...
82 return m_xEdValue
->denormalize(m_xEdValue
->get_value(FieldUnit::TWIP
));
87 IMPL_LINK_NOARG(ScMetricInputDlg
, SetDefValHdl
, weld::Toggleable
&, void)
89 if (m_xBtnDefVal
->get_active())
91 nCurrentValue
= m_xEdValue
->get_value(FieldUnit::NONE
);
92 m_xEdValue
->set_value(nDefaultValue
, FieldUnit::NONE
);
95 m_xEdValue
->set_value(nCurrentValue
, FieldUnit::NONE
);
98 IMPL_LINK_NOARG(ScMetricInputDlg
, ModifyHdl
, weld::MetricSpinButton
&, void)
100 m_xBtnDefVal
->set_active(nDefaultValue
== m_xEdValue
->get_value(FieldUnit::NONE
));
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */