Mercurial > pidgin.yaz
comparison console/libgnt/gntentry.c @ 14900:065e7ac30338
[gaim-migrate @ 17672]
Rearranging a bunch of stuff. Users shouldn't notice any change, apart from
the added ability to bind keys for the window-manager. I will update the manual
in a while.
I need to know how to revert a commit in case things go terribly wrong.
... I am going to remind everyone that Dido is AWESOME!
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 05 Nov 2006 17:28:33 +0000 |
parents | 70623f0d5cdc |
children | d9d28bd79715 |
comparison
equal
deleted
inserted
replaced
14899:a8f92a837590 | 14900:065e7ac30338 |
---|---|
72 x += offset; | 72 x += offset; |
73 y++; | 73 y++; |
74 if (y + 10 >= getmaxy(stdscr)) | 74 if (y + 10 >= getmaxy(stdscr)) |
75 y -= 11; | 75 y -= 11; |
76 gnt_widget_set_position(box, x, y); | 76 gnt_widget_set_position(box, x, y); |
77 | |
78 gnt_widget_draw(box); | |
79 } | 77 } |
80 else | 78 else |
81 gnt_tree_remove_all(GNT_TREE(entry->ddown)); | 79 gnt_tree_remove_all(GNT_TREE(entry->ddown)); |
82 | 80 |
83 for (count = 0, iter = entry->suggests; iter; iter = iter->next) | 81 for (count = 0, iter = entry->suggests; iter; iter = iter->next) |
97 { | 95 { |
98 destroy_suggest(entry); | 96 destroy_suggest(entry); |
99 return FALSE; | 97 return FALSE; |
100 } | 98 } |
101 | 99 |
100 gnt_widget_draw(entry->ddown->parent); | |
102 return TRUE; | 101 return TRUE; |
103 } | 102 } |
104 | 103 |
105 static void | 104 static void |
106 gnt_entry_draw(GntWidget *widget) | 105 gnt_entry_draw(GntWidget *widget) |
157 gnt_entry_draw(widget); | 156 gnt_entry_draw(widget); |
158 gnt_widget_queue_update(widget); | 157 gnt_widget_queue_update(widget); |
159 } | 158 } |
160 | 159 |
161 static gboolean | 160 static gboolean |
162 move_back(GntWidget *widget, GList *null) | 161 move_back(GntBindable *bind, GList *null) |
163 { | 162 { |
164 GntEntry *entry = GNT_ENTRY(widget); | 163 GntEntry *entry = GNT_ENTRY(bind); |
165 if (entry->cursor <= entry->start) | 164 if (entry->cursor <= entry->start) |
166 return FALSE; | 165 return FALSE; |
167 entry->cursor = g_utf8_find_prev_char(entry->start, entry->cursor); | 166 entry->cursor = g_utf8_find_prev_char(entry->start, entry->cursor); |
168 if (entry->cursor < entry->scroll) | 167 if (entry->cursor < entry->scroll) |
169 entry->scroll = entry->cursor; | 168 entry->scroll = entry->cursor; |
170 entry_redraw(GNT_WIDGET(entry)); | 169 entry_redraw(GNT_WIDGET(entry)); |
171 return TRUE; | 170 return TRUE; |
172 } | 171 } |
173 | 172 |
174 static gboolean | 173 static gboolean |
175 move_forward(GntWidget *widget, GList *list) | 174 move_forward(GntBindable *bind, GList *list) |
176 { | 175 { |
177 GntEntry *entry = GNT_ENTRY(widget); | 176 GntEntry *entry = GNT_ENTRY(bind); |
178 if (entry->cursor >= entry->end) | 177 if (entry->cursor >= entry->end) |
179 return FALSE; | 178 return FALSE; |
180 entry->cursor = g_utf8_find_next_char(entry->cursor, NULL); | 179 entry->cursor = g_utf8_find_next_char(entry->cursor, NULL); |
181 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) | 180 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) |
182 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); | 181 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); |
183 entry_redraw(GNT_WIDGET(entry)); | 182 entry_redraw(GNT_WIDGET(entry)); |
184 return TRUE; | 183 return TRUE; |
185 } | 184 } |
186 | 185 |
187 static gboolean | 186 static gboolean |
188 backspace(GntWidget *widget, GList *null) | 187 backspace(GntBindable *bind, GList *null) |
189 { | 188 { |
190 int len; | 189 int len; |
191 GntEntry *entry = GNT_ENTRY(widget); | 190 GntEntry *entry = GNT_ENTRY(bind); |
192 | 191 |
193 if (entry->cursor <= entry->start) | 192 if (entry->cursor <= entry->start) |
194 return TRUE; | 193 return TRUE; |
195 | 194 |
196 len = entry->cursor - g_utf8_find_prev_char(entry->start, entry->cursor); | 195 len = entry->cursor - g_utf8_find_prev_char(entry->start, entry->cursor); |
206 show_suggest_dropdown(entry); | 205 show_suggest_dropdown(entry); |
207 return TRUE; | 206 return TRUE; |
208 } | 207 } |
209 | 208 |
210 static gboolean | 209 static gboolean |
211 delkey(GntWidget *widget, GList *null) | 210 delkey(GntBindable *bind, GList *null) |
212 { | 211 { |
213 int len; | 212 int len; |
214 GntEntry *entry = GNT_ENTRY(widget); | 213 GntEntry *entry = GNT_ENTRY(bind); |
215 | 214 |
216 if (entry->cursor >= entry->end) | 215 if (entry->cursor >= entry->end) |
217 return FALSE; | 216 return FALSE; |
218 | 217 |
219 len = g_utf8_find_next_char(entry->cursor, NULL) - entry->cursor; | 218 len = g_utf8_find_next_char(entry->cursor, NULL) - entry->cursor; |
225 show_suggest_dropdown(entry); | 224 show_suggest_dropdown(entry); |
226 return TRUE; | 225 return TRUE; |
227 } | 226 } |
228 | 227 |
229 static gboolean | 228 static gboolean |
230 move_start(GntWidget *widget, GList *null) | 229 move_start(GntBindable *bind, GList *null) |
231 { | 230 { |
232 GntEntry *entry = GNT_ENTRY(widget); | 231 GntEntry *entry = GNT_ENTRY(bind); |
233 entry->scroll = entry->cursor = entry->start; | 232 entry->scroll = entry->cursor = entry->start; |
234 entry_redraw(GNT_WIDGET(entry)); | 233 entry_redraw(GNT_WIDGET(entry)); |
235 return TRUE; | 234 return TRUE; |
236 } | 235 } |
237 | 236 |
238 static gboolean | 237 static gboolean |
239 move_end(GntWidget *widget, GList *null) | 238 move_end(GntBindable *bind, GList *null) |
240 { | 239 { |
241 GntEntry *entry = GNT_ENTRY(widget); | 240 GntEntry *entry = GNT_ENTRY(bind); |
242 entry->cursor = entry->end; | 241 entry->cursor = entry->end; |
243 /* This should be better than this */ | 242 /* This should be better than this */ |
244 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) | 243 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width) |
245 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); | 244 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL); |
246 entry_redraw(GNT_WIDGET(entry)); | 245 entry_redraw(GNT_WIDGET(entry)); |
247 return TRUE; | 246 return TRUE; |
248 } | 247 } |
249 | 248 |
250 static gboolean | 249 static gboolean |
251 history_prev(GntWidget *widget, GList *null) | 250 history_prev(GntBindable *bind, GList *null) |
252 { | 251 { |
253 GntEntry *entry = GNT_ENTRY(widget); | 252 GntEntry *entry = GNT_ENTRY(bind); |
254 if (entry->histlength && entry->history->prev) | 253 if (entry->histlength && entry->history->prev) |
255 { | 254 { |
256 entry->history = entry->history->prev; | 255 entry->history = entry->history->prev; |
257 gnt_entry_set_text(entry, entry->history->data); | 256 gnt_entry_set_text(entry, entry->history->data); |
258 destroy_suggest(entry); | 257 destroy_suggest(entry); |
261 } | 260 } |
262 return FALSE; | 261 return FALSE; |
263 } | 262 } |
264 | 263 |
265 static gboolean | 264 static gboolean |
266 history_next(GntWidget *widget, GList *null) | 265 history_next(GntBindable *bind, GList *null) |
267 { | 266 { |
268 GntEntry *entry = GNT_ENTRY(widget); | 267 GntEntry *entry = GNT_ENTRY(bind); |
269 if (entry->histlength && entry->history->next) | 268 if (entry->histlength && entry->history->next) |
270 { | 269 { |
271 if (entry->history->prev == NULL) | 270 if (entry->history->prev == NULL) |
272 { | 271 { |
273 /* Save the current contents */ | 272 /* Save the current contents */ |
284 } | 283 } |
285 return FALSE; | 284 return FALSE; |
286 } | 285 } |
287 | 286 |
288 static gboolean | 287 static gboolean |
289 suggest_show(GntWidget *widget, GList *null) | 288 suggest_show(GntBindable *bind, GList *null) |
290 { | 289 { |
291 return show_suggest_dropdown(GNT_ENTRY(widget)); | 290 return show_suggest_dropdown(GNT_ENTRY(bind)); |
292 } | 291 } |
293 | 292 |
294 static gboolean | 293 static gboolean |
295 suggest_next(GntWidget *widget, GList *null) | 294 suggest_next(GntBindable *bind, GList *null) |
296 { | 295 { |
297 GntEntry *entry = GNT_ENTRY(widget); | 296 GntEntry *entry = GNT_ENTRY(bind); |
298 if (entry->ddown) { | 297 if (entry->ddown) { |
299 gnt_widget_perform_action_named(entry->ddown, "move-down", NULL); | 298 gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-down", NULL); |
300 return TRUE; | 299 return TRUE; |
301 } | 300 } |
302 return FALSE; | 301 return FALSE; |
303 } | 302 } |
304 | 303 |
305 static gboolean | 304 static gboolean |
306 suggest_prev(GntWidget *widget, GList *null) | 305 suggest_prev(GntBindable *bind, GList *null) |
307 { | 306 { |
308 GntEntry *entry = GNT_ENTRY(widget); | 307 GntEntry *entry = GNT_ENTRY(bind); |
309 if (entry->ddown) { | 308 if (entry->ddown) { |
310 gnt_widget_perform_action_named(entry->ddown, "move-up", NULL); | 309 gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-up", NULL); |
311 return TRUE; | 310 return TRUE; |
312 } | 311 } |
313 return FALSE; | 312 return FALSE; |
314 } | 313 } |
315 | 314 |
316 static gboolean | 315 static gboolean |
317 del_to_home(GntWidget *widget, GList *null) | 316 del_to_home(GntBindable *bind, GList *null) |
318 { | 317 { |
319 GntEntry *entry = GNT_ENTRY(widget); | 318 GntEntry *entry = GNT_ENTRY(bind); |
320 memmove(entry->start, entry->cursor, entry->end - entry->cursor); | 319 memmove(entry->start, entry->cursor, entry->end - entry->cursor); |
321 entry->end -= (entry->cursor - entry->start); | 320 entry->end -= (entry->cursor - entry->start); |
322 entry->cursor = entry->scroll = entry->start; | 321 entry->cursor = entry->scroll = entry->start; |
323 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); | 322 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); |
324 entry_redraw(widget); | 323 entry_redraw(GNT_WIDGET(bind)); |
325 return TRUE; | 324 return TRUE; |
326 } | 325 } |
327 | 326 |
328 static gboolean | 327 static gboolean |
329 del_to_end(GntWidget *widget, GList *null) | 328 del_to_end(GntBindable *bind, GList *null) |
330 { | 329 { |
331 GntEntry *entry = GNT_ENTRY(widget); | 330 GntEntry *entry = GNT_ENTRY(bind); |
332 entry->end = entry->cursor; | 331 entry->end = entry->cursor; |
333 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); | 332 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start)); |
334 entry_redraw(widget); | 333 entry_redraw(GNT_WIDGET(bind)); |
335 return TRUE; | 334 return TRUE; |
336 } | 335 } |
337 | 336 |
338 static const char * | 337 static const char * |
339 begin_word(const char *text, const char *begin) | 338 begin_word(const char *text, const char *begin) |
349 | 348 |
350 return ++text; | 349 return ++text; |
351 } | 350 } |
352 | 351 |
353 static gboolean | 352 static gboolean |
354 move_back_word(GntWidget *widget, GList *null) | 353 move_back_word(GntBindable *bind, GList *null) |
355 { | 354 { |
356 GntEntry *entry = GNT_ENTRY(widget); | 355 GntEntry *entry = GNT_ENTRY(bind); |
357 const char *iter = entry->cursor - 1; | 356 const char *iter = entry->cursor - 1; |
358 | 357 |
359 if (iter < entry->start) | 358 if (iter < entry->start) |
360 return TRUE; | 359 return TRUE; |
361 iter = begin_word(iter, entry->start); | 360 iter = begin_word(iter, entry->start); |
362 entry->cursor = (char*)iter; | 361 entry->cursor = (char*)iter; |
363 if (entry->cursor < entry->scroll) | 362 if (entry->cursor < entry->scroll) |
364 entry->scroll = entry->cursor; | 363 entry->scroll = entry->cursor; |
365 entry_redraw(widget); | 364 entry_redraw(GNT_WIDGET(bind)); |
366 return TRUE; | 365 return TRUE; |
367 } | 366 } |
368 | 367 |
369 static gboolean | 368 static gboolean |
370 del_prev_word(GntWidget *widget, GList *null) | 369 del_prev_word(GntBindable *bind, GList *null) |
371 { | 370 { |
372 GntEntry *entry = GNT_ENTRY(widget); | 371 GntWidget *widget = GNT_WIDGET(bind); |
372 GntEntry *entry = GNT_ENTRY(bind); | |
373 char *iter = entry->cursor - 1; | 373 char *iter = entry->cursor - 1; |
374 int count; | 374 int count; |
375 | 375 |
376 if (iter < entry->start) | 376 if (iter < entry->start) |
377 return TRUE; | 377 return TRUE; |
533 } | 533 } |
534 | 534 |
535 static void | 535 static void |
536 gnt_entry_class_init(GntEntryClass *klass) | 536 gnt_entry_class_init(GntEntryClass *klass) |
537 { | 537 { |
538 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); | |
538 parent_class = GNT_WIDGET_CLASS(klass); | 539 parent_class = GNT_WIDGET_CLASS(klass); |
539 parent_class->destroy = gnt_entry_destroy; | 540 parent_class->destroy = gnt_entry_destroy; |
540 parent_class->draw = gnt_entry_draw; | 541 parent_class->draw = gnt_entry_draw; |
541 parent_class->map = gnt_entry_map; | 542 parent_class->map = gnt_entry_map; |
542 parent_class->size_request = gnt_entry_size_request; | 543 parent_class->size_request = gnt_entry_size_request; |
543 parent_class->key_pressed = gnt_entry_key_pressed; | 544 parent_class->key_pressed = gnt_entry_key_pressed; |
544 parent_class->lost_focus = gnt_entry_lost_focus; | 545 parent_class->lost_focus = gnt_entry_lost_focus; |
545 | 546 |
546 parent_class->actions = g_hash_table_duplicate(parent_class->actions, g_str_hash, | 547 gnt_bindable_class_register_action(bindable, "cursor-home", move_start, |
547 g_str_equal, g_free, (GDestroyNotify)gnt_widget_action_free); | |
548 parent_class->bindings = g_hash_table_duplicate(parent_class->bindings, g_str_hash, | |
549 g_str_equal, g_free, (GDestroyNotify)gnt_widget_action_param_free); | |
550 | |
551 gnt_widget_class_register_action(parent_class, "cursor-home", move_start, | |
552 GNT_KEY_CTRL_A, NULL); | 548 GNT_KEY_CTRL_A, NULL); |
553 gnt_widget_register_binding(parent_class, "cursor-home", GNT_KEY_HOME, NULL); | 549 gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL); |
554 gnt_widget_class_register_action(parent_class, "cursor-end", move_end, | 550 gnt_bindable_class_register_action(bindable, "cursor-end", move_end, |
555 GNT_KEY_CTRL_E, NULL); | 551 GNT_KEY_CTRL_E, NULL); |
556 gnt_widget_register_binding(parent_class, "cursor-end", GNT_KEY_END, NULL); | 552 gnt_bindable_register_binding(bindable, "cursor-end", GNT_KEY_END, NULL); |
557 gnt_widget_class_register_action(parent_class, "delete-prev", backspace, | 553 gnt_bindable_class_register_action(bindable, "delete-prev", backspace, |
558 GNT_KEY_BACKSPACE, NULL); | 554 GNT_KEY_BACKSPACE, NULL); |
559 gnt_widget_class_register_action(parent_class, "delete-next", delkey, | 555 gnt_bindable_class_register_action(bindable, "delete-next", delkey, |
560 GNT_KEY_DEL, NULL); | 556 GNT_KEY_DEL, NULL); |
561 gnt_widget_register_binding(parent_class, "delete-next", GNT_KEY_CTRL_D, NULL); | 557 gnt_bindable_register_binding(bindable, "delete-next", GNT_KEY_CTRL_D, NULL); |
562 gnt_widget_class_register_action(parent_class, "delete-start", del_to_home, | 558 gnt_bindable_class_register_action(bindable, "delete-start", del_to_home, |
563 GNT_KEY_CTRL_U, NULL); | 559 GNT_KEY_CTRL_U, NULL); |
564 gnt_widget_class_register_action(parent_class, "delete-end", del_to_end, | 560 gnt_bindable_class_register_action(bindable, "delete-end", del_to_end, |
565 GNT_KEY_CTRL_K, NULL); | 561 GNT_KEY_CTRL_K, NULL); |
566 gnt_widget_class_register_action(parent_class, "delete-prev-word", del_prev_word, | 562 gnt_bindable_class_register_action(bindable, "delete-prev-word", del_prev_word, |
567 NULL, NULL); | 563 NULL, NULL); |
568 #if 0 | 564 #if 0 |
569 gnt_widget_class_register_action(parent_class, "delete-next-word", del_next_word, | 565 gnt_bindable_class_register_action(bindable, "delete-next-word", del_next_word, |
570 NULL, 1, NULL); | 566 NULL, 1, NULL); |
571 #endif | 567 #endif |
572 gnt_widget_class_register_action(parent_class, "cursor-prev-word", move_back_word, | 568 gnt_bindable_class_register_action(bindable, "cursor-prev-word", move_back_word, |
573 NULL, NULL); | 569 NULL, NULL); |
574 gnt_widget_class_register_action(parent_class, "cursor-prev", move_back, | 570 gnt_bindable_class_register_action(bindable, "cursor-prev", move_back, |
575 GNT_KEY_LEFT, NULL); | 571 GNT_KEY_LEFT, NULL); |
576 gnt_widget_register_binding(parent_class, "cursor-prev", GNT_KEY_CTRL_B, NULL); | 572 gnt_bindable_register_binding(bindable, "cursor-prev", GNT_KEY_CTRL_B, NULL); |
577 gnt_widget_class_register_action(parent_class, "cursor-next", move_forward, | 573 gnt_bindable_class_register_action(bindable, "cursor-next", move_forward, |
578 GNT_KEY_RIGHT, NULL); | 574 GNT_KEY_RIGHT, NULL); |
579 gnt_widget_register_binding(parent_class, "cursor-next", GNT_KEY_CTRL_F, NULL); | 575 gnt_bindable_register_binding(bindable, "cursor-next", GNT_KEY_CTRL_F, NULL); |
580 gnt_widget_class_register_action(parent_class, "suggest-show", suggest_show, | 576 gnt_bindable_class_register_action(bindable, "suggest-show", suggest_show, |
581 "\t", NULL); | 577 "\t", NULL); |
582 gnt_widget_class_register_action(parent_class, "suggest-next", suggest_next, | 578 gnt_bindable_class_register_action(bindable, "suggest-next", suggest_next, |
583 GNT_KEY_DOWN, NULL); | 579 GNT_KEY_DOWN, NULL); |
584 gnt_widget_class_register_action(parent_class, "suggest-prev", suggest_prev, | 580 gnt_bindable_class_register_action(bindable, "suggest-prev", suggest_prev, |
585 GNT_KEY_UP, NULL); | 581 GNT_KEY_UP, NULL); |
586 gnt_widget_class_register_action(parent_class, "history-prev", history_prev, | 582 gnt_bindable_class_register_action(bindable, "history-prev", history_prev, |
587 "\033" GNT_KEY_CTRL_DOWN, NULL); | 583 "\033" GNT_KEY_CTRL_DOWN, NULL); |
588 gnt_widget_class_register_action(parent_class, "history-next", history_next, | 584 gnt_bindable_class_register_action(bindable, "history-next", history_next, |
589 "\033" GNT_KEY_CTRL_UP, NULL); | 585 "\033" GNT_KEY_CTRL_UP, NULL); |
590 | 586 |
591 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), parent_class); | 587 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); |
592 | |
593 GNTDEBUG; | 588 GNTDEBUG; |
594 } | 589 } |
595 | 590 |
596 static void | 591 static void |
597 gnt_entry_init(GTypeInstance *instance, gpointer class) | 592 gnt_entry_init(GTypeInstance *instance, gpointer class) |