Writing a ReAction gadget
Posted: Sat Sep 08, 2012 10:35 am
I started learning how to write BOOPSI classes. I think I now understand a good deal of it, and I have the basic stuff (lib code and class dispatcher) set up. What I'm trying to do as part of my lesson is write a simple textbox gadget based on ReAction's space.gadget. My goal is rather modest: the textbox will just be a space.gadget with some text in it.
I have implemented the OM_NEW method as follows:
The OM_DISPOSE method is implemented like this:
It seems to work - but now I'm stuck as to how I should implement the actual layout and render methods. I have studied a couple of code examples but none of them is based on an existing gadget. Any help would be greatly appreciated!
I have implemented the OM_NEW method as follows:
Code: Select all
uint32 om_new(Class *cl, Object *o, Msg msg)
{
struct ClassBase *libBase = (struct ClassBase *)cl->cl_UserData;
struct localObjectData *lod = NULL;
uint32 retVal = 0L;
if ( (retVal = IIntuition->IDoSuperMethodA(cl, o, msg)) )
{
// Obtain pointer to our object's local instance data.
if ( (lod = (struct localObjectData *)INST_DATA(cl, retVal)) )
{
// Create space.gadget.
if ( !(lod->space = IIntuition->NewObject(SpaceClass, NULL,
SPACE_MinWidth, 200,
SPACE_MinHeight, 100,
SPACE_RenderHook, renderHook, // pointer to my hook that renders the text
TAG_DONE)) )
{
IIntuition->ICoerceMethod(cl, (Object *) retVal, OM_DISPOSE);
retVal = 0;
}
}
}
return retVal;
}
Code: Select all
uint32 om_dispose(Class *cl, Object *o, Msg msg)
{
struct ClassBase *libBase = (struct ClassBase *)cl->cl_UserData;
struct localObjectData *lod = (struct localObjectData *)INST_DATA(cl, o);
// Dispose of the space gadget.
if ( lod->space ) IIntuition->DisposeObject(lod->space);
// Let superclass dispose of the textbox object.
IIntuition->IDoSuperMethodA(cl, o, msg);
return 0;
}