include/muimaster/macros.h: get() compiler delint
[AROS.git] / workbench / libs / icon / geticontaglist.c
blob975e106e981bd8a285933dcef1bcb332ba99b6eb
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <workbench/icon.h>
9 #include "icon_intern.h"
10 #include "support.h"
11 #include "support_builtin.h"
12 #include "identify.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/icon.h>
19 AROS_LH2(struct DiskObject *, GetIconTagList,
21 /* SYNOPSIS */
22 AROS_LHA(CONST_STRPTR, name, A0),
23 AROS_LHA(struct TagItem *, tags, A1),
24 /* LOCATION */
25 struct IconBase *, IconBase, 30, Icon)
27 /* FUNCTION
28 Opens an icon from disk.
30 INPUTS
31 name - object path (without .info extension). May be NULL when
32 retrieving a default icon.
33 tags - tag list containing tags described below.
35 TAGS
36 ICONA_ErrorCode (LONG *)
37 ICONGETA_GetDefaultType (LONG) - Default icon type to get. This
38 overrides the "name" parameter.
39 ICONGETA_GetDefaultName (STRPTR) - Name of default icon to get. This
40 overrides the "name" parameter.
41 ICONGETA_FailIfUnavailable (BOOL) - Find a default icon if there is no
42 specific icon.
43 ICONGETA_GetPaletteMappedIcon (BOOL)
44 ICONGETA_IsDefaultIcon (LONG *) - Upon completion of this function, the
45 referenced LONG will be set to a boolean value indicating whether
46 the returned icon is a default icon.
47 ICONGETA_RemapIcon (BOOL)
48 ICONGETA_GenerateImageMasks (BOOL)
49 ICONGETA_Label (STRPTR)
50 ICONGETA_Screen (struct Screen *)
52 RESULT
54 NOTES
56 EXAMPLE
58 BUGS
60 SEE ALSO
62 INTERNALS
64 *****************************************************************************/
66 AROS_LIBFUNC_INIT
68 struct TagItem *tstate = (struct TagItem *)tags;
69 struct TagItem *tag;
70 struct DiskObject *icon = NULL;
71 LONG defaultType = -1;
72 CONST_STRPTR defaultName = NULL;
73 IPTR failIfUnavailable = TRUE;
74 LONG *isDefaultIcon = NULL;
76 IPTR getPaletteMappedIcon = TRUE;
77 IPTR remapIcon = TRUE;
78 IPTR generateImageMasks = TRUE;
79 struct Screen *screen = NULL;
80 STRPTR label = NULL; // FIXME: not used
81 LONG error = 0;
82 LONG *errorCode = NULL;
84 # define SET_ISDEFAULTICON(value) (isDefaultIcon != NULL ? *isDefaultIcon = (value) : (value))
86 D(bug("[%s] name %s, tags %p\n", __func__, name, tags));
88 /* Parse taglist -------------------------------------------------------*/
89 while ((tag = NextTagItem(&tstate)) != NULL)
91 switch (tag->ti_Tag)
93 case ICONGETA_GetDefaultType:
94 if (defaultType == -1)
95 defaultType = tag->ti_Data;
96 break;
98 case ICONGETA_GetDefaultName:
99 if (defaultName == NULL)
100 defaultName = (CONST_STRPTR) tag->ti_Data;
101 break;
103 case ICONGETA_FailIfUnavailable:
104 failIfUnavailable = tag->ti_Data;
105 break;
107 case ICONGETA_IsDefaultIcon:
108 isDefaultIcon = (LONG *) tag->ti_Data;
109 SET_ISDEFAULTICON(FALSE);
110 break;
112 case ICONGETA_GetPaletteMappedIcon:
113 getPaletteMappedIcon = tag->ti_Data;
114 break;
116 case ICONGETA_RemapIcon:
117 remapIcon = tag->ti_Data;
118 break;
120 case ICONGETA_GenerateImageMasks:
121 generateImageMasks = tag->ti_Data;
122 break;
124 case ICONGETA_Screen:
125 screen = (struct Screen *) tag->ti_Data;
126 break;
128 case ICONGETA_Label:
129 label = (STRPTR) tag->ti_Data;
130 break;
132 case ICONA_ErrorCode:
133 errorCode = (LONG *) tag->ti_Data;
134 break;
138 if (defaultType != -1 || defaultName != NULL)
140 if (defaultName != NULL)
142 BPTR file = OpenDefaultIcon(defaultName, MODE_OLDFILE);
144 D(bug("[%s] Find default icon '%s'\n", __func__, defaultName));
145 if (file != BNULL)
147 D(bug("[%s] Found default icon '%s'\n", __func__, defaultName));
148 icon = ReadIcon(file);
149 CloseDefaultIcon(file);
150 SET_ISDEFAULTICON(TRUE);
154 if (icon == NULL && defaultType != -1 && defaultName == NULL)
156 CONST_STRPTR defaultIconName = GetDefaultIconName(defaultType);
158 D(bug("[%s] Find default icon type %d\n", __func__, defaultType));
159 if (defaultIconName != NULL)
161 icon = GetIconTags
163 NULL,
164 ICONGETA_GetDefaultName, (IPTR) defaultIconName,
165 TAG_END
167 D(bug("[%s] Find default icon type %d as %p\n", __func__, defaultType, icon));
169 if (icon == NULL)
171 icon = GetBuiltinIcon(defaultType);
172 D(bug("[%s] Using builtin icon %p\n", __func__, icon));
173 SET_ISDEFAULTICON(TRUE);
178 else if (name != NULL)
180 BPTR file = OpenIcon(name, MODE_OLDFILE);
182 D(bug("[%s] Find custom icon '%s'\n", __func__, name));
183 if (file != BNULL)
185 D(bug("[%s] Found custom icon '%s'\n", __func__, name));
186 icon = ReadIcon(file);
187 CloseIcon(file);
189 if (icon != NULL && icon->do_Type == 0)
191 /* Force the icon type */
192 BPTR lock = LockObject(name, ACCESS_READ);
193 if (lock != BNULL)
195 LONG type = FindType(lock);
196 if (type != -1) icon->do_Type = type;
198 UnLockObject(lock);
203 * If everything else fails, just lie. Not having do_Type set
204 * causes problems.
206 if (icon != NULL && icon->do_Type == 0)
207 icon->do_Type = WBPROJECT;
209 } else {
210 /* NULL name = return empty DiskObject */
211 D(bug("[%s] Get an empty DiskObject\n", __func__));
212 icon = NewDiskObject(0);
215 /* Try to identify it by name or type */
216 if (icon == NULL && !failIfUnavailable)
218 struct IconIdentifyMsg iim;
220 D(bug("[%s] Falling back to default icon for %s\n", __func__, name));
222 if (name && (iim.iim_FileLock = LockObject(name, ACCESS_READ)) != BNULL)
224 D(bug("[%s] Locked %s, identifying\n", __func__, name));
225 if ((iim.iim_FIB = AllocDosObject(DOS_FIB, TAG_DONE)) != NULL)
227 if (Examine(iim.iim_FileLock, iim.iim_FIB))
229 iim.iim_SysBase = (struct Library *) SysBase;
230 iim.iim_DOSBase = (struct Library *) DOSBase;
231 iim.iim_UtilityBase = (struct Library *) UtilityBase;
232 iim.iim_IconBase = (struct Library *) IconBase;
233 iim.iim_Tags = tags;
235 iim.iim_ParentLock = ParentDir(iim.iim_FileLock);
236 if (iim.iim_ParentLock == BNULL && IoErr() == 0)
237 iim.iim_FIB->fib_DirEntryType = ST_ROOT;
238 iim.iim_FileHandle = Open(name, MODE_OLDFILE);
240 if (LB(IconBase)->ib_IdentifyHook != NULL)
242 /* Use user-provided identify hook */
243 icon = (struct DiskObject *) CALLHOOKPKT
245 LB(IconBase)->ib_IdentifyHook, NULL, &iim
248 if (icon != NULL)
251 Sanity check since we don't trust the
252 user-provided hook too much. ;-)
255 LONG type = FindType(iim.iim_FileLock);
256 if (type != -1) icon->do_Type = type;
260 if (icon == NULL)
262 /* Fall back to the default identify function */
263 D(bug("[%s] Finding default icon for iim %p\n", __func__, &iim));
264 icon = FindDefaultIcon(&iim);
267 if (iim.iim_ParentLock != BNULL) UnLock(iim.iim_ParentLock);
268 if (iim.iim_FileHandle != BNULL) Close(iim.iim_FileHandle);
271 FreeDosObject(DOS_FIB, iim.iim_FIB);
273 else
275 error = IoErr();
278 UnLockObject(iim.iim_FileLock);
281 if (icon == NULL && defaultType > 0) {
282 icon = GetBuiltinIcon(defaultType);
283 D(bug("[%s] Using builtin icon %p\n", __func__, icon));
286 if (icon == NULL) {
287 LONG type = (name && Stricmp("Disk", name)==0) ? WBDISK : WBPROJECT;
288 icon = GetBuiltinIcon(type);
289 D(bug("[%s] Using builtin icon %p, type %d\n", __func__, icon, type));
294 if (!icon)
295 goto exit;
297 if (label != NULL) {
298 /* TODO: Add the label specified in 'label' to the icon */
301 if (generateImageMasks) {
302 D(bug("[%s] %p: Generate image masks\n", __func__, icon));
303 /* A side effect of palette mapping the icon... */
304 getPaletteMappedIcon = TRUE;
307 if (getPaletteMappedIcon) {
308 D(bug("[%s] %p: Generate palette mapped icon\n", __func__, icon));
309 /* A side effect of remapping the icon to the DefaultPubScreen */
310 remapIcon = TRUE;
313 if (remapIcon) {
314 if (screen == NULL)
315 IconControl(NULL, ICONCTRLA_GetGlobalScreen, &screen, TAG_END);
316 } else {
317 screen = NULL;
320 /* Any last-minute fixups */
321 PrepareIcon(icon);
323 D(bug("[%s] %p: Performing initial layout for screen %p\n", __func__, icon, screen));
324 LayoutIconA(icon, screen, (struct TagItem *)tags);
326 exit:
327 /* Set error code */
328 if (errorCode != NULL)
329 *errorCode = error;
330 SetIoErr(error);
332 D(bug("[%s] name %s, tags %p => %p\n", __func__, name, tags, icon));
334 return icon;
336 AROS_LIBFUNC_EXIT
338 # undef SET_ISDEFAULTICON
340 } /* GetIconTagList() */