GtkColorSel property patch



I went through and updated the colorsel property support patch
in bug #51014 to the current GtkColorSel API. If someone wants
to sanity check this, I'd appreciate it.

Possible questionable decisions:

 * I omitted previous_color/previous_alpha properties because
   they are minimally useful and would be confusing in a GUI builder 
   (the value set there might get overridden if the GUI builder
   set the current_color/current_alpha properties afterwards)

 * I left the 'current_' in current_color/current_alpha even 
   though there is no previous_, so as to match the C API.

 * Again to match the C API, current_alpha is "_alpha", even
   though there is some mismatch between this and 
   has_opacity_control.

 * Again to match the C API, current_alpha is 0-65535 though
   as a control in a GUI builder this might be a confusing
   choice of range. (The actual widget displays 0-255)

In this patch, I've also moved gtk_color_selection_set_update_policy()
inside #ifndef GTK_DISABLE_DEPRECATED, since it is obsolete
to the point of 

  g_warning (G_STRLOC ": This function is deprecated.");

But I don't think this is actually right - if set_update_policy()
is going to do nothing and spit a warning, it isn't deprecated,
it no longer works at all, and programs using it are broken.

So the best thing to do would be to remove it entirely and 
put an entry into Changes-2.0.txt.

(If, on the other hand, we consider it doing nothing harmless,
we should remove the warning.)

Regards,
                                        Owen

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2129
diff -u -r1.2129 ChangeLog
--- ChangeLog	2001/07/19 14:57:09	1.2129
+++ ChangeLog	2001/07/19 15:52:02
@@ -1,3 +1,11 @@
+Thu Jul 19 11:41:00 2001  Owen Taylor  <otaylor redhat com>
+
+	* gtk/gtkcolorsel.c: Add propery support (roughly
+	based on patch from Lee Mallabone, #51014)
+
+	* gtk/gtkcolorsel.h: Mark gtk_color_selection_set_update_policy as
+	deprecated, since we already g_warning() on it.
+
 Sat Jul  7 02:50:14 2001  Owen Taylor  <otaylor redhat com>
 
 	* gtk/gtkwidget.c (gtk_widget_set_parent): Enforce
Index: gtk/gtkcolorsel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcolorsel.c,v
retrieving revision 1.75
diff -u -r1.75 gtkcolorsel.c
--- gtk/gtkcolorsel.c	2001/07/18 23:39:22	1.75
+++ gtk/gtkcolorsel.c	2001/07/19 15:52:03
@@ -19,7 +19,7 @@
  */
 
 /*
- * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
@@ -76,6 +76,14 @@
 };
 
 enum {
+  PROP_0,
+  PROP_HAS_PALETTE,
+  PROP_HAS_OPACITY_CONTROL,
+  PROP_CURRENT_COLOR,
+  PROP_CURRENT_ALPHA,
+};
+
+enum {
   COLORSEL_RED = 0,
   COLORSEL_GREEN = 1,
   COLORSEL_BLUE = 2,
@@ -137,6 +145,14 @@
 static void gtk_color_selection_destroy		(GtkObject		 *object);
 static void gtk_color_selection_finalize        (GObject		 *object);
 static void update_color			(GtkColorSelection	 *colorsel);
+static void gtk_color_selection_set_property    (GObject                 *object,
+					         guint                    prop_id,
+					         const GValue            *value,
+					         GParamSpec              *pspec);
+static void gtk_color_selection_get_property    (GObject                 *object,
+					         guint                    prop_id,
+					         GValue                  *value,
+					         GParamSpec              *pspec);
 
 static gint     gtk_color_selection_get_palette_size    (GtkColorSelection *colorsel);
 static gboolean gtk_color_selection_get_palette_color   (GtkColorSelection *colorsel,
@@ -1518,6 +1534,11 @@
       *ptr = '0';
   gtk_entry_set_text (GTK_ENTRY (priv->hex_entry), entryval);
   priv->changing = FALSE;
+
+  g_object_freeze_notify (G_OBJECT (colorsel));
+  g_object_notify (G_OBJECT (colorsel), "current_color");
+  g_object_notify (G_OBJECT (colorsel), "current_alpha");
+  g_object_thaw_notify (G_OBJECT (colorsel));
 }
 
 
@@ -1637,7 +1658,39 @@
   
   object_class->destroy = gtk_color_selection_destroy;
   gobject_class->finalize = gtk_color_selection_finalize;
+
+  gobject_class->set_property = gtk_color_selection_set_property;
+  gobject_class->get_property = gtk_color_selection_get_property;
   
+  g_object_class_install_property (gobject_class,
+                                   PROP_HAS_OPACITY_CONTROL,
+                                   g_param_spec_boolean ("has_opacity_control",
+							 _("Has Opacity Control"),
+							 _("Whether the color selector should allow setting opacity"),
+							 FALSE,
+							 G_PARAM_READABLE | G_PARAM_WRITABLE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_HAS_PALETTE,
+                                   g_param_spec_boolean ("has_palette",
+							 _("Has palette"),
+							 _("Whether a palette should be used"),
+							 FALSE,
+							 G_PARAM_READABLE | G_PARAM_WRITABLE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_CURRENT_COLOR,
+                                   g_param_spec_boxed ("current_color",
+                                                       _("Current Color"),
+                                                       _("The current color"),
+                                                       GDK_TYPE_COLOR,
+                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
+  g_object_class_install_property (gobject_class,
+                                   PROP_CURRENT_ALPHA,
+                                   g_param_spec_uint ("current_alpha",
+						      _("Current Alpha"),
+						      _("The current opacity value (0 fully transparent, 65535 fully opaque)"),
+						      0, 65535, 65535,
+						      G_PARAM_READABLE | G_PARAM_WRITABLE));
+  
   color_selection_signals[COLOR_CHANGED] =
     gtk_signal_new ("color_changed",
                     GTK_RUN_FIRST,
@@ -1987,6 +2040,8 @@
 	  gtk_widget_hide (priv->opacity_entry);
 	}
       color_sample_draw_samples (colorsel);
+      
+      g_object_notify (G_OBJECT (colorsel), "has_opacity_control");
     }
 }
 
@@ -2035,6 +2090,8 @@
 	gtk_widget_show (priv->palette_frame);
       else
 	gtk_widget_hide (priv->palette_frame);
+      
+      g_object_notify (G_OBJECT (colorsel), "has_palette");
     }
 }
 
@@ -2053,9 +2110,10 @@
 {
   ColorSelectionPrivate *priv;
   gint i;
+  gboolean previous_changed;
   
   g_return_if_fail (GTK_IS_COLOR_SELECTION (colorsel));
-  
+
   priv = colorsel->private_data;
   priv->changing = TRUE;
   priv->color[COLORSEL_RED] = color->red / 65535.0;
@@ -2069,6 +2127,7 @@
 		  &priv->color[COLORSEL_VALUE]);
   if (priv->default_set == FALSE)
     {
+      previous_changed = TRUE;
       for (i = 0; i < COLORSEL_NUM_CHANNELS; i++)
 	priv->old_color[i] = priv->color[i];
     }
@@ -2445,6 +2504,67 @@
   priv = colorsel->private_data;
   
   return (gtk_hsv_is_adjusting (GTK_HSV (priv->triangle_colorsel)));
+}
+
+static void
+gtk_color_selection_set_property (GObject         *object,
+				  guint            prop_id,
+				  const GValue    *value,
+				  GParamSpec      *pspec)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
+  
+  switch (prop_id)
+    {
+    case PROP_HAS_OPACITY_CONTROL:
+      gtk_color_selection_set_has_opacity_control (colorsel, 
+						   g_value_get_boolean (value));
+      break;
+    case PROP_HAS_PALETTE:
+      gtk_color_selection_set_has_palette (colorsel, 
+					   g_value_get_boolean (value));
+      break;
+    case PROP_CURRENT_COLOR:
+      gtk_color_selection_set_current_color (colorsel, g_value_get_boxed (value));
+      break;
+    case PROP_CURRENT_ALPHA:
+      gtk_color_selection_set_current_alpha (colorsel, g_value_get_uint (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+  
+}
+
+static void
+gtk_color_selection_get_property (GObject     *object,
+				  guint        prop_id,
+				  GValue      *value,
+				  GParamSpec  *pspec)
+{
+  GtkColorSelection *colorsel = GTK_COLOR_SELECTION (object);
+  GdkColor color;
+  
+  switch (prop_id)
+    {
+    case PROP_HAS_OPACITY_CONTROL:
+      g_value_set_boolean (value, gtk_color_selection_get_has_opacity_control (colorsel));
+      break;
+    case PROP_HAS_PALETTE:
+      g_value_set_boolean (value, gtk_color_selection_get_has_palette (colorsel));
+      break;
+    case PROP_CURRENT_COLOR:
+      gtk_color_selection_get_current_color (colorsel, &color);
+      g_value_set_boxed (value, &color);
+      break;
+    case PROP_CURRENT_ALPHA:
+      g_value_set_uint (value, gtk_color_selection_get_current_alpha (colorsel));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
 
Index: gtk/gtkcolorsel.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcolorsel.h,v
retrieving revision 1.20
diff -u -r1.20 gtkcolorsel.h
--- gtk/gtkcolorsel.h	2001/05/11 17:13:41	1.20
+++ gtk/gtkcolorsel.h	2001/07/19 15:52:03
@@ -70,8 +70,6 @@
 
 GtkType    gtk_color_selection_get_type                (void) G_GNUC_CONST;
 GtkWidget *gtk_color_selection_new                     (void);
-void       gtk_color_selection_set_update_policy       (GtkColorSelection *colorsel,
-							GtkUpdateType      policy);
 gboolean   gtk_color_selection_get_has_opacity_control (GtkColorSelection *colorsel);
 void       gtk_color_selection_set_has_opacity_control (GtkColorSelection *colorsel,
 							gboolean           has_opacity);
@@ -107,10 +105,12 @@
 
 #ifndef GTK_DISABLE_DEPRECATED
 /* Deprecated calls: */
-void       gtk_color_selection_set_color        (GtkColorSelection    *colorsel,
-						 gdouble               *color);
-void       gtk_color_selection_get_color        (GtkColorSelection    *colorsel,
-						 gdouble              *color);
+void gtk_color_selection_set_color         (GtkColorSelection *colorsel,
+					    gdouble           *color);
+void gtk_color_selection_get_color         (GtkColorSelection *colorsel,
+					    gdouble           *color);
+void gtk_color_selection_set_update_policy (GtkColorSelection *colorsel,
+					    GtkUpdateType      policy);
 #endif /* GTK_DISABLE_DEPRECATED */
 
 #ifdef __cplusplus




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]