Пример #1
0
 public WindowBase(IWindowBaseImpl impl, IAvaloniaDependencyResolver dependencyResolver) : base(impl, dependencyResolver)
 {
     impl.Activated       = HandleActivated;
     impl.Deactivated     = HandleDeactivated;
     impl.PositionChanged = HandlePositionChanged;
     this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl?.Resize(x));
 }
        public static Mock <IPopupImpl> CreatePopupMock(IWindowBaseImpl parent)
        {
            var popupImpl  = new Mock <IPopupImpl>();
            var clientSize = new Size();

            var positionerHelper = new ManagedPopupPositionerPopupImplHelper(parent, (pos, size, scale) =>
            {
                clientSize = size.Constrain(s_screenSize);
                popupImpl.Object.PositionChanged?.Invoke(pos);
                popupImpl.Object.Resized?.Invoke(clientSize, PlatformResizeReason.Unspecified);
            });

            var positioner = new ManagedPopupPositioner(positionerHelper);

            popupImpl.SetupAllProperties();
            popupImpl.Setup(x => x.ClientSize).Returns(() => clientSize);
            popupImpl.Setup(x => x.MaxAutoSizeHint).Returns(s_screenSize);
            popupImpl.Setup(x => x.RenderScaling).Returns(1);
            popupImpl.Setup(x => x.PopupPositioner).Returns(positioner);

            popupImpl.Setup(x => x.Dispose()).Callback(() =>
            {
                popupImpl.Object.Closed?.Invoke();
            });

            return(popupImpl);
        }
Пример #3
0
        public Task <string[]> ShowFileDialogAsync(FileDialog dialog, IWindowBaseImpl parent)
        {
            var events = new SystemDialogEvents();

            if (dialog is OpenFileDialog ofd)
            {
                _native.OpenFileDialog((parent as WindowImpl)?.Native,
                                       events, ofd.AllowMultiple,
                                       ofd.Title ?? "",
                                       ofd.InitialDirectory ?? "",
                                       ofd.InitialFileName ?? "",
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }
            else
            {
                _native.SaveFileDialog((parent as WindowImpl)?.Native,
                                       events,
                                       dialog.Title ?? "",
                                       dialog.InitialDirectory ?? "",
                                       dialog.InitialFileName ?? "",
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }

            return(events.Task.ContinueWith(t => { events.Dispose(); return t.Result; }));
        }
Пример #4
0
        private void SetWindowStartupLocation(IWindowBaseImpl owner = null)
        {
            var scaling = owner?.Scaling ?? PlatformImpl?.Scaling ?? 1;

            // TODO: We really need non-client size here.
            var rect = new PixelRect(
                PixelPoint.Origin,
                PixelSize.FromSize(ClientSize, scaling));

            if (WindowStartupLocation == WindowStartupLocation.CenterScreen)
            {
                var screen = Screens.ScreenFromPoint(owner?.Position ?? Position);

                if (screen != null)
                {
                    Position = screen.WorkingArea.CenterRect(rect).Position;
                }
            }
            else if (WindowStartupLocation == WindowStartupLocation.CenterOwner)
            {
                if (owner != null)
                {
                    // TODO: We really need non-client size here.
                    var ownerRect = new PixelRect(
                        owner.Position,
                        PixelSize.FromSize(owner.ClientSize, scaling));
                    Position = ownerRect.CenterRect(rect).Position;
                }
            }
        }
Пример #5
0
 public WindowBase(IWindowBaseImpl impl, IAvaloniaDependencyResolver?dependencyResolver) : base(impl, dependencyResolver)
 {
     Screens              = new Screens(PlatformImpl?.Screen);
     impl.Activated       = HandleActivated;
     impl.Deactivated     = HandleDeactivated;
     impl.PositionChanged = HandlePositionChanged;
 }
Пример #6
0
 public Task <string> ShowAsync(IWindowBaseImpl parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException(nameof(parent));
     }
     return(AvaloniaGlobals.SystemDialogImplementation.ShowFolderDialogAsync(this, parent));
 }
Пример #7
0
        public static Screen?ScreenFromWindow(IWindowBaseImpl window, IReadOnlyList <Screen> screens)
        {
            var rect = new PixelRect(
                window.Position,
                PixelSize.FromSize(window.FrameSize ?? window.ClientSize, window.DesktopScaling));

            return(ScreenFromRect(rect, screens));
        }
Пример #8
0
        public Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowBaseImpl parent)
        {
            var events = new SystemDialogEvents();

            _native.SelectFolderDialog((parent as WindowImpl)?.Native, events, dialog.Title ?? "", dialog.InitialDirectory ?? "");

            return(events.Task.ContinueWith(t => { events.Dispose(); return t.Result.FirstOrDefault(); }));
        }
Пример #9
0
        public WindowBase(IWindowBaseImpl impl, IAvaloniaDependencyResolver dependencyResolver) : base(ValidatingWindowBaseImpl.Wrap(impl), dependencyResolver)
        {
            Screens = new Screens(PlatformImpl?.Screen);
            var wrapped = PlatformImpl !;

            wrapped.Activated       = HandleActivated;
            wrapped.Deactivated     = HandleDeactivated;
            wrapped.PositionChanged = HandlePositionChanged;
        }
Пример #10
0
 public async Task <string> ShowAsync(IWindowBaseImpl parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException(nameof(parent));
     }
     return(((await AvaloniaGlobals.SystemDialogImplementation
              .ShowFileDialogAsync(this, parent)) ??
             Array.Empty <string>()).FirstOrDefault());
 }
        public async Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowBaseImpl parent)
        {
            await EnsureInitialized();

            return(await await RunOnGlibThread(async() =>
            {
                var res = await ShowDialog(dialog.Title, parent,
                                           GtkFileChooserAction.SelectFolder, false, dialog.InitialDirectory, null);
                return res?.FirstOrDefault();
            }));
        }
        public async Task <string[]> ShowFileDialogAsync(FileDialog dialog, IWindowBaseImpl parent)
        {
            await EnsureInitialized();

            return(await await RunOnGlibThread(
                       () => ShowDialog(dialog.Title, parent,
                                        dialog is OpenFileDialog ? GtkFileChooserAction.Open : GtkFileChooserAction.Save,
                                        (dialog as OpenFileDialog)?.AllowMultiple ?? false,
                                        Path.Combine(string.IsNullOrEmpty(dialog.InitialDirectory) ? "" : dialog.InitialDirectory,
                                                     string.IsNullOrEmpty(dialog.InitialFileName) ? "" : dialog.InitialFileName), dialog.Filters)));
        }
Пример #13
0
 public PopupImpl(IAvaloniaNativeFactory factory,
                  AvaloniaNativePlatformOptions opts,
                  IWindowBaseImpl parent) : base(opts)
 {
     _factory = factory;
     _opts    = opts;
     using (var e = new PopupEvents(this))
     {
         Init(factory.CreatePopup(e), factory.CreateScreens());
     }
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
Пример #14
0
        protected Window(IWindowBaseImpl window)
        {
            this.window = window;
            adapter     = new ControlAdapter(this);

            window.Input       = OnInput;
            window.Paint       = OnPaint;
            window.Resized     = OnResize;
            window.Closed      = () => Closed?.Invoke(this, EventArgs.Empty);
            window.Deactivated = () => Deactivated?.Invoke(this, EventArgs.Empty);
            window.Resize(new Size(DefaultSize.Width, DefaultSize.Height));
        }
Пример #15
0
    public static IWindowBaseImpl Wrap(IWindowBaseImpl impl)
    {
#if DEBUG
        if (impl is ValidatingToplevelImpl)
        {
            return(impl);
        }
        return(new ValidatingWindowBaseImpl(impl));
#else
        return(impl);
#endif
    }
        void UpdateParent(IntPtr chooser, IWindowBaseImpl parentWindow)
        {
            var xid = parentWindow.Handle.Handle;

            gtk_widget_realize(chooser);
            var window = gtk_widget_get_window(chooser);
            var parent = GetForeignWindow(xid);

            if (window != IntPtr.Zero && parent != IntPtr.Zero)
            {
                gdk_window_set_transient_for(window, parent);
            }
        }
Пример #17
0
 public PopupImpl(IAvaloniaNativeFactory factory,
                  AvaloniaNativePlatformOptions opts,
                  GlPlatformFeature glFeature,
                  IWindowBaseImpl parent) : base(opts, glFeature)
 {
     _factory   = factory;
     _opts      = opts;
     _glFeature = glFeature;
     using (var e = new PopupEvents(this))
     {
         Init(factory.CreatePopup(e, _opts.UseGpu ? glFeature?.DeferredContext.Context : null), factory.CreateScreens());
     }
     PopupPositioner = new ManagedPopupPositioner(new OsxManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
Пример #18
0
        public Task <string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowBaseImpl parent)
        {
            return(Task.Factory.StartNew(() =>
            {
                string result = string.Empty;

                var hWnd = parent?.Handle?.Handle ?? IntPtr.Zero;
                Guid clsid = UnmanagedMethods.ShellIds.OpenFileDialog;
                Guid iid = UnmanagedMethods.ShellIds.IFileDialog;

                UnmanagedMethods.CoCreateInstance(ref clsid, IntPtr.Zero, 1, ref iid, out var unk);
                var frm = (UnmanagedMethods.IFileDialog)unk;
                uint options;
                frm.GetOptions(out options);
                options |= (uint)(UnmanagedMethods.FOS.FOS_PICKFOLDERS | DefaultDialogOptions);
                frm.SetOptions(options);

                if (dialog.InitialDirectory != null)
                {
                    UnmanagedMethods.IShellItem directoryShellItem;
                    Guid riid = UnmanagedMethods.ShellIds.IShellItem;
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.InitialDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetFolder(directoryShellItem);
                    }
                }

                if (dialog.DefaultDirectory != null)
                {
                    UnmanagedMethods.IShellItem directoryShellItem;
                    Guid riid = UnmanagedMethods.ShellIds.IShellItem;
                    if (UnmanagedMethods.SHCreateItemFromParsingName(dialog.DefaultDirectory, IntPtr.Zero, ref riid, out directoryShellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        frm.SetDefaultFolder(directoryShellItem);
                    }
                }

                if (frm.Show(hWnd) == (uint)UnmanagedMethods.HRESULT.S_OK)
                {
                    UnmanagedMethods.IShellItem shellItem;
                    if (frm.GetResult(out shellItem) == (uint)UnmanagedMethods.HRESULT.S_OK)
                    {
                        result = GetAbsoluteFilePath(shellItem);
                    }
                }

                return result;
            }));
        }
Пример #19
0
        /// <summary>
        /// Initializes a new instance of the Window class.
        /// </summary>
        internal WindowBase(IWindowBaseImpl window)
        {
            this.window = window;
            adapter     = new ControlAdapter(this);

            window.Input       = OnInput;
            window.Paint       = DoPaint;
            window.Resized     = OnResize;
            window.Closed      = () => Closed?.Invoke(this, EventArgs.Empty);
            window.Deactivated = () => {
                // If we're clicking off the form, deactivate any active menus
                Application.ActiveMenu?.Deactivate();
                Deactivated?.Invoke(this, EventArgs.Empty);
            };
        }
Пример #20
0
 public PopupImpl(IAvaloniaNativeFactory factory,
                  AvaloniaNativePlatformOptions opts,
                  AvaloniaNativePlatformOpenGlInterface glFeature,
                  IWindowBaseImpl parent) : base(factory, opts, glFeature)
 {
     _opts      = opts;
     _glFeature = glFeature;
     _parent    = parent;
     using (var e = new PopupEvents(this))
     {
         var context = _opts.UseGpu ? glFeature?.MainContext : null;
         Init(factory.CreatePopup(e, context?.Context), factory.CreateScreens(), context);
     }
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
Пример #21
0
        public static Mock <IPopupImpl> CreatePopupMock(IWindowBaseImpl parent)
        {
            var popupImpl = new Mock <IPopupImpl>();

            var positionerHelper = new ManagedPopupPositionerPopupImplHelper(parent, (pos, size, scale) =>
            {
                popupImpl.Object.PositionChanged?.Invoke(pos);
                popupImpl.Object.Resized?.Invoke(size);
            });

            var positioner = new ManagedPopupPositioner(positionerHelper);

            popupImpl.Setup(x => x.Scaling).Returns(1);
            popupImpl.Setup(x => x.PopupPositioner).Returns(positioner);

            SetupToplevel(popupImpl);

            return(popupImpl);
        }
Пример #22
0
        public static Mock <IPopupImpl> CreatePopupMock(IWindowBaseImpl parent)
        {
            var popupImpl  = new Mock <IPopupImpl>();
            var clientSize = new Size();

            var positionerHelper = new ManagedPopupPositionerPopupImplHelper(parent, (pos, size, scale) =>
            {
                clientSize = size.Constrain(s_screenSize);
                popupImpl.Object.PositionChanged?.Invoke(pos);
                popupImpl.Object.Resized?.Invoke(clientSize);
            });

            var positioner = new ManagedPopupPositioner(positionerHelper);

            popupImpl.SetupAllProperties();
            popupImpl.Setup(x => x.ClientSize).Returns(() => clientSize);
            popupImpl.Setup(x => x.Scaling).Returns(1);
            popupImpl.Setup(x => x.PopupPositioner).Returns(positioner);

            SetupToplevel(popupImpl);

            return(popupImpl);
        }
Пример #23
0
 public PopupImpl(IWindowBaseImpl parent)
 {
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
Пример #24
0
 public WindowBase(IWindowBaseImpl impl) : this(impl, AvaloniaLocator.Current)
 {
 }
Пример #25
0
 public TestWindowBase(IWindowBaseImpl impl)
     : base(impl)
 {
 }
Пример #26
0
 private PopupImpl(IWindowBaseImpl parent, bool dummy) : base()
 {
     _parent         = parent;
     PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
 }
Пример #27
0
 // This is needed because we are calling virtual methods from constructors
 // One fabulous design decision leads to another, I guess
 public PopupImpl(IWindowBaseImpl parent) : this(SaveParentHandle(parent), false)
 {
 }
Пример #28
0
 // This is needed because we are calling virtual methods from constructors
 // One fabulous design decision leads to another, I guess
 static IWindowBaseImpl SaveParentHandle(IWindowBaseImpl parent)
 {
     s_parentHandle = parent.Handle.Handle;
     return(parent);
 }
Пример #29
0
 public Screen?ScreenFromWindow(IWindowBaseImpl window)
 {
     return(ScreenHelper.ScreenFromWindow(window, AllScreens));
 }
Пример #30
0
 public OsxManagedPopupPositionerPopupImplHelper(IWindowBaseImpl parent, MoveResizeDelegate moveResize) : base(parent, moveResize)
 {
 }