screen_callbacks.c
8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
* Copyright 2008, Banco do Brasil S.A.
*
* This file is part of g3270
*
* This program file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authors:
*
* Perry Werneck<perry.werneck@gmail.com>
*
*/
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include "g3270.h"
#include "lib/kybdc.h"
/*---[ Defines ]--------------------------------------------------------------*/
#define TCNT 7
#define LUCNT 8
#define CM (60 * 10)
/*---[ Prototipes ]-----------------------------------------------------------*/
static void screen_init(void);
static void screen_disp(Boolean erasing, const struct ea *display);
static void screen_suspend(void);
static void screen_resume(void);
static void screen_type(const char *model_name, int maxROWS, int maxCOLS);
static void cursor_move(int baddr);
static void cursor_mode(int mode);
static void toggle_monocase(struct toggle *t, enum toggle_type tt);
static void screen_changed(int first, int last);
static void status_ctlr_done(void);
static void status_insert_mode(Boolean on);
static void status_minus(void);
static void status_reset(void);
static void status_reverse_mode(Boolean on);
static void status_syswait(void);
static void status_twait(void);
static void status_typeahead(Boolean on);
static void status_compose(Boolean on, unsigned char c, enum keytype keytype);
static void status_lu(const char *lu);
static void status_oerr(int error_type);
static void ring_bell(void);
static void screen_flip(void);
static void screen_width(int width);
static void error_popup(const char *msg);
static void Redraw_action(Widget w, XEvent *event, String *params, Cardinal *num_params);
static void status_timing(struct timeval *t0, struct timeval *t1);
static const char *lookup_cname(int ccode);
/*---[ Globals ]--------------------------------------------------------------*/
char oia_cursor[8] = "";
char oia_LUName[12] = " ";
char oia_Timet[TCNT+1] = "";
char oia_Timer[OIA_TIMER_COUNT+1] = "";
char oia_undera = 1;
char oia_Typeahead[2] = " ";
/*---[ 3270 Screen callback table ]-------------------------------------------*/
const SCREEN_CALLBACK g3270_screen_callbacks =
{
sizeof(SCREEN_CALLBACK),
SCREEN_MAGIC,
screen_init,
screen_disp,
screen_suspend,
screen_resume,
screen_type,
screen_changed,
cursor_move,
cursor_mode,
toggle_monocase,
status_ctlr_done,
status_insert_mode,
status_minus,
status_oerr,
status_reset,
status_reverse_mode,
status_syswait,
status_twait,
status_typeahead,
status_compose,
status_lu,
ring_bell,
screen_flip,
screen_width,
lookup_cname,
error_popup,
Redraw_action,
status_timing,
status_untiming
};
/*---[ Keyboard tables ]------------------------------------------------------*/
/* I "think" this isn't necessary anymore */
static const KEYTABLE keys[] =
{
{ "DOWN", GDK_Down },
{ "UP", GDK_Up },
{ "LEFT", GDK_Left },
{ "RIGHT", GDK_Right },
{ "BACKSPACE", GDK_BackSpace },
{ CN, 0 }
};
const KEYBOARD_INFO g3270_keyboard_info =
{
sizeof(KEYBOARD_INFO),
KEYBOARD_MAGIC,
ring_bell,
gsource_addfile,
gsource_removefile,
keys
};
/*---[ Implement screen callbacks ]-------------------------------------------*/
static void screen_init(void)
{
CHKPoint();
}
static void screen_disp(Boolean erasing, const struct ea *display)
{
RedrawTerminalContents();
}
static void screen_suspend(void)
{
CHKPoint();
}
static void screen_resume(void)
{
RedrawTerminalContents();
}
static void screen_type(const char *model_name, int maxROWS, int maxCOLS)
{
DBGPrintf("Screen type: %s (%dx%d)",model_name,maxROWS,maxCOLS);
}
static void cursor_move(int baddr)
{
int row;
int col;
int cols;
Get3270DeviceBuffer(0, &cols);
row = baddr/cols;
col = baddr - (row*cols);
SetCursorPosition(row,col);
snprintf(oia_cursor,7,"%02d/%03d",row+1,col+1);
}
static void toggle_monocase(struct toggle *t, enum toggle_type tt)
{
CHKPoint();
}
/* Done with controller confirmation */
static void status_ctlr_done(void)
{
oia_undera = 1;
RedrawStatusLine();
}
static void status_insert_mode(Boolean on)
{
if(on)
SetCursorType(CURSOR_TYPE_INSERT);
else
SetCursorType(CURSOR_TYPE_OVER);
}
/* Lock the keyboard (X -f) */
static void status_minus(void)
{
SetOIAStatus(STATUS_MINUS);
}
/* Unlock the keyboard */
static void status_reset(void)
{
if (GetKeyboardStatus() & KL_ENTER_INHIBIT)
SetOIAStatus(STATUS_INHIBIT);
else if (GetKeyboardStatus() & KL_DEFERRED_UNLOCK)
SetOIAStatus(STATUS_NONSPECIFIC);
else
SetOIAStatus(STATUS_BLANK);
DBGPrintf("Reset kybd: %d",(int) GetKeyboardStatus());
}
/* Toggle reverse mode */
static void status_reverse_mode(Boolean on)
{
NotImplemented();
}
/* Lock the keyboard (X SYSTEM) */
static void status_syswait(void)
{
SetOIAStatus(STATUS_SYSWAIT);
}
/* Lock the keyboard (twait) */
static void status_twait(void)
{
oia_undera = 0;
SetOIAStatus(STATUS_TWAIT);
}
/* Toggle typeahead */
static void status_typeahead(Boolean on)
{
DBGPrintf("Typeahead: %s",on ? "Yes" : "No");
*oia_Typeahead = on ? 'T' : ' ';
RedrawStatusLine();
}
/* Set compose character */
static void status_compose(Boolean on, unsigned char c, enum keytype keytype)
{
DBGPrintf("Compose: %s Char: %02x \"%c\"",on ? "Yes" : "No", c, c);
NotImplemented();
RedrawStatusLine();
}
/* Set LU name */
static void status_lu(const char *lu)
{
if(!lu)
lu = "";
g3270_log("lib3270", "Using LU \"%s\"",lu);
snprintf(oia_LUName,11,"%-10s",lu);
UpdateWindowTitle();
RedrawStatusLine();
#ifdef EXTENSIONS
SetExtensionsChar("g3270LUChanged",lu);
#endif
}
static void ring_bell(void)
{
#ifdef DEBUG
DBGMessage("Beep!");
if(terminal && terminal->window)
gdk_beep();
#endif
}
static void screen_flip(void)
{
CHKPoint();
}
static void screen_width(int width)
{
// FIXME (perry#1#): Recalculate font size!
DBGTrace(width);
RedrawTerminalContents();
}
static void error_popup(const char *msg)
{
Log(msg);
}
static void Redraw_action(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
RedrawTerminalContents();
}
static void screen_changed(int first, int last)
{
WaitForScreen = FALSE;
// action_remove_selection(0,0);
RedrawTerminalContents();
}
static void status_oerr(int error_type)
{
switch(error_type)
{
case KL_OERR_PROTECTED:
SetOIAStatus(STATUS_PROTECTED);
break;
case KL_OERR_NUMERIC:
SetOIAStatus(STATUS_NUMERIC);
break;
case KL_OERR_OVERFLOW:
SetOIAStatus(STATUS_OVERFLOW);
break;
case KL_OERR_DBCS:
SetOIAStatus(STATUS_DBCS);
break;
}
}
#ifdef DEBUG
static int dbgTimerEnabled = 0;
#endif
static void status_timing(struct timeval *t0, struct timeval *t1)
{
unsigned long cs; // centiseconds
#ifdef DEBUG
if(!dbgTimerEnabled)
{
dbgTimerEnabled = 1;
DBGMessage("Timer ON!");
}
#endif
if (t1->tv_sec - t0->tv_sec > (99*60))
{
strncpy(oia_Timer,":??.?",OIA_TIMER_COUNT);
}
else
{
cs = (t1->tv_sec - t0->tv_sec) * 10 +
(t1->tv_usec - t0->tv_usec + 50000) / 100000;
if (cs < CM)
snprintf(oia_Timer, OIA_TIMER_COUNT, ":%02ld.%ld", cs / 10, cs % 10);
else
snprintf(oia_Timer, OIA_TIMER_COUNT, "%02ld:%02ld", cs / CM, (cs % CM) / 10);
}
RedrawStatusLine();
}
void status_untiming(void)
{
#ifdef DEBUG
if(dbgTimerEnabled)
{
dbgTimerEnabled = 0;
DBGMessage("Timer Off!");
}
#endif
*oia_Timer = 0;
RedrawStatusLine();
}
static void cursor_mode(int mode)
{
DBGPrintf("********** CURSOR: %d",mode);
SetTerminalCursorByID(mode);
}
const char *lookup_cname(int ccode)
{
int i;
for(i = 0; i < (sizeof(keys) / sizeof(KEYTABLE));i++)
{
if(ccode == keys[i].code)
return keys[i].name;
}
return CN;
}