# HG changeset patch # User Sadrul Habib Chowdhury # Date 1156317259 0 # Node ID 7c91ba42b9ba0792fa1e75f2d1c9d55a117b8f89 # Parent a8a0b10be4fbd02934595c25e2f4fae371d1e551 [gaim-migrate @ 16997] Double-width characters should work well in GntEntry's now. If it really works correctly, I can make necessary changes in textview and other places, so let me know. committer: Tailor Script diff -r a8a0b10be4fb -r 7c91ba42b9ba console/libgnt/gntentry.c --- a/console/libgnt/gntentry.c Wed Aug 23 05:16:40 2006 +0000 +++ b/console/libgnt/gntentry.c Wed Aug 23 07:14:19 2006 +0000 @@ -1,5 +1,7 @@ #include +#include #include +#include #include "gntbox.h" #include "gntentry.h" @@ -13,6 +15,25 @@ static GntWidgetClass *parent_class = NULL; static guint signals[SIGS] = { 0 }; +static int +get_onscreen_width(const char *start, const char *end) +{ + wchar_t wch; + size_t size; + int width = 0; + + while (start < end) { + if ((size = mbtowc(&wch, start, end - start)) > 0) { + start += size; + width += wcwidth(wch); + } else { + ++width; + ++start; + } + } + return width; +} + static void destroy_suggest(GntEntry *entry) { @@ -51,7 +72,7 @@ char *s = get_beginning_of_word(entry); suggest = g_strndup(s, entry->cursor - s); if (entry->scroll < s) - offset = g_utf8_pointer_to_offset(entry->scroll, s); + offset = get_onscreen_width(entry->scroll, s); } else suggest = g_strdup(entry->start); @@ -118,14 +139,14 @@ g_utf8_pointer_to_offset(entry->scroll, entry->end)); } else - mvwprintw(widget->window, 0, 0, entry->scroll); + mvwprintw(widget->window, 0, 0, "%s", entry->scroll); - stop = g_utf8_pointer_to_offset(entry->scroll, entry->end); + stop = get_onscreen_width(entry->scroll, entry->end); if (stop < widget->priv.width) - mvwhline(widget->window, 0, stop, ENTRY_CHAR, widget->priv.width - stop); + whline(widget->window, ENTRY_CHAR, widget->priv.width - stop); if (focus) - mvwchgat(widget->window, 0, g_utf8_pointer_to_offset(entry->scroll, entry->cursor), + mvwchgat(widget->window, 0, get_onscreen_width(entry->scroll, entry->cursor), 1, A_REVERSE, COLOR_PAIR(GNT_COLOR_TEXT_NORMAL), NULL); DEBUG; @@ -173,7 +194,7 @@ if (entry->cursor >= entry->end) return; entry->cursor = g_utf8_find_next_char(entry->cursor, NULL); - if (g_utf8_pointer_to_offset(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) + while (get_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); entry_redraw(GNT_WIDGET(entry)); } @@ -228,7 +249,7 @@ { entry->cursor = entry->end; /* This should be better than this */ - while (g_utf8_pointer_to_offset(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) + while (get_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); entry_redraw(GNT_WIDGET(entry)); } @@ -389,7 +410,7 @@ str++; } - while (g_utf8_pointer_to_offset(entry->scroll, entry->cursor) >= widget->priv.width) + while (get_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); if (entry->ddown)