[Gtk-sharp-list] Returning Gdk.Events
Paolo Molaro
lupus@ximian.com
Tue, 11 Mar 2003 16:51:08 +0100
On 03/11/03 Jonathan Pryor wrote:
> public static Gdk.Event CurrrentEvent {
> IntPtr handle = gtk_get_current_event ();
> string gtk_name = g_type_name (handle);
> string cs_name = mapping[gtk_name];
> Gdk.Event ev = null;
> if (cs_name != null)
> ev = Activator.CreateInstance (cs_name,
> new object[]{handle});
> else
> // no "closest match"
> ev = new Gdk.Event (handle);
> return ev;
> }
> }
>
> I prefer this approach over Mike Kestner's approach, merely because the
> dynamic types are kept in sync. Though the table construction/lookup
> overhead may be undesirable, so this might not be the best alternative.
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.
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better