home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / DOpus_Icon / doiconinfo.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  26KB  |  982 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 "iconinfo.h"
  32.  
  33. struct TagItem
  34.     iconinfo_remap_gadget[]={
  35.         {RO_Type,OBJECT_GADGET},
  36.         {RO_GadgetType,GADGET_BOOLEAN},
  37.         {RO_GadgetID,II_REMAP},
  38.         {RO_LeftFine,408},
  39.         {RO_TopFine,92},
  40.         {RO_WidthFine,114},
  41.         {RO_HeightFine,12},
  42.         {RO_TextNum,STR_REMAP_COLORS},
  43.         {RO_TextPos,TEXTPOS_CENTER},
  44.         {RO_HighRecess,TRUE},
  45.         {TAG_END,0}},
  46.     iconinfo_save_gadget[]={
  47.         {RO_Type,OBJECT_GADGET},
  48.         {RO_GadgetType,GADGET_BOOLEAN},
  49.         {RO_GadgetID,II_SAVE},
  50.         {RO_LeftFine,40},
  51.         {RO_TopFine,0},
  52.         {RO_WidthFine,100},
  53.         {RO_HeightFine,12},
  54.         {RO_TextNum,STR_SAVE},
  55.         {RO_TextPos,TEXTPOS_CENTER},
  56.         {RO_HighRecess,TRUE},
  57.         {TAG_END,0}},
  58.     iconinfo_skip_gadget[]={
  59.         {RO_Type,OBJECT_GADGET},
  60.         {RO_GadgetType,GADGET_BOOLEAN},
  61.         {RO_GadgetID,II_SKIP},
  62.         {RO_LeftFine,220},
  63.         {RO_TopFine,0},
  64.         {RO_WidthFine,100},
  65.         {RO_HeightFine,12},
  66.         {RO_TextNum,STR_SKIP},
  67.         {RO_TextPos,TEXTPOS_CENTER},
  68.         {RO_HighRecess,TRUE},
  69.         {TAG_END,0}},
  70.     iconinfo_cancel_gadget[]={
  71.         {RO_Type,OBJECT_GADGET},
  72.         {RO_GadgetType,GADGET_BOOLEAN},
  73.         {RO_GadgetID,II_CANCEL},
  74.         {RO_LeftFine,400},
  75.         {RO_TopFine,0},
  76.         {RO_WidthFine,100},
  77.         {RO_HeightFine,12},
  78.         {RO_TextNum,STR_CANCEL},
  79.         {RO_TextPos,TEXTPOS_CENTER},
  80.         {RO_HighRecess,TRUE},
  81.         {TAG_END,0}},
  82.  
  83.     iconinfo_edittooltype_gadget[]={
  84.         {RO_Type,OBJECT_GADGET},
  85.         {RO_GadgetType,GADGET_STRING},
  86.         {RO_GadgetID,II_TOOLTYPE},
  87.         {RO_LeftFine,118},
  88.         {RO_TopFine,166},
  89.         {RO_WidthFine,400},
  90.         {RO_HeightFine,8},
  91.         {RO_StringLen,128},
  92.         {TAG_END,0}},
  93.     iconinfo_deletetooltype_gadget[]={
  94.         {RO_Type,OBJECT_GADGET},
  95.         {RO_GadgetType,GADGET_BOOLEAN},
  96.         {RO_GadgetID,II_DELETE},
  97.         {RO_LeftFine,8},
  98.         {RO_TopFine,164},
  99.         {RO_WidthFine,100},
  100.         {RO_HeightFine,12},
  101.         {RO_TextNum,STR_DELETE},
  102.         {RO_TextPos,TEXTPOS_CENTER},
  103.         {RO_HighRecess,TRUE},
  104.         {TAG_END,0}},
  105.     iconinfo_newtooltype_gadget[]={
  106.         {RO_Type,OBJECT_GADGET},
  107.         {RO_GadgetType,GADGET_BOOLEAN},
  108.         {RO_GadgetID,II_NEW},
  109.         {RO_LeftFine,8},
  110.         {RO_TopFine,150},
  111.         {RO_WidthFine,100},
  112.         {RO_HeightFine,12},
  113.         {RO_TextNum,STR_NEW},
  114.         {RO_TextPos,TEXTPOS_CENTER},
  115.         {RO_HighRecess,TRUE},
  116.         {TAG_END,0}},
  117.  
  118.     iconinfo_tooltype_list[]={
  119.         {RO_Type,OBJECT_LISTVIEW},
  120.         {RO_ListViewID,0},
  121.         {RO_LeftFine,116},
  122.         {RO_TopFine,121},
  123.         {RO_WidthFine,388},
  124.         {RO_HeightFine,40},
  125.         {RO_TextNum,STR_TOOLTYPES},
  126.         {RO_TextPos,TEXTPOS_LEFT},
  127.         {RO_HighRecess,TRUE},
  128.         {TAG_END,0}},
  129.  
  130.     iconinfo_stack_gadget[]={
  131.         {RO_Type,OBJECT_GADGET},
  132.         {RO_GadgetType,GADGET_STRING},
  133.         {RO_GadgetID,II_STACK},
  134.         {RO_LeftFine,102},
  135.         {RO_TopFine,64},
  136.         {RO_WidthFine,48},
  137.         {RO_HeightFine,8},
  138.         {RO_StringLen,12},
  139.         {TAG_END,0}},
  140.  
  141.     iconinfo_comment_gadget[]={
  142.         {RO_Type,OBJECT_GADGET},
  143.         {RO_GadgetType,GADGET_STRING},
  144.         {RO_GadgetID,II_COMMENT},
  145.         {RO_LeftFine,118},
  146.         {RO_TopFine,108},
  147.         {RO_WidthFine,400},
  148.         {RO_HeightFine,8},
  149.         {RO_StringLen,80},
  150.         {RO_TextNum,STR_COMMENT},
  151.         {RO_TextPos,TEXTPOS_LEFT},
  152.         {TAG_END,0}},
  153.  
  154.     iconinfo_defaulttool_gadget[]={
  155.         {RO_Type,OBJECT_GADGET},
  156.         {RO_GadgetType,GADGET_STRING},
  157.         {RO_GadgetID,II_DEFAULTTOOL},
  158.         {RO_LeftFine,118},
  159.         {RO_TopFine,108},
  160.         {RO_WidthFine,400},
  161.         {RO_HeightFine,8},
  162.         {RO_StringLen,257},
  163.         {RO_TextNum,STR_DEFAULT_TOOL},
  164.         {RO_TextPos,TEXTPOS_LEFT},
  165.         {TAG_END,0}},
  166.  
  167.     iconinfo_protectbit_template[]={
  168.         {RO_Type,OBJECT_GADGET},
  169.         {RO_GadgetType,GADGET_CHECK},
  170.         {RO_GadgetID,0},
  171.         {RO_LeftFine,408},
  172.         {RO_TopFine,0},
  173.         {RO_TextNum,0},
  174.         {RO_TextPos,TEXTPOS_RIGHT},
  175.         {RO_BoolOn,FALSE},
  176.         {TAG_END,0}},
  177.  
  178.     *iconinfo_general_gadgets[]={
  179.         iconinfo_remap_gadget,
  180.         iconinfo_save_gadget,
  181.         iconinfo_skip_gadget,
  182.         iconinfo_cancel_gadget,
  183.         NULL},
  184.  
  185.     *iconinfo_short_general_gadgets[]={
  186.         iconinfo_remap_gadget,
  187.         NULL},
  188.  
  189.     *iconinfo_tooltype_gadgets[]={
  190.         iconinfo_edittooltype_gadget,
  191.         iconinfo_deletetooltype_gadget,
  192.         iconinfo_newtooltype_gadget,
  193.         NULL};
  194.  
  195. struct TextAttr topaz={"topaz.font",8,0,0};
  196.  
  197. struct IntuiText
  198.     save_text={1,0,JAM1,1,1,&topaz,NULL,NULL},
  199.     skip_text={1,0,JAM1,1,1,&topaz,NULL,NULL},
  200.     cancel_text={1,0,JAM1,1,1,&topaz,NULL,NULL};
  201.  
  202. struct MenuItem
  203.     save_item={
  204.         NULL,0,0,100+COMMWIDTH,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
  205.         (APTR)&save_text,NULL,'S',NULL,0xffff},
  206.     skip_item={
  207.         &save_item,0,11,100+COMMWIDTH,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
  208.         (APTR)&skip_text,NULL,'K',NULL,0xffff},
  209.     cancel_item={
  210.         &skip_item,0,22,100+COMMWIDTH,10,ITEMTEXT|ITEMENABLED|HIGHCOMP|COMMSEQ,0,
  211.         (APTR)&cancel_text,NULL,'C',NULL,0xffff};
  212.  
  213. struct Menu
  214.     icon_menu={NULL,8,0,100,0,MENUENABLED,NULL,&cancel_item};
  215.  
  216. doiconinfo(vis,name)
  217. struct VisInfo *vis;
  218. char *name;
  219. {
  220.     struct DiskObject *dobj;
  221.     struct Image *image1,*image2,*im;
  222.     struct DOpusListView *view;
  223.     char
  224.         buf[256],namebuf[256],inamebuf[33],*ptr,date[11],time[11],*olddeftool,
  225.         **ttarray,**oldtooltypes,**tttemp;
  226.     struct DOpusDateTime datetime;
  227.     ULONG class;
  228.     USHORT code;
  229.     int a,b,x,y,gadgetid,ret,gotid=0,newdef,ttcount=0,curtt=-1,compflag=0;
  230.     BPTR lock;
  231.     struct InfoData __aligned infodata;
  232.     struct FileInfoBlock __aligned fileinfo;
  233.     struct RequesterBase icon_req;
  234.     struct StringExtend stringex;
  235.     struct Window *window;
  236.     struct RastPort *rp;
  237.     struct Gadget
  238.         *icongad,
  239.         *gad,    
  240.         *tooltypegads=NULL,
  241.         *protectbitgads=NULL,
  242.         *stackgad=NULL,
  243.         *commentgad=NULL,
  244.         *defaulttoolgad=NULL;
  245.     char *stack_buf,*comment_buf,*tooltype_buf,*defaulttool_buf;
  246.     struct DOpusListView *tooltypelist;
  247.     struct IntuiMessage *msg;
  248.     struct Rectangle icon_rec;
  249.     int textxoff,textyoff,small=0;
  250.  
  251.     ttarray=NULL;
  252.     tooltypelist=NULL;
  253.  
  254.     strcpy(namebuf,name); if ((ptr=strstr(namebuf,".info"))) *ptr=0;
  255.     if (!(dobj=GetDiskObject(namebuf))) return(-2);
  256.     icongad=(struct Gadget *)&(dobj->do_Gadget);
  257.     im=image1=(struct Image *)icongad->GadgetRender;
  258.     if (icongad->Flags&GADGHIMAGE) image2=(struct Image *)icongad->SelectRender;
  259.     else image2=NULL;
  260.     oldtooltypes=dobj->do_ToolTypes;
  261.  
  262.     switch (dobj->do_Type) {
  263.         case WBDISK:
  264.             strcpy(buf,name);
  265.             doroot(buf);
  266.             doroot(namebuf);
  267.             if (!(getroot(buf,&(datetime.dat_Stamp)))) {
  268.                 FreeDiskObject(dobj);
  269.                 return(-2);
  270.             }
  271.         case WBGARBAGE: icon_req.rb_heightfine=150; break;
  272.         case WBTOOL:
  273.         case WBPROJECT:
  274.         case WBDRAWER: icon_req.rb_heightfine=196; break;
  275.         default:
  276.             FreeDiskObject(dobj);
  277.             return(-2);
  278.     }
  279.  
  280.     if (lock=Lock(namebuf,ACCESS_READ)) {
  281.         Examine(lock,&fileinfo);
  282.         Info(lock,&infodata);
  283.         UnLock(lock);
  284.  
  285.         strcpy(inamebuf,BaseName(namebuf));
  286.  
  287.         if (dobj->do_Type!=WBDISK)
  288.             CopyMem((char *)&(fileinfo.fib_Date),
  289.                 (char *)&(datetime.dat_Stamp),
  290.                 sizeof(struct DateStamp));
  291.  
  292.         datetime.dat_Format=FORMAT_DOS;
  293.         datetime.dat_StrDay=NULL;
  294.         datetime.dat_StrDate=date;
  295.         datetime.dat_StrTime=time;
  296.         datetime.dat_Flags=0;
  297.         StampToStr(&datetime);
  298.  
  299.         strcpy(buf,BaseName(name)); if (ptr=strstr(buf,".info")) *ptr=0;
  300.         gotid=1;
  301.     }
  302.     else if (dobj->do_Type==WBDISK) {
  303.         FreeDiskObject(dobj);
  304.         return(-2);
  305.     }
  306.     else {
  307.         strcpy(inamebuf,BaseName(name)); if (ptr=strstr(inamebuf,".info")) *ptr=0;
  308.         strcpy(date,"???"); time[0]=0;
  309.     }
  310.  
  311.     if (dobj->do_Type==WBPROJECT && gotid) icon_req.rb_heightfine+=14;
  312.  
  313.     iconinfo_save_gadget[4].ti_Data=icon_req.rb_heightfine-16;
  314.     iconinfo_skip_gadget[4].ti_Data=icon_req.rb_heightfine-16;
  315.     iconinfo_cancel_gadget[4].ti_Data=icon_req.rb_heightfine-16;
  316.  
  317.     icon_req.rb_width=0;
  318.     icon_req.rb_height=0;
  319.     icon_req.rb_widthfine=540;
  320.     icon_req.rb_leftoffset=4;
  321.     icon_req.rb_topoffset=0;
  322.     icon_req.rb_flags=0;
  323.  
  324.     fill_out_req(&icon_req,vis);
  325.  
  326.     icon_req.rb_privateflags=0;
  327.     icon_req.rb_screenname=NULL;
  328.  
  329.     if (icon_req.rb_screen && !(vis->vi_flags&VISF_BORDERS)) {
  330.         icon_req.rb_flags|=RBF_STRINGS;
  331.         icon_req.rb_title=NULL;
  332.     }
  333.     else {
  334.         icon_req.rb_flags|=RBF_BORDERS|RBF_CLOSEGAD|RBF_STRINGS;
  335.         icon_req.rb_title=inamebuf;
  336.     }
  337.  
  338.     icon_req.rb_extend=&stringex;
  339.     icon_req.rb_idcmpflags=
  340.         IDCMP_GADGETUP|IDCMP_GADGETDOWN|IDCMP_MOUSEBUTTONS|
  341.         IDCMP_RAWKEY|IDCMP_MOUSEMOVE|IDCMP_CLOSEWINDOW|IDCMP_MENUPICK;
  342.     icon_req.rb_string_table=string_table;
  343.  
  344.     for (a=0;a<2;a++) {
  345.         stringex.Pens[a]=vis->vi_stringcol[a];
  346.         stringex.ActivePens[a]=vis->vi_activestringcol[a];
  347.     }
  348.     stringex.InitialModes=0;
  349.     stringex.EditHook=NULL;
  350.     stringex.WorkBuffer=NULL;
  351.     for (a=0;a<4;a++) stringex.Reserved[a]=0;
  352.  
  353.     for (a=0;a<3;a++) {
  354.         if (window=OpenRequester(&icon_req)) break;
  355.         CloseRequester(&icon_req);
  356.         switch (a) {
  357.             case 0:
  358.                 icon_req.rb_flags&=~RBF_BORDERS;
  359.                 icon_req.rb_title=NULL;
  360.                 break;
  361.             case 1:
  362.                 icon_req.rb_heightfine-=17;
  363.                 small=1;
  364.                 break;
  365.             case 2:
  366.                 FreeDiskObject(dobj);
  367.                 return(0);
  368.         }
  369.     }
  370.  
  371.     if (!(addreqgadgets(&icon_req,
  372.         ((small)?iconinfo_short_general_gadgets:iconinfo_general_gadgets)))) {
  373.         CloseRequester(&icon_req);
  374.         FreeDiskObject(dobj);
  375.         return(0);
  376.     }
  377.  
  378.     textxoff=window->BorderLeft+5;
  379.     textyoff=window->BorderTop;
  380.  
  381.     icon_rec.MinX=170+textxoff;
  382.     icon_rec.MinY=16+textyoff;
  383.     icon_rec.MaxX=369+textxoff;
  384.     icon_rec.MaxY=85+textyoff;
  385.  
  386.     rp=window->RPort;
  387.     if (rp->Font->tf_YSize>8 || rp->Font->tf_Flags&FPF_PROPORTIONAL) {
  388.         struct TextFont *icon_font;
  389.  
  390.         if (icon_font=OpenFont(&topaz)) {
  391.             SetFont(rp,icon_font);
  392.             icon_req.rb_font=icon_font;
  393.             icon_req.rb_privateflags=RBP_CLOSEFONT;
  394.         }
  395.     }
  396.  
  397.     if (small) {
  398.         window->Flags&=~WFLG_RMBTRAP;
  399.         if (IntuitionBase->LibNode.lib_Version>=39) {
  400.             save_text.FrontPen=1;
  401.             skip_text.FrontPen=1;
  402.             cancel_text.FrontPen=1;
  403.         }
  404.         else {
  405.             save_text.FrontPen=0;
  406.             skip_text.FrontPen=0;
  407.             cancel_text.FrontPen=0;
  408.         }
  409.         save_text.IText=string_table[STR_SAVE];
  410.         skip_text.IText=string_table[STR_SKIP];
  411.         cancel_text.IText=string_table[STR_CANCEL];
  412.         icon_menu.MenuName=string_table[STR_ICON];
  413.         SetMenuStrip(window,&icon_menu);
  414.     }
  415.  
  416.  
  417.     if (gotid && dobj->do_Type!=WBDISK) {
  418.         struct TagItem *iconinfo_protectbit_gadgets[7];
  419.  
  420.         for (a=0;a<6;a++) {
  421.             if (iconinfo_protectbit_gadgets[a]=(struct TagItem *)
  422.                 LAllocRemember(&icon_req.rb_memory,sizeof(iconinfo_protectbit_template),MEMF_CLEAR)) {
  423.                 CopyMem((char *)iconinfo_protectbit_template,
  424.                     (char *)iconinfo_protectbit_gadgets[a],
  425.                     sizeof(iconinfo_protectbit_template));
  426.                 iconinfo_protectbit_gadgets[a][2].ti_Data=a+10;
  427.                 iconinfo_protectbit_gadgets[a][4].ti_Data=15+(a*12);
  428.                 iconinfo_protectbit_gadgets[a][5].ti_Data=STR_SCRIPT+a;
  429.                 if (fileinfo.fib_Protection&protect_flags[a]) {
  430.                     if (protect_flags[a]>15) iconinfo_protectbit_gadgets[a][7].ti_Data=TRUE;
  431.                 }
  432.                 else if (protect_flags[a]<16) iconinfo_protectbit_gadgets[a][7].ti_Data=TRUE;
  433.             }
  434.         }
  435.  
  436.         iconinfo_protectbit_gadgets[6]=NULL;
  437.         protectbitgads=addreqgadgets(&icon_req,iconinfo_protectbit_gadgets);
  438.     }
  439.  
  440.     if (dobj->do_Type==WBTOOL || dobj->do_Type==WBPROJECT) {
  441.         struct TagItem *temp_gadgets[2];
  442.  
  443.         temp_gadgets[0]=iconinfo_stack_gadget;
  444.         temp_gadgets[1]=NULL;
  445.  
  446.         if (stackgad=addreqgadgets(&icon_req,temp_gadgets)) {
  447.             stack_buf=((struct StringInfo *)stackgad->SpecialInfo)->Buffer;
  448.             if (dobj->do_StackSize<4096) dobj->do_StackSize=4096;
  449.             lsprintf(stack_buf,"%ld",dobj->do_StackSize);
  450.         }
  451.     }
  452.  
  453.     if (dobj->do_Type==WBDISK || dobj->do_Type==WBPROJECT || gotid) {
  454.         struct TagItem *temp_gadgets[2];
  455.  
  456.         temp_gadgets[1]=NULL;
  457.  
  458.         if (gotid && dobj->do_Type!=WBDISK) {
  459.             temp_gadgets[0]=iconinfo_comment_gadget;
  460.             if (commentgad=addreqgadgets(&icon_req,temp_gadgets)) {
  461.                 comment_buf=((struct StringInfo *)commentgad->SpecialInfo)->Buffer;
  462.                 strcpy(comment_buf,fileinfo.fib_Comment);
  463.             }
  464.         }
  465.         if (dobj->do_Type==WBDISK || dobj->do_Type==WBPROJECT) {
  466.             if (commentgad) {
  467.                 iconinfo_defaulttool_gadget[4].ti_Data+=14;
  468.                 iconinfo_edittooltype_gadget[4].ti_Data+=14;
  469.                 iconinfo_deletetooltype_gadget[4].ti_Data+=14;
  470.                 iconinfo_newtooltype_gadget[4].ti_Data+=14;
  471.                 iconinfo_tooltype_list[3].ti_Data+=14;
  472.             }
  473.             temp_gadgets[0]=iconinfo_defaulttool_gadget;
  474.             if (defaulttoolgad=addreqgadgets(&icon_req,temp_gadgets)) {
  475.                 defaulttool_buf=((struct StringInfo *)defaulttoolgad->SpecialInfo)->Buffer;
  476.                 if (dobj->do_DefaultTool) strcpy(defaulttool_buf,dobj->do_DefaultTool);
  477.             }
  478.         }
  479.     }
  480.     else {
  481.         if (dobj->do_Type!=WBDISK) {
  482.             UScoreText(rp,string_table[STR_COMMENT],
  483.                 117+textxoff-((strlen(string_table[STR_COMMENT])+1)*8),
  484.                 114+textyoff,-1);
  485.         }
  486.         UScoreText(rp,"---",118+textxoff,114+textyoff,-1);
  487.     }
  488.  
  489.     Do3DBox(rp,
  490.         icon_rec.MinX,icon_rec.MinY,
  491.         (icon_rec.MaxX-icon_rec.MinX+1),(icon_rec.MaxY-icon_rec.MinY+1),
  492.         vis->vi_shine,vis->vi_shadow);
  493.     drawicon(window,image1,&icon_rec);
  494.  
  495.     StrCombine(buf,inamebuf," (",256);
  496.     strcat(buf,icon_type_names[dobj->do_Type-1]);
  497.     strcat(buf,")");
  498.  
  499.     SetAPen(rp,vis->vi_fg);
  500.     UScoreText(rp,buf,((540-(strlen(buf)*8))/2)+textxoff,11+textyoff,-1);
  501.  
  502.     y=40+textyoff;
  503.     for (a=0;a<6;a++) {
  504.         ptr=specific_gadtext[dobj->do_Type-1][a];
  505.         if (ptr) {
  506.             if (a<4) x=94+textxoff;
  507.             else x=109+textxoff;
  508.             UScoreText(rp,ptr,x-(strlen(ptr)*8)-8,y,-1);
  509.             Text(rp,":",1);
  510.         }
  511.         y+=10;
  512.         if (a==3) y+=20;
  513.         else if (a>3) y+=4;
  514.     }
  515.  
  516.     UScoreText(rp,date,118+textxoff,100+textyoff,-1);
  517.     Text(rp," ",1);
  518.     Text(rp,time,strlen(time));
  519.  
  520.     switch (dobj->do_Type) {
  521.         case WBDISK:
  522.             lsprintf(buf,"%ld",infodata.id_NumBlocks);
  523.             UScoreText(rp,buf,102+textxoff,40+textyoff,-1);
  524.             lsprintf(buf,"%ld",infodata.id_NumBlocksUsed);
  525.             UScoreText(rp,buf,102+textxoff,50+textyoff,-1);
  526.             lsprintf(buf,"%ld",infodata.id_NumBlocks-infodata.id_NumBlocksUsed);
  527.             UScoreText(rp,buf,102+textxoff,60+textyoff,-1);
  528.             lsprintf(buf,"%ld",infodata.id_BytesPerBlock);
  529.             UScoreText(rp,buf,102+textxoff,70+textyoff,-1);
  530.  
  531.             switch (infodata.id_DiskState) {
  532.                 case ID_VALIDATING:
  533.                     strcpy(buf,string_table[STR_VALIDATING]);
  534.                     break;
  535.                 case ID_WRITE_PROTECTED:
  536.                     strcpy(buf,string_table[STR_WRITE_PROTECTED]);
  537.                     break;
  538.                 default:
  539.                     strcpy(buf,string_table[STR_READ_WRITE]);
  540.                     break;
  541.             }
  542.  
  543.             UScoreText(rp,buf,380+textxoff+((160-(strlen(buf)*8))/2),53+textyoff,-1);
  544.             break;
  545.  
  546.         case WBPROJECT:
  547.         case WBTOOL:
  548.             Move(rp,102+textxoff,40+textyoff);
  549.             if (gotid) {
  550.                 lsprintf(buf,"%ld",fileinfo.fib_NumBlocks);
  551.                 Text(rp,buf,strlen(buf));
  552.             }
  553.             else Text(rp,"---",3);
  554.             Move(rp,102+textxoff,50+textyoff);
  555.             if (gotid) {
  556.                 lsprintf(buf,"%ld",fileinfo.fib_Size);
  557.                 Text(rp,buf,strlen(buf));
  558.             }
  559.             else Text(rp,"---",3);
  560.  
  561.         case WBDRAWER:
  562.             if ((ttarray=oldtooltypes)) {
  563.                 for (ttcount=0;;ttcount++) if (!ttarray[ttcount]) break;
  564.                 if (ttarray=AllocMem((ttcount+1)*4,MEMF_CLEAR)) {
  565.                     for (a=0;a<ttcount;a++) {
  566.                         if (oldtooltypes[a] &&
  567.                             (ttarray[a]=AllocMem(strlen(oldtooltypes[a])+1,0)))
  568.                             strcpy(ttarray[a],oldtooltypes[a]);
  569.                     }
  570.                 }
  571.             }
  572.             else ttcount=0;
  573.             if (tooltypelist=(struct DOpusListView *)
  574.                 AddRequesterObject(&icon_req,iconinfo_tooltype_list)) {
  575.  
  576.                 fix_listview(&icon_req,tooltypelist);
  577.                 tooltypelist->items=ttarray;
  578.                 if (AddListView(tooltypelist,1)) {
  579.                     if (tooltypegads=addreqgadgets(&icon_req,iconinfo_tooltype_gadgets))
  580.                         tooltype_buf=((struct StringInfo *)tooltypegads->SpecialInfo)->Buffer;
  581.                 }
  582.                 else tooltypelist=NULL;
  583.             }
  584.             break;
  585.     }
  586.  
  587.     RefreshRequesterObject(&icon_req,NULL);
  588.     RefreshGList(window->FirstGadget,window,NULL,-1);
  589.     if (tooltypegads) offttgads(window,tooltypegads);
  590.  
  591.     FOREVER {
  592.         while (msg=(struct IntuiMessage *)GetMsg(window->UserPort)) {
  593.             if (!tooltypelist ||
  594.                 (view=ListViewIDCMP(tooltypelist,msg))==(struct DOpusListView *)-1) {
  595.  
  596.                 class=msg->Class;
  597.                 code=msg->Code;
  598.                 x=window->MouseX;
  599.                 y=window->MouseY;
  600.  
  601.                 if (class==IDCMP_GADGETUP || class==IDCMP_GADGETDOWN)
  602.                     gadgetid=((struct Gadget *)msg->IAddress)->GadgetID;
  603.                 ReplyMsg((struct Message *)msg);
  604.  
  605.                 switch (class) {
  606.                     case IDCMP_CLOSEWINDOW:
  607.                         ret=0;
  608.                         goto endreq;
  609.  
  610.                     case IDCMP_MOUSEBUTTONS:
  611.                         if (code==SELECTDOWN) {
  612.                             if (x>=icon_rec.MinX && x<=icon_rec.MaxX &&
  613.                                 y>=icon_rec.MinY && y<=icon_rec.MaxY) {
  614. hiliteimage:
  615.                                 if (icongad->Flags&GADGHIMAGE && image2) {
  616.                                     im=(im==image1)?image2:image1;
  617.                                     drawicon(window,im,&icon_rec);
  618.                                     break;
  619.                                 }
  620.                                 else {
  621.                                     compicon(rp,image1,&icon_rec);
  622.                                     compflag=1-compflag;
  623.                                 }
  624.                             }
  625.                         }
  626.                         break;
  627.  
  628.                     case IDCMP_RAWKEY:
  629.                         if (protectbitgads) {
  630.                             gad=protectbitgads;
  631.                             for (a=0;a<6;a++) {
  632.                                 if (!gad) break;
  633.                                 if (code==protect_keys[a]) {
  634.                                     gad->Flags^=SELECTED;
  635.                                     RefreshGList(gad,window,NULL,1);
  636.                                     break;
  637.                                 }
  638.                                 gad=gad->NextGadget;
  639.                             }
  640.                         }
  641.                         switch (code) {
  642.                             case 0x45:
  643.                             case 0x33:
  644.                                 ret=-1;
  645.                                 goto endreq;
  646.                             case 0x27:
  647.                                 ret=0;
  648.                                 goto endreq;
  649.                             case 0x40:
  650.                                 goto hiliteimage;
  651.                         }
  652.                         break;
  653.  
  654.                     case IDCMP_MENUPICK:
  655.                         switch (ITEMNUM(code)) {
  656.                             case 0:
  657.                                 ret=-1;
  658.                                 goto endreq;
  659.                             case 1:
  660.                                 ret=0;
  661.                                 goto endreq;
  662.                             case 2:
  663.                                 goto saveicon;
  664.                         }
  665.                         break;
  666.  
  667.                     case IDCMP_GADGETUP:
  668.                         switch (gadgetid) {
  669.                             case II_REMAP:
  670.                                 SetBusyPointer(window);
  671.                                 remapimage(image1);
  672.                                 if (image2) remapimage(image2);
  673.                                 else if (compflag) compicon(rp,image1,&icon_rec);
  674.                                 drawicon(window,im,&icon_rec);
  675.                                 if (compflag) compicon(rp,image1,&icon_rec);
  676.                                 ClearPointer(window);
  677.                                 break;
  678.  
  679.                             case II_DELETE:
  680. deletettype:
  681.                                 if (ttcount>0 && curtt>-1 && curtt<ttcount && tooltypelist) {
  682.                                     if (ttarray) {
  683.                                         if (ttcount>1 && !(tttemp=AllocMem(ttcount*4,MEMF_CLEAR)))
  684.                                             break;
  685.                                         if (ttarray[curtt]) FreeMem(ttarray[curtt],strlen(ttarray[curtt])+1);
  686.                                         if (ttcount==1) {
  687.                                             FreeMem(ttarray,8);
  688.                                             ttarray=NULL;
  689.                                             goto deletedtype;
  690.                                         }
  691.                                         if (curtt>0) CopyMem((char *)ttarray,(char *)tttemp,curtt*4);
  692.                                         if (curtt<(ttcount-1))
  693.                                             CopyMem((char *)&ttarray[curtt+1],(char *)&tttemp[curtt],
  694.                                                 (ttcount-1-curtt)*4);
  695.                                         FreeMem(ttarray,(ttcount+1)*4); ttarray=tttemp;
  696.                                     }
  697. deletedtype:
  698.                                     tooltypelist->items=ttarray;
  699.                                     --ttcount;
  700.                                     curtt=-1;
  701.                                     RefreshListView(tooltypelist,1);
  702.                                     tooltype_buf[0]=0;
  703.                                     RefreshGList(tooltypegads,window,NULL,1);
  704.                                     offttgads(window,tooltypegads);
  705.                                 }
  706.                                 break;
  707.                             case II_NEW:
  708.                                 if (!(tooltypegads->Flags&GADGDISABLED)) {
  709.                                     tooltype_buf[0]=0;
  710.                                     RefreshStrGad(tooltypegads,window);
  711.                                 }
  712.                                 else if (tooltypelist) {
  713.                                     if (!(tttemp=AllocMem((ttcount+2)*4,MEMF_CLEAR))) break;
  714.                                     if (ttarray) {
  715.                                         CopyMem((char *)ttarray,(char *)tttemp,ttcount*4);
  716.                                         FreeMem(ttarray,(ttcount+1)*4);
  717.                                     }
  718.                                     ttarray=tttemp;
  719.                                     curtt=ttcount++;
  720.                                     ttarray[curtt]=AllocMem(1,MEMF_CLEAR);
  721.                                     tooltypelist->items=ttarray;
  722.                                     RefreshListView(tooltypelist,1);
  723.                                     onttgads(window,tooltypegads);
  724.                                     tooltype_buf[0]=0;
  725.                                 }
  726.                                 ActivateStrGad(tooltypegads,window);
  727.                                 break;
  728.  
  729.                             case II_TOOLTYPE:
  730.                                 if (!tooltype_buf[0]) goto deletettype;
  731.                                 if (curtt<ttcount && ttarray) {
  732.                                     if (ttarray[curtt]) FreeMem(ttarray[curtt],strlen(ttarray[curtt])+1);
  733.                                     if ((ttarray[curtt]=AllocMem(strlen(tooltype_buf)+1,0)))
  734.                                         strcpy(ttarray[curtt],tooltype_buf);
  735.                                 }
  736.                                 curtt=-1;
  737.                                 tooltype_buf[0]=0;
  738.                                 RefreshGList(tooltypegads,window,NULL,1);
  739.                                 offttgads(window,tooltypegads);
  740.                                 if (tooltypelist) RefreshListView(tooltypelist,1);
  741.                                 break;
  742.  
  743.                             case II_SAVE:
  744. saveicon:
  745.                                 strcpy(namebuf,name);
  746.                                 if ((ptr=strstr(namebuf,".info"))) *ptr=0;
  747.  
  748.                                 if ((dobj->do_Type==WBTOOL || dobj->do_Type==WBPROJECT) &&
  749.                                     stackgad) {
  750.                                     dobj->do_StackSize=atoi(stack_buf);
  751.                                     if (dobj->do_StackSize<4096) dobj->do_StackSize=4096;
  752.                                 }
  753.  
  754.                                 if (defaulttoolgad) {
  755.                                     olddeftool=dobj->do_DefaultTool;
  756.                                     if (dobj->do_DefaultTool=
  757.                                         LAllocRemember(&icon_req.rb_memory,strlen(defaulttool_buf)+1,0)) {
  758.                                         newdef=1;
  759.                                         strcpy(dobj->do_DefaultTool,defaulttool_buf);
  760.                                     }
  761.                                     else newdef=0;
  762.                                 }
  763.                                 if (commentgad) {
  764.                                     comment_buf[79]=0;
  765.                                     SetComment(namebuf,comment_buf);
  766.                                 }
  767.  
  768.                                 dobj->do_ToolTypes=ttarray;
  769.                                 PutDiskObject(namebuf,dobj);
  770.  
  771.                                 if (defaulttoolgad) dobj->do_DefaultTool=olddeftool;
  772.  
  773.                                 dobj->do_ToolTypes=oldtooltypes;
  774.                                 if (protectbitgads) {
  775.                                     b=15;
  776.                                     gad=protectbitgads;
  777.                                     for (a=0;a<6;a++) {
  778.                                         if (!gad) break;
  779.                                         if (gad->Flags&SELECTED) {
  780.                                             if (protect_flags[a]<16) b&=~protect_flags[a];
  781.                                             else b|=protect_flags[a];
  782.                                         }
  783.                                         gad=gad->NextGadget;
  784.                                     }
  785.                                     SetProtection(namebuf,b);
  786.                                 }
  787.                                 ret=1;
  788.                                 goto endreq;
  789.  
  790.                             case II_SKIP:
  791.                                 ret=0;
  792.                                 goto endreq;
  793.  
  794.                             case II_CANCEL:
  795.                                 ret=-1;
  796.                                 goto endreq;
  797.                         }
  798.                         break;
  799.                 }
  800.             }
  801.             else if (view && view->listid==0) {
  802.                 a=view->itemselected;
  803.                 curtt=-1;
  804.                 if (a<ttcount && ttarray && ttarray[a] && tooltypegads) {
  805.                     curtt=a;
  806.                     strcpy(tooltype_buf,ttarray[a]);
  807.                     onttgads(window,tooltypegads);
  808.                     ActivateStrGad(tooltypegads,window);
  809.                 }
  810.             }
  811.         }
  812.         Wait(1<<window->UserPort->mp_SigBit);
  813.     }
  814. endreq:
  815.     if (ttarray) {
  816.         for (a=0;a<ttcount;a++) {
  817.             if (ttarray[a]) FreeMem(ttarray[a],strlen(ttarray[a])+1);
  818.         }
  819.         FreeMem(ttarray,(ttcount+1)*4);
  820.     }
  821.     if (tooltypelist) RemoveListView(tooltypelist,1);
  822.     if (small) ClearMenuStrip(window);
  823.     CloseRequester(&icon_req);
  824.     FreeDiskObject(dobj);
  825.     return(ret);
  826. }
  827.  
  828. void drawicon(window,image,rect)
  829. struct Window *window;
  830. struct Image *image;
  831. struct Rectangle *rect;
  832. {
  833.     struct Region *reg,*oldreg;
  834.     int x,y;
  835.  
  836.     x=((rect->MaxX-rect->MinX+1)-image->Width)/2;
  837.     y=((rect->MaxY-rect->MinY+1)-image->Height)/2;
  838.  
  839.     if (image->NextImage) image->NextImage=NULL;
  840.  
  841.     if (x>0 && y>0) {
  842.         drawrecaround(window->RPort,
  843.             rect->MinX,rect->MinY,
  844.             x,y,
  845.             x+image->Width,y+image->Height,
  846.             (rect->MaxX-rect->MinX+1),(rect->MaxY-rect->MinY+1));
  847.         DrawImage(window->RPort,image,x+rect->MinX,y+rect->MinY);
  848.     }
  849.     else if (reg=NewRegion()) {
  850.         OrRectRegion(reg,rect);
  851.         oldreg=InstallClipRegion(window->WLayer,reg);
  852.         DrawImage(window->RPort,image,(x<0)?rect->MinX:rect->MinX+x,(y<0)?rect->MinY:rect->MinY+y);
  853.         InstallClipRegion(window->WLayer,oldreg);
  854.         DisposeRegion(reg);
  855.     }
  856. }
  857.  
  858. void drawrecaround(r,l,t,x,y,x1,y1,width,height)
  859. struct RastPort *r;
  860. int l,t,x,y,x1,y1,width,height;
  861. {
  862.     char o;
  863.  
  864.     o=r->FgPen; SetAPen(r,0);
  865.     if (x>0) RectFill(r,l,t,l+x-1,t+height-1);
  866.     if (y>0) RectFill(r,l,t,l+width-1,t+y-1);
  867.     if (x1<l+width) RectFill(r,l+x1,t,l+width-1,t+height-1);
  868.     if (y1<t+height) RectFill(r,l,t+y1,l+width-1,t+height-1);
  869.     SetAPen(r,o);
  870. }
  871.  
  872. void compicon(rp,image,rect)
  873. struct RastPort *rp;
  874. struct Image *image;
  875. struct Rectangle *rect;
  876. {
  877.     int x,y,w,h;
  878.  
  879.     w=(rect->MaxX-rect->MinX+1);
  880.     h=(rect->MaxY-rect->MinY+1);
  881.     x=(w-image->Width)/2;
  882.     y=(h-image->Height)/2;
  883.  
  884.     SetDrMd(rp,COMPLEMENT);
  885.     RectFill(rp,
  886.         (x<0)?rect->MinX:rect->MinX+x,
  887.         (y<0)?rect->MinY:rect->MinY+y,
  888.         (x<0)?rect->MaxX:(rect->MaxX-w)+x+image->Width,
  889.         (y<0)?rect->MaxY:(rect->MaxY-h)+y+image->Height);
  890.     SetDrMd(rp,JAM2);
  891. }
  892.  
  893. void remapimage(icon)
  894. struct Image *icon;
  895. {
  896.     int wordwidth,row,col,plane,planesize,rowpos,pen,bit;
  897.     USHORT *plane_ptr[8];
  898.  
  899.     wordwidth=(icon->Width+15)/16;
  900.     planesize=wordwidth*icon->Height;
  901.  
  902.     for (plane=0;plane<icon->Depth;plane++)
  903.         plane_ptr[plane]=icon->ImageData+(planesize*plane);
  904.  
  905.     for (row=0,rowpos=0;row<icon->Height;row++,rowpos+=wordwidth) {
  906.         for (col=0;col<wordwidth;col++) {
  907.             for (bit=0;bit<16;bit++) {
  908.                 pen=0;
  909.                 for (plane=0;plane<icon->Depth;plane++) {
  910.                     if (plane_ptr[plane][rowpos+col]&(1<<bit)) pen|=1<<plane;
  911.                 }
  912.                 if (pen==1 || pen==2) {
  913.                     pen=1-(pen-1);
  914.                     for (plane=0;plane<icon->Depth;plane++) {
  915.                         if (plane==pen) plane_ptr[plane][rowpos+col]|=1<<bit;
  916.                         else plane_ptr[plane][rowpos+col]&=~(1<<bit);
  917.                     }
  918.                 }
  919.             }
  920.         }
  921.     }
  922. }
  923.  
  924. void offttgads(window,gads)
  925. struct Window *window;
  926. struct Gadget *gads;
  927. {
  928.     int a;
  929.  
  930.     for (a=0;a<2;a++) {
  931.         DisableGadget(gads,window->RPort,2,1);
  932.         gads=gads->NextGadget;
  933.     }
  934. }
  935.  
  936. void onttgads(window,gads)
  937. struct Window *window;
  938. struct Gadget *gads;
  939. {
  940.     int a;
  941.  
  942.     for (a=0;a<2;a++) {
  943.         EnableGadget(gads,window->RPort,2,1);
  944.         gads=gads->NextGadget;
  945.     }
  946. }
  947.  
  948. doroot(str)
  949. char *str;
  950. {
  951.     int i,b,f=0,c;
  952.  
  953.     c=strlen(str);
  954.     if (c==0) return(0);
  955.     i=c;
  956.     for (b=0;b<i;b++) if (str[b]==':') { ++b; f=1; break; }
  957.     if (f==1 && b==i) return(0);
  958.     else if (f>0) str[b]=0;
  959.     return(1);
  960. }
  961.  
  962. getroot(name,ds)
  963. char *name;
  964. struct DateStamp *ds;
  965. {
  966.     BPTR lock1;
  967.     struct FileLock *lock2;
  968.     char *p;
  969.     struct DeviceList *dl;
  970.     int a;
  971.  
  972.     if (!(lock1=Lock(name,ACCESS_READ))) return(0);
  973.     lock2=(struct FileLock *) BADDR(lock1);
  974.     for (a=0;a<32;a++) name[a]=0;
  975.     dl=(struct DeviceList *)BADDR(lock2->fl_Volume);
  976.     p=(char *) BADDR(dl->dl_Name);
  977.     if (p) LStrnCpy(name,p+1,*p);
  978.     if (ds) CopyMem((char *)&dl->dl_VolumeDate,(char *)ds,sizeof(struct DateStamp));
  979.     UnLock(lock1);
  980.     return(1);
  981. }
  982.