From 91c58501fa1c01342985e611d64d347727ed1906 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Wed, 19 Sep 2001 11:37:15 +0000 Subject: [PATCH] 2001-09-19 Mike Kestner * HACKING : New rulez. * NOTES: Killed. We have a mailing list now for this kind of stuff. * glib/makefile : New, to build the new glib-sharp.dll target. * glib/Object.cs : (GetObject): Commented out. Design problems here. IntPtr's can't be used in the manner this code attempts to use them. (Data prop): Commented out. Apparently keyed properties are not supported. (Object prop): Renamed RawObject, and made it protected. (Events): Fixed to cause list to be initialized if null and then return the list. * glib/ObjectManager.cs : commented out entirely. Not sure what this code is trying to accomplish and it doesn't compile. * glib/Value.cs : New attempt at implementing GValues. Doesn't work yet. * gtk/Button.cs : Updated to use RawObject. (Clicked event): s/EmitDeleteEvent/EmitClickedEvent. (Button(String)): s/gtk_label_new_with_lable/gtk_button_new_with_label. * gtk/Label.cs : Fixed some yank and paste errors where 2 value params were getting passed to all the set_* property methods. * gtk/Window.cs : Fixed hanging GTK namespace ref. * sample/HelloWorld.cs : Fixed hanging GTK namespace ref. svn path=/trunk/gtk-sharp/; revision=884 --- ChangeLog | 33 +++++++++++++++++++ HACKING | 19 +++++++++++ NOTES | 39 ---------------------- glib/.cvsignore | 3 ++ glib/Object.cs | 32 +++++++++--------- glib/ObjectManager.cs | 10 +++--- glib/Value.cs | 77 +++++++++++++++++++++++++++++++++++++++++++ glib/makefile | 11 +++++++ gtk/Button.cs | 8 ++--- gtk/Label.cs | 40 +++++++++++----------- gtk/Object.cs | 7 ++-- gtk/Widget.cs | 2 +- gtk/Window.cs | 69 ++++++++++++++++++++++++++------------ gtk/makefile | 2 +- sample/HelloWorld.cs | 2 +- sample/makefile | 2 +- 16 files changed, 244 insertions(+), 112 deletions(-) create mode 100755 HACKING delete mode 100644 NOTES create mode 100755 glib/.cvsignore create mode 100755 glib/Value.cs create mode 100755 glib/makefile diff --git a/ChangeLog b/ChangeLog index d12a7a471..94190deee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2001-09-19 Mike Kestner + + * HACKING : New rulez. + * NOTES: Killed. We have a mailing list now for this kind of stuff. + * glib/makefile : New, to build the new glib-sharp.dll target. + * glib/Object.cs : (GetObject): Commented out. Design problems here. + IntPtr's can't be used in the manner this code attempts to use them. + (Data prop): Commented out. Apparently keyed properties are not + supported. + (Object prop): Renamed RawObject, and made it protected. + (Events): Fixed to cause list to be initialized if null and then + return the list. + * glib/ObjectManager.cs : commented out entirely. Not sure what this + code is trying to accomplish and it doesn't compile. + * glib/Value.cs : New attempt at implementing GValues. Doesn't work + yet. + * gtk/Button.cs : Updated to use RawObject. + (Clicked event): s/EmitDeleteEvent/EmitClickedEvent. + (Button(String)): s/gtk_label_new_with_lable/gtk_button_new_with_label. + * gtk/Label.cs : Fixed some yank and paste errors where 2 value params + were getting passed to all the set_* property methods. + * gtk/Window.cs : Fixed hanging GTK namespace ref. + * sample/HelloWorld.cs : Fixed hanging GTK namespace ref. + + +2001-09-18 Bob Smith + + * glib/Object.cs : Moved parts of gtk/Object.cs here, and added + static GetObject method and a Data property. + * glib/ObjectManager.cs : New. + * gtk/Object.cs : removed some GObject wrapping code. + * gtk/*.cs : Updated namespace from GTK to Gtk. + 2001-09-18 Bob Smith * gtk/Object.cs : Added EventList and Object properties. diff --git a/HACKING b/HACKING new file mode 100755 index 000000000..df6c9d4eb --- /dev/null +++ b/HACKING @@ -0,0 +1,19 @@ +Please please please hack on gtk-sharp. + +Okay, now for the details. + +Prior to checking anything into CVS, please send a patch to the mailing list +(gtk-sharp-list@ximian.com) for approval. Any patches should be submitted in +diff -u format. Also, it is assumed that the submitter has verified that the +patch does not break the build, and hopefully that it doesn't break runtime. + +Second, patches without Documentation comments will be seriously frowned upon, +if not outright rejected. All classes, methods, properties, events, etc... +that are non-private should be documented with XML comment tags. At a minimum, +the summary and remarks tags, plus returns and params, if applicable. + +Third, Make a ChangeLog entry. Get credit for your hard work, and let me know +who I need to get cranky with at a glance, instead of having to do cvs history +reports. :-) + +Fourth, please please please hack on gtk-sharp. diff --git a/NOTES b/NOTES deleted file mode 100644 index 4ed54513e..000000000 --- a/NOTES +++ /dev/null @@ -1,39 +0,0 @@ -Mike, - -We have some problems. Some methods are going to return a gtk widget which -will need to be wrapped again into a c# class. This will have a nasty -reaction when callbacks are added to the wrapper, then the wrapper is nuked -when complete. It will leave a rogue pointer of some kind laying around, and -callbacks won't work as expected. - -Proposed solution: -Every GTK# class is a wrapper class. With a constructor for a GtkWidget* and -one for a default _new. Events are done as in CVS, except that the events -object will need to be bound to the GtkWidget owning it, and when a wrapper -is created, that Events object is resurected. This way, even if there is no -wrapper in existance, signals will function properly, and multiple wrappers -will work properly too. The event object will register a delete signal with -the widget so that when its nuked, it has a chance to free itself. Are we -going to have to tell the garbage collector to stay away from this class? -We might need our own class for this, and this class might not be able to be -written in c#. - - -Problem number two is with taking an arbitrary GtkWidget, and constructing a -wrapper as needed. Which wrapper is created? A simple GtkWidget wouldnt work -too well if the GtkWidget is really a button. We need to deside how to -handle this. Should we just return a GtkWidget, and force the developer to -pass the GtkWidget back to a constructor for the desided apon Widget wrapper? -How does gtk itself deal with this? Are we going to need a database of -widget wrappers for this? - -Posible solution: -How does (ToType)GtkWidget work in c#. If the type you want to cast from is -not of the right type, but the ToType contains a constructor for GtkWidget, -will the cast succeed? If so, this will work quite nicely. Everything is a -GtkWidget object, and cast bindings as needed. If this does not work, can -the cast operator be overridden some how? If so, good deal. If not again, -see if System.Reflection has anything that will help in conjunction with the -GTK Type system. - -Bob diff --git a/glib/.cvsignore b/glib/.cvsignore new file mode 100755 index 000000000..4e8ac1c1b --- /dev/null +++ b/glib/.cvsignore @@ -0,0 +1,3 @@ +*.dll +*.exe + diff --git a/glib/Object.cs b/glib/Object.cs index a41b6b03d..41eb098ca 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -4,12 +4,15 @@ // // (c) 2001 Bob Smith -namespace Glib { +namespace GLib { using System; + using System.ComponentModel; using System.Runtime.InteropServices; public class Object { + +/* public static Object GetObject(IntPtr o) { if (o == null) throw new ArgumentNullException (); @@ -22,18 +25,15 @@ namespace Glib { { Object = o; } - protected IntPtr _obj; +*/ + private IntPtr _obj; - private IntPtr Object + protected IntPtr RawObject { - get - { + get { return _obj; } - set - { - if (value == null) throw new ArgumentNullException (); - _objectManager = null; + set { _obj = value; } } @@ -41,18 +41,19 @@ namespace Glib { private EventHandlerList _events; protected EventHandlerList Events { - get - { - if (_events != null) return _events; - _events = new EventHandlerList (); + get { + if (_events == null) + _events = new EventHandlerList (); + return _events; } } - [DllImport("gtk-1.3")] +/* + [DllImport("gobject-1.3")] static extern IntPtr g_object_get_data ( IntPtr object, String key ); - [DllImport("gtk-1.3")] + [DllImport("gobject-1.3")] static extern void g_object_set_data ( IntPtr object, String key, @@ -76,7 +77,6 @@ namespace Glib { IntPtr data, DestroyNotify destroy ); -/* void (*GObjectGetPropertyFunc) (GObject *object, guint property_id, diff --git a/glib/ObjectManager.cs b/glib/ObjectManager.cs index c251ee201..c6dbf5def 100644 --- a/glib/ObjectManager.cs +++ b/glib/ObjectManager.cs @@ -4,15 +4,14 @@ // // (c) 2001 Bob Smith -namespace Glib { +namespace GLib { using System; using System.Runtime.InteropServices; - protected delegate void DestroyNotify (IntPtr data); - +/* public class ObjectManager { - public ObjectManager(IntPtr o, Glib.Object go) + public ObjectManager(IntPtr o, Object go) { if (o == null || go -- null) throw new ArgumentNullException (); _gobj = go; @@ -23,6 +22,8 @@ namespace Glib { } public Glib.Object gobj; + protected delegate void DestroyNotify (IntPtr data); + private void DestroyNotifyEvent (IntPtr data) { gobj.gh.Free(); @@ -30,4 +31,5 @@ namespace Glib { } } +*/ } diff --git a/glib/Value.cs b/glib/Value.cs new file mode 100755 index 000000000..951625620 --- /dev/null +++ b/glib/Value.cs @@ -0,0 +1,77 @@ +// GLib.GValue.cs - GLib Value class implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + [StructLayout(LayoutKind.Sequential)] + public struct GValueStruct { + uint type; + IntPtr data1; + IntPtr data2; + IntPtr data3; + IntPtr data4; + } + + public class GValue { + + GValueStruct _val; + + /// + /// GValue Constructor + /// + /// + /// + /// Constructs a GValue from a string. + /// + + [DllImport("gobject-1.3")] + static extern void g_value_set_string (ref GValueStruct val, + String data); + + public GValue (String data) + { + g_value_set_string (ref _val, data); + } + + /// + /// GetString Method + /// + /// + /// + /// Extracts a string from a GValue. Note, this method + /// will produce an exception if the GValue does not hold a + /// string value. + /// + + [DllImport("gobject-1.3")] + static extern String g_value_get_string (ref GValueStruct val); + + public String GetString () + { + // FIXME: Insert an appropriate exception here if + // _val.type indicates an error. + return g_value_get_string (ref _val); + } + + /// + /// ValueStruct Property + /// + /// + /// + /// Accesses a structure which can be easily marshalled + /// via PInvoke to set properties on GObjects. + /// + + public GValueStruct ValueStruct { + get { + return _val; + } + } + } +} diff --git a/glib/makefile b/glib/makefile new file mode 100755 index 000000000..650a32239 --- /dev/null +++ b/glib/makefile @@ -0,0 +1,11 @@ +CSC=/cygdrive/c/windows/microsoft.net/framework/v1.0.2914/csc.exe + +all: + @echo "You must use 'make windows' or 'make unix'." + @echo "'make unix' is broken for now." + +windows: + $(CSC) /unsafe /target:library /out:glib-sharp.dll /recurse:*.cs + +unix: + @echo "'make unix' is broken for now." diff --git a/gtk/Button.cs b/gtk/Button.cs index 390b33558..096acfb9e 100644 --- a/gtk/Button.cs +++ b/gtk/Button.cs @@ -18,7 +18,7 @@ namespace Gtk { { if (Events[ClickedEvent] == null) { - ConnectSignal ("clicked", new SimpleCallback (EmitDeleteEvent)); + ConnectSignal ("clicked", new SimpleCallback (EmitClickedEvent)); } Events.AddHandler (ClickedEvent, value); } @@ -48,7 +48,7 @@ namespace Gtk { public Button (IntPtr o) { - Object = o; + RawObject = o; } /// @@ -60,11 +60,11 @@ namespace Gtk { /// [DllImport("gtk-1.3")] - static extern IntPtr gtk_label_new_with_label (String str); + static extern IntPtr gtk_button_new_with_label (String str); public Button (String str) { - Object = gtk_button_new_with_label (str); + RawObject = gtk_button_new_with_label (str); } } } diff --git a/gtk/Label.cs b/gtk/Label.cs index 38270367d..db5df56d6 100644 --- a/gtk/Label.cs +++ b/gtk/Label.cs @@ -21,7 +21,7 @@ namespace Gtk { public Label (IntPtr o) { - Object = o; + RawObject = o; } /// @@ -37,7 +37,7 @@ namespace Gtk { public Label (String str) { - Object = gtk_label_new (str); + RawObject = gtk_label_new (str); } /// @@ -49,18 +49,18 @@ namespace Gtk { /// [DllImport("gtk-1.3")] - static extern void gtk_label_set_text (IntPtr hnd, const String str); + static extern void gtk_label_set_text (IntPtr hnd, String str); [DllImport("gtk-1.3")] static extern String gtk_label_get_text (IntPtr hnd); public String Text { get { - return gtk_label_get_text (Object); + return gtk_label_get_text (RawObject); } set { - gtk_label_set_text (Object, value); + gtk_label_set_text (RawObject, value); } } @@ -73,12 +73,12 @@ namespace Gtk { /// [DllImport("gtk-1.3")] - static extern void gtk_label_set_markup (IntPtr hnd, const String str); + static extern void gtk_label_set_markup (IntPtr hnd, String str); public String Markup { set { - gtk_label_set_markup (Object, value); + gtk_label_set_markup (RawObject, value); } } @@ -89,23 +89,23 @@ namespace Gtk { /// /// Parsed content. /// - +/* [DllImport("gtk-1.3")] - static extern void gtk_label_set_label (IntPtr hnd, const String str); + static extern void gtk_label_set_label (IntPtr hnd, String str); [DllImport("gtk-1.3")] static extern String gtk_label_get_label (IntPtr hnd); public String Label { get { - return gtk_label_get_label (Object); + return gtk_label_get_label (RawObject); } set { - gtk_label_set_label (Object, value); + gtk_label_set_label (RawObject, value); } } - +*/ /// /// Selectable Property /// @@ -122,11 +122,11 @@ namespace Gtk { public bool Selectable { get { - return gtk_label_get_selectable (Object); + return gtk_label_get_selectable (RawObject); } set { - gtk_label_set_selectable (Object, value, value); + gtk_label_set_selectable (RawObject, value); } } @@ -146,11 +146,11 @@ namespace Gtk { public bool UseUnderline { get { - return gtk_label_get_use_underline (Object); + return gtk_label_get_use_underline (RawObject); } set { - gtk_label_set_use_underline (Object, value, value); + gtk_label_set_use_underline (RawObject, value); } } @@ -170,11 +170,11 @@ namespace Gtk { public bool UseMarkup { get { - return gtk_label_get_use_markup (Object); + return gtk_label_get_use_markup (RawObject); } set { - gtk_label_set_use_markup (Object, value, value); + gtk_label_set_use_markup (RawObject, value); } } @@ -194,11 +194,11 @@ namespace Gtk { public bool LineWrap { get { - return gtk_label_get_line_wrap (Object); + return gtk_label_get_line_wrap (RawObject); } set { - gtk_label_set_line_wrap (Object, value, value); + gtk_label_set_line_wrap (RawObject, value); } } diff --git a/gtk/Object.cs b/gtk/Object.cs index 9a9e83e47..474e60ef0 100755 --- a/gtk/Object.cs +++ b/gtk/Object.cs @@ -7,11 +7,10 @@ namespace Gtk { using System; - using System.Drawing; + using System.ComponentModel; using System.Runtime.InteropServices; - - public abstract class Object : Glib.Object { + public abstract class Object : GLib.Object { protected delegate void SimpleCallback (IntPtr obj); @@ -25,7 +24,7 @@ namespace Gtk { protected void ConnectSignal (string name, SimpleCallback cb) { - gtk_signal_connect_full (obj, name, cb, + gtk_signal_connect_full (RawObject, name, cb, new IntPtr (0), new IntPtr (0), new IntPtr (0), 0, 0); } diff --git a/gtk/Widget.cs b/gtk/Widget.cs index da25bd90c..b357dddd5 100755 --- a/gtk/Widget.cs +++ b/gtk/Widget.cs @@ -61,7 +61,7 @@ namespace Gtk { public void Show () { - gtk_widget_show (obj); + gtk_widget_show (RawObject); } } diff --git a/gtk/Window.cs b/gtk/Window.cs index a93bac393..32778b5a1 100755 --- a/gtk/Window.cs +++ b/gtk/Window.cs @@ -1,4 +1,4 @@ -// GTK.Window.cs - GTK Window class implementation +// Gtk.Window.cs - GTK Window class implementation // // Author: Mike Kestner // @@ -6,6 +6,7 @@ namespace Gtk { + using GLib; using System; using System.Drawing; using System.Runtime.InteropServices; @@ -27,7 +28,7 @@ namespace Gtk { public Window (IntPtr o) { - Object = o; + RawObject = o; } /// @@ -39,11 +40,11 @@ namespace Gtk { /// [DllImport("gtk-1.3")] - static extern IntPtr gtk_window_new (GTK.WindowType type); + static extern IntPtr gtk_window_new (WindowType type); public Window () { - Object = gtk_window_new (WindowType.TopLevel); + RawObject = gtk_window_new (WindowType.TopLevel); } /// @@ -71,8 +72,13 @@ namespace Gtk { /// public bool AllowGrow { - get {;} - set {;} + get { + GValue val = GetProp ("allow-grow"); + return (val != 0); + } + set { + SetProp ("allow-grow", new GValue (value)); + } } /// @@ -85,8 +91,13 @@ namespace Gtk { /// public bool AllowShrink { - get {;} - set {;} + get { + GValue val = GetProp ("allow-shrink"); + return (val != 0); + } + set { + SetProp ("allow-shrink", new GValue (value)); + } } /// @@ -98,8 +109,13 @@ namespace Gtk { /// public Size DefaultSize { - get {;} - set {;} + get { + GValue val = GetProp ("default-size"); + return (val != 0); + } + set { + SetProp ("default-size", new GValue (value)); + } } /// @@ -112,8 +128,13 @@ namespace Gtk { /// public bool DestroyWithParent { - get {;} - set {;} + get { + GValue val = GetProp ("allow-grow"); + return (val != 0); + } + set { + SetProp ("allow-grow", new GValue (value)); + } } /// @@ -128,8 +149,13 @@ namespace Gtk { /// public bool IsModal { - get {;} - set {;} + get { + GValue val = GetProp ("allow-grow"); + return (val != 0); + } + set { + SetProp ("allow-grow", new GValue (value)); + } } */ /// @@ -148,7 +174,7 @@ namespace Gtk { set { gtk_window_set_position ( - obj, value.X, value.Y); + RawObject, value.X, value.Y); } } @@ -160,14 +186,15 @@ namespace Gtk { /// The Title displayed in the Window's Title Bar. /// - [DllImport("gtk-1.3")] - static extern void gtk_window_set_title (IntPtr hnd, - String title); + [DllImport("gobject-1.3")] + static extern void g_object_set_property (String title, + ref GValueStruct vs); public String Title { - set - { - gtk_window_set_title (Object, value); + set { + GValue val = new GValue (value); + GValueStruct vs = val.ValueStruct; + g_object_set_property ("title", ref vs); } } } diff --git a/gtk/makefile b/gtk/makefile index a57c9efda..909d0cd7b 100755 --- a/gtk/makefile +++ b/gtk/makefile @@ -5,7 +5,7 @@ all: @echo "'make unix' is broken for now." windows: - $(CSC) /unsafe /target:library /out:gtk-sharp.dll /recurse:*.cs + $(CSC) /unsafe /target:library /r:../glib/glib-sharp.dll /out:gtk-sharp.dll /recurse:*.cs unix: @echo "'make unix' is broken for now." diff --git a/sample/HelloWorld.cs b/sample/HelloWorld.cs index 6c23b0aec..56d585f48 100755 --- a/sample/HelloWorld.cs +++ b/sample/HelloWorld.cs @@ -6,7 +6,7 @@ namespace GtkSamples { - using GTK; + using Gtk; using System; public class HelloWorld { diff --git a/sample/makefile b/sample/makefile index c51a89626..855e14341 100755 --- a/sample/makefile +++ b/sample/makefile @@ -5,7 +5,7 @@ all: @echo "'make unix' is broken for now." windows: - $(CSC) /unsafe /out:gtk-hello-world.exe /r:../gtk/gtk-sharp.dll /recurse:*.cs + $(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll /recurse:*.cs unix: @echo "'make unix' is broken for now."