Moved ui loop methods to a new class
Minor fixes
This commit is contained in:
Родитель
17b0051973
Коммит
afcd8b9a5e
|
@ -25,6 +25,7 @@
|
|||
// THE SOFTWARE.
|
||||
using System;
|
||||
using Samples;
|
||||
using Xwt;
|
||||
|
||||
namespace GtkTest
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ namespace GtkTest
|
|||
{
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
App.Run ("Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0");
|
||||
App.Run (ToolkitType.Gtk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace MacTest
|
|||
{
|
||||
static void Main (string [] args)
|
||||
{
|
||||
App.Run ("Xwt.Mac.MacEngine, Xwt.Mac, Version=1.0.0.0");
|
||||
App.Run (ToolkitType.Cocoa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace Samples
|
|||
{
|
||||
public class App
|
||||
{
|
||||
public static void Run (string engineType)
|
||||
public static void Run (ToolkitType type)
|
||||
{
|
||||
Application.Initialize (engineType);
|
||||
Application.Initialize (type);
|
||||
|
||||
MainWindow w = new MainWindow ();
|
||||
w.Title = "Xwt Demo Application";
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
using System;
|
||||
using Samples;
|
||||
using Xwt;
|
||||
|
||||
namespace WpfTest
|
||||
{
|
||||
|
@ -33,7 +34,7 @@ namespace WpfTest
|
|||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
App.Run ("Xwt.WPFBackend.WPFEngine, Xwt.WPF, Version=1.0.0.0");
|
||||
App.Run (ToolkitType.Wpf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -377,7 +377,4 @@
|
|||
</MonoDevelop>
|
||||
</ProjectExtensions>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Xwt.Engine\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace Xwt
|
|||
{
|
||||
static Toolkit toolkit;
|
||||
static ToolkitEngineBackend engine;
|
||||
static UILoop mainLoop;
|
||||
|
||||
static readonly TaskScheduler taskScheduler = new XwtTaskScheduler ();
|
||||
|
||||
|
@ -43,6 +44,10 @@ namespace Xwt
|
|||
get { return taskScheduler; }
|
||||
}
|
||||
|
||||
public static UILoop MainLoop {
|
||||
get { return mainLoop; }
|
||||
}
|
||||
|
||||
internal static System.Threading.Thread UIThread {
|
||||
get;
|
||||
private set;
|
||||
|
@ -55,13 +60,20 @@ namespace Xwt
|
|||
Initialize (null);
|
||||
}
|
||||
|
||||
public static void Initialize (ToolkitType type)
|
||||
{
|
||||
Initialize (Toolkit.GetBackendType (type));
|
||||
}
|
||||
|
||||
public static void Initialize (string backendType)
|
||||
{
|
||||
if (engine != null)
|
||||
return;
|
||||
|
||||
toolkit = Toolkit.Load (backendType);
|
||||
toolkit.SetActive ();
|
||||
engine = toolkit.Backend;
|
||||
mainLoop = new UILoop (toolkit);
|
||||
|
||||
UIThread = System.Threading.Thread.CurrentThread;
|
||||
}
|
||||
|
@ -150,21 +162,6 @@ namespace Xwt
|
|||
return t;
|
||||
}
|
||||
|
||||
public static void DispatchPendingEvents ()
|
||||
{
|
||||
try {
|
||||
toolkit.ExitUserCode (null);
|
||||
engine.DispatchPendingEvents ();
|
||||
} finally {
|
||||
toolkit.EnterUserCode ();
|
||||
}
|
||||
}
|
||||
|
||||
public static void QueueExitAction (Action a)
|
||||
{
|
||||
Toolkit.CurrentEngine.QueueExitAction (a);
|
||||
}
|
||||
|
||||
public static StatusIcon CreateStatusIcon ()
|
||||
{
|
||||
return new StatusIcon ();
|
||||
|
@ -180,46 +177,7 @@ namespace Xwt
|
|||
Application.engine.CancelTimerInvoke (Id);
|
||||
}
|
||||
}
|
||||
|
||||
static bool LoadBackend (string type)
|
||||
{
|
||||
int i = type.IndexOf (',');
|
||||
string assembly = type.Substring (i+1).Trim ();
|
||||
type = type.Substring (0, i).Trim ();
|
||||
try {
|
||||
Assembly asm = Assembly.Load (assembly);
|
||||
if (asm != null) {
|
||||
Type t = asm.GetType (type);
|
||||
if (t != null) {
|
||||
engine = (ToolkitEngineBackend) Activator.CreateInstance (t);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Console.WriteLine (ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void InitBackend (string type)
|
||||
{
|
||||
toolkit.EnterUserCode ();
|
||||
if (type != null && LoadBackend (type))
|
||||
return;
|
||||
|
||||
if (LoadBackend ("Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0"))
|
||||
return;
|
||||
|
||||
if (LoadBackend ("Xwt.Mac.MacEngine, Xwt.Mac, Version=1.0.0.0"))
|
||||
return;
|
||||
|
||||
if (LoadBackend ("Xwt.WPFBackend.WPFEngine, Xwt.WPF, Version=1.0.0.0"))
|
||||
return;
|
||||
|
||||
throw new InvalidOperationException ("Xwt engine not found");
|
||||
}
|
||||
|
||||
|
||||
internal static void NotifyException (Exception ex)
|
||||
{
|
||||
var unhandledException = UnhandledException;
|
||||
|
@ -234,6 +192,32 @@ namespace Xwt
|
|||
}
|
||||
}
|
||||
|
||||
public class UILoop
|
||||
{
|
||||
Toolkit toolkit;
|
||||
|
||||
internal UILoop (Toolkit toolkit)
|
||||
{
|
||||
this.toolkit = toolkit;
|
||||
}
|
||||
|
||||
public void DispatchPendingEvents ()
|
||||
{
|
||||
try {
|
||||
toolkit.ExitUserCode (null);
|
||||
toolkit.Backend.DispatchPendingEvents ();
|
||||
} finally {
|
||||
toolkit.EnterUserCode ();
|
||||
}
|
||||
}
|
||||
|
||||
public void QueueExitAction (Action a)
|
||||
{
|
||||
toolkit.QueueExitAction (a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum ToolkitType
|
||||
{
|
||||
Gtk,
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace Xwt
|
|||
}
|
||||
set {
|
||||
if (dataSource != value) {
|
||||
Backend.SetSource (dataSource, dataSource is IFrontend ? (IBackend)BackendHost.ToolkitEngine.GetSafeBackend (dataSource) : null);
|
||||
Backend.SetSource (value, value is IFrontend ? (IBackend)BackendHost.ToolkitEngine.GetSafeBackend (value) : null);
|
||||
dataSource = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,13 +65,13 @@ namespace Xwt
|
|||
if (fullTypeName != null && t.LoadBackend (fullTypeName))
|
||||
return t;
|
||||
|
||||
if (t.LoadBackend (ToolkitType.Gtk))
|
||||
if (t.LoadBackend (GetBackendType (ToolkitType.Gtk)))
|
||||
return t;
|
||||
|
||||
if (t.LoadBackend (ToolkitType.Cocoa))
|
||||
if (t.LoadBackend (GetBackendType (ToolkitType.Cocoa)))
|
||||
return t;
|
||||
|
||||
if (t.LoadBackend (ToolkitType.Wpf))
|
||||
if (t.LoadBackend (GetBackendType (ToolkitType.Wpf)))
|
||||
return t;
|
||||
|
||||
throw new InvalidOperationException ("Xwt engine not found");
|
||||
|
@ -80,21 +80,21 @@ namespace Xwt
|
|||
public static Toolkit Load (ToolkitType type)
|
||||
{
|
||||
Toolkit t = new Toolkit ();
|
||||
if (t.LoadBackend (type))
|
||||
if (t.LoadBackend (GetBackendType (type)))
|
||||
return t;
|
||||
else
|
||||
throw new InvalidOperationException ("Xwt engine not found");
|
||||
}
|
||||
|
||||
bool LoadBackend (ToolkitType type)
|
||||
internal static string GetBackendType (ToolkitType type)
|
||||
{
|
||||
switch (type) {
|
||||
case ToolkitType.Gtk:
|
||||
return LoadBackend ("Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0");
|
||||
return "Xwt.GtkBackend.GtkEngine, Xwt.Gtk, Version=1.0.0.0";
|
||||
case ToolkitType.Cocoa:
|
||||
return LoadBackend ("Xwt.Mac.MacEngine, Xwt.Mac, Version=1.0.0.0");
|
||||
return "Xwt.Mac.MacEngine, Xwt.Mac, Version=1.0.0.0";
|
||||
case ToolkitType.Wpf:
|
||||
return LoadBackend ("Xwt.WPFBackend.WPFEngine, Xwt.WPF, Version=1.0.0.0");
|
||||
return "Xwt.WPFBackend.WPFEngine, Xwt.WPF, Version=1.0.0.0";
|
||||
default:
|
||||
throw new ArgumentException ("Invalid toolkit type");
|
||||
}
|
||||
|
@ -135,6 +135,11 @@ namespace Xwt
|
|||
ImageBackendHandler = Backend.CreateSharedBackend<ImageBackendHandler> (typeof(Image));
|
||||
}
|
||||
|
||||
internal void SetActive ()
|
||||
{
|
||||
currentEngine = this;
|
||||
}
|
||||
|
||||
public object GetNativeWidget (Widget w)
|
||||
{
|
||||
ValidateObject (w);
|
||||
|
|
|
@ -128,7 +128,7 @@ namespace Xwt
|
|||
}
|
||||
set {
|
||||
if (dataSource != value) {
|
||||
Backend.SetSource (dataSource, dataSource is IFrontend ? (IBackend)BackendHost.ToolkitEngine.GetSafeBackend (dataSource) : null);
|
||||
Backend.SetSource (value, value is IFrontend ? (IBackend)BackendHost.ToolkitEngine.GetSafeBackend (value) : null);
|
||||
dataSource = value;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1080,7 +1080,7 @@ namespace Xwt
|
|||
QueueForSizeCheck (Parent);
|
||||
if (!delayedSizeNegotiationRequested) {
|
||||
delayedSizeNegotiationRequested = true;
|
||||
Application.QueueExitAction (DelayedResizeRequest);
|
||||
Application.MainLoop.QueueExitAction (DelayedResizeRequest);
|
||||
}
|
||||
}
|
||||
else if (ParentWindow is Window) {
|
||||
|
@ -1098,7 +1098,7 @@ namespace Xwt
|
|||
resizeWindows.Add ((Window)window);
|
||||
if (!delayedSizeNegotiationRequested) {
|
||||
delayedSizeNegotiationRequested = true;
|
||||
Application.QueueExitAction (DelayedResizeRequest);
|
||||
Application.MainLoop.QueueExitAction (DelayedResizeRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче