Make sure Locale dirs exsit before copying icons to them.
[cake.git] / rom / workbench / addappicona.c
bloba1a6f9e83eacc6e6eba421fc730f50a446671567
1 /*
2 Copyright © 1995-2007, 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(), icon.library/DrawIconStateA()
204 INTERNALS
206 ******************************************************************************/
208 AROS_LIBFUNC_INIT
210 const struct TagItem *tagState = taglist;
211 const struct TagItem *tag;
212 struct AppIcon *appIcon;
214 if (diskobj == NULL || msgport == NULL ||
215 diskobj->do_Gadget.GadgetRender == NULL)
217 return NULL;
220 appIcon = AllocVec(sizeof(struct AppIcon), MEMF_CLEAR | MEMF_ANY);
222 if (appIcon == NULL)
224 return NULL;
227 appIcon->ai_ID = id;
228 appIcon->ai_UserData = userdata;
229 appIcon->ai_Text = text;
230 appIcon->ai_MsgPort = msgport;
231 appIcon->ai_Flags = WBAPPICONF_SupportsOpen;
233 while ((tag = NextTagItem(&tagState)))
235 switch (tag->ti_Tag)
237 case WBAPPICONA_SupportsOpen:
238 if (tag->ti_Data)
240 appIcon->ai_Flags |= WBAPPICONF_SupportsOpen;
242 break;
244 case WBAPPICONA_SupportsCopy:
245 if (tag->ti_Data)
247 appIcon->ai_Flags |= WBAPPICONF_SupportsCopy;
249 break;
251 case WBAPPICONA_SupportsRename:
252 if (tag->ti_Data)
254 appIcon->ai_Flags |= WBAPPICONF_SupportsRename;
256 break;
258 case WBAPPICONA_SupportsInformation:
259 if (tag->ti_Data)
261 appIcon->ai_Flags |= WBAPPICONF_SupportsInformation;
263 break;
265 case WBAPPICONA_SupportsSnapshot:
266 if (tag->ti_Data)
268 appIcon->ai_Flags |= WBAPPICONF_SupportsSnapshot;
270 break;
272 case WBAPPICONA_SupportsUnSnapshot:
273 if (tag->ti_Data)
275 appIcon->ai_Flags |= WBAPPICONF_SupportsUnSnapshot;
277 break;
279 case WBAPPICONA_SupportsLeaveOut:
280 if (tag->ti_Data)
282 appIcon->ai_Flags |= WBAPPICONF_SupportsLeaveOut;
284 break;
286 case WBAPPICONA_SupportsPutAway:
287 if (tag->ti_Data)
289 appIcon->ai_Flags |= WBAPPICONF_SupportsPutAway;
291 break;
293 case WBAPPICONA_SupportsDelete:
294 if (tag->ti_Data)
296 appIcon->ai_Flags |= WBAPPICONF_SupportsDelete;
298 break;
300 case WBAPPICONA_SupportsFormatDisk:
301 if (tag->ti_Data)
303 appIcon->ai_Flags |= WBAPPICONF_SupportsFormatDisk;
305 break;
307 case WBAPPICONA_SupportsEmptyTrash:
308 if (tag->ti_Data)
310 appIcon->ai_Flags |= WBAPPICONF_SupportsEmptyTrash;
312 break;
314 case WBAPPICONA_PropagatePosition:
315 if (tag->ti_Data)
317 appIcon->ai_Flags |= WBAPPICONF_PropagatePosition;
319 break;
321 case WBAPPICONA_RenderHook:
322 if (appIcon->ai_RenderHook != NULL)
324 appIcon->ai_RenderHook = (struct Hook *)tag->ti_Data;
326 break;
328 case WBAPPICONA_NotifySelectState:
329 if (tag->ti_Data)
331 appIcon->ai_Flags |= WBAPPICONF_NotifySelectState;
333 break;
337 if (appIcon->ai_Flags & WBAPPICONF_PropagatePosition)
339 appIcon->ai_DiskObject = DupDiskObject(diskobj, TAG_DONE);
341 if (appIcon->ai_DiskObject == NULL)
343 FreeVec(appIcon);
345 return NULL;
348 else
350 appIcon->ai_DiskObject = diskobj;
353 LockWorkbench();
354 AddTail(&WorkbenchBase->wb_AppIcons, (struct Node *)appIcon);
355 UnlockWorkbench();
358 NotifyWorkbench(WBNOTIFY_Create, WBNOTIFY_AppIcon, WorkbenchBase);
361 return appIcon;
363 AROS_LIBFUNC_EXIT
364 } /* AddAppIconA() */