Some fix for scrolling with lasso.
[tangerine.git] / rom / workbench / addappmenuitema.c
blobc6e8954a98eb695d4689c5d5deedf4fc3ccefab8
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Add a menuitem to Workbench's list of AppMenuItems.
6 */
9 #include <string.h>
11 #include <exec/types.h>
12 #include <exec/ports.h>
13 #include <utility/tagitem.h>
15 #include "workbench_intern.h"
16 #include <workbench/workbench.h>
17 #include <proto/utility.h>
19 BOOL keyUsed(STRPTR key, struct WorkbenchBase *WorkbenchBase);
21 /*****************************************************************************
23 NAME */
24 #include <proto/workbench.h>
26 AROS_LH5(struct AppMenuItem *, AddAppMenuItemA,
27 /* SYNOPSIS */
28 AROS_LHA(ULONG , id , D0),
29 AROS_LHA(ULONG , userdata, D1),
30 AROS_LHA(APTR , text , A0),
31 AROS_LHA(struct MsgPort *, msgport , A1),
32 AROS_LHA(struct TagItem *, taglist , A3),
34 /* LOCATION */
35 struct WorkbenchBase *, WorkbenchBase, 12, Workbench)
37 /* FUNCTION
39 Try to add a menu item to workbench.library's list of AppMenuItems (this
40 will be shown in the 'Tools' menu strip in Workbench).
42 INPUTS
44 id -- menu item identifier; for your convenience (ignored by
45 workbench.library)
46 userdata -- user specific data (ignored by workbench.library)
47 text -- menu item text; any text consisting merely of '-','_' and
48 '~' characters corresponds to a separator bar instead of
49 a textual item
50 msgport -- port to which notification messages regarding the menu
51 item will be sent
52 taglist -- tags (see below)
54 TAGS
56 WBAPPMENUA_CommandKeyString (STRPTR)
57 Command key assigned to this menu item. If the string is empty, it will
58 be ignored as will it if the command key is already in use by another
59 menu item. Only the first character of the string will be used.
60 [default = NULL]
62 RESULT
64 A pointer to an AppMenuItem which you pass to RemoveAppMenuItem() when
65 you want to remove the menu item. If it was not possible to add the menu
66 item, NULL will be returned.
68 NOTES
70 Contrary to AmigaOS, this function will report success even when there
71 is no running workbench application.
73 EXAMPLE
75 BUGS
77 SEE ALSO
79 RemoveAppMenuItem()
81 INTERNALS
83 ******************************************************************************/
85 AROS_LIBFUNC_INIT
86 AROS_LIBBASE_EXT_DECL(struct WorkbenchBase *, WorkbenchBase)
88 struct TagItem *tagState = taglist;
89 struct TagItem *tag;
91 struct AppMenuItem *appMenuItem;
93 appMenuItem = AllocVec(sizeof(struct AppMenuItem), MEMF_ANY | MEMF_CLEAR);
95 if (appMenuItem == NULL)
97 return NULL;
100 appMenuItem->ami_ID = id;
101 appMenuItem->ami_UserData = userdata;
102 appMenuItem->ami_Text = text;
103 appMenuItem->ami_MsgPort = msgport;
105 while ((tag = NextTagItem(&tagState)))
107 switch (tag->ti_Tag)
109 case WBAPPMENUA_CommandKeyString:
111 STRPTR key = (STRPTR)tag->ti_Data;
113 if (keyUsed(key, WorkbenchBase))
115 appMenuItem->ami_CommandKey = "";
117 else
119 appMenuItem->ami_CommandKey = key;
122 break;
127 LockWorkbench();
128 AddTail(&(WorkbenchBase->wb_AppMenuItems), (struct Node *)appMenuItem);
129 UnlockWorkbench();
131 /* NotifyWorkbench(WBNOTIFY_Create, WBNOTIFY_AppMenuItem, WorkbenchBase);
134 return appMenuItem;
136 AROS_LIBFUNC_EXIT
137 } /* AddAppMenuItemA */
140 BOOL keyUsed(STRPTR key, struct WorkbenchBase *WorkbenchBase)
142 struct AppMenuItem *ami;
143 BOOL found = FALSE;
145 if (strlen(key) == 0)
147 return FALSE;
150 LockWorkbench();
152 ForeachNode(&WorkbenchBase->wb_AppMenuItems, ami)
154 if (strlen(ami->ami_CommandKey) != 0 &&
155 ami->ami_CommandKey[0] == key[0])
157 found = TRUE;
158 break;
162 UnlockWorkbench();
164 return found;