diff --git a/ChangeLog b/ChangeLog index af21312d4..7124ef03d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-06-02 Mike Kestner + + * generator/ConstFilenameGen.cs : new generatable for filename encoded + const string marshaling + * generator/Makefile.am : add new file + * generator/SymbolTable.cs : add new gfilename types. + * glib/Marshaller.cs : add new filename-encoded string marshalers. + * gtk/FileSelection.custom : use FilenamePtrToString to marshal. + * gtk/Gtk.metadata : map the FileSelector filename types to my new + imaginary gfilename type. [Fixes #74963] + 2005-06-02 Mike Kestner * gtk/Object.custom : only connect to Destroyed for managed subclasses diff --git a/generator/ConstFilenameGen.cs b/generator/ConstFilenameGen.cs new file mode 100644 index 000000000..4a56f3dfc --- /dev/null +++ b/generator/ConstFilenameGen.cs @@ -0,0 +1,52 @@ +// ConstFilenameGen.cs - The Const Filename type Generatable. +// +// Author: Mike Kestner +// +// Copyright (c) 2005 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the 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 +// General Public License for more details. +// +// You should have received a copy of the GNU 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. + + +namespace GtkSharp.Generation { + + using System; + + public class ConstFilenameGen : SimpleBase, IManualMarshaler { + + public ConstFilenameGen (string ctype) : base (ctype, "string") {} + + public override string MarshalType { + get { + return "IntPtr"; + } + } + + public override string FromNative (string var) + { + return "GLib.Marshaller.FilenamePtrToString (" + var + ")"; + } + + public string AllocNative (string managed_var) + { + return "GLib.Marshaller.StringToFilenamePtr (" + managed_var + ")"; + } + + public string ReleaseNative (string native_var) + { + return "GLib.Marshaller.Free (" + native_var + ")"; + } + } +} + diff --git a/generator/Makefile.am b/generator/Makefile.am index 8120e34c3..2714f9432 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -15,6 +15,7 @@ sources = \ ClassBase.cs \ ClassGen.cs \ CodeGenerator.cs \ + ConstFilenameGen.cs \ ConstStringGen.cs \ Ctor.cs \ EnumGen.cs \ diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 85d1bc815..94444f1c3 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -90,6 +90,8 @@ namespace GtkSharp.Generation { AddType (new ConstStringGen ("const-gchar")); AddType (new ConstStringGen ("const-xmlChar")); AddType (new ConstStringGen ("const-char")); + AddType (new ConstFilenameGen ("const-gfilename")); + AddType (new MarshalGen ("gfilename", "string", "IntPtr", "GLib.Marshaller.StringToFilenamePtr({0})", "GLib.Marshaller.FilenamePtrToStringGFree({0})")); AddType (new MarshalGen ("gchar", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})")); AddType (new MarshalGen ("char", "string", "IntPtr", "GLib.Marshaller.StringToPtrGStrdup({0})", "GLib.Marshaller.PtrToStringGFree({0})")); AddType (new SimpleGen ("GStrv", "string[]")); @@ -153,6 +155,19 @@ namespace GtkSharp.Generation { } } + private bool IsConstString (string type) + { + switch (type) { + case "const-gchar": + case "const-char": + case "const-xmlChar": + case "const-gfilename": + return true; + default: + return false; + } + } + private string Trim(string type) { // HACK: If we don't detect this here, there is no @@ -161,8 +176,8 @@ namespace GtkSharp.Generation { string trim_type = type.TrimEnd('*'); - // HACK: Similar to above, but for const strings - if (trim_type == "const-gchar" || trim_type == "const-char" || trim_type == "const-xmlChar") return trim_type; + if (IsConstString (trim_type)) + return trim_type; if (trim_type.StartsWith("const-")) return trim_type.Substring(6); return trim_type; diff --git a/glib/Marshaller.cs b/glib/Marshaller.cs index db8b80fc9..f45eb3aec 100644 --- a/glib/Marshaller.cs +++ b/glib/Marshaller.cs @@ -37,6 +37,25 @@ namespace GLib { g_free (ptr); } + [DllImport("libglib-2.0-0.dll")] + static extern IntPtr g_filename_to_utf8 (IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error); + + public static string FilenamePtrToString (IntPtr ptr) + { + IntPtr dummy, error; + IntPtr utf8 = g_filename_to_utf8 (ptr, -1, IntPtr.Zero, out dummy, out error); + if (error != IntPtr.Zero) + throw new GLib.GException (error); + return Utf8PtrToString (utf8); + } + + public static string FilenamePtrToStringGFree (IntPtr ptr) + { + string ret = FilenamePtrToString (ptr); + g_free (ptr); + return ret; + } + [DllImport("glibsharpglue-2")] static extern UIntPtr glibsharp_strlen (IntPtr mem); @@ -76,6 +95,24 @@ namespace GLib { return ret; } + [DllImport("libglib-2.0-0.dll")] + static extern IntPtr g_filename_from_utf8 (IntPtr mem, int len, IntPtr read, out IntPtr written, out IntPtr error); + + public static IntPtr StringToFilenamePtr (string str) + { + if (str == null) + return IntPtr.Zero; + + IntPtr dummy, error; + IntPtr utf8 = StringToPtrGStrdup (str); + IntPtr result = g_filename_from_utf8 (utf8, -1, IntPtr.Zero, out dummy, out error); + g_free (utf8); + if (error != IntPtr.Zero) + throw new GException (error); + + return result; + } + public static IntPtr StringToPtrGStrdup (string str) { if (str == null) return IntPtr.Zero; diff --git a/gtk/FileSelection.custom b/gtk/FileSelection.custom index dce3c3a55..603dc13d9 100644 --- a/gtk/FileSelection.custom +++ b/gtk/FileSelection.custom @@ -51,7 +51,7 @@ public string[] Selections { int i = 0; IntPtr strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); while (strptr != IntPtr.Zero) { - result.Add (GLib.Marshaller.Utf8PtrToString (strptr)); + result.Add (GLib.Marshaller.FilenamePtrToString (strptr)); strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); } diff --git a/gtk/Gtk.metadata b/gtk/Gtk.metadata index 7a35ba2f5..a81f24693 100644 --- a/gtk/Gtk.metadata +++ b/gtk/Gtk.metadata @@ -252,7 +252,10 @@ GtkButton* GtkEntry* GtkLabel* + const-gfilename* 1 + const-gfilename* + gfilename* GObject GtkButton* public