From daf771ba2c89e98a46f4a94ae8f92dd05f21ee05 Mon Sep 17 00:00:00 2001 From: Nelson Carrillo Date: Sun, 19 Jul 2015 15:15:46 -0400 Subject: [PATCH] Fixes/cleanups to the Gtk/Cairo platforms - Added PopupImpl support in Perspex.Gtk - Added ShowDialog support to WindowImpl in Perspex.Gtk - Fixed resize issues in Perspex.Gtk - Renamed Centered to Center to match WPF in Cairo - Removed old Serilog references breaking compile --- Cairo/Perspex.Cairo/CairoExtensions.cs | 2 +- Gtk/Perspex.Gtk/GtkPlatform.cs | 1 + Gtk/Perspex.Gtk/Perspex.Gtk.csproj | 1 + Gtk/Perspex.Gtk/PopupImpl.cs | 29 ++++++++++++++++++++++++++ Gtk/Perspex.Gtk/WindowImpl.cs | 29 +++++++++++++++++++------- TestApplication/Program.cs | 3 --- 6 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 Gtk/Perspex.Gtk/PopupImpl.cs diff --git a/Cairo/Perspex.Cairo/CairoExtensions.cs b/Cairo/Perspex.Cairo/CairoExtensions.cs index e9969ee90e..364e330c09 100644 --- a/Cairo/Perspex.Cairo/CairoExtensions.cs +++ b/Cairo/Perspex.Cairo/CairoExtensions.cs @@ -76,7 +76,7 @@ namespace Perspex.Cairo return Pango.Alignment.Left; } - if (alignment == Perspex.Media.TextAlignment.Centered) + if (alignment == Perspex.Media.TextAlignment.Center) { return Pango.Alignment.Center; } diff --git a/Gtk/Perspex.Gtk/GtkPlatform.cs b/Gtk/Perspex.Gtk/GtkPlatform.cs index c494e37a6a..7618fb8f3c 100644 --- a/Gtk/Perspex.Gtk/GtkPlatform.cs +++ b/Gtk/Perspex.Gtk/GtkPlatform.cs @@ -40,6 +40,7 @@ namespace Perspex.Gtk { var locator = Locator.CurrentMutable; locator.Register(() => new WindowImpl(), typeof(IWindowImpl)); + locator.Register(() => new PopupImpl(), typeof(IPopupImpl)); locator.Register(() => GtkKeyboardDevice.Instance, typeof(IKeyboardDevice)); locator.Register(() => instance, typeof(IPlatformSettings)); locator.Register(() => instance, typeof(IPlatformThreadingInterface)); diff --git a/Gtk/Perspex.Gtk/Perspex.Gtk.csproj b/Gtk/Perspex.Gtk/Perspex.Gtk.csproj index 6362042d06..d520b199fb 100644 --- a/Gtk/Perspex.Gtk/Perspex.Gtk.csproj +++ b/Gtk/Perspex.Gtk/Perspex.Gtk.csproj @@ -59,6 +59,7 @@ + diff --git a/Gtk/Perspex.Gtk/PopupImpl.cs b/Gtk/Perspex.Gtk/PopupImpl.cs new file mode 100644 index 0000000000..a582458c87 --- /dev/null +++ b/Gtk/Perspex.Gtk/PopupImpl.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Perspex.Gtk +{ + using System; + using Perspex.Platform; + using global::Gtk; + + public class PopupImpl : WindowImpl, IPopupImpl + { + public PopupImpl() + : base(WindowType.Popup) + { + this.DefaultSize = new Gdk.Size(640, 480); + this.Events = Gdk.EventMask.PointerMotionMask | + Gdk.EventMask.ButtonPressMask | + Gdk.EventMask.ButtonReleaseMask; + } + + public void SetPosition(Point p) + { + this.Move((int)p.X, (int)p.Y); + } + } +} diff --git a/Gtk/Perspex.Gtk/WindowImpl.cs b/Gtk/Perspex.Gtk/WindowImpl.cs index c736b9d946..ed70b6168e 100644 --- a/Gtk/Perspex.Gtk/WindowImpl.cs +++ b/Gtk/Perspex.Gtk/WindowImpl.cs @@ -12,6 +12,7 @@ namespace Perspex.Gtk using Perspex.Input.Raw; using Perspex.Platform; using Gtk = global::Gtk; + using System.Reactive.Disposables; public class WindowImpl : Gtk.Window, IWindowImpl { @@ -31,10 +32,20 @@ namespace Perspex.Gtk this.windowHandle = new PlatformHandle(this.Handle, "GtkWindow"); } + public WindowImpl(Gtk.WindowType type) + : base(type) + { + this.DefaultSize = new Gdk.Size(640, 480); + this.Events = Gdk.EventMask.PointerMotionMask | + Gdk.EventMask.ButtonPressMask | + Gdk.EventMask.ButtonReleaseMask; + this.windowHandle = new PlatformHandle(this.Handle, "GtkWindow"); + } + public Size ClientSize { - get { return this.clientSize; } - set { this.Resize((int)value.Width, (int)value.Height); } + get; + set; } IPlatformHandle ITopLevelImpl.Handle @@ -56,12 +67,14 @@ namespace Perspex.Gtk public IPopupImpl CreatePopup() { - throw new NotImplementedException(); + return new PopupImpl(); } public void Invalidate(Rect rect) { - this.QueueDraw(); +#pragma warning disable CS0612 // Type or member is obsolete + this.Draw(new Gdk.Rectangle { X = (int)rect.X, Y = (int)rect.Y, Width = (int)rect.Width, Height = (int)rect.Height }); +#pragma warning restore CS0612 // Type or member is obsolete } public Point PointToScreen(Point point) @@ -82,7 +95,10 @@ namespace Perspex.Gtk public IDisposable ShowDialog() { - throw new NotImplementedException(); + this.Modal = true; + this.Show(); + + return Disposable.Empty; } void ITopLevelImpl.Activate() @@ -120,8 +136,7 @@ namespace Perspex.Gtk if (newSize != this.clientSize) { - this.clientSize = newSize; - this.Resized(this.clientSize); + this.Resized(newSize); } return true; diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 9071f51fbc..ed297345b0 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -17,9 +17,6 @@ using Perspex.Gtk; #endif using ReactiveUI; using Splat; -using Serilog; -using Serilog.Filters; -using Serilog.Events; namespace TestApplication {