2 Copyright © 2011, The AROS Development Team. All rights reserved.
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
)
41 BOOL
SendAppIconMessage(struct AppIcon
* appicon
, LONG numargs
, STRPTR args
)
48 if ((numargs
== 0) && (args
== NULL
))
49 return SendAppIconMenuMessage(appicon
, AMCLASSICON_Open
);
51 /* TODO: Handle the case when icons are dropped on appicon */
55 BOOL
SendAppIconMenuMessage(struct AppIcon
* appicon
, UWORD
class)
57 struct AppMessage
* msg
= NULL
;
59 struct AppIcon
* entry
= NULL
;
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
);
75 msg
->am_Type
= AMTYPE_APPICON
;
76 msg
->am_ArgList
= NULL
;
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
);
94 VOID
CleanAppIconReplyMessages()
96 struct Message
* msg
= NULL
;
98 while ((msg
= GetMsg(replyport
))) FreeVec(msg
);
101 APTR
AppObjectsLock()
103 static LONG lock
= 1;
110 VOID
AppObjectsUnlock(APTR lock
)
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
)
129 _return
= FindAppIconByPtr(lastappicon
);
134 return (struct AppIcon
*)GetSucc((struct Node
*)_return
);
139 return (struct AppIcon
*)appiconlist
->lh_Head
;
146 struct DiskObject
* AppIcon_GetDiskObject(struct AppIcon
* appicon
)
148 struct AppIcon
* entry
= NULL
;
149 struct DiskObject
* _return
= NULL
;
153 entry
= FindAppIconByPtr(appicon
);
156 _return
= entry
->ai_DiskObject
;
163 CONST_STRPTR
AppIcon_GetLabel(struct AppIcon
* appicon
)
165 struct AppIcon
* entry
= NULL
;
166 CONST_STRPTR _return
= NULL
;
170 entry
= FindAppIconByPtr(appicon
);
173 _return
= entry
->ai_Text
;
180 BOOL
AppIcon_Supports(struct AppIcon
* appicon
, ULONG tag
)
182 BOOL _return
= FALSE
;
183 /* This is a low-risk function, query passed object directly */
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;
203 BOOL
AppIcon_CallRenderHook(struct AppIcon
* appicon
, struct AppIconRenderMsg
* msg
)
205 struct AppIcon
* entry
= NULL
;
209 entry
= FindAppIconByPtr(appicon
);
211 if (entry
&& entry
->ai_RenderHook
)
212 CallHookA(entry
->ai_RenderHook
, NULL
, msg
);
216 if (entry
&& entry
->ai_RenderHook
)
222 LONG
AppObjects_Init()
224 replyport
= CreateMsgPort();
229 ADD2INIT(AppObjects_Init
, 0);