From b2f04c1d8016037b1257c57072fd4663d38148f0 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sun, 27 Oct 2002 02:30:51 +0000 Subject: [PATCH] 2002-10-26 Mike Kestner Much of this patch from Vlad, with substantial rework by mk. * */makefile.win32 : introduce mapdllnames.pl, api, and glue * generator/CallbackGen.cs : rework namespacing for csc compilation * generator/Parameters.cs : ditto * generator/Signal.cs : ditto * generator/SignalHandler.cs : ditto * glue/win32dll.c : new dll construction source * glib/Value.cs : new ushort ctor/cast operator * gtk/Table.custom : comment this out until we add a default ctor tag * gtk/ThreadNotify.cs : make ReadyEvent public * sources/Gdk.metadata : mark a Parse() param as ref svn path=/trunk/gtk-sharp/; revision=8590 --- ChangeLog | 14 ++++++++++++++ api/makefile.win32 | 6 ++++++ atk/makefile.win32 | 1 + gdk/makefile.win32 | 5 ++++- generator/CallbackGen.cs | 14 +++++++------- generator/Parameters.cs | 6 ++---- generator/Signal.cs | 10 +++++----- generator/SignalHandler.cs | 10 ++++------ generator/makefile.win32 | 1 - glib/Value.cs | 31 +++++++++++++++++++++++++++++++ glib/makefile.win32 | 5 ++++- glue/makefile.win32 | 34 ++++++++++++++++++++++++++++++++++ glue/win32dll.c | 16 ++++++++++++++++ gtk/Table.custom | 2 ++ gtk/ThreadNotify.cs | 2 +- gtk/makefile.win32 | 5 ++++- makefile.win32 | 8 ++++---- mapdllnames.pl | 37 +++++++++++++++++++++++++++++++++++++ pango/makefile.win32 | 1 + sources/Gdk.metadata | 14 ++++++++++++++ 20 files changed, 191 insertions(+), 31 deletions(-) create mode 100755 api/makefile.win32 create mode 100755 glue/makefile.win32 create mode 100755 glue/win32dll.c create mode 100755 mapdllnames.pl diff --git a/ChangeLog b/ChangeLog index 78d293399..4889898fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-10-26 Mike Kestner + + Much of this patch from Vlad, with substantial rework by mk. + * */makefile.win32 : introduce mapdllnames.pl, api, and glue + * generator/CallbackGen.cs : rework namespacing for csc compilation + * generator/Parameters.cs : ditto + * generator/Signal.cs : ditto + * generator/SignalHandler.cs : ditto + * glue/win32dll.c : new dll construction source + * glib/Value.cs : new ushort ctor/cast operator + * gtk/Table.custom : comment this out until we add a default ctor tag + * gtk/ThreadNotify.cs : make ReadyEvent public + * sources/Gdk.metadata : mark a Parse() param as ref + 2002-10-26 Ettore Perazzoli * glib/Object.cs: Changed so that Objects is a hash of diff --git a/api/makefile.win32 b/api/makefile.win32 new file mode 100755 index 000000000..7233d2847 --- /dev/null +++ b/api/makefile.win32 @@ -0,0 +1,6 @@ +all: generated-stamp + +generated-stamp: atk-api.xml gdk-api.xml gdk-symbols.xml gtk-api.xml gtk-symbols.xml pango-api.xml ../generator/codegen.exe + ../generator/codegen --generate atk-api.xml gdk-api.xml gdk-symbols.xml gtk-api.xml gtk-symbols.xml pango-api.xml + touch generated-stamp + diff --git a/atk/makefile.win32 b/atk/makefile.win32 index 9e9ec49c4..bfa646551 100644 --- a/atk/makefile.win32 +++ b/atk/makefile.win32 @@ -1,6 +1,7 @@ all: windows windows: + ../mapdllnames.pl generated/*.cs $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /out:atk-sharp.dll /recurse:*.cs docs: diff --git a/gdk/makefile.win32 b/gdk/makefile.win32 index 2e62fed7b..2f6e6c253 100644 --- a/gdk/makefile.win32 +++ b/gdk/makefile.win32 @@ -1,7 +1,10 @@ all: windows windows: - $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /out:gdk-sharp.dll /recurse:*.cs + cat *.cs generated/*.cs > allthesource.cs + ../mapdllnames.pl allthesource.cs + $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /out:gdk-sharp.dll allthesource.cs + rm allthesource.cs docs: $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /doc:gdk-sharp-docs.xml /out:gdk-sharp.dll /recurse:*.cs diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 6e23be5a9..28b3b8da5 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -23,7 +23,7 @@ namespace GtkSharp.Generation { public String MarshalType { get { - return "GtkSharp." + NS + Name + "Native"; + return NS + "Sharp." + Name + "Native"; } } @@ -57,9 +57,9 @@ namespace GtkSharp.Generation { if (!Directory.Exists (dir)) Directory.CreateDirectory (dir); - string wrapper = NS + Name + "Native"; + string wrapper = Name + "Native"; - string filename = dir + sep + "GtkSharp." + wrapper + ".cs"; + string filename = dir + sep + NS + "Sharp." + wrapper + ".cs"; FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter (stream); @@ -67,10 +67,10 @@ namespace GtkSharp.Generation { sw.WriteLine ("// Generated File. Do not modify."); sw.WriteLine ("// 2001-2002 Mike Kestner"); sw.WriteLine (); - sw.WriteLine ("namespace GtkSharp {"); + sw.WriteLine ("namespace " + NS + "Sharp {"); sw.WriteLine (); sw.WriteLine ("\tusing System;"); - sw.WriteLine ("\tusing System.Collections;"); + sw.WriteLine (); string import_sig; if (parms != null) @@ -87,7 +87,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\tpublic delegate " + m_ret + " " + wrapper + "(" + import_sig + ");"); sw.WriteLine (); - sw.WriteLine ("\tpublic class " + NS + Name + "Wrapper : GLib.DelegateWrapper {"); + sw.WriteLine ("\tpublic class " + Name + "Wrapper : GLib.DelegateWrapper {"); sw.WriteLine (); sw.WriteLine ("\t\tpublic " + m_ret + " NativeCallback (" + import_sig + ")"); @@ -147,7 +147,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\tprotected {0} _managed;", NS + "." + Name); sw.WriteLine (); - sw.WriteLine ("\t\tpublic {0} ({1} managed) : base ()", NS + Name + "Wrapper", NS + "." + Name); + sw.WriteLine ("\t\tpublic {0} ({1} managed) : base ()", Name + "Wrapper", NS + "." + Name); sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t\tNativeDelegate = new {0} (NativeCallback);", wrapper); diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 46380503d..ed78c6263 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -215,8 +215,7 @@ namespace GtkSharp.Generation { if (SymbolTable.IsCallback (type)) { call_parm = SymbolTable.CallByName (type, call_parm_name + "_wrapper"); - callback_type = type.Replace (".", ""); - callback_type = "GtkSharp." + callback_type + "Wrapper"; + callback_type = type.Replace(".", "Sharp.") + "Wrapper"; } else call_parm = SymbolTable.CallByName(type, call_parm_name); @@ -344,8 +343,7 @@ namespace GtkSharp.Generation { name = MangleName(p_elem.GetAttribute("name")); if (SymbolTable.IsCallback (c_type)) { - type = type.Replace (".", ""); - type = "GtkSharp." + type + "Wrapper"; + type = type.Replace(".", "Sharp.") + "Wrapper"; sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", type, name); sw.Write (indent + "\t\t\t"); diff --git a/generator/Signal.cs b/generator/Signal.cs index 8ca54d45e..abcdbcee2 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -57,7 +57,7 @@ namespace GtkSharp.Generation { string argsname; string handler = GetHandlerName (out argsname); if (handler != "EventHandler") - handler = "GtkSharp." + handler; + handler = container_type.NS + "Sharp." + handler; GenComments (sw); if (elem.HasAttribute("new_flag") || (container_type != null && container_type.GetSignalRecursively (Name) != null)) @@ -98,7 +98,7 @@ namespace GtkSharp.Generation { if (!Directory.Exists (dir)) Directory.CreateDirectory (dir); - string filename = dir + sep + "GtkSharp." + handler + ".cs"; + string filename = dir + sep + container_type.NS + "Sharp." + handler + ".cs"; FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter (stream); @@ -106,7 +106,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("// Generated File. Do not modify."); sw.WriteLine ("// 2001-2002 Mike Kestner"); sw.WriteLine (); - sw.WriteLine ("namespace GtkSharp {"); + sw.WriteLine ("namespace " + container_type.NS + "Sharp {"); sw.WriteLine (); sw.WriteLine ("\tusing System;"); @@ -138,13 +138,13 @@ namespace GtkSharp.Generation { sw.WriteLine ("}"); sw.Close (); argsname = "GtkSharp." + argsname; - return "GtkSharp." + handler; + return container_type.NS + "Sharp." + handler; } public void Generate (StreamWriter sw, ClassBase implementor, bool gen_docs) { string cname = "\"" + elem.GetAttribute("cname") + "\""; - string qual_marsh = "GtkSharp." + marsh; + string qual_marsh = marsh; if (gen_docs) GenComments (sw); diff --git a/generator/SignalHandler.cs b/generator/SignalHandler.cs index fc8fc1809..1b17e811f 100644 --- a/generator/SignalHandler.cs +++ b/generator/SignalHandler.cs @@ -88,7 +88,7 @@ namespace GtkSharp.Generation { Directory.CreateDirectory(dir); } - String filename = dir + sep + sname + ".cs"; + String filename = dir + sep + ns + "Sharp." + sname + ".cs"; FileStream stream = new FileStream (filename, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter (stream); @@ -96,12 +96,11 @@ namespace GtkSharp.Generation { sw.WriteLine ("// Generated File. Do not modify."); sw.WriteLine ("// 2001-2002 Mike Kestner"); sw.WriteLine (); - sw.WriteLine("namespace GtkSharp {"); - sw.WriteLine(); - sw.WriteLine("namespace " + ns + " {"); + sw.WriteLine("namespace " + ns + "Sharp {"); sw.WriteLine(); sw.WriteLine("\tusing System;"); sw.WriteLine("\tusing System.Runtime.InteropServices;"); + sw.WriteLine("\tusing GtkSharp;"); sw.WriteLine(); sw.Write("\tpublic delegate " + p_ret + " "); sw.WriteLine(dname + "(" + pinv + ", int key);"); @@ -189,10 +188,9 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\t}"); sw.WriteLine("\t}"); sw.WriteLine("}"); - sw.WriteLine("}"); sw.Close(); - return ns + "." + sname; + return ns + "Sharp." + sname; } } } diff --git a/generator/makefile.win32 b/generator/makefile.win32 index c7d2de699..177d2e2bb 100644 --- a/generator/makefile.win32 +++ b/generator/makefile.win32 @@ -2,7 +2,6 @@ all: windows windows: *.cs $(CSC) /unsafe /out:codegen.exe *.cs - ./codegen gtkapi.xml docs: windows diff --git a/glib/Value.cs b/glib/Value.cs index 1e3888a67..76d0816a7 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -244,6 +244,20 @@ namespace GLib { g_value_set_uint (_val, val); } + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value from a specified ushort. + /// + + public Value (ushort val) + { + _val = gtksharp_value_create (TypeFundamentals.TypeUInt); + g_value_set_uint (_val, val); + } + [DllImport("gobject-2.0")] static extern void g_value_set_enum (IntPtr val, int data); [DllImport("gobject-2.0")] @@ -467,6 +481,23 @@ namespace GLib { return g_value_get_uint (val._val); } + /// + /// Value to Unsigned Short Conversion + /// + /// + /// + /// Extracts a ushort from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// unsigned integer value. + /// + + public static explicit operator ushort (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return (ushort) g_value_get_uint (val._val); + } + [DllImport("gobject-2.0")] static extern int g_value_get_enum (IntPtr val); [DllImport("gobject-2.0")] diff --git a/glib/makefile.win32 b/glib/makefile.win32 index 6e63149fd..dc420f8ff 100644 --- a/glib/makefile.win32 +++ b/glib/makefile.win32 @@ -1,7 +1,10 @@ all: windows windows: - $(CSC) /unsafe /target:library /out:glib-sharp.dll /recurse:*.cs + cat *.cs > allthesource.cs + ../mapdllnames.pl allthesource.cs + $(CSC) /unsafe /target:library /out:glib-sharp.dll allthesource.cs + rm allthesource.cs docs: $(CSC) /unsafe /target:library /doc:glib-sharp-docs.xml /out:glib-sharp.dll /recurse:*.cs diff --git a/glue/makefile.win32 b/glue/makefile.win32 new file mode 100755 index 000000000..dec806098 --- /dev/null +++ b/glue/makefile.win32 @@ -0,0 +1,34 @@ +GTK_CFLAGS=`pkg-config --cflags gtk+-win32-2.0` +GTK_LIBS=`pkg-config --libs gtk+-win32-2.0` +CC=gcc -b i686-pc-mingw32 +DLLWRAP=dllwrap --mno-cygwin --target i386-mingw32 --export-all-symbols + +GLUE_OBJS = \ + adjustment.o \ + dialog.o \ + error.o \ + event.o \ + fileselection.o \ + list.o \ + object.o \ + paned.o \ + slist.o \ + style.o \ + type.o \ + value.o \ + widget.o \ + win32dll.o + +all: gtksharpglue.dll + + +%.o: %.c + $(CC) -c $(CFLAGS) $(GTK_CFLAGS) -o $@ $^ + + +gtksharpglue.dll: $(GLUE_OBJS) + $(DLLWRAP) --output-lib=libgtksharpglue.a --dllname=gtksharpglue.dll --driver-name=gcc --output-def=gtksharpglue.def $(GLUE_OBJS) $(GTK_LIBS) + + +clean: + rm -f gtksharpglue.dll *.o libgtksharpglue.a diff --git a/glue/win32dll.c b/glue/win32dll.c new file mode 100755 index 000000000..a2b42a95c --- /dev/null +++ b/glue/win32dll.c @@ -0,0 +1,16 @@ +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#include + +BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved) +{ + return TRUE; +} + + +BOOL APIENTRY DllMainCRTStartup (HINSTANCE hInst, DWORD reason, LPVOID reserved) +{ + return TRUE; +} + diff --git a/gtk/Table.custom b/gtk/Table.custom index 374b40b46..2b4b8e4c6 100644 --- a/gtk/Table.custom +++ b/gtk/Table.custom @@ -1,4 +1,6 @@ +/* FIXME: Uncomment this when the default ctor flag is added to the XML public Table() { Raw = gtk_table_new (0, 0, false); } +*/ diff --git a/gtk/ThreadNotify.cs b/gtk/ThreadNotify.cs index afae2fdf7..d939cc66c 100644 --- a/gtk/ThreadNotify.cs +++ b/gtk/ThreadNotify.cs @@ -16,7 +16,7 @@ namespace Gtk { // // This delegate will be invoked on the main Gtk thread. // - delegate void ReadyEvent (); + public delegate void ReadyEvent (); /// /// Utility class to help writting multi-threaded Gtk applications diff --git a/gtk/makefile.win32 b/gtk/makefile.win32 index 829d6fcc7..2ab7e09dd 100644 --- a/gtk/makefile.win32 +++ b/gtk/makefile.win32 @@ -1,7 +1,10 @@ all: windows windows: - $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /r:../gdk/gdk-sharp.dll /out:gtk-sharp.dll /recurse:*.cs + cat *.cs generated/*.cs > allthesource.cs + ../mapdllnames.pl allthesource.cs + $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /r:../gdk/gdk-sharp.dll /out:gtk-sharp.dll allthesource.cs + rm allthesource.cs docs: $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /r:../atk/atk-sharp.dll /r:../gdk/gdk-sharp.dll /doc:gtk-sharp-docs.xml /out:gtk-sharp.dll /recurse:*.cs diff --git a/makefile.win32 b/makefile.win32 index 92e4e217a..1e66a11f0 100755 --- a/makefile.win32 +++ b/makefile.win32 @@ -1,16 +1,16 @@ -DIRS=generator glib pango atk gdk gtk gnome sample +DIRS=glue generator api glib pango atk gdk gtk sample ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) -CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe +CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe /d:WIN32 all: windows windows: for i in $(DIRS); do \ - (cd $$i; CSC=$(CSC) make -f makefile.win32) || exit 1;\ + (cd $$i; CSC="$(CSC)" make -f makefile.win32) || exit 1;\ done; docs: for i in $(DIRS); do \ - (cd $$i; CSC=$(CSC) make -f makefile.win32 docs) || exit 1;\ + (cd $$i; CSC="$(CSC)" make -f makefile.win32 docs) || exit 1;\ done; diff --git a/mapdllnames.pl b/mapdllnames.pl new file mode 100755 index 000000000..d3e1dd20d --- /dev/null +++ b/mapdllnames.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl +# +# mapdllnames.pl : remaps the DllImport libnames for a specified source dir. +# +# Author: Mike Kestner +# +# 2002 Mike Kestner +############################################################################# + +%map = ( + 'glib-2.0', "libglib-2.0-0.dll", + 'gobject-2.0', "libgobject-2.0-0.dll", + 'pango-1.0', "libpango-1.0-0.dll", + 'atk-1.0', "libatk-1.0-0.dll", + 'gdk-x11-2.0', "libgdk-win32-2.0-0.dll", + 'gdk-pixbuf-2.0', "libgdk_pixbuf-2.0-0.dll", + 'gtk-x11-2.0', "libgtk-win32-2.0-0.dll" +); + +foreach $filename (@ARGV) { + + chomp($filename); + open(INFILE, $filename) || die "Couldn't open $filename\n"; + open(OUTFILE, ">$filename.tmp") || die "Couldn't open $filename.tmp\n"; + + while ($line = ) { + if ($line =~ /DllImport\(\"(.*)\"/ && exists($map{$1})) { + $line =~ s/\"(.*)\"/\"$map{$1}\"/; + } + + print OUTFILE $line; + } + close(INFILE); + close(OUTFILE); + `mv $filename.tmp $filename`; +} + diff --git a/pango/makefile.win32 b/pango/makefile.win32 index b61daca39..36d50b090 100644 --- a/pango/makefile.win32 +++ b/pango/makefile.win32 @@ -1,6 +1,7 @@ all: windows windows: + ../mapdllnames.pl generated/*.cs $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /out:pango-sharp.dll /recurse:*.cs docs: diff --git a/sources/Gdk.metadata b/sources/Gdk.metadata index d78bd433e..ea48390a0 100644 --- a/sources/Gdk.metadata +++ b/sources/Gdk.metadata @@ -81,6 +81,20 @@ + + + + Parse + + + + GdkColor* + pass_as + ref + + + +