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 OString
& sDialogName
,
33 : GenericDialogController(pParent
, "modules/scalc/ui/" + OStringToOUString(
34 sDialogName
.toAsciiLowerCase(), RTL_TEXTENCODING_UTF8
) + ".ui", sDialogName
)
35 , m_xEdValue(m_xBuilder
->weld_metric_spin_button("value", FieldUnit::CM
))
36 , m_xBtnDefVal(m_xBuilder
->weld_check_button("default"))
38 m_xBtnDefVal
->connect_toggled(LINK(this, ScMetricInputDlg
, SetDefValHdl
));
39 m_xEdValue
->connect_value_changed(LINK( this, ScMetricInputDlg
, ModifyHdl
));
41 m_xEdValue
->set_unit(eFUnit
);
42 m_xEdValue
->set_digits(nDecimals
);
43 m_xEdValue
->set_range(m_xEdValue
->normalize(nMinimum
),
44 m_xEdValue
->normalize(nMaximum
), FieldUnit::TWIP
);
46 sal_Int64
nMin(0), nMax(0);
47 m_xEdValue
->get_range(nMin
, nMax
, FieldUnit::TWIP
);
49 auto nIncrement
= m_xEdValue
->normalize(1);
50 m_xEdValue
->set_increments(nIncrement
/ 10, nIncrement
, FieldUnit::NONE
);
51 m_xEdValue
->set_value(m_xEdValue
->normalize(nDefault
), FieldUnit::TWIP
);
52 nDefaultValue
= m_xEdValue
->get_value(FieldUnit::NONE
);
53 m_xEdValue
->set_value(m_xEdValue
->normalize(nCurrent
), FieldUnit::TWIP
);
54 nCurrentValue
= m_xEdValue
->get_value(FieldUnit::NONE
);
55 m_xBtnDefVal
->set_active(nCurrentValue
== nDefaultValue
);
58 ScMetricInputDlg::~ScMetricInputDlg()
62 int ScMetricInputDlg::GetInputValue() const
67 double nVal = m_xEdValue->GetValue( eUnit );
68 sal_uInt16 nDecs = m_xEdValue->GetDecimalDigits();
71 // static long ImpPower10( sal_uInt16 nDecs )
75 for ( sal_uInt16 i=0; i < nDecs; i++ )
79 return nVal / nFactor;
81 // first cut off the decimal digits - not that great...
83 return m_xEdValue
->denormalize(m_xEdValue
->get_value(FieldUnit::TWIP
));
88 IMPL_LINK_NOARG(ScMetricInputDlg
, SetDefValHdl
, weld::Toggleable
&, void)
90 if (m_xBtnDefVal
->get_active())
92 nCurrentValue
= m_xEdValue
->get_value(FieldUnit::NONE
);
93 m_xEdValue
->set_value(nDefaultValue
, FieldUnit::NONE
);
96 m_xEdValue
->set_value(nCurrentValue
, FieldUnit::NONE
);
99 IMPL_LINK_NOARG(ScMetricInputDlg
, ModifyHdl
, weld::MetricSpinButton
&, void)
101 m_xBtnDefVal
->set_active(nDefaultValue
== m_xEdValue
->get_value(FieldUnit::NONE
));
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */