consider the attached piece of code,
if the button "sleep" is pressed, it will first deactivate the "hello"
button and sleep for a while. after that the "hello" button is
activated again.
the problem at the instant the "hello" button is activated again, it
receives buffered mouse events that are triggered during time of
deactivation.
for example, if I first press "sleep" then press "hello" several times
when it is deactivated, I will get something like:
tyt$ ./fltk_deactivate_problem
hello
hello
hello
hello
hello
when the button is deactivated it correctly renders itself gray in
color, and I called Fl::flush(), but it still doesnt help.
what I want is during a lengthy operation ( simulated by sleep()), the
UI is deactivated to prevent users pressing the buttons 1000 times.
when the operation is finished, the UI will be activated again.
#include <stdio.h>
#include <unistd.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
Fl_Button* b1;
void hellocb(Fl_Widget *, void *)
{
printf("hello\n");
}
void sleepcb(Fl_Widget *, void *)
{
b1->deactivate();
Fl::flush();
sleep(3);
Fl::flush();
b1->activate();
}
int main( int argc, char** argv)
{
Fl_Window *window = new Fl_Window(320,65);
b1 = new Fl_Button(20,20, 200, 25, "hello");
Fl_Button *b2 = new Fl_Button(220,20, 80, 25, "sleep(3)");
b1->callback(hellocb,0);
b2->callback(sleepcb,0);
window->end();
window->show();
return Fl::run();
}
--Chris T
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk