From 85d379913dfd6676fd79c0a113f6c2d0bc89c19b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Aug 2021 13:27:57 +0100 Subject: [PATCH] Use wxUILocale in wxSpinCtrlDouble This ensures that we use the decimal separator corresponding to the UI locale of the application, rather than C locale, so that e.g. comma is used under macOS even if setlocale() is not used. --- include/wx/generic/spinctlg.h | 2 -- src/generic/spinctlg.cpp | 7 +++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/wx/generic/spinctlg.h b/include/wx/generic/spinctlg.h index 64d9cb95c5..bba53839c9 100644 --- a/include/wx/generic/spinctlg.h +++ b/include/wx/generic/spinctlg.h @@ -427,8 +427,6 @@ private: void DoSetDigitsAndUpdate(unsigned digits); - wxString m_format; - wxDECLARE_DYNAMIC_CLASS(wxSpinCtrlDouble); }; diff --git a/src/generic/spinctlg.cpp b/src/generic/spinctlg.cpp index ae47212210..ff4a40e938 100644 --- a/src/generic/spinctlg.cpp +++ b/src/generic/spinctlg.cpp @@ -41,6 +41,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxSpinDoubleEvent, wxNotifyEvent); #if wxUSE_SPINBTN +#include "wx/numformatter.h" #include "wx/valnum.h" #include "wx/valtext.h" @@ -754,12 +755,12 @@ void wxSpinCtrlDouble::DoSendEvent() bool wxSpinCtrlDouble::DoTextToValue(const wxString& text, double *val) { - return text.ToDouble(val); + return wxNumberFormatter::FromString(text, val); } wxString wxSpinCtrlDouble::DoValueToText(double val) { - return wxString::Format(m_format, val); + return wxNumberFormatter::ToString(val, m_digits); } void wxSpinCtrlDouble::SetIncrement(double inc) @@ -802,8 +803,6 @@ void wxSpinCtrlDouble::DoSetDigitsAndUpdate(unsigned digits) void wxSpinCtrlDouble::DoSetDigits(unsigned digits) { m_digits = digits; - - m_format.Printf(wxT("%%0.%ulf"), digits); } void wxSpinCtrlDouble::ResetTextValidator()