123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #include <config.h>
- #include "lib/global.h"
- #include "lib/widget.h"
- #include "lib/widget/mouse.h"
- static void
- init_mouse_event (mouse_event_t * event, mouse_msg_t msg, const Gpm_Event * global_gpm,
- const Widget * w)
- {
- event->msg = msg;
- event->x = global_gpm->x - w->x - 1;
- event->y = global_gpm->y - w->y - 1;
- event->count = global_gpm->type & (GPM_SINGLE | GPM_DOUBLE | GPM_TRIPLE);
- event->buttons = global_gpm->buttons;
- event->result.abort = FALSE;
- event->result.repeat = FALSE;
- }
- mouse_event_t
- mouse_translate_event (Widget * w, Gpm_Event * event, gboolean * click)
- {
- gboolean in_widget;
- mouse_msg_t msg = MSG_MOUSE_NONE;
- mouse_event_t local;
-
- in_widget = w->mouse.forced_capture || mouse_global_in_widget (event, w);
- *click = FALSE;
- if ((event->type & GPM_DOWN) != 0)
- {
- if (in_widget)
- {
- if ((event->buttons & GPM_B_UP) != 0)
- msg = MSG_MOUSE_SCROLL_UP;
- else if ((event->buttons & GPM_B_DOWN) != 0)
- msg = MSG_MOUSE_SCROLL_DOWN;
- else
- {
-
- w->mouse.capture = TRUE;
- msg = MSG_MOUSE_DOWN;
- w->mouse.last_buttons_down = event->buttons;
- }
- }
- }
- else if ((event->type & GPM_UP) != 0)
- {
-
- if (w->mouse.capture)
- {
- w->mouse.capture = FALSE;
- msg = MSG_MOUSE_UP;
- if (in_widget)
- *click = !w->mouse.was_drag;
-
- if (event->buttons == 0)
- event->buttons = w->mouse.last_buttons_down;
- }
- }
- else if ((event->type & GPM_DRAG) != 0)
- {
- if (w->mouse.capture)
- msg = MSG_MOUSE_DRAG;
- }
- else if ((event->type & GPM_MOVE) != 0)
- {
- if (in_widget)
- msg = MSG_MOUSE_MOVE;
- }
- if (msg != MSG_MOUSE_NONE)
-
- w->mouse.was_drag = ((event->type & GPM_DRAG) != 0);
- init_mouse_event (&local, msg, event, w);
- return local;
- }
- int
- mouse_process_event (Widget * w, mouse_event_t * event, gboolean click)
- {
- int ret = MOU_UNHANDLED;
- if (event->msg != MSG_MOUSE_NONE)
- {
- w->mouse_callback (w, event->msg, event);
- if (click)
- w->mouse_callback (w, MSG_MOUSE_CLICK, event);
- if (!event->result.abort)
- ret = event->result.repeat ? MOU_REPEAT : MOU_NORMAL;
- }
- return ret;
- }
|