home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
datafiles
/
hardware
/
eprommer
/
source.lha
/
src
/
gad_eprommer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-14
|
25KB
|
914 lines
/*
* Source machine generated by GadToolsBox V2.0b
* which is (c) Copyright 1991-1993 Jaba Development
*
* GUI Designed by : -- Unnamed --
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include "gad_eprommer.h"
struct Screen *Scr = NULL;
UBYTE *PubScreenName = NULL;
APTR VisualInfo = NULL;
struct Window *EprommerWnd = NULL;
struct Window *OptionsWnd = NULL;
struct Window *BusyWnd = NULL;
struct Window *TestWnd = NULL;
struct Gadget *EprommerGList = NULL;
struct Gadget *OptionsGList = NULL;
struct Gadget *BusyGList = NULL;
struct Gadget *TestGList = NULL;
struct IntuiMessage EprommerMsg;
struct IntuiMessage OptionsMsg;
struct IntuiMessage BusyMsg;
struct IntuiMessage TestMsg;
struct Gadget *EprommerGadgets[21];
struct Gadget *OptionsGadgets[10];
struct Gadget *BusyGadgets[1];
struct Gadget *TestGadgets[4];
extern Class *initGet( void );
struct IClass *getClass = NULL;
struct _Object *getImage = NULL;
UWORD EprommerLeft = 26;
UWORD EprommerTop = 34;
UWORD EprommerWidth = 502;
UWORD EprommerHeight = 182;
UWORD OptionsLeft = 238;
UWORD OptionsTop = 53;
UWORD OptionsWidth = 223;
UWORD OptionsHeight = 175;
UWORD BusyLeft = 229;
UWORD BusyTop = 129;
UWORD BusyWidth = 177;
UWORD BusyHeight = 46;
UWORD TestLeft = 80;
UWORD TestTop = 98;
UWORD TestWidth = 204;
UWORD TestHeight = 95;
UBYTE *EprommerWdt = (UBYTE *)"-";
UBYTE *OptionsWdt = (UBYTE *)"Options";
UBYTE *BusyWdt = NULL;
UBYTE *TestWdt = (UBYTE *)"Check Eprommer";
struct TextAttr *Font, Attr;
UWORD FontX, FontY;
UWORD OffX, OffY;
UBYTE *DataFormat0Labels[] = {
(UBYTE *)"Binary",
(UBYTE *)"IntelHex",
NULL };
UBYTE *ProgAlgo0Labels[] = {
(UBYTE *)"50 msec",
(UBYTE *)"IntEligent",
(UBYTE *)"Eprommer",
(UBYTE *)"No delay",
NULL };
UBYTE *EpromType0Labels[] = {
(UBYTE *)"2716",
(UBYTE *)"2732",
(UBYTE *)"2732A",
(UBYTE *)"2764",
(UBYTE *)"2764A",
(UBYTE *)"27128",
(UBYTE *)"27256",
(UBYTE *)"27512",
(UBYTE *)"6216",
(UBYTE *)"6264",
(UBYTE *)"62256",
NULL };
UBYTE *NumericalBase1Labels[] = {
(UBYTE *)"Only Decimal",
(UBYTE *)"Dec. & Hex.",
(UBYTE *)"Hexadecimal",
NULL };
UBYTE *SetVpp3Labels[] = {
(UBYTE *)"12.5 V",
(UBYTE *)"21 V",
(UBYTE *)"25 V",
NULL };
UBYTE *T_CyAddress3Labels[] = {
(UBYTE *)"0x5555",
(UBYTE *)"0xAAAA",
NULL };
UBYTE *T_CyData3Labels[] = {
(UBYTE *)"0x55",
(UBYTE *)"0xAA",
NULL };
struct IntuiText EprommerIText[] = {
1, 0, JAM1,264, 11, NULL, (UBYTE *)"Address", NULL,
1, 0, JAM1,416, 11, NULL, (UBYTE *)"Eprom Type", NULL,
1, 0, JAM1,416, 127, NULL, (UBYTE *)"Algorythm", NULL,
1, 0, JAM1,100, 91, NULL, (UBYTE *)"Action", NULL };
#define Eprommer_TNUM 4
struct IntuiText BusyIText[] = {
2, 0, JAM1,52, 15, NULL, (UBYTE *)"Address:", NULL,
1, 0, JAM2,128, 15, NULL, (UBYTE *)"0x---- ", NULL };
#define Busy_TNUM 2
UWORD EprommerGTypes[] = {
CYCLE_KIND,
MX_KIND,
MX_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
GENERIC_KIND,
GENERIC_KIND,
STRING_KIND,
STRING_KIND,
STRING_KIND,
STRING_KIND,
STRING_KIND,
STRING_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND
};
UWORD OptionsGTypes[] = {
CYCLE_KIND,
CHECKBOX_KIND,
CHECKBOX_KIND,
CHECKBOX_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
CHECKBOX_KIND,
CHECKBOX_KIND,
INTEGER_KIND
};
UWORD BusyGTypes[] = {
BUTTON_KIND
};
UWORD TestGTypes[] = {
CHECKBOX_KIND,
CYCLE_KIND,
CYCLE_KIND,
CYCLE_KIND
};
struct NewGadget EprommerNGad[] = {
51, 19, 95, 11, (UBYTE *)"Data Format", NULL, GD_DataFormat, PLACETEXT_ABOVE, NULL, (APTR)DataFormatClicked,
373, 135, 17, 9, NULL, NULL, GD_ProgAlgo, PLACETEXT_RIGHT, NULL, (APTR)ProgAlgoClicked,
373, 19, 17, 9, NULL, NULL, GD_EpromType, PLACETEXT_RIGHT, NULL, (APTR)EpromTypeClicked,
220, 101, 132, 11, (UBYTE *)"Read Byte", NULL, GD_ReadByte, PLACETEXT_IN, NULL, (APTR)ReadByteClicked,
220, 116, 132, 11, (UBYTE *)"Write Byte", NULL, GD_WriteByte, PLACETEXT_IN, NULL, (APTR)WriteByteClicked,
11, 101, 88, 15, (UBYTE *)"Read", NULL, GD_ReadEprom, PLACETEXT_IN, NULL, (APTR)ReadEpromClicked,
11, 128, 88, 15, (UBYTE *)"Empty ?", NULL, GD_BlankTest, PLACETEXT_IN, NULL, (APTR)BlankTestClicked,
11, 155, 88, 15, (UBYTE *)"Compare", NULL, GD_CompareEprom, PLACETEXT_IN, NULL, (APTR)CompareEpromClicked,
111, 101, 88, 71, (UBYTE *)"Program", NULL, GD_ProgramEprom, PLACETEXT_IN, NULL, (APTR)ProgramEpromClicked,
11, 37, 20, 14, NULL, NULL, GD_LoadFileReq, 0, NULL, (APTR)LoadFileReqClicked,
11, 57, 20, 14, NULL, NULL, GD_SaveFileReq, 0, NULL, (APTR)SaveFileReqClicked,
34, 37, 117, 12, NULL, NULL, GD_LoadFile, 0, NULL, (APTR)LoadFileClicked,
34, 57, 117, 12, NULL, NULL, GD_SaveFile, 0, NULL, (APTR)SaveFileClicked,
220, 20, 80, 12, (UBYTE *)"Buffer", NULL, GD_RamAddress, PLACETEXT_RIGHT, NULL, (APTR)RamAddressClicked,
220, 37, 80, 12, (UBYTE *)"Eprom", NULL, GD_EpromAddress, PLACETEXT_RIGHT, NULL, (APTR)EpromAddressClicked,
220, 55, 80, 12, (UBYTE *)"Length", NULL, GD_Length, PLACETEXT_RIGHT, NULL, (APTR)LengthClicked,
220, 85, 46, 12, (UBYTE *)"RAM Value", NULL, GD_RamVal, PLACETEXT_RIGHT, NULL, (APTR)RamValClicked,
220, 144, 132, 11, (UBYTE *)"Options", NULL, GD_DoOptions, PLACETEXT_IN, NULL, (APTR)DoOptionsClicked,
153, 37, 49, 11, (UBYTE *)"LOAD", NULL, GD_LoadBt, PLACETEXT_IN, NULL, (APTR)LoadBtClicked,
153, 57, 49, 11, (UBYTE *)"SAVE", NULL, GD_SaveBt, PLACETEXT_IN, NULL, (APTR)SaveBtClicked,
220, 160, 132, 11, (UBYTE *)"Adjust Hardware", NULL, GD_TestHardware, PLACETEXT_IN, NULL, (APTR)TestHardwareClicked
};
struct NewGadget OptionsNGad[] = {
35, 18, 144, 12, (UBYTE *)"Numrical Base", NULL, GD_NumericalBase, PLACETEXT_ABOVE, NULL, (APTR)NumericalBaseClicked,
23, 41, 26, 11, (UBYTE *)"Buffer fragmented", NULL, GD_SetBufferFrag, PLACETEXT_RIGHT, NULL, (APTR)SetBufferFragClicked,
23, 55, 26, 11, (UBYTE *)"Clear Buffer (0xFF)", NULL, GD_SetClearBuffer, PLACETEXT_RIGHT, NULL, (APTR)SetClearBufferClicked,
24, 75, 26, 11, (UBYTE *)"Info Requester", NULL, GD_SetInfoReq, PLACETEXT_RIGHT, NULL, (APTR)SetInfoReqClicked,
7, 160, 56, 12, (UBYTE *)"Ok", NULL, GD_OptionsOk, PLACETEXT_IN, NULL, (APTR)OptionsOkClicked,
83, 160, 56, 12, (UBYTE *)"Save", NULL, GD_SavePrefs, PLACETEXT_IN, NULL, (APTR)SavePrefsClicked,
160, 160, 56, 11, (UBYTE *)"Cancel", NULL, GD_OptionsCancel, PLACETEXT_IN, NULL, (APTR)OptionsCancelClicked,
24, 111, 26, 11, (UBYTE *)"EProm default size", NULL, GD_setepsize, PLACETEXT_RIGHT, NULL, (APTR)setepsizeClicked,
24, 89, 26, 11, (UBYTE *)"Counting", NULL, GD_count, PLACETEXT_RIGHT, NULL, (APTR)countClicked,
23, 133, 28, 13, (UBYTE *)"CIA Delay", NULL, GD_CIADelay, PLACETEXT_RIGHT, NULL, (APTR)CIADelayClicked
};
struct NewGadget BusyNGad[] = {
43, 30, 81, 12, (UBYTE *)"Abort", NULL, GD_abort, PLACETEXT_IN, NULL, (APTR)abortClicked
};
struct NewGadget TestNGad[] = {
41, 51, 26, 11, (UBYTE *)"Eprom removed", NULL, GD_NoEprom, PLACETEXT_RIGHT, NULL, (APTR)NoEpromClicked,
96, 69, 92, 11, (UBYTE *)"Vpp", NULL, GD_SetVpp, PLACETEXT_LEFT, NULL, (APTR)SetVppClicked,
79, 9, 108, 11, (UBYTE *)"Address", NULL, GD_T_CyAddress, PLACETEXT_LEFT, NULL, (APTR)T_CyAddressClicked,
79, 24, 108, 11, (UBYTE *)"Data", NULL, GD_T_CyData, PLACETEXT_LEFT, NULL, (APTR)T_CyDataClicked
};
ULONG EprommerGTags[] = {
(GTCY_Labels), (ULONG)&DataFormat0Labels[ 0 ], (TAG_DONE),
(GTMX_Labels), (ULONG)&ProgAlgo0Labels[ 0 ], (GTMX_Spacing), 2, (TAG_DONE),
(GTMX_Labels), (ULONG)&EpromType0Labels[ 0 ], (TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(GTST_MaxChars), 256, (TAG_DONE),
(GTST_MaxChars), 256, (TAG_DONE),
(GTST_String), (ULONG)"0", (GTST_MaxChars), 7, (TAG_DONE),
(GTST_String), (ULONG)"0", (GTST_MaxChars), 7, (TAG_DONE),
(GTST_String), (ULONG)"0", (GTST_MaxChars), 7, (TAG_DONE),
(GTST_String), (ULONG)"0", (GTST_MaxChars), 5, (TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE)
};
ULONG OptionsGTags[] = {
(GTCY_Labels), (ULONG)&NumericalBase1Labels[ 0 ], (TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(GTIN_Number), 0, (GTIN_MaxChars), 1, (TAG_DONE)
};
ULONG BusyGTags[] = {
(TAG_DONE)
};
ULONG TestGTags[] = {
(TAG_DONE),
(GTCY_Labels), (ULONG)&SetVpp3Labels[ 0 ], (GA_Disabled), TRUE, (TAG_DONE),
(GTCY_Labels), (ULONG)&T_CyAddress3Labels[ 0 ], (TAG_DONE),
(GTCY_Labels), (ULONG)&T_CyData3Labels[ 0 ], (TAG_DONE)
};
static UWORD ComputeX( UWORD value )
{
return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
}
static UWORD ComputeY( UWORD value )
{
return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
}
static void ComputeFont( UWORD width, UWORD height )
{
Font = &Attr;
Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
FontX = Scr->RastPort.Font->tf_XSize;
OffX = Scr->WBorLeft;
OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
if ( width && height ) {
if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
goto UseTopaz;
if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
goto UseTopaz;
}
return;
UseTopaz:
Font->ta_Name = (STRPTR)"topaz.font";
FontX = FontY = Font->ta_YSize = 8;
}
int SetupScreen( void )
{
if ( ! ( Scr = LockPubScreen( PubScreenName )))
return( 1L );
ComputeFont( 0, 0 );
if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
return( 2L );
if ( ! ( getClass = initGet()))
return( 3L );
if ( ! ( getImage = NewObject( getClass, NULL, GT_VisualInfo, VisualInfo, TAG_DONE )))
return( 4L );
return( 0L );
}
void CloseDownScreen( void )
{
if ( getImage ) {
DisposeObject( getImage );
getImage = NULL;
}
if ( getClass ) {
FreeClass( getClass );
getClass = NULL;
}
if ( VisualInfo ) {
FreeVisualInfo( VisualInfo );
VisualInfo = NULL;
}
if ( Scr ) {
UnlockPubScreen( NULL, Scr );
Scr = NULL;
}
}
void EprommerRender( void )
{
struct IntuiText it;
UWORD cnt;
ComputeFont( EprommerWidth, EprommerHeight );
DrawBevelBox( EprommerWnd->RPort, OffX + ComputeX( 212 ),
OffY + ComputeY( 137 ),
ComputeX( 149 ),
ComputeY( 41 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( EprommerWnd->RPort, OffX + ComputeX( 212 ),
OffY + ComputeY( 81 ),
ComputeX( 149 ),
ComputeY( 53 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( EprommerWnd->RPort, OffX + ComputeX( 212 ),
OffY + ComputeY( 5 ),
ComputeX( 149 ),
ComputeY( 73 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( EprommerWnd->RPort, OffX + ComputeX( 4 ),
OffY + ComputeY( 5 ),
ComputeX( 205 ),
ComputeY( 73 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( EprommerWnd->RPort, OffX + ComputeX( 4 ),
OffY + ComputeY( 81 ),
ComputeX( 205 ),
ComputeY( 97 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( EprommerWnd->RPort, OffX + ComputeX( 364 ),
OffY + ComputeY( 5 ),
ComputeX( 121 ),
ComputeY( 173 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
for ( cnt = 0; cnt < Eprommer_TNUM; cnt++ ) {
CopyMem(( char * )&EprommerIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
it.ITextFont = Font;
it.LeftEdge = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
it.TopEdge = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
PrintIText( EprommerWnd->RPort, &it, 0, 0 );
}
}
int HandleEprommerIDCMP( void )
{
struct IntuiMessage *m;
int (*func)();
BOOL running = TRUE;
while( m = GT_GetIMsg( EprommerWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&EprommerMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( EprommerMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( EprommerWnd );
EprommerRender();
GT_EndRefresh( EprommerWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
running = EprommerCloseWindow();
break;
case IDCMP_RAWKEY:
running = EprommerRawKey();
break;
case IDCMP_GADGETUP:
case IDCMP_GADGETDOWN:
func = ( void * )(( struct Gadget * )EprommerMsg.IAddress )->UserData;
running = func();
break;
}
}
return( running );
}
int OpenEprommerWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = EprommerLeft, wtop = EprommerTop, ww, wh;
ComputeFont( EprommerWidth, EprommerHeight );
ww = ComputeX( EprommerWidth );
wh = ComputeY( EprommerHeight );
if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
if ( ! ( g = CreateContext( &EprommerGList )))
return( 1L );
for( lc = 0, tc = 0; lc < Eprommer_CNT; lc++ ) {
CopyMem((char * )&EprommerNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
if ( EprommerGTypes[ lc ] != GENERIC_KIND ) {
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
}
EprommerGadgets[ lc ] = g = CreateGadgetA((ULONG)EprommerGTypes[ lc ], g, &ng, ( struct TagItem * )&EprommerGTags[ tc ] );
if ( EprommerGTypes[ lc ] == GENERIC_KIND ) {
g->Flags |= GFLG_GADGIMAGE | GFLG_GADGHIMAGE;
g->Activation |= GACT_RELVERIFY;
g->GadgetRender = (APTR)getImage;
g->SelectRender = (APTR)getImage;
}
while( EprommerGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
if ( ! ( EprommerWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + Scr->WBorRight,
WA_Height, wh + OffY + Scr->WBorBottom,
WA_IDCMP, CYCLEIDCMP|MXIDCMP|BUTTONIDCMP|IDCMP_GADGETUP|STRINGIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_SIZEGADGET|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_SIMPLE_REFRESH,
WA_Gadgets, EprommerGList,
WA_Title, EprommerWdt,
WA_PubScreen, Scr,
WA_MinWidth, 67,
WA_MinHeight, 21,
WA_MaxWidth, 640,
WA_MaxHeight, 400,
WA_AutoAdjust, TRUE,
WA_PubScreenFallBack, TRUE,
TAG_DONE )))
return( 4L );
GT_RefreshWindow( EprommerWnd, NULL );
EprommerRender();
return( 0L );
}
void CloseEprommerWindow( void )
{
if ( EprommerWnd ) {
CloseWindow( EprommerWnd );
EprommerWnd = NULL;
}
if ( EprommerGList ) {
FreeGadgets( EprommerGList );
EprommerGList = NULL;
}
}
void OptionsRender( void )
{
ComputeFont( OptionsWidth, OptionsHeight );
DrawBevelBox( OptionsWnd->RPort, OffX + ComputeX( 6 ),
OffY + ComputeY( 130 ),
ComputeX( 211 ),
ComputeY( 19 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( OptionsWnd->RPort, OffX + ComputeX( 6 ),
OffY + ComputeY( 107 ),
ComputeX( 211 ),
ComputeY( 19 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( OptionsWnd->RPort, OffX + ComputeX( 6 ),
OffY + ComputeY( 4 ),
ComputeX( 211 ),
ComputeY( 31 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( OptionsWnd->RPort, OffX + ComputeX( 6 ),
OffY + ComputeY( 38 ),
ComputeX( 211 ),
ComputeY( 31 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( OptionsWnd->RPort, OffX + ComputeX( 6 ),
OffY + ComputeY( 72 ),
ComputeX( 211 ),
ComputeY( 31 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
}
int HandleOptionsIDCMP( void )
{
struct IntuiMessage *m;
int (*func)();
BOOL running = TRUE;
while( m = GT_GetIMsg( OptionsWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&OptionsMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( OptionsMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( OptionsWnd );
OptionsRender();
GT_EndRefresh( OptionsWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
running = OptionsCloseWindow();
break;
case IDCMP_RAWKEY:
running = OptionsRawKey();
break;
case IDCMP_GADGETUP:
func = ( void * )(( struct Gadget * )OptionsMsg.IAddress )->UserData;
running = func();
break;
}
}
return( running );
}
int OpenOptionsWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = OptionsLeft, wtop = OptionsTop, ww, wh;
ComputeFont( OptionsWidth, OptionsHeight );
ww = ComputeX( OptionsWidth );
wh = ComputeY( OptionsHeight );
if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
if ( ! ( g = CreateContext( &OptionsGList )))
return( 1L );
for( lc = 0, tc = 0; lc < Options_CNT; lc++ ) {
CopyMem((char * )&OptionsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
OptionsGadgets[ lc ] = g = CreateGadgetA((ULONG)OptionsGTypes[ lc ], g, &ng, ( struct TagItem * )&OptionsGTags[ tc ] );
while( OptionsGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
if ( ! ( OptionsWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + Scr->WBorRight,
WA_Height, wh + OffY + Scr->WBorBottom,
WA_IDCMP, CYCLEIDCMP|CHECKBOXIDCMP|BUTTONIDCMP|INTEGERIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_SIMPLE_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, OptionsGList,
WA_Title, OptionsWdt,
WA_ScreenTitle, "Options",
WA_PubScreen, Scr,
TAG_DONE )))
return( 4L );
GT_RefreshWindow( OptionsWnd, NULL );
OptionsRender();
return( 0L );
}
void CloseOptionsWindow( void )
{
if ( OptionsWnd ) {
CloseWindow( OptionsWnd );
OptionsWnd = NULL;
}
if ( OptionsGList ) {
FreeGadgets( OptionsGList );
OptionsGList = NULL;
}
}
void BusyRender( void )
{
struct IntuiText it;
UWORD cnt;
ComputeFont( BusyWidth, BusyHeight );
DrawBevelBox( BusyWnd->RPort, OffX + ComputeX( 6 ),
OffY + ComputeY( 4 ),
ComputeX( 167 ),
ComputeY( 22 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
for ( cnt = 0; cnt < Busy_TNUM; cnt++ ) {
CopyMem(( char * )&BusyIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
it.ITextFont = Font;
it.LeftEdge = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
it.TopEdge = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
PrintIText( BusyWnd->RPort, &it, 0, 0 );
}
}
int HandleBusyIDCMP( void )
{
struct IntuiMessage *m;
int (*func)();
BOOL running = TRUE;
while( m = GT_GetIMsg( BusyWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&BusyMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( BusyMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( BusyWnd );
BusyRender();
GT_EndRefresh( BusyWnd, TRUE );
break;
case IDCMP_RAWKEY:
running = BusyRawKey();
break;
case IDCMP_GADGETUP:
func = ( void * )(( struct Gadget * )BusyMsg.IAddress )->UserData;
running = func();
break;
}
}
return( running );
}
int OpenBusyWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = BusyLeft, wtop = BusyTop, ww, wh;
ComputeFont( BusyWidth, BusyHeight );
ww = ComputeX( BusyWidth );
wh = ComputeY( BusyHeight );
if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
if ( ! ( g = CreateContext( &BusyGList )))
return( 1L );
for( lc = 0, tc = 0; lc < Busy_CNT; lc++ ) {
CopyMem((char * )&BusyNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
BusyGadgets[ lc ] = g = CreateGadgetA((ULONG)BusyGTypes[ lc ], g, &ng, ( struct TagItem * )&BusyGTags[ tc ] );
while( BusyGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
if ( ! ( BusyWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + Scr->WBorRight,
WA_Height, wh + OffY + Scr->WBorBottom,
WA_IDCMP, BUTTONIDCMP|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, BusyGList,
WA_Title, BusyWdt,
WA_PubScreen, Scr,
TAG_DONE )))
return( 4L );
GT_RefreshWindow( BusyWnd, NULL );
BusyRender();
return( 0L );
}
void CloseBusyWindow( void )
{
if ( BusyWnd ) {
CloseWindow( BusyWnd );
BusyWnd = NULL;
}
if ( BusyGList ) {
FreeGadgets( BusyGList );
BusyGList = NULL;
}
}
void TestRender( void )
{
ComputeFont( TestWidth, TestHeight );
DrawBevelBox( TestWnd->RPort, OffX + ComputeX( 4 ),
OffY + ComputeY( 4 ),
ComputeX( 197 ),
ComputeY( 37 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
DrawBevelBox( TestWnd->RPort, OffX + ComputeX( 4 ),
OffY + ComputeY( 45 ),
ComputeX( 197 ),
ComputeY( 45 ),
GT_VisualInfo, VisualInfo, TAG_DONE );
}
int HandleTestIDCMP( void )
{
struct IntuiMessage *m;
int (*func)();
BOOL running = TRUE;
while( m = GT_GetIMsg( TestWnd->UserPort )) {
CopyMem(( char * )m, ( char * )&TestMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( TestMsg.Class ) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( TestWnd );
TestRender();
GT_EndRefresh( TestWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
running = TestCloseWindow();
break;
case IDCMP_RAWKEY:
running = TestRawKey();
break;
case IDCMP_GADGETUP:
func = ( void * )(( struct Gadget * )TestMsg.IAddress )->UserData;
running = func();
break;
}
}
return( running );
}
int OpenTestWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = TestLeft, wtop = TestTop, ww, wh;
ComputeFont( TestWidth, TestHeight );
ww = ComputeX( TestWidth );
wh = ComputeY( TestHeight );
if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
if ( ! ( g = CreateContext( &TestGList )))
return( 1L );
for( lc = 0, tc = 0; lc < Test_CNT; lc++ ) {
CopyMem((char * )&TestNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = Font;
ng.ng_LeftEdge = OffX + ComputeX( ng.ng_LeftEdge );
ng.ng_TopEdge = OffY + ComputeY( ng.ng_TopEdge );
ng.ng_Width = ComputeX( ng.ng_Width );
ng.ng_Height = ComputeY( ng.ng_Height);
TestGadgets[ lc ] = g = CreateGadgetA((ULONG)TestGTypes[ lc ], g, &ng, ( struct TagItem * )&TestGTags[ tc ] );
while( TestGTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
if ( ! ( TestWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + OffX + Scr->WBorRight,
WA_Height, wh + OffY + Scr->WBorBottom,
WA_IDCMP, CHECKBOXIDCMP|CYCLEIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, TestGList,
WA_Title, TestWdt,
WA_PubScreen, Scr,
TAG_DONE )))
return( 4L );
GT_RefreshWindow( TestWnd, NULL );
TestRender();
return( 0L );
}
void CloseTestWindow( void )
{
if ( TestWnd ) {
CloseWindow( TestWnd );
TestWnd = NULL;
}
if ( TestGList ) {
FreeGadgets( TestGList );
TestGList = NULL;
}
}