Example #1
0
        public DialogResult Show(IWindow?parent)
        {
            var    window = NativeCast.To <GtkWindow>(parent);
            IntPtr dialog = IntPtr.Zero;

            try
            {
                using GLibString title   = Title;
                using GLibString message = Message;
                dialog = Gtk.Dialog.CreateMessageDialog(
                    window?.Handle ?? IntPtr.Zero,
                    GtkDialogFlags.Modal | GtkDialogFlags.DestroyWithParent,
                    GtkMessageType.Other,
                    MapButtons(Buttons),
                    IntPtr.Zero);

                GLib.SetProperty(dialog, "title", title);
                GLib.SetProperty(dialog, "text", message);

                var result = Gtk.Dialog.Run(dialog);
                return(MapResult(result));
            }
            finally { if (dialog != IntPtr.Zero)
                      {
                          Gtk.Widget.Destroy(dialog);
                      }
            }
        }
Example #2
0
        public async Task OnStartRemote_LaunchesRemoteApp()
        {
            await using var app = App.StartRemote <XAMLTest.TestApp.App>();
            IWindow?window = await app.GetMainWindow();

            Assert.AreEqual("Test App Window", await window !.GetTitle());
        }
Example #3
0
        internal static DisplayOrientation GetOrientation(this IWindow?window)
        {
            if (window == null)
            {
                return(DeviceDisplay.Current.MainDisplayInfo.Orientation);
            }

            var appWindow = window.Handler?.MauiContext?.GetPlatformWindow()?.GetAppWindow();

            if (appWindow == null)
            {
                return(DisplayOrientation.Unknown);
            }

            DisplayOrientations orientationEnum;
            int theScreenWidth  = appWindow.Size.Width;
            int theScreenHeight = appWindow.Size.Height;

            if (theScreenWidth > theScreenHeight)
            {
                orientationEnum = DisplayOrientations.Landscape;
            }
            else
            {
                orientationEnum = DisplayOrientations.Portrait;
            }

            return(orientationEnum == DisplayOrientations.Landscape
                                ? DisplayOrientation.Landscape
                                : DisplayOrientation.Portrait);
        }
Example #4
0
        public static async Task ClassInitialize(TestContext context)
        {
            App = XamlTest.App.StartRemote(logMessage: msg => context.WriteLine(msg));

            await App.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location);

            Window = await App.CreateWindowWithContent(@"");
        }
Example #5
0
 public void Init(String type, Boolean bubbles, Boolean cancelable, IWindow?view, Int32 detail, Int32 screenX, Int32 screenY, Int32 clientX, Int32 clientY, MouseButton button, IEventTarget?target, String modifiersList, Double deltaX, Double deltaY, Double deltaZ, WheelMode deltaMode)
 {
     Init(type, bubbles, cancelable, view, detail, screenX, screenY, clientX, clientY,
          modifiersList.IsCtrlPressed(), modifiersList.IsAltPressed(), modifiersList.IsShiftPressed(), modifiersList.IsMetaPressed(), button, target);
     DeltaX    = deltaX;
     DeltaY    = deltaY;
     DeltaZ    = deltaZ;
     DeltaMode = deltaMode;
 }
Example #6
0
        /// <inheritdoc />
        public IWindow CreateWindow(WindowOptions options)
        {
            if (!IsApplicable)
            {
                ThrowUnsupported();
                return(null !);
            }

            return(_lastCreatedWindow = new GlfwWindow(options, null, null));
        }
Example #7
0
        public async Task CanGenerateTypedElement_ForCustomControlInRemoteApp()
        {
            await using var app = App.StartRemote <XAMLTest.TestApp.App>();
            IWindow?window = await app.GetMainWindow();

            Assert.IsNotNull(window);

            IVisualElement <ColorZone> colorZone = await window.GetElement <ColorZone>("/ColorZone");

            Assert.AreEqual(ColorZoneMode.PrimaryMid, await colorZone.GetMode());
        }
Example #8
0
 /// <inheritdoc />
 public IView GetView(ViewOptions?opts = null)
 {
     return(opts switch
     {
         null when _lastCreatedWindow is null => throw new InvalidOperationException
         (
             "No view has been created prior to this call, and couldn't " +
             "create one due to no view options being provided."
         ),
         null => _lastCreatedWindow !,
         _ => _lastCreatedWindow = CreateWindow(new WindowOptions(opts.Value))
     });
        public DialogResult Show(IWindow?parent)
        {
            var window = NativeCast.To <CocoaWindow>(parent);

            using var alert = NSDialog.CreateAlert();
            ObjC.Call(alert.Handle, "setShowsHelp:", IntPtr.Zero);
            ObjC.Call(alert.Handle, "setAlertStyle:", new UIntPtr((uint)NSAlertStyle.Informational));
            ObjC.Call(alert.Handle, "setMessageText:", NSString.Create(Title ?? string.Empty));
            ObjC.Call(alert.Handle, "setInformativeText:", NSString.Create(Message ?? string.Empty));
            AddButtons(alert.Handle, Buttons);

            return((DialogResult)alert.Run(window));
        }
Example #10
0
        public DialogResult Show(IWindow?parent)
        {
            var dialog = GetDialog();

            BeforeShow(dialog);

            var window = NativeCast.To <WinFormsWindow>(parent);
            var result = dialog.ShowDialog(window);

            BeforeReturn(dialog);

            return(WinFormsMapper.MapResult(result));
        }
Example #11
0
        public async Task OnGetMainWindow_ReturnsNullBeforeWindowCreated()
        {
            await using var app      = App.StartRemote();
            await using var recorder = new TestRecorder(app);

            await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location);

            IWindow?mainWindow = await app.GetMainWindow();

            Assert.IsNull(mainWindow);

            recorder.Success();
        }
Example #12
0
 public void Init(String type, Boolean bubbles, Boolean cancelable, IWindow?view, Int32 detail, Int32 screenX, Int32 screenY, Int32 clientX, Int32 clientY, Boolean ctrlKey, Boolean altKey, Boolean shiftKey, Boolean metaKey, MouseButton button, IEventTarget?target)
 {
     Init(type, bubbles, cancelable, view, detail);
     ScreenX        = screenX;
     ScreenY        = screenY;
     ClientX        = clientX;
     ClientY        = clientY;
     IsCtrlPressed  = ctrlKey;
     IsMetaPressed  = metaKey;
     IsShiftPressed = shiftKey;
     IsAltPressed   = altKey;
     Button         = button;
     Target         = target;
 }
Example #13
0
        internal static DisplayOrientation GetOrientation(this IWindow?window)
        {
            if (window == null)
            {
                return(DeviceDisplay.Current.MainDisplayInfo.Orientation);
            }

            return(window.Handler?.MauiContext?.GetPlatformWindow()?.Resources?.Configuration?.Orientation switch
            {
                Orientation.Landscape => DisplayOrientation.Landscape,
                Orientation.Portrait => DisplayOrientation.Portrait,
                Orientation.Square => DisplayOrientation.Portrait,
                _ => DisplayOrientation.Unknown
            });
Example #14
0
        public DialogResult Show(IWindow?parent)
        {
            var window = NativeCast.To <CocoaWindow>(parent);
            var dialog = CreateDialog();

            ObjC.Call(dialog.Handle, "setTitle:", NSString.Create(Title));
            ObjC.Call(dialog.Handle, "setCanCreateDirectories:", true);

            int result       = dialog.Run(window);
            var mappedResult = MapResult(result);

            BeforeReturn(dialog, mappedResult);

            return(mappedResult);
        }
Example #15
0
        internal static Devices.DisplayOrientation GetOrientation(this IWindow?window)
        {
            if (window == null)
            {
                return(Devices.DeviceDisplay.Current.MainDisplayInfo.Orientation);
            }

            bool isTV = Elementary.GetProfile() == "tv";

            return(window.Handler?.MauiContext?.GetPlatformWindow()?.Rotation switch
            {
                0 => isTV ? Devices.DisplayOrientation.Landscape : Devices.DisplayOrientation.Portrait,
                90 => isTV ? Devices.DisplayOrientation.Portrait : Devices.DisplayOrientation.Landscape,
                180 => isTV ? Devices.DisplayOrientation.Landscape : Devices.DisplayOrientation.Portrait,
                270 => isTV ? Devices.DisplayOrientation.Portrait : Devices.DisplayOrientation.Landscape,
                _ => Devices.DisplayOrientation.Unknown
            });
Example #16
0
        public async Task OnGetMainWindow_AfterMainWindowShownReturnsMainWindow()
        {
            await using var app      = App.StartRemote();
            await using var recorder = new TestRecorder(app);

            await app.InitializeWithDefaults(Assembly.GetExecutingAssembly().Location);

            IWindow window1 = await app.CreateWindowWithContent("");

            IWindow window2 = await app.CreateWindowWithContent("");

            IWindow?mainWindow = await app.GetMainWindow();

            Assert.AreEqual(window1, mainWindow);

            recorder.Success();
        }
Example #17
0
        public DialogResult Show(IWindow?parent)
        {
            var window = NativeCast.To <WinFormsWindow>(parent);

            System.Windows.Forms.DialogResult result;
            if (window == null)
            {
                result = WFMessageBox.Show(
                    Message,
                    Title,
                    WinFormsMapper.MapButtons(Buttons));
            }
            else
            {
                result = WFMessageBox.Show(
                    window,
                    Message,
                    Title,
                    WinFormsMapper.MapButtons(Buttons));
            }

            return(WinFormsMapper.MapResult(result));
        }
Example #18
0
 public void Init(String type, Boolean bubbles, Boolean cancelable, IWindow?view, Int32 detail)
 {
     Init(type, bubbles, cancelable);
     View   = view;
     Detail = detail;
 }
Example #19
0
 public FocusEvent(String type, Boolean bubbles = false, Boolean cancelable = false, IWindow?view = null, Int32 detail = 0, IEventTarget?target = null)
 {
     Init(type, bubbles, cancelable, view, detail, target);
 }
Example #20
0
 public void Init(String type, Boolean bubbles, Boolean cancelable, IWindow?view, Int32 detail, IEventTarget?target)
 {
     Init(type, bubbles, cancelable, view, detail);
     Target = target;
 }
Example #21
0
 public MouseEvent(String type, Boolean bubbles = false, Boolean cancelable = false, IWindow?view = null, Int32 detail = 0, Int32 screenX = 0, Int32 screenY = 0, Int32 clientX = 0, Int32 clientY = 0, Boolean ctrlKey = false, Boolean altKey = false, Boolean shiftKey = false, Boolean metaKey = false, MouseButton button = MouseButton.Primary, IEventTarget?relatedTarget = null)
 {
     Init(type, bubbles, cancelable, view, detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget);
 }
Example #22
0
 internal static DisplayOrientation GetOrientation(this IWindow?window) =>
 DeviceDisplay.Current.MainDisplayInfo.Orientation;
Example #23
0
        public DialogResult Show(IWindow?parent)
        {
            var    window    = NativeCast.To <GtkWindow>(parent);
            bool   useNative = false && Gtk.Version.IsAtLeast(3, 2, 0);
            IntPtr dialog    = IntPtr.Zero;

            try
            {
                using (GLibString gtitle = Title)
                {
                    if (useNative)
                    {
                        dialog = Gtk.Dialog.CreateNativeFileDialog(
                            gtitle.Pointer,
                            window?.Handle ?? IntPtr.Zero,
                            Type,
                            IntPtr.Zero,
                            IntPtr.Zero);
                    }
                    else
                    {
                        string acceptString = GetAcceptString(Type);
                        using GLibString acceptButton = acceptString;
                        using GLibString cancelButton = "_Cancel";
                        dialog = Gtk.Dialog.CreateFileDialog(
                            gtitle.Pointer,
                            window?.Handle ?? IntPtr.Zero,
                            Type,
                            cancelButton,
                            GtkResponseType.Cancel,
                            acceptButton,
                            GtkResponseType.Accept,
                            IntPtr.Zero);
                    }
                }

                Gtk.Dialog.SetCanCreateFolder(dialog, true);

                BeforeShow(dialog);

                GtkResponseType result;
                if (useNative)
                {
                    result = Gtk.Dialog.RunNative(dialog);
                }
                else
                {
                    result = Gtk.Dialog.Run(dialog);
                }

                var mappedResult = MapResult(result);
                BeforeReturn(dialog, mappedResult);

                return(mappedResult);
            }
            finally
            {
                if (dialog != IntPtr.Zero)
                {
                    if (useNative)
                    {
                        GLib.UnrefObject(dialog);
                    }
                    else
                    {
                        Gtk.Widget.Destroy(dialog);
                    }
                }
            }
        }
Example #24
0
 /// <inheritdoc />
 public IWindow CreateWindow(WindowOptions options) => _lastCreatedWindow = new GlfwWindow(options, null, null);
Example #25
0
 public WheelEvent(String type, Boolean bubbles = false, Boolean cancelable = false, IWindow?view = null, Int32 detail = 0, Int32 screenX = 0, Int32 screenY = 0, Int32 clientX = 0, Int32 clientY = 0, MouseButton button = MouseButton.Primary, IEventTarget?target = null, String?modifiersList = null, Double deltaX = 0.0, Double deltaY = 0.0, Double deltaZ = 0.0, WheelMode deltaMode = WheelMode.Pixel)
 {
     Init(type, bubbles, cancelable, view, detail, screenX, screenY, clientX, clientY, button, target, modifiersList ?? String.Empty, deltaX, deltaY, deltaZ, deltaMode);
 }
Example #26
0
 public UiEvent(String type, Boolean bubbles = false, Boolean cancelable = false, IWindow?view = null, Int32 detail = 0)
 {
     Init(type, bubbles, cancelable, view, detail);
 }