mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 11:55:30 +00:00
2002-08-31 Rachel Hestilow <hestilow@ximian.com>
* 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
This commit is contained in:
parent
7dd24ae681
commit
a502336ccf
|
@ -1,3 +1,11 @@
|
|||
2002-08-31 Rachel Hestilow <hestilow@ximian.com>
|
||||
|
||||
* 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 <hestilow@ximian.com>
|
||||
|
||||
* generator/Method.cs: Re-enable "if null then new" behavior
|
||||
|
|
45
glib/Idle.cs
Executable file
45
glib/Idle.cs
Executable file
|
@ -0,0 +1,45 @@
|
|||
// GLib.Idle.cs - Idle class implementation
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@speakeasy.net>
|
||||
// Rachel Hestilow <hestilow@ximian.com>
|
||||
//
|
||||
// (c) 2002 Mike Kestner, Rachel Hestilow
|
||||
|
||||
namespace GLib {
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
/// IdleHandler Delegate
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Delegate used for idle handlerss in the GLib main loop. Return
|
||||
/// true to restart the idle. Returning false clears the
|
||||
/// idle.
|
||||
/// </remarks>
|
||||
|
||||
public delegate bool IdleHandler ();
|
||||
|
||||
/// <summary>
|
||||
/// Idle Class
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Allows the installation of Idle Handlers on the GLib main
|
||||
/// loop.
|
||||
/// </remarks>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +64,38 @@ namespace Gtk {
|
|||
gtk_main ();
|
||||
}
|
||||
|
||||
[DllImport("gtk-x11-2.0")]
|
||||
static extern bool gtk_events_pending ();
|
||||
|
||||
/// <summary>
|
||||
/// EventsPending Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Returns true if Gtk+ events are pending in the queue.
|
||||
/// </remarks>
|
||||
|
||||
public static bool EventsPending ()
|
||||
{
|
||||
return gtk_events_pending ();
|
||||
}
|
||||
|
||||
[DllImport("gtk-x11-2.0")]
|
||||
static extern void gtk_main_iteration ();
|
||||
|
||||
/// <summary>
|
||||
/// RunIteration Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Runs a single iteration of the event loop.
|
||||
/// </remarks>
|
||||
|
||||
public static void RunIteration ()
|
||||
{
|
||||
gtk_main_iteration ();
|
||||
}
|
||||
|
||||
[DllImport("gtk-x11-2.0")]
|
||||
static extern void gtk_main_quit ();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -109,9 +121,11 @@ namespace GtkSamples {
|
|||
|
||||
sw.Add (tv);
|
||||
|
||||
win.ShowAll ();
|
||||
dialog.Destroy ();
|
||||
dialog = null;
|
||||
|
||||
Application.Run ();
|
||||
win.ShowAll ();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue