summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-01-28 06:20:30 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-01-28 06:20:30 +0000
commit40aa02249b9f527994e8d7f624bca28ef3aad93b (patch)
tree467fe72a1cd8673e6d2e075a22dac9dc627018df /gtk
parent017a5e3d5be6869abe485ea0c631160d1fa999b9 (diff)
downloadgtk+-40aa02249b9f527994e8d7f624bca28ef3aad93b.tar.gz
Allow to set a global hook function thats called whenever a link button is
2006-01-28 Matthias Clasen <mclasen@redhat.com> * gtk/gtk.symbols: * gtk/gtklinkbutton.h: * gtk/gtklinkbutton.c: Allow to set a global hook function thats called whenever a link button is clicked.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtk.symbols1
-rw-r--r--gtk/gtklinkbutton.c40
-rw-r--r--gtk/gtklinkbutton.h8
3 files changed, 49 insertions, 0 deletions
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 987dfab75d..764c76c57e 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2001,6 +2001,7 @@ gtk_link_button_new
gtk_link_button_new_with_label
gtk_link_button_get_uri
gtk_link_button_set_uri
+gtk_link_button_set_uri_hook
#endif
#endif
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 8bae769dc1..c0e2ea038c 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -102,6 +102,10 @@ static const GtkTargetEntry link_drop_types[] = {
static GdkColor default_link_color = { 0, 0, 0, 0xeeee };
static GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
+static GtkLinkButtonUriFunc uri_func = NULL;
+static gpointer uri_func_data = NULL;
+static GDestroyNotify uri_func_destroy = NULL;
+
G_DEFINE_TYPE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON);
static void
@@ -436,6 +440,9 @@ gtk_link_button_clicked (GtkButton *button)
{
GtkLinkButton *link_button = GTK_LINK_BUTTON (button);
+ if (uri_func)
+ (* uri_func) (button, link_button->priv->uri, uri_func_data);
+
link_button->priv->visited = TRUE;
set_link_color (link_button);
@@ -615,5 +622,38 @@ gtk_link_button_get_uri (GtkLinkButton *link_button)
return link_button->priv->uri;
}
+/**
+ * gtk_link_button_set_uri_hook:
+ * @func: a function called each time a #GtkLinkButton is clicked, or %NULL
+ * @data: user data to be passed to @func, or %NULL
+ * @destroy: a #GDestroyNotify that gets called when @data is no longer needed, or %NULL
+ *
+ * Sets @func as the function that should be invoked every time a user clicks
+ * a #GtkLinkButton. This function is called before every callback registered
+ * for the "clicked" signal.
+ *
+ * Return value: the previously set hook function.
+ *
+ * Since: 2.10
+ */
+GtkLinkButtonUriFunc
+gtk_link_button_set_uri_hook (GtkLinkButtonUriFunc func,
+ gpointer data,
+ GDestroyNotify destroy)
+{
+ GtkLinkButtonUriFunc old_uri_func;
+
+ if (uri_func_destroy)
+ (* uri_func_destroy) (uri_func_data);
+
+ old_uri_func = uri_func;
+
+ uri_func = func;
+ uri_func_data = data;
+ uri_func_destroy = destroy;
+
+ return old_uri_func;
+}
+
#define __GTK_LINK_BUTTON_C__
#include "gtkaliasdef.c"
diff --git a/gtk/gtklinkbutton.h b/gtk/gtklinkbutton.h
index 25affc7e71..92b48512e0 100644
--- a/gtk/gtklinkbutton.h
+++ b/gtk/gtklinkbutton.h
@@ -41,6 +41,10 @@ typedef struct _GtkLinkButton GtkLinkButton;
typedef struct _GtkLinkButtonClass GtkLinkButtonClass;
typedef struct _GtkLinkButtonPrivate GtkLinkButtonPrivate;
+typedef void (*GtkLinkButtonUriFunc) (GtkLinkButton *button,
+ const gchar *link,
+ gpointer user_data);
+
struct _GtkLinkButton
{
GtkButton parent_instance;
@@ -68,6 +72,10 @@ G_CONST_RETURN gchar *gtk_link_button_get_uri (GtkLinkButton *link_but
void gtk_link_button_set_uri (GtkLinkButton *link_button,
const gchar *uri);
+GtkLinkButtonUriFunc gtk_link_button_set_uri_hook (GtkLinkButtonUriFunc func,
+ gpointer data,
+ GDestroyNotify destroy);
+
G_END_DECLS
#endif /* __GTK_LINK_BUTTON_H__ */