Todo is to calculate the mouse coordinates in the right metric. See also ticket 40
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:
-#include <libchimara/glk.h>
+#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;
}
--- /dev/null
+#ifndef MOUSE_H
+#define MOUSE_H
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#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
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;
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) */
#include "input.h"
#include "style.h"
#include "hyperlink.h"
+#include "mouse.h"
enum InputRequestType
gulong insert_text_handler;
gulong tag_event_handler;
gulong shutdown_keypress_handler;
+ gulong button_press_event_handler;
/* Window buffer */
GString *buffer;
/* Hyperlinks */
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)
else if( !strncmp(buffer, "link", 4) ) {
do_link_test();
}
+ else if( !strncmp(buffer, "mouse", 4) ) {
+ do_mouse_test();
+ }
else {
glk_put_string("Huh?\n");
}
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);
}
}
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");
}