Ejemplo n.º 1
0
        public WindowHandle CreateWindow(WindowPrototype prototype)
        {
            BrowserWindow window = new BrowserWindow(prototype);
            WindowHandle  handle = new WindowHandle(window, window.WebBrowser);

            return(handle);
        }
        private string ShowCustomDialog()
        {
            WindowPrototype win = new WindowPrototype();

            win.Url = "dialogs/custom-dialog/custom-dialog.html";
            Container.ShowDialog(win);
            //todo: return some value?
            return("todo");
        }
Ejemplo n.º 3
0
        private void Construct(WindowPrototype prot)
        {
            string errorMessage = null;

            try
            {
                webBrowser = new WebView();
            }
            catch (Exception)
            {
                errorMessage = "Failed to create a WebKit.WebView widget.\nMake sure that libwebkitgtk-1.0 is installed.";
            }

            //todo: remove windowHandle creation from here
            WindowHandle handle = new WindowHandle(this, this.webBrowser);

            this.Destroyed += (o, args) =>
            {
                prot.OnClose(handle);
            };

            VBox vbox = new VBox(false, 0);

            this.Add(vbox);

            if (prot.Menu != null && prot.Menu.Any())
            {
                MenuBar menuBar = CreateMenu(handle, prot.Menu);

                vbox.PackStart(menuBar, false, false, 0);
            }

            if (webBrowser == null)
            {
                Label errorLabel = new Label(errorMessage);
                vbox.PackEnd(errorLabel, true, true, 0);
            }
            else
            {
                vbox.PackEnd(webBrowser, true, true, 0);

                webBrowser.TitleChanged += (o, args) =>
                {
                    string title = webBrowser.Title;
                    Application.Invoke(delegate { this.Title = title; });
                };

                webBrowser.LoadUri(prot.Url);
            }

            //todo: bug, window cannot be resized to smaller size (seems related to https://bugs.webkit.org/show_bug.cgi?id=17154)
            Resize(prot.Width, prot.Height);

            vbox.ShowAll();
        }
        private WindowHandle ConstructDialog(WindowPrototype prototype)
        {
            Form form = new Form();

            form.Size = new Size(prototype.Width, prototype.Height);

            ChromiumWebBrowser webBrowser = new ChromiumWebBrowser("about:blank");

            //todo: usage of WindowHandle is a little bit cumbersome
            WindowHandle handle = new WindowHandle(form, webBrowser);

            //todo: is SuspendLayout/ResumeLayout required?
            form.SuspendLayout();

            int occupiedHeight = 0;

            if (prototype.Menu != null && prototype.Menu.Any())
            {
                MenuStrip menu = CreateMenu(handle, prototype.Menu);

                const int menuHeight = 24;
                menu.Size     = new Size(form.ClientSize.Width, menuHeight);
                menu.Location = new Point(0, 0);
                menu.TabIndex = 0;
                form.Controls.Add(menu);
                occupiedHeight += menuHeight;
            }

            form.Controls.Add(webBrowser);

            webBrowser.Anchor   = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            webBrowser.Location = new Point(0, occupiedHeight);
            webBrowser.Size     = new Size(form.ClientSize.Width, form.ClientSize.Height - occupiedHeight);
            webBrowser.TabIndex = 1;

            form.Controls.Add(webBrowser);

            //todo: is SuspendLayout/ResumeLayout required?
            form.ResumeLayout();

            webBrowser.TitleChanged += (sender, args) =>
            {
                if (form.InvokeRequired)
                {
                    form.Invoke(new Action <string>(title => { form.Text = title; }), webBrowser.Title);
                }
            };

            webBrowser.Load(prototype.Url);

            return(handle);
        }
Ejemplo n.º 5
0
        private WindowHandle ShowDialogHandler(Window parent, WindowPrototype prototype)
        {
            //todo: use CreateWindow instead
            BrowserWindow win = new BrowserWindow(prototype);

            win.TransientFor    = parent;
            win.Modal           = true;
            win.SkipTaskbarHint = true;
            win.TypeHint        = Gdk.WindowTypeHint.Dialog;

            win.Show();

            return(new WindowHandle(win, win.WebBrowser));
        }
        public HcduContent()
        {
            MainWindowPrototype     = new WindowPrototype();
            MainWindowPrototype.Url = "index.html";

            MenuPrototype toolsMenu = new MenuPrototype {
                Text = "Tools"
            };

            MainWindowPrototype.Menu.Add(toolsMenu);

            toolsMenu.Items.Add(new MenuPrototype {
                Text = "Home Page", OnAction = wh => { Container.NavigateTo(wh, MainWindowPrototype.Url); }
            });
            toolsMenu.Items.Add(new MenuPrototype {
                Text = "Angular Material Website", OnAction = wh => { Container.NavigateTo(wh, "https://material.angularjs.org"); }
            });
            toolsMenu.Items.Add(new MenuPrototype {
                Text = "Developer tools", OnAction = wh => { Container.ShowDevTools(wh); }
            });
            toolsMenu.Items.Add(new MenuPrototype {
                Text = "Reload", OnAction = wh => { Container.ReloadPage(wh); }
            });
            toolsMenu.Items.Add(new MenuPrototype {
                Text = "Resources List", OnAction = wh => { Container.NavigateTo(wh, DebugPages.ResourcesListUrl); }
            });

            Content.AddContent(typeof(HcduContent).Assembly, "HCDU.Content.Web");
            Content.AddMethod("rest/cars/boxter", () => new Car {
                Model = "Porsche Boxster", Year = 1996
            });
            Content.AddMethod <Car>("rest/exception", () => { throw new Exception("Test Exception"); });
            Content.AddMethod("rest/selectFolder", () => SelectFolder(false));
            Content.AddMethod("rest/selectNewFolder", () => SelectFolder(true));
            Content.AddMethod("rest/showCustomDialog", ShowCustomDialog);
            Content.AddMethod("rest/closeCustomDialog", CloseCustomDialog);
            Content.AddMethod("rest/backend-events/increment", BackendEventsIncrement);
            Content.AddMethod("rest/backend-events/increment5Sec", BackendEventsIncrement5Sec);

            Sockets.AddSocketProvider("ws/backend-events", stateSocket);
            stateSocket.State = backendEventsCounter;

            //todo: use more generic way of combining packages?
            DebugPages.AppendTo(Content);
        }
        public WindowHandle ShowDialog(WindowHandle parent, WindowPrototype prototype)
        {
            Form parentForm = (Form)parent.NativeWindow;

            if (parentForm.InvokeRequired)
            {
                return((WindowHandle)parentForm.Invoke(new Func <WindowHandle, WindowPrototype, WindowHandle>(ShowDialog), parent, prototype));
            }

            WindowHandle handle = ConstructDialog(prototype);
            Form         window = (Form)handle.NativeWindow;

            window.Closed += (sender, args) => prototype.OnClose(handle);

            //todo: use ShowDialog when CefSharp 43 is released (now it freezes the application)
            window.Show(parentForm);

            //todo: this would conflict with window.ShowDialog
            return(handle);
        }
 public WindowHandle CreateWindow(WindowPrototype prototype)
 {
     return(ConstructDialog(prototype));
 }
Ejemplo n.º 9
0
 public WindowHandle ShowDialog(WindowHandle parent, WindowPrototype prototype)
 {
     return(InvokeSync(() => ShowDialogHandler((Window)parent.NativeWindow, prototype)));
 }
Ejemplo n.º 10
0
 public BrowserWindow(WindowPrototype prototype) : base(WindowType.Toplevel)
 {
     Construct(prototype);
 }