[Gtk-sharp-list] Returning Gdk.Events
Paolo Molaro
lupus@ximian.com
Tue, 11 Mar 2003 22:19:34 +0100
On 03/11/03 Miguel de Icaza wrote:
> > My suggested solution is to use something like:
> >
> > public static Gdk.Event CurrrentEvent {
> > IntPtr handle = gtk_get_current_event ();
> > GdkEventType type;
> >
> > type = (GdkEventType)Marshal.Read32 (handle);
> > switch (type) {
> > case GdkEventType.Expose:
> > return (Gdk.Event)Marshal.PtrToStructure (handle, typeof (Gdk.EventExpose));
> > case GdkEventType.ButtonPress:
> > return (Gdk.Event)Marshal.PtrToStructure (handle, typeof (Gdk.ButtonPress));
> > ...
> > }
> > }
> >
> > Modulo some small details, it should work nicely.
>
> There is only one problem here: Gdk.Event is a class, and the various
> Gdk.EventXXXX are structures that do not share a common base class.
>
> I could change the signature to return an `object' instead of a
> Gdk.Event, and it would be up to the user to do an `is' compare on the
> result.
Well, that looks like a workaround. It would be better to have the
Gdk.EventXXXX types be reference types derived from Gdk.Event:
this map nicely and I'm sure that's "what Jim Gettys would have done if
he had C# back then" (TM) :-)
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better