Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / Wanderer / appobjects.c
blob084486f9d8bb446f9dd892be33efd8b890a13709
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "appobjects.h"
8 #include <proto/workbench.h>
9 #include <proto/exec.h>
10 #include <proto/alib.h>
11 #include <aros/symbolsets.h>
14 * Wanderer needs access to internals of workbench.library to provided needed functionality.
15 * In general, "workbench replacements" needs to provide their own workbench.library or patch the
16 * existing one. All Wanderer code should treat the internals of workbench.library as READ-ONLY.
17 * Only this compilation unit may access the workbench.library internals.
20 #include "../../libs/workbench/workbench_intern.h"
23 static struct MsgPort * replyport = NULL;
26 * Assumes lock in already acquired. Returns pointer to AppIcon from workbench.library list, if the passed
27 * pointer is actually on the list.
29 STATIC struct AppIcon * FindAppIconByPtr(struct AppIcon * appicon)
31 struct AppIcon * entry = NULL;
32 ForeachNode(&LB(WorkbenchBase)->wb_AppIcons, entry)
34 if (entry == appicon)
35 return entry;
38 return NULL;
41 BOOL SendAppIconMessage(struct AppIcon * appicon, LONG numargs, STRPTR args)
43 BOOL success = FALSE;
45 if (!appicon)
46 return success;
48 if ((numargs == 0) && (args == NULL))
49 return SendAppIconMenuMessage(appicon, AMCLASSICON_Open);
51 /* TODO: Handle the case when icons are dropped on appicon */
52 return success;
55 BOOL SendAppIconMenuMessage(struct AppIcon * appicon, UWORD class)
57 struct AppMessage * msg = NULL;
58 BOOL success = FALSE;
59 struct AppIcon * entry = NULL;
61 if (!appicon)
62 return success;
64 LockWorkbench();
66 /* Check is passed entry is valid */
67 if ((entry = FindAppIconByPtr(appicon)) != NULL)
69 struct MsgPort *port = entry->ai_MsgPort;
71 msg = AllocVec(sizeof(struct AppMessage), MEMF_CLEAR);
73 if (msg)
75 msg->am_Type = AMTYPE_APPICON;
76 msg->am_ArgList = NULL;
77 msg->am_NumArgs = 0;
78 msg->am_ID = entry->ai_ID;
79 msg->am_UserData = entry->ai_UserData;
80 msg->am_Version = AM_VERSION;
81 msg->am_Class = class;
83 msg->am_Message.mn_ReplyPort = replyport;
84 PutMsg(port, (struct Message *) msg);
85 success = TRUE;
89 UnlockWorkbench();
91 return success;
94 VOID CleanAppIconReplyMessages()
96 struct Message * msg = NULL;
98 while ((msg = GetMsg(replyport))) FreeVec(msg);
101 APTR AppObjectsLock()
103 static LONG lock = 1;
105 LockWorkbench();
107 return (APTR)&lock;
110 VOID AppObjectsUnlock(APTR lock)
112 UnlockWorkbench();
115 /* Assumes lock is already held */
116 struct AppIcon * GetNextAppIconLocked(struct AppIcon * lastappicon, APTR lock)
118 struct List *appiconlist = &LB(WorkbenchBase)->wb_AppIcons;
120 /* return NULL if list empty or argument dob is already from last appicon in list*/
121 if (!IsListEmpty(appiconlist))
123 struct AppIcon * _return = NULL;
125 /* return NULL if last entry reached */
126 if (lastappicon == (struct AppIcon *)appiconlist->lh_TailPred)
127 return NULL;
129 _return = FindAppIconByPtr(lastappicon);
131 if (_return)
133 /* Return next */
134 return (struct AppIcon *)GetSucc((struct Node *)_return);
136 else
138 /* Return first */
139 return (struct AppIcon *)appiconlist->lh_Head;
143 return NULL;
146 struct DiskObject * AppIcon_GetDiskObject(struct AppIcon * appicon)
148 struct AppIcon * entry = NULL;
149 struct DiskObject * _return = NULL;
151 LockWorkbench();
153 entry = FindAppIconByPtr(appicon);
155 if (entry)
156 _return = entry->ai_DiskObject;
158 UnlockWorkbench();
160 return _return;
163 CONST_STRPTR AppIcon_GetLabel(struct AppIcon * appicon)
165 struct AppIcon * entry = NULL;
166 CONST_STRPTR _return = NULL;
168 LockWorkbench();
170 entry = FindAppIconByPtr(appicon);
172 if (entry)
173 _return = entry->ai_Text;
175 UnlockWorkbench();
177 return _return;
180 BOOL AppIcon_Supports(struct AppIcon * appicon, ULONG tag)
182 BOOL _return = FALSE;
183 /* This is a low-risk function, query passed object directly */
184 switch(tag)
186 case(WBAPPICONA_SupportsOpen): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsOpen); break;
187 case(WBAPPICONA_SupportsCopy): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsCopy); break;
188 case(WBAPPICONA_SupportsRename): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsRename); break;
189 case(WBAPPICONA_SupportsInformation): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsInformation); break;
190 case(WBAPPICONA_SupportsSnapshot): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsSnapshot); break;
191 case(WBAPPICONA_SupportsUnSnapshot): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsUnSnapshot); break;
192 case(WBAPPICONA_SupportsLeaveOut): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsLeaveOut); break;
193 case(WBAPPICONA_SupportsPutAway): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsPutAway); break;
194 case(WBAPPICONA_SupportsDelete): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsDelete); break;
195 case(WBAPPICONA_SupportsFormatDisk): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsFormatDisk); break;
196 case(WBAPPICONA_SupportsEmptyTrash): _return = !!(appicon->ai_Flags & WBAPPICONF_SupportsEmptyTrash); break;
197 case(WBAPPICONA_PropagatePosition): _return = !!(appicon->ai_Flags & WBAPPICONF_PropagatePosition); break;
198 case(WBAPPICONA_RenderHook): _return = (appicon->ai_RenderHook != NULL); break;
200 return _return;
203 BOOL AppIcon_CallRenderHook(struct AppIcon * appicon, struct AppIconRenderMsg * msg)
205 struct AppIcon * entry = NULL;
207 LockWorkbench();
209 entry = FindAppIconByPtr(appicon);
211 if (entry && entry->ai_RenderHook)
212 CallHookA(entry->ai_RenderHook, NULL, msg);
214 UnlockWorkbench();
216 if (entry && entry->ai_RenderHook)
217 return TRUE;
218 else
219 return FALSE;
222 LONG AppObjects_Init()
224 replyport = CreateMsgPort();
226 return 1;
229 ADD2INIT(AppObjects_Init, 0);