From: rodin Date: Sat, 16 Jan 2010 21:33:23 +0000 (+0000) Subject: Initial mouse support added. X-Git-Tag: v0.9~253 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=632ef9d57c270608e01b1afdba772da0da7993ca;p=projects%2Fchimara%2Fchimara.git Initial mouse support added. Todo is to calculate the mouse coordinates in the right metric. See also ticket 40 --- diff --git a/libchimara/gestalt.c b/libchimara/gestalt.c index 2316dca..f7ac63a 100644 --- a/libchimara/gestalt.c +++ b/libchimara/gestalt.c @@ -108,9 +108,9 @@ glk_gestalt_ext(glui32 sel, glui32 val, glui32 *arr, glui32 arrlen) case gestalt_Hyperlinks: return 1; - /* Hyperlinks supported on textbuffers only at the moment */ + /* Hyperlinks supported on textbuffers and textgrids */ case gestalt_HyperlinkInput: - return val == wintype_TextBuffer; + return val == wintype_TextBuffer || val == wintype_TextGrid; /* Unsupported capabilities */ case gestalt_MouseInput: diff --git a/libchimara/mouse.c b/libchimara/mouse.c index cead7ab..f6c23b2 100644 --- a/libchimara/mouse.c +++ b/libchimara/mouse.c @@ -1,11 +1,34 @@ -#include +#include "mouse.h" +#include "magic.h" void glk_request_mouse_event(winid_t win) { + VALID_WINDOW(win, return); + g_return_if_fail(win != NULL); + g_return_if_fail(win->type == wintype_TextBuffer || win->type == wintype_TextGrid); + + g_signal_handler_unblock(win->widget, win->button_press_event_handler); } void glk_cancel_mouse_event(winid_t win) { + VALID_WINDOW(win, return); + g_return_if_fail(win != NULL); + g_return_if_fail(win->type == wintype_TextBuffer || win->type == wintype_TextGrid); + + g_signal_handler_block(win->widget, win->button_press_event_handler); +} + +gboolean +on_window_button_press(GtkWidget *widget, GdkEventButton *event, winid_t win) +{ + ChimaraGlk *glk = CHIMARA_GLK(gtk_widget_get_ancestor(win->widget, CHIMARA_TYPE_GLK)); + g_assert(glk); + + /* TODO: calculate coordinates in proper metric */ + event_throw(glk, evtype_MouseInput, win, event->x, event->y); + + return TRUE; } diff --git a/libchimara/mouse.h b/libchimara/mouse.h new file mode 100644 index 0000000..0cf60a3 --- /dev/null +++ b/libchimara/mouse.h @@ -0,0 +1,13 @@ +#ifndef MOUSE_H +#define MOUSE_H + +#include +#include + +#include "glk.h" +#include "window.h" +#include "event.h" + +G_GNUC_INTERNAL gboolean on_window_button_press(GtkWidget *widget, GdkEventButton *event, winid_t win); + +#endif diff --git a/libchimara/window.c b/libchimara/window.c index 72643c3..ecc8e96 100644 --- a/libchimara/window.c +++ b/libchimara/window.c @@ -503,6 +503,8 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, g_signal_handler_block(textview, win->line_input_keypress_handler); win->shutdown_keypress_handler = g_signal_connect(textview, "key-press-event", G_CALLBACK(on_shutdown_key_press_event), win); g_signal_handler_block(textview, win->shutdown_keypress_handler); + win->button_press_event_handler = g_signal_connect( textview, "button-press-event", G_CALLBACK(on_window_button_press), win ); + g_signal_handler_block(textview, win->button_press_event_handler); } break; @@ -545,6 +547,8 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, g_signal_handler_block(textview, win->shutdown_keypress_handler); win->insert_text_handler = g_signal_connect_after( textbuffer, "insert-text", G_CALLBACK(after_window_insert_text), win ); g_signal_handler_block(textbuffer, win->insert_text_handler); + win->button_press_event_handler = g_signal_connect( textview, "button-press-event", G_CALLBACK(on_window_button_press), win ); + g_signal_handler_block(textview, win->button_press_event_handler); /* Create an editable tag to indicate uneditable parts of the window (for line input) */ diff --git a/libchimara/window.h b/libchimara/window.h index 36bf257..1d183a3 100644 --- a/libchimara/window.h +++ b/libchimara/window.h @@ -9,6 +9,7 @@ #include "input.h" #include "style.h" #include "hyperlink.h" +#include "mouse.h" enum InputRequestType @@ -73,6 +74,7 @@ struct glk_window_struct gulong insert_text_handler; gulong tag_event_handler; gulong shutdown_keypress_handler; + gulong button_press_event_handler; /* Window buffer */ GString *buffer; /* Hyperlinks */ diff --git a/tests/styletest.c b/tests/styletest.c index 33d7ce4..8165e44 100644 --- a/tests/styletest.c +++ b/tests/styletest.c @@ -7,12 +7,14 @@ void print_help(); void do_style_test(); void do_link_test(); +void do_mouse_test(); winid_t mainwin; winid_t statuswin; void glk_main(void) { + char stringbuffer[128]; event_t ev; mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); if(!mainwin) @@ -42,6 +44,9 @@ void glk_main(void) else if( !strncmp(buffer, "link", 4) ) { do_link_test(); } + else if( !strncmp(buffer, "mouse", 4) ) { + do_mouse_test(); + } else { glk_put_string("Huh?\n"); } @@ -50,15 +55,15 @@ void glk_main(void) else if(ev.type == evtype_Hyperlink) { glk_cancel_line_event(mainwin, NULL); - if(ev.val1 == 1) - glk_put_string("Link 1 was clicked\n"); - if(ev.val1 == 2) - glk_put_string("Link 2 was clicked\n"); - if(ev.val1 == 3) - glk_put_string("Link 3 was clicked\n"); - if(ev.val1 == 4) - glk_put_string("Link 4 was clicked\n"); - + snprintf(stringbuffer, 128, "Link %d was clicked\n", ev.val1); + glk_put_string(stringbuffer); + glk_request_line_event(mainwin, buffer, 255, 0); + } + else if(ev.type == evtype_MouseInput) + { + glk_cancel_line_event(mainwin, NULL); + snprintf(stringbuffer, 128, "Mouse click: x=%d, y=%d\n", ev.val1, ev.val2); + glk_put_string(stringbuffer); glk_request_line_event(mainwin, buffer, 255, 0); } } @@ -130,7 +135,13 @@ do_link_test() { glk_set_window(mainwin); } +void +do_mouse_test() { + glk_request_mouse_event(mainwin); + glk_request_mouse_event(statuswin); +} + void print_help() { - glk_put_string("The following commands are supported:\n - help (this help text)\n - style (perform style test)\n - link (perform hyperlink test)\n - quit (quit the program)\n"); + glk_put_string("The following commands are supported:\n - help (this help text)\n - style (perform style test)\n - link (perform hyperlink test)\n - mouse (perform mouse test)\n - quit (quit the program)\n"); }