1 | /* |
---|
2 | * Copyright 1993, 1994, 1995, 199 by Paul Mattes. |
---|
3 | * Permission to use, copy, modify, and distribute this software and its |
---|
4 | * documentation for any purpose and without fee is hereby granted, |
---|
5 | * provided that the above copyright notice appear in all copies and that |
---|
6 | * both that copyright notice and this permission notice appear in |
---|
7 | * supporting documentation. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * status.c |
---|
12 | * This module handles the 3270 status line. |
---|
13 | */ |
---|
14 | |
---|
15 | #include "globals.h" |
---|
16 | #include <X11/StringDefs.h> |
---|
17 | #include <X11/Shell.h> |
---|
18 | #include "3270ds.h" |
---|
19 | #include "appres.h" |
---|
20 | #include "screen.h" |
---|
21 | #include "cg.h" |
---|
22 | |
---|
23 | #include "kybdc.h" |
---|
24 | #include "statusc.h" |
---|
25 | #include "tablesc.h" |
---|
26 | #include "utilc.h" |
---|
27 | |
---|
28 | extern Window *screen_window; |
---|
29 | extern GC screen_gc(); |
---|
30 | extern GC screen_invgc(); |
---|
31 | |
---|
32 | static XChar2b *status_2b; |
---|
33 | static unsigned char *status_1b; |
---|
34 | static XChar2b *display_2b; |
---|
35 | static Boolean status_changed = False; |
---|
36 | |
---|
37 | static struct status_line { |
---|
38 | Boolean changed; |
---|
39 | int start, len, color; |
---|
40 | XChar2b *s2b; |
---|
41 | unsigned char *s1b; |
---|
42 | XChar2b *d2b; |
---|
43 | } *status_line; |
---|
44 | |
---|
45 | static int offsets[] = { |
---|
46 | 0, /* connection status */ |
---|
47 | 8, /* wait, locked */ |
---|
48 | 39, /* shift, insert, timing, cursor position */ |
---|
49 | -1 |
---|
50 | }; |
---|
51 | #define SSZ ((sizeof(offsets)/sizeof(offsets[0])) - 1) |
---|
52 | |
---|
53 | #define CTLR_REGION 0 |
---|
54 | #define WAIT_REGION 1 |
---|
55 | #define MISC_REGION 2 |
---|
56 | |
---|
57 | static int colors[SSZ] = { |
---|
58 | FA_INT_NORM_NSEL, |
---|
59 | FA_INT_HIGH_SEL, |
---|
60 | FA_INT_NORM_NSEL |
---|
61 | }; |
---|
62 | |
---|
63 | static int colors3279[SSZ] = { |
---|
64 | COLOR_BLUE, |
---|
65 | COLOR_WHITE, |
---|
66 | COLOR_BLUE |
---|
67 | }; |
---|
68 | |
---|
69 | #define CM (60 * 10) /* csec per minute */ |
---|
70 | |
---|
71 | /* |
---|
72 | * The status line is laid out thusly (M is maxCOLS): |
---|
73 | * |
---|
74 | * 0 "4" in a square |
---|
75 | * 1 "A" underlined |
---|
76 | * 2 solid box if connected, "?" in a box if not |
---|
77 | * 3..7 empty |
---|
78 | * 8... message area |
---|
79 | * M-41 Meta indication ("M" or blank) |
---|
80 | * M-40 Alt indication ("A" or blank) |
---|
81 | * M-39 Shift indication (Special symbol/"^" or blank) |
---|
82 | * M-38..M-37 empty |
---|
83 | * M-36 Compose indication ("C" or blank) |
---|
84 | * M-35 Compose first character |
---|
85 | * M-34 empty |
---|
86 | * M-33 Typeahead indication ("T" or blank) |
---|
87 | * M-32 empty |
---|
88 | * M-31 Alternate keymap indication ("K" or blank) |
---|
89 | * M-30 Reverse input mode indication ("R" or blank) |
---|
90 | * M-29 Insert mode indication (Special symbol/"I" or blank) |
---|
91 | * M-28 empty |
---|
92 | * M-27 Script indication ("S" or blank) |
---|
93 | * M-26..M-16 empty |
---|
94 | * M-15..M-9 command timing (Clock symbol and m:ss, or blank) |
---|
95 | * M-7..M cursor position (rrr/ccc or blank) |
---|
96 | */ |
---|
97 | |
---|
98 | /* Positions */ |
---|
99 | |
---|
100 | #define LBOX 0 /* left-hand box */ |
---|
101 | #define CNCT 1 /* connection between */ |
---|
102 | #define RBOX 2 /* right-hand box */ |
---|
103 | |
---|
104 | #define M0 8 /* message area */ |
---|
105 | |
---|
106 | #define SHIFT (maxCOLS-39) /* shift indication */ |
---|
107 | |
---|
108 | #define COMPOSE (maxCOLS-36) /* compose characters */ |
---|
109 | |
---|
110 | #define TYPEAHD (maxCOLS-33) /* typeahead */ |
---|
111 | |
---|
112 | #define KMAP (maxCOLS-31) /* alt keymap in effect */ |
---|
113 | |
---|
114 | #define REVERSE (maxCOLS-30) /* reverse input mode in effect */ |
---|
115 | |
---|
116 | #define INSERT (maxCOLS-29) /* insert mode */ |
---|
117 | |
---|
118 | #define SCRIPT (maxCOLS-27) /* script in progress */ |
---|
119 | |
---|
120 | #define T0 (maxCOLS-15) /* timings */ |
---|
121 | #define TCNT 7 |
---|
122 | |
---|
123 | #define C0 (maxCOLS-7) /* cursor position */ |
---|
124 | #define CCNT 7 |
---|
125 | |
---|
126 | #define STATUS_Y (ROW_TO_Y(maxROWS)+SGAP-1) |
---|
127 | |
---|
128 | static unsigned char nullblank; |
---|
129 | static Position status_y; |
---|
130 | |
---|
131 | /* Status line contents (high-level) */ |
---|
132 | |
---|
133 | static void do_disconnected(); |
---|
134 | static void do_connecting(); |
---|
135 | static void do_nonspecific(); |
---|
136 | static void do_inhibit(); |
---|
137 | static void do_blank(); |
---|
138 | static void do_twait(); |
---|
139 | static void do_syswait(); |
---|
140 | static void do_protected(); |
---|
141 | static void do_numeric(); |
---|
142 | static void do_overflow(); |
---|
143 | static void do_scrolled(); |
---|
144 | |
---|
145 | static Boolean oia_undera = False; |
---|
146 | static Boolean oia_boxsolid = False; |
---|
147 | static int oia_shift = 0; |
---|
148 | static Boolean oia_typeahead = False; |
---|
149 | static Boolean oia_compose = False; |
---|
150 | static unsigned char oia_compose_char = 0; |
---|
151 | static enum keytype oia_compose_keytype = KT_STD; |
---|
152 | static enum msg { |
---|
153 | DISCONNECTED, /* X Not Connected */ |
---|
154 | CONNECTING, /* X Connecting */ |
---|
155 | NONSPECIFIC, /* X */ |
---|
156 | INHIBIT, /* X Inhibit */ |
---|
157 | BLANK, /* (blank) */ |
---|
158 | TWAIT, /* X Wait */ |
---|
159 | SYSWAIT, /* X SYSTEM */ |
---|
160 | PROTECTED, /* X Protected */ |
---|
161 | NUMERIC, /* X Numeric */ |
---|
162 | OVERFLOW, /* X Overflow */ |
---|
163 | SCROLLED /* X Scrolled */ |
---|
164 | } oia_msg = DISCONNECTED, saved_msg; |
---|
165 | static Boolean msg_is_saved = False; |
---|
166 | static int n_scrolled = 0; |
---|
167 | static void (*msg_proc[]) () = { |
---|
168 | do_disconnected, |
---|
169 | do_connecting, |
---|
170 | do_nonspecific, |
---|
171 | do_inhibit, |
---|
172 | do_blank, |
---|
173 | do_twait, |
---|
174 | do_syswait, |
---|
175 | do_protected, |
---|
176 | do_numeric, |
---|
177 | do_overflow, |
---|
178 | do_scrolled, |
---|
179 | }; |
---|
180 | static int msg_color[] = { |
---|
181 | FA_INT_HIGH_SEL, |
---|
182 | FA_INT_NORM_NSEL, |
---|
183 | FA_INT_NORM_NSEL, |
---|
184 | FA_INT_NORM_NSEL, |
---|
185 | FA_INT_NORM_NSEL, |
---|
186 | FA_INT_NORM_NSEL, |
---|
187 | FA_INT_NORM_SEL, |
---|
188 | FA_INT_NORM_SEL, |
---|
189 | FA_INT_NORM_SEL, |
---|
190 | FA_INT_NORM_SEL, |
---|
191 | FA_INT_NORM_SEL, |
---|
192 | }; |
---|
193 | static int msg_color3279[] = { |
---|
194 | COLOR_WHITE, |
---|
195 | COLOR_WHITE, |
---|
196 | COLOR_WHITE, |
---|
197 | COLOR_WHITE, |
---|
198 | COLOR_BLUE, |
---|
199 | COLOR_WHITE, |
---|
200 | COLOR_WHITE, |
---|
201 | COLOR_RED, |
---|
202 | COLOR_RED, |
---|
203 | COLOR_RED, |
---|
204 | COLOR_WHITE, |
---|
205 | }; |
---|
206 | static Boolean oia_insert = False; |
---|
207 | static Boolean oia_reverse = False; |
---|
208 | static Boolean oia_kmap = False; |
---|
209 | static Boolean oia_script = False; |
---|
210 | static char *oia_cursor = (char *) 0; |
---|
211 | static char *oia_timing = (char *) 0; |
---|
212 | |
---|
213 | static unsigned char disc_pfx[] = { |
---|
214 | CG_lock, CG_space, CG_badcommhi, CG_commjag, CG_commlo, CG_space |
---|
215 | }; |
---|
216 | static unsigned char *disc_msg; |
---|
217 | static int disc_len = sizeof(disc_pfx); |
---|
218 | |
---|
219 | static unsigned char cnct_pfx[] = { |
---|
220 | CG_lock, CG_space, CG_commhi, CG_commjag, CG_commlo, CG_space |
---|
221 | }; |
---|
222 | static unsigned char *cnct_msg; |
---|
223 | static int cnct_len = sizeof(cnct_pfx); |
---|
224 | |
---|
225 | static unsigned char *a_not_connected; |
---|
226 | static unsigned char *a_connecting; |
---|
227 | static unsigned char *a_inhibit; |
---|
228 | static unsigned char *a_twait; |
---|
229 | static unsigned char *a_syswait; |
---|
230 | static unsigned char *a_protected; |
---|
231 | static unsigned char *a_numeric; |
---|
232 | static unsigned char *a_overflow; |
---|
233 | static unsigned char *a_scrolled; |
---|
234 | |
---|
235 | static unsigned char *make_amsg(); |
---|
236 | static unsigned char *make_emsg(); |
---|
237 | |
---|
238 | static void status_render(); |
---|
239 | static void do_ctlr(); |
---|
240 | static void do_msg(); |
---|
241 | static void paint_msg(); |
---|
242 | static void do_insert(); |
---|
243 | static void do_reverse(); |
---|
244 | static void do_kmap(); |
---|
245 | static void do_script(); |
---|
246 | static void do_shift(); |
---|
247 | static void do_typeahead(); |
---|
248 | static void do_compose(); |
---|
249 | static void do_timing(); |
---|
250 | static void do_cursor(); |
---|
251 | |
---|
252 | |
---|
253 | /* Initialize, or reinitialize the status line */ |
---|
254 | void |
---|
255 | status_init(keep_contents, model_changed, font_changed) |
---|
256 | Boolean keep_contents; |
---|
257 | Boolean model_changed; |
---|
258 | Boolean font_changed; |
---|
259 | { |
---|
260 | int i; |
---|
261 | static Boolean ever = False; |
---|
262 | |
---|
263 | if (!ever) { |
---|
264 | a_not_connected = make_amsg("statusNotConnected"); |
---|
265 | disc_msg = make_emsg(disc_pfx, "statusNotConnected", |
---|
266 | &disc_len); |
---|
267 | a_connecting = make_amsg("statusConnecting"); |
---|
268 | cnct_msg = make_emsg(cnct_pfx, "statusConnecting", &cnct_len); |
---|
269 | a_inhibit = make_amsg("statusInhibit"); |
---|
270 | a_twait = make_amsg("statusTwait"); |
---|
271 | a_syswait = make_amsg("statusSyswait"); |
---|
272 | a_protected = make_amsg("statusProtected"); |
---|
273 | a_numeric = make_amsg("statusNumeric"); |
---|
274 | a_overflow = make_amsg("statusOverflow"); |
---|
275 | a_scrolled = make_amsg("statusScrolled"); |
---|
276 | ever = True; |
---|
277 | } |
---|
278 | if (font_changed) |
---|
279 | nullblank = *standard_font ? ' ' : CG_space; |
---|
280 | if (font_changed || model_changed) { |
---|
281 | status_y = STATUS_Y; |
---|
282 | if (!(*efontinfo)->descent) |
---|
283 | ++status_y; |
---|
284 | } |
---|
285 | if (model_changed) { |
---|
286 | if (status_line) |
---|
287 | XtFree((char *)status_line); |
---|
288 | status_line = (struct status_line *) XtCalloc(sizeof(struct status_line), SSZ); |
---|
289 | if (status_2b != (XChar2b *)NULL) |
---|
290 | XtFree((char *)status_2b); |
---|
291 | status_2b = (XChar2b *)XtCalloc(sizeof(XChar2b), maxCOLS); |
---|
292 | if (status_1b != (unsigned char *)NULL) |
---|
293 | XtFree((char *)status_1b); |
---|
294 | status_1b = (unsigned char *)XtCalloc(sizeof(unsigned char), |
---|
295 | maxCOLS); |
---|
296 | if (display_2b != (XChar2b *)NULL) |
---|
297 | XtFree((XtPointer)display_2b); |
---|
298 | display_2b = (XChar2b *)XtCalloc(sizeof(XChar2b), maxCOLS); |
---|
299 | offsets[SSZ] = maxCOLS; |
---|
300 | if (appres.mono) |
---|
301 | colors[1] = FA_INT_NORM_NSEL; |
---|
302 | for (i = 0; i < SSZ; i++) { |
---|
303 | status_line[i].color = appres.m3279 ? |
---|
304 | colors3279[i] : colors[i]; |
---|
305 | status_line[i].start = offsets[i]; |
---|
306 | status_line[i].len = offsets[i+1] - offsets[i]; |
---|
307 | status_line[i].s2b = status_2b + offsets[i]; |
---|
308 | status_line[i].s1b = status_1b + offsets[i]; |
---|
309 | status_line[i].d2b = display_2b + offsets[i]; |
---|
310 | } |
---|
311 | } else |
---|
312 | (void) memset(display_2b, 0, maxCOLS * sizeof(XChar2b)); |
---|
313 | |
---|
314 | for (i = 0; i < SSZ; i++) |
---|
315 | status_line[i].changed = keep_contents; |
---|
316 | status_changed = keep_contents; |
---|
317 | |
---|
318 | /* |
---|
319 | * If reinitializing, redo the whole line, in case we switched between |
---|
320 | * a 3270 font and a standard font. |
---|
321 | */ |
---|
322 | if (keep_contents && font_changed) { |
---|
323 | do_ctlr(); |
---|
324 | paint_msg(oia_msg); |
---|
325 | do_insert(oia_insert); |
---|
326 | do_reverse(oia_reverse); |
---|
327 | do_kmap(oia_kmap); |
---|
328 | do_script(oia_script); |
---|
329 | do_shift(oia_shift); |
---|
330 | do_typeahead(oia_typeahead); |
---|
331 | do_compose(oia_compose, oia_compose_char, oia_compose_keytype); |
---|
332 | do_cursor(oia_cursor); |
---|
333 | do_timing(oia_timing); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | /* Render the status line onto the screen */ |
---|
338 | void |
---|
339 | status_disp() |
---|
340 | { |
---|
341 | int i; |
---|
342 | |
---|
343 | if (!status_changed) |
---|
344 | return; |
---|
345 | for (i = 0; i < SSZ; i++) |
---|
346 | if (status_line[i].changed) { |
---|
347 | status_render(i); |
---|
348 | (void) MEMORY_MOVE(status_line[i].d2b, |
---|
349 | (char *) status_line[i].s2b, |
---|
350 | status_line[i].len * sizeof(XChar2b)); |
---|
351 | status_line[i].changed = False; |
---|
352 | } |
---|
353 | status_changed = False; |
---|
354 | } |
---|
355 | |
---|
356 | /* Mark the entire status line as changed */ |
---|
357 | void |
---|
358 | status_touch() |
---|
359 | { |
---|
360 | int i; |
---|
361 | |
---|
362 | for (i = 0; i < SSZ; i++) { |
---|
363 | status_line[i].changed = True; |
---|
364 | (void) memset(status_line[i].d2b, 0, |
---|
365 | status_line[i].len * sizeof(XChar2b)); |
---|
366 | } |
---|
367 | status_changed = True; |
---|
368 | } |
---|
369 | |
---|
370 | /* Initialize the controller status */ |
---|
371 | void |
---|
372 | status_ctlr_init() |
---|
373 | { |
---|
374 | oia_undera = True; |
---|
375 | do_ctlr(); |
---|
376 | } |
---|
377 | |
---|
378 | /* Keyboard lock status changed */ |
---|
379 | void |
---|
380 | status_kybdlock() |
---|
381 | { |
---|
382 | /* presently implemented as explicit calls */ |
---|
383 | } |
---|
384 | |
---|
385 | /* Connected or disconnected */ |
---|
386 | void |
---|
387 | status_connect() |
---|
388 | { |
---|
389 | if (CONNECTED) { |
---|
390 | oia_boxsolid = True; |
---|
391 | do_ctlr(); |
---|
392 | if (kybdlock & KL_AWAITING_FIRST) |
---|
393 | do_msg(NONSPECIFIC); |
---|
394 | else |
---|
395 | do_msg(BLANK); |
---|
396 | status_untiming(); |
---|
397 | } else if (HALF_CONNECTED) { |
---|
398 | oia_boxsolid = False; |
---|
399 | do_ctlr(); |
---|
400 | do_msg(CONNECTING); |
---|
401 | status_untiming(); |
---|
402 | status_uncursor_pos(); |
---|
403 | } else { /* not connected */ |
---|
404 | oia_boxsolid = False; |
---|
405 | do_ctlr(); |
---|
406 | do_msg(DISCONNECTED); |
---|
407 | status_uncursor_pos(); |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | /* Lock the keyboard (twait) */ |
---|
412 | void |
---|
413 | status_twait() |
---|
414 | { |
---|
415 | oia_undera = False; |
---|
416 | do_ctlr(); |
---|
417 | do_msg(TWAIT); |
---|
418 | } |
---|
419 | |
---|
420 | /* Done with controller confirmation */ |
---|
421 | void |
---|
422 | status_ctlr_done() |
---|
423 | { |
---|
424 | oia_undera = True; |
---|
425 | do_ctlr(); |
---|
426 | } |
---|
427 | |
---|
428 | /* Lock the keyboard (X SYSTEM) */ |
---|
429 | void |
---|
430 | status_syswait() |
---|
431 | { |
---|
432 | do_msg(SYSWAIT); |
---|
433 | } |
---|
434 | |
---|
435 | /* Lock the keyboard (operator error) */ |
---|
436 | void |
---|
437 | status_oerr(error_type) |
---|
438 | int error_type; |
---|
439 | { |
---|
440 | switch (error_type) { |
---|
441 | case KL_OERR_PROTECTED: |
---|
442 | do_msg(PROTECTED); |
---|
443 | break; |
---|
444 | case KL_OERR_NUMERIC: |
---|
445 | do_msg(NUMERIC); |
---|
446 | break; |
---|
447 | case KL_OERR_OVERFLOW: |
---|
448 | do_msg(OVERFLOW); |
---|
449 | break; |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | /* Lock the keyboard (X Scrolled) */ |
---|
454 | void |
---|
455 | status_scrolled(n) |
---|
456 | int n; |
---|
457 | { |
---|
458 | if (n != 0) { |
---|
459 | if (!msg_is_saved) { |
---|
460 | saved_msg = oia_msg; |
---|
461 | msg_is_saved = True; |
---|
462 | } |
---|
463 | n_scrolled = n; |
---|
464 | paint_msg(SCROLLED); |
---|
465 | } else { |
---|
466 | if (msg_is_saved) { |
---|
467 | msg_is_saved = False; |
---|
468 | paint_msg(saved_msg); |
---|
469 | } |
---|
470 | } |
---|
471 | } |
---|
472 | |
---|
473 | /* Unlock the keyboard */ |
---|
474 | void |
---|
475 | status_reset() |
---|
476 | { |
---|
477 | if (kybdlock & KL_ENTER_INHIBIT) |
---|
478 | do_msg(INHIBIT); |
---|
479 | else if (kybdlock & KL_DEFERRED_UNLOCK) |
---|
480 | do_msg(NONSPECIFIC); |
---|
481 | else |
---|
482 | do_msg(BLANK); |
---|
483 | } |
---|
484 | |
---|
485 | /* Toggle insert mode */ |
---|
486 | void |
---|
487 | status_insert_mode(on) |
---|
488 | Boolean on; |
---|
489 | { |
---|
490 | do_insert(oia_insert = on); |
---|
491 | } |
---|
492 | |
---|
493 | /* Toggle reverse mode */ |
---|
494 | void |
---|
495 | status_reverse_mode(on) |
---|
496 | Boolean on; |
---|
497 | { |
---|
498 | do_reverse(oia_reverse = on); |
---|
499 | } |
---|
500 | |
---|
501 | /* Toggle kmap mode */ |
---|
502 | void |
---|
503 | status_kmap(on) |
---|
504 | Boolean on; |
---|
505 | { |
---|
506 | do_kmap(oia_kmap = on); |
---|
507 | } |
---|
508 | |
---|
509 | /* Toggle script mode */ |
---|
510 | void |
---|
511 | status_script(on) |
---|
512 | Boolean on; |
---|
513 | { |
---|
514 | do_script(oia_script = on); |
---|
515 | } |
---|
516 | |
---|
517 | /* Toggle shift mode */ |
---|
518 | void |
---|
519 | status_shift_mode(state) |
---|
520 | int state; |
---|
521 | { |
---|
522 | do_shift(oia_shift = state); |
---|
523 | } |
---|
524 | |
---|
525 | /* Toggle typeahead */ |
---|
526 | void |
---|
527 | status_typeahead(on) |
---|
528 | Boolean on; |
---|
529 | { |
---|
530 | do_typeahead(oia_typeahead = on); |
---|
531 | } |
---|
532 | |
---|
533 | /* Set compose character */ |
---|
534 | void |
---|
535 | status_compose(on, c, keytype) |
---|
536 | Boolean on; |
---|
537 | unsigned char c; |
---|
538 | enum keytype keytype; |
---|
539 | { |
---|
540 | oia_compose = on; |
---|
541 | oia_compose_char = c; |
---|
542 | oia_compose_keytype = keytype; |
---|
543 | do_compose(on, c, keytype); |
---|
544 | } |
---|
545 | |
---|
546 | /* Display timing */ |
---|
547 | void |
---|
548 | status_timing(t0, t1) |
---|
549 | struct timeval *t0, *t1; |
---|
550 | { |
---|
551 | static char no_time[] = ":??.?"; |
---|
552 | static char buf[TCNT+1]; |
---|
553 | |
---|
554 | if (t1->tv_sec - t0->tv_sec > (99*60)) { |
---|
555 | do_timing(oia_timing = no_time); |
---|
556 | } else { |
---|
557 | unsigned long cs; /* centiseconds */ |
---|
558 | |
---|
559 | cs = (t1->tv_sec - t0->tv_sec) * 10 + |
---|
560 | (t1->tv_usec - t0->tv_usec + 50000) / 100000; |
---|
561 | if (cs < CM) |
---|
562 | (void) sprintf(buf, ":%02ld.%ld", cs / 10, cs % 10); |
---|
563 | else |
---|
564 | (void) sprintf(buf, "%02ld:%02ld", cs / CM, (cs % CM) / 10); |
---|
565 | do_timing(oia_timing = buf); |
---|
566 | } |
---|
567 | } |
---|
568 | |
---|
569 | /* Erase timing indication */ |
---|
570 | void |
---|
571 | status_untiming() |
---|
572 | { |
---|
573 | do_timing(oia_timing = (char *) 0); |
---|
574 | } |
---|
575 | |
---|
576 | /* Update cursor position */ |
---|
577 | void |
---|
578 | status_cursor_pos(ca) |
---|
579 | int ca; |
---|
580 | { |
---|
581 | static char buf[CCNT+1]; |
---|
582 | |
---|
583 | (void) sprintf(buf, "%03d/%03d", ca/COLS + 1, ca%COLS + 1); |
---|
584 | do_cursor(oia_cursor = buf); |
---|
585 | } |
---|
586 | |
---|
587 | /* Erase cursor position */ |
---|
588 | void |
---|
589 | status_uncursor_pos() |
---|
590 | { |
---|
591 | do_cursor(oia_cursor = (char *) 0); |
---|
592 | } |
---|
593 | |
---|
594 | |
---|
595 | /* Internal routines */ |
---|
596 | |
---|
597 | /* Update the status line by displaying "symbol" at column "col". */ |
---|
598 | static void |
---|
599 | status_add(col, symbol, keytype) |
---|
600 | int col; |
---|
601 | unsigned char symbol; |
---|
602 | enum keytype keytype; |
---|
603 | { |
---|
604 | int i; |
---|
605 | XChar2b n2b; |
---|
606 | |
---|
607 | n2b.byte1 = (keytype == KT_STD) ? 0 : 1; |
---|
608 | n2b.byte2 = symbol; |
---|
609 | if (status_2b[col].byte1 == n2b.byte1 && |
---|
610 | status_2b[col].byte2 == n2b.byte2) |
---|
611 | return; |
---|
612 | status_2b[col] = n2b; |
---|
613 | status_1b[col] = symbol; |
---|
614 | status_changed = True; |
---|
615 | for (i = 0; i < SSZ; i++) |
---|
616 | if (col >= status_line[i].start && |
---|
617 | col < status_line[i].start + status_line[i].len) { |
---|
618 | status_line[i].changed = True; |
---|
619 | return; |
---|
620 | } |
---|
621 | } |
---|
622 | |
---|
623 | /* |
---|
624 | * Render a region of the status line onto the display, the idea being to |
---|
625 | * minimize the number of redundant X drawing operations performed. |
---|
626 | * |
---|
627 | * What isn't optimized is what happens when "ABC" becomes "XBZ" -- should we |
---|
628 | * redundantly draw over B or not? Right now we don't. |
---|
629 | */ |
---|
630 | static void |
---|
631 | status_render(region) |
---|
632 | int region; |
---|
633 | { |
---|
634 | int i; |
---|
635 | struct status_line *sl = &status_line[region]; |
---|
636 | int nd = 0; |
---|
637 | int i0 = -1; |
---|
638 | |
---|
639 | /* The status region may change colors; don't be so clever */ |
---|
640 | if (region == WAIT_REGION) { |
---|
641 | XDrawImageString(display, *screen_window, screen_gc(sl->color), |
---|
642 | COL_TO_X(sl->start), status_y, (char *) sl->s1b, sl->len); |
---|
643 | } else { |
---|
644 | for (i = 0; i < sl->len; i++) { |
---|
645 | if (sl->s2b[i].byte1 == sl->d2b[i].byte1 && |
---|
646 | sl->s2b[i].byte2 == sl->d2b[i].byte2) { |
---|
647 | if (nd) { |
---|
648 | if (*extended_3270font) |
---|
649 | XDrawImageString16(display, |
---|
650 | *screen_window, |
---|
651 | screen_gc(sl->color), |
---|
652 | COL_TO_X(sl->start + i0), |
---|
653 | status_y, |
---|
654 | sl->s2b + i0, nd); |
---|
655 | else |
---|
656 | XDrawImageString(display, |
---|
657 | *screen_window, |
---|
658 | screen_gc(sl->color), |
---|
659 | COL_TO_X(sl->start + i0), |
---|
660 | status_y, |
---|
661 | (char *) sl->s1b + i0, nd); |
---|
662 | nd = 0; |
---|
663 | i0 = -1; |
---|
664 | } |
---|
665 | } else { |
---|
666 | if (!nd++) |
---|
667 | i0 = i; |
---|
668 | } |
---|
669 | } |
---|
670 | if (nd) { |
---|
671 | if (*extended_3270font) |
---|
672 | XDrawImageString16(display, *screen_window, |
---|
673 | screen_gc(sl->color), |
---|
674 | COL_TO_X(sl->start + i0), status_y, |
---|
675 | sl->s2b + i0, nd); |
---|
676 | else |
---|
677 | XDrawImageString(display, *screen_window, |
---|
678 | screen_gc(sl->color), |
---|
679 | COL_TO_X(sl->start + i0), status_y, |
---|
680 | (char *) sl->s1b + i0, nd); |
---|
681 | } |
---|
682 | } |
---|
683 | |
---|
684 | /* Leftmost region has unusual attributes */ |
---|
685 | if (*standard_font && region == CTLR_REGION) { |
---|
686 | XDrawImageString(display, *screen_window, |
---|
687 | screen_invgc(sl->color), |
---|
688 | COL_TO_X(sl->start + LBOX), status_y, |
---|
689 | (char *) sl->s1b + LBOX, 1); |
---|
690 | XDrawRectangle(display, *screen_window, screen_gc(sl->color), |
---|
691 | COL_TO_X(sl->start + CNCT), |
---|
692 | status_y - (*efontinfo)->ascent + *char_height - 1, |
---|
693 | *char_width - 1, 0); |
---|
694 | XDrawImageString(display, *screen_window, |
---|
695 | screen_invgc(sl->color), |
---|
696 | COL_TO_X(sl->start + RBOX), status_y, |
---|
697 | (char *) sl->s1b + RBOX, 1); |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | /* Write into the message area of the status line */ |
---|
702 | static void |
---|
703 | status_msg_set(msg, len) |
---|
704 | unsigned char *msg; |
---|
705 | int len; |
---|
706 | { |
---|
707 | register int i; |
---|
708 | |
---|
709 | for (i = 0; i < status_line[WAIT_REGION].len; i++) { |
---|
710 | status_add(M0+i, len ? msg[i] : nullblank, KT_STD); |
---|
711 | if (len) |
---|
712 | len--; |
---|
713 | } |
---|
714 | } |
---|
715 | |
---|
716 | /* Controller status */ |
---|
717 | static void |
---|
718 | do_ctlr() |
---|
719 | { |
---|
720 | if (*standard_font) { |
---|
721 | status_add(LBOX, '4', KT_STD); |
---|
722 | if (oia_undera) |
---|
723 | status_add(CNCT, 'A', KT_STD); |
---|
724 | else |
---|
725 | status_add(CNCT, ' ', KT_STD); |
---|
726 | if (oia_boxsolid) |
---|
727 | status_add(RBOX, ' ', KT_STD); |
---|
728 | else |
---|
729 | status_add(RBOX, '?', KT_STD); |
---|
730 | } else { |
---|
731 | status_add(LBOX, CG_box4, KT_STD); |
---|
732 | if (oia_undera) |
---|
733 | status_add(CNCT, CG_underA, KT_STD); |
---|
734 | else |
---|
735 | status_add(CNCT, CG_null, KT_STD); |
---|
736 | if (oia_boxsolid) |
---|
737 | status_add(RBOX, CG_boxsolid, KT_STD); |
---|
738 | else |
---|
739 | status_add(RBOX, CG_boxquestion, KT_STD); |
---|
740 | } |
---|
741 | } |
---|
742 | |
---|
743 | /* Message area */ |
---|
744 | |
---|
745 | /* Change the state of the message area, or if scrolled, the saved message */ |
---|
746 | static void |
---|
747 | do_msg(t) |
---|
748 | enum msg t; |
---|
749 | { |
---|
750 | if (msg_is_saved) { |
---|
751 | saved_msg = t; |
---|
752 | return; |
---|
753 | } |
---|
754 | paint_msg(t); |
---|
755 | } |
---|
756 | |
---|
757 | /* Paint the message area. */ |
---|
758 | static void |
---|
759 | paint_msg(t) |
---|
760 | enum msg t; |
---|
761 | { |
---|
762 | oia_msg = t; |
---|
763 | (*msg_proc[(int)t])(); |
---|
764 | if (!appres.mono) |
---|
765 | status_line[WAIT_REGION].color = appres.m3279 ? |
---|
766 | msg_color3279[(int)t] : msg_color[(int)t]; |
---|
767 | } |
---|
768 | |
---|
769 | static void |
---|
770 | do_blank() |
---|
771 | { |
---|
772 | status_msg_set((unsigned char *) 0, 0); |
---|
773 | } |
---|
774 | |
---|
775 | static void |
---|
776 | do_disconnected() |
---|
777 | { |
---|
778 | if (*standard_font) |
---|
779 | status_msg_set(a_not_connected, |
---|
780 | strlen((char *)a_not_connected)); |
---|
781 | else |
---|
782 | status_msg_set(disc_msg, disc_len); |
---|
783 | } |
---|
784 | |
---|
785 | static void |
---|
786 | do_connecting() |
---|
787 | { |
---|
788 | if (*standard_font) |
---|
789 | status_msg_set(a_connecting, strlen((char *)a_connecting)); |
---|
790 | else |
---|
791 | status_msg_set(cnct_msg, cnct_len); |
---|
792 | } |
---|
793 | |
---|
794 | static void |
---|
795 | do_nonspecific() |
---|
796 | { |
---|
797 | static unsigned char nonspecific[] = { |
---|
798 | CG_lock |
---|
799 | }; |
---|
800 | |
---|
801 | if (*standard_font) |
---|
802 | status_msg_set((unsigned char *)"X", 1); |
---|
803 | else |
---|
804 | status_msg_set(nonspecific, sizeof(nonspecific)); |
---|
805 | } |
---|
806 | |
---|
807 | static void |
---|
808 | do_inhibit() |
---|
809 | { |
---|
810 | static unsigned char inhibit[] = { |
---|
811 | CG_lock, CG_space, CG_I, CG_n, CG_h, CG_i, CG_b, CG_i, CG_t |
---|
812 | }; |
---|
813 | |
---|
814 | if (*standard_font) |
---|
815 | status_msg_set(a_inhibit, strlen((char *)a_inhibit)); |
---|
816 | else |
---|
817 | status_msg_set(inhibit, sizeof(inhibit)); |
---|
818 | } |
---|
819 | |
---|
820 | static void |
---|
821 | do_twait() |
---|
822 | { |
---|
823 | static unsigned char twait[] = { |
---|
824 | CG_lock, CG_space, CG_clockleft, CG_clockright |
---|
825 | }; |
---|
826 | |
---|
827 | if (*standard_font) |
---|
828 | status_msg_set(a_twait, strlen((char *)a_twait)); |
---|
829 | else |
---|
830 | status_msg_set(twait, sizeof(twait)); |
---|
831 | } |
---|
832 | |
---|
833 | static void |
---|
834 | do_syswait() |
---|
835 | { |
---|
836 | static unsigned char syswait[] = { |
---|
837 | CG_lock, CG_space, CG_S, CG_Y, CG_S, CG_T, CG_E, CG_M |
---|
838 | }; |
---|
839 | |
---|
840 | if (*standard_font) |
---|
841 | status_msg_set(a_syswait, strlen((char *)a_syswait)); |
---|
842 | else |
---|
843 | status_msg_set(syswait, sizeof(syswait)); |
---|
844 | } |
---|
845 | |
---|
846 | static void |
---|
847 | do_protected() |
---|
848 | { |
---|
849 | static unsigned char protected[] = { |
---|
850 | CG_lock, CG_space, CG_leftarrow, CG_human, CG_rightarrow |
---|
851 | }; |
---|
852 | |
---|
853 | if (*standard_font) |
---|
854 | status_msg_set(a_protected, strlen((char *)a_protected)); |
---|
855 | else |
---|
856 | status_msg_set(protected, sizeof(protected)); |
---|
857 | } |
---|
858 | |
---|
859 | static void |
---|
860 | do_numeric() |
---|
861 | { |
---|
862 | static unsigned char numeric[] = { |
---|
863 | CG_lock, CG_space, CG_human, CG_N, CG_U, CG_M |
---|
864 | }; |
---|
865 | |
---|
866 | if (*standard_font) |
---|
867 | status_msg_set(a_numeric, strlen((char *)a_numeric)); |
---|
868 | else |
---|
869 | status_msg_set(numeric, sizeof(numeric)); |
---|
870 | } |
---|
871 | |
---|
872 | static void |
---|
873 | do_overflow() |
---|
874 | { |
---|
875 | static unsigned char overflow[] = { |
---|
876 | CG_lock, CG_space, CG_human, CG_greater |
---|
877 | }; |
---|
878 | |
---|
879 | if (*standard_font) |
---|
880 | status_msg_set(a_overflow, strlen((char *)a_overflow)); |
---|
881 | else |
---|
882 | status_msg_set(overflow, sizeof(overflow)); |
---|
883 | } |
---|
884 | |
---|
885 | static void |
---|
886 | do_scrolled() |
---|
887 | { |
---|
888 | static unsigned char scrolled[] = { |
---|
889 | CG_lock, CG_space, CG_S, CG_c, CG_r, CG_o, CG_l, CG_l, CG_e, |
---|
890 | CG_d, CG_space, CG_space, CG_space, CG_space, CG_space |
---|
891 | }; |
---|
892 | static unsigned char spaces[] = { |
---|
893 | CG_space, CG_space, CG_space, CG_space |
---|
894 | }; |
---|
895 | |
---|
896 | if (*standard_font) { |
---|
897 | char *t; |
---|
898 | |
---|
899 | t = XtMalloc(strlen((char *)a_scrolled) + 4); |
---|
900 | (void) sprintf(t, "%s %d", (char *)a_scrolled, n_scrolled); |
---|
901 | status_msg_set((unsigned char *)t, strlen(t)); |
---|
902 | XtFree(t); |
---|
903 | } else { |
---|
904 | char nnn[5]; |
---|
905 | int i; |
---|
906 | |
---|
907 | (void) sprintf(nnn, "%d", n_scrolled); |
---|
908 | (void) memcpy((char *)&scrolled[11], (char *)spaces, |
---|
909 | sizeof(spaces)); |
---|
910 | for (i = 0; nnn[i]; i++) |
---|
911 | scrolled[11 + i] = asc2cg[(int)nnn[i]]; |
---|
912 | status_msg_set(scrolled, sizeof(scrolled)); |
---|
913 | } |
---|
914 | } |
---|
915 | |
---|
916 | /* Insert, reverse, kmap, script, shift, compose */ |
---|
917 | |
---|
918 | static void |
---|
919 | do_insert(on) |
---|
920 | Boolean on; |
---|
921 | { |
---|
922 | status_add(INSERT, on ? (*standard_font ? 'I' : CG_insert) : nullblank, KT_STD); |
---|
923 | } |
---|
924 | |
---|
925 | static void |
---|
926 | do_reverse(on) |
---|
927 | Boolean on; |
---|
928 | { |
---|
929 | status_add(REVERSE, on ? (*standard_font ? 'R' : CG_R) : nullblank, KT_STD); |
---|
930 | } |
---|
931 | |
---|
932 | static void |
---|
933 | do_kmap(on) |
---|
934 | Boolean on; |
---|
935 | { |
---|
936 | status_add(KMAP, on ? (*standard_font ? 'K' : CG_K) : nullblank, KT_STD); |
---|
937 | } |
---|
938 | |
---|
939 | static void |
---|
940 | do_script(on) |
---|
941 | Boolean on; |
---|
942 | { |
---|
943 | status_add(SCRIPT, on ? (*standard_font ? 'S' : CG_S) : nullblank, KT_STD); |
---|
944 | } |
---|
945 | |
---|
946 | static void |
---|
947 | do_shift(state) |
---|
948 | int state; |
---|
949 | { |
---|
950 | status_add(SHIFT-2, (state & MetaKeyDown) ? |
---|
951 | (*standard_font ? 'M' : CG_M) : nullblank, KT_STD); |
---|
952 | status_add(SHIFT-1, (state & AltKeyDown) ? |
---|
953 | (*standard_font ? 'A' : CG_A) : nullblank, KT_STD); |
---|
954 | status_add(SHIFT, (state & ShiftKeyDown) ? |
---|
955 | (*standard_font ? '^' : CG_upshift) : nullblank, KT_STD); |
---|
956 | } |
---|
957 | |
---|
958 | static void |
---|
959 | do_typeahead(state) |
---|
960 | int state; |
---|
961 | { |
---|
962 | status_add(TYPEAHD, state ? (*standard_font ? 'T' : CG_T) : nullblank, KT_STD); |
---|
963 | } |
---|
964 | |
---|
965 | static void |
---|
966 | do_compose(on, c, keytype) |
---|
967 | Boolean on; |
---|
968 | unsigned char c; |
---|
969 | enum keytype keytype; |
---|
970 | { |
---|
971 | if (on) { |
---|
972 | status_add(COMPOSE, |
---|
973 | (unsigned char)(*standard_font ? 'C' : CG_C), KT_STD); |
---|
974 | status_add(COMPOSE+1, |
---|
975 | c ? (*standard_font ? c : asc2cg[c]) : nullblank, keytype); |
---|
976 | } else { |
---|
977 | status_add(COMPOSE, nullblank, KT_STD); |
---|
978 | status_add(COMPOSE+1, nullblank, KT_STD); |
---|
979 | } |
---|
980 | } |
---|
981 | |
---|
982 | /* Timing */ |
---|
983 | static void |
---|
984 | do_timing(buf) |
---|
985 | char *buf; |
---|
986 | { |
---|
987 | register int i; |
---|
988 | |
---|
989 | if (buf) { |
---|
990 | if (*standard_font) { |
---|
991 | status_add(T0, nullblank, KT_STD); |
---|
992 | status_add(T0+1, nullblank, KT_STD); |
---|
993 | } else { |
---|
994 | status_add(T0, CG_clockleft, KT_STD); |
---|
995 | status_add(T0+1, CG_clockright, KT_STD); |
---|
996 | } |
---|
997 | for (i = 0; i < (int) strlen(buf); i++) |
---|
998 | status_add(T0+2+i, *standard_font ? buf[i] : asc2cg[(unsigned char) buf[i]], KT_STD); |
---|
999 | } else |
---|
1000 | for (i = 0; i < TCNT; i++) |
---|
1001 | status_add(T0+i, nullblank, KT_STD); |
---|
1002 | } |
---|
1003 | |
---|
1004 | /* Cursor position */ |
---|
1005 | static void |
---|
1006 | do_cursor(buf) |
---|
1007 | char *buf; |
---|
1008 | { |
---|
1009 | register int i; |
---|
1010 | |
---|
1011 | if (buf) |
---|
1012 | for (i = 0; i < (int) strlen(buf); i++) |
---|
1013 | status_add(C0+i, *standard_font ? buf[i] : asc2cg[(unsigned char) buf[i]], KT_STD); |
---|
1014 | else |
---|
1015 | for (i = 0; i < CCNT; i++) |
---|
1016 | status_add(C0+i, nullblank, KT_STD); |
---|
1017 | } |
---|
1018 | |
---|
1019 | /* Prepare status messages */ |
---|
1020 | |
---|
1021 | static unsigned char * |
---|
1022 | make_amsg(key) |
---|
1023 | char *key; |
---|
1024 | { |
---|
1025 | return (unsigned char *)xs_buffer("X %s", get_message(key)); |
---|
1026 | } |
---|
1027 | |
---|
1028 | static unsigned char * |
---|
1029 | make_emsg(prefix, key, len) |
---|
1030 | unsigned char prefix[]; |
---|
1031 | char *key; |
---|
1032 | int *len; |
---|
1033 | { |
---|
1034 | char *text = get_message(key); |
---|
1035 | unsigned char *buf = (unsigned char *) XtMalloc(*len + strlen(key)); |
---|
1036 | |
---|
1037 | (void) MEMORY_MOVE((char *)buf, (char *) prefix, *len); |
---|
1038 | while (*text) |
---|
1039 | buf[(*len)++] = asc2cg[(int)*text++]; |
---|
1040 | |
---|
1041 | return buf; |
---|
1042 | } |
---|