From eed6558cf75b6438e40bbb036090c57b3eb1f027 Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Sat, 21 Nov 2015 21:00:46 +0200
Subject: [PATCH] Listbox should fire MSG_ACTION on mouse clicks too.
---
lib/widget/listbox.c | 72 +++++++++++++++++++++++++++-------------------------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
index edd15b5..ab3fc1f 100644
a
|
b
|
listbox_append_item (WListbox * l, WLEntry * e, listbox_append_t pos) |
383 | 383 | |
384 | 384 | /* --------------------------------------------------------------------------------------------- */ |
385 | 385 | |
| 386 | /* Call this whenever the user changes the selected item. */ |
| 387 | static void |
| 388 | listbox_on_change (WListbox * l) |
| 389 | { |
| 390 | listbox_draw (l, TRUE); |
| 391 | send_message (WIDGET (l)->owner, l, MSG_ACTION, l->pos, NULL); |
| 392 | } |
| 393 | |
| 394 | /* --------------------------------------------------------------------------------------------- */ |
| 395 | |
| 396 | static void |
| 397 | listbox_run_hotkey (WListbox * l, int pos) |
| 398 | { |
| 399 | WDialog *h = WIDGET (l)->owner; |
| 400 | int action; |
| 401 | |
| 402 | listbox_select_entry (l, pos); |
| 403 | listbox_on_change (l); |
| 404 | |
| 405 | if (l->callback != NULL) |
| 406 | action = l->callback (l); |
| 407 | else |
| 408 | action = LISTBOX_DONE; |
| 409 | |
| 410 | if (action == LISTBOX_DONE) |
| 411 | { |
| 412 | h->ret_value = B_ENTER; |
| 413 | dlg_stop (h); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /* --------------------------------------------------------------------------------------------- */ |
| 418 | |
386 | 419 | static inline void |
387 | 420 | listbox_destroy (WListbox * l) |
388 | 421 | { |
… |
… |
static cb_ret_t |
395 | 428 | listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) |
396 | 429 | { |
397 | 430 | WListbox *l = LISTBOX (w); |
398 | | WDialog *h = w->owner; |
399 | 431 | cb_ret_t ret_code; |
400 | 432 | |
401 | 433 | switch (msg) |
… |
… |
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void |
405 | 437 | |
406 | 438 | case MSG_HOTKEY: |
407 | 439 | { |
408 | | int pos, action; |
| 440 | int pos; |
409 | 441 | |
410 | 442 | pos = listbox_check_hotkey (l, parm); |
411 | 443 | if (pos < 0) |
412 | 444 | return MSG_NOT_HANDLED; |
413 | 445 | |
414 | | listbox_select_entry (l, pos); |
415 | | send_message (h, w, MSG_ACTION, l->pos, NULL); |
416 | | |
417 | | if (l->callback != NULL) |
418 | | action = l->callback (l); |
419 | | else |
420 | | action = LISTBOX_DONE; |
421 | | |
422 | | if (action == LISTBOX_DONE) |
423 | | { |
424 | | h->ret_value = B_ENTER; |
425 | | dlg_stop (h); |
426 | | } |
| 446 | listbox_run_hotkey (l, pos); |
427 | 447 | |
428 | 448 | return MSG_HANDLED; |
429 | 449 | } |
… |
… |
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void |
431 | 451 | case MSG_KEY: |
432 | 452 | ret_code = listbox_key (l, parm); |
433 | 453 | if (ret_code != MSG_NOT_HANDLED) |
434 | | { |
435 | | listbox_draw (l, TRUE); |
436 | | send_message (h, w, MSG_ACTION, l->pos, NULL); |
437 | | } |
| 454 | listbox_on_change (l); |
438 | 455 | return ret_code; |
439 | 456 | |
440 | 457 | case MSG_ACTION: |
… |
… |
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void |
442 | 459 | |
443 | 460 | case MSG_CURSOR: |
444 | 461 | widget_move (l, l->cursor_y, 0); |
445 | | send_message (h, w, MSG_ACTION, l->pos, NULL); |
446 | 462 | return MSG_HANDLED; |
447 | 463 | |
448 | 464 | case MSG_FOCUS: |
… |
… |
listbox_event (Gpm_Event * event, void *data) |
509 | 525 | |
510 | 526 | /* We need to refresh ourselves since the dialog manager doesn't */ |
511 | 527 | /* know about this event */ |
512 | | listbox_draw (l, TRUE); |
| 528 | listbox_on_change (l); |
513 | 529 | return ret; |
514 | 530 | } |
515 | 531 | |
… |
… |
listbox_event (Gpm_Event * event, void *data) |
517 | 533 | if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE)) |
518 | 534 | { |
519 | 535 | Gpm_Event local; |
520 | | int action; |
521 | 536 | |
522 | 537 | local = mouse_get_local (event, w); |
523 | 538 | dlg_select_widget (l); |
524 | | listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1)); |
525 | | |
526 | | if (l->callback != NULL) |
527 | | action = l->callback (l); |
528 | | else |
529 | | action = LISTBOX_DONE; |
530 | | |
531 | | if (action == LISTBOX_DONE) |
532 | | { |
533 | | w->owner->ret_value = B_ENTER; |
534 | | dlg_stop (w->owner); |
535 | | } |
| 539 | listbox_run_hotkey (l, listbox_select_pos (l, l->top, local.y - 1)); |
536 | 540 | } |
537 | 541 | |
538 | 542 | return MOU_NORMAL; |