Mercurial > pidgin.yaz
diff console/libgnt/gntentry.c @ 15231:4f0575a9264d
[gaim-migrate @ 18020]
text-changed signal for GntEntry. Not used anywhere yet, but will be in the future.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Mon, 18 Dec 2006 19:41:38 +0000 |
parents | 3fb20516042b |
children | 492f4e7416a3 |
line wrap: on
line diff
--- a/console/libgnt/gntentry.c Sun Dec 17 21:12:18 2006 +0000 +++ b/console/libgnt/gntentry.c Mon Dec 18 19:41:38 2006 +0000 @@ -9,11 +9,15 @@ enum { - SIGS = 1, + SIG_TEXT_CHANGED, + SIGS, }; +static guint signals[SIGS] = { 0 }; static GntWidgetClass *parent_class = NULL; +static void gnt_entry_set_text_internal(GntEntry *entry, const char *text); + static void destroy_suggest(GntEntry *entry) { @@ -157,6 +161,12 @@ gnt_widget_queue_update(widget); } +static void +entry_text_changed(GntEntry *entry) +{ + g_signal_emit(entry, signals[SIG_TEXT_CHANGED], 0); +} + static gboolean move_back(GntBindable *bind, GList *null) { @@ -203,6 +213,7 @@ entry_redraw(GNT_WIDGET(entry)); if (entry->ddown) show_suggest_dropdown(entry); + entry_text_changed(entry); return TRUE; } @@ -222,6 +233,7 @@ if (entry->ddown) show_suggest_dropdown(entry); + entry_text_changed(entry); return TRUE; } @@ -253,8 +265,9 @@ if (entry->histlength && entry->history->prev) { entry->history = entry->history->prev; - gnt_entry_set_text(entry, entry->history->data); + gnt_entry_set_text_internal(entry, entry->history->data); destroy_suggest(entry); + entry_text_changed(entry); return TRUE; } @@ -276,8 +289,9 @@ } entry->history = entry->history->next; - gnt_entry_set_text(entry, entry->history->data); + gnt_entry_set_text_internal(entry, entry->history->data); destroy_suggest(entry); + entry_text_changed(entry); return TRUE; } @@ -316,11 +330,14 @@ del_to_home(GntBindable *bind, GList *null) { GntEntry *entry = GNT_ENTRY(bind); + if (entry->cursor <= entry->start) + return TRUE; memmove(entry->start, entry->cursor, entry->end - entry->cursor); entry->end -= (entry->cursor - entry->start); entry->cursor = entry->scroll = entry->start; memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); entry_redraw(GNT_WIDGET(bind)); + entry_text_changed(entry); return TRUE; } @@ -328,9 +345,12 @@ del_to_end(GntBindable *bind, GList *null) { GntEntry *entry = GNT_ENTRY(bind); + if (entry->end <= entry->cursor) + return TRUE; entry->end = entry->cursor; memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); entry_redraw(GNT_WIDGET(bind)); + entry_text_changed(entry); return TRUE; } @@ -410,6 +430,7 @@ } memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); entry_redraw(widget); + entry_text_changed(entry); return TRUE; } @@ -434,11 +455,14 @@ GntWidget *widget = GNT_WIDGET(bind); char *iter = (char *)next_begin_word(entry->cursor, entry->end); int len = entry->end - iter + 1; + if (len <= 0) + return TRUE; memmove(entry->cursor, iter, len); len = iter - entry->cursor; entry->end -= len; memset(entry->end, '\0', len); entry_redraw(widget); + entry_text_changed(entry); return TRUE; } @@ -484,9 +508,10 @@ } else { - gnt_entry_set_text(entry, text); + gnt_entry_set_text_internal(entry, text); } g_free(text); + entry_text_changed(entry); return TRUE; } @@ -519,7 +544,7 @@ { /* This will cause the buffer to grow */ char *tmp = g_strdup_printf("%s%*s", entry->start, len, ""); - gnt_entry_set_text(entry, tmp); + gnt_entry_set_text_internal(entry, tmp); g_free(tmp); } @@ -543,6 +568,7 @@ show_suggest_dropdown(entry); } entry_redraw(widget); + entry_text_changed(entry); return TRUE; } } @@ -597,6 +623,15 @@ parent_class->key_pressed = gnt_entry_key_pressed; parent_class->lost_focus = gnt_entry_lost_focus; + signals[SIG_TEXT_CHANGED] = + g_signal_new("text_changed", + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GntEntryClass, text_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + gnt_bindable_class_register_action(bindable, "cursor-home", move_start, GNT_KEY_CTRL_A, NULL); gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL); @@ -703,12 +738,13 @@ GntWidget *widget = g_object_new(GNT_TYPE_ENTRY, NULL); GntEntry *entry = GNT_ENTRY(widget); - gnt_entry_set_text(entry, text); + gnt_entry_set_text_internal(entry, text); return widget; } -void gnt_entry_set_text(GntEntry *entry, const char *text) +static void +gnt_entry_set_text_internal(GntEntry *entry, const char *text) { int len; int scroll, cursor; @@ -741,6 +777,18 @@ entry_redraw(GNT_WIDGET(entry)); } +void gnt_entry_set_text(GntEntry *entry, const char *text) +{ + gboolean changed = TRUE; + if (text == NULL && entry->start == NULL) + changed = FALSE; + if (text && entry->start && g_utf8_collate(text, entry->start) == 0) + changed = FALSE; + gnt_entry_set_text_internal(entry, text); + if (changed) + entry_text_changed(entry); +} + void gnt_entry_set_max(GntEntry *entry, int max) { entry->max = max; @@ -759,10 +807,11 @@ void gnt_entry_clear(GntEntry *entry) { - gnt_entry_set_text(entry, NULL); + gnt_entry_set_text_internal(entry, NULL); entry->scroll = entry->cursor = entry->end = entry->start; entry_redraw(GNT_WIDGET(entry)); destroy_suggest(entry); + entry_text_changed(entry); } void gnt_entry_set_masked(GntEntry *entry, gboolean set)