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>
17 #include <interfaces/pm.h>
23 //----------------------------------------------------------------------------
25 // defined in pminit.c
26 extern struct ExecBase
*SysBase
;
28 // defined in pmversion.c
31 extern const CONST_APTR VecTable68K
[];
33 //----------------------------------------------------------------------------
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
,
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
);
81 /* ------------------- OS4 Manager Interface ------------------------ */
82 static const APTR managerfunctable
[] =
95 static const struct TagItem managertags
[] =
97 {MIT_Name
, (ULONG
)"__library"},
98 {MIT_VectorTable
, (ULONG
)managerfunctable
},
103 /* ---------------------- OS4 Main Interface ------------------------ */
104 static APTR functable
[] =
115 LIBPM_OpenPopupMenuA
,
126 LIBPM_OBSOLETEFilterIMsgA
,
131 LIBPM_InsertMenuItemA
,
132 LIBPM_InsertMenuItem
,
133 LIBPM_RemoveMenuItem
,
145 static const struct TagItem maintags
[] =
147 {MIT_Name
, (ULONG
)"main"},
148 {MIT_VectorTable
, (ULONG
)functable
},
153 /* Init table used in library initialization. */
154 static const ULONG interfaces
[] =
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
},
172 struct Resident ALIGNED romtag
=
177 RTF_NATIVE
| RTF_AUTOINIT
,
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
;
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
);
216 PMLibBase
->pmb_Library
.lib_Flags
|= LIBF_DELEXP
;
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
))
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);
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
;
270 va_startlinear(args
, self
); // self is always the first argument
274 ret
= ((struct PopupMenuIFace
*)self
)->PM_MakeMenuA(va_getlinearva(args
, struct TagItem
*));
282 LIBFUNC_P1VA(struct PopupMenu
*, LIBPM_MakeItem
,
283 A6
, struct PopupMenuBase
*, PopupMenuBase
)
285 struct PopupMenu
*ret
;
287 va_startlinear(args
, self
); // self is always the first argument
291 ret
= ((struct PopupMenuIFace
*)self
)->PM_MakeItemA(va_getlinearva(args
, struct TagItem
*));
299 LIBFUNC_P1VA(struct PM_IDLst
*, LIBPM_MakeIDList
,
300 A6
, struct PopupMenuBase
*, PopupMenuBase
)
302 struct PM_IDLst
*ret
;
304 va_startlinear(args
, self
); // self is always the first argument
308 ret
= ((struct PopupMenuIFace
*)self
)->PM_MakeIDListA(va_getlinearva(args
, struct TagItem
*));
316 LIBFUNC_P2VA(ULONG
, LIBPM_OpenPopupMenu
,
317 A1
, struct Window
*, wnd
,
318 A6
, struct PopupMenuBase
*, PopupMenuBase
)
322 va_startlinear(args
, wnd
);
326 ret
= ((struct PopupMenuIFace
*)self
)->PM_OpenPopupMenuA(wnd
, va_getlinearva(args
, struct TagItem
*));
334 LIBFUNC_P2VA(LONG
, LIBPM_GetItemAttrs
,
335 A2
, struct PopupMenu
*, item
,
336 A6
, struct PopupMenuBase
*, PopupMenuBase
)
340 va_startlinear(args
, item
);
344 ret
= ((struct PopupMenuIFace
*)self
)->PM_GetItemAttrsA(item
, va_getlinearva(args
, struct TagItem
*));
352 LIBFUNC_P2VA(LONG
, LIBPM_SetItemAttrs
,
353 A2
, struct PopupMenu
*, item
,
354 A6
, struct PopupMenuBase
*, PopupMenuBase
)
358 va_startlinear(args
, item
);
362 ret
= ((struct PopupMenuIFace
*)self
)->PM_SetItemAttrsA(item
, va_getlinearva(args
, struct TagItem
*));
370 LIBFUNC_P2VA(struct PM_IDLst
*, LIBPM_ExLst
,
372 A6
, struct PopupMenuBase
*, PopupMenuBase
)
374 struct PM_IDLst
*ret
;
376 va_startlinear(args
, id
);
380 ret
= ((struct PopupMenuIFace
*)self
)->PM_ExLstA(&id
);
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
)
396 va_startlinear(args
, imsg
);
400 ret
= ((struct PopupMenuIFace
*)self
)->PM_FilterIMsgA(window
, menu
, imsg
, va_getlinearva(args
, struct TagItem
*));
408 LIBFUNC_P3VA(LONG
, LIBPM_LayoutMenu
,
409 A0
, struct Window
*, window
,
410 A1
, struct PopupMenu
*, menu
,
411 A6
, struct PopupMenuBase
*, PopupMenuBase
);
415 va_startlinear(args
, menu
);
419 ret
= ((struct PopupMenuIFace
*)self
)->PM_LayoutMenuA(window
, menu
, va_getlinearva(args
, struct TagItem
*));
427 LIBFUNC_P2VA(LONG
, LIBPM_InsertMenuItem
,
428 A2
, struct PopupMenu
*, base
,
429 A6
, struct PopupMenuBase
*, PopupMenuBase
)
433 va_startlinear(args
, base
);
437 ret
= ((struct PopupMenuIFace
*)self
)->PM_InsertMenuItemA(base
, va_getlinearva(args
, struct TagItem
*));