From 6dfcbc0cd862d9ee5596951abc1746d62137c8ab Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 23 Jun 2007 00:25:03 +0000 Subject: [PATCH] Changed translation assistent to use Scintilla text controls to avoid several issues, including Right-To-Left text entry. Originally committed to SVN as r1291. --- aegisub/changelog.txt | 1 + aegisub/dialog_translation.cpp | 52 ++++++++++++++++----------------- aegisub/dialog_translation.h | 5 ++-- aegisub/scintilla_text_ctrl.cpp | 7 +++++ aegisub/scintilla_text_ctrl.h | 5 +++- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/aegisub/changelog.txt b/aegisub/changelog.txt index 4418ae832..6bd69377f 100644 --- a/aegisub/changelog.txt +++ b/aegisub/changelog.txt @@ -146,6 +146,7 @@ Please visit http://aegisub.net to download latest version - Fixed display of end frames on the subtitles grid, when set to frame mode. (demi) - Treat comments inside {}'s as plain text, not as overrides; Also, don't assume override blocks start with a backslash, even if they probably should (Dansolo) - Removed FexTracker due to licensing problems; there are plans to implement a new motion tracker in its place (jfs) +- Changed translation assistent to use Scintilla text controls to avoid several issues, including Right-To-Left text entry. = 1.10 beta - 2006.08.07 =========================== diff --git a/aegisub/dialog_translation.cpp b/aegisub/dialog_translation.cpp index 8e95346b0..a878befbb 100644 --- a/aegisub/dialog_translation.cpp +++ b/aegisub/dialog_translation.cpp @@ -62,13 +62,21 @@ DialogTranslation::DialogTranslation (wxWindow *parent,AssFile *_subs,SubtitlesG grid = _grid; audio = VideoContext::Get()->audio; + // Translation controls + OrigText = new ScintillaTextCtrl(this,TEXT_ORIGINAL,_T(""),wxDefaultPosition,wxSize(300,80)); + OrigText->SetWrapMode(wxSTC_WRAP_WORD); + OrigText->SetMarginWidth(1,0); + OrigText->StyleSetForeground(1,wxColour(10,60,200)); + OrigText->SetReadOnly(true); + //OrigText->PushEventHandler(new DialogTranslationEvent(this)); + TransText = new ScintillaTextCtrl(this,TEXT_TRANS,_T(""),wxDefaultPosition,wxSize(300,80)); + TransText->SetWrapMode(wxSTC_WRAP_WORD); + TransText->SetMarginWidth(1,0); + TransText->PushEventHandler(new DialogTranslationEvent(this)); + TransText->SetFocus(); + // Translation box wxSizer *TranslationSizer = new wxBoxSizer(wxVERTICAL); - OrigText = new wxTextCtrl(this,TEXT_ORIGINAL,_T(""),wxDefaultPosition,wxSize(300,80),wxTE_MULTILINE | wxTE_RICH | wxTE_READONLY); - TransText = new wxTextCtrl(this,TEXT_TRANS,_T(""),wxDefaultPosition,wxSize(300,80),wxTE_MULTILINE | wxTE_RICH2); - OrigText->SetEventHandler(new DialogTranslationEvent(this)); - TransText->SetEventHandler(new DialogTranslationEvent(this)); - TransText->SetFocus(); wxSizer *OriginalTransSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Original")); wxSizer *TranslatedSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Translation")); LineCount = new wxStaticText(this,-1,_("Current line: ?")); @@ -177,16 +185,9 @@ bool DialogTranslation::JumpToLine(int n,int block) { grid->editBox->SetToLine(curline); grid->EndBatch(); - // Set styles - wxTextAttr Normal(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); - wxTextAttr Highlight(wxColour(0,0,255)); - wxFont font = Normal.GetFont(); - font.SetPointSize(Options.AsInt(_T("Edit Font Size"))); - Normal.SetFont(font); - Highlight.SetFont(font); - // Adds blocks - OrigText->Clear(); + OrigText->SetReadOnly(false); + OrigText->ClearAll(); AssDialogueBlock *curBlock; bool found = false; int pos=-1; @@ -194,21 +195,18 @@ bool DialogTranslation::JumpToLine(int n,int block) { curBlock = *cur; if (curBlock->type == BLOCK_PLAIN) { pos++; + int curLen = OrigText->GetUnicodePosition(OrigText->GetLength()); + OrigText->AppendText(curBlock->text); if (pos == block) { - OrigText->SetDefaultStyle(Highlight); + OrigText->StartUnicodeStyling(curLen); + OrigText->SetUnicodeStyling(curLen,curBlock->text.Length(),1); found = true; } - else OrigText->SetDefaultStyle(Normal); } - else OrigText->SetDefaultStyle(Normal); - - if (curBlock->type == BLOCK_OVERRIDE) OrigText->AppendText(_T("{")); - OrigText->AppendText(curBlock->text); - if (curBlock->type == BLOCK_OVERRIDE) OrigText->AppendText(_T("}")); + else if (curBlock->type == BLOCK_OVERRIDE) OrigText->AppendText(_T("{") + curBlock->text + _T("}")); } - OrigText->SetDefaultStyle(Normal); - TransText->SetDefaultStyle(Normal); current->ClearBlocks(); + OrigText->SetReadOnly(true); return true; } @@ -276,7 +274,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { if (Hotkeys.IsPressed(_T("Translation Assistant Prev"))) { bool ok = JumpToLine(curline,curblock-1); if (ok) { - TransText->Clear(); + TransText->ClearAll(); TransText->SetFocus(); } @@ -288,7 +286,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { if (Hotkeys.IsPressed(_T("Translation Assistant Next")) || (Hotkeys.IsPressed(_T("Translation Assistant Accept")) && TransText->GetValue().IsEmpty())) { bool ok = JumpToLine(curline,curblock+1); if (ok) { - TransText->Clear(); + TransText->ClearAll(); TransText->SetFocus(); } @@ -322,7 +320,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { // Next if (Hotkeys.IsPressed(_T("Translation Assistant Accept"))) { JumpToLine(curline,curblock+1); - TransText->Clear(); + TransText->ClearAll(); TransText->SetFocus(); } else JumpToLine(curline,curblock); @@ -340,7 +338,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { if (curBlock->type == BLOCK_PLAIN) { pos++; if (pos == curblock) { - TransText->WriteText(curBlock->text); + TransText->AddText(curBlock->text); } } } diff --git a/aegisub/dialog_translation.h b/aegisub/dialog_translation.h index f3d8a09a8..3500bba61 100644 --- a/aegisub/dialog_translation.h +++ b/aegisub/dialog_translation.h @@ -41,6 +41,7 @@ /////////// // Headers #include +#include "scintilla_text_ctrl.h" ////////////// @@ -64,8 +65,8 @@ private: int curblock; wxStaticText *LineCount; - wxTextCtrl *OrigText; - wxTextCtrl *TransText; + ScintillaTextCtrl *OrigText; + ScintillaTextCtrl *TransText; wxCheckBox *PreviewCheck; void OnMinimize(wxIconizeEvent &event); diff --git a/aegisub/scintilla_text_ctrl.cpp b/aegisub/scintilla_text_ctrl.cpp index 836889008..a346477e7 100644 --- a/aegisub/scintilla_text_ctrl.cpp +++ b/aegisub/scintilla_text_ctrl.cpp @@ -84,6 +84,13 @@ int ScintillaTextCtrl::GetReverseUnicodePosition(int pos) { } +////////////////////////////// +// Start unicode-safe styling +void ScintillaTextCtrl::StartUnicodeStyling(int start,int mask) { + StartStyling(GetUnicodePosition(start),mask); +} + + //////////////////////// // Unicode-safe styling void ScintillaTextCtrl::SetUnicodeStyling(int start,int length,int style) { diff --git a/aegisub/scintilla_text_ctrl.h b/aegisub/scintilla_text_ctrl.h index 2b8cbfdd4..574095774 100644 --- a/aegisub/scintilla_text_ctrl.h +++ b/aegisub/scintilla_text_ctrl.h @@ -49,9 +49,12 @@ class ScintillaTextCtrl : public wxStyledTextCtrl { public: wxString GetWordAtPosition(int pos); void GetBoundsOfWordAtPosition(int pos,int &start,int &end); - void SetUnicodeStyling(int start,int length,int style); int GetUnicodePosition(int pos); int GetReverseUnicodePosition(int pos); + wxString GetValue() { return GetText(); } + + void StartUnicodeStyling(int start,int mask=31); + void SetUnicodeStyling(int start,int length,int style); void SetSelectionU(int start,int end); ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);