Thread: gadtools
View Single Post
Old 21 July 2013, 01:29   #4
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,918
Here is an example for GA_Disabled:

Code:
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/gadtools.h>

#define GID_ACTIVE       1001
#define GID_NUMBER       1002

int main (void)

{
struct Screen *scr;

if (scr = LockPubScreen (NULL))
	{
	long x,y,w,h;
	struct NewGadget ng = {0};
	struct Gadget *glist = NULL;
	struct Gadget *gad = CreateContext (&glist);
	struct Window *win;
	struct Gadget *numgad;

	ng.ng_VisualInfo = GetVisualInfo (scr,TAG_END);
	ng.ng_TextAttr   = scr->Font;
	ng.ng_Flags      = 0;

	w = scr->RastPort.TxWidth;;
	h = scr->RastPort.TxHeight;

	x = scr->WBorLeft + 8 + 8 * w;
	y = scr->WBorTop + h + 9;

	ng.ng_LeftEdge   = x;
	ng.ng_TopEdge    = y;
	ng.ng_Height     = h + 6;
	ng.ng_Width      = ng.ng_Height;
	ng.ng_GadgetText = "Active";
	ng.ng_GadgetID   = GID_ACTIVE;
	gad = CreateGadget (CHECKBOX_KIND,gad,&ng,GTCB_Scaled,TRUE,GTCB_Checked,TRUE,TAG_END);

	ng.ng_TopEdge   += ng.ng_Height + 4;
	ng.ng_Width      = 10 * w + 20;
	ng.ng_GadgetText = "Number";
	ng.ng_GadgetID   = GID_NUMBER;
	gad = CreateGadget (INTEGER_KIND,gad,&ng,GTIN_Number,123,TAG_END);
	numgad = gad;

	w = ng.ng_LeftEdge + ng.ng_Width + 8 + scr->WBorRight;
	h = ng.ng_TopEdge + ng.ng_Height + 8 + scr->WBorBottom;

	if (gad)
	if (win = OpenWindowTags (NULL,
			WA_Width,w,
			WA_Height,h,
			WA_Left,(scr->Width - w) / 2,
			WA_Top,(scr->Height - h) / 2,
			WA_PubScreen,scr,
			WA_Title,"Demo",
			WA_Flags,WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_ACTIVATE,
			WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY | CHECKBOXIDCMP | INTEGERIDCMP,
			WA_Gadgets,glist,
			TAG_END))
		{
		BOOL cont = TRUE;

		GT_RefreshWindow (win,NULL);

		do	{
			struct IntuiMessage *imsg;

			if (Wait ((1L << win->UserPort->mp_SigBit) | SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
				cont = FALSE;

			while (imsg = GT_GetIMsg (win->UserPort))
				{
				switch (imsg->Class)
					{
				case IDCMP_REFRESHWINDOW:
					GT_BeginRefresh (win);
					GT_EndRefresh (win,TRUE);
					break;
				case IDCMP_GADGETUP:
					{
					struct Gadget *gad = (struct Gadget *) imsg->IAddress;
					ULONG sel;
					switch (gad->GadgetID)
						{
					case GID_ACTIVE:
						GT_GetGadgetAttrs (gad,win,NULL,GTCB_Checked,&sel,TAG_END);
						GT_SetGadgetAttrs (numgad,win,NULL,GA_Disabled,(sel == 0),TAG_END);
						break;
					case GID_NUMBER:
						GT_GetGadgetAttrs (gad,win,NULL,GTIN_Number,&sel,TAG_END);
						Printf ("number = %ld\n",sel);
						break;
						}
					break;
					}
				case IDCMP_VANILLAKEY:
					if (imsg->Code == 0x1b)
						cont = FALSE;
					break;
				case IDCMP_CLOSEWINDOW:
					cont = FALSE;
					break;
					}

				GT_ReplyIMsg (imsg);
				}
			}
		while (cont);

		CloseWindow (win);
		}

	FreeGadgets (glist);
	FreeVisualInfo (ng.ng_VisualInfo);

	UnlockPubScreen (NULL,scr);
	}

return (RETURN_OK);
}

Last edited by thomas; 21 July 2013 at 12:44. Reason: window truely centered on screen, the right IDCMP macros used, quit with Esc added
thomas is offline  
 
Page generated in 0.04204 seconds with 11 queries