* glib/Object.cs: add needs_ref boolean that controls whether

we need to ref this object once we have a pointer to it or not.
By default this is set to true -- constructors and other functions
where we do own the object need to set this to false before setting
the "Raw" property.  Also added Unref and RefCount methods.

* glue/object.c, glue/type.c: some utility functions for
refcounting support

* gdk/Pixbuf.custom: manually wrap a few functions so that
the refcount ends up being correct at the end (need an extra Unref)

* api/gdk-api.xml, sources/Gdk.metadata: metadata updates for
hiding manually-wrapped Pixbuf stuff

svn path=/trunk/gtk-sharp/; revision=8913
This commit is contained in:
Vladimir Vukicevic 2002-11-10 10:09:05 +00:00
parent 9ad6d1b6a4
commit 58f6f01d45
7 changed files with 142 additions and 55 deletions

View File

@ -1,3 +1,20 @@
2002-11-10 Vladimir Vukicevic <vladimir@pobox.com>
* glib/Object.cs: add needs_ref boolean that controls whether
we need to ref this object once we have a pointer to it or not.
By default this is set to true -- constructors and other functions
where we do own the object need to set this to false before setting
the "Raw" property. Also added Unref and RefCount methods.
* glue/object.c, glue/type.c: some utility functions for
refcounting support
* gdk/Pixbuf.custom: manually wrap a few functions so that
the refcount ends up being correct at the end (need an extra Unref)
* api/gdk-api.xml, sources/Gdk.metadata: metadata updates for
hiding manually-wrapped Pixbuf stuff
2002-11-10 Vladimir Vukicevic <vladimir@pobox.com>
* generator/StructBase.cs: create a Zero static member for

View File

@ -2411,15 +2411,6 @@
</parameters>
</callback>
<object name="Pixbuf" cname="GdkPixbuf" parent="GObject">
<method name="AddAlpha" cname="gdk_pixbuf_add_alpha">
<return-type type="GdkPixbuf*"/>
<parameters>
<parameter type="gboolean" name="substitute_color"/>
<parameter type="guchar" name="r"/>
<parameter type="guchar" name="g"/>
<parameter type="guchar" name="b"/>
</parameters>
</method>
<method name="AlphaModeGetType" cname="gdk_pixbuf_alpha_mode_get_type" shared="true">
<return-type type="GType"/>
</method>
@ -2460,18 +2451,6 @@
<parameter type="guint32" name="color2"/>
</parameters>
</method>
<method name="CompositeColorSimple" cname="gdk_pixbuf_composite_color_simple">
<return-type type="GdkPixbuf*"/>
<parameters>
<parameter type="int" name="dest_width"/>
<parameter type="int" name="dest_height"/>
<parameter type="GdkInterpType" name="interp_type"/>
<parameter type="int" name="overall_alpha"/>
<parameter type="int" name="check_size"/>
<parameter type="guint32" name="color1"/>
<parameter type="guint32" name="color2"/>
</parameters>
</method>
<method name="Copy" cname="gdk_pixbuf_copy">
<return-type type="GdkPixbuf*"/>
</method>
@ -2721,14 +2700,6 @@
<parameter type="GdkInterpType" name="interp_type"/>
</parameters>
</method>
<method name="ScaleSimple" cname="gdk_pixbuf_scale_simple">
<return-type type="GdkPixbuf*"/>
<parameters>
<parameter type="int" name="dest_width"/>
<parameter type="int" name="dest_height"/>
<parameter type="GdkInterpType" name="interp_type"/>
</parameters>
</method>
</object>
<object name="PixbufAnimation" cname="GdkPixbufAnimation" parent="GObject">
<method name="GetHeight" cname="gdk_pixbuf_animation_get_height">

View File

@ -1,29 +1,64 @@
IntPtr LoadFromStream (System.IO.Stream input)
{
PixbufLoader loader = new PixbufLoader ();
byte [] buffer = new byte [8192];
IntPtr LoadFromStream (System.IO.Stream input)
{
PixbufLoader loader = new PixbufLoader ();
byte [] buffer = new byte [8192];
int n;
while ((n = input.Read (buffer, 0, 8192)) != 0)
loader.Write (buffer, (uint) n);
loader.Close ();
return loader.Pixbuf.Handle;
}
public Pixbuf (System.IO.Stream input)
{
Raw = LoadFromStream (input);
}
public Pixbuf (System.Reflection.Assembly assembly, string resource)
{
if (assembly == null)
assembly = System.Reflection.Assembly.GetCallingAssembly ();
System.IO.Stream s;
Pixbuf p = null;
using (s = assembly.GetManifestResourceStream (resource))
Raw = LoadFromStream (s);
}
int n;
// scale_simple, composite_color_simple, and addalpha do a gdk_pixbuf_new on the
// return first, and we also ref it
// in the GetObject. So get rid of one extra reference.
while ((n = input.Read (buffer, 0, 8192)) != 0)
loader.Write (buffer, (uint) n);
loader.Close ();
[DllImport("gdk_pixbuf-2.0")]
static extern IntPtr gdk_pixbuf_scale_simple(IntPtr raw, int dest_width, int dest_height, int interp_type);
return loader.Pixbuf.Handle;
}
public Gdk.Pixbuf ScaleSimple(int dest_width, int dest_height, Gdk.InterpType interp_type) {
IntPtr raw_ret = gdk_pixbuf_scale_simple(Handle, dest_width, dest_height, (int) interp_type);
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret);
ret.Unref ();
return ret;
}
public Pixbuf (System.IO.Stream input)
{
Raw = LoadFromStream (input);
}
[DllImport("gdk_pixbuf-2.0")]
static extern IntPtr gdk_pixbuf_composite_color_simple(IntPtr raw, int dest_width, int dest_height, int interp_type, int overall_alpha, int check_size, uint color1, uint color2);
public Pixbuf (System.Reflection.Assembly assembly, string resource)
{
if (assembly == null)
assembly = System.Reflection.Assembly.GetCallingAssembly ();
public Gdk.Pixbuf CompositeColorSimple(int dest_width, int dest_height, Gdk.InterpType interp_type, int overall_alpha, int check_size, uint color1, uint color2) {
IntPtr raw_ret = gdk_pixbuf_composite_color_simple(Handle, dest_width, dest_height, (int) interp_type, overall_alpha, check_size, color1, color2);
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret);
ret.Unref ();
return ret;
}
System.IO.Stream s;
Pixbuf p = null;
using (s = assembly.GetManifestResourceStream (resource))
Raw = LoadFromStream (s);
}
[DllImport("gdk_pixbuf-2.0")]
static extern IntPtr gdk_pixbuf_add_alpha(IntPtr raw, bool substitute_color, byte r, byte g, byte b);
public Gdk.Pixbuf AddAlpha(bool substitute_color, byte r, byte g, byte b) {
IntPtr raw_ret = gdk_pixbuf_add_alpha(Handle, substitute_color, r, g, b);
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret);
ret.Unref ();
return ret;
}

View File

@ -24,6 +24,7 @@ namespace GLib {
// Private class and instance members
IntPtr _obj;
protected bool needs_ref = true;
EventHandlerList _events;
bool disposed = false;
Hashtable Data;
@ -87,6 +88,24 @@ namespace GLib {
g_object_ref (_obj);
}
/// <summary>
/// Unref Method
/// </summary>
///
/// <remarks>
/// Decreases the reference count on the native object.
/// This method is used by generated classes and structs,
/// and should not be used in user code.
/// </remarks>
protected virtual void Unref ()
{
if (_obj == IntPtr.Zero)
return;
g_object_unref (_obj);
}
/// <summary>
/// GetObject Shared Method
@ -121,6 +140,7 @@ namespace GLib {
/// </remarks>
public Object () {
needs_ref = false;
}
/// <summary>
@ -147,15 +167,20 @@ namespace GLib {
/// Handle property.
/// </remarks>
protected IntPtr Raw {
[DllImport("libgobject-2.0.so")]
private static extern string g_type_name (uint gtype);
protected virtual IntPtr Raw {
get {
return _obj;
}
set {
if (needs_ref)
g_object_ref (value);
Objects [value] = new WeakReference (this);
_obj = value;
}
}
}
/// <summary>
/// GType Property
@ -165,6 +190,9 @@ namespace GLib {
/// The type associated with this object class.
/// </remarks>
[DllImport("libgtksharpglue.so")]
private static extern uint gtksharp_get_type_id (IntPtr obj);
public static int GType {
get {
return 0;
@ -290,5 +318,14 @@ namespace GLib {
{
return gtksharp_is_object (obj);
}
[DllImport("gtksharpglue")]
static extern int gtksharp_object_get_ref_count (IntPtr obj);
public int RefCount {
get {
return gtksharp_object_get_ref_count (Handle);
}
}
}
}

View File

@ -15,3 +15,14 @@ gtksharp_object_unref_if_floating (GObject *obj)
g_object_unref (obj);
}
gboolean
gtksharp_object_is_floating (GObject *obj)
{
return GTK_OBJECT_FLOATING (obj);
}
int
gtksharp_object_get_ref_count (GObject *obj)
{
return obj->ref_count;
}

View File

@ -1,4 +1,4 @@
/* value.c : Glue to allocate GValues on the heap.
/* type.c : GType utilities
*
* Author: Mike Kestner <mkestner@speakeasy.net>
*

View File

@ -121,4 +121,20 @@
</data>
</rule>
<!-- hides -->
<rule>
<class name="GdkPixbuf">
<method>AddAlpha</method>
<method>ScaleSimple</method>
<method>CompositeColorSimple</method>
</class>
<data>
<attribute target="method">
<name>hidden</name>
<value>1</value>
</attribute>
</data>
</rule>
</metadata>