Initial mouse support added.
authorMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Sat, 16 Jan 2010 21:33:23 +0000 (21:33 +0000)
committerMarijn van Vliet <marijn.vanvliet@med.kuleuven.be>
Sat, 16 Jan 2010 21:33:23 +0000 (21:33 +0000)
Todo is to calculate the mouse coordinates in the right metric. See also ticket 40

git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@212 ddfedd41-794f-dd11-ae45-00112f111e67

libchimara/gestalt.c
libchimara/mouse.c
libchimara/mouse.h [new file with mode: 0644]
libchimara/window.c
libchimara/window.h
tests/styletest.c

index 2316dca52cc9992e6abe2d498ff2b7ff1342e944..f7ac63a8a5cc5a84324086c57f3d12e3a423e454 100644 (file)
@@ -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:
index cead7ab53dbcb71632a5173b164cccd06994244b..f6c23b229e3b595114e26fa3b21c9991c1f46c06 100644 (file)
@@ -1,11 +1,34 @@
-#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;
 }
diff --git a/libchimara/mouse.h b/libchimara/mouse.h
new file mode 100644 (file)
index 0000000..0cf60a3
--- /dev/null
@@ -0,0 +1,13 @@
+#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
index 72643c354cc6c54714f2acdbe1ac630d0cddfb52..ecc8e96a253e3a9561249784b60dbbf0615052d2 100644 (file)
@@ -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) */
index 36bf257e390e46d2e792f5ec94c06fbad253f00b..1d183a34357983881f00bb8fbbf4b79a5811f1a8 100644 (file)
@@ -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 */
index 33d7ce440f918e0e4632a888fbf994c154654273..8165e448383f3b4fe4a139b14d4aa7828d6d51c9 100644 (file)
@@ -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");
 }