2002-08-02 Rachel Hestilow <hestilow@ximian.com>

[ Mike, this is everything I wanted in for the release. ]

	* generator/StructBase.cs: Generate field accessors for wrapped
	types (opaque, object, and structs/boxed). Bitfields, unions, and
	arrays are still unsupported for accessors, and are probably marshalling
	incorrectly. But this is enough to get events working (see example
	in sample/GnomeHelloWorld.cs).

	* parser/Metadata.pm: Support a "delete" directive, and set metadata
	on structs and boxed (previously was only checking objects and interfaces).

	* parser/Gdk.metadata: Delete bogus entries GdkWindowObject and
	GdkPixmapObject (more evil drawable stuff.)

	* sample/GnomeHelloWorld.cs: Show an example of how to use marshalled
	events, in our selection callback.

svn path=/trunk/gtk-sharp/; revision=6370
This commit is contained in:
Rachel Hestilow 2002-08-02 22:35:23 +00:00
parent 98d194f861
commit 7648593a67
8 changed files with 96 additions and 47 deletions

View file

@ -1,3 +1,22 @@
2002-08-02 Rachel Hestilow <hestilow@ximian.com>
[ Mike, this is everything I wanted in for the release. ]
* generator/StructBase.cs: Generate field accessors for wrapped
types (opaque, object, and structs/boxed). Bitfields, unions, and
arrays are still unsupported for accessors, and are probably marshalling
incorrectly. But this is enough to get events working (see example
in sample/GnomeHelloWorld.cs).
* parser/Metadata.pm: Support a "delete" directive, and set metadata
on structs and boxed (previously was only checking objects and interfaces).
* parser/Gdk.metadata: Delete bogus entries GdkWindowObject and
GdkPixmapObject (more evil drawable stuff.)
* sample/GnomeHelloWorld.cs: Show an example of how to use marshalled
events, in our selection callback.
2002-07-31 Rachel Hestilow <hestilow@ximian.com>
* generator/StructBase.cs (GetFieldInfo): Generate strings correctly.

View file

@ -108,10 +108,10 @@ namespace GtkSharp.Generation {
}
}
protected bool GetFieldInfo (XmlElement field, out string type, out string name)
protected bool GetFieldInfo (XmlElement field, out string c_type, out string type, out string name)
{
name = "";
string c_type = field.GetAttribute ("type");
c_type = field.GetAttribute ("type");
type = SymbolTable.GetCSType (c_type);
if (IsBit (field)) {
type = "uint";
@ -141,10 +141,35 @@ namespace GtkSharp.Generation {
protected bool GenField (XmlElement field, StreamWriter sw)
{
string type, name;
if (!GetFieldInfo (field, out type, out name))
string c_type, type, name;
if (!GetFieldInfo (field, out c_type, out type, out name))
return false;
sw.WriteLine ("\t\tpublic {0} {1};", type, name);
if (field.HasAttribute("array_len"))
Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name);
string wrapped = SymbolTable.GetCSType (c_type);
string wrapped_name = MangleName (field.GetAttribute ("cname"));
if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type)) {
// FIXME: cut n paste code, remove after introspection completed
sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { ");
sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";");
sw.WriteLine ("\t\t\t\tif (ret == null) ret = new " + wrapped + "(" + name + ");");
sw.WriteLine ("\t\t\t\treturn ret;");
sw.WriteLine ("\t\t\t}");
sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }");
sw.WriteLine ("\t\t}");
} else if (IsPointer (field) && (SymbolTable.IsStruct (c_type) || SymbolTable.IsBoxed (c_type))) {
sw.WriteLine ();
sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {");
sw.WriteLine ("\t\t\tget { return " + SymbolTable.FromNativeReturn (c_type, name) + "; }");
sw.WriteLine ("\t\t}");
}
return true;
}

View file

@ -3565,11 +3565,6 @@
</parameters>
</constructor>
</struct>
<struct name="PixmapObject" cname="GdkPixmapObject">
<field cname="parent_instance" type="GdkDrawable"/>
<field cname="impl" type="GdkDrawable*"/>
<field cname="depth" type="gint"/>
</struct>
<struct name="Point" cname="GdkPoint">
<field cname="x" type="gint"/>
<field cname="y" type="gint"/>
@ -3788,34 +3783,6 @@
<field cname="wmclass_class" type="gchar*"/>
<field cname="override_redirect" type="gboolean"/>
</struct>
<struct name="WindowObject" cname="GdkWindowObject">
<field cname="parent_instance" type="GdkDrawable"/>
<field cname="impl" type="GdkDrawable*"/>
<field cname="parent" type="GdkWindowObject*"/>
<field cname="user_data" type="gpointer"/>
<field cname="x" type="gint"/>
<field cname="y" type="gint"/>
<field cname="extension_events" type="gint"/>
<field cname="filters" type="GList*"/>
<field cname="children" type="GList*"/>
<field cname="bg_color" type="GdkColor"/>
<field cname="bg_pixmap" type="GdkPixmap*"/>
<field cname="paint_stack" type="GSList*"/>
<field cname="update_area" type="GdkRegion*"/>
<field cname="update_freeze_count" type="guint"/>
<field cname="window_type" type="guint8"/>
<field cname="depth" type="guint8"/>
<field cname="resize_count" type="guint8"/>
<field cname="state" type="GdkWindowState"/>
<field cname="guffaw_gravity" bits="1" type="guint"/>
<field cname="input_only" bits="1" type="guint"/>
<field cname="modal_hint" bits="1" type="guint"/>
<field cname="destroyed" bits="2" type="guint"/>
<field cname="event_mask" type="GdkEventMask"/>
<method name="GetType" cname="gdk_window_object_get_type" shared="true">
<return-type type="GType"/>
</method>
</struct>
<alias name="XEvent" cname="GdkXEvent" type="void "/>
</namespace>
<namespace name="Gtk" library="gtk-x11-2.0">
@ -14556,7 +14523,7 @@
<method name="BackwardToTagToggle" cname="gtk_text_iter_backward_to_tag_toggle">
<return-type type="gboolean"/>
<parameters>
<parameter type="GtkTextTag*" name="tag"/>
<parameter type="GtkTextTag*" name="tag" null_ok="1"/>
</parameters>
</method>
<method name="BackwardWordStart" cname="gtk_text_iter_backward_word_start">
@ -14679,7 +14646,7 @@
<method name="ForwardToTagToggle" cname="gtk_text_iter_forward_to_tag_toggle">
<return-type type="gboolean"/>
<parameters>
<parameter type="GtkTextTag*" name="tag"/>
<parameter type="GtkTextTag*" name="tag" null_ok="1"/>
</parameters>
</method>
<method name="ForwardWordEnd" cname="gtk_text_iter_forward_word_end">

View file

@ -46,6 +46,7 @@ sub parseData {
my @attrs = $data_node->attributes;
my $target = $attrs[0]->value;
my ($filter_level, $filter_value, $attr_name, $attr_value);
my $directives = "";
for ($attr_node = $data_node->firstChild; $attr_node != undef; $attr_node = $attr_node->nextSibling ()) {
if ($attr_node->nodeName eq "filter") {
my @filter_attrs = $attr_node->attributes;
@ -55,9 +56,11 @@ sub parseData {
$attr_name = $attr_node->firstChild->nodeValue;
} elsif ($attr_node->nodeName eq "value") {
$attr_value = $attr_node->firstChild->nodeValue;
} elsif ($attr_node->nodeName eq "delete") {
$directives = "delete";
}
}
my @data_attr = ("attribute", $target, "filter", $filter_level, $filter_value, $attr_name, $attr_value);
my @data_attr = ("attribute", $target, "filter", $filter_level, $filter_value, $attr_name, $attr_value, $directives);
push @data, \@data_attr;
}
@ -144,12 +147,16 @@ sub addClassData {
foreach $data (@$data_list_ref) {
if ($$data[1] eq "class") {
if ($$data[7] eq "delete") {
my $parent = $node->parentNode;
$parent->removeChild ($node);
return;
}
# my copy of XML::LibXML doesn't have this method.
#my @nodes = $node->getChildrenByTagName ($$data[5]);
my @nodes = myGetChildrenByTagName ($node, $$data[5]);
if (0 == scalar @nodes) {
print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n";
$node->setAttribute ($$data[5], $$data[6]);
}
next;
@ -163,7 +170,7 @@ sub fixupNamespace {
foreach $rule (@{$self->{rules}}) {
my ($classes_ref, $data_list_ref) = @$rule;
for ($node = $ns_node->firstChild; $node; $node = $node->nextSibling ()) {
next if not ($node->nodeName eq "object" or $node->nodeName eq "interface");
next if not ($node->nodeName eq "object" or $node->nodeName eq "interface" or $node->nodeName eq "struct" or $node->nodeName eq "boxed");
my $class, $methods_ref, $attr;
foreach $attr ($node->attributes) {
if ($attr->name eq "cname") {

View file

@ -54,5 +54,14 @@
</attribute>
</data>
</rule>
<rule>
<class name="GdkPixmapObject"/>
<class name="GdkWindowObject"/>
<data>
<attribute target="class">
<delete/>
</attribute>
</data>
</rule>
</metadata>

View file

@ -46,6 +46,7 @@ sub parseData {
my @attrs = $data_node->attributes;
my $target = $attrs[0]->value;
my ($filter_level, $filter_value, $attr_name, $attr_value);
my $directives = "";
for ($attr_node = $data_node->firstChild; $attr_node != undef; $attr_node = $attr_node->nextSibling ()) {
if ($attr_node->nodeName eq "filter") {
my @filter_attrs = $attr_node->attributes;
@ -55,9 +56,11 @@ sub parseData {
$attr_name = $attr_node->firstChild->nodeValue;
} elsif ($attr_node->nodeName eq "value") {
$attr_value = $attr_node->firstChild->nodeValue;
} elsif ($attr_node->nodeName eq "delete") {
$directives = "delete";
}
}
my @data_attr = ("attribute", $target, "filter", $filter_level, $filter_value, $attr_name, $attr_value);
my @data_attr = ("attribute", $target, "filter", $filter_level, $filter_value, $attr_name, $attr_value, $directives);
push @data, \@data_attr;
}
@ -144,12 +147,16 @@ sub addClassData {
foreach $data (@$data_list_ref) {
if ($$data[1] eq "class") {
if ($$data[7] eq "delete") {
my $parent = $node->parentNode;
$parent->removeChild ($node);
return;
}
# my copy of XML::LibXML doesn't have this method.
#my @nodes = $node->getChildrenByTagName ($$data[5]);
my @nodes = myGetChildrenByTagName ($node, $$data[5]);
if (0 == scalar @nodes) {
print STDERR "DEBUG> $class $$data[0] $$data[1] $$data[2] $$data[3] $$data[4] $$data[5] $$data[6]\n";
$node->setAttribute ($$data[5], $$data[6]);
}
next;
@ -163,7 +170,7 @@ sub fixupNamespace {
foreach $rule (@{$self->{rules}}) {
my ($classes_ref, $data_list_ref) = @$rule;
for ($node = $ns_node->firstChild; $node; $node = $node->nextSibling ()) {
next if not ($node->nodeName eq "object" or $node->nodeName eq "interface");
next if not ($node->nodeName eq "object" or $node->nodeName eq "interface" or $node->nodeName eq "struct" or $node->nodeName eq "boxed");
my $class, $methods_ref, $attr;
foreach $attr ($node->attributes) {
if ($attr->name eq "cname") {

View file

@ -153,9 +153,15 @@ namespace GtkSamples {
void icon_selected_cb (object obj, IconSelectedArgs args)
{
int idx = args.Num;
Event ev = args.Event;
Event ev_any = args.Event;
EventButton ev = EventButton.New (ev_any.Handle);
if (ev.IsValid && ev.Type == EventType.TwoButtonPress) {
// test the accessor, this is unnecessary in real code
Gdk.WindowType type = ev.window.WindowType;
if (type != Gdk.WindowType.Child)
Console.WriteLine ("Struct field accessors appear to be broken.");
if (!ev.IsNull && ev.type == EventType.TwoButtonPress && ev.button == 1) {
g_spawn_command_line_async ("mono " + entries[idx].program, IntPtr.Zero);
}
}

View file

@ -54,5 +54,14 @@
</attribute>
</data>
</rule>
<rule>
<class name="GdkPixmapObject"/>
<class name="GdkWindowObject"/>
<data>
<attribute target="class">
<delete/>
</attribute>
</data>
</rule>
</metadata>