Allow engine to force popup of its settings dialog
[xboard.git] / dialogs.c
index 36f9abd..3f445bb 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1,7 +1,7 @@
 /*
  * dialogs.c -- platform-independent code for dialogs of XBoard
  *
- * Copyright 2000, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+ * Copyright 2000, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -93,11 +93,13 @@ int
 SetCurrentComboSelection (Option *opt)
 {
     int j;
+    if(currentCps) ; else
     if(!opt->textValue) opt->value = *(int*)opt->target; /* numeric */else {
        for(j=0; opt->choice[j]; j++) // look up actual value in list of possible values, to get selection nr
            if(*(char**)opt->target && !strcmp(*(char**)opt->target, ((char**)opt->textValue)[j])) break;
        opt->value = j + (opt->choice[j] == NULL);
     }
+    SetComboChoice(opt, opt->value);
     return opt->value;
 }
 
@@ -331,8 +333,10 @@ UpgradeParticipant ()
 static void
 PseudoOK ()
 {
+    if(matchMode) return;
     GenericReadout(matchOptions, -2); // read all, but suppress calling of MatchOK
     ASSIGN(appData.participants, engineName);
+    ASSIGN(appData.tourneyFile, tfName);
     PopDown(MasterDlg); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning
 }
 
@@ -1458,6 +1462,22 @@ SecondSettingsProc ()
    SettingsPopUp(&second);
 }
 
+void
+RefreshSettingsDialog (ChessProgramState *cps, int val)
+{
+   if(val == 1) { // option values changed
+      if(shellUp[TransientDlg] && cps == currentCps) {
+         GenericUpdate(cps->option, -1); // normally update values when dialog is up
+      }
+      return; // and be done
+   }
+   if(val == 2) { // option list changed
+      if(!shellUp[TransientDlg] || cps != currentCps) return; // our dialog is not up, so nothing to do
+   }
+   PopDown(TransientDlg); // make sure any other dialog closes first
+   SettingsPopUp(cps);    // and popup new one
+}
+
 //----------------------------------------------- Load Engine --------------------------------------
 
 char *engineDir, *engineLine, *nickName, *params;
@@ -1669,6 +1689,10 @@ SetTcType (int n)
 void
 TimeControlProc ()
 {
+   if(gameMode != BeginningOfGame) {
+       DisplayError(_("Changing time control during a game is not implemented"), 0);
+       return;
+   }
    tmpMoves = appData.movesPerSession;
    tmpInc = appData.timeIncrement; if(tmpInc < 0) tmpInc = 0;
    tmpOdds1 = tmpOdds2 = 1; tcType = 0;
@@ -1771,7 +1795,7 @@ PromotionPopUp (char choice)
 { // choice depends on variant: prepare dialog acordingly
   count = 8;
   SetPromo(_("Cancel"), --count, -1); // Beware: GenericPopUp cannot handle user buttons named "cancel" (lowe case)!
-  if(choice != '+') {
+  if(choice != '+' && !IS_SHOGI(gameInfo.variant)) {
     if (!appData.testLegality || gameInfo.variant == VariantSuicide ||
         gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) ||
         gameInfo.variant == VariantGiveaway) {
@@ -1900,6 +1924,9 @@ IcsHist (int n, Option *opt, DialogClass dlg)
 
     if(opt != &chatOptions[CHAT_IN] && !(opt == &chatOptions[CHAT_PARTNER] && n == 33)) return 0;
     switch(n) {
+      case 5:
+       if(!hidden) ClearChat();
+       break;
       case 8:
        if(!hidden) PaneSwitch();
        break;
@@ -1920,7 +1947,7 @@ IcsHist (int n, Option *opt, DialogClass dlg)
         while(!dirty[chat = (chat + 1)%MAX_CHAT]) if(chat == start) break;
        if(!dirty[chat])
         while(!chatPartner[chat = (chat + 1)%MAX_CHAT][0]) if(chat == start) break;
-       if(chat == start && hidden) chat = 0; // if all unused, start left
+       if(!chatPartner[chat][0]) break; // if all unused, ignore
         ChatSwitch(chat + 1);
        break;
       case 1:
@@ -1941,6 +1968,7 @@ OutputChatMessage (int partner, char *mess)
     char *p = texts[partner];
     int len = strlen(mess) + 1;
 
+    if(!DialogExists(ChatDlg)) return;
     if(p) len += strlen(p);
     texts[partner] = (char*) malloc(len);
     snprintf(texts[partner], len, "%s%s", p ? p : "", mess);
@@ -1959,11 +1987,12 @@ ChatOK (int n)
 {   // can only be called through <Enter> in chat-partner text-edit, as there is no OK button
     char buf[MSG_SIZ];
 
-    if(!hidden && (!partner || strcmp(partner, chatPartner[activePartner]))) {
+    if(!hidden && (!partner || strcmp(partner, chatPartner[activePartner]) || !*partner)) {
        safeStrCpy(chatPartner[activePartner], partner, MSG_SIZ);
        SetWidgetText(&chatOptions[CHAT_OUT], "", -1); // clear text if we alter partner
        SetWidgetText(&chatOptions[CHAT_IN], "", ChatDlg); // clear text if we alter partner
        SetWidgetLabel(&chatOptions[activePartner+1], chatPartner[activePartner][0] ? chatPartner[activePartner] : _("New Chat"));
+       if(!*partner) PaneSwitch();
        HardSetFocus(&chatOptions[CHAT_IN], 0);
     }
     if(line[0] || hidden) { // something was typed (for ICS commands we also allow empty line!)
@@ -1976,6 +2005,10 @@ ChatOK (int n)
              snprintf(buf, MSG_SIZ, "whisper %s\n", line); // WHISPER box uses "whisper" to send
        else if(!strcmp("shouts", chatPartner[activePartner]))
              snprintf(buf, MSG_SIZ, "shout %s\n", line); // SHOUT box uses "shout" to send
+       else if(!strcmp("c-shouts", chatPartner[activePartner]))
+             snprintf(buf, MSG_SIZ, "cshout %s\n", line); // C-SHOUT box uses "cshout" to send
+       else if(!strcmp("kibitzes", chatPartner[activePartner]))
+             snprintf(buf, MSG_SIZ, "kibitz %s\n", line); // KIBITZ box uses "kibitz" to send
        else {
            if(!atoi(chatPartner[activePartner])) {
                snprintf(buf, MSG_SIZ, "> %s\n", line); // echo only tells to handle, not channel
@@ -2253,8 +2286,8 @@ ErrorPopUp (char *title, char *label, int modal)
 {
     errorUp = True;
     errorOptions[1].name = label;
-    if(dialogError = shellUp[TransientDlg])
-       GenericPopUp(errorOptions+1, title, FatalDlg, TransientDlg, MODAL, 0); // pop up as daughter of the transient dialog
+    if(dialogError = shellUp[MasterDlg])
+       GenericPopUp(errorOptions+1, title, FatalDlg, MasterDlg, MODAL, 0); // pop up as daughter of the transient dialog
     else
        GenericPopUp(errorOptions+modal, title, modal ? FatalDlg: ErrorDlg, BoardWindow, modal, 0); // kludge: option start address indicates modality
 }