| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using System;
- using System.Reactive.Disposables;
- using Avalonia.Controls;
- using Avalonia.Platform;
- using Gdk;
- namespace Avalonia.Gtk
- {
- using Gtk = global::Gtk;
- public class WindowImpl : TopLevelImpl, IWindowImpl
- {
- private Gtk.Window _window;
- private Gtk.Window Window => _window ?? (_window = (Gtk.Window)Widget);
- public WindowImpl(Gtk.WindowType type) : base(new PlatformHandleAwareWindow(type))
- {
- Init();
- }
- public WindowImpl()
- : base(new PlatformHandleAwareWindow(Gtk.WindowType.Toplevel) {DefaultSize = new Gdk.Size(900, 480)})
- {
- Init();
- }
- void Init()
- {
- Window.FocusActivated += OnFocusActivated;
- Window.ConfigureEvent += OnConfigureEvent;
- _lastClientSize = ClientSize;
- _lastPosition = Position;
- }
- private Size _lastClientSize;
- private Point _lastPosition;
- void OnConfigureEvent(object o, Gtk.ConfigureEventArgs args)
- {
- var evnt = args.Event;
- args.RetVal = true;
- var newSize = new Size(evnt.Width, evnt.Height);
- if (newSize != _lastClientSize)
- {
- Resized(newSize);
- _lastClientSize = newSize;
- }
- var newPosition = new Point(evnt.X, evnt.Y);
- if (newPosition != _lastPosition)
- {
- PositionChanged(newPosition);
- _lastPosition = newPosition;
- }
- }
- public override Size ClientSize
- {
- get
- {
- int width;
- int height;
- Window.GetSize(out width, out height);
- return new Size(width, height);
- }
- }
- public IScreenImpl Screen => new ScreenImpl(Window);
- public void Resize(Size value)
- {
- Window.Resize((int)value.Width, (int)value.Height);
- }
- public void SetTitle(string title)
- {
- Window.Title = title;
- }
- void IWindowBaseImpl.Activate()
- {
- _window.Activate();
- }
- void OnFocusActivated(object sender, EventArgs eventArgs)
- {
- Activated();
- }
- public void BeginMoveDrag()
- {
- int x, y;
- ModifierType mod;
- Window.Screen.RootWindow.GetPointer(out x, out y, out mod);
- Window.BeginMoveDrag(1, x, y, 0);
- }
- public void BeginResizeDrag(Controls.WindowEdge edge)
- {
- int x, y;
- ModifierType mod;
- Window.Screen.RootWindow.GetPointer(out x, out y, out mod);
- Window.BeginResizeDrag((Gdk.WindowEdge)(int)edge, 1, x, y, 0);
- }
- public Point Position
- {
- get
- {
- int x, y;
- Window.GetPosition(out x, out y);
- return new Point(x, y);
- }
- set { Window.Move((int)value.X, (int)value.Y); }
- }
- public IDisposable ShowDialog()
- {
- Window.Modal = true;
- Window.Show();
- return Disposable.Empty;
- }
- public void SetSystemDecorations(bool enabled) => Window.Decorated = enabled;
- public void SetIcon(IWindowIconImpl icon)
- {
- Window.Icon = ((IconImpl)icon).Pixbuf;
- }
- public void ShowTaskbarIcon(bool value) => Window.SkipTaskbarHint = !value;
- }
- }
|