home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
MENULIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-08-01
|
14KB
|
530 lines
/*
* メニュー表示
*
* Copyright Koabayashi 1994.7.9
*/
#include <stdio.h>
#include <string.h>
#include "ml.h"
#include "strclass.h"
#include "menu.h"
static ExecData SysConst[] = {
{ TYPE_FUNC, 0, -1, },
{ TYPE_INT, 0, MENU_CHECK, },
{ TYPE_INT, 0, MENU_DISABLE, },
{ TYPE_INT, 0, 0, },
};
int MenuClassID ;
static int SetMenuData( int, int, DataStruct* );
static int SetMenuPosition( int, int, DataStruct* );
static int GetMenuPosition( int, int, DataStruct* );
static int FuncInsertMenu( int, int, DataStruct* );
static int FuncMenuItems( int, int, DataStruct* );
static int FuncUpdateTitleBar( int, int, DataStruct* );
static int FuncUpdateAttribute( int, int, DataStruct* );
static int FuncUpdateObject( int, int, DataStruct* );
static int FuncPushMenu( int, int, DataStruct* );
static int FuncPopMenu( int, int, DataStruct* );
static int FuncMenuTitle( int, int, DataStruct* );
static int FuncMenuItem( int, int, DataStruct* );
static int FuncMenuFunction( int, int, DataStruct* );
static int FuncMenuQuery( int, int, DataStruct* );
static int FuncMenuEnable( int, int, DataStruct* );
static int FuncCurrentMenuItem( int, int, DataStruct* );
static int FuncCurrentMenuFunction( int, int, DataStruct* );
static int FuncCurrentMenuEnable( int, int, DataStruct* );
/* 初期化 */
void MenuLibInit()
{
MenuClassID = NewClass( "Menu", 0 );
NewFunction( MenuClassID, "MenuPosition", SetMenuPosition );
NewFunction( 0, "MenuPosition", GetMenuPosition );
NewFunction( 0, "Menu", SetMenuData );
NewFunction( MenuClassID, "InsertMenu", FuncInsertMenu);
NewFunction( MenuClassID, "MenuItems", FuncMenuItems);
NewFunction( 0, "UpdateTitleBar", FuncUpdateTitleBar );
NewFunction( 0, "UpdateAttribute", FuncUpdateAttribute );
NewFunction( 0, "UpdateObject", FuncUpdateObject );
NewFunction( 0, "PushMenu", FuncPushMenu );
NewFunction( 0, "PopMenu", FuncPopMenu );
NewFunction( MenuClassID, "MenuTitle", FuncMenuTitle);
NewFunction( MenuClassID, "MenuItem", FuncMenuItem);
NewFunction( MenuClassID, "MenuFunction", FuncMenuFunction);
NewFunction( MenuClassID, "MenuQuery", FuncMenuQuery);
NewFunction( MenuClassID, "MenuEnable", FuncMenuEnable);
NewFunction( ClassName("String"), "MenuItem", FuncCurrentMenuItem);
NewFunction( 0, "MenuFunction", FuncCurrentMenuFunction);
NewFunction( 0, "MenuEnable", FuncCurrentMenuEnable);
NewConst( "SEPARATE_MENU", (DataStruct*)&SysConst[0] );
NewConst( "MENU_CHECK", (DataStruct*)&SysConst[1] );
NewConst( "MENU_DISABLE", (DataStruct*)&SysConst[2] );
NewConst( "MENU_NOCHECK", (DataStruct*)&SysConst[3] );
NewConst( "MENU_ENABLE", (DataStruct*)&SysConst[3] );
}
/* メニューオブジェクトの設定 */
static int SetMenuData( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int i, j ;
MenuClass *menu ;
menu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
/* タイトル名 */
if ( args == 0 )
ExecError( "引数の数が違います。(Menu)" );
if ( buf[0].type != TYPE_OBJECT || ObjectCheck( &buf[0], ClassName( "String" ) ) == FALSE )
ExecError( "%d番目の引数の型が違います。(Menu)", 1 );
strncpy( menu->title, ((StringClass*)buf[0].od.ptr)->str, TITLE_LEN );
menu->title[TITLE_LEN] = '\0' ;
#ifndef WINDOWS
i = strlen(menu->title);
if (i > 5 && menu->title[i-1] == ')' && menu->title[i-3] == '&' && menu->title[i-4] == '(') {
menu->title[i-4] = '\0';
}
#endif
/* 項目数 */
/* 項目名 */
buf = buf + 1 ;
args -- ;
for( i = j = 0 ; i + 1 < args ; i += 2, j++)
{
if ( buf[i].type != TYPE_OBJECT ||
ObjectCheck( &buf[i], ClassName( "String" ) ) == FALSE )
{
ExecError( "%d番目の引数の型が違います。(Menu)", i+2 );
}
strncpy( menu->item[j], ((StringClass*)buf[i].od.ptr)->str, ITEM_LEN );
menu->item[j][ITEM_LEN] = '\0' ;
if ( buf[i+1].type != TYPE_FUNC )
ExecError( "%d番目の引数の型が違います。(Menu)", i+3 );
menu->exec[j] = buf[i+1].funcd.ident ;
if (i + 2 < args && buf[i+2].type == TYPE_FUNC) {
menu->query[j] = buf[i+2].funcd.ident;
i++;
} else {
menu->query[j] = -1;
}
if (i + 2 < args && buf[i+2].type == TYPE_INT) {
menu->check[j] = buf[i+2].id.i;
i++;
} else {
menu->check[j] = 0;
}
}
menu->items = j;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)menu ;
return RETURN_RETURN ;
}
/* メニューの設定 */
static int SetMenuPosition( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
ArgCheck( "MenuPosition", args, buf, TYPE_OBJECT, TYPE_INT, TYPE_NOASN );
n = buf[1].id.i ;
if ( n < 0 || MAX_MENU <= n )
{
ExecError( "2番目の引数の値が不正です。(SetPosition)" );
}
SetMenu( (MenuClass*)buf[0].od.ptr, n );
DrawTitleBar();
return RETURN_VOID ;
}
/* メニューの設定 */
static int GetMenuPosition( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
MenuClass *menu;
ArgCheck( "MenuPosition", args, buf, TYPE_INT, TYPE_NOASN );
n = buf[0].id.i;
if (n < 0 || n >= MAX_MENU || Menu[n] == NULL) {
StackPushBoolean(FALSE);
} else {
menu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
*menu = *(Menu[n]);
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)menu ;
}
return RETURN_RETURN ;
}
static int FuncUpdateTitleBar( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
DrawTitleBar();
return RETURN_VOID ;
}
static int FuncUpdateAttribute( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
DrawAttrSelect();
return RETURN_VOID ;
}
static int FuncUpdateObject( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
DrawObjSelect();
return RETURN_VOID ;
}
static int FuncPushMenu( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if ( MenuStackPtr < MENU_LEVELS - 1 )
PushMenu();
else
ExecError( "メニューのレベルが深すぎます(PushMenu)" );
return RETURN_VOID ;
}
static int FuncPopMenu( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
#if 0
if ( MenuStackPtr > 0 )
{
PopMenu();
DrawTitleBar();
}
else
ExecError( "メニューのレベルは最上位です(PopMenu)" );
return RETURN_VOID ;
#else
if (MenuStackPtr > 0) {
PopMenu();
DrawTitleBar();
StackPushBoolean( TRUE );
} else {
StackPushBoolean( FALSE );
}
return RETURN_RETURN;
#endif
}
static int FuncMenuItems( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int i, j;
MenuClass *menu;
StringClass *p;
menu = (MenuClass*)(buf[0].od.ptr);
StackPushInt(menu->items);
return RETURN_RETURN;
}
static int FuncInsertMenu( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int i, j;
MenuClass *omenu, *menu;
StringClass *p;
omenu = (MenuClass*)(buf[0].od.ptr);
if (buf[1].type != TYPE_INT || args < 4) {
ExecError( "引数の型が異なります(InsertMenu)" );
}
menu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
*menu = *omenu;
j = buf[1].id.i;
if (j < 0 || j >= menu->items || menu->items >= MAX_ITEM-1) {
ExecError( "引数の範囲が無効です(InsertMenu)" );
}
for (i = menu->items; i > j; --i) {
strcpy(menu->item[i], menu->item[i-1]);
menu->exec[i] = menu->exec[i-1];
menu->query[i] = menu->query[i-1];
menu->check[i] = menu->check[i-1];
}
menu->items++;
if (buf[2].type != TYPE_OBJECT ||
ObjectCheck( &buf[2], ClassName( "String" ) ) == FALSE )
{
ExecError( "%d番目の引数の型が違います。(Menu)", 2 );
}
strncpy( menu->item[j], ((StringClass*)buf[2].od.ptr)->str, ITEM_LEN );
menu->item[j][ITEM_LEN] = '\0' ;
if ( buf[3].type != TYPE_FUNC )
ExecError( "%d番目の引数の型が違います。(Menu)", 3 );
menu->exec[j] = buf[3].funcd.ident ;
i = 4;
if (i < args && buf[i].type == TYPE_FUNC) {
menu->query[j] = buf[i].funcd.ident;
i++;
} else {
menu->query[j] = -1;
}
if (i < args && buf[i].type == TYPE_INT) {
menu->check[j] = buf[i].id.i;
i++;
} else {
menu->check[j] = 0;
}
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)menu ;
return RETURN_RETURN;
}
static int FuncMenuTitle( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
MenuClass *menu, *nmenu;
StringClass *p;
menu = (MenuClass*)(buf[0].od.ptr);
if (args == 1) {
p = StringAlloc(strlen(menu->title));
strcpy(p->str, menu->title);
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)p ;
} else {
ArgCheck( "MenuTitle", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
if (ObjectCheck( &buf[1], ClassName( "String" ) ) == FALSE ) {
ExecError( "引数の型が異なります(MenuTitle)" );
}
nmenu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
p = (StringClass*)buf[1].od.ptr;
*nmenu = *menu;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)nmenu ;
strncpy( nmenu->title, p->str, TITLE_LEN );
nmenu->title[TITLE_LEN] = '\0' ;
}
return RETURN_RETURN;
}
static int FuncMenuItem( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n;
MenuClass *menu, *nmenu;
StringClass *p;
menu = (MenuClass*)(buf[0].od.ptr);
if (args < 2 || buf[1].type != TYPE_INT)
ExecError( "引数の型が異なります(MenuItem)" );
n = buf[1].id.i;
if (n < 0 || n >= menu->items) {
StackPushBoolean(FALSE);
} else if (args == 2) {
p = StringAlloc(strlen(menu->item[n]));
strcpy(p->str, menu->item[n]);
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)p ;
} else {
if (ObjectCheck( &buf[2], ClassName( "String" ) ) == FALSE ) {
ExecError( "引数の型が異なります(MenuItem)" );
}
nmenu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
*nmenu = *menu;
strncpy( nmenu->item[n], ((StringClass*)buf[2].od.ptr)->str, ITEM_LEN );
nmenu->item[n][ITEM_LEN] = '\0';
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)nmenu ;
}
return RETURN_RETURN;
}
static int FuncMenuFunction( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n;
MenuClass *menu, *nmenu;
menu = (MenuClass*)(buf[0].od.ptr);
if (args < 2 || buf[1].type != TYPE_INT)
ExecError( "引数の型が異なります(MenuFunction)" );
n = buf[1].id.i;
if (n < 0 || n >= menu->items) {
StackPushBoolean(FALSE);
} else if (args == 2) {
buf = StackAlloc( 1 );
buf->type = TYPE_FUNC ;
buf->funcd.ident = menu->exec[n];
} else {
if (buf[2].type != TYPE_FUNC) {
ExecError( "引数の型が異なります(MenuFunction)" );
}
nmenu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
*nmenu = *menu;
nmenu->exec[n] = buf[2].funcd.ident;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)nmenu ;
}
return RETURN_RETURN;
}
static int FuncMenuQuery( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n;
MenuClass *menu, *nmenu;
menu = (MenuClass*)(buf[0].od.ptr);
if (args < 2 || buf[1].type != TYPE_INT)
ExecError( "引数の型が異なります(MenuFunction)" );
n = buf[1].id.i;
if (n < 0 || n >= menu->items) {
StackPushBoolean(FALSE);
} else if (args == 2) {
buf = StackAlloc( 1 );
buf->type = TYPE_FUNC ;
buf->funcd.ident = menu->query[n];
} else {
if (buf[2].type != TYPE_FUNC) {
ExecError( "引数の型が異なります(MenuFunction)" );
}
nmenu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
*nmenu = *menu;
nmenu->query[n] = buf[2].funcd.ident;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)nmenu ;
}
return RETURN_RETURN;
}
static int FuncMenuEnable( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n;
MenuClass *menu, *nmenu;
menu = (MenuClass*)(buf[0].od.ptr);
if (args < 2 || buf[1].type != TYPE_INT)
ExecError( "引数の型が異なります(MenuCheck)" );
n = buf[1].id.i;
if (n < 0 || n >= menu->items) {
StackPushBoolean(FALSE);
} else if (args == 2) {
buf = StackAlloc( 1 );
buf->type = TYPE_INT ;
buf->funcd.ident = menu->check[n];
} else {
if (buf[2].type != TYPE_INT) {
ExecError( "引数の型が異なります(MenuCheck)" );
}
nmenu = (MenuClass*)ObjectAlloc( sizeof( MenuClass ), MenuClassID );
*nmenu = *menu;
nmenu->check[n] = buf[2].id.i;
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)nmenu ;
}
return RETURN_RETURN;
}
static int FuncCurrentMenuItem( int ident, int args, DataStruct *buf )
{
if (args == 0 && CurrentX >= 0 && CurrentY >= 0) {
StringClass *p = StringAlloc(strlen(Menu[CurrentX]->item[CurrentY]));
strcpy(p->str, Menu[CurrentX]->item[CurrentY]);
buf = StackAlloc( 1 );
buf->type = TYPE_OBJECT ;
buf->od.ptr = (Object*)p ;
return RETURN_RETURN;
} else {
ArgCheck( "MenuItem", args, buf, TYPE_OBJECT, TYPE_NOASN );
CurrentMenuItem(((StringClass*)buf[0].od.ptr)->str);
return RETURN_VOID;
}
}
static int FuncCurrentMenuFunction( int ident, int args, DataStruct *buf )
{
if (args == 0 && CurrentX >= 0 && CurrentY >= 0) {
buf = StackAlloc( 1 );
buf->type = TYPE_FUNC ;
buf->funcd.ident = Menu[CurrentX]->exec[CurrentY];
return RETURN_RETURN;
} else {
ArgCheck( "MenuFunction", args, buf, TYPE_FUNC, TYPE_NOASN );
CurrentMenuFunction(buf[0].funcd.ident);
return RETURN_VOID;
}
}
static int FuncCurrentMenuEnable( int ident, int args, DataStruct *buf )
{
if (args == 0 && CurrentX >= 0 && CurrentY >= 0) {
StackPushInt(Menu[CurrentX]->check[CurrentY]);
return RETURN_RETURN;
} else {
ArgCheck( "MenuEnable", args, buf, TYPE_INT, TYPE_NOASN );
CurrentMenuEnable(buf[0].id.i);
return RETURN_VOID;
}
}