diff --git a/src/Android/Avalonia.Android/Platform/SkiaPlatform/PopupImpl.cs b/src/Android/Avalonia.Android/Platform/SkiaPlatform/PopupImpl.cs index 7cfe04e5d6..efbc71b808 100644 --- a/src/Android/Avalonia.Android/Platform/SkiaPlatform/PopupImpl.cs +++ b/src/Android/Avalonia.Android/Platform/SkiaPlatform/PopupImpl.cs @@ -10,6 +10,7 @@ using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; +using Avalonia.Controls; using Avalonia.Platform; namespace Avalonia.Android.Platform.SkiaPlatform @@ -19,6 +20,9 @@ namespace Avalonia.Android.Platform.SkiaPlatform private Point _position; private bool _isAdded; Action IWindowBaseImpl.Activated { get; set; } + public Action PositionChanged { get; set; } + public Action Deactivated { get; set; } + public PopupImpl() : base(ActivityTracker.Current, true) { } @@ -33,7 +37,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform UpdateParams(); } - public override Point Position + public Point Position { get { return _position; } set @@ -85,5 +89,22 @@ namespace Avalonia.Android.Platform.SkiaPlatform Hide(); base.Dispose(); } + + + public void Activate() + { + } + + public void BeginMoveDrag() + { + //Not supported + } + + public void BeginResizeDrag(WindowEdge edge) + { + //Not supported + } + + } } \ No newline at end of file diff --git a/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs b/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs index 124f22458e..75772be171 100644 --- a/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs +++ b/src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs @@ -67,8 +67,6 @@ namespace Avalonia.Android.Platform.SkiaPlatform public Action Closed { get; set; } - public Action Deactivated { get; set; } - public Action Input { get; set; } public Size MaxClientSize { get; protected set; } @@ -79,27 +77,17 @@ namespace Avalonia.Android.Platform.SkiaPlatform public Action ScalingChanged { get; set; } - public Action PositionChanged { get; set; } - public View View => _view; public IPlatformHandle Handle => _view; public IEnumerable Surfaces => new object[] {this}; - - public void Activate() - { - } - + public virtual void Hide() { _view.Visibility = ViewStates.Invisible; } - - public void SetSystemDecorations(bool enabled) - { - } - + public void Invalidate(Rect rect) { if (_view.Holder?.Surface?.IsValid == true) _view.Invalidate(); @@ -124,40 +112,19 @@ namespace Avalonia.Android.Platform.SkiaPlatform { InputRoot = inputRoot; } - - public void SetTitle(string title) - { - } - + public virtual void Show() { _view.Visibility = ViewStates.Visible; } - public void BeginMoveDrag() - { - //Not supported - } - - public void BeginResizeDrag(WindowEdge edge) - { - //Not supported - } - - public virtual Point Position { get; set; } - public double Scaling => 1; void Draw() { Paint?.Invoke(new Rect(new Point(0, 0), ClientSize)); } - - public void SetIcon(IWindowIconImpl icon) - { - // No window icons for mobile platforms - } - + public virtual void Dispose() { _view.Dispose(); diff --git a/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj b/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj index 07a9ab56ed..d7e4400a99 100644 --- a/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj +++ b/src/Gtk/Avalonia.Gtk/Avalonia.Gtk.csproj @@ -61,7 +61,7 @@ - + diff --git a/src/Gtk/Avalonia.Gtk/EmbeddableImpl.cs b/src/Gtk/Avalonia.Gtk/EmbeddableImpl.cs index 997a63246b..4e8085a057 100644 --- a/src/Gtk/Avalonia.Gtk/EmbeddableImpl.cs +++ b/src/Gtk/Avalonia.Gtk/EmbeddableImpl.cs @@ -12,7 +12,7 @@ using WindowEdge = Avalonia.Controls.WindowEdge; namespace Avalonia.Gtk { - class EmbeddableImpl : WindowImplBase, IEmbeddableWindowImpl + class EmbeddableImpl : TopLevelImpl, IEmbeddableWindowImpl { #pragma warning disable CS0067 // Method not used public event Action LostFocus; @@ -37,39 +37,6 @@ namespace Avalonia.Gtk { get { return new Size(Widget.Allocation.Width, Widget.Allocation.Height); } } - - //Stubs are needed for future GTK designer embedding support - public override void SetTitle(string title) - { - } - - public override void Resize(Size value) - { - - } - - public override IDisposable ShowDialog() => Disposable.Create(() => { }); - - public override void SetSystemDecorations(bool enabled) - { - } - - public override void SetIcon(IWindowIconImpl icon) - { - } - - public override void BeginMoveDrag() - { - } - - public override void BeginResizeDrag(WindowEdge edge) - { - } - - public override Point Position - { - get { return new Point(); } - set {} - } + } } diff --git a/src/Gtk/Avalonia.Gtk/FramebufferManager.cs b/src/Gtk/Avalonia.Gtk/FramebufferManager.cs index 00a4727769..0c9ed44274 100644 --- a/src/Gtk/Avalonia.Gtk/FramebufferManager.cs +++ b/src/Gtk/Avalonia.Gtk/FramebufferManager.cs @@ -5,10 +5,10 @@ namespace Avalonia.Gtk { class FramebufferManager : IFramebufferPlatformSurface, IDisposable { - private readonly WindowImplBase _window; + private readonly TopLevelImpl _window; private SurfaceFramebuffer _fb; - public FramebufferManager(WindowImplBase window) + public FramebufferManager(TopLevelImpl window) { _window = window; } diff --git a/src/Gtk/Avalonia.Gtk/SystemDialogImpl.cs b/src/Gtk/Avalonia.Gtk/SystemDialogImpl.cs index 962621856a..05dc1bf02d 100644 --- a/src/Gtk/Avalonia.Gtk/SystemDialogImpl.cs +++ b/src/Gtk/Avalonia.Gtk/SystemDialogImpl.cs @@ -15,7 +15,7 @@ namespace Avalonia.Gtk public Task ShowFileDialogAsync(FileDialog dialog, IWindowImpl parent) { var tcs = new TaskCompletionSource(); - var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImplBase)parent)?.Widget.Toplevel as Window, + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((TopLevelImpl)parent)?.Widget.Toplevel as Window, dialog is OpenFileDialog ? FileChooserAction.Open : FileChooserAction.Save, @@ -57,7 +57,7 @@ namespace Avalonia.Gtk public Task ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) { var tcs = new TaskCompletionSource(); - var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((WindowImplBase)parent)?.Widget.Toplevel as Window, + var dlg = new global::Gtk.FileChooserDialog(dialog.Title, ((TopLevelImpl)parent)?.Widget.Toplevel as Window, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Select Folder", ResponseType.Accept) diff --git a/src/Gtk/Avalonia.Gtk/WindowImplBase.cs b/src/Gtk/Avalonia.Gtk/TopLevelImpl.cs similarity index 79% rename from src/Gtk/Avalonia.Gtk/WindowImplBase.cs rename to src/Gtk/Avalonia.Gtk/TopLevelImpl.cs index 93e2652c6e..a1bb3f847e 100644 --- a/src/Gtk/Avalonia.Gtk/WindowImplBase.cs +++ b/src/Gtk/Avalonia.Gtk/TopLevelImpl.cs @@ -15,10 +15,10 @@ namespace Avalonia.Gtk { using Gtk = global::Gtk; - public abstract class WindowImplBase : IWindowImpl + public abstract class TopLevelImpl : ITopLevelImpl { private IInputRoot _inputRoot; - protected Gtk.Widget _window; + private Gtk.Widget _widget; private FramebufferManager _framebuffer; private Gtk.IMContext _imContext; @@ -27,44 +27,43 @@ namespace Avalonia.Gtk private static readonly Gdk.Cursor DefaultCursor = new Gdk.Cursor(CursorType.LeftPtr); - protected WindowImplBase(Gtk.Widget window) + protected TopLevelImpl(Gtk.Widget window) { - _window = window; + _widget = window; _framebuffer = new FramebufferManager(this); Init(); } void Init() { - Handle = _window as IPlatformHandle; - _window.Events = EventMask.AllEventsMask; + Handle = _widget as IPlatformHandle; + _widget.Events = EventMask.AllEventsMask; _imContext = new Gtk.IMMulticontext(); _imContext.Commit += ImContext_Commit; - _window.Realized += OnRealized; - _window.Realize(); - _window.ButtonPressEvent += OnButtonPressEvent; - _window.ButtonReleaseEvent += OnButtonReleaseEvent; - _window.ScrollEvent += OnScrollEvent; - _window.Destroyed += OnDestroyed; - _window.KeyPressEvent += OnKeyPressEvent; - _window.KeyReleaseEvent += OnKeyReleaseEvent; - _window.ExposeEvent += OnExposeEvent; - _window.MotionNotifyEvent += OnMotionNotifyEvent; + _widget.Realized += OnRealized; + _widget.Realize(); + _widget.ButtonPressEvent += OnButtonPressEvent; + _widget.ButtonReleaseEvent += OnButtonReleaseEvent; + _widget.ScrollEvent += OnScrollEvent; + _widget.Destroyed += OnDestroyed; + _widget.KeyPressEvent += OnKeyPressEvent; + _widget.KeyReleaseEvent += OnKeyReleaseEvent; + _widget.ExposeEvent += OnExposeEvent; + _widget.MotionNotifyEvent += OnMotionNotifyEvent; } public IPlatformHandle Handle { get; private set; } - public Gtk.Widget Widget => _window; + public Gtk.Widget Widget => _widget; public Gdk.Drawable CurrentDrawable { get; private set; } void OnRealized (object sender, EventArgs eventArgs) { - _imContext.ClientWindow = _window.GdkWindow; + _imContext.ClientWindow = _widget.GdkWindow; } public abstract Size ClientSize { get; } - public abstract void Resize(Size value); public Size MaxClientSize { @@ -72,7 +71,7 @@ namespace Avalonia.Gtk { // TODO: This should take into account things such as taskbar and window border // thickness etc. - return new Size(_window.Screen.Width, _window.Screen.Height); + return new Size(_widget.Screen.Width, _widget.Screen.Height); } } @@ -80,7 +79,7 @@ namespace Avalonia.Gtk { get { - switch (_window.GdkWindow.State) + switch (_widget.GdkWindow.State) { case Gdk.WindowState.Iconified: return Controls.WindowState.Minimized; @@ -96,14 +95,14 @@ namespace Avalonia.Gtk switch (value) { case Controls.WindowState.Minimized: - _window.GdkWindow.Iconify(); + _widget.GdkWindow.Iconify(); break; case Controls.WindowState.Maximized: - _window.GdkWindow.Maximize(); + _widget.GdkWindow.Maximize(); break; case Controls.WindowState.Normal: - _window.GdkWindow.Deiconify(); - _window.GdkWindow.Unmaximize(); + _widget.GdkWindow.Deiconify(); + _widget.GdkWindow.Unmaximize(); break; } } @@ -141,15 +140,15 @@ namespace Avalonia.Gtk public void Invalidate(Rect rect) { - if (_window?.GdkWindow != null) - _window.GdkWindow.InvalidateRect( + if (_widget?.GdkWindow != null) + _widget.GdkWindow.InvalidateRect( new Rectangle((int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height), true); } public Point PointToClient(Point point) { int x, y; - _window.GdkWindow.GetDeskrelativeOrigin(out x, out y); + _widget.GdkWindow.GetDeskrelativeOrigin(out x, out y); return new Point(point.X - x, point.Y - y); } @@ -157,7 +156,7 @@ namespace Avalonia.Gtk public Point PointToScreen(Point point) { int x, y; - _window.GdkWindow.GetDeskrelativeOrigin(out x, out y); + _widget.GdkWindow.GetDeskrelativeOrigin(out x, out y); return new Point(point.X + x, point.Y + y); } @@ -166,28 +165,15 @@ namespace Avalonia.Gtk _inputRoot = inputRoot; } - public abstract void SetTitle(string title); - public abstract IDisposable ShowDialog(); - public abstract void SetSystemDecorations(bool enabled); - public abstract void SetIcon(IWindowIconImpl icon); - public void SetCursor(IPlatformHandle cursor) { - _window.GdkWindow.Cursor = cursor != null ? new Gdk.Cursor(cursor.Handle) : DefaultCursor; + _widget.GdkWindow.Cursor = cursor != null ? new Gdk.Cursor(cursor.Handle) : DefaultCursor; } - public void Show() => _window.Show(); - - public void Hide() => _window.Hide(); - public abstract void BeginMoveDrag(); - public abstract void BeginResizeDrag(WindowEdge edge); - public abstract Point Position { get; set; } + public void Show() => _widget.Show(); - void IWindowBaseImpl.Activate() - { - _window.Activate(); - } + public void Hide() => _widget.Hide(); private static InputModifiers GetModifierKeys(ModifierType state) { @@ -317,9 +303,9 @@ namespace Avalonia.Gtk public void Dispose() { _framebuffer.Dispose(); - _window.Hide(); - _window.Dispose(); - _window = null; + _widget.Hide(); + _widget.Dispose(); + _widget = null; } } } diff --git a/src/Gtk/Avalonia.Gtk/WindowImpl.cs b/src/Gtk/Avalonia.Gtk/WindowImpl.cs index d0c1715ee2..d8555b4e05 100644 --- a/src/Gtk/Avalonia.Gtk/WindowImpl.cs +++ b/src/Gtk/Avalonia.Gtk/WindowImpl.cs @@ -6,7 +6,7 @@ using Gdk; namespace Avalonia.Gtk { using Gtk = global::Gtk; - public class WindowImpl : WindowImplBase + public class WindowImpl : TopLevelImpl, IWindowImpl { private Gtk.Window _window; private Gtk.Window Window => _window ?? (_window = (Gtk.Window) Widget); @@ -63,22 +63,27 @@ namespace Avalonia.Gtk } } - public override void Resize(Size value) + public void Resize(Size value) { Window.Resize((int)value.Width, (int)value.Height); } - public override void SetTitle(string title) + public void SetTitle(string title) { Window.Title = title; } + void IWindowBaseImpl.Activate() + { + _window.Activate(); + } + void OnFocusActivated(object sender, EventArgs eventArgs) { Activated(); } - public override void BeginMoveDrag() + public void BeginMoveDrag() { int x, y; ModifierType mod; @@ -86,7 +91,7 @@ namespace Avalonia.Gtk Window.BeginMoveDrag(1, x, y, 0); } - public override void BeginResizeDrag(Controls.WindowEdge edge) + public void BeginResizeDrag(Controls.WindowEdge edge) { int x, y; ModifierType mod; @@ -94,7 +99,7 @@ namespace Avalonia.Gtk Window.BeginResizeDrag((Gdk.WindowEdge)(int)edge, 1, x, y, 0); } - public override Point Position + public Point Position { get { @@ -108,7 +113,7 @@ namespace Avalonia.Gtk } } - public override IDisposable ShowDialog() + public IDisposable ShowDialog() { Window.Modal = true; Window.Show(); @@ -116,9 +121,9 @@ namespace Avalonia.Gtk return Disposable.Empty; } - public override void SetSystemDecorations(bool enabled) => Window.Decorated = enabled; + public void SetSystemDecorations(bool enabled) => Window.Decorated = enabled; - public override void SetIcon(IWindowIconImpl icon) + public void SetIcon(IWindowIconImpl icon) { Window.Icon = ((IconImpl)icon).Pixbuf; } diff --git a/src/iOS/Avalonia.iOS/TopLevelImpl.cs b/src/iOS/Avalonia.iOS/TopLevelImpl.cs index 96ab2786f7..7949e331fe 100644 --- a/src/iOS/Avalonia.iOS/TopLevelImpl.cs +++ b/src/iOS/Avalonia.iOS/TopLevelImpl.cs @@ -32,6 +32,7 @@ namespace Avalonia.iOS { _keyboardHelper = new KeyboardEventsHelper(this); AutoresizingMask = UIViewAutoresizing.All; + _keyboardHelper.ActivateAutoShowKeybord(); } [Export("hasText")] @@ -44,37 +45,21 @@ namespace Avalonia.iOS public void DeleteBackward() => _keyboardHelper.DeleteBackward(); public override bool CanBecomeFirstResponder => _keyboardHelper.CanBecomeFirstResponder(); - - public Action Activated { get; set; } + public Action Closed { get; set; } - public Action Deactivated { get; set; } public Action Input { get; set; } public Action Paint { get; set; } public Action Resized { get; set; } public Action ScalingChanged { get; set; } - public Action PositionChanged { get; set; } public IPlatformHandle Handle => null; public double Scaling => UIScreen.MainScreen.Scale; - public WindowState WindowState - { - get { return WindowState.Normal; } - set { } - } - + public override void LayoutSubviews() => Resized?.Invoke(ClientSize); - public Size ClientSize - { - get { return Bounds.Size.ToAvalonia(); } - set { InvokeOnMainThread(() => Resized?.Invoke(ClientSize)); } - } - - public void Activate() - { - } + public Size ClientSize => Bounds.Size.ToAvalonia(); public override void Draw(CGRect rect) { @@ -93,42 +78,9 @@ namespace Avalonia.iOS { //Not supported } - - public void Show() - { - _keyboardHelper.ActivateAutoShowKeybord(); - } - - public void BeginMoveDrag() - { - //Not supported - } - - public void BeginResizeDrag(WindowEdge edge) - { - //Not supported - } - - public Point Position - { - get { return _position; } - set - { - _position = value; - PositionChanged?.Invoke(_position); - } - } - - public Size MaxClientSize => Bounds.Size.ToAvalonia(); - + public IEnumerable Surfaces => new object[] { this }; - - - public void Hide() - { - //Not supported - } - + public override void TouchesEnded(NSSet touches, UIEvent evt) { var touch = touches.AnyObject as UITouch; @@ -182,11 +134,7 @@ namespace Avalonia.iOS _touchLastPoint = location; } } - - public void SetIcon(IWindowIconImpl icon) - { - } - + public ILockedFramebuffer Lock() => new EmulatedFramebuffer(this); } }