From 1401f751cb69d58bc21f661e114c8bda053265e8 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 19 Jan 2016 15:02:43 +0300 Subject: [PATCH] WListbox: optimize mouse event processing. Signed-off-by: Andrew Borodin --- lib/widget/listbox.c | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 527f165c0..c68fd1d2f 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -10,7 +10,7 @@ Jakub Jelinek, 1995 Andrej Borsenkow, 1996 Norbert Warmuth, 1997 - Andrew Borodin , 2009, 2010, 2013 + Andrew Borodin , 2009, 2010, 2013, 2016 This file is part of the Midnight Commander. @@ -39,7 +39,6 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/tty/mouse.h" #include "lib/skin.h" #include "lib/strutil.h" #include "lib/util.h" /* Q_() */ @@ -397,14 +396,10 @@ listbox_on_change (WListbox * l) /* --------------------------------------------------------------------------------------------- */ static void -listbox_run_hotkey (WListbox * l, int pos) +listbox_do_action (WListbox * l) { - WDialog *h = WIDGET (l)->owner; int action; - listbox_select_entry (l, pos); - listbox_on_change (l); - if (l->callback != NULL) action = l->callback (l); else @@ -412,6 +407,8 @@ listbox_run_hotkey (WListbox * l, int pos) if (action == LISTBOX_DONE) { + WDialog *h = WIDGET (l)->owner; + h->ret_value = B_ENTER; dlg_stop (h); } @@ -419,6 +416,16 @@ listbox_run_hotkey (WListbox * l, int pos) /* --------------------------------------------------------------------------------------------- */ +static void +listbox_run_hotkey (WListbox * l, int pos) +{ + listbox_select_entry (l, pos); + listbox_on_change (l); + listbox_do_action (l); +} + +/* --------------------------------------------------------------------------------------------- */ + static inline void listbox_destroy (WListbox * l) { @@ -490,6 +497,9 @@ static void listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) { WListbox *l = LISTBOX (w); + int old_pos; + + old_pos = l->pos; switch (msg) { @@ -512,29 +522,18 @@ listbox_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) break; case MSG_MOUSE_CLICK: - if ((event->count & GPM_DOUBLE) != 0) /* Double click */ - { - int action; - - if (l->callback != NULL) - action = l->callback (l); - else - action = LISTBOX_DONE; - - if (action == LISTBOX_DONE) - { - w->owner->ret_value = B_ENTER; - dlg_stop (w->owner); - } - } + /* We don't call listbox_select_entry() here: MSG_MOUSE_DOWN/DRAG did this already. */ + if (event->count == GPM_DOUBLE) /* Double click */ + listbox_do_action (l); break; default: break; } - if (msg != MSG_MOUSE_UP) - listbox_draw (l, TRUE); + /* If the selection has changed, we redraw the widget and notify the dialog. */ + if (l->pos != old_pos) + listbox_on_change (l); } /* --------------------------------------------------------------------------------------------- */