GtkSharp/glib/Opaque.cs

139 lines
2.6 KiB
C#
Raw Normal View History

2002-07-25 Rachel Hestilow <hestilow@ximian.com> [about 60% of the marshalling patch that I lost. The rest to come tomorrow.] * generator/BoxedGen.cs, StructGen.cs: Move most of this to StructBase, delete large chunks duplicated from ClassBase. * generator/IGeneratable.cs: Add MarshalReturnType, FromNativeReturn. * generator/ClassBase.cs: Move ctor stuff here. Add a CallByName overload with no parameters for the "self" reference. * generator/EnumGen.cs, CallbackGen.cs: Implement new MarshalReturnType, FromNativeReturn. * generator/Method.cs: Use container_type.MarshalType, CallByName, and SymbolTable.FromNativeReturn when generating call and import sigs. * generator/OpaqueGen.cs: Added. * generator/Property.cs: Handle boxed and opaques differently. * generator/SymbolTable.cs: Update for the opaque stuff and the new Return methods. Also change GetClassGen to simply call the as operator. * glib/Boxed.cs: Update for struct usage -- this is now a wrapper for the purposes of using with Value. * glib/Opaque.cs: Added. New base class for opaque structs. * glue/textiter.c, gtk/TextIter.custom: Remove. * gnome/Program.cs: Update for new struct marshalling. * parser/Metadata.pm: Use our own getChildrenByTagName. * parser/README: Update for new requirements (was out of sync with build.pl) * parser/gapi2xml.pl: Hide struct like const in field elements. * parser/gapi_pp.pl: Handle embedded union fields (poorly). * sample/test/TestColorSelection.cs: Comment out null color tests for now. svn path=/trunk/gtk-sharp/; revision=6186
2002-07-26 06:08:52 +00:00
// Object.cs - GObject class wrapper implementation
//
// Authors: Bob Smith <bob@thestuff.net>
// Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Bob Smith and Mike Kestner
namespace GLib {
using System;
using System.Collections;
using System.ComponentModel;
using System.Runtime.InteropServices;
/// <summary>
/// Object Class
/// </summary>
///
/// <remarks>
/// Wrapper class for GObject.
/// </remarks>
public class Opaque : IWrapper {
// Private class and instance members
IntPtr _obj;
EventHandlerList _events;
Hashtable Data;
static Hashtable Opaques = new Hashtable();
/// <summary>
/// GetObject Shared Method
/// </summary>
///
/// <remarks>
/// Used to obtain a CLI typed object associated with a
/// given raw object pointer. This method is primarily
/// used to wrap object references that are returned
/// by either the signal system or raw class methods that
/// return GObject references.
/// </remarks>
///
/// <returns>
/// The wrapper instance.
/// </returns>
public static Opaque GetOpaque(IntPtr o)
{
Opaque obj = (Opaque)Opaques[(int)o];
if (obj != null) return obj;
return null; //FIXME: Call TypeParser here eventually.
}
/// <summary>
/// Object Constructor
/// </summary>
///
/// <remarks>
/// Dummy constructor needed for derived classes.
/// </remarks>
public Opaque () {}
/// <summary>
/// Object Constructor
/// </summary>
///
/// <remarks>
/// Creates an object from a raw object reference.
/// </remarks>
public Opaque (IntPtr raw)
{
Raw = raw;
}
/// <summary>
/// Raw Property
/// </summary>
///
/// <remarks>
/// The raw GObject reference associated with this wrapper.
/// Only subclasses of Object can access this read/write
/// property. For public read-only access, use the
/// Handle property.
/// </remarks>
protected IntPtr Raw {
get {
return _obj;
}
set {
Opaques [value] = this;
_obj = value;
}
}
/// <summary>
/// Handle Property
/// </summary>
///
/// <remarks>
/// The raw GObject reference associated with this object.
/// Subclasses can use Raw property for read/write
/// access.
/// </remarks>
public IntPtr Handle {
get {
return _obj;
}
set {
_obj = value;
}
}
public override bool Equals (object o)
{
if (!(o is Opaque))
return false;
return (Handle == ((Opaque) o).Handle);
}
/// <summary>
/// GetHashCode Method
/// </summary>
///
/// <remarks>
/// Calculates a hashing value.
/// </remarks>
public override int GetHashCode ()
{
return Handle.GetHashCode ();
}
}
}