Ticket #3571: 3571-Fix-WListbox-to-use-the-new-mouse-API.patch

File 3571-Fix-WListbox-to-use-the-new-mouse-API.patch, 4.1 KB (added by mooffie, 8 years ago)
  • lib/widget/listbox.c

    From fcf8041795214c80629a4e3d110a747173480652 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Thu, 26 Nov 2015 00:31:53 +0200
    Subject: [PATCH] Fix WListbox to use the new mouse API.
    
    ---
     lib/widget/listbox.c | 97 ++++++++++++++++++++++------------------------------
     1 file changed, 40 insertions(+), 57 deletions(-)
    
    diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
    index ef39d4d..44d0b65 100644
    a b listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    468468 
    469469/* --------------------------------------------------------------------------------------------- */ 
    470470 
    471 static int 
    472 listbox_event (Gpm_Event * event, void *data) 
     471static void 
     472listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) 
    473473{ 
    474     WListbox *l = LISTBOX (data); 
    475     Widget *w = WIDGET (data); 
    476  
    477     if (!mouse_global_in_widget (event, w)) 
    478         return MOU_UNHANDLED; 
     474    WListbox *l = LISTBOX (w); 
    479475 
    480     /* Single click */ 
    481     if ((event->type & GPM_DOWN) != 0) 
     476    switch (msg) 
     477    { 
     478    case MSG_MOUSE_DOWN: 
    482479        dlg_select_widget (l); 
     480        listbox_select_entry (l, listbox_select_pos (l, l->top, event->y)); 
     481        break; 
    483482 
    484     if (listbox_is_empty (l)) 
    485         return MOU_NORMAL; 
    486  
    487     if ((event->type & (GPM_DOWN | GPM_DRAG)) != 0) 
    488     { 
    489         int ret = MOU_REPEAT; 
    490         Gpm_Event local; 
    491         int i; 
     483    case MSG_MOUSE_SCROLL_UP: 
     484        listbox_back (l); 
     485        break; 
    492486 
    493         local = mouse_get_local (event, w); 
    494         if (local.y < 1) 
    495             for (i = -local.y; i >= 0; i--) 
    496                 listbox_back (l); 
    497         else if (local.y > w->lines) 
    498             for (i = local.y - w->lines; i > 0; i--) 
    499                 listbox_fwd (l); 
    500         else if ((local.buttons & GPM_B_UP) != 0) 
    501         { 
    502             listbox_back (l); 
    503             ret = MOU_NORMAL; 
    504         } 
    505         else if ((local.buttons & GPM_B_DOWN) != 0) 
    506         { 
    507             listbox_fwd (l); 
    508             ret = MOU_NORMAL; 
    509         } 
    510         else 
    511             listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1)); 
     487    case MSG_MOUSE_SCROLL_DOWN: 
     488        listbox_fwd (l); 
     489        break; 
    512490 
    513         listbox_draw (l, TRUE); 
    514         return ret; 
    515     } 
     491    case MSG_MOUSE_DRAG: 
     492        event->result.repeat = TRUE;    /* It'd be functional even without this. */ 
     493        listbox_select_entry (l, listbox_select_pos (l, l->top, event->y)); 
     494        break; 
    516495 
    517     /* Double click */ 
    518     if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE)) 
    519     { 
    520         Gpm_Event local; 
    521         int action; 
     496    case MSG_MOUSE_CLICK: 
    522497 
    523         local = mouse_get_local (event, w); 
    524         dlg_select_widget (l); 
    525         listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1)); 
     498        if ((event->count & GPM_DOUBLE) != 0)   /* Double click */ 
     499        { 
     500            int action; 
    526501 
    527         if (l->callback != NULL) 
    528             action = l->callback (l); 
    529         else 
    530             action = LISTBOX_DONE; 
     502            if (l->callback != NULL) 
     503                action = l->callback (l); 
     504            else 
     505                action = LISTBOX_DONE; 
    531506 
    532         if (action == LISTBOX_DONE) 
    533         { 
    534             w->owner->ret_value = B_ENTER; 
    535             dlg_stop (w->owner); 
     507            if (action == LISTBOX_DONE) 
     508            { 
     509                w->owner->ret_value = B_ENTER; 
     510                dlg_stop (w->owner); 
     511            } 
    536512        } 
     513 
     514        break; 
     515 
     516    default: 
     517        break; 
    537518    } 
    538519 
    539     return MOU_NORMAL; 
     520    if (msg != MSG_MOUSE_UP) 
     521        listbox_draw (l, TRUE); 
    540522} 
    541523 
    542524/* --------------------------------------------------------------------------------------------- */ 
    listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn 
    554536 
    555537    l = g_new (WListbox, 1); 
    556538    w = WIDGET (l); 
    557     widget_init (w, y, x, height, width, listbox_callback, listbox_event); 
     539    widget_init (w, y, x, height, width, listbox_callback, NULL); 
     540    set_easy_mouse_callback (w, listbox_mouse_callback); 
    558541 
    559542    l->list = NULL; 
    560543    l->top = l->pos = 0;