Esempio n. 1
0
        // Constructor
        public AppSystem(IForegroundWindowHook fgHook, IWindowUpdateHook winHook, IMouseHook msHook)
        {
            _state = new InitialState();

            _stateContext = new AppStateContext
            {
                PathModeLocksToHandle = false,
                ForegroundHook        = fgHook,
                WindowHook            = winHook,
                MouseHook             = msHook,
                SetCurrentState       = (next) => SetCurrentState(next),
                SendLockStateChange   = () => LockStateChanged.Invoke(this, new Events.LockStateChangedEventArgs {
                    IsLocked = IsLocked
                }),
                SendPathChange = (path) => PathChanged.Invoke(this, new Events.PathChangedEventArgs {
                    Path = path
                }),
                SendTitleChange = (title) => TitleChanged.Invoke(this, new Events.TitleChangedEventArgs {
                    Title = title
                }),
                SendDimensionsChange = (dimensions) => DimensionsChanged.Invoke(this, new Events.DimensionsChangedEventArgs {
                    Dimensions = dimensions
                }),
                SendForegroundChange = (inForeground) => ForegroundChanged.Invoke(this, new Events.ForegroundStateChangedEventArgs {
                    InForeground = inForeground
                })
            };

            fgHook.ForegroundWindowChanged += ForegroundHook_ForegroundWindowChanged;
            winHook.WindowClosed           += WindowHook_WindowClosed;
            winHook.DimensionsChanged      += WindowHook_DimensionsChanged;
            winHook.TitleChanged           += WindowHook_TitleChanged;
        }
Esempio n. 2
0
        protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            base.OnNavigatingFrom(e);
            await Refresh();

            TitleChanged?.Invoke(this, new NavigationViewContentEvent("课程列表"));
        }
Esempio n. 3
0
        public UCCefSharpX64(string url)
        {
            InitializeComponent();

            var setting = new CefSettings();

            // 设置语言
            setting.Locale = "zh-CN";
            //cef设置userAgent
            setting.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
            //配置浏览器路径
            setting.BrowserSubprocessPath = $"{CefSharpHelp.PathX64}\\CefSharp.BrowserSubprocess.exe";
            Cef.Initialize(setting, true, true);
            // Add it to the form and fill it to the form window.
            chromeBrowser = new ChromiumWebBrowser(url);
            this.Controls.Add(chromeBrowser);
            chromeBrowser.Dock                         = DockStyle.Fill;
            chromeBrowser.AddressChanged              += (sender, e) => { AddressChanged?.Invoke(sender, e.Address); };
            chromeBrowser.StatusMessage               += (sender, e) => { StatusMessage?.Invoke(sender, e.Value); };
            chromeBrowser.ConsoleMessage              += (sender, e) => { ConsoleMessage?.Invoke(sender, new ICefSharp.Model.ConsoleMessageEventArgs(e.Message, e.Source, e.Line)); };
            chromeBrowser.LoadingStateChanged         += (sender, e) => { LoadingStateChanged?.Invoke(sender, new ICefSharp.Model.LoadingStateChangedEventArgs(e.CanGoForward, e.CanGoBack, e.CanReload, e.IsLoading)); };
            chromeBrowser.LoadError                   += (sender, e) => { LoadError?.Invoke(sender, new ICefSharp.Model.LoadErrorEventArgs((int)e.ErrorCode, e.FailedUrl, e.ErrorText)); };
            chromeBrowser.IsBrowserInitializedChanged += (sender, e) => { IsBrowserInitializedChanged?.Invoke(sender, e.IsBrowserInitialized); };
            chromeBrowser.TitleChanged                += (sender, e) => { TitleChanged?.Invoke(sender, e.Title); };
        }
Esempio n. 4
0
        /// <summary>
        /// Sets up the view and sets event handlers
        /// </summary>
        void Build(CGRect rect)
        {
            var scrollWidth = NSScroller.ScrollerWidthForControlSize(NSControlSize.Regular);
            var scrollFrame = new CGRect(rect.Right - scrollWidth, rect.Y, scrollWidth, rect.Height);

            scroller = new NSScroller(scrollFrame);
            scroller.ScrollerStyle  = NSScrollerStyle.Legacy;
            scroller.DoubleValue    = 0.0;
            scroller.KnobProportion = 0.1f;
            scroller.Enabled        = false;
            AddSubview(scroller);

            scroller.Activated += ScrollerActivated;

            var terminalFrame = new CGRect(rect.X, rect.Y, rect.Width - scrollWidth, rect.Height);

            terminalView = new TerminalView(terminalFrame);
            var t = terminalView.Terminal;

            terminalView.UserInput         = HandleUserInput;
            terminalView.SizeChanged      += HandleSizeChanged;
            terminalView.TerminalScrolled += HandleTerminalScrolled;
            terminalView.CanScrollChanged += HandleTerminalCanScrollChanged;
            terminalView.TitleChanged     += (TerminalView sender, string title) => {
                TitleChanged?.Invoke(title);
            };

            AddSubview(terminalView);
        }
Esempio n. 5
0
 /// <summary>
 /// Invoked when the user changes the title text box.
 /// </summary>
 /// <param name="sender">The sending object</param>
 /// <param name="e">The event arguments</param>
 private void TitleTextBox_TextChanged(object sender, EventArgs e)
 {
     if (TitleChanged != null)
     {
         TitleChanged.Invoke(this, e);
     }
 }
Esempio n. 6
0
 public virtual void OnTitleChanged()
 {
     if (TitleChanged != null)
     {
         TitleChanged.Invoke(this, EventArgs.Empty);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Open file with shape
        /// </summary>
        /// <param name="obj"></param>
        private void OpenFile(object obj)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.DefaultExt = ".xml";
            openFileDialog.Filter     = "XML documents (.xml)|*.xml";
            if (openFileDialog.ShowDialog() == true)
            {
                string fileName = openFileDialog.FileName;
                WindowTitle = fileName;
                TitleChanged?.Invoke(WindowTitle);
                List <Shape>  polylines  = new List <Shape>();
                XmlSerializer serializer = new XmlSerializer(typeof(List <Shape>));
                using (XmlReader reader = XmlReader.Create(fileName))
                {
                    polylines = (List <Shape>)serializer.Deserialize(reader);
                }
                Polylines.Clear();
                for (int i = 0; i < polylines.Count; ++i)
                {
                    Polylines.Add(new Polyline()
                    {
                        Name = String.Format("Polyline_{0}", i + 1), Stroke = new SolidColorBrush(polylines[i].ShapeColor), Points = polylines[i].Points
                    });
                }
                OnPropertyChanged("Polylines");
            }
        }
Esempio n. 8
0
 public async Task HandleScriptCall(string data)
 {
     // run script call handling on separate task to free up UI
     await Task.Run(async() =>
     {
         var info = JsonConverter.Deserialize <InvokeInfoModel>(data);
         if (info != null)
         {
             if (info.Type == "title")
             {
                 string title = JsonConverter.Deserialize <string>(info.Parameters);
                 TitleChanged?.Invoke(this, title);
             }
             else if (info.Type == "api")
             {
                 var result = await ResolveCall(info.Id, info.Parameters);
                 await EndApiCall(info, result);
             }
             else if (info.CallbackId != null)
             {
                 string message = $"Invalid invoke type \"{info.Type ?? "<null>"}\".";
                 await EndApiCall(info, ApiResultModel.FromError(message));
             }
         }
     });
 }
Esempio n. 9
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            await Refresh();

            TitleChanged?.Invoke(this, new NavigationViewContentEvent(GetTitle()));
        }
Esempio n. 10
0
        private void InitializeSmartEvent()
        {
            // focus dummy
            _focusIn  = new SmartEvent(this, "focused");
            _focusOut = new SmartEvent(this, "unfocused");

            _focusIn.On  += (s, e) => { ((WebView)s).SetFocus(true); };
            _focusOut.On += (s, e) => { ((WebView)s).SetFocus(false); };

            _loadStarted             = new SmartEvent(this, _realHandle, "load,started");
            _loadFinished            = new SmartEvent(this, _realHandle, "load,finished");
            _loadError               = new SmartEvent <SmartCallbackLoadErrorArgs>(this, _realHandle, "load,error", SmartCallbackLoadErrorArgs.CreateFromSmartEvent);
            _titleChanged            = new SmartEvent <SmartCallbackArgs>(this, _realHandle, "title,changed", SmartCallbackArgs.CreateFromSmartEvent);
            _urlChanged              = new SmartEvent <SmartCallbackArgs>(this, _realHandle, "url,changed", SmartCallbackArgs.CreateFromSmartEvent);
            _contextMenuCustomize    = new SmartEvent <ContextMenuCustomizeEventArgs>(this, _realHandle, "contextmenu,customize", ContextMenuCustomizeEventArgs.CreateFromSmartEvent);
            _contextMenuItemSelected = new SmartEvent <ContextMenuItemEventArgs>(this, _realHandle, "contextmenu,selected", ContextMenuItemEventArgs.CreateFromSmartEvent);
            _policyNavigationDecide  = new SmartEvent <NavigationPolicyEventArgs>(this, _realHandle, "policy,navigation,decide", NavigationPolicyEventArgs.CreateFromSmartEvent);
            _policyNewWindowDecide   = new SmartEvent <NewWindowPolicyEventArgs>(this, _realHandle, "policy,newwindow,decide", NewWindowPolicyEventArgs.CreateFromSmartEvent);
            _policyResponseDecide    = new SmartEvent <ResponsePolicyEventArgs>(this, _realHandle, "policy,response,decide", ResponsePolicyEventArgs.CreateFromSmartEvent);

            _loadStarted.On             += (s, e) => { LoadStarted?.Invoke(this, EventArgs.Empty); };
            _loadFinished.On            += (s, e) => { LoadFinished?.Invoke(this, EventArgs.Empty); };
            _loadError.On               += (s, e) => { LoadError?.Invoke(this, e); };
            _titleChanged.On            += (s, e) => { TitleChanged?.Invoke(this, e); };
            _urlChanged.On              += (s, e) => { UrlChanged?.Invoke(this, e); };
            _policyNavigationDecide.On  += (s, e) => { NavigationPolicyDecideRequested?.Invoke(this, e); };
            _policyNewWindowDecide.On   += (s, e) => { NewWindowPolicyDecideRequested?.Invoke(this, e); };
            _policyResponseDecide.On    += (s, e) => { ResponsePolicyDecideRequested?.Invoke(this, e); };
            _contextMenuItemSelected.On += (s, e) => { ContextMenuItemSelected?.Invoke(this, e); };
            _contextMenuCustomize.On    += (s, e) => { _contextMenuCustomizeDelegate?.Invoke(e.Menu); };
        }
 void Update(CommandInfo ci)
 {
     if (ci.Icon != Image) {
         Image = ci.Icon;
         if (ImageChanged != null)
             ImageChanged (this, null);
     }
     if (ci.Enabled != Enabled) {
         Enabled = ci.Enabled;
         if (EnabledChanged != null)
             EnabledChanged (this, null);
     }
     if (ci.Description != Tooltip) {
         Tooltip = ci.Description;
         if (TooltipChanged != null)
             TooltipChanged (this, null);
     }
     if (ci.Visible != Visible) {
         Visible = ci.Visible;
         if (VisibleChanged != null)
             VisibleChanged (this, null);
     }
     if (ci.Text != Title) {
         Title = ci.Text;
         TitleChanged?.Invoke (this, null);
     }
 }
Esempio n. 12
0
        private void SendWindowTitle(IntPtr handle)
        {
            var title = NativeMethods.GetWindowText(handle);

            TitleChanged?.Invoke(this, new TitleChangedEventArgs {
                Title = title
            });
        }
Esempio n. 13
0
 /// <summary>
 /// to be called by view
 /// </summary>
 public void SetTitle(string title)
 {
     if (string.IsNullOrWhiteSpace(title))
     {
         title = _fallbackTitle;
     }
     TitleChanged?.Invoke(this, title);
 }
Esempio n. 14
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            await Refresh();

            // Title would not change after refreshing
            TitleChanged?.Invoke(this, new NavigationViewContentEvent("题库列表"));
        }
 private void Control_TitleChanged(string title)
 {
     if (WindowSettings.UrlPolicy != UrlPolicy.Always)
     {
         Title = title;
         window.UpdateTitle(Title);
         TitleChanged?.Invoke(Title);
     }
 }
Esempio n. 16
0
        public static void SetTitleBarText(string title)
        {
            // Get current window
            var appView = ApplicationView.GetForCurrentView();

            appView.Title = title;

            TitleChanged?.Invoke(null, title);
        }
Esempio n. 17
0
        private void ObservedValueChanged(IntPtr self, IntPtr op, IntPtr keyPath, IntPtr obj, IntPtr change, IntPtr context)
        {
            string key = NSString.GetString(keyPath);

            if (key == "title")
            {
                string title = NSString.GetString(ObjC.Call(Handle, "title"));
                TitleChanged?.Invoke(this, title);
            }
        }
Esempio n. 18
0
        private async Task InitWebview()
        {
            environment = await CoreWebView2Environment.CreateAsync();

            await webview.EnsureCoreWebView2Async(environment);

            webview.CoreWebView2.DocumentTitleChanged += (s, t) => { TitleChanged?.Invoke(this, webview.CoreWebView2.DocumentTitle); };

            string initScript = Resources.GetInitScript("Edgium");
            await webview.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(initScript);
        }
        private void Control_AddressChanged(string address)
        {
            logger.Debug($"Navigated{(WindowSettings.UrlPolicy.CanLog() ? $" to '{address}'" : "")}.");
            window.UpdateAddress(address);

            if (WindowSettings.UrlPolicy == UrlPolicy.Always || WindowSettings.UrlPolicy == UrlPolicy.BeforeTitle)
            {
                Title = address;
                window.UpdateTitle(address);
                TitleChanged?.Invoke(address);
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Invoked when the user changes the title text box.
 /// </summary>
 /// <param name="sender">The sending object</param>
 /// <param name="e">The event arguments</param>
 private void TitleTextBox_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (TitleChanged != null)
         {
             TitleChanged.Invoke(this, e);
         }
     }
     catch (Exception err)
     {
         ShowError(err);
     }
 }
Esempio n. 21
0
        public async Task Refresh()
        {
            OnContentLoading?.Invoke(this, new NavigationViewContentEvent());
            try {
                viewModel.Course = await Model.MatrixRequest.GetCourse(viewModel.CourseId);

                viewModel.Assignments = await Model.MatrixRequest.GetAssignmentList(viewModel.CourseId);
            } catch (MatrixException.MatrixException err) {
                Debug.WriteLine($"请求课程信息错误:{err.Message}");
                OnContentError?.Invoke(this, new NavigationViewContentEvent(err));
            }
            OnContentLoaded?.Invoke(this, new NavigationViewContentEvent());

            TitleChanged?.Invoke(this, new NavigationViewContentEvent(GetTitle()));
        }
Esempio n. 22
0
        public AndroidPlatformGameWindow(AndroidPlatformGameView gameView)
        {
            this.gameView = gameView;

            gameView.Load               += (o, e) => Load?.Invoke(o, e);
            gameView.Unload             += (o, e) => Unload?.Invoke(o, e);
            gameView.UpdateFrame        += (o, e) => UpdateFrame?.Invoke(o, e);
            gameView.RenderFrame        += (o, e) => RenderFrame?.Invoke(o, e);
            gameView.Resize             += (o, e) => Resize?.Invoke(o, e);
            gameView.Closed             += (o, e) => Closed?.Invoke(o, e);
            gameView.Disposed           += (o, e) => Disposed?.Invoke(o, e);
            gameView.TitleChanged       += (o, e) => TitleChanged?.Invoke(o, e);
            gameView.VisibleChanged     += (o, e) => VisibleChanged?.Invoke(o, e);
            gameView.WindowStateChanged += (o, e) => WindowStateChanged?.Invoke(o, e);
        }
        private void RequestHandler_RequestBlocked(string url)
        {
            Task.Run(() =>
            {
                var message = text.Get(TextKey.MessageBox_BrowserNavigationBlocked).Replace("%%URL%%", WindowSettings.UrlPolicy.CanLogError() ? url : "");
                var title   = text.Get(TextKey.MessageBox_BrowserNavigationBlockedTitle);

                control.TitleChanged -= Control_TitleChanged;

                if (url.Equals(startUrl, StringComparison.OrdinalIgnoreCase))
                {
                    window.UpdateTitle($"*** {title} ***");
                    TitleChanged?.Invoke($"*** {title} ***");
                }

                messageBox.Show(message, title, parent: window);
                control.TitleChanged += Control_TitleChanged;
            });
        }
Esempio n. 24
0
        private void InitializeSmartEvent()
        {
            // focus dummy
            _focusIn  = new SmartEvent(this, "focused");
            _focusOut = new SmartEvent(this, "unfocused");

            _focusIn.On  += (s, e) => { ((WebView)s).SetFocus(true); };
            _focusOut.On += (s, e) => { ((WebView)s).SetFocus(false); };

            _loadStarted  = new SmartEvent(this, _realHandle, "load,started");
            _loadFinished = new SmartEvent(this, _realHandle, "load,finished");
            _loadError    = new SmartEvent <SmartCallbackLoadErrorArgs>(this, _realHandle, "load,error", SmartCallbackLoadErrorArgs.CreateFromSmartEvent);
            _titleChanged = new SmartEvent <SmartCallbackArgs>(this, _realHandle, "title,changed", SmartCallbackArgs.CreateFromSmartEvent);
            _urlChanged   = new SmartEvent <SmartCallbackArgs>(this, _realHandle, "url,changed", SmartCallbackArgs.CreateFromSmartEvent);

            _loadStarted.On  += (s, e) => { LoadStarted?.Invoke(this, EventArgs.Empty); };
            _loadFinished.On += (s, e) => { LoadFinished?.Invoke(this, EventArgs.Empty); };
            _loadError.On    += (s, e) => { LoadError?.Invoke(this, e); };
            _titleChanged.On += (s, e) => { TitleChanged?.Invoke(this, e); };
            _urlChanged.On   += (s, e) => { UrlChanged?.Invoke(this, e); };
        }
        internal void Update()
        {
            var icon         = nativeMethods.GetWindowIcon(Handle);
            var iconChanged  = icon != IntPtr.Zero && (!(Icon is NativeIconResource) || Icon is NativeIconResource r && r.Handle != icon);
            var title        = nativeMethods.GetWindowTitle(Handle);
            var titleChanged = Title?.Equals(title, StringComparison.Ordinal) != true;

            if (iconChanged)
            {
                Icon = new NativeIconResource {
                    Handle = icon
                };
                IconChanged?.Invoke(Icon);
            }

            if (titleChanged)
            {
                Title = title;
                TitleChanged?.Invoke(title);
            }
        }
Esempio n. 26
0
        private void Initialize()
        {
            WebViewLoader.Initialize(Settings);

            chromium = new ChromiumBrowser();
            chromium.BrowserInitialized         += OnWebViewBrowserInitialized;
            chromium.LoadEnd                    += OnWebViewLoadEnd;
            chromium.LoadError                  += OnWebViewLoadError;
            chromium.TitleChanged               += delegate { TitleChanged?.Invoke(); };
            chromium.JavascriptContextCreated   += OnJavascriptContextCreated;
            chromium.JavascriptContextReleased  += OnJavascriptContextReleased;
            chromium.JavascriptUncaughException += OnJavascriptUncaughException;
            chromium.UnhandledException         += (o, e) => ForwardUnhandledAsyncException(e.Exception);

            chromium.RequestHandler     = new InternalRequestHandler(this);
            chromium.LifeSpanHandler    = new InternalLifeSpanHandler(this);
            chromium.ContextMenuHandler = new InternalContextMenuHandler(this);
            chromium.DialogHandler      = new InternalDialogHandler(this);
            chromium.DownloadHandler    = new InternalDownloadHandler(this);
            chromium.JSDialogHandler    = new InternalJsDialogHandler(this);
            chromium.DragHandler        = new InternalDragHandler(this);
            chromium.KeyboardHandler    = new InternalKeyboardHandler(this);

            if (!Settings.OsrEnabled)
            {
                // having the handler (by default) seems to cause some focus troubles, enable only osr disabled
                chromium.FocusHandler = new InternalFocusHandler(this);
            }

            EditCommands = new EditCommands(chromium);

            disposables = new IDisposable[] {
                AsyncCancellationTokenSource,
                chromium // browser should be the last
            };

            ExtraInitialize();

            GlobalWebViewInitialized?.Invoke(this);
        }
Esempio n. 27
0
        public async Task Refresh()
        {
            int courseId = viewModel.Assignment.course_id;
            int caId     = viewModel.Assignment.ca_id;

            // notify loading
            OnContentLoading?.Invoke(this, new NavigationViewContentEvent());

            try {
                viewModel.Assignment = await Model.MatrixRequest.GetAssignment(courseId, caId);
            } catch (MatrixException.MatrixException err) {
                var message = $"获取课程{courseId}作业{caId}详情失败";
                Debug.WriteLine($"{message}: {err.Message}");
                OnContentError?.Invoke(this, new NavigationViewContentEvent(err, message));
            }

            // notify loaded
            OnContentLoaded?.Invoke(this, new NavigationViewContentEvent());

            // set title since assignment name changed.
            TitleChanged?.Invoke(this, new NavigationViewContentEvent(viewModel.Assignment.name));
        }
Esempio n. 28
0
 private void Control_TitleChanged(string title)
 {
     Title       = title;
     window.Text = title;
     TitleChanged?.Invoke(Title);
 }
Esempio n. 29
0
 /// <summary>
 /// Sets the title.
 /// </summary>
 /// <param name="args">The <see cref="TitleChangedEventArgs"/> instance containing the event data.</param>
 void IWebBrowserInternal.SetTitle(TitleChangedEventArgs args)
 {
     TitleChanged?.Invoke(this, args);
 }
Esempio n. 30
0
 internal protected virtual void OnTitleChanged(TitleChangedEventArgs e)
 {
     Title = e.Title;
     TitleChanged?.Invoke(this, e);
 }