A bug in GtkSpinButton or GtkAdjustment?



The tiny example below shows the effect. Basically, GtkSpinbutton produces
"value-changed" signals *in pairs* for every click on the up or down arrow.
In addition, it seems to generate single "value-changed" signals if the
"entry" of the spinbutton is focussed *and* the enclosing container gets
an 'expose' event on it.

The program below will print "value-changed" even if you click on its
title-bar decoration!

I'm using RedHat Linux 4.2 with GTK+ 1.0.4.

Source of demonstrator-program follows:
# include	<gdk/gdk.h>
# include	<gtk/gtk.h>


static void
destroy( GtkWidget *w, gpointer data )
{

	gtk_main_quit();
	return;
}


static void
speak( GtkWidget *w, gpointer data )
{

	g_print("Value Changed\n");
	return;
}


int
main( int argc, char *argv[] )
{
	GtkWidget	*window, *vbox, *spin;
	GtkAdjustment	*adj;

	gtk_init(&argc, &argv);

	/* the master window */	
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 	gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroy), NULL);

	/* create a vbox into which everything goes */	
	vbox = gtk_vbox_new(FALSE, 2);
	gtk_container_border_width(GTK_CONTAINER(vbox), 2);
	
	/* put map display under menu */
	adj = (GtkAdjustment *) gtk_adjustment_new (0.0, -90.0, 90.0, 0.1, 10.0, 0.0);
	spin = gtk_spin_button_new(adj, 0, 0);
	gtk_signal_connect(GTK_OBJECT(adj), "value_changed", GTK_SIGNAL_FUNC(speak), NULL);
	gtk_box_pack_start(GTK_BOX(vbox), spin, TRUE, TRUE, 0);
	gtk_widget_show(spin);
	
	/* put vbox into master window */		
	gtk_container_add(GTK_CONTAINER(window), vbox);
	gtk_widget_show(vbox);

	gtk_widget_show(window);
		
	gtk_main();
	return 0;
}


--

Steve                                       | Steve's law of House Rewiring:
S.Hosgood@swansea.ac.uk                     | "No matter how many power sockets
Phone: +44 1792 297292 + ask for Steve      |  you fit in a room, you will run
Fax:   +44 1792 295811                      |  out within the first week of use
--------------------------------------------+  even if you took Steve's law of
http://iiit.swan.ac.uk/~iisteve/steve.html  |  House Rewiring into account"




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