WInput: use the new mouse API.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-01-19 15:04:48 +03:00
parent 30a56a9793
commit ebac1745bc
1 changed files with 47 additions and 43 deletions

View File

@ -41,7 +41,6 @@
#include "lib/global.h" #include "lib/global.h"
#include "lib/tty/tty.h" #include "lib/tty/tty.h"
#include "lib/tty/mouse.h"
#include "lib/tty/key.h" /* XCTRL and ALT macros */ #include "lib/tty/key.h" /* XCTRL and ALT macros */
#include "lib/fileloc.h" #include "lib/fileloc.h"
#include "lib/skin.h" #include "lib/skin.h"
@ -909,59 +908,63 @@ input_destroy (WInput * in)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Calculates the buffer index (aka "point") corresponding to some screen coordinate.
*/
static int static int
input_event (Gpm_Event * event, void *data) input_screen_to_point (const WInput * in, int x)
{ {
/* save point between GPM_DOWN and GPM_DRAG */ x += in->term_first_shown;
static int prev_point = 0;
WInput *in = INPUT (data); if (x < 0)
Widget *w = WIDGET (data); return 0;
if (!mouse_global_in_widget (event, w)) if (x < str_term_width1 (in->buffer))
return MOU_UNHANDLED; return str_column_to_pos (in->buffer, x);
if ((event->type & GPM_DOWN) != 0) return str_length (in->buffer);
{
in->first = FALSE;
input_mark_cmd (in, FALSE);
} }
if ((event->type & (GPM_DOWN | GPM_DRAG)) != 0) /* --------------------------------------------------------------------------------------------- */
static void
input_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{ {
Gpm_Event local; /* save point between MSG_MOUSE_DOWN and MSG_MOUSE_DRAG */
static int prev_point = 0;
local = mouse_get_local (event, w); WInput *in = INPUT (w);
switch (msg)
{
case MSG_MOUSE_DOWN:
dlg_select_widget (w); dlg_select_widget (w);
in->first = FALSE;
if (local.x >= w->cols - HISTORY_BUTTON_WIDTH + 1 && should_show_history_button (in)) if (event->x >= w->cols - HISTORY_BUTTON_WIDTH && should_show_history_button (in))
do_show_hist (in); do_show_hist (in);
else else
{ {
if (local.x + in->term_first_shown - 1 < str_term_width1 (in->buffer)) input_mark_cmd (in, FALSE);
in->point = str_column_to_pos (in->buffer, local.x + in->term_first_shown - 1); input_set_point (in, input_screen_to_point (in, event->x));
else /* save point for the possible following MSG_MOUSE_DRAG action */
in->point = str_length (in->buffer);
/* save point for the possible following GPM_DRAG action */
if ((event->type & GPM_DOWN) != 0)
prev_point = in->point; prev_point = in->point;
} }
} break;
/* start point: set marker using point before first GPM_DRAG action */ case MSG_MOUSE_DRAG:
if (in->mark < 0 && (event->type & GPM_DRAG) != 0) /* start point: set marker using point before first MSG_MOUSE_DRAG action */
if (in->mark < 0)
in->mark = prev_point; in->mark = prev_point;
input_set_point (in, input_screen_to_point (in, event->x));
break;
default:
/* don't create highlight region of 0 length */ /* don't create highlight region of 0 length */
if (in->mark == in->point) if (in->mark == in->point)
input_mark_cmd (in, FALSE); input_mark_cmd (in, FALSE);
break;
if ((event->type & (GPM_DOWN | GPM_DRAG)) != 0) }
input_update (in, TRUE);
return MOU_NORMAL;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -1006,7 +1009,8 @@ input_new (int y, int x, const int *colors, int width, const char *def_text,
in = g_new (WInput, 1); in = g_new (WInput, 1);
w = WIDGET (in); w = WIDGET (in);
widget_init (w, y, x, 1, width, input_callback, input_event); widget_init (w, y, x, 1, width, input_callback, NULL);
set_easy_mouse_callback (w, input_mouse_callback);
w->options |= W_IS_INPUT; w->options |= W_IS_INPUT;
w->set_options = input_set_options_callback; w->set_options = input_set_options_callback;