From 6d6f5dbf8c8e39aa0cf641a932d4da12200160fe Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 3 Mar 2025 11:20:59 -0500 Subject: Handle unicode conversion between wx and rest of app --- src/connection_dialog.cpp | 39 +++++++++++++++++++++++---------------- src/connection_dialog.h | 6 +++--- src/ipc_dialog.cpp | 4 ++-- src/ipc_dialog.h | 2 +- src/tracker_frame.cpp | 2 +- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/connection_dialog.cpp b/src/connection_dialog.cpp index 64fee98..45a5b53 100644 --- a/src/connection_dialog.cpp +++ b/src/connection_dialog.cpp @@ -4,14 +4,17 @@ ConnectionDialog::ConnectionDialog() : wxDialog(nullptr, wxID_ANY, "Connect to Archipelago") { - server_box_ = - new wxTextCtrl(this, -1, GetTrackerConfig().connection_details.ap_server, - wxDefaultPosition, {300, -1}); - player_box_ = - new wxTextCtrl(this, -1, GetTrackerConfig().connection_details.ap_player, - wxDefaultPosition, {300, -1}); + server_box_ = new wxTextCtrl( + this, -1, + wxString::FromUTF8(GetTrackerConfig().connection_details.ap_server), + wxDefaultPosition, {300, -1}); + player_box_ = new wxTextCtrl( + this, -1, + wxString::FromUTF8(GetTrackerConfig().connection_details.ap_player), + wxDefaultPosition, {300, -1}); password_box_ = new wxTextCtrl( - this, -1, GetTrackerConfig().connection_details.ap_password, + this, -1, + wxString::FromUTF8(GetTrackerConfig().connection_details.ap_password), wxDefaultPosition, {300, -1}); wxFlexGridSizer* form_sizer = new wxFlexGridSizer(2, 10, 10); @@ -30,17 +33,19 @@ ConnectionDialog::ConnectionDialog() form_sizer->Add(password_box_, wxSizerFlags().Expand()); history_list_ = new wxListBox(this, -1); - for (const ConnectionDetails& details : GetTrackerConfig().connection_history) { + for (const ConnectionDetails& details : + GetTrackerConfig().connection_history) { wxString display_text; - display_text << details.ap_player; + display_text << wxString::FromUTF8(details.ap_player); display_text << " ("; - display_text << details.ap_server; + display_text << wxString::FromUTF8(details.ap_server); display_text << ")"; history_list_->Append(display_text); } - history_list_->Bind(wxEVT_LISTBOX, &ConnectionDialog::OnOldConnectionChosen, this); + history_list_->Bind(wxEVT_LISTBOX, &ConnectionDialog::OnOldConnectionChosen, + this); wxBoxSizer* mid_sizer = new wxBoxSizer(wxHORIZONTAL); mid_sizer->Add(form_sizer, wxSizerFlags().Proportion(3).Expand()); @@ -52,7 +57,8 @@ ConnectionDialog::ConnectionDialog() this, -1, "Enter the details to connect to Archipelago."), wxSizerFlags().Align(wxALIGN_LEFT).DoubleBorder()); top_sizer->Add(mid_sizer, wxSizerFlags().DoubleBorder().Expand()); - top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border().Center()); + top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), + wxSizerFlags().Border().Center()); SetSizerAndFit(top_sizer); @@ -62,9 +68,10 @@ ConnectionDialog::ConnectionDialog() void ConnectionDialog::OnOldConnectionChosen(wxCommandEvent& e) { if (e.IsSelection()) { - const ConnectionDetails& details = GetTrackerConfig().connection_history.at(e.GetSelection()); - server_box_->SetValue(details.ap_server); - player_box_->SetValue(details.ap_player); - password_box_->SetValue(details.ap_password); + const ConnectionDetails& details = + GetTrackerConfig().connection_history.at(e.GetSelection()); + server_box_->SetValue(wxString::FromUTF8(details.ap_server)); + player_box_->SetValue(wxString::FromUTF8(details.ap_player)); + password_box_->SetValue(wxString::FromUTF8(details.ap_password)); } } diff --git a/src/connection_dialog.h b/src/connection_dialog.h index 9fe62fd..ec2ee72 100644 --- a/src/connection_dialog.h +++ b/src/connection_dialog.h @@ -14,12 +14,12 @@ class ConnectionDialog : public wxDialog { public: ConnectionDialog(); - std::string GetServerValue() { return server_box_->GetValue().ToStdString(); } + std::string GetServerValue() { return server_box_->GetValue().utf8_string(); } - std::string GetPlayerValue() { return player_box_->GetValue().ToStdString(); } + std::string GetPlayerValue() { return player_box_->GetValue().utf8_string(); } std::string GetPasswordValue() { - return password_box_->GetValue().ToStdString(); + return password_box_->GetValue().utf8_string(); } private: diff --git a/src/ipc_dialog.cpp b/src/ipc_dialog.cpp index f17c2d8..1e09a2f 100644 --- a/src/ipc_dialog.cpp +++ b/src/ipc_dialog.cpp @@ -12,8 +12,8 @@ IpcDialog::IpcDialog() : wxDialog(nullptr, wxID_ANY, "Connect to game") { address_value = GetTrackerConfig().ipc_address; } - address_box_ = - new wxTextCtrl(this, -1, address_value, wxDefaultPosition, {300, -1}); + address_box_ = new wxTextCtrl(this, -1, wxString::FromUTF8(address_value), + wxDefaultPosition, {300, -1}); wxButton* reset_button = new wxButton(this, -1, "Use Default"); reset_button->Bind(wxEVT_BUTTON, &IpcDialog::OnResetClicked, this); diff --git a/src/ipc_dialog.h b/src/ipc_dialog.h index 1caed01..a8c4512 100644 --- a/src/ipc_dialog.h +++ b/src/ipc_dialog.h @@ -13,7 +13,7 @@ class IpcDialog : public wxDialog { public: IpcDialog(); - std::string GetIpcAddress() { return address_box_->GetValue().ToStdString(); } + std::string GetIpcAddress() { return address_box_->GetValue().utf8_string(); } private: void OnResetClicked(wxCommandEvent& event); diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index 587d87b..bacef34 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp @@ -317,7 +317,7 @@ void TrackerFrame::OnStateChanged(wxCommandEvent &event) { } void TrackerFrame::OnStatusChanged(wxCommandEvent &event) { - SetStatusText(GetStatusMessage()); + SetStatusText(wxString::FromUTF8(GetStatusMessage())); } void TrackerFrame::OnRedrawPosition(wxCommandEvent &event) { -- cgit 1.4.1