1 | /* |
---|
2 | * Copyright 1993, 1994, 1995 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 | * about.c |
---|
12 | * Pop-up window with the current state of x3270. |
---|
13 | */ |
---|
14 | |
---|
15 | #include "globals.h" |
---|
16 | #include <X11/Shell.h> |
---|
17 | #include <X11/StringDefs.h> |
---|
18 | #include <X11/Xaw/Command.h> |
---|
19 | #include <X11/Xaw/Form.h> |
---|
20 | #include <X11/Xaw/Label.h> |
---|
21 | #include "appres.h" |
---|
22 | #include "objects.h" |
---|
23 | |
---|
24 | #include "aboutc.h" |
---|
25 | #include "popupsc.h" |
---|
26 | #include "telnetc.h" |
---|
27 | #include "utilc.h" |
---|
28 | |
---|
29 | static Widget about_shell = NULL; |
---|
30 | static Widget about_form; |
---|
31 | extern time_t ns_time; |
---|
32 | extern int ns_brcvd; |
---|
33 | extern int ns_rrcvd; |
---|
34 | extern int ns_bsent; |
---|
35 | extern int ns_rsent; |
---|
36 | extern int linemode; |
---|
37 | extern char *build; |
---|
38 | extern Pixmap icon; |
---|
39 | extern struct trans_list *temp_keymaps; |
---|
40 | |
---|
41 | /* Called when OK is pressed on the about popup */ |
---|
42 | /*ARGSUSED*/ |
---|
43 | static void |
---|
44 | saw_about(w, client_data, call_data) |
---|
45 | Widget w; |
---|
46 | XtPointer client_data; |
---|
47 | XtPointer call_data; |
---|
48 | { |
---|
49 | XtPopdown(about_shell); |
---|
50 | } |
---|
51 | |
---|
52 | /* Called when the about popup is popped down */ |
---|
53 | /*ARGSUSED*/ |
---|
54 | static void |
---|
55 | destroy_about(w, client_data, call_data) |
---|
56 | Widget w; |
---|
57 | XtPointer client_data; |
---|
58 | XtPointer call_data; |
---|
59 | { |
---|
60 | XtDestroyWidget(about_shell); |
---|
61 | about_shell = NULL; |
---|
62 | } |
---|
63 | |
---|
64 | /* Return a time difference in English */ |
---|
65 | static char * |
---|
66 | hms(ts) |
---|
67 | time_t ts; |
---|
68 | { |
---|
69 | time_t t, td; |
---|
70 | long hr, mn, sc; |
---|
71 | static char buf[128]; |
---|
72 | |
---|
73 | (void) time(&t); |
---|
74 | |
---|
75 | td = t - ts; |
---|
76 | hr = td / 3600; |
---|
77 | mn = (td % 3600) / 60; |
---|
78 | sc = td % 60; |
---|
79 | |
---|
80 | if (hr > 0) |
---|
81 | (void) sprintf(buf, "%ld %s %ld %s %ld %s", |
---|
82 | hr, (hr == 1) ? |
---|
83 | get_message("hour") : get_message("hours"), |
---|
84 | mn, (mn == 1) ? |
---|
85 | get_message("minute") : get_message("minutes"), |
---|
86 | sc, (sc == 1) ? |
---|
87 | get_message("second") : get_message("seconds")); |
---|
88 | else if (mn > 0) |
---|
89 | (void) sprintf(buf, "%ld %s %ld %s", |
---|
90 | mn, (mn == 1) ? |
---|
91 | get_message("minute") : get_message("minutes"), |
---|
92 | sc, (sc == 1) ? |
---|
93 | get_message("second") : get_message("seconds")); |
---|
94 | else |
---|
95 | (void) sprintf(buf, "%ld %s", |
---|
96 | sc, (sc == 1) ? |
---|
97 | get_message("second") : get_message("seconds")); |
---|
98 | |
---|
99 | return buf; |
---|
100 | } |
---|
101 | |
---|
102 | #define MAKE_SMALL(label, n) { \ |
---|
103 | w_prev = w; \ |
---|
104 | w = XtVaCreateManagedWidget( \ |
---|
105 | ObjSmallLabel, labelWidgetClass, about_form, \ |
---|
106 | XtNborderWidth, 0, \ |
---|
107 | XtNlabel, label, \ |
---|
108 | XtNfromVert, w, \ |
---|
109 | XtNleft, XtChainLeft, \ |
---|
110 | XtNvertDistance, (n), \ |
---|
111 | NULL); \ |
---|
112 | vd = n; \ |
---|
113 | } |
---|
114 | |
---|
115 | #define MAKE_LABEL(label, n) { \ |
---|
116 | w_prev = w; \ |
---|
117 | w = XtVaCreateManagedWidget( \ |
---|
118 | ObjNameLabel, labelWidgetClass, about_form, \ |
---|
119 | XtNborderWidth, 0, \ |
---|
120 | XtNlabel, label, \ |
---|
121 | XtNfromVert, w, \ |
---|
122 | XtNfromHoriz, left_anchor, \ |
---|
123 | XtNleft, XtChainLeft, \ |
---|
124 | XtNvertDistance, (n), \ |
---|
125 | NULL); \ |
---|
126 | vd = n; \ |
---|
127 | } |
---|
128 | |
---|
129 | #define MAKE_VALUE(label) { \ |
---|
130 | v = XtVaCreateManagedWidget( \ |
---|
131 | ObjDataLabel, labelWidgetClass, about_form, \ |
---|
132 | XtNborderWidth, 0, \ |
---|
133 | XtNlabel, label, \ |
---|
134 | XtNfromVert, w_prev, \ |
---|
135 | XtNfromHoriz, w, \ |
---|
136 | XtNhorizDistance, 0, \ |
---|
137 | XtNvertDistance, vd, \ |
---|
138 | XtNleft, XtChainLeft, \ |
---|
139 | NULL); \ |
---|
140 | } |
---|
141 | |
---|
142 | #define MAKE_LABEL2(label) { \ |
---|
143 | w = XtVaCreateManagedWidget( \ |
---|
144 | ObjNameLabel, labelWidgetClass, about_form, \ |
---|
145 | XtNborderWidth, 0, \ |
---|
146 | XtNlabel, label, \ |
---|
147 | XtNfromVert, w_prev, \ |
---|
148 | XtNfromHoriz, v, \ |
---|
149 | XtNhorizDistance, 0, \ |
---|
150 | XtNvertDistance, vd, \ |
---|
151 | XtNleft, XtChainLeft, \ |
---|
152 | NULL); \ |
---|
153 | } |
---|
154 | |
---|
155 | /* Called when the "About x3270..." button is pressed */ |
---|
156 | void |
---|
157 | popup_about() |
---|
158 | { |
---|
159 | Widget w = NULL, w_prev = NULL; |
---|
160 | Widget v = NULL; |
---|
161 | Widget left_anchor = NULL; |
---|
162 | int vd = 4; |
---|
163 | char fbuf[1024]; |
---|
164 | char *ftype; |
---|
165 | char *xbuf; |
---|
166 | |
---|
167 | /* Create the popup */ |
---|
168 | |
---|
169 | about_shell = XtVaCreatePopupShell( |
---|
170 | "aboutPopup", transientShellWidgetClass, toplevel, |
---|
171 | NULL); |
---|
172 | XtAddCallback(about_shell, XtNpopupCallback, place_popup, |
---|
173 | (XtPointer) CenterP); |
---|
174 | XtAddCallback(about_shell, XtNpopdownCallback, destroy_about, |
---|
175 | NULL); |
---|
176 | |
---|
177 | /* Create a form in the popup */ |
---|
178 | |
---|
179 | about_form = XtVaCreateManagedWidget( |
---|
180 | "dialog", formWidgetClass, about_shell, |
---|
181 | NULL); |
---|
182 | |
---|
183 | /* Pretty picture */ |
---|
184 | |
---|
185 | left_anchor = XtVaCreateManagedWidget( |
---|
186 | "icon", labelWidgetClass, about_form, |
---|
187 | XtNborderWidth, 0, |
---|
188 | XtNbitmap, icon, |
---|
189 | XtNfromVert, w, |
---|
190 | XtNleft, XtChainLeft, |
---|
191 | NULL); |
---|
192 | |
---|
193 | /* Miscellany */ |
---|
194 | |
---|
195 | MAKE_LABEL(build, 4); |
---|
196 | MAKE_LABEL(get_message("processId"), 4); |
---|
197 | (void) sprintf(fbuf, "%d", getpid()); |
---|
198 | MAKE_VALUE(fbuf); |
---|
199 | MAKE_LABEL2(get_message("windowId")); |
---|
200 | (void) sprintf(fbuf, "0x%lx", XtWindow(toplevel)); |
---|
201 | MAKE_VALUE(fbuf); |
---|
202 | |
---|
203 | /* Everything else at the left margin under the bitmap */ |
---|
204 | w = left_anchor; |
---|
205 | left_anchor = NULL; |
---|
206 | |
---|
207 | MAKE_SMALL("Modifications Copyright \251 1993, 1994, 1995, 1996, 1997 by Paul Mattes.\n\ |
---|
208 | Original X11 Port Copyright \251 1990 by Jeff Sparkes.\n\ |
---|
209 | File transfer code Copyright \251 1995 by Dick Altenbern.\n\ |
---|
210 | Permission to use, copy, modify, and distribute this software and its documentation\n\ |
---|
211 | for any purpose and without fee is hereby granted, provided that the above copyright\n\ |
---|
212 | notice appear in all copies and that both that copyright notice and this permission\n\ |
---|
213 | notice appear in supporting documentation.\n\ |
---|
214 | \n\ |
---|
215 | Copyright \251 1989 by Georgia Tech Research Corporation, Atlanta, GA 30332.\n\ |
---|
216 | All Rights Reserved. GTRC hereby grants public use of this software. Derivative\n\ |
---|
217 | works based on this software must incorporate this copyright notice.", 4); |
---|
218 | |
---|
219 | (void) sprintf(fbuf, "%s %s: %d %s x %d %s, %s, %s", |
---|
220 | get_message("model"), model_name, |
---|
221 | maxCOLS, get_message("columns"), |
---|
222 | maxROWS, get_message("rows"), |
---|
223 | appres.mono ? get_message("mono") : |
---|
224 | (appres.m3279 ? get_message("fullColor") : |
---|
225 | get_message("pseudoColor")), |
---|
226 | (appres.extended && !std_ds_host) ? get_message("extendedDs") : |
---|
227 | get_message("standardDs")); |
---|
228 | MAKE_LABEL(fbuf, 4); |
---|
229 | |
---|
230 | MAKE_LABEL(get_message("terminalName"), 4); |
---|
231 | MAKE_VALUE(termtype); |
---|
232 | |
---|
233 | MAKE_LABEL(get_message("emulatorFont"), 4); |
---|
234 | MAKE_VALUE(efontname); |
---|
235 | if (*standard_font) { |
---|
236 | if (*latin1_font) |
---|
237 | ftype = get_message("fullFont"); |
---|
238 | else |
---|
239 | ftype = get_message("asciiFont"); |
---|
240 | } else |
---|
241 | ftype = get_message("cgFont"); |
---|
242 | xbuf = xs_buffer(" %s", ftype); |
---|
243 | MAKE_LABEL(xbuf, 0); |
---|
244 | XtFree(xbuf); |
---|
245 | |
---|
246 | if (appres.charset) { |
---|
247 | MAKE_LABEL(get_message("characterSet"), 4); |
---|
248 | MAKE_VALUE(appres.charset); |
---|
249 | } else |
---|
250 | MAKE_LABEL(get_message("defaultCharacterSet"), 4); |
---|
251 | |
---|
252 | if (trans_list != (struct trans_list *)NULL || |
---|
253 | temp_keymaps != (struct trans_list *)NULL) { |
---|
254 | struct trans_list *t; |
---|
255 | |
---|
256 | fbuf[0] = '\0'; |
---|
257 | for (t = trans_list; t; t = t->next) { |
---|
258 | if (fbuf[0]) |
---|
259 | (void) strcat(fbuf, ","); |
---|
260 | (void) strcat(fbuf, t->name); |
---|
261 | } |
---|
262 | for (t = temp_keymaps; t; t = t->next) { |
---|
263 | if (fbuf[0]) |
---|
264 | (void) strcat(fbuf, " "); |
---|
265 | (void) strcat(fbuf, "+"); |
---|
266 | (void) strcat(fbuf, t->name); |
---|
267 | } |
---|
268 | MAKE_LABEL(get_message("keyboardMap"), 4) |
---|
269 | MAKE_VALUE(fbuf); |
---|
270 | } else |
---|
271 | MAKE_LABEL(get_message("defaultKeyboardMap"), 4); |
---|
272 | if (appres.compose_map) { |
---|
273 | MAKE_LABEL(get_message("composeMap"), 4); |
---|
274 | MAKE_VALUE(appres.compose_map); |
---|
275 | } else { |
---|
276 | MAKE_LABEL(get_message("noComposeMap"), 4); |
---|
277 | } |
---|
278 | |
---|
279 | if (appres.active_icon) { |
---|
280 | MAKE_LABEL(get_message("activeIcon"), 4); |
---|
281 | xbuf = xs_buffer(" %s", get_message("iconFont")); |
---|
282 | MAKE_LABEL(xbuf, 0); |
---|
283 | XtFree(xbuf); |
---|
284 | MAKE_VALUE(appres.icon_font); |
---|
285 | if (appres.label_icon) { |
---|
286 | xbuf = xs_buffer(" %s", get_message("iconLabelFont")); |
---|
287 | MAKE_LABEL(xbuf, 0); |
---|
288 | XtFree(xbuf); |
---|
289 | MAKE_VALUE(appres.icon_label_font); |
---|
290 | } |
---|
291 | } else |
---|
292 | MAKE_LABEL(get_message("staticIcon"), 4); |
---|
293 | |
---|
294 | if (CONNECTED) { |
---|
295 | MAKE_LABEL(get_message("connectedTo"), 4); |
---|
296 | MAKE_VALUE(current_host); |
---|
297 | (void) sprintf(fbuf, " %s", get_message("port")); |
---|
298 | MAKE_LABEL2(fbuf); |
---|
299 | (void) sprintf(fbuf, "%d", current_port); |
---|
300 | MAKE_VALUE(fbuf); |
---|
301 | if (IN_ANSI) { |
---|
302 | if (linemode) |
---|
303 | ftype = get_message("lineMode"); |
---|
304 | else |
---|
305 | ftype = get_message("charMode"); |
---|
306 | } else |
---|
307 | ftype = get_message("dsMode"); |
---|
308 | (void) sprintf(fbuf, " %s, ", ftype); |
---|
309 | (void) strcat(fbuf, hms(ns_time)); |
---|
310 | |
---|
311 | MAKE_LABEL(fbuf, 0); |
---|
312 | |
---|
313 | if (IN_3270) |
---|
314 | (void) sprintf(fbuf, "%s %d %s, %d %s\n%s %d %s, %d %s", |
---|
315 | get_message("sent"), |
---|
316 | ns_bsent, (ns_bsent == 1) ? |
---|
317 | get_message("byte") : get_message("bytes"), |
---|
318 | ns_rsent, (ns_rsent == 1) ? |
---|
319 | get_message("record") : get_message("records"), |
---|
320 | get_message("Received"), |
---|
321 | ns_brcvd, (ns_brcvd == 1) ? |
---|
322 | get_message("byte") : get_message("bytes"), |
---|
323 | ns_rrcvd, (ns_rrcvd == 1) ? |
---|
324 | get_message("record") : get_message("records")); |
---|
325 | else |
---|
326 | (void) sprintf(fbuf, "%s %d %s, %s %d %s", |
---|
327 | get_message("sent"), |
---|
328 | ns_bsent, (ns_bsent == 1) ? |
---|
329 | get_message("byte") : get_message("bytes"), |
---|
330 | get_message("received"), |
---|
331 | ns_brcvd, (ns_brcvd == 1) ? |
---|
332 | get_message("byte") : get_message("bytes")); |
---|
333 | MAKE_LABEL(fbuf, 4); |
---|
334 | |
---|
335 | if (IN_ANSI) { |
---|
336 | struct ctl_char *c = net_linemode_chars(); |
---|
337 | int i; |
---|
338 | |
---|
339 | MAKE_LABEL(get_message("specialCharacters"), 4); |
---|
340 | for (i = 0; c[i].name; i++) { |
---|
341 | if (!i || !(i % 4)) { |
---|
342 | (void) sprintf(fbuf, " %s", c[i].name); |
---|
343 | MAKE_LABEL(fbuf, 0); |
---|
344 | } else { |
---|
345 | MAKE_LABEL2(c[i].name); |
---|
346 | } |
---|
347 | MAKE_VALUE(c[i].value); |
---|
348 | } |
---|
349 | } |
---|
350 | } else if (HALF_CONNECTED) { |
---|
351 | MAKE_LABEL(get_message("connectionPending"), 4); |
---|
352 | MAKE_VALUE(current_host); |
---|
353 | MAKE_LABEL(hms(ns_time), 0); |
---|
354 | } else |
---|
355 | MAKE_LABEL(get_message("notConnected"), 4); |
---|
356 | |
---|
357 | /* Add "OK" button at the lower left */ |
---|
358 | |
---|
359 | w = XtVaCreateManagedWidget( |
---|
360 | ObjConfirmButton, commandWidgetClass, about_form, |
---|
361 | XtNfromVert, w, |
---|
362 | XtNleft, XtChainLeft, |
---|
363 | XtNbottom, XtChainBottom, |
---|
364 | NULL); |
---|
365 | XtAddCallback(w, XtNcallback, saw_about, 0); |
---|
366 | |
---|
367 | /* Pop it up */ |
---|
368 | |
---|
369 | popup_popup(about_shell, XtGrabExclusive); |
---|
370 | } |
---|
371 | |
---|
372 | #undef MAKE_LABEL |
---|
373 | #undef MAKE_VALUE |
---|