From: H.G. Muller Date: Fri, 12 Feb 2010 17:08:29 +0000 (+0100) Subject: Pop up ICS text menu with default item under mouse pointer X-Git-Tag: master-20100221~24 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b714edf2942a04d2f5f6f45c6bf6a6ad1acbc4aa;p=xboard.git Pop up ICS text menu with default item under mouse pointer The menu popup is migrated to the down-click (was up-click), so the up-click can select the item. Some trickery is needed to fool the menu into thinking that the mouse moved, so that a moveless up-down click in the ICS text field selects the default item (the upper-right one). Also allow dummy item in ICS text menu: The command "none" in the ICS text menu will now be treated as a grayed-out (disabled) entry, so it can be defined in the position underthe mouse pointer to prevent the up-click from doing anything, while keeping the menu open. Recommended for use with an entry of spaces. --- diff --git a/winboard/defaults.h b/winboard/defaults.h index c96d0cf..fa04694 100644 --- a/winboard/defaults.h +++ b/winboard/defaults.h @@ -238,7 +238,9 @@ chess.mds.mdh.se /icsport=5000\n\ Playe&rs,players,0,1\n\ &Games,games,0,1\n\ &Sought,sought,0,1\n\ -|&Tell (name),tell,1,0\n\ +| ,none,0,0\n\ +Open Chat &Box (name),chat,1,0\n\ +&Tell (name),tell,1,0\n\ M&essage (name),message,1,0\n\ -\n\ &Finger (name),finger,1,1\n\ diff --git a/winboard/wchat.c b/winboard/wchat.c index e762b19..eb5179f 100644 --- a/winboard/wchat.c +++ b/winboard/wchat.c @@ -256,11 +256,9 @@ void ChatPopUp(char *icsHandle) FARPROC lpProc; int i, partner = -1; - if(chatCount >= MAX_CHAT) return; - CheckMenuItem(GetMenu(hwndMain), IDM_NewChat, MF_CHECKED); for(i=0; iitem) { if (strcmp(e->item, "-") == 0) { AppendMenu(h, MF_SEPARATOR, 0, 0); - } else { + } else { // [HGM] re-written a bit to use only one AppendMenu call for both cases (| or no |) + int flags = MF_STRING, j = 0; if (e->item[0] == '|') { - AppendMenu(h, MF_STRING|MF_MENUBARBREAK, - IDM_CommandX + i, &e->item[1]); - } else { - AppendMenu(h, MF_STRING, IDM_CommandX + i, e->item); + flags |= MF_MENUBARBREAK; + j++; } + if(!strcmp(e->command, "none")) flags |= MF_GRAYED; // [HGM] chatclick: provide inactive dummy + AppendMenu(h, flags, IDM_CommandX + i, e->item + j); } e++; i++; @@ -6441,11 +6442,20 @@ ConsoleTextSubclass(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } return 0; } // [HGM] navigate: for Ctrl+R, flow into nex case (moved up here) to summon up menu - case WM_RBUTTONUP: - if (GetKeyState(VK_SHIFT) & ~1) { - SendDlgItemMessage(hwndConsole, OPT_ConsoleText, - WM_COMMAND, MAKEWPARAM(IDM_QuickPaste, 0), 0); - } else { + case WM_RBUTTONDOWN: + if (!(GetKeyState(VK_SHIFT) & ~1)) { + /* Move selection here if it was empty */ + POINT pt; + pt.x = LOWORD(lParam); + pt.y = HIWORD(lParam); + SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); + if (sel.cpMin == sel.cpMax) { + sel.cpMin = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&pt); /*doc is wrong*/ + sel.cpMax = sel.cpMin; + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); + } + SendMessage(hwnd, EM_HIDESELECTION, FALSE, FALSE); +{ // [HGM] chatclick: code moved here from WM_RBUTTONUP case, to have menu appear on down-click POINT pt; HMENU hmenu = LoadIcsTextMenu(icsTextMenuEntry); SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); @@ -6456,9 +6466,17 @@ ConsoleTextSubclass(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (!IsClipboardFormatAvailable(CF_TEXT)) { EnableMenuItem(hmenu, IDM_Paste, MF_BYCOMMAND|MF_GRAYED); } - pt.x = LOWORD(lParam); - pt.y = HIWORD(lParam); + pt.x = LOWORD(lParam)-30; // [HGM] chatclick: make menu pop up with pointer above upper-right item + pt.y = HIWORD(lParam)-10; // make it appear as if mouse moved there, so it will be selected on up-click + PostMessage(hwnd, WM_MOUSEMOVE, wParam, lParam+5); MenuPopup(hwnd, pt, hmenu, -1); +} + } + return 0; + case WM_RBUTTONUP: + if (GetKeyState(VK_SHIFT) & ~1) { + SendDlgItemMessage(hwndConsole, OPT_ConsoleText, + WM_COMMAND, MAKEWPARAM(IDM_QuickPaste, 0), 0); } return 0; case WM_PASTE: @@ -6467,21 +6485,6 @@ ConsoleTextSubclass(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) return SendMessage(hInput, message, wParam, lParam); case WM_MBUTTONDOWN: return SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDM_QuickPaste, 0), 0); - case WM_RBUTTONDOWN: - if (!(GetKeyState(VK_SHIFT) & ~1)) { - /* Move selection here if it was empty */ - POINT pt; - pt.x = LOWORD(lParam); - pt.y = HIWORD(lParam); - SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel); - if (sel.cpMin == sel.cpMax) { - sel.cpMin = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&pt); /*doc is wrong*/ - sel.cpMax = sel.cpMin; - SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); - } - SendMessage(hwnd, EM_HIDESELECTION, FALSE, FALSE); - } - return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDM_QuickPaste: