home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0979.lha
/
StartWindow
/
StartWindowE.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-04
|
16KB
|
607 lines
#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>
/*********************************************/
#define GetString( g ) ((( struct StringInfo * )g->SpecialInfo )->Buffer )
#define GetNumber( g ) ((( struct StringInfo * )g->SpecialInfo )->LongInt )
#define GD_CList 0
#define GD_new 1
#define GD_del 2
#define GD_gadtxt 3
#define GD_command 4
#define GD_start 5
#define GD_save 6
#define GDX_CList 0
#define GDX_new 1
#define GDX_del 2
#define GDX_gadtxt 3
#define GDX_command 4
#define GDX_start 5
#define GDX_save 6
#define Project0_CNT 7
extern struct IntuitionBase *IntuitionBase;
extern struct Library *GadToolsBase;
extern struct Screen *Scr;
extern UBYTE *PubScreenName;
extern APTR VisualInfo;
extern struct Window *Project0Wnd;
extern struct Gadget *Project0GList;
extern struct Gadget *Project0Gadgets[7];
extern UWORD Project0Left;
extern UWORD Project0Top;
extern UWORD Project0Width;
extern UWORD Project0Height;
extern UBYTE *Project0Wdt;
extern struct TextAttr topaz8;
extern UWORD Project0GTypes[];
extern struct NewGadget Project0NGad[];
extern ULONG Project0GTags[];
extern int SetupScreen( void );
extern void CloseDownScreen( void );
extern int OpenProject0Window( void );
extern void CloseProject0Window( void );
/**************************************************/
struct Screen *Scr = NULL;
UBYTE *PubScreenName = NULL;
APTR VisualInfo = NULL;
struct Window *Project0Wnd = NULL;
struct Gadget *Project0GList = NULL;
struct Gadget *Project0Gadgets[7];
UWORD Project0Left = 468;
UWORD Project0Top = 10;
UWORD Project0Width = 194;
UWORD Project0Height = 0;
UBYTE *Project0Wdt = (UBYTE *)" Start Window";
struct TextAttr topaz8 = {
( STRPTR )"topaz.font", 8, 0x00, 0x01 };
UWORD Project0GTypes[] = {
LISTVIEW_KIND,
BUTTON_KIND,
BUTTON_KIND,
STRING_KIND,
STRING_KIND,
BUTTON_KIND,
BUTTON_KIND
};
struct NewGadget Project0NGad[] = {
3, 14, 168, 72,
(UBYTE *)"Start List",
NULL, GD_CList,
PLACETEXT_ABOVE,
NULL, NULL,
4, 86, 80, 11,
(UBYTE *)"NEW",
NULL, GD_new,
PLACETEXT_IN,
NULL, NULL,
88, 86, 80, 11,
(UBYTE *)"DELETE",
NULL, GD_del,
PLACETEXT_IN,
NULL, NULL,
4, 101, 165, 12,
NULL, NULL,
GD_gadtxt, 0,
NULL, NULL,
4, 116, 165, 12,
NULL, NULL,
GD_command, 0,
NULL, NULL,
5, 131, 80, 11,
(UBYTE *)"RUN",
NULL, GD_start,
PLACETEXT_IN,
NULL, NULL,
88, 131, 80, 11,
(UBYTE *)"SAVE",
NULL, GD_save,
PLACETEXT_IN,
NULL, NULL
};
ULONG Project0GTags[] = {
(TAG_DONE),
(TAG_DONE),
(TAG_DONE),
(GTST_MaxChars), 20, (TAG_DONE),
(GTST_MaxChars), 50, (TAG_DONE),
(TAG_DONE),
(TAG_DONE)
};
int SetupScreen( void )
{
if ( ! ( Scr = LockPubScreen( PubScreenName )))
return( 1L );
if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
return( 2L );
return( 0L );
}
void CloseDownScreen( void )
{
if ( VisualInfo ) {
FreeVisualInfo( VisualInfo );
VisualInfo = NULL;
}
if ( Scr ) {
UnlockPubScreen( NULL, Scr );
Scr = NULL;
}
}
int OpenProject0Window( void )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
if ( ! ( g = CreateContext( &Project0GList )))
return( 1L );
for( lc = 0, tc = 0; lc < Project0_CNT; lc++ ) {
CopyMem((char * )&Project0NGad[ lc ], (char * )&ng,
(long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = &topaz8;
ng.ng_LeftEdge += offx;
ng.ng_TopEdge += offy;
Project0Gadgets[ lc ] = g = CreateGadgetA((ULONG)Project0GTypes[ lc ],
g, &ng, ( struct TagItem * )&Project0GTags[ tc ] );
while( Project0GTags[ tc ] ) tc += 2;
tc++;
if ( NOT g )
return( 2L );
}
if ( ! ( Project0Wnd = OpenWindowTags( NULL,
WA_Left, Project0Left,
WA_Top, Project0Top,
WA_Width, Project0Width,
WA_Height, Project0Height + offy,
WA_IDCMP, LISTVIEWIDCMP|
BUTTONIDCMP|
STRINGIDCMP|
IDCMP_NEWSIZE|
IDCMP_CLOSEWINDOW|
IDCMP_CHANGEWINDOW|
IDCMP_REFRESHWINDOW,
WA_Flags, WFLG_SIZEGADGET|
WFLG_DRAGBAR|
WFLG_DEPTHGADGET|
WFLG_CLOSEGADGET|
WFLG_SMART_REFRESH,
WA_Gadgets, Project0GList,
WA_Title, Project0Wdt,
WA_ScreenTitle, "Heinz Reinert ⌐ 1993",
WA_PubScreen, Scr,
WA_MinWidth, 194,
WA_MinHeight, 157,
WA_MaxWidth, 194,
WA_MaxHeight, 157,
TAG_DONE )))
return( 4L );
GT_RefreshWindow( Project0Wnd, NULL );
return( 0L );
}
void CloseProject0Window( void )
{
if ( Project0Wnd ) {
CloseWindow( Project0Wnd );
Project0Wnd = NULL;
}
if ( Project0GList ) {
FreeGadgets( Project0GList );
Project0GList = NULL;
}
}
/******************************************************/
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/gadtools.h>
#include <intuition/gadgetclass.h>
#include <exec/memory.h>
#include <string.h>
struct PRJ {
char Name[0];
USHORT new;
USHORT del;
char gadtxt[20];
char command[50];
USHORT start;
USHORT save;
};
struct PRJnode {
struct Node n; /*** Fⁿr Liste ***/
struct PRJ d; /*** PRJ-Struktur ***/
};
struct List prjlist;
struct PRJnode *currentprj;
void gt_SetString( struct Gadget *gad,
struct Window *w,
char *string )
{
GT_SetGadgetAttrs( gad, w, NULL, GTST_String, string, TAG_DONE );
}
char * gt_GetString( struct Gadget *gad )
{
struct StringInfo *si = gad->SpecialInfo;
if( si )
return( ( char * ) si->Buffer );
else
return( NULL );
}
void gt_AttachList( struct Gadget *lv,
struct Window *w,
struct List *list )
{
GT_SetGadgetAttrs( lv, w, NULL, GTLV_Labels, list, TAG_DONE );
}
void gt_SetLV( struct Gadget *gad,
struct Window *w,
ULONG value)
{
GT_SetGadgetAttrs( gad, w, NULL, GTLV_Selected, value, TAG_DONE );
}
struct Node * gt_GetListEntry( struct List *l,
int num )
{
int count = 0;
struct Node *n = l->lh_Head;
while( n->ln_Succ )
{
if( num==count ) return( n );
n = n->ln_Succ;
count++;
}
return( NULL );
}
int gt_GetListEntryNum( struct List *l,
struct Node *n )
{
int count = 0;
struct Node *r = l->lh_Head;
while( r->ln_Succ )
{
if( r==n ) return( count );
r = r->ln_Succ;
count++;
}
return( -1 );
}
int gt_GetListNumEntries( struct List *l )
{
int count = 0;
struct Node *n = l->lh_Head;
while( n->ln_Succ )
{
n = n->ln_Succ;
count++;
}
return( count );
}
/************************************************************************/
void loadprjlist( void )
{
struct PRJ new;
struct PRJnode *n;
BPTR f;
NewList( &prjlist );
currentprj = NULL;
f = Open( "S:Kommando.DAT", MODE_OLDFILE );
if( !f )
return;
while( Read( f, &new, sizeof( new ) ) == sizeof( new ) )
{
n = AllocVec( sizeof( *n ), 0 );
if( !n )
break;
n->d = new;
n->n.ln_Name = n->d.Name;
n->n.ln_Pri = - n->d.Name[0];
Enqueue( &prjlist, (struct Node *) n );
}
Close( f );
}
void save_and_freeprjlist( void )
{
struct PRJnode *n;
BPTR f;
f = Open( "S:Kommando.DAT", MODE_NEWFILE );
while( ( n = (struct PRJnode * ) RemHead( &prjlist ) ) )
{
if( f )
Write( f, &n->d, sizeof( struct PRJ ) );
FreeVec( n );
}
if( f )
Close( f );
}
/************************************************************************/
void setgadvals( void )
{
if( !currentprj )
return;
gt_SetString( Project0Gadgets[ GD_gadtxt ], Project0Wnd,
currentprj->d.Name );
gt_SetString( Project0Gadgets[ GD_command ], Project0Wnd,
currentprj->d.command );
}
void newprj( void )
{
struct PRJnode *new;
new = AllocVec( sizeof( *new ), MEMF_CLEAR );
if( !new )
return;
currentprj = new;
new->n.ln_Name = new->d.Name;
strcpy( new->d.Name, "new" );
gt_AttachList( Project0Gadgets[GD_CList], Project0Wnd,
(struct List *) ~0 );
new->n.ln_Pri = - new->d.Name[0];
Enqueue( &prjlist, (struct Node *) new );
gt_AttachList( Project0Gadgets[GD_CList], Project0Wnd, &prjlist );
gt_SetLV( Project0Gadgets[GD_CList], Project0Wnd,
gt_GetListEntryNum( &prjlist, new ) );
setgadvals();
}
void dogadup( struct IntuiMessage *im )
{
struct Gadget *g = im->IAddress;
switch( g->GadgetID )
{
case GD_CList:
currentprj = (struct PRJnode *) gt_GetListEntry( &prjlist, im->Code );
setgadvals();
break;
case GD_new:
newprj();
break;
case GD_del:
if( currentprj )
{
gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd,
(struct List *) ~0 );
Remove( currentprj );
FreeVec( currentprj );
currentprj = FALSE;
gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd, &prjlist );
gt_SetLV( Project0Gadgets[ GD_CList ], Project0Wnd, ~0 );
}
break;
case GD_gadtxt:
if( currentprj )
{
gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd,
(struct List *) ~0 );
strcpy( currentprj->d.Name, gt_GetString( Project0Gadgets[ GD_gadtxtá] ) );
gt_AttachList( Project0Gadgets[ GD_CList ], Project0Wnd, &prjlist );
}
break;
case GD_command:
if( currentprj )
strcpy( currentprj->d.command,
gt_GetString( Project0Gadgets[ GD_command ] ) );
break;
case GD_start:
Execute(currentprj->d.command, NULL, Output());
break;
case GD_save:
{
struct PRJnode *n;
BPTR f;
f = Open( "S:Kommando.DAT", MODE_NEWFILE );
while( ( n = (struct PRJnode * ) RemHead( &prjlist ) ) )
{
if( f )
Write( f, &n->d, sizeof( struct PRJ ) );
FreeVec( n );
}
if( f )
Close( f );
}
{
struct PRJ new;
struct PRJnode *n;
BPTR f;
NewList( &prjlist );
currentprj = NULL;
f = Open( "S:Kommando.DAT", MODE_OLDFILE );
if( !f )
return;
while( Read( f, &new, sizeof( new ) ) == sizeof( new ) )
{
n = AllocVec( sizeof( *n ), 0 );
if( !n )
break;
n->d = new;
n->n.ln_Name = n->d.Name;
n->n.ln_Pri = - n->d.Name[0];
Enqueue( &prjlist, (struct Node *) n );
}
Close( f );
}
break;
}
}
int main( void )
{
struct IntuiMessage *im,imsg;
BOOL Done = FALSE;
SetupScreen();
OpenProject0Window();
loadprjlist();
gt_AttachList( Project0Gadgets[GD_CList], Project0Wnd, &prjlist );
while( !Done )
{
while( !( im=GT_GetIMsg( Project0Wnd->UserPort ) ) )
WaitPort( Project0Wnd->UserPort );
imsg = *im;
GT_ReplyIMsg( im );
switch( imsg.Class )
{
case IDCMP_CLOSEWINDOW:
Done = TRUE;
break;
case GADGETUP:
dogadup( &imsg );
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( Project0Wnd );
GT_EndRefresh( Project0Wnd, TRUE );
break;
}
}
CloseProject0Window();
CloseDownScreen();
save_and_freeprjlist();
return(0);
}