chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Steel / c / fileicon
1 /*
2  * fileicon
3  *
4  * creates a file icon in a window, plonk over another one.
5  *
6  * © 1993-1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's Steel library.
12  *
13  * Steel is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * Steel is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Steel.  If not, write to the Free Software Foundation,
25  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #include "fileicon.h"
29 #include "wimp.h"
30 #include "wimpt.h"
31 #include "werr.h"
32 #include "msgs.h"
33 #include "buffer.h"
34 #include <stdio.h>
35 #include <string.h>
36
37 static BOOL fileicon__spriteExist(char *name)
38 {
39   BOOL there;
40   if (wimp_spriteop(40,name))
41     there=FALSE;
42   else
43     there=TRUE;
44   return (there);
45 }
46
47 char *fileicon_spriteName(int filetype,char *name)
48 {
49   char *spritename=buffer_find();
50   char *leaf=name;
51   char *p;
52   for (p=name;*p!=0;p++)
53   {
54     if (*p=='.')
55       leaf=p+1;
56   }
57   switch (filetype)
58   {
59     case 0x3000:
60       strcpy(spritename,"file_xxx");
61       break;
62     case 0x2000:
63       if (fileicon__spriteExist(leaf))
64         strcpy(spritename,leaf);
65       else
66         strcpy(spritename,"application");
67       break;
68     case 0x1000:
69       strcpy(spritename,"directory");
70       break;
71     default:
72       sprintf(spritename,"file_%.3x",filetype);
73       if (!fileicon__spriteExist(spritename))
74         strcpy(spritename,"file_xxx");
75       break;
76   }
77   return (spritename);
78 }
79
80 void fileicon(wimp_w w,wimp_i i,int filetype,char *name)
81 {
82   wimp_icreate icn;
83   wimp_i ih;
84   wimpt_noerr(wimp_get_icon_info(w,i,&(icn.i)));
85   wimpt_noerr(wimp_delete_icon(w,i));
86   if ((icn.i.flags & wimp_INDIRECT)==0)
87     werr(TRUE,msgs_lookup("ficnNII:(fileicon, caller fault): "
88                                              "Icon must be indirected."));
89   icn.i.flags=
90   (
91     wimp_ISPRITE |
92     wimp_IHCENTRE |
93     wimp_IVCENTRE |
94     wimp_IFILLED |
95     wimp_INDIRECT |
96     wimp_IBTYPE * wimp_BDEBOUNCEDRAG |
97     wimp_IFORECOL * 7 |
98     wimp_IBACKCOL * 1
99   );
100   strcpy(icn.i.data.indirectsprite.name,fileicon_spriteName(filetype,name));
101   icn.i.data.indirectsprite.spritearea=(void *)1;
102   icn.i.data.indirectsprite.nameisname=TRUE;
103   icn.w=w;
104   wimpt_noerr(wimp_create_icon(&icn,&ih));
105   wimpt_noerr(wimp_set_icon_state(w,ih,0,0));
106   if (ih!=i)
107     werr(TRUE,msgs_lookup("ficnIHD:(fileicon): Icon handle has changed."));
108 }