Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!uunet!mcsun!ukc!edcastle!helium!gordonc From: gordonc@aifh.ed.ac.uk (Gordon Cameron (RA DAI)) Newsgroups: comp.windows.x Subject: Re: Xview: Interrupting a Notify Procedure Message-ID: <1991Apr24.211819.26355@aifh.ed.ac.uk> Date: 24 Apr 91 21:18:19 GMT References: <3098@sparko.gwu.edu> Organization: Dept AI, Edinburgh University, Scotland Lines: 93 From article <3098@sparko.gwu.edu>, by darken@seas.gwu.edu: > Here's the problem: > Say I have a panel with 2 buttons on it. When I hit > button #1, I want to start a process which will continue > until button #2 is hit. How can I interrupt the notify > procedure of button #1 when #2 is hit? As I see it, > the pressing of #2 will not be recognized until #1 > is completed processing. I looked into events in > addition to notifications but nothing works yet and > the manual is rather shady in this area. Thanks in > advance! > You could try something like this : /* Globals */ int program_state , finished ; main() { --- --- program_state=DOING_LOOP ; while (running==TRUE) { xv_main_loop(----) if (program_state=DOING_SOMETHING) { /* (1) */ do_something() ; clean_up() ; /* (2) */ program_state=DOING_LOOP ; } } } { program_state=DOING_SOMETHING ; notify_stop() ; } { finished=TRUE ; } do_something() { finished=FALSE ; /* Insert your code here and in it periodically do this... notify_dispatch() ; if (finished==TRUE) { printf ("Finished off !!!\n") ; return ; // This takes you back to (2) in main } */ } What this does is to run the routine 'do_something' when you press the button #1. How ?? Pressing the button triggers the callback which sets a global variable, and calls notify_stop. The notifier returns to the top level, and then notify_start and xv_main_loop return. This leaves you in position (1) in the code. Since you have set the variable program_state, the routine 'do something' executes. Periodically in this routine, you should make calls to notify_dispatch(), which will make a single pass through the notify cycle. If you have pressed button #2, then all you will have done is to set the variable finished to TRUE. This is detected, and 'do_something' returns so you end up at point (2). You can now do whatever you want before continuing with the application (perhaps doing some graphical output). xv_main_loop then gets called again, and so you are back to where you started. I've set a variable running, which when you unset and do xv_destroy(Frame) will have the effect of quitting the application. (To be complete you should write a notify_interspose_destroy_func which sets the variable running to FALSE, so the window quit works) Hope this is useful - If you're interested, get the O'Reilly book 'XView Programming Manual' by Dan Heller, as its excellent. (see pp 397-400) Gordon Cameron, Department of Artificial Intelligence, University of Edinburgh, Scotland e-mail : gordonc@uk.ac.edai.fh