1 /* TN5250 - An implementation of the 5250 telnet protocol. 2 * Copyright (C) 1997-2008 Michael Madore 3 * 4 * This file is part of TN5250. 5 * 6 * TN5250 is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation; either version 2.1, or (at your option) 9 * any later version. 10 * 11 * TN5250 is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this software; see the file COPYING. If not, write to 18 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, 19 * Boston, MA 02111-1307 USA 20 * 21 */ 22 #ifndef TERMINAL_H 23 #define TERMINAL_H 24 25 #ifdef __cplusplus 26 extern "C" 27 { 28 #endif 29 30 /* Flags */ 31 #define TN5250_TERMINAL_HAS_COLOR 0x0001 32 33 /* Events */ 34 #define TN5250_TERMINAL_EVENT_KEY 0x0001 35 #define TN5250_TERMINAL_EVENT_DATA 0x0002 36 #define TN5250_TERMINAL_EVENT_QUIT 0x0004 37 38 /* Key definitions 39 * These are directly copied from <curses.h>, although the only real 40 * requirement is that they be unique. CursesTerminal is currently 41 * broken and relies on them being the same, though. */ 42 43 #define K_CTRL(k) ((k)-0x40) 44 /* e.g. K_CTRL('X') is curses/ascii key value for Ctrl+X */ 45 46 #define K_FIRST_SPECIAL 0400 /* Coincides with first Curses key. */ 47 48 #define K_ENTER 0x0d 49 #define K_NEWLINE 0x200 50 #define K_TAB 0x09 51 #define K_BACKTAB 0541 52 #define K_F1 (0410+1) 53 #define K_F2 (0410+2) 54 #define K_F3 (0410+3) 55 #define K_F4 (0410+4) 56 #define K_F5 (0410+5) 57 #define K_F6 (0410+6) 58 #define K_F7 (0410+7) 59 #define K_F8 (0410+8) 60 #define K_F9 (0410+9) 61 #define K_F10 (0410+10) 62 #define K_F11 (0410+11) 63 #define K_F12 (0410+12) 64 #define K_F13 (0410+13) 65 #define K_F14 (0410+14) 66 #define K_F15 (0410+15) 67 #define K_F16 (0410+16) 68 #define K_F17 (0410+17) 69 #define K_F18 (0410+18) 70 #define K_F19 (0410+19) 71 #define K_F20 (0410+20) 72 #define K_F21 (0410+21) 73 #define K_F22 (0410+22) 74 #define K_F23 (0410+23) 75 #define K_F24 (0410+24) 76 #define K_LEFT 0404 77 #define K_RIGHT 0405 78 #define K_UP 0403 79 #define K_DOWN 0402 80 #define K_ROLLDN 0523 81 #define K_ROLLUP 0522 82 #define K_BACKSPACE 0407 83 #define K_HOME 0406 84 #define K_END 0550 85 #define K_INSERT 0513 86 #define K_DELETE 0512 87 #define K_RESET 0531 88 #define K_PRINT 0532 89 #define K_HELP 0553 90 #define K_SYSREQ 0401 /* curses KEY_BREAK */ 91 #define K_CLEAR 0515 /* curses KEY_CLEAR */ 92 #define K_REFRESH 0564 /* curses KEY_REFRESH */ 93 #define K_FIELDEXIT 0517 /* curses KEY_EOL (clear to EOL) */ 94 #define K_TESTREQ 0516 /* curses KEY_EOS (as good as any) */ 95 #define K_TOGGLE 0533 /* curses KEY_LL (as good as any) */ 96 #define K_ERASE 0514 /* curses KEY_EIC (as good as any) */ 97 #define K_ATTENTION 0511 /* curses KEY_IL (as good as any) */ 98 #define K_DUPLICATE 0524 /* curses KEY_STAB (set tab - good as any) */ 99 #define K_FIELDMINUS 0526 /* curses KEY_CATAB (clear all tabs - g.a.a.) */ 100 #define K_FIELDPLUS 0520 /* curses KEY_SF */ 101 #define K_PREVWORD 0611 /* curses KEY_SLEFT (as good as any) */ 102 #define K_NEXTWORD 0622 /* curses KEY_SRIGHT (as good as any) */ 103 #define K_PREVFLD 0xfffb /* no similar curses key */ 104 #define K_NEXTFLD 0xfffc /* no similar curses key */ 105 #define K_FIELDHOME 0607 /* curses KEY_SHOME (as good as any) */ 106 #define K_EXEC 0507 /* macro execution */ 107 #define K_MEMO 0510 /* macro record */ 108 #define K_COPY_TEXT 0xfffd /* no similar curses key */ 109 #define K_PASTE_TEXT 0xfffe /* no similar curses key */ 110 #define K_UNKNOW 0xffff 111 112 113 struct _Tn5250Display; 114 115 /****s* lib5250/Tn5250Terminal 116 * NAME 117 * Tn5250Terminal 118 * SYNOPSIS 119 * Tn5250Terminal *term = get_my_terminal_object (); 120 * int w,h,r,k,f; 121 * tn5250_terminal_init(term); 122 * 123 * w = tn5250_terminal_width(term); 124 * h = tn5250_terminal_height(term); 125 * f = tn5250_terminal_flags(term); 126 * 127 * r = tn5250_terminal_waitevent(term); 128 * if ((r & TN5250_TERMINAL_EVENT_KEY) != 0) 129 * k = tn5250_terminal_getkey(term); 130 * if ((r & TN5250_TERMINAL_EVENT_QUIT) != 0) 131 * exit(0); 132 * if ((r & TN5250_TERMINAL_EVENT_DATA) != 0) 133 * read_data_from_fd (); 134 * 135 * tn5250_terminal_update(term,display); 136 * tn5250_terminal_update_indicators(term,display); 137 * tn5250_terminal_beep(term); 138 * 139 * tn5250_terminal_term(term); 140 * tn5250_terminal_destroy(term); 141 * DESCRIPTION 142 * Manages a terminal interface, such as the Curses terminal interface, 143 * the S/Lang terminal interface, or an X Windows based terminal. This 144 * is an abstract type, implementations are currently available in 145 * cursesterm.c, slangterm.c, and one should shortly be available in 146 * gtkterm.c. 147 * SOURCE 148 */ 149 struct _Tn5250Terminal 150 { 151 SOCKET_TYPE conn_fd; 152 struct _Tn5250TerminalPrivate *data; 153 154 void (*init) (struct _Tn5250Terminal * This); 155 void (*term) (struct _Tn5250Terminal * This); 156 void (*destroy) (struct _Tn5250Terminal /*@only@ */ * This); 157 int (*width) (struct _Tn5250Terminal * This); 158 int (*height) (struct _Tn5250Terminal * This); 159 int (*flags) (struct _Tn5250Terminal * This); 160 void (*update) (struct _Tn5250Terminal * This, 161 struct _Tn5250Display * display); 162 void (*update_indicators) (struct _Tn5250Terminal * This, 163 struct _Tn5250Display * display); 164 int (*waitevent) (struct _Tn5250Terminal * This); 165 int (*getkey) (struct _Tn5250Terminal * This); 166 void (*putkey) (struct _Tn5250Terminal * This, 167 struct _Tn5250Display * display, unsigned char key, 168 int row, int column); 169 void (*beep) (struct _Tn5250Terminal * This); 170 int (*enhanced) (struct _Tn5250Terminal * This); 171 int (*config) (struct _Tn5250Terminal * This, 172 struct _Tn5250Config * config); 173 void (*create_window) (struct _Tn5250Terminal * This, 174 struct _Tn5250Display * display, 175 struct _Tn5250Window * window); 176 void (*destroy_window) (struct _Tn5250Terminal * This, 177 struct _Tn5250Display * display, 178 struct _Tn5250Window * window); 179 void (*create_scrollbar) (struct _Tn5250Terminal * This, 180 struct _Tn5250Display * display, 181 struct _Tn5250Scrollbar * scrollbar); 182 void (*destroy_scrollbar) (struct _Tn5250Terminal * This, 183 struct _Tn5250Display * display); 184 void (*create_menubar) (struct _Tn5250Terminal * This, 185 struct _Tn5250Display * display, 186 struct _Tn5250Menubar * menubar); 187 void (*destroy_menubar) (struct _Tn5250Terminal * This, 188 struct _Tn5250Display * display, 189 struct _Tn5250Menubar * menubar); 190 void (*create_menuitem) (struct _Tn5250Terminal * This, 191 struct _Tn5250Display * display, 192 struct _Tn5250Menuitem * menuitem); 193 void (*destroy_menuitem) (struct _Tn5250Terminal * This, 194 struct _Tn5250Display * display, 195 struct _Tn5250Menuitem * menuitem); 196 }; 197 198 typedef struct _Tn5250Terminal Tn5250Terminal; 199 /*******/ 200 201 #ifndef _TN5250_TERMINAL_PRIVATE_DEFINED 202 #define _TN5250_TERMINAL_PRIVATE_DEFINED 203 struct _Tn5250TerminalPrivate 204 { 205 long dummy; 206 }; 207 #endif 208 209 /* Useful macros call ``methods'' on the terminal type. */ 210 /* For SWIG, we need actual functions - blah. */ 211 extern void tn5250_terminal_init (Tn5250Terminal * This); 212 extern void tn5250_terminal_term (Tn5250Terminal * This); 213 extern void tn5250_terminal_destroy (Tn5250Terminal * This); 214 extern int tn5250_terminal_width (Tn5250Terminal * This); 215 extern int tn5250_terminal_height (Tn5250Terminal * This); 216 extern int tn5250_terminal_flags (Tn5250Terminal * This); 217 extern void tn5250_terminal_update (Tn5250Terminal * This, 218 struct _Tn5250Display *d); 219 extern void tn5250_terminal_update_indicators (Tn5250Terminal * This, 220 struct _Tn5250Display *d); 221 extern int tn5250_terminal_waitevent (Tn5250Terminal * This); 222 extern int tn5250_terminal_getkey (Tn5250Terminal * This); 223 extern void tn5250_terminal_putkey (Tn5250Terminal * This, 224 struct _Tn5250Display *d, 225 unsigned char k, int y, int x); 226 extern void tn5250_terminal_beep (Tn5250Terminal * This); 227 extern int tn5250_terminal_enhanced (Tn5250Terminal * This); 228 extern int tn5250_terminal_config (Tn5250Terminal * This, 229 struct _Tn5250Config *cfg); 230 extern void tn5250_terminal_create_window (Tn5250Terminal * This, 231 struct _Tn5250Display *d, 232 struct _Tn5250Window * w); 233 extern void tn5250_terminal_destroy_window (Tn5250Terminal * This, 234 struct _Tn5250Display *d, 235 struct _Tn5250Window * w); 236 extern void tn5250_terminal_create_scrollbar (Tn5250Terminal * This, 237 struct _Tn5250Display *d, 238 struct _Tn5250Scrollbar *s); 239 extern void tn5250_terminal_destroy_scrollbar (Tn5250Terminal * This, 240 struct _Tn5250Display *d); 241 extern void tn5250_terminal_create_menubar (Tn5250Terminal * This, 242 struct _Tn5250Display *d, 243 struct _Tn5250Menubar *m); 244 extern void tn5250_terminal_destroy_menubar (Tn5250Terminal * This, 245 struct _Tn5250Display *d, 246 struct _Tn5250Menubar *m); 247 extern void tn5250_terminal_create_menuitem (Tn5250Terminal * This, 248 struct _Tn5250Display *d, 249 struct _Tn5250Menuitem *i); 250 extern void tn5250_terminal_destroy_menuitem (Tn5250Terminal * This, 251 struct _Tn5250Display *d, 252 struct _Tn5250Menuitem *i); 253 254 #ifdef __cplusplus 255 } 256 257 #endif 258 #endif /* TERMINAL_H */ 259 260 /* vi:set cindent sts=3 sw=3: */ 261