Page 1 of 1

Writing a ReAction gadget

Posted: Sat Sep 08, 2012 10:35 am
by trixie
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:

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;
}  
The OM_DISPOSE method is implemented like this:

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;
}  
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!

Re: Writing a ReAction gadget

Posted: Sat Sep 08, 2012 2:45 pm
by thomasrapp
Your approach is not the easy way you expect. What you are doing is actually a copy of layout.gadget. You create a sub-object which is independent of the class hierarchy of your class and not known to Intuition. It only appears when you call all the methods explicitely.

The better way to modify an existing class is to specify it in the MakeClass call as parent. Then your dispatcher can simply call DoSuperMethod to call the parent for everything you don't need to modify. You only "overload" those methods which should behave differently than those of the parent class.

Here is a complete example: http://thomas-rapp.homepage.t-online.de ... actgad.lha

BTW, it is nice that you have all the library stuff done already, but this is not needed to develop a gadget class. Only if you want to make the class public for other programs indepenently from your program it needs to be a library.

Re: Writing a ReAction gadget

Posted: Sat Sep 08, 2012 4:27 pm
by trixie
Good to know I'm on the wrong track :-) Thanks Thomas, the example is exactly what I needed.