commit 7d69671d49c4f916174d8d46fec79a905e600c4c Author: Mike Kestner Date: Sun Sep 16 23:15:56 2001 +0000 Initial revision svn path=/trunk/gtk-sharp/; revision=834 diff --git a/.cvsignore b/.cvsignore new file mode 100755 index 000000000..4e8ac1c1b --- /dev/null +++ b/.cvsignore @@ -0,0 +1,3 @@ +*.dll +*.exe + diff --git a/README b/README new file mode 100644 index 000000000..26543a265 --- /dev/null +++ b/README @@ -0,0 +1,11 @@ +Gtk# is a C# binding for the Gtk toolkit (www.gtk.org). The target is the +2.0 platform, and no plans are currently in place to backport to 1.2. + +The effort essentially boils down to an exercise in PInvoke against the C +dynamic libraries. It may end up being slow as hell, but we'll see when we get +there and adjust accordingly. + +The "Hello World" application in the sample directory has been executed +on Win32 using the Gtk and associated binaries provided by the Gimp Win32 +porting project. Links to these binaries can be found on the Gtk Homepage. + diff --git a/gtk/.Widget.cs.swp b/gtk/.Widget.cs.swp new file mode 100755 index 000000000..284cfa658 Binary files /dev/null and b/gtk/.Widget.cs.swp differ diff --git a/gtk/.cvsignore b/gtk/.cvsignore new file mode 100755 index 000000000..4e8ac1c1b --- /dev/null +++ b/gtk/.cvsignore @@ -0,0 +1,3 @@ +*.dll +*.exe + diff --git a/gtk/Application.cs b/gtk/Application.cs new file mode 100755 index 000000000..ce8e25f12 --- /dev/null +++ b/gtk/Application.cs @@ -0,0 +1,77 @@ +// GTK.Application.cs - GTK Main Event Loop class implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GTK { + + using System; + using System.Runtime.InteropServices; + + /// + /// Application Class + /// + /// + /// + /// Provides the initialization and event loop iteration related + /// methods for the GTK widget library. Since GTK is an event + /// driven toolkit, Applications register callbacks against various + /// events to handle user input. These callbacks are invoked from + /// the main event loop when events are detected. + /// + + public class Application { + + [DllImport("gtk-1.3")] + static extern void gtk_init (ref int argc, ref String[] argv); + + /// + /// Init Method + /// + /// + /// + /// Initializes GTK resources. + /// + + public static void Init (ref string[] args) + { + int argc = args.Length; + gtk_init (ref argc, ref args); + } + + /// + /// Run Method + /// + /// + /// + /// Begins the event loop iteration. + /// + + [DllImport("gtk-1.3")] + static extern void gtk_main (); + + public static void Run () + { + gtk_main (); + } + + + /// + /// Quit Method + /// + /// + /// + /// Terminates the event loop iteration. + /// + + [DllImport("gtk-1.3")] + static extern void gtk_main_quit (); + + public static void Quit () + { + gtk_main_quit (); + } + + } +} diff --git a/gtk/Object.cs b/gtk/Object.cs new file mode 100755 index 000000000..152f94fc0 --- /dev/null +++ b/gtk/Object.cs @@ -0,0 +1,36 @@ +// Object.cs - GtkObject class wrapper implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GTK { + + using System; + using System.Drawing; + using System.Runtime.InteropServices; + + public abstract class Object { + + protected IntPtr obj; + + protected delegate void SimpleCallback (IntPtr obj); + + [DllImport("gtk-1.3")] + static extern void gtk_signal_connect_full ( + IntPtr obj, string evname, + SimpleCallback cb, IntPtr unsupported, + IntPtr data, IntPtr destroycb, + int objsig, int after ); + + + protected void ConnectSignal (string name, SimpleCallback cb) + { + gtk_signal_connect_full (obj, name, cb, + new IntPtr (0), new IntPtr (0), + new IntPtr (0), 0, 0); + } + + + } +} diff --git a/gtk/Widget.cs b/gtk/Widget.cs new file mode 100755 index 000000000..d3280dfaa --- /dev/null +++ b/gtk/Widget.cs @@ -0,0 +1,68 @@ +// GTK.Widget.cs - GTK Widget class implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GTK { + + using System; + using System.Runtime.InteropServices; + + public abstract class Widget : Object { + + /// + /// ConnectEvents method + /// + /// + /// + /// Connects event handlers to the wrapped GTK widget. + /// It is not possible to perform this connection in a + /// constructor, since the leaf class constructor in which + /// the wrapped object is created is not executed until + /// after the base class' constructor. + /// + + protected void PrepareEvents () + { + ConnectSignal ("delete-event", + new SimpleCallback (EmitDeleteEvent)); + } + + private void EmitDeleteEvent (IntPtr obj) + { + if (Delete != null) { + EventArgs args = new EventArgs (); + Delete (this, args); + } + } + + /// + /// Delete Event + /// + /// + /// + /// Occurs when the Widget is deleted by the window + /// manager. + /// + + public event EventHandler Delete; + + /// + /// Show Method + /// + /// + /// + /// Makes the Widget visible on the display. + /// + + [DllImport("gtk-1.3")] + static extern void gtk_widget_show (IntPtr obj); + + public void Show () + { + gtk_widget_show (obj); + + } + } +} diff --git a/gtk/Window.cs b/gtk/Window.cs new file mode 100755 index 000000000..16ad39e05 --- /dev/null +++ b/gtk/Window.cs @@ -0,0 +1,162 @@ +// GTK.Window.cs - GTK Window class implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GTK { + + using System; + using System.Drawing; + using System.Runtime.InteropServices; + + public enum WindowType { + TopLevel, + Popup, + } + + public class Window : Widget { + + /// + /// Window Constructor + /// + /// + /// + /// Constructs a new Window of type TopLevel. + /// + + [DllImport("gtk-1.3")] + static extern IntPtr gtk_window_new (GTK.WindowType type); + + public Window () + { + obj = gtk_window_new (WindowType.TopLevel); + base.PrepareEvents (); + } + + /// + /// Window Constructor + /// + /// + /// + /// Constructs a new Window of type TopLevel with the + /// specified Title. + /// + + public Window (String title) : this () + { + this.Title = title; + } + +/* + /// + /// AllowGrow Property + /// + /// + /// + /// Indicates if the Window can be resized to larger than + /// the default size. + /// + + public bool AllowGrow { + get {;} + set {;} + } + + /// + /// AllowShrink Property + /// + /// + /// + /// Indicates if the Window can be resized to smaller than + /// the default size. + /// + + public bool AllowShrink { + get {;} + set {;} + } + + /// + /// DefaultSize Property + /// + /// + /// + /// The default Size of the Window in Screen Coordinates. + /// + + public Size DefaultSize { + get {;} + set {;} + } + + /// + /// DestroyWithParent Property + /// + /// + /// + /// Indicates if the Window should be destroyed when any + /// associated parent Windows are destroyed. + /// + + public bool DestroyWithParent { + get {;} + set {;} + } + + /// + /// IsModal Property + /// + /// + /// + /// Indicates if the Window is Modal. If true, the input + /// focus is grabbed by the Window and other Windows in + /// the application will not accept input until the Window + /// is closed. + /// + + public bool IsModal { + get {;} + set {;} + } +*/ + /// + /// Position Property + /// + /// + /// + /// The Position of the Window in Screen Coordinates. + /// + + [DllImport("gtk-1.3")] + static extern void gtk_window_set_position (IntPtr hnd, + int x, int y); + + public Point Position { + set + { + gtk_window_set_position ( + obj, value.X, value.Y); + } + } + + /// + /// Title Property + /// + /// + /// + /// The Title displayed in the Window's Title Bar. + /// + + [DllImport("gtk-1.3")] + static extern void gtk_window_set_title (IntPtr hnd, + String title); + + public String Title { + set + { + gtk_window_set_title (obj, value); + } + } + } +} diff --git a/gtk/makefile b/gtk/makefile new file mode 100755 index 000000000..a57c9efda --- /dev/null +++ b/gtk/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:gtk-sharp.dll /recurse:*.cs + +unix: + @echo "'make unix' is broken for now." diff --git a/sample/.cvsignore b/sample/.cvsignore new file mode 100755 index 000000000..4e8ac1c1b --- /dev/null +++ b/sample/.cvsignore @@ -0,0 +1,3 @@ +*.dll +*.exe + diff --git a/sample/HelloWorld.cs b/sample/HelloWorld.cs new file mode 100755 index 000000000..6c23b0aec --- /dev/null +++ b/sample/HelloWorld.cs @@ -0,0 +1,30 @@ +// TestWindow.cs - GTK Window class Test implementation +// +// Author: Mike Kestner +// +// (c) 2001 Mike Kestner + +namespace GtkSamples { + + using GTK; + using System; + + public class HelloWorld { + + public static int Main (string[] args) + { + Application.Init (ref args); + Window win = new Window ("Gtk# Hello World"); + win.Delete += new EventHandler (delete_cb); + win.Show (); + Application.Run (); + return 0; + } + + static void delete_cb (object obj, EventArgs args) + { + Application.Quit (); + } + + } +} diff --git a/sample/makefile b/sample/makefile new file mode 100755 index 000000000..c51a89626 --- /dev/null +++ b/sample/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 /out:gtk-hello-world.exe /r:../gtk/gtk-sharp.dll /recurse:*.cs + +unix: + @echo "'make unix' is broken for now."