Skip to content

Commit d56bc80

Browse files
GraphicsPackWindow2: Use UTF8 (#802)
1 parent 1f16e99 commit d56bc80

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/gui/GraphicPacksWindow2.cpp

+21-18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "Cafe/CafeSystem.h"
1111
#include "Cafe/TitleList/TitleList.h"
1212

13+
#include "wxHelper.h"
14+
1315
#if BOOST_OS_LINUX || BOOST_OS_MACOS
1416
#include "resource/embedded/resources.h"
1517
#endif
@@ -89,10 +91,10 @@ void GraphicPacksWindow2::FillGraphicPackList() const
8991
const auto parent_node = node;
9092
if (i < (tokens.size() - 1))
9193
{
92-
node = FindTreeItem(parent_node, wxString(token.data(), token.length()));
94+
node = FindTreeItem(parent_node, wxHelper::FromUtf8(token));
9395
if (!node.IsOk())
9496
{
95-
node = m_graphic_pack_tree->AppendItem(parent_node, wxString(token.data(), token.length()));
97+
node = m_graphic_pack_tree->AppendItem(parent_node, wxHelper::FromUtf8(token));
9698
}
9799
}
98100
else
@@ -101,9 +103,9 @@ void GraphicPacksWindow2::FillGraphicPackList() const
101103
// if a node with same name already exists, add a number suffix
102104
for (sint32 s = 0; s < 999; s++)
103105
{
104-
wxString nodeName(token.data(), token.length());
106+
wxString nodeName = wxHelper::FromUtf8(token);
105107
if (s > 0)
106-
nodeName.append(fmt::format(" #{}", s + 1));
108+
nodeName.append(wxHelper::FromUtf8(fmt::format(" #{}", s + 1)));
107109

108110
node = FindTreeItem(parent_node, nodeName);
109111
if (!node.IsOk())
@@ -218,7 +220,7 @@ GraphicPacksWindow2::GraphicPacksWindow2(wxWindow* parent, uint64_t title_id_fil
218220
text->Wrap(-1);
219221
filter_row->Add(text, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
220222

221-
m_filter_text = new wxTextCtrl(left_panel, wxID_ANY, m_filter, wxDefaultPosition, wxDefaultSize, 0);
223+
m_filter_text = new wxTextCtrl(left_panel, wxID_ANY, wxHelper::FromUtf8(m_filter), wxDefaultPosition, wxDefaultSize, 0);
222224
filter_row->Add(m_filter_text, 0, wxALL | wxEXPAND, 5);
223225
m_filter_text->Bind(wxEVT_COMMAND_TEXT_UPDATED, &GraphicPacksWindow2::OnFilterUpdate, this);
224226

@@ -386,28 +388,29 @@ void GraphicPacksWindow2::LoadPresetSelections(const GraphicPackPtr& gp)
386388
{
387389
continue;
388390
}
389-
390-
wxString label(category.empty() ? _("Active preset") : wxString(category));
391+
392+
wxString categoryWxStr = wxHelper::FromUtf8(category);
393+
wxString label(category.empty() ? _("Active preset") : categoryWxStr);
391394
auto* box = new wxStaticBox(m_preset_sizer->GetContainingWindow(), wxID_ANY, label);
392395
auto* box_sizer = new wxStaticBoxSizer(box, wxVERTICAL);
393396

394397
auto* preset = new wxChoice(box, wxID_ANY);
395-
preset->SetClientObject(new wxStringClientData(category));
398+
preset->SetClientObject(new wxStringClientData(categoryWxStr));
396399
preset->Bind(wxEVT_CHOICE, &GraphicPacksWindow2::OnActivePresetChanged, this);
397400

398401
std::optional<std::string> active_preset;
399402
for (auto& pentry : entry)
400403
{
401404
if (!pentry->visible)
402405
continue;
403-
404-
preset->AppendString(pentry->name);
406+
407+
preset->AppendString(wxHelper::FromUtf8(pentry->name));
405408
if (pentry->active)
406409
active_preset = pentry->name;
407410
}
408411

409412
if (active_preset)
410-
preset->SetStringSelection(active_preset.value());
413+
preset->SetStringSelection(wxHelper::FromUtf8(active_preset.value()));
411414
else if (preset->GetCount() > 0)
412415
preset->SetSelection(0);
413416

@@ -439,14 +442,14 @@ void GraphicPacksWindow2::OnTreeSelectionChanged(wxTreeEvent& event)
439442
{
440443
m_preset_sizer->Clear(true);
441444
m_gp_name = gp->GetName();
442-
m_graphic_pack_name->SetLabel(m_gp_name);
445+
m_graphic_pack_name->SetLabel(wxHelper::FromUtf8(m_gp_name));
443446

444447
if (gp->GetDescription().empty())
445448
m_gp_description = _("This graphic pack has no description");
446449
else
447450
m_gp_description = gp->GetDescription();
448451

449-
m_graphic_pack_description->SetLabel(m_gp_description);
452+
m_graphic_pack_description->SetLabel(wxHelper::FromUtf8(m_gp_description));
450453

451454
LoadPresetSelections(gp);
452455

@@ -567,8 +570,8 @@ void GraphicPacksWindow2::OnActivePresetChanged(wxCommandEvent& event)
567570
wxASSERT(obj);
568571
const auto string_data = dynamic_cast<wxStringClientData*>(obj->GetClientObject());
569572
wxASSERT(string_data);
570-
const auto preset = obj->GetStringSelection().ToStdString();
571-
if(m_shown_graphic_pack->SetActivePreset(string_data->GetData().c_str().AsChar(), preset))
573+
const auto preset = wxHelper::MakeUTF8(obj->GetStringSelection());
574+
if(m_shown_graphic_pack->SetActivePreset(wxHelper::MakeUTF8(string_data->GetData()), preset))
572575
{
573576
wxWindowUpdateLocker lock(this);
574577
ClearPresets();
@@ -642,10 +645,10 @@ void GraphicPacksWindow2::OnSizeChanged(wxSizeEvent& event)
642645
obj->SetSashPosition((sint32)(m_ratio * width));
643646

644647
if (!m_gp_name.empty())
645-
m_graphic_pack_name->SetLabel(m_gp_name);
648+
m_graphic_pack_name->SetLabel(wxHelper::FromUtf8(m_gp_name));
646649

647650
if (!m_gp_description.empty())
648-
m_graphic_pack_description->SetLabel(m_gp_description);
651+
m_graphic_pack_description->SetLabel(wxHelper::FromUtf8(m_gp_description));
649652

650653
m_graphic_pack_name->Wrap(m_graphic_pack_name->GetParent()->GetClientSize().GetWidth() - 10);
651654
m_graphic_pack_description->Wrap(m_graphic_pack_description->GetParent()->GetClientSize().GetWidth() - 10);
@@ -665,7 +668,7 @@ void GraphicPacksWindow2::SashPositionChanged(wxEvent& event)
665668

666669
void GraphicPacksWindow2::OnFilterUpdate(wxEvent& event)
667670
{
668-
m_filter = m_filter_text->GetValue();
671+
m_filter = wxHelper::MakeUTF8(m_filter_text->GetValue());
669672
FillGraphicPackList();
670673
event.Skip();
671674
}

0 commit comments

Comments
 (0)