home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / fm2000 / showicon.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-04  |  10.1 KB  |  409 lines

  1. /*
  2.      Filemaster - Multitasking directory utility.
  3.      Copyright (C) 2000  Toni Wilen
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <dos/dos.h>
  23. #include <workbench/workbench.h>
  24. #include <libraries/diskfont.h>
  25. #include <proto/all.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include "fmnode.h"
  29. #include "child.h"
  30. #include "fmdos.h"
  31. #include "ilbm.h"
  32. #include "fmlocale.h"
  33. #include "fmgui.h"
  34.  
  35. ULONG power2(WORD);
  36. WORD openicon(struct FMList*);
  37. WORD opendisk(struct FMList*);
  38. WORD showiconfont(struct FMHandle*,WORD,struct CMenuConfig *cmc);
  39. WORD selectfont(struct FMHandle*,struct FontContentsHeader*,struct TextAttr*);
  40.  
  41. extern struct Library *IconBase;
  42. extern struct Library *DiskfontBase;
  43. extern struct FMMain fmmain;
  44. extern UBYTE icolib[];
  45. extern UBYTE dflib[];
  46. extern UBYTE workbench[];
  47.  
  48. WORD showicon(struct FMHandle *h,struct CMenuConfig *cmc)
  49. {
  50. return(showiconfont(h,0,cmc));
  51. }
  52. WORD showfont(struct FMHandle *h,struct CMenuConfig *cmc)
  53. {
  54. return(showiconfont(h,1,cmc));
  55. }
  56.  
  57. WORD showiconfont(struct FMHandle *h,WORD type,struct CMenuConfig *cmc)
  58. {
  59. WORD ret,quitti,ignorebutton,started;
  60. WORD x,y,width,height,pagew,pageh,depth,retry=0,apu1,apu2,apu3,txtcolor;
  61. ULONG modeid=INVALID_ID;
  62. UWORD mask,code,numcols;
  63. ULONG class;
  64. ULONG *coltable=0;
  65. #ifndef V39
  66. UBYTE *coltable2=0;
  67. #endif
  68. struct Image *i1;
  69. struct Image *i2;
  70. struct Gadget *igadg;
  71. struct DiskObject *dob=0;
  72. struct DrawInfo *di;
  73. struct Screen *scr=0;
  74. struct Window *win=0;
  75. struct RastPort *rp;
  76. struct VisualInfo *vi;
  77. struct FMList *list;
  78. UBYTE name[PATH];
  79. UBYTE name2[PATH];
  80. UBYTE text[100];
  81. WORD penlist[2];
  82. UBYTE chars[256];
  83.  
  84. struct TextFont *tfont=0;
  85. struct ColorTextFont *ctfont=0;
  86. struct TextAttr tattr;
  87. struct FontContentsHeader *fch=0;
  88. UWORD *cfptr;
  89. WORD depthset=0;
  90.  
  91. list=h->owner;
  92. penlist[0]=-1;penlist[1]=-1;
  93. ret=0;
  94. changename(list,cmc->label);
  95. if(type) {
  96.     sformat(list->fmmessage1,getstring(MSG_FILECLICK_FONT),h->filename);
  97.     fmmessage(list);
  98.     if(!opendisk(list)) goto sierr;
  99.     if(!(fch=allocvec(list,h->size,0))) goto sierr;
  100.     if(readbufferfile(h,fch,h->size)==0) goto sierr;
  101. } else {
  102.     sformat(list->fmmessage1,getstring(MSG_FILECLICK_WBICON),h->filename);
  103.     fmmessage(list);
  104.     if(!openicon(list)) goto sierr;
  105.     strcpy(name,h->filename);
  106.     name[strlen(name)-5]=0;
  107.     if (!(dob=GetDiskObject(name))) {
  108.         dosrequestmsg(h->owner,0,MSG_FMDOS_OPENERR,h->filename);
  109.         goto sierr;
  110.     }
  111.     igadg=&dob->do_Gadget;
  112. }
  113.  
  114.  
  115. txtcolor=1;
  116. if(scr=LockPubScreen(workbench)) {
  117.     di=GetScreenDrawInfo(scr);
  118.     if(di) {
  119.         txtcolor=di->dri_Pens[TEXTPEN];
  120.         FreeScreenDrawInfo(scr,di);
  121.     }
  122.     depth=scr->RastPort.BitMap->Depth;
  123.     modeid=GetVPModeID(&scr->ViewPort);
  124.     numcols=power2(depth);
  125.     if(scr->ViewPort.ColorMap) {
  126.         coltable=allocvec(h->owner,numcols*4*3+8,MEMF_CLEAR);
  127.         if(coltable) {
  128. #ifdef V39
  129.             GetRGB32(scr->ViewPort.ColorMap,0,numcols,coltable+1);
  130. #else
  131.             coltable2=(UBYTE*)coltable;
  132.             for(apu1=0;apu1<numcols;apu1++) {
  133.                 apu2=GetRGB4(scr->ViewPort.ColorMap,apu1);
  134.                 *coltable2++=(apu2>>8)&0x0f;
  135.                 *coltable2++=(apu2>>4)&0x0f;
  136.                 *coltable2++=(apu2)&0x0f;
  137.             }
  138. #endif
  139.         }
  140.     }
  141.     UnlockPubScreen(0,scr);
  142. }
  143. if(modeid==INVALID_ID) modeid=0x8000;
  144.  
  145. newicon:
  146.  
  147. if(type==0) {
  148.     sformat(text,getstring(MSG_SHOWICON_TITLE),h->filename,depth,(WORD)power2(depth));
  149. } else {
  150.     text[0]=0;
  151.     if(!depthset) {
  152.         if(!selectfont(h,fch,&tattr)) {
  153.             ret=1;
  154.             quitti=1;
  155.             retry=0;
  156.             goto sierr;
  157.         }
  158.     }
  159.     strcpy(name2,list->path);
  160.     AddPart(name2,h->filename,PATH);
  161.     tattr.ta_Name=name2;
  162.     if(!(tfont=OpenDiskFont(&tattr))) {
  163.         requestmsg(list->workname,0,MSG_OK,MSG_FMDOS_OPENERR,tattr.ta_Name);
  164.         goto sierr;
  165.     }
  166.     if(tattr.ta_Style&FSF_COLORFONT)
  167.         ctfont=(struct ColorTextFont*)tfont;
  168.         else
  169.         ctfont=0;
  170.     if(ctfont&&!retry) depth=ctfont->ctf_Depth;
  171. }
  172.  
  173. vi=0;ret=0;retry=0;depthset=0;
  174. ignorebutton=0;started=1;quitti=0;
  175.  
  176. scr=OpenScreenTags(0,
  177.         SA_Title,text,
  178.         SA_Width,STDSCREENWIDTH,SA_Height,STDSCREENHEIGHT,
  179.         SA_DisplayID,modeid,SA_Depth,depth,
  180.         SA_Pens,penlist,SA_Interleaved,1,
  181.         TAG_DONE);
  182. if(!scr) {
  183.     requestmsg(list->workname,0,MSG_OK,MSG_MAIN_SCRERR1);
  184.     goto sierr;
  185. }
  186. if(ctfont) {
  187.     for(apu1=0;apu1<ctfont->ctf_ColorFontColors->cfc_Count;apu1++) {
  188.         cfptr=ctfont->ctf_ColorFontColors->cfc_ColorTable+apu1;
  189.         SetRGB4(&scr->ViewPort,apu1+ctfont->ctf_Low,((*cfptr)>>8)&0x0f,((*cfptr)>>4)&0x0f,((*cfptr))&0x0f);
  190.     }
  191. } else {
  192.     if(coltable) { 
  193.         apu1=power2(depth)-numcols;
  194. #ifdef V39
  195.         if(apu1>0) {
  196.             *coltable=(ULONG)numcols<<16|apu1;
  197.             LoadRGB32(&scr->ViewPort,coltable);
  198.         }
  199.         *coltable=(ULONG)numcols<<16;
  200.         LoadRGB32(&scr->ViewPort,coltable);
  201. #else
  202.         if(apu1>0) {
  203.             coltable2=(UBYTE*)coltable;
  204.             for(apu2=0;apu2<numcols;apu2++) SetRGB4(&scr->ViewPort,apu2+apu1,*coltable2++,*coltable2++,*coltable2++);
  205.         }
  206.         coltable2=(UBYTE*)coltable;
  207.         for(apu2=0;apu2<numcols;apu2++) SetRGB4(&scr->ViewPort,numcols,*coltable2++,*coltable2++,*coltable2++);
  208. #endif
  209.     }
  210. }
  211.  
  212. pagew=scr->Width; pageh=scr->Height;
  213. apu1=scr->WBorTop+scr->Font->ta_YSize+1;
  214. win=OpenWindowTags(0,
  215.         WA_Top,apu1,WA_Height,scr->Height-apu1,
  216.         WA_IDCMP,IDCMP_MOUSEBUTTONS|IDCMP_VANILLAKEY|IDCMP_ACTIVEWINDOW,
  217.         WA_Flags,WFLG_NOCAREREFRESH|WFLG_RMBTRAP|WFLG_ACTIVATE,
  218.         WA_CustomScreen,scr,
  219.         TAG_DONE);
  220. if(!win) {
  221.     requestmsg(list->workname,0,MSG_OK,MSG_MAIN_WINERR1);
  222.     goto sierr;
  223. }
  224. rp=win->RPort;
  225.  
  226. if(type) {
  227.     SetDrMd(rp,JAM1);
  228.     SetBPen(rp,0);
  229.     sformat(text,getstring(MSG_SHOWFONT_TITLE),h->filename,tattr.ta_YSize,depth,power2(depth));
  230.     SetWindowTitles(win,0,text);
  231.     for(apu1=0;apu1<256;apu1++) chars[apu1]=apu1;
  232.     SetAPen(rp,0);
  233.     RectFill(rp,win->BorderLeft,win->BorderTop,pagew-win->BorderRight,pageh-win->BorderBottom);
  234.     SetFont(rp,tfont);
  235.     SetAPen(rp,txtcolor);    
  236.     apu1=tfont->tf_Baseline+4;
  237.     apu2=4+tfont->tf_YSize;
  238.     for(apu3=32;apu3<256;apu3+=32) {
  239.         Move(rp,24,apu1);
  240.         Text(rp,&chars[apu3],32);
  241.         apu1+=apu2;
  242.     }
  243.     CloseFont(tfont);
  244.     retry=1;
  245. } else {
  246.     vi=GetVisualInfo(scr,0);
  247.     i1=(struct Image*)igadg->GadgetRender;
  248.     i2=(struct Image*)igadg->SelectRender;
  249.     sformatmsg(list->fmmessage2,MSG_SHOWPIC_INFO2,i1->Width,i1->Height,i1->Depth,power2(i1->Depth)," "," "," ");
  250.     fmmessage(list);
  251.     if((igadg->Flags&GADGHIGHBITS)==GADGHIMAGE) {
  252.         width=i2->Width; height=i2->Height;
  253.         x=(pagew-i1->Width-width)/2-32;
  254.         y=i1->Height>height?i1->Height:height;
  255.         y=(pageh-y)/2;
  256.         DrawImage(rp,i1,x,y);
  257.         DrawImage(rp,i2,x+i1->Width+32,y);
  258.     } else {
  259.         width=i1->Width; height=i1->Height;
  260.         x=(pagew-i1->Width*2)/2-32;
  261.         y=(pageh-i1->Height)/2;
  262.         DrawImage(rp,i1,x,y);
  263.         DrawImage(rp,i1,x+i1->Width+32,y);
  264.         if((igadg->Flags&GADGHIGHBITS)==GADGHCOMP) {
  265.             SetDrMd(rp,COMPLEMENT);
  266.             mask=power2(i1->Depth);
  267.             rp->Mask=mask-1;
  268.             RectFill(rp,x+i1->Width+32,y,width+x+i1->Width+32,height+y);
  269.         }
  270.     }
  271.     if (vi) {
  272.         DrawBevelBox(rp,x-6,y-3,i1->Width+12,i1->Height+6,GT_VisualInfo,vi);
  273.         DrawBevelBox(rp,x+i1->Width+32-6,y-3,width+12,height+6,GTBB_Recessed,1,GT_VisualInfo,vi);
  274.     }
  275. }
  276.  
  277. ret=1;
  278. while(!quitti) {
  279.     if(smallevent(win,&class,&code)) {
  280.         quitti=1;
  281.         continue;
  282.     }
  283.     if(ignorebutton) ignorebutton--;
  284.     switch(class)
  285.     {
  286.     case IDCMP_ACTIVEWINDOW:
  287.     if(!started) ignorebutton=2; else started=0;
  288.     break;
  289.     case IDCMP_MOUSEBUTTONS:
  290.     if(type) ignorebutton=0;
  291.     if(code==SELECTDOWN&&!ignorebutton) quitti=1;
  292.     if(code==MENUDOWN&&!ignorebutton) { quitti=1; ret=0; }
  293.     break;
  294.     case IDCMP_VANILLAKEY:
  295.     if(code==13||code==27) quitti=1;
  296.     if(code>='1'&&code<='8') {
  297.         depth=code-'0';
  298.         retry=1;
  299.         depthset=1;
  300.         quitti=1;
  301.     }
  302.     }
  303. }
  304. sierr:
  305. if(win) CloseWindow(win);
  306. if(scr) CloseScreen(scr);
  307. freemem(coltable);
  308. if(type==0) FreeVisualInfo(vi);
  309. win=0; scr=0; tfont=0; coltable=0; vi=0;
  310. if(retry&&!type) goto newicon;
  311. if(retry&&type) goto newicon;
  312. if(dob) FreeDiskObject(dob);
  313. freemem(fch);
  314. return(ret);
  315. }
  316.  
  317. WORD openicon(struct FMList *list)
  318. {
  319. if (!IconBase) IconBase=OpenLibrary(icolib,37);
  320. if (!IconBase) {
  321.     requestmsg(list->workname,0,MSG_OK,MSG_FMDOS_OPENERR,icolib);
  322.     return(0);
  323. }
  324. return(1);
  325. }
  326. WORD opendisk(struct FMList *list)
  327. {
  328. if (!DiskfontBase) DiskfontBase=OpenLibrary(dflib,37);
  329. if (!DiskfontBase) {
  330.     requestmsg(list->workname,0,MSG_OK,MSG_FMDOS_OPENERR,dflib);
  331.     return(0);
  332. }
  333. return(1);
  334. }
  335.  
  336. WORD selectfont(struct FMHandle *h,struct FontContentsHeader *fch,struct TextAttr *ta)
  337. {
  338. struct GUIBase *gb;
  339. struct FMList *list;
  340. struct FontContents *fc1,*fc2,*fc3;
  341. struct FontContents *fc4[10];
  342. UWORD numsizes;
  343. WORD c=0;
  344. WORD apu1,apu2,apu4;
  345. UWORD apu3;
  346. UBYTE *ptr2=0;
  347. UBYTE *ptr1;
  348. WORD ret=0;
  349. LONG issize;
  350. UBYTE used[10];
  351. UBYTE *useptr;
  352.  
  353. memseti(used,0,10);
  354. gb=getguibase(h->filename);
  355. list=h->owner;
  356. switch(fch->fch_FileID)
  357.     {
  358.     case OFCH_ID:
  359.     issize=20;
  360.     setconnectgroup(gb,1,0,0);
  361.     reqinfomsg(gb,MSG_SHOWFONT_ASKSIZE,100,guiUC|guiLEFT);
  362.     reqinteger(gb,100,&issize,1,999);
  363.     buttonbarmsg(gb,MSG_OK,1,MSG_CANCEL,0,0);
  364.     c=quickreq(gb);
  365.     if(!c) goto ferr;
  366.     ta->ta_YSize=issize;
  367.     ta->ta_Style=0;
  368.     ta->ta_Flags=0;
  369.     ret=1;
  370.     goto ferr;
  371.     case FCH_ID:
  372.     numsizes=fch->fch_NumEntries;
  373.     if(!(ptr2=allocvec(list,numsizes*(MAXFONTPATH+10),MEMF_CLEAR))) goto ferr;
  374.     ptr1=ptr2; apu4=0;
  375.     for(apu1=0;apu1<numsizes;apu1++) {
  376.         apu3=65535;
  377.         for(apu2=0;apu2<numsizes;apu2++) {
  378.             fc2=(struct FontContents*)((UBYTE*)fch+4+apu2*sizeof(struct FontContents));
  379.             if(used[apu2]==0&&fc2->fc_YSize<apu3) {
  380.                 apu3=fc2->fc_YSize;
  381.                 fc3=fc2;
  382.                 useptr=&used[apu2];
  383.             }
  384.         }
  385.         if(*useptr==0&&apu4<10) {
  386.             sformat(ptr1,"'%s' %3ld",fc3->fc_FileName,fc3->fc_YSize);
  387.             reqbutton(gb,ptr1,apu1+10,guiUC|guiLEFT);
  388.             ptr1+=strlen(ptr1)+1;
  389.             *useptr=1;
  390.             fc4[apu4]=fc3;
  391.             apu4++;
  392.         }
  393.     }
  394.     buttonbarmsg(gb,MSG_OK,1,0);
  395.     c=quickreq(gb);
  396.     if(c>=10&&c<=19) {
  397.         fc1=fc4[c-10];
  398.         ta->ta_YSize=fc1->fc_YSize;
  399.         ta->ta_Style=fc1->fc_Style;
  400.         ta->ta_Flags=fc1->fc_Flags;
  401.         ret=1;
  402.     }
  403. }
  404. ferr:
  405. freemem(ptr2);
  406. return(ret);
  407. }
  408.  
  409.