mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-09-07 07:23:18 +02:00
Implement Ownable Generatable type.
* cairo/Context.cs: add ctor (IntPtr, bool owned) * cairo/cairo-api.xml: expose cairo_t as new ownable symbol type * generator/HandleBase.cs: implement IOwnable * generator/IOwnable.cs: new interface for wrapping ownable types * generator/Makefile.am: add new files to build * generator/OwnableGen.cs: SimpleBase subclass to expose IOwnable * generator/Parameters.cs: use IOwnable.FromNative instead of HandleBase * generator/Parser.cs: parse ownable symbol type * generator/ReturnValue.cs: use IOwnable.FromNative instead of HandleBase
This commit is contained in:
parent
6647c2609c
commit
0fc5126228
@ -184,9 +184,11 @@ namespace Cairo {
|
|||||||
state = NativeMethods.cairo_create (surface.Handle);
|
state = NativeMethods.cairo_create (surface.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Context (IntPtr state)
|
public Context (IntPtr state) : this (state, true) {}
|
||||||
|
|
||||||
|
public Context (IntPtr state, bool owned)
|
||||||
{
|
{
|
||||||
this.state = NativeMethods.cairo_reference (state);
|
this.state = owned ? state : NativeMethods.cairo_reference (state);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Context ()
|
~Context ()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<namespace name="Cairo">
|
<namespace name="Cairo">
|
||||||
<enum cname="cairo_content_t" name="Content" type="enum" />
|
<enum cname="cairo_content_t" name="Content" type="enum" />
|
||||||
</namespace>
|
</namespace>
|
||||||
<symbol type="manual" cname="cairo_t" name="Cairo.Context"/>
|
<symbol type="ownable" cname="cairo_t" name="Cairo.Context"/>
|
||||||
<symbol type="manual" cname="cairo_font_options_t" name="Cairo.FontOptions"/>
|
<symbol type="manual" cname="cairo_font_options_t" name="Cairo.FontOptions"/>
|
||||||
<symbol type="manual" cname="cairo_region_t" name="Cairo.Region"/>
|
<symbol type="manual" cname="cairo_region_t" name="Cairo.Region"/>
|
||||||
<symbol type="marshal" cname="cairo_pattern_t" name="Cairo.Pattern" marshal_type="IntPtr" call_fmt="{0}.Handle" from_fmt="Cairo.Pattern.Lookup ({0})" />
|
<symbol type="marshal" cname="cairo_pattern_t" name="Cairo.Pattern" marshal_type="IntPtr" call_fmt="{0}.Handle" from_fmt="Cairo.Pattern.Lookup ({0})" />
|
||||||
|
@ -25,7 +25,7 @@ namespace GtkSharp.Generation {
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
public abstract class HandleBase : ClassBase, IAccessor {
|
public abstract class HandleBase : ClassBase, IAccessor, IOwnable {
|
||||||
|
|
||||||
protected HandleBase (XmlElement ns, XmlElement elem) : base (ns, elem) {}
|
protected HandleBase (XmlElement ns, XmlElement elem) : base (ns, elem) {}
|
||||||
|
|
||||||
|
24
generator/IOwnable.cs
Normal file
24
generator/IOwnable.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// Copyright (c) 2011 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 IOwnable {
|
||||||
|
|
||||||
|
string FromNative (string var, bool owned);
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ sources = \
|
|||||||
IManualMarshaler.cs \
|
IManualMarshaler.cs \
|
||||||
InterfaceGen.cs \
|
InterfaceGen.cs \
|
||||||
InterfaceVM.cs \
|
InterfaceVM.cs \
|
||||||
|
IOwnable.cs \
|
||||||
LogWriter.cs \
|
LogWriter.cs \
|
||||||
LPGen.cs \
|
LPGen.cs \
|
||||||
LPUGen.cs \
|
LPUGen.cs \
|
||||||
@ -44,6 +45,7 @@ sources = \
|
|||||||
ObjectBase.cs \
|
ObjectBase.cs \
|
||||||
ObjectGen.cs \
|
ObjectGen.cs \
|
||||||
OpaqueGen.cs \
|
OpaqueGen.cs \
|
||||||
|
OwnableGen.cs \
|
||||||
Parameters.cs \
|
Parameters.cs \
|
||||||
Parser.cs \
|
Parser.cs \
|
||||||
Property.cs \
|
Property.cs \
|
||||||
|
51
generator/OwnableGen.cs
Normal file
51
generator/OwnableGen.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable.
|
||||||
|
//
|
||||||
|
// Author: Mike Kestner <mkestner@novell.com>
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003 Mike Kestner
|
||||||
|
// Copyright (c) 2004 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 OwnableGen : SimpleBase, IOwnable {
|
||||||
|
|
||||||
|
public OwnableGen (string ctype, string type) : base (ctype, type, "null") {}
|
||||||
|
|
||||||
|
public override string MarshalType {
|
||||||
|
get { return "IntPtr"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string CallByName (string var_name)
|
||||||
|
{
|
||||||
|
return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string FromNative (string var)
|
||||||
|
{
|
||||||
|
return String.Format ("new {0} ({1})", QualifiedName, var);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string FromNative (string var, bool owned)
|
||||||
|
{
|
||||||
|
return String.Format ("new {0} ({1}, {2})", QualifiedName, var, owned ? "true" : "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -283,8 +283,8 @@ namespace GtkSharp.Generation {
|
|||||||
result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";";
|
result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";";
|
||||||
return result;
|
return result;
|
||||||
} else if (PassAs != String.Empty && MarshalType != CSType)
|
} else if (PassAs != String.Empty && MarshalType != CSType)
|
||||||
if (gen is HandleBase)
|
if (gen is IOwnable)
|
||||||
return new string [] { CallName + " = " + (gen as HandleBase).FromNative ("native_" + CallName, Owned) + ";" };
|
return new string [] { CallName + " = " + (gen as IOwnable).FromNative ("native_" + CallName, Owned) + ";" };
|
||||||
else
|
else
|
||||||
return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" };
|
return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" };
|
||||||
return new string [0];
|
return new string [0];
|
||||||
@ -295,8 +295,8 @@ namespace GtkSharp.Generation {
|
|||||||
{
|
{
|
||||||
if (Generatable == null)
|
if (Generatable == null)
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
else if (Generatable is HandleBase)
|
else if (Generatable is IOwnable)
|
||||||
return ((HandleBase)Generatable).FromNative (var, Owned);
|
return ((IOwnable)Generatable).FromNative (var, Owned);
|
||||||
else
|
else
|
||||||
return Generatable.FromNative (var);
|
return Generatable.FromNative (var);
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,8 @@ namespace GtkSharp.Generation {
|
|||||||
}
|
}
|
||||||
} else if (type == "manual")
|
} else if (type == "manual")
|
||||||
result = new ManualGen (cname, name);
|
result = new ManualGen (cname, name);
|
||||||
|
else if (type == "ownable")
|
||||||
|
result = new OwnableGen (cname, name);
|
||||||
else if (type == "alias")
|
else if (type == "alias")
|
||||||
result = new AliasGen (cname, name);
|
result = new AliasGen (cname, name);
|
||||||
else if (type == "marshal") {
|
else if (type == "marshal") {
|
||||||
|
@ -129,8 +129,8 @@ namespace GtkSharp.Generation {
|
|||||||
return String.Format ("({0}[]) GLib.Marshaller.PtrArrayToArray ({1}, {2}, typeof({0}))", ElementType, var, args);
|
return String.Format ("({0}[]) GLib.Marshaller.PtrArrayToArray ({1}, {2}, typeof({0}))", ElementType, var, args);
|
||||||
else
|
else
|
||||||
return String.Format ("({0}[]) GLib.Marshaller.ListPtrToArray ({1}, typeof({2}), {3}, typeof({4}))", ElementType, var, IGen.QualifiedName, args, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType);
|
return String.Format ("({0}[]) GLib.Marshaller.ListPtrToArray ({1}, typeof({2}), {3}, typeof({4}))", ElementType, var, IGen.QualifiedName, args, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType);
|
||||||
} else if (IGen is HandleBase)
|
} else if (IGen is IOwnable)
|
||||||
return ((HandleBase)IGen).FromNative (var, owned);
|
return ((IOwnable)IGen).FromNative (var, owned);
|
||||||
else if (is_null_term)
|
else if (is_null_term)
|
||||||
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
|
return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false");
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user