Re: XForms: how does fl_show_question() do it ?

Stephen Langer (langer@cam.nist.gov)
Wed, 8 Jul 1998 18:37:09 -0400

# To subscribers of the xforms list from "Stephen Langer" <langer@cam.nist.gov> :

> # To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve
Lamont) :
>
> > Sorry. You want to use fl_check_forms() or fl_check_only_forms()
instead.
> > That's what works for me.
>
> I think that would create a "buzz loop."
>
[...]
>
> If you used fl_check_forms() in this case, the do-while loop would
> buzz and eat the CPU since fl_check_forms() and its ilk return
> immediately if there is no queued event. fl_do_forms() blocks until
> an event occurs, which, in this case, is the desired behavior.
>

I just checked, and it's not eating CPU. Here are some code fragments:

QuitForm is a C++ class containing XForms objects and some flags. The
relavant ones are int quitnow and int quitcancel.
When the user wants to quit the program, this routine is invoked:

int quitcmd() {
fl_deactivate_all_forms();
QuitForm qf;
qf.makevisible();
do
fl_check_only_forms();
while(!qf.done);
fl_activate_all_forms();
return qf.quitnow;
// hiding the form is done by the QuitForm destructor
}

The form has various buttons which have simple callbacks which look like
this:

void QuitForm::CB_quitnow(FL_OBJECT*, long ptr) {
((QuitForm*) ptr)->quitnow = 1;
((QuitForm*) ptr)->done = 1;
}

void QuitForm::CB_quitcancel(FL_OBJECT*, long ptr) {
((QuitForm*) ptr)->quitnow = 0;
((QuitForm*) ptr)->done = 1;
}

(This was written before I learned how to use the pointers in the fdui
structure effectively, so the "this" pointer is being passed as the long
arg to the callback.)

It works, it's simple, and it doesn't hog the CPU.

-- Steve (the other Steve)

-- 
-- EMail: stephen.langer@nist.gov                    Phone: (301) 975-5423 --
-- WWW:  http://math.nist.gov/mcsd/Staff/SLanger/    Fax:   (301) 990-4127 --
-- Mail: Building 820 Room 365; NIST; Gaithersburg, Md          20899-0001 --
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil   or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/