Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / libraries / popupmenu / popupmenu-classic.c
blob7b618344ec456d7e590700231316308a373484fc
1 // popupmenu-classic.c
2 // $Date$
3 // $Revision$
6 #include <exec/types.h>
7 #include <exec/initializers.h>
9 #include <exec/resident.h>
11 #include <proto/exec.h>
12 #include <proto/iconobject.h>
15 #include "pmpriv.h"
16 #include "pmfind.h"
18 //----------------------------------------------------------------------------
20 // defined in pminit.c
21 extern struct ExecBase *SysBase;
23 struct SegList;
25 //----------------------------------------------------------------------------
26 // Standard library functions
28 static LIB_SAVEDS(struct Library *) LIB_ASM LIB_INTERRUPT Initlib(LIB_REG(d0, struct Library *libbase),
29 LIB_REG(a0, struct SegList *seglist), LIB_REG(a6, struct ExecBase *sysbase));
31 static LIBFUNC_PROTO(Openlib, libbase, struct Library *);
32 static LIBFUNC_PROTO(Closelib, libbase, struct SegList *);
33 static LIBFUNC_PROTO(Expungelib, libbase, struct SegList *);
34 static LIBFUNC_PROTO(Extfunclib, libbase, ULONG);
36 //----------------------------------------------------------------------------
38 // defined in pmversion.c
39 extern char _LibID[];
41 //----------------------------------------------------------------------------
43 SAVEDS(LONG) ASM Libstart(void)
45 return -1;
48 /* OS3.x Library */
50 static APTR functable[] =
52 #ifdef __MORPHOS__
53 (APTR) FUNCARRAY_32BIT_NATIVE,
54 #endif
55 Openlib,
56 Closelib,
57 Expungelib,
58 Extfunclib,
60 LIBPM_MakeMenuA,
61 LIBPM_MakeItemA,
62 LIBPM_FreePopupMenu,
63 LIBPM_OpenPopupMenuA,
64 LIBPM_MakeIDListA,
65 LIBPM_ItemChecked,
66 LIBPM_GetItemAttrsA,
67 LIBPM_SetItemAttrsA,
68 LIBPM_FindItem,
69 LIBPM_AlterState,
70 LIBPM_OBSOLETEFilterIMsgA,
71 LIBPM_ExLstA,
72 LIBPM_FilterIMsgA,
73 LIBPM_InsertMenuItemA,
74 LIBPM_RemoveMenuItem,
75 LIBPM_AbortHook,
76 LIBPM_GetVersion,
77 LIBPM_ReloadPrefs,
78 LIBPM_LayoutMenuA,
79 LIBPM_RESERVED1,
80 LIBPM_FreeIDList,
81 (APTR) -1
84 /* Init table used in library initialization. */
85 static ULONG inittab[] =
87 sizeof(struct PopupMenuBase),
88 (ULONG) functable,
90 (ULONG) Initlib
94 /* The ROM tag */
95 struct Resident ALIGNED romtag =
97 RTC_MATCHWORD,
98 &romtag,
99 &romtag + 1,
100 #ifdef __MORPHOS__
101 RTF_PPC | RTF_AUTOINIT,
102 #else
103 RTF_AUTOINIT,
104 #endif
105 POPUPMENU_VERSION,
106 NT_LIBRARY,
108 POPUPMENU_NAME,
109 _LibID,
110 inittab
113 #ifdef __MORPHOS__
114 ULONG __abox__=1;
115 #endif
117 //----------------------------------------------------------------------------
119 static LIB_SAVEDS(struct Library *) LIB_ASM LIB_INTERRUPT Initlib(LIB_REG(d0, struct Library *libbase),
120 LIB_REG(a0, struct SegList *seglist), LIB_REG(a6, struct ExecBase *sysbase))
122 struct PopupMenuBase *PopupMenuBase = (struct PopupMenuBase *) libbase;
124 SysBase = sysbase;
126 PopupMenuBase->pmb_ExecBase = (struct Library *) SysBase;
127 PopupMenuBase->pmb_Library.lib_Revision = POPUPMENU_REVISION;
128 PopupMenuBase->pmb_SegList = (ULONG) seglist;
130 #if 0
131 if (!IconObjectInit(PopupMenuBase))
133 CALLLIBFUNC(Expungelib, &PopupMenuBase->pmb_Library);
134 PopupMenuBase = NULL;
136 #endif
138 d1(KPrintF(__FILE__ "/" __FUNC__ "/%ld PopupMenuBase=%08lx\n", __LINE__, PopupMenuBase));
140 return PopupMenuBase ? &PopupMenuBase->pmb_Library : NULL;
144 static LIBFUNC(Openlib, libbase, struct Library *)
146 struct PopupMenuBase *PopupMenuBase = (struct PopupMenuBase *) libbase;
148 PopupMenuBase->pmb_Library.lib_OpenCnt++;
149 PopupMenuBase->pmb_Library.lib_Flags &= ~LIBF_DELEXP;
151 if (!PMLibInit(PopupMenuBase))
153 d1(KPrintF(__FILE__ "/" __FUNC__ "/%ld fail\n", __LINE__));
154 CALLLIBFUNC(Closelib, &PopupMenuBase->pmb_Library);
155 return NULL;
158 d1(KPrintF(__FILE__ "/" __FUNC__ "/%ld success\n", __LINE__));
160 return &PopupMenuBase->pmb_Library;
162 LIBFUNC_END
165 static LIBFUNC(Closelib, libbase, struct SegList *)
167 struct PopupMenuBase *PopupMenuBase = (struct PopupMenuBase *) libbase;
169 d1(KPrintF(__FILE__ "/" __FUNC__ "/%ld OpenCnt=%lu\n", __LINE__, PopupMenuBase->pmb_Library.lib_OpenCnt));
171 PopupMenuBase->pmb_Library.lib_OpenCnt--;
173 if (0 == PopupMenuBase->pmb_Library.lib_OpenCnt)
175 if (PopupMenuBase->pmb_Library.lib_Flags & LIBF_DELEXP)
177 return CALLLIBFUNC(Expungelib, &PopupMenuBase->pmb_Library);
181 return NULL;
183 LIBFUNC_END
186 static LIBFUNC(Expungelib, libbase, struct SegList *)
188 struct PopupMenuBase *PopupMenuBase = (struct PopupMenuBase *) libbase;
190 d1(KPrintF(__FILE__ "/" __FUNC__ "/%ld OpenCnt=%lu\n", __LINE__, PopupMenuBase->pmb_Library.lib_OpenCnt));
192 if (0 == PopupMenuBase->pmb_Library.lib_OpenCnt)
194 ULONG size = PopupMenuBase->pmb_Library.lib_NegSize + PopupMenuBase->pmb_Library.lib_PosSize;
195 UBYTE *ptr = (UBYTE *) PopupMenuBase - PopupMenuBase->pmb_Library.lib_NegSize;
196 struct SegList *libseglist = (struct SegList *) PopupMenuBase->pmb_SegList;
198 Remove((struct Node *) PopupMenuBase);
199 PMLibCleanup(PopupMenuBase);
200 FreeMem(ptr,size);
202 return libseglist;
205 PopupMenuBase->pmb_Library.lib_Flags |= LIBF_DELEXP;
207 return NULL;
209 LIBFUNC_END
212 static LIBFUNC(Extfunclib, libbase, ULONG)
214 (void) libbase;
216 return 0;
218 LIBFUNC_END