home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dmenu1.zip
/
DM10SRC.ZIP
/
DOUGMENU.C
next >
Wrap
Text File
|
1991-10-15
|
8KB
|
346 lines
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "malloc.h"
#include "menu.h"
#include "setup.c"
#include "parse.c"
#include "draw.c"
#include "input.c"
#include "execute.c"
/***************************************************************************/
void Critical_Error(error,error_string)
char error_string[];
error_type error;
{
Clean_Up();
printf("\nA critical error has occured.");
switch(error){
case MEMORY:
printf("\nOut of memory durring %s.\n",error_string);
break;
case FILE_OPEN:
printf("\nUnable to open file %s\n",current_menu);
break;
case SYNTAX:
printf("\n%s (%u) Syntax Error.\n",current_file,line_count);
break;
case VALUE:
printf("\n%s (%u) Illegal or Missing Value.\n",current_file,line_count);
break;
case POSITION:
printf("\n%s (%u) Unexpected Structure.\n",current_file,line_count);
break;
case DISPLAY:
printf("\nUnable to display first menu.\n");
break;
case ENVIROMENT:
printf("\n%s\n",error_string);
break;
}
exit(1);
}
/***************************************************************************/
void Last_Window_Globals(void)
{
win_index--;
current_menu = Win[win_index].menu;
current_item = Win[win_index].item;
top = Win[win_index].top;
bottom = Win[win_index].bottom;
left = Win[win_index].left;
right = Win[win_index].right;
width = Win[win_index].width;
height = Win[win_index].height;
}
/***************************************************************************/
boolean Windowfy_Menu(menu)
Menu *menu;
/* sets h,w,t,b,l,r, current_item and style */
/* sets nothing and returns NO if error */
{
if (menu == NULL){
current_item = Win[win_index].item;
return(NO);
}
if (win_index == MAX_RECURSION){
Error_Box("Only 10 windows can open at a time.","The next menu cannot be displayed.");
current_item = Win[win_index].item;
return(NO);
}
win_index++;
current_menu = menu;
current_item = Home_Item();
if (current_item == NULL){
Error_Box("Unable to display menu.","The menu has no options.");
Last_Window_Globals();
return(NO);
}
height = current_menu->number_of_items +3;
width = current_menu->longest_title +3;
if (height > (byte)(max_screen_y-4) || width >= max_screen_x){
Error_Box("Unable to display menu.","The menu is too large.");
Last_Window_Globals();
return(NO);
}
left = current_menu->offset_x;
top = current_menu->offset_y;
if (left == CENTER)
left = (byte)( (max_screen_x - width)/2 );
if (top == CENTER)
top = (byte)( (max_screen_y - height)/2 +1);
else if (cascade && current_menu->offset_x == Win[0].left &&
current_menu->offset_y == Win[0].top){
left = (byte) ( Win[0].left + (win_index) * cascade_x );
top = (byte) ( Win[0].top + (win_index) * cascade_y );
}
if (top <3)
top = 3;
right = left + width;
if (right >= (byte)(max_screen_x-1) ){
right = (byte)(max_screen_x-2);
left = (byte)(right - width);
}
bottom = top + height;
if (bottom > (byte)(max_screen_y-1) ){
bottom = (byte)(max_screen_y-1);
top = (byte)(bottom - height);
}
Win[win_index].menu = current_menu;
Win[win_index].item = current_item;
Win[win_index].top = top;
Win[win_index].left = left;
Win[win_index].right = right;
Win[win_index].width = width;
Win[win_index].bottom = bottom;
Win[win_index].height = height;
if (win_index) Win[win_index].storage = Store_Screen(left,right,top,bottom);
/* force mouse reset */
last_x = 0;
return(YES);
}
/***************************************************************************/
Item *Number_To_Item(number)
byte number;
{
Item *item = current_item;
if (number > current_menu->number_of_items)
return ( current_item );
while (item->item_number < number)
item = item->next_item;
while (item->item_number > number)
item = item->last_item;
return(item);
}
/***************************************************************************/
Item *Home_Item()
{
Item *item = current_menu->first_item;
while (item->first_line == NULL){
item = item->next_item;
/* if no selectable items */
if (item == NULL)
return(NULL);
}
return(item);
}
/***************************************************************************/
Item *End_Item()
{
Item *item = current_item;
while (item->next_item != NULL)
item = item->next_item;
while (item->first_line == NULL)
item = item->last_item;
return(item);
}
/***************************************************************************/
Item *Move_Up()
{
Item *item = current_item->last_item;
if (item == NULL)
return( End_Item() );
while (item->first_line == NULL){
if (item->last_item == NULL)
return( End_Item() );
item = item->last_item;
}
return(item);
}
/***************************************************************************/
Item *Move_Down()
{
Item *item = current_item->next_item;
if (item == NULL)
return( Home_Item () );
while (item->first_line == NULL){
if (item->next_item == NULL)
return( Home_Item () );
item = item->next_item;
}
return(item);
}
/***************************************************************************/
void Remove_Window(number_to_remove)
byte number_to_remove;
{
if (shadow) Remove_Shadow(left,right,top,bottom);
while ( number_to_remove-- > 0){
Restore_Screen(Win[win_index].storage,left,right,top,bottom);
Last_Window_Globals();
}
Display_Menu(NULL);
Select(current_item);
/* force mouse refresh */
last_x = 0;
}
/***************************************************************************/
Menu *Find_Menu(menu_to_find)
char menu_to_find[];
{
Menu *menu_to_check = first_menu;
menu_to_find++; /* chop off '%' */
while ( strcmpi(menu_to_find,menu_to_check->title) )
if ((menu_to_check = menu_to_check->next_menu) == NULL){
Error_Box("Unable to locate menu labeled:",menu_to_find);
return(NULL);
}
return (menu_to_check);
}
/**************************************************************************/
void Execute_Item()
{
Display_Menu( Win[win_index].item );
if (shadow) Remove_Shadow(left,right,top,bottom);
if ( current_item->first_line->text_line[0] == '%')
Windowfy_Menu( Find_Menu( current_item->first_line->text_line ) );
else
if ( Compare(current_item->first_line->text_line,"#display") )
Display_Item_Text();
else
Make_Batch();
Display_Menu( NULL );
Select( current_item );
}
/***************************************************************************/
void main( argc, argv )
int argc;
char *argv[];
{
Break_Off();
Display_Title_Screen();
Get_Video_Info();
Set_Up_Enviroment();
Set_Up_Mouse();
Parse( argv[1] );
Set_Up_Screen();
Hide_Cursor();
/* clear key board buffer */
while (kbhit())
getch();
for (;;){
Wait_For_Event();
switch ( event.action ){
case GOTO_ITEM:
Select( Number_To_Item( event.data ) );
break;
case MOVE_UP:
Select(Move_Up());
break;
case MOVE_DOWN:
Select(Move_Down());
break;
case GOTO_END:
Select(End_Item());
break;
case GOTO_TOP:
Select(Home_Item());
break;
case ESCAPE:
if (win_index == 0){
if (exitable)
Exit_Query();
}
else
Remove_Window(event.data);
break;
case DO_ITEM:
Win[win_index].event = DO_ITEM;
Execute_Item();
break;
case FUNCTION_KEY:
current_item = function_key[ event.data ];
Win[win_index].event = FUNCTION_KEY+current_item->item_number;
Execute_Item();
break;
}
}
}