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; }); }
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); */ }
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); }
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); }
/// <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); }
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); } } }
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) { }
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) { }
protected internal unsafe override bool OnCursorChange(CefBrowser browser, IntPtr cursor, CefCursorType type, CefCursorInfo customCursorInfo) { return(_implementation.OnCursorChange(browser, cursor, type, customCursorInfo)); }
/// <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'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); }
public override void OnCursorChange(CefBrowser browser, IntPtr cursor, CefCursorType type, CefCursorInfo customCursorInfo) { _implementation.OnCursorChange(browser, cursor, type, customCursorInfo); }
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; }); }
protected override void OnCursorChange(CefBrowser browser, System.IntPtr cursorHandle, CefCursorType type, CefCursorInfo customCursorInfo) { } // throw new NotImplementedException();
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) //); }