summaryrefslogtreecommitdiff
path: root/gtk/gtklinkbutton.c
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2013-10-08 12:50:08 +0200
committerBenjamin Otte <otte@redhat.com>2013-11-04 16:36:11 +0100
commit2ba33adf96d33f4b4efa127749d824b5beb0ff74 (patch)
tree175189d75e009cd74f315bc15b455853d6b53e0a /gtk/gtklinkbutton.c
parent5201c876d54d523a2bc2861a0f2661d77a0a8e35 (diff)
downloadgtk+-2ba33adf96d33f4b4efa127749d824b5beb0ff74.tar.gz
GtkLinkButton: Use :link and :visited for the label's color
https://bugzilla.gnome.org/show_bug.cgi?id=709629
Diffstat (limited to 'gtk/gtklinkbutton.c')
-rw-r--r--gtk/gtklinkbutton.c71
1 files changed, 14 insertions, 57 deletions
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 9260b79268..4abcb255ab 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -103,7 +103,6 @@ static gboolean gtk_link_button_button_press (GtkWidget *widget,
GdkEventButton *event);
static void gtk_link_button_clicked (GtkButton *button);
static gboolean gtk_link_button_popup_menu (GtkWidget *widget);
-static void gtk_link_button_style_updated (GtkWidget *widget);
static void gtk_link_button_unrealize (GtkWidget *widget);
static gboolean gtk_link_button_enter_cb (GtkWidget *widget,
GdkEventCrossing *event,
@@ -130,9 +129,6 @@ static const GtkTargetEntry link_drop_types[] = {
{ "_NETSCAPE_URL", 0, 0 }
};
-static const GdkColor default_link_color = { 0, 0, 0, 0xeeee };
-static const GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
-
static guint link_signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE_WITH_PRIVATE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON)
@@ -151,7 +147,6 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
widget_class->button_press_event = gtk_link_button_button_press;
widget_class->popup_menu = gtk_link_button_popup_menu;
- widget_class->style_updated = gtk_link_button_style_updated;
widget_class->unrealize = gtk_link_button_unrealize;
container_class->add = gtk_link_button_add;
@@ -222,7 +217,8 @@ gtk_link_button_init (GtkLinkButton *link_button)
link_button->priv = gtk_link_button_get_instance_private (link_button);
gtk_button_set_relief (GTK_BUTTON (link_button), GTK_RELIEF_NONE);
-
+ gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
+
g_signal_connect (link_button, "enter-notify-event",
G_CALLBACK (gtk_link_button_enter_cb), NULL);
g_signal_connect (link_button, "leave-notify-event",
@@ -233,7 +229,7 @@ gtk_link_button_init (GtkLinkButton *link_button)
g_object_set (link_button, "has-tooltip", TRUE, NULL);
g_signal_connect (link_button, "query-tooltip",
G_CALLBACK (gtk_link_button_query_tooltip_cb), NULL);
-
+
/* enable drag source */
gtk_drag_source_set (GTK_WIDGET (link_button),
GDK_BUTTON1_MASK,
@@ -296,46 +292,6 @@ gtk_link_button_set_property (GObject *object,
}
static void
-set_link_color (GtkLinkButton *link_button)
-{
- GdkColor *link_color = NULL;
- GtkWidget *label;
- GdkRGBA rgba;
-
- label = gtk_bin_get_child (GTK_BIN (link_button));
- if (!GTK_IS_LABEL (label))
- return;
-
- if (link_button->priv->visited)
- {
- gtk_widget_style_get (GTK_WIDGET (link_button),
- "visited-link-color", &link_color, NULL);
- if (!link_color)
- link_color = (GdkColor *) &default_visited_link_color;
- }
- else
- {
- gtk_widget_style_get (GTK_WIDGET (link_button),
- "link-color", &link_color, NULL);
- if (!link_color)
- link_color = (GdkColor *) &default_link_color;
- }
-
- rgba.red = link_color->red / 65535.;
- rgba.green = link_color->green / 65535.;
- rgba.blue = link_color->blue / 65535.;
- rgba.alpha = 1;
- gtk_widget_override_color (label, GTK_STATE_FLAG_NORMAL, &rgba);
- gtk_widget_override_color (label, GTK_STATE_FLAG_ACTIVE, &rgba);
- gtk_widget_override_color (label, GTK_STATE_FLAG_PRELIGHT, &rgba);
- gtk_widget_override_color (label, GTK_STATE_FLAG_SELECTED, &rgba);
-
- if (link_color != &default_link_color &&
- link_color != &default_visited_link_color)
- gdk_color_free (link_color);
-}
-
-static void
set_link_underline (GtkLinkButton *link_button)
{
GtkWidget *label;
@@ -362,19 +318,10 @@ gtk_link_button_add (GtkContainer *container,
{
GTK_CONTAINER_CLASS (gtk_link_button_parent_class)->add (container, widget);
- set_link_color (GTK_LINK_BUTTON (container));
set_link_underline (GTK_LINK_BUTTON (container));
}
static void
-gtk_link_button_style_updated (GtkWidget *widget)
-{
- GTK_WIDGET_CLASS (gtk_link_button_parent_class)->style_updated (widget);
-
- set_link_color (GTK_LINK_BUTTON (widget));
-}
-
-static void
set_hand_cursor (GtkWidget *widget,
gboolean show_hand)
{
@@ -725,6 +672,7 @@ gtk_link_button_query_tooltip_cb (GtkWidget *widget,
}
+
/**
* gtk_link_button_set_uri:
* @link_button: a #GtkLinkButton
@@ -795,7 +743,16 @@ gtk_link_button_set_visited (GtkLinkButton *link_button,
{
link_button->priv->visited = visited;
- set_link_color (link_button);
+ if (visited)
+ {
+ gtk_widget_unset_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK);
+ gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_VISITED, FALSE);
+ }
+ else
+ {
+ gtk_widget_unset_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_VISITED);
+ gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
+ }
g_object_notify (G_OBJECT (link_button), "visited");
}