From cd73a17587e3790c41912505a6a9033f0911e76f Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 2 May 2002 21:57:41 +0000 Subject: [PATCH] 2002-05-02 Mike Kestner * README : Describe the new make procedure. * configure.in : Add the new Makefile generation. * makefile : add the glue dir, make linux the default build, add an install target * */makefile.win32 : temp build files for win32 * */Makefile.in : new configurable make system * */makefile : killed * generator/BoxedGen.cs : Now uses GLib.Boxed * generator/ObjectGen.cs : Use Values for Props. * generator/SymbolTable.cs : Add IsEnum method. * glib/Boxed.cs : Major overhaul. * glib/Object.cs : Remove type specific (Get|Set)Property. Now use GValue based property accessors. * glib/TypeFundamentals.cs : Update to current values. * glib/Value.cs : Refactor to use glue. svn path=/trunk/gtk-sharp/; revision=4236 --- ChangeLog | 18 ++ README | 18 +- atk/.cvsignore | 1 + atk/{makefile => Makefile.in} | 12 +- atk/makefile.win32 | 5 + configure.in | 6 + gdk/.cvsignore | 1 + gdk/{makefile => Makefile.in} | 12 +- gdk/makefile.win32 | 5 + generator/.cvsignore | 2 + generator/BoxedGen.cs | 4 +- generator/ObjectGen.cs | 28 +-- generator/SymbolTable.cs | 12 + generator/makefile | 32 ++- generator/makefile.win32 | 6 + glib/.cvsignore | 1 + glib/Boxed.cs | 85 +++---- glib/{makefile => Makefile.in} | 12 +- glib/Object.cs | 350 ++-------------------------- glib/TypeFundamentals.cs | 40 ++-- glib/Value.cs | 296 ++++++++++++++++++----- glib/makefile.win32 | 5 + gtk/.cvsignore | 1 + gtk/{makefile => Makefile.in} | 9 +- gtk/makefile.win32 | 5 + makefile | 14 +- makefile.win32 | 11 + pango/.cvsignore | 1 + pango/{makefile => Makefile.in} | 12 +- pango/makefile.win32 | 5 + sample/.cvsignore | 1 + sample/Makefile.in | 21 ++ sample/{makefile => makefile.win32} | 6 +- 33 files changed, 513 insertions(+), 524 deletions(-) rename atk/{makefile => Makefile.in} (79%) create mode 100644 atk/makefile.win32 rename gdk/{makefile => Makefile.in} (76%) create mode 100644 gdk/makefile.win32 create mode 100644 generator/makefile.win32 rename glib/{makefile => Makefile.in} (61%) create mode 100644 glib/makefile.win32 rename gtk/{makefile => Makefile.in} (81%) create mode 100644 gtk/makefile.win32 create mode 100755 makefile.win32 rename pango/{makefile => Makefile.in} (68%) create mode 100644 pango/makefile.win32 create mode 100755 sample/Makefile.in rename sample/{makefile => makefile.win32} (62%) mode change 100755 => 100644 diff --git a/ChangeLog b/ChangeLog index 9698c2482..2d6a24432 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2002-05-02 Mike Kestner + + * README : Describe the new make procedure. + * configure.in : Add the new Makefile generation. + * makefile : add the glue dir, make linux the default build, + add an install target + * */makefile.win32 : temp build files for win32 + * */Makefile.in : new configurable make system + * */makefile : killed + * generator/BoxedGen.cs : Now uses GLib.Boxed + * generator/ObjectGen.cs : Use Values for Props. + * generator/SymbolTable.cs : Add IsEnum method. + * glib/Boxed.cs : Major overhaul. + * glib/Object.cs : Remove type specific (Get|Set)Property. Now + use GValue based property accessors. + * glib/TypeFundamentals.cs : Update to current values. + * glib/Value.cs : Refactor to use glue. + 2002-04-25 Mike Kestner * autogen.sh : simple config for the glue build diff --git a/README b/README index 33f35759a..fbb889959 100644 --- a/README +++ b/README @@ -10,14 +10,24 @@ there and adjust accordingly. Building Gtk#: -------------- Currently, it is only possible to compile Gtk# on Win32 using the .Net -framework compiler and libraries. Miguel and company will be changing that -shortly. The win32 compilation utilizes the cygwin environment for a GNU -build environment. To compile the package type: +framework compiler and libraries. The build system is in a transitional +state at the moment. Windows compilation utilizes the cygwin environment +for a GNU build environment. To compile the package type: -make windows +make -f makefile.win32 in the top level directory. +The linux build fails due to unresolved issues in mcs. If you would like +to help work these issues, the build procedure on linux is the typical: + +configure +make +make install + +If you are compiling from CVS, you will need libtool and the auto* tools +and will need to replace the configure above with autogen.sh. + Discussion: ----------- A mailing list for Gtk# discussion (gtk-sharp-list@ximian.com) is available. diff --git a/atk/.cvsignore b/atk/.cvsignore index 7851f6209..c0c9b37f9 100644 --- a/atk/.cvsignore +++ b/atk/.cvsignore @@ -1,4 +1,5 @@ *.dll *.exe generated +Makefile diff --git a/atk/makefile b/atk/Makefile.in similarity index 79% rename from atk/makefile rename to atk/Makefile.in index d65ce290e..afc10f2de 100644 --- a/atk/makefile +++ b/atk/Makefile.in @@ -1,15 +1,19 @@ MCS=mcs -all: - @echo "You must use 'make windows' or 'make unix'." - @echo "'make unix' is broken for now." +all: linux windows: $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /out:atk-sharp.dll /recurse:*.cs -linux: +linux: atk-sharp.dll + +atk-sharp.dll: generated/*.cs $(MCS) --unsafe --target library -r ../glib/glib-sharp.dll -r ../pango/pango-sharp.dll -o atk-sharp.dll --recurse *.cs unix: @echo "'make unix' is broken for now." $(CSC) --unsafe --target=library --r=../glib/glib-sharp.dll --r=../pango/pango-sharp.dll --out=atk-sharp.dll --recurse=*.cs + +install: all + cp atk-sharp.dll @prefix@/lib + diff --git a/atk/makefile.win32 b/atk/makefile.win32 new file mode 100644 index 000000000..b99fed808 --- /dev/null +++ b/atk/makefile.win32 @@ -0,0 +1,5 @@ +all: windows + +windows: + $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /r:../pango/pango-sharp.dll /out:atk-sharp.dll /recurse:*.cs + diff --git a/configure.in b/configure.in index 155de6552..b1b23e271 100644 --- a/configure.in +++ b/configure.in @@ -76,6 +76,12 @@ AC_SUBST(CFLAGS) AC_OUTPUT([ glue/Makefile +glib/Makefile +pango/Makefile +atk/Makefile +gdk/Makefile +gtk/Makefile +sample/Makefile ]) echo " diff --git a/gdk/.cvsignore b/gdk/.cvsignore index 7851f6209..c0c9b37f9 100644 --- a/gdk/.cvsignore +++ b/gdk/.cvsignore @@ -1,4 +1,5 @@ *.dll *.exe generated +Makefile diff --git a/gdk/makefile b/gdk/Makefile.in similarity index 76% rename from gdk/makefile rename to gdk/Makefile.in index 52a422e40..c83769e7f 100755 --- a/gdk/makefile +++ b/gdk/Makefile.in @@ -1,14 +1,18 @@ MCS=mcs -all: - @echo "You must use 'make windows' or 'make unix'." - @echo "'make unix' is broken for now." +all: linux 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 -linux: +linux: gdk-sharp.dll + +gdk-sharp.dll: generated/*.cs $(MCS) --unsafe --target library -r ../glib/glib-sharp.dll -r ../pango/pango-sharp.dll -r ../atk/atk-sharp.dll -o gdk-sharp.dll --recurse *.cs unix: @echo "'make unix' is broken for now." + +install: all + cp gdk-sharp.dll @prefix@/lib + diff --git a/gdk/makefile.win32 b/gdk/makefile.win32 new file mode 100644 index 000000000..3e29098c6 --- /dev/null +++ b/gdk/makefile.win32 @@ -0,0 +1,5 @@ +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 + diff --git a/generator/.cvsignore b/generator/.cvsignore index 4e8ac1c1b..18d381e24 100644 --- a/generator/.cvsignore +++ b/generator/.cvsignore @@ -1,3 +1,5 @@ *.dll *.exe +generated-stamp +Makefile diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index 61271d273..62dde9615 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -29,7 +29,7 @@ namespace GtkSharp.Generation { public String FromNative(String var) { - return "(" + QualifiedName + ") GtkSharp.Boxed.GetBoxed(" + var + ")"; + return "(" + QualifiedName + ") GLib.Boxed.FromNative(" + var + ")"; } public void Generate (SymbolTable table) @@ -57,7 +57,7 @@ namespace GtkSharp.Generation { sw.WriteLine (); sw.WriteLine ("\t[StructLayout(LayoutKind.Sequential)]"); - sw.WriteLine ("\tpublic class " + Name + " : GtkSharp.Boxed {"); + sw.WriteLine ("\tpublic class " + Name + " : GLib.Boxed {"); sw.WriteLine (); sw.WriteLine("\t\tpublic " + Name + "(IntPtr raw) : base(raw) {}"); diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 24a03aea1..9225e95f9 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -160,8 +160,7 @@ namespace GtkSharp.Generation { char[] ast = {'*'}; c_type = c_type.TrimEnd(ast); - String cs_type = table.GetCSType(c_type); - String m_type; + string cs_type = table.GetCSType(c_type); XmlElement parent = (XmlElement) prop.ParentNode; name = prop.GetAttribute("name"); @@ -169,20 +168,17 @@ namespace GtkSharp.Generation { name += "Prop"; } - if (table.IsObject(c_type)) { - m_type = "GLib.Object"; - } else if (table.IsBoxed(c_type)) { - m_type = "GtkSharp.Boxed"; + string v_type = ""; + if (table.IsEnum(c_type)) { + v_type = "int"; } else if (table.IsInterface(c_type)) { // FIXME: Handle interface props properly. Console.Write("Interface property detected "); Statistics.ThrottledCount++; return true; - } else { - m_type = table.GetMarshalType(c_type); } - if ((cs_type == "") || (m_type == "")) { + if (cs_type == "") { Console.Write("Property has unknown Type {0} ", c_type); Statistics.ThrottledCount++; return false; @@ -195,11 +191,11 @@ namespace GtkSharp.Generation { sw.WriteLine("\t\tpublic " + cs_type + " " + name + " {"); if (prop.HasAttribute("readable")) { sw.WriteLine("\t\t\tget {"); - sw.WriteLine("\t\t\t\t" + m_type + " val;"); + sw.WriteLine("\t\t\t\tGLib.Value val;"); sw.WriteLine("\t\t\t\tGetProperty(\"" + prop.GetAttribute("cname") + "\", out val);"); - sw.Write("\t\t\t\treturn "); - if (cs_type != m_type) { - sw.Write("(" + cs_type + ") "); + sw.Write("\t\t\t\treturn (" + cs_type + ") "); + if (v_type != "") { + sw.Write("(" + v_type + ") "); } sw.WriteLine("val;"); sw.WriteLine("\t\t\t}"); @@ -207,7 +203,11 @@ namespace GtkSharp.Generation { if (prop.HasAttribute("writeable") && !prop.HasAttribute("construct-only")) { sw.WriteLine("\t\t\tset {"); - sw.WriteLine("\t\t\t\tSetProperty(\"" + prop.GetAttribute("cname") + "\", (" + m_type + ") value);"); + sw.Write("\t\t\t\tSetProperty(\"" + prop.GetAttribute("cname") + "\", new GLib.Value("); + if (v_type != "") { + sw.Write("(" + v_type + ") "); + } + sw.WriteLine("value));"); sw.WriteLine("\t\t\t}"); } diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 234b77ff0..16dcd0677 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -185,6 +185,18 @@ namespace GtkSharp.Generation { return false; } + public bool IsEnum(string c_type) + { + c_type = Trim(c_type); + if (complex_types.ContainsKey(c_type)) { + IGeneratable gen = (IGeneratable) complex_types[c_type]; + if (gen is EnumGen) { + return true; + } + } + return false; + } + public bool IsInterface(string c_type) { c_type = Trim(c_type); diff --git a/generator/makefile b/generator/makefile index 1f49b532f..24256f7ba 100644 --- a/generator/makefile +++ b/generator/makefile @@ -1,16 +1,34 @@ MCS=mcs +SOURCES=BoxedGen.cs \ + CallbackGen.cs \ + CodeGenerator.cs \ + EnumGen.cs \ + IGeneratable.cs \ + InterfaceGen.cs \ + ObjectGen.cs \ + Parser.cs \ + SignalHandler.cs \ + Statistics.cs \ + StructBase.cs \ + StructGen.cs \ + SymbolTable.cs -all: - @echo "You must use 'make windows' or 'make linux'." - @echo "'make unix' is broken for now." +all: linux -windows: +windows: *.cs $(CSC) /unsafe /out:codegen.exe *.cs ./codegen gtkapi.xml -linux: - $(MCS) --unsafe -o codegen.exe -r System.Xml.dll *.cs - mono ./codegen.exe gtkapi.xml +linux: generated-stamp + +generated-stamp: codegen.exe gtkapi.xml + mono ./codegen.exe gtkapi.xml && touch generated-stamp unix: @echo "'make unix' is broken for now." + +install: all + @echo "Nothing to install in generator." + +codegen.exe: *.cs + $(MCS) --unsafe -o codegen.exe -r System.Xml.dll *.cs diff --git a/generator/makefile.win32 b/generator/makefile.win32 new file mode 100644 index 000000000..b35aeb414 --- /dev/null +++ b/generator/makefile.win32 @@ -0,0 +1,6 @@ +all: windows + +windows: *.cs + $(CSC) /unsafe /out:codegen.exe *.cs + ./codegen gtkapi.xml + diff --git a/glib/.cvsignore b/glib/.cvsignore index 7851f6209..c0c9b37f9 100755 --- a/glib/.cvsignore +++ b/glib/.cvsignore @@ -1,4 +1,5 @@ *.dll *.exe generated +Makefile diff --git a/glib/Boxed.cs b/glib/Boxed.cs index 61cf7fdb9..9eb31b3d2 100644 --- a/glib/Boxed.cs +++ b/glib/Boxed.cs @@ -4,10 +4,9 @@ // // (c) 2001-2002 Mike Kestner -namespace GtkSharp { +namespace GLib { using System; - using System.Runtime.InteropServices; /// /// Boxed Class @@ -19,61 +18,21 @@ namespace GtkSharp { public abstract class Boxed { - IntPtr _raw; + private IntPtr raw; - // Destructor is required since we are allocating unmanaged - // heap resources. - - ~Boxed () - { - Marshal.FreeHGlobal (_raw); - } + public Boxed () : this (IntPtr.Zero) {} /// /// Boxed Constructor /// /// /// - /// Dummy constructor needed for subclasses. + /// Constructs a Boxed type from a raw ref. /// - public Boxed() + public Boxed (IntPtr raw) { - } - - /// - /// Boxed Constructor - /// - /// - /// - /// Wraps a raw boxed type reference. - /// - - public Boxed(IntPtr raw) - { - Raw = raw; - } - - /// - /// Raw Property - /// - /// - /// - /// Gets a marshallable IntPtr. - /// - - protected IntPtr Raw { - get { - if (_raw == IntPtr.Zero) { - // FIXME: Ugly hack. - _raw = Marshal.AllocHGlobal (128); - Marshal.StructureToPtr (this, _raw, true); - } - return _raw; - } - set { - _raw = value; - } + this.raw = raw; } /// @@ -84,25 +43,41 @@ namespace GtkSharp { /// Gets a marshallable IntPtr. /// - public IntPtr Handle { + public virtual IntPtr Handle { get { - return _raw; + return raw; } } /// - /// GetBoxed Shared Method + /// Raw Property /// /// /// - /// Gets a managed class representing a raw ref. + /// Gets or sets a marshallable IntPtr. /// - public static Boxed GetBoxed (IntPtr raw) - { - // FIXME: Use the type manager to box the raw ref. - return null; + protected IntPtr Raw { + get { + return raw; + } + set { + raw = value; + } } + /// + /// FromNative Method + /// + /// + /// + /// Gets a Boxed type from a raw IntPtr. + /// + + public static GLib.Boxed FromNative (IntPtr raw) + { + // FIXME: + return null; + } } } diff --git a/glib/makefile b/glib/Makefile.in similarity index 61% rename from glib/makefile rename to glib/Makefile.in index 0412bbf32..3a4cc6a5c 100755 --- a/glib/makefile +++ b/glib/Makefile.in @@ -1,14 +1,18 @@ MCS=mcs -all: - @echo "You must use 'make windows' or 'make unix'." - @echo "'make unix' is broken for now." +all: linux windows: $(CSC) /unsafe /target:library /out:glib-sharp.dll /recurse:*.cs -linux: +linux: glib-sharp.dll + +glib-sharp.dll: *.cs generated/*.cs $(MCS) --unsafe --target library -o glib-sharp.dll --recurse *.cs unix: @echo "'make unix' is broken for now." + +install: all + cp glib-sharp.dll @prefix@/lib || exit 1 + diff --git a/glib/Object.cs b/glib/Object.cs index e8917412a..66ed88646 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -194,148 +194,18 @@ namespace GLib { /// /// /// - /// Accesses a string Property. + /// Accesses a Value Property. /// - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out string val, IntPtr term); + [DllImport("gobject-2.0")] + static extern void g_object_get_property ( + IntPtr obj, string name, out IntPtr val); - public void GetProperty (String name, out String val) + public void GetProperty (String name, out GLib.Value val) { - g_object_get (Raw, name, out val, new IntPtr (0)); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses a boolean Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out bool val, IntPtr term); - - public void GetProperty (String name, out bool val) - { - g_object_get (Raw, name, out val, new IntPtr (0)); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses a double Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out double val, IntPtr term); - - public void GetProperty (String name, out double val) - { - g_object_get (Raw, name, out val, new IntPtr (0)); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses a float Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out float val, IntPtr term); - - public void GetProperty (String name, out float val) - { - g_object_get (Raw, name, out val, new IntPtr (0)); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses an integer Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out int val, IntPtr term); - - public void GetProperty (String name, out int val) - { - g_object_get (Raw, name, out val, new IntPtr (0)); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses an unsigned integer Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out uint val, IntPtr term); - - public void GetProperty (String name, out uint val) - { - g_object_get (Raw, name, out val, new IntPtr (0)); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses an Object Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_get (IntPtr obj, string name, - out IntPtr val, IntPtr term); - - public void GetProperty (String name, out GLib.Object val) - { - IntPtr obj; - g_object_get (Raw, name, out obj, new IntPtr (0)); - val = GLib.Object.GetObject (obj); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses a Boxed Property. - /// - - public void GetProperty (String name, out GtkSharp.Boxed val) - { - IntPtr raw; - g_object_get (Raw, name, out raw, new IntPtr (0)); - val = GtkSharp.Boxed.GetBoxed (raw); - } - - /// - /// GetProperty Method - /// - /// - /// - /// Accesses an IntPtr Property. - /// - - public void GetProperty (String name, out IntPtr val) - { - g_object_get (Raw, name, out val, new IntPtr (0)); + IntPtr v; + g_object_get_property (Raw, name, out v); + val = new GLib.Value (v, v); } /// @@ -343,209 +213,17 @@ namespace GLib { /// /// /// - /// Changes the value of a string Property. + /// Accesses a Value Property. /// - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - string val, IntPtr term); + [DllImport("gobject-2.0")] + static extern void g_object_set_property ( + IntPtr obj, string name, IntPtr val); - public void SetProperty (String name, String val) + public void SetProperty (String name, GLib.Value val) { - g_object_set (Raw, name, val, new IntPtr (0)); + g_object_set_property (Raw, name, val.Handle); } - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of an integer Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - int val, IntPtr term); - - public void SetProperty (String name, int val) - { - g_object_set (Raw, name, val, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of an unsigned integer Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - uint val, IntPtr term); - - public void SetProperty (String name, uint val) - { - g_object_set (Raw, name, val, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of a boolean Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - bool val, IntPtr term); - - public void SetProperty (String name, bool val) - { - g_object_set (Raw, name, val, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of a double Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - double val, IntPtr term); - - public void SetProperty (String name, double val) - { - g_object_set (Raw, name, val, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of a float Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - float val, IntPtr term); - - public void SetProperty (String name, float val) - { - g_object_set (Raw, name, val, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of an IntPtr Property. - /// - - [DllImport("gobject-2.0", CallingConvention=CallingConvention.Cdecl)] - static extern void g_object_set (IntPtr obj, string name, - IntPtr val, IntPtr term); - - public void SetProperty (String name, IntPtr val) - { - g_object_set (Raw, name, val, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of an Object Property. - /// - - public void SetProperty (String name, GLib.Object val) - { - g_object_set (Raw, name, val.Handle, new IntPtr (0)); - } - - /// - /// SetProperty Method - /// - /// - /// - /// Changes the value of a Boxed Property. - /// - - public void SetProperty (String name, GtkSharp.Boxed val) - { - g_object_set (Raw, name, val.Handle, new IntPtr (0)); - } - - -/* - [DllImport("gtk-2.0")] - static extern void g_object_set_data_full ( - IntPtr obj, - String key, - IntPtr data, - DestroyNotify destroy ); - - -GParamSpec* g_object_class_find_property (GObjectClass *oclass, - const gchar *property_name); -GParamSpec** g_object_class_list_properties (GObjectClass *oclass, - guint *n_properties); -gpointer g_object_ref (gpointer object); -void g_object_unref (gpointer object); -void g_object_weak_ref (GObject *object, - GWeakNotify notify, - gpointer data); -void g_object_weak_unref (GObject *object, - GWeakNotify notify, - gpointer data); -void g_object_add_weak_pointer (GObject *object, - gpointer *weak_pointer_location); -void g_object_remove_weak_pointer (GObject *object, - gpointer *weak_pointer_location); -gpointer g_object_connect (gpointer object, - const gchar *signal_spec, - ...); -void g_object_disconnect (gpointer object, - const gchar *signal_spec, - ...); -void g_object_set (gpointer object, - const gchar *first_property_name, - ...); -void g_object_get (gpointer object, - const gchar *first_property_name, - ...); -void g_object_notify (GObject *object, - const gchar *property_name); -void g_object_freeze_notify (GObject *object); -void g_object_thaw_notify (GObject *object); -void g_object_set_data_full (GObject *object, - const gchar *key, - gpointer data, - GDestroyNotify destroy); -gpointer g_object_steal_data (GObject *object, - const gchar *key); -gpointer g_object_get_qdata (GObject *object, - GQuark quark); -void g_object_set_qdata (GObject *object, - GQuark quark, - gpointer data); -void g_object_set_qdata_full (GObject *object, - GQuark quark, - gpointer data, - GDestroyNotify destroy); -gpointer g_object_steal_qdata (GObject *object, - GQuark quark); -void g_object_watch_closure (GObject *object, - GClosure *closure); -void g_object_run_dispose (GObject *object); -*/ - } } diff --git a/glib/TypeFundamentals.cs b/glib/TypeFundamentals.cs index 50a3049a5..824d35e75 100644 --- a/glib/TypeFundamentals.cs +++ b/glib/TypeFundamentals.cs @@ -15,24 +15,26 @@ namespace GLib { /// public enum TypeFundamentals { - TypeInvalid, - TypeNone, - TypeInterface, - TypeChar, - TypeUChar, - TypeBoolean, - TypeInt, - TypeUInt, - TypeLong, - TypeULong, - TypeEnum, - TypeFlags, - TypeFloat, - TypeDouble, - TypeString, - TypePointer, - TypeBoxed, - TypeParam, - TypeObject, + TypeInvalid = 0 << 2, + TypeNone = 1 << 2, + TypeInterface = 2 << 2, + TypeChar = 3 << 2, + TypeUChar = 4 << 2, + TypeBoolean = 5 << 2, + TypeInt = 6 << 2, + TypeUInt = 7 << 2, + TypeLong = 8 << 2, + TypeULong = 9 << 2, + TypeInt64 = 10 << 2, + TypeUInt64 = 11 << 2, + TypeEnum = 12 << 2, + TypeFlags = 13 << 2, + TypeFloat = 14 << 2, + TypeDouble = 15 << 2, + TypeString = 16 << 2, + TypePointer = 17 << 2, + TypeBoxed = 18 << 2, + TypeParam = 19 << 2, + TypeObject = 20 << 2, } } diff --git a/glib/Value.cs b/glib/Value.cs index a387b0b90..5b684d962 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -23,7 +23,7 @@ namespace GLib { IntPtr _val; - // Destructor is required since we are allocating unmananged + // Destructor is required since we are allocating unmanaged // heap resources. [DllImport("glib-2.0")] @@ -34,36 +34,18 @@ namespace GLib { g_free (_val); } - /// - /// Value Constructor - /// - /// - /// - /// Creates an uninitialized Value on the unmanaged heap. - /// Use the Init method prior to attempting to assign a - /// value to it. - /// - [DllImport("glib-2.0", - CallingConvention=CallingConvention.Cdecl)] - static extern IntPtr g_malloc0 (long n_bytes); + // import the glue function to allocate values on heap - public Value () + [DllImport("gtksharpglue")] + static extern IntPtr gtksharp_value_create(TypeFundamentals type); + + // Constructor to wrap a raw GValue ref. We need the dummy param + // to distinguish this ctor from the TypePointer ctor. + + public Value (IntPtr val, IntPtr dummy) { - _val = g_malloc0 (5 * IntPtr.Size); - } - - /// - /// Value Constructor - /// - /// - /// - /// Creates an initialized Value of the specified type. - /// - - public Value (TypeFundamentals type) : this () - { - Init (type); + _val = val; } /// @@ -74,16 +56,65 @@ namespace GLib { /// Constructs a Value from a specified boolean. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] + [DllImport("gobject-2.0")] static extern void g_value_set_boolean (IntPtr val, bool data); - public Value (bool val) : this () + public Value (bool val) { - g_value_init (_val, TypeFundamentals.TypeBoolean); + _val = gtksharp_value_create(TypeFundamentals.TypeBoolean); g_value_set_boolean (_val, val); } + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value from a specified boxed type. + /// + + [DllImport("gobject-2.0")] + static extern void g_value_set_boxed (IntPtr val, IntPtr data); + public Value (GLib.Boxed val) + { + _val = gtksharp_value_create(TypeFundamentals.TypeBoxed); + g_value_set_boxed (_val, val.Handle); + } + + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value from a specified double. + /// + + [DllImport("gobject-2.0")] + static extern void g_value_set_double (IntPtr val, double data); + + public Value (double val) + { + _val = gtksharp_value_create (TypeFundamentals.TypeDouble); + g_value_set_double (_val, val); + } + + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value from a specified float. + /// + + [DllImport("gobject-2.0")] + static extern void g_value_set_float (IntPtr val, float data); + + public Value (float val) + { + _val = gtksharp_value_create (TypeFundamentals.TypeFloat); + g_value_set_float (_val, val); + } + /// /// Value Constructor /// @@ -92,16 +123,49 @@ namespace GLib { /// Constructs a Value from a specified integer. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] + [DllImport("gobject-2.0")] static extern void g_value_set_int (IntPtr val, int data); - public Value (int val) : this () + public Value (int val) { - g_value_init (_val, TypeFundamentals.TypeInt); + _val = gtksharp_value_create (TypeFundamentals.TypeInt); g_value_set_int (_val, val); } + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value from a specified object. + /// + + [DllImport("gobject-2.0")] + static extern void g_value_set_object (IntPtr val, IntPtr data); + + public Value (GLib.Object val) + { + _val = gtksharp_value_create (TypeFundamentals.TypeObject); + g_value_set_object (_val, val.Handle); + } + + /// + /// Value Constructor + /// + /// + /// + /// Constructs a Value from a specified pointer. + /// + + [DllImport("gobject-2.0")] + static extern void g_value_set_pointer (IntPtr val, IntPtr data); + + public Value (IntPtr val) + { + _val = gtksharp_value_create (TypeFundamentals.TypePointer); + g_value_set_pointer (_val, val); + } + /// /// Value Constructor /// @@ -110,32 +174,30 @@ namespace GLib { /// Constructs a Value from a specified string. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] - static extern void g_value_set_string (IntPtr val, - string data); - public Value (string val) : this () + [DllImport("gobject-2.0")] + static extern void g_value_set_string (IntPtr val, string data); + + public Value (string val) { - g_value_init (_val, TypeFundamentals.TypeString); + _val = gtksharp_value_create (TypeFundamentals.TypeString); g_value_set_string (_val, val); } /// - /// Init Method + /// Value Constructor /// /// /// - /// Prepares a raw value to hold a specified type. + /// Constructs a Value from a specified uint. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] - static extern void g_value_init (IntPtr val, - TypeFundamentals type); + [DllImport("gobject-2.0")] + static extern void g_value_set_uint (IntPtr val, uint data); - public void Init (TypeFundamentals type) + public Value (uint val) { - g_value_init (_val, type); + _val = gtksharp_value_create (TypeFundamentals.TypeUInt); + g_value_set_uint (_val, val); } /// @@ -148,8 +210,7 @@ namespace GLib { /// boolean value. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] + [DllImport("gobject-2.0")] static extern bool g_value_get_boolean (IntPtr val); public static explicit operator bool (Value val) @@ -159,6 +220,67 @@ namespace GLib { return g_value_get_boolean (val._val); } + /// + /// Value to Boxed Conversion + /// + /// + /// + /// Extracts a boxed type from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// boxed type value. + /// + + [DllImport("gobject-2.0")] + static extern IntPtr g_value_get_boxed (IntPtr val); + + public static explicit operator GLib.Boxed (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + // FIXME: Figure out how to wrap this boxed type + return null; + } + + /// + /// Value to Double Conversion + /// + /// + /// + /// Extracts a double from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// double value. + /// + + [DllImport("gobject-2.0")] + static extern double g_value_get_double (IntPtr val); + + public static explicit operator double (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return g_value_get_double (val._val); + } + + /// + /// Value to Float Conversion + /// + /// + /// + /// Extracts a float from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// float value. + /// + + [DllImport("gobject-2.0")] + static extern float g_value_get_float (IntPtr val); + + public static explicit operator float (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return g_value_get_float (val._val); + } + /// /// Value to Integer Conversion /// @@ -169,8 +291,7 @@ namespace GLib { /// integer value. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] + [DllImport("gobject-2.0")] static extern int g_value_get_int (IntPtr val); public static explicit operator int (Value val) @@ -180,6 +301,46 @@ namespace GLib { return g_value_get_int (val._val); } + /// + /// Value to Object Conversion + /// + /// + /// + /// Extracts an object from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// object value. + /// + + [DllImport("gobject-2.0")] + static extern IntPtr g_value_get_object (IntPtr val); + + public static explicit operator GLib.Object (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return GLib.Object.GetObject(g_value_get_object (val._val)); + } + + /// + /// Value to Pointer Conversion + /// + /// + /// + /// Extracts a pointer from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// pointer value. + /// + + [DllImport("gobject-2.0")] + static extern IntPtr g_value_get_pointer (IntPtr val); + + public static explicit operator IntPtr (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return g_value_get_pointer (val._val); + } + /// /// Value to String Conversion /// @@ -190,8 +351,7 @@ namespace GLib { /// string value. /// - [DllImport("gobject-2.0", - CallingConvention=CallingConvention.Cdecl)] + [DllImport("gobject-2.0")] static extern string g_value_get_string (IntPtr val); public static explicit operator String (Value val) @@ -202,14 +362,34 @@ namespace GLib { } /// - /// MarshalAs Property + /// Value to Unsigned Integer Conversion + /// + /// + /// + /// Extracts an uint from a Value. Note, this method + /// will produce an exception if the Value does not hold a + /// unsigned integer value. + /// + + [DllImport("gobject-2.0")] + static extern uint g_value_get_uint (IntPtr val); + + public static explicit operator uint (Value val) + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return g_value_get_uint (val._val); + } + + /// + /// Handle Property /// /// /// /// Read only. Accesses a pointer to the raw GValue. /// - public IntPtr MarshalAs { + public IntPtr Handle { get { return _val; } diff --git a/glib/makefile.win32 b/glib/makefile.win32 new file mode 100644 index 000000000..d44fd5e19 --- /dev/null +++ b/glib/makefile.win32 @@ -0,0 +1,5 @@ +all: windows + +windows: + $(CSC) /unsafe /target:library /out:glib-sharp.dll /recurse:*.cs + diff --git a/gtk/.cvsignore b/gtk/.cvsignore index 7851f6209..c0c9b37f9 100755 --- a/gtk/.cvsignore +++ b/gtk/.cvsignore @@ -1,4 +1,5 @@ *.dll *.exe generated +Makefile diff --git a/gtk/makefile b/gtk/Makefile.in similarity index 81% rename from gtk/makefile rename to gtk/Makefile.in index ff53752bb..865e3a55f 100755 --- a/gtk/makefile +++ b/gtk/Makefile.in @@ -1,15 +1,20 @@ MCS=mcs -all: +all: linux @echo "You must use 'make windows' or 'make unix'." @echo "'make unix' is broken for now." 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 -linux: +linux: gtk-sharp.dll + +gtk-sharp.dll: *.cs generated/*.cs $(MCS) --unsafe --target library -r ../glib/glib-sharp.dll -r ../pango/pango-sharp.dll -r ../atk/atk-sharp.dll -r ../gdk/gdk-sharp.dll -o gtk-sharp.dll --recurse *.cs unix: @echo "'make unix' is broken for now." +install: all + cp gtk-sharp.dll @prefix@/lib + diff --git a/gtk/makefile.win32 b/gtk/makefile.win32 new file mode 100644 index 000000000..4cbe995e4 --- /dev/null +++ b/gtk/makefile.win32 @@ -0,0 +1,5 @@ +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 + diff --git a/makefile b/makefile index 6aa954406..87c6efae0 100644 --- a/makefile +++ b/makefile @@ -1,11 +1,9 @@ -DIRS=generator glib pango atk gdk gtk sample +DIRS=glue generator glib pango atk gdk gtk sample ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe MCS=mcs -all: - @echo "You must use 'make windows' or 'make linux'." - @echo "'make unix' is broken for now." +all: linux windows: for i in $(DIRS); do \ @@ -16,8 +14,12 @@ unix: @echo "'make unix' is broken for now." linux: - (cd glue;make) || exit 1 for i in $(DIRS); do \ - (cd $$i; MCS="$(MCS)" make linux) || exit 1;\ + (cd $$i; MCS="$(MCS)" make) || exit 1;\ + done; + +install: + for i in $(DIRS); do \ + (cd $$i; make install) || exit 1; \ done; diff --git a/makefile.win32 b/makefile.win32 new file mode 100755 index 000000000..90248043b --- /dev/null +++ b/makefile.win32 @@ -0,0 +1,11 @@ +DIRS=generator glib pango atk gdk gtk sample +ROOT=/cygdrive/$(subst \,/,$(subst :\,/,$(SYSTEMROOT))) +CSC=$(ROOT)/microsoft.net/framework/v1.0.3705/csc.exe + +all: windows + +windows: + for i in $(DIRS); do \ + (cd $$i; CSC=$(CSC) make -f makefile.win32) || exit 1;\ + done; + diff --git a/pango/.cvsignore b/pango/.cvsignore index 7851f6209..c0c9b37f9 100644 --- a/pango/.cvsignore +++ b/pango/.cvsignore @@ -1,4 +1,5 @@ *.dll *.exe generated +Makefile diff --git a/pango/makefile b/pango/Makefile.in similarity index 68% rename from pango/makefile rename to pango/Makefile.in index 0f68e9016..74a6374de 100644 --- a/pango/makefile +++ b/pango/Makefile.in @@ -1,14 +1,18 @@ MCS=mcs -all: - @echo "You must use 'make windows' or 'make unix'." - @echo "'make unix' is broken for now." +all: linux windows: $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /out:pango-sharp.dll /recurse:*.cs -linux: +linux: pango-sharp.dll + +pango-sharp.dll: generated/*.cs $(MCS) --unsafe --target library -r ../glib/glib-sharp.dll -o pango-sharp.dll --recurse *.cs unix: @echo "'make unix' is broken for now." + +install: all + cp pango-sharp.dll @prefix@/lib + diff --git a/pango/makefile.win32 b/pango/makefile.win32 new file mode 100644 index 000000000..5e4fabd9b --- /dev/null +++ b/pango/makefile.win32 @@ -0,0 +1,5 @@ +all: windows + +windows: + $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /out:pango-sharp.dll /recurse:*.cs + diff --git a/sample/.cvsignore b/sample/.cvsignore index 7851f6209..c0c9b37f9 100755 --- a/sample/.cvsignore +++ b/sample/.cvsignore @@ -1,4 +1,5 @@ *.dll *.exe generated +Makefile diff --git a/sample/Makefile.in b/sample/Makefile.in new file mode 100755 index 000000000..852015e72 --- /dev/null +++ b/sample/Makefile.in @@ -0,0 +1,21 @@ +MCS=mcs + +all: linux + +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 + +gtk-hello-world.exe: HelloWorld.cs + $(MCS) --unsafe -o gtk-hello-world.exe -r ../glib/glib-sharp.dll -r ../gtk/gtk-sharp.dll -r ../gdk/gdk-sharp.dll HelloWorld.cs + +button.exe: ButtonApp.cs + $(MCS) --unsafe -o button.exe -r ../glib/glib-sharp.dll -r ../gtk/gtk-sharp.dll ButtonApp.cs + +unix: + @echo "'make unix' is broken for now." + +install: + diff --git a/sample/makefile b/sample/makefile.win32 old mode 100755 new mode 100644 similarity index 62% rename from sample/makefile rename to sample/makefile.win32 index ab47636e7..5dba2b60f --- a/sample/makefile +++ b/sample/makefile.win32 @@ -1,10 +1,6 @@ -all: - @echo "You must use 'make windows' or 'make unix'." - @echo "'make unix' is broken for now." +all: windows 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 -unix: - @echo "'make unix' is broken for now."