Fix changing of float setting by generic popup
[xboard.git] / xoptions.c
index 6fe3822..1d51738 100644 (file)
@@ -624,6 +624,7 @@ int values[MAX_OPTIONS];
 ChessProgramState *currentCps;
 static Option *currentOption;
 extern Widget shells[];
+static Boolean browserUp;
 
 void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b)
 {
@@ -659,6 +660,7 @@ void SpinCallback(w, client_data, call_data)
        XtSetArg(args[0], XtNstring, &q);
        XtGetValues(currentOption[data].handle, args, 1);
        for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
+       browserUp = True;
        if(XsraSelFile(shells[0], currentOption[data].name, NULL, NULL, "", "", r,
                                  currentOption[data].type == PathName ? "p" : "f", NULL, &p)) {
                int len = strlen(p);
@@ -666,6 +668,7 @@ void SpinCallback(w, client_data, call_data)
                XtSetArg(args[0], XtNstring, p);
                XtSetValues(currentOption[data].handle, args, 1);
        }
+       browserUp = False;
        SetFocus(currentOption[data].handle, shells[0], (XEvent*) NULL, False);
        return;
     } else
@@ -785,6 +788,7 @@ void GenericPopDown(w, event, prms, nprms)
      Cardinal *nprms;
 {
     int n;
+    if(browserUp) return; // prevent closing dialog when it has an open file-browse daughter
     PopDown(prms[0][0] - '0');
 }
 
@@ -1233,13 +1237,14 @@ void GenericReadout()
                    sscanf(val, "%f", &x);
                    if(x > currentOption[i].max) x = currentOption[i].max;
                    if(x < currentOption[i].min) x = currentOption[i].min;
-                   if(currentOption[i].value != x) {
+                   if(currentOption[i].type == Fractional)
+                       *(float*) currentOption[i].target = x; // engines never have float options!
+                   else if(currentOption[i].value != x) {
                        currentOption[i].value = x;
-                       if(currentCps) { // engines never have float options, so no decimals!
+                       if(currentCps) {
                            snprintf(buf, MSG_SIZ,  "option %s=%.0f\n", currentOption[i].name, x);
                            SendToProgram(buf, currentCps);
-                       } else if(currentOption[i].type == Spin) *(int*) currentOption[i].target = x;
-                       else *(float*) currentOption[i].target = x;
+                       } else *(int*) currentOption[i].target = x;
                    }
                    break;
                case CheckBox:
@@ -1926,70 +1931,27 @@ void TypeInProc(w, event, prms, nprms)
      String *prms;
      Cardinal *nprms;
 {
-    Widget edit;
-    int j, fromX, fromY, toX, toY;
-    Arg args[16];
+    Arg args[2];
     String val;
-    char *move, promoChar;
-    ChessMove moveType;
 
-    if(prms[0][0] == '0') PopDown(0); // escape hit
-    edit = boxOptions[0].handle;
-    j = 0;
-    XtSetArg(args[j], XtNstring, &val); j++;
-    XtGetValues(edit, args, j);
-      move = val;
-      { int n; Board board;\r
-       // [HGM] FENedit\r
-       if(gameMode == EditPosition && ParseFEN(board, &n, move) ) {\r
-               EditPositionPasteFEN(move);\r
-               PopDown(0);\r
-               return;\r
-       }\r
-       // [HGM] movenum: allow move number to be typed in any mode\r
-       if(sscanf(move, "%d", &n) == 1 && n != 0 ) {\r
-         ToNrEvent(2*n-1);\r
-         PopDown(0);\r
-         return;\r
-       }\r
-      }\r
-      if (gameMode != EditGame && currentMove != forwardMostMove && \r
-       gameMode != Training) {\r
-       DisplayMoveError(_("Displayed move is not current"));\r
-      } else {\r
-       int ok = ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, \r
-         &moveType, &fromX, &fromY, &toX, &toY, &promoChar);\r
-       if(!ok && move[0] >= 'a') { move[0] += 'A' - 'a'; ok = 2; } // [HGM] try also capitalized\r
-       if (ok==1 || ok && ParseOneMove(move, gameMode == EditPosition ? blackPlaysFirst : currentMove, \r
-         &moveType, &fromX, &fromY, &toX, &toY, &promoChar)) {\r
-         UserMoveEvent(fromX, fromY, toX, toY, promoChar);     \r
-       } else {\r
-         DisplayMoveError(_("Could not parse move"));\r
-       }\r
-      }\r
-      PopDown(0);\r
+    if(prms[0][0] == '1') {
+       XtSetArg(args[0], XtNstring, &val);
+       XtGetValues(boxOptions[0].handle, args, 1);
+       TypeInDoneEvent((char*)val);
+    }
+    PopDown(0);\r
 }
 
 char moveTypeInTranslations[] =
     "<Key>Return: TypeInProc(1) \n"
     "<Key>Escape: TypeInProc(0) \n";
 
-void MoveTypeInPopup(char firstchar)
+void PopUpMoveDialog(char firstchar)
 {
     static char buf[2];
-    if ((gameMode == BeginningOfGame && !appData.icsActive) || \r
-        gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack ||\r
-       gameMode == AnalyzeMode || gameMode == EditGame || \r
-       gameMode == EditPosition || gameMode == IcsExamining ||\r
-       gameMode == IcsPlayingWhite || gameMode == IcsPlayingBlack ||\r
-       isdigit(firstchar) && // [HGM] movenum: allow typing in of move nr in 'passive' modes\r
-               ( gameMode == AnalyzeFile || gameMode == PlayFromGameFile ||\r
-                 gameMode == IcsObserving || gameMode == TwoMachinesPlay    ) ||\r
-       gameMode == Training) {\r
-           buf[0]= firstchar; icsText = buf;
-           if(GenericPopUp(boxOptions, _("Type a move"), 0))
-               XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(moveTypeInTranslations));
-       }
+    buf[0] = firstchar; icsText = buf;
+    if(GenericPopUp(boxOptions, _("Type a move"), 0))
+       XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(moveTypeInTranslations));
 }
 
 void MoveTypeInProc(Widget widget, caddr_t unused, XEvent *event)
@@ -2001,9 +1963,8 @@ void MoveTypeInProc(Widget widget, caddr_t unused, XEvent *event)
     XQueryKeymap(xDisplay,keys);
     metaL = XKeysymToKeycode(xDisplay, XK_Meta_L);
     metaR = XKeysymToKeycode(xDisplay, XK_Meta_R);
-//{int i; for(i=0;i<32;i++)printf("%02x",keys[i]);printf("\n");}
     if ( n == 1 && *buf > 32 && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7))) // printable, no alt
-       MoveTypeInPopup(*buf);
+       PopUpMoveDialog(*buf);
 
 }