andrew@epps.kodak.com (Andrew Lukasik) (03/12/91)
Does anyone have experiece changing XmTextField background and foreground colors? I am getting "X Error or failed request" errors from deep down in Motif. My application is trying to do simple integer validation on an XmTextField motionVerifyCallback. If the user enters a character into this field I want to provide visual feeback of the error by briefly changing the backround color to red and then back to it's original value. I've gotten this to work nicely except that on occasion I get Xerrors and die. The color will change to red and then back for me but when I go to add the next valid character (an integer) I get an X error and croak. This does not always happen on the first try. I've managed to isolate the source of the error to somewhere down inside Motif by doing the following: I've run my application in "-synchronous" mode and the error I get is: X Error of failed request: BadDrawable (invalid Pixmap or Window parameter) Major opcode of failed request: 62 (X_CopyArea) Minor opcode of failed request: 0 Resource id in failed request: 0x13000ad Serial number of failed request: 1756 Current serial number in output stream: 1757 a breakpoint in 'exit()' allows me to reveal the following stack trace: (dbx) where exit(0x1) at 0xab11c _XDefaultError() at 0xa7005 _XError(0x128b2c, 0xdfff07c) at 0xa7067 _XReply() at 0xa64e1 XSync(0x128b2c, 0x0) at 0xa497d _XSyncFunction(0x128b2c) at 0xa49c7 XCopyArea(0x128b2c, 0x13000ad, 0x1300074, 0x16776c, 0x0, 0x0, 0x5, 0xe, 0x13, 0x4) at 0x9c5e1 `TextF`PaintCursor() at 0x68051 ChangeBlinkBehavior(0x179ba8, 0x0) at 0x68219 TextFieldExpose(0x179ba8, 0xdfff610, 0x12a040) at 0x6d2b5 SendExposureEvent() at 0x86071 CompressExposures(0xdfff610, 0x179ba8, 0x12e8e0) at 0x85ffb DispatchEvent() at 0x85d49 DecideToDispatch(0xdfff610) at 0x862b5 XtDispatchEvent(0xdfff610) at 0x863e5 XtAppMainLoop(0x127c34) at 0x86663 XtMainLoop() at 0x8663b MainLoop__17DialogInterpreterFv(__0this = 0xe007e), line 290 in "DialogC.C" main(__0argc = 2, __0argv = 0xdfff6a8, 0xdfff6b4), line 87 in "Dialog.C" I suspect from looking at this that there may be some bug in Motif's handling of the exposure caused by the background repainting. If I turn the text cursor off alltogether it works just fine, 'cept you can't see where you're about to type :-(. I tried turning the cursor off before changing the background and on again after changing it back with limited success. This seemd to work but when I complicated things more by posting an warning dialog after the third error the crash returned. I tried various combinations of turning the cursor on and off from various places but to no avail. So, Is this a known bug? Am I doing something dreadfully wrong? Anyone else experience this problem? I've enclosed a snippet of code showing how I've attempted to do this. I had to add the XtAppAddTimeOut() so server could grab a few cycles to change the background color for me. Could this be part of the problem?? . . . XmTextVerifyCallbackStruct *xmt; XmTextBlockRec *tblk; xmt = (XmTextVerifyCallbackStruct *)call_data; tblk = (XmTextBlockRec *)xmt->text; . . . . if(!isdigit(*(tblk->ptr))) { // when we set the doit field to false this prevents // the character from being inserted into the widget xmt->doit = FALSE; errorCount++; if (errorCount >= errorThreshold) { // if our error count passes the threshold value // popup a warning, // change the background and foreground color of // the widget. XtVaSetValues(widgetId, XmNbackground, warningColor, XmNforeground, bgColor, NULL); // leave the colors inverted till the user takes // down the warning di.PopUpValidateIntegerWarning(); } else { // Just quickly change the background color // so the user has visual feedback that he // did something wrong. XtVaSetValues(widgetId, XmNbackground, warningColor, XmNforeground, bgColor, NULL); // Call a time out to let the color change // take effect. // rePaint will be called affter the timeout // and will change the color back to default. // Pass the widgetId so we can retreive ui widget // id and use it to get the colors to restore. XtAppAddTimeOut(XtWidgetToApplicationContext(widgetId), 100, (XtTimerCallbackProc) rePaint, (XtPointer) widgetId); } } // end is not a good value (is not an integer) . . . XtTimerCallbackProc rePaint(Widget w) { XtPointer uiWidget; // Get the ui widget object id out of the motif widget XtVaGetValues(w, XmNuserData, &uiWidget, NULL); // The widget has the correct (original) color id's stored XtVaSetValues(w, XmNbackground, ((GenericWidget *) uiWidget)->bgColor, XmNforeground, ((GenericWidget *) uiWidget)->fgColor, NULL); } Thanks in advance for any help. I will glady sumarize and post to the net any responses. Andrew -- ------------------------------------------------------------------------- Andrew Lukasik <andrew@epps.kodak.com> Voice: 508-670-4019 Atex Advanced Publishing Systems Fax: 508-670-4033 Atex, Inc; 165 Lexington St. MS 400/165L; Billerica MA 01821 -- ------------------------------------------------------------------------- Andrew Lukasik <andrew@epps.kodak.com> Voice: 508-670-4019 Atex Advanced Publishing Systems Fax: 508-670-4033 Atex, Inc; 165 Lexington St. MS 400/165L; Billerica MA 01821