Initial revision
[ssr] / StraySrc / Glass / !Glass / c / iconData
1 /*
2 * iconData.c
3 *
4 * Central handling for icon data
5 *
6 * © 1994-1998 Straylight
7 */
8
9 /*----- Licensing note ----------------------------------------------------*
10 *
11 * This file is part of Straylight's Glass.
12 *
13 * Glass 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 * Glass 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 Glass. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 /*
31 * ANSI standard headers
32 */
33
34 #include <string.h>
35
36 /*
37 * Steel headers
38 */
39
40 #define _STDAPP
41 #define _LOWLVL
42 #include "steel/Steel.h"
43
44 /*
45 * Glass headers
46 */
47
48 #include "gStruct.h"
49
50 #include "glass.h"
51 #include "iconData.h"
52 #include "indir.h"
53
54 /*----- External routines -------------------------------------------------*/
55
56 /*
57 * BOOL iconData_processIcon
58 * (
59 * glass_windPointer *w,
60 * int i;
61 * iconData_proc proc,
62 * BOOL updateSize,
63 * void *handle
64 * )
65 *
66 * Use
67 * Processes one icon in the given window. This routine will replace all
68 * the indirection pointers with pointers to blocks from the indirection
69 * heap.
70 *
71 * Parameters
72 * glass_windPointer *w == the window data from which the icon is from
73 * int i == the icon to update (-1 for the title)
74 * BOOL updateSize == whether to update the window's size variable
75 * iconData_proc proc == function to return a pointer to an indirected
76 * string given what's in the data word. Pass 0 if its actually a
77 * valid pointer
78 * void *handle == pointer to pass to 'proc'
79 *
80 * Returns
81 * FALSE if it ran out of memory, or TRUE for success
82 */
83
84 BOOL iconData_processIcon
85 (
86 glass_windPointer *w,
87 int i,
88 iconData_proc proc,
89 BOOL updateSize,
90 void *handle
91 )
92 {
93 char *p;
94 char *q;
95 char *indir;
96 char *valid;
97 int flags;
98 if (i==-1)
99 {
100 flags=w->def->desc.w.titleflags;
101 if (flags & wimp_INDIRECT)
102 {
103 if (proc)
104 indir=proc(w->def->desc.w.title.indirecttext.buffer,handle);
105 else
106 indir=w->def->desc.w.title.indirecttext.buffer;
107 utils_ctermToNterm(indir);
108 if (w->def->desc.w.title.indirecttext.bufflen<strlen(indir)+1)
109 w->def->desc.w.title.indirecttext.bufflen=strlen(indir)+1;
110 p=indir_alloc(w->def->desc.w.title.indirecttext.bufflen);
111 if (!p)
112 return (FALSE);
113
114 /* --- Watch out -- indir might have moved :-( --- */
115
116 if (proc)
117 indir=proc(w->def->desc.w.title.indirecttext.buffer,handle);
118 else
119 indir=w->def->desc.w.title.indirecttext.buffer;
120 utils_ctermToNterm(indir);
121
122 strcpy(p,indir);
123 if (flags & wimp_ITEXT &&
124 w->def->desc.w.title.indirecttext.validstring!=(char *)-1)
125 {
126 if (proc)
127 valid=proc(w->def->desc.w.title.indirecttext.validstring,handle);
128 else
129 valid=w->def->desc.w.title.indirecttext.validstring;
130 utils_ctermToNterm(valid);
131 q=indir_alloc(strlen(valid)+1);
132 if (!q)
133 {
134 indir_free(p);
135 return (FALSE);
136 }
137
138 /* --- Aaarrghh -- valid might have moved. Find it again --- */
139
140 if (proc)
141 valid=proc(w->def->desc.w.title.indirecttext.validstring,handle);
142 else
143 valid=w->def->desc.w.title.indirecttext.validstring;
144 utils_ctermToNterm(valid);
145
146 strcpy(q,valid);
147 w->def->desc.w.title.indirecttext.validstring=q;
148 if (updateSize)
149 w->size+=strlen(valid)+1;
150 }
151 else if ((flags & 3)==2)
152 w->def->desc.w.title.indirectsprite.spritearea=w->t->s;
153 if (updateSize)
154 w->size+=w->def->desc.w.title.indirecttext.bufflen;
155 w->def->desc.w.title.indirecttext.buffer=p;
156 }
157 }
158 else
159 {
160 flags=w->def->i[i].i.flags;
161 if (flags & wimp_INDIRECT)
162 {
163 if (proc)
164 indir=proc(w->def->i[i].i.data.indirecttext.buffer,handle);
165 else
166 indir=w->def->i[i].i.data.indirecttext.buffer;
167 utils_ctermToNterm(indir);
168 if (w->def->i[i].i.data.indirecttext.bufflen<strlen(indir)+1)
169 w->def->i[i].i.data.indirecttext.bufflen=strlen(indir)+1;
170 p=indir_alloc(w->def->i[i].i.data.indirecttext.bufflen);
171 if (!p)
172 return (FALSE);
173
174 /* --- indir may have moved in a nasty way --- */
175
176 if (proc)
177 indir=proc(w->def->i[i].i.data.indirecttext.buffer,handle);
178 else
179 indir=w->def->i[i].i.data.indirecttext.buffer;
180 utils_ctermToNterm(indir);
181
182 strcpy(p,indir);
183 if (flags & wimp_ITEXT &&
184 w->def->i[i].i.data.indirecttext.validstring!=(char *)-1)
185 {
186 if (proc)
187 valid=proc(w->def->i[i].i.data.indirecttext.validstring,handle);
188 else
189 valid=w->def->i[i].i.data.indirecttext.validstring;
190 utils_ctermToNterm(valid);
191 q=indir_alloc(strlen(valid)+1);
192 if (!q)
193 {
194 indir_free(p);
195 return (FALSE);
196 }
197
198 /* --- There's a saboteur about moving valid around --- */
199
200 if (proc)
201 valid=proc(w->def->i[i].i.data.indirecttext.validstring,handle);
202 else
203 valid=w->def->i[i].i.data.indirecttext.validstring;
204 utils_ctermToNterm(valid);
205
206 strcpy(q,valid);
207 w->def->i[i].i.data.indirecttext.validstring=q;
208 if (updateSize)
209 w->size+=strlen(valid)+1;
210 }
211 else if ((flags & 3)==2)
212 w->def->i[i].i.data.indirectsprite.spritearea=w->t->s;
213 if (updateSize)
214 w->size+=w->def->i[i].i.data.indirecttext.bufflen;
215 w->def->i[i].i.data.indirecttext.buffer=p;
216 }
217 }
218 return (TRUE);
219 }
220
221 /*
222 * BOOL iconData_handleFont(glass_windPointer *w,wimp_iconflags *f)
223 *
224 * Use
225 * Processes a font handle, refinding etc. and adding to font reference
226 * array. It assumes the icon is from an external source, and doesn't
227 * attempt to free the font.
228 *
229 * Parameters
230 * glass_windPointer *w == the window containing the icon/title to fiddle
231 * wimp_iconflags *f == icon flags to fiddle with
232 *
233 * Returns
234 * TRUE if all went well, or FALSE if the icon's font has been lost. In
235 * this case the icon has been deantialiased(!) leaving potentially very
236 * strange colours.
237 */
238
239 BOOL iconData_handleFont(glass_windPointer *w,wimp_iconflags *f)
240 {
241 os_regset r;
242 int fhandle;
243 char buff[50];
244 if (*f & wimp_IFONT)
245 {
246 fhandle=(*f>>24) & 0xff;
247 r.r[0]=fhandle;
248 r.r[1]=(int)buff;
249 if (os_swix(XFont_ReadDefn,&r))
250 {
251 *f&=~wimp_IFONT;
252 return (FALSE);
253 }
254 r.r[4]=r.r[5]=0;
255 if (os_swix(XFont_FindFont,&r))
256 {
257 *f&=~wimp_IFONT;
258 return (FALSE);
259 }
260 *f=(*f & 0x00ffffff) | (fhandle<<24);
261 w->antiAliased=TRUE;
262 w->fonts[fhandle]++;
263 }
264 return (TRUE);
265 }