home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
util
/
blank
/
gblanker
/
source
/
winhand.c
< prev
Wrap
C/C++ Source or Header
|
1994-10-18
|
7KB
|
294 lines
/*
* Copyright (c) 1994 Michael D. Bayne.
* All rights reserved.
*
* Please see the documentation accompanying the distribution for distribution
* and disclaimer information.
*/
#include <exec/memory.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <string.h>
#include <stdlib.h>
#include "includes.h"
#include "libraries.h"
#include "protos/protos.h"
STRPTR NameSansParens( STRPTR Name )
{
BYTE Buf[64];
if( Name[0] == '{' )
{
strcpy( Buf, Name + 1 );
Buf[strlen( Buf ) - 1] = '\0';
}
else
return Name;
return Buf;
}
STRPTR NameForEntry( struct List *Entries, LONG Entry )
{
struct Node *Tmp;
for( Tmp = Entries->lh_Head; Entry && Tmp; Tmp = Tmp->ln_Succ, --Entry );
return Tmp ? Tmp->ln_Name : 0L;
}
int BT_PREFSClicked( VOID )
{
if( Stricmp( Prefs->bp_Blanker, "Random" ))
MessageModule( BM_DOPREFS );
return OK;
}
int BT_INFOClicked( VOID )
{
struct EasyStruct InfoReq =
{ sizeof( struct EasyStruct ), 0, "Information", 0L, "Ok" };
BYTE InfoFileName[128];
BPTR InfoFile;
InfoReq.es_TextFormat = AllocVec( 1024 * sizeof( BYTE ), MEMF_CLEAR );
if( !InfoReq.es_TextFormat )
return OK;
ActivateCxObj( ServerBroker, 0l );
strcpy( InfoFileName, Prefs->bp_Dir );
AddPart( InfoFileName, NameSansParens( Prefs->bp_Blanker ), 128 );
strcat( InfoFileName, ".txt" );
if( InfoFile = Open( InfoFileName, MODE_OLDFILE ))
{
LONG BytesRead;
BytesRead = Read( InfoFile, InfoReq.es_TextFormat, 1024 );
if( InfoReq.es_TextFormat[BytesRead-1] == '\n' )
InfoReq.es_TextFormat[BytesRead-1] = '\0';
else
InfoReq.es_TextFormat[BytesRead] = '\0';
Close( InfoFile );
}
else
{
strcpy( InfoReq.es_TextFormat,
"No information available for module: " );
strcat( InfoReq.es_TextFormat, NameSansParens( Prefs->bp_Blanker ));
strcat( InfoReq.es_TextFormat, "." );
}
EasyRequestArgs( BlankerWnd, &InfoReq, 0L, 0L );
FreeVec( InfoReq.es_TextFormat );
ActivateCxObj( ServerBroker, 1l );
return OK;
}
int BT_HIDEClicked( VOID )
{
return CLOSEWIN;
}
int BT_SAVEClicked( VOID )
{
Prefs->bp_Left = BlankerWnd->LeftEdge;
Prefs->bp_Top = BlankerWnd->TopEdge;
SaveDefaultPrefs( Prefs );
return OK;
}
int BT_QUITClicked( VOID )
{
return QUIT;
}
int LV_BLANKERSClicked( VOID )
{
LONG Rand;
MessageModule( BM_DOQUIT );
strcpy( Prefs->bp_Blanker,
NameForEntry( BlankerEntries, BlankerMsg.Code ));
Rand = !Stricmp( Prefs->bp_Blanker, "Random" );
GT_SetGadgetAttrs( BlankerGadgets[GD_BT_PREFS], BlankerWnd, 0L,
GA_Disabled, Rand, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_BT_TOGGLE], BlankerWnd, 0L,
GA_Disabled, Rand, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_REPLACE], BlankerWnd, 0L,
GA_Disabled, !Rand, TAG_DONE );
if( !Rand )
LoadModule( Prefs->bp_Dir, Prefs->bp_Blanker );
return OK;
}
int CY_REPLACEClicked( VOID )
{
if( BlankerMsg.Code )
Prefs->bp_Flags |= BF_REPLACE;
else
Prefs->bp_Flags &= ~BF_REPLACE;
return OK;
}
int CY_BLANKCORNERClicked( VOID )
{
Prefs->bp_BlankCorner = BlankerMsg.Code;
return OK;
}
int CY_DONTCORNERClicked( VOID )
{
Prefs->bp_DontCorner = BlankerMsg.Code;
return OK;
}
int BT_TOGGLEClicked( VOID )
{
struct Node *Entry = FindName( BlankerEntries, Prefs->bp_Blanker );
BYTE TmpName[64], OldPath[128], NewPath[128], *Name = Entry->ln_Name;
strcpy( TmpName, Name );
GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
GTLV_Labels, ~0, TAG_DONE );
if( Name[0] == '{' )
{
strcpy( Name, TmpName + 1 );
Name[strlen( Name ) - 1] = '\0';
}
else
{
strcpy( Name, "{" );
strcat( Name, TmpName );
strcat( Name, "}" );
}
GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
GTLV_Labels, BlankerEntries, TAG_DONE );
strcpy( Prefs->bp_Blanker, Name );
strcpy( OldPath, Prefs->bp_Dir );
AddPart( OldPath, TmpName, 128 );
strcpy( NewPath, Prefs->bp_Dir );
AddPart( NewPath, Name, 128 );
Rename( OldPath, NewPath );
return OK;
}
int BlankerCloseWindow( VOID )
{
return CLOSEWIN;
}
int BlankerVanillaKey( VOID )
{
switch( BlankerMsg.Code )
{
case 'p':
return BT_PREFSClicked();
case 'i':
return BT_INFOClicked();
case 'h':
return CLOSEWIN;
case 's':
return BT_SAVEClicked();
case 't':
return BT_TOGGLEClicked();
case 'q':
return QUIT;
case 'b':
Prefs->bp_BlankCorner = ( Prefs->bp_BlankCorner + 1 ) % 5;
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_BLANKCORNER], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_BlankCorner, TAG_DONE );
return OK;
case 'B':
Prefs->bp_BlankCorner = ( Prefs->bp_BlankCorner + 4 ) % 5;
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_BLANKCORNER], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_BlankCorner, TAG_DONE );
return OK;
case 'd':
Prefs->bp_DontCorner = ( Prefs->bp_DontCorner + 1 ) % 5;
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_DONTCORNER], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_DontCorner, TAG_DONE );
return OK;
case 'D':
Prefs->bp_DontCorner = ( Prefs->bp_DontCorner + 4 ) % 5;
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_DONTCORNER], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_DontCorner, TAG_DONE );
return OK;
default:
return OK;
}
}
LONG openMainWindow( VOID )
{
static BYTE Title[80];
struct Node *TmpNode;
LONG i;
if( !BlankerWnd )
{
if( SetupScreen())
return 1L;
strcpy( Title, "Garshneblanker ( PopKey=" );
strcat( Title, Prefs->bp_PopKey );
strcat( Title, ", BlankKey=" );
strcat( Title, Prefs->bp_BlankKey );
strcat( Title, " )" );
BlankerLeft = Prefs->bp_Left;
BlankerTop = Prefs->bp_Top;
OpenBlankerWindow();
SetWindowTitles( BlankerWnd, "Garshneblanker", Title );
}
else
{
ActivateWindow( BlankerWnd );
WindowToFront( BlankerWnd );
}
if( BlankerWnd )
ScreenToFront( BlankerWnd->WScreen );
else
return QUIT;
GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
GTLV_Labels, BlankerEntries, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_REPLACE], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_Flags & BF_REPLACE, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_BLANKCORNER], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_BlankCorner, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_DONTCORNER], BlankerWnd, 0L,
GTCY_Active, Prefs->bp_DontCorner, TAG_DONE );
for( i = 0, TmpNode = BlankerEntries->lh_Head;
TmpNode && Stricmp( TmpNode->ln_Name, Prefs->bp_Blanker );
TmpNode = TmpNode->ln_Succ, i++ );
if( !TmpNode )
i = 0;
GT_SetGadgetAttrs( BlankerGadgets[GD_LV_BLANKERS], BlankerWnd, 0L,
GTLV_Selected, i, GTLV_MakeVisible, i, GTLV_Top, i,
TAG_DONE );
i = !Stricmp( Prefs->bp_Blanker, "Random" );
GT_SetGadgetAttrs( BlankerGadgets[GD_BT_PREFS], BlankerWnd, 0L,
GA_Disabled, i, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_BT_TOGGLE], BlankerWnd, 0L,
GA_Disabled, i, TAG_DONE );
GT_SetGadgetAttrs( BlankerGadgets[GD_CY_REPLACE], BlankerWnd, 0L,
GA_Disabled, !i, TAG_DONE );
return OK;
}