NAME GU_GetGadgetPtr -- Get a pointer to a gadget's gadget structure. SYNOPSIS gad = GU_GetGadgetPtr(id, gadgets) D0,SR(Z) D0 A0 APTR GU_GetGadgetPtr(UWORD, struct LayoutGadget *); FUNCTION Find a gadget's gadget structure by giving its ID. The gadget pointer is always found last in the LayoutGadget structure. You can use this function to get that pointer. It is also possible to get the gadget structure by taking it directly from the LayoutGadget structure array, but then you must know exactly in which structure it is located. Assembly language programmers can use a PC relative pointer to get the gadget pointer. INPUTS id - the ID of the gadget to search for gadgets - a pointer to the array of LayoutGadget structures. RESULT gad - pointer to the requested gadget. For bevelboxes, this function will return a BBoxData structure. A ProgressGad structure is returned for a progress display gadget. EXAMPLE Some of the LayoutGadget structures from BetterTest.c: struct LayoutGadget gadgets[] = { { MSG_NEXTDRIVE, NextDriveGad, StdGTTags, NULL }, { MSG_PREVDRIVE, PrevDriveGad, StdGTTags, NULL }, { MSG_DRIVE, DriveGad, DriveGTTags, NULL }, { MSG_REQUESTER, ReqGad, StdGTTags, NULL }, { MSG_CHECKME, CheckBoxGad, StdGTTags, NULL }, { MSG_FILENAME, FileNameGad, StdGTTags, NULL }, { -1, NULL, NULL, NULL } }; The examples should get the gadget structure of the Requester gadget (not assuming that ID's begin with 0). There is two methods you can use to get a gadgets structure: 1. Use the pointer in the array directly: thegadget = gadgets[3].lg_Gadget This will only work if you know in which LayoutGadget structure the gadget is in. 2. Use this library function: thegadget = GU_GetGadgetPtr(MSG_REQUESTER, gadgets); This will always work if all gadgets have a unique ID. Some of the LayoutGadget structures from BetterTest.s: gadgets: GADGET MSG_NEXTDRIVE, NextDriveGad, StdGTTags GADGET MSG_PREVDRIVE, PrevDriveGad, StdGTTags GADGET MSG_DRIVE, DriveGad, DriveGTTags GADGET MSG_REQUESTER, ReqGad, StdGTTags GADGET MSG_CHECKME, CheckBoxGad, StdGTTags GADGET MSG_FILENAME, FileNameGad, StdGTTags GADGET -1,NULL,NULL Assembly language programmers can use three methods to get the pointer: 1. Use the pointer in the array directly: lea.l gadgets(pc),a0 ; Get array moveq.l #lg_SIZEOF,d0 ; Get the size of the LayoutGadget mulu #3,d0 ; struct and calculate offset to ; the right structure in the array move.l lg_Gadget(a0,d0.l),d0 ; Get the gadget pointer This will only work if you know in which LayoutGadget structure the gadget is in. 2. Use this library function: lea.l gadgets(pc),a0 ; Get array moveq.l #MSG_REQUESTER,d0 ; Gadget to search for jsr _LVOGU_GetGadgetPtr(a6) ; Get gadget, result in D0 This will always work if all gadgets have a unique ID. 3. Use an extra label for each gadget that should be easy to access: gadgets: GADGET MSG_NEXTDRIVE, NextDriveGad, StdGTTags GADGET MSG_PREVDRIVE, PrevDriveGad, StdGTTags GADGET MSG_DRIVE, DriveGad, DriveGTTags GADGET MSG_REQUESTER, ReqGad, StdGTTags reqgad: equ *-4 GADGET MSG_CHECKME, CheckBoxGad, StdGTTags GADGET MSG_FILENAME, FileNameGad, StdGTTags filenamegad: equ *-4 GADGET -1,NULL,NULL move.l reqgad(pc),d0 ; Get the gadget This will always work.
Converted on 19 Jul 1996 with RexxDoesAmigaGuide2HTML by Michael Ranner.