protected override void WndProc(ref Message m) { //if(m.Msg== Api.WM_PAINT) { // var p1 = APerf.Create(); // base.WndProc(ref m); // p1.NW('P'); // return; //} //var w = (AWnd)m.HWnd; //AOutput.Write(m); switch (m.Msg) { case Api.WM_SETFOCUS: if (!_noModelEnsureCurrentSelected) { Program.Model.EnsureCurrentSelected(); } break; case Api.WM_CHAR: { int c = (int)m.WParam; if (c < 32) { if (!(c == 9 || c == 10 || c == 13)) { return; } } else { if (CodeInfo.SciBeforeCharAdded(this, (char)c)) { return; } } } break; case Api.WM_KEYDOWN: if ((KKey)m.WParam == KKey.Insert) { return; } break; case Api.WM_RBUTTONDOWN: { //workaround for Scintilla bug: when right-clicked a margin, if caret or selection start is at that line, goes to the start of line POINT p = (AMath.LoShort(m.LParam), AMath.HiShort(m.LParam)); int margin = Z.MarginFromPoint(p, false); if (margin >= 0) { var selStart = Z.SelectionStart8; var(_, start, end) = Z.LineStartEndFromPos(false, Z.PosFromXY(false, p, false)); if (selStart >= start && selStart <= end) { return; } //do vice versa if the end of non-empty selection is at the start of the right-clicked line, to avoid comment/uncomment wrong lines if (margin == c_marginLineNumbers || margin == c_marginMarkers) { if (Z.SelectionEnd8 == start) { Z.GoToPos(false, start); //clear selection above start } } } } break; case Api.WM_CONTEXTMENU: { bool kbd = (int)m.LParam == -1; int margin = kbd ? -1 : Z.MarginFromPoint((AMath.LoShort(m.LParam), AMath.HiShort(m.LParam)), true); switch (margin) { case -1: Strips.ddEdit.ZShowAsContextMenu(kbd); break; case c_marginLineNumbers: case c_marginMarkers: ZCommentLines(null); break; //case c_marginFold: // break; } } return; } base.WndProc(ref m); switch (m.Msg) { //case Api.WM_MOUSEMOVE: // CodeInfo.SciMouseMoved(this, AMath.LoShort(m.LParam), AMath.HiShort(m.LParam)); // break; case Api.WM_KILLFOCUS: CodeInfo.SciKillFocus(this); break; case Api.WM_LBUTTONUP: if (ModifierKeys == Keys.Control) { CiGoTo.GoToSymbolFromPos(onCtrlClick: true); } break; } }
bool _WndProc(wnd w, int msg, nint wparam, nint lparam, ref nint lresult) { switch (msg) { case Api.WM_SETFOCUS: if (!_noModelEnsureCurrentSelected) { App.Model.EnsureCurrentSelected(); } break; case Api.WM_CHAR: { int c = (int)wparam; if (c < 32) { if (c is not(9 or 10 or 13)) { return(true); } } else { if (CodeInfo.SciBeforeCharAdded(this, (char)c)) { return(true); } } } break; case Api.WM_MBUTTONDOWN: Api.SetFocus(w); return(true); case Api.WM_RBUTTONDOWN: { //workaround for Scintilla bug: when right-clicked a margin, if caret or selection start is at that line, goes to the start of line POINT p = Math2.NintToPOINT(lparam); int margin = zMarginFromPoint(p, false); if (margin >= 0) { var selStart = zSelectionStart8; var(_, start, end) = zLineStartEndFromPos(false, zPosFromXY(false, p, false)); if (selStart >= start && selStart <= end) { return(true); } //do vice versa if the end of non-empty selection is at the start of the right-clicked line, to avoid comment/uncomment wrong lines if (margin == c_marginLineNumbers || margin == c_marginMarkers) { if (zSelectionEnd8 == start) { zGoToPos(false, start); //clear selection above start } } } } break; case Api.WM_CONTEXTMENU: { bool kbd = (int)lparam == -1; int margin = kbd ? -1 : zMarginFromPoint(Math2.NintToPOINT(lparam), true); switch (margin) { case -1: var m = new KWpfMenu(); App.Commands[nameof(Menus.Edit)].CopyToMenu(m); m.Show(this, byCaret: kbd); break; case c_marginLineNumbers or c_marginMarkers or c_marginImages or c_marginChanges: ModifyCode.CommentLines(null, notSlashStar: true); break; case c_marginFold: int fold = popupMenu.showSimple("Folding: hide all|Folding: show all", owner: Hwnd) - 1; //note: no "toggle", it's not useful if (fold >= 0) { Call(SCI_FOLDALL, fold); } break; } return(true); } //case Api.WM_PAINT: // _Paint(false); // break; //case Api.WM_PAINT: { // using var p1 = perf.local(); // Call(msg, wparam, lparam); // return true; // } } //Call(msg, wparam, lparam); //in winforms version this was after base.WndProc. Now in hook cannot do it, therefore using async. //SHOULDDO: superclass and use normal wndproc instead of hook. Now possible various anomalies because of async. switch (msg) { //case Api.WM_MOUSEMOVE: // CodeInfo.SciMouseMoved(this, Math2.LoShort(m.LParam), Math2.HiShort(m.LParam)); // break; case Api.WM_KILLFOCUS: //Dispatcher.InvokeAsync(() => CodeInfo.SciKillFocus(this));//no, dangerous CodeInfo.SciKillFocus(this); break; //case Api.WM_LBUTTONUP: // //rejected. Sometimes I accidentally Ctrl+click and then wonder why it shows eg the github search dialog. // if (Keyboard.Modifiers == ModifierKeys.Control && !zIsSelection) { // Dispatcher.InvokeAsync(() => CiGoTo.GoToSymbolFromPos()); // } // break; } return(false); }