From 96554759a276e3b972fffb23042f68485c7805e7 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 13 Feb 2010 15:34:04 +0100 Subject: [PATCH] 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. --- xoptions.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-) 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) -- 1.7.0.4