Mercurial > pidgin
comparison finch/libgnt/gntentry.c @ 18382:aa60f5a89286
A 'completion' signal to emit whenever user accepts a completion suggest.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 30 Jun 2007 06:41:54 +0000 |
parents | 72a52cff76f3 |
children | 85b155a574a3 |
comparison
equal
deleted
inserted
replaced
18381:76b7adc8e934 | 18382:aa60f5a89286 |
---|---|
23 #include <ctype.h> | 23 #include <ctype.h> |
24 #include <string.h> | 24 #include <string.h> |
25 | 25 |
26 #include "gntbox.h" | 26 #include "gntbox.h" |
27 #include "gntentry.h" | 27 #include "gntentry.h" |
28 #include "gntmarshal.h" | |
28 #include "gntstyle.h" | 29 #include "gntstyle.h" |
29 #include "gnttree.h" | 30 #include "gnttree.h" |
30 #include "gntutils.h" | 31 #include "gntutils.h" |
31 | 32 |
32 enum | 33 enum |
33 { | 34 { |
34 SIG_TEXT_CHANGED, | 35 SIG_TEXT_CHANGED, |
36 SIG_COMPLETION, | |
35 SIGS, | 37 SIGS, |
36 }; | 38 }; |
37 static guint signals[SIGS] = { 0 }; | 39 static guint signals[SIGS] = { 0 }; |
38 | 40 |
39 static GntWidgetClass *parent_class = NULL; | 41 static GntWidgetClass *parent_class = NULL; |
67 | 69 |
68 static gboolean | 70 static gboolean |
69 complete_suggest(GntEntry *entry, const char *text) | 71 complete_suggest(GntEntry *entry, const char *text) |
70 { | 72 { |
71 gboolean changed = FALSE; | 73 gboolean changed = FALSE; |
74 int offstart = 0, offend = 0; | |
75 | |
72 if (entry->word) { | 76 if (entry->word) { |
73 char *s = get_beginning_of_word(entry); | 77 char *s = get_beginning_of_word(entry); |
74 const char *iter = text; | 78 const char *iter = text; |
79 offstart = g_utf8_pointer_to_offset(entry->start, s); | |
75 while (*iter && toupper(*s) == toupper(*iter)) { | 80 while (*iter && toupper(*s) == toupper(*iter)) { |
76 if (*s != *iter) | 81 if (*s != *iter) |
77 changed = TRUE; | 82 changed = TRUE; |
78 *s++ = *iter++; | 83 *s++ = *iter++; |
79 } | 84 } |
80 if (*iter) { | 85 if (*iter) { |
81 gnt_entry_key_pressed(GNT_WIDGET(entry), iter); | 86 gnt_entry_key_pressed(GNT_WIDGET(entry), iter); |
82 changed = TRUE; | 87 changed = TRUE; |
83 } | 88 } |
89 offend = g_utf8_pointer_to_offset(entry->start, entry->cursor); | |
84 } else { | 90 } else { |
91 offstart = 0; | |
85 gnt_entry_set_text_internal(entry, text); | 92 gnt_entry_set_text_internal(entry, text); |
86 changed = TRUE; | 93 changed = TRUE; |
87 } | 94 offend = g_utf8_strlen(text, -1); |
95 } | |
96 | |
97 if (changed) | |
98 g_signal_emit(G_OBJECT(entry), signals[SIG_COMPLETION], 0, | |
99 entry->start + offstart, entry->start + offend); | |
88 return changed; | 100 return changed; |
89 } | 101 } |
90 | 102 |
91 static gboolean | 103 static gboolean |
92 show_suggest_dropdown(GntEntry *entry) | 104 show_suggest_dropdown(GntEntry *entry) |
684 G_SIGNAL_RUN_LAST, | 696 G_SIGNAL_RUN_LAST, |
685 G_STRUCT_OFFSET(GntEntryClass, text_changed), | 697 G_STRUCT_OFFSET(GntEntryClass, text_changed), |
686 NULL, NULL, | 698 NULL, NULL, |
687 g_cclosure_marshal_VOID__VOID, | 699 g_cclosure_marshal_VOID__VOID, |
688 G_TYPE_NONE, 0); | 700 G_TYPE_NONE, 0); |
701 | |
702 signals[SIG_COMPLETION] = | |
703 g_signal_new("completion", | |
704 G_TYPE_FROM_CLASS(klass), | |
705 G_SIGNAL_RUN_LAST, | |
706 0, NULL, NULL, | |
707 gnt_closure_marshal_VOID__POINTER_POINTER, | |
708 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); | |
689 | 709 |
690 gnt_bindable_class_register_action(bindable, "cursor-home", move_start, | 710 gnt_bindable_class_register_action(bindable, "cursor-home", move_start, |
691 GNT_KEY_CTRL_A, NULL); | 711 GNT_KEY_CTRL_A, NULL); |
692 gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL); | 712 gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL); |
693 gnt_bindable_class_register_action(bindable, "cursor-end", move_end, | 713 gnt_bindable_class_register_action(bindable, "cursor-end", move_end, |