home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Program / main8.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  22KB  |  750 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. #include "requesters.h"
  33.  
  34. checkexec(name)
  35. char *name;
  36. {
  37.     int file,check;
  38.  
  39.     if (!(file=Open(name,MODE_OLDFILE))) return(0);
  40.     Read(file,(char *)&check,4);
  41.     Close(file);
  42.     return((check==0x3f3));
  43. }
  44.  
  45. void newcli()
  46. {
  47.     char buf[200];
  48.  
  49.     lsprintf(buf,"%s \"%s\"",config->outputcmd,config->output);
  50.     if (!(Execute(buf,0,nil_file_handle))) doerror(IoErr());
  51.     else {
  52.         WBenchToFront();
  53.         okay();
  54.     }
  55. }
  56.  
  57. void getprot(protect,buffer)
  58. int protect;
  59. char *buffer;
  60. {
  61.     int a;
  62.     char *key=globstring[STR_PROTBIT_HSPA];
  63.  
  64.     strcpy(buffer,globstring[STR_PROTBIT_RWED]);
  65.     for (a=7;a>=0;a--)
  66.         if (protect&(1<<a)) buffer[7-a]=key[7-a];
  67. }
  68.  
  69. getprotval(buf)
  70. char *buf;
  71. {
  72.     int a,b,c,prot=15;
  73.  
  74.     a=strlen(buf);
  75.     for (b=0;b<a;b++) {
  76.         buf[b]=LToLower(buf[b]);
  77.         for (c=0;c<8;c++) {
  78.             if (buf[b]==globstring[STR_PROTBIT_ALLBITS][7-c]) {
  79.                 if (c<4) prot&=~(1<<c);
  80.                 else prot|=(1<<c);
  81.                 break;
  82.             }
  83.         }
  84.     }
  85.     return(prot);
  86. }
  87.  
  88. checkexistreplace(sourcename,destname,date,allabort,all)
  89. char *sourcename,*destname;
  90. struct DateStamp *date;
  91. int allabort,all;
  92. {
  93.     char buf[400],datebuf1[40],datebuf2[40];
  94.     int a,suc_dfib;
  95.     struct DateStamp ds;
  96.     struct FileInfoBlock __aligned d_fib;
  97.     struct FileInfoBlock __aligned s_fib;
  98.  
  99.     if (!(lockandexamine(sourcename,&s_fib))) return(1);
  100.     suc_dfib=lockandexamine(destname,&d_fib);
  101.  
  102.     if (suc_dfib && d_fib.fib_DirEntryType>0) {
  103.         if (s_fib.fib_DirEntryType<0) {
  104.             doerror(ERROR_OBJECT_EXISTS);
  105.             return(0);
  106.         }
  107.         return(1);
  108.     }
  109.  
  110.     if (config->existflags&REPLACE_ALWAYS) return(1);
  111.     if (config->existflags&REPLACE_NEVER) {
  112.         doerror(ERROR_OBJECT_EXISTS);
  113.         return(0);
  114.     }
  115.     if (config->existflags&REPLACE_OLDER) {
  116.         if (!date) {
  117.             DateStamp(&ds);
  118.             date=&ds;
  119.         }
  120.         if (suc_dfib) {
  121.             if (CompareDate(date,&(d_fib.fib_Date))>0) return(1);
  122.             doerror(ERROR_OBJECT_EXISTS);
  123.         }
  124.         return(0);
  125.     }
  126.     if (config->existflags&REPLACE_ASK) {
  127.         doerror(ERROR_OBJECT_EXISTS);
  128.         if (sourcename==destname || !suc_dfib) {
  129.             lsprintf(buf,globstring[STR_FILE_EXISTS_REPLACE],BaseName(destname));
  130.         }
  131.         else {
  132.             seedate(&s_fib.fib_Date,datebuf1,0);
  133.             seedate(&d_fib.fib_Date,datebuf2,0);
  134.             lsprintf(buf,globstring[STR_OLD_NEW_FILE_REPLACE],BaseName(destname),
  135.                 s_fib.fib_Size,datebuf1,d_fib.fib_Size,datebuf2);
  136.         }
  137.         a=simplerequest(buf,globstring[STR_REPLACE],globstring[STR_SKIP],
  138.             globstring[(allabort?(all?STR_ALL:STR_ABORT):STR_TRY_AGAIN)],
  139.             (all?globstring[STR_ABORT]:NULL),NULL);
  140.         return(a);
  141.     }
  142. }
  143.  
  144. lockandexamine(name,fib)
  145. char *name;
  146. struct FileInfoBlock *fib;
  147. {
  148.     BPTR lock;
  149.  
  150.     fib->fib_OwnerUID=fib->fib_OwnerGID=0;
  151.     if (!(lock=Lock(name,ACCESS_READ))) return(0);
  152.     Examine(lock,fib);
  153.     UnLock(lock);
  154.     return(1);
  155. }
  156.  
  157. void layoutcenter(off)
  158. int off;
  159. {
  160.     int a,max;
  161.     int tiny_extra;
  162.  
  163.     removewindowgadgets(Window);
  164.  
  165.     scrdata_diskname_width[0]=scrdata_diskname_width[1]=(scrdata_width/2)-4;
  166.     scrdata_dispwin_width[0]=scrdata_dispwin_width[1]=(scrdata_width-24-config->sliderwidth*2)/2;
  167.     scrdata_dirwin_center=((scrdata_width/2)-2)+scrdata_xoffset;
  168.  
  169.     max=(scrdata_dirwin_center-((config->sliderwidth*2)+(scrdata_font_xsize*10)))/scrdata_font_xsize;
  170.     if (off>max) off=max;
  171.     else if (off<-max) off=-max;
  172.  
  173.     scrdata_diskname_width[0]+=scrdata_font_xsize*off;
  174.     scrdata_diskname_width[1]-=scrdata_font_xsize*off;
  175.     scrdata_dispwin_width[0]+=scrdata_font_xsize*off;
  176.     scrdata_dispwin_width[1]-=scrdata_font_xsize*off;
  177.  
  178.     scrdata_dispwin_center=scrdata_xoffset+scrdata_diskname_width[0]+4;
  179.  
  180.     for (a=0;a<2;a++) {
  181.         vert_propgad[a].Width=config->sliderwidth;
  182.         vert_propgad[a].Height=scrdata_prop_height;
  183.     }
  184.  
  185.     if (config->slider_pos&1) {
  186.         vert_propgad[0].LeftEdge=scrdata_dispwin_center-config->sliderwidth-4;
  187.         scrdata_dispwin_left[0]=scrdata_xoffset;
  188.     }
  189.     else {
  190.         vert_propgad[0].LeftEdge=scrdata_xoffset+4;
  191.         scrdata_dispwin_left[0]=vert_propgad[0].LeftEdge+vert_propgad[0].Width+4;
  192.     }
  193.  
  194.     if (config->slider_pos&2) {
  195.         scrdata_dispwin_left[1]=scrdata_dispwin_center;
  196.         vert_propgad[1].LeftEdge=scrdata_dispwin_left[1]+scrdata_dispwin_width[1]+8;
  197.         tiny_extra=config->sliderwidth+8;
  198.     }
  199.     else {
  200.         vert_propgad[1].LeftEdge=scrdata_dispwin_center+4;
  201.         scrdata_dispwin_left[1]=vert_propgad[1].LeftEdge+vert_propgad[0].Width+4;
  202.         tiny_extra=0;
  203.     }
  204.  
  205.     scrdata_dispwin_xpos[0]=scrdata_dispwin_left[0];
  206.     scrdata_dispwin_xpos[1]=scrdata_dispwin_left[1];
  207.  
  208.     scrdata_diskname_xpos[0]=scrdata_xoffset;
  209.     scrdata_diskname_xpos[1]=scrdata_xoffset+scrdata_diskname_width[0]+4;
  210.  
  211.     for (a=0;a<2;a++) {
  212.         scrdata_dispwin_nchars[a]=scrdata_dispwin_width[a]/scrdata_font_xsize;
  213.         if ((scrdata_dispwin_nchars[a]*scrdata_font_xsize)>scrdata_dispwin_width[a]-2)
  214.             --scrdata_dispwin_nchars[a];
  215.         scrdata_dirwin_width[a]=scrdata_dispwin_nchars[a]*scrdata_font_xsize;
  216.         scrdata_dirwin_xpos[a]=scrdata_dispwin_xpos[a]+2+((scrdata_dispwin_width[a]-scrdata_dirwin_width[a])/2);
  217.     }
  218.  
  219.     for (a=0;a<2;a++) {
  220.         screen_gadgets[SCRGAD_MOVEUP1+a].TopEdge=scrdata_dispwin_ypos-1;
  221.         screen_gadgets[SCRGAD_MOVEDOWN1+a].TopEdge=
  222.             scrdata_dispwin_ypos+
  223.             scrdata_prop_height+
  224.             config->arrowsize[0]+4;
  225.  
  226.         switch (config->arrowpos[0]) {
  227.             case ARROWS_INSIDE:
  228.                 screen_gadgets[SCRGAD_MOVEUP1+a].TopEdge=
  229.                     scrdata_dispwin_ypos+
  230.                     scrdata_prop_height+3;
  231.                 vert_propgad[a].TopEdge=scrdata_dispwin_ypos+1;
  232.                 break;
  233.             case ARROWS_OUTSIDE:
  234.                 screen_gadgets[SCRGAD_MOVEDOWN1+a].TopEdge=scrdata_dispwin_ypos+config->arrowsize[0];
  235.                 vert_propgad[a].TopEdge=scrdata_dispwin_ypos+((config->arrowsize[0]*2)+3);
  236.                 break;
  237.             case ARROWS_EACHSIDE:
  238.                 vert_propgad[a].TopEdge=scrdata_dispwin_ypos+config->arrowsize[0]+2;
  239.                 break;
  240.         }
  241.     }
  242.  
  243.     for (a=0;a<2;a++) {
  244.         path_strgadget[a].TopEdge=scrdata_dirwin_bottom+30+config->sliderheight;
  245.         path_strgadget[a].Width=scrdata_dispwin_width[a]-((config->arrowsize[2]*2)+20);
  246.         path_strgadget[a].Height=scrdata_string_height;
  247.  
  248.         horiz_propgad[a].TopEdge=scrdata_dirwin_bottom+26;
  249.         horiz_propgad[a].Width=scrdata_dispwin_width[a]-((config->arrowsize[1]*2)+20);
  250.         horiz_propgad[a].Height=config->sliderheight;
  251.  
  252.         screen_gadgets[SCRGAD_TINYBUFFERLIST+a].TopEdge=scrdata_dirwin_bottom+24;
  253.         screen_gadgets[SCRGAD_TINYBUFFERLIST+a].Height=config->sliderheight+4;
  254.         screen_gadgets[SCRGAD_TINYSELECT+a].TopEdge=scrdata_dirwin_bottom+28+config->sliderheight;
  255.         screen_gadgets[SCRGAD_TINYSELECT+a].Height=scrdata_string_height+4;
  256.         screen_gadgets[SCRGAD_MOVEUP1+a].LeftEdge=
  257.             screen_gadgets[SCRGAD_MOVEDOWN1+a].LeftEdge=vert_propgad[a].LeftEdge-4;
  258.         screen_gadgets[SCRGAD_LEFTPARENT+a].Height=scrdata_dispwin_height;
  259.         screen_gadgets[SCRGAD_LEFTPARENT+a].TopEdge=scrdata_dispwin_ypos;
  260.     }
  261.  
  262.     switch (config->arrowpos[1]) {
  263.         case ARROWS_INSIDE:
  264.             horiz_propgad[0].LeftEdge=scrdata_xoffset+4;
  265.             screen_gadgets[SCRGAD_MOVELEFT1].LeftEdge=
  266.                 horiz_propgad[0].LeftEdge+horiz_propgad[0].Width+4;
  267.             screen_gadgets[SCRGAD_MOVERIGHT1].LeftEdge=
  268.                 horiz_propgad[0].LeftEdge+horiz_propgad[0].Width+config->arrowsize[1]+12;
  269.  
  270.             screen_gadgets[SCRGAD_MOVELEFT2].LeftEdge=
  271.                 scrdata_dispwin_xpos[1]+tiny_extra;
  272.             screen_gadgets[SCRGAD_MOVERIGHT2].LeftEdge=
  273.                 screen_gadgets[SCRGAD_MOVELEFT2].LeftEdge+config->arrowsize[1]+8;
  274.             horiz_propgad[1].LeftEdge=
  275.                 screen_gadgets[SCRGAD_MOVERIGHT2].LeftEdge+config->arrowsize[1]+12;
  276.             break;
  277.  
  278.         case ARROWS_OUTSIDE:
  279.             screen_gadgets[SCRGAD_MOVELEFT1].LeftEdge=scrdata_xoffset;
  280.             screen_gadgets[SCRGAD_MOVERIGHT1].LeftEdge=scrdata_xoffset+config->arrowsize[1]+8;
  281.             horiz_propgad[0].LeftEdge=scrdata_xoffset+(config->arrowsize[1]*2)+20;
  282.  
  283.             horiz_propgad[1].LeftEdge=
  284.                 scrdata_dispwin_xpos[1]+4+tiny_extra;
  285.             screen_gadgets[SCRGAD_MOVELEFT2].LeftEdge=
  286.                 horiz_propgad[1].LeftEdge+horiz_propgad[1].Width+4;
  287.             screen_gadgets[SCRGAD_MOVERIGHT2].LeftEdge=
  288.                 screen_gadgets[SCRGAD_MOVELEFT2].LeftEdge+
  289.                 config->arrowsize[1]+8;
  290.             break;
  291.  
  292.         case ARROWS_EACHSIDE:
  293.             screen_gadgets[SCRGAD_MOVELEFT1].LeftEdge=scrdata_xoffset;
  294.             horiz_propgad[0].LeftEdge=scrdata_xoffset+config->arrowsize[1]+12;
  295.             screen_gadgets[SCRGAD_MOVERIGHT1].LeftEdge=
  296.                 scrdata_xoffset+
  297.                 horiz_propgad[0].Width+config->arrowsize[1]+16;
  298.  
  299.             screen_gadgets[SCRGAD_MOVELEFT2].LeftEdge=
  300.                 scrdata_dispwin_xpos[1]+tiny_extra;
  301.             horiz_propgad[1].LeftEdge=
  302.                 screen_gadgets[SCRGAD_MOVELEFT2].LeftEdge+config->arrowsize[1]+12;
  303.             screen_gadgets[SCRGAD_MOVERIGHT2].LeftEdge=
  304.                 horiz_propgad[1].LeftEdge+horiz_propgad[1].Width+4;
  305.             break;
  306.     }
  307.  
  308.     switch (config->arrowpos[2]) {
  309.         case ARROWS_INSIDE:
  310.             path_strgadget[0].LeftEdge=scrdata_xoffset+4;
  311.             screen_gadgets[SCRGAD_BUFFERLEFT1].LeftEdge=
  312.                 path_strgadget[0].LeftEdge+path_strgadget[0].Width+4;
  313.             screen_gadgets[SCRGAD_BUFFERRIGHT1].LeftEdge=
  314.                 path_strgadget[0].LeftEdge+path_strgadget[0].Width+config->arrowsize[2]+12;
  315.  
  316.             screen_gadgets[SCRGAD_BUFFERLEFT2].LeftEdge=
  317.                 scrdata_dispwin_xpos[1]+tiny_extra;
  318.             screen_gadgets[SCRGAD_BUFFERRIGHT2].LeftEdge=
  319.                 screen_gadgets[SCRGAD_BUFFERLEFT2].LeftEdge+config->arrowsize[2]+8;
  320.             path_strgadget[1].LeftEdge=
  321.                 screen_gadgets[SCRGAD_BUFFERRIGHT2].LeftEdge+config->arrowsize[2]+12;
  322.             break;
  323.  
  324.         case ARROWS_OUTSIDE:
  325.             screen_gadgets[SCRGAD_BUFFERLEFT1].LeftEdge=scrdata_xoffset;
  326.             screen_gadgets[SCRGAD_BUFFERRIGHT1].LeftEdge=scrdata_xoffset+config->arrowsize[2]+8;
  327.             path_strgadget[0].LeftEdge=scrdata_xoffset+(config->arrowsize[2]*2)+20;
  328.  
  329.             path_strgadget[1].LeftEdge=scrdata_dispwin_xpos[1]+4+tiny_extra;
  330.             screen_gadgets[SCRGAD_BUFFERLEFT2].LeftEdge=
  331.                 path_strgadget[1].LeftEdge+path_strgadget[1].Width+4;
  332.             screen_gadgets[SCRGAD_BUFFERRIGHT2].LeftEdge=
  333.                 screen_gadgets[SCRGAD_BUFFERLEFT2].LeftEdge+
  334.                 config->arrowsize[2]+8;
  335.             break;
  336.  
  337.         case ARROWS_EACHSIDE:
  338.             screen_gadgets[SCRGAD_BUFFERLEFT1].LeftEdge=scrdata_xoffset;
  339.             path_strgadget[0].LeftEdge=scrdata_xoffset+config->arrowsize[2]+12;
  340.             screen_gadgets[SCRGAD_BUFFERRIGHT1].LeftEdge=
  341.                 scrdata_xoffset+path_strgadget[0].Width+config->arrowsize[2]+16;
  342.  
  343.             screen_gadgets[SCRGAD_BUFFERLEFT2].LeftEdge=
  344.                 scrdata_dispwin_xpos[1]+tiny_extra;
  345.             path_strgadget[1].LeftEdge=
  346.                 screen_gadgets[SCRGAD_BUFFERLEFT2].LeftEdge+config->arrowsize[2]+12;
  347.             screen_gadgets[SCRGAD_BUFFERRIGHT2].LeftEdge=
  348.                 path_strgadget[1].LeftEdge+path_strgadget[1].Width+4;
  349.             break;
  350.     }
  351.  
  352.     for (a=0;a<4;a++) {
  353.         screen_gadgets[SCRGAD_BUFFERLEFT1+a].TopEdge=scrdata_dirwin_bottom+28+config->sliderheight;
  354.         screen_gadgets[SCRGAD_BUFFERLEFT1+a].Height=scrdata_string_height+4;
  355.         screen_gadgets[SCRGAD_MOVELEFT1+a].TopEdge=scrdata_dirwin_bottom+24;
  356.         screen_gadgets[SCRGAD_MOVELEFT1+a].Height=config->sliderheight+4;
  357.         screen_gadgets[SCRGAD_MOVEUP1+a].Width=
  358.             screen_gadgets[SCRGAD_TINYBUFFERLIST+a].Width=config->sliderwidth+8;
  359.     }
  360.  
  361.     screen_gadgets[SCRGAD_MOVEUP1].Height=config->arrowsize[0]+1;
  362.     screen_gadgets[SCRGAD_MOVEDOWN1].Height=config->arrowsize[0]+1;
  363.     screen_gadgets[SCRGAD_MOVEUP2].Height=config->arrowsize[0]+1;
  364.     screen_gadgets[SCRGAD_MOVEDOWN2].Height=config->arrowsize[0]+1;
  365.  
  366.     screen_gadgets[SCRGAD_MOVELEFT1].Width=config->arrowsize[1]+8;
  367.     screen_gadgets[SCRGAD_MOVERIGHT1].Width=config->arrowsize[1]+8;
  368.     screen_gadgets[SCRGAD_MOVELEFT2].Width=config->arrowsize[1]+8;
  369.     screen_gadgets[SCRGAD_MOVERIGHT2].Width=config->arrowsize[1]+8;
  370.  
  371.     screen_gadgets[SCRGAD_BUFFERLEFT1].Width=config->arrowsize[2]+8;
  372.     screen_gadgets[SCRGAD_BUFFERRIGHT1].Width=config->arrowsize[2]+8;
  373.     screen_gadgets[SCRGAD_BUFFERLEFT2].Width=config->arrowsize[2]+8;
  374.     screen_gadgets[SCRGAD_BUFFERRIGHT2].Width=config->arrowsize[2]+8;
  375.  
  376.     screen_gadgets[SCRGAD_TINYBUFFERLIST].LeftEdge=
  377.         screen_gadgets[SCRGAD_TINYSELECT].LeftEdge=
  378.         scrdata_dispwin_center-config->sliderwidth-8;
  379.     screen_gadgets[SCRGAD_TINYRESELECT].LeftEdge=
  380.         screen_gadgets[SCRGAD_TINYAREXX].LeftEdge=
  381.         scrdata_dispwin_center;
  382.  
  383.     screen_gadgets[SCRGAD_LEFTPARENT].LeftEdge=0;
  384.     screen_gadgets[SCRGAD_RIGHTPARENT].LeftEdge=scrdata_xoffset+(scrdata_width-2);
  385.  
  386.     for (a=SCRGAD_TINYBUFFERLIST;a<=SCRGAD_BUFFERRIGHT2;a++) {
  387.         screen_gadgets[a].GadgetRender=NULL;
  388.         screen_gadgets[a].SelectRender=NULL;
  389.     }
  390. }
  391.  
  392. void fix_rmb_gadgets()
  393. {
  394.     int a;
  395.  
  396.     mainrmbgads[0].x=scrdata_gadget_offset;
  397.     mainrmbgads[0].y=scrdata_gadget_ypos-1;
  398.     mainrmbgads[0].w=scrdata_drive_width;
  399.     mainrmbgads[0].h=scr_gadget_rows*scrdata_gadget_height;
  400.  
  401.     if (drive_bank_unsel_border) {
  402.         mainrmbgads[0].flags|=RGF_ALTBORD;
  403.         mainrmbgads[0].high_bord[0]=drive_bank_unsel_border;
  404.         mainrmbgads[0].high_bord[1]=drive_bank_sel_border;
  405.     }
  406.     else mainrmbgads[0].flags&=~RGF_ALTBORD;
  407.  
  408.     for (a=0;a<4;a++)
  409.         makermbgad(&mainrmbgads[a+1],&screen_gadgets[SCRGAD_TINYBUFFERLIST+a],1);
  410.     for (a=0;a<2;a++)
  411.         makermbgad(&mainrmbgads[a+5],&screen_gadgets[SCRGAD_LEFTPARENT+a],0);
  412. }
  413.  
  414. void dosizedirwindows(size)
  415. int size;
  416. {
  417.     ULONG class;
  418.     USHORT code;
  419.     int x,ox,fail=0,max;
  420.  
  421.     max=(scrdata_dirwin_center-((config->sliderwidth*2)+(scrdata_font_xsize*10)))/scrdata_font_xsize;
  422.     if (size!=65536) {
  423.         if (size>max) size=max;
  424.         else if (size<-max) size=-max;
  425.         ox=size; fail=-1;
  426.     }
  427.     else {
  428.         if ((scrdata_width-24-config->sliderwidth*2)<scrdata_font_xsize*24) return;
  429.  
  430.         SetDrMd(main_rp,COMPLEMENT);
  431.         sizedirwindow_gfx((ox=config->windowdelta));
  432.         Window->Flags|=WFLG_REPORTMOUSE;
  433.  
  434.         FOREVER {
  435.             while (getintuimsg()) {
  436.                 if (IMsg->MouseX<scrdata_dirwin_center) {
  437.                     x=(IMsg->MouseX-(scrdata_dirwin_center+4))/scrdata_font_xsize;
  438.                 }
  439.                 else {
  440.                     x=(IMsg->MouseX-scrdata_dirwin_center)/scrdata_font_xsize;
  441.                 }
  442.  
  443.                 if (x>max) x=max;
  444.                 else if (x<-max) x=-max;
  445.                 class=IMsg->Class; code=IMsg->Code;
  446.                 ReplyMsg((struct Message *)IMsg);
  447.                 if (class==IDCMP_MOUSEBUTTONS) {
  448.                     if (code==MENUDOWN) {
  449.                         fail=1;
  450.                         break;
  451.                     }
  452.                     if (code==SELECTUP) {
  453.                         fail=-1;
  454.                         break;
  455.                     }
  456.                 }
  457.                 else if (class==IDCMP_MOUSEMOVE) {
  458.                     if (x!=ox) {
  459.                         sizedirwindow_gfx(ox);
  460.                         sizedirwindow_gfx((ox=x));
  461.                     }
  462.                 }
  463.                 else if (class==IDCMP_RAWKEY) {
  464.                     if (code==0x45) {
  465.                         fail=-1;
  466.                         sizedirwindow_gfx(ox);
  467.                         sizedirwindow_gfx((ox=0));
  468.                         break;
  469.                     }
  470.                 }
  471.             }
  472.             if (fail) break;
  473.             Wait(1<<Window->UserPort->mp_SigBit);
  474.         }
  475.         sizedirwindow_gfx(ox);
  476.         SetDrMd(main_rp,JAM2);
  477.         Window->Flags&=~WFLG_REPORTMOUSE;
  478.     }
  479.     if (fail==-1 && ox!=config->windowdelta && !status_iconified) {
  480.         busy();
  481.         layoutcenter((config->windowdelta=ox));
  482.         fix_rmb_gadgets();
  483.         SetAPen(main_rp,screen_pens[0].pen);
  484.         rectfill(main_rp,
  485.             scrdata_dispwin_center-config->sliderwidth-7,
  486.             scrdata_dispwin_ypos-1,
  487.             (config->sliderwidth*2)+13,
  488.             scrdata_dispwin_height+2);
  489.         RectFill(main_rp,
  490.             scrdata_xoffset,
  491.             horiz_propgad[0].TopEdge-2,
  492.             scrdata_xoffset+scrdata_width-1,
  493.             path_strgadget[0].TopEdge+path_strgadget[0].Height+1);
  494.         setupdisplay(0);
  495.         for (x=0;x<2;x++) RefreshStrGad(&path_strgadget[x],Window);
  496.         okay();
  497.         unbusy();
  498.     }
  499. }
  500.  
  501. void sizedirwindow_gfx(dx)
  502. int dx;
  503. {
  504.     int x;
  505.  
  506.     x=scrdata_dirwin_center+(dx*scrdata_font_xsize);
  507.     rectfill(main_rp,x,scrdata_dispwin_ypos,4,scrdata_dispwin_height);
  508. }
  509.  
  510. void fix_requester(req,title)
  511. struct RequesterBase *req;
  512. char *title;
  513. {
  514.     req->rb_fg=screen_pens[config->requestfg].pen;
  515.     req->rb_bg=screen_pens[config->requestbg].pen;
  516.     req->rb_shine=screen_pens[config->gadgettopcol].pen;
  517.     req->rb_shadow=screen_pens[config->gadgetbotcol].pen;
  518.     req->rb_font=scr_font[FONT_REQUEST];
  519.     req->rb_screen=Window->WScreen;
  520.     req->rb_extend=&requester_stringex;
  521.     fix_stringex(&requester_stringex);
  522.     if (config->generalscreenflags&SCR_GENERAL_REQDRAG) {
  523.         req->rb_title=title;
  524.         req->rb_flags=RBF_BORDERS|RBF_STRINGS;
  525.     }
  526.     else {
  527.         req->rb_title=NULL;
  528.         req->rb_flags=RBF_STRINGS;
  529.     }
  530.     req->rb_string_table=globstring;
  531.     if (status_publicscreen) {
  532.         req->rb_window=Window;
  533.         req->rb_flags|=RBF_WINDOWCENTER;
  534.     }
  535.     else req->rb_flags&=~RBF_WINDOWCENTER;
  536. }
  537.  
  538. void fix_stringex(extend)
  539. struct StringExtend *extend;
  540. {
  541.     extend->Font=scr_font[FONT_REQUEST];
  542.     extend->Pens[0]=screen_pens[config->stringfgcol].pen;
  543.     extend->Pens[1]=screen_pens[config->stringbgcol].pen;
  544.     extend->ActivePens[0]=screen_pens[config->stringselfgcol].pen;
  545.     extend->ActivePens[1]=screen_pens[config->stringselbgcol].pen;
  546. }
  547.  
  548. struct Gadget *addreqgadgets(reqbase,gadgets,mask,count)
  549. struct RequesterBase *reqbase;
  550. struct TagItem **gadgets;
  551. int mask,*count;
  552. {
  553.     int gad;
  554.     struct Gadget *gadget=NULL,*newgadget,*firstgadget;
  555.  
  556.     for (gad=0;;gad++) {
  557.         if (!gadgets[gad]) break;
  558.         if (gad>31 || !(mask&(1<<gad))) {
  559.             if (!(newgadget=(struct Gadget *)
  560.                 AddRequesterObject(reqbase,gadgets[gad]))) return(NULL);
  561.             if (gadget) gadget->NextGadget=newgadget;
  562.             else firstgadget=newgadget;
  563.             gadget=newgadget;
  564.             if (count) ++*count;
  565.         }
  566.     }
  567.     AddGadgets(reqbase->rb_window,firstgadget,NULL,gad,reqbase->rb_shine,reqbase->rb_shadow,1);
  568.     return(firstgadget);
  569. }
  570.  
  571. void set_reqobject(object,tagmatch,data)
  572. struct TagItem *object;
  573. ULONG tagmatch,data;
  574. {
  575.     int tag;
  576.  
  577.     for (tag=0;;tag++) {
  578.         if (object[tag].ti_Tag==TAG_END) break;
  579.         if (object[tag].ti_Tag==tagmatch) {
  580.             object[tag].ti_Data=data;
  581.             break;
  582.         }
  583.     }
  584. }
  585.  
  586. void FadeRGB32(screen,cmap,count,dir,fadetime)
  587. struct Screen *screen;
  588. ULONG *cmap;
  589. int count,dir,fadetime;
  590. {
  591.     if (system_version2<OSVER_39) {
  592.         UWORD *cmap4;
  593.         int a,b;
  594.  
  595.         if (cmap4=AllocMem(count*sizeof(UWORD),MEMF_CLEAR)) {
  596.             for (a=0,b=0;a<count;a++) {
  597.                 cmap4[a]=(cmap[b++]>>20)&0x0f00;
  598.                 cmap4[a]|=(cmap[b++]>>24)&0x0ff0;
  599.                 cmap4[a]|=(cmap[b++]>>28)&0x0fff;
  600.             }
  601.             FadeRGB4(screen,cmap4,count,dir,fadetime);
  602.             FreeMem(cmap4,count*sizeof(UWORD));
  603.         }
  604.         else if (dir>0) load_palette(screen,cmap);
  605.         else load_palette(screen,(ULONG *)nullpalette);
  606.     }
  607.     else {
  608.         ULONG *tempmap;
  609.         int i,j,s,t,n,mod,val,orval,maxval;
  610.         struct timerequest treq;
  611.         struct MsgPort *fade_port=NULL;
  612.         struct DisplayInfo dinfo;
  613.  
  614.         if (!(tempmap=AllocMem(((count*3)+2)*sizeof(ULONG),MEMF_CLEAR)) ||
  615.             fadetime<1 ||
  616.             !(fade_port=LCreatePort(NULL,0)) ||
  617.             !(GetDisplayInfoData(NULL,
  618.                 (char *)&dinfo,sizeof(struct DisplayInfo),
  619.                 DTAG_DISP,GetVPModeID(&screen->ViewPort))) ||
  620.             (OpenDevice(TIMERNAME,UNIT_VBLANK,&treq.tr_node,0))) {
  621.             if (tempmap) {
  622.                 CopyMem((char *)cmap,(char *)&tempmap[1],count*3*sizeof(ULONG));
  623.                 tempmap[0]=count<<16;
  624.                 LoadRGB32(&screen->ViewPort,tempmap);
  625.             }
  626.             else load_palette(screen,cmap);
  627.         }
  628.         else {
  629.             maxval=1<<dinfo.RedBits;
  630.             if (dinfo.RedBits<4) i=1;
  631.             else i=maxval>>4;
  632.  
  633.             tempmap[0]=count<<16;
  634.  
  635.             if (dir==1) {
  636.                 s=maxval-1; t=-1; n=-i;
  637.                 LoadRGB32(&screen->ViewPort,tempmap);
  638.             }
  639.             else {
  640.                 s=1; t=maxval; n=i;
  641.             }
  642.             mod=32-dinfo.RedBits;
  643.             orval=(1<<mod)-1;
  644.  
  645.             treq.tr_node.io_Message.mn_ReplyPort=fade_port;
  646.             treq.tr_node.io_Command=TR_ADDREQUEST;
  647.             treq.tr_node.io_Flags=0;
  648.     
  649.             for (i=s;i+=n;) {
  650.                 if (dir==1) {
  651.                     if (i<=t) break;
  652.                 }
  653.                 else {
  654.                     if (i>=t) break;
  655.                 }
  656.                 for (j=0;j<count*3;j++) {
  657.                     val=(cmap[j]>>mod)-i;
  658.                     if (val<0) val=0;
  659.                     else if (val>=maxval) val=maxval-1;
  660.                     tempmap[j+1]=(val<<mod)|orval;
  661.                 }
  662.  
  663.                 treq.tr_time.tv_secs=0;
  664.                 treq.tr_time.tv_micro=fadetime*22000;
  665.                 SendIO(&treq.tr_node);
  666.                 WaitBOVP(&screen->ViewPort);
  667.                 LoadRGB32(&screen->ViewPort,tempmap);
  668.                 WaitIO(&treq.tr_node);
  669.             }
  670.             if (dir>0) CopyMem((char *)cmap,(char *)&tempmap[1],count*3*sizeof(ULONG));
  671.             else for (j=0;j<count*3;j++) tempmap[j+1]=0;
  672.             LoadRGB32(&screen->ViewPort,tempmap);
  673.             CloseDevice(&treq.tr_node);
  674.         }
  675.         if (fade_port) LDeletePort(fade_port);
  676.         if (tempmap) FreeMem(tempmap,((count*3)+2)*sizeof(ULONG));
  677.     }
  678. }
  679.  
  680. void FadeRGB4(screen,cmap,count,dir,fadetime)
  681. struct Screen *screen;
  682. UWORD *cmap;
  683. int count,dir,fadetime;
  684. {
  685.     UWORD *tempmap=NULL;
  686.     char red,green,blue;
  687.     int i,j,s,t,n;
  688.     struct timerequest treq;
  689.     struct MsgPort *fade_port=NULL;
  690.  
  691.     if (dir==1) {
  692.         s=15; t=-1; n=-1;
  693.     }
  694.     else {
  695.         s=1; t=16; n=1;
  696.     }
  697.  
  698.     if (fadetime<1 ||
  699.         !(tempmap=AllocMem(count*sizeof(UWORD),MEMF_CLEAR)) ||
  700.         !(fade_port=LCreatePort(NULL,0)) ||
  701.         (OpenDevice(TIMERNAME,UNIT_VBLANK,&treq.tr_node,0))) {
  702.         LoadRGB4(&screen->ViewPort,cmap,count);
  703.     }
  704.     else {
  705.         treq.tr_node.io_Message.mn_ReplyPort=fade_port;
  706.         treq.tr_node.io_Command=TR_ADDREQUEST;
  707.         treq.tr_node.io_Flags=0;
  708.  
  709.         if (dir==1) LoadRGB4(&screen->ViewPort,tempmap,count);
  710.         for (i=s;i!=t;i+=n) {
  711.             for (j=0;j<count;j++) {
  712.                 red=((cmap[j]>>8)&0xf)-i;
  713.                 green=((cmap[j]>>4)&0xf)-i;
  714.                 blue=(cmap[j]&0xf)-i;
  715.                 if (red<0) red=0; if (green<0) green=0; if (blue<0) blue=0;
  716.                 tempmap[j]=(UWORD)red<<8|(UWORD)green<<4|(UWORD)blue;
  717.             }
  718.             treq.tr_time.tv_secs=0;
  719.             treq.tr_time.tv_micro=fadetime*20000;
  720.             SendIO(&treq.tr_node);
  721.             WaitBOVP(&screen->ViewPort);
  722.             LoadRGB4(&screen->ViewPort,tempmap,count);
  723.             WaitIO(&treq.tr_node);
  724.         }
  725.         CloseDevice(&treq.tr_node);
  726.     }
  727.     if (fade_port) LDeletePort(fade_port);
  728.     if (tempmap) FreeMem(tempmap,count*sizeof(UWORD));
  729. }
  730.  
  731. void removewindowgadgets(window)
  732. struct Window *window;
  733. {
  734.     if (window && window->FirstGadget) {
  735.         struct Gadget *gad;
  736.  
  737.         FOREVER {
  738.             gad=window->FirstGadget;
  739.             while (gad) {
  740.                 if (!(gad->GadgetType>YP_SYSGADGET)) {
  741.                     RemoveGList(window,gad,1);
  742.                     break;
  743.                 }
  744.                 gad=gad->NextGadget;
  745.             }
  746.             if (!gad) break;
  747.         }
  748.     }
  749. }
  750.