GtkLinkButton: Use :link and :visited for the label's color

https://bugzilla.gnome.org/show_bug.cgi?id=709629
This commit is contained in:
Timm Bäder 2013-10-08 12:50:08 +02:00 committed by Benjamin Otte
parent 5201c876d5
commit 2ba33adf96

View File

@ -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,
@ -295,46 +291,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)
{
@ -362,18 +318,9 @@ 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");
}