gtk+ r21013 - in trunk: . gtk



Author: mitch
Date: Tue Aug  5 14:46:26 2008
New Revision: 21013
URL: http://svn.gnome.org/viewvc/gtk+?rev=21013&view=rev

Log:
2008-08-05  Michael Natterer  <mitch imendio com>

	Bug 544858 â Seal GtkAdjustment

	* gtk/gtk.symbols
	* gtk/gtkadjustment.[ch] (struct GtkAdjustment): seal all struct
	members.

	Add accessors for all properties and additionally a new function
	gtk_adjustment_configure() which sets all properties at
	once. Patch by Christian Dywan and myself.



Modified:
   trunk/ChangeLog
   trunk/gtk/gtk.symbols
   trunk/gtk/gtkadjustment.c
   trunk/gtk/gtkadjustment.h

Modified: trunk/gtk/gtk.symbols
==============================================================================
--- trunk/gtk/gtk.symbols	(original)
+++ trunk/gtk/gtk.symbols	Tue Aug  5 14:46:26 2008
@@ -198,10 +198,21 @@
 #if IN_FILE(__GTK_ADJUSTMENT_C__)
 gtk_adjustment_changed
 gtk_adjustment_clamp_page
+gtk_adjustment_configure
 gtk_adjustment_get_type G_GNUC_CONST
 gtk_adjustment_get_value
+gtk_adjustment_get_lower
+gtk_adjustment_get_upper
+gtk_adjustment_get_step_increment
+gtk_adjustment_get_page_increment
+gtk_adjustment_get_page_size
 gtk_adjustment_new
 gtk_adjustment_set_value
+gtk_adjustment_set_lower
+gtk_adjustment_set_upper
+gtk_adjustment_set_step_increment
+gtk_adjustment_set_page_increment
+gtk_adjustment_set_page_size
 gtk_adjustment_value_changed
 #endif
 #endif

Modified: trunk/gtk/gtkadjustment.c
==============================================================================
--- trunk/gtk/gtkadjustment.c	(original)
+++ trunk/gtk/gtkadjustment.c	Tue Aug  5 14:46:26 2008
@@ -64,6 +64,8 @@
 
 static guint adjustment_signals[LAST_SIGNAL] = { 0 };
 
+static guint64 adjustment_changed_stamp = 0; /* protected by global gdk lock */
+
 G_DEFINE_TYPE (GtkAdjustment, gtk_adjustment, GTK_TYPE_OBJECT)
 
 static void
@@ -310,7 +312,10 @@
       }
 
   if (changed)
-    gtk_adjustment_changed (GTK_ADJUSTMENT (object));
+    {
+      adjustment_changed_stamp++;
+      gtk_adjustment_changed (GTK_ADJUSTMENT (object));
+    }
 }
 
 GtkObject *
@@ -321,7 +326,7 @@
 		    gdouble page_increment,
 		    gdouble page_size)
 {
-  return g_object_new (GTK_TYPE_ADJUSTMENT, 
+  return g_object_new (GTK_TYPE_ADJUSTMENT,
 		       "lower", lower,
 		       "upper", upper,
 		       "step-increment", step_increment,
@@ -364,6 +369,285 @@
     }
 }
 
+/**
+ * gtk_adjustment_get_lower:
+ * @adjustment: a #GtkAdjustment
+ *
+ * Retrieves the minimum value of the adjustment.
+ *
+ * Return value: The current minimum value of the adjustment.
+ *
+ * Since: 2.14
+ **/
+gdouble
+gtk_adjustment_get_lower (GtkAdjustment *adjustment)
+{
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
+
+  return adjustment->lower;
+}
+
+/**
+ * gtk_adjustment_set_lower:
+ * @adjustment: a #GtkAdjustment
+ * @lower: the new minimum value
+ *
+ * Sets the minimum value of the adjustment.
+ *
+ * When setting multiple adjustment properties via their individual
+ * setters, multiple "changed" signals will be emitted. However, since
+ * the emission of the "changed" signal is tied to the emission of the
+ * "GObject::notify" signals of the changed properties, it's possible
+ * to compress the "changed" signals into one by calling
+ * g_object_freeze_notify() and g_object_thaw_notify() around the
+ * calls to the individual setters.
+ *
+ * Alternatively, using a single g_object_set() for all the properties
+ * to change, or using gtk_adjustment_configure() has the same effect
+ * of compressing "changed" emissions.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_adjustment_set_lower (GtkAdjustment *adjustment,
+                          gdouble        lower)
+{
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  if (lower != adjustment->lower)
+    g_object_set (adjustment, "lower", lower, NULL);
+}
+
+/**
+ * gtk_adjustment_get_upper:
+ * @adjustment: a #GtkAdjustment
+ *
+ * Retrieves the maximum value of the adjustment.
+ *
+ * Return value: The current maximum value of the adjustment.
+ *
+ * Since: 2.14
+ **/
+gdouble
+gtk_adjustment_get_upper (GtkAdjustment *adjustment)
+{
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
+
+  return adjustment->upper;
+}
+
+/**
+ * gtk_adjustment_set_upper:
+ * @adjustment: a #GtkAdjustment
+ * @upper: the new maximum value
+ *
+ * Sets the maximum value of the adjustment.
+ *
+ * Note that values will be restricted by
+ * <literal>upper - page-size</literal> if the page-size
+ * property is nonzero.
+ *
+ * See gtk_adjustment_set_lower() about how to compress multiple
+ * emissions of the "changed" signal when setting multiple adjustment
+ * properties.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_adjustment_set_upper (GtkAdjustment *adjustment,
+                          gdouble        upper)
+{
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  if (upper != adjustment->upper)
+    g_object_set (adjustment, "upper", upper, NULL);
+}
+
+/**
+ * gtk_adjustment_get_step_increment:
+ * @adjustment: a #GtkAdjustment
+ *
+ * Retrieves the step increment of the adjustment.
+ *
+ * Return value: The current step increment of the adjustment.
+ *
+ * Since: 2.14
+ **/
+gdouble
+gtk_adjustment_get_step_increment (GtkAdjustment *adjustment)
+{
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
+
+  return adjustment->step_increment;
+}
+
+/**
+ * gtk_adjustment_set_step_increment:
+ * @adjustment: a #GtkAdjustment
+ * @step_increment: the new step increment
+ *
+ * Sets the step increment of the adjustment.
+ *
+ * See gtk_adjustment_set_lower() about how to compress multiple
+ * emissions of the "changed" signal when setting multiple adjustment
+ * properties.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_adjustment_set_step_increment (GtkAdjustment *adjustment,
+                                   gdouble        step_increment)
+{
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  if (step_increment != adjustment->step_increment)
+    g_object_set (adjustment, "step-increment", step_increment, NULL);
+}
+
+/**
+ * gtk_adjustment_get_page_increment:
+ * @adjustment: a #GtkAdjustment
+ *
+ * Retrieves the page increment of the adjustment.
+ *
+ * Return value: The current page increment of the adjustment.
+ *
+ * Since: 2.14
+ **/
+gdouble
+gtk_adjustment_get_page_increment (GtkAdjustment *adjustment)
+{
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
+
+  return adjustment->page_increment;
+}
+
+/**
+ * gtk_adjustment_set_page_increment:
+ * @adjustment: a #GtkAdjustment
+ * @page_increment: the new page increment
+ *
+ * Sets the page increment of the adjustment.
+ *
+ * See gtk_adjustment_set_lower() about how to compress multiple
+ * emissions of the "changed" signal when setting multiple adjustment
+ * properties.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_adjustment_set_page_increment (GtkAdjustment *adjustment,
+                                   gdouble        page_increment)
+{
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  if (page_increment != adjustment->page_increment)
+    g_object_set (adjustment, "page-increment", page_increment, NULL);
+}
+
+/**
+ * gtk_adjustment_get_page_size:
+ * @adjustment: a #GtkAdjustment
+ *
+ * Retrieves the page size of the adjustment.
+ *
+ * Return value: The current page size of the adjustment.
+ *
+ * Since: 2.14
+ **/
+gdouble
+gtk_adjustment_get_page_size (GtkAdjustment *adjustment)
+{
+  g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), 0.0);
+
+  return adjustment->page_size;
+}
+
+/**
+ * gtk_adjustment_set_page_size:
+ * @adjustment: a #GtkAdjustment
+ * @page_size: the new page size
+ *
+ * Sets the page size of the adjustment.
+ *
+ * See gtk_adjustment_set_lower() about how to compress multiple
+ * emissions of the "changed" signal when setting multiple adjustment
+ * properties.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_adjustment_set_page_size (GtkAdjustment *adjustment,
+                              gdouble        page_size)
+{
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  if (page_size != adjustment->page_size)
+    g_object_set (adjustment, "page-size", page_size, NULL);
+}
+
+/**
+ * gtk_adjustment_configure:
+ * @adjustment: a #GtkAdjustment
+ * @value: the new value
+ * @lower: the new minimum value
+ * @upper: the new maximum value
+ * @step_increment: the new step increment
+ * @page_increment: the new page increment
+ * @page_size: the new page size
+ *
+ * Sets all properties of the adjustment at once.
+ *
+ * Use this function to avoid multiple emissions of the "changed"
+ * signal. See gtk_adjustment_set_lower() for an alternative way
+ * of compressing multiple emissions of "changed" into one.
+ *
+ * Since: 2.14
+ **/
+void
+gtk_adjustment_configure (GtkAdjustment *adjustment,
+                          gdouble        value,
+                          gdouble        lower,
+                          gdouble        upper,
+                          gdouble        step_increment,
+                          gdouble        page_increment,
+                          gdouble        page_size)
+{
+  gboolean value_changed = FALSE;
+  guint64 old_stamp = adjustment_changed_stamp;
+
+  g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+  g_object_freeze_notify (G_OBJECT (adjustment));
+
+  g_object_set (adjustment,
+                "lower", lower,
+                "upper", upper,
+                "step-increment", step_increment,
+                "page-increment", page_increment,
+                "page-size", page_size,
+                NULL);
+
+  value = CLAMP (value, lower, upper - page_size);
+
+  if (value != adjustment->value)
+    {
+      /* set value manually to make sure "changed" is emitted with the
+       * new value in place and is emitted before "value-changed"
+       */
+      adjustment->value = value;
+      value_changed = TRUE;
+    }
+
+  g_object_thaw_notify (G_OBJECT (adjustment));
+
+  if (old_stamp == adjustment_changed_stamp)
+    gtk_adjustment_changed (adjustment); /* force emission before ::value-changed */
+
+  if (value_changed)
+    gtk_adjustment_value_changed (adjustment);
+}
+
 void
 gtk_adjustment_changed (GtkAdjustment *adjustment)
 {

Modified: trunk/gtk/gtkadjustment.h
==============================================================================
--- trunk/gtk/gtkadjustment.h	(original)
+++ trunk/gtk/gtkadjustment.h	Tue Aug  5 14:46:26 2008
@@ -51,22 +51,22 @@
 struct _GtkAdjustment
 {
   GtkObject parent_instance;
-  
-  gdouble lower;
-  gdouble upper;
-  gdouble value;
-  gdouble step_increment;
-  gdouble page_increment;
-  gdouble page_size;
+
+  gdouble GSEAL (lower);
+  gdouble GSEAL (upper);
+  gdouble GSEAL (value);
+  gdouble GSEAL (step_increment);
+  gdouble GSEAL (page_increment);
+  gdouble GSEAL (page_size);
 };
 
 struct _GtkAdjustmentClass
 {
   GtkObjectClass parent_class;
-  
+
   void (* changed)	 (GtkAdjustment *adjustment);
   void (* value_changed) (GtkAdjustment *adjustment);
-  
+
   /* Padding for future expansion */
   void (*_gtk_reserved1) (void);
   void (*_gtk_reserved2) (void);
@@ -82,14 +82,39 @@
 						 gdouble	  step_increment,
 						 gdouble	  page_increment,
 						 gdouble	  page_size);
+
 void	   gtk_adjustment_changed		(GtkAdjustment	 *adjustment);
 void	   gtk_adjustment_value_changed		(GtkAdjustment	 *adjustment);
 void	   gtk_adjustment_clamp_page		(GtkAdjustment	 *adjustment,
 						 gdouble	  lower,
 						 gdouble	  upper);
+
 gdouble	   gtk_adjustment_get_value		(GtkAdjustment   *adjustment);
 void	   gtk_adjustment_set_value		(GtkAdjustment	 *adjustment,
 						 gdouble	  value);
+gdouble    gtk_adjustment_get_lower             (GtkAdjustment   *adjustment);
+void       gtk_adjustment_set_lower             (GtkAdjustment   *adjustment,
+                                                 gdouble          lower);
+gdouble    gtk_adjustment_get_upper             (GtkAdjustment   *adjustment);
+void       gtk_adjustment_set_upper             (GtkAdjustment   *adjustment,
+                                                 gdouble          upper);
+gdouble    gtk_adjustment_get_step_increment    (GtkAdjustment   *adjustment);
+void       gtk_adjustment_set_step_increment    (GtkAdjustment   *adjustment,
+                                                 gdouble          step_increment);
+gdouble    gtk_adjustment_get_page_increment    (GtkAdjustment   *adjustment);
+void       gtk_adjustment_set_page_increment    (GtkAdjustment   *adjustment,
+                                                 gdouble          page_increment);
+gdouble    gtk_adjustment_get_page_size         (GtkAdjustment   *adjustment);
+void       gtk_adjustment_set_page_size         (GtkAdjustment   *adjustment,
+                                                 gdouble          page_size);
+
+void       gtk_adjustment_configure             (GtkAdjustment   *adjustment,
+                                                 gdouble          value,
+						 gdouble          lower,
+						 gdouble          upper,
+						 gdouble          step_increment,
+						 gdouble          page_increment,
+						 gdouble          page_size);
 
 G_END_DECLS
 



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