[Gtk-sharp-list] How to increase Gdk.Window reference count ?
Christian Hoff
christian_hoff at gmx.net
Tue Dec 22 08:55:57 EST 2009
kmarecki wrote:
> Hello,
>
> I would like to emulate key pressed events for GtkEntry.
> In plain C, code looks like this :
>
> gtk_widget_grab_focus((GtkWidget*)entry);
> GdkWindow *window=gtk_widget_get_window((GtkWidget*)entry);
> g_object_ref((gpointer)window);
>
> GdkEventKey* event=(GdkEventKey*)gdk_event_new(type);
> event->window=window;
> event->keyval=keyval;
> event->send_event=TRUE;
>
> gdk_event_put((GdkEvent*)event);
> gdk_event_free((GdkEvent*)event);
>
>
> (I've omitted for simplicity setting other GdkEventKey fields).
> Invoking g_object_ref is necessary because gdk_event_put
> calls g_object_unref.
>
> Tried following (based on Banshee class GtkWorkarounds)
>
> MethodInfo g_object_ref = typeof (GLib.Object).GetMethod ("g_object_ref",
> BindingFlags.NonPublic | BindingFlags.Static);
>
> g_object_ref.Invoke(null, new object[] { window.Handle });
>
> But it did not work out. There is no error except that my entry is
> destroyed,
> indicates that reference increasing was unsuccessful.
>
Uggh, that's a really nasty workaround... Why don't you try calling
g_object_ref via pinvoke:
[DllImport ("libgobject-2.0-0.dll", CallingConvention =
CallingConvention.Cdecl)]
static extern IntPtr g_object_ref (IntPtr raw);
(obviously, you need to adjust the library name when running this on
Unix/Mac). If the problem persists, set the GTK_SHARP_DEBUG environment
variable to some value (like "1") and see if the GLib messages on the
console are helpful.
You might also want to read a related post about sending mouse clicks:
http://go-mono.com/forums/#nabble-tt26687184
Good luck!
Christian
More information about the Gtk-sharp-list
mailing list