X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwchat.c;h=3be1e7f7d33d2bb1dd196b8191470c2a97d8c083;hb=HEAD;hp=e762b199c424b5277b9204158797c6d3029858be;hpb=31d464fc0f1de8577fd198a180ba26f8cd884ac2;p=xboard.git diff --git a/winboard/wchat.c b/winboard/wchat.c index e762b19..3be1e7f 100644 --- a/winboard/wchat.c +++ b/winboard/wchat.c @@ -3,7 +3,8 @@ * * Author: H.G.Muller (August 2009) * - * Copyright 2009, 2010 Free Software Foundation, Inc. + * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. * * ------------------------------------------------------------------------ * @@ -32,6 +33,7 @@ #include #include #include +#include #include "common.h" #include "frontend.h" @@ -41,8 +43,10 @@ #include "wsnap.h" int chatCount; +static int onTop; extern char chatPartner[MAX_CHAT][MSG_SIZ]; HANDLE chatHandle[MAX_CHAT]; +static WNDPROC chatInputWindowProc; void SendToICS P((char *s)); void ChatPopUp P((char *s)); @@ -52,12 +56,17 @@ void ChatPopDown(); extern int opponentKibitzes; /* Imports from winboard.c */ +VOID SaveInHistory(char *cmd); +char *PrevInHistory(char *cmd); +char *NextInHistory(); extern HWND ChatDialog; extern HINSTANCE hInst; -extern HWND hwndMain; +extern HWND hwndConsole; +extern char ics_handle[]; extern WindowPlacement wpChat[MAX_CHAT]; +extern WindowPlacement wpConsole; extern BoardSize boardSize; @@ -132,36 +141,109 @@ static void InsertIntoMemo( HANDLE hDlg, char * text ) SendMessage( hMemo, EM_SCROLLCARET, 0, 0); } +LRESULT CALLBACK +InterceptArrowKeys(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + char buf[MSG_SIZ]; + char *p; + CHARRANGE sel; + + switch (message) { + case WM_KEYDOWN: // cloned from ConsoleInputSubClass() + switch (wParam) { + case VK_UP: + GetWindowText(hwnd, buf, MSG_SIZ); + p = PrevInHistory(buf); + if (p != NULL) { + SetWindowText(hwnd, p); + sel.cpMin = 999999; + sel.cpMax = 999999; + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); + return 0; + } + break; + case VK_DOWN: + p = NextInHistory(); + if (p != NULL) { + SetWindowText(hwnd, p); + sel.cpMin = 999999; + sel.cpMax = 999999; + SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM)&sel); + return 0; + } + break; + } + } + return (*chatInputWindowProc)(hwnd, message, wParam, lParam); +} + // This seems pure front end LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { static SnapData sd; char buf[MSG_SIZ], mess[MSG_SIZ]; - int partner = -1, i; + int partner = -1, i, x, y; static BOOL filterHasFocus[MAX_CHAT]; + WORD wMask; + HWND hMemo; for(i=0; ipartner), chatPartner[i]); + } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 0 ); + for(i=0; icode == EN_LINK) + { + ENLINK *pLink = (ENLINK*)lParam; + if (pLink->msg == WM_LBUTTONUP) + { + TEXTRANGE tr; + + tr.chrg = pLink->chrg; + tr.lpstrText = malloc(1+tr.chrg.cpMax-tr.chrg.cpMin); + SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), EM_GETTEXTRANGE, 0, (LPARAM)&tr); + ShellExecute(NULL, "open", tr.lpstrText, NULL, NULL, SW_SHOW); + free(tr.lpstrText); + } + } + break; + case WM_COMMAND: - /* + /* [AS] If is pressed while editing the filter, it's better to apply the filter rather than selecting the current game. @@ -185,12 +267,9 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam switch (LOWORD(wParam)) { - case IDCANCEL: - chatHandle[partner] = 0; - chatPartner[partner][0] = 0; - ChatPopDown(); - EndDialog(hDlg, TRUE); - break; + case IDCANCEL: /* let Esc key switch focus back to console */ + SetFocus(GetDlgItem(hwndConsole, OPT_ConsoleInput)); + break; case IDC_Clear: SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), WM_SETTEXT, 0, (LPARAM) "" ); @@ -198,25 +277,48 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam case IDC_Change: GetDlgItemText(hDlg, IDC_ChatPartner, chatPartner[partner], MSG_SIZ); + for(i=0; i %s\n", mess); // echo only tells to handle, not channel + snprintf(buf, MSG_SIZ, "> %s\r\n", mess); // echo only tells to handle, not channel InsertIntoMemo(hDlg, buf); - sprintf(buf, "xtell %s %s\n", chatPartner[partner], mess); + snprintf(buf, MSG_SIZ, "xtell %s %s\n", chatPartner[partner], mess); } else - sprintf(buf, "tell %s %s\n", chatPartner[partner], mess); + snprintf(buf, MSG_SIZ, "tell %s %s\n", chatPartner[partner], mess); } SendToICS(buf); break; + case IDC_Focus1: + case IDC_Focus2: + case IDC_Focus3: + case IDC_Focus4: + i = LOWORD(wParam) - IDC_Focus1; + if(i >= partner) i++; + onTop = i; + SetFocus(GetDlgItem(hDlg, IDC_Send)); + if(chatHandle[i]) { + int j; + for(j=0; j= MAX_CHAT) return; + char buf[MSG_SIZ]; + static int first = 1; CheckMenuItem(GetMenu(hwndMain), IDM_NewChat, MF_CHECKED); for(i=0; i