2001-09-16 23:15:56 +00:00
|
|
|
// GTK.Application.cs - GTK Main Event Loop class implementation
|
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
2001-09-19 02:04:57 +00:00
|
|
|
namespace Gtk {
|
2001-09-16 23:15:56 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
2003-03-15 20:49:37 +00:00
|
|
|
using Gdk;
|
2001-09-16 23:15:56 +00:00
|
|
|
|
|
|
|
public class Application {
|
|
|
|
|
2003-03-11 02:26:25 +00:00
|
|
|
//
|
|
|
|
// Disables creation of instances.
|
|
|
|
//
|
|
|
|
private Application ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
2004-01-19 03:24:25 +00:00
|
|
|
static extern void gtk_init (ref int argc, ref IntPtr argv);
|
|
|
|
|
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
|
|
static extern bool gtk_init_check (ref int argc, ref IntPtr argv);
|
2002-03-26 01:29:43 +00:00
|
|
|
|
|
|
|
public static void Init ()
|
|
|
|
{
|
2004-01-19 03:24:25 +00:00
|
|
|
IntPtr argv = new IntPtr(0);
|
|
|
|
int argc = 0;
|
|
|
|
|
|
|
|
gtk_init (ref argc, ref argv);
|
2002-03-26 01:29:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-19 03:24:25 +00:00
|
|
|
static bool do_init (string progname, ref string[] args, bool check)
|
|
|
|
{
|
|
|
|
bool res = false;
|
|
|
|
string[] progargs = new string[args.Length + 1];
|
|
|
|
|
|
|
|
progargs[0] = progname;
|
|
|
|
args.CopyTo (progargs, 1);
|
|
|
|
|
2004-05-19 18:57:28 +00:00
|
|
|
IntPtr buf = GLib.Marshaller.ArgvToArrayPtr (progargs);
|
2004-01-19 03:24:25 +00:00
|
|
|
int argc = progargs.Length;
|
|
|
|
|
|
|
|
if (check)
|
|
|
|
res = gtk_init_check (ref argc, ref buf);
|
|
|
|
else
|
|
|
|
gtk_init (ref argc, ref buf);
|
|
|
|
|
|
|
|
// copy back the resulting argv, minus argv[0], which we're
|
|
|
|
// not interested in.
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
args = new string[0];
|
|
|
|
else {
|
2004-05-19 18:57:28 +00:00
|
|
|
progargs = GLib.Marshaller.ArrayPtrToArgv (buf, argc);
|
2004-01-19 03:24:25 +00:00
|
|
|
args = new string[argc - 1];
|
|
|
|
Array.Copy (progargs, 1, args, 0, argc - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2001-09-16 23:15:56 +00:00
|
|
|
|
2004-01-19 03:24:25 +00:00
|
|
|
public static void Init (string progname, ref string[] args)
|
2001-09-16 23:15:56 +00:00
|
|
|
{
|
2004-01-19 03:24:25 +00:00
|
|
|
do_init (progname, ref args, false);
|
2001-09-16 23:15:56 +00:00
|
|
|
}
|
|
|
|
|
2004-01-19 03:24:25 +00:00
|
|
|
public static bool InitCheck (string progname, ref string[] args)
|
2003-03-11 02:26:25 +00:00
|
|
|
{
|
2004-01-19 03:24:25 +00:00
|
|
|
return do_init (progname, ref args, true);
|
2003-03-11 02:26:25 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void gtk_main ();
|
|
|
|
|
2001-09-16 23:15:56 +00:00
|
|
|
public static void Run ()
|
|
|
|
{
|
|
|
|
gtk_main ();
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
2002-08-31 20:37:52 +00:00
|
|
|
static extern bool gtk_events_pending ();
|
|
|
|
|
|
|
|
|
|
|
|
public static bool EventsPending ()
|
|
|
|
{
|
|
|
|
return gtk_events_pending ();
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
2002-08-31 20:37:52 +00:00
|
|
|
static extern void gtk_main_iteration ();
|
|
|
|
|
2003-03-11 02:26:25 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
|
|
static extern bool gtk_main_iteration_do (bool blocking);
|
2002-08-31 20:37:52 +00:00
|
|
|
|
|
|
|
public static void RunIteration ()
|
|
|
|
{
|
|
|
|
gtk_main_iteration ();
|
|
|
|
}
|
|
|
|
|
2003-03-11 02:26:25 +00:00
|
|
|
public static bool RunIteration (bool blocking)
|
|
|
|
{
|
|
|
|
return gtk_main_iteration_do (blocking);
|
|
|
|
}
|
|
|
|
|
2003-02-22 04:34:56 +00:00
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
2002-06-23 18:49:33 +00:00
|
|
|
static extern void gtk_main_quit ();
|
2001-09-16 23:15:56 +00:00
|
|
|
|
|
|
|
public static void Quit ()
|
|
|
|
{
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
2003-03-11 02:26:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
[DllImport("libgtk-win32-2.0-0.dll")]
|
|
|
|
static extern IntPtr gtk_get_current_event ();
|
2003-03-15 20:49:37 +00:00
|
|
|
|
2004-02-20 22:33:32 +00:00
|
|
|
public static Gdk.Event CurrentEvent {
|
2003-03-15 20:49:37 +00:00
|
|
|
get {
|
2004-02-20 22:33:32 +00:00
|
|
|
return new Gdk.Event (gtk_get_current_event ());
|
2003-03-15 20:49:37 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-16 23:15:56 +00:00
|
|
|
}
|
|
|
|
}
|