1
1

Put global mouse coordinates to widgets.

Now each widget gets absolute coordinates of mouse pointer and decides
itself how to handle them.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
Andrew Borodin 2011-03-21 16:43:56 +03:00
родитель 7956b64e54
Коммит 33d25a0c8f
18 изменённых файлов: 287 добавлений и 202 удалений

Просмотреть файл

@ -63,6 +63,7 @@ enum Gpm_Etype
/* Constants returned from the mouse callback */
enum
{
MOU_UNHANDLED = 0,
MOU_NORMAL,
MOU_REPEAT
};

Просмотреть файл

@ -182,20 +182,21 @@ button_callback (Widget * w, widget_msg_t msg, int parm)
static int
button_event (Gpm_Event * event, void *data)
{
WButton *b = data;
Widget *w = (Widget *) data;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
{
Dlg_head *h = b->widget.owner;
dlg_select_widget (b);
dlg_select_widget (w);
if ((event->type & GPM_UP) != 0)
{
button_callback (&b->widget, WIDGET_KEY, ' ');
h->callback (h, &b->widget, DLG_POST_KEY, ' ', NULL);
return MOU_NORMAL;
button_callback (w, WIDGET_KEY, ' ');
w->owner->callback (w->owner, w, DLG_POST_KEY, ' ', NULL);
}
}
return MOU_NORMAL;
}

Просмотреть файл

@ -218,16 +218,23 @@ buttonbar_callback (Widget * w, widget_msg_t msg, int parm)
static int
buttonbar_event (Gpm_Event * event, void *data)
{
WButtonBar *bb = data;
int button;
Widget *w = (Widget *) data;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
if ((event->type & GPM_UP) != 0)
{
WButtonBar *bb = (WButtonBar *) data;
Gpm_Event local;
int button;
local = mouse_get_local (event, w);
button = buttonbar_get_button_by_x_coord (bb, local.x - 1);
if (button >= 0)
buttonbar_call (bb, button);
}
if (!(event->type & GPM_UP))
return MOU_NORMAL;
if (event->y == 2)
return MOU_NORMAL;
button = buttonbar_get_button_by_x_coord (bb, event->x - 1);
if (button >= 0)
buttonbar_call (bb, button);
return MOU_NORMAL;
}

Просмотреть файл

@ -108,22 +108,22 @@ check_callback (Widget * w, widget_msg_t msg, int parm)
static int
check_event (Gpm_Event * event, void *data)
{
WCheck *c = data;
Widget *w = data;
Widget *w = (Widget *) data;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
{
Dlg_head *h = c->widget.owner;
dlg_select_widget (c);
if (event->type & GPM_UP)
dlg_select_widget (w);
if ((event->type & GPM_UP) != 0)
{
check_callback (w, WIDGET_KEY, ' ');
check_callback (w, WIDGET_FOCUS, 0);
h->callback (h, w, DLG_POST_KEY, ' ', NULL);
return MOU_NORMAL;
w->owner->callback (w->owner, w, DLG_POST_KEY, ' ', NULL);
}
}
return MOU_NORMAL;
}

Просмотреть файл

@ -357,12 +357,12 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
{
GList *item;
GList *starting_widget = h->current;
Gpm_Event new_event;
int x = event->x;
int y = event->y;
/* close the dialog by mouse click out of dialog area */
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0)
&& ((event->type & GPM_DOWN) != 0) /* left click */
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
{
h->ret_value = B_CANCEL;
@ -380,21 +380,19 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
else
item = dlg_widget_next (h, item);
if (((widget->options & W_DISABLED) == 0)
&& (x > widget->x) && (x <= widget->x + widget->cols)
&& (y > widget->y) && (y <= widget->y + widget->lines))
if ((widget->options & W_DISABLED) == 0 && widget->mouse != NULL)
{
new_event = *event;
new_event.x -= widget->x;
new_event.y -= widget->y;
/* put global cursor position to the widget */
int ret;
if (widget->mouse != NULL)
return widget->mouse (&new_event, widget);
ret = widget->mouse (event, widget);
if (ret != MOU_UNHANDLED)
return ret;
}
}
while (item != starting_widget);
return MOU_NORMAL;
return MOU_UNHANDLED;
}
/* --------------------------------------------------------------------------------------------- */
@ -775,7 +773,7 @@ create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
new_d->fullscreen = (new_d->x == 0 && new_d->y == 0
&& new_d->cols == COLS && new_d->lines == LINES);
new_d->mouse_status = MOU_NORMAL;
new_d->mouse_status = MOU_UNHANDLED;
/* Strip existing spaces, add one space before and after the title */
if (title != NULL)

Просмотреть файл

@ -902,6 +902,10 @@ static int
input_event (Gpm_Event * event, void *data)
{
WInput *in = (WInput *) data;
Widget *w = (Widget *) data;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
if ((event->type & GPM_DOWN) != 0)
{
@ -911,19 +915,25 @@ input_event (Gpm_Event * event, void *data)
if ((event->type & (GPM_DOWN | GPM_DRAG)) != 0)
{
dlg_select_widget (in);
Gpm_Event local;
if (event->x >= in->field_width - HISTORY_BUTTON_WIDTH + 1
local = mouse_get_local (event, w);
dlg_select_widget (w);
if (local.x >= in->field_width - HISTORY_BUTTON_WIDTH + 1
&& should_show_history_button (in))
do_show_hist (in);
else
{
in->point = str_length (in->buffer);
if (event->x + in->term_first_shown - 1 < str_term_width1 (in->buffer))
in->point = str_column_to_pos (in->buffer, event->x + in->term_first_shown - 1);
if (local.x + in->term_first_shown - 1 < str_term_width1 (in->buffer))
in->point = str_column_to_pos (in->buffer, local.x + in->term_first_shown - 1);
}
input_update (in, TRUE);
}
/* A lone up mustn't do anything */
if (in->highlight && (event->type & (GPM_UP | GPM_DRAG)) != 0)
return MOU_NORMAL;

Просмотреть файл

@ -434,43 +434,44 @@ listbox_callback (Widget * w, widget_msg_t msg, int parm)
static int
listbox_event (Gpm_Event * event, void *data)
{
WListbox *l = data;
int i;
WListbox *l = (WListbox *) data;
Widget *w = (Widget *) data;
Dlg_head *h = l->widget.owner;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
/* Single click */
if (event->type & GPM_DOWN)
if ((event->type & GPM_DOWN) != 0)
dlg_select_widget (l);
if (l->list == NULL)
return MOU_NORMAL;
if (event->type & (GPM_DOWN | GPM_DRAG))
if ((event->type & (GPM_DOWN | GPM_DRAG)) != 0)
{
int ret = MOU_REPEAT;
Gpm_Event local;
int i;
if (event->x < 0 || event->x > l->widget.cols)
return ret;
if (event->y < 1)
for (i = -event->y; i >= 0; i--)
local = mouse_get_local (event, w);
if (local.y < 1)
for (i = -local.y; i >= 0; i--)
listbox_back (l);
else if (event->y > l->widget.lines)
for (i = event->y - l->widget.lines; i > 0; i--)
else if (local.y > w->lines)
for (i = local.y - w->lines; i > 0; i--)
listbox_fwd (l);
else if (event->buttons & GPM_B_UP)
else if ((local.buttons & GPM_B_UP) != 0)
{
listbox_back (l);
ret = MOU_NORMAL;
}
else if (event->buttons & GPM_B_DOWN)
else if ((local.buttons & GPM_B_DOWN) != 0)
{
listbox_fwd (l);
ret = MOU_NORMAL;
}
else
listbox_select_entry (l, listbox_select_pos (l, l->top, event->y - 1));
listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1));
/* We need to refresh ourselves since the dialog manager doesn't */
/* know about this event */
@ -481,14 +482,12 @@ listbox_event (Gpm_Event * event, void *data)
/* Double click */
if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE))
{
Gpm_Event local;
int action;
if (event->x < 0 || event->x >= l->widget.cols
|| event->y < 1 || event->y > l->widget.lines)
return MOU_NORMAL;
local = mouse_get_local (event, w);
dlg_select_widget (l);
listbox_select_entry (l, listbox_select_pos (l, l->top, event->y - 1));
listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1));
if (l->callback != NULL)
action = l->callback (l);
@ -497,11 +496,11 @@ listbox_event (Gpm_Event * event, void *data)
if (action == LISTBOX_DONE)
{
h->ret_value = B_ENTER;
dlg_stop (h);
return MOU_NORMAL;
w->owner->ret_value = B_ENTER;
dlg_stop (w->owner);
}
}
return MOU_NORMAL;
}

Просмотреть файл

@ -589,10 +589,15 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
static int
menubar_event (Gpm_Event * event, void *data)
{
WMenuBar *menubar = data;
WMenuBar *menubar = (WMenuBar *) data;
Widget *w = (Widget *) data;
gboolean was_active = TRUE;
int left_x, right_x, bottom_y;
Menu *menu;
Gpm_Event local;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
/* ignore unsupported events */
if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0)
@ -604,22 +609,24 @@ menubar_event (Gpm_Event * event, void *data)
if (!menubar->is_dropped)
{
menubar->previous_widget = dlg_get_current_widget_id (menubar->widget.owner);
menubar->previous_widget = dlg_get_current_widget_id (w->owner);
menubar->is_active = TRUE;
menubar->is_dropped = TRUE;
was_active = FALSE;
}
local = mouse_get_local (event, w);
/* Mouse operations on the menubar */
if (event->y == 1 || !was_active)
if (local.y == 1 || !was_active)
{
if ((event->type & GPM_UP) != 0)
if ((local.type & GPM_UP) != 0)
return MOU_NORMAL;
/* wheel events on menubar */
if (event->buttons & GPM_B_UP)
if ((local.buttons & GPM_B_UP) != 0)
menubar_left (menubar);
else if (event->buttons & GPM_B_DOWN)
else if ((local.buttons & GPM_B_DOWN) != 0)
menubar_right (menubar);
else
{
@ -627,8 +634,8 @@ menubar_event (Gpm_Event * event, void *data)
unsigned int new_selection = 0;
while ((new_selection < len)
&& (event->x > ((Menu *) g_list_nth_data (menubar->menu,
new_selection))->start_x))
&& (local.x > ((Menu *) g_list_nth_data (menubar->menu,
new_selection))->start_x))
new_selection++;
if (new_selection != 0) /* Don't set the invalid value -1 */
@ -649,11 +656,11 @@ menubar_event (Gpm_Event * event, void *data)
return MOU_NORMAL;
}
if (!menubar->is_dropped || (event->y < 2))
if (!menubar->is_dropped || (local.y < 2))
return MOU_NORMAL;
/* middle click -- everywhere */
if (((event->buttons & GPM_B_MIDDLE) != 0) && ((event->type & GPM_DOWN) != 0))
if (((local.buttons & GPM_B_MIDDLE) != 0) && ((local.type & GPM_DOWN) != 0))
{
menubar_execute (menubar);
return MOU_NORMAL;
@ -671,18 +678,18 @@ menubar_event (Gpm_Event * event, void *data)
bottom_y = g_list_length (menu->entries) + 3;
if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y))
if ((local.x >= left_x) && (local.x <= right_x) && (local.y <= bottom_y))
{
int pos = event->y - 3;
int pos = local.y - 3;
const menu_entry_t *entry = g_list_nth_data (menu->entries, pos);
/* mouse wheel */
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
{
menubar_up (menubar);
return MOU_NORMAL;
}
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
{
menubar_down (menubar);
return MOU_NORMAL;
@ -702,10 +709,11 @@ menubar_event (Gpm_Event * event, void *data)
menubar_execute (menubar);
}
}
else
else if (((local.type & GPM_DOWN) != 0) && ((local.buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
{
/* use click not wheel to close menu */
if (((event->type & GPM_DOWN) != 0) && ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
menubar_finish (menubar);
}
return MOU_NORMAL;
}

Просмотреть файл

@ -147,22 +147,27 @@ radio_callback (Widget * w, widget_msg_t msg, int parm)
static int
radio_event (Gpm_Event * event, void *data)
{
WRadio *r = data;
Widget *w = data;
Widget *w = (Widget *) data;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
{
Dlg_head *h = r->widget.owner;
WRadio *r = (WRadio *) data;
Gpm_Event local;
r->pos = event->y - 1;
dlg_select_widget (r);
local = mouse_get_local (event, w);
r->pos = local.y - 1;
dlg_select_widget (w);
if ((event->type & GPM_UP) != 0)
{
radio_callback (w, WIDGET_KEY, ' ');
h->callback (h, w, DLG_POST_KEY, ' ', NULL);
return MOU_NORMAL;
w->owner->callback (w->owner, w, DLG_POST_KEY, ' ', NULL);
}
}
return MOU_NORMAL;
}

Просмотреть файл

@ -227,3 +227,28 @@ widget_erase (Widget * w)
}
/* --------------------------------------------------------------------------------------------- */
/* get mouse pointer location within widget */
Gpm_Event
mouse_get_local (const Gpm_Event * global, const Widget * w)
{
Gpm_Event local;
local.buttons = global->buttons;
local.x = global->x - w->x;
local.y = global->y - w->y;
local.type = global->type;
return local;
}
/* --------------------------------------------------------------------------------------------- */
gboolean
mouse_global_in_widget (const Gpm_Event * event, const Widget * w)
{
return (event->x > w->x) && (event->y > w->y) && (event->x <= w->x + w->cols)
&& (event->y <= w->y + w->lines);
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -6,7 +6,7 @@
#ifndef MC__WIDGET_INTERNAL_H
#define MC__WIDGET_INTERNAL_H
#include "lib/tty/mouse.h" /* mouse_h */
#include "lib/tty/mouse.h"
/*** typedefs(not structures) and defined constants **********************************************/
@ -124,6 +124,10 @@ void widget_set_size (Widget * widget, int y, int x, int lines, int cols);
void widget_selectcolor (struct Widget *w, gboolean focused, gboolean hotkey);
void widget_erase (Widget * w);
/* get mouse pointer location within widget */
Gpm_Event mouse_get_local (const Gpm_Event * global, const Widget * w);
gboolean mouse_global_in_widget (const Gpm_Event * event, const Widget * w);
/*** inline functions ****************************************************************************/
static inline cb_ret_t

Просмотреть файл

@ -2847,16 +2847,16 @@ dview_labels (WDiff * dview)
/* --------------------------------------------------------------------------------------------- */
static int
dview_event (Gpm_Event * event, void *x)
dview_event (Gpm_Event * event, void *data)
{
WDiff *dview = (WDiff *) x;
int result = MOU_NORMAL;
WDiff *dview = (WDiff *) data;
/* We are not interested in the release events */
if (!mouse_global_in_widget (event, data))
return MOU_UNHANDLED;
/* We are not interested in release events */
if ((event->type & (GPM_DOWN | GPM_DRAG)) == 0)
{
return result;
}
return MOU_NORMAL;
/* Wheel events */
if ((event->buttons & GPM_B_UP) != 0 && (event->type & GPM_DOWN) != 0)
@ -2872,7 +2872,7 @@ dview_event (Gpm_Event * event, void *x)
dview_update (dview);
}
return result;
return MOU_NORMAL;
}
static gboolean

Просмотреть файл

@ -118,86 +118,88 @@ static int
edit_event (Gpm_Event * event, void *data)
{
WEdit *edit = (WEdit *) data;
Widget *w = (Widget *) data;
Gpm_Event local;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
/* Unknown event type */
if (!(event->type & (GPM_DOWN | GPM_DRAG | GPM_UP)))
if ((event->type & (GPM_DOWN | GPM_DRAG | GPM_UP)) == 0)
return MOU_NORMAL;
edit_update_curs_row (edit);
edit_update_curs_col (edit);
/* Outside editor window */
if (event->y < 1 || event->x < 1
|| event->x > edit->widget.cols || event->y > edit->widget.lines)
return MOU_NORMAL;
local = mouse_get_local (event, w);
/* Double click */
if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE))
if ((local.type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE))
{
edit_mark_current_word_cmd (edit);
goto update;
}
#if 0
/* Triple click */
if ((event->type & (GPM_TRIPLE | GPM_UP)) == (GPM_UP | GPM_TRIPLE))
if ((local.type & (GPM_TRIPLE | GPM_UP)) == (GPM_UP | GPM_TRIPLE))
{
edit_mark_current_line_cmd (edit);
goto update;
}
#endif
/* Wheel events */
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
{
edit_move_up (edit, 2, 1);
goto update;
}
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
{
edit_move_down (edit, 2, 1);
goto update;
}
/* A lone up mustn't do anything */
if (edit->mark2 != -1 && event->type & (GPM_UP | GPM_DRAG))
if (edit->mark2 != -1 && (local.type & (GPM_UP | GPM_DRAG)) != 0)
return MOU_NORMAL;
if (event->type & (GPM_DOWN | GPM_UP))
if ((local.type & (GPM_DOWN | GPM_UP)) != 0)
edit_push_key_press (edit);
if (!option_cursor_beyond_eol)
edit->prev_col = event->x - edit->start_col - option_line_state_width - 1;
edit->prev_col = local.x - edit->start_col - option_line_state_width - 1;
else
{
long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
edit_eol (edit, edit->curs1));
if (event->x > line_len)
if (local.x > line_len)
{
edit->over_col = event->x - line_len - edit->start_col - option_line_state_width - 1;
edit->over_col = local.x - line_len - edit->start_col - option_line_state_width - 1;
edit->prev_col = line_len;
}
else
{
edit->over_col = 0;
edit->prev_col = event->x - option_line_state_width - edit->start_col - 1;
edit->prev_col = local.x - option_line_state_width - edit->start_col - 1;
}
}
--event->y;
if (event->y > edit->curs_row)
edit_move_down (edit, event->y - edit->curs_row, 0);
else if (event->y < edit->curs_row)
edit_move_up (edit, edit->curs_row - event->y, 0);
--local.y;
if (local.y > edit->curs_row)
edit_move_down (edit, local.y - edit->curs_row, 0);
else if (local.y < edit->curs_row)
edit_move_up (edit, edit->curs_row - local.y, 0);
else
edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1));
if (event->type & GPM_DOWN)
if ((local.type & GPM_DOWN) != 0)
{
edit_mark_cmd (edit, 1); /* reset */
edit->highlight = 0;
}
if (!(event->type & GPM_DRAG))
if ((local.type & GPM_DRAG) == 0)
edit_mark_cmd (edit, 0);
update:

Просмотреть файл

@ -321,14 +321,17 @@ info_callback (Widget * w, widget_msg_t msg, int parm)
static int
info_event (Gpm_Event * event, void *data)
{
Widget *w = &((WInfo *) data)->widget;
Widget *w = (Widget *) data;
Gpm_Event local;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
local = mouse_get_local (event, w);
/* rest of the upper frame, the menu is invisible - call menu */
if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible)
{
event->x += w->x;
if ((local.type & GPM_DOWN) != 0 && local.y == 1 && !menubar_visible)
return the_menubar->widget.mouse (event, the_menubar);
}
return MOU_NORMAL;
}

Просмотреть файл

@ -1896,7 +1896,6 @@ mini_status_format (WPanel * panel)
switch (panel->list_type)
{
case list_long:
return "full perm space nlink space owner space group space size space mtime space name";
@ -3445,18 +3444,18 @@ mouse_set_mark (WPanel * panel)
/* --------------------------------------------------------------------------------------------- */
static int
static gboolean
mark_if_marking (WPanel * panel, Gpm_Event * event)
{
if (event->buttons & GPM_B_RIGHT)
if ((event->buttons & GPM_B_RIGHT) != 0)
{
if (event->type & GPM_DOWN)
if ((event->type & GPM_DOWN) != 0)
mouse_toggle_mark (panel);
else
mouse_set_mark (panel);
return 1;
return TRUE;
}
return 0;
return FALSE;
}
/* --------------------------------------------------------------------------------------------- */
@ -3522,43 +3521,46 @@ mouse_sort_col (Gpm_Event * event, WPanel * panel)
* Mouse callback of the panel minus repainting.
* If the event is redirected to the menu, *redir is set to TRUE.
*/
static int
static inline int
do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
{
const int lines = llines (panel);
const gboolean is_active = dlg_widget_active (panel);
const gboolean mouse_down = (event->type & GPM_DOWN) != 0;
Widget *w = (Widget *) panel;
Gpm_Event local;
*redir = FALSE;
local = mouse_get_local (event, w);
/* 1st line */
if (mouse_down && event->y == 1)
if (mouse_down && local.y == 1)
{
/* "<" button */
if (event->x == 2)
if (local.x == 2)
{
directory_history_prev (panel);
return MOU_NORMAL;
}
/* "." button show/hide hidden files */
if (event->x == panel->widget.cols - 5)
if (local.x == panel->widget.cols - 5)
{
panel->widget.owner->callback (panel->widget.owner, NULL,
DLG_ACTION, CK_ShowHidden, NULL);
midnight_dlg->callback (midnight_dlg, NULL, DLG_ACTION, CK_ShowHidden, NULL);
repaint_screen ();
return MOU_NORMAL;
}
/* ">" button */
if (event->x == panel->widget.cols - 1)
if (local.x == panel->widget.cols - 1)
{
directory_history_next (panel);
return MOU_NORMAL;
}
/* "^" button */
if (event->x >= panel->widget.cols - 4 && event->x <= panel->widget.cols - 2)
if (local.x >= panel->widget.cols - 4 && local.x <= panel->widget.cols - 2)
{
directory_history_list (panel);
return MOU_NORMAL;
@ -3568,7 +3570,6 @@ do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
if (!menubar_visible)
{
*redir = TRUE;
event->x += panel->widget.x;
return the_menubar->widget.mouse (event, the_menubar);
}
@ -3577,14 +3578,14 @@ do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
}
/* sort on clicked column; don't handle wheel events */
if (mouse_down && (event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && event->y == 2)
if (mouse_down && (local.buttons & (GPM_B_UP | GPM_B_DOWN)) == 0 && local.y == 2)
{
mouse_sort_col (event, panel);
return MOU_NORMAL;
}
/* Mouse wheel events */
if (mouse_down && (event->buttons & GPM_B_UP))
if (mouse_down && (local.buttons & GPM_B_UP) != 0)
{
if (is_active)
{
@ -3596,7 +3597,7 @@ do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
return MOU_NORMAL;
}
if (mouse_down && (event->buttons & GPM_B_DOWN))
if (mouse_down && (local.buttons & GPM_B_DOWN) != 0)
{
if (is_active)
{
@ -3608,20 +3609,20 @@ do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
return MOU_NORMAL;
}
event->y -= 2;
if ((event->type & (GPM_DOWN | GPM_DRAG)))
local.y -= 2;
if ((local.type & (GPM_DOWN | GPM_DRAG)) != 0)
{
int my_index;
if (!is_active)
change_panel ();
if (panel->top_file + event->y > panel->count)
if (panel->top_file + local.y > panel->count)
my_index = panel->count - 1;
else
{
my_index = panel->top_file + event->y - 1;
if (panel->split && (event->x > ((panel->widget.cols - 2) / 2)))
my_index = panel->top_file + local.y - 1;
if (panel->split && (local.x > ((panel->widget.cols - 2) / 2)))
my_index += llines (panel);
if (my_index >= panel->count)
@ -3636,13 +3637,14 @@ do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
}
/* This one is new */
mark_if_marking (panel, event);
mark_if_marking (panel, &local);
}
else if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
else if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
{
if (event->y > 0 && event->y <= lines)
if (local.y > 0 && local.y <= lines)
do_enter (panel);
}
return MOU_NORMAL;
}
@ -3652,10 +3654,13 @@ do_panel_event (Gpm_Event * event, WPanel * panel, gboolean * redir)
static int
panel_event (Gpm_Event * event, void *data)
{
WPanel *panel = data;
WPanel *panel = (WPanel *) data;
int ret;
gboolean redir;
if (!mouse_global_in_widget (event, (Widget *) data))
return MOU_UNHANDLED;
ret = do_panel_event (event, panel, &redir);
if (!redir)
send_message ((Widget *) panel, WIDGET_DRAW, 0);

Просмотреть файл

@ -580,10 +580,10 @@ tree_move_to_bottom (WTree * tree)
}
/* --------------------------------------------------------------------------------------------- */
/** Handle mouse click */
/** Handle mouse click */
static void
tree_event (WTree * tree, int y)
tree_mouse_click (WTree * tree, int y)
{
if (tree->tree_shown[y])
{
@ -630,46 +630,49 @@ maybe_chdir (WTree * tree)
/** Mouse callback */
static int
event_callback (Gpm_Event * event, void *data)
tree_event (Gpm_Event * event, void *data)
{
WTree *tree = data;
WTree *tree = (WTree *) data;
Widget *w = (Widget *) data;
Gpm_Event local;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
local = mouse_get_local (event, w);
/* rest of the upper frame, the menu is invisible - call menu */
if (tree->is_panel && (event->type & GPM_DOWN) && event->y == 1 && !menubar_visible)
{
event->x += tree->widget.x;
if (tree->is_panel && (local.type & GPM_DOWN) != 0 && local.y == 1 && !menubar_visible)
return the_menubar->widget.mouse (event, the_menubar);
}
if (!(event->type & GPM_UP))
if ((local.type & GPM_UP) == 0)
return MOU_NORMAL;
if (tree->is_panel)
event->y--;
local.y--;
event->y--;
local.y--;
if (!tree->active)
change_panel ();
if (event->y < 0)
if (local.y < 0)
{
tree_move_backward (tree, tlines (tree) - 1);
show_tree (tree);
}
else if (event->y >= tlines (tree))
else if (local.y >= tlines (tree))
{
tree_move_forward (tree, tlines (tree) - 1);
show_tree (tree);
}
else
{
tree_event (tree, event->y);
if ((event->type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
{
tree_mouse_click (tree, local.y);
if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
tree_chdir_sel (tree);
}
}
return MOU_NORMAL;
}
@ -1265,7 +1268,7 @@ tree_new (int y, int x, int lines, int cols, gboolean is_panel)
{
WTree *tree = g_new (WTree, 1);
init_widget (&tree->widget, y, x, lines, cols, tree_callback, event_callback);
init_widget (&tree->widget, y, x, lines, cols, tree_callback, tree_event);
tree->is_panel = is_panel;
tree->selected_ptr = 0;

Просмотреть файл

@ -604,17 +604,23 @@ help_show (Dlg_head * h, const char *paint_start)
static int
help_event (Gpm_Event * event, void *vp)
{
Widget *w = vp;
Widget *w = (Widget *) vp;
GSList *current_area;
Gpm_Event local;
if (!mouse_global_in_widget (event, w))
return MOU_UNHANDLED;
if ((event->type & GPM_UP) == 0)
return 0;
return MOU_NORMAL;
local = mouse_get_local (event, w);
/* The event is relative to the dialog window, adjust it: */
event->x -= 2;
event->y -= 2;
local.x -= 2;
local.y -= 2;
if (event->buttons & GPM_B_RIGHT)
if ((local.buttons & GPM_B_RIGHT) != 0)
{
currentpoint = history[history_ptr].page;
selected_item = history[history_ptr].link;
@ -623,24 +629,26 @@ help_event (Gpm_Event * event, void *vp)
history_ptr = HISTORY_SIZE - 1;
help_callback (w->owner, NULL, DLG_DRAW, 0, NULL);
return 0;
return MOU_NORMAL;
}
/* Test whether the mouse click is inside one of the link areas */
for (current_area = link_area; current_area != NULL; current_area = g_slist_next (current_area))
{
Link_Area *la = (Link_Area *) current_area->data;
/* Test one line link area */
if (event->y == la->y1 && event->x >= la->x1 && event->y == la->y2 && event->x <= la->x2)
if (local.y == la->y1 && local.x >= la->x1 && local.y == la->y2 && local.x <= la->x2)
break;
/* Test two line link area */
if (la->y1 + 1 == la->y2)
{
/* The first line */
if (event->y == la->y1 && event->x >= la->x1)
if (local.y == la->y1 && local.x >= la->x1)
break;
/* The second line */
if (event->y == la->y2 && event->x <= la->x2)
if (local.y == la->y2 && local.x <= la->x2)
break;
}
/* Mouse will not work with link areas of more than two lines */
@ -658,11 +666,11 @@ help_event (Gpm_Event * event, void *vp)
currentpoint = help_follow_link (currentpoint, la->link_name);
selected_item = NULL;
}
else if (event->y < 0)
else if (local.y < 0)
move_backward (help_lines - 1);
else if (event->y >= help_lines)
else if (local.y >= help_lines)
move_forward (help_lines - 1);
else if (event->y < help_lines / 2)
else if (local.y < help_lines / 2)
move_backward (1);
else
move_forward (1);
@ -670,7 +678,7 @@ help_event (Gpm_Event * event, void *vp)
/* Show the new node */
help_callback (w->owner, NULL, DLG_DRAW, 0, NULL);
return 0;
return MOU_NORMAL;
}
/* --------------------------------------------------------------------------------------------- */

Просмотреть файл

@ -88,40 +88,44 @@ char *mcview_show_eof = NULL;
/* --------------------------------------------------------------------------------------------- */
/** Both views */
static int
mcview_event (mcview_t * view, Gpm_Event * event, int *result)
static gboolean
do_mcview_event (mcview_t * view, Gpm_Event * event, int *result)
{
screen_dimen y, x;
Gpm_Event local;
*result = MOU_NORMAL;
local = mouse_get_local (event, (Widget *) view);
/* rest of the upper frame, the menu is invisible - call menu */
if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) && event->y == 1 && !menubar_visible)
if (mcview_is_in_panel (view) && (local.type & GPM_DOWN) != 0 && local.y == 1
&& !menubar_visible)
{
event->x += view->widget.x;
*result = the_menubar->widget.mouse (event, the_menubar);
return 0; /* don't draw viewer over menu */
return FALSE; /* don't draw viewer over menu */
}
/* We are not interested in the release events */
if (!(event->type & (GPM_DOWN | GPM_DRAG)))
return 0;
if ((local.type & (GPM_DOWN | GPM_DRAG)) == 0)
return FALSE;
/* Wheel events */
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
{
mcview_move_up (view, 2);
return 1;
*result = MOU_NORMAL;
return TRUE;
}
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
{
mcview_move_down (view, 2);
return 1;
*result = MOU_NORMAL;
return TRUE;
}
x = event->x;
y = event->y;
x = local.x;
y = local.y;
/* Scrolling left and right */
if (!view->text_wrap_mode)
@ -164,28 +168,30 @@ mcview_event (mcview_t * view, Gpm_Event * event, int *result)
goto processed;
}
return 0;
return FALSE;
processed:
*result = MOU_REPEAT;
return 1;
return TRUE;
}
/* --------------------------------------------------------------------------------------------- */
/** Real view only */
/** Real view only */
static int
mcview_real_event (Gpm_Event * event, void *x)
mcview_event (Gpm_Event * event, void *data)
{
mcview_t *view = (mcview_t *) x;
mcview_t *view = (mcview_t *) data;
int result;
if (mcview_event (view, event, &result))
if (!mouse_global_in_widget (event, (Widget *) data))
return MOU_UNHANDLED;
if (do_mcview_event (view, event, &result))
mcview_update (view);
return result;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
@ -195,7 +201,7 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel)
{
mcview_t *view = g_new0 (mcview_t, 1);
init_widget (&view->widget, y, x, lines, cols, mcview_callback, mcview_real_event);
init_widget (&view->widget, y, x, lines, cols, mcview_callback, mcview_event);
view->hex_mode = FALSE;
view->hexedit_mode = FALSE;