Several unicode fixes related to wxScintilla, spellcheck and thesaurus

Originally committed to SVN as r617.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-26 01:08:46 +00:00
parent 518c4d3766
commit 8b055489eb
8 changed files with 60 additions and 15 deletions

View File

@ -40,6 +40,7 @@
#include <errno.h>
#include <wx/tokenzr.h>
#include <wx/choicdlg.h>
#include <wx/filename.h>
#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);
}

View File

@ -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;

View File

@ -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;i<n;i++) {

View File

@ -59,6 +59,8 @@ public:
~HunspellSpellChecker();
void AddWord(wxString word);
bool CanAddWord(wxString word);
bool CheckWord(wxString word);
wxArrayString GetSuggestions(wxString word);

View File

@ -251,14 +251,34 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
}
///////////////////////////////////
// Get unicode-compatible position
int SubsTextEditCtrl::GetUnicodePosition(int pos) {
wxString string = GetText().Left(pos);
wxCharBuffer buffer = string.mb_str(wxConvUTF8);
return strlen(buffer);
}
///////////////////////////////////////
// Reverse unicode-compatible position
int SubsTextEditCtrl::GetReverseUnicodePosition(int pos) {
wxCharBuffer buffer = GetText().mb_str(wxConvUTF8);
char *buf2 = new char[pos+1];
memcpy(buf2,buffer,pos);
buf2[pos] = 0;
wxString buf3(buf2,wxConvUTF8);
return buf3.Length();
}
////////////////////////
// Unicode-safe styling
void SubsTextEditCtrl::SetUnicodeStyling(int start,int length,int style) {
// Get the real length
wxString string = GetText().Mid(start,length);
wxCharBuffer buffer = string.mb_str(wxConvUTF8);
const char* utf8str = buffer;
int len = strlen(utf8str);
int len = strlen(buffer);
// Set styling
SetStyling(len,style);
@ -345,10 +365,7 @@ void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
// Check if it's valid
if (!spellchecker->CheckWord(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;i<nSugs;i++) menu.Append(EDIT_MENU_SUGGESTIONS+i,sugs[i])->SetFont(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();
}

View File

@ -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);

View File

@ -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

View File

@ -35,6 +35,7 @@
#include <wx/filename.h>
#include <wx/msw/registry.h>
#include <wx/filename.h>
#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 {