/* * fileicon * * creates a file icon in a window, plonk over another one. * * © 1993-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Steel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "fileicon.h" #include "wimp.h" #include "wimpt.h" #include "werr.h" #include "msgs.h" #include "buffer.h" #include #include static BOOL fileicon__spriteExist(char *name) { BOOL there; if (wimp_spriteop(40,name)) there=FALSE; else there=TRUE; return (there); } char *fileicon_spriteName(int filetype,char *name) { char *spritename=buffer_find(); char *leaf=name; char *p; for (p=name;*p!=0;p++) { if (*p=='.') leaf=p+1; } switch (filetype) { case 0x3000: strcpy(spritename,"file_xxx"); break; case 0x2000: if (fileicon__spriteExist(leaf)) strcpy(spritename,leaf); else strcpy(spritename,"application"); break; case 0x1000: strcpy(spritename,"directory"); break; default: sprintf(spritename,"file_%.3x",filetype); if (!fileicon__spriteExist(spritename)) strcpy(spritename,"file_xxx"); break; } return (spritename); } void fileicon(wimp_w w,wimp_i i,int filetype,char *name) { wimp_icreate icn; wimp_i ih; wimpt_noerr(wimp_get_icon_info(w,i,&(icn.i))); wimpt_noerr(wimp_delete_icon(w,i)); if ((icn.i.flags & wimp_INDIRECT)==0) werr(TRUE,msgs_lookup("ficnNII:(fileicon, caller fault): " "Icon must be indirected.")); icn.i.flags= ( wimp_ISPRITE | wimp_IHCENTRE | wimp_IVCENTRE | wimp_IFILLED | wimp_INDIRECT | wimp_IBTYPE * wimp_BDEBOUNCEDRAG | wimp_IFORECOL * 7 | wimp_IBACKCOL * 1 ); strcpy(icn.i.data.indirectsprite.name,fileicon_spriteName(filetype,name)); icn.i.data.indirectsprite.spritearea=(void *)1; icn.i.data.indirectsprite.nameisname=TRUE; icn.w=w; wimpt_noerr(wimp_create_icon(&icn,&ih)); wimpt_noerr(wimp_set_icon_state(w,ih,0,0)); if (ih!=i) werr(TRUE,msgs_lookup("ficnIHD:(fileicon): Icon handle has changed.")); }