diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2013-11-14 17:00:30 +0400 |
---|---|---|
committer | Lluis Sanchez <lluis@xamarin.com> | 2013-11-14 17:00:30 +0400 |
commit | 1c9ab98e8c90e080abbc5629a89d0603f88b68a4 (patch) | |
tree | f9f70933fcd7ed380a4c72d69ebe3fd1fb0db3e7 /Xwt.Mac | |
parent | 2cf479a5b8c8b9592e1ecff7ffc3c2a05cfed055 (diff) |
[Mac] Fixes for the closing event unit tests
Diffstat (limited to 'Xwt.Mac')
-rw-r--r-- | Xwt.Mac/Xwt.Mac/DialogBackend.cs | 15 | ||||
-rw-r--r-- | Xwt.Mac/Xwt.Mac/WindowBackend.cs | 31 |
2 files changed, 40 insertions, 6 deletions
diff --git a/Xwt.Mac/Xwt.Mac/DialogBackend.cs b/Xwt.Mac/Xwt.Mac/DialogBackend.cs index dc1ec092..a0a05d20 100644 --- a/Xwt.Mac/Xwt.Mac/DialogBackend.cs +++ b/Xwt.Mac/Xwt.Mac/DialogBackend.cs @@ -58,14 +58,13 @@ namespace Xwt.Mac }; buttonBoxView = ((ViewBackend)buttonBox.GetBackend ()).Widget; ContentView.AddSubview (buttonBoxView); - - WillClose += HandleWillClose; } - void HandleWillClose (object sender, EventArgs e) + protected override void OnClosed () { + base.OnClosed (); if (modalSessionRunning) - EndLoop (); + InternalEndLoop (); } public override void LayoutWindow () @@ -141,6 +140,14 @@ namespace Xwt.Mac public void EndLoop () { + if (RequestClose ()) { + InternalEndLoop (); + ApplicationContext.InvokeUserCode (EventSink.OnClosed); + } + } + + public void InternalEndLoop () + { modalSessionRunning = false; NSApplication.SharedApplication.StopModal (); } diff --git a/Xwt.Mac/Xwt.Mac/WindowBackend.cs b/Xwt.Mac/Xwt.Mac/WindowBackend.cs index 952a8541..19f8f5d9 100644 --- a/Xwt.Mac/Xwt.Mac/WindowBackend.cs +++ b/Xwt.Mac/Xwt.Mac/WindowBackend.cs @@ -63,6 +63,10 @@ namespace Xwt.Mac // TODO: do it only if mouse move events are enabled in a widget AcceptsMouseMovedEvents = true; + WillClose += delegate { + OnClosed (); + }; + Center (); } @@ -200,10 +204,26 @@ namespace Xwt.Mac bool OnShouldClose (NSObject ob) { + return RequestClose (); + } + + internal bool RequestClose () + { bool res = true; ApplicationContext.InvokeUserCode (() => res = eventSink.OnCloseRequested ()); return res; } + + protected virtual void OnClosed () + { + if (!disposing) + ApplicationContext.InvokeUserCode (eventSink.OnClosed); + } + + void IWindowFrameBackend.Close () + { + PerformClose (this); + } bool VisibilityEventsEnabled () { @@ -406,10 +426,17 @@ namespace Xwt.Mac #endregion static Selector closeSel = new Selector ("close"); - + + bool disposing; + void IWindowFrameBackend.Dispose () { - Messaging.void_objc_msgSend (this.Handle, closeSel.Handle); + disposing = true; + try { + Messaging.void_objc_msgSend (this.Handle, closeSel.Handle); + } finally { + disposing = false; + } } public void DragStart (TransferDataSource data, DragDropAction dragAction, object dragImage, double xhot, double yhot) |