2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
8 #include <utility/tagitem.h>
9 #include <proto/icon.h>
10 #include <proto/workbench.h>
12 #include "icon_intern.h"
14 /*****************************************************************************
18 AROS_LH3(BOOL
, PutIconTagList
,
21 AROS_LHA(CONST_STRPTR
, name
, A0
),
22 AROS_LHA(struct DiskObject
*, icon
, A1
),
23 AROS_LHA(struct TagItem
*, tags
, A2
),
26 struct IconBase
*, IconBase
, 31, Icon
)
44 *****************************************************************************/
48 struct TagItem
*tstate
= tags
;
49 struct TagItem
*tag
= NULL
;
52 LONG defaultType
= -1;
53 STRPTR defaultName
= NULL
;
54 LONG
*errorCode
= NULL
;
56 BOOL notifyWorkbench
= FALSE
;
57 BOOL onlyUpdatePosition
= FALSE
;
59 # define SET_ERRORCODE(value) (errorCode != NULL ? *errorCode = (value) : (value))
61 /* Check input parameters ----------------------------------------------*/
62 D(bug("[%s] Icon %p\n", __func__
, icon
));
63 if (icon
== NULL
) return FALSE
;
65 /* Parse taglist -------------------------------------------------------*/
66 while ((tag
= NextTagItem(&tstate
)) != NULL
)
68 D(bug("[%s]\tTag (0x%08x, 0x%p)\n", __func__
, tag
->ti_Tag
, (APTR
)tag
->ti_Data
));
72 case ICONPUTA_PutDefaultType
:
73 defaultType
= tag
->ti_Data
;
74 tag
->ti_Tag
= TAG_IGNORE
; /* avoid recursion */
77 case ICONPUTA_PutDefaultName
:
78 defaultName
= (STRPTR
) tag
->ti_Data
;
79 tag
->ti_Tag
= TAG_IGNORE
; /* avoid recursion */
83 errorCode
= (LONG
*) tag
->ti_Data
;
87 case ICONPUTA_NotifyWorkbench
:
88 notifyWorkbench
= tag
->ti_Data
;
90 case ICONPUTA_OnlyUpdatePosition
:
91 onlyUpdatePosition
= tag
->ti_Data
;
96 D(bug("[%s]\tdefaultType=%d\n", __func__
, defaultType
));
97 D(bug("[%s]\tdefaultName='%s'\n", __func__
, defaultName
));
98 D(bug("[%s]\tname='%s'\n", __func__
, name
));
99 if (defaultType
!= -1)
101 CONST_STRPTR defaultIconName
= GetDefaultIconName(defaultType
);
103 if (defaultIconName
!= NULL
)
105 success
= PutIconTags
108 ICONPUTA_PutDefaultName
, (IPTR
) defaultIconName
,
109 TAG_MORE
, (IPTR
) tags
113 else if (defaultName
!= NULL
)
115 BPTR file
= OpenDefaultIcon(defaultName
, MODE_NEWFILE
);
119 success
= WriteIcon(file
, icon
, tags
);
120 CloseDefaultIcon(file
);
123 else if (name
!= NULL
)
125 BPTR file
= OpenIcon(name
, onlyUpdatePosition
? MODE_OLDFILE
: MODE_NEWFILE
);
128 success
= WriteIcon(file
, icon
, tags
);
133 /* Notify workbench if we added/changed the icon */
134 D(bug("[%s]\tsuccess=%d\n", __func__
, success
));
135 if (success
&& name
&& notifyWorkbench
&& WorkbenchBase
) {
138 lock
= Lock(name
, SHARED_LOCK
);
140 parent
= ParentDir(lock
);
142 UpdateWorkbench(FilePart(name
), parent
, UPDATEWB_ObjectAdded
);
151 # undef SET_ERRORCODE
154 } /* PutIconTagList() */