WTree: use the new mouse API.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2016-01-30 18:14:48 +03:00
parent 5debec4917
commit 4b420aa85c

View File

@ -14,7 +14,7 @@
Norbert Warmuth, 1997
Miguel de Icaza, 1996, 1999
Slava Zanko <slavazanko@gmail.com>, 2013
Andrew Borodin <aborodin@vmail.ru>, 2013, 2014
Andrew Borodin <aborodin@vmail.ru>, 2013, 2014, 2016
This file is part of the Midnight Commander.
@ -46,7 +46,6 @@
#include "lib/global.h"
#include "lib/tty/tty.h"
#include "lib/tty/mouse.h"
#include "lib/tty/key.h"
#include "lib/skin.h"
#include "lib/vfs/vfs.h"
@ -612,59 +611,6 @@ maybe_chdir (WTree * tree)
tree_chdir_sel (tree);
}
/* --------------------------------------------------------------------------------------------- */
/** Mouse callback */
static int
tree_event (Gpm_Event * event, void *data)
{
WTree *tree = (WTree *) data;
Widget *w = WIDGET (data);
Gpm_Event local;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
/* rest of the upper frame - call menu */
if (tree->is_panel && (event->type & GPM_DOWN) != 0 && event->y == WIDGET (w->owner)->y + 1)
return MOU_UNHANDLED;
local = mouse_get_local (event, w);
if ((local.type & GPM_UP) == 0)
return MOU_NORMAL;
if (tree->is_panel)
local.y--;
local.y--;
if (!tree->active)
change_panel ();
if (local.y < 0)
{
tree_move_backward (tree, tlines (tree) - 1);
show_tree (tree);
}
else if (local.y >= tlines (tree))
{
tree_move_forward (tree, tlines (tree) - 1);
show_tree (tree);
}
else if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
{
if (tree->tree_shown[local.y] != NULL)
{
tree->selected_ptr = tree->tree_shown[local.y];
tree->topdiff = local.y;
}
tree_chdir_sel (tree);
}
return MOU_NORMAL;
}
/* --------------------------------------------------------------------------------------------- */
/** Search tree for text */
@ -1253,6 +1199,73 @@ tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* Mouse callback
*/
static void
tree_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{
WTree *tree = (WTree *) w;
int y;
y = event->y;
if (tree->is_panel)
y--;
switch (msg)
{
case MSG_MOUSE_DOWN:
/* rest of the upper frame - call menu */
if (tree->is_panel && event->y == WIDGET (w->owner)->y)
{
/* return MOU_UNHANDLED */
event->result.abort = TRUE;
}
else if (!tree->active)
change_panel ();
break;
case MSG_MOUSE_CLICK:
{
int lines;
lines = tlines (tree);
if (y < 0)
{
tree_move_backward (tree, lines - 1);
show_tree (tree);
}
else if (y >= lines)
{
tree_move_forward (tree, lines - 1);
show_tree (tree);
}
else if ((event->count & GPM_DOUBLE) != 0)
{
if (tree->tree_shown[y] != NULL)
{
tree->selected_ptr = tree->tree_shown[y];
tree->topdiff = y;
}
tree_chdir_sel (tree);
}
}
break;
case MSG_MOUSE_SCROLL_UP:
case MSG_MOUSE_SCROLL_DOWN:
/* TODO: Ticket #2218 */
break;
default:
break;
}
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -1266,7 +1279,8 @@ tree_new (int y, int x, int lines, int cols, gboolean is_panel)
tree = g_new (WTree, 1);
w = WIDGET (tree);
widget_init (w, y, x, lines, cols, tree_callback, tree_event);
widget_init (w, y, x, lines, cols, tree_callback, NULL);
set_easy_mouse_callback (w, tree_mouse_callback);
tree->is_panel = is_panel;
tree->selected_ptr = 0;