X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xoptions.c;h=acbbba8c96fd54333ea6cb77c72c11027267de96;hb=aae1b2706f58097dcdd1ee907e26add590d81df9;hp=b8a8a680a2f6d5a44f98107b7b5e1d7b0325964f;hpb=b80a07a436b0211145c915a7d79bf7c41ae891e4;p=xboard.git diff --git a/xoptions.c b/xoptions.c index b8a8a68..acbbba8 100644 --- a/xoptions.c +++ b/xoptions.c @@ -45,6 +45,7 @@ extern char *getenv(); #if HAVE_UNISTD_H # include #endif +#include #include #include @@ -78,6 +79,8 @@ extern char *getenv(); # define N_(s) s #endif +extern void SendToProgram P((char *message, ChessProgramState *cps)); + extern Widget formWidget, shellWidget, boardWidget, menuBarWidget; extern Display *xDisplay; extern int squareSize; @@ -140,7 +143,6 @@ void ShuffleCallback(w, client_data, call_data) ShufflePopDown(); shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it! ResetGameEvent(); - AnalysisPopDown(); return; } if (strcmp(name, _("random")) == 0) { @@ -162,7 +164,6 @@ void ShuffleCallback(w, client_data, call_data) shuffleOpenings = True; ShufflePopDown(); ResetGameEvent(); - AnalysisPopDown(); return; } } @@ -245,6 +246,7 @@ int tcIncrement, tcMoves; void TimeControlPopDown() { if (!TimeControlUp) return; + previous = NULL; XtPopdown(TimeControlShell); XtDestroyWidget(TimeControlShell); TimeControlUp = False; @@ -567,6 +569,7 @@ Widget engDrawMoves, engThreshold, engRule, engRepeat; void EnginePopDown() { if (!EngineUp) return; + previous = NULL; XtPopdown(EngineShell); XtDestroyWidget(EngineShell); EngineUp = False; @@ -602,8 +605,8 @@ void EngineCallback(w, client_data, call_data) // read all switches appData.periodicUpdates = ReadToggle(w1); // appData.hideThinkingFromHuman = ReadToggle(w2); - appData.firstScoreIsAbsolute = ReadToggle(w3); - appData.secondScoreIsAbsolute = ReadToggle(w4); + first.scoreIsAbsolute = appData.firstScoreIsAbsolute = ReadToggle(w3); + second.scoreIsAbsolute = appData.secondScoreIsAbsolute = ReadToggle(w4); appData.testClaims = ReadToggle(w5); appData.checkMates = ReadToggle(w6); appData.materialDraws = ReadToggle(w7); @@ -907,6 +910,7 @@ struct NewVarButton buttonDesc[] = { {N_("berolina"), "#FFFFFF", 0, VariantBerolina}, {N_("cylinder"), "#FFFFFF", 0, VariantCylinder}, {N_("shatranj"), "#FFFFFF", 0, VariantShatranj}, + {N_("makruk"), "#FFFFFF", 0, VariantMakruk}, {N_("atomic"), "#FFFFFF", 0, VariantAtomic}, {N_("two kings"), "#FFFFFF", 0, VariantTwoKings}, {N_("3-checks"), "#FFFFFF", 0, Variant3Check}, @@ -958,7 +962,7 @@ void NewVariantCallback(w, client_data, call_data) XtGetValues(w, args, 1); if (strcmp(name, _(" OK ")) == 0) { - int nr = (int) XawToggleGetCurrent(buttonDesc[0].handle) - 1; + int nr = (intptr_t) XawToggleGetCurrent(buttonDesc[0].handle) - 1; if(nr < 0) return; v = buttonDesc[nr].variant; if(!appData.noChessProgram) { @@ -1079,7 +1083,7 @@ void NewVariantPopUp() "for missing bitmaps. (See manual.)")); j++; XtCreateManagedWidget("warning", labelWidgetClass, form, args, j); - XtRealizeWidget(popup); + XtRealizeWidget(popup); CatchDeleteWindow(popup, "NewVariantPopDown"); XQueryPointer(xDisplay, xBoardWindow, &root, &child, @@ -1125,6 +1129,7 @@ struct UciControl controlDesc[] = { void UciPopDown() { if (!UciUp) return; + previous = NULL; XtPopdown(UciShell); XtDestroyWidget(UciShell); UciUp = False; @@ -1323,6 +1328,7 @@ ChessProgramState *currentCps; void SettingsPopDown() { if (!SettingsUp) return; + previous = NULL; XtPopdown(SettingsShell); XtDestroyWidget(SettingsShell); SettingsUp = False; @@ -1338,23 +1344,24 @@ void SpinCallback(w, client_data, call_data) Arg args[16]; char buf[MSG_SIZ]; int i, j; + int data = (intptr_t) client_data; XtSetArg(args[0], XtNlabel, &name); XtGetValues(w, args, 1); j = 0; XtSetArg(args[0], XtNstring, &val); - XtGetValues(currentCps->option[(int)client_data].handle, args, 1); + XtGetValues(currentCps->option[data].handle, args, 1); sscanf(val, "%d", &j); if (strcmp(name, "+") == 0) { - if(++j > currentCps->option[(int)client_data].max) return; + if(++j > currentCps->option[data].max) return; } else if (strcmp(name, "-") == 0) { - if(--j < currentCps->option[(int)client_data].min) return; + if(--j < currentCps->option[data].min) return; } else return; sprintf(buf, "%d", j); XtSetArg(args[0], XtNstring, buf); - XtSetValues(currentCps->option[(int)client_data].handle, args, 1); + XtSetValues(currentCps->option[data].handle, args, 1); } void SettingsCallback(w, client_data, call_data) @@ -1366,6 +1373,7 @@ void SettingsCallback(w, client_data, call_data) Arg args[16]; char buf[MSG_SIZ]; int i, j; + int data = (intptr_t) client_data; XtSetArg(args[0], XtNlabel, &name); XtGetValues(w, args, 1); @@ -1374,7 +1382,7 @@ void SettingsCallback(w, client_data, call_data) SettingsPopDown(); return; } - if (strcmp(name, _("OK")) == 0 || (int)client_data) { // save buttons imply OK + if (strcmp(name, _("OK")) == 0 || data) { // save buttons imply OK int nr; for(i=0; inrOptions; i++) { // send all options that had to be OK-ed to engine @@ -1420,7 +1428,7 @@ void SettingsCallback(w, client_data, call_data) break; } } - if((int)client_data) { // send save-button command to engine + if(data) { // send save-button command to engine sprintf(buf, "option %s\n", name); SendToProgram(buf, currentCps); } @@ -1437,8 +1445,8 @@ void ComboSelect(w, addr, index) // callback for all combo items caddr_t index; { Arg args[16]; - int i = ((int)addr)>>8; - int j = 255 & (int) addr; + int i = ((intptr_t)addr)>>8; + int j = 255 & (intptr_t) addr; values[i] = j; // store in temporary, for transfer at OK XtSetArg(args[0], XtNlabel, ((char**)currentCps->option[i].textValue)[j]); @@ -1465,7 +1473,7 @@ void CreateComboPopup(parent, name, n, mb) menu, args, j); XtAddCallback(entry, XtNcallback, (XtCallbackProc) ComboSelect, - (caddr_t) (256*n+i)); + (caddr_t)(intptr_t) (256*n+i)); i++; } } @@ -1473,18 +1481,22 @@ void CreateComboPopup(parent, name, n, mb) void SettingsPopUp(ChessProgramState *cps) { Arg args[16]; - Widget popup, layout, dialog, edit, form, oldform, last, b_ok, b_cancel; + Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL; Window root, child; - int x, y, i, j; - int win_x, win_y; + int x, y, i, j, height, width, h, c; + int win_x, win_y, maxWidth, maxTextWidth; unsigned int mask; char def[80], *p, *q; + static char pane[6] = "paneX"; + Widget texts[100], forelast = NULL, anchor, widest; // to do: start up second engine if needed if(!cps->initDone || !cps->nrOptions) return; // nothing to be done currentCps = cps; - i = 0; + if(cps->nrOptions > 50) width = 4; else if(cps->nrOptions>24) width = 2; else width = 1; + height = cps->nrOptions / width + 1; + i = 0; XtSetArg(args[i], XtNresizable, True); i++; SettingsShell = popup = XtCreatePopupShell(_("Settings Menu"), transientShellWidgetClass, @@ -1493,12 +1505,21 @@ void SettingsPopUp(ChessProgramState *cps) layout = XtCreateManagedWidget(layoutName, formWidgetClass, popup, layoutArgs, XtNumber(layoutArgs)); - + for(c=0; cnrOptions; i++) { + j=0; + XtSetArg(args[j], XtNfromHoriz, leftMargin); j++; + XtSetValues(form, args, j); + leftMargin = form; + + last = widest = NULL; anchor = forelast; + for(h=0; h= cps->nrOptions) break; switch(cps->option[i].type) { case Spin: sprintf(def, "%d", cps->option[i].value); @@ -1507,12 +1528,13 @@ void SettingsPopUp(ChessProgramState *cps) XtSetArg(args[j], XtNfromVert, last); j++; XtSetArg(args[j], XtNborderWidth, 0); j++; XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++; + texts[h] = dialog = XtCreateManagedWidget(cps->option[i].name, labelWidgetClass, form, args, j); j=0; XtSetArg(args[j], XtNfromVert, last); j++; XtSetArg(args[j], XtNfromHoriz, dialog); j++; XtSetArg(args[j], XtNborderWidth, 1); j++; - XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 100); j++; + XtSetArg(args[j], XtNwidth, cps->option[i].type == Spin ? 40 : 175); j++; XtSetArg(args[j], XtNeditType, XawtextEdit); j++; XtSetArg(args[j], XtNuseStringInPlace, False); j++; XtSetArg(args[j], XtNdisplayCaret, False); j++; @@ -1532,7 +1554,8 @@ void SettingsPopUp(ChessProgramState *cps) XtSetArg(args[j], XtNheight, 10); j++; XtSetArg(args[j], XtNwidth, 20); j++; edit = XtCreateManagedWidget("+", commandWidgetClass, form, args, j); - XtAddCallback(edit, XtNcallback, SpinCallback, (XtPointer) i); + XtAddCallback(edit, XtNcallback, SpinCallback, + (XtPointer)(intptr_t) i); j=0; XtSetArg(args[j], XtNfromVert, edit); j++; @@ -1540,7 +1563,8 @@ void SettingsPopUp(ChessProgramState *cps) XtSetArg(args[j], XtNheight, 10); j++; XtSetArg(args[j], XtNwidth, 20); j++; last = XtCreateManagedWidget("-", commandWidgetClass, form, args, j); - XtAddCallback(last, XtNcallback, SpinCallback, (XtPointer) i); + XtAddCallback(last, XtNcallback, SpinCallback, + (XtPointer)(intptr_t) i); break; case CheckBox: j=0; @@ -1563,8 +1587,9 @@ void SettingsPopUp(ChessProgramState *cps) XtSetArg(args[j], XtNfromVert, last); j++; XtSetArg(args[j], XtNstate, cps->option[i].value); j++; cps->option[i].handle = (void*) - (last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j)); - XtAddCallback(last, XtNcallback, SettingsCallback, (XtPointer) (cps->option[i].type == SaveButton)); + (dialog = last = XtCreateManagedWidget(cps->option[i].name, commandWidgetClass, form, args, j)); + XtAddCallback(last, XtNcallback, SettingsCallback, + (XtPointer)(intptr_t) (cps->option[i].type == SaveButton)); break; case ComboBox: j=0; @@ -1587,16 +1612,53 @@ void SettingsPopUp(ChessProgramState *cps) } } + // make an attempt to align all spins and textbox controls + maxWidth = maxTextWidth = 0; + for(h=0; h= cps->nrOptions) break; + if(cps->option[i].type == Spin || cps->option[i].type == TextBox) { + Dimension w; + j=0; + XtSetArg(args[j], XtNwidth, &w); j++; + XtGetValues(texts[h], args, j); + if(cps->option[i].type == Spin) { + if(w > maxWidth) maxWidth = w; + widest = texts[h]; + } else { + if(w > maxTextWidth) maxTextWidth = w; + if(!widest) widest = texts[h]; + } + } + } + if(maxTextWidth + 110 < maxWidth) + maxTextWidth = maxWidth - 110; + else maxWidth = maxTextWidth + 110; + for(h=0; h= cps->nrOptions) break; + j=0; + if(cps->option[i].type == Spin) { + XtSetArg(args[j], XtNwidth, maxWidth); j++; + XtSetValues(texts[h], args, j); + } else + if(cps->option[i].type == TextBox) { + XtSetArg(args[j], XtNwidth, maxTextWidth); j++; + XtSetValues(texts[h], args, j); + } + } + } j=0; - XtSetArg(args[j], XtNfromVert, last); j++; + XtSetArg(args[j], XtNfromVert, anchor ? anchor : last); j++; XtSetArg(args[j], XtNbottom, XtChainBottom); j++; XtSetArg(args[j], XtNtop, XtChainBottom); j++; - XtSetArg(args[j], XtNleft, XtChainLeft); j++; - XtSetArg(args[j], XtNright, XtChainLeft); j++; + XtSetArg(args[j], XtNleft, XtChainRight); j++; + XtSetArg(args[j], XtNright, XtChainRight); j++; + XtSetArg(args[j], XtNfromHoriz, widest ? widest : dialog); j++; b_ok = XtCreateManagedWidget(_("OK"), commandWidgetClass, form, args, j); XtAddCallback(b_ok, XtNcallback, SettingsCallback, (XtPointer) 0); - XtSetArg(args[j], XtNfromHoriz, b_ok); j++; + XtSetArg(args[j-1], XtNfromHoriz, b_ok); b_cancel = XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j); XtAddCallback(b_cancel, XtNcallback, SettingsPopDown, (XtPointer) 0); @@ -1614,7 +1676,7 @@ void SettingsPopUp(ChessProgramState *cps) SettingsUp = True; previous = NULL; - SetFocus(edit, popup, (XEvent*) NULL, False); + if(edit)SetFocus(edit, popup, (XEvent*) NULL, False); } void FirstSettingsProc(w, event, prms, nprms) @@ -1635,107 +1697,10 @@ void SecondSettingsProc(w, event, prms, nprms) SettingsPopUp(&second); } -//--------------------------- General Popup for Cloning ---------------------------------- -#if 0 -int XXXUp; -Widget XXXShell; - -void XXXPopDown() -{ - if (!XXXUp) return; - XtPopdown(XXXShell); - XtDestroyWidget(XXXShell); - XXXUp = False; - ModeHighlight(); -} - -void XXXCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Widget w2; - Arg args[16]; - char buf[80]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, _("cancel")) == 0) { - XXXPopDown(); - return; - } - if (strcmp(name, _("ok")) == 0) { - int nr; String name; - name = XawDialogGetValueString(w2 = XtParent(w)); - if(sscanf(name ,"%d",&nr) != 1) { - sprintf(buf, "%d", appData.defaultFrcPosition); - XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value - XtSetValues(w2, args, 1); - return; - } - XXXPopDown(); - return; - } -} +//---------------------------- Chat Windows ---------------------------------------------- -void XXXPopUp() +void OutputChatMessage(int partner, char *mess) { - 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[80]; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - XXXShell = popup = - XtCreatePopupShell(_("XXX Menu"), transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - sprintf(def, "%d\n", appData.defaultFrcPosition); - i = 0; - XtSetArg(args[i], XtNlabel, ""); i++; - XtSetArg(args[i], XtNvalue, def); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("XXX", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("ok"), XXXCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, _("cancel"), XXXCallback, (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "XXXPopDown"); - - 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); - XXXUp = True; - - edit = XtNameToWidget(dialog, "*value"); - - previous = NULL; - SetFocus(engThreshold, popup, (XEvent*) NULL, False); + return; // dummy } -void XXXMenuProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - XXXPopUp(); -} -#endif \ No newline at end of file