2002-09-11 Rachel Hestilow <hestilow@ximian.com>

* glib/Object.cs (Ref): Added.

	* gtk/Object.custom (Ref): Overload. Note that we were reffed.
	(DisposeNative): Unref if we were explicitly reffed.

	* generator/Method.cs: Call Ref if needs_ret is set.
	* generator/StructBase.cs: Call Ref on all object accessors.

	* glue/style.c: Ref returned GCs.

	* sources/Gtk.metadata: Set needs_ret on various gdk-related
	accessors in GtkWidget. Hide Ref/Unref methods on Widget and
	RcStyle as these ought to be deprecated anyway.

svn path=/trunk/gtk-sharp/; revision=7380
This commit is contained in:
Rachel Hestilow 2002-09-12 05:21:16 +00:00
parent 2239115a55
commit 32ae593a0e
8 changed files with 110 additions and 15 deletions

View file

@ -1,3 +1,19 @@
2002-09-11 Rachel Hestilow <hestilow@ximian.com>
* glib/Object.cs (Ref): Added.
* gtk/Object.custom (Ref): Overload. Note that we were reffed.
(DisposeNative): Unref if we were explicitly reffed.
* generator/Method.cs: Call Ref if needs_ret is set.
* generator/StructBase.cs: Call Ref on all object accessors.
* glue/style.c: Ref returned GCs.
* sources/Gtk.metadata: Set needs_ret on various gdk-related
accessors in GtkWidget. Hide Ref/Unref methods on Widget and
RcStyle as these ought to be deprecated anyway.
2002-09-11 Rodrigo Moya <rodrigo@gnome-db.org>
* gnomedb/Makefile.in:

View file

@ -5453,10 +5453,10 @@
<return-type type="GType"/>
</method>
<constructor cname="gtk_rc_style_new"/>
<method name="Ref" cname="gtk_rc_style_ref">
<method name="Ref" cname="gtk_rc_style_ref" hidden="1">
<return-type type="void"/>
</method>
<method name="Unref" cname="gtk_rc_style_unref">
<method name="Unref" cname="gtk_rc_style_unref" hidden="1">
<return-type type="void"/>
</method>
</object>
@ -9420,22 +9420,22 @@
<method name="GetChildVisible" cname="gtk_widget_get_child_visible">
<return-type type="gboolean"/>
</method>
<method name="GetColormap" cname="gtk_widget_get_colormap">
<method name="GetColormap" cname="gtk_widget_get_colormap" needs_ref="1">
<return-type type="GdkColormap*"/>
</method>
<method name="GetCompositeName" cname="gtk_widget_get_composite_name">
<return-type type="gchar*"/>
</method>
<method name="GetDefaultColormap" cname="gtk_widget_get_default_colormap" shared="true">
<method name="GetDefaultColormap" cname="gtk_widget_get_default_colormap" shared="true" needs_ref="1">
<return-type type="GdkColormap*"/>
</method>
<method name="GetDefaultDirection" cname="gtk_widget_get_default_direction" shared="true">
<return-type type="GtkTextDirection"/>
</method>
<method name="GetDefaultStyle" cname="gtk_widget_get_default_style" shared="true">
<method name="GetDefaultStyle" cname="gtk_widget_get_default_style" shared="true" needs_ref="1">
<return-type type="GtkStyle*"/>
</method>
<method name="GetDefaultVisual" cname="gtk_widget_get_default_visual" shared="true">
<method name="GetDefaultVisual" cname="gtk_widget_get_default_visual" shared="true" needs_ref="1">
<return-type type="GdkVisual*"/>
</method>
<method name="GetDirection" cname="gtk_widget_get_direction">
@ -9447,7 +9447,7 @@
<method name="GetExtensionEvents" cname="gtk_widget_get_extension_events">
<return-type type="GdkExtensionMode"/>
</method>
<method name="GetModifierStyle" cname="gtk_widget_get_modifier_style">
<method name="GetModifierStyle" cname="gtk_widget_get_modifier_style" needs_ref="1">
<return-type type="GtkRcStyle*"/>
</method>
<method name="GetName" cname="gtk_widget_get_name">
@ -9459,7 +9459,7 @@
<method name="GetParent" cname="gtk_widget_get_parent">
<return-type type="GtkWidget*"/>
</method>
<method name="GetParentWindow" cname="gtk_widget_get_parent_window">
<method name="GetParentWindow" cname="gtk_widget_get_parent_window" needs_ref="1">
<return-type type="GdkWindow*"/>
</method>
<method name="GetPointer" cname="gtk_widget_get_pointer">
@ -9479,7 +9479,7 @@
<parameter type="gint*" name="height"/>
</parameters>
</method>
<method name="GetStyle" cname="gtk_widget_get_style">
<method name="GetStyle" cname="gtk_widget_get_style" needs_ref="1">
<return-type type="GtkStyle*"/>
</method>
<method name="GetToplevel" cname="gtk_widget_get_toplevel">
@ -9488,7 +9488,7 @@
<method name="GetType" cname="gtk_widget_get_type" shared="true">
<return-type type="GtkType"/>
</method>
<method name="GetVisual" cname="gtk_widget_get_visual">
<method name="GetVisual" cname="gtk_widget_get_visual" needs_ref="1">
<return-type type="GdkVisual*"/>
</method>
<method name="GrabDefault" cname="gtk_widget_grab_default">
@ -9625,7 +9625,7 @@
<method name="Realize" cname="gtk_widget_realize">
<return-type type="void"/>
</method>
<method name="Ref" cname="gtk_widget_ref">
<method name="Ref" cname="gtk_widget_ref" hidden="1">
<return-type type="GtkWidget*"/>
</method>
<method name="RegionIntersect" cname="gtk_widget_region_intersect">
@ -9863,7 +9863,7 @@
<method name="Unrealize" cname="gtk_widget_unrealize">
<return-type type="void"/>
</method>
<method name="Unref" cname="gtk_widget_unref">
<method name="Unref" cname="gtk_widget_unref" hidden="1">
<return-type type="void"/>
</method>
</object>

View file

@ -25,6 +25,7 @@ namespace GtkSharp.Generation {
private string name, cname, safety;
private string protection = "public";
private bool is_get, is_set;
private bool needs_ref = false;
public Method (string libname, XmlElement elem, ClassBase container_type)
{
@ -40,6 +41,10 @@ namespace GtkSharp.Generation {
this.libname = elem.GetAttribute ("library");
else
this.libname = libname;
// caller does not own reference?
if (elem.HasAttribute ("needs_ref"))
this.needs_ref = (elem.GetAttribute ("needs_ref") == "1");
}
public bool IsGetter {
@ -387,6 +392,8 @@ namespace GtkSharp.Generation {
{
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";");
if (needs_ref)
sw.WriteLine(indent + "\t\t\tret.Ref ();");
if (SymbolTable.IsOpaque (rettype))
sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
}

View file

@ -152,8 +152,17 @@ namespace GtkSharp.Generation {
string wrapped = SymbolTable.GetCSType (c_type);
string wrapped_name = MangleName (field.GetAttribute ("cname"));
if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type)) {
// FIXME: cut n paste code, remove after introspection completed
if (SymbolTable.IsObject (c_type)) {
sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { ");
sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";");
sw.WriteLine ("\t\t\t\tret.Ref ();");
sw.WriteLine ("\t\t\t\treturn ret;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }");
sw.WriteLine ("\t\t}");
} else if (SymbolTable.IsOpaque (c_type)) {
sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { ");

View file

@ -64,6 +64,26 @@ namespace GLib {
g_object_unref (_obj);
}
[DllImport("gobject-2.0")]
static extern void g_object_ref (IntPtr raw);
/// <summary>
/// Ref Method
/// </summary>
///
/// <remarks>
/// Increases 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>
public virtual void Ref ()
{
if (_obj == IntPtr.Zero)
return;
g_object_ref (_obj);
}
/// <summary>
/// GetObject Shared Method
/// </summary>

View file

@ -12,24 +12,28 @@
GdkGC*
gtksharp_gtk_style_get_white_gc (GtkStyle *style)
{
g_object_ref (G_OBJECT (style->white_gc));
return style->white_gc;
}
GdkGC*
gtksharp_gtk_style_get_black_gc (GtkStyle *style)
{
g_object_ref (G_OBJECT (style->black_gc));
return style->black_gc;
}
GdkGC**
gtksharp_gtk_style_get_fg_gc (GtkStyle *style)
{
g_object_ref (G_OBJECT (style->fg_gc));
return style->fg_gc;
}
GdkGC**
gtksharp_gtk_style_get_bg_gc (GtkStyle *style)
{
g_object_ref (G_OBJECT (style->bg_gc));
return style->bg_gc;
}

View file

@ -12,6 +12,17 @@
protected override void DisposeNative ()
{
gtksharp_object_unref_if_floating (Handle);
if (_needs_unref)
base.DisposeNative ();
else
gtksharp_object_unref_if_floating (Handle);
}
private bool _needs_unref = false;
public override void Ref ()
{
_needs_unref = true;
base.Ref ();
}

View file

@ -1254,6 +1254,12 @@
<rule>
<class name="GtkWidget">
<method>Destroyed</method>
<method>Ref</method>
<method>Unref</method>
</class>
<class name="GtkRcStyle">
<method>Ref</method>
<method>Unref</method>
</class>
<data>
<attribute target="method">
@ -1834,4 +1840,26 @@
</data>
</rule>
<!-- reference rules -->
<rule>
<class name="GtkWidget">
<method>GetStyle</method>
<method>GetModifierStyle</method>
<method>GetDefaultStyle</method>
<method>GetParentWindow</method>
<method>GetColormap</method>
<method>GetVisual</method>
<method>GetDefaultColormap</method>
<method>GetDefaultVisual</method>
</class>
<data>
<attribute target="method">
<name>needs_ref</name>
<value>1</value>
</attribute>
</data>
</rule>
</metadata>