mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-25 08:05:36 +00:00
fe699e9fbb
* gconf/Value.cs: Update to use new string marshalling. * generator/StringGen.cs, ConstStringGen.cs: Added. * generator/IGeneratable.cs: Add new method ToNativeReturn. * generator/CallbackGen.cs: Implement ToNativeReturn. Call ToNativeReturn for the return statement. Fix a couple of places where s_ret was being used incorrectly for m_ret. * generator/ClassGen.cs, EnumGen.cs, ManualGen.cs, SimpleGen.cs, StructBase.cs: Implement ToNativeReturn. * generator/SignalHandler.cs: Call ToNativeReturn for the return statement, instead of CallByName. * generator/SymbolTable.cs: Use StringGen for gchar, char, and gunichar, and ConstStringGen for their const variants. Add a new method wrapper for ToNativeReturn. (Trim): Add a special-case for const strings so that the const is not stripped. Otherwise there is no way of resolving the const case. * glade/XML.custom: Update to use new string marshalling. * glib/Marshaller.cs: Added. * glib/GException.cs, Markup.cs, ObjectManager.cs, Value.cs: Update to use new string marshalling. * glib/Object.cs: Remove old g_type_name DllImport as it is no longer used. * glue/fileselection.c (gtksharp_file_selection_get_fileop_entry): Mark this as const return. * gtk/ColorSelection.custom, FileSelection.custom, SelectionData.custom: Update to use new string marshalling. svn path=/trunk/gtk-sharp/; revision=15286
115 lines
3 KiB
C#
115 lines
3 KiB
C#
// Generated File. Do not modify.
|
|
// <c> 2001-2002 Mike Kestner
|
|
|
|
namespace GtkSharp {
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
public class ObjectManager {
|
|
|
|
private static Hashtable types = new Hashtable ();
|
|
|
|
[DllImport("gtksharpglue")]
|
|
static extern IntPtr gtksharp_get_type_name (IntPtr raw);
|
|
|
|
public static GLib.Object CreateObject (IntPtr raw)
|
|
{
|
|
if (raw == IntPtr.Zero)
|
|
return null;
|
|
|
|
string typename = Marshal.PtrToStringAnsi (gtksharp_get_type_name (raw));
|
|
string mangled;
|
|
if (types.ContainsKey(typename))
|
|
mangled = (string)types[typename];
|
|
else
|
|
mangled = GetExpected (typename);
|
|
Type t = Type.GetType (mangled);
|
|
|
|
// if null, try to get a parent type
|
|
if (t == null)
|
|
t = GetValidParentType (raw);
|
|
|
|
if (t == null) {
|
|
// should never get reached since everything should end up at
|
|
// GObject. Perhaps throw an exception here instead?
|
|
Console.WriteLine ("*** Warning: No C# equivalent for class '" + typename +
|
|
"' found, returning null");
|
|
return null;
|
|
}
|
|
|
|
return (GLib.Object) Activator.CreateInstance (t, new object[] {raw});
|
|
}
|
|
|
|
public static void RegisterType (string native_name, string managed_name, string assembly)
|
|
{
|
|
types.Add(native_name, managed_name + "," + assembly);
|
|
}
|
|
|
|
public static void RegisterType (string native_name, string mangled)
|
|
{
|
|
types.Add(native_name, mangled);
|
|
}
|
|
|
|
static string GetExpected (string cname)
|
|
{
|
|
StringBuilder expected = new StringBuilder ();
|
|
string ns = "";
|
|
bool needs_dot = true;
|
|
for (int i = 0; i < cname.Length; i++)
|
|
{
|
|
if (needs_dot && i > 0 && Char.IsUpper (cname[i])) {
|
|
// check for initial "G" and mangle to "GLib" if so
|
|
// really only necessary for GObject
|
|
if (expected.Length == 1 && expected[0] == 'G') {
|
|
ns = "glib";
|
|
expected = new StringBuilder ("GLib.");
|
|
} else {
|
|
ns = expected.ToString ().ToLower ();
|
|
expected.Append ('.');
|
|
}
|
|
needs_dot = false;
|
|
}
|
|
expected.Append (cname[i]);
|
|
}
|
|
expected.AppendFormat (",{0}-sharp", ns);
|
|
|
|
string expected_string = expected.ToString ();
|
|
RegisterType (cname, expected_string);
|
|
return expected_string;
|
|
}
|
|
|
|
[DllImport("gtksharpglue")]
|
|
static extern int gtksharp_get_type_id (IntPtr raw);
|
|
|
|
[DllImport("gtksharpglue")]
|
|
static extern int gtksharp_get_parent_type (int typ);
|
|
|
|
[DllImport("gtksharpglue")]
|
|
static extern IntPtr gtksharp_get_type_name_for_id (int typ);
|
|
|
|
static Type GetValidParentType (IntPtr raw)
|
|
{
|
|
int type_id = gtksharp_get_type_id (raw);
|
|
string typename;
|
|
string mangled;
|
|
Type t;
|
|
// We will always end up at GObject and will break this loop
|
|
while (true) {
|
|
type_id = gtksharp_get_parent_type (type_id);
|
|
typename = Marshal.PtrToStringAnsi (gtksharp_get_type_name_for_id (type_id));
|
|
if (types.ContainsKey (typename))
|
|
mangled = (string)types[typename];
|
|
else
|
|
mangled = GetExpected (typename);
|
|
t = Type.GetType (mangled);
|
|
if (t != null) {
|
|
return t;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|