2002-07-30 Rachel Hestilow <hestilow@ximian.com>

* generator/ClassBase.cs: Change hasDefaultConstructor to protected,
	adjust now that it is an attr and not a subnode. Also add virtual
	property AssignToName (for ctors).

	* generator/Ctor.cs: Add property ForceStatic.
	(Generate): Optimize return code a bit for the static case.

	* generator/Method.cs: Assign to a "raw_ret" pointer before calling
	FromNativeReturn.

	* generator/Parameters.cs: Change "out ref" to "out", not "ref".

	* generator/Property.cs: Fix to work correctly with all object and
	struct types (mostly just some if-cases added).

	* generator/SignalHandler.cs: Remove args_type and argfields (unused).
	(Generate): Initialize struct if necessary.

	* generator/StructBase.cs: Massive reworking to support methods, ctors,
	etc.

	* generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types.

	* glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both.

	* glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event
	fields. Fix docs.

	* glib/Value.cs: Work correctly with boxed properties.

	* gnome/Modules.cs: Use new struct ctors.

	* gnome/Program.custom: Remove Get, this is being generated now.

	* parser/Gdk.metadata: Fix the drawable classes to inherit correctly.

	* parser/Metadata.pm: Change per-class attributes to actually be
	attributes.

	* parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor.

	* parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap
	typedefs.

	* sample/test/TestColorSelection.cs: Display color string in hex format,
	update to use IsNull instead of == null, and size dialog to look pretty.

	* sample/Size.cs: Added.

svn path=/trunk/gtk-sharp/; revision=6264
This commit is contained in:
Rachel Hestilow 2002-07-30 23:02:12 +00:00
parent 9823d2d8ea
commit 967e3e9c5a
24 changed files with 376 additions and 111 deletions

View file

@ -1,3 +1,54 @@
2002-07-30 Rachel Hestilow <hestilow@ximian.com>
* generator/ClassBase.cs: Change hasDefaultConstructor to protected,
adjust now that it is an attr and not a subnode. Also add virtual
property AssignToName (for ctors).
* generator/Ctor.cs: Add property ForceStatic.
(Generate): Optimize return code a bit for the static case.
* generator/Method.cs: Assign to a "raw_ret" pointer before calling
FromNativeReturn.
* generator/Parameters.cs: Change "out ref" to "out", not "ref".
* generator/Property.cs: Fix to work correctly with all object and
struct types (mostly just some if-cases added).
* generator/SignalHandler.cs: Remove args_type and argfields (unused).
(Generate): Initialize struct if necessary.
* generator/StructBase.cs: Massive reworking to support methods, ctors,
etc.
* generator/SymbolTable.cs: Add GdkAtom and gconstpointer simple types.
* glib/Boxed.cs: Accept both IntPtr and object ctors. Add access for both.
* glib/Opaque.cs: Fix copy/pasted copyright notice, remove data and event
fields. Fix docs.
* glib/Value.cs: Work correctly with boxed properties.
* gnome/Modules.cs: Use new struct ctors.
* gnome/Program.custom: Remove Get, this is being generated now.
* parser/Gdk.metadata: Fix the drawable classes to inherit correctly.
* parser/Metadata.pm: Change per-class attributes to actually be
attributes.
* parser/Gtk.metadata: Add a dummy attribute value for disabledefaultctor.
* parser/gapi2xml.pl: Add hacks for the (broken) Drawable and Bitmap
typedefs.
* sample/test/TestColorSelection.cs: Display color string in hex format,
update to use IsNull instead of == null, and size dialog to look pretty.
* sample/Size.cs: Added.
2002-07-25 Rachel Hestilow <hestilow@ximian.com>
[about 60% of the marshalling patch that I lost.

View file

@ -19,7 +19,7 @@ namespace GtkSharp.Generation {
protected ArrayList interfaces = null;
protected ArrayList ctors = new ArrayList();
private bool hasDefaultConstructor = true;
protected bool hasDefaultConstructor = true;
private bool ctors_initted = false;
private Hashtable clash_map;
@ -43,6 +43,8 @@ namespace GtkSharp.Generation {
}
protected ClassBase (XmlElement ns, XmlElement elem) : base (ns, elem) {
hasDefaultConstructor = !elem.HasAttribute ("disabledefaultconstructor");
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
@ -73,10 +75,6 @@ namespace GtkSharp.Generation {
ctors.Add (new Ctor (LibraryName, member, this));
break;
case "disabledefaultconstructor":
hasDefaultConstructor = false;
break;
default:
break;
}
@ -123,6 +121,10 @@ namespace GtkSharp.Generation {
return "Handle";
}
public virtual String AssignToName {
get { return "Raw"; }
}
public virtual String FromNative(String var)
{
return "(" + QualifiedName + ") GLib.Object.GetObject(" + var + ")";

View file

@ -19,12 +19,18 @@ namespace GtkSharp.Generation {
private bool preferred;
private String clashName = null;
private ClassBase container_type;
private bool force_static;
public bool Preferred {
get { return preferred; }
set { preferred = value; }
}
public bool ForceStatic {
get { return force_static; }
set { force_static = value; }
}
public Ctor (string libname, XmlElement elem, ClassBase container_type) {
this.libname = libname;
this.elem = elem;
@ -71,7 +77,7 @@ namespace GtkSharp.Generation {
}
int clashes = (int) clash_map[sigtypes];
string cname = elem.GetAttribute("cname");
if (clashes > 0 && !Preferred) {
if (force_static || (clashes > 0 && !Preferred)) {
String mname = cname.Substring(cname.IndexOf("new"));
mname = mname.Substring(0,1).ToUpper() + mname.Substring(1);
int idx;
@ -126,20 +132,26 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\tpublic static " + safety + modifiers + name + " " + clashName);
sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(sw, false, "");
sw.WriteLine("\t\t\tIntPtr ret = " + cname + call + ";");
if (parms != null)
parms.HandleException (sw, "");
sw.WriteLine("\t\t\treturn new " + name + "(ret);");
sw.Write("\t\t\treturn ");
if (container_type is StructBase)
sw.Write ("{0}.New (", name);
else
sw.Write ("new {0} (", name);
sw.WriteLine (cname + call + ");");
} else {
sw.WriteLine("\t\tpublic " + safety + name + sig);
sw.WriteLine("\t\t{");
if (parms != null)
parms.Initialize(sw, false, "");
sw.WriteLine("\t\t\tRaw = " + cname + call + ";");
sw.WriteLine("\t\t\t{0} = {1}{2};", container_type.AssignToName, cname, call);
if (parms != null)
parms.HandleException (sw, "");
}
sw.WriteLine("\t\t}");

View file

@ -349,8 +349,11 @@ namespace GtkSharp.Generation {
sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";");
sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);");
}
else
sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, cname + call) + ";");
else {
sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";");
sw.Write(indent + "\t\t\t");
sw.WriteLine(s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";");
}
}
if (parms != null)

View file

@ -226,8 +226,8 @@ namespace GtkSharp.Generation {
}
import_sig += (m_type + " " + name);
// FIXME: lame
call_string = call_string.Replace ("out ref", "ref");
import_sig = import_sig.Replace ("out ref", "ref");
call_string = call_string.Replace ("out ref", "out");
import_sig = import_sig.Replace ("out ref", "out");
i++;
}

View file

@ -74,7 +74,7 @@ namespace GtkSharp.Generation {
Statistics.ThrottledCount++;
return;
} else if (SymbolTable.IsObject(c_type)) {
v_type = "(GLib.Object)";
v_type = "(GLib.UnwrappedObject)";
} else if (SymbolTable.IsBoxed (c_type)) {
v_type = "(GLib.Boxed)";
} else if (SymbolTable.IsOpaque (c_type)) {
@ -95,21 +95,18 @@ namespace GtkSharp.Generation {
sw.WriteLine("\t\t\tget {");
sw.WriteLine("\t\t\t\tGLib.Value val = new GLib.Value (Handle, " + cname + ");");
sw.WriteLine("\t\t\t\tGetProperty(" + cname + ", val);");
if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type)) {
sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) (GLib.UnwrappedObject) val;");
if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type) || SymbolTable.IsBoxed (c_type)) {
sw.WriteLine("\t\t\t\tSystem.IntPtr raw_ret = (System.IntPtr) {0} val;", v_type);
sw.WriteLine("\t\t\t\t" + cs_type + " ret = " + SymbolTable.FromNativeReturn(c_type, "raw_ret") + ";");
sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);");
if (!SymbolTable.IsBoxed (c_type))
sw.WriteLine("\t\t\t\tif (ret == null) ret = new " + cs_type + "(raw_ret);");
} else {
sw.Write("\t\t\t\t" + cs_type + " ret = ");
if (SymbolTable.IsBoxed (c_type)) {
sw.WriteLine ("({0}) (({1} val).Obj);", cs_type, v_type);
} else {
sw.Write ("(" + cs_type + ") ");
if (v_type != "") {
sw.Write(v_type + " ");
}
sw.WriteLine("val;");
sw.Write ("(" + cs_type + ") ");
if (v_type != "") {
sw.Write(v_type + " ");
}
sw.WriteLine("val;");
}
sw.WriteLine("\t\t\t\treturn ret;");
@ -124,7 +121,7 @@ namespace GtkSharp.Generation {
} else if (SymbolTable.IsBoxed (c_type)) {
sw.WriteLine("Handle, " + cname + ", new GLib.Boxed (value)));");
} else {
if (v_type != "") {
if (v_type != "" && !(SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type))) {
sw.Write(v_type + " ");
}
sw.WriteLine("value));");

View file

@ -14,7 +14,6 @@ namespace GtkSharp.Generation {
public class SignalHandler {
private static Hashtable handlers = new Hashtable ();
private string args_type;
public static String GetName(XmlElement sig)
{
@ -40,7 +39,6 @@ namespace GtkSharp.Generation {
string key = retval;
string pinv = "";
string name = SymbolTable.GetName(retval);
string argfields = "";
int pcnt = 0;
ArrayList parms = new ArrayList();
@ -152,8 +150,11 @@ namespace GtkSharp.Generation {
sw.WriteLine("= GLib.Object.GetObject(arg" + idx + ");");
} else {
string ctype = (string) parms[idx];
sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";");
ClassBase wrapper = SymbolTable.GetClassGen (ctype);
if (wrapper != null && (wrapper is StructBase)) {
sw.WriteLine("\t\t\targ{0}._Initialize ();", idx);
}
sw.WriteLine("\t\t\targs.Args[" + (idx-1) + "] = " + SymbolTable.FromNative (ctype, "arg" + idx) + ";");
if ((wrapper != null && ((wrapper is ObjectGen) || (wrapper is OpaqueGen))) || SymbolTable.IsManuallyWrapped (ctype)) {
sw.WriteLine("\t\t\tif (args.Args[" + (idx-1) + "] == null)");
sw.WriteLine("\t\t\t\targs.Args[{0}] = new {1}(arg{2});", idx-1, SymbolTable.GetCSType (ctype), idx);

View file

@ -13,8 +13,35 @@ namespace GtkSharp.Generation {
using System.Xml;
public class StructBase : ClassBase {
public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem) {}
ArrayList fields = new ArrayList ();
uint bitfields;
public StructBase (XmlElement ns, XmlElement elem) : base (ns, elem)
{
hasDefaultConstructor = false;
foreach (XmlNode node in elem.ChildNodes) {
if (!(node is XmlElement)) continue;
XmlElement member = (XmlElement) node;
switch (node.Name) {
case "field":
fields.Add (member);
break;
case "callback":
Statistics.IgnoreCount++;
break;
default:
if (!IsNodeNameHandled (node.Name))
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
break;
}
}
}
public override String MarshalType {
get
@ -40,6 +67,10 @@ namespace GtkSharp.Generation {
return "ref this";
}
public override String AssignToName {
get { return "raw"; }
}
public override String FromNative(String var)
{
return var;
@ -47,33 +78,71 @@ namespace GtkSharp.Generation {
public override String FromNativeReturn(String var)
{
return "new " + QualifiedName + " (" + var + ")";
return QualifiedName + ".New (" + var + ")";
}
bool IsBit (XmlElement field)
{
return (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1"));
}
bool IsPointer (XmlElement field)
{
string c_type = field.GetAttribute("type");
return (c_type[c_type.Length - 1] == '*');
}
protected void GenFields (StreamWriter sw)
{
bitfields = 0;
bool need_field = true;
foreach (XmlElement field in fields) {
if (IsBit (field)) {
if (need_field)
need_field = false;
else
continue;
} else
need_field = true;
GenField (field, sw);
}
}
protected bool GetFieldInfo (XmlElement field, out string type, out string name)
{
name = "";
if (IsBit (field))
type = "uint";
else if (IsPointer (field)) {
type = "IntPtr";
name = "_";
} else {
string c_type = field.GetAttribute ("type");
type = SymbolTable.GetCSType (c_type);
if (type == "") {
Console.WriteLine ("Field has unknown Type {0}", c_type);
Statistics.ThrottledCount++;
return false;
}
}
if (field.HasAttribute("array_len"))
type += "[]";
if (IsBit (field))
name = String.Format ("_bitfield{0}", bitfields++);
else
name += MangleName (field.GetAttribute ("cname"));
return true;
}
protected bool GenField (XmlElement field, StreamWriter sw)
{
String c_type;
if (field.HasAttribute("bits") && (field.GetAttribute("bits") == "1")) {
c_type = "gboolean";
} else {
c_type = field.GetAttribute("type");
}
char[] ast = {'*'};
c_type = c_type.TrimEnd(ast);
String m_type = SymbolTable.GetMarshalType(c_type);
if (m_type == "") {
Console.WriteLine ("Field has unknown Type {0}", c_type);
Statistics.ThrottledCount++;
string type, name;
if (!GetFieldInfo (field, out type, out name))
return false;
}
sw.Write ("\t\t public " + m_type);
if (field.HasAttribute("array_len")) {
sw.Write ("[]");
}
sw.WriteLine (" " + MangleName(field.GetAttribute("cname")) + ";");
sw.WriteLine ("\t\tpublic {0} {1};", type, name);
return true;
}
@ -109,7 +178,10 @@ namespace GtkSharp.Generation {
sw.WriteLine ("\tpublic struct " + Name + " {");
sw.WriteLine ();
GenFields (sw);
sw.WriteLine ();
GenCtors (sw);
GenMethods (sw, null, null, true);
AppendCustom(sw);
sw.WriteLine ("\t}");
@ -118,9 +190,30 @@ namespace GtkSharp.Generation {
protected override void GenCtors (StreamWriter sw)
{
sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) {}");
sw.WriteLine ("\t\tbool _is_null;");
sw.WriteLine ("\t\tpublic bool IsNull {");
sw.WriteLine ("\t\t\tget { return _is_null; }");
sw.WriteLine ("\t\t}");
sw.WriteLine ("\t\tpublic void _Initialize () {");
sw.WriteLine ("\t\t\t_is_null = false;");
sw.WriteLine ("\t\t}");
sw.WriteLine();
//base.GenCtors (sw);
sw.WriteLine ("\t\tpublic static " + QualifiedName + " New(IntPtr raw) {");
sw.WriteLine ("\t\t\t{0} self = new {0}();", QualifiedName);
sw.WriteLine ("\t\t\tif (raw == IntPtr.Zero) {");
sw.WriteLine ("\t\t\t\tself._is_null = true;");
sw.WriteLine ("\t\t\t} else {");
sw.WriteLine ("\t\t\t\tself = ({0}) Marshal.PtrToStructure (raw, self.GetType ());", QualifiedName);
sw.WriteLine ("\t\t\t\tself._is_null = false;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t\treturn self;");
sw.WriteLine ("\t\t}");
sw.WriteLine();
foreach (Ctor ctor in Ctors) {
ctor.ForceStatic = true;
}
base.GenCtors (sw);
}
}

View file

@ -26,6 +26,7 @@ namespace GtkSharp.Generation {
simple_types.Add ("guint", "uint");
simple_types.Add ("glong", "long");
simple_types.Add ("gshort", "short");
simple_types.Add ("gushort", "ushort");
simple_types.Add ("guint32", "uint");
simple_types.Add ("const-gchar", "string");
simple_types.Add ("const-char", "string");
@ -71,6 +72,8 @@ namespace GtkSharp.Generation {
simple_types.Add ("GHashTable", "System.IntPtr");
simple_types.Add ("va_list", "System.IntPtr");
simple_types.Add ("GParamSpec", "System.IntPtr");
simple_types.Add ("GdkAtom", "System.IntPtr");
simple_types.Add ("gconstpointer", "System.IntPtr");
manually_wrapped_types = new Hashtable ();
manually_wrapped_types.Add ("GdkEvent", "Gdk.Event");

View file

@ -2624,7 +2624,7 @@
</parameters>
</method>
</object>
<object name="Pixmap" cname="GdkPixmap" parent="GObject">
<object name="Pixmap" cname="GdkPixmap" parent="GdkDrawable">
<method name="ColormapCreateFromXpm" cname="gdk_pixmap_colormap_create_from_xpm" shared="true">
<return-type type="GdkPixmap*"/>
<parameters>
@ -2752,7 +2752,7 @@
<return-type type="GType"/>
</method>
</object>
<object name="Window" cname="GdkWindow" parent="GObject">
<object name="Window" cname="GdkWindow" parent="GdkDrawable">
<method name="AddFilter" cname="gdk_window_add_filter">
<return-type type="void"/>
<parameters>
@ -3254,7 +3254,7 @@
<return-type type="void"/>
</method>
</object>
<struct name="Bitmap" cname="GdkBitmap">
<object name="Bitmap" cname="GdkBitmap" parent="GdkDrawable">
<field cname="parent_instance" type="GObject"/>
<method name="CreateFromData" cname="gdk_bitmap_create_from_data" shared="true">
<return-type type="GdkBitmap*"/>
@ -3265,7 +3265,7 @@
<parameter type="gint" name="height"/>
</parameters>
</method>
</struct>
</object>
<boxed name="Color" cname="GdkColor">
<field cname="pixel" type="guint32"/>
<field cname="red" type="guint16"/>
@ -9051,7 +9051,7 @@
<return-type type="GtkType"/>
</method>
</object>
<object name="ScrolledWindow" cname="GtkScrolledWindow" parent="GtkBin">
<object name="ScrolledWindow" cname="GtkScrolledWindow" parent="GtkBin" disabledefaultconstructor="1">
<field cname="hscrollbar" type="GtkWidget*"/>
<field cname="vscrollbar" type="GtkWidget*"/>
<field cname="hscrollbar_policy" bits="2" type="guint"/>
@ -9147,7 +9147,6 @@
<parameter type="GtkAdjustment*" name="hadjustment"/>
</parameters>
</method>
<disabledefaultconstructor/>
</object>
<object name="Separator" cname="GtkSeparator" parent="GtkWidget">
<method name="GetType" cname="gtk_separator_get_type" shared="true">

View file

@ -17,7 +17,8 @@ namespace GLib {
/// </remarks>
public class Boxed {
object raw;
object obj;
IntPtr raw;
/// <summary>
/// Boxed Constructor
@ -29,7 +30,12 @@ namespace GLib {
public Boxed (object o)
{
this.raw = raw;
this.obj = obj;
}
public Boxed (IntPtr ptr)
{
this.raw = ptr;
}
/// <summary>
@ -39,8 +45,7 @@ namespace GLib {
/// <remarks>
/// Gets a marshallable IntPtr.
/// </remarks>
public virtual object Obj {
public virtual IntPtr Handle {
get {
return raw;
}
@ -48,5 +53,18 @@ namespace GLib {
raw = value;
}
}
public static explicit operator System.IntPtr (Boxed boxed) {
return boxed.Handle;
}
public virtual object Obj {
get {
return obj;
}
set {
obj = value;
}
}
}
}

View file

@ -1,9 +1,10 @@
// Object.cs - GObject class wrapper implementation
// Opaque .cs - Opaque struct wrapper implementation
//
// Authors: Bob Smith <bob@thestuff.net>
// Mike Kestner <mkestner@speakeasy.net>
// Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2001 Bob Smith and Mike Kestner
// (c) 2001 Bob Smith and Mike Kestner, 2002 Rachel Hestilow
namespace GLib {
@ -24,8 +25,6 @@ namespace GLib {
// Private class and instance members
IntPtr _obj;
EventHandlerList _events;
Hashtable Data;
static Hashtable Opaques = new Hashtable();
/// <summary>
@ -37,7 +36,7 @@ namespace GLib {
/// given raw object pointer. This method is primarily
/// used to wrap object references that are returned
/// by either the signal system or raw class methods that
/// return GObject references.
/// return opaque struct references.
/// </remarks>
///
/// <returns>
@ -52,7 +51,7 @@ namespace GLib {
}
/// <summary>
/// Object Constructor
/// Opaque Constructor
/// </summary>
///
/// <remarks>
@ -62,11 +61,11 @@ namespace GLib {
public Opaque () {}
/// <summary>
/// Object Constructor
/// Opaque Constructor
/// </summary>
///
/// <remarks>
/// Creates an object from a raw object reference.
/// Creates an opaque wrapper from a raw object reference.
/// </remarks>
public Opaque (IntPtr raw)
@ -79,8 +78,8 @@ namespace GLib {
/// </summary>
///
/// <remarks>
/// The raw GObject reference associated with this wrapper.
/// Only subclasses of Object can access this read/write
/// The raw Opaque reference associated with this wrapper.
/// Only subclasses of Opaque can access this read/write
/// property. For public read-only access, use the
/// Handle property.
/// </remarks>
@ -100,7 +99,7 @@ namespace GLib {
/// </summary>
///
/// <remarks>
/// The raw GObject reference associated with this object.
/// The raw Opaque reference associated with this object.
/// Subclasses can use Raw property for read/write
/// access.
/// </remarks>
@ -134,5 +133,9 @@ namespace GLib {
{
return Handle.GetHashCode ();
}
public static explicit operator System.IntPtr (Opaque opaque) {
return opaque.Handle;
}
}
}

View file

@ -288,10 +288,7 @@ namespace GLib {
public static explicit operator GLib.Boxed (Value val)
{
// FIXME: Insert an appropriate exception here if
// _val.type indicates an error.
// FIXME: Figure out how to wrap this boxed type
return null;
return new GLib.Boxed (g_value_get_boxed (val._val));
}
[DllImport("gobject-2.0")]

View file

@ -11,11 +11,15 @@ namespace Gnome
static extern System.IntPtr libgnomeui_module_info_get ();
public static ModuleInfo LibGnome {
get { return new ModuleInfo (libgnome_module_info_get ()); }
get {
return ModuleInfo.New (libgnome_module_info_get ());
}
}
public static ModuleInfo UI {
get { return new ModuleInfo (libgnomeui_module_info_get ()); }
get {
return ModuleInfo.New (libgnomeui_module_info_get ());
}
}
}
}

View file

@ -64,17 +64,4 @@ public void Quit ()
Gtk.Application.Quit ();
}
[DllImport("libgnome-2.so.0")]
static extern System.IntPtr gnome_program_get ();
public static Program Get ()
{
IntPtr raw = gnome_program_get ();
if (raw == IntPtr.Zero)
return null;
Program program = (Program) GLib.Object.GetObject (raw);
if (program == null)
program = new Program (raw);
return program;
}

View file

@ -150,8 +150,7 @@ sub addClassData {
if (0 == scalar @nodes) {
print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n";
my $new_node = $doc->createElement ($$data[5]);
$node->appendChild ($new_node);
$node->setAttribute ($$data[5], $$data[6]);
}
next;
}

View file

@ -41,4 +41,18 @@
</attribute>
</data>
</rule>
<!-- drawable hacks-->
<rule>
<class name="GdkBitmap"/>
<class name="GdkPixmap"/>
<class name="GdkWindow"/>
<data>
<attribute target="class">
<name>parent</name>
<value>GdkDrawable</value>
</attribute>
</data>
</rule>
</metadata>

View file

@ -1205,6 +1205,7 @@
<data>
<attribute target="class">
<name>disabledefaultconstructor</name>
<value>1</value>
</attribute>
</data>
</rule>

View file

@ -150,8 +150,7 @@ sub addClassData {
if (0 == scalar @nodes) {
print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n";
my $new_node = $doc->createElement ($$data[5]);
$node->appendChild ($new_node);
$node->setAttribute ($$data[5], $$data[6]);
}
next;
}

View file

@ -50,6 +50,8 @@ while ($line = <STDIN>) {
$ptrs{$2} = $1;
} elsif ($line =~ /typedef\s+(struct\s+\w+)\s+(\w+);/) {
next if ($2 =~ /Private$/);
# fixme: siiigh
$2 = "GdkDrawable" if ($1 eq "_GdkDrawable");
$types{$2} = $1;
} elsif ($line =~ /typedef\s+(\w+\s+\**)(\w+);/) {
$types{$2} = $1;
@ -324,7 +326,11 @@ foreach $key (sort (keys (%types))) {
$def = "privatestruct";
}
if (exists($boxdefs{$key})) {
# fixme: hack
if ($key eq "GdkBitmap") {
$struct_el = addNameElem($ns_elem, 'object', $key, $ns);
} elsif (exists($boxdefs{$key})) {
$struct_el = addNameElem($ns_elem, 'boxed', $key, $ns);
} else {
$struct_el = addNameElem($ns_elem, 'struct', $key, $ns);

42
sample/Size.cs Normal file
View file

@ -0,0 +1,42 @@
// Size.cs - struct marshalling test
//
// Author: Rachel Hestilow <hestilow@ximian.com>
//
// (c) 2002 Rachel Hestilow
namespace GtkSamples {
using Gtk;
using Gdk;
using GtkSharp;
using System;
public class SizeTest {
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Gtk# Hello World");
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
win.SizeAllocated += new SizeAllocatedHandler (Size_Allocated);
win.ShowAll ();
Application.Run ();
return 0;
}
static void Window_Delete (object obj, DeleteEventArgs args)
{
SignalArgs sa = (SignalArgs) args;
Application.Quit ();
sa.RetVal = true;
}
static void Size_Allocated (object obj, SizeAllocatedArgs args)
{
Gdk.Rectangle rect = args.Allocation;
if (rect.IsNull)
Console.WriteLine ("ERROR: Allocation is null!");
Console.WriteLine ("Size: ({0}, {1})", rect.width, rect.height);
}
}
}

View file

@ -7,6 +7,7 @@
//
using System;
using System.Text;
using Gtk;
using GtkSharp;
@ -59,20 +60,38 @@ namespace WidgetViewer {
window.ColorSelection.HasPalette = ((ToggleButton )o).Active;
}
static string HexFormat (Gdk.Color color)
{
StringBuilder s = new StringBuilder ();
ushort[] vals = { color.red, color.green, color.blue };
char[] hexchars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
s.Append ('#');
foreach (ushort val in vals) {
/* Convert to a range of 0-255, then lookup the
* digit for each half-byte */
byte rounded = (byte) (val >> 8);
s.Append (hexchars[(rounded & 0xf0) >> 4]);
s.Append (hexchars[rounded & 0x0f]);
}
return s.ToString ();
}
static void Color_Changed (object o, EventArgs args)
{
Gdk.Color color = window.ColorSelection.CurrentColor;
Console.WriteLine (HexFormat (color));
}
static void Color_Selection_OK (object o, EventArgs args)
{
Gdk.Color selected = window.ColorSelection.CurrentColor;
/*
if (selected == null) {
if (selected.IsNull) {
Console.WriteLine ("Color selection failed.");
return;
}
*/
Display_Result (selected);
}
@ -85,20 +104,20 @@ namespace WidgetViewer {
static void Display_Result (Gdk.Color color)
{
/*
if (color == null)
if (color.IsNull)
Console.WriteLine ("Null color");
*/
dialog = new Dialog ();
dialog.Title = "Selected Color";
dialog.VBox.PackStart (new Gtk.Label (HexFormat (color)),
false, false, 0);
DrawingArea da = new DrawingArea ();
da.ModifyBg (StateType.Normal, color);
Console.WriteLine (da);
dialog.VBox.PackStart (da, true, true, 0);
dialog.SetDefaultSize (200, 200);
Button button = new Button ("OK");
button.Clicked += new EventHandler (Close_Button);

View file

@ -41,4 +41,18 @@
</attribute>
</data>
</rule>
<!-- drawable hacks-->
<rule>
<class name="GdkBitmap"/>
<class name="GdkPixmap"/>
<class name="GdkWindow"/>
<data>
<attribute target="class">
<name>parent</name>
<value>GdkDrawable</value>
</attribute>
</data>
</rule>
</metadata>

View file

@ -1205,6 +1205,7 @@
<data>
<attribute target="class">
<name>disabledefaultconstructor</name>
<value>1</value>
</attribute>
</data>
</rule>