2001-12-04 Mike Kestner <mkestner@speakeasy.net>

* codegen/defs-parse.pl : Index %structs by cname, not name. Derive
	  structs from class to facilitate marshalling since Value types can't
	  use the Marshal.PtrToStructure method. Generate StructLayout attr
	  for struct class defs. Stuff the signal args into a SignalArgs inst
	  to pass to the EventHandlers.
	* sample/HelloWorld.cs : some cleanup and temporary signal playcode.

svn path=/trunk/gtk-sharp/; revision=1526
This commit is contained in:
Mike Kestner 2001-12-04 19:34:26 +00:00
parent 82646f231e
commit 354b306274
5 changed files with 45 additions and 13 deletions

View File

@ -1,3 +1,12 @@
2001-12-04 Mike Kestner <mkestner@speakeasy.net>
* codegen/defs-parse.pl : Index %structs by cname, not name. Derive
structs from class to facilitate marshalling since Value types can't
use the Marshal.PtrToStructure method. Generate StructLayout attr
for struct class defs. Stuff the signal args into a SignalArgs inst
to pass to the EventHandlers.
* sample/HelloWorld.cs : some cleanup and temporary signal playcode.
2001-12-01 Mike Kestner <mkestner@speakeasy.net>
* makefile : Make ROOT /cygdrive/, not //.

View File

@ -36,7 +36,7 @@ while ($def = get_def()) {
$def =~ /c-name "(\w+)"/;
$cname=$1;
$def =~ s/\n\s*//g;
$structs{$name} = $def;
$structs{$cname} = $def;
$maptypes{$cname} = $name;
$marshaltypes{$cname} = $name;
} elsif ($def =~ /^\(define-object (\w+)/) {
@ -172,18 +172,16 @@ sub gen_enum
close (OUTFILE);
}
# Code generation for the structure definitions.
sub gen_struct
{
my ($name, $def) = @_;
my ($cname, $def) = @_;
$def =~ /c-name "(\w+)"/;
$cname = $1;
$def =~ /define-struct (\w+)/;
$name = $1;
$def =~ /in-module "(\w+)"/;
$namespace = $1;
$maptypes{$cname} = $name;
$marshaltypes{$cname} = $name;
$dir = "../" . lc ($namespace) . "/generated";
open (OUTFILE, ">$dir/$name.cs") || die "can't open file";
@ -196,7 +194,8 @@ sub gen_struct
print OUTFILE "\t/// <remarks>\n\t///\tFIXME: Add docs.\n";
print OUTFILE "\t/// </remarks>\n\n";
print OUTFILE "\tpublic struct $name {\n";
print OUTFILE "\t[StructLayout(LayoutKind.Sequential)]\n";
print OUTFILE "\tpublic class $name {\n";
if ($def =~ /fields'\((.*)\)\)\)/) {
foreach $parm (split(/\)'\(/, $1)) {
@ -303,6 +302,7 @@ sub gen_object
close (OUTFILE);
}
# Code generation for signal definitions.
sub gen_signal
{
my ($name, $def, $dll) = @_;
@ -344,6 +344,7 @@ sub gen_signal
return $code;
}
# Code generation for property definitions.
sub gen_prop
{
my ($name, $def, $dll) = @_;
@ -522,6 +523,7 @@ sub gen_param_strings
return ($call, $pinv, $sig);
}
# Code generation for signal handlers.
sub get_sighandler
{
my ($def) = @_;
@ -589,6 +591,24 @@ sub get_sighandler
print SIGFILE "\t\t\t\tthrow new Exception(\"Unexpected signal key\");";
print SIGFILE "\n\n\t\t\t$sname inst = ($sname) _Instances[key];\n";
print SIGFILE "\t\t\tSignalArgs args = new SignalArgs ();\n";
if ($def =~ /parameters'\((.*)\)\)\)/) {
my (@parms) = split(/\)'\(/, $1);
print "$sname pcnt=$#parms\n";
for ($idx=0; $idx < $#parms; $idx++) {
$parms[$idx+1] =~ s/\*//g;
$parms[$idx+1] =~ /"(\S*)" "(\S*)"/;
$ptype = $1;
$pname = $2;
$pname =~ s/object/objekt/;
$pname =~ s/event/ev3nt/;
print "$ptype $pname\n";
if (exists($objects{$ptype})) {
print SIGFILE "\t\t\targs.Args[$idx] = GLib.Object.GetObject($pname);\n";
} elsif (exists($maptypes{$ptype})) {
print SIGFILE "\t\t\targs.Args[$idx] = $pname;\n";
} else { warn "Whassup wit $ptype?"; }
}
}
print SIGFILE "\t\t\tinst._handler (inst._obj, args);\n";
if ($ret ne "none") {
print SIGFILE "\t\t\treturn ($maptypes{$ret}) args.RetVal;\n";

View File

@ -73,6 +73,7 @@ namespace Gdk {
SimpleEvent se = (SimpleEvent) _Instances [inst_key];
Event evnt = new Event ();
Marshal.PtrToStructure (e, evnt);
// Marshal.PtrToStructure (e, (object) evnt);
EventArgs args = new SimpleEventArgs (evnt);
se._handler (se._obj, args);
return true; //FIXME: How do we manage the return value?

View File

@ -7,6 +7,8 @@
namespace GtkSamples {
using Gtk;
using Gdk;
using GtkSharp;
using System;
using System.Drawing;
@ -16,10 +18,7 @@ namespace GtkSamples {
{
Application.Init (ref args);
Window win = new Window ("Gtk# Hello World");
win.DefaultSize = new Size (400, 400);
System.Console.WriteLine (win.Title);
System.Console.WriteLine (win.DefaultSize);
System.Console.WriteLine (win.AllowShrink);
win.DefaultSize = new Size (200, 150);
win.Deleted += new EventHandler (Window_Delete);
win.Show ();
Application.Run ();
@ -28,6 +27,9 @@ namespace GtkSamples {
static void Window_Delete (object obj, EventArgs args)
{
SimpleEventArgs sa = (SimpleEventArgs) args;
Console.WriteLine(sa.Event.type);
Application.Quit ();
}

View File

@ -3,7 +3,7 @@ all:
@echo "'make unix' is broken for now."
windows:
$(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll HelloWorld.cs
$(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll /r:../gdk/gdk-sharp.dll HelloWorld.cs
$(CSC) /unsafe /out:button.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll ButtonApp.cs
unix: