Path: utzoo!attcan!uunet!ginosko!usc!bloom-beacon!EXPO.LCS.MIT.EDU!kit From: kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) Newsgroups: comp.windows.x Subject: Re: Changing label Message-ID: <8908282229.AA01895@expo.lcs.mit.edu> Date: 28 Aug 89 22:29:38 GMT References: <4344@cps3xx.UUCP> Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 94 > I think XFlush() must be treated differently from other requests (doesn't have > to go the the buffer), because if it does then how can it flush the buffer ? It turns out that not only must the X buffer be flushed, but the toolkit needs to dispatch an expose event to the label widget. The means that a simple call to XFlush() will not do the trick. > Any other suggestion ? You bet! Here is a short example program that seems to work correctly. Please keep in mind that any kind of event dispatching and blocking like this is at best a bit kludgy, and at worst very dangerous. I do not suggest using code that blocks, but if you must here is an example. You will notice that I have put in a fail safe so that if the event never comes you will not end up with a frozen application. Chris D. Peterson MIT X Consortium Net: kit@expo.lcs.mit.edu Phone: (617) 253 - 9608 Address: MIT - Room NE43-213 ------------------ cut here ---------------------------------------------- #include #include #include #include #include #include #define DELAY 1000 /* This value seems to work for my network, your mileage may vary. */ void ChangeLabel(w, str) Widget w; char * str; { Arg args[1]; XEvent event; int count; XtSetArg(args[0], XtNlabel, str); XtSetValues(w, args, (Cardinal) 1); while ( (count < DELAY) && !XCheckTypedWindowEvent(XtDisplay(w), XtWindow(w), Expose, &event) ) count++; /* Keeps the application from seizing up if the window isn't visable. */ XtDispatchEvent( &event ); XFlush(XtDisplay(w)); sleep(5); } /* ARGSUSED */ void Activate(w, closure, call_data) Widget w; caddr_t closure, call_data; { ChangeLabel((Widget) closure, "one"); ChangeLabel((Widget) closure, "two"); ChangeLabel((Widget) closure, "three"); printf("Done.\n"); } void main(argc, argv) int argc; char **argv; { Widget toplevel, box, command, label; toplevel = XtInitialize( NULL, "Demo", NULL, (Cardinal) 0, &argc, argv ); box = XtCreateManagedWidget( "box", boxWidgetClass, toplevel, NULL, (Cardinal) 0); label = XtCreateManagedWidget( "label", labelWidgetClass, box, NULL, (Cardinal) 0); command = XtCreateManagedWidget( "command", commandWidgetClass, box, NULL, (Cardinal) 0); XtAddCallback(command, XtNcallback, Activate, (caddr_t) label); XtRealizeWidget(toplevel); XtMainLoop(); }