home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TIMEXSRC.ZIP
/
UA_EVWIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-29
|
14KB
|
444 lines
/* ua_evwin.c -- Event editing window control
February 1990 Mark E. Mallett, Personal Workstation Magazine
This module contains the code controlling the event editing dialog
window.
Included are the following routines:
event_winproc Event editing window procedure
*/
#define INCL_WIN
#include <stdio.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#include <os2.h>
#include "timex.h"
#include "ua_timex.h"
#include "ua_pm.h"
#include "ua_baif.h"
#include "evpack.h"
/* Local definitions */
/* External data referenced */
extern EVENT *CureventP; /* Current event */
/* External routines used */
extern int atoi( char *strP );
extern void get_events( void );
/* Local data publicly available */
/* Local routines and forward declarations */
static void fill_evwin( void );
static int proc_evdata( void );
static void set_dayof( int id );
/* Private data */
static HWND EvwinH; /* Event window handle */
/* Table describing the day-of elements */
static struct {
int do_id; /* Base ID */
int do_elC; /* Number of elements */
} Dotbl[] = {
{ EEL_DAYOFMON, 31 },
{ EEL_DAYOFWEEK, 7 },
{ 0, 0 } } ;
/*
*//* event_winproc( winH, msgcode, mp1, mp2 )
Window procedure for the event editing window
Accepts :
winH Window handler
msgcode Message code
mp1 First message parameter
mp2 Second window parameter
Returns :
*/
MRESULT EXPENTRY
event_winproc(
HWND winH, /* Window handle */
USHORT msgcode, /* Message code */
MPARAM mp1, /* First parm */
MPARAM mp2 /* Second parm */
) {
int i; /* Scratch */
int yearX; /* Index in year list */
HWND yearH; /* Handle for year list */
char buf[50]; /* String buffer */
/* Dispatch on the message code */
switch( msgcode ) {
case WM_INITDLG: /* Dialog initialization */
EvwinH = winH; /* Remember event window handle */
set_dayof( EEL_DAYOFMON ); /* Setup day-of dialog */
/* If we're modifying an event, setup screen from it */
if ( CureventP != NULL )
fill_evwin();
break;
case WM_COMMAND: /* Command from a button */
switch ( COMMANDMSG( &msgcode )->cmd ) {
case EEL_YEARADD: /* Add a year */
/* Get the year to add */
WinQueryDlgItemText( EvwinH, EEL_YEARENTER, 50, &buf[0] );
if ( ( buf[0] == NUL ) || !isdigit( buf[0] ) )
warning( EC_NOTOK, "Year must be entered." );
else {
/* Turn it into a 4-digit year */
i = atoi( &buf[0] );
sprintf( &buf[0], "%04d", i < 100 ? i + 1900 : i );
/* Add it to the list */
yearH = WinWindowFromID( EvwinH, EEL_YEARLIST );
WinSendMsg( yearH, LM_INSERTITEM,
MPFROM2SHORT( LIT_SORTASCENDING, 0 ),
MPFROMP( &buf[0] ) );
}
return( 0 );
case EEL_YEARDEL: /* Delete selected year */
yearH = WinWindowFromID( EvwinH, EEL_YEARLIST );
yearX = (int)WinSendMsg( yearH, LM_QUERYSELECTION,
MPFROMSHORT( LIT_FIRST ), 0L );
if ( yearX == LIT_NONE )
warning( EC_OK, "No year selected." );
else {
/* Remove it from the list */
WinSendMsg( yearH, LM_DELETEITEM,
MPFROMSHORT( yearX ), 0L );
}
return( 0 );
case EEL_DONE:
/* Process the information */
if ( !proc_evdata() )
break; /* Need more info */
/* Get new events list from database */
get_events();
/* All set -- fall through to get rid of window */
case EEL_CANCEL:
WinDismissDlg( winH, TRUE );
return( 0 );
case EEL_DAYOFWEEK+EEL_DAYOF: /* Switch to day-of-month */
set_dayof( EEL_DAYOFMON );
return( 0 );
case EEL_DAYOFMON+EEL_DAYOF: /* Switch to day-of-week */
set_dayof( EEL_DAYOFWEEK );
return( 0 );
}
return( 0 );
case WM_ERASEBACKGROUND:
return( 1 );
}
/* Not handled here... give to parent handler */
return( WinDefDlgProc( winH, msgcode, mp1, mp2 ) );
}
/*
*//* fill_evwin()
Fill the event window from the current event
*/
static void
fill_evwin( void ) {
int i; /* Scratch */
int y; /* Year number */
HWND ylistH; /* Yearlist window handle */
char buf[50]; /* String buffer */
/* Event name */
WinSetDlgItemText( EvwinH, EEL_EVNAME, CureventP->ev_nameP );
/* Action type */
WinSetDlgItemText( EvwinH, EEL_ACTYPE,
CureventP->ev_acttype == ACTION_RUN ? "RUN" :
"???" );
/* Action string */
WinSetDlgItemText( EvwinH, EEL_ACTION, CureventP->ev_actargP );
/* Priority class */
sprintf( &buf[0], "%d", CureventP->ev_priclass );
WinSetDlgItemText( EvwinH, EEL_PRICLASS, &buf[0] );
/* Priority value */
sprintf( &buf[0], "%d", CureventP->ev_prival );
WinSetDlgItemText( EvwinH, EEL_PRIVAL, &buf[0] );
/* Years */
ylistH = WinWindowFromID( EvwinH, EEL_YEARLIST );
WinSendMsg( ylistH, LM_DELETEALL, NULL, NULL );
for( i = 0; i < CureventP->ev_yearC; ++i ) {
for( y = CureventP->ev_yearP[i].y_first;
y <= CureventP->ev_yearP[i].y_last;
++y ) {
sprintf( &buf[0], "%04d", y );
WinSendMsg( ylistH, LM_INSERTITEM,
MPFROM2SHORT( LIT_SORTASCENDING, 0 ),
MPFROMP( &buf[0] ) );
}
}
/* Months */
for( i = 0; i < 12; ++i )
if ( ( CureventP->ev_months & ( 1 << i ) ) != 0 )
WinSendDlgItemMsg( EvwinH, EEL_MONTH+i, BM_SETCHECK,
MPFROMSHORT( 1 ), 0L );
/* Day-of */
if ( CureventP->ev_dayof == DAYOF_MONTH ) {
set_dayof( EEL_DAYOFMON );
for ( i = 0; i < 31; ++i )
if ( ( CureventP->ev_dayofs & ( 1L << i ) ) != 0 )
WinSendDlgItemMsg( EvwinH, EEL_DAYOFMON+i, BM_SETCHECK,
MPFROMSHORT( 1 ), 0L );
}
else {
set_dayof( EEL_DAYOFWEEK );
for ( i = 0; i < 7; ++i )
if ( ( CureventP->ev_dayofs & ( 1L << i ) ) != 0 )
WinSendDlgItemMsg( EvwinH, EEL_DAYOFWEEK+i, BM_SETCHECK,
MPFROMSHORT( 1 ), 0L );
}
/* Hours */
for( i = 0; i < 24; ++i )
if ( ( CureventP->ev_hours & ( 1L << i ) ) != 0 )
WinSendDlgItemMsg( EvwinH, EEL_HOUR+i, BM_SETCHECK,
MPFROMSHORT( 1 ), 0L );
/* Minutes */
for( i = 0; i < 60; ++i )
if ( ( CureventP->ev_mins[i/32] & ( 1L << ( i%32 ) ) ) != 0 )
WinSendDlgItemMsg( EvwinH, EEL_MIN + (i/5)*5, BM_SETCHECK,
MPFROMSHORT( 1 ), 0L );
}
/*
*//* proc_evdata()
Process the event data when it's done
Accepts :
Returns :
< value > TRUE if processed,
FALSE if not all fields are filled in.
error return if error.
*/
static int
proc_evdata( void ) {
int status;
int i; /* Scratch */
int n; /* Another scratch */
int priclass; /* Priority class */
int prival; /* Priority value */
EVENT *eventP; /* Ptr to event */
HWND ylistH; /* Yearlist handle */
char evname[100]; /* Name of event */
char acttype[20]; /* Action type */
char action[100]; /* Action string */
char buf[50]; /* Scratch buffer */
/* Get the info that is required */
WinQueryDlgItemText( EvwinH, EEL_EVNAME, 100, &evname[0] );
if ( evname[0] == NUL ) {
warning( EC_OK, "Event name is required." );
return( FALSE );
}
WinQueryDlgItemText( EvwinH, EEL_ACTYPE, 20, &acttype[0] );
if ( acttype[0] == NUL ) {
warning( EC_OK, "Action Type is required." );
return( FALSE );
}
WinQueryDlgItemText( EvwinH, EEL_ACTION, 100, &action[0] );
if ( action[0] == NUL ) {
warning( EC_OK, "Action string is required." );
return( FALSE );
}
/* Make event from the event data ... */
event_clear();
event_name( &evname[0] );
if ( stricmp( &acttype[0], "Run" ) == 0 )
event_acttype( ACTION_RUN );
event_action( &action[0] );
/* Priority */
WinQueryDlgItemText( EvwinH, EEL_PRICLASS, 50, &buf[0] );
if ( buf[0] != NUL )
priclass = atoi( &buf[0] );
else
priclass = -1;
WinQueryDlgItemText( EvwinH, EEL_PRIVAL, 50, &buf[0] );
if ( buf[0] != NUL )
prival = atoi( &buf[0] );
else
prival = -1;
event_pri( prival, priclass );
/* Get the year data */
ylistH = WinWindowFromID( EvwinH, EEL_YEARLIST );
n = (int)WinSendMsg( ylistH, LM_QUERYITEMCOUNT, NULL, NULL );
for( i = 0; i < n; ++i ) {
WinSendMsg( ylistH, LM_QUERYITEMTEXT,
MPFROM2SHORT( i, 50 ),
MPFROMP( &buf[0] ) );
event_year( atoi( &buf[0] ), atoi( &buf[0] ) );
}
/* Get the months */
for( i = 0; i < 12; ++i )
if ( WinSendDlgItemMsg( EvwinH, EEL_MONTH+i, BM_QUERYCHECK,
NULL, NULL ) )
event_month( i );
/* Day-of */
/* Check for day-of-month */
if ( WinIsWindowEnabled( WinWindowFromID( EvwinH, EEL_DAYOFMON ) ) ) {
for( i = 0; i < 31; ++i )
if ( WinSendDlgItemMsg( EvwinH, EEL_DAYOFMON+i, BM_QUERYCHECK,
NULL, NULL ) )
event_dayofmon( i+1 );
}
else {
/* Day of week */
for( i = 0; i < 7; ++i )
if ( WinSendDlgItemMsg( EvwinH, EEL_DAYOFWEEK+i,BM_QUERYCHECK,
NULL, NULL ) )
event_dayofwk( i );
}
/* Get the hours */
for( i = 0; i < 24; ++i )
if ( WinSendDlgItemMsg( EvwinH, EEL_HOUR+i, BM_QUERYCHECK,
NULL, NULL ) )
event_hour( i );
/* Minutes */
for( i = 0; i < 60; i += 5 )
if ( WinSendDlgItemMsg( EvwinH, EEL_MIN+i, BM_QUERYCHECK,
NULL, NULL ) )
event_min( i );
eventP = event_make();
/* Update the database. */
if ( CureventP == NULL )
status = ba_add( eventP );
else
status = ba_modify( CureventP->ev_nameP, eventP );
free( eventP );
return( status );
}
/*
*//* set_dayof( id )
Setup the "day of" dialog
Accepts :
id ID of the root of the dialog
Returns :
*/
static void
set_dayof(
int id /* The ID to set */
) {
int doX; /* Index into day-of table */
int elid; /* Element id */
int baseid; /* Base ID of group */
int maxid; /* Maximum ID */
HWND winH; /* Subwindow handle */
/* Adjust the passed ID to be the id of the surrounding box. */
--id;
/* Start update */
WinEnableWindowUpdate( EvwinH, FALSE );
/* Go through the day-of table */
for( doX = 0; ( baseid = Dotbl[doX].do_id ) != 0; ++doX ) {
--baseid; /* ID of box */
maxid = baseid + Dotbl[doX].do_elC;
for( elid = baseid; elid <= maxid; ++elid ) {
winH = WinWindowFromID( EvwinH, elid );
WinShowWindow( winH, id == baseid );
WinEnableWindow( winH, id == baseid );
}
/* Also do the switch box */
winH = WinWindowFromID( EvwinH, baseid+EEL_DAYOF+1 );
WinShowWindow( winH, id == baseid );
WinEnableWindow( winH, id == baseid );
}
/* Update the screen now */
/* WinShowWindow( EvwinH, TRUE ); */
WinEnableWindowUpdate( EvwinH, TRUE );
}