| 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 { |
| 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; |