static WORD MyIntuiTextLength(struct VisualInfo *vi, struct IntuiText *it, struct GadToolsBase_intern * GadToolsBase) { WORD width; if (it->ITextFont) { struct IntuiText *it_next = it->NextText; it->NextText = NULL; width = IntuiTextLength(it); it->NextText = it_next; } else { width = TextLength(&vi->vi_screen->RastPort, it->IText, strlen(it->IText)); } return width; }
static BOOL LayOutReq (struct AHIAudioModeRequesterExt *req, struct TextAttr *TextAttr) { struct Gadget *gad; struct NewGadget ng; struct TextAttr *gadtextattr; struct TextFont *font; LONG fontwidth,buttonheight,buttonwidth,pixels; struct IntuiText intuitext = {1,0,JAM1,0,0,NULL,NULL,NULL}; LONG sliderlevels,sliderlevel; LONG selected; selected=GetSelected(req); GetSliderAttrs(req,&sliderlevels,&sliderlevel); // Calculate gadget area req->gx=req->Window->BorderLeft+4; req->gy=req->Window->BorderTop+2; req->gw=req->Window->Width-req->gx-(req->Window->BorderRight+4); req->gh=req->Window->Height-req->gy-(req->Window->BorderBottom+2); if(req->Gadgets) { RemoveGList(req->Window,req->Gadgets,-1); FreeGadgets(req->Gadgets); SetAPen(req->Window->RPort,0); SetDrMd(req->Window->RPort,JAM1); EraseRect(req->Window->RPort, req->Window->BorderLeft, req->Window->BorderTop, req->Window->Width-req->Window->BorderRight-1,req->Window->Height-req->Window->BorderBottom-1); RefreshWindowFrame(req->Window); } req->Gadgets=NULL; if((gad=CreateContext(&req->Gadgets))) { if(TextAttr) gadtextattr=TextAttr; else gadtextattr=req->Window->WScreen->Font; if((font=OpenFont(gadtextattr))) { fontwidth=font->tf_XSize; CloseFont(font); } else return FALSE; buttonheight=gadtextattr->ta_YSize+6; intuitext.ITextFont=gadtextattr; intuitext.IText=req->PositiveText; buttonwidth=IntuiTextLength(&intuitext); intuitext.IText=req->NegativeText; pixels=IntuiTextLength(&intuitext); buttonwidth=max(pixels,buttonwidth); buttonwidth+=4+fontwidth; // Create gadgets and check if they fit // Do the two buttons fit? if(2*buttonwidth > req->gw) return FALSE; ng.ng_TextAttr=gadtextattr; ng.ng_VisualInfo=req->vi; ng.ng_UserData=req; // OK button ng.ng_LeftEdge=req->gx; ng.ng_TopEdge=req->gy+req->gh-buttonheight; ng.ng_Width=buttonwidth; ng.ng_Height=buttonheight; ng.ng_GadgetText=req->PositiveText; ng.ng_GadgetID=OKBUTTON; ng.ng_Flags=PLACETEXT_IN; gad=CreateGadget(BUTTON_KIND,gad,&ng,TAG_END); // Cancel button ng.ng_LeftEdge=req->gx+req->gw-ng.ng_Width; ng.ng_GadgetText=req->NegativeText; ng.ng_GadgetID=CANCELBUTTON; gad=CreateGadget(BUTTON_KIND,gad,&ng,TAG_END); // Frequency if(req->Flags & freqgad) { intuitext.IText = GetString(msgReqFrequency, req->Catalog); pixels=IntuiTextLength(&intuitext)+INTERWIDTH; if(pixels+MINSLIDERWIDTH+INTERWIDTH+FREQLEN2*fontwidth > req->gw) return FALSE; ng.ng_Width=req->gw-pixels-INTERWIDTH-FREQLEN2*fontwidth; ng.ng_LeftEdge=req->gx+pixels; ng.ng_TopEdge-=2+buttonheight; ng.ng_GadgetText = GetString(msgReqFrequency, req->Catalog); ng.ng_GadgetID=FREQSLIDER; ng.ng_Flags=PLACETEXT_LEFT; gad=CreateGadget(SLIDER_KIND,gad,&ng, GTSL_Min,0, GTSL_Max,sliderlevels-1, GTSL_Level,sliderlevel, GTSL_LevelFormat, (ULONG) FREQTEXT2, GTSL_MaxLevelLen,FREQLEN2, GTSL_LevelPlace,PLACETEXT_RIGHT, GTSL_DispFunc, (ULONG) m68k_IndexToFrequency, GA_RelVerify,TRUE, GA_Disabled,!sliderlevels || (req->tempAudioID == AHI_DEFAULT_ID), TAG_DONE); req->slidergadget=gad; // Save for HadleReq()... } // ListView if((ng.ng_Height=ng.ng_TopEdge-2-req->gy) < buttonheight) return FALSE; ng.ng_LeftEdge=req->gx; ng.ng_TopEdge=req->gy; ng.ng_Width=req->gw; ng.ng_GadgetText=NULL, ng.ng_GadgetID=LISTVIEW; ng.ng_Flags=PLACETEXT_ABOVE; gad=CreateGadget(LISTVIEW_KIND,gad,&ng, GTLV_ScrollWidth,(fontwidth>8 ? fontwidth*2 : 18), GTLV_Labels, (ULONG) req->list, GTLV_ShowSelected,NULL, ((selected == ~0) || (GadToolsBase->lib_Version >= 39) ? TAG_IGNORE : GTLV_Top),selected, (selected == ~0 ? TAG_IGNORE : GTLV_MakeVisible),selected, GTLV_Selected,selected, TAG_DONE); req->listviewgadget=gad; // Save for HadleReq()... if(!gad) return FALSE; } else return FALSE; AddGList(req->Window,req->Gadgets,~0,-1,NULL); RefreshGList(req->Gadgets,req->Window,NULL,-1); GT_RefreshWindow(req->Window,NULL); return TRUE; }
/*********************************************************************************** * Procedure: request * Synopsis: rc = request(nochoice, txtidx, parm, option) * Purpose: Present a requester to the user ***********************************************************************************/ int request(int nochoice, int txtidx, char *parm, char *option ) { int rqrc; #ifdef PROJECT_VMAKE /* VOpts doesn't support REXX - under VMake want to fail with no requester */ if (global.inrexx) { global.rexxrc = txtidx; /* rexx RC matches config file text entries */ return 0; /* equivalent to user clicking "Cancel" */ } #endif if (IntuitionBase->LibNode.lib_Version >= 36) { int i; ULONG iflags; char *args[5]; struct EasyStruct RespES = { sizeof(struct EasyStruct), 0, NULL, "%s", "%s|%s" }; i = 0; args[i++] = global.text[txtidx]; if (parm) { RespES.es_TextFormat = "%s\n%s"; args[i++] = parm; } if (nochoice) { RespES.es_GadgetFormat = global.text[TEXT_OK]; } else { args[i++] = global.text[TEXT_OK]; if (option) { RespES.es_GadgetFormat = "%s|%s|%s"; args[i++] = option; } args[i++] = global.text[TEXT_CANCEL]; } iflags = IDCMP_DISKINSERTED; rqrc = EasyRequestArgs(global.window, &RespES, &iflags, (APTR)args); } else { struct IntuiText body, body1, pos, neg; int width, height; body.FrontPen = body.BackPen = -1; body.DrawMode = JAM1; body.LeftEdge = 6; body.TopEdge = 4; body.ITextFont = &global.ri.TextAttr; body.IText = global.text[txtidx]; body.NextText = NULL; body1 = body; pos = body; neg = body; width = IntuiTextLength(&body); height = 4 * global.iheight; if (parm) { int ewidth; body.NextText = &body1; body1.IText = parm; body1.TopEdge = global.iheight; height += global.iheight; ewidth = IntuiTextLength(&body1); if (ewidth > width) width = ewidth; } width += 36; /* margins, resize gadget etc. */ pos.IText = global.text[TEXT_OK]; if (nochoice) { neg.IText = pos.IText; } else { neg.IText = global.text[TEXT_CANCEL]; } rqrc = AutoRequest(global.window, &body, &pos, &neg, 0, 0, width, height); } #ifdef PROJECT_VMAKE /* VOpts doesn't support ARexx - want VMake to set ARexx return code */ /* unless user followed a success path from the requester */ if ((rqrc == 0) || nochoice) global.rexxrc = txtidx; #endif return rqrc; }