2 Copyright © 1995-2012, 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(const struct TagItem
*, tags
, A1
),
25 struct IconBase
*, IconBase
, 30, Icon
)
32 ICONA_ErrorCode (LONG *)
33 ICONGETA_GetDefaultType (LONG) - Default icon type to get. This
34 overrides the "name" parameter.
35 ICONGETA_GetDefaultName (STRPTR) - Name of default icon to get. This
36 overrides the "name" parameter.
37 ICONGETA_FailIfUnavailable (BOOL)
38 ICONGETA_GetPaletteMappedIcon (BOOL)
39 ICONGETA_IsDefaultIcon (LONG *) - Upon completion of this function, the
40 referenced LONG will be set to a boolean value indicating whether
41 the returned icon is a default icon.
42 ICONGETA_RemapIcon (BOOL)
43 ICONGETA_GenerateImageMasks (BOOL)
44 ICONGETA_Label (STRPTR)
45 ICONGETA_Screen (struct Screen *)
59 *****************************************************************************/
63 struct TagItem
*tstate
= (struct TagItem
*)tags
;
65 struct DiskObject
*icon
= NULL
;
66 LONG defaultType
= -1;
67 CONST_STRPTR defaultName
= NULL
;
68 IPTR failIfUnavailable
= TRUE
;
69 LONG
*isDefaultIcon
= NULL
;
71 IPTR getPaletteMappedIcon
= TRUE
;
72 IPTR remapIcon
= TRUE
;
73 IPTR generateImageMasks
= TRUE
;
74 struct Screen
*screen
= NULL
;
75 STRPTR label
= NULL
; // FIXME: not used
77 LONG
*errorCode
= NULL
;
79 # define SET_ISDEFAULTICON(value) (isDefaultIcon != NULL ? *isDefaultIcon = (value) : (value))
81 D(bug("[%s] name %s, tags %p\n", __func__
, name
, tags
));
83 /* Parse taglist -------------------------------------------------------*/
84 while ((tag
= NextTagItem(&tstate
)) != NULL
)
88 case ICONGETA_GetDefaultType
:
89 if (defaultType
== -1)
90 defaultType
= tag
->ti_Data
;
93 case ICONGETA_GetDefaultName
:
94 if (defaultName
== NULL
)
95 defaultName
= (CONST_STRPTR
) tag
->ti_Data
;
98 case ICONGETA_FailIfUnavailable
:
99 failIfUnavailable
= tag
->ti_Data
;
102 case ICONGETA_IsDefaultIcon
:
103 isDefaultIcon
= (LONG
*) tag
->ti_Data
;
104 SET_ISDEFAULTICON(FALSE
);
107 case ICONGETA_GetPaletteMappedIcon
:
108 getPaletteMappedIcon
= tag
->ti_Data
;
111 case ICONGETA_RemapIcon
:
112 remapIcon
= tag
->ti_Data
;
115 case ICONGETA_GenerateImageMasks
:
116 generateImageMasks
= tag
->ti_Data
;
119 case ICONGETA_Screen
:
120 screen
= (struct Screen
*) tag
->ti_Data
;
124 label
= (STRPTR
) tag
->ti_Data
;
127 case ICONA_ErrorCode
:
128 errorCode
= (LONG
*) tag
->ti_Data
;
133 if (defaultType
!= -1 || defaultName
!= NULL
)
135 if (defaultName
!= NULL
)
137 BPTR file
= OpenDefaultIcon(defaultName
, MODE_OLDFILE
);
139 D(bug("[%s] Find default icon '%s'\n", __func__
, defaultName
));
142 D(bug("[%s] Found default icon '%s'\n", __func__
, defaultName
));
143 icon
= ReadIcon(file
);
144 CloseDefaultIcon(file
);
145 SET_ISDEFAULTICON(TRUE
);
149 if (icon
== NULL
&& defaultType
!= -1 && defaultName
== NULL
)
151 CONST_STRPTR defaultIconName
= GetDefaultIconName(defaultType
);
153 D(bug("[%s] Find default icon type %d\n", __func__
, defaultType
));
154 if (defaultIconName
!= NULL
)
159 ICONGETA_GetDefaultName
, (IPTR
) defaultIconName
,
162 D(bug("[%s] Find default icon type %d as %p\n", __func__
, defaultType
, icon
));
166 icon
= GetBuiltinIcon(defaultType
);
167 D(bug("[%s] Using builtin icon %p\n", __func__
, icon
));
168 SET_ISDEFAULTICON(TRUE
);
173 else if (name
!= NULL
)
175 BPTR file
= OpenIcon(name
, MODE_OLDFILE
);
177 D(bug("[%s] Find custom icon '%s'\n", __func__
, name
));
180 D(bug("[%s] Found custom icon '%s'\n", __func__
, name
));
181 icon
= ReadIcon(file
);
184 if (icon
!= NULL
&& icon
->do_Type
== 0)
186 /* Force the icon type */
187 BPTR lock
= LockObject(name
, ACCESS_READ
);
190 LONG type
= FindType(lock
);
191 if (type
!= -1) icon
->do_Type
= type
;
198 /* NULL name = return empty DiskObject */
199 D(bug("[%s] Get an empty DiskObject\n", __func__
));
200 icon
= NewDiskObject(0);
203 /* Try to identify it by name or type */
204 if (icon
== NULL
&& !failIfUnavailable
)
206 struct IconIdentifyMsg iim
;
208 D(bug("[%s] Falling back to default icon for %s\n", __func__
, name
));
210 if (name
&& (iim
.iim_FileLock
= LockObject(name
, ACCESS_READ
)) != BNULL
)
212 D(bug("[%s] Locked %s, identifying\n", __func__
, name
));
213 if ((iim
.iim_FIB
= AllocDosObject(DOS_FIB
, TAG_DONE
)) != NULL
)
215 if (Examine(iim
.iim_FileLock
, iim
.iim_FIB
))
217 iim
.iim_SysBase
= (struct Library
*) SysBase
;
218 iim
.iim_DOSBase
= (struct Library
*) DOSBase
;
219 iim
.iim_UtilityBase
= (struct Library
*) UtilityBase
;
220 iim
.iim_IconBase
= (struct Library
*) IconBase
;
223 iim
.iim_ParentLock
= ParentDir(iim
.iim_FileLock
);
224 if (iim
.iim_ParentLock
== BNULL
&& IoErr() == 0)
225 iim
.iim_FIB
->fib_DirEntryType
= ST_ROOT
;
226 iim
.iim_FileHandle
= Open(name
, MODE_OLDFILE
);
228 if (LB(IconBase
)->ib_IdentifyHook
!= NULL
)
230 /* Use user-provided identify hook */
231 icon
= (struct DiskObject
*) CALLHOOKPKT
233 LB(IconBase
)->ib_IdentifyHook
, NULL
, &iim
239 Sanity check since we don't trust the
240 user-provided hook too much. ;-)
243 LONG type
= FindType(iim
.iim_FileLock
);
244 if (type
!= -1) icon
->do_Type
= type
;
250 /* Fall back to the default identify function */
251 D(bug("[%s] Finding default icon for iim %p\n", __func__
, &iim
));
252 icon
= FindDefaultIcon(&iim
);
255 if (iim
.iim_ParentLock
!= BNULL
) UnLock(iim
.iim_ParentLock
);
256 if (iim
.iim_FileHandle
!= BNULL
) Close(iim
.iim_FileHandle
);
259 FreeDosObject(DOS_FIB
, iim
.iim_FIB
);
266 UnLockObject(iim
.iim_FileLock
);
269 if (icon
== NULL
&& defaultType
> 0) {
270 icon
= GetBuiltinIcon(defaultType
);
271 D(bug("[%s] Using builtin icon %p\n", __func__
, icon
));
275 LONG type
= (name
&& Stricmp("Disk", name
)==0) ? WBDISK
: WBPROJECT
;
276 icon
= GetBuiltinIcon(type
);
277 D(bug("[%s] Using builtin icon %p, type %d\n", __func__
, icon
, type
));
286 /* TODO: Add the label specified in 'label' to the icon */
289 if (generateImageMasks
) {
290 D(bug("[%s] %p: Generate image masks\n", __func__
, icon
));
291 /* A side effect of palette mapping the icon... */
292 getPaletteMappedIcon
= TRUE
;
295 if (getPaletteMappedIcon
) {
296 D(bug("[%s] %p: Generate palette mapped icon\n", __func__
, icon
));
297 /* A side effect of remapping the icon to the DefaultPubScreen */
303 IconControl(NULL
, ICONCTRLA_GetGlobalScreen
, &screen
, TAG_END
);
308 /* Any last-minute fixups */
311 D(bug("[%s] %p: Performing initial layout for screen %p\n", __func__
, icon
, screen
));
312 LayoutIconA(icon
, screen
, (struct TagItem
*)tags
);
316 if (errorCode
!= NULL
)
320 D(bug("[%s] name %s, tags %p => %p\n", __func__
, name
, tags
, icon
));
326 # undef SET_ISDEFAULTICON
328 } /* GetIconTagList() */