diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2008-09-10 23:56:49 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2008-09-10 23:56:49 +0000 |
| commit | b6bde2e4569aa617c8a6af64947c688c624ed7f8 (patch) | |
| tree | 010d15843eb7d4faf7cd1b0cd44d5b9c00462a83 /src/Fl_Text_Editor.cxx | |
| parent | dfb50e85292687561927610e689eb5ab30d0ba26 (diff) | |
Merging the UTF8 patch, consisting of O'ksi'd s original 1.1.6 patch and additions by Ian. PLEASE BE AWARE that the patch in its current incarnation is a regression in many aspects and further work is required before we can announce Unicode support.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6212 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Text_Editor.cxx')
| -rw-r--r-- | src/Fl_Text_Editor.cxx | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index 5c2ef5996..880ca844c 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -34,6 +34,26 @@ #include <FL/Fl_Text_Editor.H> #include <FL/fl_ask.H> +static int utf_len(char c) +{ + if (!(c & 0x80)) return 1; + if (c & 0x40) { + if (c & 0x20) { + if (c & 0x10) { + if (c & 0x08) { + if (c & 0x04) { + return 6; + } + return 5; + } + return 4; + } + return 3; + } + return 2; + } + return 0; +} Fl_Text_Editor::Fl_Text_Editor(int X, int Y, int W, int H, const char* l) : Fl_Text_Display(X, Y, W, H, l) { @@ -198,8 +218,14 @@ int Fl_Text_Editor::kf_ignore(int, Fl_Text_Editor*) { } int Fl_Text_Editor::kf_backspace(int, Fl_Text_Editor* e) { - if (!e->buffer()->selected() && e->move_left()) - e->buffer()->select(e->insert_position(), e->insert_position()+1); + if (!e->buffer()->selected() && e->move_left()) { + int l = 1; + char c = e->buffer()->character(e->insert_position()); + if (c & 0x80 && c & 0x40) { + l = utf_len(c); + } + e->buffer()->select(e->insert_position(), e->insert_position()+l); + } kill_selection(e); e->show_insert_position(); e->set_changed(); @@ -343,8 +369,15 @@ int Fl_Text_Editor::kf_insert(int, Fl_Text_Editor* e) { } int Fl_Text_Editor::kf_delete(int, Fl_Text_Editor* e) { - if (!e->buffer()->selected()) - e->buffer()->select(e->insert_position(), e->insert_position()+1); + if (!e->buffer()->selected()) { + int l = 1; + char c = e->buffer()->character(e->insert_position()); + if (c & 0x80 && c & 0x40) { + l = utf_len(c); + } + e->buffer()->select(e->insert_position(), e->insert_position()+l); + } + kill_selection(e); e->show_insert_position(); e->set_changed(); @@ -399,7 +432,7 @@ int Fl_Text_Editor::handle_key() { // This uses the right-hand ctrl key as a "compose prefix" and returns // the changes that should be made to the text, as a number of // bytes to delete and a string to insert: - int del; + int del = 0; if (Fl::compose(del)) { if (del) buffer()->select(insert_position()-del, insert_position()); kill_selection(this); |
