From b12961f992b180d5e394d3bd0d6a6d4a2e579421 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Aug 2021 23:15:49 +0200 Subject: [PATCH] Display locale information directly in the main sample frame This is more convenient than having to open the "About" dialog to see the details of the locale being used. It also makes it unnecessary to store wxLocale reference in the frame class, simplifying the sample code. --- samples/internat/internat.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/samples/internat/internat.cpp b/samples/internat/internat.cpp index 82e80f9e98..21abd20e1c 100644 --- a/samples/internat/internat.cpp +++ b/samples/internat/internat.cpp @@ -100,8 +100,6 @@ public: void OnTestMsgBox(wxCommandEvent& event); wxDECLARE_EVENT_TABLE(); - - wxLocale& m_locale; }; // ---------------------------------------------------------------------------- @@ -290,8 +288,7 @@ bool MyApp::OnInit() MyFrame::MyFrame(wxLocale& locale) : wxFrame(NULL, wxID_ANY, - _("International wxWidgets App")), - m_locale(locale) + _("International wxWidgets App")) { SetIcon(wxICON(sample)); @@ -353,9 +350,20 @@ MyFrame::MyFrame(wxLocale& locale) wxPanel* const panel = new wxPanel(this); - // create some controls affected by the locale wxSizer* const topSizer = new wxBoxSizer(wxVERTICAL); + wxString localeInfo; + wxString locale = locale.GetLocale(); + wxString sysname = locale.GetSysName(); + wxString canname = locale.GetCanonicalName(); + localeInfo.Printf("Current locale: %s (system name: %s, canonical name: %s)", + locale, sysname, canname ); + + topSizer->Add(new wxStaticText(panel, wxID_ANY, localeInfo), + wxSizerFlags().Center().Border()); + + // create some controls affected by the locale + // this demonstrates RTL layout mirroring for Arabic locales and using // locale-specific decimal separator in wxSpinCtrlDouble. wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); @@ -400,20 +408,10 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { - wxString localeInfo; - wxString locale = m_locale.GetLocale(); - wxString sysname = m_locale.GetSysName(); - wxString canname = m_locale.GetCanonicalName(); - - localeInfo.Printf(_("Language: %s\nSystem locale name: %s\nCanonical locale name: %s\n"), - locale, sysname, canname ); - wxMessageDialog dlg( this, - wxString(_("I18n sample\n(c) 1998, 1999 Vadim Zeitlin and Julian Smart")) - + "\n\n" - + localeInfo, - _("About Internat"), + _("I18n sample\n(c) 1998, 1999 Vadim Zeitlin and Julian Smart"), + _("About Internat"), wxOK | wxICON_INFORMATION ); dlg.ShowModal();