예제 #1
0
        protected virtual void OnCurrentHwndSourceChanged(DependencyPropertyChangedEventArgs e)
        {
            Initialize();

            // Unregister the old keyboard input site.
            IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite;

            if (keyboardInputSite != null)
            {
                ((IKeyboardInputSink)this).KeyboardInputSite = null;
                keyboardInputSite.Unregister();
            }

            // Register the new keyboard input site with the containing
            // HwndSource.
            IKeyboardInputSink sink = CurrentHwndSource;

            if (sink != null)
            {
                ((IKeyboardInputSink)this).KeyboardInputSite = sink.RegisterKeyboardInputSink(this);
            }

            // Set the owner of the RedirectedWindow to our CurrentHwndSource.
            // This keeps the RedirectedWindow on top of the HwndSource.
            if (CurrentHwndSource != null)
            {
                HWND hwndSource = new HWND(CurrentHwndSource.Handle);
                HWND hwndRoot   = hwndSource; // User32NativeMethods.GetAncestor(hwndSource, GA.ROOT); // need to get the top-level window?
                NativeMethods.SetWindowLongPtr(
                    _redirectedWindow.Handle,
                    GWL.HWNDPARENT,
                    hwndRoot.DangerousGetHandle());
            }
        }
예제 #2
0
        protected virtual void UnregisterSourceKeyboardInputSink()
        {
            IKeyboardInputSink keyboardInputSink = this;

            if (keyboardInputSink.KeyboardInputSite != null)
            {
                keyboardInputSink.KeyboardInputSite.Unregister();
            }
        }
예제 #3
0
        protected virtual void RegisterSourceKeyboardInputSink(IKeyboardInputSink sourceKeyboardInputSink)
        {
            IKeyboardInputSink keyboardInputSink = this;

            if (sourceKeyboardInputSink != null)
            {
                keyboardInputSink.KeyboardInputSite = sourceKeyboardInputSink.RegisterKeyboardInputSink(this);
            }
        }
예제 #4
0
        private void OnSourceChanged(object sender, SourceChangedEventArgs e)
        {
            IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite;

            if (keyboardInputSite != null)
            {
                ((IKeyboardInputSink)this).KeyboardInputSite = null;
                keyboardInputSite.Unregister();
            }
            IKeyboardInputSink sink = source as IKeyboardInputSink;

            if (sink != null)
            {
                ((IKeyboardInputSink)this).KeyboardInputSite = sink.RegisterKeyboardInputSink(this);
            }

            source = e.NewSource;

            if (!isBuildingWindow)
            {
                isBuildingWindow = true;
                HwndSource parent = (HwndSource)e.NewSource;

                try
                {
                    if (hWnd.Handle == IntPtr.Zero)
                    {
                        hWnd = new HandleRef(this, ((INativeHandleContract)contract.Contract).GetHandle());

                        LayoutUpdated    += OnLayoutUpdated;
                        IsEnabledChanged += OnEnabledChanged;
                        IsVisibleChanged += OnVisibleChanged;

                        PostMessage(new HandleRef(null, Handle), 0x9005, parent.Handle, IntPtr.Zero);
                        PostMessage(new HandleRef(null, Handle), 0x9002, IntPtr.Zero, IntPtr.Zero);
                        InvalidateMeasure();
                    }
                }
                finally
                {
                    isBuildingWindow = false;
                }
            }
            else
            {
                Debug.Assert(false);
            }
        }
예제 #5
0
        private void OnSourceChanged(object sender, SourceChangedEventArgs e)
        {
            IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite;

            if (keyboardInputSite != null)
            {
                if (this._fTrusted.Value)
                {
                    new UIPermission(PermissionState.Unrestricted).Assert();
                }
                try
                {
                    ((IKeyboardInputSink)this).KeyboardInputSite = null;
                    keyboardInputSite.Unregister();
                }
                finally
                {
                    if (this._fTrusted.Value)
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            IKeyboardInputSink keyboardInputSink = PresentationSource.CriticalFromVisual(this, false) as IKeyboardInputSink;

            if (keyboardInputSink != null)
            {
                if (this._fTrusted.Value)
                {
                    new UIPermission(PermissionState.Unrestricted).Assert();
                }
                try
                {
                    ((IKeyboardInputSink)this).KeyboardInputSite = keyboardInputSink.RegisterKeyboardInputSink(this);
                }
                finally
                {
                    if (this._fTrusted.Value)
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                }
            }
            this.BuildOrReparentWindow();
        }
예제 #6
0
        public HwndSourceKeyboardInputSite(HwndSource source, IKeyboardInputSink sink)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }
            if (!(sink is UIElement))
            {
                throw new ArgumentException(SR.Get(SRID.KeyboardSinkMustBeAnElement), "sink");
            }

            _source = source;

            _sink = sink;
            _sink.KeyboardInputSite = this;

            _sinkElement = sink as UIElement;
        }
예제 #7
0
        public HwndSourceKeyboardInputSite(HwndSource source, IKeyboardInputSink sink)
        {
            if(source == null)
            {
                throw new ArgumentNullException("source");
            }
            if(sink == null)
            {
                throw new ArgumentNullException("sink");
            }
            if(!(sink is UIElement))
            {
                throw new ArgumentException(SR.Get(SRID.KeyboardSinkMustBeAnElement), "sink");
            }
            
            _source = source;

            _sink = sink;
            _sink.KeyboardInputSite = this;

            _sinkElement = sink as UIElement;
        }
예제 #8
0
 protected override bool ProcessDialogKey(Keys keyData)
 {
     if (base.ProcessDialogKey(keyData) || OverrideTabStop == false || HwndHost == null)
     {
         return(true);
     }
     if ((keyData & (Keys.Alt | Keys.Control)) == Keys.None)
     {
         Keys keyCode = (Keys)keyData & Keys.KeyCode;
         if (keyCode == Keys.Tab)
         {
             IKeyboardInputSink sink = HwndHost;
             if (sink == null || sink.KeyboardInputSite == null)
             {
                 return(false);
             }
             return(sink.KeyboardInputSite.OnNoMoreTabStops(
                        new TraversalRequest((keyData & Keys.Shift) == Keys.None ?
                                             FocusNavigationDirection.Next : FocusNavigationDirection.Previous)));
         }
     }
     return(false);
 }
예제 #9
0
파일: HwndHost.cs 프로젝트: z2516305651/wpf
        private void OnSourceChanged(object sender, SourceChangedEventArgs e)
        {
            // Remove ourselves as an IKeyboardInputSinks child of our previous
            // containing window.
            IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite;

            if (keyboardInputSite != null)
            {
                // Derived classes that implement IKeyboardInputSink should support setting it to null.
                ((IKeyboardInputSink)this).KeyboardInputSite = null;

                keyboardInputSite.Unregister();
            }

            // Add ourselves as an IKeyboardInputSinks child of our containing window.
            IKeyboardInputSink source = PresentationSource.CriticalFromVisual(this, false /* enable2DTo3DTransition */) as IKeyboardInputSink;

            if (source != null)
            {
                ((IKeyboardInputSink)this).KeyboardInputSite = source.RegisterKeyboardInputSink(this);
            }

            BuildOrReparentWindow();
        }
예제 #10
0
        protected IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
        {
            CheckDisposed(true);

            if (sink == null)
            {
                throw new ArgumentNullException("sink");
            }

            if (sink.KeyboardInputSite != null)
            {
                throw new ArgumentException(SR.Get(SRID.KeyboardSinkAlreadyOwned));
            }

            HwndSourceKeyboardInputSite site = new HwndSourceKeyboardInputSite(this, sink);

            if (_keyboardInputSinkChildren == null)
                _keyboardInputSinkChildren = new List<HwndSourceKeyboardInputSite>();
            _keyboardInputSinkChildren.Add(site);

            return site;
        }
 protected virtual new IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
 {
   return default(IKeyboardInputSite);
 }
 IKeyboardInputSite System.Windows.Interop.IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
   return default(IKeyboardInputSite);
 }
예제 #13
0
파일: HwndHost.cs 프로젝트: z2516305651/wpf
 IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     return(RegisterKeyboardInputSinkCore(sink));
 }
예제 #14
0
파일: HwndHost.cs 프로젝트: z2516305651/wpf
        // General security note on the implementation pattern of this interface. In Dev10 it was chosen
        // to expose the interface implementation for overriding to customers. We did so by keeping the
        // explicit interface implementations (that do have the property of being hidden from the public
        // contract, which limits IntelliSense on derived types like WebBrowser) while sticking protected
        // virtuals next to them. Those virtuals contain our base implementation, while the explicit
        // interface implementation methods do call trivially into the virtuals.
        //
        // This comment outlines the security rationale applied to those methods.
        //
        // <SecurityNote Name="IKeyboardInputSink_Implementation">
        //     The security attributes on the virtual methods within this region mirror the corresponding
        //     IKeyboardInputSink methods; customers can override those methods, so we insert a LinkDemand
        //     to encourage them to have a LinkDemand too (via FxCop).

        /// <summary>
        ///     Registers a IKeyboardInputSink with the HwndSource in order
        ///     to retreive a unique IKeyboardInputSite for it.
        /// </summary>
        protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
        {
            throw new InvalidOperationException(SR.Get(SRID.HwndHostDoesNotSupportChildKeyboardSinks));
        }
 protected virtual new IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
 {
     return(default(IKeyboardInputSite));
 }
 IKeyboardInputSite System.Windows.Interop.IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     return(default(IKeyboardInputSite));
 }
예제 #17
0
 IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     throw new NotSupportedException();
 }
 protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
 {
     throw new InvalidOperationException("RedirectedHwndHost does not support child keyboard sinks be default.");
 }
예제 #19
0
 public IKeyboardInputSite RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     throw new InvalidOperationException("HwndHostDoesNotSupportChildKeyboardSinks");
 }
예제 #20
0
        private async void wvMain_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
        {
            try
            {
                tbUrl.Text = wvMain.Source.AbsoluteUri;

                string title = wvMain.CoreWebView2.DocumentTitle;

                Global.MainWindow.Title = "ArtSoftWebBrowser2019 " + title;

                string url = wvMain.Source.AbsoluteUri;

                if (wvMain.Source.Host == "www.google.pl")
                {
                    string[] lpa = wvMain.Source.AbsoluteUri.Split(new char[] { '#' });
                    url = lpa[0];
                }

                Global.Link = Global.DataBase.Link.Where(l => l.Url == url).FirstOrDefault();

                if (Global.Link == null)
                {
                    Global.Link             = new Link();
                    Global.Link.Name        = title.Substring(0, Math.Min(title.Length, 50));
                    Global.Link.Url         = wvMain.Source.AbsoluteUri;
                    Global.Link.Type        = string.Empty;
                    Global.Link.Description = string.Empty;
                    Global.Link.Path        = string.Empty;
                    Global.Link.Added       = false;
                    Global.Link.Active      = false;
                    Global.Link.Loaded      = DateTime.Now;
                    Global.Link.Time        = 0;
                    Global.DataBase.Link.Add(Global.Link);
                }

                Global.Link.Opened = DateTime.Now;

                Global.DataBase.SaveChanges();

                Global.Info        = new Info();
                Global.Info.Opened = DateTime.Now;
                Global.Info.Ticked = DateTime.Now;
                Global.Info.Time   = 0;

                await wvMain.EnsureCoreWebView2Async(null);

                wvMain.CoreWebView2.AddHostObjectToScript("linkhandler", new LinkHandler());

                string script = "";

                script += "const lh = chrome.webview.hostObjects.linkhandler;";
                script += "var links = document.getElementsByTagName('a');";
                script += "for (var i = 0; i < links.length; i++)";
                script += "{";
                script += "   var link = links[i];";
                script += "   link.onmouseover = function(e){ lh.OnMouseOver(e.srcElement.href, e.screenY, e.screenX) };";
                script += "   link.onmouseout = function(){ lh.OnMouseOut() };";
                script += "}";

                await wvMain.ExecuteScriptAsync(script);

                string cs = GetStatusText(Global.Link);
                lblStatus.Content = cs;

                IKeyboardInputSink kis = Global.Browser.wvMain;
                kis.TabInto(new TraversalRequest(FocusNavigationDirection.First));

                Dispatcher.Invoke(delegate() { cbTime.IsChecked = true; });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
예제 #21
0
 protected override void RegisterSourceKeyboardInputSink(IKeyboardInputSink sourceKeyboardInputSink)
 {
 }
예제 #22
0
 protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
 {
     throw new InvalidOperationException("RedirectedHwndHost does not support child keyboard sinks be default.");
 }
 IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     return RegisterKeyboardInputSinkCore(sink);
 }
예제 #24
0
 protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink)
 {
     throw new InvalidOperationException(SR.Get(SRID.HwndHostDoesNotSupportChildKeyboardSinks));
 }
예제 #25
0
 IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     throw new NotSupportedException();
 }
예제 #26
0
 IKeyboardInputSite System.Windows.Interop.IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink)
 {
     throw new NotSupportedException();
 }