Problem with scrolled window and scroll bars



First post didn't seem to work, so if you get duplicates, i apologize.

I'm using GTK+ 1.0.0

Under some conditions, when an image is resized within a scrolled window, the
scroll bars toggle on and off in an endless loop, hanging the program. I use a
table inside a scrolled window (to center the image), to which a
gtk_drawing_area was attached. I use gtk_set_back_pixmap to change the image
within the drawing area.

I managed to duplicate the problem in the source code below. (the source file is
also in the included attachment).

This may be a bug, but if I'm doing something wrong, please help.

Warning: bug causes program to hog the system and (CTRL - C) does not work, on
my machine I must use kill (kill -s 9 pid).

/*### start of gtkbugs.c ### */

#include <stdio.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>

GtkWidget *window;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *scrolledwin;
GtkWidget *table;
GtkWidget *drawingarea;
GtkWidget *label;
GtkWidget *button;

GdkPixmap *pixmap;

void destroy_window(GtkWidget *widget, gpointer *data)
	{
	gtk_main_quit();
	}

void resize_drawing_area()
{
	GdkPixmap *pixmap1;

	pixmap1 = gdk_pixmap_new(window->window,800,688,-1);
	gdk_draw_rectangle (pixmap, drawingarea->style->black_gc, TRUE, 0, 0, 800, 688);

	gtk_widget_set_usize(table,800,688);
	gdk_window_set_back_pixmap(drawingarea->window,pixmap,FALSE);
	gdk_window_clear(drawingarea->window);
	gdk_flush();

}

int main (int argc, char *argv[])
	{
	gtk_init (&argc, &argv);


	/* window and message widgets */
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_policy (GTK_WINDOW (window),TRUE,TRUE,TRUE);
	gtk_signal_connect (GTK_OBJECT (window), "delete_event",(GtkSignalFunc) destroy_window, NULL);
	gtk_window_set_title (GTK_WINDOW (window), "GTK bugs program");
	gtk_widget_realize(window);

	vbox = gtk_vbox_new(FALSE,0);
	gtk_container_add(GTK_CONTAINER(window),vbox);
	gtk_widget_show(vbox);

	label = gtk_label_new("scrolled window scrollbars toggle on-off, causing program hang\nWarning: program difficult to kill (even CTRL - C, use CTRL - Z and kill -s 9)");
	gtk_box_pack_start(GTK_BOX(vbox),label,FALSE,FALSE,0);
	gtk_widget_show(label);

	button = gtk_button_new_with_label("click me for new image");
	gtk_signal_connect (GTK_OBJECT (button), "clicked",(GtkSignalFunc) resize_drawing_area, NULL);
	gtk_box_pack_start(GTK_BOX(vbox),button,FALSE,FALSE,0);
	gtk_widget_show(button);

/* problem is with widgets beyond this point (I think) */

	/* scrolled window */
	scrolledwin = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_set_usize(scrolledwin,812,694);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
          				GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_box_pack_start (GTK_BOX (vbox), scrolledwin, TRUE, TRUE, 0);
	gtk_widget_show (scrolledwin);

	/* table inside scrolled window */
	table= gtk_table_new (1,1,TRUE);
	gtk_container_add(GTK_CONTAINER (scrolledwin),table);
	gtk_widget_show (table);

	/* drawing area within table */
	drawingarea = gtk_drawing_area_new();
	gtk_table_attach(GTK_TABLE (table),drawingarea,0,1,0,1,GTK_EXPAND,GTK_EXPAND,0,0);
	gtk_widget_show (drawingarea);

	gtk_widget_show(window);


	/* set initial pixmap */
	pixmap = gdk_pixmap_new(window->window,500,768,-1);
	gdk_draw_rectangle (pixmap, drawingarea->style->black_gc, TRUE, 0, 0, 500, 768);

	gtk_widget_set_usize(table,500,768);
	gdk_window_set_back_pixmap(drawingarea->window,pixmap,FALSE);
	gdk_window_clear(drawingarea->window);
	gdk_flush();

	gtk_main ();
	return 0;
	}
/* ### end of file ### */

--
John Ellis <johne@bellatlantic.net>
http://www.geocities.com/SiliconValley/Haven/5235/

gtkbugs1.tar.gz



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