Some refactoring in xoptions.c to separate out front-end
[xboard.git] / xoptions.c
index fd61145..c3878a0 100644 (file)
@@ -104,132 +104,6 @@ void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b)
     previous = w;
 }
 
-//--------------------------- New Shuffle Game --------------------------------------------
-int shuffleUp;
-Widget shuffleShell;
-
-void ShufflePopDown()
-{
-    if (!shuffleUp) return;
-    XtPopdown(shuffleShell);
-    XtDestroyWidget(shuffleShell);
-    shuffleUp = False;
-    ModeHighlight();
-}
-
-void ShuffleCallback(w, client_data, call_data)
-     Widget w;
-     XtPointer client_data, call_data;
-{
-    String name;
-    Widget w2;
-    Arg args[16];
-    char buf[MSG_SIZ];
-
-    XtSetArg(args[0], XtNlabel, &name);
-    XtGetValues(w, args, 1);
-
-    if (strcmp(name, _("cancel")) == 0) {
-        ShufflePopDown();
-        return;
-    }
-    if (strcmp(name, _("off")) == 0) {
-        ShufflePopDown();
-       shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it!
-       ResetGameEvent();
-        return;
-    }
-    if (strcmp(name, _("random")) == 0) {
-      snprintf(buf, MSG_SIZ,  "%d", rand());
-       XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
-       XtSetValues(XtParent(w), args, 1);
-        return;
-    }
-    if (strcmp(name, _("ok")) == 0) {
-       int nr; String name;
-        name = XawDialogGetValueString(w2 = XtParent(w));
-       if(sscanf(name ,"%d",&nr) != 1) {
-         snprintf(buf, MSG_SIZ,  "%d", appData.defaultFrcPosition);
-           XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value
-           XtSetValues(w2, args, 1);
-           return;
-       }
-       appData.defaultFrcPosition = nr;
-       shuffleOpenings = True;
-        ShufflePopDown();
-       ResetGameEvent();
-        return;
-    }
-}
-
-void ShufflePopUp()
-{
-    Arg args[16];
-    Widget popup, layout, dialog, edit;
-    Window root, child;
-    int x, y, i;
-    int win_x, win_y;
-    unsigned int mask;
-    char def[MSG_SIZ];
-
-    i = 0;
-    XtSetArg(args[i], XtNresizable, True); i++;
-    XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++;
-    shuffleShell = popup =
-      XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass,
-                        shellWidget, args, i);
-
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, popup,
-                           layoutArgs, XtNumber(layoutArgs));
-
-    snprintf(def, MSG_SIZ,  "%d\n", appData.defaultFrcPosition);
-    i = 0;
-    XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++;
-    XtSetArg(args[i], XtNvalue, def); i++;
-    XtSetArg(args[i], XtNborderWidth, 0); i++;
-    dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass,
-                                  layout, args, i);
-
-//    XtSetArg(args[0], XtNeditType, XawtextEdit);  // [HGM] can't get edit to work decently
-//    XtSetArg(args[1], XtNuseStringInPlace, False);
-//    XtSetValues(dialog, args, 2);
-
-    XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog);
-    XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog);
-    XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog);
-    XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog);
-
-    XtRealizeWidget(popup);
-    CatchDeleteWindow(popup, "ShufflePopDown");
-
-    XQueryPointer(xDisplay, xBoardWindow, &root, &child,
-                 &x, &y, &win_x, &win_y, &mask);
-
-    XtSetArg(args[0], XtNx, x - 10);
-    XtSetArg(args[1], XtNy, y - 30);
-    XtSetValues(popup, args, 2);
-
-    XtPopup(popup, XtGrabExclusive);
-    shuffleUp = True;
-
-    edit = XtNameToWidget(dialog, "*value");
-
-    XtSetKeyboardFocus(popup, edit);
-}
-
-void ShuffleMenuProc(w, event, prms, nprms)
-     Widget w;
-     XEvent *event;
-     String *prms;
-     Cardinal *nprms;
-{
-//    if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
-//     Reset(FALSE, TRUE);
-//    }
-    ShufflePopUp();
-}
-
 //--------------------------- Time-Control Menu Popup ----------------------------------
 int TimeControlUp;
 Widget TimeControlShell;
@@ -307,7 +181,7 @@ void TimeControlCallback(w, client_data, call_data)
        XtSetArg(args[j], XtNlabel, _("sec/move (max)")); j++;
        XtSetValues(tcMess1, args, j);
        j=0;
-       XtSetArg(args[j], XtNlabel, _("")); j++;
+       XtSetArg(args[j], XtNlabel, ""); j++;
        XtSetValues(tcMess2, args, j);
        j=0;
        XtSetArg(args[j], XtNstring, ""); j++;
@@ -605,6 +479,7 @@ void TimeControlProc(w, event, prms, nprms)
 //--------------------------- Engine-specific options menu ----------------------------------
 
 typedef void ButtonCallback(int n);
+typedef int OKCallback(int n);
 
 int values[MAX_OPTIONS];
 ChessProgramState *currentCps;
@@ -612,6 +487,28 @@ static Option *currentOption;
 static Boolean browserUp;
 ButtonCallback *comboCallback;
 
+void GetWidgetText(Option *opt, char **buf)
+{
+    Arg arg;
+    XtSetArg(arg, XtNstring, buf);
+    XtGetValues(opt->handle, &arg, 1);
+}
+
+void SetWidgetText(Option *opt, char *buf, int n)
+{
+    Arg arg;
+    XtSetArg(arg, XtNstring, buf);
+    XtSetValues(opt->handle, &arg, 1);
+    SetFocus(opt->handle, shells[n], NULL, False);
+}
+
+void SetWidgetState(Option *opt, int state)
+{
+    Arg arg;
+    XtSetArg(arg, XtNstate, state);
+    XtSetValues(opt->handle, &arg, 1);
+}
+
 void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b)
 {
     Widget w = currentOption[(int)(intptr_t)data].handle;
@@ -620,8 +517,7 @@ void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b)
 
     XtSetArg(args[0], XtNstate, &s);
     XtGetValues(w, args, 1);
-    XtSetArg(args[0], XtNstate, !s);
-    XtSetValues(w, args, 1);
+    SetWidgetState(&currentOption[(int)(intptr_t)data], !s);
 }
 
 void SpinCallback(w, client_data, call_data)
@@ -637,14 +533,10 @@ void SpinCallback(w, client_data, call_data)
     XtSetArg(args[0], XtNlabel, &name);
     XtGetValues(w, args, 1);
 
-    j = 0;
-    XtSetArg(args[0], XtNstring, &val);
-    XtGetValues(currentOption[data].handle, args, 1);
+    GetWidgetText(&currentOption[data], &val);
     sscanf(val, "%d", &j);
     if (strcmp(name, "browse") == 0) {
-       char *q, *r;
-       XtSetArg(args[0], XtNstring, &q);
-       XtGetValues(currentOption[data].handle, args, 1);
+       char *q=val, *r;
        for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash
        if(!strcmp(r, "") && !currentCps && currentOption[data].type == FileName && currentOption[data].textValue)
                r = currentOption[data].textValue;
@@ -667,9 +559,7 @@ void SpinCallback(w, client_data, call_data)
        if(--j < currentOption[data].min) return;
     } else return;
     snprintf(buf, MSG_SIZ,  "%d", j);
-    XtSetArg(args[0], XtNstring, buf);
-    XtSetValues(currentOption[data].handle, args, 1);
-    SetFocus(currentOption[data].handle, shells[0], NULL, False);
+    SetWidgetText(&currentOption[data], buf, 0);
 }
 
 void ComboSelect(w, addr, index) // callback for all combo items
@@ -725,7 +615,7 @@ static int oldCores, oldPonder;
 int MakeColors P((void));
 void CreateGCs P((int redo));
 void CreateAnyPieces P((void));
-void GenericReadout P((int selected));
+int GenericReadout P((int selected));
 Widget shells[10];
 Widget marked[10];
 Boolean shellUp[10];
@@ -779,41 +669,45 @@ void GenericPopDown(w, event, prms, nprms)
     PopDown(prms[0][0] - '0');
 }
 
-char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params;
+char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params, *tfName;
 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick;
 extern Option installOptions[], matchOptions[];
 char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
 char *engineList[100] = {" "}, *engineMnemonic[100] = {""};
 
-void AddToTourney(int n)
+void AddLine(Option *opt, char *s)
 {
-    Arg args[2];
-    char *p, *val, buf[10000];
     XawTextBlock t;
+    t.ptr = s; t.firstPos = 0; t.length = strlen(s); t.format = XawFmt8Bit;
+    XawTextReplace(opt->handle, 9999, 9999, &t);
+    t.ptr = "\n"; t.length = 1;
+    XawTextReplace(opt->handle, 9999, 9999, &t);
+}
 
+void AddToTourney(int n)
+{
     GenericReadout(4);  // selected engine
-    t.ptr = engineChoice; t.firstPos = 0; t.length = strlen(engineChoice); t.format = XawFmt8Bit;
-    XawTextReplace(matchOptions[3].handle, 9999, 9999, &t);
-    t.ptr = "\n"; t.length = 1;
-    XawTextReplace(matchOptions[3].handle, 9999, 9999, &t);
+    AddLine(&matchOptions[3], engineChoice);
 }
 
-void MatchOK(int n)
+int MatchOK(int n)
 {
     if(appData.participants && appData.participants[0]) free(appData.participants);
     appData.participants = strdup(engineName);
+    if(!CreateTourney(tfName)) return !appData.participants[0];
     PopDown(0); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning
-    if(CreateTourney(appData.tourneyFile)) MatchEvent(2); // start tourney
+    MatchEvent(2); // start tourney
+    return 1;
 }
 
 Option matchOptions[] = {
-{ 0,  0,          0, NULL, (void*) &appData.tourneyFile, ".trn", NULL, FileName, N_("Tournament file:") },
+{ 0,  0,          0, NULL, (void*) &tfName, ".trn", NULL, FileName, N_("Tournament file:") },
 { 0,  0,          0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round    (for concurrent playing of a single") },
 { 0,  0,          0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle      tourney with multiple XBoards)") },
 { 0xD, 150,       0, NULL, (void*) &engineName, "", NULL, TextBox, "Tourney participants:" },
 { 0,  1,          0, NULL, (void*) &engineChoice, (char*) (engineMnemonic+1), (engineMnemonic+1), ComboBox, N_("Select Engine:") },
 { 0,  0,         10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0 = round-robin, 1 = gauntlet):") },
-{ 0,  1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles:") },
+{ 0,  1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles (or Swiss rounds):") },
 { 0,  1, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, N_("Default Number of Games in Match (or Pairing):") },
 { 0,  0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Match Games (msec):") },
 { 0,  0,          0, NULL, (void*) &appData.saveGameFile, ".pgn", NULL, FileName, N_("Save Tourney Games on:") },
@@ -825,11 +719,12 @@ Option matchOptions[] = {
 { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }
 };
 
-void GeneralOptionsOK(int n)
+int GeneralOptionsOK(int n)
 {
        int newPonder = appData.ponderNextMove;
        appData.ponderNextMove = oldPonder;
        PonderNextMoveEvent(newPonder);
+       return 1;
 }
 
 Option generalOptions[] = {
@@ -840,6 +735,7 @@ Option generalOptions[] = {
 { 0,  0, 0, NULL, (void*) &appData.autoFlipView, "", NULL, CheckBox, N_("Auto Flip View") },
 { 0,  0, 0, NULL, (void*) &appData.blindfold, "", NULL, CheckBox, N_("Blindfold") },
 { 0,  0, 0, NULL, (void*) &appData.dropMenu, "", NULL, CheckBox, N_("Drop Menu") },
+{ 0,  0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
 { 0,  0, 0, NULL, (void*) &appData.highlightDragging, "", NULL, CheckBox, N_("Highlight Dragging (Show Move Targets)") },
 { 0,  0, 0, NULL, (void*) &appData.highlightLastMove, "", NULL, CheckBox, N_("Highlight Last Move") },
 { 0,  0, 0, NULL, (void*) &appData.highlightMoveWithArrow, "", NULL, CheckBox, N_("Highlight with Arrow") },
@@ -851,7 +747,6 @@ Option generalOptions[] = {
 { 0,  0, 0, NULL, (void*) &appData.popupMoveErrors, "", NULL, CheckBox, N_("Popup Move Errors") },
 { 0,  0, 0, NULL, (void*) &appData.showCoords, "", NULL, CheckBox, N_("Show Coordinates") },
 { 0,  0, 0, NULL, (void*) &appData.markers, "", NULL, CheckBox, N_("Show Target Squares") },
-{ 0,  0, 0, NULL, (void*) &appData.hideThinkingFromHuman, "", NULL, CheckBox, N_("Hide Thinking from Human") },
 { 0,  0, 0, NULL, (void*) &appData.testLegality, "", NULL, CheckBox, N_("Test Legality") },
 { 0, 0, 10, NULL, (void*) &appData.flashCount, "", NULL, Spin, N_("Flash Moves (0 = no flashing):") },
 { 0, 1, 10, NULL, (void*) &appData.flashRate, "", NULL, Spin, N_("Flash Rate (high = fast):") },
@@ -934,7 +829,7 @@ Option variantDescriptors[] = {
 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
 };
 
-void CommonOptionsOK(int n)
+int CommonOptionsOK(int n)
 {
        int newPonder = appData.ponderNextMove;
        // make sure changes are sent to first engine by re-initializing it
@@ -946,6 +841,7 @@ void CommonOptionsOK(int n)
            appData.ponderNextMove = oldPonder;
            PonderNextMoveEvent(newPonder);
        }
+       return 1;
 }
 
 Option commonEngineOptions[] = {
@@ -978,9 +874,10 @@ Option adjudicationOptions[] = {
 { 0, 1,    0, NULL, NULL, "", NULL, EndMark , "" }
 };
 
-void IcsOptionsOK(int n)
+int IcsOptionsOK(int n)
 {
     ParseIcsTextColors();
+    return 1;
 }
 
 Option icsOptions[] = {
@@ -1101,7 +998,7 @@ Option soundOptions[] = {
 { 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
 };
 
-void SetColor(char *colorName, Widget box)
+void SetColor(char *colorName, Option *box)
 {
        Arg args[5];
        Pixel buttonColor;
@@ -1117,16 +1014,13 @@ void SetColor(char *colorName, Widget box)
            }
        } else buttonColor = (Pixel) 0;
        XtSetArg(args[0], XtNbackground, buttonColor);;
-       XtSetValues(box, args, 1);
+       XtSetValues(box->handle, args, 1);
 }
 
 void SetColorText(int n, char *buf)
 {
-    Arg args[5];
-    XtSetArg(args[0], XtNstring, buf);
-    XtSetValues(currentOption[n-1].handle, args, 1);
-    SetFocus(currentOption[n-1].handle, shells[0], NULL, False);
-    SetColor(buf, currentOption[n].handle);
+    SetWidgetText(&currentOption[n-1], buf, 0);
+    SetColor(buf, &currentOption[n]);
 }
 
 void DefColor(int n)
@@ -1139,8 +1033,7 @@ void RefreshColor(int source, int n)
     int col, j, r, g, b, step = 10;
     char *s, buf[MSG_SIZ]; // color string
     Arg args[5];
-    XtSetArg(args[0], XtNstring, &s);
-    XtGetValues(currentOption[source].handle, args, 1);
+    GetWidgetText(&currentOption[source], &s);
     if(sscanf(s, "#%x", &col) != 1) return;   // malformed
     b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
     switch(n) {
@@ -1170,7 +1063,7 @@ void AdjustColor(int i)
     RefreshColor(i-n-1, n);
 }
 
-void BoardOptionsOK(int n)
+int BoardOptionsOK(int n)
 {
     if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap;
     useImages = useImageSqs = 0;
@@ -1178,6 +1071,7 @@ void BoardOptionsOK(int n)
     CreateAnyPieces();
     InitDrawingSizes(-1, 0);
     DrawPosition(True, NULL);
+    return 1;
 }
 
 Option boardOptions[] = {
@@ -1228,9 +1122,9 @@ Option boardOptions[] = {
 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
 };
 
-void GenericReadout(int selected)
+int GenericReadout(int selected)
 {
-    int i, j;
+    int i, j, res=1;
     String val;
     Arg args[16];
     char buf[MSG_SIZ], **dest;
@@ -1299,7 +1193,7 @@ void GenericReadout(int selected)
                    break;
                case EndMark:
                    if(currentOption[i].target) // callback for implementing necessary actions on OK (like redraw)
-                       ((ButtonCallback*) currentOption[i].target)(i);
+                       res = ((OKCallback*) currentOption[i].target)(i);
                    break;
            default:
                printf("GenericReadout: unexpected case in switch.\n");
@@ -1311,6 +1205,7 @@ void GenericReadout(int selected)
            }
            if(currentOption[i].type == EndMark) break;
        }
+       return res;
 }
 
 void GenericCallback(w, client_data, call_data)
@@ -1332,8 +1227,7 @@ void GenericCallback(w, client_data, call_data)
         return;
     }
     if (strcmp(name, _("OK")) == 0) { // save buttons imply OK
-        GenericReadout(-1);
-        PopDown(data);
+        if(GenericReadout(-1)) PopDown(data);
         return;
     }
     if(currentCps) {
@@ -1528,12 +1422,12 @@ GenericPopUp(Option *option, char *title, int dlgNr)
            option[i].handle = (void*)
                (dialog = last = XtCreateManagedWidget(option[i].name, commandWidgetClass, form, args, j));
            if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) {
-               SetColor( *(char**) option[i-1].target, last);
+               SetColor( *(char**) option[i-1].target, &option[i]);
                XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1);
            }
            XtAddCallback(last, XtNcallback, GenericCallback,
                          (XtPointer)(intptr_t) i + (dlgNr<<16));
-           if(option[i].textValue) SetColor( option[i].textValue, last);
+           if(option[i].textValue) SetColor( option[i].textValue, &option[i]);
            forelast = lastrow; // next button can go on same row
            break;
          case ComboBox:
@@ -1763,6 +1657,8 @@ void MatchOptionsProc(w, event, prms, nprms)
 {
    NamesToList(firstChessProgramNames, engineList, engineMnemonic);
    comboCallback = &AddToTourney;
+   matchOptions[5].min = -(appData.pairingEngine[0] != NULLCHAR); // with pairing engine, allow Swiss
+   ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));
    GenericPopUp(matchOptions, _("Match Options"), 0);
 }
 
@@ -1851,16 +1747,15 @@ static int commentIndex;
 void ClearComment P((int n));
 extern char commentTranslations[];
 
-void NewComCallback(int n)
+int NewComCallback(int n)
 {
     ReplaceComment(commentIndex, commentText);
+    return 1;
 }
 
 void SaveChanges(int n)
 {
-    Arg args[16];
-    XtSetArg(args[0], XtNstring, &commentText);
-    XtGetValues(currentOption[0].handle, args, 1);
+    GetWidgetText(&currentOption[0], &commentText);
     ReplaceComment(commentIndex, commentText);
 }
 
@@ -1885,8 +1780,7 @@ void NewCommentPopup(char *title, char *text, int index)
     if(shells[1]) { // if already exists, alter title and content
        XtSetArg(args[0], XtNtitle, title);
        XtSetValues(shells[1], args, 1);
-       XtSetArg(args[0], XtNstring, text);
-       XtSetValues(commentOptions[0].handle, args, 1);
+       SetWidgetText(&commentOptions[0], text, 1);
     }
     if(commentText) free(commentText); commentText = strdup(text);
     commentIndex = index;
@@ -1897,16 +1791,15 @@ void NewCommentPopup(char *title, char *text, int index)
 
 static char *tagsText, *msgText;
 
-void NewTagsCallback(int n)
+int NewTagsCallback(int n)
 {
     ReplaceTags(tagsText, &gameInfo);
+    return 1;
 }
 
 void changeTags(int n)
 {
-    Arg args[16];
-    XtSetArg(args[0], XtNstring, &tagsText);
-    XtGetValues(currentOption[1].handle, args, 1);
+    GetWidgetText(&currentOption[1], &tagsText);
     if(bookUp) SaveToBook(tagsText); else\r
     ReplaceTags(tagsText, &gameInfo);
 }
@@ -1925,8 +1818,7 @@ void NewTagsPopup(char *text, char *msg)
     char *title = bookUp ? _("Edit book") : _("Tags");
 
     if(shells[2]) { // if already exists, alter title and content
-       XtSetArg(args[0], XtNstring, text);
-       XtSetValues(tagsOptions[1].handle, args, 1);
+       SetWidgetText(&tagsOptions[1], text, 2);
        XtSetArg(args[0], XtNtitle, title);
        XtSetValues(shells[2], args, 1);
     }
@@ -1949,13 +1841,11 @@ void PutText(char *text, int pos)
     char buf[MSG_SIZ], *p;
 
     if(strstr(text, "$add ") == text) {
-       XtSetArg(args[0], XtNstring, &p);
-       XtGetValues(boxOptions[0].handle, args, 1);
+       GetWidgetText(&boxOptions[0], &p);
        snprintf(buf, MSG_SIZ, "%s%s", p, text+5); text = buf;
        pos += strlen(p) - 5;
     }
-    XtSetArg(args[0], XtNstring, text);
-    XtSetValues(boxOptions[0].handle, args, 1);
+    SetWidgetText(&boxOptions[0], text, 4);
     XtSetArg(args[0], XtNinsertPosition, pos);
     XtSetValues(boxOptions[0].handle, args, 1);
 //    SetFocus(boxOptions[0].handle, shells[4], NULL, False); // No idea why this does not work, and the following is needed:
@@ -1979,8 +1869,7 @@ void TypeInProc(w, event, prms, nprms)
     String val;
 
     if(prms[0][0] == '1') {
-       XtSetArg(args[0], XtNstring, &val);
-       XtGetValues(boxOptions[0].handle, args, 1);
+       GetWidgetText(&boxOptions[0], &val);
        TypeInDoneEvent((char*)val);
     }
     PopDown(0);\r
@@ -2038,10 +1927,11 @@ void SecondSettingsProc(w, event, prms, nprms)
    SettingsPopUp(&second);
 }
 
-void InstallOK(int n)
+int InstallOK(int n)
 {
     PopDown(0); // early popdown, to allow FreezeUI to instate grab
     if(engineChoice[0] == engineNr[0][0])  Load(&first, 0); else Load(&second, 1);
+    return 1;
 }
 
 Option installOptions[] = {
@@ -2086,6 +1976,41 @@ void EditBookProc(w, event, prms, nprms)
     EditBookEvent();
 }
 
+void SetRandom P((int n));
+
+int ShuffleOK(int n)
+{
+    ResetGameEvent();
+    return 1;
+}
+
+Option shuffleOptions[] = {
+{   0,  0,   50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, "shuffle" },
+{ 0,-1,2000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") },
+{   0,  0,    0, NULL, (void*) &SetRandom, NULL, NULL, Button, "randomize" },
+{   0,  1,    0, NULL, (void*) &SetRandom, NULL, NULL, Button, "pick fixed" },
+{   0,  1,    0, NULL, (void*) &ShuffleOK, "", NULL, EndMark , "" }
+};
+
+void SetRandom(int n)
+{
+    int r = n==2 ? -1 : rand() & (1<<30)-1;
+    char buf[MSG_SIZ];
+    Arg args[2];
+    snprintf(buf, MSG_SIZ,  "%d", r);
+    SetWidgetText(&shuffleOptions[1], buf, 0);
+    SetWidgetState(&shuffleOptions[0], True);
+}
+
+void ShuffleMenuProc(w, event, prms, nprms)
+     Widget w;
+     XEvent *event;
+     String *prms;
+     Cardinal *nprms;
+{
+    GenericPopUp(shuffleOptions, _("New Shuffle Game"), 0);
+}
+
 //---------------------------- Chat Windows ----------------------------------------------
 
 void OutputChatMessage(int partner, char *mess)