Ticket #3571: high-level mouse API.
[midnight-commander.git] / lib / widget / mouse.h
blob63fcf75a6d797bd51ffcd2c17ce4b46feaeec020
1 /** \file mouse.h
2 * \brief Header: Hight-level mouse API.
4 * This is a thin layer over the low-level mouse protocol in lib/tty/mouse.h.
5 * The latter is oblivious to the regions on the screen and is therefore a
6 * bit hard to use in widgets. This layer translates the low level Gpm_Event
7 * into something that's easy to work with in widgets.
8 */
10 #ifndef MC__WIDGET_MOUSE_H
11 #define MC__WIDGET_MOUSE_H
13 /*** enums ***************************************************************************************/
15 /* Mouse messages */
16 typedef enum
19 * Notes:
20 * (1) "anywhere" means "inside or outside the widget".
21 * (2) the mouse wheel is not considered "mouse button".
23 MSG_MOUSE_NONE = 0,
24 MSG_MOUSE_DOWN = 1, /* When mouse button is pressed down inside the widget. */
25 MSG_MOUSE_UP, /* When mouse button, previously pressed inside the widget, is released anywhere. */
26 MSG_MOUSE_CLICK, /* When mouse button, previously pressed inside the widget, is released inside the widget. */
27 MSG_MOUSE_DRAG, /* When a drag, initiated by button press inside the widget, occurs anywhere. */
28 MSG_MOUSE_MOVE, /* (Not currently implemented in MC.) */
29 MSG_MOUSE_SCROLL_UP, /* When mouse wheel is rotated away from the user. */
30 MSG_MOUSE_SCROLL_DOWN /* When mouse wheel is rotated towards the user. */
31 } mouse_msg_t;
33 /*** structures declarations (and typedefs of structures)*****************************************/
35 /* Mouse event structure. */
36 typedef struct
38 mouse_msg_t msg;
40 int x, y; /* Local to the widget. */
41 int buttons; /* Bitwise-or of: GPM_B_LEFT, GPM_B_MIDDLE, GPM_B_RIGHT */
42 int count; /* One of: GPM_SINGLE, GPM_DOUBLE, GPM_TRIPLE */
44 /* A mechanism for the callback to report back: */
45 struct
47 gboolean abort;
48 gboolean repeat;
49 } result;
50 } mouse_event_t;
52 /*** typedefs(not structures) and defined constants **********************************************/
54 /* A callback to respond to mouse events.
55 * Note: We embed "easy" in it to distinguish it from the old-style callbacks we still use. */
56 typedef void (*easy_mouse_callback) (Widget * w, mouse_msg_t msg, mouse_event_t * event);
58 /*** global variables defined in .c file *********************************************************/
60 /*** declarations of public functions ************************************************************/
62 /* Installs an easy callback on a widget. */
63 void set_easy_mouse_callback (Widget * w, easy_mouse_callback cb);
65 /*** inline functions ****************************************************************************/
67 #endif /* MC__WIDGET_MOUSE_H */