From: H.G. Muller Date: Sat, 13 Feb 2010 14:34:04 +0000 (+0100) Subject: Fix XB crash on giving keyboard focus to non-text widget X-Git-Tag: v4.4.3.20100220~3 X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=commitdiff_plain;h=96554759a276e3b972fffb23042f68485c7805e7 Fix XB crash on giving keyboard focus to non-text widget In the Engine-Settings dialog SetFocus() could be called for non-text widgets, and this made XawTextSetInsertionPoint() croak. Setting the insertion point to the end in SetFocus() was a bad ide anyway, as it interfered with copying from the engine-output window, which would uncontrollably scroll on getting focus. It is solved now by setting the insertion point already on creation of the text widgets. --- diff --git a/xoptions.c b/xoptions.c index 73dda5f..1504048 100644 --- a/xoptions.c +++ b/xoptions.c @@ -104,7 +104,6 @@ void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b) } XtSetArg(args, XtNdisplayCaret, True); XtSetValues(w, &args, 1); - XawTextSetInsertionPoint(w, 9999); // position cursor at end XtSetKeyboardFocus((Widget) data, w); previous = w; } @@ -393,7 +392,7 @@ void TimeControlPopUp() XtSetArg(args[j], XtNright, XtChainRight); j++; XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNwidth, 85); j++; -// XtSetArg(args[j], XtNheight, 20); j++; + XtSetArg(args[j], XtNinsertPosition, 9999); j++; tcTime = XtCreateManagedWidget("TC", asciiTextWidgetClass, form, args, j); XtAddEventHandler(tcTime, ButtonPressMask, False, SetFocus, (XtPointer) popup); @@ -763,7 +762,7 @@ void EnginePopUp() XtSetArg(args[j], XtNright, XtChainLeft); j++; XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNwidth, 60); j++; -// XtSetArg(args[j], XtNheight, 20); j++; + XtSetArg(args[j], XtNinsertPosition, 9999); j++; engThreshold = XtCreateManagedWidget("Threshold", asciiTextWidgetClass, form, args, j); XtAddEventHandler(engThreshold, ButtonPressMask, False, SetFocus, (XtPointer) popup); @@ -1236,6 +1235,7 @@ void UciPopUp() XtSetArg(args[j], XtNright, XtChainRight); j++; XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNwidth, i&1 ? 245 : 50); j++; + XtSetArg(args[j], XtNinsertPosition, 9999); j++; if(i&1) { XtSetArg(args[j], XtNstring, * (char**) controlDesc[i].ptr ? * (char**) controlDesc[i].ptr : ""); j++; @@ -1478,7 +1478,7 @@ void CreateComboPopup(parent, name, n, mb) void SettingsPopUp(ChessProgramState *cps) { Arg args[16]; - Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL; + Widget popup, layout, dialog, edit=NULL, form, oldform, last, b_ok, b_cancel, leftMargin = NULL, textField = NULL; Window root, child; int x, y, i, j, height, width, h, c; int win_x, win_y; @@ -1535,9 +1535,10 @@ void SettingsPopUp(ChessProgramState *cps) XtSetArg(args[j], XtNright, XtChainRight); j++; XtSetArg(args[j], XtNresizable, True); j++; XtSetArg(args[j], XtNstring, cps->option[i].type==Spin ? def : cps->option[i].textValue); j++; + XtSetArg(args[j], XtNinsertPosition, 9999); j++; edit = last; cps->option[i].handle = (void*) - (last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j)); + (textField = last = XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j)); XtAddEventHandler(last, ButtonPressMask, False, SetFocus, (XtPointer) popup); if(cps->option[i].type == TextBox) break; @@ -1633,7 +1634,7 @@ void SettingsPopUp(ChessProgramState *cps) SettingsUp = True; previous = NULL; - if(edit)SetFocus(edit, popup, (XEvent*) NULL, False); + if(textField)SetFocus(textField, popup, (XEvent*) NULL, False); } void FirstSettingsProc(w, event, prms, nprms)