diff --git a/build/Aegisub/Aegisub.vcxproj b/build/Aegisub/Aegisub.vcxproj index d65900d02..718bf1010 100644 --- a/build/Aegisub/Aegisub.vcxproj +++ b/build/Aegisub/Aegisub.vcxproj @@ -184,7 +184,6 @@ - @@ -376,7 +375,6 @@ - diff --git a/build/Aegisub/Aegisub.vcxproj.filters b/build/Aegisub/Aegisub.vcxproj.filters index fac782817..8e7224267 100644 --- a/build/Aegisub/Aegisub.vcxproj.filters +++ b/build/Aegisub/Aegisub.vcxproj.filters @@ -390,9 +390,6 @@ Main UI\Grid - - Main UI\Edit box - Main UI\Grid @@ -926,9 +923,6 @@ Main UI\Grid - - Main UI\Edit box - Main UI\Edit box diff --git a/src/Makefile b/src/Makefile index e6d056023..90c09b12b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -208,7 +208,6 @@ SRC += \ preferences_base.cpp \ project.cpp \ resolution_resampler.cpp \ - scintilla_text_ctrl.cpp \ search_replace_engine.cpp \ selection_controller.cpp \ spellchecker.cpp \ diff --git a/src/dialog_fonts_collector.cpp b/src/dialog_fonts_collector.cpp index 86938a7ee..ed012837f 100644 --- a/src/dialog_fonts_collector.cpp +++ b/src/dialog_fonts_collector.cpp @@ -24,7 +24,6 @@ #include "include/aegisub/context.h" #include "libresrc/libresrc.h" #include "options.h" -#include "scintilla_text_ctrl.h" #include "utils.h" #include @@ -52,7 +51,7 @@ namespace { class DialogFontsCollector final : public wxDialog { AssFile *subs; - ScintillaTextCtrl *collection_log; + wxStyledTextCtrl *collection_log; wxButton *close_btn; wxButton *dest_browse_button; wxButton *start_btn; @@ -250,7 +249,7 @@ DialogFontsCollector::DialogFontsCollector(agi::Context *c) destination_box->Add(dest_browse_sizer, wxSizerFlags().Expand()); wxStaticBoxSizer *log_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Log")); - collection_log = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(600, 300)); + collection_log = new wxStyledTextCtrl(this, -1, wxDefaultPosition, wxSize(600, 300)); collection_log->SetWrapMode(wxSTC_WRAP_WORD); collection_log->SetMarginWidth(1, 0); collection_log->SetReadOnly(true); @@ -384,13 +383,14 @@ void DialogFontsCollector::OnRadio(wxCommandEvent &) { void DialogFontsCollector::OnAddText(wxThreadEvent &event) { std::pair str = event.GetPayload>(); collection_log->SetReadOnly(false); - int pos = collection_log->GetReverseUnicodePosition(collection_log->GetLength()); - collection_log->AppendText(str.second); + int pos = collection_log->GetLength(); + auto const& utf8 = str.second.utf8_str(); + collection_log->AppendTextRaw(utf8.data(), utf8.length()); if (str.first) { - collection_log->StartUnicodeStyling(pos, 31); - collection_log->SetUnicodeStyling(pos, str.second.size(), str.first); + collection_log->StartStyling(pos, 31); + collection_log->SetStyling(utf8.length(), str.first); } - collection_log->GotoPos(pos); + collection_log->GotoPos(pos + utf8.length()); collection_log->SetReadOnly(true); } diff --git a/src/dialog_translation.cpp b/src/dialog_translation.cpp index e8bdf77cf..b9b59d928 100644 --- a/src/dialog_translation.cpp +++ b/src/dialog_translation.cpp @@ -41,12 +41,14 @@ #include #include +#include #include #include #include #include #include +#include static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wxString const& text) { sizer->Add(new wxStaticText(parent, -1, text)); @@ -77,7 +79,7 @@ DialogTranslation::DialogTranslation(agi::Context *c) line_number_display = new wxStaticText(this, -1, ""); original_box->Add(line_number_display, 0, wxBOTTOM, 5); - original_text = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(320, 80)); + original_text = new wxStyledTextCtrl(this, -1, wxDefaultPosition, wxSize(320, 80)); original_text->SetWrapMode(wxSTC_WRAP_WORD); original_text->SetMarginWidth(1, 0); original_text->StyleSetForeground(1, wxColour(10, 60, 200)); @@ -163,8 +165,7 @@ DialogTranslation::DialogTranslation(agi::Context *c) UpdateDisplay(); } -DialogTranslation::~DialogTranslation() { -} +DialogTranslation::~DialogTranslation() { } void DialogTranslation::OnActiveLineChanged(AssDialogue *new_line) { if (switching_lines) return; @@ -243,9 +244,8 @@ void DialogTranslation::UpdateDisplay() { int initial_pos = original_text->GetLength(); original_text->AppendTextRaw(block->GetText().c_str()); if (i == cur_block) { - int cur_size = original_text->GetReverseUnicodePosition(initial_pos); - original_text->StartUnicodeStyling(cur_size); - original_text->SetUnicodeStyling(cur_size, block->GetText().size(), 1); + original_text->StartStyling(initial_pos, 31); + original_text->SetStyling(block->GetText().size(), 1); } } else @@ -262,11 +262,11 @@ void DialogTranslation::UpdateDisplay() { } void DialogTranslation::Commit(bool next) { - wxString new_value = translated_text->GetValue(); - new_value.Replace("\r\n", "\\N"); - new_value.Replace("\r", "\\N"); - new_value.Replace("\n", "\\N"); - *blocks[cur_block] = AssDialogueBlockPlain(from_wx(new_value)); + std::string new_value = translated_text->GetTextRaw().data(); + boost::replace_all(new_value, "\r\n", "\\N"); + boost::replace_all(new_value, "\r", "\\N"); + boost::replace_all(new_value, "\n", "\\N"); + *blocks[cur_block] = AssDialogueBlockPlain(new_value); active_line->UpdateText(blocks); file_change_connection.Block(); @@ -285,7 +285,8 @@ void DialogTranslation::Commit(bool next) { } void DialogTranslation::InsertOriginal() { - translated_text->AddText(to_wx(blocks[cur_block]->GetText())); + auto const& text = blocks[cur_block]->GetText(); + translated_text->AddTextRaw(text.data(), text.size()); } void DialogTranslation::OnKeyDown(wxKeyEvent &evt) { diff --git a/src/dialog_translation.h b/src/dialog_translation.h index c18ba9939..9901c1186 100644 --- a/src/dialog_translation.h +++ b/src/dialog_translation.h @@ -14,10 +14,6 @@ // // Aegisub Project http://www.aegisub.org/ -/// @file dialog_translation.h -/// @see dialog_translation.cpp -/// @ingroup tools_ui - #include #include @@ -29,10 +25,10 @@ namespace agi { struct Context; } class AssDialogue; class AssDialogueBlock; class PersistLocation; -class ScintillaTextCtrl; class SubsTextEditCtrl; -class wxStaticText; class wxCheckBox; +class wxStaticText; +class wxStyledTextCtrl; /// Assistant for translating subtitles in one language to another language class DialogTranslation final : public wxDialog { @@ -55,7 +51,7 @@ class DialogTranslation final : public wxDialog { bool switching_lines = false; wxStaticText *line_number_display; - ScintillaTextCtrl *original_text; + wxStyledTextCtrl *original_text; SubsTextEditCtrl *translated_text; wxCheckBox *seek_video; diff --git a/src/scintilla_text_ctrl.cpp b/src/scintilla_text_ctrl.cpp deleted file mode 100644 index 0c52eb097..000000000 --- a/src/scintilla_text_ctrl.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2007, Rodrigo Braz Monteiro -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of the Aegisub Group nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Aegisub Project http://www.aegisub.org/ - -/// @file scintilla_text_ctrl.cpp -/// @brief Customised version of wxStyledTextControl used for main edit box -/// @ingroup custom_control -/// - -#include "scintilla_text_ctrl.h" -#include "utils.h" - -ScintillaTextCtrl::ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) -: wxStyledTextCtrl(parent, id, pos, size, style, value) -{ - Bind(wxEVT_MOUSEWHEEL, &ScintillaTextCtrl::OnMouseWheel, this); -} - -/// @brief Get unicode-compatible position -int ScintillaTextCtrl::GetUnicodePosition(int pos) { - return GetText().Left(pos).utf8_str().length(); -} - -/// @brief Reverse unicode-compatible position -int ScintillaTextCtrl::GetReverseUnicodePosition(int pos) { - wxCharBuffer buffer = GetTextRaw(); - return wxString::FromUTF8(buffer.data(), std::min(pos, buffer.length())).length(); -} - -/// @brief Start unicode-safe styling -void ScintillaTextCtrl::StartUnicodeStyling(int start,int mask) { - StartStyling(GetUnicodePosition(start),mask); - // Cache the text for styling as GetText is hideously slow - text = GetText(); -} - -/// @brief Unicode-safe styling -void ScintillaTextCtrl::SetUnicodeStyling(int start,int length,int style) { - // Get the real length - int len = text.Mid(start, length).utf8_str().length(); - - SetStyling(len,style); -} - -void ScintillaTextCtrl::OnMouseWheel(wxMouseEvent& evt) { - if (ForwardMouseWheelEvent(this, evt)) { - // Skip the event so that wxSTC's default mouse wheel handler is hit - evt.Skip(); - } -} diff --git a/src/scintilla_text_ctrl.h b/src/scintilla_text_ctrl.h deleted file mode 100644 index e8ed68f29..000000000 --- a/src/scintilla_text_ctrl.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2007, Rodrigo Braz Monteiro -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither the name of the Aegisub Group nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Aegisub Project http://www.aegisub.org/ - -#include - -class ScintillaTextCtrl : public wxStyledTextCtrl { - wxString text; - - void OnMouseWheel(wxMouseEvent& evt); -public: - int GetUnicodePosition(int pos); - int GetReverseUnicodePosition(int pos); - - void StartUnicodeStyling(int start,int mask=31); - void SetUnicodeStyling(int start,int length,int style); - - ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxString(), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); -}; diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index 9177659dc..33f77cd85 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -27,11 +27,6 @@ // // Aegisub Project http://www.aegisub.org/ -/// @file subs_edit_ctrl.cpp -/// @brief Main subtitle editing text control -/// @ingroup main_ui -/// - #include "subs_edit_ctrl.h" #include "ass_dialogue.h" @@ -82,7 +77,7 @@ enum { }; SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, agi::Context *context) -: ScintillaTextCtrl(parent, -1, "", wxDefaultPosition, wsize, style) +: wxStyledTextCtrl(parent, -1, wxDefaultPosition, wsize, style) , spellchecker(SpellCheckerFactory::GetSpellChecker()) , thesaurus(agi::make_unique()) , context(context) diff --git a/src/subs_edit_ctrl.h b/src/subs_edit_ctrl.h index 6574501c6..8385a15ff 100644 --- a/src/subs_edit_ctrl.h +++ b/src/subs_edit_ctrl.h @@ -27,11 +27,10 @@ // // Aegisub Project http://www.aegisub.org/ -#include "scintilla_text_ctrl.h" - #include #include #include +#include class Thesaurus; namespace agi { @@ -43,7 +42,7 @@ namespace agi { /// @class SubsTextEditCtrl /// @brief A Scintilla control with spell checking and syntax highlighting -class SubsTextEditCtrl final : public ScintillaTextCtrl { +class SubsTextEditCtrl final : public wxStyledTextCtrl { /// Backend spellchecker to use std::unique_ptr spellchecker;