2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <workbench/icon.h>
9 #include "icon_intern.h"
11 #include "support_builtin.h"
14 /*****************************************************************************
17 #include <proto/icon.h>
19 AROS_LH2(struct DiskObject
*, GetIconTagList
,
22 AROS_LHA(CONST_STRPTR
, name
, A0
),
23 AROS_LHA(struct TagItem
*, tags
, A1
),
25 struct IconBase
*, IconBase
, 30, Icon
)
28 Opens an icon from disk.
31 name - object path (without .info extension). May be NULL when
32 retrieving a default icon.
33 tags - tag list containing tags described below.
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
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 *)
64 *****************************************************************************/
68 struct TagItem
*tstate
= (struct TagItem
*)tags
;
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
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
)
93 case ICONGETA_GetDefaultType
:
94 if (defaultType
== -1)
95 defaultType
= tag
->ti_Data
;
98 case ICONGETA_GetDefaultName
:
99 if (defaultName
== NULL
)
100 defaultName
= (CONST_STRPTR
) tag
->ti_Data
;
103 case ICONGETA_FailIfUnavailable
:
104 failIfUnavailable
= tag
->ti_Data
;
107 case ICONGETA_IsDefaultIcon
:
108 isDefaultIcon
= (LONG
*) tag
->ti_Data
;
109 SET_ISDEFAULTICON(FALSE
);
112 case ICONGETA_GetPaletteMappedIcon
:
113 getPaletteMappedIcon
= tag
->ti_Data
;
116 case ICONGETA_RemapIcon
:
117 remapIcon
= tag
->ti_Data
;
120 case ICONGETA_GenerateImageMasks
:
121 generateImageMasks
= tag
->ti_Data
;
124 case ICONGETA_Screen
:
125 screen
= (struct Screen
*) tag
->ti_Data
;
129 label
= (STRPTR
) tag
->ti_Data
;
132 case ICONA_ErrorCode
:
133 errorCode
= (LONG
*) tag
->ti_Data
;
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
));
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
)
164 ICONGETA_GetDefaultName
, (IPTR
) defaultIconName
,
167 D(bug("[%s] Find default icon type %d as %p\n", __func__
, defaultType
, icon
));
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
));
185 D(bug("[%s] Found custom icon '%s'\n", __func__
, name
));
186 icon
= ReadIcon(file
);
189 if (icon
!= NULL
&& icon
->do_Type
== 0)
191 /* Force the icon type */
192 BPTR lock
= LockObject(name
, ACCESS_READ
);
195 LONG type
= FindType(lock
);
196 if (type
!= -1) icon
->do_Type
= type
;
203 * If everything else fails, just lie. Not having do_Type set
206 if (icon
!= NULL
&& icon
->do_Type
== 0)
207 icon
->do_Type
= WBPROJECT
;
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
;
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
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
;
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
);
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
));
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
));
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 */
315 IconControl(NULL
, ICONCTRLA_GetGlobalScreen
, &screen
, TAG_END
);
320 /* Any last-minute fixups */
323 D(bug("[%s] %p: Performing initial layout for screen %p\n", __func__
, icon
, screen
));
324 LayoutIconA(icon
, screen
, (struct TagItem
*)tags
);
328 if (errorCode
!= NULL
)
332 D(bug("[%s] name %s, tags %p => %p\n", __func__
, name
, tags
, icon
));
338 # undef SET_ISDEFAULTICON
340 } /* GetIconTagList() */