Viewer: use the new mouse API.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-01-31 15:36:11 +03:00
parent 4317ceaf84
commit f926b25fe5

View File

@ -38,7 +38,6 @@
#include "lib/global.h"
#include "lib/tty/tty.h"
#include "lib/tty/mouse.h"
#include "lib/vfs/vfs.h"
#include "lib/strutil.h"
#include "lib/util.h" /* load_file_position() */
@ -77,85 +76,82 @@ char *mcview_show_eof = NULL;
/*** file scope variables ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/** Both views */
static gboolean
do_mcview_event (WView * view, Gpm_Event * event, int *result)
static void
mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{
screen_dimen y, x;
Gpm_Event local;
Widget *w = WIDGET (view);
WView *view = (WView *) w;
gboolean ok = TRUE;
/* rest of the upper frame - call menu */
if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) != 0 &&
event->y == WIDGET (w->owner)->y + 1)
switch (msg)
{
*result = MOU_UNHANDLED;
return FALSE; /* don't draw viewer over menu */
case MSG_MOUSE_DOWN:
if (mcview_is_in_panel (view))
{
if (event->y == WIDGET (w->owner)->y)
{
/* return MOU_UNHANDLED */
event->result.abort = TRUE;
/* don't draw viewer over menu */
ok = FALSE;
break;
}
*result = MOU_NORMAL;
local = mouse_get_local (event, w);
/* We are not interested in the release events */
if ((local.type & (GPM_DOWN | GPM_DRAG)) == 0)
return FALSE;
/* Wheel events. Allow them in the inactive panel */
if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
if (!view->active)
{
mcview_move_up (view, 2);
return TRUE;
}
if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
{
mcview_move_down (view, 2);
return TRUE;
}
/* Grab focus */
if (mcview_is_in_panel (view) && !view->active)
change_panel ();
}
}
/* fall throught */
x = local.x;
y = local.y;
/* Scrolling left and right */
case MSG_MOUSE_CLICK:
if (!view->text_wrap_mode)
{
/* Scrolling left and right */
screen_dimen x;
x = event->x + 1; /* FIXME */
if (x < view->data_area.width * 1 / 4)
{
mcview_move_left (view, 1);
goto processed;
event->result.repeat = msg == MSG_MOUSE_DOWN;
}
if (x < view->data_area.width * 3 / 4)
else if (x < view->data_area.width * 3 / 4)
{
/* ignore the click */
ok = FALSE;
}
else
{
mcview_move_right (view, 1);
goto processed;
event->result.repeat = msg == MSG_MOUSE_DOWN;
}
}
else
{
/* Scrolling up and down */
screen_dimen y;
y = event->y + 1; /* FIXME */
if (y < view->data_area.top + view->data_area.height * 1 / 3)
{
if (mcview_mouse_move_pages)
mcview_move_up (view, view->data_area.height / 2);
else
mcview_move_up (view, 1);
goto processed;
event->result.repeat = msg == MSG_MOUSE_DOWN;
}
else if (y < view->data_area.top + view->data_area.height * 2 / 3)
{
/* ignore the click */
ok = FALSE;
}
else
{
@ -163,31 +159,27 @@ do_mcview_event (WView * view, Gpm_Event * event, int *result)
mcview_move_down (view, view->data_area.height / 2);
else
mcview_move_down (view, 1);
goto processed;
event->result.repeat = msg == MSG_MOUSE_DOWN;
}
}
break;
case MSG_MOUSE_SCROLL_UP:
mcview_move_up (view, 2);
break;
case MSG_MOUSE_SCROLL_DOWN:
mcview_move_down (view, 2);
break;
default:
ok = FALSE;
break;
}
return FALSE;
processed:
*result = MOU_REPEAT;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
/** Real view only */
static int
mcview_event (Gpm_Event * event, void *data)
{
WView *view = (WView *) data;
int result;
if (!mouse_global_in_widget (event, WIDGET (data)))
return MOU_UNHANDLED;
if (do_mcview_event (view, event, &result))
if (ok)
mcview_update (view);
return result;
}
/* --------------------------------------------------------------------------------------------- */
@ -200,7 +192,8 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
WView *view;
view = g_new0 (WView, 1);
widget_init (WIDGET (view), y, x, lines, cols, mcview_callback, mcview_event);
widget_init (WIDGET (view), y, x, lines, cols, mcview_callback, NULL);
set_easy_mouse_callback (WIDGET (view), mcview_mouse_callback);
view->hex_mode = FALSE;
view->hexedit_mode = FALSE;