git: Line endings of README.txt
[projects/chimara/chimara.git] / libchimara / mouse.c
1 #include "mouse.h"
2 #include "magic.h"
3
4 /**
5  * glk_request_mouse_event:
6  * @win: Window on which to request a mouse input event.
7  *
8  * Requests mouse input on the window @win.
9  */
10 void
11 glk_request_mouse_event(winid_t win)
12 {
13         VALID_WINDOW(win, return);
14         g_return_if_fail(win != NULL);
15         g_return_if_fail(win->type == wintype_TextGrid || win->type == wintype_Graphics);
16
17         g_signal_handler_unblock(win->widget, win->button_press_event_handler);
18 }
19
20 /**
21  * glk_cancel_mouse_event:
22  * @win: Window with a mouse input event pending.
23  *
24  * Cancels the pending mouse input request on @win.
25  */
26 void 
27 glk_cancel_mouse_event(winid_t win)
28 {
29         VALID_WINDOW(win, return);
30         g_return_if_fail(win != NULL);
31         g_return_if_fail(win->type == wintype_TextGrid || win->type == wintype_Graphics);
32
33         g_signal_handler_block(win->widget, win->button_press_event_handler);
34 }
35
36 gboolean
37 on_window_button_press(GtkWidget *widget, GdkEventButton *event, winid_t win)
38 {
39         ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK));
40         g_assert(glk);
41
42         switch(win->type)
43         {
44                 case wintype_TextGrid:
45                         event_throw(glk, evtype_MouseInput, win, event->x/win->unit_width, event->y/win->unit_height);
46                         break;
47                 case wintype_Graphics:
48                         event_throw(glk, evtype_MouseInput, win, event->x, event->y);
49                         break;
50                 default:
51             ILLEGAL_PARAM("Unknown window type: %u", win->type);
52         }
53
54         g_signal_handler_block(win->widget, win->button_press_event_handler);
55
56         return TRUE;
57 }