From 354b3062744cc032b62d34342a9df5f750ff8c9f Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 4 Dec 2001 19:34:26 +0000 Subject: [PATCH] 2001-12-04 Mike Kestner * 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 --- ChangeLog | 9 +++++++++ codegen/defs-parse.pl | 36 ++++++++++++++++++++++++++++-------- gdk/SimpleEvent.cs | 1 + sample/HelloWorld.cs | 10 ++++++---- sample/makefile | 2 +- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0f6517a50..abcf23e38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2001-12-04 Mike Kestner + + * 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 * makefile : Make ROOT /cygdrive/, not //. diff --git a/codegen/defs-parse.pl b/codegen/defs-parse.pl index 63bb7330b..35f2919ea 100755 --- a/codegen/defs-parse.pl +++ b/codegen/defs-parse.pl @@ -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/// \n\t///\tFIXME: Add docs.\n"; print OUTFILE "\t/// \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"; diff --git a/gdk/SimpleEvent.cs b/gdk/SimpleEvent.cs index 8a413a573..b21bc5b1a 100644 --- a/gdk/SimpleEvent.cs +++ b/gdk/SimpleEvent.cs @@ -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? diff --git a/sample/HelloWorld.cs b/sample/HelloWorld.cs index 2f3cdd638..b12fa968e 100755 --- a/sample/HelloWorld.cs +++ b/sample/HelloWorld.cs @@ -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 (); } diff --git a/sample/makefile b/sample/makefile index 3ac05158e..ab47636e7 100755 --- a/sample/makefile +++ b/sample/makefile @@ -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: