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