home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Vectronix 2
/
VECTRONIX2.iso
/
FILES_07
/
GENEVANO.LZH
/
GEVA_NEO.MSA
/
TASKMAN.C
< prev
next >
Wrap
Text File
|
1993-06-17
|
48KB
|
1,632 lines
/* The MAGIC Task Manager
by Dan Wilga
Copyright ╜ 1993, Gribnif Software
All rights reserved.
This source code is provided to registered owners of MAGIC as a learning
tool. No portion of this code can be sold or used for commercial purposes
without the permission of Gribnif Software. Modified versions of the Task
Manager may not be distributed.
This file is only partly commented so far
*/
#include "aes.h"
#include "vdi.h"
#include "new_aes.h" /* AES 4.0 extensions */
#include "xwind.h" /* MAGIC extensions */
#include "tos.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "taskman.h" /* resource file constants */
/* window type for the main window */
#define WIN_TYPE FULLER|NAME|MOVER|SIZER|X_MENU|CLOSER|UPARROW|DNARROW|VSLIDE
/* definitions for seeing if MAGIC is present, by way of JARxxx */
#define CJar_cookie 0x434A6172L /* "CJar" */
#define my_cookie 0x4D414743 /* "MAGC" */
#define _VDO_COOKIE 0x5F56444FL /* _VDO */
#define CJar_xbios 0x434A /* "CJ" */
#define CJar_OK 0x6172 /* "ar" */
#define CJar(mode,cookie,value) (int)xbios(CJar_xbios,mode,cookie,value)
/* root window object */
OBJECT blank[65] = { -1, -1, -1, G_BOX, TOUCHEXIT, 0, 0x1070L };
/* new item in the Tasks list */
OBJECT new[] = { -1, -1, -1, G_STRING, SELECTABLE|TOUCHEXIT|RBUTTON, X_MAGIC, 0L, 0, 0, 0x060A, 1 };
/* window dimensions, inside and outside */
GRECT winner, max, wsize = { 50, 60, 250, 100 };
/* hold info for up to 65 applications */
struct App
{
char name[12];
int num, asleep;
} app[65];
int apid, /* my application ID */
apps, /* number of apps in use */
char_h, /* height of a char in G_STRING */
tasknum, /* index of currently selected task (0=none) */
flagmode, /* 0 for global flag editing */
flagnum, /* index or apid of flag being edited */
fknum, /* number (0-4) of flag key being edited */
dattnum, /* */
color_mode; /* 0 = 1-plane, 1 = 2-plane, 2 = 4-plane, 3 = 8+ plane */
char **new_flag,/* points to the string "--New--" within the RSC file */
**sys_font,/* points to the string "System" within the RSC file */
was_new; /* != 0 if the user used the New button in flag editor */
SETTINGS set0, /* MAGIC settings when dialog got opened (for Cancel) */
set; /* current settings */
APPFLAGS apf0, /* flags when dialog got opened */
apf; /* current flags */
OBJECT *menu, /* points to the main window menu tree */
*colors, /* points to the colors popup menu */
*patterns, /* points to the patterns popup menu */
*fontpop; /* points to the fonts popup menu */
#define MENU_START -5
#define APP_SWITCH -4
#define APP_SLEEP -3
#define ASCII_TABLE -2
#define REDRAW_ALL -1
int xkey=MENU_START; /* index of key being edited in the Keyboard dialog */
int vdi_hand, /* VDI device handle */
work_in[] = { 1, 7, 1, 1, 1, 1, 1, 1, 1, 1, 2 },
work_out[57], /* returns from v_opnvwk() */
has_gdos, /* indicates presence of GDOS */
fonts, /* number of fonts available */
font_id[16], /* ID's of up to 16 fonts */
font_wid, /* width of one char in the current font */
font_ht, /* height of one char in the current font */
font_num; /* index of the current font */
char *mover_text, /* points to text in mover of Window options */
*info_text; /* points to text in info bar in Window opts */
XFONTINFO fontinfo, /* info about the font used by MAGIC */
fontinfo0; /* initial state of fontinfo */
/* some function prototypes */
void set_if( OBJECT *tree, int num, int true );
void start_form( int fnum, int tnum, int type );
void k_mode( OBJECT *o, int fnum, int mode, int draw );
void k_set( OBJECT *o, int is_main, int draw );
void close_vdi(void);
int mo_init( OBJECT *o );
int k_init( OBJECT *o );
int wo_init( OBJECT *o );
int d_init( OBJECT *o );
int vo_init( OBJECT *o );
int fo_init( OBJECT *o );
int fk_init( OBJECT *o );
int mo_touch( OBJECT *o, int num );
int k_touch( OBJECT *o, int num );
int fo_touch( OBJECT *o, int num );
int fk_touch( OBJECT *o, int num );
int d_touch( OBJECT *o, int num );
int wo_touch( OBJECT *o, int num );
int mo_exit( OBJECT *o, int num );
int fo_exit( OBJECT *o, int num );
int k_exit( OBJECT *o, int num );
int wo_exit( OBJECT *o, int num );
int d_exit( OBJECT *o, int num );
int vo_exit( OBJECT *o, int num );
/* describe a modeless dialog */
typedef struct
{
int handle; /* handle of window containing dial */
OBJECT *tree; /* dial's object tree */
int (*init)( OBJECT *o ); /* function to initialize it */
int (*touch)( OBJECT *o, int num ); /* called when TOUCHEXIT is clicked */
int (*exit)( OBJECT *o, int num ); /* called when EXIT is clicked */
} FORM;
FORM form[] = { { 0, 0L, k_init, k_touch, k_exit }, /* Keyboard */
{ 0, 0L, mo_init, mo_touch, mo_exit }, /* Misc Options */
{ 0, 0L, d_init, d_touch, d_exit }, /* Dialog Options */
{ 0, 0L, wo_init, wo_touch, wo_exit }, /* Window Options */
{ 0, 0L, vo_init, 0L, vo_exit }, /* Video */
{ 0, 0L, fo_init, fo_touch, fo_exit }, /* Flags */
{ 0, 0L, fk_init, fk_touch, k_exit }, /* Flag Keys */
{ 0, 0L, 0L } }; /* end of list */
/***
/* Convert from a TEDINFO (te_ptext) filename to a regular string */
void from_edit( char *src, char *dest )
{
int i=0;
do
{
if( *src != ' ' ) *dest++ = *src;
if( i++==7 && *(src+1) && *(src+1)!=' ' ) *dest++ = '.';
}
while( *src++ && i<11 );
if( i==11 ) *dest++ = '\0';
}
/* Convert from a regular string to a TEDINFO (te_ptext) filename */
void to_edit( char *src, char *dest )
{
int j=0;
while( *src && j<12 )
{
if( *src != '.' || j>7 )
{
if( *src == '.' ) src++;
else if( *src!=' ' ) *dest++ = *src++; /* elim spaces */
}
else *dest++ = ' ';
j++;
}
*dest = 0;
} ***/
int alert( int num )
{
char **ptr;
rsrc_gaddr( 15, num, &ptr );
return form_alert( 1, *ptr );
}
/* Close and delete a window */
void close_wind( int *hand )
{
if( *hand )
{
if( *hand==form[3].handle ) close_vdi();
wind_close(*hand);
wind_delete(*hand);
*hand=0;
}
}
/* Get MAGIC's current settings */
void get_set(void)
{
x_settings( 0, sizeof(SETTINGS), &set0 );
x_settings( 0, sizeof(SETTINGS), &set );
}
/* initialize Misc Options dialog */
int mo_init( OBJECT *o )
{
get_set();
set_if( o, MOPULL, set.flags.s.pulldown );
set_if( o, MOINS, set.flags.s.insert_mode );
set_if( o, MOFOLL, set.flags.s.alerts_under_mouse );
set_if( o, MOCOL, set.flags.s.fsel_1col );
set_if( o, MOLONG, set.flags.s.long_titles );
set_if( o, MOGROW, set.flags.s.grow_shrink );
set_if( o, MOTOP, set.flags.s.tear_aways_topped );
x_sprintf( o[MOGAD].ob_spec.tedinfo->te_ptext, "%d", set.gadget_pause*20 );
return 1;
}
/* Misc Options touchexit event */
int mo_touch( OBJECT *o, int num )
{
num++; /* object clicked on, not used here */
/* get all settings from the dialog */
set.flags.s.pulldown = o[MOPULL].ob_state&SELECTED;
set.flags.s.insert_mode = o[MOINS].ob_state&SELECTED;
set.flags.s.alerts_under_mouse = o[MOFOLL].ob_state&SELECTED;
set.flags.s.fsel_1col = o[MOCOL].ob_state&SELECTED;
set.flags.s.long_titles = o[MOLONG].ob_state&SELECTED;
set.flags.s.grow_shrink = o[MOGROW].ob_state&SELECTED;
set.flags.s.tear_aways_topped = o[MOTOP].ob_state&SELECTED;
set.gadget_pause = atoi(o[MOGAD].ob_spec.tedinfo->te_ptext)/20;
/* set them in MAGIC */
x_settings( 1, sizeof(SETTINGS), &set );
return -1;
}
/* Misc Options exit event */
int mo_exit( OBJECT *o, int num )
{
if( num!=MOOK ) x_settings( 1, sizeof(SETTINGS), &set0 ); /* Cancel */
else mo_touch( o, 0 ); /* get settings and set in MAGIC */
return 1; /* close dialog */
}
/* hide or show an object */
void hide_if( OBJECT *o, int num, int truth )
{
if( !truth ) o[num].ob_flags |= HIDETREE;
else o[num].ob_flags &= ~HIDETREE;
}
/* set an object to be editable or not editable */
void edit_if( OBJECT *o, int num, int truth )
{
if( !truth ) o[num].ob_flags &= ~EDITABLE;
else o[num].ob_flags |= EDITABLE;
}
/* get current flags from dialog */
void fo_stat( OBJECT *o )
{
x_appl_flags( flagmode, flagnum, &apf0 );
apf = apf0;
x_form_filename( o, FONAME, 0, flagmode ? app[tasknum-1].name+2 : apf.name );
edit_if( o, FONAME, !flagmode && flagnum );
hide_if( o, FONAME, flagmode || flagnum );
hide_if( o, FOPREV, !flagmode && flagnum );
o[FODESC].ob_spec.tedinfo->te_ptext = apf.desc;
edit_if( o, FODESC, !flagmode && flagnum );
hide_if( o, FONEXT, !flagmode && x_appl_flags( 0, flagnum+1, 0L ) );
set_if( o, FOSPEC, apf.flags.s.special_types );
set_if( o, FOLIMIT, apf.flags.s.limit_memory );
set_if( o, FOKEEP, apf.flags.s.keep_deskmenu );
set_if( o, FOAES40, apf.flags.s.AES40_msgs );
set_if( o, FOREDRAW, apf.flags.s.exit_redraw );
x_sprintf( o[FOLNUM].ob_spec.tedinfo->te_ptext, "%d",
apf.flags.s.mem_limit );
set_if( o, FOMULTI, apf.flags.s.multitask );
hide_if( o, FOMULTI, !flagmode );
set_if( o, FOHAND, apf.flags.s.limit_handles );
hide_if( o, FOHAND, !flagmode );
set_if( o, FOLEFT, apf.flags.s.off_left );
set_if( o, FOROUND, apf.flags.s.round_buttons );
set_if( o, FOAUTO, apf.flags.s.kbd_equivs );
set_if( o, FOUNDRAW, apf.flags.s.undo_equivs );
hide_if( o, FODEL, !flagmode && flagnum );
hide_if( o, FONEW, !flagmode );
if( form[5].handle>0 ) wind_set( form[5].handle, X_WF_DIALOG, form[5].tree );
if( form[6].handle>0 ) k_set( form[6].tree, 0, 1 );
}
int fo_init( OBJECT *o )
{
flagmode = tasknum>0 ? 3 : 0;
flagnum = tasknum>0 ? app[tasknum-1].num : 0;
fo_stat(o);
was_new = 0;
return 1;
}
int fo_set( OBJECT *o, int warn )
{
x_form_filename( o, FONAME, 1, apf.name );
if( flagmode || !flagnum || apf.name[0] && strncmp(apf.name,*new_flag,12) )
{
apf.flags.s.special_types = o[FOSPEC].ob_state&SELECTED;
apf.flags.s.limit_memory = o[FOLIMIT].ob_state&SELECTED;
apf.flags.s.exit_redraw = o[FOREDRAW].ob_state&SELECTED;
apf.flags.s.keep_deskmenu = o[FOKEEP].ob_state&SELECTED;
apf.flags.s.AES40_msgs = o[FOAES40].ob_state&SELECTED;
apf.flags.s.mem_limit = atoi( o[FOLNUM].ob_spec.tedinfo->te_ptext );
apf.flags.s.multitask = o[FOMULTI].ob_state&SELECTED;
apf.flags.s.limit_handles = o[FOHAND].ob_state&SELECTED;
apf.flags.s.off_left = o[FOLEFT].ob_state&SELECTED;
apf.flags.s.round_buttons = o[FOROUND].ob_state&SELECTED;
apf.flags.s.kbd_equivs = o[FOAUTO].ob_state&SELECTED;
apf.flags.s.undo_equivs = o[FOUNDRAW].ob_state&SELECTED;
x_appl_flags( flagmode+1, flagnum, &apf );
return 1;
}
else
{
if( warn ) alert( ALNONAME );
return 0;
}
}
int fo_touch( OBJECT *o, int num )
{
if( num==FOPREV )
{
if( flagnum && fo_set( o, 1 ) )
{
flagnum--;
fo_stat(o);
was_new = 0;
}
}
else if( num==FONEXT )
{
if( x_appl_flags( flagmode, flagnum+1, 0L ) && fo_set( o, 1 ) )
{
flagnum++;
fo_stat(o);
was_new = 0;
}
}
else fo_set( o, 0 );
return -1;
}
int fo_exit( OBJECT *o, int num )
{
switch(num)
{
case FODEL:
x_appl_flags( 2, flagnum, 0L );
flagnum--;
fo_stat(o);
was_new = 0;
return 0;
case FONEW:
if( fo_set( o, 1 ) )
{
x_appl_flags( 0, 0, &apf ); /* get default */
strcpy( apf.name, *new_flag ); /* set name to "--New--" */
apf.desc[0] = 0;
x_appl_flags( 1, -1, &apf ); /* create new */
while( x_appl_flags( 0, flagnum+1, &apf ) ) flagnum++; /* find end */
apf0 = apf;
fo_stat(o);
was_new = 1;
}
return 0;
case FOKEYS:
if( !fo_set( o, 1 ) ) return 0;
start_form( 6, FLKEYS, NAME|MOVER );
return 0;
case FOOK:
if( !fo_set( o, 1 ) ) return 0;
break;
default:
if( !was_new ) x_appl_flags( flagmode+1, flagnum, &apf0 );
else x_appl_flags( 2, flagnum, 0L ); /* delete it */
}
/* exiting, so close the Keys dialog */
if( form[6].handle>0 ) close_wind(&form[6].handle);
return 1;
}
int fk_init( OBJECT *o )
{
int i;
if( !flagmode && !flagnum ) fknum = 1;
else fknum = 0;
for( i=0; i<5; i++ )
set_if( o, i+KOMENU, i==fknum );
k_mode( o, 6, 0, 0 );
k_set( o, 0, 0 );
return 1;
}
int k_init( OBJECT *o )
{
WIND_TREE wt;
int hand = form[0].handle;
k_mode( o, 0, 0, 0 );
get_set();
k_set( o, 1, 0 );
wind_set( hand, WF_HSLIDE, 500 );
wind_set( hand, WF_HSLSIZE, 0 );
wind_set( hand, WF_VSLIDE, 500 );
wind_set( hand, WF_VSLSIZE, 0 );
wt.handle = hand;
x_wind_tree( X_WT_GETCNT, &wt );
wt.count = -1;
wt.flag &= ~(X_WTFL_SLIDERS|X_WTFL_CLICKS);
x_wind_tree( X_WT_SET, &wt );
return 1;
}
void ksel( int num, int flag )
{
num = num-MENU_START+KOMENU;
if( flag ) form[0].tree[num].ob_state |= SELECTED;
else form[0].tree[num].ob_state &= ~SELECTED;
x_wdial_draw( form[0].handle, num, 0 );
}
void new_key( int num, int convert )
{
static int keyx[] = { XS_CLOSE, 99, XS_CYCLE, XS_FULL, XS_LFINFO, 99, XS_RTINFO };
if( convert )
{
if( --num > sizeof(keyx)/sizeof(int) ) return;
num = keyx[num];
}
if( num!=99 && num!=xkey )
{
if( xkey<0 && num>=0 ) ksel( xkey, 0 );
xkey = num;
k_set( form[0].tree, 1, 1 );
}
}
unsigned char k_shift( OBJECT *o )
{
return ((o[KOALT].ob_state&SELECTED)<<3) |
((o[KOCNTRL].ob_state&SELECTED)<<2) |
((o[KOSHIFT].ob_state&SELECTED) ? 3 : 0);
}
int fk_touch( OBJECT *o, int num )
{
if( num<KOMENU || num>KOREDRAW )
{
(&apf.open_key+fknum)->shift = k_shift(o);
fo_set( form[5].tree, 1 );
}
else if( fknum != num-KOMENU && !(o[num].ob_state&DISABLED) )
{
fknum = num-KOMENU;
k_set( o, 0, 1 );
}
return -1;
}
int k_touch( OBJECT *o, int num )
{
if( num<KOMENU || num>KOREDRAW )
{
set.wind_keys[xkey].shift = k_shift(o);
x_settings( 1, sizeof(SETTINGS), &set );
}
else new_key( num-KOMENU+MENU_START, 0 );
return -1;
}
int k_exit( OBJECT *o, int num )
{
int sh=0, key=0, dum, is_main;
KEYCODE *k;
is_main = o == form[0].tree;
switch( num )
{
case KOQUIT:
return 1;
case KOREAD:
k_mode( o, is_main?0:6, 1, 1 );
wind_update( BEG_UPDATE );
evnt_multi( MU_KEYBD, 0,0,0, 0,0,0,0,0,
0,0,0,0,0, &dum, 0,0, &dum, &dum, &dum, &sh, &key, &dum );
wind_update( END_UPDATE );
k_mode( o, is_main?0:6, 0, 1 );
if( sh&3 ) sh |= 3;
/* fall through to process key */
case KOCLEAR: /* key=sh=0 for clear */
k = is_main ? &set.wind_keys[xkey] : &apf.open_key+fknum;
k->shift = sh&0xf;
k->scan = key>>8;
k->ascii = 0;
k_set( o, is_main, 1 );
if( is_main ) x_settings( 1, sizeof(SETTINGS), &set );
else fo_set( form[5].tree, 1 );
return 0;
default:
if( is_main ) x_settings( 1, sizeof(SETTINGS), &set0 );
return 0;
}
}
char reztbl[] = { 0, 1, 2, 7, 4, 6 };
int vo_exit( OBJECT *o, int num )
{
int rez, i;
if( num==VOOK )
for( i=VOSTLOW; i<=VOSTLOW+5; i++ )
if( o[i].ob_state & SELECTED )
if( (rez = reztbl[i-VOSTLOW]) != Getrez() )
shel_write( 5, rez+2, 0, 0L, 0L );
return 1;
}
int vo_init( OBJECT *o )
{
int rez, i;
long vid;
char TT_vid;
rez = Getrez();
TT_vid = CJar( 0, _VDO_COOKIE, &vid ) == CJar_OK && (int)(vid>>16)==2;
for( i=VOSTLOW; i<=VOSTLOW+5; i++ )
if( rez==8 && i!=VOSTLOW+5 || TT_vid && i==VOSTLOW+5 ||
!TT_vid && rez==2 && i!=VOSTLOW+2 ||
!TT_vid && rez!=2 && i==VOSTLOW+2 ||
!TT_vid && i>VOSTLOW+2 )
{
o[i].ob_state |= DISABLED;
o[i].ob_state &= ~SELECTED;
}
else
{
o[i].ob_state &= ~DISABLED;
if( reztbl[i-VOSTLOW]==rez ) o[i].ob_state |= SELECTED;
else o[i].ob_state &= ~SELECTED;
}
return 1;
}
void k_mode( OBJECT *o, int fnum, int mode, int draw )
{
hide_if( o, KOCLICK, !mode );
hide_if( o, KOPRESS, mode );
if( draw ) x_wdial_draw( form[fnum].handle, KOBACK, 8 );
}
void k_set( OBJECT *o, int is_main, int draw )
{
int i;
unsigned char *ptr, c, c2;
char **p;
KEYCODE *key;
static unsigned char
keycode[] = { 0, 1, 0xf, 0xe, 0x53, 0x52, 0x62, 0x61, 0x47, 0x48, 0x50,
0x4d, 0x4b, 0x72, 0x60, 0x39 },
keynam[][6] = { "???", "Esc", "Tab", "Bksp", "Del", "Ins", "Help", "Undo",
"Home", "", "", "", "", "Enter", "ISO", "Space" }, fmt[]="F%d",
kpfmt[]="kp %c";
key = is_main ? &set.wind_keys[xkey] : &apf.open_key+fknum;
set_if( o, KOSHIFT, key->shift&3 );
set_if( o, KOCNTRL, key->shift&4 );
set_if( o, KOALT, key->shift&8 );
*(ptr = o[KOKEY].ob_spec.free_string) = '\0';
if( (c = key->ascii) != 0 )
if( c == ' ' ) strcpy( ptr, "Space" );
else
{
*ptr++ = c;
*ptr = 0;
}
else
{
c = key->scan;
if( c==0x74 ) c=0x4d;
else if( c==0x73 ) c=0x4b;
else if( c==0x77 ) c=0x47;
else if( c>=0x78 && c<=0x83 ) c -= 0x76;
for( i=0; i<sizeof(keycode); i++ )
if( keycode[i] == c ) strcpy( ptr, keynam[i] );
if( c >= 0x3b && c <= 0x44 ) x_sprintf( ptr, fmt, c-0x3a );
else if( c >= 0x54 && c <= 0x5d ) x_sprintf( ptr, fmt, c-0x53 );
if( !*ptr )
{
c2 = *(Keytbl( (void *)-1L, (void *)-1L, (void *)-1L )->unshift + c);
if( c >= 0x63 && c <= 0x72 || c == 0x4a || c == 0x4e )
x_sprintf( ptr, kpfmt, c2 );
else
{
*ptr++ = c2;
*ptr = '\0';
}
}
}
rsrc_gaddr( 15, is_main ? S0+xkey : FLK0+fknum, &p );
o[KOCNTRL-1].ob_spec.free_string = *p;
if( !is_main )
{
o[KOMENU-1].ob_spec.free_string = flagmode ? app[tasknum-1].name+2 :
apf.desc[0] ? apf.desc : apf.name;
if( flagmode || flagnum ) o[KOMENU].ob_state &= ~DISABLED;
else o[KOMENU].ob_state |= DISABLED;
}
if( draw )
{
if( !is_main ) x_wdial_draw( form[6].handle, KOMENU-1, 8 );
x_wdial_draw( is_main ? form[0].handle : form[6].handle, KOCNTRL-1, 8 );
}
}
int get_prefer( OB_PREFER **op )
{
int ret;
switch( dattnum )
{
case 0:
*op = set.color_root;
ret = DOSBOX;
break;
case 1:
*op = set.color_3D;
ret = DOS3D;
break;
case 2:
*op = set.color_exit;
ret = DOSEXIT;
break;
case 3:
*op = set.color_other;
ret = DOSOTHER;
break;
}
*op += color_mode;
return ret;
}
void d_obj( int truth, unsigned int *state, int bit, OBJECT *o, int obj )
{
if( truth ) *state |= bit;
set_if( o, obj, truth );
}
void d_sample( OBJECT *o, int num, int val )
{
o[num].ob_spec.index = (o[num].ob_spec.index&0xFFFF0000L) |
(unsigned int)(num==DOPSAMP ? patterns[val+PFIL0].ob_spec.index :
colors[val+PCOL0].ob_spec.index);
}
void d_stat( OBJECT *o, int draw )
{
OB_PREFER *op;
unsigned int obj, *state;
OBJECT *ch;
obj = get_prefer( &op );
ch = &o[obj];
*(state = &ch->ob_state) = X_MAGIC;
d_obj( op->s.outlined, state, OUTLINED, o, DOUTLINE );
d_obj( op->s.shadowed, state, SHADOWED, o, DSHADOW );
d_obj( op->s.draw_3D, state, X_DRAW3D, o, D3D );
d_obj( op->s.rounded, state, X_ROUNDED, o, DROUND );
set_if( o, DOPAQUE, op->s.textmode );
if( obj==DOSBOX ) ch->ob_spec.index =
(ch->ob_spec.index&0xFFFF0000L) | (unsigned int)op->l;
else
ch->ob_spec.tedinfo->te_color = (unsigned int)op->l;
d_sample( o, DOPSAMP, op->s.fillpattern );
d_sample( o, DOPSAMP+1, op->s.interiorcol );
d_sample( o, DOPSAMP+2, op->s.textcol );
d_sample( o, DOPSAMP+3, op->s.framecol );
if( draw&1 ) x_wdial_draw( form[2].handle, obj==DOSBOX ? DOSBOX-1 : DOSBOX, 8 );
if( draw&2 ) x_wdial_draw( form[2].handle, DOBOX, 8 );
if( draw&4 ) x_wdial_draw( form[2].handle, DOSBOX2, 8 );
}
int d_init( OBJECT *o )
{
int old;
get_set();
old = dattnum;
for( dattnum=0; dattnum<4; dattnum++ )
if( dattnum!=old ) d_stat( o, 0 );
dattnum = old;
d_stat( o, 0 ); /* do the current one last */
return 1;
}
unsigned int do_popup( OBJECT *o, int obj, OBJECT *pop, unsigned int val )
{
MENU m, out;
int x, y;
m.mn_tree = pop;
m.mn_menu = 0;
m.mn_item = val+1;
m.mn_scroll = 1;
objc_offset( o, obj, &x, &y );
if( menu_popup( &m, x, y, &out ) ) return out.mn_item-1;
return val;
}
int d_touch( OBJECT *o, int num )
{
OB_PREFER *op;
if( num>=DOOUT && num<=DOOTHER )
{
if( (num-=DOOUT) != dattnum )
{
dattnum = num;
d_stat( o, 2|4 );
}
}
else
{
get_prefer( &op );
switch( num )
{
case DOUTLINE:
op->s.outlined ^= 1;
break;
case DSHADOW:
op->s.shadowed ^= 1;
break;
case D3D:
op->s.draw_3D ^= 1;
break;
case DROUND:
op->s.rounded ^= 1;
break;
case DOPAQUE:
op->s.textmode ^= 1;
break;
case DOPLEFT:
op->s.fillpattern--;
break;
case DOPRT:
op->s.fillpattern++;
break;
case DOPAT:
op->s.fillpattern = do_popup( o, DOPAT, patterns, op->s.fillpattern );
break;
case DOPLEFT+3:
op->s.interiorcol--;
break;
case DOPRT+3:
op->s.interiorcol++;
break;
case DOPAT+3:
op->s.interiorcol = do_popup( o, DOPAT+3, colors, op->s.interiorcol );
break;
case DOPLEFT+6:
op->s.textcol--;
break;
case DOPRT+6:
op->s.textcol++;
break;
case DOPAT+6:
op->s.textcol = do_popup( o, DOPAT+6, colors, op->s.textcol );
break;
case DOPLEFT+9:
op->s.framecol--;
break;
case DOPRT+9:
op->s.framecol++;
break;
case DOPAT+9:
op->s.framecol = do_popup( o, DOPAT+9, colors, op->s.framecol );
break;
}
d_stat( o, 1|4 );
}
return -1;
}
int d_exit( OBJECT *o, int num )
{
if( num==DOOK ) x_settings( 1, sizeof(SETTINGS), &set );
o++;
return 1;
}
void close_vdi(void)
{
if( vdi_hand )
{
if( has_gdos ) vst_unload_fonts( vdi_hand, 0 );
v_clsvwk( vdi_hand );
vdi_hand = 0;
}
}
void text_size( OBJECT *o, char *string, int center )
{
int i;
(char *)(o->ob_spec.userblk->ub_parm) = string;
if( !string ) o->ob_width = font_wid;
else if( (o->ob_width = strlen(string) * font_wid) > o[-1].ob_width )
{
o->ob_width = (i=o[-1].ob_width / font_wid) * font_wid;
o->ob_spec.userblk->ub_parm += strlen(string)-i;
}
o->ob_height = font_ht;
if( center ) o->ob_x = (o[-1].ob_width - o->ob_width + 1) / 2;
o->ob_y = (o[-1].ob_height - font_ht + 1) / 2;
}
void wo_update( OBJECT *o, int draw )
{
int w, h, cw, ch;
w = o[XWOUTER].ob_width;
h = o[XWOUTER].ob_height;
cw = font_wid + fontinfo.gadget_wid;
ch = font_ht + fontinfo.gadget_ht;
o[XWMOVE].ob_width = o[XWBACK].ob_width = o[XWFULL].ob_width =
o[XWUP].ob_width = o[XWVBIGSL].ob_width = o[XWVSMLSL].ob_width = cw;
o[XWMOVE].ob_height = o[XWBACK].ob_height = o[XWFULL].ob_height =
o[XWUP].ob_height = o[XWINFO].ob_height = o[XWVSMLSL].ob_height = ch;
o[XWMOVE].ob_width = w - cw*2 + 2;
o[XWBACK].ob_x = w - cw*2 + 1;
o[XWFULL].ob_x = o[XWUP].ob_x = o[XWVBIGSL].ob_x = w - cw;
o[XWINFO].ob_y = ch - 1;
o[XWINFO].ob_width = w;
o[XWUP].ob_y = (ch-1)*2;
o[XWVBIGSL].ob_y = (ch-1)*3;
o[XWVBIGSL].ob_height = h - (ch-1)*3;
if( o[XWUP].ob_y + ch > h ) o[XWUP].ob_height = -5;
if( o[XWINFO].ob_y + ch > h ) o[XWINFO].ob_height = -5;
if( o[XWVSMLSL].ob_y + o[XWVBIGSL].ob_y + ch > h ) o[XWVSMLSL].ob_height = -5;
text_size( &o[XWMOVET], mover_text, 1 );
text_size( &o[XWINFOT], info_text, 0 );
text_size( &o[XWBACKT], 0L, 1 );
text_size( &o[XWFULLT], 0L, 1 );
text_size( &o[XWUPT], 0L, 1 );
if( draw ) x_wdial_draw( form[3].handle, XWOUTER, 8 );
x_appl_font( 1, 0, &fontinfo );
}
void new_point( OBJECT *o, int draw )
{
int dum;
fontinfo.point_size = vst_point( vdi_hand, fontinfo.point_size,
&dum, &dum, &font_wid, &font_ht );
x_sprintf( o[WOPT].ob_spec.free_string, "%d", fontinfo.point_size );
wo_update( o, draw );
if( draw ) x_wdial_draw( form[3].handle, WOPT, 8 );
}
void new_gadget( OBJECT *o, int draw )
{
x_sprintf( o[WOWID].ob_spec.free_string, "%d", fontinfo.gadget_wid );
x_sprintf( o[WOHT].ob_spec.free_string, "%d", fontinfo.gadget_ht );
wo_update( o, draw );
if( draw )
{
x_wdial_draw( form[3].handle, WOWID, 8 );
x_wdial_draw( form[3].handle, WOHT, 8 );
}
}
void set_fnum( OBJECT *o, int i, int draw )
{
int dum;
font_num = i;
o[WOFONT].ob_spec.free_string = fontpop[i+1].ob_spec.free_string+1;
if( draw ) x_wdial_draw( form[3].handle, WOFONT, 8 );
vst_font( vdi_hand, fontinfo.font_id = font_id[i] );
vst_alignment( vdi_hand, 0, 5, &dum, &dum );
new_point( o, draw );
}
void get_font( OBJECT *o, int draw )
{
int i;
x_appl_font( 0, 0, &fontinfo0 );
memcpy( &fontinfo, &fontinfo0, sizeof(fontinfo) );
o[WOFONT].ob_spec.free_string = "";
font_num = 0;
for( i=0; i<fonts; i++ )
if( font_id[i] == fontinfo.font_id )
{
set_fnum( o, i, draw );
break;
}
}
int cdecl win_text( PARMBLK *pb )
{
int clip[4];
char *s, temp[2];
clip[2] = (clip[0] = pb->pb_xc) + pb->pb_wc - 1;
clip[3] = (clip[1] = pb->pb_yc) + pb->pb_hc - 1;
vs_clip( vdi_hand, 1, clip );
if( (s = (char *)(pb->pb_parm)) == 0 )
{
temp[0] = pb->pb_tree[pb->pb_obj].ob_type>>8;
temp[1] = 0;
s = temp;
vswr_mode( vdi_hand, MD_TRANS );
}
else vswr_mode( vdi_hand, MD_REPLACE );
v_gtext( vdi_hand, pb->pb_x, pb->pb_y, s );
return pb->pb_currstate;
}
void set_onechar( OBJECT *o, USERBLK *ub )
{
o->ob_type = (o->ob_spec.obspec.character<<8) | G_USERDEF;
o->ob_spec.userblk = ub;
}
int wo_init( OBJECT *o )
{
int i, j, total, id, min, max, dum[5], maxw, wid;
char namebuf[32];
static USERBLK ub_move, ub_info, ub_onechar;
if( vdi_hand ) return 1; /* just in case it's already open */
vdi_hand = graf_handle( dum, dum, dum, dum );
work_in[0] = Getrez() + 2;
v_opnvwk( work_in, &vdi_hand, work_out );
if( !vdi_hand )
{
alert( ALNOVDI );
return 0;
}
total = work_out[10];
has_gdos = vq_gdos();
if( has_gdos )
{
graf_mouse( BUSYBEE, 0L );
total += vst_load_fonts( vdi_hand, 0 );
graf_mouse( ARROW, 0L );
}
for( i=1, fonts=0; i<=total && fonts<16; i++ )
{
id = vqt_name( vdi_hand, i, namebuf );
if( id != -1 )
{
vst_font( vdi_hand, id );
vqt_fontinfo( vdi_hand, &min, &max, dum, &maxw, dum );
for( j=min; j<=max; j++ )
{
vqt_width( vdi_hand, j, &wid, dum, dum );
if( wid != maxw ) break;
}
if( j>max )
{
font_id[fonts] = id;
strncpy( fontpop[++fonts].ob_spec.free_string+1,
id==1 ? *sys_font : namebuf, 16 );
objc_add( fontpop, 0, fonts );
}
}
}
fontpop[0].ob_height = fontpop[1].ob_height*fonts;
if( o[XWMOVET].ob_type != G_USERDEF )
{
o[XWMOVET].ob_type = o[XWINFOT].ob_type = G_USERDEF;
mover_text = o[XWMOVET].ob_spec.free_string;
o[XWMOVET].ob_spec.userblk = &ub_move;
info_text = o[XWINFOT].ob_spec.free_string;
o[XWINFOT].ob_spec.userblk = &ub_info;
set_onechar( &o[XWBACKT], &ub_onechar );
set_onechar( &o[XWFULLT], &ub_onechar );
set_onechar( &o[XWUPT], &ub_onechar );
ub_move.ub_code = ub_info.ub_code = ub_onechar.ub_code = win_text;
}
get_font( o, 0 );
new_gadget( o, 0 );
return 1;
}
int wo_exit( OBJECT *o, int num )
{
switch( num )
{
case WOFONT:
if( fonts>1 ) set_fnum( o, do_popup( o, WOFONT, fontpop, font_num ), 1 );
return 0;
case WODFLT:
fontinfo.font_id = fontinfo.point_size = fontinfo.gadget_wid =
fontinfo.gadget_ht = -2; /* reset to defaults */
x_appl_font( 1, 0, &fontinfo ); /* set */
x_appl_font( 0, 0, &fontinfo ); /* get new values */
get_font( o, 1 );
new_gadget( o, 1 );
return 0;
case WOOK:
if( memcmp( &fontinfo, &fontinfo0, sizeof(fontinfo) ) ) alert( ALSAVE );
return 1;
default:
x_appl_font( 1, 0, &fontinfo0 );
return 1;
}
}
int wo_touch( OBJECT *o, int num )
{
int pt, dum;
switch( num )
{
case WOPUP:
for( pt=fontinfo.point_size+1; pt<25; pt++ )
if( vst_point( vdi_hand, pt, &dum, &dum, &dum, &dum ) == pt )
{
fontinfo.point_size = pt;
new_point( o, 1 );
break;
}
break;
case WOPDWN:
if( vst_point( vdi_hand, pt=fontinfo.point_size-1, &dum, &dum,
&dum, &dum ) <= pt )
{
fontinfo.point_size = pt;
new_point( o, 1 );
}
break;
case WOWUP:
if( fontinfo.gadget_wid<25 )
{
fontinfo.gadget_wid++;
new_gadget( o, 1 );
}
break;
case WOWDWN:
if( fontinfo.gadget_wid>0 )
{
fontinfo.gadget_wid--;
new_gadget( o, 1 );
}
break;
case WOHUP:
if( fontinfo.gadget_ht<25 )
{
fontinfo.gadget_ht++;
new_gadget( o, 1 );
}
break;
case WOHDWN:
if( fontinfo.gadget_ht>0 )
{
fontinfo.gadget_ht--;
new_gadget( o, 1 );
}
break;
}
num++;
return -1;
}
void calc_bord( int type, OBJECT *tree, GRECT *g )
{
wind_calc( WC_BORDER, type, tree[0].ob_x, tree[0].ob_y,
tree[0].ob_width, tree[0].ob_height, &g->g_x, &g->g_y,
&g->g_w, &g->g_h );
}
void start_form( int fnum, int tnum, int type )
{
FORM *f = &form[fnum];
int dum, hand;
GRECT out;
if( f->handle>0 ) wind_set( f->handle, WF_TOP );
else
{
if( !f->tree )
{
rsrc_gaddr( 0, tnum, &f->tree );
f->tree[1].ob_flags |= HIDETREE;
calc_bord( type, f->tree, &out );
out.g_x = (max.g_w-out.g_w)/2 + max.g_x;
out.g_y = (max.g_h-out.g_h)/2 + max.g_y;
wind_calc( WC_WORK, type, out.g_x, out.g_y, out.g_w, out.g_h,
&f->tree[0].ob_x, &f->tree[0].ob_y, &dum, &dum );
}
else calc_bord( type, f->tree, &out );
if( (hand=wind_create( type, out.g_x, out.g_y, out.g_w, out.g_h )) > 0 )
{
f->handle = hand;
if( (*f->init)( f->tree ) )
{
wind_set( hand, X_WF_DIALOG, f->tree );
wind_set( hand, WF_NAME, f->tree[1].ob_spec.free_string );
wind_open( hand, out.g_x, out.g_y, out.g_w, out.g_h );
}
else close_wind( &f->handle );
}
}
}
void use_form( int hand, int num )
{
int i, j, but;
FORM *f;
if( !hand ) return;
for( f=&form[0]; f->init; f++ )
if( f->handle == hand )
{
but = num&0x7FFF;
if( f->tree[but].ob_flags & TOUCHEXIT )
if( f->touch && (j=(*f->touch)( f->tree, but )) >= 0 )
x_wdial_draw( f->handle, j, 8 );
if( f->tree[but].ob_flags&EXIT )
{
f->tree[but].ob_state &= ~SELECTED;
if( f->exit && (*f->exit)( f->tree, num ) ) close_wind(&f->handle);
else x_wdial_draw( f->handle, but, 8 );
}
return;
}
}
char chksum( char *buf )
{
char chk=0;
while( *buf ) chk = (chk + *buf++)<<1;
return chk;
}
int qsc( struct App *ap1, struct App *ap2 )
{
return( strcmp( ap1->name, ap2->name ) );
}
void set_term_sleep(void)
{
menu_ienable( menu, TERM, tasknum>0 );
menu_ienable( menu, SLEEP, tasknum>0 );
menu_icheck( menu, SLEEP, tasknum>0 && (app[tasknum-1].asleep&1) );
}
int task_list(void)
{
static char chk=0;
char nchk;
int i, j, type, sleep;
struct App *a;
for( nchk=0, j=0, i=1, a=&app[0]; i<65; i++, a++ )
if( appl_search( j, a->name+3, &type, &a->num ) )
{
a->asleep = x_appl_sleep( a->num, -1 );
if( a->asleep&2 ) strcpy( a->name+2, a->name+3 );
else a->name[2] = ' ';
nchk += chksum(a->name+3) + type + a->asleep;
a->name[0] = type!=4 ? ' ' : '°';
a->name[1] = ' ';
j=1;
}
else break;
i--;
qsort( app, i, sizeof(app[0]), qsc );
if( i != apps || chk != nchk )
{
apps = i;
chk = nchk;
blank[0].ob_head = blank[0].ob_tail = -1;
for( i=1, a=&app[0]; i<=apps; i++, a++ )
{
memcpy( blank+i, new, sizeof(OBJECT) );
blank[i].ob_y = (i-1)*char_h;
blank[i].ob_spec.free_string = a->name;
if( a->asleep&1 ) blank[i].ob_flags |= X_ITALICS;
if( !(a->asleep&2) ) blank[i].ob_state |= X_SMALLTEXT;
if( i==tasknum ) blank[i].ob_state |= SELECTED;
objc_add( blank, 0, i );
}
return 1;
}
return 0;
}
void set_bl_height(void)
{
int i;
blank[0].ob_height = (i=apps*char_h) > winner.g_h ? i : winner.g_h;
}
void get_inner(void)
{
wind_calc( WC_WORK, WIN_TYPE, wsize.g_x, wsize.g_y, wsize.g_w, wsize.g_h,
&winner.g_x, &winner.g_y, &winner.g_w, &winner.g_h );
new[0].ob_x = 2;
blank[0].ob_width = winner.g_w;
set_bl_height();
}
void get_outer(void)
{
/* winner.g_w = (winner.g_w+5)/8*8 + 2;*/
winner.g_h = (winner.g_h+(char_h>>1))/char_h*char_h;
wind_calc( WC_BORDER, WIN_TYPE, winner.g_x, winner.g_y,
winner.g_w, winner.g_h, &wsize.g_x, &wsize.g_y, &wsize.g_w,
&wsize.g_h );
}
void but_up(void)
{
int b, dum;
do
graf_mkstate( &dum, &dum, &b, &dum );
while( b&1 );
}
void tnum_onoff( int handle, int num, int state )
{
x_wdial_change( handle, num, !state ? (blank[num].ob_state&~SELECTED) :
(blank[num].ob_state|SELECTED) );
}
void opentask( int handle, int num )
{
int msg[8];
/* if( app[num-1].asleep&1 ) x_appl_sleep( app[num-1].num, 0 );*/
msg[0] = AC_OPEN;
msg[2] = 0;
msg[4] = -1;
appl_write( msg[1] = app[num-1].num, 16, msg );
tnum_onoff( handle, num, 0 );
}
void set_if( OBJECT *tree, int num, int true )
{
if( true ) tree[num].ob_state |= SELECTED;
else tree[num].ob_state &= ~SELECTED;
}
int exec_ext( char *path, char *env, int i )
{
char *ptr;
if( shel_envrn( &ptr, env ) && *ptr )
{
strcat( path, i ? "," : "*.{" );
strcat( path, ptr );
return 1;
}
return i;
}
int spf_alert( char *s, char *s2 )
{
char buf[200];
x_sprintf( buf, s, s2 );
return( form_alert( 1, buf ) );
}
void get_color_mode(void)
{
int work[56], vplanes, vdi_hand;
vdi_hand = graf_handle( work, work, work, work );
vq_extnd( vdi_hand, 1, work );
vplanes = work[4];
if( vplanes>=8 ) color_mode = 3;
else if( vplanes>=4 ) color_mode = 2;
else if( vplanes>=2 ) color_mode = 1;
else color_mode = 0;
}
int main(void)
{
char **title, **fstitle, path[120], name[13*5+1], temp[150], temp2[80],
*ptr, *ptr2, **term_msg, **ptr3, was_open=0;
int handle=0, buf[8], but, dum, event, i, etype=MU_MESAG|X_MU_DIALOG,
timer, min_ht, min_wid; /* min_wid is acutally the only width */
long cookie;
GRECT old;
SHWRCMD shwrcmd;
apid = appl_init();
shel_write( 9, 1, 0, 0L, 0L );
/* check to make sure MAGIC is active */
if( CJar( 0, my_cookie, &cookie ) != CJar_OK || !cookie )
{
form_alert( 1, "[1][MAGIC must be present|in order for TASKMAN|to run][Ok]" );
}
else if( rsrc_load("taskman.rsc") )
{
get_color_mode();
/* default item selector path */
path[0] = Dgetdrv()+'A';
path[1] = ':';
Dgetpath( path+2, 0 );
strcat( path, "\\" );
/* read extensions from GEM env vars for use in item selector */
if( !exec_ext( path, "ACCEXT=", exec_ext( path, "TOSEXT=",
exec_ext( path, "GEMEXT=", 0 ) ) ) ) strcat( path, "*.*" );
else strcat( path, "}" );
name[0] = 0;
/* get main window menu tree and initialize root for keybd equivs */
rsrc_gaddr( 0, TMENU, &menu );
menu[0].ob_state |= X_MAGIC;
/* get the popup menus */
rsrc_gaddr( 0, PCOLORS, &colors );
rsrc_gaddr( 0, PFILLS, &patterns );
rsrc_gaddr( 0, PFONTS, &fontpop );
/* get other strings used */
rsrc_gaddr( 15, TITLE, &title );
rsrc_gaddr( 15, FSTITLE, &fstitle );
rsrc_gaddr( 15, NEW, &new_flag );
rsrc_gaddr( 15, SSYSTEM, &sys_font );
/* fix the new object tree used for entries in the task list */
rsrc_obfix( new, 0 );
appl_getinfo( 0, &char_h, &dum, &dum, &dum );
/* set default window width to same size as menu */
wsize.g_w = menu[2].ob_width;
get_inner();
wind_get( 0, WF_WORKXYWH, &max.g_x, &max.g_y, &max.g_w, &max.g_h );
/* set the correct name in the menu */
menu_register( apid, *title );
if( _app ) /* running as PRG */
{
graf_mouse( ARROW, 0L );
goto open;
}
timer = 500; /* wait for 5 seconds, normally */
for(;;)
{
event = evnt_multi( etype, 0,0,0, 0,0,0,0,0,
0,0,0,0,0, buf, timer,0, &dum, &dum, &dum, &dum, &dum, &dum );
timer = 500;
if( event&MU_MESAG ) switch( buf[0] )
{
case AC_OPEN:
open: if( handle<=0 )
{
if( !was_open )
{
wind_update( BEG_UPDATE );
task_list();
set_term_sleep();
wind_update( END_UPDATE );
winner.g_h = apps<16 ? apps*char_h : char_h*16;
get_outer();
}
if( (handle=wind_create( WIN_TYPE,
wsize.g_x, wsize.g_y, wsize.g_w, wsize.g_h )) > 0 )
{
if( !was_open )
{
wind_get( handle, X_WF_MINMAX, &min_wid, &min_ht, &dum, &dum );
if( min_wid < menu[2].ob_width ) min_wid=menu[2].ob_width;
wind_calc( WC_BORDER, WIN_TYPE, 0, 0, (10*8)+4, 0,
&dum, &dum, &buf[0], &dum );
if( min_wid < buf[0] ) min_wid = buf[0];
wsize.g_w = min_wid;
if( wsize.g_h < min_ht ) wsize.g_h = min_ht;
}
wind_set( handle, X_WF_MINMAX, min_wid, min_ht, min_wid, -1 );
get_inner();
blank[0].ob_x = winner.g_x;
blank[0].ob_y = winner.g_y;
wind_set( handle, X_WF_DIALOG, blank );
wind_set( handle, X_WF_DIALHT, char_h );
wind_set( handle, X_WF_MENU, menu );
wind_set( handle, WF_NAME, *title + 2 );
wind_open( handle, wsize.g_x, wsize.g_y, wsize.g_w, wsize.g_h );
etype |= MU_TIMER;
timer = 0; /* force task list update */
was_open=1;
}
break;
}
buf[3] = handle; /* fall through if already open */
case WM_TOPPED:
wind_set( buf[3], WF_TOP );
break;
case WM_FULLED:
if( buf[3] != handle ) break;
buf[4] = wsize.g_x;
buf[5] = wsize.g_y;
wind_get( handle, X_WF_MINMAX, &dum, &dum, &buf[6], &buf[7] );
case WM_MOVED:
case WM_SIZED:
if( buf[3]==handle )
{
old = wsize;
wsize = *(GRECT *)&buf[4];
get_inner();
if( winner.g_h > blank[0].ob_height ) winner.g_h =
blank[0].ob_height;
get_outer();
*(GRECT *)&buf[4] = wsize;
}
wind_set( buf[3], WF_CURRXYWH, buf[4], buf[5], buf[6], buf[7] );
/* force a redraw if it wouldn't otherwise happen */
if( buf[3]==handle && wsize.g_w <= old.g_w && wsize.g_h <= old.g_h &&
(wsize.g_w != old.g_w || wsize.g_h != old.g_h) ) wind_set( handle,
X_WF_DIALOG, blank );
break;
case WM_CLOSED:
if( buf[3]==handle )
{
close: close_wind(&handle);
etype &= ~MU_TIMER;
if( _app )
{
appl_exit();
return 0;
}
}
break;
case AC_CLOSE:
handle=0;
close_vdi();
for( i=0; form[i].init; i++ )
form[i].handle = 0;
etype = MU_MESAG|X_MU_DIALOG;
break;
case WM_ARROWED:
if( form[0].handle>0 && buf[3]==form[0].handle ) new_key( buf[4], 0 );
break;
case AP_TERM:
appl_exit();
return 0;
case SHUT_COMPLETED:
if( buf[3]==0 ) alert( ALNOSHUT );
else
{
appl_exit();
return 0;
}
break;
case RESCH_COMPLETED:
if( buf[3]==0 ) alert( ALREZ );
else
{
appl_exit();
return 0;
}
break;
case CH_EXIT:
if( buf[4] )
{
appl_search( -1, temp2, &dum, &but );
rsrc_gaddr( 15, ALTERM, &term_msg );
rsrc_gaddr( 15, SUNKNOWN, &ptr3 );
x_sprintf( temp, *term_msg, but==buf[3] ? temp2 : *ptr3, buf[4] );
if( buf[4]<0 ) x_form_error( temp, buf[4] );
else
{
rsrc_gaddr( 15, SUNDEF, &ptr3 );
spf_alert( temp, *ptr3 );
}
}
timer = 0;
break;
case X_WM_SELECTED:
if( form[0].handle>0 && buf[3]==form[0].handle )
if( buf[4]==WMOVE )
{
wind_get( buf[3], WF_CURRXYWH, buf+4, buf+5, buf+6, buf+7 );
if( graf_dragbox( buf[6], buf[7], buf[4], buf[5],
max.g_x-buf[6], max.g_y, max.g_w<<1, max.g_h<<1, buf+4, buf+5 ) )
wind_set( buf[3], WF_CURRXYWH, buf[4], buf[5], buf[6], buf[7] );
}
else new_key( buf[4], 1 );
break;
case X_MN_SELECTED:
switch( buf[4] )
{
case OPEN:
if( tasknum>0 )
{
opentask( handle, tasknum );
tasknum=0;
set_term_sleep();
}
else if( x_fsel_input( path, sizeof(path), name, 5,
&but, *fstitle ) && but )
{
strcpy( temp, path );
if( (ptr=strrchr(temp,'\\')) == 0 ) ptr=temp;
else ptr++;
for( ptr2=name; *ptr2; ptr2+=strlen(ptr2)+1 )
{
strcpy( ptr, ptr2 );
shwrcmd.name = temp;
shwrcmd.dflt_dir = path;
if( !shel_write( (1<<10)|0, 1, 0, (char *)&shwrcmd, "" ) )
{
rsrc_gaddr( 15, ALOPEN, &ptr3 );
spf_alert( *ptr3, ptr2 );
}
}
}
break;
case QUIT:
if( handle ) close_wind(&handle);
for( i=0; form[i].init; i++ )
if( form[i].handle ) close_wind(&form[i].handle);
etype = MU_MESAG|X_MU_DIALOG;
if( _app )
{
appl_exit();
return 0;
}
break;
case TERM:
if( tasknum>0 )
if( x_appl_term( app[tasknum-1].num, 0, 1 ) ) timer = 0;
break;
case SLEEP:
if( tasknum>0 )
{
x_appl_sleep( app[tasknum-1].num, (app[tasknum-1].asleep&1)^1 );
timer = 0;
}
break;
case SHUT:
if( alert( ALSHUT ) == 1 ) shel_write( 4, 1, 0, 0L, 0L );
break;
case KEYBOARD:
start_form( 0, KEYOPTS, CLOSER|FULLER|MOVER|INFO|UPARROW|DNARROW|VSLIDE|LFARROW|RTARROW|HSLIDE );
break;
case MISC:
start_form( 1, MISCOPTS, NAME|MOVER );
break;
case DIALOGS:
start_form( 2, DIALOPTS, NAME|MOVER );
break;
case TWINDOWS:
start_form( 3, WINDOPTS, NAME|MOVER );
break;
case VIDEO:
start_form( 4, VIDOPTS, NAME|MOVER );
break;
case FLAGS:
start_form( 5, FLAGOPTS, NAME|MOVER );
break;
case SAVE:
x_shel_put( X_SHLOADSAVE, 0L );
break;
case RELOAD:
x_shel_get( X_SHLOADSAVE, 0, 0L );
break;
}
menu_tnormal( menu, buf[3], 1 );
break;
}
if( event&X_MU_DIALOG )
{
but = buf[2]&0x7fff;
if( buf[3]==handle )
if( buf[2]&0x8000 )
{
if( but ) opentask( handle, but );
else if( tasknum>0 ) tnum_onoff( handle, tasknum, 0 );
tasknum=0;
set_term_sleep();
}
else
{
/* a DISABLED object does not get selected automatically,
so we have to handle this ourselves */
if( tasknum>0 && tasknum!=but ) tnum_onoff( handle, tasknum, 0 );
if( but && blank[but].ob_state&DISABLED ) tnum_onoff( handle, but, 1 );
tasknum=but;
but_up();
set_term_sleep();
}
else use_form( buf[3], buf[2] );
}
if( event&MU_TIMER && handle>0 )
{
wind_update( BEG_UPDATE );
if( task_list() )
{
set_bl_height();
wind_calc( WC_BORDER, WIN_TYPE, 0, 0, blank[0].ob_width,
blank[0].ob_height, &dum, &dum, buf, buf+1 );
wind_set( handle, X_WF_MINMAX, -1, -1, buf[0], buf[1] );
if( tasknum>0 ) blank[tasknum].ob_state &= ~SELECTED;
tasknum = 0;
set_term_sleep();
wind_set( handle, X_WF_DIALOG, blank );
}
wind_update( END_UPDATE );
}
}
}
else form_alert( 1, "[1][|TASKMAN.RSC not found!][Ok]" );
if( _app )
{
appl_exit();
return 0;
}
for(;;)
{
evnt_mesag(buf);
if( buf[0]==AP_TERM )
{
appl_exit();
return 0;
}
}
}