
        ****************************************************************
        * J a m e s   H   T a y l o r          12 West Drive, Cleadon, *
        * Sunderland, Tyne & Wear, UK, SR6 7SJ       Tel: 091 536 2165 *
        ****************************************************************

       Below  are  a  few C functions  I use a lot  which may  be  of  some
       interest  to  other  members.  They  are  concerned  with Dialog box
       handling and button setting/resetting and tedinfo strings.

       /*-
        * myform.h header file
        */

       #define      MOUSE_ON   graf_mouse(M_ON,NULL)
       #define      MOUSE_OFF  graf_mouse(M_OFF,NULL)

       MFDB      sMFDB = {0L,640,400,40,1,1,0,0,0};
       MFDB      dMFDB = {0L,640,400,40,1,1,0,0,0};
       MFDB      iMFDB = {0L,640,400,40,1,1,0,0,0};

       short    v_handle;      /* The VDI handle */

       int      handle_dialog(OBJECT *dlog,int editnum);
       int      doform_noctr(OBJECT *dlog, int editnum);

       /*
             Dialog box handler.
       */
       int handle_dialog(OBJECT *dlog,int editnum)
       {

             short x,y,w,h;
             short pxyarray[8];

             int but;

             MOUSE_OFF;

             form_center(dlog,&x,&y,&w,&h);

             pxyarray[0] = x;pxyarray[1] = y;
             pxyarray[2] = x+w;pxyarray[3] = y+h;
             pxyarray[4] = x;pxyarray[5] = y;
             pxyarray[6] = x+w;pxyarray[7] = y+h;
             vro_cpyfm(v_handle,3,pxyarray,&sMFDB,&dMFDB);

             form_dial(FMD_START,0,0,0,0,x,y,w,h);
             form_dial(FMD_GROW,x+w/2,y+h/2,0,0,x,y,w,h);
             objc_draw(dlog,0,10,x,y,w,h);
             MOUSE_ON;
             but=form_do(dlog,editnum);
             MOUSE_OFF;
             form_dial(FMD_SHRINK,x+w/2,y+h/2,0,0,x,y,w,h);
             form_dial(FMD_FINISH,0,0,0,0,x,y,w,h);
             vro_cpyfm(v_handle,3,pxyarray,&dMFDB,&sMFDB);
             MOUSE_ON;
           /* De-select exit button */
             dlog[but].ob_state&=~SELECTED;
             return but;
       }



       /*
             Dialog box handler.
             Does not centre the dialog or draw expanding gizmos.
       */
       int doform_noctr(OBJECT *dlog,int editnum)
       {
             short x,y,w,h;
             short pxyarray[8];
             int but;

             MOUSE_OFF;

             x = pxyarray[0] = dlog[0].ob_x;
             y = pxyarray[1] = dlog[0].ob_y;
             w = dlog[0].ob_width;pxyarray[2] = x+w;
             h = dlog[0].ob_height;pxyarray[3] = y+h;
             pxyarray[4] = 0;pxyarray[5] = 0;
             pxyarray[6] = w;pxyarray[7] = h;
           /* Save screen area */
             vro_cpyfm(v_handle,3,pxyarray,&sMFDB,&iMFDB);
           /* Draw the dialog box */
             objc_draw(dlog,0,10,x,y,w,h);
             MOUSE_ON;
             but=form_do(dlog,editnum);
             MOUSE_OFF;
           /* Replace screen area */
             pxyarray[0] = 0; pxyarray[1] = 0;
             pxyarray[2] = w; pxyarray[3] = h;
             pxyarray[4] = x; pxyarray[5] = y;
             pxyarray[6] = x+w;pxyarray[7] = y+h;

             vro_cpyfm(v_handle,3,pxyarray,&iMFDB,&sMFDB);
             MOUSE_ON;
           /* de-select exit button */
             dlog[but].ob_state&=~SELECTED;
             return but;
       }



       /*
        * copy a string into a TEDINFO structure.
        */
       void set_tedinfo(OBJECT *tree,int obj,char *source)
       {
             char *dest;

             dest=((TEDINFO *)tree[obj].ob_spec)->te_ptext;
             strcpy(dest,source);
       }




       /*
        * copy the string from a TEDINFO into another string
        */
       void get_tedinfo(OBJECT *tree, int obj, char *dest)
       {
             char *source;

           /* Extract address */
             source=((TEDINFO *)tree[obj].ob_spec)->te_ptext;
             strcpy(dest,source);
       }



       /* Set a radio button */
       void set_rbut(OBJECT *tree,int parent,int button)
       {
             int b;

             for (b=tree[parent].ob_head; b!=parent; b=tree[b].ob_next)
                   if (b==button)
                         tree[b].ob_state |= SELECTED;
                   else
                         tree[b].ob_state &= ~SELECTED;
       }



       /* Set/reset a dialog button */
       void set_but(OBJECT *tree,int button,int mode)
       {
             tree[button].ob_state=mode;
       }




       /*
             Set/reset a dialog button,
             Usage: set_obstat(dlog,index,DISABLED,0); (enable object)
             Notes:      SELECTED      0
                         CROSSED       1
                         CHECKED       2
                         DISABLED      3     mode: 0=reset bit, 1=set bit
                         OUTLINED      4
                         SHADOWED      5
       */
       void set_obstat(OBJECT *tree, int index, int bit_mask, int mode)
       {
             if(mode == 0)
                   tree[index].ob_state &= ~bit_mask;
             else
                   tree[index].ob_state |= bit_mask;
       }

       /*
             Return the state of an object.
             index = index of object.
             bit_mask = mask of bits to be tested (see above Notes.)
             Usage: ret_obstat(dlog,index,SELECTED); (enable object)
       */
       int ret_obstat(OBJECT *tree, int index, int bit_mask)
       {
                   return tree[index].ob_state && bit_mask;
       }




       /*
             Return a dialog button state.
       */
       int ret_sb(OBJECT *tree,int button)
       {
             return tree[button].ob_state;
       }



       /*
             Return the button set in a group of radio buttons.
             Note: only one button will be set.
             parent = index of the parent object.
       */
       int ret_srb(OBJECT *tree,int parent)
       {
             int b;

             b=tree[parent].ob_head;
             for     (;    b!=parent    &&    !(tree[b].ob_state&SELECTED);
       b=tree[b].ob_next)
                   ;

             return b;
       }



       /*
             Returns set buttons (not radio) in a group, as a bit pattern.
             Note:  The  last  button  must  not  be the last object in the
       tree.
       */
       int ret_buts(OBJECT *tree,int parent)
       {
             int b, bits;
             float e;

             bits = 0; b=tree[parent].ob_head;
             for (; b<=tree[parent].ob_tail; b=tree[b].ob_next)
             {
                   if(tree[b].ob_state&SELECTED)
                   {
                         e = b-parent-1;
                         bits |= (int)(pow2(e));
                   }
             }
             return bits;
       }



       /*
             Set buttons (max 32) from an integer bit pattern.
             NB: last button must not be the last object in the tree.
       */
       void set_buts(OBJECT *tree,int patt,int parent)
       {
             int b, bit;
             float bt;

             b=tree[parent].ob_head;
             for (bt=0;b<=tree[parent].ob_tail;b=tree[b].ob_next,bt++)
             {
                   bit = (int)(pow2(bt));
                   if(patt & bit)
                   {
                         tree[b].ob_state |= SELECTED;
                   }
                   else
                   {
                         tree[b].ob_state &= ~SELECTED;
                   }
             }
       }

       ------------------------ end of file ------------------------------