home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / EVENTLIB.C < prev    next >
C/C++ Source or Header  |  1996-06-05  |  7KB  |  253 lines

  1. /*
  2.  *    イベント制御
  3.  *
  4.  *        Copyright T.Kobayashi    1994.6.26
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <assert.h>
  10.  
  11. #include "event.h"
  12. #include "graph.h"
  13. #include "input.h"
  14. #include "ml.h"
  15. #include "strclass.h"
  16.  
  17. #if 0
  18. static    char    *SysConstName[] = {
  19.     "ESC",
  20.     "BS",
  21.     "RET",
  22.     "LEFT_SWITCH",
  23.     "RIGHT_SWITCH",
  24.     "HELP",
  25.     NULL
  26. };
  27.  
  28. static    IntData        SysConst[] = {
  29.     { TYPE_INT,    0,        0x1b,            },
  30.     { TYPE_INT,    0,        0x08,            },
  31.     { TYPE_INT,    0,        0x0D,            },
  32.     { TYPE_INT,    0,        LEFT_SWITCH,    },
  33.     { TYPE_INT,    0,        RIGHT_SWITCH,    },
  34.     { TYPE_INT,    0,        0x8000 + 30,    },
  35. };
  36. #endif
  37. typedef struct {
  38.     char    *Name;
  39.     IntData    Data;
  40. }    ConstData;
  41.  
  42. static ConstData    SysConst[] = {
  43.     {"ESC",                    { TYPE_INT,    0,    0x1b,            }},
  44.     {"BS",                    { TYPE_INT,    0,    0x08,            }},
  45.     {"RET",                    { TYPE_INT,    0,    0x0D,            }},
  46.     {"LEFT_SWITCH",            { TYPE_INT,    0,    LEFT_SWITCH,    }},
  47.     {"RIGHT_SWITCH",        { TYPE_INT,    0,    RIGHT_SWITCH,    }},
  48.     {"HELP",                { TYPE_INT, 0,    KEY_HELP        }},
  49.     {"MOUSE_LEFT",            { TYPE_INT,    0,    LEFT_SWITCH,    }},
  50.     {"MOUSE_RIGHT",            { TYPE_INT,    0,    RIGHT_SWITCH,    }},
  51.     {"KEY_TAB",                { TYPE_INT, 0,     0x09,    }},
  52.     {"KEY_ESC",                { TYPE_INT, 0,     0x1b,    }},
  53.     {"KEY_BS",                { TYPE_INT, 0,     0x08,    }},
  54.     {"KEY_RET",                { TYPE_INT, 0,     0x0D,    }},
  55.     {"KEY_F1",                { TYPE_INT, 0,     KEY_F1,        }},
  56.     {"KEY_F2",                { TYPE_INT, 0,     KEY_F2,        }},
  57.     {"KEY_F3",                { TYPE_INT, 0,     KEY_F3,        }},
  58.     {"KEY_F4",                { TYPE_INT, 0,     KEY_F4,        }},
  59.     {"KEY_F5",                { TYPE_INT, 0,     KEY_F5,        }},
  60.     {"KEY_F6",                { TYPE_INT, 0,     KEY_F6,        }},
  61.     {"KEY_F7",                { TYPE_INT, 0,     KEY_F7,        }},
  62.     {"KEY_F8",                { TYPE_INT, 0,     KEY_F8,        }},
  63.     {"KEY_F9",                { TYPE_INT, 0,     KEY_F9,        }},
  64.     {"KEY_F10",                { TYPE_INT, 0,     KEY_F10,    }},
  65.     {"KEY_F11",                { TYPE_INT, 0,     KEY_F11,    }},
  66.     {"KEY_F12",                { TYPE_INT, 0,     KEY_F12,    }},
  67.     {"KEY_F13",                { TYPE_INT, 0,     KEY_F13,    }},
  68.     {"KEY_F14",                { TYPE_INT, 0,     KEY_F14,    }},
  69.     {"KEY_F15",                { TYPE_INT, 0,     KEY_F15,    }},
  70.     {"KEY_ROLLUP",            { TYPE_INT, 0,     KEY_ROLLUP,    }},
  71.     {"KEY_ROLLDOWN",        { TYPE_INT, 0,     KEY_ROLLDOWN,    }},
  72.     {"KEY_INS",                { TYPE_INT, 0,     KEY_INS,    }},
  73.     {"KEY_DEL",                { TYPE_INT, 0,     KEY_DEL,    }},
  74.     {"KEY_UP",                { TYPE_INT, 0,     KEY_UP,        }},
  75.     {"KEY_LEFT",            { TYPE_INT, 0,     KEY_LEFT,    }},
  76.     {"KEY_RIGHT",            { TYPE_INT, 0,     KEY_RIGHT,    }},
  77.     {"KEY_DOWN",            { TYPE_INT, 0,     KEY_DOWN,    }},
  78.     {"KEY_CLR",                { TYPE_INT, 0,     KEY_CLR,    }},
  79.     {"KEY_HELP",            { TYPE_INT, 0,     KEY_HELP,    }},
  80.     {"KEY_HOME",            { TYPE_INT, 0,     KEY_HOME,    }},
  81.     {"KEY_UNDO",            { TYPE_INT, 0,     KEY_UNDO,    }},
  82.     {"KEY_NUMPAD_0",        { TYPE_INT, 0,     KEY_NUMPAD_0,    }},
  83.     {"KEY_NUMPAD_1",        { TYPE_INT, 0,     KEY_NUMPAD_1,    }},
  84.     {"KEY_NUMPAD_2",        { TYPE_INT, 0,     KEY_NUMPAD_2,    }},
  85.     {"KEY_NUMPAD_3",        { TYPE_INT, 0,     KEY_NUMPAD_3,    }},
  86.     {"KEY_NUMPAD_4",        { TYPE_INT, 0,     KEY_NUMPAD_4,    }},
  87.     {"KEY_NUMPAD_5",        { TYPE_INT, 0,     KEY_NUMPAD_5,    }},
  88.     {"KEY_NUMPAD_6",        { TYPE_INT, 0,     KEY_NUMPAD_6,    }},
  89.     {"KEY_NUMPAD_7",        { TYPE_INT, 0,     KEY_NUMPAD_7,    }},
  90.     {"KEY_NUMPAD_8",        { TYPE_INT, 0,     KEY_NUMPAD_8,    }},
  91.     {"KEY_NUMPAD_9",        { TYPE_INT, 0,     KEY_NUMPAD_9,    }},
  92.     {"KEY_NUMPAD_SLASH",    { TYPE_INT, 0,     KEY_NUMPAD_SLASH,    }},
  93.     {"KEY_NUMPAD_ASTERISK",    { TYPE_INT, 0,     KEY_NUMPAD_ASTERISK,    }},
  94.     {"KEY_NUMPAD_MINUS",    { TYPE_INT, 0,     KEY_NUMPAD_MINUS,    }},
  95.     {"KEY_NUMPAD_PLUS",        { TYPE_INT, 0,     KEY_NUMPAD_PLUS,    }},
  96.     {"KEY_NUMPAD_EQUAL",    { TYPE_INT, 0,     KEY_NUMPAD_EQUAL,    }},
  97.     {"KEY_NUMPAD_ENTER",    { TYPE_INT, 0,     KEY_NUMPAD_ENTER,    }},
  98.     {"KEY_NUMPAD_COMMA",    { TYPE_INT, 0,     KEY_NUMPAD_COMMA,    }},
  99.     {"KEY_NUMPAD_PERIOD",    { TYPE_INT, 0,     KEY_NUMPAD_PERIOD,    }},
  100. };
  101.  
  102.  
  103. static    int        GetMouseMove( int, int, DataStruct* );
  104. static    int        GetKeyCode( int, int, DataStruct* );
  105. static    int        GetShiftStat( int, int, DataStruct* );
  106. static    int        FuncFlushKey( int, int, DataStruct* );
  107. static    int        KeyEvent( int, int, DataStruct* );
  108. static    int        InputEvent( int, int, DataStruct* );
  109. static    int        FuncCallKeyEvent( int, int, DataStruct* );
  110.  
  111. void    EventLibInit()
  112. {
  113.     int        i ;
  114. #if 0
  115.     for( i = 0 ; SysConstName[i] != NULL ; i++ )
  116.     {
  117.         NewConst( SysConstName[i], (DataStruct*)&SysConst[i] );
  118.     }
  119. #endif
  120.     for( i = 0; i < sizeof(SysConst) / sizeof(SysConst[0]); i++) {
  121.         NewConst( SysConst[i].Name, (DataStruct*)&(SysConst[i].Data));
  122.     }
  123.  
  124.     NewFunction( 0, "MouseMove", GetMouseMove );
  125.     NewFunction( 0, "KeyCode", GetKeyCode );
  126.     NewFunction( 0, "ShiftStat", GetShiftStat );
  127.     NewFunction( 0, "FlushKey", FuncFlushKey );
  128.     NewFunction( 0, "KeyEvent", KeyEvent );
  129.     NewFunction( 0, "InputEvent", InputEvent );
  130.     NewFunction( 0, "CallKeyEvent", FuncCallKeyEvent);
  131. }
  132.  
  133. /*    マウスの移動フラグの読み出し    */
  134. static    int        GetMouseMove( ident, args, buf )
  135. int        ident ;
  136. int        args ;
  137. DataStruct    *buf ;
  138. {
  139.     ArgCheck( "MouseMove", args, buf, TYPE_NOASN );
  140.     StackPushBoolean( MouseMove );
  141.  
  142.     return RETURN_RETURN ;
  143. }
  144.  
  145. /*    キーの読み出し            */
  146. static    int        GetKeyCode( ident, args, buf )
  147. int        ident ;
  148. int        args ;
  149. DataStruct    *buf ;
  150. {
  151.     ArgCheck( "KeyCode", args, buf, TYPE_NOASN );
  152.     StackPushInt( KeyCode );
  153.  
  154.     return RETURN_RETURN ;
  155. }
  156.  
  157. /*    シフトキーの状態読み出し    */
  158. static    int        GetShiftStat( ident, args, buf )
  159. int        ident ;
  160. int        args ;
  161. DataStruct    *buf ;
  162. {
  163.     ArgCheck( "ShiftStat", args, buf, TYPE_NOASN );
  164.     StackPushInt( ShiftStat );
  165.  
  166.     return RETURN_RETURN ;
  167. }
  168.  
  169. /*    キーバッファのクリア    */
  170. static    int        FuncFlushKey( ident, args, buf )
  171. int        ident ;
  172. int        args ;
  173. DataStruct    *buf ;
  174. {
  175.     FlushKey();
  176.  
  177.     return RETURN_VOID ;
  178. }
  179.  
  180. /*    キーイベント関数の設定    */
  181. static    int        KeyEvent( ident, args, buf )
  182. int        ident ;
  183. int        args ;
  184. DataStruct    *buf ;
  185. {
  186.     StringClass    *str ;
  187.     if (args == 0 || buf[0].type != TYPE_FUNC) {
  188.         (*ExecError)( "型が不正です。(KeyEvent)" );
  189.     }
  190.     if (args == 2 && buf[0].type == TYPE_FUNC && ObjectCheck( &buf[1], ClassName("String"))) {
  191.         ArgCheck( "KeyEvent", args, buf, TYPE_FUNC, TYPE_OBJECT, TYPE_NOASN );
  192.  
  193.         if ( ObjectCheck( &buf[1], ClassName( "String" ) ) )
  194.         {
  195.             str = (StringClass*)buf[1].od.ptr ;
  196.             EventSetKey( buf[0].funcd.ident, str->str );
  197.         }
  198.         else
  199.             (*ExecError)( "型が不正です。(KeyEvent)" );
  200.     } else {
  201.         int    ident, i;
  202.         char    str[4] = "F00";
  203.         ident = buf[0].funcd.ident;
  204.         for (i = 1; i < args; ++i) {
  205.             if (buf[i].type != TYPE_INT) {
  206.                 (*ExecError)( "型が不正です。(KeyEvent)" );
  207.             }
  208.             if (0 <= buf[i].id.i && buf[i].id.i < 128) {
  209.                 str[2] = buf[i].id.i;
  210.                 EventSetKey( ident, str+2);
  211.             } else if (KEY_FUNC_START <= buf[i].id.i && buf[i].id.i < KEY_FUNC_END) {
  212.                 str[1] = (buf[i].id.i-KEY_FUNC_START)/10 + '0';
  213.                 str[2] = (buf[i].id.i-KEY_FUNC_START)%10 + '0';
  214.                 EventSetKey(ident, str);
  215.             }
  216.         }
  217.     }
  218.     return RETURN_VOID ;
  219. }
  220.  
  221.  
  222. /*    入力イベント関数の設定    */
  223. static    int        InputEvent( ident, args, buf )
  224. int        ident ;
  225. int        args ;
  226. DataStruct    *buf ;
  227. {
  228.     ArgCheck( "InputEvent", args, buf, TYPE_FUNC, TYPE_NOASN );
  229.     EventSetInput( buf[0].funcd.ident );
  230.  
  231.     return RETURN_VOID ;
  232. }
  233.  
  234. /*    */
  235. static    int        FuncCallKeyEvent( ident, args, buf )
  236. int        ident ;
  237. int        args ;
  238. DataStruct    *buf ;
  239. {
  240.     StringClass    *str ;
  241.     if (args > 0) {
  242.         if ( ObjectCheck( &buf[0], ClassName( "String" ) ) ) {
  243.             str = buf[0].od.ptr;
  244.             KeyCode = str->str[0];
  245.         } else {
  246.             ArgCheck( "InputEvent", args, buf, TYPE_INT, TYPE_NOASN );
  247.             KeyCode = buf[0].id.i;
  248.         }
  249.     }
  250.     StackPushBoolean(CallKeyEvent());
  251.     return RETURN_RETURN ;
  252. }
  253.