X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xoptions.c;h=1d5173835947ff27d4ca48c4c1c43956ebe159b8;hb=f09bb2248bceae137817926c5bacd1f5b73c0019;hp=04198cae681488ec11521e55231a59b8ea1269b1;hpb=5679f357b11ddeae09d5d3ba6613b6bda1dc00e9;p=xboard.git diff --git a/xoptions.c b/xoptions.c index 04198ca..1d51738 100644 --- a/xoptions.c +++ b/xoptions.c @@ -624,6 +624,7 @@ int values[MAX_OPTIONS]; ChessProgramState *currentCps; static Option *currentOption; extern Widget shells[]; +static Boolean browserUp; void CheckCallback(Widget ww, XtPointer data, XEvent *event, Boolean *b) { @@ -659,6 +660,7 @@ void SpinCallback(w, client_data, call_data) XtSetArg(args[0], XtNstring, &q); XtGetValues(currentOption[data].handle, args, 1); for(r = ""; *q; q++) if(*q == '.') r = q; else if(*q == '/') r = ""; // last dot after last slash + browserUp = True; if(XsraSelFile(shells[0], currentOption[data].name, NULL, NULL, "", "", r, currentOption[data].type == PathName ? "p" : "f", NULL, &p)) { int len = strlen(p); @@ -666,6 +668,7 @@ void SpinCallback(w, client_data, call_data) XtSetArg(args[0], XtNstring, p); XtSetValues(currentOption[data].handle, args, 1); } + browserUp = False; SetFocus(currentOption[data].handle, shells[0], (XEvent*) NULL, False); return; } else @@ -727,6 +730,7 @@ void CreateComboPopup(parent, name, n, mb) typedef void ButtonCallback(int n); +extern WindowPlacement wpComment, wpTags; char *trialSound; static int oldCores, oldPonder; int MakeColors P((void)); @@ -737,7 +741,7 @@ void GenericReadout(); Widget shells[10]; Widget marked[10]; Boolean shellUp[10]; -WindowPlacement *wp[10]; +WindowPlacement *wp[10] = { NULL, &wpComment, &wpTags }; Option *dialogOptions[10]; void MarkMenu(char *item, int dlgNr) @@ -784,6 +788,7 @@ void GenericPopDown(w, event, prms, nprms) Cardinal *nprms; { int n; + if(browserUp) return; // prevent closing dialog when it has an open file-browse daughter PopDown(prms[0][0] - '0'); } @@ -806,7 +811,7 @@ void GeneralOptionsOK(int n) } Option generalOptions[] = { -{ 0, 0, 0, NULL, (void*) &appData.alwaysPromoteToQueen, "", NULL, CheckBox, _("Always Queen") }, +{ 0, 0, 0, NULL, (void*) &appData.sweepSelect, "", NULL, CheckBox, _("Almost Always Queen (Detour Under-Promote)") }, { 0, 0, 0, NULL, (void*) &appData.animateDragging, "", NULL, CheckBox, _("Animate Dragging") }, { 0, 0, 0, NULL, (void*) &appData.animate, "", NULL, CheckBox, _("Animate Moving") }, { 0, 0, 0, NULL, (void*) &appData.autoCallFlag, "", NULL, CheckBox, _("Auto Flag") }, @@ -1232,13 +1237,14 @@ void GenericReadout() sscanf(val, "%f", &x); if(x > currentOption[i].max) x = currentOption[i].max; if(x < currentOption[i].min) x = currentOption[i].min; - if(currentOption[i].value != x) { + if(currentOption[i].type == Fractional) + *(float*) currentOption[i].target = x; // engines never have float options! + else if(currentOption[i].value != x) { currentOption[i].value = x; - if(currentCps) { // engines never have float options, so no decimals! + if(currentCps) { snprintf(buf, MSG_SIZ, "option %s=%.0f\n", currentOption[i].name, x); SendToProgram(buf, currentCps); - } else if(currentOption[i].type == Spin) *(int*) currentOption[i].target = x; - else *(float*) currentOption[i].target = x; + } else *(int*) currentOption[i].target = x; } break; case CheckBox: @@ -1275,6 +1281,7 @@ void GenericReadout() case Button: case SaveButton: case Label: + case Break: break; } if(currentOption[i].type == EndMark) break; @@ -1327,7 +1334,7 @@ GenericPopUp(Option *option, char *title, int dlgNr) static char pane[6] = "paneX"; Widget texts[100], forelast = NULL, anchor, widest, lastrow = NULL; - if(shellUp[dlgNr]) return 0; // already up + if(shellUp[dlgNr]) return 0; // already up if(dlgNr && shells[dlgNr]) { XtPopup(shells[dlgNr], XtGrabNone); shellUp[dlgNr] = True; @@ -1492,7 +1499,7 @@ 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 && !currentCps) { + if(option[i].choice && ((char*)option[i].choice)[0] == '#' && !currentCps) { SetColor( *(char**) option[i-1].target, last); XtAddEventHandler(option[i-1].handle, KeyReleaseMask, False, ColorChanged, (XtPointer)(intptr_t) i-1); } @@ -1797,11 +1804,97 @@ void IcsTextProc(w, event, prms, nprms) GenericPopUp(textOptions, _("ICS text menu"), 3); } +static char *commentText; +static int commentIndex; +void ClearComment P((int n)); +extern char commentTranslations[]; + +void NewComCallback(int n) +{ + ReplaceComment(commentIndex, commentText); +} + +void SaveChanges(int n) +{ + Arg args[16]; + XtSetArg(args[0], XtNstring, &commentText); + XtGetValues(currentOption[0].handle, args, 1); + ReplaceComment(commentIndex, commentText); +} + +Option commentOptions[] = { +{ 0xD, 200, 300, NULL, (void*) &commentText, "", NULL, TextBox, "" }, +{ 0, 0, 0, NULL, (void*) &ClearComment, NULL, NULL, Button, "clear" }, +{ 0, 1, 0, NULL, (void*) &SaveChanges, NULL, NULL, Button, "save changes" }, +{ 0, 1, 0, NULL, (void*) &NewComCallback, "", NULL, EndMark , "" } +}; + +void ClearComment(int n) +{ + XtCallActionProc(commentOptions[0].handle, "select-all", NULL, NULL, 0); + XtCallActionProc(commentOptions[0].handle, "kill-selection", NULL, NULL, 0); +} + +void NewCommentPopup(char *title, char *text, int index) +{ + Widget edit; + Arg args[16]; + + 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); + } + commentText = text; + commentIndex = index; + MarkMenu("menuView.Show Comments", 1); + if(GenericPopUp(commentOptions, title, 1)) + XtOverrideTranslations(commentOptions[0].handle, XtParseTranslationTable(commentTranslations)); +} + +static char *tagsText, *msgText; + +void NewTagsCallback(int n) +{ + ReplaceTags(tagsText, &gameInfo); +} + +void changeTags(int n) +{ + Arg args[16]; + XtSetArg(args[0], XtNstring, &tagsText); + XtGetValues(currentOption[0].handle, args, 1); + ReplaceTags(tagsText, &gameInfo); +} + +Option tagsOptions[] = { +{ 0xD, 200, 250, NULL, (void*) &tagsText, "", NULL, TextBox, "" }, +{ 0, 0, 0, NULL, NULL, NULL, NULL, Label, "" }, +{ 0, 0, 0, NULL, (void*) &changeTags, NULL, NULL, Button, "save changes" }, +{ 0, 1, 0, NULL, (void*) &NewTagsCallback, "", NULL, EndMark , "" } +}; + +void NewTagsPopup(char *text, char *msg) +{ + Widget edit; + Arg args[16]; + + if(shells[2]) { // if already exists, alter title and content + XtSetArg(args[0], XtNstring, text); + XtSetValues(tagsOptions[0].handle, args, 1); + } + tagsText = text; + tagsOptions[1].textValue = msg; + MarkMenu("menuView.Show Tags", 2); + GenericPopUp(tagsOptions, _("Tags"), 2); +} + extern char ICSInputTranslations[]; char *icsText; Option boxOptions[] = { -{ 0, 20, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" }, +{ 0, 30, 400, NULL, (void*) &icsText, "", NULL, TextBox, "" }, { 0, 3, 0, NULL, NULL, "", NULL, EndMark , "" } }; @@ -1832,6 +1925,49 @@ void InputBoxPopup() XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(ICSInputTranslations)); } +void TypeInProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + Arg args[2]; + String val; + + if(prms[0][0] == '1') { + XtSetArg(args[0], XtNstring, &val); + XtGetValues(boxOptions[0].handle, args, 1); + TypeInDoneEvent((char*)val); + } + PopDown(0); +} + +char moveTypeInTranslations[] = + "Return: TypeInProc(1) \n" + "Escape: TypeInProc(0) \n"; + +void PopUpMoveDialog(char firstchar) +{ + static char buf[2]; + buf[0] = firstchar; icsText = buf; + if(GenericPopUp(boxOptions, _("Type a move"), 0)) + XtOverrideTranslations(boxOptions[0].handle, XtParseTranslationTable(moveTypeInTranslations)); +} + +void MoveTypeInProc(Widget widget, caddr_t unused, XEvent *event) +{ + char buf[10], keys[32]; + KeySym sym; + KeyCode metaL, metaR; + int n = XLookupString(&(event->xkey), buf, 10, &sym, NULL); + XQueryKeymap(xDisplay,keys); + metaL = XKeysymToKeycode(xDisplay, XK_Meta_L); + metaR = XKeysymToKeycode(xDisplay, XK_Meta_R); + if ( n == 1 && *buf > 32 && !(keys[metaL>>3]&1<<(metaL&7)) && !(keys[metaR>>3]&1<<(metaR&7))) // printable, no alt + PopUpMoveDialog(*buf); + +} + void SettingsPopUp(ChessProgramState *cps) {