Re: XForms: status bar

From: spl@ncmir.ucsd.edu
Date: Wed Mar 06 2002 - 14:24:39 EST


# To subscribers of the xforms list from spl@ncmir.ucsd.edu :

> Can someone point me in the right direction? I am looking for a status
> bar that I can put on my form while some other process is working in the
> background. I've looked in the manual and did a search on the list
> archive for 'status', 'bar' and 'value' with no luck. Any and all help
> is appreciated.

You mean a progress bar?

There is no such thing, exactly, but you can use a Fill Slider as
shown in the following example.

#include <stdio.h>
#include <forms.h>
#include <stdlib.h>

typedef struct {
        FL_FORM *try;
        void *vdata;
        char *cdata;
        long ldata;
        FL_OBJECT *progress;
} FD_try;

extern FD_try * create_form_try(void);

struct s {

    FL_OBJECT *obj;
    double fraction;
    
};

void timeout( int id, void *data )

{

    struct s *progress = ( struct s *) data;

    progress->fraction += 0.01;

    fl_set_slider_value( progress->obj, progress->fraction );

    if ( progress->fraction < 1.0 )
        fl_add_timeout( 100, timeout, data );

}

void do_it_cb(FL_OBJECT *ob, long data)

{

    static struct s progress;

    progress.obj = ( ( FD_try *) ob->form->fdui )->progress;
    fl_add_timeout( 100, timeout, &progress );

}

void bail_cb(FL_OBJECT *ob, long data)
{

    exit( 0 );

}

FD_try *create_form_try(void)
{
    FL_OBJECT *obj;
    FD_try *fdui = (FD_try *) fl_calloc(1, sizeof(*fdui));
    
    fdui->try = fl_bgn_form(FL_NO_BOX, 310, 120);
    obj = fl_add_box(FL_FLAT_BOX,0,0,310,120,"");
    fdui->progress =
        obj =
        fl_add_slider(FL_HOR_FILL_SLIDER,30,15,260,30,
                      "You call this progress?");
    fl_set_object_boxtype(obj,FL_FLAT_BOX);
    fl_set_object_color(obj,FL_COL1,FL_GREEN);
    fl_set_object_lsize(obj,FL_LARGE_SIZE);
    fl_set_slider_size(obj, 0.15);
    obj = fl_add_button(FL_NORMAL_BUTTON,5,75,90,40,"Do it");
    fl_set_object_callback(obj,do_it_cb,0);
    obj = fl_add_button(FL_NORMAL_BUTTON,215,75,90,40,"Bail");
    fl_set_object_callback(obj,bail_cb,0);
    fl_end_form();
    
    fdui->try->fdui = fdui;

  return fdui;
}

int main(int argc, char *argv[])
{
 
    FD_try *try;
    
    fl_initialize(&argc, argv, 0, 0, 0);
    
    try = create_form_try();

    fl_set_slider_value( try->progress, 0.0 );
    fl_show_form(try->try,FL_PLACE_CENTER,FL_FULLBORDER,"try");
    fl_do_forms();

    exit( 0 );

}

                                                        spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://world.std.com/~xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/



This archive was generated by hypermail 2b29 : Wed May 01 2002 - 13:54:15 EDT