From a502336ccf3f0ff9b0f93541521b7b3ef31c9bf4 Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Sat, 31 Aug 2002 20:37:52 +0000 Subject: [PATCH] 2002-08-31 Rachel Hestilow * glib/Idle.cs: Added. * gtk/Application.cs: Add EventsPending, RunIteration. * sample/TreeViewDemo.cs: Add a status dialog while populating tree. svn path=/trunk/gtk-sharp/; revision=7164 --- ChangeLog | 8 ++++++ glib/Idle.cs | 45 +++++++++++++++++++++++++++++++ gtk/Application.cs | 32 ++++++++++++++++++++++ sample/TreeViewDemo.cs | 60 +++++++++++++++++++++++++++++++++++++----- 4 files changed, 139 insertions(+), 6 deletions(-) create mode 100755 glib/Idle.cs diff --git a/ChangeLog b/ChangeLog index 97914f8b8..78c8f614e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-08-31 Rachel Hestilow + + * glib/Idle.cs: Added. + * gtk/Application.cs: Add EventsPending, RunIteration. + + * sample/TreeViewDemo.cs: Add a status dialog while + populating tree. + 2002-08-31 Rachel Hestilow * generator/Method.cs: Re-enable "if null then new" behavior diff --git a/glib/Idle.cs b/glib/Idle.cs new file mode 100755 index 000000000..f5a1412d4 --- /dev/null +++ b/glib/Idle.cs @@ -0,0 +1,45 @@ +// GLib.Idle.cs - Idle class implementation +// +// Author: Mike Kestner +// Rachel Hestilow +// +// (c) 2002 Mike Kestner, Rachel Hestilow + +namespace GLib { + + using System; + using System.Runtime.InteropServices; + + /// + /// IdleHandler Delegate + /// + /// + /// + /// Delegate used for idle handlerss in the GLib main loop. Return + /// true to restart the idle. Returning false clears the + /// idle. + /// + + public delegate bool IdleHandler (); + + /// + /// Idle Class + /// + /// + /// + /// Allows the installation of Idle Handlers on the GLib main + /// loop. + /// + + public class Idle { + + [DllImport("glib-2.0")] + static extern uint g_idle_add (IdleHandler d, IntPtr data); + + public static uint Add (IdleHandler hndlr) + { + return g_idle_add (hndlr, IntPtr.Zero); + } + } +} + diff --git a/gtk/Application.cs b/gtk/Application.cs index c5a5ca3cb..d2c226b15 100755 --- a/gtk/Application.cs +++ b/gtk/Application.cs @@ -64,6 +64,38 @@ namespace Gtk { gtk_main (); } + [DllImport("gtk-x11-2.0")] + static extern bool gtk_events_pending (); + + /// + /// EventsPending Method + /// + /// + /// + /// Returns true if Gtk+ events are pending in the queue. + /// + + public static bool EventsPending () + { + return gtk_events_pending (); + } + + [DllImport("gtk-x11-2.0")] + static extern void gtk_main_iteration (); + + /// + /// RunIteration Method + /// + /// + /// + /// Runs a single iteration of the event loop. + /// + + public static void RunIteration () + { + gtk_main_iteration (); + } + [DllImport("gtk-x11-2.0")] static extern void gtk_main_quit (); diff --git a/sample/TreeViewDemo.cs b/sample/TreeViewDemo.cs index fdaf8f7ee..de628dc44 100644 --- a/sample/TreeViewDemo.cs +++ b/sample/TreeViewDemo.cs @@ -16,6 +16,8 @@ namespace GtkSamples { public class TreeViewDemo { private static TreeStore store = null; + private static Dialog dialog = null; + private static Label dialog_label = null; private static void ProcessType (TreeIter parent, Type t) { @@ -36,8 +38,11 @@ namespace GtkSamples { private static void ProcessAssembly (TreeIter parent, Assembly asm) { TreeIter iter = new TreeIter (); + string asm_name = asm.GetName ().Name; foreach (Type t in asm.GetTypes ()) { + UpdateDialog ("Loading from {0}:\n{1}", asm_name, t.ToString ()); + GLib.Value Name = new GLib.Value (t.Name); GLib.Value Type = new GLib.Value (t.ToString ()); @@ -54,8 +59,6 @@ namespace GtkSamples { if (store != null) return; - Console.WriteLine ("Loading data from assemblies..."); - store = new TreeStore ((int)TypeFundamentals.TypeString, (int)TypeFundamentals.TypeString); @@ -66,6 +69,8 @@ namespace GtkSamples { // stuff in some scary class. if (asm.GetName ().Name == "mscorlib") continue; + UpdateDialog ("Loading {0}", asm.GetName ().Name); + GLib.Value Name = new GLib.Value (asm.GetName ().Name); GLib.Value Type = new GLib.Value ("Assembly"); @@ -81,6 +86,15 @@ namespace GtkSamples { { Application.Init (); + Idle.Add (new IdleHandler (IdleCB)); + + Application.Run (); + } + + public static bool IdleCB () + { + PopulateStore (); + Window win = new Window ("TreeView demo"); win.DeleteEvent += new DeleteEventHandler (DeleteCB); win.DefaultSize = new Size (640,480); @@ -88,8 +102,6 @@ namespace GtkSamples { ScrolledWindow sw = new ScrolledWindow (); win.Add (sw); - PopulateStore (); - TreeView tv = new TreeView (store); tv.HeadersVisible = true; @@ -108,10 +120,12 @@ namespace GtkSamples { tv.AppendColumn (TypeCol); sw.Add (tv); + + dialog.Destroy (); + dialog = null; win.ShowAll (); - - Application.Run (); + return false; } private static void DeleteCB (Object o, DeleteEventArgs args) @@ -119,5 +133,39 @@ namespace GtkSamples { Application.Quit (); args.RetVal = true; } + + private static void UpdateDialog (string format, params object[] args) + { + string text = String.Format (format, args); + + if (dialog == null) + { + dialog = new Dialog (); + dialog.Title = "Loading data from assemblies..."; + dialog.AddButton (Stock.Cancel, 1); + dialog.Response += new ResponseHandler (ResponseCB); + dialog.DefaultSize = new Size (480, 100); + + VBox vbox = dialog.VBox; + HBox hbox = new HBox (false, 4); + vbox.PackStart (hbox, true, true, 0); + + Gtk.Image icon = new Gtk.Image (Stock.DialogInfo, IconSize.Dialog); + hbox.PackStart (icon, false, false, 0); + dialog_label = new Label (text); + hbox.PackStart (dialog_label, false, false, 0); + dialog.ShowAll (); + } else { + dialog_label.Text = text; + while (Application.EventsPending ()) + Application.RunIteration (); + } + } + + private static void ResponseCB (object obj, ResponseArgs args) + { + Application.Quit (); + System.Environment.Exit (0); + } } }