Mercurial > pidgin
comparison console/libgnt/gntentry.c @ 13882:5c750626eaa5
[gaim-migrate @ 16362]
New widget GntTextView. It's really simple as it is. But it 'works'.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 28 Jun 2006 00:17:35 +0000 |
parents | 0d0ab1e39d0a |
children | 9d66969a2e32 |
comparison
equal
deleted
inserted
replaced
13881:5d5e249c488e | 13882:5c750626eaa5 |
---|---|
27 | 27 |
28 static void | 28 static void |
29 gnt_entry_size_request(GntWidget *widget) | 29 gnt_entry_size_request(GntWidget *widget) |
30 { | 30 { |
31 GntEntry *entry = GNT_ENTRY(widget); | 31 GntEntry *entry = GNT_ENTRY(widget); |
32 widget->priv.height = 1; | 32 |
33 widget->priv.width = 20; | 33 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) |
34 { | |
35 widget->priv.height = 1; | |
36 widget->priv.width = 20; | |
37 } | |
34 } | 38 } |
35 | 39 |
36 static void | 40 static void |
37 gnt_entry_map(GntWidget *widget) | 41 gnt_entry_map(GntWidget *widget) |
38 { | 42 { |
39 if (widget->priv.width == 0 || widget->priv.height == 0) | 43 if (widget->priv.width == 0 || widget->priv.height == 0) |
40 gnt_widget_size_request(widget); | 44 gnt_widget_size_request(widget); |
41 DEBUG; | 45 DEBUG; |
42 } | 46 } |
43 | 47 |
48 static void | |
49 entry_redraw(GntWidget *widget) | |
50 { | |
51 gnt_entry_draw(widget); | |
52 gnt_widget_queue_update(widget); | |
53 } | |
54 | |
44 static gboolean | 55 static gboolean |
45 gnt_entry_key_pressed(GntWidget *widget, const char *text) | 56 gnt_entry_key_pressed(GntWidget *widget, const char *text) |
46 { | 57 { |
47 GntEntry *entry = GNT_ENTRY(widget); | 58 GntEntry *entry = GNT_ENTRY(widget); |
48 | 59 |
50 { | 61 { |
51 if (strcmp(text + 1, GNT_KEY_DEL) == 0 && entry->cursor < entry->end) | 62 if (strcmp(text + 1, GNT_KEY_DEL) == 0 && entry->cursor < entry->end) |
52 { | 63 { |
53 memmove(entry->cursor, entry->cursor + 1, entry->end - entry->cursor + 1); | 64 memmove(entry->cursor, entry->cursor + 1, entry->end - entry->cursor + 1); |
54 entry->end--; | 65 entry->end--; |
55 gnt_entry_draw(widget); | 66 entry_redraw(widget); |
56 } | 67 } |
57 else if (strcmp(text + 1, GNT_KEY_LEFT) == 0 && entry->cursor > entry->start) | 68 else if (strcmp(text + 1, GNT_KEY_LEFT) == 0 && entry->cursor > entry->start) |
58 { | 69 { |
59 entry->cursor--; | 70 entry->cursor--; |
60 if (entry->cursor < entry->scroll) | 71 if (entry->cursor < entry->scroll) |
61 entry->scroll--; | 72 entry->scroll--; |
62 gnt_entry_draw(widget); | 73 entry_redraw(widget); |
63 } | 74 } |
64 else if (strcmp(text + 1, GNT_KEY_RIGHT) == 0 && entry->cursor < entry->end) | 75 else if (strcmp(text + 1, GNT_KEY_RIGHT) == 0 && entry->cursor < entry->end) |
65 { | 76 { |
66 entry->cursor++; | 77 entry->cursor++; |
67 if (entry->cursor - entry->scroll > widget->priv.width) | 78 if (entry->cursor - entry->scroll > widget->priv.width) |
68 entry->scroll++; | 79 entry->scroll++; |
69 gnt_entry_draw(widget); | 80 entry_redraw(widget); |
70 } | 81 } |
71 /* XXX: handle other keys, like home/end, and ctrl+ goodness */ | 82 /* XXX: handle other keys, like home/end, and ctrl+ goodness */ |
72 } | 83 } |
73 else | 84 else |
74 { | 85 { |
104 | 115 |
105 entry->end++; | 116 entry->end++; |
106 if (entry->cursor - entry->scroll > widget->priv.width) | 117 if (entry->cursor - entry->scroll > widget->priv.width) |
107 entry->scroll++; | 118 entry->scroll++; |
108 } | 119 } |
109 gnt_entry_draw(widget); | 120 entry_redraw(widget); |
121 return TRUE; | |
110 } | 122 } |
111 else | 123 else |
112 { | 124 { |
113 /* Backspace is here */ | 125 /* Backspace is here */ |
114 if (strcmp(text, GNT_KEY_BACKSPACE) == 0 && entry->cursor > entry->start) | 126 if (strcmp(text, GNT_KEY_BACKSPACE) == 0 && entry->cursor > entry->start) |
118 entry->end--; | 130 entry->end--; |
119 | 131 |
120 if (entry->scroll > entry->start) | 132 if (entry->scroll > entry->start) |
121 entry->scroll--; | 133 entry->scroll--; |
122 | 134 |
123 gnt_entry_draw(widget); | 135 entry_redraw(widget); |
124 } | 136 } |
125 } | 137 } |
126 } | 138 } |
127 | 139 |
128 return FALSE; | 140 return FALSE; |
231 entry->end = entry->start + len; | 243 entry->end = entry->start + len; |
232 | 244 |
233 entry->scroll = entry->start + scroll; | 245 entry->scroll = entry->start + scroll; |
234 entry->cursor = entry->end - cursor; | 246 entry->cursor = entry->end - cursor; |
235 | 247 |
236 /* XXX: redraw if necessary? */ | 248 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(entry), GNT_WIDGET_MAPPED)) |
249 entry_redraw(GNT_WIDGET(entry)); | |
237 } | 250 } |
238 | 251 |
239 void gnt_entry_set_max(GntEntry *entry, int max) | 252 void gnt_entry_set_max(GntEntry *entry, int max) |
240 { | 253 { |
241 entry->max = max; | 254 entry->max = max; |
245 { | 258 { |
246 entry->flag = flag; | 259 entry->flag = flag; |
247 /* XXX: Check the existing string to make sure the flags are respected? */ | 260 /* XXX: Check the existing string to make sure the flags are respected? */ |
248 } | 261 } |
249 | 262 |
263 const char *gnt_entry_get_text(GntEntry *entry) | |
264 { | |
265 return entry->start; | |
266 } | |
267 | |
268 void gnt_entry_clear(GntEntry *entry) | |
269 { | |
270 gnt_entry_set_text(entry, NULL); | |
271 entry->scroll = entry->cursor = entry->end = entry->start; | |
272 entry_redraw(GNT_WIDGET(entry)); | |
273 } | |
274 | |
275 |