From 426e4593c7703bcc4c7398ba6deda1bdd33654d8 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sat, 29 Dec 2012 16:53:30 -0800 Subject: [PATCH] Fix a bunch of incorrect implicit wxString <-> std::string conversions The implicit conversion assumes that std::string is encoded in the local charset, while it's always actually UTF-8. --- aegisub/src/audio_karaoke.cpp | 2 +- aegisub/src/auto4_lua.cpp | 2 +- aegisub/src/charset_detect.cpp | 2 +- aegisub/src/dialog_export.cpp | 20 ++++++++++++-------- aegisub/src/dialog_export.h | 12 ++++-------- aegisub/src/dialog_spellchecker.cpp | 2 +- aegisub/src/font_file_lister.cpp | 4 ++-- aegisub/src/main.cpp | 2 +- aegisub/src/preferences.cpp | 4 +--- aegisub/src/preferences_base.cpp | 4 ++-- aegisub/src/subs_edit_ctrl.cpp | 2 +- aegisub/src/toolbar.cpp | 3 ++- aegisub/src/tooltip_manager.cpp | 6 +++--- aegisub/src/video_context.cpp | 2 +- 14 files changed, 33 insertions(+), 34 deletions(-) diff --git a/aegisub/src/audio_karaoke.cpp b/aegisub/src/audio_karaoke.cpp index 5ea4939e3..5c551d438 100644 --- a/aegisub/src/audio_karaoke.cpp +++ b/aegisub/src/audio_karaoke.cpp @@ -90,7 +90,7 @@ AudioKaraoke::AudioKaraoke(wxWindow *parent, agi::Context *c) SetSizerAndFit(main_sizer); /// @todo subscribe - split_font.SetFaceName(OPT_GET("Audio/Karaoke/Font Face")->GetString()); + split_font.SetFaceName(to_wx(OPT_GET("Audio/Karaoke/Font Face")->GetString())); split_font.SetPointSize(OPT_GET("Audio/Karaoke/Font Size")->GetInt()); split_area->Bind(wxEVT_SIZE, &AudioKaraoke::OnSize, this); diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 68310032d..a12b97538 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -498,7 +498,7 @@ namespace Automation4 { catch (agi::Exception const& e) { Destroy(); name = GetPrettyFilename(); - description = e.GetChainedMessage(); + description = to_wx(e.GetChainedMessage()); } } diff --git a/aegisub/src/charset_detect.cpp b/aegisub/src/charset_detect.cpp index dcf0e14d9..6bdf4371b 100644 --- a/aegisub/src/charset_detect.cpp +++ b/aegisub/src/charset_detect.cpp @@ -61,7 +61,7 @@ wxString GetEncoding(wxString const& filename) { if (list.size() == 1) { auto charset = list.begin(); LOG_I("charset/file") << filename << " (" << charset->second << ")"; - return charset->second; + return to_wx(charset->second); } wxArrayString choices; diff --git a/aegisub/src/dialog_export.cpp b/aegisub/src/dialog_export.cpp index 4b3147e1b..117a7eefb 100644 --- a/aegisub/src/dialog_export.cpp +++ b/aegisub/src/dialog_export.cpp @@ -34,22 +34,27 @@ #include "config.h" -#include -#include -#include -#include -#include - #include "dialog_export.h" #include "ass_exporter.h" #include "ass_file.h" +#include "compat.h" #include "include/aegisub/context.h" #include "charset_conv.h" #include "help_button.h" #include "libresrc/libresrc.h" #include "subtitle_format.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + // Swap the items at idx and idx + 1 static void swap(wxCheckListBox *list, int idx, int sel_dir) { if (idx < 0 || idx + 1 == (int)list->GetCount()) return; @@ -65,7 +70,6 @@ static void swap(wxCheckListBox *list, int idx, int sel_dir) { list->Thaw(); } - DialogExport::DialogExport(agi::Context *c) : wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX) , c(c) @@ -178,7 +182,7 @@ void DialogExport::OnProcess(wxCommandEvent &) { wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this); } catch (agi::Exception const& err) { - wxMessageBox(err.GetMessage(), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this); + wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this); } catch (...) { wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this); diff --git a/aegisub/src/dialog_export.h b/aegisub/src/dialog_export.h index 952319701..1f08ae4fb 100644 --- a/aegisub/src/dialog_export.h +++ b/aegisub/src/dialog_export.h @@ -32,20 +32,16 @@ /// @ingroup export /// -#include - -#include -#include #include -#include -#include -#include -#include #include class AssExporter; namespace agi { struct Context; } +class wxCheckListBox; +class wxChoice; +class wxSizer; +class wxTextCtrl; class DialogExport : public wxDialog { agi::Context *c; diff --git a/aegisub/src/dialog_spellchecker.cpp b/aegisub/src/dialog_spellchecker.cpp index 77e872298..2f79aacf7 100644 --- a/aegisub/src/dialog_spellchecker.cpp +++ b/aegisub/src/dialog_spellchecker.cpp @@ -277,7 +277,7 @@ bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int } text.replace(word_start, word_len, auto_rep->second); - active_line->Text = from_wx(text); + active_line->Text = to_wx(text); *commit_id = context->ass->Commit(_("spell check replace"), AssFile::COMMIT_DIAG_TEXT, *commit_id); word_start += auto_rep->second.size(); } diff --git a/aegisub/src/font_file_lister.cpp b/aegisub/src/font_file_lister.cpp index 50875efa5..3182d3a7c 100644 --- a/aegisub/src/font_file_lister.cpp +++ b/aegisub/src/font_file_lister.cpp @@ -56,7 +56,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { for (auto& block : blocks) { if (AssDialogueBlockOverride *ovr = dynamic_cast(&block)) { for (auto const& tag : ovr->Tags) { - wxString name = tag.Name; + std::string const& name = tag.Name; if (name == "\\r") { style = styles[tag.Params[0].Get(line->Style)]; @@ -77,7 +77,7 @@ void FontCollector::ProcessDialogueLine(const AssDialogue *line, int index) { } } else if (AssDialogueBlockPlain *txt = dynamic_cast(&block)) { - wxString text = txt->GetText(); + wxString text(to_wx(txt->GetText())); if (text.empty() || (text.size() >= 2 && text.StartsWith("{") && text.EndsWith("}"))) continue; diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 861dfc10c..263fab0bb 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -270,7 +270,7 @@ bool AegisubApp::OnInit() { return false; } catch (agi::Exception const& e) { - wxMessageBox(e.GetMessage(),"Fatal error while initializing"); + wxMessageBox(to_wx(e.GetMessage()),"Fatal error while initializing"); return false; } diff --git a/aegisub/src/preferences.cpp b/aegisub/src/preferences.cpp index 9fdb6b25c..e067feca2 100644 --- a/aegisub/src/preferences.cpp +++ b/aegisub/src/preferences.cpp @@ -268,10 +268,8 @@ class CommandRenderer : public wxDataViewCustomRenderer { public: CommandRenderer() : wxDataViewCustomRenderer("wxDataViewIconText", wxDATAVIEW_CELL_EDITABLE) + , autocomplete(to_wx(cmd::get_registered_commands())) { - std::vector cmd_names = cmd::get_registered_commands(); - autocomplete.reserve(cmd_names.size()); - copy(cmd_names.begin(), cmd_names.end(), std::back_inserter(autocomplete)); } wxWindow *CreateEditorCtrl(wxWindow *parent, wxRect label_rect, wxVariant const& value) { diff --git a/aegisub/src/preferences_base.cpp b/aegisub/src/preferences_base.cpp index d91414360..ec77942ee 100644 --- a/aegisub/src/preferences_base.cpp +++ b/aegisub/src/preferences_base.cpp @@ -218,7 +218,7 @@ void OptionPage::OptionBrowse(wxFlexGridSizer *flex, const wxString &name, const if (opt->GetType() != agi::OptionValue::Type_String) throw PreferenceIncorrectType("Option must be agi::OptionValue::Type_String for BrowseButton."); - wxTextCtrl *text = new wxTextCtrl(this, -1 , opt->GetString()); + wxTextCtrl *text = new wxTextCtrl(this, -1 , to_wx(opt->GetString())); text->SetMinSize(wxSize(160, -1)); text->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(opt_name, parent)); @@ -250,7 +250,7 @@ void OptionPage::OptionFont(wxSizer *sizer, std::string opt_prefix) { parent->AddChangeableOption(face_opt->GetName()); parent->AddChangeableOption(size_opt->GetName()); - wxTextCtrl *font_name = new wxTextCtrl(this, -1, face_opt->GetString()); + wxTextCtrl *font_name = new wxTextCtrl(this, -1, to_wx(face_opt->GetString())); font_name->SetMinSize(wxSize(160, -1)); font_name->Bind(wxEVT_COMMAND_TEXT_UPDATED, StringUpdater(face_opt->GetName().c_str(), parent)); diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index 9ecf0e13e..af64ad997 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -443,7 +443,7 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) { std::string suggestion; int sugIdx = event.GetId() - EDIT_MENU_THESAURUS_SUGS; if (sugIdx >= 0) - suggestion = from_wx(thesSugs[sugIdx]); + suggestion = thesSugs[sugIdx]; else suggestion = sugs[event.GetId() - EDIT_MENU_SUGGESTIONS]; diff --git a/aegisub/src/toolbar.cpp b/aegisub/src/toolbar.cpp index 4cf02318a..5cd6e1eed 100644 --- a/aegisub/src/toolbar.cpp +++ b/aegisub/src/toolbar.cpp @@ -21,6 +21,7 @@ #include "include/aegisub/toolbar.h" #include "command/command.h" +#include "compat.h" #include "include/aegisub/context.h" #include "include/aegisub/hotkey.h" #include "libresrc/libresrc.h" @@ -156,7 +157,7 @@ namespace { std::vector hotkeys = hotkey::get_hotkey_strs(ht_context, command->name()); if (!hotkeys.empty()) - ret += " (" + boost::join(hotkeys, "/") + ")"; + ret += to_wx(" (" + boost::join(hotkeys, "/") + ")"); return ret; } diff --git a/aegisub/src/tooltip_manager.cpp b/aegisub/src/tooltip_manager.cpp index a739b56fd..89b21117b 100644 --- a/aegisub/src/tooltip_manager.cpp +++ b/aegisub/src/tooltip_manager.cpp @@ -36,13 +36,13 @@ #include "tooltip_manager.h" +#include "compat.h" #include "include/aegisub/hotkey.h" #include -#include - #include +#include struct ToolTipBinding { wxWeakRef window; @@ -96,6 +96,6 @@ void ToolTipBinding::Update() { window->SetToolTip(toolTip); } else { - window->SetToolTip(toolTip + " (" + str + ")"); + window->SetToolTip(toolTip + to_wx(" (" + str + ")")); } } diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index f60c50cbe..a79490690 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -420,7 +420,7 @@ void VideoContext::LoadKeyframes(wxString filename) { config::mru->Add("Keyframes", from_wx(filename)); } catch (agi::keyframe::Error const& err) { - wxMessageBox(err.GetMessage(), "Error opening keyframes file", wxOK | wxICON_ERROR | wxCENTER, context->parent); + wxMessageBox(to_wx(err.GetMessage()), "Error opening keyframes file", wxOK | wxICON_ERROR | wxCENTER, context->parent); config::mru->Remove("Keyframes", from_wx(filename)); } catch (agi::FileSystemError const&) {