r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / workbench / addappicona.c
blobf62678d3c42d60913bcf705670b1538481fc9c95
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Add an icon to Workbench's list of AppIcons.
6 Lang: English
7 */
9 #include <exec/types.h>
10 #include <exec/ports.h>
11 #include <utility/tagitem.h>
12 #include <dos/dos.h>
13 #include <graphics/gfx.h>
15 #include <proto/utility.h>
17 #include "workbench_intern.h"
18 #include <workbench/workbench.h>
21 /*****************************************************************************
23 NAME */
24 #include <proto/workbench.h>
26 AROS_LH7(struct AppIcon *, AddAppIconA,
27 /* SYNOPSIS */
28 AROS_LHA(ULONG, id, D0),
29 AROS_LHA(ULONG, userdata, D1),
30 AROS_LHA(char *, text, A0),
31 AROS_LHA(struct MsgPort *, msgport, A1),
32 AROS_LHA(BPTR, lock, A2),
33 AROS_LHA(struct DiskObject *, diskobj, A3),
34 AROS_LHA(struct TagItem *, taglist, A4),
36 /* LOCATION */
37 struct WorkbenchBase *, WorkbenchBase, 10, Workbench)
39 /* FUNCTION
41 Add an icon to the workbench's list of AppIcons. If a workbench is
42 running, the icon will appear on the workbench screen given that the
43 call is successful.
44 When a user interacts with the AppIcon, an AppMessage of type
45 MTYPE_APPICON is sent to the message port specified. The different
46 supported actions are:
48 1. User double-clicking on the icon. am_NumArgs is zero and am_ArgList is
49 NULL.
50 2. Dropping one or more icons on the AppIcon. am_Numargs is the number of
51 icons dropped plus one; am_ArgList is an array of pointers to WBArg
52 structures of the icons dropped.
53 3. Dropping the AppIcon on another icon -- NOT SUPPORTED.
54 4. Invoking an "Icons" menu item when the AppIcon is selected. am_Class
55 will be set to a value in AMCLASSICON_Open ... AMCLASSICON_EmptyTrash.
57 INPUTS
59 id -- AppIcon identification number; only for your use (ignored by
60 workbench.library)
61 userdata -- user specific data (ignored by workbench.library)
62 text -- name of the icon
63 lock -- currently unused (must be set to NULL)
64 msgport -- message port to which notification messages will be sent
65 diskobj -- pointer to a DiskObject structure filled in as described
66 below:
67 do_Magic -- 0
68 do_Version -- 0
69 do_Gadget -- a gadget structure filled in as follows:
70 NextGadget -- NULL
71 LeftEdge -- 0
72 TopEdge -- 0
73 Width -- width of icon hit box
74 Height -- height of icon hit box
75 Flags -- 0 or GADGHIMAGE
76 Activation -- 0
77 GadgetType -- 0
78 GadgetRender -- pointer to an Image structure
79 filled in as follows:
80 LeftEdge -- 0
81 TopEdge -- 0
82 Width -- width of image (must be <=
83 width of icon hit box)
84 Height -- height of image (must be <=
85 height of icon hit box)
86 Depth -- number of bit planes of
87 image
88 ImageData -- pointer to word aligned
89 image data
90 PlanePick -- plane mask
91 ((1 << depth) - 1)
92 PlaneOnOff -- 0
93 NextImage -- NULL
94 SelectRender -- NULL
95 GadgetText -- NULL
96 MutualExclude -- NULL
97 SpecialInfo -- NULL
98 GadgetID -- NULL
99 UserData -- NULL
100 do_Type -- 0
101 do_DefaultTool -- NULL
102 do_ToolTypes -- NULL
103 do_CurrentX -- NO_ICON_POSITION (recommended)
104 do_CurrentY -- NO_ICON_POSITION (recommended)
105 do_DrawerData -- NULL
106 do_ToolWindow -- NULL
107 do_StackSize -- 0
109 taglist -- tags (see below)
111 TAGS
113 WBAPPICONA_SupportsOpen (BOOL)
114 Set to TRUE if the AppIcon should respond to the "Open" menu.
115 [default = TRUE]
117 WBAPPICONA_SupportsCopy (BOOL)
118 Set to TRUE if the AppIcon should respond to the "Copy" menu.
119 [default = FALSE]
121 WBAPPICONA_SupportsRename (BOOL)
122 Set to TRUE if the AppIcon should respond to the "Rename" menu.
123 [default = FALSE]
125 WBAPPICONA_SupportsInformation (BOOL)
126 Set to TRUE if the AppIcon should respond to the "Information" menu.
127 [default = FALSE]
129 WBAPPICONA_SupportsSnapshot (BOOL)
130 Set to TRUE if the AppIcon should respond to the "Snapshot" menu.
131 [default = FALSE]
133 WBAPPICONA_SupportsUnSnapshot (BOOL)
134 Set to TRUE if the AppIcon should respond to the "UnSnapshot" menu.
135 [default = FALSE]
137 WBAPPICONA_SupportsLeaveOut (BOOL)
138 Set to TRUE if the AppIcon should respond to the "Leave Out" menu.
139 [default = FALSE]
141 WBAPPICONA_SupportsPutAway (BOOL)
142 Set to TRUE if the AppIcon should respond to the "Put Away" menu.
143 [default = FALSE]
145 WBAPPICONA_SupportsDelete (BOOL)
146 Set to TRUE if the AppIcon should respond to the "Delete" menu.
147 [default = FALSE]
149 WBAPPICONA_SupportsFormatDisk (BOOL)
150 Set to TRUE if the AppIcon should respond to the "Format Disk" menu.
151 [default = FALSE]
153 WBAPPICONA_SupportsEmptyTrash (BOOL)
154 Set to TRUE if the AppIcon should respond to the "Empty Trash" menu.
155 [default = FALSE]
157 WBAPPICONA_PropagatePosition (BOOL)
158 Set to TRUE if the AppIcon's position should be updated in the DiskObject
159 passed to this function when the AppIcon is moved. If this is set to TRUE,
160 workbench.library will assume that the structure is not freed as long as
161 the AppIcon is alive.
162 [default = FALSE]
164 WBAPPICONA_RenderHook (struct Hook *)
165 Pointer to a hook that will be invoked when the AppIcon is rendered.
166 Using this hook and WorkbenchControlA() dynamic or animated AppIcons may
167 be created. The hook will be called with the following parameters:
169 result = hookFunc(hook, reserved, arm);
171 where the 'hookFunc' has the prototype
173 LONG hookFunc(struct Hook *hook, APTR reserved,
174 struct AppIconRenderMsg *arm);
176 If the hook function returns TRUE, the regular image of the AppIcon will
177 be drawn; if it returns FALSE, nothing will be drawn. This allows you to
178 do all the icon rendering except for when dragging the icon on the screen.
180 WBAPPICONA_NotifySelectState (BOOL)
181 When TRUE, you will be notificed whenever the AppIcon becomes selected or
182 unselected; the am_Class will be set to AMCLASSICON_Selected or
183 AMCLASSICON_Unselected.
185 RESULT
187 A pointer to an AppIcon structure -- which should be used with
188 RemoveAppIcon() when you want to remove the icon -- or NULL if it was
189 not possible to add the AppIcon.
191 NOTES
193 Contrary to AmigaOS, AppIcons may be added when there is no workbench
194 application running.
196 EXAMPLE
198 BUGS
200 SEE ALSO
202 RemoveAppIcon(), WorkbenchControlA(), DrawIconStateA()
204 INTERNALS
206 ******************************************************************************/
208 AROS_LIBFUNC_INIT
209 AROS_LIBBASE_EXT_DECL(struct WorkbenchBase *, WorkbenchBase)
211 struct TagItem *tagState = taglist;
212 struct TagItem *tag;
213 struct AppIcon *appIcon;
215 if (diskobj == NULL || msgport == NULL ||
216 diskobj->do_Gadget.GadgetRender == NULL)
218 return NULL;
221 appIcon = AllocVec(sizeof(struct AppIcon), MEMF_CLEAR | MEMF_ANY);
223 if (appIcon == NULL)
225 return NULL;
228 appIcon->ai_ID = id;
229 appIcon->ai_UserData = userdata;
230 appIcon->ai_Text = text;
231 appIcon->ai_MsgPort = msgport;
232 appIcon->ai_Flags = WBAPPICONF_SupportsOpen;
234 while ((tag = NextTagItem(&tagState)))
236 switch (tag->ti_Tag)
238 case WBAPPICONA_SupportsOpen:
239 if (tag->ti_Data == TRUE)
241 appIcon->ai_Flags |= WBAPPICONF_SupportsOpen;
243 break;
245 case WBAPPICONA_SupportsCopy:
246 if (tag->ti_Data == TRUE)
248 appIcon->ai_Flags |= WBAPPICONF_SupportsCopy;
250 break;
252 case WBAPPICONA_SupportsRename:
253 if (tag->ti_Data == TRUE)
255 appIcon->ai_Flags |= WBAPPICONF_SupportsRename;
257 break;
259 case WBAPPICONA_SupportsInformation:
260 if (tag->ti_Data == TRUE)
262 appIcon->ai_Flags |= WBAPPICONF_SupportsInformation;
264 break;
266 case WBAPPICONA_SupportsSnapshot:
267 if (tag->ti_Data == TRUE)
269 appIcon->ai_Flags |= WBAPPICONF_SupportsSnapshot;
271 break;
273 case WBAPPICONA_SupportsUnSnapshot:
274 if (tag->ti_Data == TRUE)
276 appIcon->ai_Flags |= WBAPPICONF_SupportsUnSnapshot;
278 break;
280 case WBAPPICONA_SupportsLeaveOut:
281 if (tag->ti_Data == TRUE)
283 appIcon->ai_Flags |= WBAPPICONF_SupportsLeaveOut;
285 break;
287 case WBAPPICONA_SupportsPutAway:
288 if (tag->ti_Data == TRUE)
290 appIcon->ai_Flags |= WBAPPICONF_SupportsPutAway;
292 break;
294 case WBAPPICONA_SupportsDelete:
295 if (tag->ti_Data == TRUE)
297 appIcon->ai_Flags |= WBAPPICONF_SupportsDelete;
299 break;
301 case WBAPPICONA_SupportsFormatDisk:
302 if (tag->ti_Data == TRUE)
304 appIcon->ai_Flags |= WBAPPICONF_SupportsFormatDisk;
306 break;
308 case WBAPPICONA_SupportsEmptyTrash:
309 if (tag->ti_Data == TRUE)
311 appIcon->ai_Flags |= WBAPPICONF_SupportsEmptyTrash;
313 break;
315 case WBAPPICONA_PropagatePosition:
316 if (tag->ti_Data == TRUE)
318 appIcon->ai_Flags |= WBAPPICONF_PropagatePosition;
320 break;
322 case WBAPPICONA_RenderHook:
323 if (appIcon->ai_RenderHook != NULL)
325 appIcon->ai_RenderHook = (struct Hook *)tag->ti_Data;
327 break;
329 case WBAPPICONA_NotifySelectState:
330 if (tag->ti_Data == TRUE)
332 appIcon->ai_Flags |= WBAPPICONF_NotifySelectState;
334 break;
338 if (appIcon->ai_Flags & WBAPPICONF_PropagatePosition)
340 appIcon->ai_DiskObject = DupDiskObject(diskobj, TAG_DONE);
342 if (appIcon->ai_DiskObject == NULL)
344 FreeVec(appIcon);
346 return NULL;
349 else
351 appIcon->ai_DiskObject = diskobj;
354 LockWorkbench();
355 AddTail(&WorkbenchBase->wb_AppIcons, (struct Node *)appIcon);
356 UnlockWorkbench();
359 NotifyWorkbench(WBNOTIFY_Create, WBNOTIFY_AppIcon, WorkbenchBase);
362 return appIcon;
364 AROS_LIBFUNC_EXIT
365 } /* AddAppIconA() */