RE: XForms: Problems with function generate_menu

From: Steve Lamont (spl@ncmir.ucsd.edu)
Date: Wed Feb 05 2003 - 14:49:03 EST

  • Next message: Nicolas CASTAGNE: "XForms: Some help about threads and Xforms and OpenGL..."

    # To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :

    > Where StrReasons is the char array holding the labels for the popupmenu and
    > ShowReason is the callback which writes into a logfile

    Here's a quick and very dirty piece of test code I lashed together (5
    yard penalty and loss of down for making me do this rather than
    supplying your own). It's not intended to be pretty or well
    structured and it isn't, but it works for me.

                                                            spl

                                    - - -

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

    #include <forms.h>

    char StrReasons[8][512];

    int ShowReason( int reason )

    {

        fprintf( stderr, "reason %d = %s\n", reason, StrReasons[reason - 1] );
        return 0;

    }

    static FL_PUP_ENTRY fdchoice_0[] =
    {
        { StrReasons[0] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[1] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[2] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[3] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[4] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[5] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[6] , ShowReason, "", FL_PUP_NONE},
        { StrReasons[7] , ShowReason, "", FL_PUP_NONE},
        {0}
    };

    void button_cb(FL_OBJECT *ob, long data)
    {

        int pupId = fl_newpup(0);

        fl_setpup_entries(pupId, fdchoice_0);
        fl_dopup(pupId);

    }

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

    extern FD_try * create_form_try(void);

    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, 220, 120);
      obj = fl_add_box(FL_FLAT_BOX,0,0,220,120,"");
      fdui->button = obj = fl_add_button(FL_MENU_BUTTON,40,30,150,60,"Pop Up");
        fl_set_object_callback(obj,button_cb,0);
      fl_end_form();

      fl_adjust_form_size(fdui->try);
      fdui->try->fdui = fdui;

      return fdui;
    }

    int main(int argc, char *argv[])
    {
       FD_try *fd_try;
       int i;

       for ( i = 0; i < 8; i++ ) {

           char buffer[512];

           snprintf( buffer, sizeof( buffer ), "Reason %d", i );
           strcpy( StrReasons[i], buffer );

       }

       fl_initialize(&argc, argv, 0, 0, 0);
       fd_try = create_form_try();

       /* fill-in form initialization code */

       /* show the first form */
       fl_show_form(fd_try->try,FL_PLACE_CENTERFREE,FL_FULLBORDER,"try");
       fl_do_forms();
       return 0;
    }
    _________________________________________________
    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 Feb 05 2003 - 14:49:59 EST