home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Otherware
/
Otherware_1_SB_Development.iso
/
amiga
/
comms
/
network
/
grn1asrc.lha
/
requesters.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-20
|
17KB
|
611 lines
#include "defs.h"
static TATTR topaz80 = { "topaz.font", 8, 0,0 };
static VINFO *vi;
// The 1x1 null requester that is used to disable the gadtools gadgets,
// as per the flamewars on usenet:
static struct Requester req = {
0,
0,0,
1,1,
0,0,
0,
0,
0,
0,
0,
0,
0,
0,
};
BOOL GuageRequest(percent,titleText, reqText, buttonText)
UWORD percent;
char *titleText, *reqText, *buttonText;
{
short titleLen = TextLength(topazRP, titleText, strlen(titleText));
short reqLen = TextLength(topazRP, reqText, strlen(reqText));
short buttonLen = TextLength(topazRP, buttonText, strlen(buttonText));
static WINDOW *reqWindow = 0;
WINDOW *win = mainWindow;
short width = titleLen;
short height = topazRP->TxHeight*6 + screen->BarHeight;
static GADGET *gList = 0, *gadget;
NEWGAD ng;
static RPORT *reqrp;
IMSG *m, msg;
static UWORD guageX,guageY,guageW,guageH;
UWORD ww;
static BOOL activeFlag;
vi = GetVisualInfo(screen, TAG_DONE);
if (reqLen > width) width = reqLen;
if (buttonLen > width) width = buttonLen;
width += 10;
if (!reqWindow) {
if (percent >= 100) return 0;
gadget = CreateContext(&gList);
if (!gadget) return 0;
ng.ng_GadgetID = 0;
ng.ng_TextAttr = &topaz80;
ng.ng_VisualInfo = vi;
ng.ng_LeftEdge = (width-buttonLen)/2;
ng.ng_TopEdge = height-topazRP->TxHeight-6-INTERHEIGHT;
ng.ng_Width = buttonLen+6;
ng.ng_Height = topazRP->TxHeight+6;
ng.ng_GadgetText = buttonText;
ng.ng_Flags = NG_HIGHLABEL;
gadget = CreateGadget(BUTTON_KIND, gadget, &ng, GT_Underscore, ' ', TAG_DONE);
if (!gadget) {
FreeGadgets(gList);
gList = 0;
return 0;
}
Request(&req, win);
reqWindow = OpenWindowTags(NULL,
WA_Left,win->LeftEdge+(win->Width - width)/2,
WA_Top,win->TopEdge+(win->Height - height)/2,
WA_Width,width,
WA_Height,height,
WA_DetailPen,3,
WA_BlockPen,1,
WA_IDCMP,BUTTONIDCMP|INACTIVEWINDOW,
WA_Gadgets,gList,
WA_Title,titleText,
WA_CustomScreen,screen,
WA_SuperBitMap,0,
WA_MinWidth,30,
WA_MinHeight,30,
WA_MaxWidth,-1,
WA_MaxHeight,-1,
WA_SizeGadget,FALSE,
WA_DragBar,FALSE,
WA_DepthGadget,FALSE,
WA_CloseGadget,FALSE,
WA_Backdrop,FALSE,
WA_ReportMouse,FALSE,
WA_Borderless,FALSE,
WA_Activate,TRUE,
WA_RMBTrap,TRUE,
WA_SimpleRefresh,TRUE,
TAG_DONE
);
if (!reqWindow) {
FreeGadgets(gList);
gList = 0;
EndRequest(&req, win);
return !0;
}
activeFlag = !0;
GT_RefreshWindow(reqWindow, NULL);
reqrp = reqWindow->RPort;
SetFont(reqrp, topaz80Font);
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
guageH = 12;
guageW = width-16;
guageX = (width-guageW)/2;
guageY = screen->BarHeight+2+reqrp->TxHeight + 2;
DrawBevelBox(reqrp, guageX,guageY,guageW,guageH, GTBB_Recessed,TRUE, GT_VisualInfo, vi, TAG_DONE);
guageW -=4; guageH -= 3;
}
if (percent >= 100) {
CloseWindow(reqWindow);
reqWindow = 0;
FreeGadgets(gList);
gList = 0;
EndRequest(&req, win);
return 0;
}
ww = percent*guageW/100;
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
guageH = 12;
guageW = width-16;
guageX = (width-guageW)/2;
guageY = screen->BarHeight+2+reqrp->TxHeight + 2;
DrawBevelBox(reqrp, guageX,guageY,guageW,guageH, GTBB_Recessed,TRUE, GT_VisualInfo, vi, TAG_DONE);
guageW -=4; guageH -= 3;
ww = percent*guageW/100;
if (ww) {
SetAPen(reqrp,3);
RectFill(reqrp, guageX+2,guageY+1,guageX+ww+2,guageY+1+guageH);
}
while (m = GT_GetIMsg(reqWindow->UserPort)) {
msg = *m;
GT_ReplyIMsg(m);
if (msg.Class == IDCMP_GADGETUP || msg.Class == IDCMP_GADGETDOWN) {
CloseWindow(reqWindow);
reqWindow = 0;
FreeGadgets(gList);
gList = 0;
EndRequest(&req, win);
return !0;
}
else if (msg.Class == IDCMP_REFRESHWINDOW) {
GT_BeginRefresh(reqWindow);
GT_EndRefresh(reqWindow, TRUE);
}
else if (msg.Class == IDCMP_INACTIVEWINDOW) {
activeFlag = 0;
}
}
if (!activeFlag && IntuitionBase->ActiveWindow == win) {
MoveWindowInFrontOf(reqWindow, win);
ActivateWindow(reqWindow);
activeFlag = !0;
}
return 0;
}
BOOL OneGadgetRequest(titleText, reqText, buttonText)
char *titleText, *reqText, *buttonText;
{
short titleLen = TextLength(topazRP, titleText, strlen(titleText));
short reqLen = TextLength(topazRP, reqText, strlen(reqText));
short buttonLen = TextLength(topazRP, buttonText, strlen(buttonText));
WINDOW *reqWindow = 0, *win = mainWindow;
short width = titleLen;
short height = topazRP->TxHeight*4 + screen->BarHeight;
GADGET *gList = 0, *gadget;
NEWGAD ng;
RPORT *reqrp;
IMSG *m, msg;
BOOL activeFlag = 0;
vi = GetVisualInfo(screen, TAG_DONE);
if (reqLen > width) width = reqLen;
if (buttonLen > width) width = buttonLen;
width += 10;
gadget = CreateContext(&gList);
if (!gadget) return 0;
ng.ng_GadgetID = 0;
ng.ng_TextAttr = &topaz80;
ng.ng_VisualInfo = vi;
ng.ng_LeftEdge = (width-buttonLen)/2;
ng.ng_TopEdge = height-topazRP->TxHeight-6-INTERHEIGHT;
ng.ng_Width = buttonLen+6;
ng.ng_Height = topazRP->TxHeight+6;
ng.ng_GadgetText = buttonText;
ng.ng_Flags = NG_HIGHLABEL;
gadget = CreateGadget(BUTTON_KIND, gadget, &ng, GT_Underscore, '_', TAG_DONE);
if (!gadget) {
FreeGadgets(gList);
return 0;
}
Request(&req, win);
reqWindow = OpenWindowTags(NULL,
WA_Left,win->LeftEdge+(win->Width - width)/2,
WA_Top,win->TopEdge+(win->Height - height)/2,
WA_Width,width,
WA_Height,height,
WA_DetailPen,3,
WA_BlockPen,1,
WA_IDCMP,BUTTONIDCMP|INACTIVEWINDOW|IDCMP_RAWKEY,
WA_Gadgets,gList,
WA_Title,titleText,
WA_CustomScreen,screen,
WA_SuperBitMap,0,
WA_MinWidth,30,
WA_MinHeight,30,
WA_MaxWidth,-1,
WA_MaxHeight,-1,
WA_SizeGadget,FALSE,
WA_DragBar,FALSE,
WA_DepthGadget,FALSE,
WA_CloseGadget,FALSE,
WA_Backdrop,FALSE,
WA_ReportMouse,FALSE,
WA_Borderless,FALSE,
WA_Activate,TRUE,
WA_RMBTrap,TRUE,
WA_SimpleRefresh,TRUE,
TAG_DONE
);
if (!reqWindow) {
FreeGadgets(gList);
EndRequest(&req, win);
return 0;
}
GT_RefreshWindow(reqWindow, NULL);
activeFlag = !0;
reqrp = reqWindow->RPort;
SetFont(reqrp, topaz80Font);
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
MoveWindowInFrontOf(reqWindow, win);
while (1) {
Delay(25);
while (m = GT_GetIMsg(reqWindow->UserPort)) {
msg = *m;
GT_ReplyIMsg(m);
if (msg.Class == IDCMP_GADGETUP || msg.Class == IDCMP_GADGETDOWN) {
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
return !0;
}
else if (msg.Class == IDCMP_REFRESHWINDOW) {
GT_BeginRefresh(reqWindow);
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
GT_EndRefresh(reqWindow, TRUE);
}
else if (msg.Class == IDCMP_RAWKEY && msg.Code == 0x45) {
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
return !0;
}
else if (msg.Class == IDCMP_INACTIVEWINDOW) {
activeFlag = 0;
}
}
if (!activeFlag && IntuitionBase->ActiveWindow == win) {
MoveWindowInFrontOf(reqWindow, win);
ActivateWindow(reqWindow);
activeFlag = !0;
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
}
}
}
BOOL TwoGadgetRequest(titleText, reqText, leftText, rightText)
char *titleText, *reqText, *leftText, *rightText;
{
short titleLen = TextLength(topazRP, titleText, strlen(titleText));
short reqLen = TextLength(topazRP, reqText, strlen(reqText));
short leftLen = TextLength(topazRP, leftText, strlen(leftText));
short rightLen = TextLength(topazRP, rightText, strlen(rightText));
WINDOW *reqWindow = 0, *win = mainWindow;
short width = titleLen;
short height = topazRP->TxHeight*4 + screen->BarHeight;
GADGET *gList = 0, *gadget;
NEWGAD ng;
RPORT *reqrp;
IMSG *m, msg;
BOOL activeFlag = 0;
vi = GetVisualInfo(screen, TAG_DONE);
if (leftLen > rightLen) rightLen = leftLen;
if (rightLen > leftLen) leftLen = rightLen;
if (reqLen > width) width = reqLen;
if (leftLen + rightLen + 20 > width) width = leftLen + rightLen + 32;
width += 10;
gadget = CreateContext(&gList);
if (!gadget) return 0;
ng.ng_GadgetID = 0;
ng.ng_TextAttr = &topaz80;
ng.ng_VisualInfo = vi;
ng.ng_LeftEdge = 6;
ng.ng_TopEdge = height-topazRP->TxHeight-6-INTERHEIGHT;
ng.ng_Width = leftLen+6;
ng.ng_Height = topazRP->TxHeight+6;
ng.ng_GadgetText = leftText;
ng.ng_Flags = NG_HIGHLABEL;
gadget = CreateGadget(BUTTON_KIND, gadget, &ng, GT_Underscore, '_', TAG_DONE);
if (!gadget) {
FreeGadgets(gList);
return 0;
}
ng.ng_GadgetID = 1;
ng.ng_TextAttr = &topaz80;
ng.ng_VisualInfo = vi;
ng.ng_LeftEdge = width-rightLen-12;
ng.ng_TopEdge = height-topazRP->TxHeight-6-INTERHEIGHT;
ng.ng_Width = rightLen+6;
ng.ng_Height = topazRP->TxHeight+6;
ng.ng_GadgetText = rightText;
ng.ng_Flags = NG_HIGHLABEL;
gadget = CreateGadget(BUTTON_KIND, gadget, &ng, GT_Underscore, '_', TAG_DONE);
if (!gadget) {
FreeGadgets(gList);
return 0;
}
Request(&req, win);
reqWindow = OpenWindowTags(NULL,
WA_Left,win->LeftEdge+(win->Width - width)/2,
WA_Top,win->TopEdge+(win->Height - height)/2,
WA_Width,width,
WA_Height,height,
WA_DetailPen,3,
WA_BlockPen,1,
WA_IDCMP,BUTTONIDCMP|INACTIVEWINDOW|VANILLAKEY,
WA_Gadgets,gList,
WA_Title,titleText,
WA_CustomScreen,screen,
WA_SuperBitMap,0,
WA_MinWidth,30,
WA_MinHeight,30,
WA_MaxWidth,-1,
WA_MaxHeight,-1,
WA_SizeGadget,FALSE,
WA_DragBar,FALSE,
WA_DepthGadget,FALSE,
WA_CloseGadget,FALSE,
WA_Backdrop,FALSE,
WA_ReportMouse,FALSE,
WA_Borderless,FALSE,
WA_Activate,TRUE,
WA_RMBTrap,TRUE,
WA_SimpleRefresh,TRUE,
TAG_DONE
);
if (!reqWindow) {
FreeGadgets(gList);
EndRequest(&req, win);
return 0;
}
GT_RefreshWindow(reqWindow, NULL);
activeFlag = !0;
reqrp = reqWindow->RPort;
SetFont(reqrp, topaz80Font);
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
MoveWindowInFrontOf(reqWindow, win);
while (1) {
Delay(25);
while (m = GT_GetIMsg(reqWindow->UserPort)) {
msg = *m;
GT_ReplyIMsg(m);
if (msg.Class == IDCMP_GADGETUP || msg.Class == IDCMP_GADGETDOWN) {
gadget = (GADGET *)msg.IAddress;
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
if (gadget->GadgetID) return 0; else return !0;
}
else if (msg.Class == IDCMP_REFRESHWINDOW) {
GT_BeginRefresh(reqWindow);
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
GT_EndRefresh(reqWindow, TRUE);
}
else if (msg.Class == IDCMP_INACTIVEWINDOW) {
activeFlag = 0;
}
else if (msg.Class == IDCMP_VANILLAKEY) {
if (msg.Code == 'y' || msg.Code == 'Y') {
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
return !0;
}
if (msg.Code == 'n' || msg.Code == 'N' || msg.Code == 0x1b) {
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
return 0;
}
}
}
if (!activeFlag && IntuitionBase->ActiveWindow == win) {
MoveWindowInFrontOf(reqWindow, win);
ActivateWindow(reqWindow);
activeFlag = !0;
SetAPen(reqrp, 2);
Move(reqrp, (width-reqLen)/2,screen->BarHeight+2+reqrp->TxBaseline);
Text(reqrp, reqText, strlen(reqText));
}
}
}
static char *postText[] = {
"You are about to post news. This will cause a zillion Unix machines",
"to spread your article all over the explored universe at a cost of",
"several trillion dollars. And to top it off, you can expect other",
"lunatics in NetLand to follow up to your article and do likewise.",
"If you are lucky, you won't get flamed to a crisp.",
" ",
" Are you really sure you want to proceed? ",
0,
};
BOOL SendItRequest() {
char *titleText = "GRN - Read Carefully before answering...";
char *leftText = "_YES, I have guts";
char *rightText = "_NO, I am a gutless worm";
short titleLen = TextLength(topazRP, titleText, strlen(titleText));
short reqLen = TextLength(topazRP, postText[0], strlen(postText[0]));
short leftLen = TextLength(topazRP, leftText, strlen(leftText))+INTERWIDTH;
short rightLen = TextLength(topazRP, rightText, strlen(rightText))+INTERWIDTH;
WINDOW *reqWindow = 0, *win = mainWindow;
short width = titleLen;
short height = topazRP->TxHeight*10 + screen->BarHeight;
GADGET *gList = 0, *gadget;
NEWGAD ng;
RPORT *reqrp;
IMSG *m, msg;
BOOL activeFlag = 0;
short i, y;
vi = GetVisualInfo(screen, TAG_DONE);
if (leftLen > rightLen) rightLen = leftLen;
if (rightLen > leftLen) leftLen = rightLen;
if (reqLen > width) width = reqLen;
if (leftLen + rightLen + 20 > width) width = leftLen + rightLen + 32;
width += 10;
gadget = CreateContext(&gList);
if (!gadget) return 0;
ng.ng_GadgetID = 0;
ng.ng_TextAttr = &topaz80;
ng.ng_VisualInfo = vi;
ng.ng_LeftEdge = 6;
ng.ng_TopEdge = height-topazRP->TxHeight-6-INTERHEIGHT;
ng.ng_Width = leftLen+6;
ng.ng_Height = topazRP->TxHeight+6;
ng.ng_GadgetText = leftText;
ng.ng_Flags = NG_HIGHLABEL;
gadget = CreateGadget(BUTTON_KIND, gadget, &ng, GT_Underscore, '_', TAG_DONE);
if (!gadget) {
FreeGadgets(gList);
return 0;
}
ng.ng_GadgetID = 1;
ng.ng_TextAttr = &topaz80;
ng.ng_VisualInfo = vi;
ng.ng_LeftEdge = width-rightLen-12;
ng.ng_TopEdge = height-topazRP->TxHeight-6-INTERHEIGHT;
ng.ng_Width = rightLen+6;
ng.ng_Height = topazRP->TxHeight+6;
ng.ng_GadgetText = rightText;
ng.ng_Flags = NG_HIGHLABEL;
gadget = CreateGadget(BUTTON_KIND, gadget, &ng, GT_Underscore, '_', TAG_DONE);
if (!gadget) {
FreeGadgets(gList);
return 0;
}
Request(&req, win);
reqWindow = OpenWindowTags(NULL,
WA_Left,win->LeftEdge+(win->Width - width)/2,
WA_Top,win->TopEdge+(win->Height - height)/2,
WA_Width,width,
WA_Height,height,
WA_DetailPen,3,
WA_BlockPen,1,
WA_IDCMP,BUTTONIDCMP|INACTIVEWINDOW|VANILLAKEY,
WA_Gadgets,gList,
WA_Title,titleText,
WA_CustomScreen,screen,
WA_SuperBitMap,0,
WA_MinWidth,30,
WA_MinHeight,30,
WA_MaxWidth,-1,
WA_MaxHeight,-1,
WA_SizeGadget,FALSE,
WA_DragBar,FALSE,
WA_DepthGadget,FALSE,
WA_CloseGadget,FALSE,
WA_Backdrop,FALSE,
WA_ReportMouse,FALSE,
WA_Borderless,FALSE,
WA_Activate,TRUE,
WA_RMBTrap,TRUE,
WA_SimpleRefresh,TRUE,
TAG_DONE
);
if (!reqWindow) {
FreeGadgets(gList);
EndRequest(&req, win);
return 0;
}
GT_RefreshWindow(reqWindow, NULL);
activeFlag = !0;
reqrp = reqWindow->RPort;
SetFont(reqrp, topaz80Font);
y = screen->BarHeight+2+reqrp->TxBaseline;
for (i=0; postText[i]; i++) {
SetAPen(reqrp, 1);
Move(reqrp, (width-reqLen)/2, y);
Text(reqrp, postText[i], strlen(postText[i]));
y += reqrp->TxHeight;
}
MoveWindowInFrontOf(reqWindow, win);
while (1) {
Delay(25);
while (m = GT_GetIMsg(reqWindow->UserPort)) {
msg = *m;
GT_ReplyIMsg(m);
if (msg.Class == IDCMP_GADGETUP || msg.Class == IDCMP_GADGETDOWN) {
gadget = (GADGET *)msg.IAddress;
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
if (gadget->GadgetID) return 0; else return !0;
}
else if (msg.Class == IDCMP_REFRESHWINDOW) {
GT_BeginRefresh(reqWindow);
SetAPen(reqrp, 2);
y = screen->BarHeight+2+reqrp->TxBaseline;
for (i=0; postText[i]; i++) {
SetAPen(reqrp, 1);
Move(reqrp, (width-reqLen)/2, y);
Text(reqrp, postText[i], strlen(postText[i]));
y += reqrp->TxHeight;
}
GT_EndRefresh(reqWindow, TRUE);
}
else if (msg.Class == IDCMP_INACTIVEWINDOW) {
activeFlag = 0;
}
else if (msg.Class == IDCMP_VANILLAKEY) {
if (msg.Code == 'y' || msg.Code == 'Y') {
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
return !0;
}
if (msg.Code == 'n' || msg.Code == 'N' || msg.Code == 0x1b) {
CloseWindow(reqWindow);
FreeGadgets(gList);
EndRequest(&req, win);
return 0;
}
}
}
if (!activeFlag && IntuitionBase->ActiveWindow == win) {
MoveWindowInFrontOf(reqWindow, win);
ActivateWindow(reqWindow);
activeFlag = !0;
y = screen->BarHeight+2+reqrp->TxBaseline;
for (i=0; postText[i]; i++) {
SetAPen(reqrp, 1);
Move(reqrp, (width-reqLen)/2, y);
Text(reqrp, postText[i], strlen(postText[i]));
y += reqrp->TxHeight;
}
}
}
}