X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xoptions.c;h=c3878a0ee3d534f10f691678531dce98f7c11dd4;hb=c2bf6cfe30a36d4a6428ea518dbeac6f21713450;hp=5cadaf9730ae7377f76e8bfea574918e084b6462;hpb=00d7f7869e045cbed5037d39e1e56224692eb766;p=xboard.git diff --git a/xoptions.c b/xoptions.c index 5cadaf9..c3878a0 100644 --- a/xoptions.c +++ b/xoptions.c @@ -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++; @@ -613,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; @@ -621,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(¤tOption[(int)(intptr_t)data], !s); } void SpinCallback(w, client_data, call_data) @@ -638,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(¤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; @@ -668,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(¤tOption[data], buf, 0); } void ComboSelect(w, addr, index) // callback for all combo items @@ -780,37 +669,39 @@ 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); } 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:" }, @@ -844,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") }, @@ -855,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):") }, @@ -1107,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; @@ -1123,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(¤tOption[n-1], buf, 0); + SetColor(buf, ¤tOption[n]); } void DefColor(int n) @@ -1145,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(¤tOption[source], &s); if(sscanf(s, "#%x", &col) != 1) return; // malformed b = col & 0xFF; g = col & 0xFF00; r = col & 0xFF0000; switch(n) { @@ -1535,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: @@ -1771,6 +1658,7 @@ 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); } @@ -1867,9 +1755,7 @@ int NewComCallback(int n) 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); } @@ -1894,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; @@ -1914,9 +1799,7 @@ int NewTagsCallback(int n) 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 ReplaceTags(tagsText, &gameInfo); } @@ -1935,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); } @@ -1959,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: @@ -1989,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); @@ -2097,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)