Category : C Source Code
Archive   : SMPDEMO2.ZIP
Filename : MOUSE.C

 
Output of file : MOUSE.C contained in archive : SMPDEMO2.ZIP
/* Screen Manager Professional (tm) (c) 1991 Magee Enterprises, Inc.
* for C Compilers.
*
* FILE: MOUSE.C contains all event handling functions
*
* Power Programming Tools for Advanced Interface Design.
* written by: Jim Everingham May 25, 1990
* last Modification: January 23, 1991
*/

#include /* include standard C header files */
#include
#include
#include

#include "smp.h" /* Screen Manager window and menu header file */
#include "smpkey.h" /* Screen Manager keyboard support */
#include "smpdata.h" /* Screen Manager data entry support */
#include "smpmouse.h" /* Screen Manager mouse support */

#include "smpdemo.h" /* text screens and function prototypes */

/* event handling function for the file viewer */

SMP_HANDLER fileViewHandler ( SMP_EVENT event )
{

static int /* button positions and their keyboard equivelents */
position[ 5 ][ 3 ] = {

1, 13, K_PGDN, /* Page Down */
17, 33, K_PGUP, /* Page Up */
37, 43, K_HOME, /* Home - Beginning of File */
47, 56, K_END, /* End - End of File */
60, 67, K_ESC /* Esc - Exit view window */

};

int i;

switch ( event->type ) { /* process event type */

case SMP_LPRESS: /* left button press */

/* check if the mouse was pressed on the left or right arrow */
if ( event->y == ( w_height ( event->window ) - 2 ) )

if ( event->x > 0 && event->x < 4 )
k_playkey ( K_LEFT );

else if ( ( event->x > ( w_width ( event->window ) - 6 ) ) &&
( event->x < ( w_width ( event->window ) - 2 ) ) )
k_playkey ( K_RIGHT );

/* if the button was pressed on the button row */
if ( event->y != fileButtonRow )
break;

/* check button coordinates and play the appropriate key value */
for ( i = 0; i < 5; i++ )

if ( ( event->x >= position[ i ][ 0 ] ) &&
( event->x <= position[ i ][ 1 ] ) ) {

w_recolor ( event->window,
position[ i ][ 0 ], event->y,
position[ i ][ 1 ] - position[ i ][ 0 ] + 1,
attr(BLACK,LIGHTGREY) );

k_playkey ( (SMP_KEY) position[ i ][ 2 ] );
break;

}


break;

case SMP_RPRESS: /* Esc was pressed */

k_playkey ( K_ESC ); /* simulate the Esc key */
break;

}
}


SMP_KEY okButton ( int x, int y )
{
SMP_HANDLE okWindow; /* window handle for ok Button */
SMP_KEY keyStroke; /* keyboard value */
static char * okMsg = "< Ok >"; /* Ok button message */

w_def (
okWindow = w_nexthandle ( ), /* create a window handle */
x, y, /* upper left handle corner */
x + 4 + strlen ( okMsg ), y, /* lower right hand corner */
attr(WHITE,MAGENTA), /* inner color */
attr(YELLOW,MAGENTA), /* frame color */
0, /* borderless */
INSTANT ); /* open instantly */

/* assign event handling function to press button window */
mm_setevent ( okWindow, okHandler );

w_center ( okWindow, okMsg ); /* center ok Button message */
keyStroke = k_read ( ); /* read keyboard */
w_remove ( okWindow ); /* remove window */
return ( keyStroke ); /* return pressed key */

}

/* event handling function for the Ok button */

SMP_HANDLER okHandler ( SMP_EVENT event )
{
mm_coff ( ); /* disable mouse cursor */

switch ( event->type ) { /* process event type */

case SMP_INIT: /* init event is called when assigned */

w_open ( event->window );
break;

case SMP_LPRESS: /* left button press */

k_playkey ( K_ENTER );
break;

}

mm_con ( ); /* enable mouse cursor */
}

/* event handler for the Scroll, Resize, Move demo */

SMP_HANDLER scrollHandler ( SMP_EVENT event )
{
/* if a button was pressed, play an Esc key */
if ( event->type == SMP_LPRESS || event->type == SMP_RPRESS )
k_playkey ( K_ESC );
}

/* event handling function for the animation box */

SMP_HANDLER animateHandler ( SMP_EVENT event )
{
mm_coff ( ); /* disable mouse cursor */

switch ( event->type ) { /* process event type */

case SMP_LPRESS: /* left button press */

if ( event->x < 13 ) { /* if the Esc button was pressed... */

/* recolor mouse button */
w_recolor ( event->window, 1, 0, 12, attr(BLACK,LIGHTGREY) );
k_playkey ( K_ESC );
delay ( 100 ); /* dramatic pause */

}
else if ( event->x < 31 ) { /* if the '+' button was pressed */

/* recolor mouse button */
w_recolor ( event->window, 15, 0, 14, attr(BLACK,LIGHTGREY) );
delay ( 100 ); /* pause */
/* reset original button color */
w_recolor ( event->window, 15, 0, 14, attr(LIGHTCYAN,BLUE) );
/* simulate the '+' key */
k_playkey ( (SMP_KEY) '+' );

}

else { /* if the '-' button was clicked on */


/* recolor mouse button */
w_recolor ( event->window, 31, 0, 15, attr(BLACK,LIGHTGREY) );
delay ( 100 ); /* pause */
/* reset original button color */
w_recolor ( event->window, 31, 0, 15, attr(LIGHTCYAN,BLUE) );
k_playkey ( (SMP_KEY) '-' );

}

break;

case SMP_RPRESS: /* if the right button was pressed, play Esc key */

k_playkey ( K_ESC );
break;

}

mm_con ( ); /* enable mouse cursor */
}

/* event handling function for the vga slider color mixer and */
/* color selector windows */

SMP_HANDLER sliderHandler ( SMP_EVENT event )
{
static int button = 0; /* set to TRUE when pressed, FALSE when released */

switch ( event->type ) { /* process event type */

case SMP_LRELEASE: /* set button to FALSE if button is release */
case SMP_LEAVEWIN: /* or mouse leaves the window */

button = 0; /* button to FALSE */
break;

case SMP_POS: /* mouse position has changed */

if ( !button ) /* if the button is not depressed, exit */
break;

case SMP_LPRESS: /* if the left mouse button is pressed */

/* is this the window of the color selector? */
if ( event->window == slideWindow )
if ( event->y <= 1 ) { /* is this the right row? */

if ( event->x < 2 ) /* is it a valid coordinate? */
break;

/* set the current color */
currentColor = ( event->x >> 1 ) - 1;
k_playkey ( 1 ); /* just keep thing rolling */

break;

}
else
break;

button = 1; /* set button press flag to TRUE */

if ( event->x > 30 ) /* must be mixer window, valid coordinate? */
event->x = 30;

switch ( event->y ) { /* row: 0-GREEN, 1-BLUE, 2-RED */

case 0:

/* set the green value for this color */
vga_set ( currentColor, _GREEN, event->x << 1 );
break;

case 1:

/* set the blue value for this color */
vga_set ( currentColor, _BLUE, event->x << 1 );
break;

case 2:

/* set the red value for this color */
vga_set ( currentColor, _RED, event->x << 1 );
break;

}

k_playkey ( 1 ); /* just keep processing... */

break;

case SMP_RPRESS: /* if the right button is pressed, simulate Esc */

k_playkey ( K_ESC ); /* play Esc key */
break;

}
}

/* this event handler is assigned to the copy window routine and simply exits */
/* when a key is pressed by simulating the Enter key */

SMP_HANDLER copyHandler ( SMP_EVENT event )
{

if ( event->type == SMP_LPRESS ||/* any button pressed? */
event->type == SMP_RPRESS )
k_playkey ( K_ENTER ); /* simulate Enter */
}

/* this event handler is assigned to the data entry routine to display help
* when the help key message is clicked on and exit when the Esc key messsage
* is clicked on
*/

SMP_HANDLER dataHandler ( SMP_EVENT event )
{
mm_coff ( ); /* disable the mouse cursor */

switch ( event->type ) { /* process event type */

case SMP_LPRESS: /* left button press event type */

/* the messages reside on the bottom row, if this is the right row ... */
if ( event->y == ( w_height ( event->window ) - 1 ) )

/* if the button press lies in the realm of the Help message ... */
if ( event->x >= 13 && event->x <= 22 )
k_playkey ( K_F1 ); /* simulate pressing of the F1 key */

/* if the button press lies in the realm of the Exit message ... */
else if ( event->x >= 23 && event->x <= 33 )
k_playkey ( K_ESC ); /* simulate pressingof the Esc key */

break;

}

mm_con ( ); /* enable the mouse cursor */
}


  3 Responses to “Category : C Source Code
Archive   : SMPDEMO2.ZIP
Filename : MOUSE.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/