home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / conapi.zip / TAU / INCLUDE / OS2 / bsecon.h < prev    next >
C/C++ Source or Header  |  2000-02-11  |  13KB  |  397 lines

  1. /*
  2.  *    ***********************************************************************
  3.  *                            32-bit Unicode Console API
  4.  *    (c) Copyright 1991-2000 Jonathan de Boyne Pollard. All Rights reserved.
  5.  *    ***********************************************************************
  6.  *
  7.  * OS/2 base include for Console API.
  8.  *
  9.  */
  10. #if defined(__IBMC__)
  11.    #pragma checkout( suspend )
  12.    #ifndef __CHKHDR__
  13.       #pragma checkout( suspend )
  14.    #endif
  15.    #pragma checkout( resume )
  16. #elif defined(__IBMCPP__)
  17.    #pragma info( none )
  18.    #ifndef __CHKHDR__
  19.       #pragma info( none )
  20.    #endif
  21.    #pragma info( restore )
  22. #endif
  23.  
  24. #if defined(__BORLANDC__)
  25. #    pragma option -a1
  26. #elif defined(__IBMCPP__)
  27. #    pragma pack(1)
  28. #endif
  29.  
  30. //#if !defined(___STDDEF_H_INCLUDED)
  31. //#include <_stddef.h>
  32. //#endif
  33.  
  34. #if defined(INCL_CONSOLE)
  35.  
  36. //
  37. //    Shift state flags
  38. //
  39. enum {
  40.     CON_KBD_LEFT_SHIFT_PRESSED        = 0x00000001 ,
  41.     CON_KBD_RIGHT_SHIFT_PRESSED     = 0x00000002 ,
  42.     CON_KBD_FAKE_SHIFT_PRESSED        = 0x00000004 ,
  43.     CON_KBD_LEFT_CTRL_PRESSED        = 0x00000010 ,
  44.     CON_KBD_RIGHT_CTRL_PRESSED        = 0x00000020 ,
  45.     CON_KBD_FAKE_CTRL_PRESSED        = 0x00000040 ,
  46.     CON_KBD_LEFT_ALT_PRESSED        = 0x00000100 ,
  47.     CON_KBD_RIGHT_ALT_PRESSED        = 0x00000200 ,
  48.     CON_KBD_LEFT_WIN_PRESSED        = 0x00001000 ,
  49.     CON_KBD_RIGHT_WIN_PRESSED        = 0x00002000 ,
  50.  
  51.     CON_KBD_ANY_SHIFT_PRESSED        = 0x00000007 ,
  52.     CON_KBD_ANY_CTRL_PRESSED        = 0x00000070 ,
  53.     CON_KBD_ANY_ALT_PRESSED         = 0x00000300 ,
  54.     CON_KBD_ANY_WIN_PRESSED         = 0x00003000 ,
  55.  
  56.     CON_KBD_SCROLL_LOCK_PRESSED     = 0x00010000 ,
  57.     CON_KBD_NUM_LOCK_PRESSED        = 0x00020000 ,
  58.     CON_KBD_CAPS_LOCK_PRESSED        = 0x00040000 ,
  59.  
  60.     CON_KBD_SCROLL_LOCK_ON            = 0x01000000 ,
  61.     CON_KBD_NUM_LOCK_ON             = 0x02000000 ,
  62.     CON_KBD_CAPS_LOCK_ON            = 0x04000000 ,
  63.     CON_KBD_INSERT_MODE_ON            = 0x08000000 ,
  64. } ;
  65.  
  66. //
  67. //    Flags for keyboard events
  68. //
  69. enum {
  70.     CON_KBD_EVENT_IS_RELEASE        = 0x0001 ,
  71.     CON_KBD_EVENT_HAS_VKEY            = 0x0002 ,
  72.     CON_KBD_EVENT_HAS_CHAR            = 0x0008 ,
  73.     CON_KBD_EVENT_HAS_SCAN            = 0x0004 ,
  74. } ;
  75.  
  76. //
  77. //    Keyboard virtual key numbers
  78. //
  79. enum {
  80.     CON_KBD_KEY_SYSRQ            = 1 ,
  81.     CON_KBD_KEY_PAUSE ,
  82.     CON_KBD_KEY_BREAK            = 3 ,
  83.     CON_KBD_KEY_PRINTSCREEN ,
  84.     CON_KBD_KEY_CAPSLOCK ,
  85.     CON_KBD_KEY_NUMLOCK ,
  86.     CON_KBD_KEY_SCRLLOCK ,
  87.     CON_KBD_KEY_BACKSPACE        = '\b' ,
  88.     CON_KBD_KEY_TAB             = '\t' ,
  89.     CON_KBD_KEY_ENTER ,
  90.     CON_KBD_KEY_RETURN            = '\r' ,
  91.     CON_KBD_KEY_BACKTAB ,
  92.     CON_KBD_KEY_CLEAR ,
  93.     CON_KBD_KEY_HOME ,
  94.     CON_KBD_KEY_END ,
  95.     CON_KBD_KEY_LEFT ,
  96.     CON_KBD_KEY_RIGHT ,
  97.     CON_KBD_KEY_DOWN ,
  98.     CON_KBD_KEY_UP ,
  99.     CON_KBD_KEY_PAGEDOWN ,
  100.     CON_KBD_KEY_PAGEUP ,
  101.     CON_KBD_KEY_INSERT ,
  102.     CON_KBD_KEY_DELETE ,
  103.     CON_KBD_KEY_MENU ,
  104.     CON_KBD_KEY_ESC             = 27 ,
  105.     CON_KBD_KEY_ALT ,
  106.     CON_KBD_KEY_CTRL ,
  107.     CON_KBD_KEY_SHIFT ,
  108.  
  109.     CON_KBD_KEY_SPACE            = ' ' ,
  110.     CON_KBD_KEY_ASTERISK        = '*' ,
  111.     CON_KBD_KEY_PLUS            = '+' ,
  112.     CON_KBD_KEY_MINUS            = '-' ,
  113.     CON_KBD_KEY_DECIMAL         = '.' ,
  114.     CON_KBD_KEY_DIVIDE            = '/' ,
  115.  
  116.     CON_KBD_KEY_0                = '0' ,
  117.     CON_KBD_KEY_1 ,
  118.     CON_KBD_KEY_2 ,
  119.     CON_KBD_KEY_3 ,
  120.     CON_KBD_KEY_4 ,
  121.     CON_KBD_KEY_5 ,
  122.     CON_KBD_KEY_6 ,
  123.     CON_KBD_KEY_7 ,
  124.     CON_KBD_KEY_8 ,
  125.     CON_KBD_KEY_9 ,
  126.     CON_KBD_KEY_PUNCT_COLON     = ':' , // [ ;: ]
  127.     CON_KBD_KEY_PUNCT_LESS        = '<' , // [ ;< ]
  128.     CON_KBD_KEY_PUNCT_EQUALS    = '=' , // [ =+ ]
  129.     CON_KBD_KEY_PUNCT_GREATER    = '>' , // [ .> ]
  130.     CON_KBD_KEY_PUNCT_QUERY     = '?' , // [ /? ]
  131.  
  132.     CON_KBD_KEY_PUNCT_AT            = '@' ,     // [ '@ ]
  133.     CON_KBD_KEY_A                    = 'A' ,
  134.     CON_KBD_KEY_B ,
  135.     CON_KBD_KEY_C ,
  136.     CON_KBD_KEY_D ,
  137.     CON_KBD_KEY_E ,
  138.     CON_KBD_KEY_F ,
  139.     CON_KBD_KEY_G ,
  140.     CON_KBD_KEY_H ,
  141.     CON_KBD_KEY_I ,
  142.     CON_KBD_KEY_J ,
  143.     CON_KBD_KEY_K ,
  144.     CON_KBD_KEY_L ,
  145.     CON_KBD_KEY_M ,
  146.     CON_KBD_KEY_N ,
  147.     CON_KBD_KEY_O ,
  148.     CON_KBD_KEY_P ,
  149.     CON_KBD_KEY_Q ,
  150.     CON_KBD_KEY_R ,
  151.     CON_KBD_KEY_S ,
  152.     CON_KBD_KEY_T ,
  153.     CON_KBD_KEY_U ,
  154.     CON_KBD_KEY_V ,
  155.     CON_KBD_KEY_W ,
  156.     CON_KBD_KEY_X ,
  157.     CON_KBD_KEY_Y ,
  158.     CON_KBD_KEY_Z ,
  159.     CON_KBD_KEY_PUNCT_LBRACKET        = '[' ,     // [ [{ ]
  160.     CON_KBD_KEY_PUNCT_VBAR            = '|' ,     // [ `| ]
  161.     CON_KBD_KEY_PUNCT_RBRACKET        = ']' ,     // [ }] ]
  162.     CON_KBD_KEY_PUNCT_BACKSLASH     = '\\' ,    // [ ▌\ ]
  163.     CON_KBD_KEY_PUNCT_TILDE         = '~' ,     // [ #~ ]
  164.     CON_KBD_KEY_PUNCT_UNDERSCORE    = '_' ,     // [ -_ ]
  165.  
  166.     CON_KBD_KEY_NUMPAD_0 = 96 ,
  167.     CON_KBD_KEY_NUMPAD_1 ,
  168.     CON_KBD_KEY_NUMPAD_2 ,
  169.     CON_KBD_KEY_NUMPAD_3 ,
  170.     CON_KBD_KEY_NUMPAD_4 ,
  171.     CON_KBD_KEY_NUMPAD_5 ,
  172.     CON_KBD_KEY_NUMPAD_6 ,
  173.     CON_KBD_KEY_NUMPAD_7 ,
  174.     CON_KBD_KEY_NUMPAD_8 ,
  175.     CON_KBD_KEY_NUMPAD_9 ,
  176.  
  177.     CON_KBD_KEY_WINDOW1 = 112 ,
  178.     CON_KBD_KEY_WINDOW2 ,
  179.  
  180.     CON_KBD_KEY_F1 = 128 ,
  181.     CON_KBD_KEY_F2 ,
  182.     CON_KBD_KEY_F3 ,
  183.     CON_KBD_KEY_F4 ,
  184.     CON_KBD_KEY_F5 ,
  185.     CON_KBD_KEY_F6 ,
  186.     CON_KBD_KEY_F7 ,
  187.     CON_KBD_KEY_F8 ,
  188.     CON_KBD_KEY_F9 ,
  189.     CON_KBD_KEY_F10 ,
  190.     CON_KBD_KEY_F11 ,
  191.     CON_KBD_KEY_F12 ,
  192.     CON_KBD_KEY_F13 ,
  193.     CON_KBD_KEY_F14 ,
  194.     CON_KBD_KEY_F15 ,
  195.     CON_KBD_KEY_F16 ,
  196.     CON_KBD_KEY_F17 ,
  197.     CON_KBD_KEY_F18 ,
  198.     CON_KBD_KEY_F19 ,
  199.     CON_KBD_KEY_F20 ,
  200.     CON_KBD_KEY_F21 ,
  201.     CON_KBD_KEY_F22 ,
  202.     CON_KBD_KEY_F23 ,
  203.     CON_KBD_KEY_F24 ,
  204.     CON_KBD_KEY_F25 ,
  205.     CON_KBD_KEY_F26 ,
  206.     CON_KBD_KEY_F27 ,
  207.     CON_KBD_KEY_F28 ,
  208.     CON_KBD_KEY_F29 ,
  209.     CON_KBD_KEY_F30 ,
  210.     CON_KBD_KEY_F31 ,
  211.     CON_KBD_KEY_F32 ,
  212.     CON_KBD_KEY_F33 ,
  213.     CON_KBD_KEY_F34 ,
  214.     CON_KBD_KEY_F35 ,
  215.     CON_KBD_KEY_F36 ,
  216.     CON_KBD_KEY_F37 ,
  217.     CON_KBD_KEY_F38 ,
  218.     CON_KBD_KEY_F39 ,
  219.     CON_KBD_KEY_F40 ,
  220.     CON_KBD_KEY_F41 ,
  221.     CON_KBD_KEY_F42 ,
  222.     CON_KBD_KEY_F43 ,
  223.     CON_KBD_KEY_F44 ,
  224.     CON_KBD_KEY_F45 ,
  225.     CON_KBD_KEY_F46 ,
  226.     CON_KBD_KEY_F47 ,
  227.     CON_KBD_KEY_F48 ,
  228. } ;
  229.  
  230. //
  231. //    Console mode flags
  232. //
  233. enum {
  234.     CON_DISABLE_ANSI_CSI_SEQUENCES    = 0x0001 ,
  235.     CON_DISABLE_ANSI_CONTROL_CHARS    = 0x0002 ,
  236.     CON_DISABLE_WRAP_AT_EOL         = 0x0004 ,
  237.     CON_ENABLE_UTF8_OUTPUT            = 0x0008 ,
  238.     CON_DISABLE_EDITING_KEYS        = 0x0010 ,
  239.     CON_DISABLE_LINE_INPUT            = 0x0020 ,
  240.     CON_DISABLE_LINE_INPUT_ECHO     = 0x0040 ,
  241.     CON_ENABLE_PASSWORD_MODE        = 0x0080 ,
  242.     CON_ENABLE_UTF8_INPUT            = 0x0100 ,
  243.     CON_ENABLE_SHIFT_EVENTS         = 0x1000 ,
  244.     CON_ENABLE_MOUSE_EVENTS         = 0x2000 ,
  245.     CON_ENABLE_SIZE_EVENTS            = 0x4000 ,
  246. } ;
  247.  
  248. typedef unsigned short CONSOLE_UNICHAR ;            // UCS-2 character
  249.  
  250. #if !defined(__BORLANDC__) && !defined(__IBMCPP__)
  251. _Packed
  252. #endif
  253. struct CONSOLE_INPUT_EVENT {
  254.     enum { NONE, KEY, MOUSE, WINDOW_SIZE, MENU, FOCUS } ;
  255.     USHORT Type ;
  256. #if defined(__HIGHC__) || defined(__WATCOMC__)
  257.     unsigned long long TimeStamp ;
  258. #else
  259.     unsigned long TimeStampLo, TimeStampHi ;
  260. #endif
  261.  
  262.     union {
  263. #if !defined(__BORLANDC__) && !defined(__IBMCPP__)
  264.         _Packed
  265. #endif
  266.         struct {
  267.             ULONG Flags ;
  268.             USHORT RepeatCount ;
  269.             USHORT VirtualKeyCode ;
  270.             USHORT ScanCode ;
  271.             CONSOLE_UNICHAR Character ;
  272.             ULONG ShiftState ;
  273.         } KeyEvent ;
  274. #if !defined(__BORLANDC__) && !defined(__IBMCPP__)
  275.         _Packed
  276. #endif
  277.         struct {
  278.             size_t Row, Column ;
  279.             ULONG ButtonState ;
  280.             ULONG ShiftState ;
  281.             enum { CLICK, DOUBLE_CLICK, MOTION } ;
  282.             ULONG EventType ;
  283.         } MouseEvent ;
  284. #if !defined(__BORLANDC__) && !defined(__IBMCPP__)
  285.         _Packed
  286. #endif
  287.         struct {
  288.             size_t Width, Height ;
  289.         } OutputBufferSizeEvent ;
  290. #if !defined(__BORLANDC__) && !defined(__IBMCPP__)
  291.         _Packed
  292. #endif
  293.         struct {
  294.             char reserved[32] ;
  295.         } NullEvent ;
  296.     } ;
  297. } ;
  298.  
  299. #if !defined(__BORLANDC__) && !defined(__IBMCPP__)
  300. _Packed
  301. #endif
  302. struct CONSOLE_CELL {
  303.     CONSOLE_UNICHAR Char ;
  304.     unsigned char Attr ;
  305.  
  306.     CONSOLE_CELL () {}
  307.     CONSOLE_CELL ( CONSOLE_UNICHAR c, unsigned char a ) : Char(c), Attr(a) {}
  308. } ;
  309.  
  310. enum {
  311.     CON_ATTR_BLACK,
  312.     CON_ATTR_BLUE,
  313.     CON_ATTR_GREEN,
  314.     CON_ATTR_CYAN,
  315.     CON_ATTR_RED,
  316.     CON_ATTR_MAGENTA,
  317.     CON_ATTR_YELLOW,
  318.     CON_ATTR_WHITE,
  319.     CON_ATTR_BRIGHT,
  320. } ;
  321.  
  322. extern inline
  323. unsigned char
  324. CONSOLE_MAKE_ATTR ( unsigned char brfg, unsigned char fg, unsigned char brbg, unsigned char bg )
  325. {
  326.     return (((brbg & CON_ATTR_BRIGHT) | (bg & 7)) << 4) | (brfg & CON_ATTR_BRIGHT) | (fg & 7) ;
  327. }
  328.  
  329. extern "C" {
  330.  
  331. APIRET APIENTRY DosWriteConsoleOutputCellStr        ( HFILE Handle, const CONSOLE_CELL * PtrCellStr, size_t Cells, size_t Row, size_t Col ) ;
  332. APIRET APIENTRY DosWriteConsoleOutputCharStr        ( HFILE Handle, const CONSOLE_UNICHAR * PtrCharStr, size_t Cells, size_t Row, size_t Col ) ;
  333. APIRET APIENTRY DosWriteConsoleOutputAttrStr        ( HFILE Handle, const unsigned char * PtrAttrStr, size_t Cells, size_t Row, size_t Col ) ;
  334. APIRET APIENTRY DosWriteConsoleOutputCharStrAttr    ( HFILE Handle, const CONSOLE_UNICHAR * PtrCharStr, size_t Cells, size_t Row, size_t Col, unsigned char Attr ) ;
  335. APIRET APIENTRY DosWriteConsoleOutputNAttr            ( HFILE Handle, unsigned char Attr, size_t Cells, size_t Row, size_t Col ) ;
  336. APIRET APIENTRY DosWriteConsoleOutputNCell            ( HFILE Handle, const CONSOLE_CELL & Cell, size_t Cells, size_t Row, size_t Col ) ;
  337. APIRET APIENTRY DosWriteConsoleOutputNChar            ( HFILE Handle, CONSOLE_UNICHAR Char, size_t Cells, size_t Row, size_t Col ) ;
  338. APIRET APIENTRY DosReadConsoleOutputCellStr         ( HFILE Handle, CONSOLE_CELL * PtrCellStr, size_t Cells, size_t Row, size_t Col ) ;
  339. APIRET APIENTRY DosReadConsoleOutputCharStr         ( HFILE Handle, CONSOLE_UNICHAR * PtrCharStr, size_t Cells, size_t Row, size_t Col ) ;
  340. APIRET APIENTRY DosReadConsoleOutputAttrStr         ( HFILE Handle, unsigned char * PtrAttrStr, size_t Cells, size_t Row, size_t Col ) ;
  341. APIRET APIENTRY DosScrollConsoleUp                    ( HFILE Handle, size_t Top, size_t Left, size_t Height, size_t Width, size_t Delta, const CONSOLE_CELL & Space ) ;
  342. APIRET APIENTRY DosScrollConsoleDown                ( HFILE Handle, size_t Top, size_t Left, size_t Height, size_t Width, size_t Delta, const CONSOLE_CELL & Space ) ;
  343. APIRET APIENTRY DosScrollConsoleLeft                ( HFILE Handle, size_t Top, size_t Left, size_t Height, size_t Width, size_t Delta, const CONSOLE_CELL & Space ) ;
  344. APIRET APIENTRY DosScrollConsoleRight                ( HFILE Handle, size_t Top, size_t Left, size_t Height, size_t Width, size_t Delta, const CONSOLE_CELL & Space ) ;
  345. APIRET APIENTRY DosSetConsoleCursorPos                ( HFILE Handle, size_t Row, size_t Col ) ;
  346. APIRET APIENTRY DosQueryConsoleCursorPos            ( HFILE Handle, size_t & Row, size_t & Col ) ;
  347. APIRET APIENTRY DosSetConsoleCursorSize             ( HFILE Handle, unsigned int PercentStart, unsigned int PercentEnd, BOOL Visible ) ;
  348. APIRET APIENTRY DosQueryConsoleCursorSize            ( HFILE Handle, unsigned int & PercentStart, unsigned int & PercentEnd, BOOL & Visible ) ;
  349. APIRET APIENTRY DosSetConsoleShiftState             ( HFILE Handle, ULONG ShiftState ) ;
  350. APIRET APIENTRY DosQueryConsoleShiftState            ( HFILE Handle, ULONG & ShiftState ) ;
  351. APIRET APIENTRY DosSetConsoleSize                    ( HFILE Handle, size_t Rows, size_t Cols ) ;
  352. APIRET APIENTRY DosQueryConsoleSize                 ( HFILE Handle, size_t & Rows, size_t & Cols ) ;
  353. APIRET APIENTRY DosQueryMaximumConsoleSize            ( HFILE Handle, size_t & Rows, size_t & Cols ) ;
  354. //APIRET APIENTRY DosSetConsoleWindowSize            ( HFILE Handle, size_t Rows, size_t Cols ) ;
  355. //APIRET APIENTRY DosQueryConsoleWindowSize         ( HFILE Handle, size_t & Rows, size_t & Cols ) ;
  356. //APIRET APIENTRY DosQueryMaximumConsoleWindowSize    ( HFILE Handle, size_t & Rows, size_t & Cols ) ;
  357. APIRET APIENTRY DosSetConsoleMode                    ( HFILE Handle, ULONG Flags ) ;
  358. APIRET APIENTRY DosQueryConsoleMode                 ( HFILE Handle, ULONG & Flags ) ;
  359. APIRET APIENTRY DosSetConsoleOutputAttr             ( HFILE Handle, unsigned char OutputAttr, unsigned char ScrollAttr ) ;
  360. APIRET APIENTRY DosSetConsoleOutputFocus            ( HFILE Handle ) ;
  361. APIRET APIENTRY DosSetConsoleInputFocus             ( HFILE Handle ) ;
  362. APIRET APIENTRY DosSetConsoleOutputCodePage         ( HFILE Handle, unsigned int CodePage ) ;
  363. APIRET APIENTRY DosQueryConsoleOutputCodePage        ( HFILE Handle, unsigned int & CodePage ) ;
  364. APIRET APIENTRY DosSetConsoleInputCodePage            ( HFILE Handle, unsigned int CodePage ) ;
  365. APIRET APIENTRY DosQueryConsoleInputCodePage        ( HFILE Handle, unsigned int & CodePage ) ;
  366. APIRET APIENTRY DosReadConsoleInputEvent            ( HFILE Handle, CONSOLE_INPUT_EVENT * Events, size_t MaxEvents, size_t & NumEvents, BOOL remove ) ;
  367. //APIRET APIENTRY DosWriteConsoleInputEvent             ( HFILE Handle, CONSOLE_INPUT_EVENT * Events, size_t MaxEvents, size_t & NumEvents ) ;
  368. //APIRET APIENTRY DosQueryConsoleInputEventCount        ( HFILE Handle, size_t & NumEvents ) ;
  369. APIRET APIENTRY DosFlushConsoleInputEvents            ( HFILE Handle ) ;
  370. APIRET APIENTRY DosQueryConsoleNumberOfMouseButtons ( HFILE Handle, size_t & Buttons ) ;
  371. //APIRET APIENTRY DosSetConsoleTitle                    ( HFILE Handle, const CONSOLE_UNICHAR * PtrTitleStr ) ;
  372. //APIRET APIENTRY DosQueryConsoleTitle                    ( HFILE Handle, CONSOLE_UNICHAR * PtrTitleStr, size_t BufLen, size_t & Length ) ;
  373.  
  374. }
  375.  
  376. #endif /* INCL_CONSOLE */
  377.  
  378. #if defined(__BORLANDC__)
  379. #    pragma option -a.
  380. #elif defined(__IBMCPP__)
  381. #    pragma pack()
  382. #endif
  383.  
  384. #if defined(__IBMC__)
  385.    #pragma checkout( suspend )
  386.    #ifndef __CHKHDR__
  387.       #pragma checkout( resume )
  388.    #endif
  389.    #pragma checkout( resume )
  390. #elif defined(__IBMCPP__)
  391.    #pragma info( none )
  392.    #ifndef __CHKHDR__
  393.       #pragma info( restore )
  394.    #endif
  395.    #pragma info( restore )
  396. #endif
  397.