[Gtk-sharp-list] Returning Gdk.Events

Mike Kestner mkestner@speakeasy.net
10 Mar 2003 23:28:03 -0600


On Mon, 2003-03-10 at 20:17, Miguel de Icaza wrote:

> 	GdkEvent *gtk_get_current_event ()
> 
>      The problem is that the Event can be one of many of the various
> events, how can I construct the right event depending on the type field
> of the event?

The "union" problem.

I think the way to do this would be to add a static prop to
Gtk.Application:

public static CurrentEvent {
	get {
		return new Gdk.Event (gtk_get_current_event ());
	}
}

In the code that uses Gtk.Application.CurrentEvent, you'd do something
like:

Gdk.Event e = Gtk.Application.CurrentEvent;
switch (e.EventType) {
case EventType.Button:
	Gdk.EventButton eb = (Gdk.EventButton) e;
	// do whatever
	break;

etc...

We'd need to add explicit cast operators to the Gdk.Event class in order
to perform the casts, which could use Marshal.PtrToStucture to
"demarshal" the appropriate struct type.

Anyway, that's the kneejerk reaction.  I think rachel had given some
thought to GdkEvent marshaling at one point.  She can probably poke
holes in this strategy.  :)

-- 
Mike Kestner <mkestner@speakeasy.net>