Allow escape sequences in telluser(error) messages
[xboard.git] / winboard / wchat.c
index 3b90b2c..30b6aa5 100644 (file)
@@ -61,7 +61,7 @@ char *NextInHistory();
 extern HWND ChatDialog;\r
 \r
 extern HINSTANCE hInst;\r
-extern HWND hwndMain;\r
+extern HWND hwndConsole;\r
 \r
 extern WindowPlacement wpChat[MAX_CHAT];\r
 extern WindowPlacement wpConsole;\r
@@ -180,7 +180,7 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
 {\r
     static SnapData sd;\r
     char buf[MSG_SIZ], mess[MSG_SIZ];\r
-    int partner = -1, i;\r
+    int partner = -1, i, x, y;\r
     static BOOL filterHasFocus[MAX_CHAT];\r
     WORD wMask;\r
     HWND hMemo;\r
@@ -195,18 +195,21 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
                sprintf(buf, "Chat Window %s", first.tidy);\r
                SetWindowText(hDlg, buf);\r
         }\r
-       for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) {\r
+       for(i=0; i<MAX_CHAT; i++) if(chatHandle[i]) {\r
+           if(i == partner) continue;\r
            // set our button in other open chats\r
            SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]);\r
            EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 1 );\r
            // and buttons for other chats in ours\r
            SetDlgItemText(hDlg, IDC_Focus1+i-(i>partner), chatPartner[i]);\r
-       } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 1 );\r
+       } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 0 );\r
        for(i=0; i<MAX_CHAT-1; i++) { Button_SetStyle(GetDlgItem(hDlg, IDC_Focus1+i), BS_PUSHBUTTON|BS_LEFT, TRUE); }\r
-        SetWindowPos(hDlg, NULL, wpConsole.x, wpConsole.y, 0, 0, SWP_NOZORDER|SWP_NOSIZE);\r
+        x = wpConsole.x; y = wpConsole.y; EnsureOnScreen(&x, &y, 0, 0);\r
+        SetWindowPos(hDlg, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE);\r
        SendMessage( GetDlgItem(hDlg, IDC_ChatPartner), // [HGM] clickbox: initialize with requested handle\r
                        WM_SETTEXT, 0, (LPARAM) chatPartner[partner] );\r
        filterHasFocus[partner] = TRUE;\r
+       onTop = partner; // a newly opened box becomes top one\r
        if(chatPartner[partner][0]) {\r
            filterHasFocus[partner] = FALSE;\r
            SetFocus( GetDlgItem(hDlg, OPT_ChatInput) );\r
@@ -261,12 +264,9 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
 \r
         switch (LOWORD(wParam)) {\r
 \r
-       case IDCANCEL:\r
-           chatHandle[partner] = 0;\r
-           chatPartner[partner][0] = 0;\r
-            ChatPopDown();\r
-           EndDialog(hDlg, TRUE);\r
-            break;\r
+       case IDCANCEL: /* let Esc key switch focus back to console */\r
+           SetFocus(GetDlgItem(hwndConsole, OPT_ConsoleInput));\r
+           break;\r
 \r
        case IDC_Clear:\r
            SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), WM_SETTEXT, 0, (LPARAM) "" );\r
@@ -285,8 +285,10 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
            SetDlgItemText(hDlg, OPT_ChatInput, "");\r
            // from here on it could be back-end\r
            SaveInHistory(mess);\r
-           if(!strcmp("WHISPER", chatPartner[partner]))\r
+           if(!strcmp("whispers", chatPartner[partner]))\r
                sprintf(buf, "whisper %s\n", mess); // WHISPER box uses "whisper" to send\r
+           else if(!strcmp("shouts", chatPartner[partner]))\r
+               sprintf(buf, "shout %s\n", mess); // SHOUT box uses "shout" to send\r
            else {\r
                if(!atoi(chatPartner[partner])) {\r
                    sprintf(buf, "> %s\r\n", mess); // echo only tells to handle, not channel\r
@@ -369,7 +371,7 @@ void ChatPopUp(char *icsHandle)
     lpProc = MakeProcInstance( (FARPROC) ChatProc, hInst );\r
 \r
     /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */\r
-    CreateDialog( hInst, MAKEINTRESOURCE(DLG_Chat), hwndMain, (DLGPROC)lpProc );\r
+    CreateDialog( hInst, MAKEINTRESOURCE(DLG_Chat), hwndConsole, (DLGPROC)lpProc );\r
 \r
     FreeProcInstance(lpProc);\r
 \r