Rename mouse.was_drag to mouse.last_msg.

Get rid of the 'click' variable.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Mooffie 2016-03-23 18:17:05 +02:00 committed by Andrew Borodin
parent 8490ca7be4
commit 438e841226
5 changed files with 26 additions and 24 deletions

View File

@ -365,12 +365,11 @@ dlg_handle_key (WDialog * h, int d_key)
static int
dlg_mouse_translator (Gpm_Event * event, Widget * w)
{
gboolean run_click;
mouse_event_t me;
me = mouse_translate_event (w, event, &run_click);
me = mouse_translate_event (w, event);
return mouse_process_event (w, &me, run_click);
return mouse_process_event (w, &me);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -78,12 +78,11 @@ init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * glob
*
* @param w Widget object
* @param event GPM event
* @param click whether mouse click was raised or not
*
* @return high level mouse event
*/
mouse_event_t
mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
mouse_translate_event (Widget * w, Gpm_Event * event)
{
gboolean in_widget;
mouse_msg_t msg = MSG_MOUSE_NONE;
@ -97,8 +96,6 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
*/
in_widget = w->mouse.forced_capture || mouse_global_in_widget (event, w);
*click = FALSE;
if ((event->type & GPM_DOWN) != 0)
{
if (in_widget)
@ -132,9 +129,6 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
w->mouse.capture = FALSE;
msg = MSG_MOUSE_UP;
if (in_widget)
*click = !w->mouse.was_drag;
/*
* When using xterm, event->buttons reports the buttons' state
* after the event occurred (meaning that event->buttons is zero,
@ -158,10 +152,6 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
msg = MSG_MOUSE_MOVE;
}
if (msg != MSG_MOUSE_NONE)
/* Remember the current state for next event. */
w->mouse.was_drag = ((event->type & GPM_DRAG) != 0);
init_mouse_event (&local, msg, event, w);
return local;
@ -172,23 +162,33 @@ mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
/**
* Call widget mouse handler to process high-level mouse event.
*
* Besides sending to the widget the event itself, this function may also
* send one or more pseudo events. Currently, MSG_MOUSE_CLICK is the only
* pseudo event in existence but in the future (e.g., with the introduction
* of a drag-drop API) there may be more.
*
* @param w Widget object
* @param high level mouse event
* @param click whether mouse click was raised or not
* @param event high level mouse event
*
* @return result of mouse event handling
*/
int
mouse_process_event (Widget * w, mouse_event_t * event, gboolean click)
mouse_process_event (Widget * w, mouse_event_t * event)
{
int ret = MOU_UNHANDLED;
if (event->msg != MSG_MOUSE_NONE)
{
w->mouse_callback (w, event->msg, event);
if (click)
/* Upon releasing the mouse button: if the mouse hasn't been dragged
* since the MSG_MOUSE_DOWN, we also trigger a click. */
if (event->msg == MSG_MOUSE_UP && w->mouse.last_msg == MSG_MOUSE_DOWN)
w->mouse_callback (w, MSG_MOUSE_CLICK, event);
/* Record the current event type for the benefit of the next event. */
w->mouse.last_msg = event->msg;
if (!event->result.abort)
ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL;
}

View File

@ -58,9 +58,9 @@ typedef struct
/*** declarations of public functions ************************************************************/
/* Translate GPM event to high-level event */
mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click);
mouse_event_t mouse_translate_event (Widget * w, Gpm_Event * event);
/* Process high-level mouse event */
int mouse_process_event (Widget * w, mouse_event_t * event, gboolean click);
int mouse_process_event (Widget * w, mouse_event_t * event);
/*** inline functions ****************************************************************************/

View File

@ -149,10 +149,10 @@ widget_init (Widget * w, int y, int x, int lines, int cols,
w->mouse_callback = mouse_callback;
w->set_options = widget_default_set_options_callback;
w->owner = NULL;
w->mouse.capture = FALSE;
w->mouse.forced_capture = FALSE;
w->mouse.capture = FALSE;
w->mouse.last_msg = MSG_MOUSE_NONE;
w->mouse.last_buttons_down = 0;
w->mouse.was_drag = FALSE;
/* Almost all widgets want to put the cursor in a suitable place */
w->options = W_WANT_CURSOR;

View File

@ -112,10 +112,13 @@ struct Widget
/* Mouse-related fields. */
struct
{
/* Public members: */
gboolean forced_capture; /* Overrides the 'capture' member. Set explicitly by the programmer. */
/* Implementation details: */
gboolean capture; /* Whether the widget "owns" the mouse. */
gboolean forced_capture; /* Overrides the above. Set explicitly by the programmer. */
mouse_msg_t last_msg; /* The previous event type processed. */
int last_buttons_down;
gboolean was_drag;
} mouse;
};