Fixed typos in comments.
[AROS.git] / workbench / libs / icon / puticontaglist.c
blobf4fd714460ae6937c91a50c73e3f8bd43f0f14f6
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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 /*****************************************************************************
16 NAME */
18 AROS_LH3(BOOL, PutIconTagList,
20 /* SYNOPSIS */
21 AROS_LHA(CONST_STRPTR, name, A0),
22 AROS_LHA(struct DiskObject *, icon, A1),
23 AROS_LHA(struct TagItem *, tags, A2),
25 /* LOCATION */
26 struct IconBase *, IconBase, 31, Icon)
28 /* FUNCTION
30 INPUTS
32 RESULT
34 NOTES
36 EXAMPLE
38 BUGS
40 SEE ALSO
42 INTERNALS
44 *****************************************************************************/
46 AROS_LIBFUNC_INIT
48 struct TagItem *tstate = tags;
49 struct TagItem *tag = NULL;
51 BOOL success = FALSE;
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));
69 switch (tag->ti_Tag)
72 case ICONPUTA_PutDefaultType:
73 defaultType = tag->ti_Data;
74 tag->ti_Tag = TAG_IGNORE; /* avoid recursion */
75 break;
77 case ICONPUTA_PutDefaultName:
78 defaultName = (STRPTR) tag->ti_Data;
79 tag->ti_Tag = TAG_IGNORE; /* avoid recursion */
80 break;
82 case ICONA_ErrorCode:
83 errorCode = (LONG *) tag->ti_Data;
84 SET_ERRORCODE(0);
85 break;
87 case ICONPUTA_NotifyWorkbench:
88 notifyWorkbench = tag->ti_Data;
89 break;
90 case ICONPUTA_OnlyUpdatePosition:
91 onlyUpdatePosition = tag->ti_Data;
92 break;
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
107 NULL, icon,
108 ICONPUTA_PutDefaultName, (IPTR) defaultIconName,
109 TAG_MORE, (IPTR) tags
113 else if (defaultName != NULL)
115 BPTR file = OpenDefaultIcon(defaultName, MODE_NEWFILE);
117 if (file != BNULL)
119 success = WriteIcon(file, icon, tags);
120 CloseDefaultIcon(file);
123 else if (name != NULL)
125 BPTR file = OpenIcon(name, onlyUpdatePosition ? MODE_OLDFILE : MODE_NEWFILE);
126 if (file != BNULL)
128 success = WriteIcon(file, icon, tags);
129 CloseIcon(file);
133 /* Notify workbench if we added/changed the icon */
134 D(bug("[%s]\tsuccess=%d\n", __func__, success));
135 if (success && name && notifyWorkbench && WorkbenchBase) {
136 BPTR lock, parent;
138 lock = Lock(name, SHARED_LOCK);
139 if (lock) {
140 parent = ParentDir(lock);
141 if (parent) {
142 UpdateWorkbench(FilePart(name), parent, UPDATEWB_ObjectAdded);
143 UnLock(parent);
145 UnLock(lock);
149 return success;
151 # undef SET_ERRORCODE
153 AROS_LIBFUNC_EXIT
154 } /* PutIconTagList() */