summaryrefslogtreecommitdiffstats
path: root/lib/widget/mouse.h
blob: 44e7b238b4805f030d84ac94cac55b3f3d472a0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/** \file mouse.h
 *  \brief Header: Hight-level mouse API.
 *
 * This is a thin layer over the low-level mouse protocol in lib/tty/mouse.h.
 * The latter is oblivious to the regions on the screen and is therefore a
 * bit hard to use in widgets. This layer translates the low level Gpm_Event
 * into something that's easy to work with in widgets.
 */

#ifndef MC__WIDGET_MOUSE_H
#define MC__WIDGET_MOUSE_H

#include "lib/tty/mouse.h"      /* Gpm_Event */

/*** enums ***************************************************************************************/

/* Mouse messages */
typedef enum
{
    /*
     * Notes:
     * (1) "anywhere" means "inside or outside the widget".
     * (2) the mouse wheel is not considered "mouse button".
     */
    MSG_MOUSE_NONE = 0,
    MSG_MOUSE_DOWN = 1,         /* When mouse button is pressed down inside the widget. */
    MSG_MOUSE_UP,               /* When mouse button, previously pressed inside the widget, is released anywhere. */
    MSG_MOUSE_CLICK,            /* When mouse button, previously pressed inside the widget, is released inside the widget. */
    MSG_MOUSE_DRAG,             /* When a drag, initiated by button press inside the widget, occurs anywhere. */
    MSG_MOUSE_MOVE,             /* (Not currently implemented in MC.) */
    MSG_MOUSE_SCROLL_UP,        /* When mouse wheel is rotated away from the user. */
    MSG_MOUSE_SCROLL_DOWN       /* When mouse wheel is rotated towards the user. */
} mouse_msg_t;

/*** structures declarations (and typedefs of structures)*****************************************/

/* Mouse event structure. */
typedef struct
{
    mouse_msg_t msg;

    int x, y;                   /* Local to the widget. */
    int buttons;                /* Bitwise-or of: GPM_B_LEFT, GPM_B_MIDDLE, GPM_B_RIGHT */
    int count;                  /* One of: GPM_SINGLE, GPM_DOUBLE, GPM_TRIPLE */

    /* A mechanism for the callback to report back: */
    struct
    {
        gboolean abort;
        gboolean repeat;
    } result;
} mouse_event_t;

/*** typedefs(not structures) and defined constants **********************************************/

/*** global variables defined in .c file *********************************************************/

/*** declarations of public functions ************************************************************/

/* Translate GPM event to high-level event and process it */
int mouse_handle_event (Widget * w, Gpm_Event * event);

/*** inline functions ****************************************************************************/

#endif /* MC__WIDGET_MOUSE_H */