home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************/
- /* */
- /* Includes */
- /* */
- /*************************************************************************/
-
- #include "Calculator_Includes.h"
- #include "Calculator_Structures.h"
-
- /*************************************************************************/
- /* */
- /* Variables and Structures */
- /* */
- /*************************************************************************/
-
- extern struct IntuitionBase *IntuitionBase;
- extern struct GfxBase *GfxBase;
-
- extern struct Library *GadToolsBase;
- extern struct Library *AslBase;
- extern struct Library *DataTypesBase;
-
- /*************************************************************************/
- /* */
- /* Defines */
- /* */
- /*************************************************************************/
-
- #define RASTERX (GfxBase->DefaultFont->tf_XSize)
- #define RASTERY (GfxBase->DefaultFont->tf_YSize)
-
- #define XSIZE(x) ((x)*RASTERX)
- #define YSIZE(x) ((x)*RASTERY)
-
- #define XPOS(x) (XSIZE(x)+customscreen->WBorLeft)
- #define YPOS(x) (YSIZE(x)+customscreen->BarHeight+1)
-
- /*************************************************************************/
- /* */
- /* SleepWindow() und WakenWindow() */
- /* */
- /*************************************************************************/
-
- static struct Requester waitrequest;
-
- void SleepWindow(struct Window *win)
- {
- InitRequester(&waitrequest);
- Request(&waitrequest,win);
- SetWindowPointer(win,WA_BusyPointer,1L,TAG_DONE);
- }
-
- void WakenWindow(struct Window *win)
- {
- EndRequest(&waitrequest,win);
- SetWindowPointer(win,WA_Pointer,0L,TAG_DONE);
- }
-
- /*************************************************************************/
- /* */
- /* GUICreatorErrorReport() */
- /* */
- /*************************************************************************/
-
- void GUICreatorErrorReport(struct Window *win,ULONG type)
- {
- char error[256];
- struct EasyStruct easystruct = { sizeof(struct EasyStruct),0,"Caution:",error,"OK" };
-
- if (type == ERROR_NO_WINDOW_OPENED)
- strcpy(error,"Could not open window (no memory?)");
- else if (type == ERROR_NO_PUBSCREEN_LOCKED)
- strcpy(error,"Could not lock pubscreen");
- else if (type == ERROR_NO_GADGETS_CREATED)
- strcpy(error,"Could not create gadgets");
- else if (type == ERROR_NO_GADGETLIST_CREATED)
- strcpy(error,"Could not create gadgetlist");
- else if (type == ERROR_NO_VISUALINFO)
- strcpy(error,"Could not read visualinfo from screen");
- else if (type == ERROR_NO_PICTURE_LOADED)
- strcpy(error,"Could not read picture data");
- else if (type == ERROR_NO_WINDOW_MENU)
- strcpy(error,"Could not create menu");
- else if (type == ERROR_SCREEN_TOO_SMALL)
- strcpy(error,"This screen is too small for the window");
- else Fault(type,"Error",error,sizeof(error));
-
- if (win && !win->FirstRequest)
- {
- SleepWindow(win);
- EasyRequestArgs(win,&easystruct,NULL,NULL);
- WakenWindow(win);
- }
- else EasyRequestArgs(win,&easystruct,NULL,NULL);
-
- }
-
- /*************************************************************************/
- /* */
- /* CreateBevelFrames() */
- /* */
- /*************************************************************************/
-
- void CreateBevelFrames(struct Window *win,APTR visualinfo,ULONG bevelcount,struct BevelFrame bevels[])
- {
- ULONG i;
- for (i=0;i<bevelcount;i++)
- {
- DrawBevelBox(win->RPort,bevels[i].bb_LeftEdge,bevels[i].bb_TopEdge,bevels[i].bb_Width,bevels[i].bb_Height,GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
- DrawBevelBox(win->RPort,bevels[i].bb_LeftEdge+2,bevels[i].bb_TopEdge+1,bevels[i].bb_Width-4,bevels[i].bb_Height-2,GT_VisualInfo,visualinfo,TAG_END);
- if (bevels[i].bb_Title)
- {
- char title[64];
- sprintf(title," %s ",bevels[i].bb_Title);
- Move(win->RPort,bevels[i].bb_LeftEdge+(bevels[i].bb_Width-XSIZE(strlen(title)))/2,bevels[i].bb_TopEdge+2);
- SetAPen(win->RPort,bevels[i].bb_Color);
- Text(win->RPort,title,strlen(title));
- }
- /* end-if */
- }
- /* end-for */
- }
-
- /*************************************************************************/
- /* */
- /* CreateLines() */
- /* */
- /*************************************************************************/
-
- void CreateLines(struct Window *win,int linecount,struct Line lines[])
- {
- ULONG i;
- for (i=0;i<linecount;i++)
- {
- SetAPen(win->RPort,lines[i].li_Color);
- Move(win->RPort,lines[i].li_LeftEdge,lines[i].li_TopEdge);
- Draw(win->RPort,lines[i].li_Width>0?lines[i].li_LeftEdge+lines[i].li_Width-1:lines[i].li_LeftEdge+lines[i].li_Width,lines[i].li_Height>0?lines[i].li_TopEdge+lines[i].li_Height-1:lines[i].li_TopEdge+lines[i].li_Height);
- }
- /* end-for */
- }
-
- /*************************************************************************/
- /* */
- /* CreateTexts() */
- /* */
- /*************************************************************************/
-
- void CreateTexts(struct Window *win,int textcount,struct Text texts[], long double xscale,long double yscale)
- {
- ULONG i;
- for (i=0;i<textcount;i++)
- {
- SetAPen(win->RPort,texts[i].tx_Color);
- Move(win->RPort,texts[i].tx_LeftEdge,texts[i].tx_TopEdge+(ULONG)(yscale*GfxBase->DefaultFont->tf_Baseline));
- Text(win->RPort,texts[i].tx_Text,strlen(texts[i].tx_Text));
- }
- /* end-for */
- }
-
- /*************************************************************************/
- /* */
- /* About() */
- /* */
- /*************************************************************************/
-
- void About(struct Window *hostwin)
- {
- APTR visualinfo=GetVisualInfo(hostwin->WScreen,TAG_DONE);
- if (visualinfo)
- {
- Object *o=NewDTObject("/About.IFF",DTA_SourceType,DTST_FILE,DTA_GroupID,GID_PICTURE,TAG_DONE);
- if (o)
- {
- struct Gadget *gadgetlist = NULL;
- struct Screen *customscreen = hostwin->WScreen;
- struct Gadget *gadget = CreateContext(&gadgetlist);
- if (gadget)
- {
- ULONG height=25,width=34,left=0,top=0;
- ULONG textcount=18;
-
- struct Gadget *wingad;
-
- STRPTR title = "About";
- struct Window *win = NULL;
-
- struct TextAttr textattr = { GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name,GfxBase->DefaultFont->tf_YSize,FS_NORMAL,FPF_DISKFONT };
-
- struct NewGadget newgad = { XPOS(1),YPOS(22),XSIZE(32)+200,YSIZE(2),"_OK",&textattr,2,PLACETEXT_IN,visualinfo,NULL };
-
- struct Text texts[] = {
- 200+XPOS(4),YPOS(2),"****************************",1,
- 200+XPOS(4),YPOS(3),"* *",1,
- 200+XPOS(4),YPOS(4),"* This GUI was designed *",1,
- 200+XPOS(4),YPOS(5),"* *",1,
- 200+XPOS(4),YPOS(6),"* with GUI-Creator V 1.0 *",1,
- 200+XPOS(4),YPOS(7),"* *",1,
- 200+XPOS(4),YPOS(8),"* © 1995 by *",1,
- 200+XPOS(4),YPOS(9),"* Markus Hillenbrand *",1,
- 200+XPOS(4),YPOS(10),"* *",1,
- 200+XPOS(4),YPOS(11),"* ------------------------ *",1,
- 200+XPOS(4),YPOS(12),"* *",1,
- 200+XPOS(4),YPOS(13),"* GUI-Creator is Shareware *",1,
- 200+XPOS(4),YPOS(14),"* *",1,
- 200+XPOS(4),YPOS(15),"* Please read the docs for *",1,
- 200+XPOS(4),YPOS(16),"* *",1,
- 200+XPOS(4),YPOS(17),"* more information! *",1,
- 200+XPOS(4),YPOS(18),"* *",1,
- 200+XPOS(4),YPOS(19),"****************************",1,
- };
-
- height= YSIZE(height);
- width = XSIZE(width)+200;
- left = (customscreen->Width-width)/2;
- top = (customscreen->Height-height)/2;
-
- wingad = gadget = CreateGadget(BUTTON_KIND,gadget,&newgad,GT_Underscore,'_',TAG_END);
-
- if (height>customscreen->Height || width>customscreen->Width) GUICreatorErrorReport(hostwin,ERROR_SCREEN_TOO_SMALL);
- win=OpenWindowTags(NULL,WA_Activate, TRUE,
- WA_CloseGadget, TRUE,
- WA_DepthGadget, TRUE,
- WA_SizeGadget, FALSE,
- WA_DragBar, TRUE,
- WA_Gadgets, gadgetlist,
- WA_InnerHeight, height,
- WA_InnerWidth, width,
- WA_IDCMP, IDCMP_CLOSEWINDOW|BUTTONIDCMP|IDCMPUPDATE|IDCMP_VANILLAKEY,
- WA_Left, left,
- WA_Top, top,
- WA_SmartRefresh, TRUE,
- WA_Title, title,
- WA_CustomScreen, customscreen,
- TAG_END);
- if (win)
- {
- struct IntuiMessage *imessage = NULL;
- struct Gadget *idcmpgad = NULL;
- struct BitMap *bmcopy = NULL;
- struct TagItem *tag = NULL;
- struct TagItem *tstate = NULL;
- ULONG idcmpclass = 0;
- UWORD messagecode = 0;
- BOOL running = TRUE;
-
- SleepWindow(hostwin);
- SetFont(win->RPort,GfxBase->DefaultFont);
-
- DrawBevelBox(win->RPort,XPOS(1),YPOS(1),204,102,GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
- DrawBevelBox(win->RPort,XPOS(3)+200,YPOS(1),XSIZE(30),YSIZE(20),GT_VisualInfo,visualinfo,GTBB_Recessed,TRUE,TAG_END);
-
- SetDTAttrs(o,NULL,NULL,GA_Left,XPOS(1)+2,GA_Top,YPOS(1)+1,GA_Width,200,GA_Height,100,PDTA_Remap,TRUE,PDTA_DestBitMap,&bmcopy,ICA_TARGET,ICTARGET_IDCMP,TAG_DONE);
- AddDTObject(win,NULL,o,-1L);
-
- CreateTexts(win,textcount,texts,1.0,1.0);
-
- GT_RefreshWindow(win,NULL);
-
- while (running)
- {
- Wait(1L << win->UserPort->mp_SigBit);
- while (imessage=GT_GetIMsg(win->UserPort))
- {
- idcmpgad=(struct Gadget *)imessage->IAddress;
- idcmpclass=imessage->Class;
- messagecode =imessage->Code;
-
- GT_ReplyIMsg(imessage);
-
- switch(idcmpclass)
- {
- case IDCMP_VANILLAKEY:
- if (messagecode == 27 || messagecode == 'o' || messagecode == 'O') running=FALSE;
- break;
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh(win);
- GT_EndRefresh(win,TRUE);
- break;
- case IDCMP_CLOSEWINDOW:
- running=FALSE;
- break;
- case BUTTONIDCMP:
- running=FALSE;
- break;
- case IDCMP_IDCMPUPDATE:
- tstate=(struct TagItem*)imessage->IAddress;
- while (tag=NextTagItem(&tstate)) if (tag->ti_Tag == DTA_Sync) RefreshDTObjectA(o,win,NULL,NULL);
- break;
- }
- /* end-switch */
-
- }
- /* end-while */
- }
- /* end-while */
-
- CloseWindow(win);
- WakenWindow(hostwin);
- }
- else GUICreatorErrorReport(hostwin,ERROR_NO_WINDOW_OPENED);
- FreeGadgets(gadgetlist);
- }
- else GUICreatorErrorReport(hostwin,ERROR_NO_GADGETLIST_CREATED);
- DisposeDTObject(o);
- }
- else GUICreatorErrorReport(hostwin,ERROR_NO_PICTURE_LOADED);
- FreeVisualInfo(visualinfo);
- }
- else GUICreatorErrorReport(hostwin,ERROR_NO_VISUALINFO);
-
- }
-