From 9693ee998ec9d2819b44d77ad5abc19fbee5e30f Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Fri, 5 Jul 2002 20:22:21 +0000 Subject: [PATCH] 2002-07-05 Rachel Hestilow * configure.in: Conditionally compile Gnome. * parser/gapi_pp.pl: Handle line breaks in function declarations. * parser/gapi2xml.pl: Handle non-literals in property definitions. * glue/program.c: Added. * glue/Makefile.am: Add program.c (conditionally compiled). Update INCLUDES. * gnome/Makefile.in: Conditionally compile this. * gnome/Program.custom, Modules.cs: Added. * samples/Makefile.in: Conditionally compile gnome example. * samples/GnomeHelloWorld.cs: Use Gnome.Program. svn path=/trunk/gtk-sharp/; revision=5609 --- ChangeLog | 17 +++++ configure.in | 23 +++--- generator/gtkapi.xml | 151 ++++++++++++++++++++++++++++++++------ glue/Makefile.am | 4 +- glue/program.c | 138 ++++++++++++++++++++++++++++++++++ gnome/Makefile.in | 5 +- gnome/Modules.cs | 22 ++++++ gnome/Program.custom | 83 +++++++++++++++++++++ makefile | 2 + parser/gapi2xml.pl | 13 +++- parser/gapi_pp.pl | 22 +++++- sample/GnomeHelloWorld.cs | 8 +- sample/Makefile.in | 10 ++- 13 files changed, 451 insertions(+), 47 deletions(-) create mode 100644 glue/program.c create mode 100644 gnome/Modules.cs create mode 100644 gnome/Program.custom diff --git a/ChangeLog b/ChangeLog index 573cebb72..6a68bc4e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2002-07-05 Rachel Hestilow + + * configure.in: Conditionally compile Gnome. + + * parser/gapi_pp.pl: Handle line breaks in function declarations. + * parser/gapi2xml.pl: Handle non-literals in property definitions. + + * glue/program.c: Added. + * glue/Makefile.am: Add program.c (conditionally compiled). + Update INCLUDES. + + * gnome/Makefile.in: Conditionally compile this. + * gnome/Program.custom, Modules.cs: Added. + + * samples/Makefile.in: Conditionally compile gnome example. + * samples/GnomeHelloWorld.cs: Use Gnome.Program. + 2002-07-01 Rachel Hestilow * generator/gtkapi.xml: diff --git a/configure.in b/configure.in index 3f98b9d6e..4aca7c723 100644 --- a/configure.in +++ b/configure.in @@ -57,20 +57,25 @@ AC_ARG_WITH(crosspkgdir, [ --with-crosspkgdir=/path/to/pkg-config/dir], fi ) + ## Versions of dependencies +GNOME_REQUIRED_VERSION=2.0.0 GTK_REQUIRED_VERSION=2.0.0 +PKG_CHECK_MODULES(BASE_DEPENDENCIES, libgnome-2.0 >= $GNOME_REQUIRED_VERSION gtk+-2.0 >= $GTK_REQUIRED_VERSION gmodule-2.0 >= $GTK_REQUIRED_VERSION, enable_gnome=yes, enable_gnome=no) -PKG_CHECK_MODULES(BASE_DEPENDENCIES, gtk+-2.0 >= $GTK_REQUIRED_VERSION) +if test "x$enable_gnome" = "xno"; then + PKG_CHECK_MODULES(BASE_DEPENDENCIES, gtk+-2.0 >= $GTK_REQUIRED_VERSION gmodule-2.0 >= $GTK_REQUIRED_VERSION) +fi -GTK_CFLAGS=`$PKG_CONFIG --cflags gtk+-2.0` -GTK_LIBS=`$PKG_CONFIG --libs gtk+-2.0` -GMODULE_CFLAGS=`$PKG_CONFIG --cflags gmodule-2.0` -GMODULE_LIBS=`$PKG_CONFIG --libs gmodule-2.0` +#GTK_CFLAGS=`$PKG_CONFIG --cflags gtk+-2.0` +#GTK_LIBS=`$PKG_CONFIG --libs gtk+-2.0` +#GMODULE_CFLAGS=`$PKG_CONFIG --cflags gmodule-2.0` +#GMODULE_LIBS=`$PKG_CONFIG --libs gmodule-2.0` -AC_SUBST(GTK_CFLAGS) -AC_SUBST(GTK_LIBS) -AC_SUBST(GMODULE_CFLAGS) -AC_SUBST(GMODULE_LIBS) +AC_SUBST(BASE_DEPENDENCIES_CFLAGS) +AC_SUBST(BASE_DEPENDENCIES_LIBS) + +AM_CONDITIONAL(ENABLE_GNOME, test "x$enable_gnome" = "xyes") AC_SUBST(CFLAGS) diff --git a/generator/gtkapi.xml b/generator/gtkapi.xml index 781385b41..513c2ba42 100644 --- a/generator/gtkapi.xml +++ b/generator/gtkapi.xml @@ -537,9 +537,24 @@ + + + + + + + + + + + + + + + @@ -923,25 +938,76 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3714,6 +3780,9 @@ + + + @@ -4166,6 +4235,12 @@ + + + + + + @@ -6430,8 +6505,8 @@ - - + + @@ -13178,7 +13253,7 @@ - + @@ -16265,7 +16340,7 @@ - + @@ -16473,7 +16548,7 @@ - + @@ -17250,7 +17325,7 @@ - + @@ -21446,6 +21521,9 @@ + + + @@ -21464,6 +21542,12 @@ + + + + + + @@ -21491,6 +21575,13 @@ + + + + + + + @@ -21571,12 +21662,24 @@ + + + + + + + + + + + + diff --git a/glue/Makefile.am b/glue/Makefile.am index f6bec5a55..228a0deae 100644 --- a/glue/Makefile.am +++ b/glue/Makefile.am @@ -1,6 +1,7 @@ lib_LTLIBRARIES = libgtksharpglue.la -INCLUDES = $(GTK_CFLAGS) -I$(top_srcdir) +INCLUDES = @BASE_DEPENDENCIES_CFLAGS@ -I$(top_srcdir) + libgtksharpglue_la_SOURCES = \ value.c \ @@ -9,6 +10,7 @@ libgtksharpglue_la_SOURCES = \ error.c \ event.c \ slist.c \ +@ENABLE_GNOME_TRUE@ program.c \ # libgtksharpglue.dll: $(libgtksharpglue_la_OBJECTS) libgtksharpglue.rc libgtksharpglue.def diff --git a/glue/program.c b/glue/program.c new file mode 100644 index 000000000..855a8e890 --- /dev/null +++ b/glue/program.c @@ -0,0 +1,138 @@ +#include +#include +#include +#include + +typedef struct { + char *name; + GValue *value; +} PropertyArg; + +static gchar* +get_default (GObjectClass *klass, const gchar *property) +{ + GParamSpec *spec = g_object_class_find_property (klass, property); + GParamSpecString *strspec; + gchar *ret; + + g_return_val_if_fail (spec != NULL, NULL); + g_return_val_if_fail (strspec != NULL, NULL); + + strspec = G_PARAM_SPEC_STRING (spec); + ret = g_strdup (strspec->default_value); + //g_param_spec_unref (spec); + + return ret; +} + +/* FIXME: HACK */ +GnomeProgram* +gtksharp_gnome_program_init (const char *app_id, const char *app_version, + const GnomeModuleInfo *module_info, + int argc, char **argv, + int nargs, PropertyArg* args) +{ + GnomeProgram *ret; + int i; + gboolean *unhandled = g_new0 (gboolean, nargs); + + /* ok, these are the known construct-time arguments which means we + * _have_ to pass them into init. */ + + GObjectClass *klass = g_type_class_ref (GNOME_TYPE_PROGRAM); + gchar *human_readable_name = NULL; + gchar *gnome_path = NULL; + gchar *gnome_prefix = NULL; + gchar *gnome_libdir = NULL; + gchar *gnome_datadir = NULL; + gchar *gnome_sysconfdir = NULL; + gboolean create_directories = TRUE; + gchar *gnome_espeaker = NULL; + + for (i = 0; i < nargs; i++) + { + if (!strcmp (args[i].name, GNOME_PARAM_HUMAN_READABLE_NAME)) + human_readable_name = g_strdup (g_value_get_string (args[i].value)); + else if (!strcmp (args[i].name, GNOME_PARAM_GNOME_PATH)) + gnome_path = g_strdup (g_value_get_string (args[i].value)); + else if (!strcmp (args[i].name, GNOME_PARAM_GNOME_PREFIX)) + gnome_prefix = g_strdup (g_value_get_string (args[i].value)); + else if (!strcmp (args[i].name, GNOME_PARAM_GNOME_LIBDIR)) + gnome_libdir = g_strdup (g_value_get_string (args[i].value)); + else if (!strcmp (args[i].name, GNOME_PARAM_GNOME_DATADIR)) + gnome_datadir = g_strdup (g_value_get_string (args[i].value)); + else if (!strcmp (args[i].name, GNOME_PARAM_GNOME_SYSCONFDIR)) + gnome_sysconfdir = g_strdup (g_value_get_string (args[i].value)); + else if (!strcmp (args[i].name, GNOME_PARAM_CREATE_DIRECTORIES)) + create_directories = g_value_get_boolean (args[i].value); + else + unhandled[i] = TRUE; + } + + if (!human_readable_name) + human_readable_name = g_strdup (app_id); + if (!gnome_path) + gnome_path = get_default (klass, GNOME_PARAM_GNOME_PATH); + if (!gnome_prefix) + gnome_prefix = get_default (klass, GNOME_PARAM_GNOME_PREFIX); + if (!gnome_libdir) + gnome_libdir = get_default (klass, GNOME_PARAM_GNOME_LIBDIR); + if (!gnome_datadir) + gnome_datadir = get_default (klass, GNOME_PARAM_GNOME_DATADIR); + if (!gnome_sysconfdir) + gnome_sysconfdir = get_default (klass, GNOME_PARAM_GNOME_SYSCONFDIR); + /* FIXME: string[] marshalling broken */ + argc = 1; + argv = g_new0 (char*, 1); + argv[0] = app_id; + + ret = gnome_program_init (app_id, app_version, module_info, + argc, argv, + GNOME_PARAM_HUMAN_READABLE_NAME, + human_readable_name, + GNOME_PARAM_GNOME_PREFIX, + gnome_prefix, + GNOME_PARAM_GNOME_LIBDIR, + gnome_libdir, + GNOME_PARAM_GNOME_DATADIR, + gnome_datadir, + GNOME_PARAM_GNOME_SYSCONFDIR, + gnome_sysconfdir, + GNOME_PARAM_CREATE_DIRECTORIES, + create_directories, + (gnome_path) ? (GNOME_PARAM_GNOME_PATH) : ((gnome_espeaker) ? GNOME_PARAM_ESPEAKER : NULL), + (gnome_path) ? (gnome_path) : ((gnome_espeaker) ? gnome_espeaker : NULL), + (gnome_espeaker && gnome_path) ? GNOME_PARAM_ESPEAKER : NULL, + (gnome_espeaker && gnome_path) ? gnome_espeaker : NULL, + NULL); + + for (i = 0; i < nargs; i++) + { + if (unhandled[i]) + g_object_set_property (G_OBJECT (ret), + args[i].name, args[i].value); + } + + if (human_readable_name) + g_free (human_readable_name); + if (gnome_path) + g_free (gnome_path); + if (gnome_prefix) + g_free (gnome_prefix); + if (gnome_libdir) + g_free (gnome_libdir); + if (gnome_datadir) + g_free (gnome_datadir); + if (gnome_sysconfdir) + g_free (gnome_sysconfdir); + if (gnome_espeaker) + g_free (gnome_espeaker); + + g_free (unhandled); + + /* Remove this too when marshalling fixed */ + g_free (argv); + + return ret; +} + diff --git a/gnome/Makefile.in b/gnome/Makefile.in index 8bb3d6a33..55ef55331 100755 --- a/gnome/Makefile.in +++ b/gnome/Makefile.in @@ -1,6 +1,7 @@ MCS=mcs -all: linux +@ENABLE_GNOME_TRUE@ all: linux +@ENABLE_GNOME_FALSE@ all: 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 /r:../gtk/gtk-sharp.dll /out:gnome-sharp.dll /recurse:*.cs @@ -15,5 +16,5 @@ clean: rm -f generated/* install: all - cp gnome-sharp.dll @prefix@/lib +@ENABLE_GNOME_TRUE@ cp gnome-sharp.dll @prefix@/lib diff --git a/gnome/Modules.cs b/gnome/Modules.cs new file mode 100644 index 000000000..fb82ef84c --- /dev/null +++ b/gnome/Modules.cs @@ -0,0 +1,22 @@ +namespace Gnome +{ + using System; + using System.Runtime.InteropServices; + + class Modules + { + [DllImport("libgnome-2.so.0")] + static extern System.IntPtr libgnome_module_info_get (); + [DllImport("libgnomeui-2.so.0")] + static extern System.IntPtr libgnomeui_module_info_get (); + + public static ModuleInfo LibGnome { + get { return new ModuleInfo (libgnome_module_info_get ()); } + } + + public static ModuleInfo UI { + get { return new ModuleInfo (libgnomeui_module_info_get ()); } + } + } +} + diff --git a/gnome/Program.custom b/gnome/Program.custom new file mode 100644 index 000000000..fe544dd9e --- /dev/null +++ b/gnome/Program.custom @@ -0,0 +1,83 @@ +// +// Gnome.Program.custom - Gnome Program class customizations +// +// Author: Rachel Hestilow +// +// Copyright (C) 2002 Rachel Hestilow +// +// This code is inserted after the automatically generated code. +// + +[DllImport("gobject-2.0")] +static extern void g_type_init (); + +[DllImport("libgnome-2.so.0")] +static extern System.IntPtr gnome_program_get_type (); + +[StructLayout(LayoutKind.Sequential)] +struct PropertyArg { + public string name; + public IntPtr value; +} + +[DllImport("gtksharpglue")] +static extern System.IntPtr +gtksharp_gnome_program_init (string app_id, string app_version, System.IntPtr module, int argc, string[] argv, int nargs, PropertyArg[] args); + +public Program (string app_id, string app_version, ModuleInfo module, + string[] argv, params object[] props) +{ + int nargs = props.Length / 2; + PropertyArg[] args = new PropertyArg[nargs]; + GLib.Value[] vals = new GLib.Value[nargs]; + string[] new_argv = new string[argv.Length + 1]; + + g_type_init (); + + for (int i = 0; i < nargs; i++) + { + args[i].name = (string) props[i * 2]; + GLib.Value value; + // FIXME: handle more types + object prop = props[i * 2 + 1]; + Type type = prop.GetType (); + if (type == "hello".GetType ()) + value = new GLib.Value ((string) prop); + else if (type == true.GetType ()) + value = new GLib.Value ((bool) prop); + else + value = null; + vals[i] = value; + args[i].value = value.Handle; + } + + /* FIXME: Is there a way to access this in .NET? */ + new_argv[0] = app_id; + Array.Copy (argv, 0, new_argv, 1, argv.Length); + Raw = gtksharp_gnome_program_init (app_id, app_version, module.Handle, new_argv.Length, new_argv, nargs, args); +} + +public void Run () +{ + Gtk.Application.Run (); +} + +public void Quit () +{ + Gtk.Application.Quit (); +} + +[DllImport("libgnome-2.so.0")] +static extern System.IntPtr gnome_program_get (); + +public static Program Get () +{ + IntPtr raw = gnome_program_get (); + if (raw == IntPtr.Zero) + return null; + Program program = (Program) GLib.Object.GetObject (raw); + if (program == null) + program = new Program (raw); + return program; +} + diff --git a/makefile b/makefile index dba0107a7..55a7f5620 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,5 @@ +EXTRA_DIRS = + DIRS=generator glib pango atk gdk gtk gnome sample ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe diff --git a/parser/gapi2xml.pl b/parser/gapi2xml.pl index afa286b33..bd1b3990a 100755 --- a/parser/gapi2xml.pl +++ b/parser/gapi2xml.pl @@ -137,6 +137,11 @@ while ($line = ) { $boxdefs{$1} = $line; } elsif ($line =~ /^BUILTIN\s*\{\s*\"(\w+)\".*GTK_TYPE_(ENUM|FLAGS)/) { # ignoring these for now. + } elsif ($line =~ /^\#define/) { + my $test_ns = uc ($ns); + if ($line =~ /\#define\s+(\w+)\s+\"(.*)\"/) { + $defines{$1} = $2; + } } else { print $line; } @@ -231,7 +236,6 @@ foreach $type (sort(keys(%ifaces))) { $classdef = $sdefs{$1} if ($ifacetype =~ /struct\s+(\w+)/); if ($initfunc) { - print "parsing $inst\n"; parseInitFunc($iface_el, $initfunc); } else { warn "Don't have an init func for $inst.\n" if $debug; @@ -514,9 +518,12 @@ sub addPropElem my $type = $1; my @params = split(/,/, $2); - # FIXME: Handle non-literals. Needs work in the pp too. $name = $params[0]; - $name =~ s/\"//g; + if ($defines{$name}) { + $name = $defines{$name}; + } else { + $name =~ s/\"//g; + } while ($params[2] !~ /(\"|NULL)\s*\)?$/) { die "Unable to reconstruct doc string.\n" if (!$params[3]); diff --git a/parser/gapi_pp.pl b/parser/gapi_pp.pl index b7aa82233..96864e4f6 100755 --- a/parser/gapi_pp.pl +++ b/parser/gapi_pp.pl @@ -23,12 +23,23 @@ foreach $fname (@hdrs) { open(INFILE, $fname) || die "Could open $fname\n"; + $braces = 0; + $prepend = ""; while ($line = ) { - + $braces++ if ($line =~ /{/ and $line !~ /}/); + $braces-- if ($line =~ /}/ and $line !~ /{/); + next if ($line =~ /$ignoreit_regex/); next if ($line !~ /\S/); - if ($line =~ /#\s*define\s+\w+\s*\D+/) { + $line = $prepend . $line; + $prepend = ""; + + if ($line =~ /#\s*define\s+\w+\s+\"/) { + $def = $line; + while ($def !~ /\".*\"/) {$def .= ($line = );} + print $def; + } elsif ($line =~ /#\s*define\s+\w+\s*\D+/) { $def = $line; while ($line =~ /\\\n/) {$def .= ($line = );} if ($def =~ /_CHECK_\w*CAST|INSTANCE_GET_INTERFACE/) { @@ -48,7 +59,12 @@ foreach $fname (@hdrs) { } elsif ($line =~ /^enum\s+\{/) { while ($line !~ /^};/) {$line = ;} } else { - print $line; + if ($braces or $line =~ /;/) { + print $line; + } else { + $prepend = $line; + $prepend =~ s/\n/ /g; + } } } } diff --git a/sample/GnomeHelloWorld.cs b/sample/GnomeHelloWorld.cs index bad145b97..56bcda56d 100644 --- a/sample/GnomeHelloWorld.cs +++ b/sample/GnomeHelloWorld.cs @@ -105,12 +105,15 @@ namespace GtkSamples { public static int Main (string[] args) { - Application.Init (); + /* FIXME: Broken params support in mcs, should be fixed soonish */ + object[] props = new object[0]; + Program kit = new Program ("gnome-hello-world", "0.0.1", Modules.UI, + args, props); GnomeHelloWorld hello = new GnomeHelloWorld (); Window win = hello.CreateWindow (); win.ShowAll (); - Application.Run (); + kit.Run (); return 0; } @@ -123,6 +126,7 @@ namespace GtkSamples { static void exit_cb (object o, EventArgs args) { + Console.WriteLine ("hi {0}", Gnome.Program.Get ().AppId); Application.Quit (); } diff --git a/sample/Makefile.in b/sample/Makefile.in index d4baf4823..d034f8668 100755 --- a/sample/Makefile.in +++ b/sample/Makefile.in @@ -1,7 +1,11 @@ MCS=mcs -local_paths=-L ../glib -L ../pango -L ../atk -L ../gdk -L ../gtk -L ../gnome -all_assemblies=-r glib-sharp -r pango-sharp -r atk-sharp -r gdk-sharp -r gtk-sharp -r gnome-sharp -r System.Drawing +@ENABLE_GNOME_TRUE@ GNOME_PATH=-L ../gnome +@ENABLE_GNOME_TRUE@ GNOME_ASSEMBLY=-r gnome-sharp +@ENABLE_GNOME_TRUE@ GNOME_TARGETS=gnome-hello-world.exe + +local_paths=-L ../glib -L ../pango -L ../atk -L ../gdk -L ../gtk $(GNOME_PATH) +all_assemblies=-r glib-sharp -r pango-sharp -r atk-sharp -r gdk-sharp -r gtk-sharp $(GNOME_ASSEMBLY) -r System.Drawing all: linux @@ -10,7 +14,7 @@ windows: $(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 -linux: gtk-hello-world.exe button.exe menu.exe gnome-hello-world.exe +linux: gtk-hello-world.exe button.exe menu.exe $(GNOME_TARGETS) gtk-hello-world.exe: HelloWorld.cs $(MCS) --unsafe -o gtk-hello-world.exe $(local_paths) $(all_assemblies) HelloWorld.cs