Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!snorkelwacker.mit.edu!bloom-beacon!unislc.UUCP!ctk From: ctk@unislc.UUCP (Carol Toomer-Keay) Newsgroups: comp.windows.x Subject: (none) Message-ID: <9012171804.AA29328@unislc.UUCP> Date: 17 Dec 90 18:04:38 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 190 Help! I'm developing a demo using Motif and have run into a strange problem. I need to create a form containing 2 label widgets. Then I need to be able to change the background color of each label in the following manner: Change background color of label 1. Sleep a few seconds Change background color of label1 one back to original color Sleep a few seconds Change background color of label 2. Sleep a few seconds Change background color of label2 one back to original color What actually happens is the text in the label disapeers until all the color changing is complete! Depending on how I try to work around this, the color changes might not be visible. I've decided all of this occurs because the expose event is lagging far behind the call to XtSetValues. It also looks like XtSetValues calls XClearArea which is why the text disapeers in the first place. (See code below.) I've tried to use Xlib instead of XtSetValues to do this and have the same problem. I even tried to send an expose event to the window and still no luck. Has anyone seen this before? Is it a known bug or feature? Is there a workaround? I need to get this demo working ASAP so timing is critical. Any and all workarounds or ideas are welcome. Note: I'm using X11R3, Motif 1.0, running on a Unisys 6050, displaying on a Unisys workstation. Many Thanks, Carol ctk@unislc ------------- Begin Code Sample -------------------------- #include #include #include #include #include #include #include #include #include #include XmString string; XmStringCharSet CharSet = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET; XColor red, blue; unsigned long Black; Colormap cmap; Display *display; int screen; Arg args[20]; int n; Widget Shell1 = NULL; Widget form = NULL; Widget label = NULL; Widget label2 = NULL; Widget ErrorDialog = NULL; void highlight(); void chg_color1(); void chg_color2(); void main (argc, argv) int argc; char **argv; { Arg args[20]; int n; Shell1 = XtInitialize (argv[0], "TryMe", NULL, 0, &argc, argv); n = 0; XtSetArg(args[n], XmNwidth, 600); n++; XtSetArg(args[n], XmNheight, 700); n++; XtSetValues(Shell1, args, n); /* get the display and screen variables */ display = XtDisplay(Shell1); screen = DefaultScreen(display); cmap = DefaultColormap(display, screen); Black = BlackPixel(display, screen); if (XParseColor (display, cmap, "blue", &blue) == 0) { printf("error from color parse\n"); } if (XAllocColor(display, cmap, &blue) == 0) { printf("error from color alloc\n"); } if (XParseColor (display, cmap, "red", &red) == 0) { printf("error from color parse\n"); } if (XAllocColor(display, cmap, &red) == 0) { printf("error from color alloc\n"); } n = 0; form = XmCreateForm(Shell1, "form", args, n); XtManageChild(form); n = 0; string = XmStringLtoRCreate("Merry Christmas", CharSet); XtSetArg(args[n], XmNlabelString, string); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNtopPosition, 25); n++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNbottomPosition, 50); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNleftPosition, 25); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNrightPosition, 50); n++; XtSetArg(args[n], XmNborderWidth, 8); n++; label = XmCreateLabel(form, "label", args, n); XtManageChild(label); XmStringFree(string); n = 0; string = XmStringLtoRCreate("Happy New Year", CharSet); XtSetArg(args[n], XmNlabelString, string); n++; XtSetArg(args[n], XmNtopAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNtopPosition, 50); n++; XtSetArg(args[n], XmNbottomAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNbottomPosition, 75); n++; XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNleftPosition, 50); n++; XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++; XtSetArg(args[n], XmNrightPosition, 75); n++; XtSetArg(args[n], XmNborderWidth, 8); n++; label2 = XmCreateLabel(form, "label", args, n); XtManageChild(label2); XmStringFree(string); RUNSUB(); XtRealizeWidget(Shell1); XtMainLoop(); } RUNSUB() { n = 0; XtSetArg(args[n], XmNwidth, 200); n++; XtSetArg(args[n], XmNheight, 200); n++; XtSetArg(args[n], XmNdialogType, XmDIALOG_ERROR); n++; XtSetArg(args[n], XmNautoUnmanage, FALSE); n++; ErrorDialog = XmCreateErrorDialog(Shell1, "ErrorDialog", args, n); XtManageChild(ErrorDialog); XtAddCallback(ErrorDialog, XmNokCallback, highlight, NULL ); } void highlight() { chg_color1(label); sleep(3); chg_color2(label); chg_color1(label2); sleep(3); chg_color2(label2); return; } void chg_color1(widget) Widget widget; { n = 0; string = XmStringLtoRCreate("Merry ChrisMoose", CharSet); XtSetArg(args[n], XmNlabelString, string); n++; XtSetArg(args[n], XmNbackground, red.pixel); n++; XtSetValues(widget, args, n); XSync(display, 0); XFlush(display); return; } void chg_color2(widget) Widget widget; { XtSetArg(args[n], XmNbackground, blue.pixel); n++; XtSetValues(widget, args, n); return; }