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;
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++;
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;
XtSetArg(args[0], XtNstate, &s);
XtGetValues(w, args, 1);
- XtSetArg(args[0], XtNstate, !s);
- XtSetValues(w, args, 1);
+ SetWidgetState(¤tOption[(int)(intptr_t)data], !s);
}
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(¤tOption[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;
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(¤tOption[data], buf, 0);
}
void ComboSelect(w, addr, index) // callback for all combo items
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);
}
int MatchOK(int n)
{
if(appData.participants && appData.participants[0]) free(appData.participants);
appData.participants = strdup(engineName);
- if(!CreateTourney(appData.tourneyFile)) return 0;
+ if(!CreateTourney(tfName)) return !appData.participants[0];
PopDown(0); // early popdown to prevent FreezeUI called through MatchEvent from causing XtGrab warning
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:") },
{ 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") },
{ 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):") },
{ 0, 1, 0, NULL, NULL, "", NULL, EndMark , "" }
};
-void SetColor(char *colorName, Widget box)
+void SetColor(char *colorName, Option *box)
{
Arg args[5];
Pixel buttonColor;
}
} 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(¤tOption[n-1], buf, 0);
+ SetColor(buf, ¤tOption[n]);
}
void DefColor(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(¤tOption[source], &s);
if(sscanf(s, "#%x", &col) != 1) return; // malformed
b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000;
switch(n) {
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:
{
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);
}
void SaveChanges(int n)
{
- Arg args[16];
- XtSetArg(args[0], XtNstring, &commentText);
- XtGetValues(currentOption[0].handle, args, 1);
+ GetWidgetText(¤tOption[0], &commentText);
ReplaceComment(commentIndex, commentText);
}
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;
void changeTags(int n)
{
- Arg args[16];
- XtSetArg(args[0], XtNstring, &tagsText);
- XtGetValues(currentOption[1].handle, args, 1);
+ GetWidgetText(¤tOption[1], &tagsText);
if(bookUp) SaveToBook(tagsText); else\r
ReplaceTags(tagsText, &gameInfo);
}
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);
}
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:
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
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)