From ed804756cca35b2ffb186da3ae6859664eefc86f Mon Sep 17 00:00:00 2001 From: Christian Hoff Date: Wed, 19 Aug 2009 16:07:44 +0000 Subject: [PATCH] 2009-08-19 Christian Hoff * glib/MainContext.cs: Add API to create new MainContexts. Add a few missing methods. * glib/MainLoop.cs: Allow creating MainLoops in non-default MainContexts. [Fixes #526232] * glib/MainContext.xml, glib/MainLoop.xml: Add docs for the new API. svn path=/trunk/gtk-sharp/; revision=140256 --- ChangeLog | 7 ++ doc/ChangeLog | 4 + doc/en/GLib/MainContext.xml | 168 ++++++++++++++++++++++++++++++++++-- doc/en/GLib/MainLoop.xml | 74 +++++++++++++++- glib/MainContext.cs | 131 +++++++++++++++++++++++++--- glib/MainLoop.cs | 31 ++++++- 6 files changed, 397 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63085fe01..966a50981 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-08-19 Christian Hoff + + * glib/MainContext.cs: Add API to create new MainContexts. Add a few + missing methods. + * glib/MainLoop.cs: Allow creating MainLoops in non-default MainContexts. + [Fixes #526232] + 2009-08-18 Christian Hoff * sample/GtkDemo/Makefile.am: Resurrect local Mono.Cairo build. diff --git a/doc/ChangeLog b/doc/ChangeLog index f21f92be4..60dce9c85 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2009-08-19 Christian Hoff + + * glib/MainContext.xml, glib/MainLoop.xml: Add docs for the new API. + 2008-03-17 Mike Kestner * en/Gtk/HBox.xml: diff --git a/doc/en/GLib/MainContext.xml b/doc/en/GLib/MainContext.xml index c238f2aba..f35ae58c8 100644 --- a/doc/en/GLib/MainContext.xml +++ b/doc/en/GLib/MainContext.xml @@ -25,6 +25,21 @@ This is the default constructor for . + + + Property + + GLib.MainContext + + + Returns the default main context. + + + + + + + Property @@ -37,6 +52,64 @@ + + + Method + + System.Boolean + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + System.Void + + + + To be added. + To be added. + + + + + + Method + + System.Int32 + + + + To be added. + To be added. + To be added. + + + + + + Property + + System.Boolean + + + Checks if any sources have pending events for the given context. + An object of type + + + + + Method @@ -51,19 +124,19 @@ - + Method System.Boolean - + - an object of type + an object of type Runs a single iteration for the given main loop. an object of type - This involves checking to see if any event sources are ready to be processed, then if no events sources are ready and is , waiting for a source to become ready, then dispatching the highest priority events sources that are ready. Note that even when is , it is still possible for g_main_context_iteration() to return , since the the wait may be interrupted for other reasons than an event source becoming ready. + This is a convenience function for GLib.MainContext.Default.RunIteration(may_block). @@ -76,7 +149,92 @@ Checks if any sources have pending events for the given context. an object of type - + This is a convenince function for GLib.MainContext.Default.HasPendingEvents. + + + + + Method + + System.Void + + + + To be added. + To be added. + + + + + + Method + + System.Void + + + + To be added. + To be added. + + + + + + Method + + System.Boolean + + + + Runs a single iteration for the given main loop. + + if successful. + This is a convenience overload for GLib.MainContext.Default.RunIteration(System.Boolean) with passed in. + + + + + + Method + + System.Boolean + + + + + + To be added. + Runs a single iteration for the given main loop. + + if successful. + This involves checking to see if any event sources are ready to be processed, then if no events sources are ready and is , waiting for a source to become ready, then dispatching the highest priority events sources that are ready. Note that even when is , it is still possible for g_main_context_iteration() to return , since the the wait may be interrupted for other reasons than an event source becoming ready. + + + + + + Property + + GLib.MainContext + + + Returns the default MainContext for the current thread. If none exists, one will be created. + To be added. + When being called from the Gtk# main loop, returns . + + + + + + Method + + System.Void + + + + To be added. + To be added. + diff --git a/doc/en/GLib/MainLoop.xml b/doc/en/GLib/MainLoop.xml index 5a32db8dc..c2fb2f8ea 100644 --- a/doc/en/GLib/MainLoop.xml +++ b/doc/en/GLib/MainLoop.xml @@ -21,11 +21,69 @@ - Default constructor + Creates a new main loop in the default context. + + + Constructor + + + + + The context in which to create the main loop. + Creates a new main loop in the specified context. + + + + + + + Constructor + + + + + + The context in which to create the main loop + Indicates whether the main loop is currently running. + Creates a new main loop. + + + + + + + Property + + GLib.MainContext + + + returns the in which this main loop was created. + + + + + + + + Method + + System.Boolean + + + + + + To be added. + To be added. + True if "o" and "this" are equal/share the same native handle. + + + + Method @@ -38,6 +96,20 @@ + + + Method + + System.Int32 + + + + To be added. + To be added. + To be added. + + + Property diff --git a/glib/MainContext.cs b/glib/MainContext.cs index a56899bce..6caed6348 100644 --- a/glib/MainContext.cs +++ b/glib/MainContext.cs @@ -25,32 +25,143 @@ namespace GLib { using System.Runtime.InteropServices; public class MainContext { - + IntPtr handle; + + [DllImport("libglib-2.0-0.dll")] + static extern IntPtr g_main_context_new (); + + public MainContext () + { + handle = g_main_context_new (); + } + + [DllImport("libglib-2.0-0.dll")] + static extern void g_main_context_ref (IntPtr raw); + + internal MainContext (IntPtr raw) + { + handle = raw; + g_main_context_ref (handle); + } + + internal IntPtr Handle { + get { + return handle; + } + } + + [DllImport("libglib-2.0-0.dll")] + static extern void g_main_context_unref (IntPtr raw); + + ~MainContext () + { + g_main_context_unref (handle); + handle = IntPtr.Zero; + } + + [DllImport("libglib-2.0-0.dll")] + static extern IntPtr g_main_context_default (); + + public static MainContext Default { + get { + return new MainContext (g_main_context_default ()); + } + } + + [DllImport("libglib-2.0-0.dll")] + static extern IntPtr g_main_context_thread_default (); + + public MainContext ThreadDefault { + get { + IntPtr raw = g_main_context_thread_default (); + // NULL is returned if the thread-default main context is the default context. We'd rather not adopt this strange bahaviour. + return raw == IntPtr.Zero ? Default : new MainContext (raw); + } + } + + [DllImport("libglib-2.0-0.dll")] + static extern void g_main_context_push_thread_default (IntPtr raw); + + public void PushThreadDefault () + { + g_main_context_push_thread_default (handle); + } + + [DllImport("libglib-2.0-0.dll")] + static extern void g_main_context_pop_thread_default (IntPtr raw); + + public void PopThreadDefault () + { + g_main_context_pop_thread_default (handle); + } + + + [DllImport("libglib-2.0-0.dll")] + static extern bool g_main_context_iteration (IntPtr raw, bool may_block); + + public bool RunIteration (bool may_block) + { + return g_main_context_iteration (handle, may_block); + } + + public bool RunIteration () + { + return RunIteration (false); + } + + [DllImport("libglib-2.0-0.dll")] + static extern bool g_main_context_pending (IntPtr raw); + + public bool HasPendingEvents + { + get { + return g_main_context_pending (handle); + } + } + + [DllImport("libglib-2.0-0.dll")] + static extern void g_main_context_wakeup (IntPtr raw); + + public void Wakeup () + { + g_main_context_wakeup (handle); + } + + + public override bool Equals (object o) + { + if (!(o is MainContext)) + return false; + + return Handle == (o as MainContext).Handle; + } + + public override int GetHashCode () + { + return Handle.GetHashCode (); + } + + [DllImport("libglib-2.0-0.dll")] static extern int g_main_depth (); public static int Depth { get { return g_main_depth (); } } - [DllImport("libglib-2.0-0.dll")] - static extern bool g_main_context_iteration (IntPtr Raw, bool MayBlock); public static bool Iteration () { - return g_main_context_iteration (IntPtr.Zero, false); + return Iteration (false); } - public static bool Iteration (bool MayBlock) + public static bool Iteration (bool may_block) { - return g_main_context_iteration (IntPtr.Zero, MayBlock); + return Default.RunIteration (may_block); } - [DllImport("libglib-2.0-0.dll")] - static extern bool g_main_context_pending (IntPtr Raw); - public static bool Pending () { - return g_main_context_pending (IntPtr.Zero); + return Default.HasPendingEvents; } } } diff --git a/glib/MainLoop.cs b/glib/MainLoop.cs index 67caf4319..d61345b50 100644 --- a/glib/MainLoop.cs +++ b/glib/MainLoop.cs @@ -28,9 +28,13 @@ namespace GLib { [DllImport("libglib-2.0-0.dll")] static extern IntPtr g_main_loop_new (IntPtr context, bool isRunning); - public MainLoop () + public MainLoop () : this (MainContext.Default) { } + + public MainLoop (MainContext context) : this (context, false) { } + + public MainLoop (MainContext context, bool is_running) { - handle = g_main_loop_new (IntPtr.Zero, false); + handle = g_main_loop_new (context.Handle, is_running); } [DllImport("libglib-2.0-0.dll")] @@ -66,6 +70,29 @@ namespace GLib { { g_main_loop_quit (handle); } + + [DllImport("libglib-2.0-0.dll")] + static extern IntPtr g_main_loop_get_context (IntPtr loop); + + public MainContext Context { + get { + return new MainContext (g_main_loop_get_context (handle)); + } + } + + + public override bool Equals (object o) + { + if (!(o is MainLoop)) + return false; + + return handle == (o as MainLoop).handle; + } + + public override int GetHashCode () + { + return handle.GetHashCode (); + } } }