From 0cdee479e213552af793e118b5d8842b8c79cc09 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 28 Oct 2003 15:45:35 +0000 Subject: [PATCH] 2003-10-28 Mike Kestner * generator/BoxedGen.cs : generate GLib.Value ctors. [fixes #47168] * generator/Property.cs : use new Boxed value ctors. * generator/StructBase.cs : use existing Writer if available. svn path=/trunk/gtk-sharp/; revision=19433 --- ChangeLog | 6 ++++++ generator/BoxedGen.cs | 21 +++++++++++++++++++++ generator/Property.cs | 9 +++++---- generator/StructBase.cs | 11 ++++++++++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index d52ddc6ec..f55c802ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-10-28 Mike Kestner + + * generator/BoxedGen.cs : generate GLib.Value ctors. [fixes #47168] + * generator/Property.cs : use new Boxed value ctors. + * generator/StructBase.cs : use existing Writer if available. + 2003-10-27 Moritz Balz * gdk/Drawable.custom : add a S.D.Rectangle overload for DrawRect. diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index 3fd705549..045c1843b 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -22,7 +22,28 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { + StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); base.Generate (gen_info); + sw.WriteLine ("\t\t[DllImport(\"gtksharpglue\")]"); + sw.WriteLine ("\t\tstatic extern IntPtr gtksharp_value_create (uint gtype);"); + sw.WriteLine (); + sw.WriteLine ("\t\t[DllImport(\"libgobject-2.0-0.dll\")]"); + sw.WriteLine ("\t\tstatic extern void g_value_set_boxed (IntPtr handle, ref " + QualifiedName + " boxed);"); + sw.WriteLine (); + sw.WriteLine ("\t\tpublic static explicit operator GLib.Value (" + QualifiedName + " boxed)"); + sw.WriteLine ("\t\t{"); + + sw.WriteLine ("\t\t\tIntPtr handle = gtksharp_value_create (" + QualifiedName + ".GType);"); + sw.WriteLine ("\t\t\tg_value_set_boxed (handle, ref boxed);"); + sw.WriteLine ("\t\t\treturn new GLib.Value (handle, IntPtr.Zero);"); + sw.WriteLine ("\t\t}"); + + sw.WriteLine ("#endregion"); + AppendCustom(sw, gen_info.CustomDir); + sw.WriteLine ("\t}"); + sw.WriteLine ("}"); + sw.Close (); + gen_info.Writer = null; Statistics.BoxedCount++; } } diff --git a/generator/Property.cs b/generator/Property.cs index bb6666a04..f8e8a1e55 100644 --- a/generator/Property.cs +++ b/generator/Property.cs @@ -148,14 +148,15 @@ namespace GtkSharp.Generation { sw.WriteLine(); } else if (elem.HasAttribute("writeable") && !elem.HasAttribute("construct-only")) { sw.WriteLine("\t\t\tset {"); - sw.Write("\t\t\t\tSetProperty(" + cname + ", new GLib.Value("); + sw.Write("\t\t\t\tSetProperty(" + cname + ", "); if (table.IsEnum(c_type)) { - sw.WriteLine("Handle, " + cname + ", new GLib.EnumWrapper ((int) value, {0})));", table.IsEnumFlags (c_type) ? "true" : "false"); + sw.WriteLine("new GLib.Value(Handle, " + cname + ", new GLib.EnumWrapper ((int) value, {0})));", table.IsEnumFlags (c_type) ? "true" : "false"); } else if (table.IsBoxed (c_type)) { - sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));"); + sw.WriteLine("(GLib.Value) (value));"); } else if (table.IsOpaque (c_type)) { - sw.WriteLine("Handle, " + cname + ", value));"); + sw.WriteLine("new GLib.Value(Handle, " + cname + ", value));"); } else { + sw.Write("new GLib.Value("); if (v_type != "" && !(table.IsObject (c_type) || table.IsOpaque (c_type))) { sw.Write(v_type + " "); } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 398dd404e..691e56a03 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -208,7 +208,13 @@ namespace GtkSharp.Generation { public virtual void Generate (GenerationInfo gen_info) { - StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); + bool need_close = false; + if (gen_info.Writer == null) { + gen_info.Writer = gen_info.OpenStream (Name); + need_close = true; + } + + StreamWriter sw = gen_info.Writer; sw.WriteLine ("namespace " + NS + " {"); sw.WriteLine (); @@ -227,6 +233,9 @@ namespace GtkSharp.Generation { GenCtors (gen_info); GenMethods (gen_info, null, null); + if (!need_close) + return; + sw.WriteLine ("#endregion"); AppendCustom(sw, gen_info.CustomDir);