From 8b055489eb43a28cec75bf2f64f05b734c5c2bc7 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Tue, 26 Dec 2006 01:08:46 +0000 Subject: [PATCH] Several unicode fixes related to wxScintilla, spellcheck and thesaurus Originally committed to SVN as r617. --- core/mkv_wrap.cpp | 4 +++- core/spellchecker.h | 4 +++- core/spellchecker_hunspell.cpp | 18 +++++++++++++++-- core/spellchecker_hunspell.h | 2 ++ core/subs_edit_ctrl.cpp | 36 +++++++++++++++++++++++++--------- core/subs_edit_ctrl.h | 2 ++ core/thesaurus_myspell.cpp | 1 + core/video_provider_avs.cpp | 8 ++++++-- 8 files changed, 60 insertions(+), 15 deletions(-) diff --git a/core/mkv_wrap.cpp b/core/mkv_wrap.cpp index eb462c3af..dbda0a555 100644 --- a/core/mkv_wrap.cpp +++ b/core/mkv_wrap.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include "mkv_wrap.h" #include "dialog_progress.h" #include "ass_file.h" @@ -548,7 +549,8 @@ MkvStdIO::MkvStdIO(wxString filename) { memrealloc = StdIoRealloc; memfree = StdIoFree; progress = StdIoProgress; - fp = fopen(filename.mb_str(),"rb"); + wxFileName fname(filename); + fp = fopen(fname.GetShortPath().mb_str(wxConvUTF8),"rb"); if (fp) { setvbuf(fp, NULL, _IOFBF, CACHESIZE); } diff --git a/core/spellchecker.h b/core/spellchecker.h index d715307eb..7b8ebaf62 100644 --- a/core/spellchecker.h +++ b/core/spellchecker.h @@ -51,7 +51,9 @@ public: SpellChecker() {} virtual ~SpellChecker() {} - virtual void AddWord(wxString word)=0; + virtual void AddWord(wxString word) {} + virtual bool CanAddWord(wxString word) { return false; } + virtual bool CheckWord(wxString word)=0; virtual wxArrayString GetSuggestions(wxString word)=0; diff --git a/core/spellchecker_hunspell.cpp b/core/spellchecker_hunspell.cpp index 8de43954d..d3bd40239 100644 --- a/core/spellchecker_hunspell.cpp +++ b/core/spellchecker_hunspell.cpp @@ -64,6 +64,14 @@ HunspellSpellChecker::~HunspellSpellChecker() { } +////////////////////////// +// Can add to dictionary? +bool HunspellSpellChecker::CanAddWord(wxString word) { + if (!hunspell) return false; + return (word.mb_str(*conv) != NULL); +} + + ////////////////////////// // Add word to dictionary void HunspellSpellChecker::AddWord(wxString word) { @@ -75,7 +83,9 @@ void HunspellSpellChecker::AddWord(wxString word) { // Check if the word is valid bool HunspellSpellChecker::CheckWord(wxString word) { if (!hunspell) return true; - return (hunspell->spell(word.mb_str(*conv)) == 1); + wxCharBuffer buf = word.mb_str(*conv); + if (buf) return (hunspell->spell(buf) == 1); + return false; } @@ -85,11 +95,15 @@ wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) { // Array wxArrayString suggestions; + // Word + wxCharBuffer buf = word.mb_str(*conv); + if (!buf) return suggestions; + // Get suggestions if (hunspell) { // Grab raw from Hunspell char **results; - int n = hunspell->suggest(&results,word.mb_str(*conv)); + int n = hunspell->suggest(&results,buf); // Convert each for (int i=0;iCheckWord(curWord)) { // Get length before it - wxString string = GetText().Left(startPos[i]); - wxCharBuffer buffer = string.mb_str(wxConvUTF8); - const char* utf8str = buffer; - int utf8len = strlen(utf8str); + int utf8len = GetUnicodePosition(startPos[i]); // Set styling StartStyling(utf8len,32); @@ -432,6 +449,7 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) { // Position if (activePos == -1) activePos = GetCurrentPos(); + activePos = GetReverseUnicodePosition(activePos); // Get current word under cursor currentWord = GetWordAtPosition(activePos); @@ -461,7 +479,7 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) { for (int i=0;iSetFont(font); // Append "add word" - menu.Append(EDIT_MENU_ADD_TO_DICT,wxString::Format(_("Add \"%s\" to dictionary"),currentWord.c_str())); + menu.Append(EDIT_MENU_ADD_TO_DICT,wxString::Format(_("Add \"%s\" to dictionary"),currentWord.c_str()))->Enable(spellchecker->CanAddWord(currentWord)); menu.AppendSeparator(); } @@ -715,7 +733,7 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) { SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1)); // Set selection - SetSelection(start,start+suggestion.Length()); + SetSelection(GetUnicodePosition(start),GetUnicodePosition(start+suggestion.Length())); SetFocus(); } @@ -742,6 +760,6 @@ void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) { SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1)); // Set selection - SetSelection(start,start+suggestion.Length()); + SetSelection(GetUnicodePosition(start),GetUnicodePosition(start+suggestion.Length())); SetFocus(); } diff --git a/core/subs_edit_ctrl.h b/core/subs_edit_ctrl.h index e5c9ead3d..883c08586 100644 --- a/core/subs_edit_ctrl.h +++ b/core/subs_edit_ctrl.h @@ -67,6 +67,8 @@ private: wxString GetWordAtPosition(int pos); void GetBoundsOfWordAtPosition(int pos,int &start,int &end); + int GetUnicodePosition(int pos); + int GetReverseUnicodePosition(int pos); void SetUnicodeStyling(int start,int length,int style); void ShowPopupMenu(int activePos=-1); diff --git a/core/thesaurus_myspell.cpp b/core/thesaurus_myspell.cpp index aac75fd65..55b79b651 100644 --- a/core/thesaurus_myspell.cpp +++ b/core/thesaurus_myspell.cpp @@ -71,6 +71,7 @@ void MySpellThesaurus::Lookup(wxString word,ThesaurusEntryArray &result) { // Grab raw from MyThes mentry *me; wxCharBuffer buf = word.Lower().mb_str(*conv); + if (!buf) return; int n = mythes->Lookup(buf,strlen(buf),&me); // Each entry diff --git a/core/video_provider_avs.cpp b/core/video_provider_avs.cpp index bb1ee3806..b4654a796 100644 --- a/core/video_provider_avs.cpp +++ b/core/video_provider_avs.cpp @@ -35,6 +35,7 @@ #include #include +#include #include "video_provider_avs.h" #include "options.h" #include "main.h" @@ -157,7 +158,9 @@ PClip AvisynthVideoProvider::OpenVideo(wxString _filename, bool mpeg2dec3_priori try { // Prepare filename - char *videoFilename = env->SaveString(_filename.mb_str(wxConvLocal)); + //char *videoFilename = env->SaveString(_filename.mb_str(wxConvLocal)); + wxFileName fname(_filename); + char *videoFilename = env->SaveString(fname.GetShortPath().mb_str(wxConvLocal)); // Avisynth file, just import it if (extension == _T(".avs")) { @@ -275,7 +278,8 @@ PClip AvisynthVideoProvider::ApplySubtitles(wxString _filename, PClip videosourc // Insert subs AVSValue script; char temp[512]; - strcpy(temp,_filename.mb_str(wxConvLocal)); + wxFileName fname(_filename); + strcpy(temp,fname.GetShortPath().mb_str(wxConvLocal)); AVSValue args[2] = { videosource, temp }; try {