Mercurial > pidgin
diff console/libgnt/gntentry.c @ 14311:fda9dc44807d
[gaim-migrate @ 17001]
Wide-characters should no longer eat characters at the end of the line in textview.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 23 Aug 2006 13:46:51 +0000 |
parents | 578a2c9af05e |
children | 1bd09d355f9e |
line wrap: on
line diff
--- a/console/libgnt/gntentry.c Wed Aug 23 12:29:08 2006 +0000 +++ b/console/libgnt/gntentry.c Wed Aug 23 13:46:51 2006 +0000 @@ -1,11 +1,10 @@ #include <ctype.h> -#include <stdlib.h> #include <string.h> -#include <wchar.h> #include "gntbox.h" #include "gntentry.h" #include "gnttree.h" +#include "gntutils.h" enum { @@ -15,25 +14,6 @@ static GntWidgetClass *parent_class = NULL; static guint signals[SIGS] = { 0 }; -static int -get_onscreen_width(const char *start, const char *end) -{ - wchar_t wch; - int 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) { @@ -72,7 +52,7 @@ char *s = get_beginning_of_word(entry); suggest = g_strndup(s, entry->cursor - s); if (entry->scroll < s) - offset = get_onscreen_width(entry->scroll, s); + offset = gnt_util_onscreen_width(entry->scroll, s); } else suggest = g_strdup(entry->start); @@ -141,12 +121,12 @@ else mvwprintw(widget->window, 0, 0, "%s", entry->scroll); - stop = get_onscreen_width(entry->scroll, entry->end); + stop = gnt_util_onscreen_width(entry->scroll, entry->end); if (stop < widget->priv.width) whline(widget->window, ENTRY_CHAR, widget->priv.width - stop); if (focus) - mvwchgat(widget->window, 0, get_onscreen_width(entry->scroll, entry->cursor), + mvwchgat(widget->window, 0, gnt_util_onscreen_width(entry->scroll, entry->cursor), 1, A_REVERSE, COLOR_PAIR(GNT_COLOR_TEXT_NORMAL), NULL); DEBUG; @@ -194,7 +174,7 @@ if (entry->cursor >= entry->end) return; entry->cursor = g_utf8_find_next_char(entry->cursor, NULL); - while (get_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) + while (gnt_util_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)); } @@ -249,7 +229,7 @@ { entry->cursor = entry->end; /* This should be better than this */ - while (get_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) + while (gnt_util_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)); } @@ -410,7 +390,7 @@ str++; } - while (get_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) + while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); if (entry->ddown)