X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwchat.c;h=3be1e7f7d33d2bb1dd196b8191470c2a97d8c083;hb=HEAD;hp=48d555a122d58944d4da4fc87959c52b5f157131;hpb=6256f7e127a42d71c5e99a0bf70eee0a599c5839;p=xboard.git diff --git a/winboard/wchat.c b/winboard/wchat.c index 48d555a..3be1e7f 100644 --- a/winboard/wchat.c +++ b/winboard/wchat.c @@ -3,6 +3,9 @@ * * Author: H.G.Muller (August 2009) * + * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. + * * ------------------------------------------------------------------------ * * GNU XBoard is free software: you can redistribute it and/or modify @@ -30,6 +33,7 @@ #include #include #include +#include #include "common.h" #include "frontend.h" @@ -39,23 +43,30 @@ #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(); +void ChatPopUp P((char *s)); void ChatPopDown(); /* Imports from backend.c */ 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; @@ -130,31 +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. @@ -178,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) "" ); @@ -191,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; + int i, partner = -1; + char buf[MSG_SIZ]; + static int first = 1; CheckMenuItem(GetMenu(hwndMain), IDM_NewChat, MF_CHECKED); + for(i=0; i