Re: XForms: Few questions...

Steve Lamont (
Thu, 16 Oct 97 08:06:45 PDT

To subscribers of the xforms list from (Steve Lamont) :

> 1. My prog needs to loop with few routines that reads data from system.
> I must also use in XForms that fl_do_forms() function, and it contains
> also loop inside. fl_do_forms() exits only when exit button is pressed,
> but my prog needs to read that system-data from system really often (or,
> it depends, does it read data, or not, but call those reading
> functions).

There are several ways to do this and which way is best depends upon
your situation and (no offense intended) level of programming

The simplest is to not call fl_do_forms() but call fl_check_forms()
somewhere in your loop. It is basically one iteration of the
fl_do_forms() loop. You need to call this routine fairly often in
order to maintain interactivity.

The second way to do what you want is to register an idle callback.
It will be called when XForms is not handling interactive functions
(which is most of the time). It is intended for background type
tasks. You can make any XForms call from inside this callback.
Generally what you'll do is make an iteration or two of your loop and
then return control to XForms. I use this method for such things a
background image rendering.

There are also timer callbacks (these are separate beasts from Timer
Objects -- don't confuse the two), which are called after a timer
expires. These are not repetitively called -- they're one shots and
you need to register a new callback if you want the timer to fire
again. For periodic callbacks, use an idle callback and just set the
delta to whatever suits you. Note that neither of these two methods
are particularly accurate -- there's significant slop in the period
between calls. Of course, Unix timers are pretty lousy in general, so
if you want real time performance, you're going to be on a real time
operating system such as LynxOS or its ilk anyhow.

If you are servicing some sort of asynchronous I/O, you can set an I/O
callback which will only be invoked when there's activity on your file
descriptor. This is useful for servicing things like socket
connections or devices which only present data in spurts. You *don't*
want to use this for reading a file off disk.

Finally, there are signal callbacks if your application is signal
driven. These are invoked after a signal arrives. Note that this is
different than setting a signal handler with signal() or sigvec(). In
an XForms signal callback you can make any call you wish since the
callback is dispatched by XForms rather than the operating system.
You are very limited in what you safely can do in a Unix signal
handler since you have no idea what has been interrupted -- X and
XForms, for instance, are non-reentrant, so making X or XForms calls
from within a Unix signal handler. [This is probably more than you
wanted to know about this subject.]

The IO callback sounds as if it will do what you want to do with only
a small amount of redesigning your application.

I personally strongly recommend using one or more of the callback
approaches rather than breaking the programming model by using
fl_check_forms(). I know, however, that others on this mailing list
disagree with me on this. Refer to the sections on idle callbacks,
asynchronous I/O, signal callbacks, and timer callbacks in the manual
for complete information.

> 2. My prog needs to monitor keyboard while system has XForms' input
> routine. I need only to know how to know that tab, arrow up/down is
> pressed.

You may need to set a raw callback for KeyPress Events with
fl_register_raw_callback(). See my previous posting on capturing
resize (ConfigureNotify) events for a discussion of how to set this up.

> 3. How can I use multiple colours in browser (like printing ANSI on
> text-based applications)?

The Browser Object has limited color modification on a per-line
basis. If you want something more sophisticated you'll probably have
to roll your own Free or custom Object.

> 4. How can I disable browser's left-right slide bar? Maybe should ask,
> how can I cut lines after last word that fits to browser and enter words
> after that to next line (and it should also look when comes last word
> that fits, etc etc)...

There are routines to turn off to the scroll bars. Refer to
fl_set_browser_hscrollbar(). You can also use the
fl_get_string_width() function to find out how long your text string
will be and act accordingly.

To unsubscribe, send the message "unsubscribe" to or see
Xforms Home Page:
List Archive: