diff --git a/AngelLoader/CustomControls/RichTextBoxCustom.cs b/AngelLoader/CustomControls/RichTextBoxCustom.cs index 618265bbe..f637cad8b 100644 --- a/AngelLoader/CustomControls/RichTextBoxCustom.cs +++ b/AngelLoader/CustomControls/RichTextBoxCustom.cs @@ -321,12 +321,26 @@ private enum ScrollInfoMask [DllImport("user32.dll")] private static extern int GetWindowLong(IntPtr hWnd, int index); + [DllImport("user32.dll")] + private static extern IntPtr SetCursor(IntPtr hCursor); + + private const int WM_SETCURSOR = 0x20; + private static bool VerticalScrollBarVisible(Control ctl) { int style = GetWindowLong(ctl.Handle, -16); return (style & 0x200000) != 0; } + private bool CursorOverText(Control control, bool fullArea = false) + { + if (!control.Visible || !control.Enabled) return false; + var rpt = PointToClient(control.PointToScreen(new System.Drawing.Point(0, 0))); + var rcs = fullArea ? control.Size : control.ClientSize; + var ptc = PointToClient(Cursor.Position); + return ptc.X >= rpt.X && ptc.X < rpt.X + rcs.Width && ptc.Y >= rpt.Y && ptc.Y < rpt.Y + rcs.Height; + } + private static void BetterScroll(IntPtr handle, int pixels) { var si = GetCurrentScrollInfo(handle); @@ -375,6 +389,26 @@ private void InterceptMousewheel(ref Message m) } } + // Intercept mouse cursor in order to keep it from flickering + private void InterceptCursor(ref Message m) + { + if (!CursorOverText(this, false)) + { + if (Cursor != Cursors.Arrow) + { + Cursor = Cursors.Arrow; + } + } + else + { + if ((Cursor != Cursors.IBeam) && (Cursor != Cursors.Hand)) + { + Cursor = Cursors.IBeam; + } + } + SetCursor(Cursor.Handle); + } + protected override void WndProc(ref Message m) { switch ((uint)m.Msg) @@ -382,6 +416,13 @@ protected override void WndProc(ref Message m) case InteropMisc.WM_MOUSEWHEEL: InterceptMousewheel(ref m); break; + case InteropMisc.WM_MBUTTONDOWN: + break; + case InteropMisc.WM_MBUTTONDBLCLK: + break; + case WM_SETCURSOR: + InterceptCursor(ref m); + break; default: base.WndProc(ref m); break;