Пример #1
0
        private static void PropertyInitStyle()
        {
            var iconFile = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                ? "wwwroot/photino-logo.ico"
                : "wwwroot/photino-logo.png";

            mainWindow = new PhotinoWindow
            {
                IconFile = iconFile,
                Title    = $"My Photino Window {_windowNumber++}",

                StartUrl = "wwwroot/main.html",
                //StartString = "<h1>Hello Photino!</h1>",

                //Centered = true,
                //Chromeless = true,
                //FullScreen = true,
                //Maximized = true,
                //Minimized = true,
                //Resizable = false,
                //TopMost = true,
                //UseOsDefaultLocation = false,
                UseOsDefaultSize = false,
                //Zoom = 300,

                //ContextMenuEnabled = false,
                //DevToolsEnabled = false,
                //GrantBrowserPermissions = false,

                //CenterOnInitialize = true,
                //Size = new Size(800, 600),
                Height = 600,
                Width  = 800,
                //Location = new Point(50, 50),
                //Top = 50,
                //Left = 50,

                WindowCreatingHandler        = WindowCreating,
                WindowCreatedHandler         = WindowCreated,
                WindowLocationChangedHandler = WindowLocationChanged,
                WindowSizeChangedHandler     = WindowSizeChanged,
                WindowMaximizedHandler       = WindowMaximized,
                WindowRestoredHandler        = WindowRestored,
                WindowMinimizedHandler       = WindowMinimized,
                WebMessageReceivedHandler    = MessageReceivedFromWindow,
                WindowClosingHandler         = WindowIsClosing,
                WindowFocusInHandler         = WindowFocusIn,
                WindowFocusOutHandler        = WindowFocusOut,

                //TemporaryFilesPath = @"C:\Temp",

                LogVerbosity = _logEvents ? 2 : 0,
            };

            //Can this be done with a property?
            mainWindow.RegisterCustomSchemeHandler("app", AppCustomSchemeUsed);

            mainWindow.WaitForClose();

            Console.WriteLine("Done Blocking!");
        }
Пример #2
0
        private static void MessageReceivedFromWindow(object sender, string message)
        {
            Log(sender, $"MessageRecievedFromWindow Callback Fired.");

            var currentWindow = sender as PhotinoWindow;

            if (string.Compare(message, "child-window", true) == 0)
            {
                var iconFile = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                    ? "wwwroot/photino-logo.ico"
                    : "wwwroot/photino-logo.png";

                var x = new PhotinoWindow(currentWindow)
                        .SetTitle($"Child Window {_windowNumber++}")
                        //.SetIconFile(iconFile)
                        .Load("wwwroot/main.html")

                        .SetUseOsDefaultLocation(true)
                        .SetHeight(600)
                        .SetWidth(800)

                        .SetGrantBrowserPermissions(false)

                        .RegisterWindowCreatingHandler(WindowCreating)
                        .RegisterWindowCreatedHandler(WindowCreated)
                        .RegisterLocationChangedHandler(WindowLocationChanged)
                        .RegisterSizeChangedHandler(WindowSizeChanged)
                        .RegisterWebMessageReceivedHandler(MessageReceivedFromWindow)
                        .RegisterWindowClosingHandler(WindowIsClosing)

                        .RegisterCustomSchemeHandler("app", AppCustomSchemeUsed)

                        .SetTemporaryFilesPath(currentWindow.TemporaryFilesPath)
                        .SetLogVerbosity(_logEvents ? 2 : 0);

                x.WaitForClose();

                //x.Center();           //WaitForClose() is non-blocking for child windows
                //x.SetHeight(800);
                //x.Close();
            }
            else if (string.Compare(message, "zoom-in", true) == 0)
            {
                currentWindow.Zoom += 5;
                Log(sender, $"Zoom: {currentWindow.Zoom}");
            }
            else if (string.Compare(message, "zoom-out", true) == 0)
            {
                currentWindow.Zoom -= 5;
                Log(sender, $"Zoom: {currentWindow.Zoom}");
            }
            else if (string.Compare(message, "center", true) == 0)
            {
                currentWindow.Center();
            }
            else if (string.Compare(message, "close", true) == 0)
            {
                currentWindow.Close();
            }
            else if (string.Compare(message, "minimize", true) == 0)
            {
                currentWindow.SetMinimized(!currentWindow.Minimized);
            }
            else if (string.Compare(message, "maximize", true) == 0)
            {
                currentWindow.SetMaximized(!currentWindow.Maximized);
            }
            else if (string.Compare(message, "setcontextmenuenabled", true) == 0)
            {
                currentWindow.SetContextMenuEnabled(!currentWindow.ContextMenuEnabled);
            }
            else if (string.Compare(message, "setdevtoolsenabled", true) == 0)
            {
                currentWindow.SetDevToolsEnabled(!currentWindow.DevToolsEnabled);
            }
            else if (string.Compare(message, "setgrantbrowserpermissions", true) == 0)
            {
                currentWindow.SetGrantBrowserPermissions(!currentWindow.GrantBrowserPermissions);
            }
            else if (string.Compare(message, "seticonfile", true) == 0)
            {
                var iconFile = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
                    ? "wwwroot/photino-logo.ico"
                    : "wwwroot/photino-logo.png";

                currentWindow.SetIconFile(iconFile);
            }
            else if (string.Compare(message, "setposition", true) == 0)
            {
                currentWindow.SetLeft(currentWindow.Left + 5);
                currentWindow.SetTop(currentWindow.Top + 5);
            }
            else if (string.Compare(message, "setresizable", true) == 0)
            {
                currentWindow.SetResizable(!currentWindow.Resizable);
            }
            else if (string.Compare(message, "setsize-up", true) == 0)
            {
                currentWindow.SetHeight(currentWindow.Height + 5);
                currentWindow.SetWidth(currentWindow.Width + 5);
            }
            else if (string.Compare(message, "setsize-down", true) == 0)
            {
                currentWindow.SetHeight(currentWindow.Height - 5);
                currentWindow.SetWidth(currentWindow.Width - 5);
            }
            else if (string.Compare(message, "settitle", true) == 0)
            {
                currentWindow.SetTitle(currentWindow.Title + "*");
            }
            else if (string.Compare(message, "settopmost", true) == 0)
            {
                currentWindow.SetTopMost(!currentWindow.Topmost);
            }
            else if (string.Compare(message, "setfullscreen", true) == 0)
            {
                currentWindow.SetFullScreen(!currentWindow.FullScreen);
            }
            else if (string.Compare(message, "showproperties", true) == 0)
            {
                var properties = GetPropertiesDisplay(currentWindow);
                currentWindow.OpenAlertWindow("Settings", properties);
            }
            else if (string.Compare(message, "sendWebMessage", true) == 0)
            {
                currentWindow.SendWebMessage("alert('web message');");
            }
            else if (string.Compare(message, "toastNotification", true) == 0)
            {
                currentWindow.SendNotification("Toast Title", " Taoast message!");
            }
            else
            {
                throw new Exception($"Unknown message '{message}'");
            }
        }