/*** Performs some checks on what user has enterred ***/ void check_tab(struct Gadget *str) { UBYTE *buf = GetSI(str)->Buffer, *start; for(start=buf; *buf; buf++) if(*buf < '0' || *buf > '9') { /* Wrong char, avert user */ GetSI(str)->BufferPos = buf-start; DisplayBeep(NULL); ActivateGadget(str, Wnd, NULL); break; } }
void LIBFUNC L_ActivateStrGad( REG(a0, struct Gadget *gad), REG(a1, struct Window *win)) { if (!(gad->Flags&GFLG_SELECTED) && !(gad->Flags&GFLG_DISABLED)) { struct StringInfo *sinfo; sinfo=(struct StringInfo *)gad->SpecialInfo; sinfo->BufferPos=strlen(sinfo->Buffer); RefreshGList(gad,win,0,1); ActivateGadget(gad,win,0); } }
STATIC ULONG FOHandleEvents(struct LayoutData *ld, struct AslBase_intern *AslBase) { struct IntuiMessage *imsg = ld->ld_Event; struct FOUserData *udata = (struct FOUserData *)ld->ld_UserData; struct IntFontReq *iforeq = (struct IntFontReq *)ld->ld_IntReq; WORD gadid; ULONG retval = GHRET_OK; EnterFunc(bug("FOHandleEvents: Class: %d\n", imsg->Class)); switch (imsg->Class) { case IDCMP_CLOSEWINDOW: retval = FALSE; break; case IDCMP_RAWKEY: switch (imsg->Code) { case CURSORUP: FOChangeActiveFont(ld, -1, imsg->Qualifier, FALSE, AslBase); break; case RAWKEY_PAGEUP: FOChangeActiveFont(ld, -1, IEQUALIFIER_LSHIFT, FALSE, AslBase); break; case RAWKEY_HOME: FOChangeActiveFont(ld, -1, IEQUALIFIER_LALT, FALSE, AslBase); break; case RAWKEY_NM_WHEEL_UP: FOChangeActiveFont(ld, -3, imsg->Qualifier, FALSE, AslBase); break; case CURSORDOWN: FOChangeActiveFont(ld, 1, imsg->Qualifier, FALSE, AslBase); break; case RAWKEY_PAGEDOWN: FOChangeActiveFont(ld, 1, IEQUALIFIER_LSHIFT, FALSE, AslBase); break; case RAWKEY_END: FOChangeActiveFont(ld, 1, IEQUALIFIER_LALT, FALSE, AslBase); break; case RAWKEY_NM_WHEEL_DOWN: FOChangeActiveFont(ld, 3, imsg->Qualifier, FALSE, AslBase); break; } break; case IDCMP_VANILLAKEY: switch(imsg->Code) { case 27: retval = FALSE; break; } break; case IDCMP_GADGETUP: gadid = ((struct Gadget *)imsg->IAddress)->GadgetID; D(bug("GADGETUP! gadgetid=%d code=%d\n", gadid, imsg->Code)); switch (gadid) { case ID_BUTCANCEL: retval = FALSE; break; case ID_BUTOK: retval = FOGetSelectedFont(ld, AslBase); break; case ID_NAMELISTVIEW: { struct ASLLVFontReqNode *fontnode; IPTR active; IPTR size; GetAttr(ASLLV_Active, udata->NameListview, &active); GetAttr(STRINGA_LongVal, udata->SizeString, &size); if ((fontnode = (struct ASLLVFontReqNode *)FindListNode(&udata->NameListviewList, (WORD)active))) { FOActivateFont(ld, active, (LONG)size, AslBase); if (imsg->Code) /* TRUE if double clicked */ { retval = FOGetSelectedFont(ld, AslBase); } } ActivateGadget((struct Gadget *)udata->NameString, ld->ld_Window, NULL); } break; case ID_SIZELISTVIEW: if (udata->ActiveFont) { struct Node *node; IPTR active; GetAttr(ASLLV_Active, udata->SizeListview, &active); if ((node = FindListNode(&udata->ActiveFont->SizeList, (WORD)active))) { FOSetSizeString((LONG)node->ln_Name, ld, AslBase); FOUpdatePreview(ld, AslBase); if (imsg->Code) /* TRUE if double clicked */ { retval = FOGetSelectedFont(ld, AslBase); } } ActivateGadget((struct Gadget *)udata->SizeString, ld->ld_Window, NULL); } break; case ID_NAMESTRING: if (imsg->Code == STRINGCODE_CURSORUP) { FOChangeActiveFont(ld, -1, imsg->Qualifier, TRUE, AslBase); ActivateGadget((struct Gadget *)udata->NameString, ld->ld_Window, NULL); break; } else if (imsg->Code == STRINGCODE_CURSORDOWN) { FOChangeActiveFont(ld, 1, imsg->Qualifier, TRUE, AslBase); ActivateGadget((struct Gadget *)udata->NameString, ld->ld_Window, NULL); break; } else if ((imsg->Code == 0) || (imsg->Code == 9)) { FOUpdatePreview(ld, AslBase); break; } break; case ID_SIZESTRING: if (imsg->Code == STRINGCODE_CURSORUP) { FOChangeActiveSize(ld, -1, imsg->Qualifier, AslBase); ActivateGadget((struct Gadget *)udata->SizeString, ld->ld_Window, NULL); break; } else if (imsg->Code == STRINGCODE_CURSORDOWN) { FOChangeActiveSize(ld, 1, imsg->Qualifier, AslBase); ActivateGadget((struct Gadget *)udata->SizeString, ld->ld_Window, NULL); break; } else if ((imsg->Code == 0) || (imsg->Code == 9)) { IPTR val; LONG size; GetAttr(STRINGA_LongVal, udata->SizeString, (IPTR *)&val); size = (LONG)val; if ((size < iforeq->ifo_MinHeight) || (size > iforeq->ifo_MaxHeight)) { if (size < iforeq->ifo_MinHeight) size = iforeq->ifo_MinHeight; if (size > iforeq->ifo_MaxHeight) size = iforeq->ifo_MaxHeight; FOSetSizeString(size, ld, AslBase); } FOActivateSize(ld, -size, AslBase); break; } break; case ID_STYLE: case ID_FRONTPEN: case ID_BACKPEN: FOUpdatePreview(ld, AslBase); break; } /* switch (gadget ID) */ break; /* case IDCMP_GADGETUP: */ case IDCMP_MENUPICK: if (ld->ld_Menu) { UWORD men = imsg->Code; while(men != MENUNULL) { struct MenuItem *item; if ((item = ItemAddress(ld->ld_Menu, men))) { switch((IPTR)GTMENUITEM_USERDATA(item)) { /* Control menu */ case FOMEN_LASTFONT: FOChangeActiveFont(ld, -1, 0, FALSE, AslBase); break; case FOMEN_NEXTFONT: FOChangeActiveFont(ld, 1, 0, FALSE, AslBase); break; case FOMEN_RESTORE: FORestore(ld, iforeq->ifo_TextAttr.ta_Name, iforeq->ifo_TextAttr.ta_YSize, AslBase); break; case FOMEN_RESCAN: FOGetFonts(ld, AslBase); break; case FOMEN_OK: retval = FOGetSelectedFont(ld, AslBase); break; case FOMEN_CANCEL: retval = FALSE; break; } /* switch id */ men = item->NextSelect; } /* if ((item = ItemAddress(ld->ld_Menu, men))) */ else { men = MENUNULL; } } /* while(men != MENUNULL) */ } /* if (ld->ld_Menu) */ break; /* case IDCMP_MENUPICK: */ } /* switch (imsg->Class) */ ReturnInt ("FOHandleEvents", ULONG, retval); }
BOOL get_string(UBYTE * buff, LONG max_len) { struct Gadget *g, *sg; struct NewGadget ng; struct Gadget *gl; struct Window *win; struct IntuiMessage *msg; struct StringInfo *strinfo; UWORD koodi, msgID; ULONG classi; APTR address; UWORD offy; BOOL quit, ok; g = CreateContext(&gl); if (!g) return FALSE; offy = scr->WBorTop + scr->RastPort.TxHeight + 1; ng.ng_TextAttr = &topaz8; ng.ng_VisualInfo = VisInfo; ng.ng_Flags = PLACETEXT_IN; ng.ng_LeftEdge = 14; ng.ng_TopEdge = offy + 34; ng.ng_Width = 90; ng.ng_Height = 15; ng.ng_GadgetText = (UBYTE *) "OK"; ng.ng_GadgetID = GAD_OK; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_LeftEdge = 246; ng.ng_TopEdge = offy + 34; ng.ng_GadgetText = (UBYTE *) "Cancel"; ng.ng_GadgetID = GAD_CANCEL; g = CreateGadget(BUTTON_KIND, g, &ng, TAG_DONE); ng.ng_LeftEdge = 14; ng.ng_TopEdge = offy + 10; ng.ng_Width = 322; ng.ng_Height = 15; ng.ng_GadgetText = NULL; ng.ng_GadgetID = GAD_STRING; sg = CreateGadget(STRING_KIND, g, &ng, GTST_String, buff, GTST_MaxChars, max_len, TAG_DONE); strinfo = (struct StringInfo *) sg->SpecialInfo; ok = FALSE; newwindow.Title = "Amiga Disk File"; newwindow.Width = 350; newwindow.Height = 65; newwindow.FirstGadget = gl; newwindow.Screen = scr; newwindow.LeftEdge = scr->MouseX - (newwindow.Width / 2); if (newwindow.LeftEdge + newwindow.Width > scr->Width) newwindow.LeftEdge = scr->Width - newwindow.Width; newwindow.TopEdge = scr->MouseY - (newwindow.Height / 2); if (newwindow.TopEdge + newwindow.Height > scr->Height) newwindow.TopEdge = scr->Height - newwindow.Height; win = OpenWindow(&newwindow); if (win) { ActivateGadget(sg, win, NULL); quit = FALSE; while (!quit) { WaitPort(win->UserPort); while (msg = (struct IntuiMessage *) GT_GetIMsg(win->UserPort)) { classi = msg->Class; koodi = msg->Code; address = msg->IAddress; if (classi == IDCMP_GADGETUP) msgID = ((struct Gadget *) msg->IAddress)->GadgetID; else msgID = msg->Code; GT_ReplyIMsg((struct IntuiMessage *) msg); switch (classi) { case IDCMP_CLOSEWINDOW: quit = TRUE; break; case IDCMP_GADGETUP: switch (msgID) { case GAD_CANCEL: quit = TRUE; break; case GAD_OK: case GAD_STRING: strcpy(buff, strinfo->Buffer); quit = ok = TRUE; break; } break; default: break; } } } CloseWindow(win); } FreeGadgets(gl); return ok; }