[dia] Prefer gtk_adjustment_configure() over new/set pattern



commit e0ec03710b809ce935213e647ffc60e0fb00a7e3
Author: Hans Breuer <hans breuer org>
Date:   Sun May 25 11:07:47 2014 +0200

    Prefer gtk_adjustment_configure() over new/set pattern
    
    Previously Property::reset_widget() was creating and setting a new
    adjustment object to reconfigure value and range. This might have been
    the easiest way before gtk_adjustment_configure() was available with
    GTK+ 2.14. But with the access pattern for PropEventHandler (next
    commit) the recreation caused problems because of signals to already
    destroyed objects. The easiest way to overcome that was the switch to
    gtk_spin_button_get_adjustment() / gtk_adjustment_configure().

 lib/prop_geomtypes.c |   33 +++++++--------------------------
 lib/prop_inttypes.c  |   17 +++++++++--------
 lib/prop_matrix.c    |   10 +++++-----
 3 files changed, 21 insertions(+), 39 deletions(-)
---
diff --git a/lib/prop_geomtypes.c b/lib/prop_geomtypes.c
index 8632473..2236ba3 100644
--- a/lib/prop_geomtypes.c
+++ b/lib/prop_geomtypes.c
@@ -81,19 +81,17 @@ realprop_get_widget(RealProperty *prop, PropDialog *dialog)
 static void 
 realprop_reset_widget(RealProperty *prop, WIDGET *widget)
 {
-  GtkAdjustment *adj;
+  GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(widget));
   if (prop->common.descr->extra_data) {
     PropNumData *numdata = prop->common.descr->extra_data;
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->real_data,
-                                            numdata->min, numdata->max,
-                                            numdata->step, 
-                                            10.0 * numdata->step, 0));
+    gtk_adjustment_configure (adj, prop->real_data,
+                             numdata->min, numdata->max,
+                             numdata->step, 10.0 * numdata->step, 0);
   } else {
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->real_data,
-                                            G_MINFLOAT, G_MAXFLOAT,
-                                            0.1, 1.0, 0));
+    gtk_adjustment_configure (adj, prop->real_data,
+                             G_MINFLOAT, G_MAXFLOAT,
+                             0.1, 1.0, 0);
   }
-  gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(widget), adj);
 }
 
 static void 
@@ -191,21 +189,6 @@ lengthprop_get_widget(LengthProperty *prop, PropDialog *dialog)
 static void 
 lengthprop_reset_widget(LengthProperty *prop, WIDGET *widget)
 {
-  /*
-  GtkAdjustment *adj;
-  if (prop->common.extra_data) {
-    PropNumData *numdata = prop->common.extra_data;
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->length_data,
-                                            numdata->min, numdata->max,
-                                            numdata->step, 
-                                            10.0 * numdata->step, 0));
-  } else {
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->length_data,
-                                            G_MINFLOAT, G_MAXFLOAT,
-                                            0.1, 1.0, 0));
-  }
-  dia_unit_spinner_set_adjustment(GTK_SPIN_BUTTON(widget), adj);
-  */
   dia_unit_spinner_set_value(DIA_UNIT_SPINNER(widget), prop->length_data);
 }
 
@@ -295,9 +278,7 @@ fontsizeprop_get_widget(FontsizeProperty *prop, PropDialog *dialog)
                                                          G_MAXFLOAT,
                                                          0.1, 1.0, 0));
   GtkWidget *ret = dia_unit_spinner_new(adj, prefs_get_fontsize_unit());
-  /*  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(ret),TRUE);*/
   prophandler_connect(&prop->common, G_OBJECT(ret), "value-changed");
-  /*fontsizeprop_reset_widget(prop, ret);*/
   return ret;
 }
 
diff --git a/lib/prop_inttypes.c b/lib/prop_inttypes.c
index a8451e3..67f1ec7 100644
--- a/lib/prop_inttypes.c
+++ b/lib/prop_inttypes.c
@@ -292,18 +292,19 @@ intprop_get_widget(IntProperty *prop, PropDialog *dialog)
 static void 
 intprop_reset_widget(IntProperty *prop, WIDGET *widget)
 {
-  GtkAdjustment *adj;
+  GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(widget));
   if (prop->common.descr->extra_data) {
     PropNumData *numdata = prop->common.descr->extra_data;
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->int_data,
-                                            numdata->min, numdata->max,
-                                            numdata->step, 10.0 * numdata->step, 0));
+    gtk_adjustment_configure (adj,
+                             prop->int_data,
+                              numdata->min, numdata->max,
+                              numdata->step, 10.0 * numdata->step, 0);
   } else {
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(prop->int_data,
-                                            G_MININT, G_MAXINT,
-                                            1.0, 10.0, 0));
+    gtk_adjustment_configure (adj,
+                             prop->int_data,
+                              G_MININT, G_MAXINT,
+                              1.0, 10.0, 0);
   }
-  gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(widget), adj);
   gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(widget), TRUE);
 }
 
diff --git a/lib/prop_matrix.c b/lib/prop_matrix.c
index 9dcfccd..6ae6bf6 100644
--- a/lib/prop_matrix.c
+++ b/lib/prop_matrix.c
@@ -195,7 +195,6 @@ matrixprop_reset_widget(MatrixProperty *prop, GtkWidget *widget)
 {
   GList *children, *child;
   GtkWidget *sb;
-  GtkAdjustment *adj;
   real angle, sx, sy;
   int i = 0;
 
@@ -213,16 +212,17 @@ matrixprop_reset_widget(MatrixProperty *prop, GtkWidget *widget)
 
   children = gtk_container_get_children (GTK_CONTAINER (widget));
   for (child = children; child != NULL; child = g_list_next (child)) {
+    GtkAdjustment *adj;
     sb = child->data;
+    adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(sb));
     if (i == 0)
-      adj = GTK_ADJUSTMENT (gtk_adjustment_new(angle, -180.0, 180.0, 1.0, 15.0, 0));
+      gtk_adjustment_configure (adj, angle, -180.0, 180.0, 1.0, 15.0, 0);
     else if (i == 1)
-      adj = GTK_ADJUSTMENT (gtk_adjustment_new(sx, 0.01, 100.0, 0.1, 1.0, 0));
+      gtk_adjustment_configure (adj, sx, 0.01, 100.0, 0.1, 1.0, 0);
     else if (i == 2)
-      adj = GTK_ADJUSTMENT (gtk_adjustment_new(sy, 0.01, 100.0, 0.1, 1.0, 0));
+      gtk_adjustment_configure (adj, sy, 0.01, 100.0, 0.1, 1.0, 0);
     else
       g_assert_not_reached ();
-    gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(sb), GTK_ADJUSTMENT (adj));
     ++i;
   }
 }


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