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
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)
{ 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:
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
Option shuffleOptions[] = {
{ 0, 0, 50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, "shuffle" },
-{ 0,-1,1000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") },
+{ 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();
+ int r = n==2 ? -1 : rand() & (1<<30)-1;
char buf[MSG_SIZ];
Arg args[2];
snprintf(buf, MSG_SIZ, "%d", r);
- XtSetArg(args[0],XtNstring, buf);
- XtSetValues(shuffleOptions[1].handle, args, 1);
- XtSetArg(args[0],XtNstate, True);
- XtSetValues(shuffleOptions[0].handle, args, 1);
+ SetWidgetText(&shuffleOptions[1], buf, 0);
+ SetWidgetState(&shuffleOptions[0], True);
}
void ShuffleMenuProc(w, event, prms, nprms)