Browse Source

Make app shutdown when main window closed.

pull/4/head
Steven Kirk 12 years ago
parent
commit
255708de24
  1. 18
      Perspex.Windows/Window.cs
  2. 9
      Perspex/Application.cs
  3. 15
      Perspex/ICloseable.cs
  4. 1
      Perspex/Perspex.csproj
  5. 2
      TestApplication/Program.cs

18
Perspex.Windows/Window.cs

@ -23,7 +23,7 @@ namespace Perspex.Windows
using Perspex.Windows.Threading;
using Splat;
public class Window : ContentControl, ILayoutRoot, IRendered
public class Window : ContentControl, ILayoutRoot, IRendered, ICloseable
{
private UnmanagedMethods.WndProc wndProcDelegate;
@ -75,6 +75,8 @@ namespace Perspex.Windows
});
}
public event EventHandler Closed;
public Size ClientSize
{
get
@ -166,6 +168,14 @@ namespace Perspex.Windows
}
}
private void OnClosed()
{
if (this.Closed != null)
{
this.Closed(this, EventArgs.Empty);
}
}
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")]
private IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
@ -175,9 +185,9 @@ namespace Perspex.Windows
switch ((UnmanagedMethods.WindowsMessage)msg)
{
////case UnmanagedMethods.WindowsMessage.WM_DESTROY:
//// this.OnClosed();
//// break;
case UnmanagedMethods.WindowsMessage.WM_DESTROY:
this.OnClosed();
break;
case UnmanagedMethods.WindowsMessage.WM_KEYDOWN:
WindowsKeyboardDevice.Instance.UpdateKeyStates();

9
Perspex/Application.cs

@ -6,9 +6,11 @@
namespace Perspex
{
using System.Threading;
using Perspex.Controls;
using Perspex.Input;
using Perspex.Styling;
using Perspex.Threading;
using Splat;
public class Application
@ -85,5 +87,12 @@ namespace Perspex
Locator.CurrentMutable.Register(() => this.InputManager, typeof(IInputManager));
Locator.CurrentMutable.Register(() => styler, typeof(IStyler));
}
public void Run(ICloseable closable)
{
DispatcherFrame frame = new DispatcherFrame();
closable.Closed += (s, e) => frame.Continue = false;
Dispatcher.PushFrame(frame);
}
}
}

15
Perspex/ICloseable.cs

@ -0,0 +1,15 @@
// -----------------------------------------------------------------------
// <copyright file="ICloseable.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex
{
using System;
public interface ICloseable
{
event EventHandler Closed;
}
}

1
Perspex/Perspex.csproj

@ -101,6 +101,7 @@
<Compile Include="Controls\LogicalChildren.cs" />
<Compile Include="Controls\Panel.cs" />
<Compile Include="Controls\StackPanel.cs" />
<Compile Include="ICloseable.cs" />
<Compile Include="IHeadered.cs" />
<Compile Include="Diagnostics\Debug.cs" />
<Compile Include="Input\InputElement.cs" />

2
TestApplication/Program.cs

@ -234,7 +234,7 @@ namespace TestApplication
};
window.Show();
Dispatcher.Run();
Application.Current.Run(window);
}
}
}

Loading…
Cancel
Save