GtkSharp/gtk/Object.custom
Christian Hoff 7b752d233c 2009-09-03 Christian Hoff <christian_hoff@gmx.net>
* glib/Global.cs: Kill the calling convention field again.
	It breaks GLib 2.x compatibility in the generator and there is
	probably no need to make the calling convention configurable.
	* .cs, *.custom: Hardcode Cdecl calling convention instead of
	using GLib's field.

svn path=/trunk/gtk-sharp/; revision=141283
2009-09-03 19:50:53 +00:00

158 lines
4.5 KiB
Plaintext
Executable file

// Gtk.Object.custom - Gtk Object class customizations
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2002-2003 Mike Kestner
// Copyright (c) 2007 Novell, Inc.
//
// This code is inserted after the automatically generated code.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
static Hashtable destroy_handlers;
static Hashtable DestroyHandlers {
get {
if (destroy_handlers == null)
destroy_handlers = new Hashtable ();
return destroy_handlers;
}
}
private static void OverrideDestroyed (GLib.GType gtype)
{
// Do Nothing. We don't want to hook into the native vtable.
// We will manually invoke the VM on signal invocation. The signal
// always raises before the default handler because this signal
// is RUN_CLEANUP.
}
[GLib.DefaultSignalHandler(Type=typeof(Gtk.Object), ConnectionMethod="OverrideDestroyed")]
protected virtual void OnDestroyed ()
{
if (DestroyHandlers.Contains (Handle)) {
EventHandler handler = (EventHandler) DestroyHandlers [Handle];
handler (this, EventArgs.Empty);
DestroyHandlers.Remove (Handle);
}
}
[GLib.Signal("destroy")]
public event EventHandler Destroyed {
add {
EventHandler handler = (EventHandler) DestroyHandlers [Handle];
DestroyHandlers [Handle] = Delegate.Combine (handler, value);
}
remove {
EventHandler handler = (EventHandler) DestroyHandlers [Handle];
handler = (EventHandler) Delegate.Remove (handler, value);
if (handler != null)
DestroyHandlers [Handle] = handler;
else
DestroyHandlers.Remove (Handle);
}
}
event EventHandler InternalDestroyed {
add {
GLib.Signal sig = GLib.Signal.Lookup (this, "destroy");
sig.AddDelegate (value);
}
remove {
GLib.Signal sig = GLib.Signal.Lookup (this, "destroy");
sig.RemoveDelegate (value);
}
}
static void NativeDestroy (object o, EventArgs args)
{
Gtk.Object obj = o as Gtk.Object;
if (obj == null)
return;
obj.OnDestroyed ();
}
static EventHandler native_destroy_handler;
static EventHandler NativeDestroyHandler {
get {
if (native_destroy_handler == null)
native_destroy_handler = new EventHandler (NativeDestroy);
return native_destroy_handler;
}
}
protected override void CreateNativeObject (string[] names, GLib.Value[] vals)
{
base.CreateNativeObject (names, vals);
}
public override void Dispose ()
{
if (Handle == IntPtr.Zero)
return;
InternalDestroyed -= NativeDestroyHandler;
base.Dispose ();
}
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void g_object_ref_sink (IntPtr raw);
protected override IntPtr Raw {
get {
return base.Raw;
}
set {
if (value != IntPtr.Zero)
g_object_ref_sink (value);
base.Raw = value;
if (value != IntPtr.Zero)
InternalDestroyed += NativeDestroyHandler;
}
}
[DllImport ("libgtk-win32-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void gtk_object_destroy (IntPtr raw);
public virtual void Destroy ()
{
if (Handle == IntPtr.Zero)
return;
gtk_object_destroy (Handle);
InternalDestroyed -= NativeDestroyHandler;
}
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_object_is_floating (IntPtr raw);
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_object_force_floating (IntPtr raw);
[DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_object_unref (IntPtr raw);
public bool IsFloating {
get {
return g_object_is_floating (Handle);
}
set {
if (value == true) {
if (!IsFloating)
g_object_force_floating (Handle);
} else {
g_object_ref_sink (Handle);
g_object_unref (Handle);
}
}
}