home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Config / main2.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  28KB  |  1,019 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "config.h"
  32.  
  33. static struct dopusgadgetbanks *currentbank,*selbank;
  34.  
  35. dogadgetconfig()
  36. {
  37.     ULONG class;
  38.     USHORT code,gadgetid;
  39.     struct ConfigUndo *undo;
  40.     struct DOpusRemember *gadkey=NULL;
  41.     struct dopusgadgetbanks *bank,*bank2;
  42.     struct newdopusfunction *secondgad;
  43.     struct Gadget *gad;
  44.     struct Border *unselborder,*selborder;
  45.     char buf[80];
  46.     int a,b,x,y,mode=-1;
  47.  
  48.     if (!(gadgads=(struct Gadget *)LAllocRemember(&gadkey,sizeof(struct Gadget)*GADCOUNT,
  49.         MEMF_CLEAR))) return(0);
  50.  
  51.     CreateGadgetBorders(&gadkey,
  52.         80,10,
  53.         &selborder,&unselborder,
  54.         0,
  55.         screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  56.  
  57.     selgad=NULL; selbank=NULL; seligad=NULL;
  58.  
  59.     x=x_off+38; y=y_off+4;
  60.     for (a=0;a<GADCOUNT;a++) {
  61.         gadgads[a].NextGadget=(a<GADCOUNT-1)?&gadgads[a+1]:NULL;
  62.         gadgads[a].LeftEdge=x;
  63.         gadgads[a].TopEdge=y;
  64.         gadgads[a].Width=80;
  65.         gadgads[a].Height=10;
  66.         gadgads[a].Flags=(selborder)?GFLG_GADGHIMAGE:GFLG_GADGHCOMP;
  67.         gadgads[a].Activation=GACT_RELVERIFY;
  68.         gadgads[a].GadgetType=GTYP_BOOLGADGET;
  69.         gadgads[a].GadgetID=a+100;
  70.         gadgads[a].GadgetRender=unselborder;
  71.         gadgads[a].SelectRender=selborder;
  72.         if ((x+=80)>=x_off+598) {
  73.             x=x_off+38;
  74.             if ((y+=10)==y_off+64) y+=14;
  75.         }
  76.     }
  77.  
  78.     paint_state=0;
  79.     showconfigscreen(CFG_GADGET);
  80.     ClearMenuStrip(Window);
  81.     projectmenu.NextMenu=&gadrowsmenu;
  82.     neatstuffitem.Flags&=~CHECKED;
  83.     neatstuffmenu.LeftEdge=272;
  84.  
  85.     for (a=0;a<5;a++) {
  86.         if (config->gadgetrows==rowtrans[a]) gadrowsitems[a].Flags|=CHECKED;
  87.         else gadrowsitems[a].Flags&=~CHECKED;
  88.     }
  89.     FSSetMenuStrip(Window,&projectmenu);
  90.     undo=makeundo(UNDO_GADGET);
  91.     currentbank=firstbank;
  92.     showgadgets(currentbank,1);
  93.     nextbankrmb.x=maingad[0].LeftEdge;
  94.     nextbankrmb.y=maingad[0].TopEdge;
  95.     insertbankrmb.x=maingad[1].LeftEdge;
  96.     insertbankrmb.y=maingad[1].TopEdge;
  97.     fixrmbimage(&nextbankrmb,maingad,1,-1,-1);
  98.  
  99.     FOREVER {
  100.         Wait(1<<Window->UserPort->mp_SigBit);
  101.         while (IMsg=getintuimsg()) {
  102.             class=IMsg->Class;
  103.             code=IMsg->Code;
  104.             x=IMsg->MouseX;
  105.             y=IMsg->MouseY;
  106.             if (class==IDCMP_GADGETUP || class==IDCMP_GADGETDOWN) {
  107.                 gad=(struct Gadget *)IMsg->IAddress;
  108.                 gadgetid=gad->GadgetID;
  109.             }
  110.             ReplyMsg((struct Message *)IMsg);
  111.             switch (class) {
  112.                 case IDCMP_MENUPICK:
  113.                     if (code==MENUNULL) break;
  114.                     switch (MENUNUM(code)) {
  115.                         case 0:
  116.                             if (selgad) {
  117.                                 if (selbank==currentbank) select_gadget(seligad,0);
  118.                                 selbank=NULL; seligad=NULL; selgad=NULL;
  119.                             }
  120.                             if (mode>-1) {
  121.                                 select_gadget(&maingad[mode],0);
  122.                                 mode=-1;
  123.                             }
  124.                             dogadgetinfo(NULL);
  125.                             switch ((a=ITEMNUM(code))) {
  126.                                 case 0:
  127.                                 case 1:
  128.                                     if (doload(CFG_GADGET,a)) {
  129.                                         if (bank=firstbank) {
  130.                                             while (bank->next) bank=bank->next;
  131.                                             currentbank=bank;
  132.                                             showgadgets(currentbank,1);
  133.                                             if (a) dogadgetinfo(cfg_string[STR_NEW_GADGET_BANKS_APPENDED]);
  134.                                             else dogadgetinfo(cfg_string[STR_DEFAULT_GADGET_BANKS_APPENDED]);
  135.                                         }
  136.                                     }
  137.                                     break;
  138.                             }
  139.                             break;
  140.                         case 1:
  141.                             config->gadgetrows=rowtrans[ITEMNUM(code)];
  142.                             break;
  143.                         case 2:
  144.                             if (ITEMNUM(code)==0) {
  145.                                 if (neatstuffitem.Flags&CHECKED) {
  146.                                     if (!(paint_state=get_paint_colours(&paint_fg,&paint_bg,CFG_GADGET))) {
  147.                                         ClearMenuStrip(Window);
  148.                                         neatstuffitem.Flags&=~CHECKED;
  149.                                         FSSetMenuStrip(Window,&projectmenu);
  150.                                     }
  151.                                 }
  152.                                 else paint_state=0;
  153.                                 showgadgets(currentbank,0);
  154.                             }
  155.                             break;
  156.                     }
  157.                     break;
  158.  
  159.                 case IDCMP_MOUSEBUTTONS:
  160.                     if (code==MENUDOWN) {
  161.                         fixrmbimage(&nextbankrmb,maingad,0,x,y);
  162.                         if ((a=DoRMBGadget(&nextbankrmb,Window))==0) {
  163.                             if (currentbank) {
  164.                                 if (mode==-1) dogadgetinfo(NULL);
  165.                                 if (selgad && selbank==currentbank) select_gadget(seligad,0);
  166.                                 bank2=currentbank;
  167.                                 if (!(bank=lastbank(currentbank))) {
  168.                                     bank=firstbank;
  169.                                     while (bank && bank->next) bank=bank->next;
  170.                                 }
  171.                                 currentbank=bank;
  172.                                 if (currentbank!=bank2) showgadgets(currentbank,1);
  173.                                 if (selgad && selbank==currentbank) select_gadget(seligad,1);
  174.                             }
  175.                             else dogadgetinfo(cfg_string[STR_NO_GADGET_BANKS_CONFIGURED]);
  176.                         }
  177.                         else if (a==1) makenewbank(1);
  178.                         fixrmbimage(&nextbankrmb,maingad,1,-1,-1);
  179.                     }
  180.                     break;
  181.  
  182.                 case IDCMP_GADGETUP:
  183.                     if (gadgetid<GAD_OKAY) {
  184.                         if (selgad) {
  185.                             if (gadgetid!=GAD_NEXTBANK) selgad=NULL;
  186.                             if (selbank==currentbank) select_gadget(seligad,0);
  187.                             if (gadgetid!=GAD_NEXTBANK) {
  188.                                 selbank=NULL; seligad=NULL;
  189.                             }
  190.                         }
  191.                         if (mode==gadgetid) {
  192.                             mode=-1;
  193.                             dogadgetinfo(NULL);
  194.                             break;
  195.                         }
  196.                         if (gadgetid!=GAD_NEXTBANK && mode>-1) {
  197.                             select_gadget(&maingad[mode],0);
  198.                             mode=-1;
  199.                         }
  200.                         if (gadgetid!=GAD_NEWBANK && !firstbank) {
  201.                             dogadgetinfo(cfg_string[STR_NO_GADGET_BANKS_CONFIGURED]);
  202.                             if (gad->Activation&GACT_TOGGLESELECT) select_gadget(gad,0);
  203.                             break;
  204.                         }
  205.                     }
  206.                     else if (gadgetid>=100) {
  207.                         if (!firstbank) {
  208.                             dogadgetinfo(cfg_string[STR_NO_GADGET_BANKS_CONFIGURED]);
  209.                             break;
  210.                         }
  211.                         a=gadgetid-100;
  212.                         if (mode>-1) {
  213.                             if (mode==GAD_DELETEGADGET) {
  214.                                 selgad=&(currentbank->gadgets[a]);
  215.                                 clearmenu(selgad);
  216.                                 selgad->fpen=1; selgad->bpen=0;
  217.                                 freenewfunction(selgad);
  218.                                 selgad=NULL;
  219.                                 dogadgetinfo(cfg_string[STR_GADGET_DELETED]);
  220.                                 showgadgetname(selgad,gad);
  221.                             }
  222.                             else if (!selgad) {
  223.                                 selgad=&(currentbank->gadgets[a]);
  224.                                 seligad=gad;
  225.                                 selbank=currentbank;
  226.                                 select_gadget(gad,1);
  227.                                 if (mode==GAD_COPYGADGET)
  228.                                     dogadgetinfo(cfg_string[STR_SELECT_GADGET_TO_COPY]);
  229.                                 else if (mode==GAD_SWAPGADGET)
  230.                                     dogadgetinfo(cfg_string[STR_SELECT_GADGET_TO_SWAP]);
  231.                             }
  232.                             else {
  233.                                 secondgad=&(currentbank->gadgets[a]);
  234.                                 if (selgad==secondgad) select_gadget(gad,0);
  235.                                 else {
  236.                                     if (mode==GAD_COPYGADGET) {
  237.                                         freenewfunction(secondgad);
  238.                                         CopyMem((char *)selgad,(char *)secondgad,sizeof(struct newdopusfunction));
  239.                                         secondgad->name=getcopy(selgad->name,-1,NULL);
  240.                                         secondgad->function=getcopy(selgad->function,-1,NULL);
  241.                                     }
  242.                                     else if (mode==GAD_SWAPGADGET)
  243.                                         SwapMem((char *)selgad,(char *)secondgad,sizeof(struct dopusfunction));
  244.                                     showgadgetname(secondgad,gad);
  245.                                     if (selbank==currentbank) {
  246.                                         select_gadget(seligad,0);
  247.                                         showgadgetname(selgad,seligad);
  248.                                     }
  249.                                 }
  250.                                 selgad=NULL; seligad=NULL; selbank=NULL;
  251.                                 if (mode==GAD_COPYGADGET)
  252.                                     dogadgetinfo(cfg_string[STR_SELECT_A_GADGET_TO_COPY]);
  253.                                 else if (mode==GAD_SWAPGADGET)
  254.                                     dogadgetinfo(cfg_string[STR_SELECT_FIRST_GADGET_TO_SWAP]);
  255.                             }
  256.                         }
  257.                         else {
  258.                             if (paint_state) {
  259.                                 currentbank->gadgets[a].fpen=paint_fg;
  260.                                 currentbank->gadgets[a].bpen=paint_bg;
  261.                                 showgadgetname(¤tbank->gadgets[a],&gadgads[a]);
  262.                             }
  263.                             else {
  264.                                 cleanconfigscreen();
  265.                                 selgad=&(currentbank->gadgets[a]);
  266.                                 doscreentitle(cfg_string[STR_GADGET_EDIT_SCREEN]);
  267.                                 editfunction((struct dopusfunction *)selgad,CFG_GADGET,NULL);
  268.                                 showconfigscreen(CFG_GADGET);
  269.                                 fixrmbimage(&nextbankrmb,maingad,1,-1,-1);
  270.                                 selgad=NULL;
  271.                                 showgadgets(currentbank,1);
  272.                             }
  273.                         }
  274.                         break;
  275.                     }
  276.                     switch (gadgetid) {
  277.                         case GAD_NEXTBANK:
  278.                             bank2=currentbank;
  279.                             if (!(currentbank=currentbank->next)) currentbank=firstbank;
  280.                             if (currentbank!=bank2) showgadgets(currentbank,1);
  281.                             if (mode==-1) dogadgetinfo(NULL);
  282.                             break;
  283.                         case GAD_NEWBANK:
  284.                             makenewbank(0);
  285.                             break;
  286.                         case GAD_COPYBANK:
  287.                             dogadgetinfo(NULL);
  288.                             buf[0]=0;
  289.                             if (!getstring(cfg_string[STR_ENTER_BANK_TO_COPY],buf,5,SRF_LONGINT|SRF_CENTJUST))
  290.                                 break;
  291.                             a=atoi(buf)-1;
  292.                             if (a<0) break;
  293.                             bank2=currentbank;
  294.                             bank=firstbank;
  295.                             for (b=0;b<a;b++) if (!(bank=bank->next)) break;
  296.                             if (bank) {
  297.                                 showgadgets(bank,1);
  298.                                 if (!(request(cfg_string[STR_BANK_ALREADY_EXISTS]))) {
  299.                                     showgadgets(currentbank,1);
  300.                                     break;
  301.                                 }
  302.                                 freegadgetbank(bank,0);
  303.                                 currentbank=bank;
  304.                                 dogadgetinfo(cfg_string[STR_GADGET_BANK_COPIED]);
  305.                             }
  306.                             else if (!makenewbank(0)) break;
  307.                             CopyMem((char *)bank2,(char *)currentbank,sizeof(struct newdopusfunction)*GADCOUNT);
  308.                             copygadgets(bank2,currentbank,NULL);
  309.                             showgadgets(currentbank,1);
  310.                             break;
  311.                         case GAD_SWAPBANK:
  312.                             dogadgetinfo(NULL);
  313.                             buf[0]=0;
  314.                             if (!getstring(cfg_string[STR_ENTER_BANK_TO_SWAP],buf,5,SRF_LONGINT|SRF_CENTJUST))
  315.                                 break;
  316.                             a=atoi(buf)-1;
  317.                             if (a<0) break;
  318.                             bank=firstbank;
  319.                             for (b=0;b<a;b++) if (!(bank=bank->next)) break;
  320.                             if (!bank) {
  321.                                 dogadgetinfo(cfg_string[STR_BANK_DOES_NOT_EXIST]);
  322.                                 break;
  323.                             }
  324.                             if (bank==currentbank) break;
  325.                             SwapMem((char *)bank,(char *)currentbank,sizeof(struct newdopusfunction)*GADCOUNT);
  326.                             showgadgets(currentbank,1);
  327.                             dogadgetinfo(cfg_string[STR_BANKS_SWAPPED]);
  328.                             break;
  329.                         case GAD_DELETEBANK:
  330.                             dogadgetinfo(NULL);
  331.                             if (currentbank==firstbank && !currentbank->next) {
  332.                                 if (!request(cfg_string[STR_ONLY_BANK_CONFIGURED])) break;
  333.                             }
  334.                             else if (!request(cfg_string[STR_REALLY_DELETE_BANK]))
  335.                                 break;
  336.                             if (bank=lastbank(currentbank)) bank->next=currentbank->next;
  337.                             if (firstbank==currentbank) firstbank=currentbank->next;
  338.                             freegadgetbank(currentbank,1);
  339.                             if (bank && bank->next) currentbank=bank->next;
  340.                             else if (bank) currentbank=bank;
  341.                             else currentbank=firstbank;
  342.                             dogadgetinfo(cfg_string[STR_BANK_DELETED]);
  343.                             showgadgets(currentbank,1);
  344.                             break;
  345.                         case GAD_COPYGADGET:
  346.                             mode=GAD_COPYGADGET;
  347.                             dogadgetinfo(cfg_string[STR_SELECT_A_GADGET_TO_COPY]);
  348.                             break;
  349.                         case GAD_SWAPGADGET:
  350.                             mode=GAD_SWAPGADGET;
  351.                             dogadgetinfo(cfg_string[STR_SELECT_FIRST_GADGET_TO_SWAP]);
  352.                             break;
  353.                         case GAD_DELETEGADGET:
  354.                             mode=GAD_DELETEGADGET;
  355.                             dogadgetinfo(cfg_string[STR_SELECT_GADGET_TO_DELETE]);
  356.                             break;
  357.                         case GAD_CANCEL:
  358.                             doundo(undo,UNDO_GADGET);
  359.                         case GAD_OKAY:
  360.                             doundo(undo,0);
  361.                             RemoveGList(Window,gadgads,GADCOUNT);
  362.                             LFreeRemember(&gadkey); gadgads=NULL;
  363.                             ClearMenuStrip(Window); projectmenu.NextMenu=NULL;
  364.                             FSSetMenuStrip(Window,&projectmenu);
  365.                             paint_state=0;
  366.                             return((gadgetid==GAD_OKAY));
  367.                     }
  368.             }
  369.         }
  370.     }
  371. }
  372.  
  373. void showgadgets(bank,show)
  374. struct dopusgadgetbanks *bank;
  375. int show;
  376. {
  377.     int a;
  378.     struct dopusgadgetbanks *bank2;
  379.     char buf[60],*ptr;
  380.  
  381.     if (show) {
  382.         for (a=0;a<GADCOUNT;a++) {
  383.             if (bank) {
  384.                 showgadgetname(&bank->gadgets[a],&gadgads[a]);
  385.                 if (selgad==&bank->gadgets[a]) select_gadget(&gadgads[a],1);
  386.             }
  387.             else showgadgetname(NULL,&gadgads[a]);
  388.         }
  389.     }
  390.     if (bank) {
  391.         bank2=firstbank; a=0;
  392.         while (bank2 && bank2!=bank) {
  393.             ++a;
  394.             bank2=bank2->next;
  395.         }
  396.         lsprintf(buf,"%s %ld",cfg_string[STR_GADGET_BANK_NUMBER],a+1);
  397.         if (paint_state) strcat(buf,cfg_string[STR_PAINT_STATE]);
  398.         ptr=buf;
  399.     }
  400.     else ptr=cfg_string[STR_GADGET_SCREEN_NO_BANKS];
  401.     doscreentitle(ptr);
  402. }
  403.  
  404. void showgadgetname(gad,gadget)
  405. struct newdopusfunction *gad;
  406. struct Gadget *gadget;
  407. {
  408.     int a,x,y;
  409.  
  410.     x=gadget->LeftEdge;
  411.     y=gadget->TopEdge;
  412.     if (gad) SetAPen(rp,screen_pens[gad->bpen].pen);
  413.     else SetAPen(rp,screen_pens[0].pen);
  414.     RectFill(rp,x+2,y+1,x+77,y+8);
  415.     if (gad) {
  416.         SetAPen(rp,screen_pens[gad->fpen].pen);
  417.         SetBPen(rp,screen_pens[gad->bpen].pen);
  418.         if (gad->name && gad->name[0]) {
  419.             Move(rp,x+((80-(((a=strlen(gad->name))>9?(a=9):a)*8))/2),y+7);
  420.             Text(rp,gad->name,a);
  421.         }
  422.     }
  423.     SetBPen(rp,screen_pens[0].pen);
  424. }
  425.  
  426. makenewbank(insert)
  427. int insert;
  428. {
  429.     struct dopusgadgetbanks *bank,*bank2;
  430.     int a;
  431.  
  432.     if (!(bank=AllocMem(sizeof(struct dopusgadgetbanks),MEMF_CLEAR))) {
  433.         dogadgetinfo(cfg_string[STR_NO_MEMORY_FOR_NEW_BANK]);
  434.         return(0);
  435.     }
  436.     for (a=0;a<GADCOUNT;a++) {
  437.         bank->gadgets[a].stack=4000; bank->gadgets[a].delay=2;
  438.         if (paint_state) {
  439.             bank->gadgets[a].fpen=paint_fg;
  440.             bank->gadgets[a].bpen=paint_bg;
  441.         }
  442.         else bank->gadgets[a].fpen=1;
  443.     }
  444.     if (insert && firstbank) {
  445.         if (currentbank==firstbank) {
  446.             bank->next=firstbank;
  447.             firstbank=bank;
  448.         }
  449.         else {
  450.             bank2=firstbank;
  451.             while (bank2->next) {
  452.                 if (bank2->next==currentbank) break;
  453.                 bank2=bank2->next;
  454.             }
  455.             if (bank2->next==currentbank) {
  456.                 bank2->next=bank;
  457.                 bank->next=currentbank;
  458.             }
  459.             else bank2->next=bank;
  460.         }
  461.     }
  462.     else {
  463.         if (!firstbank) firstbank=bank;
  464.         else {
  465.             bank2=firstbank;
  466.             while (bank2->next) bank2=bank2->next;
  467.             bank2->next=bank;
  468.         }
  469.     }
  470.     currentbank=bank;
  471.     showgadgets(currentbank,1);
  472.     dogadgetinfo(cfg_string[STR_NEW_BANK_CREATED]);
  473.     return(1);
  474. }
  475.  
  476. struct dopusgadgetbanks *lastbank(bank)
  477. struct dopusgadgetbanks *bank;
  478. {
  479.     struct dopusgadgetbanks *temp;
  480.  
  481.     temp=firstbank;
  482.     while (temp && temp->next!=bank) temp=temp->next;
  483.     return(temp);
  484. }
  485.  
  486. void dogadgetinfo(str)
  487. char *str;
  488. {
  489.     int tx,ex,len,x;
  490.  
  491.     x=(Window->Width-580)/2;
  492.  
  493.     Do3DBox(rp,
  494.         x,y_off+144,
  495.         580,10,
  496.         screen_pens[config->gadgetbotcol].pen,screen_pens[config->gadgettopcol].pen);
  497.     SetDrMd(rp,JAM2);
  498.  
  499.     tx=x;
  500.     if (str) {
  501.         SetAPen(rp,screen_pens[1].pen);
  502.         tx+=(580-((len=strlen(str))*8))/2;
  503.         UScoreText(rp,str,tx,y_off+151,-1);
  504.         ex=rp->cp_x;
  505.     }
  506.     else ex=x;
  507.     SetAPen(rp,screen_pens[0].pen);
  508.     if (tx>x) RectFill(rp,x,y_off+145,tx-1,y_off+153);
  509.     if (ex<x+579) RectFill(rp,ex,y_off+145,x+579,y_off+153);
  510. }
  511.  
  512. static struct newdopusfunction *selmenu;
  513. static int menuoffset;
  514.  
  515. domenuconfig()
  516. {
  517.     ULONG class;
  518.     USHORT code,gadgetid;
  519.     struct ConfigUndo *undo;
  520.     struct Gadget *gad;
  521.     struct DOpusRemember *menukey=NULL;
  522.     struct newdopusfunction *secondmenu;
  523.     int a,b,x,y,mode=-1,gid,mnum=-1,omnum;
  524.     char buf[100];
  525.  
  526.     if (!(menugads=(struct Gadget *)LAllocRemember(&menukey,sizeof(struct Gadget)*
  527.         (MENUCOUNT+5-(HIDDENLINES*5)),MEMF_CLEAR))) return(0);
  528.     selgad=NULL; selbank=NULL;
  529.     menuoffset=0;
  530.  
  531.     a=0; gid=100;
  532.     for (x=0;x<5;x++,gid+=HIDDENLINES) {
  533.         for (y=0;y<20-HIDDENLINES;y++,a++) {
  534.             menugads[a].NextGadget=(a<MENUCOUNT+4-(HIDDENLINES*5))?&menugads[a+1]:NULL;
  535.             menugads[a].LeftEdge=(x*120)+x_off+12;
  536.             menugads[a].TopEdge=(y*8)+y_off+21;
  537.             menugads[a].Width=112;
  538.             menugads[a].Height=8;
  539.             menugads[a].Flags=GADGHCOMP; menugads[a].Activation=RELVERIFY;
  540.             menugads[a].GadgetType=BOOLGADGET;
  541.             menugads[a].GadgetID=gid++;
  542.         }
  543.     }
  544.     gid=200;
  545.     for (x=0;x<5;x++,a++) {
  546.         menugads[a].NextGadget=(x<4)?&menugads[a+1]:NULL;
  547.         menugads[a].LeftEdge=(x*120)+x_off+12;
  548.         menugads[a].TopEdge=y_off+8;
  549.         menugads[a].Width=112;
  550.         menugads[a].Height=8;
  551.         menugads[a].Flags=GADGHCOMP; menugads[a].Activation=RELVERIFY;
  552.         menugads[a].GadgetType=BOOLGADGET;
  553.         menugads[a].GadgetID=gid++;
  554.     }
  555.  
  556.     fix_slider(&menuslidergads[0]);
  557.     AddGadgetBorders(&menukey,
  558.         &menuslidergads[1],
  559.         2,
  560.         screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  561.  
  562.     showconfigscreen(CFG_MENU);
  563.     ClearMenuStrip(Window);
  564.     projectmenu.NextMenu=&neatstuffmenu;
  565.     neatstuffitem.Flags&=~CHECKED;
  566.     neatstuffmenu.LeftEdge=140;
  567.     FSSetMenuStrip(Window,&projectmenu);
  568.  
  569.     paint_state=0;
  570.     undo=makeundo(UNDO_MENU);
  571.     showmenus(7);
  572.  
  573.     FOREVER {
  574.         Wait(1<<Window->UserPort->mp_SigBit);
  575.         while (IMsg=getintuimsg()) {
  576.             class=IMsg->Class; code=IMsg->Code;
  577.             if (class==GADGETUP || class==GADGETDOWN) {
  578.                 gad=(struct Gadget *)IMsg->IAddress;
  579.                 gadgetid=gad->GadgetID;
  580.             }
  581.             ReplyMsg((struct Message *)IMsg);
  582.             switch (class) {
  583.                 case IDCMP_MENUPICK:
  584.                     if (code==MENUNULL) break;
  585.                     switch (MENUNUM(code)) {
  586.                         case 0:
  587.                             if (selmenu) {
  588.                                 selmenu=NULL;
  589.                                 showmenus(5);
  590.                             }
  591.                             dogadgetinfo(NULL);
  592.                             if (mode>-1) {
  593.                                 select_gadget(&maingad[mode],0);
  594.                                 mode=-1;
  595.                             }
  596.                             switch ((a=ITEMNUM(code))) {
  597.                                 case 0:
  598.                                 case 1:
  599.                                     if (doload(CFG_MENU,a)) {
  600.                                         showmenus(5);
  601.                                         if (a) dogadgetinfo(cfg_string[STR_NEW_MENUS_LOADED]);
  602.                                         else dogadgetinfo(cfg_string[STR_DEFAULT_MENUS_LOADED]);
  603.                                     }
  604.                                     break;
  605.                             }
  606.                             break;
  607.                         case 1:
  608.                             if (ITEMNUM(code)==0) {
  609.                                 if (neatstuffitem.Flags&CHECKED) {
  610.                                     if (!(paint_state=get_paint_colours(&paint_fg,&paint_bg,CFG_MENU))) {
  611.                                         ClearMenuStrip(Window);
  612.                                         neatstuffitem.Flags&=~CHECKED;
  613.                                         FSSetMenuStrip(Window,&projectmenu);
  614.                                     }
  615.                                 }
  616.                                 else paint_state=0;
  617.                                 do_menuscreen_title(STR_MENU_SCREEN);
  618.                             }
  619.                             break;
  620.                     }
  621.                     break;
  622.  
  623.                 case IDCMP_GADGETUP:
  624.                     if (gadgetid<MENU_OKAY) {
  625.                         if (selmenu) {
  626.                             selmenu=NULL;
  627.                             showmenus(5);
  628.                         }
  629.                         dogadgetinfo(NULL);
  630.                         if (mode==gadgetid) {
  631.                             mode=-1;
  632.                             break;
  633.                         }
  634.                         if (mode>-1) {
  635.                             select_gadget(&maingad[mode],0);
  636.                             mode=-1;
  637.                         }
  638.                     }
  639.                     if (gadgetid>199) {
  640.                         if ((a=gadgetid-200)<0 || a>4) break;
  641.                         if (mode==MENU_DELETEMENU || mode==MENU_SORTMENU ||
  642.                             mode==MENU_COPYMENU || mode==MENU_SWAPMENU) {
  643.                             gadgetid=100+(a*20);
  644.                         }
  645.                         else {
  646.                             if (getstring(cfg_string[STR_ENTER_MENU_TITLE],config->menutit[a],14,SRF_CENTJUST))
  647.                                 showmenus(4);
  648.                             break;
  649.                         }
  650.                     }
  651.                     if (gadgetid>99 && gadgetid<200) {
  652.                         a=(gadgetid-100)+menuoffset;
  653.                         omnum=mnum; mnum=a/20;
  654.                         if (mode>-1) {
  655.                             switch (mode) {
  656.                                 case MENU_DELETEITEM:    
  657.                                     clearmenu(&config->menu[a]);
  658.                                     freenewfunction(&config->menu[a]);
  659.                                     if (((a+1)%20)!=0) {
  660.                                         x=((a+20)/20)*20-1;
  661.                                         y=x-a;
  662.                                         CopyMem((char *)&config->menu[a+1],&config->menu[a],y*sizeof(struct dopusfunction));
  663.                                         clearmenu(&config->menu[x]);
  664.                                         config->menu[x].function=NULL;
  665.                                         config->menu[x].name=NULL;
  666.                                     }
  667.                                     showmenus(1);
  668.                                     dogadgetinfo(cfg_string[STR_MENU_ITEM_DELETED]);
  669.                                     break;
  670.                                 case MENU_INSERTITEM:
  671.                                     x=((a+20)/20)*20-1;
  672.                                     freenewfunction(&config->menu[x]);
  673.                                     for (b=x-1;b>=a;b--)
  674.                                         CopyMem((char *)&config->menu[b],&config->menu[b+1],sizeof(struct dopusfunction));
  675.                                     clearmenu(&config->menu[a]);
  676.                                     config->menu[a].name=NULL;
  677.                                     config->menu[a].function=NULL;
  678.                                     showmenus(1);
  679.                                     dogadgetinfo(cfg_string[STR_MENU_ITEM_INSERTED]);
  680.                                     break;
  681.                                 case MENU_DELETEMENU:
  682.                                     lsprintf(buf,"%s\n%s",
  683.                                         config->menutit[mnum],
  684.                                         cfg_string[STR_REALLY_DELETE_THIS_MENU]);
  685.                                     if (request(buf)) {
  686.                                         b=(mnum*20)+20;
  687.                                         for (a=mnum*20;a<b;a++) {
  688.                                             clearmenu(&config->menu[a]);
  689.                                             freenewfunction(&config->menu[a]);
  690.                                         }
  691.                                         config->menutit[mnum][0]=0;
  692.                                         showmenus(5);
  693.                                         dogadgetinfo(cfg_string[STR_MENU_DELETED]);
  694.                                     }
  695.                                     break;
  696.                                 case MENU_SORTMENU:
  697.                                     sortmenustrip(mnum);
  698.                                     showmenus(5);
  699.                                     dogadgetinfo(cfg_string[STR_MENU_SORTED]);
  700.                                     break;
  701.                                 default:
  702.                                     if (!selmenu) {
  703.                                         selmenu=&config->menu[a];
  704.                                         HiliteGad(gad,rp);
  705.                                         switch (mode) {
  706.                                             case MENU_COPYMENU:
  707.                                                 dogadgetinfo(cfg_string[STR_SELECT_MENU_TO_COPY]);
  708.                                                 break;
  709.                                             case MENU_SWAPMENU:
  710.                                                 dogadgetinfo(cfg_string[STR_SELECT_MENU_TO_SWAP]);
  711.                                                 break;
  712.                                             case MENU_COPYITEM:
  713.                                                 dogadgetinfo(cfg_string[STR_SELECT_ITEM_TO_COPY]);
  714.                                                 break;
  715.                                             case MENU_SWAPITEM:
  716.                                                 dogadgetinfo(cfg_string[STR_SELECT_ITEM_TO_SWAP]);
  717.                                                 break;
  718.                                         }
  719.                                     }
  720.                                     else {
  721.                                         secondmenu=&config->menu[a];
  722.                                         if (selmenu==secondmenu) {
  723.                                             HiliteGad(gad,rp);
  724.                                             selmenu=NULL;
  725.                                         }
  726.                                         else {
  727.                                             switch (mode) {
  728.                                                 case MENU_COPYITEM:
  729.                                                     freenewfunction(secondmenu);
  730.                                                     CopyMem((char *)selmenu,(char *)secondmenu,sizeof(struct newdopusfunction));
  731.                                                     secondmenu->function=getcopy(selmenu->function,-1,NULL);
  732.                                                     secondmenu->name=getcopy(selmenu->name,-1,NULL);
  733.                                                     break;
  734.                                                 case MENU_SWAPITEM:
  735.                                                     SwapMem((char *)selmenu,(char *)secondmenu,sizeof(struct newdopusfunction));
  736.                                                     break;
  737.                                                 case MENU_COPYMENU:
  738.                                                     if (omnum<0 || mnum==omnum) break;
  739.                                                     CopyMem((char *)&config->menu[omnum*20],(char *)&config->menu[mnum*20],
  740.                                                         sizeof(struct newdopusfunction)*20);
  741.                                                     b=(mnum*20)+20;
  742.                                                     for (a=mnum*20;a<b;a++) {
  743.                                                         config->menu[a].name=getcopy(config->menu[a].name,-1,NULL);
  744.                                                         config->menu[a].function=getcopy(config->menu[a].function,-1,NULL);
  745.                                                     }
  746.                                                     strcpy(config->menutit[mnum],config->menutit[omnum]);
  747.                                                     break;
  748.                                                 case MENU_SWAPMENU:
  749.                                                     if (omnum<0 || mnum==omnum) break;
  750.                                                     SwapMem((char *)&config->menu[omnum*20],(char *)&config->menu[mnum*20],
  751.                                                         sizeof(struct newdopusfunction)*20);
  752.                                                     SwapMem(config->menutit[mnum],config->menutit[omnum],16);
  753.                                                     break;
  754.                                             }
  755.                                             selmenu=NULL;
  756.                                             showmenus(5);
  757.                                         }
  758.                                         doinitmenutext(mode);
  759.                                     }
  760.                                     break;
  761.                             }
  762.                         }
  763.                         else {
  764.                             if (paint_state) {
  765.                                 config->menu[a].fpen=paint_fg;
  766.                                 config->menu[a].bpen=paint_bg;
  767.                                 showmenus(1);
  768.                             }
  769.                             else {
  770.                                 cleanconfigscreen();
  771.                                 selmenu=&config->menu[a];
  772.                                 doscreentitle(cfg_string[STR_MENU_ITEM_EDIT_SCREEN]);
  773.                                 editfunction((struct dopusfunction *)selmenu,CFG_MENU,NULL);
  774.                                 showconfigscreen(CFG_MENU);
  775.                                 FixSliderPot(Window,&menuslidergads[0],menuoffset,20,20-HIDDENLINES,2);
  776.                                 selmenu=NULL;
  777.                                 showmenus(7);
  778.                             }
  779.                         }
  780.                         break;
  781.                     }
  782.                     switch (gadgetid) {
  783.                         case MENU_CANCEL:
  784.                             doundo(undo,UNDO_MENU);
  785.                         case MENU_OKAY:
  786.                             doundo(undo,0);
  787.                             RemoveGList(Window,menugads,MENUCOUNT);
  788.                             LFreeRemember(&menukey); menugads=NULL;
  789.                             ClearMenuStrip(Window); projectmenu.NextMenu=NULL;
  790.                             FSSetMenuStrip(Window,&projectmenu);
  791.                             paint_state=0;
  792.                             return((gadgetid==MENU_OKAY));
  793.                     }
  794.                     if (gadgetid<MENU_OKAY) mode=doinitmenutext(gadgetid);
  795.                     break;
  796.  
  797.                 case IDCMP_GADGETDOWN:
  798.                     switch (gadgetid) {
  799.                         case MENU_SLIDER:
  800.                             a=menuoffset;
  801.                             menuoffset=GetSliderPos(&menuslidergads[0],20,20-HIDDENLINES);
  802.                             if (a!=menuoffset) showmenus(1);
  803.                             FOREVER {
  804.                                 Wait(1<<Window->UserPort->mp_SigBit);
  805.                                 while (IMsg=getintuimsg()) {
  806.                                     class=IMsg->Class;
  807.                                     ReplyMsg((struct Message *)IMsg);
  808.                                     if (class==IDCMP_GADGETUP) break;
  809.                                     if (class==IDCMP_MOUSEMOVE) {
  810.                                         a=menuoffset;
  811.                                         menuoffset=GetSliderPos(&menuslidergads[0],20,20-HIDDENLINES);
  812.                                         if (a!=menuoffset) showmenus(1);
  813.                                     }
  814.                                 }
  815.                                 if (class==IDCMP_GADGETUP) break;
  816.                             }
  817.                             ShowSlider(Window,&menuslidergads[0]);
  818.                             break;
  819.                         case MENU_MOVEUP:
  820.                             menuoffset-=2;
  821.                             if (menuoffset<-1) {
  822.                                 menuoffset=0;
  823.                                 break;
  824.                             }
  825.                         case MENU_MOVEDOWN:
  826.                             ++menuoffset;
  827.                             if (menuoffset>HIDDENLINES) {
  828.                                 menuoffset=HIDDENLINES;
  829.                                 break;
  830.                             }
  831.                             showmenus(1);
  832.                             FixSliderPot(Window,&menuslidergads[0],menuoffset,20,20-HIDDENLINES,2);
  833.                             Delay(5);
  834.                             FOREVER {
  835.                                 while (IMsg=getintuimsg()) {
  836.                                     class=IMsg->Class;
  837.                                     ReplyMsg((struct Message *)IMsg);
  838.                                     if (class==IDCMP_GADGETUP) break;
  839.                                 }
  840.                                 if (class==IDCMP_GADGETUP) break;
  841.                                 if (gadgetid==MENU_MOVEUP) {
  842.                                     --menuoffset;
  843.                                     if (menuoffset<0) {
  844.                                         menuoffset=0;
  845.                                         break;
  846.                                     }
  847.                                 }
  848.                                 else {
  849.                                     ++menuoffset;
  850.                                     if (menuoffset>HIDDENLINES) {
  851.                                         menuoffset=HIDDENLINES;
  852.                                         break;
  853.                                     }
  854.                                 }
  855.                                 FixSliderPot(Window,&menuslidergads[0],menuoffset,20,20-HIDDENLINES,2);
  856.                                 showmenus(1);
  857.                             }
  858.                             break;
  859.                     }
  860.                     break;
  861.             }
  862.         }
  863.     }
  864. }
  865.  
  866. void showmenus(disp)
  867. int disp;
  868. {
  869.     int a,b,x,y;
  870.  
  871.     a=0;
  872.     SetDrMd(rp,JAM2);
  873.     for (x=0;x<5;x++) {
  874.         if (disp&1) {
  875.             b=(x*20)+menuoffset;
  876.             for (y=0;y<20-HIDDENLINES;y++,a++,b++)
  877.                 showmenuname(&config->menu[b],&menugads[a]);
  878.         }
  879.         if (disp&2) {
  880.             do3dbox((x*120)+x_off+12,y_off+21,112,160-(HIDDENLINES*8));
  881.         }
  882.         if (disp&4) {
  883.             showmenutext(config->menutit[x],(x*120)+x_off+12,y_off+8,0,1);
  884.             do3dbox((x*120)+x_off+12,y_off+8,112,8);
  885.         }
  886.     }
  887. }
  888.  
  889. void showmenuname(menu,gadget)
  890. struct newdopusfunction *menu;
  891. struct Gadget *gadget;
  892. {
  893.     int x,y;
  894.  
  895.     x=gadget->LeftEdge;
  896.     y=gadget->TopEdge;
  897.     if (menu) {
  898.         showmenutext(menu->name,x,y,menu->fpen,menu->bpen);
  899.         if (menu==selmenu) HiliteGad(gadget,rp);
  900.     }
  901.     else {
  902.         SetAPen(rp,screen_pens[1].pen);
  903.         RectFill(rp,x,y,x+111,y+7);
  904.     }
  905. }
  906.  
  907. void showmenutext(txt,x,y,fp,bp)
  908. char *txt;
  909. int x,y,fp,bp;
  910. {
  911.     int a;
  912.  
  913.     SetAPen(rp,screen_pens[fp].pen);
  914.     SetBPen(rp,screen_pens[bp].pen);
  915.     Move(rp,x,y+6);
  916.     if (txt) {
  917.         if ((a=strlen(txt))>0) {
  918.             if (a>14) a=14;
  919.             Text(rp,txt,a);
  920.         }
  921.     }
  922.     else a=0;
  923.     if (a<14) Text(rp,spacestring,14-a);
  924.     SetBPen(rp,screen_pens[0].pen);
  925. }
  926.  
  927. void clearmenu(menu)
  928. struct newdopusfunction *menu;
  929. {
  930.     menu->which=0;
  931.     menu->stack=4000;
  932.     menu->key=0;
  933.     menu->qual=0;
  934.     menu->type=0;
  935.     menu->pri=0;
  936.     menu->delay=0;
  937.     if (paint_state) {
  938.         menu->fpen=paint_fg;
  939.         menu->bpen=paint_bg;
  940.     }
  941.     else {
  942.         menu->fpen=0;
  943.         menu->bpen=1;
  944.     }
  945. }
  946.  
  947. doinitmenutext(id)
  948. int id;
  949. {
  950.     int mode=-1;
  951.  
  952.     switch (id) {
  953.         case MENU_COPYMENU:
  954.             mode=MENU_COPYMENU;
  955.             dogadgetinfo(cfg_string[STR_SELECT_ITEM_IN_MENU_TO_COPY]);
  956.             break;
  957.         case MENU_SWAPMENU:
  958.             mode=MENU_SWAPMENU;
  959.             dogadgetinfo(cfg_string[STR_SELECT_ITEM_IN_MENU_TO_SWAP]);
  960.             break;
  961.         case MENU_DELETEMENU:
  962.             mode=MENU_DELETEMENU;
  963.             dogadgetinfo(cfg_string[STR_SELECT_ITEM_IN_MENU_TO_DELETE]);
  964.             break;
  965.         case MENU_SORTMENU:
  966.             mode=MENU_SORTMENU;
  967.             dogadgetinfo(cfg_string[STR_SELECT_ITEM_IN_MENU_TO_SORT]);
  968.             break;
  969.         case MENU_INSERTITEM:
  970.             mode=MENU_INSERTITEM;
  971.             dogadgetinfo(cfg_string[STR_SELECT_ITEM_TO_INSERT_BEFORE]);
  972.             break;
  973.         case MENU_COPYITEM:
  974.             mode=MENU_COPYITEM;
  975.             dogadgetinfo(cfg_string[STR_SELECT_MENU_ITEM_TO_COPY]);
  976.             break;
  977.         case MENU_SWAPITEM:
  978.             mode=MENU_SWAPITEM;
  979.             dogadgetinfo(cfg_string[STR_SELECT_MENU_ITEM_TO_SWAP]);
  980.             break;
  981.         case MENU_DELETEITEM:
  982.             mode=MENU_DELETEITEM;
  983.             dogadgetinfo(cfg_string[STR_SELECT_MENU_ITEM_TO_DELETE]);
  984.             break;
  985.     }
  986.     return(mode);
  987. }
  988.  
  989. void sortmenustrip(m)
  990. int m;
  991. {
  992.     int gap,i,j,k;
  993.     char *ptr1,*ptr2,*zstr="\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f";
  994.  
  995.     m*=20;
  996.     for (gap=10;gap>0;gap/=2)
  997.         for (i=gap;i<20;i++)
  998.             for (j=i-gap;j>=0;j-=gap) {
  999.                 k=j+gap;
  1000.                 ptr1=(config->menu[j+m].name && config->menu[j+m].name[0])?config->menu[j+m].name:zstr;
  1001.                 ptr2=(config->menu[k+m].name && config->menu[k+m].name[0])?config->menu[k+m].name:zstr;
  1002.                 if (LStrCmpI(ptr1,ptr2)<=0) break;
  1003.                 SwapMem((char *)&config->menu[j+m],(char *)&config->menu[k+m],
  1004.                     sizeof(struct newdopusfunction));
  1005.             }
  1006. }
  1007.  
  1008. void do_menuscreen_title(title)
  1009. int title;
  1010. {
  1011.     if (!paint_state) doscreentitle(cfg_string[title]);
  1012.     else {
  1013.         char temp[80];
  1014.  
  1015.         StrCombine(temp,cfg_string[title],cfg_string[STR_PAINT_STATE],80);
  1016.         doscreentitle(temp);
  1017.     }
  1018. }
  1019.