Ejemplo n.º 1
0
 protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     _uiHelper.PerformInUiThread(() =>
         {
             Cursor cursor = CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false));
             _owner.Cursor = cursor;
         });
 }
Ejemplo n.º 2
0
        public unsafe static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            if (cursorInfo.Buffer == IntPtr.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(cursorInfo));
            }

            return(Cursor.Default);            // Not supported

            /*
             * CefSize size = cursorInfo.Size;
             *
             * var bufferSize = size.Width * size.Height * 4;
             * int ICON_HEADER_SIZE = sizeof(ICONDIR);
             * var stream = new MemoryStream(bufferSize);
             * {
             *      if (stream.Seek(ICON_HEADER_SIZE, SeekOrigin.Begin) != ICON_HEADER_SIZE)
             *      {
             *              stream.Seek(0, SeekOrigin.Begin);
             *              stream.Write(new byte[ICON_HEADER_SIZE], 0, ICON_HEADER_SIZE);
             *      }
             *      using (var image = new WriteableBitmap(new PixelSize(size.Width, size.Height), OffscreenGraphics.Dpi, PixelFormat.Bgra8888))
             *      {
             *              using (ILockedFramebuffer frameBuffer = image.Lock())
             *              {
             *                      System.Runtime.CompilerServices.Unsafe.CopyBlock((void*)frameBuffer.Address, (void*)cursorInfo.Buffer, (uint)bufferSize);
             *              }
             *              image.Save(stream); // Save in png format!!!
             *      }
             *      stream.Seek(0, SeekOrigin.Begin);
             * }
             *
             * CefPoint hotSpot = cursorInfo.Hotspot;
             *
             * var icon = new ICONDIR();
             * icon.IconType = 2;
             * icon.ImagesCount = 1;
             * icon.Width = (byte)size.Width;
             * icon.Height = (byte)size.Height;
             * icon.HotSpotX = (short)hotSpot.X;
             * icon.HotSpotY = (short)hotSpot.Y;
             * icon.BytesInRes = (int)stream.Length - ICON_HEADER_SIZE;
             * icon.ImageOffset = ICON_HEADER_SIZE;
             *
             * using (var iconHead = new UnmanagedMemoryStream(icon._data, ICON_HEADER_SIZE))
             * {
             *      iconHead.CopyTo(stream);
             *      stream.Seek(0, SeekOrigin.Begin);
             * }
             *
             * return new Cursor(stream);
             */
        }
Ejemplo n.º 3
0
        public unsafe static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            CefSize size = cursorInfo.Size;

            if (size.Width > 0 && size.Height > 0 && cursorInfo.Buffer != IntPtr.Zero)
            {
                try
                {
                    var bufferSize       = size.Width * size.Height * 4;
                    int ICON_HEADER_SIZE = sizeof(ICONDIR);
                    var stream           = new MemoryStream();
                    {
                        DpiScale dpi    = OffscreenGraphics.DpiScale;
                        var      source = BitmapSource.Create(size.Width, size.Height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Bgra32, null, cursorInfo.Buffer, bufferSize, size.Width << 2);
                        if (stream.Seek(ICON_HEADER_SIZE, SeekOrigin.Begin) != ICON_HEADER_SIZE)
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Write(new byte[ICON_HEADER_SIZE], 0, ICON_HEADER_SIZE);
                        }

                        var png = new PngBitmapEncoder();
                        png.Frames.Add(BitmapFrame.Create(source));
                        png.Save(stream);
                        stream.Seek(0, SeekOrigin.Begin);
                    }

                    CefPoint hotSpot = cursorInfo.Hotspot;

                    var icon = new ICONDIR();
                    icon.IconType    = 2;
                    icon.ImagesCount = 1;
                    icon.Width       = (byte)size.Width;
                    icon.Height      = (byte)size.Height;
                    icon.HotSpotX    = (short)hotSpot.X;
                    icon.HotSpotY    = (short)hotSpot.Y;
                    icon.BytesInRes  = (int)stream.Length - ICON_HEADER_SIZE;
                    icon.ImageOffset = ICON_HEADER_SIZE;

                    using (var iconHead = new UnmanagedMemoryStream(icon._data, ICON_HEADER_SIZE))
                    {
                        iconHead.CopyTo(stream);
                        stream.Seek(0, SeekOrigin.Begin);
                    }

                    return(new Cursor(stream));
                }
                catch (AccessViolationException) { throw; }
                catch { }
            }
            return(Cursors.Arrow);
        }
Ejemplo n.º 4
0
        public unsafe static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            CefSize size = cursorInfo.Size;

            if (size.Width > 0 && size.Height > 0 && cursorInfo.Buffer != IntPtr.Zero)
            {
                try
                {
                    CefPoint hotSpot = cursorInfo.Hotspot;
                    using (var bitmap = new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Premul, cursorInfo.Buffer,
                                                   new PixelSize(size.Width, size.Height), OffscreenGraphics.DpiScale.Dpi, size.Width * 4))
                    {
                        return(new Cursor(bitmap, new PixelPoint(hotSpot.X, hotSpot.Y)));
                    }
                }
                catch (AccessViolationException) { throw; }
                catch { }
            }
            return(Cursor.Default);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates new instance of the <see cref="Cursor"/> class.
        /// </summary>
        /// <param name="cursorInfo">The cursor information.</param>
        /// <returns>A new <see cref="Cursor"/> that this method creates.</returns>
        public static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            CefSize size       = cursorInfo.Size;
            Bitmap  bitmap     = null;
            IntPtr  iconHandle = IntPtr.Zero;

            try
            {
                if (size.Width > 0 && size.Height > 0 && cursorInfo.Buffer != IntPtr.Zero)
                {
                    bitmap     = new Bitmap(size.Width, size.Height, 4 * size.Width, PixelFormat.Format32bppArgb, cursorInfo.Buffer);
                    iconHandle = bitmap.GetHicon();
                    if (iconHandle != IntPtr.Zero && NativeMethods.GetIconInfo(iconHandle, out ICONINFO iconInfo))
                    {
                        iconInfo.Hotspot = cursorInfo.Hotspot;
                        iconInfo.IsIcon  = false;
                        IntPtr cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo);
                        if (cursorHandle == IntPtr.Zero)
                        {
                            return(Cursors.Default);
                        }

                        return(new CustomCursor(cursorHandle)._cursor);
                    }
                }
            }
            catch (AccessViolationException) { throw; }
            catch { }
            finally
            {
                if (iconHandle != IntPtr.Zero)
                {
                    NativeMethods.DestroyIcon(iconHandle);
                }
                bitmap?.Dispose();
            }
            return(Cursors.Default);
        }
Ejemplo n.º 6
0
        public static Cursor Create(ref CefCursorInfo cursorInfo)
        {
            if (cursorInfo.Buffer == IntPtr.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(cursorInfo));
            }

            CefSize size = cursorInfo.Size;

            using (var bitmap = new Bitmap(size.Width, size.Height, 4 * size.Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, cursorInfo.Buffer))
            {
                IntPtr iconHandle = bitmap.GetHicon();
                try
                {
                    if (NativeMethods.GetIconInfo(iconHandle, out ICONINFO iconInfo))
                    {
                        iconInfo.Hotspot = cursorInfo.Hotspot;
                        iconInfo.IsIcon  = false;
                        IntPtr cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo);
                        if (cursorHandle == IntPtr.Zero)
                        {
                            return(Cursors.Default);
                        }

                        return(new CustomCursor(cursorHandle)._cursor);
                    }
                    else
                    {
                        return(Cursors.Default);
                    }
                }
                finally
                {
                    NativeMethods.DestroyIcon(iconHandle);
                }
            }
        }
Ejemplo n.º 7
0
        protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
        {
            Cursor cursor;

            if (type == CefCursorType.Custom)
            {
                cursor = CustomCursor.Create(ref customCursorInfo);
            }
            else if (cursorHandle == IntPtr.Zero)
            {
                cursor = CustomCursor.None;
            }
            else
            {
                cursor = new Cursor(cursorHandle);
            }
            WebView.RaiseCefCursorChange(new CursorChangeEventArgs(cursor, type));
        }
 protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
 {
 }
Ejemplo n.º 9
0
 public unsafe static Cursor Create(ref CefCursorInfo cursorInfo)
 {
     return(Cursor.Default);
 }
 protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     _owner.InvokeIfRequired(() => _owner.HostWindowInternal.Cursor = new Cursor(cursorHandle));
 }
 internal protected virtual void OnCursorChange(CefBrowser browser, IntPtr cursor, CefCursorType type, CefCursorInfo customCursorInfo)
 {
 }
Ejemplo n.º 12
0
 protected internal unsafe override bool OnCursorChange(CefBrowser browser, IntPtr cursor, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     return(_implementation.OnCursorChange(browser, cursor, type, customCursorInfo));
 }
Ejemplo n.º 13
0
        /// <inheritdoc />
        protected override bool OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
        {
            var ea = new CursorChangeEventArgs(type != CefCursorType.Custom ? CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false)) : CustomCursor.Create(ref customCursorInfo), type);

            WebView.RaiseCefCursorChange(ea);
            return(ea.Handled);
        }
 /// <summary>
 /// Called when the browser&apos;s cursor has changed.
 /// </summary>
 /// <param name="browser">The browser.</param>
 /// <param name="cursor">The cursor handle.</param>
 /// <param name="type">The cursor type.</param>
 /// <param name="customCursorInfo">
 /// The custom cursor information (if <paramref name="type"/> is <see cref="CefCursorType.Custom"/>).
 /// </param>
 /// <returns>true if the cursor change was handled or false for default handling.</returns>
 internal protected virtual bool OnCursorChange(CefBrowser browser, IntPtr cursor, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     return(false);
 }
Ejemplo n.º 15
0
 public override void OnCursorChange(CefBrowser browser, IntPtr cursor, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     _implementation.OnCursorChange(browser, cursor, type, customCursorInfo);
 }
Ejemplo n.º 16
0
 protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     _uiHelper.PerformInUiThread(() =>
     {
         //Cursor cursor = CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false));
         //_owner.Cursor = cursor;
     });
 }
Ejemplo n.º 17
0
 protected override void OnCursorChange(CefBrowser browser,
                                        System.IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
 {
 }   // throw new NotImplementedException();
Ejemplo n.º 18
0
 protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo)
 {
     //WebView.RaiseCefCursorChange(
     //	new CursorChangeEventArgs(type != CefCursorType.Custom ? CursorInteropHelper.Create(cursorHandle) : CustomCursor.Create(ref customCursorInfo), type)
     //);
 }