Autodocs updated.
[cake.git] / workbench / libs / icon / geticontaglist.c
blob6c4acd0608c485ec7cacd60288cbeff1a3928eda
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <workbench/icon.h>
8 #include "icon_intern.h"
9 #include "support.h"
10 #include "support_builtin.h"
11 #include "identify.h"
13 /*****************************************************************************
15 NAME */
16 #include <proto/icon.h>
18 AROS_LH2(struct DiskObject *, GetIconTagList,
20 /* SYNOPSIS */
21 AROS_LHA(CONST_STRPTR, name, A0),
22 AROS_LHA(const struct TagItem *, tags, A1),
23 /* LOCATION */
24 struct Library *, IconBase, 30, Icon)
26 /* FUNCTION
27 Open icon from disk
28 INPUTS
30 TAGS
31 ICONA_ErrorCode (LONG *)
32 ICONGETA_GetDefaultType (LONG) - Default icon type to get. This
33 overrides the "name" paramter.
34 ICONGETA_GetDefaultName (STRPTR) - Name of default icon to get. This
35 overrides the "name" paramter.
36 ICONGETA_FailIfUnavailable (BOOL)
37 ICONGETA_GetPaletteMappedIcon (BOOL)
38 ICONGETA_IsDefaultIcon (LONG *) - Upon completion of this function, the
39 referenced LONG will be set to a boolean value indicating whether
40 the returned icon is a default icon.
41 ICONGETA_RemapIcon (BOOL)
42 ICONGETA_GenerateImageMasks (BOOL)
43 ICONGETA_Label (STRPTR)
44 ICONGETA_Screen (struct Screen *)
46 RESULT
48 NOTES
50 EXAMPLE
52 BUGS
54 SEE ALSO
56 INTERNALS
58 *****************************************************************************/
60 AROS_LIBFUNC_INIT
62 const struct TagItem *tstate = tags;
63 const struct TagItem *tag;
64 struct DiskObject *icon = NULL;
65 LONG defaultType = -1;
66 CONST_STRPTR defaultName = NULL;
67 IPTR failIfUnavailable = TRUE;
68 LONG *isDefaultIcon = NULL;
70 IPTR getPaletteMappedIcon = TRUE; // FIXME: not used
71 IPTR remapIcon = TRUE; // FIXME: not used
72 IPTR generateImageMasks = TRUE; // FIXME: not used
73 struct Screen *screen = NULL; // FIXME: not used
74 STRPTR label = NULL; // FIXME: not used
75 LONG error = 0;
76 LONG *errorCode = NULL;
78 # define SET_ISDEFAULTICON(value) (isDefaultIcon != NULL ? *isDefaultIcon = (value) : (value))
80 /* Parse taglist -------------------------------------------------------*/
81 while ((tag = NextTagItem(&tstate)) != NULL)
83 switch (tag->ti_Tag)
85 case ICONGETA_GetDefaultType:
86 if (defaultType == -1)
87 defaultType = tag->ti_Data;
88 break;
90 case ICONGETA_GetDefaultName:
91 if (defaultName == NULL)
92 defaultName = (CONST_STRPTR) tag->ti_Data;
93 break;
95 case ICONGETA_FailIfUnavailable:
96 failIfUnavailable = tag->ti_Data;
97 break;
99 case ICONGETA_IsDefaultIcon:
100 isDefaultIcon = (LONG *) tag->ti_Data;
101 SET_ISDEFAULTICON(FALSE);
102 break;
104 case ICONGETA_GetPaletteMappedIcon:
105 getPaletteMappedIcon = tag->ti_Data;
106 break;
108 case ICONGETA_RemapIcon:
109 remapIcon = tag->ti_Data;
110 break;
112 case ICONGETA_GenerateImageMasks:
113 generateImageMasks = tag->ti_Data;
114 break;
116 case ICONGETA_Screen:
117 screen = (struct Screen *) tag->ti_Data;
118 break;
120 case ICONGETA_Label:
121 label = (STRPTR) tag->ti_Data;
122 break;
124 case ICONA_ErrorCode:
125 errorCode = (LONG *) tag->ti_Data;
126 break;
130 if (defaultType != -1 || defaultName != NULL)
132 if (defaultName != NULL)
134 BPTR file = OpenDefaultIcon(defaultName, MODE_OLDFILE);
136 if (file != NULL)
138 icon = ReadIcon(file);
139 CloseDefaultIcon(file);
142 SET_ISDEFAULTICON(TRUE);
145 if (icon == NULL && defaultType != -1)
147 CONST_STRPTR defaultIconName = GetDefaultIconName(defaultType);
149 if (defaultIconName != NULL)
151 icon = GetIconTags
153 NULL,
154 ICONGETA_GetDefaultName, (IPTR) defaultIconName,
155 TAG_MORE, (IPTR) tags
158 if (icon == NULL)
160 icon = GetBuiltinIcon(defaultType);
165 else if (name != NULL)
167 BPTR file = OpenIcon(name, MODE_OLDFILE);
169 if (file != NULL)
171 icon = ReadIcon(file);
172 CloseIcon(file);
174 if (icon != NULL)
176 /* Force the icon type */
177 BPTR lock = LockObject(name, ACCESS_READ);
178 if (lock != NULL)
180 LONG type = FindType(lock);
181 if (type != -1) icon->do_Type = type;
183 UnLockObject(lock);
187 else if (!failIfUnavailable)
189 struct IconIdentifyMsg iim;
191 if ((iim.iim_FileLock = LockObject(name, ACCESS_READ)) != NULL)
193 if ((iim.iim_FIB = AllocDosObject(DOS_FIB, TAG_DONE)) != NULL)
195 if (Examine(iim.iim_FileLock, iim.iim_FIB))
197 iim.iim_SysBase = (struct Library *) SysBase;
198 iim.iim_DOSBase = (struct Library *) DOSBase;
199 iim.iim_UtilityBase = (struct Library *) UtilityBase;
200 iim.iim_IconBase = IconBase;
201 iim.iim_Tags = tags;
203 iim.iim_ParentLock = ParentDir(iim.iim_FileLock);
204 iim.iim_FileHandle = Open(name, MODE_OLDFILE);
206 if (LB(IconBase)->ib_IdentifyHook != NULL)
208 /* Use user-provided identify hook */
209 icon = (struct DiskObject *) CALLHOOKPKT
211 LB(IconBase)->ib_IdentifyHook, NULL, &iim
214 if (icon != NULL)
217 Sanity check since we don't trust the
218 user-provided hook too much. ;-)
221 LONG type = FindType(iim.iim_FileLock);
222 if (type != -1) icon->do_Type = type;
226 if (icon == NULL)
228 /* Fall back to the default identify function */
229 icon = FindDefaultIcon(&iim);
232 if (iim.iim_ParentLock != NULL) UnLock(iim.iim_ParentLock);
233 if (iim.iim_FileHandle != NULL) Close(iim.iim_FileHandle);
236 FreeDosObject(DOS_FIB, iim.iim_FIB);
238 else
240 error = IoErr();
243 UnLockObject(iim.iim_FileLock);
248 /* Set error code */
249 if (errorCode != NULL)
250 *errorCode = error;
251 SetIoErr(error);
253 return icon;
255 AROS_LIBFUNC_EXIT
257 # undef SET_ISDEFAULTICON
259 } /* GetIconTagList() */