Ticket #3562: 3562-listbox-should-fire-MSG_ACTION-on-mouse-clicks-too.patch

File 3562-listbox-should-fire-MSG_ACTION-on-mouse-clicks-too.patch, 4.2 KB (added by mooffie, 8 years ago)
  • lib/widget/listbox.c

    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) 
    383383 
    384384/* --------------------------------------------------------------------------------------------- */ 
    385385 
     386/* Call this whenever the user changes the selected item. */ 
     387static void 
     388listbox_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 
     396static void 
     397listbox_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 
    386419static inline void 
    387420listbox_destroy (WListbox * l) 
    388421{ 
    static cb_ret_t 
    395428listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) 
    396429{ 
    397430    WListbox *l = LISTBOX (w); 
    398     WDialog *h = w->owner; 
    399431    cb_ret_t ret_code; 
    400432 
    401433    switch (msg) 
    listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    405437 
    406438    case MSG_HOTKEY: 
    407439        { 
    408             int pos, action; 
     440            int pos; 
    409441 
    410442            pos = listbox_check_hotkey (l, parm); 
    411443            if (pos < 0) 
    412444                return MSG_NOT_HANDLED; 
    413445 
    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); 
    427447 
    428448            return MSG_HANDLED; 
    429449        } 
    listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    431451    case MSG_KEY: 
    432452        ret_code = listbox_key (l, parm); 
    433453        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); 
    438455        return ret_code; 
    439456 
    440457    case MSG_ACTION: 
    listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    442459 
    443460    case MSG_CURSOR: 
    444461        widget_move (l, l->cursor_y, 0); 
    445         send_message (h, w, MSG_ACTION, l->pos, NULL); 
    446462        return MSG_HANDLED; 
    447463 
    448464    case MSG_FOCUS: 
    listbox_event (Gpm_Event * event, void *data) 
    509525 
    510526        /* We need to refresh ourselves since the dialog manager doesn't */ 
    511527        /* know about this event */ 
    512         listbox_draw (l, TRUE); 
     528        listbox_on_change (l); 
    513529        return ret; 
    514530    } 
    515531 
    listbox_event (Gpm_Event * event, void *data) 
    517533    if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE)) 
    518534    { 
    519535        Gpm_Event local; 
    520         int action; 
    521536 
    522537        local = mouse_get_local (event, w); 
    523538        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)); 
    536540    } 
    537541 
    538542    return MOU_NORMAL;