Expose_event on GtkDrawingArea



I just found a surprising bit of behaviour which I'll try to describe in
as small a posting as possible:

Starting from Owen's reply last week to a previous poster who couldn't get
expose events working (thanks Owen), I create a drawing area and a button
as follows: (Read it as if "OLD_WAY" is defined):

[stuff deleted]
	button = gtk_button_new_with_label("enquire");
	darea = gtk_drawing_area_new();
	gtk_widget_set_events (darea, GDK_EXPOSURE_MASK);
/*	gtk_drawing_area_size(GTK_DRAWING_AREA(darea), 300, 200); */
	gtk_widget_set_usize(darea, 300, 200);
	gtk_box_pack_start(GTK_BOX(vbox), darea, TRUE, TRUE, 0);
# ifdef OLD_WAY		
	gtk_signal_connect(GTK_OBJECT(darea), "expose_event", GTK_SIGNAL_FUNC(enquire), ( gpointer * ) darea);
 	gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(enquire), ( gpointer * ) darea);
# else
	gtk_signal_connect_object(GTK_OBJECT(darea), "expose_event", GTK_SIGNAL_FUNC(enquire), GTK_OBJECT(darea));
 	gtk_signal_connect_object(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(enquire), GTK_OBJECT(darea));
# endif
	gtk_box_pack_end(GTK_BOX(vbox), button, TRUE, FALSE, 0);
	gtk_widget_show(button);
	gtk_tooltips_set_tip(tips, button, "Draws on drawing-area & reports its size", "Private");
	
	gtk_widget_show(darea);
[more stuff deleted]


And here's the start of the definition of the 'enquire' function:


# ifdef OLDWAY
void
enquire( GtkWidget *gw, gpointer *data )
{
	GtkWidget	*wptr = ( GtkWidget * ) data;
# else	
void
enquire( GtkWidget *wptr )
{
# endif
	gint		x, y, w, h, d;
	
	if ( wptr == NULL ) {
		g_print("wptr is NULL\n");
		return;
	}
	
	if ( wptr->window == NULL ) {
		g_print("wptr->window is NULL\n");
		return;
	}
	
	if ( !GTK_WIDGET_REALIZED(wptr) ) {
		g_print("widget not realised\n");
		return;
	}
	
	gdk_window_get_geometry(wptr->window, &x, &y, &w, &h, &d);
	g_print("x=%d, y=%d, w=%d, h=%d, d=%d\n", x, y, w, h, d);
[rest deleted (mostly gdk_draw_* calls) ]



So, the 'enquire' function can get called either when the button is clicked or
when the drawing area is exposed. It draws on the drawing area using a load
of gdk_draw_* functions which I've left off for clarity.

(Hey - who said it had to be a sensible program  :-)
It's just a testbed for learning about gtk.)


The point of all this is that if compiled with OLD_WAY defined, then when
'expose' events trigger the 'enquire' routine, it continually returns early
with the message "wptr->window is NULL". Trigger it by pressing the button
however, and it works OK.

Recompile with OLD_WAY *undefined*, and everything works OK all the time. The
GDK calls in 'enquire' redraw on the drawing area just as I want!!

                       ---------------------

I call this weird. Surely the two sorts of event_handler are supposed to
differ only in the number of parameters they need? What's so funny about
expose events that makes them behave differently? Or am I just misusing
the system?

I'm on RedHat Linux 4.2, XFree86 X server, Afterstep window manager, GTK+ 1.0.1.


P.S
Another odd bit of behaviour, nothing to do with event handling is that the
program from which the above is extracted does weird things when the window
manager tries resizing it. Basically it won't let the window manager make
it any narrower than the 300 pixels set in the "set_usize" call, yet it
will allow itself to be made smaller vertically than the 200 pixels set
in the same call to "set_usize"! I assume this is something to do with
Afterstep - but has anyone seen similar behaviour elesewhere? I think I saw
it do the same thing on FVWM too, but can't prove that right at the moment.

Thanks in advance for any comments.
Steve

--

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]