A gadget resource lets you implement a custom UI element. A gadget is best thought of as simply a reserved rectangle at a set location on the form. You must provide all drawing and event handling code. There is no default behavior for a gadget.
If the gadget is an extended gadget, you can write a callback function (FormGadgetHandlerType()
) to provide drawing and event handling code for the gadget. A pointer to the gadget is passed to the callback, so you can use the same function for multiple gadgets. Use FrmSetGadgetHandler()
to set the callback function.
When the form receives certain requests to draw itself, delete itself, or to hide or show a gadget, it calls the gadget handler function you provide. When the form receives events intended for the gadget, it passes those to the gadget handler function as well.
Listing 7.1 shows an example of a gadget handler function.
Boolean GadgetHandler (struct FormGadgetType *gadgetP, uint16_t cmd, void *paramP) { Boolean handled = false; switch (cmd) { case formGadgetDrawCmd: // Sent to active gadgets any time form is drawn or // redrawn. DrawGadget(); gadgetP->attr.visible = true; handled = true; break; case formGadgetHandleEventCmd: //Sent when form receives a gadget event. //paramP points to EventType structure. if (paramP->eType == frmGadgetEnterEvent) { // penDown in gadget's bounds. GadgetTapped (); handled = true; } if (paramP->eType == frmGadgetMiscEvent) { //This event is sent by your application //when it needs to send info to the gadget } break; case formGadgetDeleteCmd: //Perform any cleanup prior to deletion. break; case formGadgetEraseCmd: //FrmHideObject() takes care of this event if you //return false. handled = false; break; } return handled; }