Fix Xaw Chat Console
[xboard.git] / dialogs.c
index a2cd3c5..8dbcf04 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1707,18 +1707,20 @@ PromotionPopUp (char choice)
 //---------------------------- Chat Windows ----------------------------------------------
 
 static char *line, *memo, *chatMemo, *partner, *texts[MAX_CHAT], dirty[MAX_CHAT], *inputs[MAX_CHAT], *icsLine, *tmpLine;
-static int activePartner, hidden = 1;
+static int activePartner;
+int hidden = 1;
 
 void ChatSwitch P((int n));
 int  ChatOK P((int n));
 
 #define CHAT_ICS     6
 #define CHAT_PARTNER 8
-#define CHAT_OUT    10
-#define CHAT_PANE   11
-#define CHAT_IN     12
+#define CHAT_OUT    11
+#define CHAT_PANE   12
+#define CHAT_IN     13
 
 void PaneSwitch P((void));
+void ClearChat P((void));
 
 WindowPlacement wpTextMenu;
 
@@ -1758,6 +1760,7 @@ Option chatOptions[] = {
 { 250, T_VSCRL | T_FILL | T_WRAP | T_TOP,    510, NULL, (void*) &memo, NULL, (void*) &ContextMenu, TextBox, "" },
 {  0,  0,   0, NULL, NULL, "", NULL, Break , "" },
 { 0,   T_TOP,    100, NULL, (void*) &partner, NULL, NULL, TextBox, N_("Chat partner:") },
+{  0, SAME_ROW, 0, NULL, (void*) &ClearChat,  NULL, NULL, Button, N_("End Chat") },
 {  0, SAME_ROW, 0, NULL, (void*) &PaneSwitch, NULL, NULL, Button, N_("Hide") },
 { 250, T_VSCRL | T_FILL | T_WRAP | T_TOP,    510, NULL, (void*) &chatMemo, NULL, (void*) &ContextMenu, TextBox, "" },
 {  0,  0,   0, NULL, NULL, "", NULL, Break , "" },
@@ -1796,6 +1799,9 @@ IcsHist (int n, Option *opt, DialogClass dlg)
        if(hidden) BoardToTop();
        else PaneSwitch();
        break;
+      case 15:
+       NewChat(lastTalker);
+       break;
       case 14:
        for(chat=0; chat < MAX_CHAT; chat++) if(!chatPartner[chat][0]) break;
        if(chat < MAX_CHAT) ChatSwitch(chat + 1);
@@ -1856,7 +1862,7 @@ ChatOK (int n)
        // from here on it could be back-end
        if(line[strlen(line)-1] == '\n') line[strlen(line)-1] = NULLCHAR;
        SaveInHistory(line);
-       if(hidden) snprintf(buf, MSG_SIZ, "%s\n", line); else // command for ICS
+       if(hidden || !*chatPartner[activePartner]) snprintf(buf, MSG_SIZ, "%s\n", line); else // command for ICS
        if(!strcmp("whispers", chatPartner[activePartner]))
              snprintf(buf, MSG_SIZ, "whisper %s\n", line); // WHISPER box uses "whisper" to send
        else if(!strcmp("shouts", chatPartner[activePartner]))
@@ -1930,6 +1936,19 @@ PaneSwitch ()
 //    SetInsertPos(&chatOptions[CHAT_IN], strlen(icsLine));
 }
 
+void
+ClearChat ()
+{   // clear the chat to make it free for other use
+    chatPartner[activePartner][0] = NULLCHAR;
+    ASSIGN(texts[activePartner], "");
+    ASSIGN(inputs[activePartner], "");
+    SetWidgetText(&chatOptions[CHAT_PARTNER], "", ChatDlg);
+    SetWidgetText(&chatOptions[CHAT_OUT], "", ChatDlg);
+    SetWidgetText(&chatOptions[CHAT_IN], "", ChatDlg);
+    SetWidgetLabel(&chatOptions[activePartner+1], _("New Chat"));
+    HardSetFocus(&chatOptions[CHAT_PARTNER], 0);
+}
+
 static void
 NewChat (char *name)
 {   // open a chat on program request. If no empty one available, use last
@@ -1954,7 +1973,7 @@ ChatProc ()
     if(GenericPopUp(chatOptions, _("ICS Interaction"), ChatDlg, BoardWindow, NONMODAL, appData.topLevel))
        AddHandler(&chatOptions[CHAT_PARTNER], ChatDlg, 2), AddHandler(&chatOptions[CHAT_IN], ChatDlg, 2); // treats return as OK
     Show(&chatOptions[CHAT_PANE], hidden = 1); // hide
-    HardSetFocus(&chatOptions[CHAT_IN], 0);
+//    HardSetFocus(&chatOptions[CHAT_IN], 0);
     MarkMenu("View.OpenChatWindow", ChatDlg);
     CursorAtEnd(&chatOptions[CHAT_IN]);
 }