[gtk+/wip/colorchooser-v2] GtkColorSwatch: Use widget state instead of a custom 'selected'
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/colorchooser-v2] GtkColorSwatch: Use widget state instead of a custom 'selected'
- Date: Thu, 9 Feb 2012 04:48:27 +0000 (UTC)
commit cf6e32723ab4b45c99a0b0405e20a38fed0f3de7
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Feb 8 23:48:11 2012 -0500
GtkColorSwatch: Use widget state instead of a custom 'selected'
gtk/gtkcolorchooserwidget.c | 15 ++++++++++-----
gtk/gtkcolorswatch.c | 35 +++++++----------------------------
gtk/gtkcolorswatchprivate.h | 3 ---
3 files changed, 17 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 6599fac..1e0e3a1 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -103,8 +103,8 @@ select_swatch (GtkColorChooserWidget *cc,
return;
if (cc->priv->current != NULL)
- gtk_color_swatch_set_selected (cc->priv->current, FALSE);
- gtk_color_swatch_set_selected (swatch, TRUE);
+ gtk_widget_unset_state_flags (GTK_WIDGET (cc->priv->current), GTK_STATE_FLAG_SELECTED);
+ gtk_widget_set_state_flags (GTK_WIDGET (swatch), GTK_STATE_FLAG_SELECTED, FALSE);
cc->priv->current = swatch;
gtk_color_swatch_get_rgba (swatch, &color);
@@ -140,10 +140,15 @@ swatch_customize (GtkColorSwatch *swatch,
static void
swatch_selected (GtkColorSwatch *swatch,
- GParamSpec *pspec,
+ GtkStateFlags previous,
GtkColorChooserWidget *cc)
{
- select_swatch (cc, swatch);
+ GtkStateFlags flags;
+
+ flags = gtk_widget_get_state_flags (GTK_WIDGET (swatch));
+ if ((flags & GTK_STATE_FLAG_SELECTED) != (previous & GTK_STATE_FLAG_SELECTED) &&
+ (flags & GTK_STATE_FLAG_SELECTED) != 0)
+ select_swatch (cc, swatch);
}
static void
@@ -152,7 +157,7 @@ connect_swatch_signals (GtkWidget *p,
{
g_signal_connect (p, "activate", G_CALLBACK (swatch_activate), data);
g_signal_connect (p, "customize", G_CALLBACK (swatch_customize), data);
- g_signal_connect (p, "notify::selected", G_CALLBACK (swatch_selected), data);
+ g_signal_connect (p, "state-flags-changed", G_CALLBACK (swatch_selected), data);
}
static void
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index 8766ee6..0bd1d64 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -38,7 +38,6 @@ struct _GtkColorSwatchPrivate
GdkRGBA color;
gdouble radius[4];
gchar *icon;
- guint selected : 1;
guint has_color : 1;
guint contains_pointer : 1;
guint use_alpha : 1;
@@ -185,7 +184,7 @@ swatch_draw (GtkWidget *widget,
GTK_ICON_LOOKUP_GENERIC_FALLBACK
| GTK_ICON_LOOKUP_USE_BUILTIN);
}
- else if (swatch->priv->selected)
+ else if ((state & GTK_STATE_FLAG_SELECTED) != 0)
{
GdkRGBA bg, border;
GtkBorder border_width;
@@ -358,8 +357,8 @@ swatch_key_press (GtkWidget *widget,
event->keyval == GDK_KEY_KP_Enter ||
event->keyval == GDK_KEY_KP_Space)
{
- if (swatch->priv->has_color && !swatch->priv->selected)
- gtk_color_swatch_set_selected (swatch, TRUE);
+ if (swatch->priv->has_color && (gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_SELECTED) == 0)
+ gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
else
g_signal_emit (swatch, signals[ACTIVATE], 0);
return TRUE;
@@ -489,18 +488,20 @@ swatch_button_release (GtkWidget *widget,
GdkEventButton *event)
{
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
+ GtkStateFlags flags;
if (event->button == GDK_BUTTON_PRIMARY &&
swatch->priv->contains_pointer)
{
+ flags = gtk_widget_get_state_flags (widget);
if (!swatch->priv->has_color)
{
g_signal_emit (swatch, signals[ACTIVATE], 0);
return TRUE;
}
- else if (!swatch->priv->selected)
+ else if ((flags & GTK_STATE_FLAG_SELECTED) == 0)
{
- gtk_color_swatch_set_selected (swatch, TRUE);
+ gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
return TRUE;
}
}
@@ -532,9 +533,6 @@ swatch_get_property (GObject *object,
gtk_color_swatch_get_rgba (swatch, &color);
g_value_set_boxed (value, &color);
break;
- case PROP_SELECTED:
- g_value_set_boolean (value, swatch->priv->selected);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -554,9 +552,6 @@ swatch_set_property (GObject *object,
case PROP_RGBA:
gtk_color_swatch_set_rgba (swatch, g_value_get_boxed (value));
break;
- case PROP_SELECTED:
- gtk_color_swatch_set_selected (swatch, g_value_get_boolean (value));
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -614,10 +609,6 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
g_param_spec_boxed ("rgba", P_("RGBA Color"), P_("Color as RGBA"),
GDK_TYPE_RGBA, GTK_PARAM_READWRITE));
- g_object_class_install_property (object_class, PROP_SELECTED,
- g_param_spec_boolean ("selected", P_("Selected"), P_("Selected"),
- FALSE, GTK_PARAM_READWRITE));
-
g_type_class_add_private (object_class, sizeof (GtkColorSwatchPrivate));
}
@@ -689,18 +680,6 @@ gtk_color_swatch_get_rgba (GtkColorSwatch *swatch,
}
void
-gtk_color_swatch_set_selected (GtkColorSwatch *swatch,
- gboolean selected)
-{
- if (swatch->priv->selected != selected)
- {
- swatch->priv->selected = selected;
- gtk_widget_queue_draw (GTK_WIDGET (swatch));
- g_object_notify (G_OBJECT (swatch), "selected");
- }
-}
-
-void
gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
const gchar *icon)
{
diff --git a/gtk/gtkcolorswatchprivate.h b/gtk/gtkcolorswatchprivate.h
index 71bcd1a..bc8a03d 100644
--- a/gtk/gtkcolorswatchprivate.h
+++ b/gtk/gtkcolorswatchprivate.h
@@ -82,9 +82,6 @@ void gtk_color_swatch_set_hsva (GtkColorSwatch *swatch,
gdouble v,
gdouble a);
G_GNUC_INTERNAL
-void gtk_color_swatch_set_selected (GtkColorSwatch *swatch,
- gboolean selected);
-G_GNUC_INTERNAL
void gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
gboolean can_drop);
G_GNUC_INTERNAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]