diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-14 20:11:39 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-15 14:59:31 +0200 |
commit | 288b9f7edd26458e3a71aad9f96279ec9ef00931 (patch) | |
tree | 8ecc14057aae7cf28f6f30c2dcba70c9b653c7c8 /vcl | |
parent | c7cd9bec28fbe06b46c4bc24db39d843857ce731 (diff) |
need to set the formatter as early as possible
easiest thing is to distinguish between an external one and a
built-in one and have callers own the external one
Change-Id: Ia14dea81614f7bc7958c5fa11cce928a9a59976a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98790
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/app/weldutils.cxx | 4 | ||||
-rw-r--r-- | vcl/source/control/fmtfield.cxx | 39 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 49 |
3 files changed, 58 insertions, 34 deletions
diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index 3c11b8e4afbb..acf1ba3473b5 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -147,12 +147,16 @@ EntryFormatter::~EntryFormatter() { m_rEntry.connect_changed(Link<weld::Entry&, void>()); m_rEntry.connect_focus_out(Link<weld::Widget&, void>()); + if (m_pSpinButton) + m_pSpinButton->SetFormatter(nullptr); } void EntryFormatter::Init() { m_rEntry.connect_changed(LINK(this, EntryFormatter, ModifyHdl)); m_rEntry.connect_focus_out(LINK(this, EntryFormatter, FocusOutHdl)); + if (m_pSpinButton) + m_pSpinButton->SetFormatter(this); } Selection EntryFormatter::GetEntrySelection() const diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx index 52f959056dda..48a82370b325 100644 --- a/vcl/source/control/fmtfield.cxx +++ b/vcl/source/control/fmtfield.cxx @@ -1010,7 +1010,8 @@ namespace DoubleNumericField::DoubleNumericField(vcl::Window* pParent, WinBits nStyle) : FormattedField(pParent, nStyle) { - m_xFormatter.reset(new DoubleNumericFormatter(*this)); + m_xOwnFormatter.reset(new DoubleNumericFormatter(*this)); + m_pFormatter = m_xOwnFormatter.get(); ResetConformanceTester(); } @@ -1044,7 +1045,9 @@ void DoubleNumericField::ResetConformanceTester() DoubleCurrencyField::DoubleCurrencyField(vcl::Window* pParent, WinBits nStyle) :FormattedField(pParent, nStyle) { - m_xFormatter.reset(new DoubleCurrencyFormatter(*this)); + m_xOwnFormatter.reset(new DoubleCurrencyFormatter(*this)); + m_pFormatter = m_xOwnFormatter.get(); + m_bPrependCurrSym = false; // initialize with a system currency format @@ -1059,7 +1062,7 @@ void DoubleCurrencyField::setCurrencySymbol(const OUString& rSymbol) m_sCurrencySymbol = rSymbol; UpdateCurrencyFormat(); - m_xFormatter->FormatChanged(FORMAT_CHANGE_TYPE::CURRENCY_SYMBOL); + m_pFormatter->FormatChanged(FORMAT_CHANGE_TYPE::CURRENCY_SYMBOL); } void DoubleCurrencyField::setPrependCurrSym(bool _bPrepend) @@ -1069,16 +1072,16 @@ void DoubleCurrencyField::setPrependCurrSym(bool _bPrepend) m_bPrependCurrSym = _bPrepend; UpdateCurrencyFormat(); - m_xFormatter->FormatChanged(FORMAT_CHANGE_TYPE::CURRSYM_POSITION); + m_pFormatter->FormatChanged(FORMAT_CHANGE_TYPE::CURRSYM_POSITION); } void DoubleCurrencyField::UpdateCurrencyFormat() { // the old settings LanguageType eLanguage; - m_xFormatter->GetFormat(eLanguage); - bool bThSep = m_xFormatter->GetThousandsSep(); - sal_uInt16 nDigits = m_xFormatter->GetDecimalDigits(); + m_pFormatter->GetFormat(eLanguage); + bool bThSep = m_pFormatter->GetThousandsSep(); + sal_uInt16 nDigits = m_pFormatter->GetDecimalDigits(); // build a new format string with the base class' and my own settings @@ -1142,17 +1145,19 @@ void DoubleCurrencyField::UpdateCurrencyFormat() } // set this new basic format - static_cast<DoubleCurrencyFormatter*>(m_xFormatter.get())->GuardSetFormat(sNewFormat.makeStringAndClear(), eLanguage); + static_cast<DoubleCurrencyFormatter*>(m_pFormatter)->GuardSetFormat(sNewFormat.makeStringAndClear(), eLanguage); } FormattedField::FormattedField(vcl::Window* pParent, WinBits nStyle) : SpinField(pParent, nStyle, WindowType::FORMATTEDFIELD) + , m_pFormatter(nullptr) { } void FormattedField::dispose() { - m_xFormatter.reset(); + m_pFormatter = nullptr; + m_xOwnFormatter.reset(); SpinField::dispose(); } @@ -1300,22 +1305,26 @@ bool FormattedField::EventNotify(NotifyEvent& rNEvt) } } - if (rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS && m_xFormatter) - m_xFormatter->EntryLostFocus(); + if (rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS && m_pFormatter) + m_pFormatter->EntryLostFocus(); return SpinField::EventNotify( rNEvt ); } Formatter& FormattedField::GetFormatter() { - if (!m_xFormatter) - m_xFormatter.reset(new FieldFormatter(*this)); - return *m_xFormatter; + if (!m_pFormatter) + { + m_xOwnFormatter.reset(new FieldFormatter(*this)); + m_pFormatter = m_xOwnFormatter.get(); + } + return *m_pFormatter; } void FormattedField::SetFormatter(Formatter* pFormatter) { - m_xFormatter.reset(pFormatter); + m_xOwnFormatter.reset(); + m_pFormatter = pFormatter; } // currently used by online diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 375526d595a5..29199170b5f9 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -12192,7 +12192,8 @@ class GtkInstanceFormattedSpinButton : public GtkInstanceEntry, public virtual w { private: GtkSpinButton* m_pButton; - std::unique_ptr<weld::EntryFormatter> m_xFormatter; + std::unique_ptr<weld::EntryFormatter> m_xOwnFormatter; + weld::EntryFormatter* m_pFormatter; gulong m_nValueChangedSignalId; gulong m_nOutputSignalId; gulong m_nInputSignalId; @@ -12252,6 +12253,7 @@ public: GtkInstanceFormattedSpinButton(GtkSpinButton* pButton, GtkInstanceBuilder* pBuilder, bool bTakeOwnership) : GtkInstanceEntry(GTK_ENTRY(pButton), pBuilder, bTakeOwnership) , m_pButton(pButton) + , m_pFormatter(nullptr) , m_nValueChangedSignalId(g_signal_connect(pButton, "value-changed", G_CALLBACK(signalValueChanged), this)) , m_nOutputSignalId(g_signal_connect(pButton, "output", G_CALLBACK(signalOutput), this)) , m_nInputSignalId(g_signal_connect(pButton, "input", G_CALLBACK(signalInput), this)) @@ -12271,27 +12273,28 @@ public: virtual void connect_changed(const Link<weld::Entry&, void>& rLink) override { - if (!m_xFormatter) // once a formatter is set, it takes over "changed" + if (!m_pFormatter) // once a formatter is set, it takes over "changed" { GtkInstanceEntry::connect_changed(rLink); return; } - m_xFormatter->connect_changed(rLink); + m_pFormatter->connect_changed(rLink); } virtual void connect_focus_out(const Link<weld::Widget&, void>& rLink) override { - if (!m_xFormatter) // once a formatter is set, it takes over "focus-out" + if (!m_pFormatter) // once a formatter is set, it takes over "focus-out" { GtkInstanceEntry::connect_focus_out(rLink); return; } - m_xFormatter->connect_focus_out(rLink); + m_pFormatter->connect_focus_out(rLink); } virtual void SetFormatter(weld::EntryFormatter* pFormatter) override { - m_xFormatter.reset(pFormatter); + m_xOwnFormatter.reset(); + m_pFormatter = pFormatter; sync_range_from_formatter(); sync_value_from_formatter(); sync_increments_from_formatter(); @@ -12299,7 +12302,7 @@ public: virtual weld::EntryFormatter& GetFormatter() override { - if (!m_xFormatter) + if (!m_pFormatter) { auto aFocusOutHdl = m_aFocusOutHdl; m_aFocusOutHdl = Link<weld::Widget&, void>(); @@ -12311,38 +12314,46 @@ public: gtk_spin_button_get_range(m_pButton, &fMin, &fMax); double fStep; gtk_spin_button_get_increments(m_pButton, &fStep, nullptr); - m_xFormatter.reset(new weld::EntryFormatter(*this)); - m_xFormatter->SetMinValue(fMin); - m_xFormatter->SetMaxValue(fMax); - m_xFormatter->SetSpinSize(fStep); - m_xFormatter->SetValue(fValue); + m_xOwnFormatter.reset(new weld::EntryFormatter(*this)); + m_xOwnFormatter->SetMinValue(fMin); + m_xOwnFormatter->SetMaxValue(fMax); + m_xOwnFormatter->SetSpinSize(fStep); + m_xOwnFormatter->SetValue(fValue); - m_xFormatter->connect_focus_out(aFocusOutHdl); - m_xFormatter->connect_changed(aChangeHdl); + m_xOwnFormatter->connect_focus_out(aFocusOutHdl); + m_xOwnFormatter->connect_changed(aChangeHdl); + + m_pFormatter = m_xOwnFormatter.get(); } - return *m_xFormatter; + return *m_pFormatter; } virtual void sync_value_from_formatter() override { + if (!m_pFormatter) + return; disable_notify_events(); - gtk_spin_button_set_value(m_pButton, m_xFormatter->GetValue()); + gtk_spin_button_set_value(m_pButton, m_pFormatter->GetValue()); enable_notify_events(); } virtual void sync_range_from_formatter() override { + if (!m_pFormatter) + return; disable_notify_events(); - double fMin = m_xFormatter->HasMinValue() ? m_xFormatter->GetMinValue() : std::numeric_limits<double>::lowest(); - double fMax = m_xFormatter->HasMaxValue() ? m_xFormatter->GetMaxValue() : std::numeric_limits<double>::max(); + double fMin = m_pFormatter->HasMinValue() ? m_pFormatter->GetMinValue() : std::numeric_limits<double>::lowest(); + double fMax = m_pFormatter->HasMaxValue() ? m_pFormatter->GetMaxValue() : std::numeric_limits<double>::max(); gtk_spin_button_set_range(m_pButton, fMin, fMax); enable_notify_events(); } virtual void sync_increments_from_formatter() override { + if (!m_pFormatter) + return; disable_notify_events(); - double fSpinSize = m_xFormatter->GetSpinSize(); + double fSpinSize = m_pFormatter->GetSpinSize(); gtk_spin_button_set_increments(m_pButton, fSpinSize, fSpinSize * 10); enable_notify_events(); } |