Skip to content

Commit

Permalink
Implement SubsTextEditCtrl based on wxTextCtrl
Browse files Browse the repository at this point in the history
Previous wxSTC-based SubsTextEditCtrl renamed to SubsStyledTextEditCtrl
  • Loading branch information
wangqr committed Apr 4, 2021
1 parent 477579b commit 99fee26
Show file tree
Hide file tree
Showing 10 changed files with 767 additions and 528 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ add_executable(Aegisub WIN32
src/string_codec.cpp
src/subs_controller.cpp
src/subs_edit_box.cpp
src/subs_edit_ctrl.cpp
src/subs_preview.cpp
src/subtitles_provider.cpp
src/subtitles_provider_libass.cpp
Expand Down Expand Up @@ -524,7 +525,7 @@ find_package(wxWidgets REQUIRED adv base core gl stc xml)
option(WITH_WXSTC "Enable wxStyledTextCtrl support" ON)
if(WITH_WXSTC)
target_compile_definitions(Aegisub PRIVATE "WITH_WXSTC")
target_sources(Aegisub PRIVATE src/subs_edit_ctrl.cpp)
target_sources(Aegisub PRIVATE src/subs_edit_ctrl_stc.cpp)
endif()
include(${wxWidgets_USE_FILE})
target_link_libraries(Aegisub LINK_PRIVATE ${wxWidgets_LIBRARIES})
Expand Down
4 changes: 2 additions & 2 deletions src/dialog_translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "options.h"
#include "persist_location.h"
#include "project.h"
#include "subs_edit_ctrl.h"
#include "subs_edit_ctrl_stc.h"
#include "selection_controller.h"
#include "video_controller.h"

Expand Down Expand Up @@ -95,7 +95,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
}

{
translated_text_stc = new SubsTextEditCtrl(this, wxSize(320, 80), 0, nullptr);
translated_text_stc = new SubsStyledTextEditCtrl(this, wxSize(320, 80), 0, nullptr);
translated_text_stc->SetWrapMode(wxSTC_WRAP_WORD);
translated_text_stc->SetMarginWidth(1, 0);
translated_text_stc->SetFocus();
Expand Down
4 changes: 2 additions & 2 deletions src/dialog_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace agi { struct Context; }
class AssDialogue;
class AssDialogueBlock;
class PersistLocation;
class SubsTextEditCtrl;
class SubsStyledTextEditCtrl;
class wxCheckBox;
class wxStaticText;
class wxStyledTextCtrl;
Expand Down Expand Up @@ -54,7 +54,7 @@ class DialogTranslation final : public wxDialog {
wxStyledTextCtrl *original_text;
#ifdef WITH_WXSTC
const bool use_stc;
SubsTextEditCtrl *translated_text_stc;
SubsStyledTextEditCtrl *translated_text_stc;
#endif
wxTextCtrl* translated_text_tc;
wxCheckBox *seek_video;
Expand Down
2 changes: 2 additions & 0 deletions src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void Interface_Colours(wxTreebook *book, Preferences *parent) {
auto syntax = p->PageSizer(_("Syntax Highlighting"));
p->OptionAdd(syntax, _("Background"), "Colour/Subtitle/Background");
p->OptionAdd(syntax, _("Normal"), "Colour/Subtitle/Syntax/Normal");
#ifdef WITH_WXSTC
p->OptionAdd(syntax, _("Comments"), "Colour/Subtitle/Syntax/Comment");
p->OptionAdd(syntax, _("Drawings"), "Colour/Subtitle/Syntax/Drawing");
p->OptionAdd(syntax, _("Brackets"), "Colour/Subtitle/Syntax/Brackets");
Expand All @@ -272,6 +273,7 @@ void Interface_Colours(wxTreebook *book, Preferences *parent) {
p->OptionAdd(syntax, _("Line Break"), "Colour/Subtitle/Syntax/Line Break");
p->OptionAdd(syntax, _("Karaoke templates"), "Colour/Subtitle/Syntax/Karaoke Template");
p->OptionAdd(syntax, _("Karaoke variables"), "Colour/Subtitle/Syntax/Karaoke Variable");
#endif

p->sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->AddSpacer(5);
Expand Down
15 changes: 5 additions & 10 deletions src/subs_edit_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#include "placeholder_ctrl.h"
#include "selection_controller.h"
#include "subs_edit_ctrl.h"
#ifdef WITH_WXSTC
#include "subs_edit_ctrl_stc.h"
#endif
#include "text_selection_controller.h"
#include "timeedit_ctrl.h"
#include "tooltip_manager.h"
Expand Down Expand Up @@ -216,12 +219,12 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
// Text editor
#ifdef WITH_WXSTC
if (use_stc) {
edit_ctrl_stc = new SubsTextEditCtrl(this, wxDefaultSize, wxBORDER_SUNKEN, c);
edit_ctrl_stc = new SubsStyledTextEditCtrl(this, wxDefaultSize, wxBORDER_SUNKEN, c);
edit_ctrl_stc->Bind(wxEVT_CHAR_HOOK, &SubsEditBox::OnKeyDown, this);
}
else {
#endif
edit_ctrl_tc = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN | wxTE_MULTILINE);
edit_ctrl_tc = new SubsTextEditCtrl(this, wxDefaultSize, wxBORDER_SUNKEN | wxTE_MULTILINE, c);
edit_ctrl_tc->Bind(wxEVT_CHAR_HOOK, &SubsEditBox::OnKeyDown, this);
#ifdef WITH_WXSTC
}
Expand Down Expand Up @@ -313,14 +316,6 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
if (!fontname.empty()) font.SetFaceName(fontname);
font.SetPointSize(OPT_GET("Subtitle/Edit Box/Font Size")->GetInt());
secondary_editor->SetFont(font);
#ifdef WITH_WXSTC
if (!use_stc) {
#endif
edit_ctrl_tc->SetFont(font);
#ifdef WITH_WXSTC
}
#endif


bool show_original = OPT_GET("Subtitle/Show Original")->GetBool();
if (show_original) {
Expand Down
4 changes: 2 additions & 2 deletions src/subs_edit_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace agi { struct Context; }
namespace agi { class Time; }
class AssDialogue;
class AssStyle;
class SubsTextEditCtrl;
class SubsStyledTextEditCtrl;
class TimeEdit;
class wxButton;
class wxCheckBox;
Expand Down Expand Up @@ -201,7 +201,7 @@ class SubsEditBox final : public wxPanel {

#ifdef WITH_WXSTC
const bool use_stc;
SubsTextEditCtrl *edit_ctrl_stc;
SubsStyledTextEditCtrl *edit_ctrl_stc;
#endif
wxTextCtrl* edit_ctrl_tc;
wxTextCtrl *secondary_editor;
Expand Down
Loading

0 comments on commit 99fee26

Please sign in to comment.