From: Philip Chimento Date: Wed, 16 Feb 2011 23:55:01 +0000 (+0100) Subject: Proper state of new hyperlinks' event handlers X-Git-Tag: v0.9~138 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=9cf2c15bb9775ea5c540bc4128f1b79881da3cd7;p=projects%2Fchimara%2Fchimara.git Proper state of new hyperlinks' event handlers Fixes #17. New hyperlinks' event handler callbacks were blocked by default at creation, but they should be unblocked if there is currently a hyperlink event request pending in the window. --- diff --git a/libchimara/hyperlink.c b/libchimara/hyperlink.c index aa9f426..1f40bc3 100644 --- a/libchimara/hyperlink.c +++ b/libchimara/hyperlink.c @@ -1,3 +1,5 @@ +#include +#include #include "hyperlink.h" #include "chimara-glk-private.h" #include "magic.h" @@ -75,7 +77,8 @@ glk_set_hyperlink_stream(strid_t str, glui32 linkval) new_hyperlink->value = linkval; new_hyperlink->tag = gtk_text_tag_new(NULL); new_hyperlink->event_handler = g_signal_connect( new_hyperlink->tag, "event", G_CALLBACK(on_hyperlink_clicked), new_hyperlink ); - g_signal_handler_block(new_hyperlink->tag, new_hyperlink->event_handler); + if(!str->window->hyperlink_event_requested) + g_signal_handler_block(new_hyperlink->tag, new_hyperlink->event_handler); new_hyperlink->window = str->window; /* Add the new tag to the tag table of the textbuffer */ @@ -137,6 +140,12 @@ glk_request_hyperlink_event(winid_t win) g_return_if_fail(win != NULL); g_return_if_fail(win->type == wintype_TextBuffer || win->type == wintype_TextGrid); + if(win->hyperlink_event_requested) { + WARNING(_("Tried to request a hyperlink event on a window that already had a hyperlink request")); + return; + } + + win->hyperlink_event_requested = TRUE; g_hash_table_foreach(win->hyperlinks, hyperlink_unblock_event_handler, NULL); } @@ -155,6 +164,12 @@ glk_cancel_hyperlink_event(winid_t win) g_return_if_fail(win != NULL); g_return_if_fail(win->type == wintype_TextBuffer || win->type == wintype_TextGrid); + if(!win->hyperlink_event_requested) { + WARNING(_("Tried to cancel a nonexistent hyperlink request")); + return; + } + + win->hyperlink_event_requested = FALSE; g_hash_table_foreach(win->hyperlinks, hyperlink_block_event_handler, NULL); } @@ -165,6 +180,8 @@ on_hyperlink_clicked(GtkTextTag *tag, GObject *object, GdkEvent *event, GtkTextI g_assert(glk); if(event->type == GDK_BUTTON_PRESS) { + link->window->hyperlink_event_requested = FALSE; + g_hash_table_foreach(link->window->hyperlinks, hyperlink_block_event_handler, NULL); event_throw(glk, evtype_Hyperlink, link->window, link->value, 0); } diff --git a/libchimara/window.h b/libchimara/window.h index 2945511..1fecb5e 100644 --- a/libchimara/window.h +++ b/libchimara/window.h @@ -87,6 +87,7 @@ struct glk_window_struct /* Hyperlinks */ GHashTable *hyperlinks; struct hyperlink *current_hyperlink; + gboolean hyperlink_event_requested; /* Graphics */ glui32 background_color; /* Pager (textbuffer only) */