Implemented output buffering.
[rodin/chimara.git] / libchimara / hyperlink.c
1 #include "hyperlink.h"
2 #include "chimara-glk-private.h"
3
4 extern GPrivate *glk_data_key;
5
6 /**
7  * glk_set_hyperlink:
8  * @linkval: Set to nonzero to initiate hyperlink mode. Set to zero to disengage.
9  *
10  * Use this function to create hyperlinks in a textbuffer. It sets the current stream
11  * to hyperlink mode, after which text will become a hyperlink until hyperlink mode
12  * is turned off. If the current stream does not write to a textbuffer window, this function
13  * does nothing.
14  *
15  * You can request hyperlink events with glk_request_hyperlink_event() to react
16  * to clicks on the link.
17  */
18 void 
19 glk_set_hyperlink(glui32 linkval)
20 {
21         ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key);
22         g_return_if_fail(glk_data->current_stream != NULL);
23         glk_set_hyperlink_stream(glk_data->current_stream, linkval);
24 }
25
26 /**
27  * glk_set_hyperlink:
28  * @str: The stream to set the hyperlink mode on.
29  * @linkval: Set to nonzero to initiate hyperlink mode. Set to zero to disengage.
30  *
31  * Use this function to create hyperlinks in a textbuffer. It sets a stream to a textbuffer
32  * window to hyperlink mode, after which text will become a hyperlink until hyperlink mode
33  * is turned off. Calling this function on a stream that does not write to a textbuffer does
34  * nothing.
35  *
36  * You can request hyperlink events with glk_request_hyperlink_event() to react
37  * to clicks on the link.
38  */
39 void 
40 glk_set_hyperlink_stream(strid_t str, glui32 linkval)
41 {
42         g_return_if_fail(str != NULL);
43         g_return_if_fail(str->window != NULL);
44         g_return_if_fail(str->window->type == wintype_TextBuffer);
45
46         str->hyperlink_mode = (linkval != 0);
47 }
48
49 void 
50 glk_request_hyperlink_event(winid_t win)
51 {
52         VALID_WINDOW(win, return);
53         g_return_if_fail(win != NULL);
54         g_return_if_fail(win->mouse_click_handler != 0);
55         g_return_if_fail(win->type != wintype_TextBuffer || win->type != wintype_TextGrid);
56
57         g_signal_handler_unblock( G_OBJECT(win->widget), win->mouse_click_handler );
58 }
59
60 void 
61 glk_cancel_hyperlink_event(winid_t win)
62 {
63         VALID_WINDOW(win, return);
64         g_return_if_fail(win != NULL);
65         g_return_if_fail(win->mouse_click_handler != 0);
66         g_return_if_fail(win->type != wintype_TextBuffer || win->type != wintype_TextGrid);
67         
68         g_signal_handler_block( G_OBJECT(win->widget), win->mouse_click_handler );
69 }
70
71 /* Internal function: General callback for signal button-release-event on a
72  * text buffer or text grid window.  Used for detecting clicks on hyperlinks.
73  * Blocked when not in use.
74  */
75 gboolean
76 on_window_button_release_event(GtkWidget *widget, GdkEventButton *event, winid_t win)
77 {
78         printf("Click on (%f,%f)\n", event->x, event->y);
79         return TRUE;
80 }