diff --git a/Gtk/Perspex.Gtk/GtkPlatform.cs b/Gtk/Perspex.Gtk/GtkPlatform.cs index 5b928fff1b..7a7a6c5f41 100644 --- a/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -24,8 +24,9 @@ namespace Perspex.Gtk public static void Initialize() { var locator = Locator.CurrentMutable; - //locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); - locator.Register(() => instance, typeof(IPlatformThreadingInterface)); + locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); + //locator.Register(() => WindowsKeyboardDevice.Instance, typeof(IKeyboardDevice)); + locator.Register(() => instance, typeof(IPlatformThreadingInterface)); } public void ProcessMessage () diff --git a/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 6f662d64e7..1f6e0ef54a 100644 --- a/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -1,4 +1,4 @@ - + Debug @@ -57,7 +57,7 @@ - + diff --git a/Gtk/Perspex.Gtk/Window.cs b/Gtk/Perspex.Gtk/Window.cs deleted file mode 100644 index 67111d34f6..0000000000 --- a/Gtk/Perspex.Gtk/Window.cs +++ /dev/null @@ -1,132 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright 2014 MIT Licence. See licence.md for more information. -// -// ----------------------------------------------------------------------- - -namespace Perspex.Gtk -{ - using System; - using System.Reactive.Linq; - using Perspex.Controls; - using Perspex.Controls.Presenters; - using Perspex.Input; - using Perspex.Layout; - using Perspex.Rendering; - using Perspex.Platform; - using Perspex.Threading; - using Splat; - using Gtk = global::Gtk; - - public class Window : ContentControl, ILayoutRoot, IRenderRoot, ICloseable - { - public static readonly PerspexProperty TitleProperty = - PerspexProperty.Register("Title"); - - private Gtk.Window inner; - - private Dispatcher dispatcher; - - private IRenderer renderer; - - public Window () - { - IPlatformRenderInterface factory = Locator.Current.GetService(); - - this.inner = new Gtk.Window(Gtk.WindowType.Toplevel); - inner.SetDefaultSize(1400, 800); - inner.SetPosition(Gtk.WindowPosition.Center); - - inner.DeleteEvent += (o, a) => - { - if (this.Closed != null) - { - this.Closed(this, EventArgs.Empty); - } - }; - - var clientSize = this.ClientSize; - this.renderer = factory.CreateRenderer(this.inner.Handle, (int)clientSize.Width, (int)clientSize.Height); - this.LayoutManager = new LayoutManager(this); - this.RenderManager = new RenderManager(); - this.Template = ControlTemplate.Create(this.DefaultTemplate); - - this.LayoutManager.LayoutNeeded.Subscribe(x => - { - this.dispatcher.InvokeAsync( - () => - { - this.LayoutManager.ExecuteLayoutPass(); - this.renderer.Render(this); - this.RenderManager.RenderFinished(); - }, - DispatcherPriority.Render); - }); - - this.RenderManager.RenderNeeded - .Where(_ => !this.LayoutManager.LayoutQueued) - .Subscribe(x => - { - this.dispatcher.InvokeAsync( - () => - { - if (!this.LayoutManager.LayoutQueued) - { - this.renderer.Render(this); - this.RenderManager.RenderFinished(); - } - }, - DispatcherPriority.Render); - }); - } - - public event System.EventHandler Closed; - - public Size ClientSize - { - get - { - int width; - int height; - this.inner.GetSize(out width, out height); - return new Size(width, height); - } - } - - public ILayoutManager LayoutManager - { - get; - private set; - } - - public IRenderManager RenderManager - { - get; - private set; - } - - public string Title - { - get { return this.GetValue(TitleProperty); } - set { this.SetValue(TitleProperty, value); } - } - - public void Show() - { - this.inner.Show(); - } - - private Control DefaultTemplate(Window c) - { - Border border = new Border(); - border.Background = new Perspex.Media.SolidColorBrush(0xffffffff); - ContentPresenter contentPresenter = new ContentPresenter(); - contentPresenter.Bind( - ContentPresenter.ContentProperty, - this.GetObservable(Window.ContentProperty), - BindingPriority.Style); - border.Content = contentPresenter; - return border; - } - } -} \ No newline at end of file diff --git a/Gtk/Perspex.Gtk/WindowImpl.cs b/Gtk/Perspex.Gtk/WindowImpl.cs new file mode 100644 index 0000000000..f22b931b97 --- /dev/null +++ b/Gtk/Perspex.Gtk/WindowImpl.cs @@ -0,0 +1,73 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Gtk +{ + using System; + using Perspex.Controls; + using Perspex.Input.Raw; + using Perspex.Platform; + using Gtk = global::Gtk; + + public class WindowImpl : IWindowImpl + { + private Gtk.Window inner; + + private Window owner; + + public WindowImpl () + { + this.inner = new Gtk.Window(Gtk.WindowType.Toplevel); + + // TODO: Use ?. operator on these when it's available. + this.inner.FocusActivated += (s, a) => this.Activated.Invoke(this, EventArgs.Empty); + this.inner.Destroyed += (s, a) => this.Closed.Invoke(this, EventArgs.Empty); + this.inner.ConfigureEvent += (s, a) => this.Resized.Invoke(this, new RawSizeEventArgs(a.Event.Width, a.Event.Height)); + + this.Handle = new PlatformHandle(this.inner.Handle, "GtkWindow"); + } + + public Size ClientSize + { + get + { + int width; + int height; + this.inner.GetSize(out width, out height); + return new Size(width, height); + } + } + + public IPlatformHandle Handle + { + get; + private set; + } + + public event EventHandler Activated; + + public event EventHandler Closed; + + public event EventHandler Input; + + public event EventHandler Resized; + + public void SetOwner(Window window) + { + this.owner = window; + } + + public void SetTitle(string title) + { + this.inner.Title = title; + } + + public void Show() + { + this.inner.Show(); + } + } +} \ No newline at end of file diff --git a/Perspex.Base/Perspex.Base.csproj b/Perspex.Base/Perspex.Base.csproj index cbffed72d5..e560962bbd 100644 --- a/Perspex.Base/Perspex.Base.csproj +++ b/Perspex.Base/Perspex.Base.csproj @@ -47,6 +47,7 @@ + diff --git a/Perspex.Base/Platform/PlatformHandle.cs b/Perspex.Base/Platform/PlatformHandle.cs new file mode 100644 index 0000000000..b5d2c0daf6 --- /dev/null +++ b/Perspex.Base/Platform/PlatformHandle.cs @@ -0,0 +1,23 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Platform +{ + using System; + + public class PlatformHandle : IPlatformHandle + { + public PlatformHandle(IntPtr handle, string descriptor) + { + this.Handle = handle; + this.HandleDescriptor = descriptor; + } + + public IntPtr Handle { get; private set; } + + public string HandleDescriptor { get; private set; } + } +} diff --git a/Windows/Perspex.Win32/WindowImpl.cs b/Windows/Perspex.Win32/WindowImpl.cs index aae7099aa4..d257d69f55 100644 --- a/Windows/Perspex.Win32/WindowImpl.cs +++ b/Windows/Perspex.Win32/WindowImpl.cs @@ -124,7 +124,7 @@ namespace Perspex.Win32 throw new Win32Exception(); } - this.Handle = new PlatformHandle(this.hwnd); + this.Handle = new PlatformHandle(this.hwnd, "HWND"); } [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1305:FieldNamesMustNotUseHungarianNotation", Justification = "Using Win32 naming for consistency.")] @@ -198,17 +198,5 @@ namespace Perspex.Win32 return UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam); } - - private class PlatformHandle : IPlatformHandle - { - public PlatformHandle(IntPtr hwnd) - { - this.Handle = hwnd; - } - - public IntPtr Handle { get; private set; } - - public string HandleDescriptor { get { return "HWND"; } } - } } }