Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!pp!kauai!duanev From: duanev@kauai.ACA.MCC.COM (Duane Voth) Newsgroups: comp.windows.x Subject: Re: help (with a popup prompt design) Summary: but what if you hate implementing event driven state machines... Message-ID: <304@kauai.ACA.MCC.COM> Date: 16 Aug 89 22:35:22 GMT References: <3982@ncar.ucar.edu> <8908151941.AA26642@expo.lcs.mit.edu> Organization: MCC, Austin, TX Lines: 75 In article <8908151941.AA26642@expo.lcs.mit.edu>, converse@EXPO.LCS.MIT.EDU (Donna Converse) writes: > > > I want to have a generic warning routine, call it display_warning(), > > that when invoked will popup and display a warning message > > (under the Xt instrinics) and require the user to select a proceed or > > cancel button. The problem > > is that I want display_warning() to return a value depending on the > > user's selection. How do I get display_warning() to wait until a selection > > has been made before returning?. > > I think the programming model for control flow needs to be changed from a > computational one to an event driven model. The user is out there doing > stuff that causes your program to get notification of events. Your program > cannot control or anticipate the order of events, or the timing between > events. Instead, your code is a collection of responses to events, with > callbacks and client data and some global variables as "chewing gum and, > paperclips" holding it all together. I ran into this same problem. A function like display_warning() forces the user to focus his attention on a very specific point. The application is basically helpless until the user deals with the warning. In addition, the warining popup focuses input thus severely restricting the kinds of "application" events that occur. So why force returning all the way back to the main event handler. Bottom line is: the application code looks MUCH nicer if a function like display_warning() can return a 1 or a 0. The way I did this is as follows: #define WAITING 0 #define PROCEED 1 #define CANCEL 2 static int warning_response; proceed_button_callback() { warning_response = PROCEED; } cancel_button_callback() { warning_response = CANCEL; } display_warning() { XEvent event; /* popup warning window... */ warning_response = WAITING; while (warning_response == WAITING) { XtAppNextEvent(appContext, &event); XtDispatchEvent(&event); } /* popdown and cleanup */ return(warning_response); } Clean, efficient, functional. duane -- --- duane voth duanev@mcc.com ---- ALL systems are arbitrary! --- effectiveness is the measure of Truth --