2005-03-08 Mike Kestner <mkestner@novell.com>

* */*.cs : scrub for StringToPtrAnsi and string usage in DllImports.
	* */*.custom : begin the scrub here too.
	* generator/ConstStringGen.cs : implement IManualMarshaler and move to
	100% IntPtr marshaling.
	* generator/Ctor.cs : call Body.Finish too.
	* generator/IManualMarshaler.cs : new interface for generatables that
	marshal manually and need cleanup.
	* generator/Makefile.am : new file.
	* generator/MethodBody.cs : use IManualMarshaler if applicable.

svn path=/trunk/gtk-sharp/; revision=41579
This commit is contained in:
Mike Kestner 2005-03-08 21:28:08 +00:00
parent 24bbc054f2
commit 90a870e2de
44 changed files with 472 additions and 339 deletions

View file

@ -1,3 +1,15 @@
2005-03-08 Mike Kestner <mkestner@novell.com>
* */*.cs : scrub for StringToPtrAnsi and string usage in DllImports.
* */*.custom : begin the scrub here too.
* generator/ConstStringGen.cs : implement IManualMarshaler and move to
100% IntPtr marshaling.
* generator/Ctor.cs : call Body.Finish too.
* generator/IManualMarshaler.cs : new interface for generatables that
marshal manually and need cleanup.
* generator/Makefile.am : new file.
* generator/MethodBody.cs : use IManualMarshaler if applicable.
2005-03-07 Mike Kestner <mkestner@novell.com> 2005-03-07 Mike Kestner <mkestner@novell.com>
* generator/MethodBody.cs : remove an unused var. * generator/MethodBody.cs : remove an unused var.

View file

@ -217,5 +217,20 @@
<remarks>To be added</remarks> <remarks>To be added</remarks>
</Docs> </Docs>
</Member> </Member>
<Member MemberName="Free">
<MemberSignature Language="C#" Value="public static void Free (IntPtr ptr);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="ptr" Type="System.IntPtr" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="ptr">a <see cref="T:System.IntPtr" /></param>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members> </Members>
</Type> </Type>

View file

@ -48,40 +48,6 @@
<remarks>To be added</remarks> <remarks>To be added</remarks>
</Docs> </Docs>
</Member> </Member>
<Member MemberName="Init">
<MemberSignature Language="C#" Value="public static void Init (string [] args);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="args" Type="System.String[]" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="args">a <see cref="T:System.String[]" /></param>
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName="Init">
<MemberSignature Language="C#" Value="public static void Init (string app_id, string version, string [] args);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="app_id" Type="System.String" />
<Parameter Name="version" Type="System.String" />
<Parameter Name="args" Type="System.String[]" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="app_id">a <see cref="T:System.String" /></param>
<param name="version">a <see cref="T:System.String" /></param>
<param name="args">a <see cref="T:System.String[]" /></param>
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName="Run"> <Member MemberName="Run">
<MemberSignature Language="C#" Value="public static void Run ();" /> <MemberSignature Language="C#" Value="public static void Run ();" />
<MemberType>Method</MemberType> <MemberType>Method</MemberType>
@ -117,5 +83,39 @@
<remarks>To be added</remarks> <remarks>To be added</remarks>
</Docs> </Docs>
</Member> </Member>
<Member MemberName="Init">
<MemberSignature Language="C#" Value="public static void Init (ref string [] args);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="args" Type="System.String[]&amp;" RefType="ref" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="args">a <see cref="T:System.String[]" /></param>
<remarks>To be added</remarks>
</Docs>
</Member>
<Member MemberName="Init">
<MemberSignature Language="C#" Value="public static void Init (string app_id, string version, ref string [] args);" />
<MemberType>Method</MemberType>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="app_id" Type="System.String" />
<Parameter Name="version" Type="System.String" />
<Parameter Name="args" Type="System.String[]&amp;" RefType="ref" />
</Parameters>
<Docs>
<summary>To be added</summary>
<param name="app_id">a <see cref="T:System.String" /></param>
<param name="version">a <see cref="T:System.String" /></param>
<param name="args">a <see cref="T:System.String[]" /></param>
<remarks>To be added</remarks>
</Docs>
</Member>
</Members> </Members>
</Type> </Type>

View file

@ -165,7 +165,7 @@ namespace GConf
switch (val_type) switch (val_type)
{ {
case ValueType.String: case ValueType.String:
return Marshal.PtrToStringAnsi (gconf_value_get_string (Raw)); return GLib.Marshaller.Utf8PtrToString (gconf_value_get_string (Raw));
case ValueType.Int: case ValueType.Int:
return gconf_value_get_int (Raw); return gconf_value_get_int (Raw);
case ValueType.Float: case ValueType.Float:

View file

@ -23,42 +23,53 @@ using System.Runtime.InteropServices;
namespace Gda namespace Gda
{ {
/// <summary>
/// GDA Application class
/// </summary>
///
/// <remarks>
/// Provides the initialization and event loop iteration related
/// methods for the GDA data access library.
/// </remarks>
public class Application public class Application
{ {
private const string VERSION = "0.10"; private const string VERSION = "0.10";
[DllImport("gda-2")] [DllImport("gda-2")]
static extern void gda_init (string app_id, string version, int nargs, string[] args); static extern void gda_init (IntPtr app_id, IntPtr version, int nargs, IntPtr args);
[DllImport("gda-2")]
static extern void gda_init (IntPtr app_id, IntPtr version, ref int argc, ref IntPtr argv);
public static void Init () public static void Init ()
{ {
gda_init ("Gda#", VERSION, 0, new string[0]); Init ("Gda#", VERSION);
} }
public static void Init (string app_id, string version) public static void Init (string app_id, string version)
{ {
gda_init (app_id, version, 0, new string[0]); IntPtr native_appid = GLib.Marshaller.StringToPtrGStrdup (app_id);
IntPtr native_version = GLib.Marshaller.StringToPtrGStrdup (version);
gda_init (native_appid, native_version, 0, IntPtr.Zero);
GLib.Marshaller.Free (native_appid);
GLib.Marshaller.Free (native_version);
} }
public static void Init (string[] args) public static void Init (ref string[] args)
{ {
gda_init ("Gda#", VERSION, args.Length, args); Init ("Gda#", VERSION, ref args);
} }
public static void Init (string app_id, string version, string[] args) public static void Init (string app_id, string version, ref string[] args)
{ {
gda_init (app_id, version, args.Length, args); IntPtr native_appid = GLib.Marshaller.StringToPtrGStrdup (app_id);
IntPtr native_version = GLib.Marshaller.StringToPtrGStrdup (version);
GLib.Argv argv = new GLib.Argv (args);
IntPtr arg_ptr = argv.Handle;
int argc = args.Length;
gda_init (native_appid, native_version, ref argc, ref arg_ptr);
GLib.Marshaller.Free (native_appid);
GLib.Marshaller.Free (native_version);
if (arg_ptr != argv.Handle)
throw new Exception ("Init returned new argv handle.");
if (argc <= 1)
args = new string [0];
else
args = argv.GetArgs (argc);
} }
[DllImport("gda-2")] [DllImport("gda-2")]
static extern void gda_main_run (IntPtr init_func, IntPtr user_data); static extern void gda_main_run (IntPtr init_func, IntPtr user_data);

View file

@ -21,6 +21,9 @@
public static XmlConnection NewFromFile (string filename) public static XmlConnection NewFromFile (string filename)
{ {
return new XmlConnection (gda_xml_connection_new_from_file (filename)); IntPtr filename_as_native = GLib.Marshaller.StringToPtrGStrdup (filename);
XmlConnection ret = new XmlConnection (gda_xml_connection_new_from_file (filename_as_native));
GLib.Marshaller.Free (filename_as_native);
return ret;
} }

View file

@ -53,7 +53,7 @@
public string Name { public string Name {
get { get {
IntPtr rawName = gtksharp_gdk_device_get_name (Handle); IntPtr rawName = gtksharp_gdk_device_get_name (Handle);
return Marshal.PtrToStringAnsi(rawName); return GLib.Marshaller.Utf8PtrToString (rawName);
} }
} }

View file

@ -42,7 +42,7 @@ namespace Gdk {
public string Name { public string Name {
get { get {
return Marshal.PtrToStringAnsi (gtksharp_gdk_event_setting_get_name (Handle)); return GLib.Marshaller.Utf8PtrToString (gtksharp_gdk_event_setting_get_name (Handle));
} }
} }
} }

View file

@ -43,7 +43,7 @@ namespace Gdk {
string[] result = new string [count]; string[] result = new string [count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
IntPtr ptr = Marshal.ReadIntPtr (list_ptr, i * IntPtr.Size); IntPtr ptr = Marshal.ReadIntPtr (list_ptr, i * IntPtr.Size);
result [i] = Marshal.PtrToStringAnsi (ptr); result [i] = GLib.Marshaller.Utf8PtrToString (ptr);
} }
gdk_free_text_list (list_ptr); gdk_free_text_list (list_ptr);
return result; return result;
@ -63,7 +63,7 @@ namespace Gdk {
string[] result = new string [count]; string[] result = new string [count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
IntPtr ptr = Marshal.ReadIntPtr (list_ptr, i * IntPtr.Size); IntPtr ptr = Marshal.ReadIntPtr (list_ptr, i * IntPtr.Size);
result [i] = Marshal.PtrToStringAnsi (ptr); result [i] = GLib.Marshaller.Utf8PtrToString (ptr);
} }
gdk_free_text_list (list_ptr); gdk_free_text_list (list_ptr);
return result; return result;

View file

@ -1,8 +1,10 @@
// GtkSharp.Generation.ConstStringGen.cs - The Const String type Generatable. // GtkSharp.Generation.ConstStringGen.cs - The Const String type Generatable.
// //
// Author: Rachel Hestilow <rachel@nullenvoid.com> // Author: Rachel Hestilow <rachel@nullenvoid.com>
// Mike Kestner <mkestner@novell.com>
// //
// Copyright (c) 2003 Rachel Hestilow // Copyright (c) 2003 Rachel Hestilow
// Copyright (c) 2005 Novell, Inc.
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public // modify it under the terms of version 2 of the GNU General Public
@ -23,22 +25,29 @@ namespace GtkSharp.Generation {
using System; using System;
public class ConstStringGen : SimpleBase { public class ConstStringGen : SimpleBase, IManualMarshaler {
public ConstStringGen (string ctype) : base (ctype, "string") public ConstStringGen (string ctype) : base (ctype, "string") {}
{
}
public override string MarshalReturnType { public override string MarshalType {
get get {
{
return "IntPtr"; return "IntPtr";
} }
} }
public override string FromNativeReturn(string var) public override string FromNative (string var)
{ {
return "Marshal.PtrToStringAnsi(" + var + ")"; return "GLib.Marshaller.Utf8PtrToString (" + var + ")";
}
public string AllocNative (string managed_var)
{
return "GLib.Marshaller.StringToPtrGStrdup (" + managed_var + ")";
}
public string ReleaseNative (string native_var)
{
return "GLib.Marshaller.Free (" + native_var + ")";
} }
} }
} }

View file

@ -151,6 +151,7 @@ namespace GtkSharp.Generation {
Body.Initialize(gen_info, false, false, ""); Body.Initialize(gen_info, false, false, "");
sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, CName, Body.GetCallString (false)); sw.WriteLine("\t\t\t{0} = {1}({2});", container_type.AssignToName, CName, Body.GetCallString (false));
Body.Finish (sw, "");
Body.HandleException (sw, ""); Body.HandleException (sw, "");
} }

View file

@ -0,0 +1,32 @@
// GtkSharp.Generation.IManualMarshaler.cs - Interface for manual marshaling.
//
// 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 {
public interface IManualMarshaler {
string AllocNative (string managed_var);
string ReleaseNative (string native_var);
}
}

View file

@ -22,6 +22,7 @@ sources = \
GenBase.cs \ GenBase.cs \
GenerationInfo.cs \ GenerationInfo.cs \
IGeneratable.cs \ IGeneratable.cs \
IManualMarshaler.cs \
ImportSignature.cs \ ImportSignature.cs \
InterfaceGen.cs \ InterfaceGen.cs \
LPGen.cs \ LPGen.cs \

View file

@ -77,7 +77,7 @@ namespace GtkSharp.Generation {
result[i] = igen.CallByName (CastFromInt (p.CSType) + parameters [i - 1].Name + ".Length"); result[i] = igen.CallByName (CastFromInt (p.CSType) + parameters [i - 1].Name + ".Length");
continue; continue;
} else if (p.IsArray && p.MarshalType != p.CSType) { } else if (p.IsArray && p.MarshalType != p.CSType) {
result[i] = (is_set && i == 0 ? "native_value" : "native_" + p.Name); result[i] = "native_" + p.Name;
continue; continue;
} }
@ -90,7 +90,8 @@ namespace GtkSharp.Generation {
if (p.CSType != p.MarshalType && !(igen is StructBase || igen is ByRefGen)) if (p.CSType != p.MarshalType && !(igen is StructBase || igen is ByRefGen))
call_parm = p.Name + "_as_native"; call_parm = p.Name + "_as_native";
} } else if (igen is IManualMarshaler)
call_parm = p.Name + "_as_native";
if (p.CType == "GError**") { if (p.CType == "GError**") {
call_parm = call_parm.Replace (p.Name, "error"); call_parm = call_parm.Replace (p.Name, "error");
@ -124,12 +125,16 @@ namespace GtkSharp.Generation {
if ((is_get || p.PassAs == "out") && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen)) if ((is_get || p.PassAs == "out") && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen))
sw.WriteLine(indent + "\t\t\t" + gen.MarshalType + " " + name + "_as_native;"); sw.WriteLine(indent + "\t\t\t" + gen.MarshalType + " " + name + "_as_native;");
else if (p.IsArray && p.MarshalType != p.CSType) {
if (p.IsArray && p.MarshalType != p.CSType) { sw.WriteLine(indent + "\t\t\t{0}[] native_" + p.Name + " = new {0} [{1}.Length];", p.MarshalType.TrimEnd('[', ']'), name);
sw.WriteLine(indent + "\t\t\t{0}[] native_{1} = new {0} [{1}.Length];", p.MarshalType.TrimEnd('[', ']'), name);
sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < {0}.Length; i++)", name); sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < {0}.Length; i++)", name);
sw.WriteLine(indent + "\t\t\t\tnative_{0} [i] = {1};", name, p.CallByName (name + "[i]")); if (gen is IManualMarshaler)
} sw.WriteLine(indent + "\t\t\t\tnative_{0} [i] = {1};", p.Name, (gen as IManualMarshaler).AllocNative (name + "[i]"));
else
sw.WriteLine(indent + "\t\t\t\tnative_{0} [i] = {1};", p.Name, p.CallByName (name + "[i]"));
} else if (gen is IManualMarshaler)
sw.WriteLine(indent + "\t\t\t" + gen.MarshalType + " " + p.Name + "_as_native = " + (gen as IManualMarshaler).AllocNative (name) + ";");
if (gen is CallbackGen) { if (gen is CallbackGen) {
CallbackGen cbgen = gen as CallbackGen; CallbackGen cbgen = gen as CallbackGen;
@ -160,6 +165,11 @@ namespace GtkSharp.Generation {
if (p.PassAs == "out" && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen)) if (p.PassAs == "out" && p.CSType != p.MarshalType && !(gen is StructBase || gen is ByRefGen))
sw.WriteLine(indent + "\t\t\t" + p.Name + " = " + gen.FromNative (p.Name + "_as_native") + ";"); sw.WriteLine(indent + "\t\t\t" + p.Name + " = " + gen.FromNative (p.Name + "_as_native") + ";");
else if (p.IsArray && gen is IManualMarshaler) {
sw.WriteLine(indent + "\t\t\tfor (int i = 0; i < native_" + p.Name + ".Length; i++)");
sw.WriteLine(indent + "\t\t\t\t" + (gen as IManualMarshaler).ReleaseNative ("native_" + p.Name + "[i]") + ";");
} else if (gen is IManualMarshaler)
sw.WriteLine(indent + "\t\t\t" + (gen as IManualMarshaler).ReleaseNative (p.Name + "_as_native") + ";");
} }
} }

View file

@ -50,7 +50,7 @@
} }
else else
{ {
ret = Marshal.PtrToStringAnsi (ptr); ret = GLib.Marshaller.Utf8PtrToString (ptr);
} }
return ret; return ret;
} }
@ -71,7 +71,7 @@
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
ret = ""; ret = "";
else else
ret = Marshal.PtrToStringAnsi (ptr); ret = GLib.Marshaller.Utf8PtrToString (ptr);
return ret; return ret;
} }

View file

@ -30,9 +30,6 @@ namespace GLib {
IntPtr handle; IntPtr handle;
bool add_progname = false; bool add_progname = false;
[DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_strdup (string str);
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_malloc(IntPtr size); static extern IntPtr g_malloc(IntPtr size);
@ -62,7 +59,7 @@ namespace GLib {
arg_ptrs = new IntPtr [args.Length]; arg_ptrs = new IntPtr [args.Length];
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
arg_ptrs [i] = g_strdup (args[i]); arg_ptrs [i] = Marshaller.StringToPtrGStrdup (args[i]);
handle = g_malloc (new IntPtr (IntPtr.Size * args.Length)); handle = g_malloc (new IntPtr (IntPtr.Size * args.Length));
@ -83,7 +80,7 @@ namespace GLib {
string[] result = new string [count]; string[] result = new string [count];
for (int i = 0; i < count; i++, idx++) for (int i = 0; i < count; i++, idx++)
result [i] = Marshal.PtrToStringAnsi (Marshal.ReadIntPtr (handle, idx * IntPtr.Size)); result [i] = Marshaller.Utf8PtrToString (Marshal.ReadIntPtr (handle, idx * IntPtr.Size));
return result; return result;
} }

View file

@ -71,7 +71,7 @@ namespace GLib {
private delegate void DestroyNotify (IntPtr data); private delegate void DestroyNotify (IntPtr data);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
private static extern void g_object_set_data (IntPtr obj, string name, IntPtr data, DestroyNotify destroy); private static extern void g_object_set_data (IntPtr obj, IntPtr name, IntPtr data, DestroyNotify destroy);
private void AddDestroyNotify (GLib.Object o) { private void AddDestroyNotify (GLib.Object o) {
// This is a bit of an ugly hack. There is no // This is a bit of an ugly hack. There is no
@ -79,10 +79,11 @@ namespace GLib {
// explicitly, so we set some data and ask // explicitly, so we set some data and ask
// for notification when it is removed // for notification when it is removed
string name = String.Format ("_GtkSharpDelegateWrapper_{0}", notify_count); IntPtr name = Marshaller.StringToPtrGStrdup (String.Format ("_GtkSharpDelegateWrapper_{0}", notify_count));
DestroyNotify destroy = new DestroyNotify (this.OnDestroy); DestroyNotify destroy = new DestroyNotify (this.OnDestroy);
g_object_set_data (o.Handle, name, IntPtr.Zero, destroy); g_object_set_data (o.Handle, name, IntPtr.Zero, destroy);
Marshaller.Free (name);
lock (typeof (DelegateWrapper)) { lock (typeof (DelegateWrapper)) {
instances[this] = destroy; instances[this] = destroy;
notify_count++; notify_count++;

View file

@ -28,17 +28,19 @@ namespace GLib {
public class FileUtils public class FileUtils
{ {
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
extern static bool g_file_get_contents (string filename, out IntPtr contents, out int length, out IntPtr error); extern static bool g_file_get_contents (IntPtr filename, out IntPtr contents, out int length, out IntPtr error);
public static string GetFileContents (string filename) public static string GetFileContents (string filename)
{ {
int length; int length;
IntPtr contents, error; IntPtr contents, error;
IntPtr native_filename = Marshaller.StringToPtrGStrdup (filename);
if (!g_file_get_contents (filename, out contents, out length, out error)) if (!g_file_get_contents (native_filename, out contents, out length, out error))
throw new GException (error); throw new GException (error);
return Marshal.PtrToStringAnsi (contents, length); Marshaller.Free (native_filename);
return Marshaller.Utf8PtrToString (contents);
} }
private FileUtils () {} private FileUtils () {}

View file

@ -37,7 +37,7 @@ namespace GLib {
static extern IntPtr gtksharp_error_get_message (IntPtr errptr); static extern IntPtr gtksharp_error_get_message (IntPtr errptr);
public override string Message { public override string Message {
get { get {
return Marshal.PtrToStringAnsi (gtksharp_error_get_message (errptr)); return Marshaller.Utf8PtrToString (gtksharp_error_get_message (errptr));
} }
} }

View file

@ -36,11 +36,13 @@ namespace GLib {
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_string_new (string text); static extern IntPtr g_string_new (IntPtr text);
public GString (string text) public GString (string text)
{ {
handle = g_string_new (text); IntPtr native_text = Marshaller.StringToPtrGStrdup (text);
handle = g_string_new (native_text);
Marshaller.Free (native_text);
} }
public IntPtr Handle { public IntPtr Handle {
@ -51,7 +53,7 @@ namespace GLib {
public static string PtrToString (IntPtr ptr) public static string PtrToString (IntPtr ptr)
{ {
return Marshal.PtrToStringAnsi (ptr); return Marshaller.Utf8PtrToString (ptr);
} }
} }
} }

View file

@ -89,7 +89,7 @@ namespace GLib {
public void Append (string item) public void Append (string item)
{ {
this.Append (Marshal.StringToHGlobalAnsi (item)); this.Append (Marshaller.StringToPtrGStrdup (item));
} }
public void Prepend (IntPtr raw) public void Prepend (IntPtr raw)
@ -139,7 +139,7 @@ namespace GLib {
object ret = null; object ret = null;
if (element_type != null) { if (element_type != null) {
if (element_type == typeof (string)) if (element_type == typeof (string))
ret = Marshal.PtrToStringAnsi (data); ret = Marshaller.Utf8PtrToString (data);
else if (element_type == typeof (int)) else if (element_type == typeof (int))
ret = (int) data; ret = (int) data;
else if (element_type.IsValueType) else if (element_type.IsValueType)

View file

@ -28,9 +28,7 @@ namespace GLib {
using System.Collections; using System.Collections;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public delegate void LogFunc (string log_domain, public delegate void LogFunc (string log_domain, LogLevelFlags log_level, string message);
LogLevelFlags log_level,
string message);
public delegate void PrintFunc (string message); public delegate void PrintFunc (string message);
@ -69,25 +67,25 @@ namespace GLib {
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern void g_logv (string log_domain, LogLevelFlags flags, string message); static extern void g_logv (IntPtr log_domain, LogLevelFlags flags, IntPtr message);
public void WriteLog (string logDomain, LogLevelFlags flags, string format, params object [] args) public void WriteLog (string logDomain, LogLevelFlags flags, string format, params object [] args)
{ {
g_logv (logDomain, flags, String.Format (format, args)); IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain);
IntPtr nmessage = Marshaller.StringToPtrGStrdup (String.Format (format, args));
g_logv (ndom, flags, nmessage);
Marshaller.Free (ndom);
Marshaller.Free (nmessage);
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern uint g_log_set_handler (string log_domain, static extern uint g_log_set_handler (IntPtr log_domain, LogLevelFlags flags, LogFunc log_func, IntPtr user_data);
LogLevelFlags flags,
LogFunc log_func,
IntPtr user_data);
public static uint SetLogHandler (string logDomain, public static uint SetLogHandler (string logDomain, LogLevelFlags flags, LogFunc logFunc)
LogLevelFlags flags,
LogFunc logFunc)
{ {
uint result = g_log_set_handler (logDomain, flags, logFunc, IntPtr.Zero); IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain);
uint result = g_log_set_handler (ndom, flags, logFunc, IntPtr.Zero);
Marshaller.Free (ndom);
EnsureHash (); EnsureHash ();
handlers [result] = logFunc; handlers [result] = logFunc;
@ -95,14 +93,16 @@ namespace GLib {
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern uint g_log_remove_handler (string log_domain, uint handler_id); static extern uint g_log_remove_handler (IntPtr log_domain, uint handler_id);
public static void RemoveLogHandler (string logDomain, uint handlerID) public static void RemoveLogHandler (string logDomain, uint handlerID)
{ {
if (handlers != null && handlers.ContainsKey (handlerID)) if (handlers != null && handlers.ContainsKey (handlerID))
handlers.Remove (handlerID); handlers.Remove (handlerID);
g_log_remove_handler (logDomain, handlerID); IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain);
g_log_remove_handler (ndom, handlerID);
Marshaller.Free (ndom);
} }
@ -129,17 +129,16 @@ namespace GLib {
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern void g_log_default_handler (string log_domain, static extern void g_log_default_handler (IntPtr log_domain, LogLevelFlags log_level, IntPtr message, IntPtr unused_data);
LogLevelFlags log_level,
string message,
IntPtr unused_data);
public static void DefaultHandler (string logDomain, public static void DefaultHandler (string logDomain, LogLevelFlags logLevel, string message)
LogLevelFlags logLevel,
string message)
{ {
g_log_default_handler (logDomain, logLevel, message, IntPtr.Zero); IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain);
IntPtr nmess = Marshaller.StringToPtrGStrdup (message);
g_log_default_handler (ndom, logLevel, nmess, IntPtr.Zero);
Marshaller.Free (ndom);
Marshaller.Free (nmess);
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
@ -151,11 +150,14 @@ namespace GLib {
} }
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
extern static LogLevelFlags g_log_set_fatal_mask (string log_domain, LogLevelFlags fatal_mask); extern static LogLevelFlags g_log_set_fatal_mask (IntPtr log_domain, LogLevelFlags fatal_mask);
public static LogLevelFlags SetAlwaysFatal (string logDomain, LogLevelFlags fatalMask) public static LogLevelFlags SetAlwaysFatal (string logDomain, LogLevelFlags fatalMask)
{ {
return g_log_set_fatal_mask (logDomain, fatalMask); IntPtr ndom = Marshaller.StringToPtrGStrdup (logDomain);
LogLevelFlags result = g_log_set_fatal_mask (ndom, fatalMask);
Marshaller.Free (ndom);
return result;
} }
/* /*

View file

@ -48,7 +48,7 @@ namespace GLib {
private static GType boxed_type = GType.Invalid; private static GType boxed_type = GType.Invalid;
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
private static extern IntPtr g_boxed_type_register_static (string typename, CopyFunc copy_func, FreeFunc free_func); private static extern IntPtr g_boxed_type_register_static (IntPtr typename, CopyFunc copy_func, FreeFunc free_func);
public static GType GType { public static GType GType {
get { get {
@ -56,7 +56,9 @@ namespace GLib {
copy = new CopyFunc (Copy); copy = new CopyFunc (Copy);
free = new FreeFunc (Free); free = new FreeFunc (Free);
boxed_type = new GLib.GType (g_boxed_type_register_static ("GtkSharpValue", copy, free)); IntPtr name = Marshaller.StringToPtrGStrdup ("GtkSharpValue");
boxed_type = new GLib.GType (g_boxed_type_register_static (name, copy, free));
Marshaller.Free (name);
} }
return boxed_type; return boxed_type;

View file

@ -30,14 +30,17 @@ namespace GLib {
private Markup () {} private Markup () {}
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_markup_escape_text (string text, int len); static extern IntPtr g_markup_escape_text (IntPtr text, int len);
static public string EscapeText (string s) static public string EscapeText (string s)
{ {
if (s == null) if (s == null)
return ""; return String.Empty;
return Marshaller.PtrToStringGFree (g_markup_escape_text (s, -1)); IntPtr native = Marshaller.StringToPtrGStrdup (s);
string result = Marshaller.PtrToStringGFree (g_markup_escape_text (native, -1));
Marshaller.Free (native);
return result;
} }
} }
} }

View file

@ -32,6 +32,11 @@ namespace GLib {
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern void g_free (IntPtr mem); static extern void g_free (IntPtr mem);
public static void Free (IntPtr ptr)
{
g_free (ptr);
}
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_utf8_strlen (IntPtr mem, int size); static extern IntPtr g_utf8_strlen (IntPtr mem, int size);
@ -63,12 +68,14 @@ namespace GLib {
return ret; return ret;
} }
[DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_strdup (byte[] bytes);
public static IntPtr StringToPtrGStrdup (string str) { public static IntPtr StringToPtrGStrdup (string str) {
if (str == null)
return IntPtr.Zero;
byte[] bytes = System.Text.Encoding.UTF8.GetBytes (str); byte[] bytes = System.Text.Encoding.UTF8.GetBytes (str);
return g_strdup (bytes); IntPtr result = g_malloc (new UIntPtr ((ulong)bytes.Length + 1));
Marshal.Copy (bytes, 0, result, bytes.Length);
Marshal.WriteByte (result, bytes.Length, 0);
return result;
} }
public static string StringFormat (string format, params object[] args) { public static string StringFormat (string format, params object[] args) {
@ -89,7 +96,7 @@ namespace GLib {
// [native pointer size] * [count] bytes. // [native pointer size] * [count] bytes.
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_malloc(ulong size); static extern IntPtr g_malloc(UIntPtr size);
static bool check_sixtyfour () { static bool check_sixtyfour () {
int szint = Marshal.SizeOf (typeof (int)); int szint = Marshal.SizeOf (typeof (int));
@ -111,8 +118,8 @@ namespace GLib {
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
ptrs[i] = (int) Marshal.StringToHGlobalAuto (args[i]); ptrs[i] = (int) Marshal.StringToHGlobalAuto (args[i]);
IntPtr buf = g_malloc ((ulong) Marshal.SizeOf(typeof(int)) * IntPtr buf = g_malloc (new UIntPtr ((ulong) Marshal.SizeOf(typeof(int)) *
(ulong) args.Length); (ulong) args.Length));
Marshal.Copy (ptrs, 0, buf, ptrs.Length); Marshal.Copy (ptrs, 0, buf, ptrs.Length);
return buf; return buf;
} }
@ -124,8 +131,8 @@ namespace GLib {
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
ptrs[i] = (long) Marshal.StringToHGlobalAuto (args[i]); ptrs[i] = (long) Marshal.StringToHGlobalAuto (args[i]);
IntPtr buf = g_malloc ((ulong) Marshal.SizeOf(typeof(long)) * IntPtr buf = g_malloc (new UIntPtr ((ulong) Marshal.SizeOf(typeof(long)) *
(ulong) args.Length); (ulong) args.Length));
Marshal.Copy (ptrs, 0, buf, ptrs.Length); Marshal.Copy (ptrs, 0, buf, ptrs.Length);
return buf; return buf;
} }

View file

@ -28,7 +28,7 @@ namespace GLib {
public string Property { public string Property {
get { get {
IntPtr raw_ret = g_param_spec_get_name ((IntPtr) Args[0]); IntPtr raw_ret = g_param_spec_get_name ((IntPtr) Args[0]);
return Marshal.PtrToStringAnsi (raw_ret); return Marshaller.Utf8PtrToString (raw_ret);
} }
} }
} }

View file

@ -147,14 +147,16 @@ namespace GLib {
} }
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_register_type (string name, IntPtr parent_type); static extern IntPtr gtksharp_register_type (IntPtr name, IntPtr parent_type);
protected static GType RegisterGType (System.Type t) protected static GType RegisterGType (System.Type t)
{ {
GType parent_gtype = LookupGType (t.BaseType); GType parent_gtype = LookupGType (t.BaseType);
string name = t.FullName.Replace(".", "_"); string name = t.FullName.Replace(".", "_");
GLib.ObjectManager.RegisterType (name, t.FullName, t.Assembly.GetName().Name); GLib.ObjectManager.RegisterType (name, t.FullName, t.Assembly.GetName().Name);
GType gtype = new GType (gtksharp_register_type (name, parent_gtype.Val)); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
GType gtype = new GType (gtksharp_register_type (native_name, parent_gtype.Val));
GLib.Marshaller.Free (native_name);
ConnectDefaultHandlers (gtype, t); ConnectDefaultHandlers (gtype, t);
InvokeClassInitializers (gtype, t); InvokeClassInitializers (gtype, t);
g_types[t] = gtype; g_types[t] = gtype;
@ -196,11 +198,16 @@ namespace GLib {
} }
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_object_newv (IntPtr gtype, int n_params, string[] names, GLib.Value[] vals); static extern IntPtr gtksharp_object_newv (IntPtr gtype, int n_params, IntPtr[] names, GLib.Value[] vals);
protected virtual void CreateNativeObject (string[] names, GLib.Value[] vals) protected virtual void CreateNativeObject (string[] names, GLib.Value[] vals)
{ {
Raw = gtksharp_object_newv (LookupGType ().Val, names.Length, names, vals); IntPtr[] native_names = new IntPtr [names.Length];
for (int i = 0; i < names.Length; i++)
native_names [i] = GLib.Marshaller.StringToPtrGStrdup (names [i]);
Raw = gtksharp_object_newv (LookupGType ().Val, names.Length, native_names, vals);
foreach (IntPtr p in native_names)
GLib.Marshaller.Free (p);
} }
protected virtual IntPtr Raw { protected virtual IntPtr Raw {
@ -231,7 +238,7 @@ namespace GLib {
protected string TypeName { protected string TypeName {
get { get {
return Marshal.PtrToStringAnsi (gtksharp_get_type_name (Raw)); return Marshaller.Utf8PtrToString (gtksharp_get_type_name (Raw));
} }
} }
@ -351,29 +358,35 @@ namespace GLib {
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_object_get_property (IntPtr obj, string name, ref GLib.Value val); static extern void g_object_get_property (IntPtr obj, IntPtr name, ref GLib.Value val);
protected GLib.Value GetProperty (string name) protected GLib.Value GetProperty (string name)
{ {
Value val = new Value (this, name); Value val = new Value (this, name);
g_object_get_property (Raw, name, ref val); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
g_object_get_property (Raw, native_name, ref val);
GLib.Marshaller.Free (native_name);
return val; return val;
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_object_set_property (IntPtr obj, string name, ref GLib.Value val); static extern void g_object_set_property (IntPtr obj, IntPtr name, ref GLib.Value val);
protected void SetProperty (string name, GLib.Value val) protected void SetProperty (string name, GLib.Value val)
{ {
g_object_set_property (Raw, name, ref val); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
g_object_set_property (Raw, native_name, ref val);
GLib.Marshaller.Free (native_name);
} }
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern void gtksharp_override_virtual_method (IntPtr gtype, string name, Delegate cb); static extern void gtksharp_override_virtual_method (IntPtr gtype, IntPtr name, Delegate cb);
protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb) protected static void OverrideVirtualMethod (GType gtype, string name, Delegate cb)
{ {
gtksharp_override_virtual_method (gtype.Val, name, cb); IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
gtksharp_override_virtual_method (gtype.Val, native_name, cb);
GLib.Marshaller.Free (native_name);
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]

View file

@ -40,7 +40,7 @@ namespace GLib {
if (raw == IntPtr.Zero) if (raw == IntPtr.Zero)
return null; return null;
string typename = Marshal.PtrToStringAnsi (gtksharp_get_type_name (raw)); string typename = Marshaller.Utf8PtrToString (gtksharp_get_type_name (raw));
string mangled; string mangled;
if (types.ContainsKey(typename)) if (types.ContainsKey(typename))
mangled = (string)types[typename]; mangled = (string)types[typename];
@ -141,7 +141,7 @@ namespace GLib {
type_id = gtksharp_get_parent_type (type_id); type_id = gtksharp_get_parent_type (type_id);
if (type_id == 0) if (type_id == 0)
return null; return null;
typename = Marshal.PtrToStringAnsi (gtksharp_get_type_name_for_id (type_id)); typename = Marshaller.Utf8PtrToString (gtksharp_get_type_name_for_id (type_id));
if (types.ContainsKey (typename)) if (types.ContainsKey (typename))
mangled = (string)types[typename]; mangled = (string)types[typename];
else else

View file

@ -68,7 +68,9 @@ namespace GLib {
name = signal_name; name = signal_name;
this.marshaler = marshaler; this.marshaler = marshaler;
gc_handle = GCHandle.Alloc (this); gc_handle = GCHandle.Alloc (this);
g_object_set_data_full (handle, name + "_signal_marshaler", (IntPtr) gc_handle, notify); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (name + "_signal_marshaler");
g_object_set_data_full (handle, native_key, (IntPtr) gc_handle, notify);
GLib.Marshaller.Free (native_key);
} }
public static Signal Lookup (GLib.Object obj, string name) public static Signal Lookup (GLib.Object obj, string name)
@ -78,7 +80,9 @@ namespace GLib {
public static Signal Lookup (GLib.Object obj, string name, Delegate marshaler) public static Signal Lookup (GLib.Object obj, string name, Delegate marshaler)
{ {
IntPtr data = g_object_get_data (obj.Handle, name + "_signal_marshaler"); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (name + "_signal_marshaler");
IntPtr data = g_object_get_data (obj.Handle, native_key);
GLib.Marshaller.Free (native_key);
if (data == IntPtr.Zero) if (data == IntPtr.Zero)
return new Signal (obj, name, marshaler); return new Signal (obj, name, marshaler);
@ -99,18 +103,26 @@ namespace GLib {
} }
} }
uint Connect (int flags)
{
IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
uint id = g_signal_connect_data (handle, native_name, marshaler, (IntPtr) gc_handle, IntPtr.Zero, flags);
GLib.Marshaller.Free (native_name);
return id;
}
public void AddDelegate (Delegate d) public void AddDelegate (Delegate d)
{ {
if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) { if (d.Method.IsDefined (typeof (ConnectBeforeAttribute), false)) {
if (before_handler == null) { if (before_handler == null) {
before_handler = d; before_handler = d;
before_id = g_signal_connect_data (handle, name, marshaler, (IntPtr) gc_handle, IntPtr.Zero, 0); before_id = Connect (0);
} else } else
before_handler = Delegate.Combine (before_handler, d); before_handler = Delegate.Combine (before_handler, d);
} else { } else {
if (after_handler == null) { if (after_handler == null) {
after_handler = d; after_handler = d;
after_id = g_signal_connect_data (handle, name, marshaler, (IntPtr) gc_handle, IntPtr.Zero, 1); after_id = Connect (1);
} else } else
after_handler = Delegate.Combine (after_handler, d); after_handler = Delegate.Combine (after_handler, d);
} }
@ -138,7 +150,9 @@ namespace GLib {
void DisconnectObject () void DisconnectObject ()
{ {
g_object_set_data (handle, name + "_signal_marshaler", IntPtr.Zero); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (name + "_signal_marshaler");
g_object_set_data (handle, native_key, IntPtr.Zero);
GLib.Marshaller.Free (native_key);
} }
void DisconnectHandler (uint handler_id) void DisconnectHandler (uint handler_id)
@ -169,16 +183,16 @@ namespace GLib {
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_object_get_data (IntPtr instance, string key); static extern IntPtr g_object_get_data (IntPtr instance, IntPtr key);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_object_set_data (IntPtr instance, string key, IntPtr data); static extern void g_object_set_data (IntPtr instance, IntPtr key, IntPtr data);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_object_set_data_full (IntPtr instance, string key, IntPtr data, DestroyNotify notify); static extern void g_object_set_data_full (IntPtr instance, IntPtr key, IntPtr data, DestroyNotify notify);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern uint g_signal_connect_data(IntPtr obj, string name, Delegate cb, IntPtr gc_handle, IntPtr dummy, int flags); static extern uint g_signal_connect_data(IntPtr obj, IntPtr name, Delegate cb, IntPtr gc_handle, IntPtr dummy, int flags);
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_signal_get_invocation_hint (IntPtr instance); static extern IntPtr g_signal_get_invocation_hint (IntPtr instance);

View file

@ -61,11 +61,13 @@ namespace GLib {
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern uint g_signal_connect_data(IntPtr obj, string name, Delegate cb, int key, IntPtr p, int flags); static extern uint g_signal_connect_data(IntPtr obj, IntPtr name, Delegate cb, int key, IntPtr p, int flags);
protected void Connect (string name, Delegate cb, int flags) protected void Connect (string name, Delegate cb, int flags)
{ {
_HandlerID = g_signal_connect_data(_obj.Handle, name, cb, _key, new IntPtr(0), flags); IntPtr native_name = Marshaller.StringToPtrGStrdup (name);
_HandlerID = g_signal_connect_data(_obj.Handle, native_name, cb, _key, new IntPtr(0), flags);
Marshaller.Free (native_name);
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]

View file

@ -42,13 +42,13 @@ namespace GLib {
static extern void g_value_unset (ref GLib.Value val); static extern void g_value_unset (ref GLib.Value val);
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_value_create_from_property(ref GLib.Value val, IntPtr obj, string name); static extern IntPtr gtksharp_value_create_from_property(ref GLib.Value val, IntPtr obj, IntPtr name);
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_value_create_from_type_and_property(ref GLib.Value val, IntPtr gtype, string name); static extern IntPtr gtksharp_value_create_from_type_and_property(ref GLib.Value val, IntPtr gtype, IntPtr name);
[DllImport("glibsharpglue-2")] [DllImport("glibsharpglue-2")]
static extern IntPtr gtksharp_value_create_from_type_name(ref GLib.Value val, string type_name); static extern IntPtr gtksharp_value_create_from_type_name(ref GLib.Value val, IntPtr type_name);
public void Dispose () public void Dispose ()
{ {
@ -71,7 +71,9 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
gtksharp_value_create_from_property (ref this, obj.Handle, prop_name); IntPtr prop = GLib.Marshaller.StringToPtrGStrdup (prop_name);
gtksharp_value_create_from_property (ref this, obj.Handle, prop);
GLib.Marshaller.Free (prop);
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
@ -89,7 +91,9 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
gtksharp_value_create_from_type_name (ref this, type_name); IntPtr native = GLib.Marshaller.StringToPtrGStrdup (type_name);
gtksharp_value_create_from_type_name (ref this, native);
GLib.Marshaller.Free (native);
g_value_set_boxed (ref this, val.Handle); g_value_set_boxed (ref this, val.Handle);
} }
@ -98,7 +102,9 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
gtksharp_value_create_from_property (ref this, obj, prop_name); IntPtr native = GLib.Marshaller.StringToPtrGStrdup (prop_name);
gtksharp_value_create_from_property (ref this, obj, native);
GLib.Marshaller.Free (native);
g_value_set_boxed (ref this, val.Handle); g_value_set_boxed (ref this, val.Handle);
} }
@ -163,11 +169,13 @@ namespace GLib {
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
static extern void g_value_set_string (ref Value val, string data); static extern void g_value_set_string (ref Value val, IntPtr data);
public Value (string val) : this (GType.String) public Value (string val) : this (GType.String)
{ {
g_value_set_string (ref this, val); IntPtr native_val = GLib.Marshaller.StringToPtrGStrdup (val);
g_value_set_string (ref this, native_val);
GLib.Marshaller.Free (native_val);
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
@ -194,7 +202,9 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
gtksharp_value_create_from_type_name (ref this, type_name); IntPtr native = GLib.Marshaller.StringToPtrGStrdup (type_name);
gtksharp_value_create_from_type_name (ref this, native);
GLib.Marshaller.Free (native);
if (wrap.flags) if (wrap.flags)
g_value_set_flags (ref this, (uint) (int) wrap); g_value_set_flags (ref this, (uint) (int) wrap);
else else
@ -206,7 +216,9 @@ namespace GLib {
{ {
type = IntPtr.Zero; type = IntPtr.Zero;
pad_1 = pad_2 = 0; pad_1 = pad_2 = 0;
gtksharp_value_create_from_type_and_property (ref this, obj.NativeType.Val, prop_name); IntPtr native = GLib.Marshaller.StringToPtrGStrdup (prop_name);
gtksharp_value_create_from_type_and_property (ref this, obj.NativeType.Val, native);
GLib.Marshaller.Free (native);
if (wrap.flags) if (wrap.flags)
g_value_set_flags (ref this, (uint) (int) wrap); g_value_set_flags (ref this, (uint) (int) wrap);
else else
@ -317,7 +329,7 @@ namespace GLib {
public static explicit operator String (Value val) public static explicit operator String (Value val)
{ {
IntPtr str = g_value_get_string (ref val); IntPtr str = g_value_get_string (ref val);
return str == IntPtr.Zero ? null : Marshal.PtrToStringAnsi (str); return str == IntPtr.Zero ? null : GLib.Marshaller.Utf8PtrToString (str);
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
@ -393,9 +405,11 @@ namespace GLib {
GType type = TypeConverter.LookupType (value.GetType()); GType type = TypeConverter.LookupType (value.GetType());
if (type == ManagedValue.GType) if (type == ManagedValue.GType)
g_value_set_boxed (ref this, ManagedValue.WrapObject (value)); g_value_set_boxed (ref this, ManagedValue.WrapObject (value));
else if (type == GType.String) else if (type == GType.String) {
g_value_set_string (ref this, (string) value); IntPtr native = GLib.Marshaller.StringToPtrGStrdup ((string)value);
else if (type == GType.Boolean) g_value_set_string (ref this, native);
GLib.Marshaller.Free (native);
} else if (type == GType.Boolean)
g_value_set_boolean (ref this, (bool) value); g_value_set_boolean (ref this, (bool) value);
else if (type == GType.Int) else if (type == GType.Int)
g_value_set_int (ref this, (int) value); g_value_set_int (ref this, (int) value);

View file

@ -46,10 +46,12 @@ namespace Gnome {
} }
[DllImport("gnomeui-2")] [DllImport("gnomeui-2")]
static extern IntPtr gnome_icon_theme_lookup_icon(IntPtr raw, string icon_name, int size, ref Gnome.IconData icon_data, out int base_size); static extern IntPtr gnome_icon_theme_lookup_icon(IntPtr raw, IntPtr icon_name, int size, ref Gnome.IconData icon_data, out int base_size);
public string LookupIcon(string icon_name, int size, Gnome.IconData icon_data, out int base_size) { public string LookupIcon(string icon_name, int size, Gnome.IconData icon_data, out int base_size) {
IntPtr raw_ret = gnome_icon_theme_lookup_icon(Handle, icon_name, size, ref icon_data, out base_size); IntPtr native_icon_name = GLib.Marshaller.StringToPtrGStrdup (icon_name);
IntPtr raw_ret = gnome_icon_theme_lookup_icon(Handle, native_icon_name, size, ref icon_data, out base_size);
GLib.Marshaller.Free (native_icon_name);
string ret = GLib.Marshaller.PtrToStringGFree(raw_ret); string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
return ret; return ret;
} }

View file

@ -55,7 +55,7 @@
retval = new string[length]; retval = new string[length];
for (int i = 0, j = 0; i < length; i++, j += size) { for (int i = 0, j = 0; i < length; i++, j += size) {
IntPtr string_ptr = Marshal.ReadIntPtr (new IntPtr (raw_ret.ToInt32 () + j)); IntPtr string_ptr = Marshal.ReadIntPtr (new IntPtr (raw_ret.ToInt32 () + j));
retval[i] = Marshal.PtrToStringAnsi (string_ptr); retval[i] = GLib.Marshaller.Utf8PtrToString (string_ptr);
} }
g_strfreev (raw_ret); g_strfreev (raw_ret);

View file

@ -19,7 +19,9 @@ namespace Gnome
cb_wrapper = new GnomeSharp.PanelAppletFactoryCallbackWrapper (new PanelAppletFactoryCallback (Creation), null); cb_wrapper = new GnomeSharp.PanelAppletFactoryCallbackWrapper (new PanelAppletFactoryCallback (Creation), null);
_IID = applet.IID; _IID = applet.IID;
_factoryIID = applet.FactoryIID; _factoryIID = applet.FactoryIID;
panel_applet_factory_main(_factoryIID, GLib.Object.LookupGType (applet_type).Val, cb_wrapper.NativeDelegate, IntPtr.Zero); IntPtr native_iid = GLib.Marshaller.StringToPtrGStrdup (_factoryIID);
panel_applet_factory_main (native_iid, GLib.Object.LookupGType (applet_type).Val, cb_wrapper.NativeDelegate, IntPtr.Zero);
GLib.Marshaller.Free (native_iid);
} }
private static bool Creation (PanelApplet applet, string iid) private static bool Creation (PanelApplet applet, string iid)
@ -31,6 +33,6 @@ namespace Gnome
} }
[DllImport("panel-applet-2")] [DllImport("panel-applet-2")]
static extern int panel_applet_factory_main(string iid, IntPtr applet_type, GnomeSharp.PanelAppletFactoryCallbackNative cb, IntPtr data); static extern int panel_applet_factory_main(IntPtr iid, IntPtr applet_type, GnomeSharp.PanelAppletFactoryCallbackNative cb, IntPtr data);
} }
} }

View file

@ -24,47 +24,54 @@ using System.Runtime.InteropServices;
namespace GnomeDb namespace GnomeDb
{ {
/// <summary>
/// GnomeDb Application class
/// </summary>
///
/// <remarks>
/// Provides the initialization and event loop iteration related
/// methods for the libgnomedb library.
/// </remarks>
public class Application public class Application
{ {
private const string VERSION = "0.10"; private const string VERSION = "0.10";
[DllImport("gnomedb-2")] [DllImport("gnomedb-2")]
static extern void gnome_db_init (string app_id, string version, int nargs, IntPtr args); static extern void gnome_db_init (IntPtr app_id, IntPtr version, int nargs, IntPtr args);
public static void Init () public static void Init ()
{ {
gnome_db_init ("GnomeDb#", VERSION, 0, new IntPtr(0)); Init ("GnomeDb#", VERSION);
} }
public static void Init (string app_id, string version) public static void Init (string app_id, string version)
{ {
gnome_db_init (app_id, version, 0, new IntPtr(0)); IntPtr native_appid = GLib.Marshaller.StringToPtrGStrdup (app_id);
IntPtr native_version = GLib.Marshaller.StringToPtrGStrdup (version);
gnome_db_init (native_appid, native_version, 0, IntPtr.Zero);
GLib.Marshaller.Free (native_appid);
GLib.Marshaller.Free (native_version);
} }
[DllImport("gnomedb-2")] [DllImport("gnomedb-2")]
static extern void gnome_db_init (string app_id, string version, ref int nargs, ref String [] args); static extern void gnome_db_init (IntPtr app_id, IntPtr version, ref int argc, ref IntPtr argv);
public static void Init (ref string [] args) public static void Init (ref string [] args)
{ {
int argc = args.Length; Init ("GnomeDb#", VERSION, ref args);
gnome_db_init ("GnomeDb#", VERSION, ref argc, ref args);
} }
public static void Init (string app_id, string version, ref string [] args) public static void Init (string app_id, string version, ref string[] args)
{ {
IntPtr native_appid = GLib.Marshaller.StringToPtrGStrdup (app_id);
IntPtr native_version = GLib.Marshaller.StringToPtrGStrdup (version);
GLib.Argv argv = new GLib.Argv (args);
IntPtr arg_ptr = argv.Handle;
int argc = args.Length; int argc = args.Length;
gnome_db_init (app_id, version, ref argc, ref args); gnome_db_init (native_appid, native_version, ref argc, ref arg_ptr);
GLib.Marshaller.Free (native_appid);
GLib.Marshaller.Free (native_version);
if (arg_ptr != argv.Handle)
throw new Exception ("Init returned new argv handle.");
if (argc <= 1)
args = new string [0];
else
args = argv.GetArgs (argc);
} }
[DllImport("gnomedb-2")] [DllImport("gnomedb-2")]
static extern void gnome_db_main_run (IntPtr init_func, IntPtr user_data); static extern void gnome_db_main_run (IntPtr init_func, IntPtr user_data);

View file

@ -93,7 +93,7 @@ namespace Gnome.Vfs {
public string Name { public string Name {
get { get {
if (info.name != IntPtr.Zero) if (info.name != IntPtr.Zero)
return Marshal.PtrToStringAnsi (info.name); return GLib.Marshaller.Utf8PtrToString (info.name);
else else
return null; return null;
} }
@ -229,7 +229,7 @@ namespace Gnome.Vfs {
get { get {
if ((ValidFields & FileInfoFields.SymlinkName) != 0 && if ((ValidFields & FileInfoFields.SymlinkName) != 0 &&
info.symlink_name != IntPtr.Zero) info.symlink_name != IntPtr.Zero)
return Marshal.PtrToStringAnsi (info.symlink_name); return GLib.Marshaller.Utf8PtrToString (info.symlink_name);
else else
throw new ArgumentException ("SymlinkName is not set"); throw new ArgumentException ("SymlinkName is not set");
} }
@ -239,7 +239,7 @@ namespace Gnome.Vfs {
get { get {
if ((ValidFields & FileInfoFields.MimeType) != 0 && if ((ValidFields & FileInfoFields.MimeType) != 0 &&
info.mime_type != IntPtr.Zero) info.mime_type != IntPtr.Zero)
return Marshal.PtrToStringAnsi (info.mime_type); return GLib.Marshaller.Utf8PtrToString (info.mime_type);
else else
throw new ArgumentException ("MimeType is not set"); throw new ArgumentException ("MimeType is not set");
} }

View file

@ -76,7 +76,7 @@ namespace Gnome.Vfs {
internal static string ResultToString (int result) internal static string ResultToString (int result)
{ {
IntPtr ptr = gnome_vfs_result_to_string (result); IntPtr ptr = gnome_vfs_result_to_string (result);
return Marshal.PtrToStringAnsi (ptr); return GLib.Marshaller.Utf8PtrToString (ptr);
} }
public static void ThrowException (Result result) public static void ThrowException (Result result)

View file

@ -106,7 +106,7 @@ public Gtk.Entry FileopEntry {
static extern IntPtr gtksharp_file_selection_get_fileop_file (IntPtr i); static extern IntPtr gtksharp_file_selection_get_fileop_file (IntPtr i);
public string FileopFile { public string FileopFile {
get { get {
return Marshal.PtrToStringAnsi (gtksharp_file_selection_get_fileop_file (this.Handle)); return GLib.Marshaller.Utf8PtrToString (gtksharp_file_selection_get_fileop_file (this.Handle));
} }
} }
@ -155,7 +155,7 @@ public string[] Selections {
int i = 0; int i = 0;
IntPtr strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); IntPtr strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++);
while (strptr != IntPtr.Zero) { while (strptr != IntPtr.Zero) {
result.Add (Marshal.PtrToStringAnsi (strptr)); result.Add (GLib.Marshaller.Utf8PtrToString (strptr));
strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++); strptr = Marshal.ReadIntPtr (strv, IntPtr.Size * i++);
} }

View file

@ -40,7 +40,7 @@
retval = new string[length]; retval = new string[length];
for (int i = 0, j = 0; i < length; i++, j += size) { for (int i = 0, j = 0; i < length; i++, j += size) {
IntPtr string_ptr = Marshal.ReadIntPtr (new IntPtr (raw_ret.ToInt32 () + j)); IntPtr string_ptr = Marshal.ReadIntPtr (new IntPtr (raw_ret.ToInt32 () + j));
retval[i] = Marshal.PtrToStringAnsi (string_ptr); retval[i] = GLib.Marshaller.Utf8PtrToString (string_ptr);
} }
g_strfreev (raw_ret); g_strfreev (raw_ret);

View file

@ -32,5 +32,7 @@
return; return;
} }
Raw = gtk_radio_menu_item_new_with_mnemonic (IntPtr.Zero, label); IntPtr label_as_native = GLib.Marshaller.StringToPtrGStrdup (label);
Raw = gtk_radio_menu_item_new_with_mnemonic (IntPtr.Zero, label_as_native);
GLib.Marshaller.Free (label_as_native);
} }

View file

@ -53,11 +53,11 @@
return Gtk.StockItem.Zero; return Gtk.StockItem.Zero;
Gtk.StockItem item = new Gtk.StockItem (); Gtk.StockItem item = new Gtk.StockItem ();
item.StockId = Marshal.PtrToStringAnsi (const_item.StockId); item.StockId = GLib.Marshaller.Utf8PtrToString (const_item.StockId);
item.Label = Marshal.PtrToStringAnsi (const_item.Label); item.Label = GLib.Marshaller.Utf8PtrToString (const_item.Label);
item.Modifier = const_item.Modifier; item.Modifier = const_item.Modifier;
item.Keyval = const_item.Keyval; item.Keyval = const_item.Keyval;
item.TranslationDomain = Marshal.PtrToStringAnsi (const_item.TranslationDomain); item.TranslationDomain = GLib.Marshaller.Utf8PtrToString (const_item.TranslationDomain);
return item; return item;
} }

View file

@ -46,22 +46,25 @@ namespace Gtk {
public static explicit operator StockItem (ConstStockItem csi) public static explicit operator StockItem (ConstStockItem csi)
{ {
Gtk.StockItem item = new Gtk.StockItem (); Gtk.StockItem item = new Gtk.StockItem ();
item.StockId = Marshal.PtrToStringAnsi (csi.StockId); item.StockId = GLib.Marshaller.Utf8PtrToString (csi.StockId);
item.Label = Marshal.PtrToStringAnsi (csi.Label); item.Label = GLib.Marshaller.Utf8PtrToString (csi.Label);
item.Modifier = csi.Modifier; item.Modifier = csi.Modifier;
item.Keyval = csi.Keyval; item.Keyval = csi.Keyval;
item.TranslationDomain = Marshal.PtrToStringAnsi (csi.TranslationDomain); item.TranslationDomain = GLib.Marshaller.Utf8PtrToString (csi.TranslationDomain);
return item; return item;
} }
} }
[DllImport("libgtk-win32-2.0-0.dll")] [DllImport("libgtk-win32-2.0-0.dll")]
static extern bool gtk_stock_lookup (string stock_id, out ConstStockItem item); static extern bool gtk_stock_lookup (IntPtr stock_id, out ConstStockItem item);
public static bool Lookup (string stock_id, ref Gtk.StockItem item) public static bool Lookup (string stock_id, ref Gtk.StockItem item)
{ {
ConstStockItem const_item; ConstStockItem const_item;
if (!gtk_stock_lookup (stock_id, out const_item)) IntPtr native_id = GLib.Marshaller.StringToPtrGStrdup (stock_id);
bool found = gtk_stock_lookup (native_id, out const_item);
GLib.Marshaller.Free (native_id);
if (!found)
return false; return false;
item = (StockItem) const_item; item = (StockItem) const_item;
return true; return true;

View file

@ -72,15 +72,21 @@ public void SetMarkupWithAccel (string markup, char accel_marker, out char accel
} }
[DllImport ("libpango-1.0-0.dll")] [DllImport ("libpango-1.0-0.dll")]
static extern void pango_layout_set_text (IntPtr raw, string text, int length); static extern void pango_layout_set_text (IntPtr raw, IntPtr text, int length);
public void SetText (string text) { public void SetText (string text)
pango_layout_set_text (Handle, text, -1); {
IntPtr native_text = GLib.Marshaller.StringToPtrGStrdup (text);
pango_layout_set_text (Handle, native_text, -1);
GLib.Marshaller.Free (native_text);
} }
[DllImport ("libpango-1.0-0.dll")] [DllImport ("libpango-1.0-0.dll")]
static extern void pango_layout_set_markup (IntPtr raw, string markup, int length); static extern void pango_layout_set_markup (IntPtr raw, IntPtr markup, int length);
public void SetMarkup (string markup) { public void SetMarkup (string markup)
pango_layout_set_markup (Handle, markup, -1); {
IntPtr native_markup = GLib.Marshaller.StringToPtrGStrdup (markup);
pango_layout_set_markup (Handle, native_markup, -1);
GLib.Marshaller.Free (native_markup);
} }

View file

@ -1,10 +1,11 @@
//
// rsvg/Tool.cs - Rsvg Tool class // rsvg/Tool.cs - Rsvg Tool class
// //
// Author: Charles Iliya Krempeaux <charles@reptile.ca> // Author: Charles Iliya Krempeaux <charles@reptile.ca>
// Mike Kestner <mkestner@novell.com>
// //
// Copyright (C) 2003 Reptile Consulting & Services Ltd. // Copyright (C) 2003 Reptile Consulting & Services Ltd.
// Copyright (C) 2003 Charles Iliya Krempeaux. // Copyright (C) 2003 Charles Iliya Krempeaux.
// Copyright (C) 2005 Novell, Inc.
// //
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General // modify it under the terms of version 2 of the Lesser GNU General
@ -22,137 +23,94 @@
// O B J E C T S //////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace Rsvg {
namespace Rsvg { using System;
using System.Runtime.InteropServices;
public class Tool public class Tool {
{
[DllImport("rsvg-2")]
static extern IntPtr rsvg_pixbuf_from_file (IntPtr file_name, out IntPtr error);
[DllImport("rsvg-2")]
static extern IntPtr rsvg_pixbuf_from_file_at_zoom (IntPtr file_name, double x_zoom, double y_zoom, out IntPtr error);
[DllImport("rsvg-2")]
static extern IntPtr rsvg_pixbuf_from_file_at_size (IntPtr file_name, int width, int height, out IntPtr error);
[DllImport("rsvg-2")]
static extern IntPtr rsvg_pixbuf_from_file_at_max_size (IntPtr file_name, int max_width, int max_height, out IntPtr error);
[DllImport("rsvg-2")]
static extern IntPtr rsvg_pixbuf_from_file_at_zoom_with_max (IntPtr file_name, double x_zoom, double y_zoom, int max_width, int max_height, out IntPtr error);
// D L L I M P O R T S //////////////////////////////////////////////////////////////////////////////////////// public static Gdk.Pixbuf PixbufFromFile (string file_name)
{
IntPtr error = IntPtr.Zero;
IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup (file_name);
IntPtr raw_pixbuf = rsvg_pixbuf_from_file(native_filename, out error);
GLib.Marshaller.Free (native_filename);
[System.Runtime.InteropServices.DllImport("rsvg-2")] if (IntPtr.Zero != error)
static extern System.IntPtr rsvg_pixbuf_from_file( string file_name throw new GLib.GException (error);
, out System.IntPtr error
);
[System.Runtime.InteropServices.DllImport("rsvg-2")] return GLib.Object.GetObject (raw_pixbuf, true) as Gdk.Pixbuf;
static extern }
System.IntPtr
rsvg_pixbuf_from_file_at_zoom( string file_name
, double x_zoom
, double y_zoom
, out System.IntPtr error
);
[System.Runtime.InteropServices.DllImport("rsvg-2")] public static Gdk.Pixbuf PixbufFromFileAtZoom (string file_name, double x_zoom, double y_zoom)
static extern {
System.IntPtr IntPtr error = IntPtr.Zero;
rsvg_pixbuf_from_file_at_size( string file_name IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup (file_name);
, int width IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_zoom (native_filename, x_zoom, y_zoom, out error);
, int height GLib.Marshaller.Free (native_filename);
, out System.IntPtr error
);
[System.Runtime.InteropServices.DllImport("rsvg-2")] if (IntPtr.Zero != error)
static extern throw new GLib.GException (error);
System.IntPtr
rsvg_pixbuf_from_file_at_max_size( string file_name
, int max_width
, int max_height
, out System.IntPtr error
);
[System.Runtime.InteropServices.DllImport("rsvg-2")] return GLib.Object.GetObject (raw_pixbuf, true) as Gdk.Pixbuf;
static extern }
System.IntPtr
rsvg_pixbuf_from_file_at_zoom_with_max( string file_name
, double x_zoom
, double y_zoom
, int max_width
, int max_height
, out System.IntPtr error
);
//////////////////////////////////////////////////////////////////////////////////////// D L L I M P O R T S // public static Gdk.Pixbuf PixbufFromFileAtSize(string file_name, int width, int height)
{
IntPtr error = IntPtr.Zero;
IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup (file_name);
// P R O C E D U R E S ////////////////////////////////////////////////////////////////////////////////////////// IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_size (native_filename, width, height, out error);
GLib.Marshaller.Free (native_filename);
public static Gdk.Pixbuf PixbufFromFile(string file_name)
{ if (IntPtr.Zero != error)
System.IntPtr error = System.IntPtr.Zero; throw new GLib.GException (error);
System.IntPtr raw_pixbuf = rsvg_pixbuf_from_file(file_name, out error); return GLib.Object.GetObject (raw_pixbuf, true) as Gdk.Pixbuf;
}
if (System.IntPtr.Zero != error) {
throw new GLib.GException ( error ); public static Gdk.Pixbuf PixbufFromFileAtMaxSize(string file_name, int max_width, int max_height)
} else { {
return new Gdk.Pixbuf( raw_pixbuf ); IntPtr error = IntPtr.Zero;
} IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup (file_name);
} IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_max_size (native_filename, max_width, max_height, out error);
GLib.Marshaller.Free (native_filename);
public static Gdk.Pixbuf PixbufFromFileAtZoom(string file_name, double x_zoom, double y_zoom)
{ if (IntPtr.Zero != error)
System.IntPtr error = System.IntPtr.Zero; throw new GLib.GException (error);
System.IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_zoom(file_name, x_zoom, y_zoom, out error); return GLib.Object.GetObject (raw_pixbuf, true) as Gdk.Pixbuf;
}
if (System.IntPtr.Zero != error) {
throw new GLib.GException( error ); public static Gdk.Pixbuf PixbufFromFileAtZoomWithMaxSize(string file_name, double x_zoom, double y_zoom, int max_width, int max_height)
} else { {
return new Gdk.Pixbuf( raw_pixbuf ); IntPtr error = IntPtr.Zero;
} IntPtr native_filename = GLib.Marshaller.StringToPtrGStrdup (file_name);
} IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_zoom_with_max (native_filename, x_zoom, y_zoom, max_width, max_height, out error);
GLib.Marshaller.Free (native_filename);
public static Gdk.Pixbuf PixbufFromFileAtSize(string file_name, int width, int height)
{ if (IntPtr.Zero != error)
System.IntPtr error = System.IntPtr.Zero; throw new GLib.GException (error);
System.IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_size(file_name, width, height, out error); return GLib.Object.GetObject (raw_pixbuf, true) as Gdk.Pixbuf;
}
if (System.IntPtr.Zero != error) { }
throw new GLib.GException( error ); }
} else {
return new Gdk.Pixbuf( raw_pixbuf );
}
}
public static Gdk.Pixbuf PixbufFromFileAtMaxSize(string file_name, int max_width, int max_height)
{
System.IntPtr error = System.IntPtr.Zero;
System.IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_max_size(file_name, max_width, max_height, out error);
if (System.IntPtr.Zero != error) {
throw new GLib.GException( error );
} else {
return new Gdk.Pixbuf( raw_pixbuf );
}
}
public static Gdk.Pixbuf PixbufFromFileAtZoomWithMaxSize(string file_name, double x_zoom, double y_zoom, int max_width, int max_height)
{
System.IntPtr error = System.IntPtr.Zero;
System.IntPtr raw_pixbuf = rsvg_pixbuf_from_file_at_zoom_with_max(file_name, x_zoom, y_zoom, max_width, max_height, out error);
if (System.IntPtr.Zero != error) {
throw new GLib.GException( error );
} else {
return new Gdk.Pixbuf( raw_pixbuf );
}
}
////////////////////////////////////////////////////////////////////////////////////////// P R O C E D U R E S //
} // class Tool
} // namespace Rsvg
//////////////////////////////////////////////////////////////////////////////////////////////////////////// O B J E C T S //