XForms: XForms menus

From: Didier Verkindt (verkindt@lapp.in2p3.fr)
Date: Fri Jun 09 2000 - 03:40:07 EDT

  • Next message: Steve Lamont: "Re: XForms: XForms menus"

    # To subscribers of the xforms list from Didier Verkindt <verkindt@lapp.in2p3.fr> :

    Hi,
    Trying to read a menu that has a lot of entries, I got the following
    problem: the menu vertical band did not go out of the form, then
    I can not read more than the first 10 entries of the menu.
    Is this a Xform bug or is it an inappropriate use from me.

    Here is the source code:

    /********************************************************/
    /* */
    /* MODULE : FbmClientX.c (with GUI) */
    /* AUTHOR : D. Verkindt, LAPP */
    /* VERSION : v2r3 */
    /* DATE : 12/05/2000 */
    /* */
    /* This application is the Xclient. It sends */
    /* control messages to the Main Frame Builder Server */
    /* (Cm messages) and get back the status of it. */
    /* */
    /********************************************************/

    /*
    ****************************************************************************
    */
    char version[] = "MainFBclientX(v2r3) using Cm(v7r9), CSet(v2r5),
    Xforms(v0.88)";
    /*
    ****************************************************************************
    */

    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <signal.h>
    #include <forms.h>
    #include <mainpanel.h>
    #include <CmMessage.h>

    #define LSTRING_MAX 256

    struct FbMclient{
      char outputs[LSTRING_MAX];
      char *curServer;
      char CmName[LSTRING_MAX];
      int repeated;
    };

    void FbMcInit (char **argv,int argc);
    CmMessageStatus FbMcGetAnswerHandler (CmMessage message, char* sender,
    char* serverName);
    void FbMcSendCtrlMsg (FL_OBJECT *obj, long arg);
    void FbMcGetServerList (FL_OBJECT *obj, long arg);
    CmMessageStatus FbMcNamesHandler (CmMessage message);
    void FbMcClear (FL_OBJECT *obj, long arg);
    void FbMcQuit (FL_OBJECT *obj,long arg);
    void quitHandler (int sig);

    int debug = 12;
    struct FbMclient *mfbc;

    FD_mainpanel *mainpanel;

    /*------------------------------------------------------ Main -------*/
    int main( int argc, char *argv[])
    {
     printf("\n\n\n");

    printf("-----------------------------------------------------------------------------\n\n");
     printf(" VIRGO MainFB Client \n");
     printf(" version is %s \n", version);
     printf(" %s %s %s \n\n",__DATE__,__TIME__,__FILE__);

    printf("-----------------------------------------------------------------------------\n");
     printf("\n\n\n");

     if (debug>10) printf("\nMain \n");

     signal(SIGINT,quitHandler); /* Take care only of Ctrl-C */

     fl_set_border_width(-2);
     fl_initialize(&argc, argv, "MainFBclient", 0, 0);

     mainpanel = create_form_mainpanel();
     
     FbMcInit(argv,argc);

     fl_set_form_position(mainpanel->mainpanel, -150-960, -100-680);

    fl_show_form(mainpanel->mainpanel,FL_PLACE_POSITION,FL_FULLBORDER,"principal");
     
     while(fl_do_forms()){}
     
     quitHandler(0);
     return(0);
    }

    /*---------------------------------------------------- FbMcInit
    ---------*/
    void FbMcInit(char **argv,int argc)
    {
     if (debug>10) printf("\nFbMcInit \n");

     mfbc = (struct FbMclient *)calloc(1,sizeof(struct FbMclient));

    /*--- Default arguments ---*/

     mfbc->curServer = (char *)calloc(LSTRING_MAX, sizeof(char));
     strcpy(mfbc->curServer, "MainFB");
     strcpy(mfbc->CmName, "MainFBclient");

    /*--- Get arguments ---*/

     if (argc == 2 && strncmp(argv[1],"-h",2)==0)
        {printf("\n\n");
         printf("----------------------------- HELP
    --------------------------------\n");
         printf(" This application is the MainFB client. It sends control
    messages \n");
         printf(" to the Main Frame Builder Server (MFBS) via Cm messages and
    \n");
         printf(" get back the status (short or full) of the MFBS.
    \n");
         printf(" For any argument, the sign '-' validates default.
    \n\n");
         printf(" Synthaxe is: MainFBclient arg1 arg2
    \n");
         printf(" arg1 = local Cm name (default=MainFBclient)
    \n");
         printf(" arg2 = debug level (default=0)
    \n");

    printf("-------------------------------------------------------------------\n\n");
         exit(0);
        }

     if (argc > 1)
        {if (strcmp(argv[1],"-") != 0) strcpy(mfbc->CmName, argv[1]);}

     if (argc > 2)
        {if (strcmp(argv[2],"-") != 0) debug = atoi(argv[2]);}

     /*--- Initialize for GUI and Cm ---*/

     mfbc->repeated = 0;
     fl_set_input(mainpanel->repeat_period, "2");
     fl_clear_browser(mainpanel->results);
     fl_set_browser_fontstyle(mainpanel->results, FL_FIXED_STYLE);

     if (!CmMessageOpenServer (mfbc->CmName))
        {fprintf (stderr, "FbMcSendCtrlMsg: Cm Declaration error.\n");
         exit(0);
        }
     CmMessageInstallHandler (FbMcGetAnswerHandler, "MainFBmsg");
     CmMessageInstallHandler((CmMessageHandler)FbMcNamesHandler, "NSNames");
     FbMcGetServerList(NULL,0);

     fl_set_object_label(mainpanel->infoLine, "Client Status: Ready");
     return;
    }

    /*---------------------------------------------------- FbMcRepeatSend
    ---------*/
    void FbMcRepeatSend(FL_OBJECT *obj, long arg)
    {
     int period,i;

     if (debug>10) printf("\nFbMcRepeatSend \n");

     if (strlen(mfbc->curServer) == 0)
        {fl_set_object_label(mainpanel->infoLine,"Client Status: I need a
    server name");
         return;
        }

     mfbc->repeated = (mfbc->repeated + 1) % 2;

     if (mfbc->repeated <= 0)
        {return;}
     else if (arg == 1)
        {fl_set_object_color(mainpanel->repeat, FL_RED, 0);
         fl_set_object_label(mainpanel->repeat, "Stop");
        }
     else
        {fl_set_object_color(mainpanel->repeatfull, FL_RED, 0);
         fl_set_object_label(mainpanel->repeatfull, "Stop");
        }

     while (mfbc->repeated)
        {FbMcSendCtrlMsg(NULL, arg);
         period = atoi(fl_get_input(mainpanel->repeat_period));
         if (period < 2)
            {period = 2;
             fl_set_input(mainpanel->repeat_period, "2");
            }
         for (i=0; i<period; i++)
            {fl_check_forms();
             sleep(1);
             period = atoi(fl_get_input(mainpanel->repeat_period));
             if (period < 2)
                {period = 2;
                 fl_set_input(mainpanel->repeat_period,"2");
                }
            }
        }

     if (arg == 1)
        {fl_set_object_color(mainpanel->repeat, FL_BLACK, 0);
         fl_set_object_label(mainpanel->repeat, "Repeat");
        }
     else
        {fl_set_object_color(mainpanel->repeatfull, FL_BLACK, 0);
         fl_set_object_label(mainpanel->repeatfull, "Repeat Full");
        }

     return;
    }

    /*---------------------------------------------------- FbMcSendCtrlMsg
    ---------*/
    void FbMcSendCtrlMsg(FL_OBJECT *obj, long arg)
    {
     CmMessage message;
     char *ctrlmsg, msg[LSTRING_MAX], dummy[LSTRING_MAX];
     const char *outputs;
     CmConnectCondition condition;
     int cmsend_ok;

     if (debug>10) printf("\nFbMcSendCtrlMsg \n");

     if (strlen(mfbc->curServer) == 0)
        {fl_set_object_label(mainpanel->infoLine,"Client Status: I need a
    server name");
         return;
        }

     message = CmMessageNew();
        
     if (arg == 1)
        {CmMessagePutText(message, "getStatus");}

     else if (arg == 2)
        {CmMessagePutText(message, "getFullStatus");}

     else if (arg == 3)
        {outputs = fl_show_input("Server outputs to add", mfbc->outputs);
         if (!outputs) return;
         ctrlmsg = (char *)calloc(strlen(outputs)+11,sizeof(char));
         sprintf(ctrlmsg,"addoutput %s",outputs);
         CmMessagePutText(message, ctrlmsg);
         free(ctrlmsg);
         strcpy(mfbc->outputs, outputs);
        }

     else if (arg == 4)
        {outputs = fl_show_input("Server outputs to remove", mfbc->outputs);
         if (!outputs) return;
         ctrlmsg = (char *)calloc(strlen(outputs)+11, sizeof(char));
         sprintf(ctrlmsg,"suboutput %s", outputs);
         CmMessagePutText(message, ctrlmsg);
         free(ctrlmsg);
         strcpy(mfbc->outputs, outputs);
        }

     else if (arg == 5)
        {sprintf(msg,"Do you really want to Stop the server %s ?",
    mfbc->curServer);
         if(!fl_show_question(msg,1)) return;
         CmMessagePutText(message,"exit");
        }

     else
        {return;}

     CmMessageSetType(message, "MainFBmsg");
     cmsend_ok = CmMessageSend(message, mfbc->curServer);
     CmMessageDelete(message);

     if (cmsend_ok == 0)
        {printf(" Server %s not responding... request not received. \n",
    mfbc->curServer);
         sprintf(dummy," Server %s not responding... request not received.
    Try again.", mfbc->curServer);
         fl_set_object_label(mainpanel->infoLine, dummy);
         return;
        }

     /*--- Wait for an answer in case of getStatus or getFullStatus or
    Exit---*/

     if (arg == 1 || arg == 2 || arg == 5)
        {printf(" Waiting for an answer from Server (%s)... \n",
    mfbc->curServer);
         fl_set_object_label(mainpanel->infoLine,"Client Status: Waiting for
    an answer from the Server");

         condition = CmMessageWaitWithTimeout(5.);

         if (condition != CmConnectTimeoutDetection && condition !=
    CmConnectBreakDetection)
            {printf("CmMessageWait stopped abnormally... \n");
             fl_set_object_label(mainpanel->infoLine, "Client Status:
    CmMessageWait stopped abnormally...");
            }
         if (condition == CmConnectTimeoutDetection)
            {printf(" Timeout reached... \n");
             fl_set_object_label(mainpanel->infoLine, "Client Status:
    CmMessageWait timeout reached...");
            }
        }

     return;
    }

    /*----------------------------------------------------
    FbMcGetAnswerHandler ---------*/
    CmMessageStatus FbMcGetAnswerHandler (CmMessage message, char* sender,
    char* serverName)
    {
     char *answer, *title, alertmsg[LSTRING_MAX];
     int newtopline;

     if (debug>10) printf("\nFbMcGetAnswerHandler \n");

     if (strcmp(sender, mfbc->curServer) != 0)
        {sprintf(alertmsg, "Client Status: %s is not the MainFB server but it
    sent a message here.",sender);
         printf("%s \n", alertmsg);
         fl_set_object_label(mainpanel->infoLine, alertmsg);
         return(CmMessageBreak);
        }

     title = CmMessageGetText(message);
     answer = CmMessageGetText(message);

     if (strcmp(title, "getStatus") == 0)
        {fl_add_browser_line(mainpanel->results, answer);
         fl_add_browser_line(mainpanel->results,
    "------------------------------------------------------------------\n");
         newtopline = fl_get_browser_maxline(mainpanel->results) -
                      fl_get_browser_screenlines(mainpanel->results) + 1;
         fl_set_browser_topline(mainpanel->results, newtopline);
         fl_set_object_label(mainpanel->infoLine, "Client Status: Short
    Status received");
        }

     if (strcmp(title,"getFullStatus") == 0)
        {fl_add_browser_line(mainpanel->results, answer);
         fl_add_browser_line(mainpanel->results,
    "------------------------------------------------------------------\n");
         newtopline = fl_get_browser_maxline(mainpanel->results) -
                      fl_get_browser_screenlines(mainpanel->results) + 1;
         fl_set_browser_topline(mainpanel->results, newtopline);
         fl_set_object_label(mainpanel->infoLine,"Client Status: Full Status
    received");
        }

     if (strcmp(title,"exit") == 0)
        {fl_set_object_label(mainpanel->infoLine, "Client Status: MainFB
    server stopped");}

     free(answer);
     free(title);
     return(CmMessageBreak);
    }

    /*--------------------------------------------------- FbMcGetServerList
    -----*/
    void FbMcGetServerList(FL_OBJECT *obj, long arg)
    {
     CmMessage message;
     CmConnectCondition condition;
     CmConnect server;
     char* destination;
     const char *menuItem;

     if (debug>10) printf("\nFbMcGetServerList : arg=%ld \n",arg);

     if (arg == 1)
        {menuItem = fl_get_choice_text(mainpanel->serverMenu);
         strcpy(mfbc->curServer, menuItem);
        }

     server = CmConnectGetNameServer();
     destination = CmConnectGetName(server);

     message = CmMessageNew();
     CmMessageSetType(message, "NSGetNames");
     CmMessageSend(message, destination);
     CmMessageDelete(message);

     condition = CmMessageWaitWithTimeout(3.);

     if (condition == CmConnectTimeoutDetection)
        {printf("Timeout reached. I could not update the list of servers.\n");
         fl_set_object_label(mainpanel->infoLine, "Timeout reached. I could
    not update the list of servers.");
        }

     return;
    }

    /*-------------------------------------------- FbMcNamesHandler
    ---------*/
    CmMessageStatus FbMcNamesHandler (CmMessage message)
    {
     const char *name;
     int flag;

     if (debug>10) printf("\nFbMcNamesHandler \n");

     fl_clear_choice(mainpanel->serverMenu);
     flag = 0;

     while (CmMessageGetItemType (message) == CmMessageItemText)
        {name = CmMessageGetText (message);
         if (strcmp(name, mfbc->curServer) == 0) {flag = 1; continue;}
         if (strcmp(name,"<unknown>") == 0) continue;
         if (strcmp(name,mfbc->CmName) == 0) continue;
         fl_addto_choice(mainpanel->serverMenu, name);
        }

     if (flag == 1)
        {fl_addto_choice(mainpanel->serverMenu, mfbc->curServer);
         fl_set_choice_text(mainpanel->serverMenu, mfbc->curServer);
        }

     return (CmMessageBreak);
    }

    /*---------------------------------------------------- FbMcClear
    ---------*/
    void FbMcClear(FL_OBJECT *obj, long arg)
    {
     if (debug>10) printf("\nFbMcClear \n");
     
     fl_clear_browser(mainpanel->results);
     fl_set_object_label(mainpanel->infoLine,"Client Status: Status Window
    Cleared");

     return;
    }

    /*--------------------------------------------------- quitHandler -----*/
    void quitHandler(int sig)
    {
     FbMcQuit(NULL,0);
    }

    /*--------------------------------------------------- FbMcQuit -----*/
    void FbMcQuit(FL_OBJECT *obj,long arg)
    {
     char clientName[LSTRING_MAX];

     if (debug>10) printf("\nFbMcQuit \n");

     if (arg == 0)
        {if (!fl_show_question("Do you really want to Quit ?",1)) return;}

     CmMessageUninstallHandler ("MainFBmsg");
     CmMessageUninstallHandler ("NSNames");

     strcpy(clientName,CmConnectGetName(CmConnectWhoAmI()));
     CmMessageCloseServer(clientName);
     if (debug>10) printf(" My name was %s. Disconnected.\n\n", clientName);
     printf("\n bye bye ! \n\n");

     exit(0);
    }

    -----------------------------------------------------------------
    /* Form definition file generated with fdesign. */

    #include "forms.h"
    #include <stdlib.h>
    #include "mainpanel.h"

    FD_mainpanel *create_form_mainpanel(void)
    {
      FL_OBJECT *obj;
      FD_mainpanel *fdui = (FD_mainpanel *) fl_calloc(1, sizeof(*fdui));

      fdui->mainpanel = fl_bgn_form(FL_NO_BOX, 750, 530);
      obj = fl_add_box(FL_UP_BOX,0,0,750,530,"");
      obj = fl_add_frame(FL_ENGRAVED_FRAME,10,430,730,30,"");
      fdui->results = obj =
    fl_add_browser(FL_NORMAL_BROWSER,20,100,720,300,"Status Window");
        fl_set_object_color(obj,FL_WHITE,FL_YELLOW);
        fl_set_object_lsize(obj,FL_NORMAL_SIZE);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
      fdui->getstatus = obj = fl_add_button(FL_NORMAL_BUTTON,90,430,80,30,"Get
    Status");
        fl_set_object_color(obj,FL_WHEAT,FL_COL1);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcSendCtrlMsg,1);
      fdui->getfullstatus = obj =
    fl_add_button(FL_NORMAL_BUTTON,240,430,100,30,"Get Full Status");
        fl_set_object_color(obj,FL_WHEAT,FL_COL1);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcSendCtrlMsg,2);
      fdui->addoutputs = obj =
    fl_add_button(FL_NORMAL_BUTTON,530,430,90,30,"Add Outputs");
        fl_set_object_color(obj,FL_WHEAT,FL_COL1);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcSendCtrlMsg,3);
      fdui->quit = obj = fl_add_button(FL_NORMAL_BUTTON,680,60,60,30,"Quit");
        fl_set_object_color(obj,FL_RED,FL_COL1);
        fl_set_object_lcolor(obj,FL_WHITE);
        fl_set_object_lsize(obj,FL_NORMAL_SIZE);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcQuit,0);
      fdui->infoLine = obj = fl_add_text(FL_NORMAL_TEXT,10,500,730,20,"infos
    line");
        fl_set_object_lcolor(obj,FL_WHITE);
        fl_set_object_lalign(obj,FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
        fl_set_object_lstyle(obj,FL_TIMESBOLDITALIC_STYLE);
      fdui->exit = obj = fl_add_button(FL_NORMAL_BUTTON,20,60,90,30,"Stop
    Server");
        fl_set_object_color(obj,FL_WHEAT,FL_COL1);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcSendCtrlMsg,5);
      fdui->clear_results = obj =
    fl_add_button(FL_NORMAL_BUTTON,10,430,50,30,"Clear");
        fl_set_object_color(obj,FL_WHEAT,FL_COL1);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcClear,1);
      fdui->title = obj = fl_add_text(FL_NORMAL_TEXT,260,10,230,40,"Main Frame
    Builder Client");
        fl_set_object_lcolor(obj,FL_WHITE);
        fl_set_object_lsize(obj,FL_MEDIUM_SIZE);
        fl_set_object_lalign(obj,FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
        fl_set_object_lstyle(obj,FL_TIMESBOLDITALIC_STYLE+FL_SHADOW_STYLE);
      fdui->repeat = obj =
    fl_add_button(FL_NORMAL_BUTTON,170,430,70,30,"Repeat");
        fl_set_object_color(obj,FL_BOTTOM_BCOL,FL_COL1);
        fl_set_object_lcolor(obj,FL_WHITE);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcRepeatSend,1);
      fdui->repeat_period = obj =
    fl_add_input(FL_INT_INPUT,360,470,70,30,"Repeat period (sec)");
        fl_set_object_color(obj,FL_LEFT_BCOL,FL_LEFT_BCOL);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
      fdui->serverMenu = obj =
    fl_add_choice(FL_NORMAL_CHOICE2,270,60,210,30,"Server:");
        fl_set_object_color(obj,FL_WHITE,FL_BLACK);
        fl_set_object_lsize(obj,FL_NORMAL_SIZE);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcGetServerList,1);
      fdui->suboutputs = obj =
    fl_add_button(FL_NORMAL_BUTTON,620,430,120,30,"Remove Outputs");
        fl_set_object_color(obj,FL_WHEAT,FL_COL1);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcSendCtrlMsg,4);
      fdui->repeatfull = obj =
    fl_add_button(FL_NORMAL_BUTTON,340,430,90,30,"Repeat Full");
        fl_set_object_color(obj,FL_BOTTOM_BCOL,FL_COL1);
        fl_set_object_lcolor(obj,FL_WHITE);
        fl_set_object_lstyle(obj,FL_TIMESBOLD_STYLE);
        fl_set_object_callback(obj,FbMcRepeatSend,2);
      fl_end_form();

      fdui->mainpanel->fdui = fdui;

      return fdui;
    }
    /*---------------------------------------*/

    ------------------------------------------------------------------

    #ifndef FD_mainpanel_h_
    #define FD_mainpanel_h_
    /* Header file generated with fdesign. */

    /**** Callback routines ****/

    extern void FbMcSendCtrlMsg(FL_OBJECT *, long);
    extern void FbMcQuit(FL_OBJECT *, long);
    extern void FbMcClear(FL_OBJECT *, long);
    extern void FbMcRepeatSend(FL_OBJECT *, long);
    extern void FbMcGetServerList(FL_OBJECT *, long);

    /**** Forms and Objects ****/

    typedef struct {
            FL_FORM *mainpanel;
            void *vdata;
            long ldata;
            FL_OBJECT *results;
            FL_OBJECT *getstatus;
            FL_OBJECT *getfullstatus;
            FL_OBJECT *addoutputs;
            FL_OBJECT *quit;
            FL_OBJECT *infoLine;
            FL_OBJECT *exit;
            FL_OBJECT *clear_results;
            FL_OBJECT *title;
            FL_OBJECT *repeat;
            FL_OBJECT *repeat_period;
            FL_OBJECT *serverMenu;
            FL_OBJECT *suboutputs;
            FL_OBJECT *repeatfull;
    } FD_mainpanel;

    extern FD_mainpanel * create_form_mainpanel(void);

    #endif /* FD_mainpanel_h_ */

    ---
      Didier Verkindt
      LAPP, Chemin de Bellevue, BP 110, 74941 ANNECY-LE-VIEUX, FRANCE
      tel: 33(0)450091628    fax: 33(0)450279495
      email: verkindt@lapp.in2p3.fr
      web:   http://wwwlapp.in2p3.fr/~verkindt
    

    _________________________________________________ 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 : Fri Jun 09 2000 - 03:44:45 EDT