Chores Most GUI applications have all one thing in common, which is they wait
for something to happen and for most application this can be a very
long time. FOX allows you to do something usefull with that time by
having a feature called chores. Whenever a application is idling, FOX
can send out a chore message to indicate that it is idling. By default
no such message is send out. In order to receive such a message you
need to register it with FXApp:
getApp()->addChore(target,selector [,userdata]);
Notice that chores are registered by their target and selector id.
Adding a duplicate chore will replace the already registered chore.
Similary you can remove a chore by its target and selector:
getApp()->removeChore(target,selector);
Once a chore
is fired, it is automatically removed by the application. Chores only fire once. It is important that you remove any outstanding
chores before quiting the application or when the target objects get
removed before the chore is fired.
Once registered, FXApp will send out a SEL_CHORE message to the
specified target and selector id. The void pointer will contain any
userdata specified when registering the chore.
In the message map of the receiving object add a message
handler:
FXMAPFUNC(SEL_CHORE,FXYourObject::ID_MY_CHORE,FXYourObject::onChore),
And the message handler itself will look something like this:
long FXYourObject::onChore(FXObject * obj, FXSelector sel,void*){ return 1; }
A common way to reschedule the chore once fired is to add this
to end of the message handler itself. A word of caution, in case of
chores this will result in 100% cpu activity, disallowing other
applications to do their stuff. In case you still need this kind of
functionality it is better to use timer instead of chore, giving other
applications time to process their own stuff.
TimersNow that you know how chores work, timers should be really easy. Like
chores they have a very similar api and behaviour. Timers will also
only fire once. To schedule a timer call:
getApp()->addTimeout(target,selector,milliseconds [,userdata]);
To remove a timer before it is fired:
getApp()->removeTimeout(target,selector);
There are two additional apis for timers:
hastimer = getApp()->hasTimeout(target,selector);
and
remainingmilliseconds = getApp()->remainTimeout(target,selector);
|