From aa1077bbb14894bf7bcb129554f11363d5b3c913 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sun, 7 Oct 2001 00:41:52 +0000 Subject: [PATCH] 2001-10-07 Mike Kestner * glib/Object.cs : Added public Handle property. It would be nice if I could make the RawObject public for get and protected for set, but that doesn't appear to be possible with C# properties. * gtk/Container.cs : New class with 2 of the 3 props and the Add/Remove methods only implemented. * gtk/Widget.cs : Added SizeRequest prop which is a combination of HeightRequest and SizeRequest. Embrace and extend gtk... * gtk/Window.cs : Derive from newly added Container subclass. * sample/ButtonApp.cs : Simple tire-kicking app. svn path=/trunk/gtk-sharp/; revision=1112 --- ChangeLog | 12 ++++++ glib/Object.cs | 23 ++++++++-- gtk/Container.cs | 100 ++++++++++++++++++++++++++++++++++++++++++++ gtk/Widget.cs | 19 +++++++++ gtk/Window.cs | 10 ++++- sample/ButtonApp.cs | 41 ++++++++++++++++++ sample/makefile | 3 +- 7 files changed, 203 insertions(+), 5 deletions(-) create mode 100644 gtk/Container.cs create mode 100755 sample/ButtonApp.cs diff --git a/ChangeLog b/ChangeLog index d53d7734f..a8b91739d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2001-10-07 Mike Kestner + + * glib/Object.cs : Added public Handle property. It would be nice + if I could make the RawObject public for get and protected for set, + but that doesn't appear to be possible with C# properties. + * gtk/Container.cs : New class with 2 of the 3 props and the Add/Remove + methods only implemented. + * gtk/Widget.cs : Added SizeRequest prop which is a combination of + HeightRequest and SizeRequest. Embrace and extend gtk... + * gtk/Window.cs : Derive from newly added Container subclass. + * sample/ButtonApp.cs : Simple tire-kicking app. + 2001-10-06 Mike Kestner * gtk/Button.cs : Implemented 3 constructors, 5 methods, 4 properties, diff --git a/glib/Object.cs b/glib/Object.cs index 70543eefe..9534627ae 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -58,8 +58,9 @@ namespace GLib { /// /// /// The raw GObject reference associated with this wrapper. - /// Only subclasses of Object should need to access this - /// unmanaged pointer. + /// Only subclasses of Object can access this read/write + /// property. For public read-only access, use the + /// Handle property. /// protected IntPtr RawObject { @@ -72,6 +73,22 @@ namespace GLib { } } + /// + /// Handle Property + /// + /// + /// + /// The raw GObject reference associated with this object. + /// Subclasses can use RawObject property for read/write + /// access. + /// + + public IntPtr Handle { + get { + return _obj; + } + } + /// /// Events Property /// @@ -81,7 +98,7 @@ namespace GLib { /// object indexed by the Gtk+ signal name. /// - public EventHandlerList Events { + protected EventHandlerList Events { get { if (_events == null) _events = new EventHandlerList (); diff --git a/gtk/Container.cs b/gtk/Container.cs new file mode 100644 index 000000000..6282a9c69 --- /dev/null +++ b/gtk/Container.cs @@ -0,0 +1,100 @@ +// Gtk.Container.cs - GtkContainer class wrapper implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace Gtk { + + using System; + using System.Runtime.InteropServices; + + /// + /// Container Class + /// + /// + /// + /// Abstract class which provides the capability to embed a + /// widget within its boundaries. + /// + + public abstract class Container : Widget { + + /// + /// BorderWidth Property + /// + /// + /// + /// The Width, in pixels, of the border around the + /// Container. + /// + + public int BorderWidth { + get { + int val; + GetProperty ("border-width", out val); + return val; + } + set { + SetProperty ("border-width", value); + } + } + + // FIXME: Implement Child property. + + /// + /// ResizeMode Property + /// + /// + /// + /// Indicates the resizing policy for the Container. + /// + + public ResizeMode ResizeMode { + get { + int val; + GetProperty ("border-width", out val); + return (ResizeMode) val; + } + set { + SetProperty ("border-width", (int) value); + } + } + + /// + /// Add Method + /// + /// + /// + /// Adds a child Widget to the Container. + /// + + [DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi, + CallingConvention=CallingConvention.Cdecl)] + static extern void gtk_container_add (IntPtr obj, IntPtr child); + + public void Add (Widget child) + { + gtk_container_add (Handle, child.Handle); + } + + /// + /// Remove Method + /// + /// + /// + /// Remove a child Widget from the Container. + /// + + [DllImport("gtk-1.3.dll", CharSet=CharSet.Ansi, + CallingConvention=CallingConvention.Cdecl)] + static extern void gtk_container_remove (IntPtr obj, + IntPtr child); + + public void Remove (Widget child) + { + gtk_container_remove (Handle, child.Handle); + } + + } +} diff --git a/gtk/Widget.cs b/gtk/Widget.cs index 463b53f0f..ee3798eb2 100755 --- a/gtk/Widget.cs +++ b/gtk/Widget.cs @@ -8,6 +8,7 @@ namespace Gtk { using System; using System.Collections; + using System.Drawing; using System.Runtime.InteropServices; using GLib; using Gdk; @@ -213,6 +214,24 @@ namespace Gtk { } } + /// + /// SizeRequest Property + /// + /// + /// + /// The desired size in pixels for the widget. + /// + + public Size SizeRequest { + get { + return new Size (WidthRequest, HeightRequest); + } + set { + WidthRequest = value.Width; + HeightRequest = value.Height; + } + } + /// /// Visible Property /// diff --git a/gtk/Window.cs b/gtk/Window.cs index a382ab6a3..5b502ab55 100755 --- a/gtk/Window.cs +++ b/gtk/Window.cs @@ -11,7 +11,15 @@ namespace Gtk { using System.Drawing; using System.Runtime.InteropServices; - public class Window : Widget { + /// + /// Window Class + /// + /// + /// + /// A Top Level Window object. + /// + + public class Window : Container { /// /// Window Object Constructor diff --git a/sample/ButtonApp.cs b/sample/ButtonApp.cs new file mode 100755 index 000000000..9514b8177 --- /dev/null +++ b/sample/ButtonApp.cs @@ -0,0 +1,41 @@ +// ButtonApp.cs - Gtk.Button class Test implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GtkSamples { + + using Gtk; + using System; + using System.Drawing; + + public class ButtonApp { + + public static int Main (string[] args) + { + Application.Init (ref args); + Window win = new Window ("Button Tester"); + win.DeleteEvent += new EventHandler (Window_Delete); + Button btn = new Button (); + btn.Clicked += new EventHandler (btn_click); + btn.SizeRequest = new Size (32, 24); + btn.Show (); + win.Add (btn); + win.Show (); + Application.Run (); + return 0; + } + + static void btn_click (object obj, EventArgs args) + { + Console.WriteLine ("Button Clicked"); + } + + static void Window_Delete (object obj, EventArgs args) + { + Application.Quit (); + } + + } +} diff --git a/sample/makefile b/sample/makefile index 45beaef1c..3ac05158e 100755 --- a/sample/makefile +++ b/sample/makefile @@ -3,7 +3,8 @@ all: @echo "'make unix' is broken for now." windows: - $(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-sharp.dll /recurse:*.cs + $(CSC) /unsafe /out:gtk-hello-world.exe /r:../glib/glib-sharp.dll /r:../gtk/gtk-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."