2001-11-24 Mike Kestner <mkestner@speakeasy.net>
* codegen/defs-parse.pl : mkdir the glib/generated dir. (gen_signal): Call new get_sighandler sub. Doesn't use the returned value yet. s/event/ev3nt on arg names. (get_sighandler): new sub to lookup or gen a signal helper/delegate. Only generates the delegate so far. * codegen/hardcoded.defs : Added a stub for Gdk.Event. * gdk/Event.cs : Killed, now a generated struct. * gdk/SimpleEvent.cs (SimpleEventCallback): Use Marshal.PtrToStructure to create the Event, not a ctor(IntPtr). * glib/SignalCallback.cs : New abstract base class for signal helpers. svn path=/trunk/gtk-sharp/; revision=1437
This commit is contained in:
parent
2ce0c470c2
commit
bb8d2c4ee9
6 changed files with 154 additions and 54 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2001-11-24 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
|
* codegen/defs-parse.pl : mkdir the glib/generated dir.
|
||||||
|
(gen_signal): Call new get_sighandler sub. Doesn't use the returned
|
||||||
|
value yet. s/event/ev3nt on arg names.
|
||||||
|
(get_sighandler): new sub to lookup or gen a signal helper/delegate.
|
||||||
|
Only generates the delegate so far.
|
||||||
|
* codegen/hardcoded.defs : Added a stub for Gdk.Event.
|
||||||
|
* gdk/Event.cs : Killed, now a generated struct.
|
||||||
|
* gdk/SimpleEvent.cs (SimpleEventCallback): Use Marshal.PtrToStructure
|
||||||
|
to create the Event, not a ctor(IntPtr).
|
||||||
|
* glib/SignalCallback.cs : New abstract base class for signal helpers.
|
||||||
|
|
||||||
2001-11-14 Mike Kestner <mkestner@speakeasy.net>
|
2001-11-14 Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
|
||||||
* codegen/defs-parse.pl : Add System.Collections to usings.
|
* codegen/defs-parse.pl : Add System.Collections to usings.
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
|
|
||||||
%usings = (
|
%usings = (
|
||||||
'Gdk', "System,System.Collections,System.Runtime.InteropServices,GLib",
|
'GLib', "System,System.Collections,System.Runtime.InteropServices,GLib",
|
||||||
'Gtk', "System,System.Collections,System.Runtime.InteropServices,GLib,Gdk");
|
'Gdk', "System,System.Collections,System.Runtime.InteropServices,GLib,Gdk",
|
||||||
|
'Gtk', "System,System.Collections,System.Runtime.InteropServices,GLib,Gdk,Gtk",
|
||||||
|
'GtkSharp', "System,System.Collections,System.Runtime.InteropServices,GLib,Gdk,Gtk");
|
||||||
|
|
||||||
|
`mkdir -p ../glib/generated`;
|
||||||
`mkdir -p ../gdk/generated`;
|
`mkdir -p ../gdk/generated`;
|
||||||
`mkdir -p ../gtk/generated`;
|
`mkdir -p ../gtk/generated`;
|
||||||
|
|
||||||
|
@ -241,7 +244,6 @@ sub gen_object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "Generating Class $typename in $dir/$typename.cs\n";
|
|
||||||
open (OUTFILE, ">$dir/$typename.cs") || die "can't open file";
|
open (OUTFILE, ">$dir/$typename.cs") || die "can't open file";
|
||||||
|
|
||||||
print OUTFILE "// Generated file: Do not modify\n\n";
|
print OUTFILE "// Generated file: Do not modify\n\n";
|
||||||
|
@ -299,13 +301,12 @@ sub gen_object
|
||||||
print OUTFILE `cat $custom` if -e $custom;
|
print OUTFILE `cat $custom` if -e $custom;
|
||||||
print OUTFILE "\t}\n}\n";
|
print OUTFILE "\t}\n}\n";
|
||||||
close (OUTFILE);
|
close (OUTFILE);
|
||||||
print "done\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub gen_signal
|
sub gen_signal
|
||||||
{
|
{
|
||||||
my ($name, $def, $dll) = @_;
|
my ($name, $def, $dll) = @_;
|
||||||
my ($cname, @plist, $ret, $sret, $mret, $code);
|
my ($marsh, $cname, @plist, $ret, $sret, $mret, $code);
|
||||||
|
|
||||||
$def =~ /define-signal (\w+)/;
|
$def =~ /define-signal (\w+)/;
|
||||||
$cname = "\"$1\"";
|
$cname = "\"$1\"";
|
||||||
|
@ -316,6 +317,8 @@ sub gen_signal
|
||||||
$def =~ /parameters\s*'\((.*)\)\)\)/;
|
$def =~ /parameters\s*'\((.*)\)\)\)/;
|
||||||
@plist = split(/\)'\(/, $1);
|
@plist = split(/\)'\(/, $1);
|
||||||
|
|
||||||
|
$marsh = get_sighandler ($def);
|
||||||
|
|
||||||
if (($ret eq "none") && (@plist == 1)) {
|
if (($ret eq "none") && (@plist == 1)) {
|
||||||
$marsh = "SimpleSignal";
|
$marsh = "SimpleSignal";
|
||||||
} elsif (($ret eq "gboolean") && (@plist == 2) &&
|
} elsif (($ret eq "gboolean") && (@plist == 2) &&
|
||||||
|
@ -494,6 +497,7 @@ sub gen_param_strings
|
||||||
$ptype = $1;
|
$ptype = $1;
|
||||||
$pname = $2;
|
$pname = $2;
|
||||||
$pname =~ s/object/objekt/;
|
$pname =~ s/object/objekt/;
|
||||||
|
$pname =~ s/event/ev3nt/;
|
||||||
if ($sig) {
|
if ($sig) {
|
||||||
$sig .= ', ';
|
$sig .= ', ';
|
||||||
$call .= ', ';
|
$call .= ', ';
|
||||||
|
@ -518,3 +522,66 @@ sub gen_param_strings
|
||||||
return ($call, $pinv, $sig);
|
return ($call, $pinv, $sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_sighandler
|
||||||
|
{
|
||||||
|
my ($def) = @_;
|
||||||
|
my ($key, $name, $sname, $dname, $dir, $ns, $nspace, $tok);
|
||||||
|
|
||||||
|
$def =~ /return-type \"(\w+)\"/;
|
||||||
|
my $ret = $1;
|
||||||
|
|
||||||
|
$def =~ /parameters'\((.*)\)\)\)/;
|
||||||
|
my @parms = split(/\)'\(/, $1);
|
||||||
|
|
||||||
|
for ($i = 1; $i < @parms; $i++) {
|
||||||
|
$parms[$i] =~ /^\"(\w+)/;
|
||||||
|
$key .= ":$1";
|
||||||
|
}
|
||||||
|
$key = $ret . $key;
|
||||||
|
|
||||||
|
if (exists($sighandlers{$key})) {
|
||||||
|
return $sighandlers{$key};
|
||||||
|
}
|
||||||
|
|
||||||
|
my ($call, $pinv, $sig) = gen_param_strings($def);
|
||||||
|
|
||||||
|
if ($key =~ /Gtk/) {
|
||||||
|
$dir = "../gtk/generated";
|
||||||
|
$nspace = "Gtk";
|
||||||
|
} elsif ($key =~ /Gdk/) {
|
||||||
|
$dir = "../gdk/generated";
|
||||||
|
$nspace = "Gdk";
|
||||||
|
} else {
|
||||||
|
$dir = "../glib/generated";
|
||||||
|
$nspace = "GLib";
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = "";
|
||||||
|
foreach $tok (split(/:/, $key)) {
|
||||||
|
if (exists($objects{$tok})) {
|
||||||
|
$name .= "Object";
|
||||||
|
} elsif (exists($maptypes{$tok})) {
|
||||||
|
$name .= "$maptypes{$tok}";
|
||||||
|
} else {
|
||||||
|
die "Whassup with $tok?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sname = $name . "Signal";
|
||||||
|
$dname = $name . "Delegate";
|
||||||
|
|
||||||
|
$sighandlers{$key} = $name;
|
||||||
|
|
||||||
|
open (SIGFILE, ">$dir/$sname.cs") || die "can't open file";
|
||||||
|
|
||||||
|
print SIGFILE "// Generated file: Do not modify\n\n";
|
||||||
|
print SIGFILE "namespace GtkSharp {\n\n";
|
||||||
|
foreach $ns (split (/,/, $usings{$nspace})) {
|
||||||
|
print SIGFILE "\tusing $ns;\n";
|
||||||
|
}
|
||||||
|
print SIGFILE "\tpublic delegate $marshaltypes{$ret} ";
|
||||||
|
print SIGFILE "$dname($pinv, int key);\n\n";
|
||||||
|
print SIGFILE "}\n";
|
||||||
|
close (SIGFILE);
|
||||||
|
|
||||||
|
return $sighandlers{$key};
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,14 @@
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(define-struct Event
|
||||||
|
(in-module "Gdk")
|
||||||
|
(c-name "GdkEvent")
|
||||||
|
(fields
|
||||||
|
'("GdkEventType" "type")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
(define-struct AccelEntry
|
(define-struct AccelEntry
|
||||||
(in-module "Gtk")
|
(in-module "Gtk")
|
||||||
(c-name "GtkAccelEntry")
|
(c-name "GtkAccelEntry")
|
||||||
|
|
47
gdk/Event.cs
47
gdk/Event.cs
|
@ -1,47 +0,0 @@
|
||||||
namespace Gdk {
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
public class Event
|
|
||||||
{
|
|
||||||
public Event(IntPtr e)
|
|
||||||
{
|
|
||||||
_event = e;
|
|
||||||
}
|
|
||||||
protected IntPtr _event;
|
|
||||||
public EventType Type
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
IntPtr ptr = Marshal.ReadIntPtr (_event);
|
|
||||||
return (EventType)((int)ptr);
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Marshal.WriteIntPtr(_event, new IntPtr((int)value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: Fix or kill later.
|
|
||||||
public EventAny Any
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (EventAll)this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static explicit operator EventAll (Event e)
|
|
||||||
{
|
|
||||||
return Marshal.PtrToStructure(e._event, EventAll);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct EventAny
|
|
||||||
{
|
|
||||||
public IntPtr type;
|
|
||||||
public IntPtr window;
|
|
||||||
public SByte send_event;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -71,8 +71,9 @@ namespace Gdk {
|
||||||
throw new Exception ("Unexpected event key");
|
throw new Exception ("Unexpected event key");
|
||||||
|
|
||||||
SimpleEvent se = (SimpleEvent) _Instances [inst_key];
|
SimpleEvent se = (SimpleEvent) _Instances [inst_key];
|
||||||
EventArgs args = new SimpleEventArgs (
|
Event evnt = new Event ();
|
||||||
new Gdk.Event (e));
|
Marshal.PtrToStructure (e, evnt);
|
||||||
|
EventArgs args = new SimpleEventArgs (evnt);
|
||||||
se._handler (se._obj, args);
|
se._handler (se._obj, args);
|
||||||
return true; //FIXME: How do we manage the return value?
|
return true; //FIXME: How do we manage the return value?
|
||||||
}
|
}
|
||||||
|
|
58
glib/SignalCallback.cs
Normal file
58
glib/SignalCallback.cs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// GtkSharp.SignalCallback.cs - Signal callback base class implementation
|
||||||
|
//
|
||||||
|
// Authors: Mike Kestner <mkestner@speakeasy.net>
|
||||||
|
//
|
||||||
|
// (c) 2001 Mike Kestner
|
||||||
|
|
||||||
|
namespace GtkSharp {
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using GLib;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SignalCallback Class
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <remarks>
|
||||||
|
/// Base Class for GSignal to C# event marshalling.
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
public abstract class SignalCallback {
|
||||||
|
|
||||||
|
// A counter used to produce unique keys for instances.
|
||||||
|
protected static int _NextKey = 0;
|
||||||
|
|
||||||
|
// Hashtable containing refs to all current instances.
|
||||||
|
protected static Hashtable _Instances = new Hashtable ();
|
||||||
|
|
||||||
|
// protected instance members
|
||||||
|
protected GLib.Object _obj;
|
||||||
|
protected EventHandler _handler;
|
||||||
|
protected int _key;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SignalCallback Constructor
|
||||||
|
/// </summary>
|
||||||
|
///
|
||||||
|
/// <remarks>
|
||||||
|
/// Initializes instance data.
|
||||||
|
/// </remarks>
|
||||||
|
|
||||||
|
public SignalCallback (GLib.Object obj, IntPtr raw,
|
||||||
|
String name, EventHandler eh)
|
||||||
|
{
|
||||||
|
_key = _NextKey++;
|
||||||
|
_obj = obj;
|
||||||
|
_handler = eh;
|
||||||
|
_Instances [_key] = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor needed to release references from the instance
|
||||||
|
// table and unpin the delegate if no refs remain.
|
||||||
|
~SignalCallback ()
|
||||||
|
{
|
||||||
|
_Instances.Remove (_key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue