More fixes related to scintilla & Unicode...

Originally committed to SVN as r618.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-26 01:20:58 +00:00
parent 8b055489eb
commit ac36d6f0cd
4 changed files with 21 additions and 6 deletions

View File

@ -412,7 +412,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
grid->MakeCellVisible(curLine,0);
if (field == 0) {
grid->editBox->SetToLine(curLine);
grid->editBox->TextEdit->SetSelection(pos,pos+replaceLen);
grid->editBox->TextEdit->SetSelectionU(pos,pos+replaceLen);
}
grid->EndBatch();

View File

@ -1041,13 +1041,13 @@ void SubsEditBox::SetOverride (wxString tagname,wxString preValue,int forcePos)
// Shift selection
selstart = origStart;
TextEdit->SetSelection(origStart+shift,selend+shift);
TextEdit->SetSelectionU(origStart+shift,selend+shift);
}
// Commit changes and shift selection
TextEdit->SetTextTo(line->Text);
line->ClearBlocks();
TextEdit->SetSelection(selstart+shift,selend+shift);
TextEdit->SetSelectionU(selstart+shift,selend+shift);
TextEdit->SetFocus();
}

View File

@ -263,10 +263,18 @@ int SubsTextEditCtrl::GetUnicodePosition(int pos) {
///////////////////////////////////////
// Reverse unicode-compatible position
int SubsTextEditCtrl::GetReverseUnicodePosition(int pos) {
// Get UTF8
wxCharBuffer buffer = GetText().mb_str(wxConvUTF8);
// Limit position to it
if (pos > (signed)strlen(buffer)) pos = strlen(buffer);
// Get UTF8 substring
char *buf2 = new char[pos+1];
memcpy(buf2,buffer,pos);
buf2[pos] = 0;
// Convert back and return its length
wxString buf3(buf2,wxConvUTF8);
return buf3.Length();
}
@ -399,7 +407,7 @@ void SubsTextEditCtrl::SetTextTo(const wxString _text) {
UpdateStyle();
// Restore selection
SetSelection(from,to);
SetSelectionU(GetReverseUnicodePosition(from),GetReverseUnicodePosition(to));
// Finish
Thaw();
@ -733,7 +741,7 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
// Set selection
SetSelection(GetUnicodePosition(start),GetUnicodePosition(start+suggestion.Length()));
SetSelectionU(start,start+suggestion.Length());
SetFocus();
}
@ -760,6 +768,12 @@ void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) {
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
// Set selection
SetSelection(GetUnicodePosition(start),GetUnicodePosition(start+suggestion.Length()));
SetSelectionU(start,start+suggestion.Length());
SetFocus();
}
// Set selection, unicode-aware
void SubsTextEditCtrl::SetSelectionU(int start, int end) {
SetSelection(GetUnicodePosition(start),GetUnicodePosition(end));
}

View File

@ -89,6 +89,7 @@ public:
SubsTextEditCtrl(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);
~SubsTextEditCtrl();
void SetSelectionU(int start,int end);
void SetTextTo(const wxString text);
void UpdateStyle(int start=0,int length=-1);
void StyleSpellCheck(int start=0,int length=-1);