![]()
![]()
![]()
Overview ======== Building a class is rather simple. All you have to do is to write a class dispatcher function, setup a hook structure, call MUI_GetClass() to find the pointer to your superclass and use intuition.library/MakeClass() to create the class. If you already wrote BOOPSI classes, you should know whats going on here. Objects from custom classes are created using intuition.library / NewObject(), not muimaster.library / MUI_NewObject(). Nevertheless, you can use these objects like every other MUI objects, e.g. as children of groups, in virtual groups or wherever you like. All classes you create have to be subclasses of MUI's area class, most of them will probably be direct subclasses but you can also have subclasses of list class or even subclasses of your own classes if you want. Here's an example of how a custom class could be generated: /* Get a pointer to the superclass. MUI will lock this */ /* and prevent it from being flushed during you hold */ /* the pointer. When you're done, you have to call */ /* MUI_FreeClass() to release this lock. */ if (!(SuperClass=MUI_GetClass(MUIC_Area))) fail("Superclass for the new class not found."); /* Create the new class with the boopsi function call. */ /* You will need the sizeof your classes instance data */ /* here. */ if (!(MyClass = MakeClass(NULL,NULL,SuperClass,sizeof(struct MyData),0))) { MUI_FreeClass(SuperClass); fail("Failed to create class."); } /* Set the dispatcher for the new class. */ MyClass->cl_Dispatcher.h_Entry = (APTR)MyDispatcher; MyClass->cl_Dispatcher.h_SubEntry = NULL; MyClass->cl_Dispatcher.h_Data = NULL; ... ... app = ApplicationObject, ..., SubWindow, window = WindowObject, ... WindowContents, VGroup, Child, MyObj = NewObject(MyClass,NULL, TextFrame, MUIA_Background, MUII_BACKGROUND, TAG_DONE), End, End, End; ... ... /* Shutdown. When the application is disposed, /* MUI also deletes MyObj. */ MUI_DisposeObject(app); // dispose all objects. FreeClass(MyClass); // free our private class. MUI_FreeClass(SuperClass); // release super class pointer. You're dispatcher will look like a traditional BOOPSI dispatcher: SAVEDS ASM ULONG MyDispatcher( REG(a0) struct IClass *cl, REG(a2) Object *obj, REG(a1) Msg msg) { switch (msg->MethodID) { case OM_NEW : return(mNew (cl,obj,(APTR)msg)); case OM_DISPOSE : return(mDispose (cl,obj,(APTR)msg)); case MUIM_AskMinMax: return(mAskMinMax(cl,obj,(APTR)msg)); case MUIM_Draw : return(mDraw (cl,obj,(APTR)msg)); ... } return(DoSuperMethodA(cl,obj,msg)); } What methods are available and need to be supported is discussed in the following chapter. Note: Your dispatcher will also receive some undocumented methods. It's not a wise choice to make any assumptions here, the only thing you should do is pass them to your superclass immediately!