2005-06-02 Mike Kestner <mkestner@novell.com>
* 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] svn path=/trunk/gtk-sharp/; revision=45328
This commit is contained in:
parent
dfa84ee168
commit
fee353d525
7 changed files with 122 additions and 3 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2005-06-02 Mike Kestner <mkestner@novell.com>
|
||||
|
||||
* 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 <mkestner@novell.com>
|
||||
|
||||
* gtk/Object.custom : only connect to Destroyed for managed subclasses
|
||||
|
|
52
generator/ConstFilenameGen.cs
Normal file
52
generator/ConstFilenameGen.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
// ConstFilenameGen.cs - The Const Filename type Generatable.
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@novell.com>
|
||||
//
|
||||
// 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 + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ sources = \
|
|||
ClassBase.cs \
|
||||
ClassGen.cs \
|
||||
CodeGenerator.cs \
|
||||
ConstFilenameGen.cs \
|
||||
ConstStringGen.cs \
|
||||
Ctor.cs \
|
||||
EnumGen.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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++);
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,10 @@
|
|||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/field[@name='OkButton']" name="type">GtkButton*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/field[@name='SelectionEntry']" name="type">GtkEntry*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/field[@name='SelectionText']" name="type">GtkLabel*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/method[@name='GetFilename']/return-type" name="type">const-gfilename*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/method[@name='GetSelections']" name="hidden">1</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/method[@name='SetFilename']/*/*[@name='filename']" name="type">const-gfilename*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFileSelection']/property[@name='Filename']" name="type">gfilename*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFilePath']" name="parent">GObject</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFontSelectionDialog']/field[@name='ApplyButton']" name="type">GtkButton*</attr>
|
||||
<attr path="/api/namespace/object[@cname='GtkFontSelectionDialog']/field[@name='ApplyButton']" name="access">public</attr>
|
||||
|
|
Loading…
Reference in a new issue