home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / ui_utils / aib623.lha / source / menus.c < prev    next >
C/C++ Source or Header  |  1992-03-21  |  34KB  |  1,590 lines

  1. /* menus.c */
  2. #include "aib.h"
  3. #include "extern.h"
  4.  
  5. /* defines */
  6. #define NORM 0
  7. #define MX   1
  8. #define TOG  2
  9.  
  10. /* prototypes */
  11.  
  12. void old_menu(void);
  13. struct title_box *grabtitle(struct title_box *);
  14. struct item_box *grabitem(struct item_box *);
  15. struct sub_box *grabsub(struct sub_box *);
  16. void free_allmenu(struct title_box *);
  17. void generate(void);
  18. LONG GetMX_it(struct item_box *);
  19. LONG GetMX_sub(struct sub_box *);
  20. void freeall_subs(struct sub_box *);
  21. void freeall_items(struct item_box *);
  22. void menu_opts(struct Gadget *, UWORD);
  23. struct title_box *new_title(struct title_box*);
  24. struct item_box *new_item(struct item_box*);
  25. struct sub_box *new_sub(struct sub_box*);
  26. void add_title(char [256]);
  27. void add_item(char [256]);
  28. void add_sub(char [256]);
  29. void change_title(UWORD,char *);
  30. void change_item(UWORD,char *);
  31. void change_sub(UWORD,char*);
  32. struct title_box *locate_title(UWORD);
  33. struct item_box  *locate_item(UWORD);
  34. struct sub_box   *locate_sub (UWORD);
  35. void rem_title(struct title_box*);
  36. void rem_item(struct item_box*);
  37. void rem_sub(struct sub_box*);
  38. void swapit (void);
  39. void swapit_it(void);
  40. void swapit_sub(void);
  41. void prepare_title(void);
  42. void prepare_item(void);
  43. void prepare_sub(void);
  44. void disable_all(void);
  45.  
  46. /* globals needed */
  47. struct List it_list,sub_list;
  48. char new_t[256],new_i[256],new_s[256];
  49. struct title_box *curr_t = NULL;
  50. struct item_box *curr_i = NULL;
  51. struct sub_box *curr_s = NULL;
  52. int ord_title = -1;
  53. int ord_item = -1;
  54. int ord_sub = -1;
  55. struct title_box *swap_tit = NULL;
  56. struct item_box  *swap_it  = NULL;
  57. struct sub_box   *swap_sub = NULL;
  58. BOOL fchecked = FALSE;
  59. int curr_box =0;
  60. int num_entries = 0;
  61.  
  62. /************************** menu gads ***********************************/
  63. void menu_opts (struct Gadget *gad, UWORD code)
  64. {
  65.     switch (gad->GadgetID) {
  66.  
  67.   case MM_titl:
  68.     if (!topt) break;
  69.     ord_title=code;
  70.     curr_t=locate_title(code);
  71.  
  72.     if (swap_tit) swapit();
  73.  
  74.     /* activate legal buttons */
  75.     prepare_title();
  76.  
  77.     break;
  78.     
  79.   case MM_item:
  80.     if (!curr_t->items) break;
  81.     ord_item=code;
  82.     curr_i=locate_item(code);
  83.  
  84.     if (swap_it) swapit_it();
  85.  
  86.     /* activate legal buttons */
  87.     prepare_item();
  88.  
  89.     break;
  90.  
  91.   case MM_subs:
  92.     if (!curr_i->submenu) break;
  93.     ord_sub=code;
  94.     curr_s=locate_sub(code);
  95.  
  96.     if (swap_sub) swapit_sub();
  97.  
  98.     /* activate legal buttons */
  99.     prepare_sub();
  100.  
  101.     break;
  102.  
  103.   case MM_tstring:
  104.     strcpy(new_t,((struct StringInfo *)gad->SpecialInfo)->Buffer);
  105.     if (ord_title >= 0) change_title(ord_title,new_t);
  106.     else break;
  107.     GT_SetGadgetAttrs(tl,window,NULL,
  108.         GTLV_Labels,&tit_list,
  109.         GA_Disabled,FALSE,
  110.         GTLV_Selected,curr_t->index,
  111.         TAG_DONE);
  112.     GT_SetGadgetAttrs(select,window,NULL,
  113.         GTTX_Text,"T",
  114.         TAG_DONE);
  115.     GT_SetGadgetAttrs(stype,window,NULL,
  116.         GTTX_Text,curr_t->title,
  117.         TAG_DONE);
  118.     break;
  119.      
  120.   case MM_istring:
  121.     strcpy(new_i,((struct StringInfo *)gad->SpecialInfo)->Buffer);
  122.     if (ord_item >= 0) change_item(ord_item,new_i);
  123.     else break;
  124.     GT_SetGadgetAttrs(il,window,NULL,
  125.         GTLV_Labels,&it_list,
  126.         GTLV_Selected,curr_i->index,
  127.         TAG_DONE);
  128.     GT_SetGadgetAttrs(select,window,NULL,
  129.         GTTX_Text,"I",
  130.         TAG_DONE);
  131.     GT_SetGadgetAttrs(stype,window,NULL,
  132.         GTTX_Text,curr_i->item,
  133.         TAG_DONE);
  134.     break;
  135.  
  136.   case MM_sstring:
  137.     strcpy(new_s,((struct StringInfo *)gad->SpecialInfo)->Buffer);
  138.     if (ord_sub >= 0) change_sub(ord_sub,new_s);
  139.     else break;
  140.     GT_SetGadgetAttrs(sl,window,NULL,
  141.         GTLV_Labels,&sub_list,
  142.         GTLV_Selected,curr_s->index,
  143.         TAG_DONE);
  144.     GT_SetGadgetAttrs(select,window,NULL,
  145.         GTTX_Text,"S",
  146.         TAG_DONE);
  147.     GT_SetGadgetAttrs(stype,window,NULL,
  148.         GTTX_Text,curr_s->submenu,
  149.         TAG_DONE);
  150.     break;
  151.  
  152.  
  153.   case MM_ts:
  154.  
  155.     if (ord_title <1) break;
  156.     /* is this the first time? */
  157.     if (!swap_tit) {
  158.         swap_tit = curr_t;
  159.                 NewList(&it_list);
  160.         disable_all();
  161.         GT_SetGadgetAttrs(ts,window,NULL,    
  162.             GA_Disabled,FALSE,
  163.             TAG_DONE);
  164.         }
  165.      
  166.     else {  /* undo swap */
  167.         swap_tit =NULL;
  168.         prepare_title();
  169.           }
  170.     break;
  171.  
  172.   case MM_ta:
  173.     num_entries++;
  174.         curr_t = new_title(curr_t);
  175.  
  176.     GT_SetGadgetAttrs(tl,window,NULL,
  177.         GTLV_Labels,-1,
  178.         GA_Disabled,FALSE,
  179.         TAG_DONE);
  180.     
  181.     add_title(curr_t->title);
  182.  
  183.     GT_SetGadgetAttrs(tl,window,NULL,
  184.         GTLV_Labels,&tit_list,
  185.         GTLV_Selected,curr_t->index,
  186.         GA_Disabled,FALSE,
  187.         TAG_DONE);
  188.  
  189.     ord_title=curr_t->index;
  190.     prepare_title();
  191.     /* update items display... */
  192.     break;
  193.  
  194.   case MM_td:
  195.     num_entries--;
  196.     if (ord_title <0) break;
  197.      curr_box=0;
  198.     rem_title(curr_t);
  199.     disable_all();
  200.     GT_SetGadgetAttrs(select,window,NULL,
  201.         GTTX_Text,"",
  202.         TAG_DONE);
  203.     GT_SetGadgetAttrs(stype,window,NULL,
  204.         GTTX_Text,"",
  205.         TAG_DONE);
  206.     GT_SetGadgetAttrs(tstring,window,NULL,
  207.         GTST_String,"",
  208.         TAG_DONE);
  209.     GT_SetGadgetAttrs(il,window,NULL,
  210.         GTLV_Labels,0,
  211.         TAG_DONE);    
  212.     GT_SetGadgetAttrs(tl,window,NULL,
  213.         GTLV_Labels,&tit_list,
  214.         TAG_DONE);
  215.     GT_SetGadgetAttrs(ta,window,NULL,
  216.         GA_Disabled,FALSE,
  217.         TAG_DONE);
  218.     ord_title=-1;  
  219.     break;
  220.  
  221. case MM_ia:
  222.     num_entries++;
  223.     if (ord_title <0) break;
  224.         curr_i=new_item(curr_i);
  225.  
  226.     GT_SetGadgetAttrs(il,window,NULL,
  227.         GTLV_Labels,-1,
  228.         GA_Disabled,FALSE,
  229.         TAG_DONE);
  230.     
  231.     add_item(curr_i->item);
  232.  
  233.     GT_SetGadgetAttrs(il,window,NULL,
  234.         GTLV_Labels,&it_list,
  235.         GTLV_Selected,curr_i->index,
  236.         GA_Disabled,FALSE,
  237.         TAG_DONE);
  238.  
  239.     ord_item=curr_i->index;
  240.     prepare_item();
  241.     break;
  242.  
  243. case MM_id:
  244.     num_entries--;
  245.     if (ord_item <0) break;
  246.     curr_box=0;
  247.     rem_item(curr_i);
  248.     disable_all();
  249.     GT_SetGadgetAttrs(select,window,NULL,
  250.         GTTX_Text,"",
  251.         TAG_DONE);
  252.     GT_SetGadgetAttrs(stype,window,NULL,
  253.         GTTX_Text,"",
  254.         TAG_DONE);
  255.     GT_SetGadgetAttrs(istring,window,NULL,
  256.         GTST_String,"",
  257.         GA_Disabled,TRUE,
  258.         TAG_DONE);
  259.     GT_SetGadgetAttrs(sl,window,NULL,
  260.         GTLV_Labels,0,
  261.         TAG_DONE);
  262.     GT_SetGadgetAttrs(ta,window,NULL,
  263.         GA_Disabled,FALSE,
  264.         TAG_DONE);    
  265.     GT_SetGadgetAttrs(ia,window,NULL,
  266.         GA_Disabled,FALSE,
  267.         TAG_DONE);    
  268.     GT_SetGadgetAttrs(il,window,NULL,
  269.         GTLV_Labels,&it_list,
  270.         TAG_DONE);
  271.     ord_item=-1;  
  272.     break;
  273.  
  274. case MM_is:
  275.  
  276.     if (ord_item <1) break;
  277.     /* is this the first time? */
  278.     if (!swap_it) {
  279.         swap_it = curr_i;
  280.         disable_all();
  281.         GT_SetGadgetAttrs(is,window,NULL,    
  282.             GA_Disabled,FALSE,
  283.             TAG_DONE);
  284.         }
  285.      
  286.     else {  /* undo swap */
  287.         swap_it =NULL;
  288.         prepare_item();
  289.           }
  290.     break;
  291.  
  292. case MM_sa:
  293.     num_entries++;
  294.     if (ord_item <0) break;
  295.         curr_s=new_sub(curr_s);
  296.  
  297.     GT_SetGadgetAttrs(sl,window,NULL,
  298.         GTLV_Labels,-1,
  299.         GA_Disabled,FALSE,
  300.         TAG_DONE);
  301.     
  302.     add_sub(curr_s->submenu);
  303.  
  304.     GT_SetGadgetAttrs(sl,window,NULL,
  305.         GTLV_Labels,&sub_list,
  306.         GTLV_Selected,curr_s->index,
  307.         GA_Disabled,FALSE,
  308.         TAG_DONE);
  309.  
  310.     ord_sub=curr_s->index;
  311.     prepare_sub();
  312.     break;
  313.  
  314. case MM_sd:
  315.     num_entries--;
  316.     if (ord_sub <0) break;
  317.     curr_box=0;
  318.     rem_sub(curr_s);
  319.     disable_all();
  320.     GT_SetGadgetAttrs(select,window,NULL,
  321.         GTTX_Text,"",
  322.         TAG_DONE);
  323.     GT_SetGadgetAttrs(stype,window,NULL,
  324.         GTTX_Text,"",
  325.         TAG_DONE);
  326.     GT_SetGadgetAttrs(ta,window,NULL,
  327.         GA_Disabled,FALSE,
  328.         TAG_DONE);    
  329.     GT_SetGadgetAttrs(ia,window,NULL,
  330.         GA_Disabled,FALSE,
  331.         TAG_DONE);
  332.     GT_SetGadgetAttrs(sa,window,NULL,
  333.         GA_Disabled,FALSE,
  334.         TAG_DONE);
  335.     GT_SetGadgetAttrs(sl,window,NULL,
  336.         GTLV_Labels,&sub_list,
  337.         TAG_DONE);
  338.     
  339.     ord_sub=-1;  
  340.     break;
  341.  
  342. case MM_ss:
  343.  
  344.     if (ord_sub <1) break;
  345.     /* is this the first time? */
  346.     if (!swap_sub) {
  347.         swap_sub = curr_s;
  348.         disable_all();
  349.         GT_SetGadgetAttrs(ss,window,NULL,    
  350.             GA_Disabled,FALSE,
  351.             TAG_DONE);
  352.         }
  353.      
  354.     else {  /* undo swap */
  355.         swap_sub =NULL;
  356.         prepare_sub();
  357.           }
  358.     break;
  359.  
  360.  
  361. case MM_fche:
  362.     fchecked=(fchecked)?FALSE:TRUE;
  363.     GT_SetGadgetAttrs(nfont,window,NULL,
  364.         GA_Disabled,(fchecked)?FALSE:TRUE,
  365.         TAG_DONE);
  366.     if (fchecked) menuta = &menucta;
  367.     else menuta = screen->Font;
  368.     break;
  369.  
  370.     /***** title, item, and sub choices... ******/
  371.  
  372. case MM_dis:
  373.      if (curr_box==1) curr_t->disabled=(curr_t->disabled)?FALSE:TRUE;
  374.     else if (curr_box==2) curr_i->disabled=(curr_i->disabled)?FALSE:TRUE;
  375.     else if (curr_box==3) curr_s->disabled=(curr_s->disabled)?FALSE:TRUE;
  376.      break;
  377.     
  378.     /***** item , and sub choices... ******/
  379.     
  380. case MM_bar:
  381.     if (curr_box==2) curr_i->menubar=(curr_i->menubar)?FALSE:TRUE;
  382.     else if (curr_box==3) curr_s->menubar=(curr_s->menubar)?FALSE:TRUE;
  383.      break;
  384.  
  385. case MM_chec:
  386.     if (curr_box==2) curr_i->checked=(curr_i->checked)?FALSE:TRUE;
  387.     else if (curr_box==3) curr_s->checked=(curr_s->checked)?FALSE:TRUE;
  388.      break;
  389.  
  390. case MM_tog:
  391.     if (curr_box==2)  curr_i->type=code;
  392.     else if (curr_box==3)  curr_s->type=code;
  393.     if (code == 2)
  394.     GT_SetGadgetAttrs(chec,window,NULL,
  395.         GA_Disabled,TRUE,
  396.         TAG_DONE);
  397.     else 
  398.     GT_SetGadgetAttrs(chec,window,NULL,
  399.         GA_Disabled,FALSE,
  400.         TAG_DONE);
  401.      break;
  402.  
  403. case MM_func:
  404.         if (curr_box==2) strcpy(curr_i->function,
  405.         ((struct StringInfo *)gad->SpecialInfo)->Buffer );
  406.     else if (curr_box==3) strcpy(curr_s->function,
  407.         ((struct StringInfo *)gad->SpecialInfo)->Buffer );
  408.      break;
  409.  
  410. case MM_key:
  411.         if (curr_box==2) strcpy(curr_i->hotkey,
  412.         ((struct StringInfo *)gad->SpecialInfo)->Buffer );
  413.     else if (curr_box==3) strcpy(curr_s->hotkey,
  414.         ((struct StringInfo *)gad->SpecialInfo)->Buffer );
  415.      break;
  416.  
  417. default:
  418.     gad_opts(gad,code);
  419.     break;
  420.     }
  421.  
  422. }
  423.  
  424.  
  425. /****** handle MX *********************************************************/
  426.  
  427. LONG GetMX_it(struct item_box *temp)
  428. {
  429.  LONG flag = 0;
  430.  LONG count = 1;
  431.  
  432.  while (temp)
  433.     {
  434.      if (temp->type != 2) flag = flag | count;
  435.      count=count*2;
  436.      temp=temp->next;
  437.     }
  438.  
  439.  return(flag); 
  440.  
  441. }
  442.  
  443. LONG GetMX_sub (struct sub_box *temp)
  444. {
  445.  LONG flag = 0;
  446.  LONG count = 1;
  447.  
  448.  while (temp)
  449.     {
  450.      if (temp->type != 2) flag = flag | count;
  451.      count=count*2;
  452.      temp=temp->next;
  453.     }
  454.  
  455.  return(flag); 
  456.  
  457. }
  458.  
  459.  
  460. /* generate menu! ********************************************************/
  461.  
  462. void generate(void)
  463. {
  464.  UWORD mxi,mxs,x, flags;
  465.  LONG ic,sc,sfl,ifl;
  466.  
  467.  struct title_box *tempt=topt;
  468.  struct item_box *tempi= NULL;
  469.  struct sub_box *temps = NULL;
  470.  
  471.  x=0;
  472.  
  473.  if (their_menu) free(their_menu);
  474.  their_menu = NULL;
  475.  
  476.  if (topt) {
  477.  their_menu = (struct NewMenu *)calloc(num_entries+1,sizeof(struct NewMenu));
  478.  
  479.  while (tempt)
  480.     {
  481.       (their_menu +x)->nm_Type = (UBYTE) NM_TITLE;
  482.       (their_menu +x)->nm_Label=tempt->title;
  483.       (their_menu +x)->nm_CommKey=0;
  484.       (their_menu +x)->nm_Flags=0;
  485.       (their_menu +x)->nm_MutualExclude = 0;
  486.       (their_menu +x)->nm_UserData = 0;
  487.      x++;
  488.  
  489.      /* handle items */
  490.      if (tempt->items) 
  491.         {
  492.          tempi = tempt->items;
  493.          mxi=0;
  494.          ic=1;
  495.          ifl = GetMX_it(tempt->items);
  496.          while(tempi)
  497.            {
  498.             flags=0;
  499.              (their_menu +x)->nm_Type = NM_ITEM;
  500.             (their_menu +x)->nm_Label=(tempi->menubar)?
  501.                      NM_BARLABEL:tempi->item;
  502.                 
  503.             if (!(tempi->submenu) && strlen(tempi->hotkey)>0)
  504.              (their_menu +x)->nm_CommKey=tempi->hotkey;
  505.  
  506.             else (their_menu + x)->nm_CommKey = 0;
  507.                     
  508.               (their_menu +x)->nm_MutualExclude =0;
  509.             if (tempi->disabled) flags = NM_ITEMDISABLED;
  510.             if (tempi->type == 2) {
  511.                 if (!mxi) flags = flags | CHECKED;
  512.                 mxi=1; 
  513.                 flags = flags | CHECKIT; 
  514.                      (their_menu +x)->nm_MutualExclude = 
  515.                     (tempi->type==2)?~(ic|ifl):0;
  516.                 }
  517.             else if (tempi->type == 1) {
  518.                 flags = flags | MENUTOGGLE | CHECKIT;
  519.                 if (tempi->checked) flags = flags | CHECKED;
  520.                 }
  521.             (their_menu +x)->nm_Flags=flags;
  522.  
  523.              (their_menu +x)->nm_UserData = (strlen(tempi->function)>0)
  524.                 ?tempi->function:0;
  525.             x++;
  526.             ic = ic * 2;
  527.             /* handle submenus */
  528.             if (tempi->submenu && !tempi->type && !tempi->menubar)
  529.             {
  530.              temps = tempi->submenu;
  531.              mxs=0;
  532.              sc=1;
  533.              sfl = GetMX_sub(tempi->submenu);
  534.              while(temps)
  535.                 {
  536.                  flags = 0;
  537.                  (their_menu +x)->nm_Type = NM_SUB;
  538.                  (their_menu +x)->nm_Label=(temps->menubar)?
  539.                         NM_BARLABEL:temps->submenu;
  540.  
  541.                  if (strlen(temps->hotkey)>0)
  542.                   (their_menu +x)->nm_CommKey=temps->hotkey;
  543.  
  544.                  else (their_menu + x)->nm_CommKey = 0;
  545.                     
  546.                    (their_menu +x)->nm_MutualExclude =0;
  547.                 if (temps->disabled) flags = NM_ITEMDISABLED;
  548.                 if (temps->type == 2) {
  549.                     if (!mxs) flags = flags | CHECKED;
  550.                     mxs=1; 
  551.                     flags = flags | CHECKIT; 
  552.                          (their_menu +x)->nm_MutualExclude = 
  553.                         (temps->type==2)?~(sc|sfl):0;
  554.                     }
  555.                 else if (temps->type == 1) {
  556.                     flags = flags | MENUTOGGLE;
  557.                     if (temps->checked) flags = flags | CHECKED;
  558.                     }
  559.                  (their_menu +x)->nm_Flags=flags;
  560.  
  561.                  (their_menu +x)->nm_UserData = (strlen(temps->function)>0)?
  562.                     temps->function:0;
  563.                  x++;
  564.                  sc = sc * 2;
  565.                   temps = temps->next;
  566.                 }
  567.              }                  
  568.             tempi=tempi->next;
  569.            }
  570.             }
  571.     
  572.      tempt = tempt->next;
  573.     }
  574.  
  575.  (their_menu +x)->nm_Type = NM_END;
  576.  (their_menu +x)->nm_Label=0;
  577.  (their_menu +x)->nm_CommKey=0;
  578.  (their_menu +x)->nm_Flags=0;
  579.  (their_menu +x)->nm_MutualExclude = 0;
  580.  (their_menu +x)->nm_UserData = 0;
  581.  
  582.  }
  583. }
  584.  
  585. /* disable all ***********************************************************/
  586.  
  587. void disable_all(void)
  588. {
  589.  struct Gadget *gads[20];
  590.  int x;
  591.  
  592.  
  593.   /* disabled */
  594.  gads[0]=sstring; gads[1]=sa; gads[2]=ss; gads[3]=sd;
  595.  gads[5]=istring; gads[6]=is; gads[7]=id; gads[8]=bar; gads[9]=chec; 
  596.  gads[10]=tog; gads[11]=func;  gads[12]=tstring; gads[13]=ta; gads[14]=ts; 
  597.  gads[15]=td;  gads[16]=ia; gads[17]=dis; gads[18]=dis; gads[19]=key;
  598.  
  599.  for (x=0;x<20;x++)
  600.     GT_SetGadgetAttrs(gads[x],window,NULL,
  601.         GA_Disabled,TRUE,
  602.         TAG_DONE);
  603.  
  604.  
  605. }
  606.  
  607. /************************* prepare title *********************************/
  608.  
  609. void prepare_title(void)
  610. {
  611.  struct Gadget *gads[13];
  612.  struct item_box *temp= curr_t->items; 
  613.  int x;
  614.  
  615.  /* disabled */
  616.  gads[0]=sstring; gads[1]=sa; gads[2]=ss; gads[3]=sd; gads[4]=sl;
  617.  gads[5]=istring; gads[6]=is; gads[7]=id;
  618.  gads[8]=bar; gads[9]=chec; gads[10]=tog; gads[11]=func; gads[12]=key;
  619.  
  620.  for (x=0;x<13;x++)
  621.     GT_SetGadgetAttrs(gads[x],window,NULL,
  622.         GA_Disabled,TRUE,
  623.         TAG_DONE);
  624.  
  625.  /* abled */
  626.  gads[0]=tstring; gads[1]=ta; gads[2]=ts; gads[3]=td; gads[4]=il; 
  627.  gads[5]=ia; gads[6]=dis;
  628.  
  629. for (x=0;x<7;x++)
  630.     GT_SetGadgetAttrs(gads[x],window,NULL,
  631.         GA_Disabled,FALSE,
  632.         TAG_DONE);
  633.     
  634.  curr_box=1;
  635.  ord_item=-1;
  636.  ord_sub =-1;
  637.  
  638.  /* enter visual response */
  639.  GT_SetGadgetAttrs(select,window,NULL,
  640.     GTTX_Text,"T",
  641.     TAG_DONE);
  642.  GT_SetGadgetAttrs(stype,window,NULL,
  643.     GTTX_Text,curr_t->title,
  644.     TAG_DONE);
  645.  
  646.  GT_SetGadgetAttrs(dis,window,NULL,
  647.     GTCB_Checked,curr_t->disabled,
  648.      TAG_DONE);
  649.  
  650.  /* update item & sub boxes... */
  651.  curr_i=curr_t->items;
  652.  
  653.  NewList(&sub_list);
  654.  NewList(&it_list);
  655.  while (temp) { add_item(temp->item);
  656.         temp=temp->next; }
  657.  
  658.     GT_SetGadgetAttrs(il,window,NULL,
  659.         GTLV_Labels,&it_list,
  660.         TAG_DONE);
  661.     GT_SetGadgetAttrs(sl,window,NULL,
  662.         GTLV_Labels,0,
  663.         TAG_DONE);
  664. }
  665.  
  666. /************************ prepare item ************************************/
  667.  
  668. void prepare_item(void)
  669. {
  670.  struct Gadget *gads[13];
  671.  struct sub_box *temp = curr_i->submenu;
  672.  int x;
  673.  
  674.  /* disabled */
  675.  gads[0]=sstring; gads[1]=ss; gads[2]=sd; gads[3]=sl;
  676.  gads[4]=tstring; gads[5]=ts; gads[6]=td; 
  677.  
  678.  
  679.  for (x=0;x<7;x++)
  680.     GT_SetGadgetAttrs(gads[x],window,NULL,
  681.         GA_Disabled,TRUE,
  682.         TAG_DONE);
  683.  
  684.  /* abled */
  685.  gads[0]=istring; gads[1]=ia; gads[2]=is; gads[3]=id; gads[4]=il; 
  686.  gads[5]=sa; gads[6]=dis; gads[7]=chec; gads[8]=tog; gads[9]=func;
  687.  gads[10]=bar; gads[11]=ta; gads[12]=key;
  688.  
  689. for (x=0;x<13;x++)
  690.     GT_SetGadgetAttrs(gads[x],window,NULL,
  691.         GA_Disabled,FALSE,
  692.         TAG_DONE);
  693.     
  694.  curr_box=2;
  695.  ord_sub = -1;
  696.  
  697.  /* enter visual response */
  698.  GT_SetGadgetAttrs(select,window,NULL,
  699.     GTTX_Text,"I",
  700.     TAG_DONE);
  701.  GT_SetGadgetAttrs(stype,window,NULL,
  702.     GTTX_Text,curr_i->item,
  703.     TAG_DONE);
  704.  GT_SetGadgetAttrs(dis,window,NULL,
  705.     GTCB_Checked,curr_i->disabled,
  706.     TAG_DONE);
  707.  GT_SetGadgetAttrs(bar,window,NULL,
  708.     GTCB_Checked,curr_i->menubar,
  709.     TAG_DONE);
  710.  GT_SetGadgetAttrs(chec,window,NULL,
  711.     GTCB_Checked,curr_i->checked,
  712.     TAG_DONE);
  713.  GT_SetGadgetAttrs(tog,window,NULL,
  714.     GTCY_Active,curr_i->type,
  715.     TAG_DONE);
  716.  GT_SetGadgetAttrs(func,window,NULL,
  717.     GTST_String,curr_i->function,
  718.     TAG_DONE);
  719.  GT_SetGadgetAttrs(key,window,NULL,
  720.     GTST_String,curr_i->hotkey,
  721.     TAG_DONE);
  722.  
  723.   /* handle MX disabling of checked */
  724. if (curr_i->type == 2)
  725.      GT_SetGadgetAttrs(chec,window,NULL,
  726.     GA_Disabled,TRUE,
  727.     TAG_DONE);
  728.  
  729.  /* update sub box... */
  730.  NewList(&sub_list);
  731.   while (temp) { add_sub(temp->submenu);
  732.         temp=temp->next; }
  733.  
  734.     GT_SetGadgetAttrs(sl,window,NULL,
  735.         GTLV_Labels,&sub_list,
  736.         TAG_DONE);
  737. }
  738.  
  739. /*************************** prepare sub *********************************/
  740.  
  741. void prepare_sub(void)
  742. {
  743.  struct Gadget *gads[13];
  744.  int x;
  745.  
  746.  /* disabled */
  747.  gads[0]=istring; gads[1]=is; gads[2]=id; gads[3]=il;
  748.  gads[4]=tstring; gads[5]=ts; gads[6]=td; 
  749.  
  750.  
  751.  for (x=0;x<7;x++)
  752.     GT_SetGadgetAttrs(gads[x],window,NULL,
  753.         GA_Disabled,TRUE,
  754.         TAG_DONE);
  755.  
  756.  /* abled */
  757.  gads[0]=sstring; gads[1]=sa; gads[2]=ss; gads[3]=dis; gads[4]=chec; 
  758.  gads[5]=tog; gads[6]=func; gads[7 ]=bar; gads[8 ]=ta; gads[9]=sd;
  759.  gads[10]=ia; gads[11]=key;
  760.  
  761. for (x=0;x<12;x++)
  762.     GT_SetGadgetAttrs(gads[x],window,NULL,
  763.         GA_Disabled,FALSE,
  764.         TAG_DONE);
  765.     
  766.  curr_box=3;
  767.  
  768.  /* enter visual response */
  769.  GT_SetGadgetAttrs(select,window,NULL,
  770.     GTTX_Text,"S",
  771.     TAG_DONE);
  772.  GT_SetGadgetAttrs(stype,window,NULL,
  773.     GTTX_Text,curr_s->submenu,
  774.     TAG_DONE);
  775.  GT_SetGadgetAttrs(dis,window,NULL,
  776.     GTCB_Checked,curr_s->disabled,
  777.     TAG_DONE);
  778.  GT_SetGadgetAttrs(bar,window,NULL,
  779.     GTCB_Checked,curr_s->menubar,
  780.     TAG_DONE);
  781.  GT_SetGadgetAttrs(chec,window,NULL,
  782.     GTCB_Checked,curr_s->checked,
  783.     TAG_DONE);
  784.  GT_SetGadgetAttrs(tog,window,NULL,
  785.     GTCY_Active,curr_s->type,
  786.     TAG_DONE);
  787.  GT_SetGadgetAttrs(func,window,NULL,
  788.     GTST_String,curr_s->function,
  789.     TAG_DONE);
  790.  GT_SetGadgetAttrs(key,window,NULL,
  791.     GTST_String,curr_s->hotkey,
  792.     TAG_DONE);
  793.  
  794. /* handle MX disabling of Checked */
  795. if (curr_s->type == 2)
  796.      GT_SetGadgetAttrs(chec,window,NULL,
  797.     GA_Disabled,TRUE,
  798.     TAG_DONE);
  799.  
  800. }
  801.  
  802.  
  803. /****************************** swap_sub *************************************/
  804.  
  805. void swapit_sub (void)
  806. {
  807.  struct sub_box *temp;
  808.  struct Node *node1,*node2;
  809.  int ord;
  810.  
  811.   if ( !(temp=(struct sub_box *)calloc(sizeof(struct sub_box),1) ))
  812.     abort_me("Out of memory");
  813.  
  814.  if (swap_sub != curr_s)
  815. {
  816.  
  817.  /* find nodes */
  818.  node1 = node2 = sub_list.lh_Head;
  819.  for (ord=0;ord < curr_s->index;ord++)
  820.     node1 = node1->ln_Succ;
  821.  for (ord=0;ord < swap_sub->index;ord++)
  822.     node2 = node2->ln_Succ;
  823.  
  824.  /* swap items's data */
  825.  temp->disabled = curr_s->disabled;
  826.  strcpy(temp->submenu,curr_s->submenu);
  827.  temp->menubar = curr_s->menubar;
  828.  temp->type = curr_s->type;
  829.  strcpy(temp->function,curr_s->function);
  830.  temp->checked = curr_s->checked;
  831.  strcpy(temp->hotkey,curr_s->hotkey);
  832.  
  833.  curr_s->disabled = swap_sub->disabled;
  834.  strcpy(curr_s->submenu,swap_sub->submenu);
  835.  curr_s->menubar = swap_sub->menubar;
  836.  curr_s->type = swap_sub->type;
  837.  curr_s->checked = swap_sub->checked;
  838.  strcpy(curr_s->function,swap_sub->function); 
  839.  strcpy(curr_s->hotkey,swap_sub->hotkey);
  840.  
  841.  swap_sub->disabled = temp->disabled;
  842.  strcpy(swap_sub->submenu,temp->submenu);
  843.  swap_sub->menubar = temp->menubar;
  844.  swap_sub->type = temp->type;
  845.  swap_sub->checked = temp->checked;
  846.  strcpy(swap_sub->function,temp->function); 
  847.  strcpy(swap_sub->hotkey,temp->hotkey);
  848.  
  849.  free(temp);
  850.  
  851.  /* fix nodes now */ 
  852.  node2->ln_Name = swap_sub->submenu;
  853.  node1->ln_Name = curr_s->submenu;
  854.  
  855.  }
  856.  swap_sub = NULL;
  857.  ord_item = curr_s->index;
  858.  
  859.     GT_SetGadgetAttrs(sl,window,NULL,
  860.         GTLV_Labels,&sub_list,
  861.         GTLV_Selected,curr_s->index,
  862.         TAG_DONE);
  863.     GT_SetGadgetAttrs(sstring,window,NULL,
  864.         GTST_String,curr_s->submenu,
  865.         TAG_DONE);
  866. }
  867.  
  868. /************************* swapit_it ***************************************/
  869.  
  870. void swapit_it (void)
  871. {
  872.  struct item_box *temp;
  873.  struct Node *node1,*node2;
  874.  int ord;
  875.  
  876.   if ( !(temp=(struct item_box *)calloc(sizeof(struct item_box),1) ))
  877.     abort_me("Out of memory");
  878.  
  879.  if (swap_it != curr_i)
  880. {
  881.  
  882.  /* find nodes */
  883.  node1 = node2 = it_list.lh_Head;
  884.  for (ord=0;ord < curr_i->index;ord++)
  885.     node1 = node1->ln_Succ;
  886.  for (ord=0;ord < swap_it->index;ord++)
  887.     node2 = node2->ln_Succ;
  888.  
  889.  /* swap items's data */
  890.  temp->disabled = curr_i->disabled;
  891.  temp->submenu = curr_i->submenu;
  892.  strcpy(temp->item,curr_i->item);
  893.  temp->menubar = curr_i->menubar;
  894.  temp->type = curr_i->type;
  895.  strcpy(temp->function,curr_i->function);
  896.  temp->checked = curr_i->checked;
  897.  strcpy(temp->hotkey,curr_i->hotkey);
  898.  
  899.  curr_i->submenu = swap_it->submenu;
  900.  curr_i->disabled = swap_it->disabled;
  901.  strcpy(curr_i->item,swap_it->item);
  902.  curr_i->menubar = swap_it->menubar;
  903.  curr_i->type = swap_it->type;
  904.  curr_i->checked = swap_it->checked;
  905.  strcpy(curr_i->function,swap_it->function); 
  906.  strcpy(curr_i->hotkey, swap_it->hotkey);
  907.  
  908.  swap_it->submenu = temp->submenu;
  909.  swap_it->disabled = temp->disabled;
  910.  strcpy(swap_it->item,temp->item);
  911.  swap_it->menubar = temp->menubar;
  912.  swap_it->type = temp->type;
  913.  swap_it->checked = temp->checked;
  914.  strcpy(swap_it->function,temp->function); 
  915.  strcpy(swap_it->hotkey,temp->hotkey);
  916.  
  917.  free(temp);
  918.  
  919.  /* fix nodes now */ 
  920.  node2->ln_Name = swap_it->item;
  921.  node1->ln_Name = curr_i->item;
  922.  
  923.  }
  924.  swap_it = NULL;
  925.  ord_item = curr_i->index;
  926.  
  927.     GT_SetGadgetAttrs(il,window,NULL,
  928.         GTLV_Labels,&it_list,
  929.         GTLV_Selected,curr_i->index,
  930.         TAG_DONE);
  931.     GT_SetGadgetAttrs(istring,window,NULL,
  932.         GTST_String,curr_i->item,
  933.         TAG_DONE);
  934. }
  935.  
  936.  
  937. /********************** swapit ********************************************/
  938.  
  939. void swapit (void)
  940. {
  941.  struct title_box *temp;
  942.  struct Node *node1,*node2;
  943.  int ord;
  944.  
  945.   if ( !(temp=(struct title_box *)calloc(sizeof(struct title_box),1) ))
  946.     abort_me("Out of memory");
  947.  
  948.  if (swap_tit != curr_t)
  949. {
  950.  
  951.  /* find nodes */
  952.  node1 = node2 = tit_list.lh_Head;
  953.  for (ord=0;ord < curr_t->index;ord++)
  954.     node1 = node1->ln_Succ;
  955.  for (ord=0;ord < swap_tit->index;ord++)
  956.     node2 = node2->ln_Succ;
  957.  
  958.  /* swap title's data */
  959.  temp->disabled = curr_t->disabled;
  960.  temp->items = curr_t->items;
  961.  strcpy(temp->title,curr_t->title);
  962.  
  963.  curr_t->items = swap_tit->items;
  964.  curr_t->disabled = swap_tit->disabled;
  965.  strcpy(curr_t->title,swap_tit->title);
  966.  
  967.  swap_tit->items = temp->items;
  968.  swap_tit->disabled = temp->disabled;
  969.  strcpy(swap_tit->title,temp->title);
  970.  
  971.  free(temp);
  972.  
  973.  /* fix nodes now */ 
  974.  node2->ln_Name = swap_tit->title;
  975.  node1->ln_Name = curr_t->title;
  976.  
  977.  }
  978.  swap_tit = NULL;
  979.  ord_title = curr_t->index;
  980.  
  981.     GT_SetGadgetAttrs(tl,window,NULL,
  982.         GTLV_Labels,&tit_list,
  983.         GTLV_Selected,curr_t->index,
  984.         TAG_DONE);
  985.     GT_SetGadgetAttrs(tstring,window,NULL,
  986.         GTST_String,curr_t->title,
  987.         TAG_DONE);
  988. }
  989.  
  990.  
  991. /************************************* remove item ********************/
  992.  
  993. void rem_item(struct item_box *curr)
  994. {
  995.  struct item_box *temp = curr;
  996.  struct Node *node;
  997.  int ord,x;
  998.  
  999.  x=temp->index;
  1000.  
  1001.  curr_i = curr_t->items;
  1002.  
  1003.  /* remove link */
  1004.  if (temp->prev ) temp->prev->next = temp->next;
  1005.     else if (temp->next) curr_t->items = curr_i = temp->next;
  1006.     else curr_t->items = curr_i = NULL;
  1007.  
  1008.  if (temp->next ) temp->next->prev = temp->prev;
  1009.  
  1010.  
  1011.  /* update indices */
  1012.  temp=temp->next;
  1013.  while(temp) { temp->index--;temp=temp->next;}
  1014.  
  1015.  /* free node */
  1016.  node = it_list.lh_Head;
  1017.  for (ord=0;ord < x;ord++)
  1018.     node=node->ln_Succ;
  1019.  
  1020.  Remove(node);
  1021.  /*free(node);*/
  1022.  
  1023.  /* free its sub_menus*/
  1024.  if (curr->submenu) freeall_subs(curr->submenu);
  1025.  free(curr);
  1026. }
  1027.  
  1028. /********************************* remove sub *****************************/
  1029.  
  1030. void rem_sub(struct sub_box *curr)
  1031. {
  1032.  struct sub_box *temp = curr;
  1033.  struct Node *node;
  1034.  int ord,x;
  1035.  
  1036.  x=temp->index;
  1037.  
  1038.  curr_s = curr_i->submenu;
  1039.  
  1040.  /* remove link */
  1041.  if (temp->prev ) temp->prev->next = temp->next;
  1042.     else if (temp->next) curr_i->submenu = curr_s = temp->next;
  1043.     else curr_i->submenu = curr_s = NULL;
  1044.  
  1045.  if (temp->next ) temp->next->prev = temp->prev;
  1046.  
  1047.  
  1048.  /* update indices */
  1049.  temp=temp->next;
  1050.  while(temp) { temp->index--;temp=temp->next;}
  1051.  
  1052.  /* free node */
  1053.  node = sub_list.lh_Head;
  1054.  for (ord=0;ord < x;ord++)
  1055.     node=node->ln_Succ;
  1056.  
  1057.  Remove(node);
  1058.  /*free(node);*/
  1059.  
  1060.  free(curr);
  1061. }
  1062.  
  1063.  
  1064. /********************************* freeall items ************************/
  1065.  
  1066. void freeall_items(struct item_box *curr)
  1067. {
  1068.   struct item_box *temp = curr;
  1069.  
  1070.    while (curr)
  1071.     {
  1072.       temp=curr->next;
  1073.       if (curr->submenu) freeall_subs (curr->submenu);
  1074.       free(curr);
  1075.       curr=temp;
  1076.     }
  1077. }
  1078.  
  1079. /******************************* freeall subs ***************************/
  1080.  
  1081. void freeall_subs(struct sub_box *curr)
  1082. {
  1083.   struct sub_box *temp = curr;
  1084.  
  1085.   while (curr)
  1086.     {
  1087.       temp=curr->next;
  1088.       free(curr);
  1089.       curr=temp;
  1090.     }
  1091. }
  1092.  
  1093.  
  1094. /********************************** remove title ***************************/
  1095.  
  1096. void rem_title(struct title_box *curr)
  1097. {
  1098.  struct title_box *temp = curr;
  1099.  struct Node *node;
  1100.  int ord,x;
  1101.  
  1102.  x=temp->index;
  1103.  
  1104.  curr_t = topt;
  1105.  /* remove link */
  1106.  if (temp->prev ) temp->prev->next = temp->next;
  1107.     else if (temp->next) topt = curr_t = temp->next;
  1108.     else  topt=curr_t=NULL;
  1109.  
  1110.  if (temp->next ) temp->next->prev = temp->prev;
  1111.  
  1112.  
  1113.  /* update indices */
  1114.  temp=temp->next;
  1115.  while(temp) { temp->index--;temp=temp->next;}
  1116.  
  1117.  /* free item,sub menus */
  1118.  
  1119.  /* free node */
  1120.  node = tit_list.lh_Head;
  1121.  for (ord=0;ord < x;ord++)
  1122.     node=node->ln_Succ;
  1123.  
  1124.  Remove(node);
  1125.  /*free(node);*/
  1126.  
  1127.  /* free title */
  1128.  if (curr->items) freeall_items(curr->items);
  1129.  free(curr);
  1130. }
  1131.  
  1132.  
  1133. /******************************** locate sub ****************************/
  1134.  
  1135. struct sub_box *locate_sub(UWORD code)
  1136. {
  1137.   struct sub_box *temp = curr_i->submenu;
  1138.  
  1139.   while ((temp->index != code) && temp)
  1140.     temp=temp->next;
  1141.  
  1142.   return(temp);
  1143. }
  1144.  
  1145. /**************************** locate item ********************************/
  1146.  
  1147. struct item_box *locate_item(UWORD code)
  1148. {
  1149.   struct item_box *temp = curr_t->items;
  1150.  
  1151.   while ((temp->index != code) && temp)
  1152.     temp=temp->next;
  1153.  
  1154.   return(temp);
  1155. }
  1156.  
  1157. /*************************** locate title ********************************/
  1158.  
  1159. struct title_box *locate_title(UWORD code)
  1160. {
  1161.   struct title_box *temp = topt;
  1162.  
  1163.   while ((temp->index != code) && temp)
  1164.     temp=temp->next;
  1165.  
  1166.   return(temp);
  1167. }
  1168.  
  1169. /****************************** change sub *****************************/
  1170.  
  1171. void change_sub(UWORD code, char *nt)
  1172. {
  1173.  struct sub_box *temp=curr_i->submenu;
  1174.  
  1175.  while((temp->index != code) && temp)
  1176.     temp=temp->next;
  1177.  
  1178.  if (temp)
  1179.     {
  1180.      strcpy(temp->submenu,nt);
  1181.      curr_s = temp;
  1182.     }
  1183. }
  1184.  
  1185.  
  1186. /***************************** change item ****************************/
  1187.  
  1188. void change_item(UWORD code, char *nt)
  1189. {
  1190.  struct item_box *temp=curr_t->items;
  1191.  
  1192.  while((temp->index != code) && temp)
  1193.     temp=temp->next;
  1194.  
  1195.  if (temp)
  1196.     {
  1197.       strcpy(temp->item,nt);
  1198.       curr_i = temp;
  1199.     }
  1200. }
  1201.  
  1202. /***************************** change title ****************************/
  1203.  
  1204. void change_title(UWORD code, char *nt)
  1205. {
  1206.  struct title_box *temp=topt;
  1207.  
  1208.  while((temp->index != code) && temp)
  1209.     temp=temp->next;
  1210.  
  1211.  if (temp){
  1212.        strcpy(temp->title,nt);
  1213.        curr_t = temp;
  1214.      }
  1215. }
  1216.  
  1217. /************************** add title ***********************************/
  1218.  
  1219. void add_title(char *nt)
  1220. {
  1221.  struct Node *node;
  1222.  
  1223.  node=(struct Node *)AllocRemember(&rmem,sizeof(struct Node), MEMF_CLEAR);
  1224.       if (!node)
  1225.           abort_me("couldn't allocate LISTVIEW list.");
  1226.  node->ln_Name = nt;
  1227.  AddTail(&tit_list,node);
  1228.  
  1229. }
  1230.  
  1231.  
  1232. /****************** add item *******************************************/
  1233.  
  1234. void add_item(char *nt)
  1235. {
  1236.  struct Node *node;
  1237.  
  1238.  node=(struct Node *)AllocRemember(&rmem,sizeof(struct Node), MEMF_CLEAR);
  1239.       if (!node)
  1240.           abort_me("couldn't allocate LISTVIEW list.");
  1241.  node->ln_Name = nt;
  1242.  AddTail(&it_list,node);
  1243.  
  1244. }
  1245.  
  1246.  
  1247. /********************** add sub *****************************************/
  1248.  
  1249. void add_sub(char *nt)
  1250. {
  1251.  struct Node *node;
  1252.  
  1253.  node=(struct Node *)AllocRemember(&rmem,sizeof(struct Node), MEMF_CLEAR);
  1254.       if (!node)
  1255.           abort_me("couldn't allocate LISTVIEW list.");
  1256.  node->ln_Name = nt;
  1257.  AddTail(&sub_list,node);
  1258.  
  1259. }
  1260.  
  1261. /************* new title ***********************************************/
  1262. struct title_box *new_title(struct title_box *curr)
  1263. {
  1264.   struct title_box *temp1, *temp2;
  1265.  
  1266.  
  1267.   if ( !(temp1=(struct title_box *)calloc(1,sizeof(struct title_box)) ))
  1268.     abort_me("Out of memory");
  1269.  
  1270.   strcpy(temp1->title,"<none>");
  1271.   temp1->disabled = FALSE;
  1272.  
  1273.   if (curr == NULL) 
  1274.     {
  1275.     curr = topt = temp1;
  1276.     curr->index = 0;
  1277.     curr->next = curr->prev = NULL;
  1278.     curr->items = NULL;
  1279.  
  1280.     }
  1281.   else {
  1282.     /* add new one at end */
  1283.     while (curr->next != NULL) curr = curr->next;
  1284.  
  1285.     temp2 = curr;
  1286.     curr = temp1;
  1287.     curr->index = temp2->index+1;
  1288.     curr->next = temp2->next;
  1289.     temp2->next = curr;
  1290.     curr->prev = temp2;
  1291.     curr->items = NULL;
  1292.  
  1293.     /* maintain proper indices */
  1294. /*    while(temp1->next)
  1295.          {
  1296.          temp1=temp1->next;
  1297.          temp1->index++;
  1298.         }*/
  1299.     }
  1300.  
  1301. return(curr);
  1302. }
  1303.  
  1304.  
  1305. /************* new item ************************************************/
  1306.  
  1307. struct item_box *new_item(struct item_box *curr)
  1308. {
  1309.   struct item_box *temp1, *temp2;
  1310.  
  1311.   if ( !(temp1=(struct item_box *)calloc(1,sizeof(struct item_box )) ))
  1312.     abort_me("Out of memory");
  1313.  
  1314.  
  1315.   strcpy(temp1->item,"<item>");
  1316.   temp1->disabled = FALSE;
  1317.   temp1->menubar = FALSE;
  1318.   temp1->checked = FALSE;
  1319.   temp1->type = NORM;
  1320.   strcpy(temp1->hotkey,"");
  1321.  
  1322.  
  1323.   if (curr_t->items == NULL) 
  1324.     {
  1325.     curr_t->items = temp1;
  1326.     strcpy(curr_t->items->function,"");
  1327.     curr_t->items->next = curr_t->items->prev = NULL;
  1328.     curr_t->items->submenu = NULL;
  1329.     curr_t->items->index = 0;
  1330.     return(curr_t->items);
  1331.     }
  1332.   else {
  1333.     /* add new one at end*/
  1334.     while (curr->next != NULL) curr = curr->next;    
  1335.  
  1336.     temp2 = curr;
  1337.     curr = temp1;
  1338.     curr->next = temp2->next;
  1339.     temp2->next = curr;
  1340.     curr->prev = temp2;
  1341.     curr->submenu = NULL;
  1342.     strcpy(curr->function,"");
  1343.     curr->index = temp2->index+1;
  1344.  
  1345.     /* maintain proper indices */
  1346. /*    while(temp1->next)
  1347.          {
  1348.          temp1=temp1->next;
  1349.          temp1->index++;
  1350.         }*/
  1351.     }
  1352.  
  1353. return(curr);
  1354. }
  1355.  
  1356. /************* new sub *************************************************/
  1357.  
  1358. struct sub_box *new_sub(struct sub_box *curr)
  1359. {
  1360.   struct sub_box *temp1, *temp2;
  1361.  
  1362.   if ( !(temp1=(struct sub_box *)calloc(1,sizeof(struct sub_box )) ))
  1363.     abort_me("Out of memory");
  1364.  
  1365.   strcpy(temp1->submenu,"<sub>");
  1366.   temp1->disabled = FALSE;
  1367.   temp1->menubar = FALSE;
  1368.   temp1->checked = FALSE;
  1369.   temp1->type = NORM;
  1370.   strcpy(temp1->hotkey,"");
  1371.   
  1372.   if (curr_i->submenu == NULL) 
  1373.     {
  1374.     curr_i->submenu = temp1;
  1375.     curr_i->submenu->next = curr_i->submenu->prev = NULL;
  1376.     strcpy(curr_i->submenu->function,"");
  1377.     curr_i->submenu->index = 0;
  1378.     return(curr_i->submenu);
  1379.     }
  1380.   else {
  1381.     /* add new one at end */
  1382.     while (curr->next) curr = curr->next;
  1383.  
  1384.     temp2 = curr;
  1385.     curr = temp1;
  1386.     curr->next = temp2->next;
  1387.     temp2->next = curr;
  1388.     curr->prev = temp2;
  1389.     strcpy(curr->function,"");
  1390.     curr->index = temp2->index+1;
  1391.  
  1392.     /* maintain proper indices */
  1393.     while(temp1->next)
  1394.          {
  1395.          temp1=temp1->next;
  1396.          temp1->index++;
  1397.         }
  1398.     }
  1399.  
  1400. return(curr);
  1401. }
  1402.  
  1403.  
  1404. /***************** clone current parameters *********************************/
  1405.  
  1406. void old_menu(void)
  1407. {
  1408.   struct title_box *temp= topt;
  1409.   struct title_box *newt = NULL;
  1410.  
  1411.   if (topt) {
  1412.     
  1413.   /* grab first one */
  1414.   if ( !(newtop=newt=(struct title_box *)calloc(1,sizeof(struct title_box)) ))
  1415.     abort_me("Out of memory");
  1416.    
  1417. /*  printf("%s\n",temp->title); */
  1418.   newt->disabled = temp->disabled;
  1419.   strcpy(newt->title,temp->title);
  1420.   newt->next = NULL;
  1421.   newt->prev = NULL; 
  1422.   newt->items = NULL;
  1423.   newt->index = temp->index;
  1424.   if (temp->items)  newt->items = grabitem(temp->items);
  1425.  
  1426.   temp = temp->next;
  1427.   
  1428.   while (temp) {
  1429.   newt->next =grabtitle(temp);
  1430.   newt->next->prev = newt;
  1431.   newt=newt->next;
  1432.   temp = temp->next;
  1433.    }
  1434.  } else newtop = NULL;
  1435. }
  1436.  
  1437. /********************** grabtitle *****************************************/
  1438.  
  1439. struct title_box *grabtitle(struct title_box *temp)
  1440. {
  1441.   struct title_box *newt = NULL;
  1442.   
  1443.   if ( !(newt=(struct title_box *)calloc(1,sizeof(struct title_box)) ))
  1444.     abort_me("Out of memory");
  1445.    
  1446.  newt->disabled = temp->disabled;
  1447.  strcpy(newt->title,temp->title);
  1448.  newt->next = NULL;
  1449.  newt->index = temp->index;
  1450.  
  1451.  newt->items = NULL;
  1452.  if (temp->items)  newt->items = grabitem(temp->items);
  1453.  
  1454.  return(newt);
  1455. }
  1456.  
  1457. /******************* grabitem ********************************************/
  1458.  
  1459. struct item_box *grabitem(struct item_box *tempi)
  1460. {
  1461.  struct item_box *newi = NULL;
  1462.  struct item_box *newi2 = NULL;
  1463.  
  1464.  /* get first one */
  1465.  if ( !(newi=newi2=(struct item_box *)calloc(1,sizeof(struct item_box)) ))
  1466.     abort_me("Out of memory");
  1467.  
  1468.  newi->disabled = tempi->disabled;
  1469.  strcpy(newi->item,tempi->item);
  1470.  newi->menubar = tempi->menubar;
  1471.  newi->type = tempi->type;
  1472.  newi->checked = tempi->checked;
  1473.  strcpy(newi->function,tempi->function); 
  1474.  strcpy(newi->hotkey, tempi->hotkey);
  1475.  newi->prev = newi->next = NULL;
  1476.  newi->index = tempi->index;
  1477.  
  1478.  newi->submenu = NULL;
  1479.  if (tempi->submenu) newi->submenu = grabsub(tempi->submenu); 
  1480.  
  1481.  tempi=tempi->next;
  1482.  
  1483.   while (tempi){
  1484.       if ( !(newi2->next=(struct item_box *)calloc(1,sizeof(struct item_box)) ))
  1485.     abort_me("Out of memory");    
  1486.             
  1487.       newi2->next->prev = newi2;
  1488.       newi2->next->next = NULL;
  1489.       newi2 = newi2->next;
  1490.  
  1491.         newi2->index = tempi->index;
  1492.         newi2->disabled = tempi->disabled;
  1493.      strcpy(newi2->item,tempi->item);
  1494.     newi2->menubar = tempi->menubar;
  1495.      newi2->type = tempi->type;
  1496.      newi2->checked = tempi->checked;
  1497.      strcpy(newi2->function,tempi->function); 
  1498.      strcpy(newi2->hotkey, tempi->hotkey);
  1499.     if (tempi->submenu) newi2->submenu = grabsub(tempi->submenu); 
  1500.     tempi=tempi->next;
  1501.     }
  1502.  
  1503.  return(newi);
  1504. }
  1505.  
  1506. /******************** grabsub *********************************************/
  1507.  
  1508. struct sub_box *grabsub(struct sub_box *temps)
  1509. {
  1510.  struct sub_box *news,*news2;
  1511.  
  1512.  /* get first */
  1513.  if ( !(news=news2=(struct sub_box *)calloc(1,sizeof(struct sub_box )) ))
  1514.     abort_me("Out of memory");
  1515.  
  1516.  news->disabled = temps->disabled;
  1517.  strcpy(news->submenu,temps->submenu);
  1518.  news->menubar = temps->menubar;
  1519.  news->type = temps->type;
  1520.  strcpy(news->function,temps->function);
  1521.  news->checked = temps->checked;
  1522.  strcpy(news->hotkey,temps->hotkey);
  1523.  news->next=news->prev = NULL;
  1524.  news->index = temps->index;
  1525.  
  1526.  temps=temps->next;
  1527.  
  1528.  while(temps)
  1529.      {
  1530.       if ( !(news2->next=(struct sub_box *)calloc(1,sizeof(struct sub_box )) ))
  1531.     abort_me("Out of memory");
  1532.  
  1533.       news2->next->prev = news2;
  1534.       news2->next->next = NULL;
  1535.       news2=news2->next;
  1536.  
  1537.      news2->index = temps->index;
  1538.      news2->disabled = temps->disabled;
  1539.      strcpy(news2->submenu,temps->submenu);
  1540.      news2->menubar = temps->menubar;
  1541.      news2->type = temps->type;
  1542.      strcpy(news2->function,temps->function);
  1543.      news2->checked = temps->checked;
  1544.      strcpy(news2->hotkey,temps->hotkey);
  1545.  
  1546.        temps=temps->next;
  1547.     }
  1548.  
  1549. return(news);
  1550. }
  1551.  
  1552. /**************** free menu structure *************************************/
  1553.  
  1554. void free_allmenu (struct title_box *top)
  1555. {
  1556.  struct title_box *temp = top;
  1557.  struct title_box *temp2 = NULL;
  1558.  struct item_box  *tempi, *tempi2;
  1559.  struct sub_box   *temps, *temps2;
  1560.  
  1561.  while (temp)
  1562.      {
  1563.      temp2 = temp;
  1564.       if (temp->items) {
  1565.         tempi = tempi2 = temp->items;
  1566.         while(tempi)
  1567.             {
  1568.               if (tempi->submenu){
  1569.               temps = temps2 = tempi->submenu;
  1570.               while(temps)
  1571.                 {
  1572.                   if (temps->next) temps=temps->next;
  1573.                   else temps=NULL;
  1574.                   free(temps2);
  1575.                   temps2 = temps;
  1576.                 }}
  1577.                if (tempi->next) tempi=tempi->next;
  1578.                else tempi=NULL;
  1579.                free(tempi2);
  1580.                tempi2 = tempi;
  1581.             }}
  1582.       if (temp->next) temp=temp->next;
  1583.       else temp=NULL;
  1584.       free(temp2);
  1585.       temp2=temp;
  1586.     }
  1587. }
  1588.  
  1589.  
  1590.