forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / scalos / libraries / popupmenu / popupmenu-aos4.c
blobf0f42a79b5c1a503fb647194bf0c2a18fab4ea0d
1 // popupmenu-aos4.c
2 // $Date$
3 // $Revision$
5 #include <exec/interfaces.h>
6 #include <exec/emulation.h>
7 #include <exec/exectags.h>
8 #include <exec/resident.h>
9 #include <intuition/intuition.h>
11 #include <proto/exec.h>
13 #ifdef __USE_INLINE__
14 #undef __USE_INLINE__
15 #endif
17 #include <interfaces/pm.h>
19 #include <stdarg.h>
21 #include "pmpriv.h"
23 //----------------------------------------------------------------------------
25 // defined in pminit.c
26 extern struct ExecBase *SysBase;
28 // defined in pmversion.c
29 extern char _LibID[];
31 extern const CONST_APTR VecTable68K[];
33 //----------------------------------------------------------------------------
35 int _start(void)
37 return -1;
40 static struct Library *Initlib(struct Library *libbase, BPTR seglist, struct ExecIFace *pIExec);
41 static BPTR Expungelib(struct LibraryManagerInterface *Self);
42 static struct LibraryHeader *Openlib(struct LibraryManagerInterface *Self, ULONG version);
43 static BPTR Closelib(struct LibraryManagerInterface *Self);
44 static ULONG Obtainlib(struct LibraryManagerInterface *Self);
45 static ULONG Releaselib(struct LibraryManagerInterface *Self);
47 LIBFUNC_P1VA_PROTO(struct PopupMenu *, LIBPM_MakeMenu,
48 A6, struct PopupMenuBase *, PopupMenuBase);
49 LIBFUNC_P1VA_PROTO(struct PopupMenu *, LIBPM_MakeItem,
50 A6, struct PopupMenuBase *, PopupMenuBase);
51 LIBFUNC_P1VA_PROTO(struct PM_IDLst *, LIBPM_MakeIDList,
52 A6, struct PopupMenuBase *, PopupMenuBase);
54 LIBFUNC_P2VA_PROTO(ULONG, LIBPM_OpenPopupMenu,
55 A1, struct Window *, wnd,
56 A6, struct PopupMenuBase *, PopupMenuBase);
57 LIBFUNC_P2VA_PROTO(LONG, LIBPM_GetItemAttrs,
58 A2, struct PopupMenu *, item,
59 A6, struct PopupMenuBase *, PopupMenuBase);
60 LIBFUNC_P2VA_PROTO(LONG, LIBPM_SetItemAttrs,
61 A2, struct PopupMenu *, item,
62 A6, struct PopupMenuBase *, PopupMenuBase);
63 LIBFUNC_P2VA_PROTO(struct PM_IDLst *, LIBPM_ExLst,
64 A1, ULONG, id,
65 A6, struct PopupMenuBase *, PopupMenuBase);
66 LIBFUNC_P4VA_PROTO(APTR, LIBPM_FilterIMsg,
67 A0, struct Window *, window,
68 A1, struct PopupMenu *, menu,
69 A2, struct IntuiMessage *, imsg,
70 A6, struct PopupMenuBase *, PopupMenuBase);
71 LIBFUNC_P3VA_PROTO(LONG, LIBPM_LayoutMenu,
72 A0, struct Window *, window,
73 A1, struct PopupMenu *, menu,
74 A6, struct PopupMenuBase *, PopupMenuBase);
75 LIBFUNC_P2VA_PROTO(LONG, LIBPM_InsertMenuItem,
76 A2, struct PopupMenu *, base,
77 A6, struct PopupMenuBase *, l);
79 /* OS4.0 Library */
81 /* ------------------- OS4 Manager Interface ------------------------ */
82 static const APTR managerfunctable[] =
84 (APTR)Obtainlib,
85 (APTR)Releaselib,
86 (APTR)NULL,
87 (APTR)NULL,
88 (APTR)Openlib,
89 (APTR)Closelib,
90 (APTR)Expungelib,
91 (APTR)NULL,
92 (APTR)-1
95 static const struct TagItem managertags[] =
97 {MIT_Name, (ULONG)"__library"},
98 {MIT_VectorTable, (ULONG)managerfunctable},
99 {MIT_Version, 1},
100 {TAG_DONE, 0}
103 /* ---------------------- OS4 Main Interface ------------------------ */
104 static APTR functable[] =
106 Obtainlib,
107 Releaselib,
108 NULL,
109 NULL,
110 LIBPM_MakeMenuA,
111 LIBPM_MakeMenu,
112 LIBPM_MakeItemA,
113 LIBPM_MakeItem,
114 LIBPM_FreePopupMenu,
115 LIBPM_OpenPopupMenuA,
116 LIBPM_OpenPopupMenu,
117 LIBPM_MakeIDListA,
118 LIBPM_MakeIDList,
119 LIBPM_ItemChecked,
120 LIBPM_GetItemAttrsA,
121 LIBPM_GetItemAttrs,
122 LIBPM_SetItemAttrsA,
123 LIBPM_SetItemAttrs,
124 LIBPM_FindItem,
125 LIBPM_AlterState,
126 LIBPM_OBSOLETEFilterIMsgA,
127 LIBPM_ExLstA,
128 LIBPM_ExLst,
129 LIBPM_FilterIMsgA,
130 LIBPM_FilterIMsg,
131 LIBPM_InsertMenuItemA,
132 LIBPM_InsertMenuItem,
133 LIBPM_RemoveMenuItem,
134 LIBPM_AbortHook,
135 LIBPM_GetVersion,
136 LIBPM_ReloadPrefs,
137 LIBPM_LayoutMenuA,
138 LIBPM_LayoutMenu,
139 LIBPM_RESERVED1,
140 LIBPM_FreeIDList,
142 (APTR) -1
145 static const struct TagItem maintags[] =
147 {MIT_Name, (ULONG)"main"},
148 {MIT_VectorTable, (ULONG)functable},
149 {MIT_Version, 1},
150 {TAG_DONE, 0}
153 /* Init table used in library initialization. */
154 static const ULONG interfaces[] =
156 (ULONG)managertags,
157 (ULONG)maintags,
158 (ULONG)0
161 static const struct TagItem inittab[] =
163 {CLT_DataSize, (ULONG)sizeof(struct PopupMenuBase)},
164 {CLT_Interfaces, (ULONG) interfaces},
165 {CLT_Vector68K, (ULONG)VecTable68K},
166 {CLT_InitFunc, (ULONG) Initlib},
167 {TAG_DONE, 0}
171 /* The ROM tag */
172 struct Resident ALIGNED romtag =
174 RTC_MATCHWORD,
175 &romtag,
176 &romtag + 1,
177 RTF_NATIVE | RTF_AUTOINIT,
178 POPUPMENU_VERSION,
179 NT_LIBRARY,
181 POPUPMENU_NAME,
182 (char *)_LibID,
183 (APTR)inittab
186 /* ------------------- OS4 Manager Functions ------------------------ */
187 static struct Library * Initlib(struct Library *libbase, BPTR seglist, struct ExecIFace *pIExec)
189 struct PopupMenuBase *PMLibBase = (struct PopupMenuBase *) libbase;
190 // struct ExtendedLibrary *ExtLib = (struct ExtendedLibrary *) ((ULONG)libbase + libbase->lib_PosSize);
191 // struct LibraryManagerInterface *Self = (struct LibraryManagerInterface *) ExtLib->ILibrary;
193 SysBase = (struct ExecBase *)pIExec->Data.LibBase;
194 IExec = pIExec;
195 PMLibBase->pmb_Library.lib_Revision = POPUPMENU_REVISION;
196 PMLibBase->pmb_SegList = seglist;
198 return PMLibBase ? &PMLibBase->pmb_Library : NULL;
201 static BPTR Expungelib(struct LibraryManagerInterface *Self)
203 struct PopupMenuBase *PMLibBase = (struct PopupMenuBase *) Self->Data.LibBase;
205 if (0 == PMLibBase->pmb_Library.lib_OpenCnt)
207 BPTR libseglist = PMLibBase->pmb_SegList;
209 Remove((struct Node *) PMLibBase);
210 PMLibCleanup(PMLibBase);
211 DeleteLibrary((struct Library *)PMLibBase);
213 return libseglist;
216 PMLibBase->pmb_Library.lib_Flags |= LIBF_DELEXP;
218 return (BPTR)NULL;
221 static struct LibraryHeader *Openlib(struct LibraryManagerInterface *Self, ULONG version)
223 struct PopupMenuBase *PMLibBase = (struct PopupMenuBase *) Self->Data.LibBase;
225 PMLibBase->pmb_Library.lib_OpenCnt++;
226 PMLibBase->pmb_Library.lib_Flags &= ~LIBF_DELEXP;
228 if (!PMLibInit(PMLibBase))
230 Closelib(Self);
231 return NULL;
234 return (struct LibraryHeader *)&PMLibBase->pmb_Library;
237 static BPTR Closelib(struct LibraryManagerInterface *Self)
239 struct PopupMenuBase *PMLibBase = (struct PopupMenuBase *) Self->Data.LibBase;
241 PMLibBase->pmb_Library.lib_OpenCnt--;
243 if (0 == PMLibBase->pmb_Library.lib_OpenCnt)
245 if (PMLibBase->pmb_Library.lib_Flags & LIBF_DELEXP)
247 return Expungelib(Self);
251 return (BPTR)NULL;
254 static ULONG Obtainlib(struct LibraryManagerInterface *Self)
256 return(Self->Data.RefCount++);
259 static ULONG Releaselib(struct LibraryManagerInterface *Self)
261 return(Self->Data.RefCount--);
264 /* ------------------- OS4 Varargs Functions ------------------------ */
265 LIBFUNC_P1VA(struct PopupMenu *, LIBPM_MakeMenu,
266 A6, struct PopupMenuBase *, PopupMenuBase)
268 struct PopupMenu *ret;
269 va_list args;
270 va_startlinear(args, self); // self is always the first argument
272 (void)PopupMenuBase;
274 ret = ((struct PopupMenuIFace *)self)->PM_MakeMenuA(va_getlinearva(args, struct TagItem *));
276 va_end(args);
278 return(ret);
280 LIBFUNC_END
282 LIBFUNC_P1VA(struct PopupMenu *, LIBPM_MakeItem,
283 A6, struct PopupMenuBase *, PopupMenuBase)
285 struct PopupMenu *ret;
286 va_list args;
287 va_startlinear(args, self); // self is always the first argument
289 (void)PopupMenuBase;
291 ret = ((struct PopupMenuIFace *)self)->PM_MakeItemA(va_getlinearva(args, struct TagItem *));
293 va_end(args);
295 return(ret);
297 LIBFUNC_END
299 LIBFUNC_P1VA(struct PM_IDLst *, LIBPM_MakeIDList,
300 A6, struct PopupMenuBase *, PopupMenuBase)
302 struct PM_IDLst *ret;
303 va_list args;
304 va_startlinear(args, self); // self is always the first argument
306 (void)PopupMenuBase;
308 ret = ((struct PopupMenuIFace *)self)->PM_MakeIDListA(va_getlinearva(args, struct TagItem *));
310 va_end(args);
312 return(ret);
314 LIBFUNC_END
316 LIBFUNC_P2VA(ULONG, LIBPM_OpenPopupMenu,
317 A1, struct Window *, wnd,
318 A6, struct PopupMenuBase *, PopupMenuBase)
320 ULONG ret;
321 va_list args;
322 va_startlinear(args, wnd);
324 (void)PopupMenuBase;
326 ret = ((struct PopupMenuIFace *)self)->PM_OpenPopupMenuA(wnd, va_getlinearva(args, struct TagItem *));
328 va_end(args);
330 return(ret);
332 LIBFUNC_END
334 LIBFUNC_P2VA(LONG, LIBPM_GetItemAttrs,
335 A2, struct PopupMenu *, item,
336 A6, struct PopupMenuBase *, PopupMenuBase)
338 LONG ret;
339 va_list args;
340 va_startlinear(args, item);
342 (void)PopupMenuBase;
344 ret = ((struct PopupMenuIFace *)self)->PM_GetItemAttrsA(item, va_getlinearva(args, struct TagItem *));
346 va_end(args);
348 return(ret);
350 LIBFUNC_END
352 LIBFUNC_P2VA(LONG, LIBPM_SetItemAttrs,
353 A2, struct PopupMenu *, item,
354 A6, struct PopupMenuBase *, PopupMenuBase)
356 LONG ret;
357 va_list args;
358 va_startlinear(args, item);
360 (void)PopupMenuBase;
362 ret = ((struct PopupMenuIFace *)self)->PM_SetItemAttrsA(item, va_getlinearva(args, struct TagItem *));
364 va_end(args);
366 return(ret);
368 LIBFUNC_END
370 LIBFUNC_P2VA(struct PM_IDLst *, LIBPM_ExLst,
371 A1, ULONG, id,
372 A6, struct PopupMenuBase *, PopupMenuBase)
374 struct PM_IDLst *ret;
375 va_list args;
376 va_startlinear(args, id);
378 (void)PopupMenuBase;
380 ret = ((struct PopupMenuIFace *)self)->PM_ExLstA(&id);
382 va_end(args);
384 return(ret);
386 LIBFUNC_END
388 LIBFUNC_P4VA(APTR, LIBPM_FilterIMsg,
389 A0, struct Window *, window,
390 A1, struct PopupMenu *, menu,
391 A2, struct IntuiMessage *, imsg,
392 A6, struct PopupMenuBase *, PopupMenuBase)
394 APTR ret;
395 va_list args;
396 va_startlinear(args, imsg);
398 (void)PopupMenuBase;
400 ret = ((struct PopupMenuIFace *)self)->PM_FilterIMsgA(window, menu, imsg, va_getlinearva(args, struct TagItem *));
402 va_end(args);
404 return(ret);
406 LIBFUNC_END
408 LIBFUNC_P3VA(LONG, LIBPM_LayoutMenu,
409 A0, struct Window *, window,
410 A1, struct PopupMenu *, menu,
411 A6, struct PopupMenuBase *, PopupMenuBase);
413 LONG ret;
414 va_list args;
415 va_startlinear(args, menu);
417 (void)PopupMenuBase;
419 ret = ((struct PopupMenuIFace *)self)->PM_LayoutMenuA(window, menu, va_getlinearva(args, struct TagItem *));
421 va_end(args);
423 return(ret);
425 LIBFUNC_END
427 LIBFUNC_P2VA(LONG, LIBPM_InsertMenuItem,
428 A2, struct PopupMenu *, base,
429 A6, struct PopupMenuBase *, PopupMenuBase)
431 LONG ret;
432 va_list args;
433 va_startlinear(args, base);
435 (void)PopupMenuBase;
437 ret = ((struct PopupMenuIFace *)self)->PM_InsertMenuItemA(base, va_getlinearva(args, struct TagItem *));
439 va_end(args);
441 return(ret);
443 LIBFUNC_END