home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / main11.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  23KB  |  743 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 "DOpus.h"
  32.  
  33. #define BUTPROP 1
  34. #define BUTEXIT 2
  35.  
  36. static struct AppIcon *appicon;
  37. static struct Image iconbutpropimage;
  38. static struct PropInfo
  39.     iconbutpropinfo={
  40.         AUTOKNOB|FREEVERT|PROPNEWLOOK|PROPBORDERLESS,0,0,0,0x3000};
  41.  
  42. USHORT __chip
  43.     uniconifydata[2][20]={
  44.         {0x3f80,0xa0a0,0x2080,0xa0a0,0x3f80,0x8020,0x0000,0x8020,
  45.             0x0000,0xaaa0,
  46.         0x0000,0x1f00,0x1f00,0x1f00,0x0000,0x0000,0x0000,0x0000,
  47.             0x0000,0x0000},
  48.         {0xffe0,0x8020,0xffe0,0x8020,0x8020,0x8020,0x8020,0x8020,
  49.             0x8020,0xffe0,
  50.         0x0000,0x7fc0,0x0000,0x7fc0,0x7fc0,0x7fc0,0x7fc0,0x7fc0,
  51.             0x7fc0,0x0000}};
  52.  
  53. struct Image
  54.     uniconifyimage[2]={
  55.         {0,0,11,10,2,uniconifydata[0],3,0,NULL},
  56.         {0,0,11,10,2,uniconifydata[1],3,0,NULL}};
  57.  
  58. struct Gadget
  59.     dummybordergad={
  60.         NULL,-18,0,17,10,
  61.         GFLG_GADGHNONE|GFLG_RELRIGHT,
  62.         GACT_RIGHTBORDER,
  63.         GTYP_BOOLGADGET,
  64.         NULL,NULL,NULL,NULL,NULL,0,NULL},
  65.     iconbutpropgad={
  66.         &dummybordergad,-14,0,11,0,
  67.         GFLG_GADGHNONE|GFLG_RELRIGHT,
  68.         GACT_IMMEDIATE|GACT_RELVERIFY|GACT_FOLLOWMOUSE|GACT_RIGHTBORDER,
  69.         GTYP_PROPGADGET,
  70.         (APTR)&iconbutpropimage,NULL,NULL,NULL,(APTR)&iconbutpropinfo,BUTPROP,NULL},
  71.     iconbutexitgad={
  72.         &iconbutpropgad,0,0,11,10,
  73.         GFLG_GADGIMAGE|GFLG_GADGHIMAGE|GFLG_RELRIGHT,
  74.         GACT_RELVERIFY|GACT_RIGHTBORDER,
  75.         GTYP_BOOLGADGET,(APTR)&uniconifyimage[0],(APTR)&uniconifyimage[1],
  76.         NULL,NULL,NULL,BUTEXIT,NULL};
  77.  
  78. struct NewWindow
  79.     icon_win={
  80.         100,0,433,10,255,255,
  81.         ICON_IDCMP,
  82.         WFLG_CLOSEGADGET|WFLG_RMBTRAP|WFLG_DRAGBAR|WFLG_DEPTHGADGET,
  83.         NULL,NULL,NULL,NULL,NULL,0,0,0,0,WBENCHSCREEN},
  84.     appicon_win={
  85.         0,0,1,1,255,255,ICON_IDCMP,
  86.         WFLG_BACKDROP|WFLG_BORDERLESS|WFLG_SIMPLE_REFRESH|WFLG_NOCAREREFRESH,
  87.         NULL,NULL,NULL,NULL,NULL,0,0,0,0,WBENCHSCREEN};
  88.  
  89. static int icon_tx,icon_ty,icon_len,icon_fpen,icon_bpen,icon_maxlen;
  90. static int icon_type,icon_gotclock;
  91. static struct TextFont *winfont;
  92. static char icontitletext[200];
  93. static struct DOpusRemember *icon_key;
  94. static struct MsgPort *iconify_time_port;
  95. static struct timerequest iconify_timereq;
  96.  
  97. static struct DiskObject iconify_appicon={
  98.     0,0,
  99.         {NULL,0,0,80,41,GADGBACKFILL,0,0,
  100.         (APTR)&appicon_image,NULL,NULL,NULL,NULL,NULL,NULL},
  101.     0,NULL,NULL,NO_ICON_POSITION,NO_ICON_POSITION,NULL,NULL,NULL};
  102.  
  103. void iconify(louise,buttons,banknum)
  104. int louise,buttons,banknum;
  105. {
  106.     ULONG class;
  107.     USHORT code,gadgetid;
  108.     struct DOpusDateTime dt;
  109.     struct Screen scrbuf,*sptr;
  110.     struct DrawInfo *drinfo;
  111.     int
  112.         wmes,chipc,fast,h,m,s,waitbits,
  113.         a,b,nheight,nwidth,buttonrows,oldrows,olddata_gadgetrow_offset,x,y,x1,y1,c,d,w,
  114.         fastnum,chipnum,bankcount,bankstep,menunum,itemnum,num,cdelay,
  115.         usage,oldusage=100;
  116.     char date[16],time[16],buf[50],buf1[50],buf2[50],ampm,formstring[100],*old;
  117.     struct dopusgadgetbanks *bank,*oldbank,**bankarray;
  118.     struct dopushotkey *hotkey;
  119.     struct dopusfuncpar par;
  120.     struct AppMessage *amsg;
  121.     struct MenuItem *item;
  122.  
  123.     endnotifies();
  124.     shutthingsdown(louise);
  125.  
  126.     status_iconified=1; status_flags&=~STATUS_ISINBUTTONS; cdelay=0;
  127.     GetWBScreen(&scrbuf);
  128.     nwidth=scrbuf.Width; nheight=scrbuf.Height;
  129.     winfont=scrbuf.RastPort.Font;
  130.     appicon=NULL; icon_key=NULL;
  131.     icon_type=config->icontype;
  132.  
  133.     if (system_version2 && (sptr=LockPubScreen("Workbench"))) {
  134.         drinfo=GetScreenDrawInfo(sptr);
  135.         icon_fpen=drinfo->dri_Pens[FILLTEXTPEN];
  136.         icon_bpen=drinfo->dri_Pens[FILLPEN];
  137.         FreeScreenDrawInfo(sptr,drinfo);
  138.         UnlockPubScreen(NULL,sptr);
  139.     }
  140.     else {
  141.         icon_fpen=1; icon_bpen=0;
  142.     }
  143.  
  144.     oldrows=config->gadgetrows;
  145.     oldbank=dopus_curgadbank;
  146.     olddata_gadgetrow_offset=data_gadgetrow_offset;
  147.  
  148.     if (buttons) {
  149.         bank=dopus_firstgadbank; bankcount=0;
  150.         while (bank) {
  151.             ++bankcount;
  152.             bank=bank->next;
  153.         }
  154.         if ((bankarray=LAllocRemember(&icon_key,bankcount*4,MEMF_CLEAR))) {
  155.             bank=dopus_firstgadbank;
  156.             for (a=0;a<bankcount;a++) {
  157.                 bankarray[a]=bank;
  158.                 bank=bank->next;
  159.             }
  160.         }
  161.         else bankcount=0;
  162.         icon_win.LeftEdge=config->iconbutx; icon_win.TopEdge=config->iconbuty;
  163.         icon_type&=~(ICON_NOWINDOW|ICON_APPICON);
  164.         if (buttons>1) {
  165.             buttonrows=buttons-1;
  166.             if (buttonrows!=2 && buttonrows!=3 && buttonrows!=6)
  167.                 buttonrows=config->gadgetrows;
  168.         }
  169.         else buttonrows=config->gadgetrows;
  170.         if (buttonrows<2) buttonrows=2;
  171.         config->gadgetrows=buttonrows;
  172.         scr_gadget_rows=buttonrows;
  173.         bankstep=6/buttonrows;
  174.     }
  175.     else {
  176.         icon_win.LeftEdge=config->iconx;
  177.         icon_win.TopEdge=config->icony;
  178.  
  179.         if (icon_type&ICON_APPICON) {
  180.             if (!system_version2 || !WorkbenchBase ||
  181.                 !(appicon=AddAppIconA(0,0,(UBYTE *)"Directory Opus",
  182.                 appmsg_port,NULL,&iconify_appicon,NULL)))
  183.             icon_type&=~(ICON_APPICON);
  184.         }
  185.     }
  186.  
  187.     icon_gotclock=0;
  188.     if (!(icon_type&(ICON_NOWINDOW|ICON_APPICON))) {
  189.         icon_win.Title=(STRPTR)str_space_string;
  190.         if (!(icon_type&(ICON_MEMORY|ICON_DATE|ICON_TIME|ICON_CPU))) {
  191.             if (buttons) strcpy(buf,"WW");
  192.             else strcpy(buf,"DirOpusWW");
  193.         }
  194.         else {
  195.             strcpy(buf,"W");
  196.             icon_gotclock=1;
  197.             if (icon_type&ICON_MEMORY) {
  198.                 chipnum=getmaxmem(MEMF_CHIP,MEMF_ANY);
  199.                 fastnum=getmaxmem(MEMF_ANY,MEMF_CHIP);
  200.                 if (icon_type&ICON_BYTES) {
  201.                     chipnum+=3;
  202.                     fastnum+=3;
  203.                 }
  204.                 if (icon_type&ICON_C_AND_F) {
  205.                     if (fastnum<2) lsprintf(buf2,"%lc:",globstring[STR_CLOCK_MEM][0]);
  206.                     else lsprintf(buf2,"%lc:",globstring[STR_CLOCK_CHIP][0]);
  207.                     strcat(buf,buf2);
  208.                 }
  209.                 else {
  210.                     if (fastnum<2) strcat(buf,globstring[STR_CLOCK_MEM]);
  211.                     else strcat(buf,globstring[STR_CLOCK_CHIP]);
  212.                 }
  213.                 for (a=0;a<chipnum;a++) buf1[a]='8'; buf1[a]=0;
  214.                 strcat(buf,buf1);
  215.                 if (fastnum>1) {
  216.                     if (icon_type&ICON_C_AND_F) lsprintf(buf2," %lc:",globstring[STR_CLOCK_FAST][0]);
  217.                     else lsprintf(buf2," %s",globstring[STR_CLOCK_FAST]);
  218.                     strcat(buf,buf2);
  219.                     for (a=0;a<fastnum;a++) buf1[a]='8'; buf1[a]=0;
  220.                     strcat(buf,buf1);
  221.                 }
  222.                 strcat(buf," ");
  223.             }
  224.             if (icon_type&ICON_CPU) strcat(buf,"CPU:100% ");
  225.             if (icon_type&ICON_DATE) strcat(buf,"88-WWW-88 ");
  226.             if (icon_type&ICON_TIME) {
  227.                 strcat(buf,"88:88:88");
  228.                 if (config->dateformat&DATE_12HOUR) strcat(buf,"P");
  229.                 strcat(buf," ");
  230.             }
  231.             if ((icon_len=strlen(buf)) && buf[icon_len-1]!=' ') strcat(buf," ");
  232. /*
  233.             if (system_version2) strcat(buf,"W");
  234. */
  235.         }
  236.         icon_len=0;
  237.         icon_win.Height=scrbuf.WBorTop+winfont->tf_YSize+(system_version2?1:0);
  238.         icon_win.Width=dotextlength(&scrbuf.RastPort,buf,&icon_len,0);
  239.         icon_ty=((icon_win.Height-winfont->tf_YSize)/2)+winfont->tf_Baseline;
  240.         if (buttons) {
  241.             icon_win.Height+=buttonrows*(scr_font[FONT_ICONIFY]->tf_YSize+2)+scrbuf.WBorBottom;
  242.             icon_win.Width=scrbuf.Width;
  243.             if (config->generalscreenflags&SCR_GENERAL_NEWLOOKMENU)
  244.                 icon_win.Flags|=WFLG_NEWLOOKMENUS;
  245.             else icon_win.Flags&=~WFLG_NEWLOOKMENUS;
  246.  
  247.             if (system_version2) iconbutexitgad.LeftEdge=-14;
  248.             else iconbutexitgad.LeftEdge=-16;
  249.  
  250.             iconbutexitgad.TopEdge=scrbuf.WBorTop+winfont->tf_YSize+3;
  251.             dummybordergad.TopEdge=iconbutexitgad.TopEdge;
  252.             iconbutpropgad.TopEdge=iconbutexitgad.TopEdge+12;
  253.             iconbutpropgad.Height=icon_win.Height-iconbutpropgad.TopEdge-scrbuf.WBorBottom-1;
  254.             dummybordergad.NextGadget=NULL;
  255.  
  256.             icon_win.FirstGadget=&iconbutexitgad;
  257.         }
  258.         else {
  259.             if (system_version2) icon_win.Width+=50;
  260.             else icon_win.Width+=88;
  261.             icon_win.FirstGadget=NULL;
  262.         }
  263.  
  264.         if (icon_win.LeftEdge+icon_win.Width>nwidth)
  265.             icon_win.LeftEdge=nwidth-icon_win.Width;
  266.         if (icon_win.TopEdge+icon_win.Height>nheight)
  267.             icon_win.TopEdge=nheight-icon_win.Height-1;
  268.         if (icon_win.LeftEdge<0) icon_win.LeftEdge=0;
  269.         if (icon_win.TopEdge<0) icon_win.TopEdge=0;
  270.  
  271.         if (!(Window=(struct Window *) OpenWindow(&icon_win))) goto uniconify;
  272.         main_rp=Window->RPort;
  273.  
  274.         if (WorkbenchBase) dopus_appwindow=AddAppWindowA(APPWINID,0,Window,appmsg_port,NULL);
  275.  
  276.         if (buttons) {
  277.             get_colour_table();
  278.             FixSliderBody(Window,&iconbutpropgad,(bankcount*6)/buttonrows,1,1);
  279.             if (!system_version2) {
  280.                 SetAPen(main_rp,screen_pens[1].pen);
  281.                 Move(main_rp,Window->Width-Window->BorderRight,Window->BorderTop);
  282.                 Draw(main_rp,Window->Width-Window->BorderRight,Window->Height-Window->BorderBottom);
  283.                 Move(main_rp,Window->Width-Window->BorderRight+1,Window->BorderTop);
  284.                 Draw(main_rp,Window->Width-Window->BorderRight+1,Window->Height-Window->BorderBottom);
  285.             }
  286.             SetFont(main_rp,scr_font[FONT_ICONIFY]);
  287.             scrdata_drive_width=0;
  288.             data_gadgetrow_offset=0;
  289.             if ((dopus_curgadbank=dopus_firstgadbank)) {
  290.                 for (a=0;a<banknum;a++) {
  291.                     if (!dopus_curgadbank->next) break;
  292.                     dopus_curgadbank=dopus_curgadbank->next;
  293.                 }
  294.             }
  295.             FixSliderPot(Window,&iconbutpropgad,a*bankstep,(bankcount*6)/buttonrows,1,1);
  296.             w=Window->Width-Window->BorderLeft-Window->BorderRight;
  297.             scrdata_gadget_width=w/7;
  298.             scrdata_gadget_xpos=((w-(scrdata_gadget_width*7))/2)+Window->BorderLeft;
  299.             if (scrdata_gadget_xpos<Window->BorderLeft) scrdata_gadget_xpos=Window->BorderLeft;
  300.             scrdata_gadget_offset=0;
  301.             scrdata_gadget_height=scr_font[FONT_ICONIFY]->tf_YSize+2;
  302.             scrdata_gadget_ypos=Window->BorderTop+1;
  303.             drawgadgets(1,0);
  304.             layout_menus();
  305.             status_flags|=STATUS_ISINBUTTONS;
  306.         }
  307.         else SetFont(main_rp,winfont);
  308.  
  309.         if (!system_version2) {
  310.             icon_tx=30;
  311.             if (config->icontype&ICON_APPICON) icon_type&=~(ICON_APPICON);
  312.         }
  313.  
  314.         SetDrMd(main_rp,JAM2);
  315.         if (icon_gotclock) {
  316.             if ((iconify_time_port=LCreatePort(0,0))) {
  317.                 OpenDevice(TIMERNAME,UNIT_VBLANK,&iconify_timereq.tr_node,0);
  318.                 iconify_timereq.tr_node.io_Message.mn_ReplyPort=iconify_time_port;
  319.                 iconify_timereq.tr_node.io_Command=TR_ADDREQUEST;
  320.                 iconify_timereq.tr_node.io_Flags=0;
  321.                 iconify_timereq.tr_time.tv_secs=0;
  322.                 iconify_timereq.tr_time.tv_micro=2;
  323.                 SendIO(&iconify_timereq.tr_node);
  324.             }
  325.             else icon_gotclock=0;
  326.         }
  327.         else {
  328.             if (buttons) SetWindowTitles(Window,globstring[STR_BUTTON_STRIP],(char *)-1);
  329.             else SetWindowTitles(Window,"DirOpus",(char *)-1);
  330.         }
  331.     }
  332.     else if (icon_type&ICON_APPICON)
  333.         Window=OpenWindow(&appicon_win);
  334.  
  335.     if (!(status_flags&STATUS_DONEREXX)) {
  336.         status_flags|=STATUS_DONEREXX;
  337.         rexx_command(config->startupscript,NULL);
  338.     }
  339.  
  340.     FOREVER {
  341.         waitbits=0;
  342.         if (WorkbenchBase) {
  343.             if (icon_type&ICON_APPICON || dopus_appwindow)
  344.                 waitbits|=1<<appmsg_port->mp_SigBit;
  345.         }
  346.         if (icon_gotclock) {
  347.             if (!system_version2) strcpy(formstring," ");
  348.             else formstring[0]=0;
  349.             if (icon_type&ICON_MEMORY) {
  350.                 chipc=AvailMem(MEMF_CHIP);
  351.                 fast=AvailMem(MEMF_ANY)-chipc;
  352.                 if (!(icon_type&ICON_BYTES)) {
  353.                     chipc/=1024;
  354.                     fast/=1024;
  355.                 }
  356.                 if (fastnum>1) {
  357.                     if (icon_type&ICON_C_AND_F) {
  358.                         lsprintf(buf1,"%lc:%%%ldld %lc:%%%ldld ",
  359.                             globstring[STR_CLOCK_CHIP][0],chipnum,
  360.                             globstring[STR_CLOCK_FAST][0],fastnum);
  361.                     }
  362.                     else {
  363.                         lsprintf(buf1,"%s%%%ldld %s%%%ldld ",
  364.                             globstring[STR_CLOCK_CHIP],chipnum,
  365.                             globstring[STR_CLOCK_FAST],fastnum);
  366.                     }
  367.                     lsprintf(buf,buf1,chipc,fast);
  368.                 }
  369.                 else {
  370.                     if (icon_type&ICON_C_AND_F) {
  371.                         lsprintf(buf1,"%lc:%%%ldld ",
  372.                             globstring[STR_CLOCK_MEM][0],chipnum);
  373.                     }
  374.                     else {
  375.                         lsprintf(buf1,"%s%%%ldld ",
  376.                             globstring[STR_CLOCK_MEM],chipnum);
  377.                     }
  378.                     lsprintf(buf,buf1,chipc);
  379.                 }
  380.                 strcat(formstring,buf);
  381.             }
  382.             if (icon_type&ICON_CPU) {
  383.                 if (!(usage=(getusage()/10))) usage=oldusage;
  384.                 lsprintf(buf,"CPU:%3ld%% ",usage);
  385.                 strcat(formstring,buf);
  386.                 oldusage=usage;
  387.             }
  388.             DateStamp(&(dt.dat_Stamp));
  389.             initdatetime(&dt,date,time,0);
  390.             if (icon_type&ICON_DATE) {
  391.                 strcat(formstring,date);
  392.                 strcat(formstring," ");
  393.             }
  394.             if (icon_type&ICON_TIME) {
  395.                 if (config->dateformat&DATE_12HOUR) {
  396.                     h=dt.dat_Stamp.ds_Minute/60; m=dt.dat_Stamp.ds_Minute%60;
  397.                     s=dt.dat_Stamp.ds_Tick/TICKS_PER_SECOND;
  398.                     if (h>11) { ampm='P'; h-=12; }
  399.                     else ampm='A';
  400.                     if (h==0) h=12;
  401.                     lsprintf(time,"%2ld:%02ld:%02ld%lc",h,m,s,ampm);
  402.                 }
  403.                 strcat(formstring,time);
  404.                 strcat(formstring," ");
  405.             }
  406.             if (!cdelay) {
  407.                 formstring[icon_len]=0;
  408.                 iconstatustext(formstring,buttons);
  409.             }
  410.             waitbits|=1<<iconify_time_port->mp_SigBit;
  411.         }
  412.         if (Window) waitbits|=1<<Window->UserPort->mp_SigBit;
  413.         waitbits|=INPUTSIG_UNICONIFY|rexx_signalbit|INPUTSIG_HOTKEY;
  414.         if ((wmes=Wait(waitbits))&INPUTSIG_HOTKEY) {
  415.             if (dopus_globalhotkey==(struct dopushotkey *)-1) {
  416.                 cleanupiconify();
  417.                 status_iconified=0;
  418.                 quit();
  419.             }
  420.             else if (dopus_globalhotkey==(struct dopushotkey *)-2) {
  421.                 dopus_globalhotkey=NULL;
  422.                 continue;
  423.             }
  424.             else if (dopus_globalhotkey) {
  425.                 hotkey=dopus_globalhotkey; dopus_globalhotkey=NULL;
  426.                 CopyMem((char *)&hotkey->func.which,(char *)&par,sizeof(struct dopusfuncpar));
  427.                 par.which&=FLAG_OUTWIND|FLAG_NOQUOTE|FLAG_SHELLUP|FLAG_DOPUSUP;
  428.                 par.which|=FLAG_ASYNC;
  429.                 if (par.which&FLAG_OUTWIND) par.which|=FLAG_WB2F;
  430.                 status_flags|=STATUS_FROMHOTKEY;
  431.                 dofunctionstring(hotkey->func.function,hotkey->name,NULL,&par);
  432.                 status_flags&=~STATUS_FROMHOTKEY;
  433.             }
  434.         }
  435.         if (WorkbenchBase) {
  436.             if ((icon_type&ICON_APPICON || dopus_appwindow) &&
  437.                 wmes&1<<appmsg_port->mp_SigBit) {
  438.                 if (dopus_appwindow) ActivateWindow(Window);
  439.                 while (amsg=(struct AppMessage *)GetMsg(appmsg_port)) {
  440.                     if (amsg->am_Type==MTYPE_APPICON && amsg->am_NumArgs==0) {
  441.                         ReplyMsg((struct Message *)amsg);
  442.                         goto endiconify;
  443.                     }
  444.                     else if ((amsg->am_Type==MTYPE_APPICON && Window) ||
  445.                         (amsg->am_Type==MTYPE_APPWINDOW && amsg->am_ID==APPWINID)) {
  446.                         for (a=0;a<amsg->am_NumArgs;a++) {
  447.                             if (amsg->am_ArgList[a].wa_Lock) {
  448.                                 if (status_flags&STATUS_ISINBUTTONS &&
  449.                                     amsg->am_MouseY>Window->BorderTop) {
  450.                                     if (dopus_curgadbank && (b=gadgetfrompos(amsg->am_MouseX,amsg->am_MouseY))!=-1) {
  451.                                         b+=data_gadgetrow_offset*7;
  452.                                         if (isvalidgad(&dopus_curgadbank->gadgets[b])) {
  453.                                             PathName(amsg->am_ArgList[a].wa_Lock,func_external_file,256);
  454.                                             if (func_external_file[0] &&
  455.                                                 func_external_file[(strlen(func_external_file)-1)]==':' &&
  456.                                                 !amsg->am_ArgList[a].wa_Name[0])
  457.                                                 TackOn(func_external_file,"Disk.info",256);
  458.                                             else TackOn(func_external_file,amsg->am_ArgList[a].wa_Name,256);
  459.                                             if (!(CheckExist(func_external_file,NULL)))
  460.                                                 StrConcat(func_external_file,".info",256);
  461.                                             dofunctionstring(dopus_curgadbank->gadgets[b].function,
  462.                                                 dopus_curgadbank->gadgets[b].name,
  463.                                                 NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[b].which);
  464.                                             if (!status_iconified) break;
  465.                                             cdelay=3;
  466.                                             ModifyIDCMP(Window,ICON_IDCMP);
  467.                                         }
  468.                                     }
  469.                                 }
  470.                                 else {
  471.                                     if (amsg->am_ArgList[a].wa_Name[0]) {
  472.                                         char pathbuf[256];
  473.  
  474.                                         PathName(amsg->am_ArgList[a].wa_Lock,pathbuf,256);
  475.                                         strcpy(func_external_file,pathbuf);
  476.                                         TackOn(func_external_file,amsg->am_ArgList[a].wa_Name,256);
  477.                                         ftype_doubleclick(pathbuf,amsg->am_ArgList[a].wa_Name,0);
  478.                                         ModifyIDCMP(Window,ICON_IDCMP);
  479.                                         unbusy();
  480.                                     }
  481.                                 }
  482.                             }
  483.                         }
  484.                         func_external_file[0]=0;
  485.                     }
  486.                     ReplyMsg((struct Message *)amsg);
  487.                     if (!status_iconified) return;
  488.                 }
  489.             }
  490.         }
  491.         if (wmes&rexx_signalbit) {
  492.             func_global_function=0;
  493.             rexx_dispatch(0);
  494.             if (func_global_function==FUNC_UNICONIFY) wmes=INPUTSIG_UNICONIFY;
  495.             else if (func_global_function==FUNC_QUIT) {
  496.                 cleanupiconify();
  497.                 status_iconified=0;
  498.                 quit();
  499.             }
  500.         }
  501.         if (wmes&INPUTSIG_UNICONIFY) {
  502. endiconify:
  503.             status_iconified=-1;
  504.             cleanupiconify();
  505.             goto uniconify;
  506.         }
  507.         if (Window && wmes&1<<Window->UserPort->mp_SigBit) {
  508.             while (getintuimsg()) {
  509.                 class=IMsg->Class; code=IMsg->Code;
  510.                 x=IMsg->MouseX; y=IMsg->MouseY;
  511.                 if (class==IDCMP_GADGETUP || class==IDCMP_GADGETDOWN)
  512.                     gadgetid=((struct Gadget *)IMsg->IAddress)->GadgetID;
  513.                 ReplyMsg((struct Message *)IMsg);
  514.                 switch (class) {
  515.                     case IDCMP_MENUPICK:
  516.                         if (!buttons) break;
  517.                         Window->Flags|=RMBTRAP;
  518.                         if (Window->MenuStrip && code!=MENUNULL) {
  519.                             menunum=menu_real_number[MENUNUM(code)];
  520.                             num=ITEMNUM(code);
  521.                             item=menu_menus[menunum].FirstItem;
  522.                             for (a=0,itemnum=0;a<num && item;a++) {
  523.                                 if (item->Flags&ITEMTEXT) ++itemnum;
  524.                                 item=item->NextItem;
  525.                             }
  526.                             if (item) {
  527.                                 a=(menunum*20)+itemnum;
  528.                                 if (!isvalidgad(&config->menu[a])) break;
  529.                                 dofunctionstring(config->menu[a].function,config->menu[a].name,
  530.                                     NULL,(struct dopusfuncpar *)&config->menu[a].which);
  531.                                 if (!status_iconified) return;
  532.                                 cdelay=3;
  533.                                 ModifyIDCMP(Window,ICON_IDCMP);
  534.                             }
  535.                         }
  536.                         break;
  537.                     case IDCMP_GADGETDOWN:
  538.                         if (!buttons || gadgetid!=BUTPROP || !bankcount) break;
  539.                         FOREVER {
  540.                             bank=dopus_curgadbank; b=data_gadgetrow_offset;
  541.                             data_gadgetrow_offset=GetSliderPos(&iconbutpropgad,(bankcount*6)/buttonrows,1);
  542.                             a=data_gadgetrow_offset/bankstep;
  543.                             data_gadgetrow_offset%=bankstep; data_gadgetrow_offset*=buttonrows;
  544.                             dopus_curgadbank=bankarray[a];
  545.                             if (bank!=dopus_curgadbank || data_gadgetrow_offset!=b) drawgadgets(0,0);
  546.                             if (getintuimsg()) {
  547.                                 class=IMsg->Class;
  548.                                 ReplyMsg((struct Message *)IMsg);
  549.                                 if (class==IDCMP_MOUSEMOVE) continue;
  550.                                 if (class==IDCMP_GADGETUP) break;
  551.                             }
  552.                             Wait(1<<Window->UserPort->mp_SigBit);
  553.                         }
  554.                         FixSliderPot(Window,&iconbutpropgad,(a*bankstep)+(data_gadgetrow_offset/buttonrows),
  555.                             (bankcount*6)/buttonrows,1,1);
  556.                         break;
  557.                     case IDCMP_GADGETUP:
  558.                         if (!buttons) break;
  559.                         if (gadgetid>=MAIN_GAD_BASE && gadgetid<MAIN_GAD_BASE+GADCOUNT) {
  560.                             a=(gadgetid-MAIN_GAD_BASE)+(data_gadgetrow_offset*7);
  561.                             if (!dopus_curgadbank || !(isvalidgad(&dopus_curgadbank->gadgets[a]))) break;
  562.                             dofunctionstring(dopus_curgadbank->gadgets[a].function,
  563.                                 dopus_curgadbank->gadgets[a].name,
  564.                                 NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[a].which);
  565.                             if (!status_iconified) return;
  566.                             cdelay=3;
  567.                             ModifyIDCMP(Window,ICON_IDCMP);
  568.                         }
  569.                         else if (gadgetid==BUTEXIT) goto deiconify;
  570.                         break;
  571.                     case IDCMP_DISKREMOVED:
  572.                     case IDCMP_DISKINSERTED:
  573.                         setupchangestate();
  574.                         break;
  575.                     case IDCMP_CLOSEWINDOW:
  576.                         if (!(a=simplerequest(globstring[STR_REALLY_QUIT],
  577.                             globstring[STR_QUIT],str_cancelstring,globstring[STR_UNICONIFY],NULL))) break;
  578.                         if (a==2) goto endiconify;
  579.                         cleanupiconify();
  580.                         status_iconified=0;
  581.                         quit();
  582.                         break;
  583.                     case IDCMP_MOUSEBUTTONS:
  584.                         if (code!=MENUDOWN) {
  585.                             if (!(icon_type&ICON_MEMORY|ICON_DATE|ICON_TIME|ICON_CPU))
  586.                                 iconstatustext("Dir Opus",buttons);
  587.                             break;
  588.                         }
  589.                         if (buttons) {
  590.                             if (x<0 || y<Window->BorderTop ||
  591.                                 x>Window->Width || y>Window->Height) {
  592.                                 quickfixmenus();
  593.                                 break;
  594.                             }
  595.                             for (c=0;c<buttonrows;c++) {
  596.                                 a=42+((data_gadgetrow_offset+c)*7);
  597.                                 for (d=0;d<7;d++,a++) {
  598.                                     if (isvalidgad(&dopus_curgadbank->gadgets[a])) {
  599.                                         y1=(c*scrdata_gadget_height)+scrdata_gadget_ypos-1;
  600.                                         x1=scrdata_gadget_xpos+(d*scrdata_gadget_width);
  601.                                         if (x>=x1 && x<x1+scrdata_gadget_width && y>=y1 && y<y1+scrdata_gadget_height) {
  602.                                             if (!(dormbgadget(x1,y1,
  603.                                                 &dopus_curgadbank->gadgets[a-42],
  604.                                                 &dopus_curgadbank->gadgets[a]))) {
  605.                                                 dofunctionstring(dopus_curgadbank->gadgets[a].function,
  606.                                                     dopus_curgadbank->gadgets[a].name,
  607.                                                     NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[a].which);
  608.                                                 if (!status_iconified) return;
  609.                                                 cdelay=3;
  610.                                                 ModifyIDCMP(Window,ICON_IDCMP);
  611.                                                 c=buttonrows;
  612.                                                 break;
  613.                                             }
  614.                                         }
  615.                                     }
  616.                                 }
  617.                             }
  618.                             break;
  619.                         }
  620. deiconify:
  621.                         status_iconified=-1;
  622.                         cleanupiconify();
  623. uniconify:
  624.                         config->gadgetrows=oldrows;
  625.                         dopus_curgadbank=oldbank; data_gadgetrow_offset=olddata_gadgetrow_offset;
  626.                         SetUp(louise);
  627.                         if (Window && status_publicscreen) ScreenToFront(Window->WScreen);
  628.                         rexx_command(config->uniconscript,NULL);
  629.                         startnotifies();
  630.                         LFreeRemember(&icon_key);
  631.                         return;
  632.                 }
  633.             }
  634.         }
  635.         if (icon_gotclock && CheckIO(&iconify_timereq.tr_node)) {
  636.             WaitIO(&iconify_timereq.tr_node);
  637.             iconify_timereq.tr_time.tv_secs=1;
  638.             iconify_timereq.tr_time.tv_micro=0;
  639.             SendIO(&iconify_timereq.tr_node);
  640.             if (cdelay) {
  641.                 if (!(--cdelay) && !system_version2) {
  642.                     old=Window->Title;
  643.                     SetWindowTitles(Window,str_space_string,(char *)-1);
  644.                     SetWindowTitles(Window,old,(char *)-1);
  645.                 }
  646.             }
  647.         }
  648.     }
  649. }
  650.  
  651. void remiclock()
  652. {
  653.     if (!(CheckIO(&iconify_timereq.tr_node))) AbortIO(&iconify_timereq.tr_node);
  654.     WaitIO(&iconify_timereq.tr_node);
  655.     CloseDevice(&iconify_timereq.tr_node);
  656.     LDeletePort(iconify_time_port);
  657. }
  658.  
  659. getmaxmem(type,nottype)
  660. ULONG type,nottype;
  661. {
  662.     struct MemHeader *memory;
  663.     ULONG size=0;
  664.     int a;
  665.  
  666.     Forbid();
  667.     memory=(struct MemHeader *)SysBase->MemList.lh_Head;
  668.     while (memory->mh_Node.ln_Succ) {
  669.         if ((!type || (memory->mh_Attributes&type)) &&
  670.             (!nottype || !(memory->mh_Attributes¬type))) {
  671.             size+=(ULONG)((ULONG)memory->mh_Upper-(ULONG)memory->mh_Lower);
  672.         }
  673.         memory=(struct MemHeader *)memory->mh_Node.ln_Succ;
  674.     }
  675.     Permit();
  676.     size=(size+1023)/1024;
  677.     for (a=1;;a++) if (!(size/=10)) break;
  678.     return(a);
  679. }
  680.  
  681. void iconstatustext(buf,buttons)
  682. char *buf;
  683. int buttons;
  684. {
  685.     int a;
  686.  
  687.     if (system_version2) {
  688.         strcpy(icontitletext,buf);
  689.         SetWindowTitles(Window,icontitletext,(char *)-1);
  690.     }
  691.     else {
  692.         if (IntuitionBase->ActiveWindow==Window) {
  693.             SetAPen(main_rp,icon_fpen);
  694.             SetBPen(main_rp,icon_bpen);
  695.         }
  696.         else {
  697.             SetAPen(main_rp,0);
  698.             SetBPen(main_rp,1);
  699.         }
  700.         if (buttons) SetFont(main_rp,winfont);
  701.         a=strlen(buf);
  702.         Move(main_rp,icon_tx,icon_ty);
  703.         Text(main_rp,buf,a);
  704.         if (a<icon_len) Text(main_rp,str_space_string,icon_len-a);
  705.         if (buttons) SetFont(main_rp,scr_font[FONT_ICONIFY]);
  706.     }
  707. }
  708.  
  709. void cleanupiconify()
  710. {
  711.     if (icon_type&ICON_APPICON) {
  712.         RemoveAppIcon(appicon);
  713.         appicon=NULL;
  714.         if (Window) {
  715.             CloseWindow(Window);
  716.             Window=NULL;
  717.         }
  718.     }
  719.     else {
  720.         if (Window) {
  721.             if (status_flags&STATUS_ISINBUTTONS) {
  722.                 free_colour_table();
  723.                 if (WorkbenchBase && dopus_appwindow) {
  724.                     RemoveAppWindow(dopus_appwindow);
  725.                     dopus_appwindow=NULL;
  726.                 }
  727.                 config->iconbutx=Window->LeftEdge;
  728.                 config->iconbuty=Window->TopEdge;
  729.             }
  730.             else {
  731.                 config->iconx=Window->LeftEdge;
  732.                 config->icony=Window->TopEdge;
  733.             }
  734.         }
  735.         if (icon_gotclock) remiclock();
  736.         if (Window) {
  737.             if (Window->MenuStrip) ClearMenuStrip(Window);
  738.             CloseWindow(Window); Window=NULL;
  739.         }
  740.     }
  741.     LFreeRemember(&icon_key);
  742. }
  743.