grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / muimaster / support_classes.c
blob6e2bfb2b90202c9b25f86d6b2d8f3ec4372228b2
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
7 #include <stdio.h>
9 #include <intuition/classes.h>
10 #include <clib/alib_protos.h>
11 #include <proto/exec.h>
12 #include <proto/intuition.h>
13 #include <proto/utility.h>
14 #include <proto/muimaster.h>
17 #include "mui.h"
18 #include "support.h"
19 #include "support_classes.h"
20 #include "muimaster_intern.h"
22 /*#define MYDEBUG*/
23 #include "debug.h"
25 static const struct __MUIBuiltinClass *const builtins[] = {
26 &_MUI_Notify_desc,
27 &_MUI_Family_desc,
28 &_MUI_Application_desc,
29 &_MUI_Window_desc,
30 &_MUI_Area_desc,
31 &_MUI_Rectangle_desc,
32 &_MUI_Group_desc,
33 &_MUI_Image_desc,
34 &_MUI_Configdata_desc,
35 &_MUI_Text_desc,
36 &_MUI_Numeric_desc,
37 &_MUI_Slider_desc,
38 &_MUI_String_desc,
39 ZUNE_BOOPSI_DESC & _MUI_Prop_desc,
40 &_MUI_Scrollbar_desc,
41 &_MUI_Register_desc,
42 &_MUI_Menuitem_desc,
43 &_MUI_Menu_desc,
44 &_MUI_Menustrip_desc,
45 ZUNE_VIRTGROUP_DESC ZUNE_SCROLLGROUP_DESC & _MUI_Scrollbutton_desc,
46 &_MUI_Semaphore_desc,
47 &_MUI_Dataspace_desc,
48 &_MUI_Bitmap_desc,
49 &_MUI_Bodychunk_desc,
50 &_MUI_ChunkyImage_desc,
51 &_MUI_Cycle_desc,
52 &_MUI_Popstring_desc,
53 &_MUI_Listview_desc,
54 &_MUI_List_desc,
55 ZUNE_POPASL_DESC & _MUI_Popobject_desc,
56 ZUNE_GAUGE_DESC
57 ZUNE_ABOUTMUI_DESC
58 ZUNE_SETTINGSGROUP_DESC
59 ZUNE_IMAGEADJUST_DESC
60 ZUNE_POPIMAGE_DESC
61 ZUNE_SCALE_DESC
62 ZUNE_RADIO_DESC
63 ZUNE_ICONLISTVIEW_DESC
64 ZUNE_BALANCE_DESC
65 ZUNE_COLORFIELD_DESC
66 ZUNE_COLORADJUST_DESC
67 ZUNE_IMAGEDISPLAY_DESC
68 ZUNE_PENDISPLAY_DESC
69 ZUNE_PENADJUST_DESC ZUNE_POPPEN_DESC & _MUI_Mccprefs_desc,
70 ZUNE_FRAMEDISPLAY_DESC
71 ZUNE_POPFRAME_DESC
72 ZUNE_FRAMEADJUST_DESC
73 ZUNE_VOLUMELIST_DESC
74 ZUNE_DIRLIST_DESC
75 ZUNE_NUMERICBUTTON_DESC
76 ZUNE_POPLIST_DESC
77 ZUNE_CRAWLING_DESC
78 ZUNE_POPSCREEN_DESC
79 ZUNE_LEVELMETER_DESC
80 ZUNE_KNOB_DESC ZUNE_DTPIC_DESC ZUNE_PALETTE_DESC
83 Class *ZUNE_GetExternalClass(ClassID classname,
84 struct Library *MUIMasterBase)
86 struct Library *mcclib = NULL;
87 struct MUI_CustomClass *mcc = NULL;
88 CONST_STRPTR const *pathptr;
89 TEXT s[255];
91 static CONST_STRPTR const searchpaths[] = {
92 "Zune/%s",
93 "Classes/Zune/%s",
94 "MUI/%s",
95 NULL,
98 for (pathptr = searchpaths; *pathptr; pathptr++)
100 snprintf(s, 255, *pathptr, classname);
102 D(bug("Trying opening of %s\n", s));
104 if ((mcclib = OpenLibrary(s, 0)))
106 D(bug("Calling MCC Query. Librarybase at 0x%lx\n", mcclib));
108 mcc = MCC_Query(0);
109 if (!mcc)
110 mcc = MCC_Query(1); /* MCP? */
112 if (mcc)
114 if (mcc->mcc_Class)
116 mcc->mcc_Module = mcclib;
117 D(bug("Successfully opened %s as external class\n",
118 classname));
120 return mcc->mcc_Class;
124 CloseLibrary(mcclib);
128 D(bug("Failed to open external class %s\n", classname));
129 return NULL;
132 /**************************************************************************/
133 static Class *ZUNE_FindBuiltinClass(ClassID classid, struct Library *MUIMasterBase)
135 struct MUIMasterBase_intern *intZuneBase = (struct MUIMasterBase_intern *)MUIMasterBase;
136 Class *cl = NULL, *cl2;
138 ForeachNode(&intZuneBase->BuiltinClasses, cl2)
140 if (!strcmp(cl2->cl_ID, classid))
142 cl = cl2;
143 break;
147 return cl;
150 static Class *ZUNE_MakeBuiltinClass(ClassID classid,
151 struct Library *MUIMasterBase)
153 int i;
154 Class *cl = NULL;
155 struct Library *mb = NULL;
157 D(bug("Makeing Builtinclass %s\n", classid));
159 for (i = 0; i < sizeof(builtins) / sizeof(builtins[0]); i++)
161 if (!strcmp(builtins[i]->name, classid))
163 Class *supercl;
164 ClassID superclid;
166 /* This may seem strange, but opening muimaster.library here is
167 done in order to increase muimaster.library's open count, so
168 that it doesn't get expunged while some of its internal
169 classes are still in use. We don't use muimaster.library
170 directly but the name of the library stored inside the base,
171 because the library can be compiled also as zunemaster.library
174 mb = OpenLibrary(MUIMasterBase->lib_Node.ln_Name, 0);
176 /* It can't possibly fail, but well... */
177 if (!mb)
178 break;
180 if (strcmp(builtins[i]->supername, ROOTCLASS) == 0)
182 superclid = ROOTCLASS;
183 supercl = NULL;
185 else
187 superclid = NULL;
188 supercl = MUI_GetClass(builtins[i]->supername);
190 if (!supercl)
191 break;
194 cl = MakeClass(builtins[i]->name, superclid, supercl,
195 builtins[i]->datasize, 0);
196 if (cl)
198 #if defined(__MAXON__) || defined(__amigaos4__)
199 cl->cl_Dispatcher.h_Entry = builtins[i]->dispatcher;
200 #else
201 cl->cl_Dispatcher.h_Entry = (HOOKFUNC) metaDispatcher;
202 cl->cl_Dispatcher.h_SubEntry = builtins[i]->dispatcher;
203 #endif
204 /* Use this as a reference counter */
205 cl->cl_Dispatcher.h_Data = 0;
208 break;
212 if (!cl && mb)
213 CloseLibrary(mb);
215 return cl;
218 Class *ZUNE_GetBuiltinClass(ClassID classid, struct Library * mb)
220 Class *cl;
222 ObtainSemaphore(&MUIMB(MUIMasterBase)->ZuneSemaphore);
224 cl = ZUNE_FindBuiltinClass(classid, mb);
226 if (!cl)
228 cl = ZUNE_MakeBuiltinClass(classid, mb);
230 if (cl)
232 ZUNE_AddBuiltinClass(cl, mb);
234 /* Increase the reference counter */
235 char *count = cl->cl_Dispatcher.h_Data;
236 count++;
237 cl->cl_Dispatcher.h_Data = count;
241 ReleaseSemaphore(&MUIMB(MUIMasterBase)->ZuneSemaphore);
243 return cl;
247 * metaDispatcher - puts h_Data in A6 and calls real dispatcher
250 #ifdef __AROS__
251 AROS_UFH3(IPTR, metaDispatcher,
252 AROS_UFHA(struct IClass *, cl, A0),
253 AROS_UFHA(Object *, obj, A2), AROS_UFHA(Msg, msg, A1))
255 AROS_USERFUNC_INIT
256 return AROS_UFC4(IPTR, cl->cl_Dispatcher.h_SubEntry,
257 AROS_UFPA(Class *, cl, A0),
258 AROS_UFPA(Object *, obj, A2),
259 AROS_UFPA(Msg, msg, A1),
260 AROS_UFPA(APTR, cl->cl_Dispatcher.h_Data, A6));
262 AROS_USERFUNC_EXIT}
264 #else
265 #ifdef __SASC
266 __asm ULONG metaDispatcher(register __a0 struct IClass * cl,
267 register __a2 Object * obj, register __a1 Msg msg)
269 __asm ULONG(*entry) (register __a0 struct IClass * cl,
270 register __a2 Object * obj, register __a1 Msg msg) =
271 (__asm ULONG(*)(register __a0 struct IClass *,
272 register __a2 Object *,
273 register __a1 Msg))cl->cl_Dispatcher.h_SubEntry;
275 putreg(REG_A6, (long)cl->cl_Dispatcher.h_Data);
276 return entry(cl, obj, msg);
278 #endif
279 #endif