Re: Patch: Bug 50278



Owen Taylor wrote:
 
> Why don't you send another version of the patch with the doc comment
> and the suggested changes; Havoc agrees with the above modifications,
> and hopefully nobody else will disagree too strongly ;-)
> 
> I'll give that a quick look-over and then you should be able to go
> ahead and commit it.

Here's the patch sans documentation.  I have yet to find any examples of
what you are referring to as "doc comment".  If you mean a blurb in
docs/reference/gtk/tmpl/*, I can add that and send it for review.  If
you mean something like:

/**
 * yadayada:
 * @foo:
 */

inline, I can whip that up as well.  Let me know.

Mike
Index: gtk/gtkspinbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkspinbutton.c,v
retrieving revision 1.53
diff -u -r1.53 gtkspinbutton.c
--- gtk/gtkspinbutton.c	2001/03/18 04:50:33	1.53
+++ gtk/gtkspinbutton.c	2001/03/28 01:59:32
@@ -64,6 +64,7 @@
 {
   INPUT,
   OUTPUT,
+  VALUE_CHANGED,
   LAST_SIGNAL
 };
 
@@ -248,6 +249,14 @@
 		    GTK_SIGNAL_OFFSET (GtkSpinButtonClass, output),
 		    gtk_marshal_BOOLEAN__VOID,
 		    GTK_TYPE_BOOL, 0);
+
+  spinbutton_signals[VALUE_CHANGED] =
+    gtk_signal_new ("value_changed",
+		    GTK_RUN_LAST,
+		    GTK_CLASS_TYPE (object_class),
+		    GTK_SIGNAL_OFFSET (GtkSpinButtonClass, value_changed),
+		    gtk_marshal_VOID__VOID,
+		    GTK_TYPE_NONE, 0);
 }
 
 static void
@@ -1062,6 +1071,9 @@
   if (return_val == FALSE)
     gtk_spin_button_default_output (spin_button);
 
+  gtk_signal_emit (GTK_OBJECT (spin_button), 
+		   spinbutton_signals[VALUE_CHANGED]);
+
   gtk_spin_button_draw_arrow (spin_button, GTK_ARROW_UP);
   gtk_spin_button_draw_arrow (spin_button, GTK_ARROW_DOWN);
 }
@@ -1421,6 +1433,36 @@
   return GTK_WIDGET (spin);
 }
 
+GtkWidget *
+gtk_spin_button_new_with_range (gdouble min,
+				gdouble max,
+				gdouble step)
+{
+  GtkObject *adj;
+  GtkSpinButton *spin;
+  gint digits;
+
+  g_return_val_if_fail (min < max, NULL);
+
+  spin = gtk_type_new (GTK_TYPE_SPIN_BUTTON);
+
+  adj = gtk_adjustment_new (min, min, max, step, 10 * step, step);
+
+  if (fabs (step) >= 1.0)
+    digits = 0;
+  else {
+    digits = abs ((gint) floor (log10 (fabs (step))));
+    if (digits > 5)
+      digits = 5;
+  }
+
+  gtk_spin_button_configure (spin, GTK_ADJUSTMENT (adj), step, digits);
+
+  gtk_spin_button_set_numeric (spin, TRUE);
+
+  return GTK_WIDGET (spin);
+}
+
 /* Callback used when the spin button's adjustment changes.  We need to redraw
  * the arrows when the adjustment's range changes, and reevaluate our size request.
  */
@@ -1468,7 +1510,6 @@
 GtkAdjustment *
 gtk_spin_button_get_adjustment (GtkSpinButton *spin_button)
 {
-  g_return_val_if_fail (spin_button != NULL, NULL);
   g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), NULL);
 
   return spin_button->adjustment;
@@ -1478,7 +1519,6 @@
 gtk_spin_button_set_digits (GtkSpinButton *spin_button,
 			    guint          digits)
 {
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
   g_return_if_fail (digits < 6);
 
@@ -1491,10 +1531,31 @@
     }
 }
 
+void
+gtk_spin_button_set_increments (GtkSpinButton *spin_button,
+				gdouble        step,
+				gdouble        page)
+{
+  g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
+
+  spin_button->adjustment->step_increment = step;
+  spin_button->adjustment->page_increment = page;
+}
+
+void
+gtk_spin_button_set_range (GtkSpinButton *spin_button,
+			   gdouble        min,
+			   gdouble        max)
+{
+  g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
+
+  spin_button->adjustment->lower = min;
+  spin_button->adjustment->upper = max;
+}
+
 gfloat
 gtk_spin_button_get_value_as_float (GtkSpinButton *spin_button)
 {
-  g_return_val_if_fail (spin_button != NULL, 0.0);
   g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), 0.0);
 
   return spin_button->adjustment->value;
@@ -1505,7 +1566,6 @@
 {
   gfloat val;
 
-  g_return_val_if_fail (spin_button != NULL, 0);
   g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), 0);
 
   val = spin_button->adjustment->value;
@@ -1519,7 +1579,6 @@
 gtk_spin_button_set_value (GtkSpinButton *spin_button, 
 			   gfloat         value)
 {
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
 
   if (fabs (value - spin_button->adjustment->value) > EPSILON)
@@ -1538,7 +1597,6 @@
 gtk_spin_button_set_update_policy (GtkSpinButton             *spin_button,
 				   GtkSpinButtonUpdatePolicy  policy)
 {
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
 
   spin_button->update_policy = policy;
@@ -1548,7 +1606,6 @@
 gtk_spin_button_set_numeric (GtkSpinButton  *spin_button,
 			     gboolean        numeric)
 {
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
 
   spin_button->numeric = (numeric != 0);
@@ -1558,7 +1615,6 @@
 gtk_spin_button_set_wrap (GtkSpinButton  *spin_button,
 			  gboolean        wrap)
 {
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
 
   spin_button->wrap = (wrap != 0);
@@ -1580,7 +1636,6 @@
 {
   guint new_val;
 
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
 
   new_val = (snap_to_ticks != 0);
@@ -1601,7 +1656,6 @@
   GtkAdjustment *adj;
   gfloat diff;
 
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
   
   adj = spin_button->adjustment;
@@ -1670,7 +1724,6 @@
   gint error = 0;
   gint return_val;
 
-  g_return_if_fail (spin_button != NULL);
   g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
 
   return_val = FALSE;
Index: gtk/gtkspinbutton.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkspinbutton.h,v
retrieving revision 1.22
diff -u -r1.22 gtkspinbutton.h
--- gtk/gtkspinbutton.h	2001/03/18 04:50:33	1.22
+++ gtk/gtkspinbutton.h	2001/03/28 01:59:33
@@ -106,6 +106,7 @@
   gint (*input)  (GtkSpinButton *spin_button,
 		  gfloat        *new_value);
   gint (*output) (GtkSpinButton *spin_button);
+  void (*value_changed) (GtkSpinButton *spin_button);
 };
 
 
@@ -120,6 +121,10 @@
 						    gfloat	    climb_rate,
 						    guint	    digits);
 
+GtkWidget*	gtk_spin_button_new_with_range	   (gdouble  min,
+						    gdouble  max,
+						    gdouble  step);
+
 void		gtk_spin_button_set_adjustment	   (GtkSpinButton  *spin_button,
 						    GtkAdjustment  *adjustment);
 
@@ -127,6 +132,14 @@
 
 void		gtk_spin_button_set_digits	   (GtkSpinButton  *spin_button,
 						    guint	    digits);
+
+void		gtk_spin_button_set_increments	   (GtkSpinButton  *spin_button,
+						    gdouble         step,
+						    gdouble         page);
+
+void		gtk_spin_button_set_range	   (GtkSpinButton  *spin_button,
+						    gdouble         min,
+						    gdouble         max);
 
 gfloat		gtk_spin_button_get_value_as_float (GtkSpinButton  *spin_button);
 
Index: gtk/testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/testgtk.c,v
retrieving revision 1.228
diff -u -r1.228 testgtk.c
--- gtk/testgtk.c	2001/03/08 17:13:11	1.228
+++ gtk/testgtk.c	2001/03/28 02:00:17
@@ -3622,6 +3622,23 @@
   gtk_label_set_text (label, buf);
 }
 
+static void
+get_spin_value (GtkWidget *widget, gpointer data)
+{
+  gchar *buffer;
+  GtkLabel *label;
+  GtkSpinButton *spin;
+
+  spin = GTK_SPIN_BUTTON (widget);
+  label = GTK_LABEL (data);
+
+  buffer = g_strdup_printf ("%0.*f", spin->digits,
+			    gtk_spin_button_get_value_as_float (spin));
+  gtk_label_set_text (label, buffer);
+
+  g_free (buffer);
+}
+
 static gint
 spin_button_time_output_func (GtkSpinButton *spin_button)
 {
@@ -3901,6 +3918,22 @@
 
       gtk_box_pack_start (GTK_BOX (vbox), val_label, TRUE, TRUE, 0);
       gtk_label_set_text (GTK_LABEL (val_label), "0");
+
+      frame = gtk_frame_new ("Using Convenience Constructor");
+      gtk_box_pack_start (GTK_BOX (main_vbox), frame, TRUE, TRUE, 0);
+  
+      hbox = gtk_hbox_new (FALSE, 0);
+      gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
+      gtk_container_add (GTK_CONTAINER (frame), hbox);
+      
+      val_label = gtk_label_new ("0.0");
+
+      spinner = gtk_spin_button_new_with_range (0.0, 10.0, 0.009);
+      gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinner), 0.0);
+      gtk_signal_connect (GTK_OBJECT (spinner), "value_changed",
+			  GTK_SIGNAL_FUNC (get_spin_value), val_label);
+      gtk_box_pack_start (GTK_BOX (hbox), spinner, TRUE, TRUE, 5);
+      gtk_box_pack_start (GTK_BOX (hbox), val_label, TRUE, TRUE, 5);
 
       hbox = gtk_hbox_new (FALSE, 0);
       gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, TRUE, 0);


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