2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 #include <workbench/icon.h>
8 #include "icon_intern.h"
10 #include "support_builtin.h"
13 /*****************************************************************************
16 #include <proto/icon.h>
18 AROS_LH2(struct DiskObject
*, GetIconTagList
,
21 AROS_LHA(CONST_STRPTR
, name
, A0
),
22 AROS_LHA(const struct TagItem
*, tags
, A1
),
24 struct Library
*, IconBase
, 30, Icon
)
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 *)
58 *****************************************************************************/
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
76 LONG
*errorCode
= NULL
;
78 # define SET_ISDEFAULTICON(value) (isDefaultIcon != NULL ? *isDefaultIcon = (value) : (value))
80 /* Parse taglist -------------------------------------------------------*/
81 while ((tag
= NextTagItem(&tstate
)) != NULL
)
85 case ICONGETA_GetDefaultType
:
86 if (defaultType
== -1)
87 defaultType
= tag
->ti_Data
;
90 case ICONGETA_GetDefaultName
:
91 if (defaultName
== NULL
)
92 defaultName
= (CONST_STRPTR
) tag
->ti_Data
;
95 case ICONGETA_FailIfUnavailable
:
96 failIfUnavailable
= tag
->ti_Data
;
99 case ICONGETA_IsDefaultIcon
:
100 isDefaultIcon
= (LONG
*) tag
->ti_Data
;
101 SET_ISDEFAULTICON(FALSE
);
104 case ICONGETA_GetPaletteMappedIcon
:
105 getPaletteMappedIcon
= tag
->ti_Data
;
108 case ICONGETA_RemapIcon
:
109 remapIcon
= tag
->ti_Data
;
112 case ICONGETA_GenerateImageMasks
:
113 generateImageMasks
= tag
->ti_Data
;
116 case ICONGETA_Screen
:
117 screen
= (struct Screen
*) tag
->ti_Data
;
121 label
= (STRPTR
) tag
->ti_Data
;
124 case ICONA_ErrorCode
:
125 errorCode
= (LONG
*) tag
->ti_Data
;
130 if (defaultType
!= -1 || defaultName
!= NULL
)
132 if (defaultName
!= NULL
)
134 BPTR file
= OpenDefaultIcon(defaultName
, MODE_OLDFILE
);
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
)
154 ICONGETA_GetDefaultName
, (IPTR
) defaultIconName
,
155 TAG_MORE
, (IPTR
) tags
160 icon
= GetBuiltinIcon(defaultType
);
165 else if (name
!= NULL
)
167 BPTR file
= OpenIcon(name
, MODE_OLDFILE
);
171 icon
= ReadIcon(file
);
176 /* Force the icon type */
177 BPTR lock
= LockObject(name
, ACCESS_READ
);
180 LONG type
= FindType(lock
);
181 if (type
!= -1) icon
->do_Type
= type
;
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
;
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
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
;
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
);
243 UnLockObject(iim
.iim_FileLock
);
249 if (errorCode
!= NULL
)
257 # undef SET_ISDEFAULTICON
259 } /* GetIconTagList() */