Jacob's patch for a drag-list to select SSH ciphers. Heavily hacked
[u/mdw/putty] / windlg.c
1 #include <windows.h>
2 #include <commctrl.h>
3 #include <commdlg.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <ctype.h>
7 #include <time.h>
8
9 #include "ssh.h"
10 #include "putty.h"
11 #include "winstuff.h"
12 #include "win_res.h"
13 #include "storage.h"
14
15 static char **events = NULL;
16 static int nevents = 0, negsize = 0;
17
18 static int readytogo;
19 static int sesslist_has_focus;
20
21 static struct prefslist cipherlist;
22
23 void force_normal(HWND hwnd)
24 {
25 static int recurse = 0;
26
27 WINDOWPLACEMENT wp;
28
29 if (recurse)
30 return;
31 recurse = 1;
32
33 wp.length = sizeof(wp);
34 if (GetWindowPlacement(hwnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) {
35 wp.showCmd = SW_SHOWNORMAL;
36 SetWindowPlacement(hwnd, &wp);
37 }
38 recurse = 0;
39 }
40
41 static void MyGetDlgItemInt(HWND hwnd, int id, int *result)
42 {
43 BOOL ok;
44 int n;
45 n = GetDlgItemInt(hwnd, id, &ok, FALSE);
46 if (ok)
47 *result = n;
48 }
49
50 static void MyGetDlgItemFlt(HWND hwnd, int id, int *result, int scale)
51 {
52 char text[80];
53 BOOL ok;
54 ok = GetDlgItemText(hwnd, id, text, sizeof(text) - 1);
55 if (ok && text[0])
56 *result = (int) (scale * atof(text));
57 }
58
59 static void MySetDlgItemFlt(HWND hwnd, int id, double value)
60 {
61 char text[80];
62 sprintf(text, "%g", value);
63 SetDlgItemText(hwnd, id, text);
64 }
65
66 static int CALLBACK LogProc(HWND hwnd, UINT msg,
67 WPARAM wParam, LPARAM lParam)
68 {
69 int i;
70
71 switch (msg) {
72 case WM_INITDIALOG:
73 {
74 static int tabs[4] = { 78, 108 };
75 SendDlgItemMessage(hwnd, IDN_LIST, LB_SETTABSTOPS, 2,
76 (LPARAM) tabs);
77 }
78 for (i = 0; i < nevents; i++)
79 SendDlgItemMessage(hwnd, IDN_LIST, LB_ADDSTRING,
80 0, (LPARAM) events[i]);
81 return 1;
82 case WM_COMMAND:
83 switch (LOWORD(wParam)) {
84 case IDOK:
85 case IDCANCEL:
86 logbox = NULL;
87 SetActiveWindow(GetParent(hwnd));
88 DestroyWindow(hwnd);
89 return 0;
90 case IDN_COPY:
91 if (HIWORD(wParam) == BN_CLICKED ||
92 HIWORD(wParam) == BN_DOUBLECLICKED) {
93 int selcount;
94 int *selitems;
95 selcount = SendDlgItemMessage(hwnd, IDN_LIST,
96 LB_GETSELCOUNT, 0, 0);
97 if (selcount == 0) { /* don't even try to copy zero items */
98 MessageBeep(0);
99 break;
100 }
101
102 selitems = smalloc(selcount * sizeof(int));
103 if (selitems) {
104 int count = SendDlgItemMessage(hwnd, IDN_LIST,
105 LB_GETSELITEMS,
106 selcount,
107 (LPARAM) selitems);
108 int i;
109 int size;
110 char *clipdata;
111 static unsigned char sel_nl[] = SEL_NL;
112
113 if (count == 0) { /* can't copy zero stuff */
114 MessageBeep(0);
115 break;
116 }
117
118 size = 0;
119 for (i = 0; i < count; i++)
120 size +=
121 strlen(events[selitems[i]]) + sizeof(sel_nl);
122
123 clipdata = smalloc(size);
124 if (clipdata) {
125 char *p = clipdata;
126 for (i = 0; i < count; i++) {
127 char *q = events[selitems[i]];
128 int qlen = strlen(q);
129 memcpy(p, q, qlen);
130 p += qlen;
131 memcpy(p, sel_nl, sizeof(sel_nl));
132 p += sizeof(sel_nl);
133 }
134 write_aclip(clipdata, size, TRUE);
135 sfree(clipdata);
136 }
137 sfree(selitems);
138
139 for (i = 0; i < nevents; i++)
140 SendDlgItemMessage(hwnd, IDN_LIST, LB_SETSEL,
141 FALSE, i);
142 }
143 }
144 return 0;
145 }
146 return 0;
147 case WM_CLOSE:
148 logbox = NULL;
149 SetActiveWindow(GetParent(hwnd));
150 DestroyWindow(hwnd);
151 return 0;
152 }
153 return 0;
154 }
155
156 static int CALLBACK LicenceProc(HWND hwnd, UINT msg,
157 WPARAM wParam, LPARAM lParam)
158 {
159 switch (msg) {
160 case WM_INITDIALOG:
161 return 1;
162 case WM_COMMAND:
163 switch (LOWORD(wParam)) {
164 case IDOK:
165 EndDialog(hwnd, 1);
166 return 0;
167 }
168 return 0;
169 case WM_CLOSE:
170 EndDialog(hwnd, 1);
171 return 0;
172 }
173 return 0;
174 }
175
176 static int CALLBACK AboutProc(HWND hwnd, UINT msg,
177 WPARAM wParam, LPARAM lParam)
178 {
179 switch (msg) {
180 case WM_INITDIALOG:
181 SetDlgItemText(hwnd, IDA_VERSION, ver);
182 return 1;
183 case WM_COMMAND:
184 switch (LOWORD(wParam)) {
185 case IDOK:
186 case IDCANCEL:
187 EndDialog(hwnd, TRUE);
188 return 0;
189 case IDA_LICENCE:
190 EnableWindow(hwnd, 0);
191 DialogBox(hinst, MAKEINTRESOURCE(IDD_LICENCEBOX),
192 NULL, LicenceProc);
193 EnableWindow(hwnd, 1);
194 SetActiveWindow(hwnd);
195 return 0;
196
197 case IDA_WEB:
198 /* Load web browser */
199 ShellExecute(hwnd, "open",
200 "http://www.chiark.greenend.org.uk/~sgtatham/putty/",
201 0, 0, SW_SHOWDEFAULT);
202 return 0;
203 }
204 return 0;
205 case WM_CLOSE:
206 EndDialog(hwnd, TRUE);
207 return 0;
208 }
209 return 0;
210 }
211
212 /*
213 * Null dialog procedure.
214 */
215 static int CALLBACK NullDlgProc(HWND hwnd, UINT msg,
216 WPARAM wParam, LPARAM lParam)
217 {
218 return 0;
219 }
220
221 static char savedsession[2048];
222
223 enum { IDCX_ABOUT =
224 IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
225
226 sessionpanelstart,
227 IDC_TITLE_SESSION,
228 IDC_BOX_SESSION1,
229 IDC_BOX_SESSION2,
230 IDC_BOX_SESSION3,
231 IDC_HOSTSTATIC,
232 IDC_HOST,
233 IDC_PORTSTATIC,
234 IDC_PORT,
235 IDC_PROTSTATIC,
236 IDC_PROTRAW,
237 IDC_PROTTELNET,
238 IDC_PROTRLOGIN,
239 IDC_PROTSSH,
240 IDC_SESSSTATIC,
241 IDC_SESSEDIT,
242 IDC_SESSLIST,
243 IDC_SESSLOAD,
244 IDC_SESSSAVE,
245 IDC_SESSDEL,
246 IDC_CLOSEEXIT,
247 IDC_COEALWAYS,
248 IDC_COENEVER,
249 IDC_COENORMAL,
250 sessionpanelend,
251
252 loggingpanelstart,
253 IDC_TITLE_LOGGING,
254 IDC_BOX_LOGGING1,
255 IDC_LSTATSTATIC,
256 IDC_LSTATOFF,
257 IDC_LSTATASCII,
258 IDC_LSTATRAW,
259 IDC_LGFSTATIC,
260 IDC_LGFEDIT,
261 IDC_LGFBUTTON,
262 IDC_LSTATXIST,
263 IDC_LSTATXOVR,
264 IDC_LSTATXAPN,
265 IDC_LSTATXASK,
266 loggingpanelend,
267
268 keyboardpanelstart,
269 IDC_TITLE_KEYBOARD,
270 IDC_BOX_KEYBOARD1,
271 IDC_BOX_KEYBOARD2,
272 IDC_BOX_KEYBOARD3,
273 IDC_DELSTATIC,
274 IDC_DEL008,
275 IDC_DEL127,
276 IDC_HOMESTATIC,
277 IDC_HOMETILDE,
278 IDC_HOMERXVT,
279 IDC_FUNCSTATIC,
280 IDC_FUNCTILDE,
281 IDC_FUNCLINUX,
282 IDC_FUNCXTERM,
283 IDC_FUNCVT400,
284 IDC_FUNCVT100P,
285 IDC_FUNCSCO,
286 IDC_KPSTATIC,
287 IDC_KPNORMAL,
288 IDC_KPAPPLIC,
289 IDC_KPNH,
290 IDC_NOAPPLICK,
291 IDC_NOAPPLICC,
292 IDC_CURSTATIC,
293 IDC_CURNORMAL,
294 IDC_CURAPPLIC,
295 IDC_COMPOSEKEY,
296 IDC_CTRLALTKEYS,
297 IDC_TELNETKEY,
298 keyboardpanelend,
299
300 terminalpanelstart,
301 IDC_TITLE_TERMINAL,
302 IDC_BOX_TERMINAL1,
303 IDC_BOX_TERMINAL2,
304 IDC_WRAPMODE,
305 IDC_DECOM,
306 IDC_LFHASCR,
307 IDC_BCE,
308 IDC_BLINKTEXT,
309 IDC_ANSWERBACK,
310 IDC_ANSWEREDIT,
311 IDC_ECHOSTATIC,
312 IDC_ECHOBACKEND,
313 IDC_ECHOYES,
314 IDC_ECHONO,
315 IDC_EDITSTATIC,
316 IDC_EDITBACKEND,
317 IDC_EDITYES,
318 IDC_EDITNO,
319 terminalpanelend,
320
321 bellpanelstart,
322 IDC_TITLE_BELL,
323 IDC_BOX_BELL1,
324 IDC_BOX_BELL2,
325 IDC_BELLSTATIC,
326 IDC_BELL_DISABLED,
327 IDC_BELL_DEFAULT,
328 IDC_BELL_WAVEFILE,
329 IDC_BELL_VISUAL,
330 IDC_BELL_WAVESTATIC,
331 IDC_BELL_WAVEEDIT,
332 IDC_BELL_WAVEBROWSE,
333 IDC_B_IND_STATIC,
334 IDC_B_IND_DISABLED,
335 IDC_B_IND_FLASH,
336 IDC_B_IND_STEADY,
337 IDC_BELLOVL,
338 IDC_BELLOVLNSTATIC,
339 IDC_BELLOVLN,
340 IDC_BELLOVLTSTATIC,
341 IDC_BELLOVLT,
342 IDC_BELLOVLEXPLAIN,
343 IDC_BELLOVLSSTATIC,
344 IDC_BELLOVLS,
345 bellpanelend,
346
347 windowpanelstart,
348 IDC_TITLE_WINDOW,
349 IDC_BOX_WINDOW1,
350 IDC_BOX_WINDOW2,
351 IDC_BOX_WINDOW3,
352 IDC_ROWSSTATIC,
353 IDC_ROWSEDIT,
354 IDC_COLSSTATIC,
355 IDC_COLSEDIT,
356 IDC_LOCKSIZE,
357 IDC_SCROLLBAR,
358 IDC_CLOSEWARN,
359 IDC_SAVESTATIC,
360 IDC_SAVEEDIT,
361 IDC_ALTF4,
362 IDC_ALTSPACE,
363 IDC_ALTONLY,
364 IDC_SCROLLKEY,
365 IDC_SCROLLDISP,
366 IDC_ALWAYSONTOP,
367 windowpanelend,
368
369 appearancepanelstart,
370 IDC_TITLE_APPEARANCE,
371 IDC_BOX_APPEARANCE1,
372 IDC_BOX_APPEARANCE2,
373 IDC_BOX_APPEARANCE3,
374 IDC_BOX_APPEARANCE4,
375 IDC_BOX_APPEARANCE5,
376 IDC_CURSORSTATIC,
377 IDC_CURBLOCK,
378 IDC_CURUNDER,
379 IDC_CURVERT,
380 IDC_BLINKCUR,
381 IDC_FONTSTATIC,
382 IDC_CHOOSEFONT,
383 IDC_WINTITLE,
384 IDC_WINEDIT,
385 IDC_WINNAME,
386 IDC_HIDEMOUSE,
387 IDC_SUNKENEDGE,
388 appearancepanelend,
389
390 connectionpanelstart,
391 IDC_TITLE_CONNECTION,
392 IDC_BOX_CONNECTION1,
393 IDC_BOX_CONNECTION2,
394 IDC_TTSTATIC,
395 IDC_TTEDIT,
396 IDC_LOGSTATIC,
397 IDC_LOGEDIT,
398 IDC_PINGSTATIC,
399 IDC_PINGEDIT,
400 connectionpanelend,
401
402 telnetpanelstart,
403 IDC_TITLE_TELNET,
404 IDC_BOX_TELNET1,
405 IDC_BOX_TELNET2,
406 IDC_TSSTATIC,
407 IDC_TSEDIT,
408 IDC_ENVSTATIC,
409 IDC_VARSTATIC,
410 IDC_VAREDIT,
411 IDC_VALSTATIC,
412 IDC_VALEDIT,
413 IDC_ENVLIST,
414 IDC_ENVADD,
415 IDC_ENVREMOVE,
416 IDC_EMSTATIC,
417 IDC_EMBSD,
418 IDC_EMRFC,
419 IDC_ACTSTATIC,
420 IDC_TPASSIVE,
421 IDC_TACTIVE,
422 telnetpanelend,
423
424 rloginpanelstart,
425 IDC_TITLE_RLOGIN,
426 IDC_BOX_RLOGIN1,
427 IDC_BOX_RLOGIN2,
428 IDC_R_TSSTATIC,
429 IDC_R_TSEDIT,
430 IDC_RLLUSERSTATIC,
431 IDC_RLLUSEREDIT,
432 rloginpanelend,
433
434 sshpanelstart,
435 IDC_TITLE_SSH,
436 IDC_BOX_SSH1,
437 IDC_BOX_SSH2,
438 IDC_BOX_SSH3,
439 IDC_NOPTY,
440 IDC_BOX_SSHCIPHER,
441 IDC_CIPHERSTATIC2,
442 IDC_CIPHERLIST,
443 IDC_CIPHERUP,
444 IDC_CIPHERDN,
445 IDC_BUGGYMAC,
446 IDC_SSHPROTSTATIC,
447 IDC_SSHPROT1,
448 IDC_SSHPROT2,
449 IDC_CMDSTATIC,
450 IDC_CMDEDIT,
451 IDC_COMPRESS,
452 sshpanelend,
453
454 sshauthpanelstart,
455 IDC_TITLE_SSHAUTH,
456 IDC_BOX_SSHAUTH1,
457 IDC_BOX_SSHAUTH2,
458 IDC_PKSTATIC,
459 IDC_PKEDIT,
460 IDC_PKBUTTON,
461 IDC_AGENTFWD,
462 IDC_AUTHTIS,
463 sshauthpanelend,
464
465 selectionpanelstart,
466 IDC_TITLE_SELECTION,
467 IDC_BOX_SELECTION1,
468 IDC_BOX_SELECTION2,
469 IDC_BOX_SELECTION3,
470 IDC_MBSTATIC,
471 IDC_MBWINDOWS,
472 IDC_MBXTERM,
473 IDC_CCSTATIC,
474 IDC_CCLIST,
475 IDC_CCSET,
476 IDC_CCSTATIC2,
477 IDC_CCEDIT,
478 IDC_RAWCNP,
479 selectionpanelend,
480
481 colourspanelstart,
482 IDC_TITLE_COLOURS,
483 IDC_BOX_COLOURS1,
484 IDC_BOX_COLOURS2,
485 IDC_BOLDCOLOUR,
486 IDC_PALETTE,
487 IDC_COLOURSTATIC,
488 IDC_COLOURLIST,
489 IDC_RSTATIC,
490 IDC_GSTATIC,
491 IDC_BSTATIC,
492 IDC_RVALUE,
493 IDC_GVALUE,
494 IDC_BVALUE,
495 IDC_CHANGE,
496 colourspanelend,
497
498 translationpanelstart,
499 IDC_TITLE_TRANSLATION,
500 IDC_BOX_TRANSLATION1,
501 IDC_BOX_TRANSLATION2,
502 IDC_CODEPAGESTATIC,
503 IDC_CODEPAGE,
504 IDC_VTSTATIC,
505 IDC_VTXWINDOWS,
506 IDC_VTOEMANSI,
507 IDC_VTOEMONLY,
508 IDC_VTPOORMAN,
509 IDC_VTUNICODE,
510 translationpanelend,
511
512 tunnelspanelstart,
513 IDC_TITLE_TUNNELS,
514 IDC_BOX_TUNNELS1,
515 IDC_BOX_TUNNELS2,
516 IDC_X11_FORWARD,
517 IDC_X11_DISPSTATIC,
518 IDC_X11_DISPLAY,
519 IDC_LPORT_ALL,
520 IDC_PFWDSTATIC,
521 IDC_PFWDSTATIC2,
522 IDC_PFWDREMOVE,
523 IDC_PFWDLIST,
524 IDC_PFWDADD,
525 IDC_SPORTSTATIC,
526 IDC_SPORTEDIT,
527 IDC_DPORTSTATIC,
528 IDC_DPORTEDIT,
529 IDC_PFWDLOCAL,
530 IDC_PFWDREMOTE,
531
532 tunnelspanelend,
533
534 controlendvalue
535 };
536
537 static const char *const colours[] = {
538 "Default Foreground", "Default Bold Foreground",
539 "Default Background", "Default Bold Background",
540 "Cursor Text", "Cursor Colour",
541 "ANSI Black", "ANSI Black Bold",
542 "ANSI Red", "ANSI Red Bold",
543 "ANSI Green", "ANSI Green Bold",
544 "ANSI Yellow", "ANSI Yellow Bold",
545 "ANSI Blue", "ANSI Blue Bold",
546 "ANSI Magenta", "ANSI Magenta Bold",
547 "ANSI Cyan", "ANSI Cyan Bold",
548 "ANSI White", "ANSI White Bold"
549 };
550 static const int permcolour[] = {
551 TRUE, FALSE, TRUE, FALSE, TRUE, TRUE,
552 TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE,
553 TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE
554 };
555
556 static void fmtfont(char *buf)
557 {
558 sprintf(buf, "Font: %s, ", cfg.font);
559 if (cfg.fontisbold)
560 strcat(buf, "bold, ");
561 if (cfg.fontheight == 0)
562 strcat(buf, "default height");
563 else
564 sprintf(buf + strlen(buf), "%d-point",
565 (cfg.fontheight < 0 ? -cfg.fontheight : cfg.fontheight));
566 }
567
568 /* 2nd arg: NZ => don't redraw session list (use when loading
569 * a new session) */
570 static void init_dlg_ctrls(HWND hwnd, int keepsess)
571 {
572 int i;
573 char fontstatic[256];
574
575 SetDlgItemText(hwnd, IDC_HOST, cfg.host);
576 SetDlgItemText(hwnd, IDC_SESSEDIT, savedsession);
577 if (!keepsess) {
578 int i, n;
579 n = SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_GETCOUNT, 0, 0);
580 for (i = n; i-- > 0;)
581 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_DELETESTRING, i, 0);
582 for (i = 0; i < nsessions; i++)
583 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_ADDSTRING,
584 0, (LPARAM) (sessions[i]));
585 }
586 SetDlgItemInt(hwnd, IDC_PORT, cfg.port, FALSE);
587 CheckRadioButton(hwnd, IDC_PROTRAW, IDC_PROTSSH,
588 cfg.protocol == PROT_SSH ? IDC_PROTSSH :
589 cfg.protocol == PROT_TELNET ? IDC_PROTTELNET :
590 cfg.protocol ==
591 PROT_RLOGIN ? IDC_PROTRLOGIN : IDC_PROTRAW);
592 SetDlgItemInt(hwnd, IDC_PINGEDIT, cfg.ping_interval, FALSE);
593
594 CheckRadioButton(hwnd, IDC_DEL008, IDC_DEL127,
595 cfg.bksp_is_delete ? IDC_DEL127 : IDC_DEL008);
596 CheckRadioButton(hwnd, IDC_HOMETILDE, IDC_HOMERXVT,
597 cfg.rxvt_homeend ? IDC_HOMERXVT : IDC_HOMETILDE);
598 CheckRadioButton(hwnd, IDC_FUNCTILDE, IDC_FUNCSCO,
599 cfg.funky_type == 0 ? IDC_FUNCTILDE :
600 cfg.funky_type == 1 ? IDC_FUNCLINUX :
601 cfg.funky_type == 2 ? IDC_FUNCXTERM :
602 cfg.funky_type == 3 ? IDC_FUNCVT400 :
603 cfg.funky_type == 4 ? IDC_FUNCVT100P :
604 cfg.funky_type == 5 ? IDC_FUNCSCO : IDC_FUNCTILDE);
605 CheckDlgButton(hwnd, IDC_NOAPPLICC, cfg.no_applic_c);
606 CheckDlgButton(hwnd, IDC_NOAPPLICK, cfg.no_applic_k);
607 CheckRadioButton(hwnd, IDC_CURNORMAL, IDC_CURAPPLIC,
608 cfg.app_cursor ? IDC_CURAPPLIC : IDC_CURNORMAL);
609 CheckRadioButton(hwnd, IDC_KPNORMAL, IDC_KPNH,
610 cfg.nethack_keypad ? IDC_KPNH :
611 cfg.app_keypad ? IDC_KPAPPLIC : IDC_KPNORMAL);
612 CheckDlgButton(hwnd, IDC_ALTF4, cfg.alt_f4);
613 CheckDlgButton(hwnd, IDC_ALTSPACE, cfg.alt_space);
614 CheckDlgButton(hwnd, IDC_ALTONLY, cfg.alt_only);
615 CheckDlgButton(hwnd, IDC_COMPOSEKEY, cfg.compose_key);
616 CheckDlgButton(hwnd, IDC_CTRLALTKEYS, cfg.ctrlaltkeys);
617 CheckDlgButton(hwnd, IDC_TELNETKEY, cfg.telnet_keyboard);
618 CheckRadioButton(hwnd, IDC_ECHOBACKEND, IDC_ECHONO,
619 cfg.localecho == LD_BACKEND ? IDC_ECHOBACKEND :
620 cfg.localecho == LD_YES ? IDC_ECHOYES : IDC_ECHONO);
621 CheckRadioButton(hwnd, IDC_EDITBACKEND, IDC_EDITNO,
622 cfg.localedit == LD_BACKEND ? IDC_EDITBACKEND :
623 cfg.localedit == LD_YES ? IDC_EDITYES : IDC_EDITNO);
624 SetDlgItemText(hwnd, IDC_ANSWEREDIT, cfg.answerback);
625 CheckDlgButton(hwnd, IDC_ALWAYSONTOP, cfg.alwaysontop);
626 CheckDlgButton(hwnd, IDC_SCROLLKEY, cfg.scroll_on_key);
627 CheckDlgButton(hwnd, IDC_SCROLLDISP, cfg.scroll_on_disp);
628
629 CheckDlgButton(hwnd, IDC_WRAPMODE, cfg.wrap_mode);
630 CheckDlgButton(hwnd, IDC_DECOM, cfg.dec_om);
631 CheckDlgButton(hwnd, IDC_LFHASCR, cfg.lfhascr);
632 SetDlgItemInt(hwnd, IDC_ROWSEDIT, cfg.height, FALSE);
633 SetDlgItemInt(hwnd, IDC_COLSEDIT, cfg.width, FALSE);
634 SetDlgItemInt(hwnd, IDC_SAVEEDIT, cfg.savelines, FALSE);
635 fmtfont(fontstatic);
636 SetDlgItemText(hwnd, IDC_FONTSTATIC, fontstatic);
637 CheckRadioButton(hwnd, IDC_BELL_DISABLED, IDC_BELL_VISUAL,
638 cfg.beep == BELL_DISABLED ? IDC_BELL_DISABLED :
639 cfg.beep == BELL_DEFAULT ? IDC_BELL_DEFAULT :
640 cfg.beep == BELL_WAVEFILE ? IDC_BELL_WAVEFILE :
641 cfg.beep ==
642 BELL_VISUAL ? IDC_BELL_VISUAL : IDC_BELL_DEFAULT);
643 CheckRadioButton(hwnd, IDC_B_IND_DISABLED, IDC_B_IND_STEADY,
644 cfg.beep_ind ==
645 B_IND_DISABLED ? IDC_B_IND_DISABLED : cfg.beep_ind ==
646 B_IND_FLASH ? IDC_B_IND_FLASH : cfg.beep_ind ==
647 B_IND_STEADY ? IDC_B_IND_STEADY : IDC_B_IND_DISABLED);
648 SetDlgItemText(hwnd, IDC_BELL_WAVEEDIT, cfg.bell_wavefile);
649 CheckDlgButton(hwnd, IDC_BELLOVL, cfg.bellovl);
650 SetDlgItemInt(hwnd, IDC_BELLOVLN, cfg.bellovl_n, FALSE);
651 MySetDlgItemFlt(hwnd, IDC_BELLOVLT, cfg.bellovl_t / 1000.0);
652 MySetDlgItemFlt(hwnd, IDC_BELLOVLS, cfg.bellovl_s / 1000.0);
653
654 CheckDlgButton(hwnd, IDC_BCE, cfg.bce);
655 CheckDlgButton(hwnd, IDC_BLINKTEXT, cfg.blinktext);
656
657 SetDlgItemText(hwnd, IDC_WINEDIT, cfg.wintitle);
658 CheckDlgButton(hwnd, IDC_WINNAME, cfg.win_name_always);
659 CheckDlgButton(hwnd, IDC_HIDEMOUSE, cfg.hide_mouseptr);
660 CheckDlgButton(hwnd, IDC_SUNKENEDGE, cfg.sunken_edge);
661 CheckRadioButton(hwnd, IDC_CURBLOCK, IDC_CURVERT,
662 cfg.cursor_type == 0 ? IDC_CURBLOCK :
663 cfg.cursor_type == 1 ? IDC_CURUNDER : IDC_CURVERT);
664 CheckDlgButton(hwnd, IDC_BLINKCUR, cfg.blink_cur);
665 CheckDlgButton(hwnd, IDC_SCROLLBAR, cfg.scrollbar);
666 CheckDlgButton(hwnd, IDC_LOCKSIZE, cfg.locksize);
667 CheckRadioButton(hwnd, IDC_COEALWAYS, IDC_COENORMAL,
668 cfg.close_on_exit == COE_NORMAL ? IDC_COENORMAL :
669 cfg.close_on_exit ==
670 COE_NEVER ? IDC_COENEVER : IDC_COEALWAYS);
671 CheckDlgButton(hwnd, IDC_CLOSEWARN, cfg.warn_on_close);
672
673 SetDlgItemText(hwnd, IDC_TTEDIT, cfg.termtype);
674 SetDlgItemText(hwnd, IDC_TSEDIT, cfg.termspeed);
675 SetDlgItemText(hwnd, IDC_R_TSEDIT, cfg.termspeed);
676 SetDlgItemText(hwnd, IDC_RLLUSEREDIT, cfg.localusername);
677 SetDlgItemText(hwnd, IDC_LOGEDIT, cfg.username);
678 SetDlgItemText(hwnd, IDC_LGFEDIT, cfg.logfilename);
679 CheckRadioButton(hwnd, IDC_LSTATOFF, IDC_LSTATRAW,
680 cfg.logtype == 0 ? IDC_LSTATOFF :
681 cfg.logtype == 1 ? IDC_LSTATASCII : IDC_LSTATRAW);
682 CheckRadioButton(hwnd, IDC_LSTATXOVR, IDC_LSTATXASK,
683 cfg.logxfovr == LGXF_OVR ? IDC_LSTATXOVR :
684 cfg.logxfovr == LGXF_ASK ? IDC_LSTATXASK :
685 IDC_LSTATXAPN);
686 {
687 char *p = cfg.environmt;
688 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_RESETCONTENT, 0, 0);
689 while (*p) {
690 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_ADDSTRING, 0,
691 (LPARAM) p);
692 p += strlen(p) + 1;
693 }
694 p = cfg.portfwd;
695 while (*p) {
696 SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_ADDSTRING, 0,
697 (LPARAM) p);
698 p += strlen(p) + 1;
699 }
700 }
701 CheckRadioButton(hwnd, IDC_EMBSD, IDC_EMRFC,
702 cfg.rfc_environ ? IDC_EMRFC : IDC_EMBSD);
703 CheckRadioButton(hwnd, IDC_TPASSIVE, IDC_TACTIVE,
704 cfg.passive_telnet ? IDC_TPASSIVE : IDC_TACTIVE);
705
706 SetDlgItemText(hwnd, IDC_TTEDIT, cfg.termtype);
707 SetDlgItemText(hwnd, IDC_LOGEDIT, cfg.username);
708 CheckDlgButton(hwnd, IDC_NOPTY, cfg.nopty);
709 CheckDlgButton(hwnd, IDC_COMPRESS, cfg.compression);
710 CheckDlgButton(hwnd, IDC_BUGGYMAC, cfg.buggymac);
711 CheckDlgButton(hwnd, IDC_AGENTFWD, cfg.agentfwd);
712 CheckRadioButton(hwnd, IDC_SSHPROT1, IDC_SSHPROT2,
713 cfg.sshprot == 1 ? IDC_SSHPROT1 : IDC_SSHPROT2);
714 CheckDlgButton(hwnd, IDC_AUTHTIS, cfg.try_tis_auth);
715 SetDlgItemText(hwnd, IDC_PKEDIT, cfg.keyfile);
716 SetDlgItemText(hwnd, IDC_CMDEDIT, cfg.remote_cmd);
717
718 {
719 int i;
720 static const struct { char *s; int c; } ciphers[] = {
721 { "3DES", CIPHER_3DES },
722 { "Blowfish", CIPHER_BLOWFISH },
723 { "DES (SSH 1 only)", CIPHER_DES },
724 { "AES (SSH 2 only)", CIPHER_AES },
725 { "-- warn below here --", CIPHER_WARN }
726 };
727
728 /* Set up the "selected ciphers" box. */
729 /* (cipherlist assumed to contain all ciphers) */
730 SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_RESETCONTENT, 0, 0);
731 for (i = 0; i < CIPHER_MAX; i++) {
732 int c = cfg.ssh_cipherlist[i];
733 int j, pos;
734 char *cstr = NULL;
735 for (j = 0; j < (sizeof ciphers) / (sizeof ciphers[0]); j++) {
736 if (ciphers[j].c == c) {
737 cstr = ciphers[j].s;
738 break;
739 }
740 }
741 pos = SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_ADDSTRING,
742 0, (LPARAM) cstr);
743 SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_SETITEMDATA,
744 pos, (LPARAM) c);
745 }
746 SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_ADDSTRING,
747 0, (LPARAM) "FIXME1");
748 SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_ADDSTRING,
749 0, (LPARAM) "FIXME2");
750
751 }
752
753
754 CheckRadioButton(hwnd, IDC_MBWINDOWS, IDC_MBXTERM,
755 cfg.mouse_is_xterm ? IDC_MBXTERM : IDC_MBWINDOWS);
756 CheckDlgButton(hwnd, IDC_RAWCNP, cfg.rawcnp);
757 {
758 static int tabs[4] = { 25, 61, 96, 128 };
759 SendDlgItemMessage(hwnd, IDC_CCLIST, LB_SETTABSTOPS, 4,
760 (LPARAM) tabs);
761 }
762 for (i = 0; i < 128; i++) {
763 char str[100];
764 sprintf(str, "%d\t(0x%02X)\t%c\t%d", i, i,
765 (i >= 0x21 && i != 0x7F) ? i : ' ', cfg.wordness[i]);
766 SendDlgItemMessage(hwnd, IDC_CCLIST, LB_ADDSTRING, 0,
767 (LPARAM) str);
768 }
769
770 CheckDlgButton(hwnd, IDC_BOLDCOLOUR, cfg.bold_colour);
771 CheckDlgButton(hwnd, IDC_PALETTE, cfg.try_palette);
772 {
773 int i, n;
774 n = SendDlgItemMessage(hwnd, IDC_COLOURLIST, LB_GETCOUNT, 0, 0);
775 for (i = n; i-- > 0;)
776 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
777 LB_DELETESTRING, i, 0);
778 for (i = 0; i < 22; i++)
779 if (cfg.bold_colour || permcolour[i])
780 SendDlgItemMessage(hwnd, IDC_COLOURLIST, LB_ADDSTRING, 0,
781 (LPARAM) colours[i]);
782 }
783 SendDlgItemMessage(hwnd, IDC_COLOURLIST, LB_SETCURSEL, 0, 0);
784 SetDlgItemInt(hwnd, IDC_RVALUE, cfg.colours[0][0], FALSE);
785 SetDlgItemInt(hwnd, IDC_GVALUE, cfg.colours[0][1], FALSE);
786 SetDlgItemInt(hwnd, IDC_BVALUE, cfg.colours[0][2], FALSE);
787
788 {
789 int i;
790 char *cp;
791 int index = 0;
792 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_RESETCONTENT, 0, 0);
793 for (i = 0; (cp = cp_enumerate(i)) != NULL; i++) {
794 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_ADDSTRING,
795 0, (LPARAM) cp);
796 if (!strcmp(cp, cfg.line_codepage))
797 index = i;
798 }
799 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_SETCURSEL, index, 0);
800 }
801
802 CheckRadioButton(hwnd, IDC_VTXWINDOWS, IDC_VTUNICODE,
803 cfg.vtmode == VT_XWINDOWS ? IDC_VTXWINDOWS :
804 cfg.vtmode == VT_OEMANSI ? IDC_VTOEMANSI :
805 cfg.vtmode == VT_OEMONLY ? IDC_VTOEMONLY :
806 cfg.vtmode == VT_UNICODE ? IDC_VTUNICODE :
807 IDC_VTPOORMAN);
808
809 CheckDlgButton(hwnd, IDC_X11_FORWARD, cfg.x11_forward);
810 SetDlgItemText(hwnd, IDC_X11_DISPLAY, cfg.x11_display);
811
812 CheckDlgButton(hwnd, IDC_LPORT_ALL, cfg.lport_acceptall);
813 CheckRadioButton(hwnd, IDC_PFWDLOCAL, IDC_PFWDREMOTE, IDC_PFWDLOCAL);
814 }
815
816 struct treeview_faff {
817 HWND treeview;
818 HTREEITEM lastat[4];
819 };
820
821 static HTREEITEM treeview_insert(struct treeview_faff *faff,
822 int level, char *text)
823 {
824 TVINSERTSTRUCT ins;
825 int i;
826 HTREEITEM newitem;
827 ins.hParent = (level > 0 ? faff->lastat[level - 1] : TVI_ROOT);
828 ins.hInsertAfter = faff->lastat[level];
829 #if _WIN32_IE >= 0x0400 && defined NONAMELESSUNION
830 #define INSITEM DUMMYUNIONNAME.item
831 #else
832 #define INSITEM item
833 #endif
834 ins.INSITEM.mask = TVIF_TEXT;
835 ins.INSITEM.pszText = text;
836 newitem = TreeView_InsertItem(faff->treeview, &ins);
837 if (level > 0)
838 TreeView_Expand(faff->treeview, faff->lastat[level - 1],
839 TVE_EXPAND);
840 faff->lastat[level] = newitem;
841 for (i = level + 1; i < 4; i++)
842 faff->lastat[i] = NULL;
843 return newitem;
844 }
845
846 /*
847 * Create the panelfuls of controls in the configuration box.
848 */
849 static void create_controls(HWND hwnd, int dlgtype, int panel)
850 {
851 if (panel == sessionpanelstart) {
852 /* The Session panel. Accelerators used: [acgo] nprtih elsd w */
853 struct ctlpos cp;
854 ctlposinit(&cp, hwnd, 80, 3, 13);
855 bartitle(&cp, "Basic options for your PuTTY session",
856 IDC_TITLE_SESSION);
857 if (dlgtype == 0) {
858 beginbox(&cp, "Specify your connection by host name or IP address",
859 IDC_BOX_SESSION1);
860 multiedit(&cp,
861 "Host &Name (or IP address)",
862 IDC_HOSTSTATIC, IDC_HOST, 75,
863 "&Port", IDC_PORTSTATIC, IDC_PORT, 25, NULL);
864 if (backends[3].backend == NULL) {
865 /* this is PuTTYtel, so only three protocols available */
866 radioline(&cp, "Protocol:", IDC_PROTSTATIC, 3,
867 "&Raw", IDC_PROTRAW,
868 "&Telnet", IDC_PROTTELNET,
869 "Rlog&in", IDC_PROTRLOGIN, NULL);
870 } else {
871 radioline(&cp, "Protocol:", IDC_PROTSTATIC, 4,
872 "&Raw", IDC_PROTRAW,
873 "&Telnet", IDC_PROTTELNET,
874 "Rlog&in", IDC_PROTRLOGIN,
875 #ifdef FWHACK
876 "SS&H/hack",
877 #else
878 "SS&H",
879 #endif
880 IDC_PROTSSH, NULL);
881 }
882 endbox(&cp);
883 beginbox(&cp, "Load, save or delete a stored session",
884 IDC_BOX_SESSION2);
885 sesssaver(&cp, "Sav&ed Sessions",
886 IDC_SESSSTATIC, IDC_SESSEDIT, IDC_SESSLIST,
887 "&Load", IDC_SESSLOAD,
888 "&Save", IDC_SESSSAVE, "&Delete", IDC_SESSDEL, NULL);
889 endbox(&cp);
890 }
891 beginbox(&cp, NULL, IDC_BOX_SESSION3);
892 radioline(&cp, "Close &window on exit:", IDC_CLOSEEXIT, 4,
893 "Always", IDC_COEALWAYS,
894 "Never", IDC_COENEVER,
895 "Only on clean exit", IDC_COENORMAL, NULL);
896 endbox(&cp);
897 }
898
899 if (panel == loggingpanelstart) {
900 /* The Logging panel. Accelerators used: [acgo] tplfwe */
901 struct ctlpos cp;
902 ctlposinit(&cp, hwnd, 80, 3, 13);
903 bartitle(&cp, "Options controlling session logging",
904 IDC_TITLE_LOGGING);
905 beginbox(&cp, NULL, IDC_BOX_LOGGING1);
906 radiobig(&cp,
907 "Session logging:", IDC_LSTATSTATIC,
908 "Logging &turned off completely", IDC_LSTATOFF,
909 "Log &printable output only", IDC_LSTATASCII,
910 "&Log all session output", IDC_LSTATRAW, NULL);
911 editbutton(&cp, "Log &file name:",
912 IDC_LGFSTATIC, IDC_LGFEDIT, "Bro&wse...",
913 IDC_LGFBUTTON);
914 radiobig(&cp,
915 "What to do if the log file already &exists:",
916 IDC_LSTATXIST, "Always overwrite it", IDC_LSTATXOVR,
917 "Always append to the end of it", IDC_LSTATXAPN,
918 "Ask the user every time", IDC_LSTATXASK, NULL);
919 endbox(&cp);
920 }
921
922 if (panel == terminalpanelstart) {
923 /* The Terminal panel. Accelerators used: [acgo] wdlen hts */
924 struct ctlpos cp;
925 ctlposinit(&cp, hwnd, 80, 3, 13);
926 bartitle(&cp, "Options controlling the terminal emulation",
927 IDC_TITLE_TERMINAL);
928 beginbox(&cp, "Set various terminal options", IDC_BOX_TERMINAL1);
929 checkbox(&cp, "Auto &wrap mode initially on", IDC_WRAPMODE);
930 checkbox(&cp, "&DEC Origin Mode initially on", IDC_DECOM);
931 checkbox(&cp, "Implicit CR in every &LF", IDC_LFHASCR);
932 checkbox(&cp, "Use background colour to &erase screen", IDC_BCE);
933 checkbox(&cp, "Enable bli&nking text", IDC_BLINKTEXT);
934 multiedit(&cp,
935 "An&swerback to ^E:", IDC_ANSWERBACK,
936 IDC_ANSWEREDIT, 100, NULL);
937 endbox(&cp);
938
939 beginbox(&cp, "Line discipline options", IDC_BOX_TERMINAL2);
940 radioline(&cp, "Local ec&ho:", IDC_ECHOSTATIC, 3,
941 "Auto", IDC_ECHOBACKEND,
942 "Force on", IDC_ECHOYES, "Force off", IDC_ECHONO, NULL);
943 radioline(&cp, "Local line edi&ting:", IDC_EDITSTATIC, 3,
944 "Auto", IDC_EDITBACKEND,
945 "Force on", IDC_EDITYES, "Force off", IDC_EDITNO, NULL);
946 endbox(&cp);
947 }
948
949 if (panel == bellpanelstart) {
950 /* The Bell panel. Accelerators used: [acgo] bdsm wit */
951 struct ctlpos cp;
952 ctlposinit(&cp, hwnd, 80, 3, 13);
953 bartitle(&cp, "Options controlling the terminal bell",
954 IDC_TITLE_BELL);
955 beginbox(&cp, "Set the style of bell", IDC_BOX_BELL1);
956 radiobig(&cp,
957 "Action to happen when a &bell occurs:", IDC_BELLSTATIC,
958 "None (bell disabled)", IDC_BELL_DISABLED,
959 "Play Windows Default Sound", IDC_BELL_DEFAULT,
960 "Play a custom sound file", IDC_BELL_WAVEFILE,
961 "Visual bell (flash window)", IDC_BELL_VISUAL, NULL);
962 editbutton(&cp, "Custom sound file to play as a bell:",
963 IDC_BELL_WAVESTATIC, IDC_BELL_WAVEEDIT,
964 "Bro&wse...", IDC_BELL_WAVEBROWSE);
965 radioline(&cp, "Taskbar/caption &indication on bell:",
966 IDC_B_IND_STATIC, 3, "Disabled", IDC_B_IND_DISABLED,
967 "Flashing", IDC_B_IND_FLASH, "Steady", IDC_B_IND_STEADY,
968 NULL);
969 endbox(&cp);
970 beginbox(&cp, "Control the bell overload behaviour",
971 IDC_BOX_BELL2);
972 checkbox(&cp, "Bell is temporarily &disabled when over-used",
973 IDC_BELLOVL);
974 staticedit(&cp, "Over-use means this &many bells...",
975 IDC_BELLOVLNSTATIC, IDC_BELLOVLN, 20);
976 staticedit(&cp, "... in &this many seconds",
977 IDC_BELLOVLTSTATIC, IDC_BELLOVLT, 20);
978 statictext(&cp,
979 "The bell is re-enabled after a few seconds of silence.",
980 IDC_BELLOVLEXPLAIN);
981 staticedit(&cp, "Seconds of &silence required", IDC_BELLOVLSSTATIC,
982 IDC_BELLOVLS, 20);
983 endbox(&cp);
984 }
985
986 if (panel == keyboardpanelstart) {
987 /* The Keyboard panel. Accelerators used: [acgo] bhf ruyntd */
988 struct ctlpos cp;
989 ctlposinit(&cp, hwnd, 80, 3, 13);
990 /*
991 bartitle(&cp, "Options controlling the effects of keys",
992 IDC_TITLE_KEYBOARD);
993 */
994 beginbox(&cp, "Change the sequences sent by:", IDC_BOX_KEYBOARD1);
995 radioline(&cp, "The &Backspace key", IDC_DELSTATIC, 2,
996 "Control-H", IDC_DEL008,
997 "Control-? (127)", IDC_DEL127, NULL);
998 radioline(&cp, "The &Home and End keys", IDC_HOMESTATIC, 2,
999 "Standard", IDC_HOMETILDE, "rxvt", IDC_HOMERXVT, NULL);
1000 radioline(&cp, "The &Function keys and keypad", IDC_FUNCSTATIC, 3,
1001 "ESC[n~", IDC_FUNCTILDE,
1002 "Linux", IDC_FUNCLINUX,
1003 "Xterm R6", IDC_FUNCXTERM,
1004 "VT400", IDC_FUNCVT400,
1005 "VT100+", IDC_FUNCVT100P, "SCO", IDC_FUNCSCO, NULL);
1006 endbox(&cp);
1007 beginbox(&cp, "Application keypad settings:", IDC_BOX_KEYBOARD2);
1008 checkbox(&cp,
1009 "Application c&ursor keys totally disabled",
1010 IDC_NOAPPLICC);
1011 radioline(&cp, "Initial state of cu&rsor keys:", IDC_CURSTATIC, 2,
1012 "Normal", IDC_CURNORMAL,
1013 "Application", IDC_CURAPPLIC, NULL);
1014 checkbox(&cp,
1015 "Application ke&ypad keys totally disabled",
1016 IDC_NOAPPLICK);
1017 radioline(&cp, "Initial state of &numeric keypad:", IDC_KPSTATIC,
1018 3, "Normal", IDC_KPNORMAL, "Application", IDC_KPAPPLIC,
1019 "NetHack", IDC_KPNH, NULL);
1020 endbox(&cp);
1021 beginbox(&cp, "Enable extra keyboard features:",
1022 IDC_BOX_KEYBOARD3);
1023 checkbox(&cp, "AltGr ac&ts as Compose key", IDC_COMPOSEKEY);
1024 checkbox(&cp, "Control-Alt is &different from AltGr",
1025 IDC_CTRLALTKEYS);
1026 endbox(&cp);
1027 }
1028
1029 if (panel == windowpanelstart) {
1030 /* The Window panel. Accelerators used: [acgo] rmz sdkp w4ylt */
1031 struct ctlpos cp;
1032 ctlposinit(&cp, hwnd, 80, 3, 13);
1033 bartitle(&cp, "Options controlling PuTTY's window",
1034 IDC_TITLE_WINDOW);
1035 beginbox(&cp, "Set the size of the window", IDC_BOX_WINDOW1);
1036 multiedit(&cp,
1037 "&Rows", IDC_ROWSSTATIC, IDC_ROWSEDIT, 50,
1038 "Colu&mns", IDC_COLSSTATIC, IDC_COLSEDIT, 50, NULL);
1039 checkbox(&cp, "Lock window size against resi&zing", IDC_LOCKSIZE);
1040 endbox(&cp);
1041 beginbox(&cp, "Control the scrollback in the window",
1042 IDC_BOX_WINDOW2);
1043 staticedit(&cp, "Lines of &scrollback",
1044 IDC_SAVESTATIC, IDC_SAVEEDIT, 50);
1045 checkbox(&cp, "&Display scrollbar", IDC_SCROLLBAR);
1046 checkbox(&cp, "Reset scrollback on &keypress", IDC_SCROLLKEY);
1047 checkbox(&cp, "Reset scrollback on dis&play activity",
1048 IDC_SCROLLDISP);
1049 endbox(&cp);
1050 beginbox(&cp, NULL, IDC_BOX_WINDOW3);
1051 checkbox(&cp, "&Warn before closing window", IDC_CLOSEWARN);
1052 checkbox(&cp, "Window closes on ALT-F&4", IDC_ALTF4);
1053 checkbox(&cp, "S&ystem menu appears on ALT-Space", IDC_ALTSPACE);
1054 checkbox(&cp, "System menu appears on A&LT alone", IDC_ALTONLY);
1055 checkbox(&cp, "Ensure window is always on &top", IDC_ALWAYSONTOP);
1056 endbox(&cp);
1057 }
1058
1059 if (panel == appearancepanelstart) {
1060 /* The Appearance panel. Accelerators used: [acgo] luvb h ti p s */
1061 struct ctlpos cp;
1062 ctlposinit(&cp, hwnd, 80, 3, 13);
1063 bartitle(&cp, "Options controlling PuTTY's appearance",
1064 IDC_TITLE_APPEARANCE);
1065 beginbox(&cp, "Adjust the use of the cursor", IDC_BOX_APPEARANCE1);
1066 radioline(&cp, "Cursor appearance:", IDC_CURSORSTATIC, 3,
1067 "B&lock", IDC_CURBLOCK,
1068 "&Underline", IDC_CURUNDER,
1069 "&Vertical line", IDC_CURVERT, NULL);
1070 checkbox(&cp, "Cursor &blinks", IDC_BLINKCUR);
1071 endbox(&cp);
1072 beginbox(&cp, "Set the font used in the terminal window",
1073 IDC_BOX_APPEARANCE2);
1074 staticbtn(&cp, "", IDC_FONTSTATIC, "C&hange...", IDC_CHOOSEFONT);
1075 endbox(&cp);
1076 beginbox(&cp, "Adjust the use of the window title",
1077 IDC_BOX_APPEARANCE3);
1078 multiedit(&cp,
1079 "Window &title:", IDC_WINTITLE, IDC_WINEDIT, 100, NULL);
1080 checkbox(&cp, "Avoid ever using &icon title", IDC_WINNAME);
1081 endbox(&cp);
1082 beginbox(&cp, "Adjust the use of the mouse pointer",
1083 IDC_BOX_APPEARANCE4);
1084 checkbox(&cp, "Hide mouse &pointer when typing in window",
1085 IDC_HIDEMOUSE);
1086 endbox(&cp);
1087 beginbox(&cp, "Adjust the window border", IDC_BOX_APPEARANCE5);
1088 checkbox(&cp, "&Sunken-edge border (slightly thicker)",
1089 IDC_SUNKENEDGE);
1090 endbox(&cp);
1091 }
1092
1093 if (panel == translationpanelstart) {
1094 /* The Translation panel. Accelerators used: [acgo] xbep t s */
1095 struct ctlpos cp;
1096 ctlposinit(&cp, hwnd, 80, 3, 13);
1097 bartitle(&cp, "Options controlling character set translation",
1098 IDC_TITLE_TRANSLATION);
1099 beginbox(&cp, "Adjust how PuTTY displays line drawing characters",
1100 IDC_BOX_TRANSLATION1);
1101 radiobig(&cp,
1102 "Handling of line drawing characters:", IDC_VTSTATIC,
1103 "Font has &XWindows encoding", IDC_VTXWINDOWS,
1104 "Use font in &both ANSI and OEM modes", IDC_VTOEMANSI,
1105 "Use font in O&EM mode only", IDC_VTOEMONLY,
1106 "&Poor man's line drawing (" "+" ", " "-" " and " "|" ")",
1107 IDC_VTPOORMAN, "&Unicode mode", IDC_VTUNICODE, NULL);
1108 endbox(&cp);
1109 beginbox(&cp, "Character set translation on received data",
1110 IDC_BOX_TRANSLATION2);
1111 dropdownlist(&cp,
1112 "Received data assumed to be in which character set:",
1113 IDC_CODEPAGESTATIC, IDC_CODEPAGE);
1114 endbox(&cp);
1115 }
1116
1117 if (panel == selectionpanelstart) {
1118 /* The Selection panel. Accelerators used: [acgo] d wx hst */
1119 struct ctlpos cp;
1120 ctlposinit(&cp, hwnd, 80, 3, 13);
1121 bartitle(&cp, "Options controlling copy and paste",
1122 IDC_TITLE_SELECTION);
1123 beginbox(&cp, "Translation of pasted characters",
1124 IDC_BOX_SELECTION1);
1125 checkbox(&cp,
1126 "&Don't translate line drawing chars into +, - and |",
1127 IDC_RAWCNP);
1128 endbox(&cp);
1129 beginbox(&cp, "Control which mouse button does which thing",
1130 IDC_BOX_SELECTION2);
1131 radiobig(&cp, "Action of mouse buttons:", IDC_MBSTATIC,
1132 "&Windows (Right pastes, Middle extends)", IDC_MBWINDOWS,
1133 "&xterm (Right extends, Middle pastes)", IDC_MBXTERM,
1134 NULL);
1135 endbox(&cp);
1136 beginbox(&cp, "Control the select-one-word-at-a-time mode",
1137 IDC_BOX_SELECTION3);
1138 charclass(&cp, "C&haracter classes:", IDC_CCSTATIC, IDC_CCLIST,
1139 "&Set", IDC_CCSET, IDC_CCEDIT,
1140 "&to class", IDC_CCSTATIC2);
1141 endbox(&cp);
1142 }
1143
1144 if (panel == colourspanelstart) {
1145 /* The Colours panel. Accelerators used: [acgo] blum */
1146 struct ctlpos cp;
1147 ctlposinit(&cp, hwnd, 80, 3, 13);
1148 bartitle(&cp, "Options controlling use of colours",
1149 IDC_TITLE_COLOURS);
1150 beginbox(&cp, "General options for colour usage",
1151 IDC_BOX_COLOURS1);
1152 checkbox(&cp, "&Bolded text is a different colour",
1153 IDC_BOLDCOLOUR);
1154 checkbox(&cp, "Attempt to use &logical palettes", IDC_PALETTE);
1155 endbox(&cp);
1156 beginbox(&cp, "Adjust the precise colours PuTTY displays",
1157 IDC_BOX_COLOURS2);
1158 colouredit(&cp, "Select a colo&ur and then click to modify it:",
1159 IDC_COLOURSTATIC, IDC_COLOURLIST,
1160 "&Modify...", IDC_CHANGE,
1161 "Red:", IDC_RSTATIC, IDC_RVALUE,
1162 "Green:", IDC_GSTATIC, IDC_GVALUE,
1163 "Blue:", IDC_BSTATIC, IDC_BVALUE, NULL);
1164 endbox(&cp);
1165 }
1166
1167 if (panel == connectionpanelstart) {
1168 /* The Connection panel. Accelerators used: [acgo] tuk */
1169 struct ctlpos cp;
1170 ctlposinit(&cp, hwnd, 80, 3, 13);
1171 bartitle(&cp, "Options controlling the connection",
1172 IDC_TITLE_CONNECTION);
1173 if (dlgtype == 0) {
1174 beginbox(&cp, "Data to send to the server",
1175 IDC_BOX_CONNECTION1);
1176 staticedit(&cp, "Terminal-&type string", IDC_TTSTATIC,
1177 IDC_TTEDIT, 50);
1178 staticedit(&cp, "Auto-login &username", IDC_LOGSTATIC,
1179 IDC_LOGEDIT, 50);
1180 endbox(&cp);
1181 } else {
1182 beginbox(&cp, "Adjust telnet session.", IDC_BOX_CONNECTION1);
1183 checkbox(&cp, "Keyboard sends telnet Backspace and Interrupt",
1184 IDC_TELNETKEY);
1185 endbox(&cp);
1186 }
1187 beginbox(&cp, "Sending of null packets to keep session active",
1188 IDC_BOX_CONNECTION2);
1189 staticedit(&cp, "Seconds between &keepalives (0 to turn off)",
1190 IDC_PINGSTATIC, IDC_PINGEDIT, 20);
1191 endbox(&cp);
1192 }
1193
1194 if (panel == telnetpanelstart) {
1195 /* The Telnet panel. Accelerators used: [acgo] svldr bftk */
1196 struct ctlpos cp;
1197 ctlposinit(&cp, hwnd, 80, 3, 13);
1198 if (dlgtype == 0) {
1199 bartitle(&cp, "Options controlling Telnet connections",
1200 IDC_TITLE_TELNET);
1201 beginbox(&cp, "Data to send to the server", IDC_BOX_TELNET1);
1202 staticedit(&cp, "Terminal-&speed string", IDC_TSSTATIC,
1203 IDC_TSEDIT, 50);
1204 envsetter(&cp, "Environment variables:", IDC_ENVSTATIC,
1205 "&Variable", IDC_VARSTATIC, IDC_VAREDIT, "Va&lue",
1206 IDC_VALSTATIC, IDC_VALEDIT, IDC_ENVLIST, "A&dd",
1207 IDC_ENVADD, "&Remove", IDC_ENVREMOVE);
1208 endbox(&cp);
1209 beginbox(&cp, "Telnet protocol adjustments", IDC_BOX_TELNET2);
1210 radioline(&cp, "Handling of OLD_ENVIRON ambiguity:",
1211 IDC_EMSTATIC, 2, "&BSD (commonplace)", IDC_EMBSD,
1212 "R&FC 1408 (unusual)", IDC_EMRFC, NULL);
1213 radioline(&cp, "&Telnet negotiation mode:", IDC_ACTSTATIC, 2,
1214 "Passive", IDC_TPASSIVE, "Active",
1215 IDC_TACTIVE, NULL);
1216 checkbox(&cp, "&Keyboard sends telnet Backspace and Interrupt",
1217 IDC_TELNETKEY);
1218 endbox(&cp);
1219 }
1220 }
1221
1222 if (panel == rloginpanelstart) {
1223 /* The Rlogin panel. Accelerators used: [acgo] sl */
1224 struct ctlpos cp;
1225 ctlposinit(&cp, hwnd, 80, 3, 13);
1226 if (dlgtype == 0) {
1227 bartitle(&cp, "Options controlling Rlogin connections",
1228 IDC_TITLE_RLOGIN);
1229 beginbox(&cp, "Data to send to the server", IDC_BOX_RLOGIN1);
1230 staticedit(&cp, "Terminal-&speed string", IDC_R_TSSTATIC,
1231 IDC_R_TSEDIT, 50);
1232 staticedit(&cp, "&Local username:", IDC_RLLUSERSTATIC,
1233 IDC_RLLUSEREDIT, 50);
1234 endbox(&cp);
1235 }
1236 }
1237
1238 if (panel == sshpanelstart) {
1239 /* The SSH panel. Accelerators used: [acgo] r pe12i sud */
1240 struct ctlpos cp;
1241 ctlposinit(&cp, hwnd, 80, 3, 13);
1242 if (dlgtype == 0) {
1243 bartitle(&cp, "Options controlling SSH connections",
1244 IDC_TITLE_SSH);
1245 beginbox(&cp, "Data to send to the server", IDC_BOX_SSH1);
1246 multiedit(&cp,
1247 "&Remote command:", IDC_CMDSTATIC, IDC_CMDEDIT, 100,
1248 NULL);
1249 endbox(&cp);
1250 beginbox(&cp, "Protocol options", IDC_BOX_SSH2);
1251 checkbox(&cp, "Don't allocate a &pseudo-terminal", IDC_NOPTY);
1252 checkbox(&cp, "Enable compr&ession", IDC_COMPRESS);
1253 radioline(&cp, "Preferred SSH protocol version:",
1254 IDC_SSHPROTSTATIC, 2,
1255 "&1", IDC_SSHPROT1, "&2", IDC_SSHPROT2, NULL);
1256 checkbox(&cp, "&Imitate SSH 2 MAC bug in commercial <= v2.3.x",
1257 IDC_BUGGYMAC);
1258 endbox(&cp);
1259 beginbox(&cp, "Encryption options", IDC_BOX_SSH3);
1260 prefslist(&cipherlist, &cp, "Encryption cipher &selection policy:",
1261 IDC_CIPHERSTATIC2, IDC_CIPHERLIST, IDC_CIPHERUP,
1262 IDC_CIPHERDN);
1263 endbox(&cp);
1264 }
1265 }
1266
1267 if (panel == sshauthpanelstart) {
1268 /* The SSH authentication panel. Accelerators used: [acgo] m fkw */
1269 struct ctlpos cp;
1270 ctlposinit(&cp, hwnd, 80, 3, 13);
1271 if (dlgtype == 0) {
1272 bartitle(&cp, "Options controlling SSH authentication",
1273 IDC_TITLE_SSHAUTH);
1274 beginbox(&cp, "Authentication methods",
1275 IDC_BOX_SSHAUTH1);
1276 checkbox(&cp, "Atte&mpt TIS or CryptoCard authentication",
1277 IDC_AUTHTIS);
1278 endbox(&cp);
1279 beginbox(&cp, "Authentication parameters",
1280 IDC_BOX_SSHAUTH2);
1281 checkbox(&cp, "Allow agent &forwarding", IDC_AGENTFWD);
1282 editbutton(&cp, "Private &key file for authentication:",
1283 IDC_PKSTATIC, IDC_PKEDIT, "Bro&wse...",
1284 IDC_PKBUTTON);
1285 endbox(&cp);
1286 }
1287 }
1288
1289 if (panel == tunnelspanelstart) {
1290 /* The Tunnels panel. Accelerators used: [acgo] deilmrstx */
1291 struct ctlpos cp;
1292 ctlposinit(&cp, hwnd, 80, 3, 13);
1293 if (dlgtype == 0) {
1294 bartitle(&cp, "Options controlling SSH tunnelling",
1295 IDC_TITLE_TUNNELS);
1296 beginbox(&cp, "X11 forwarding", IDC_BOX_TUNNELS1);
1297 checkbox(&cp, "&Enable X11 forwarding", IDC_X11_FORWARD);
1298 multiedit(&cp, "&X display location", IDC_X11_DISPSTATIC,
1299 IDC_X11_DISPLAY, 50, NULL);
1300 endbox(&cp);
1301 beginbox(&cp, "Port forwarding", IDC_BOX_TUNNELS2);
1302 checkbox(&cp, "Local ports accept connections from o&ther hosts", IDC_LPORT_ALL);
1303 staticbtn(&cp, "Forwarded ports:", IDC_PFWDSTATIC,
1304 "&Remove", IDC_PFWDREMOVE);
1305 fwdsetter(&cp, IDC_PFWDLIST,
1306 "Add new forwarded port:", IDC_PFWDSTATIC2,
1307 "&Source port", IDC_SPORTSTATIC, IDC_SPORTEDIT,
1308 "Dest&ination", IDC_DPORTSTATIC, IDC_DPORTEDIT,
1309 "A&dd", IDC_PFWDADD);
1310 bareradioline(&cp, 2,
1311 "&Local", IDC_PFWDLOCAL, "Re&mote", IDC_PFWDREMOTE, NULL);
1312 endbox(&cp);
1313
1314 }
1315 }
1316 }
1317
1318 /*
1319 * Helper function to load the session selected in SESSLIST
1320 * if any, as this is done in more than one place in
1321 * GenericMainDlgProc(). 0 => failure.
1322 */
1323 static int load_selected_session(HWND hwnd)
1324 {
1325 int n = SendDlgItemMessage(hwnd, IDC_SESSLIST,
1326 LB_GETCURSEL, 0, 0);
1327 int isdef;
1328 if (n == LB_ERR) {
1329 MessageBeep(0);
1330 return 0;
1331 }
1332 isdef = !strcmp(sessions[n], "Default Settings");
1333 load_settings(sessions[n], !isdef, &cfg);
1334 init_dlg_ctrls(hwnd, TRUE);
1335 if (!isdef)
1336 SetDlgItemText(hwnd, IDC_SESSEDIT, sessions[n]);
1337 else
1338 SetDlgItemText(hwnd, IDC_SESSEDIT, "");
1339 /* Restore the selection, which will have been clobbered by
1340 * SESSEDIT handling. */
1341 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL, n, 0);
1342 return 1;
1343 }
1344
1345 /*
1346 * This function is the configuration box.
1347 */
1348 static int GenericMainDlgProc(HWND hwnd, UINT msg,
1349 WPARAM wParam, LPARAM lParam, int dlgtype)
1350 {
1351 HWND hw, treeview;
1352 struct treeview_faff tvfaff;
1353 HTREEITEM hsession;
1354 OPENFILENAME of;
1355 char filename[sizeof(cfg.keyfile)];
1356 CHOOSEFONT cf;
1357 LOGFONT lf;
1358 char fontstatic[256];
1359 char portname[32];
1360 struct servent *service;
1361 int i;
1362 static UINT draglistmsg = WM_NULL;
1363
1364 switch (msg) {
1365 case WM_INITDIALOG:
1366 readytogo = 0;
1367 SetWindowLong(hwnd, GWL_USERDATA, 0);
1368 SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
1369 (LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON)));
1370 /*
1371 * Centre the window.
1372 */
1373 { /* centre the window */
1374 RECT rs, rd;
1375
1376 hw = GetDesktopWindow();
1377 if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
1378 MoveWindow(hwnd,
1379 (rs.right + rs.left + rd.left - rd.right) / 2,
1380 (rs.bottom + rs.top + rd.top - rd.bottom) / 2,
1381 rd.right - rd.left, rd.bottom - rd.top, TRUE);
1382 }
1383
1384 /*
1385 * Create the tree view.
1386 */
1387 {
1388 RECT r;
1389 WPARAM font;
1390 HWND tvstatic;
1391
1392 r.left = 3;
1393 r.right = r.left + 75;
1394 r.top = 3;
1395 r.bottom = r.top + 10;
1396 MapDialogRect(hwnd, &r);
1397 tvstatic = CreateWindowEx(0, "STATIC", "Cate&gory:",
1398 WS_CHILD | WS_VISIBLE,
1399 r.left, r.top,
1400 r.right - r.left, r.bottom - r.top,
1401 hwnd, (HMENU) IDCX_TVSTATIC, hinst,
1402 NULL);
1403 font = SendMessage(hwnd, WM_GETFONT, 0, 0);
1404 SendMessage(tvstatic, WM_SETFONT, font, MAKELPARAM(TRUE, 0));
1405
1406 r.left = 3;
1407 r.right = r.left + 75;
1408 r.top = 13;
1409 r.bottom = r.top + 206;
1410 MapDialogRect(hwnd, &r);
1411 treeview = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "",
1412 WS_CHILD | WS_VISIBLE |
1413 WS_TABSTOP | TVS_HASLINES |
1414 TVS_DISABLEDRAGDROP | TVS_HASBUTTONS
1415 | TVS_LINESATROOT |
1416 TVS_SHOWSELALWAYS, r.left, r.top,
1417 r.right - r.left, r.bottom - r.top,
1418 hwnd, (HMENU) IDCX_TREEVIEW, hinst,
1419 NULL);
1420 font = SendMessage(hwnd, WM_GETFONT, 0, 0);
1421 SendMessage(treeview, WM_SETFONT, font, MAKELPARAM(TRUE, 0));
1422 tvfaff.treeview = treeview;
1423 memset(tvfaff.lastat, 0, sizeof(tvfaff.lastat));
1424 }
1425
1426 /*
1427 * Set up the tree view contents.
1428 */
1429 hsession = treeview_insert(&tvfaff, 0, "Session");
1430 treeview_insert(&tvfaff, 1, "Logging");
1431 treeview_insert(&tvfaff, 0, "Terminal");
1432 treeview_insert(&tvfaff, 1, "Keyboard");
1433 treeview_insert(&tvfaff, 1, "Bell");
1434 treeview_insert(&tvfaff, 0, "Window");
1435 treeview_insert(&tvfaff, 1, "Appearance");
1436 treeview_insert(&tvfaff, 1, "Translation");
1437 treeview_insert(&tvfaff, 1, "Selection");
1438 treeview_insert(&tvfaff, 1, "Colours");
1439 treeview_insert(&tvfaff, 0, "Connection");
1440 if (dlgtype == 0) {
1441 treeview_insert(&tvfaff, 1, "Telnet");
1442 treeview_insert(&tvfaff, 1, "Rlogin");
1443 if (backends[3].backend != NULL) {
1444 treeview_insert(&tvfaff, 1, "SSH");
1445 /* XXX long name is ugly */
1446 /* XXX make it closed by default? */
1447 treeview_insert(&tvfaff, 2, "Auth");
1448 treeview_insert(&tvfaff, 2, "Tunnels");
1449 }
1450 }
1451
1452 /*
1453 * Put the treeview selection on to the Session panel. This
1454 * should also cause creation of the relevant controls.
1455 */
1456 TreeView_SelectItem(treeview, hsession);
1457
1458 /*
1459 * Set focus into the first available control.
1460 */
1461 {
1462 HWND ctl;
1463 ctl = GetDlgItem(hwnd, IDC_HOST);
1464 if (!ctl)
1465 ctl = GetDlgItem(hwnd, IDC_CLOSEEXIT);
1466 SetFocus(ctl);
1467 }
1468
1469 SetWindowLong(hwnd, GWL_USERDATA, 1);
1470 sesslist_has_focus = 0;
1471 return 0;
1472 case WM_LBUTTONUP:
1473 /*
1474 * Button release should trigger WM_OK if there was a
1475 * previous double click on the session list.
1476 */
1477 ReleaseCapture();
1478 if (readytogo)
1479 SendMessage(hwnd, WM_COMMAND, IDOK, 0);
1480 break;
1481 case WM_NOTIFY:
1482 if (LOWORD(wParam) == IDCX_TREEVIEW &&
1483 ((LPNMHDR) lParam)->code == TVN_SELCHANGED) {
1484 HTREEITEM i =
1485 TreeView_GetSelection(((LPNMHDR) lParam)->hwndFrom);
1486 TVITEM item;
1487 int j;
1488 char buffer[64];
1489 item.hItem = i;
1490 item.pszText = buffer;
1491 item.cchTextMax = sizeof(buffer);
1492 item.mask = TVIF_TEXT;
1493 TreeView_GetItem(((LPNMHDR) lParam)->hwndFrom, &item);
1494 for (j = controlstartvalue; j < controlendvalue; j++) {
1495 HWND item = GetDlgItem(hwnd, j);
1496 if (item)
1497 DestroyWindow(item);
1498 }
1499 if (!strcmp(buffer, "Session"))
1500 create_controls(hwnd, dlgtype, sessionpanelstart);
1501 if (!strcmp(buffer, "Logging"))
1502 create_controls(hwnd, dlgtype, loggingpanelstart);
1503 if (!strcmp(buffer, "Keyboard"))
1504 create_controls(hwnd, dlgtype, keyboardpanelstart);
1505 if (!strcmp(buffer, "Terminal"))
1506 create_controls(hwnd, dlgtype, terminalpanelstart);
1507 if (!strcmp(buffer, "Bell"))
1508 create_controls(hwnd, dlgtype, bellpanelstart);
1509 if (!strcmp(buffer, "Window"))
1510 create_controls(hwnd, dlgtype, windowpanelstart);
1511 if (!strcmp(buffer, "Appearance"))
1512 create_controls(hwnd, dlgtype, appearancepanelstart);
1513 if (!strcmp(buffer, "Tunnels"))
1514 create_controls(hwnd, dlgtype, tunnelspanelstart);
1515 if (!strcmp(buffer, "Connection"))
1516 create_controls(hwnd, dlgtype, connectionpanelstart);
1517 if (!strcmp(buffer, "Telnet"))
1518 create_controls(hwnd, dlgtype, telnetpanelstart);
1519 if (!strcmp(buffer, "Rlogin"))
1520 create_controls(hwnd, dlgtype, rloginpanelstart);
1521 if (!strcmp(buffer, "SSH"))
1522 create_controls(hwnd, dlgtype, sshpanelstart);
1523 if (!strcmp(buffer, "Auth"))
1524 create_controls(hwnd, dlgtype, sshauthpanelstart);
1525 if (!strcmp(buffer, "Selection"))
1526 create_controls(hwnd, dlgtype, selectionpanelstart);
1527 if (!strcmp(buffer, "Colours"))
1528 create_controls(hwnd, dlgtype, colourspanelstart);
1529 if (!strcmp(buffer, "Translation"))
1530 create_controls(hwnd, dlgtype, translationpanelstart);
1531
1532 init_dlg_ctrls(hwnd, FALSE);
1533
1534 SetFocus(((LPNMHDR) lParam)->hwndFrom); /* ensure focus stays */
1535 return 0;
1536 }
1537 break;
1538 case WM_COMMAND:
1539 /*
1540 * Only process WM_COMMAND once the dialog is fully formed.
1541 */
1542 if (GetWindowLong(hwnd, GWL_USERDATA) == 1)
1543 switch (LOWORD(wParam)) {
1544 case IDOK:
1545 /* Behaviour of the "Open" button is different if the
1546 * session list has focus, *unless* the user just
1547 * double-clicked... */
1548 if (sesslist_has_focus && !readytogo) {
1549 if (!load_selected_session(hwnd)) {
1550 MessageBeep(0);
1551 return 0;
1552 }
1553 }
1554 /* If at this point we have a valid session, go! */
1555 if (*cfg.host)
1556 EndDialog(hwnd, 1);
1557 else
1558 MessageBeep(0);
1559 return 0;
1560 case IDCANCEL:
1561 EndDialog(hwnd, 0);
1562 return 0;
1563 case IDC_PROTTELNET:
1564 case IDC_PROTRLOGIN:
1565 case IDC_PROTSSH:
1566 case IDC_PROTRAW:
1567 if (HIWORD(wParam) == BN_CLICKED ||
1568 HIWORD(wParam) == BN_DOUBLECLICKED) {
1569 int i = IsDlgButtonChecked(hwnd, IDC_PROTSSH);
1570 int j = IsDlgButtonChecked(hwnd, IDC_PROTTELNET);
1571 int k = IsDlgButtonChecked(hwnd, IDC_PROTRLOGIN);
1572 cfg.protocol =
1573 i ? PROT_SSH : j ? PROT_TELNET : k ? PROT_RLOGIN :
1574 PROT_RAW;
1575 if ((cfg.protocol == PROT_SSH && cfg.port != 22)
1576 || (cfg.protocol == PROT_TELNET && cfg.port != 23)
1577 || (cfg.protocol == PROT_RLOGIN
1578 && cfg.port != 513)) {
1579 cfg.port = i ? 22 : j ? 23 : 513;
1580 SetDlgItemInt(hwnd, IDC_PORT, cfg.port, FALSE);
1581 }
1582 }
1583 break;
1584 case IDC_HOST:
1585 if (HIWORD(wParam) == EN_CHANGE)
1586 GetDlgItemText(hwnd, IDC_HOST, cfg.host,
1587 sizeof(cfg.host) - 1);
1588 break;
1589 case IDC_PORT:
1590 if (HIWORD(wParam) == EN_CHANGE) {
1591 GetDlgItemText(hwnd, IDC_PORT, portname, 31);
1592 if (isdigit(portname[0]))
1593 MyGetDlgItemInt(hwnd, IDC_PORT, &cfg.port);
1594 else {
1595 service = getservbyname(portname, NULL);
1596 if (service)
1597 cfg.port = ntohs(service->s_port);
1598 else
1599 cfg.port = 0;
1600 }
1601 }
1602 break;
1603 case IDC_SESSEDIT:
1604 if (HIWORD(wParam) == EN_CHANGE) {
1605 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
1606 (WPARAM) - 1, 0);
1607 GetDlgItemText(hwnd, IDC_SESSEDIT,
1608 savedsession, sizeof(savedsession) - 1);
1609 savedsession[sizeof(savedsession) - 1] = '\0';
1610 }
1611 break;
1612 case IDC_SESSSAVE:
1613 if (HIWORD(wParam) == BN_CLICKED ||
1614 HIWORD(wParam) == BN_DOUBLECLICKED) {
1615 /*
1616 * Save a session
1617 */
1618 char str[2048];
1619 GetDlgItemText(hwnd, IDC_SESSEDIT, str,
1620 sizeof(str) - 1);
1621 if (!*str) {
1622 int n = SendDlgItemMessage(hwnd, IDC_SESSLIST,
1623 LB_GETCURSEL, 0, 0);
1624 if (n == LB_ERR) {
1625 MessageBeep(0);
1626 break;
1627 }
1628 strcpy(str, sessions[n]);
1629 }
1630 save_settings(str, !!strcmp(str, "Default Settings"),
1631 &cfg);
1632 get_sesslist(FALSE);
1633 get_sesslist(TRUE);
1634 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
1635 FALSE, 0);
1636 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT,
1637 0, 0);
1638 for (i = 0; i < nsessions; i++)
1639 SendDlgItemMessage(hwnd, IDC_SESSLIST,
1640 LB_ADDSTRING, 0,
1641 (LPARAM) (sessions[i]));
1642 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
1643 (WPARAM) - 1, 0);
1644 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
1645 TRUE, 0);
1646 InvalidateRect(GetDlgItem(hwnd, IDC_SESSLIST), NULL,
1647 TRUE);
1648 }
1649 break;
1650 case IDC_SESSLIST:
1651 case IDC_SESSLOAD:
1652 if (LOWORD(wParam) == IDC_SESSLIST) {
1653 if (HIWORD(wParam) == LBN_SETFOCUS)
1654 sesslist_has_focus = 1;
1655 else if (HIWORD(wParam) == LBN_KILLFOCUS)
1656 sesslist_has_focus = 0;
1657 }
1658 if (LOWORD(wParam) == IDC_SESSLOAD &&
1659 HIWORD(wParam) != BN_CLICKED &&
1660 HIWORD(wParam) != BN_DOUBLECLICKED) break;
1661 if (LOWORD(wParam) == IDC_SESSLIST &&
1662 HIWORD(wParam) != LBN_DBLCLK) break;
1663 /* Load the session selected in SESSLIST. */
1664 if (load_selected_session(hwnd) &&
1665 LOWORD(wParam) == IDC_SESSLIST) {
1666 /*
1667 * A double-click on a saved session should
1668 * actually start the session, not just load it.
1669 * Unless it's Default Settings or some other
1670 * host-less set of saved settings.
1671 */
1672 if (*cfg.host) {
1673 readytogo = TRUE;
1674 SetCapture(hwnd);
1675 }
1676 }
1677 break;
1678 case IDC_SESSDEL:
1679 if (HIWORD(wParam) == BN_CLICKED ||
1680 HIWORD(wParam) == BN_DOUBLECLICKED) {
1681 int n = SendDlgItemMessage(hwnd, IDC_SESSLIST,
1682 LB_GETCURSEL, 0, 0);
1683 if (n == LB_ERR || n == 0) {
1684 MessageBeep(0);
1685 break;
1686 }
1687 del_settings(sessions[n]);
1688 get_sesslist(FALSE);
1689 get_sesslist(TRUE);
1690 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
1691 FALSE, 0);
1692 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT,
1693 0, 0);
1694 for (i = 0; i < nsessions; i++)
1695 SendDlgItemMessage(hwnd, IDC_SESSLIST,
1696 LB_ADDSTRING, 0,
1697 (LPARAM) (sessions[i]));
1698 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
1699 (WPARAM) - 1, 0);
1700 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
1701 TRUE, 0);
1702 InvalidateRect(GetDlgItem(hwnd, IDC_SESSLIST), NULL,
1703 TRUE);
1704 }
1705 case IDC_PINGEDIT:
1706 if (HIWORD(wParam) == EN_CHANGE)
1707 MyGetDlgItemInt(hwnd, IDC_PINGEDIT,
1708 &cfg.ping_interval);
1709 break;
1710 case IDC_DEL008:
1711 case IDC_DEL127:
1712 if (HIWORD(wParam) == BN_CLICKED ||
1713 HIWORD(wParam) == BN_DOUBLECLICKED)
1714 cfg.bksp_is_delete =
1715 IsDlgButtonChecked(hwnd, IDC_DEL127);
1716 break;
1717 case IDC_HOMETILDE:
1718 case IDC_HOMERXVT:
1719 if (HIWORD(wParam) == BN_CLICKED ||
1720 HIWORD(wParam) == BN_DOUBLECLICKED)
1721 cfg.rxvt_homeend =
1722 IsDlgButtonChecked(hwnd, IDC_HOMERXVT);
1723 break;
1724 case IDC_FUNCTILDE:
1725 case IDC_FUNCLINUX:
1726 case IDC_FUNCXTERM:
1727 case IDC_FUNCVT400:
1728 case IDC_FUNCVT100P:
1729 case IDC_FUNCSCO:
1730 if (HIWORD(wParam) == BN_CLICKED ||
1731 HIWORD(wParam) == BN_DOUBLECLICKED)
1732 switch (LOWORD(wParam)) {
1733 case IDC_FUNCTILDE:
1734 cfg.funky_type = 0;
1735 break;
1736 case IDC_FUNCLINUX:
1737 cfg.funky_type = 1;
1738 break;
1739 case IDC_FUNCXTERM:
1740 cfg.funky_type = 2;
1741 break;
1742 case IDC_FUNCVT400:
1743 cfg.funky_type = 3;
1744 break;
1745 case IDC_FUNCVT100P:
1746 cfg.funky_type = 4;
1747 break;
1748 case IDC_FUNCSCO:
1749 cfg.funky_type = 5;
1750 break;
1751 }
1752 break;
1753 case IDC_KPNORMAL:
1754 case IDC_KPAPPLIC:
1755 if (HIWORD(wParam) == BN_CLICKED ||
1756 HIWORD(wParam) == BN_DOUBLECLICKED) {
1757 cfg.app_keypad =
1758 IsDlgButtonChecked(hwnd, IDC_KPAPPLIC);
1759 cfg.nethack_keypad = FALSE;
1760 }
1761 break;
1762 case IDC_KPNH:
1763 if (HIWORD(wParam) == BN_CLICKED ||
1764 HIWORD(wParam) == BN_DOUBLECLICKED) {
1765 cfg.app_keypad = FALSE;
1766 cfg.nethack_keypad = TRUE;
1767 }
1768 break;
1769 case IDC_CURNORMAL:
1770 case IDC_CURAPPLIC:
1771 if (HIWORD(wParam) == BN_CLICKED ||
1772 HIWORD(wParam) == BN_DOUBLECLICKED)
1773 cfg.app_cursor =
1774 IsDlgButtonChecked(hwnd, IDC_CURAPPLIC);
1775 break;
1776 case IDC_NOAPPLICC:
1777 if (HIWORD(wParam) == BN_CLICKED ||
1778 HIWORD(wParam) == BN_DOUBLECLICKED)
1779 cfg.no_applic_c =
1780 IsDlgButtonChecked(hwnd, IDC_NOAPPLICC);
1781 break;
1782 case IDC_NOAPPLICK:
1783 if (HIWORD(wParam) == BN_CLICKED ||
1784 HIWORD(wParam) == BN_DOUBLECLICKED)
1785 cfg.no_applic_k =
1786 IsDlgButtonChecked(hwnd, IDC_NOAPPLICK);
1787 break;
1788 case IDC_ALTF4:
1789 if (HIWORD(wParam) == BN_CLICKED ||
1790 HIWORD(wParam) == BN_DOUBLECLICKED)
1791 cfg.alt_f4 = IsDlgButtonChecked(hwnd, IDC_ALTF4);
1792 break;
1793 case IDC_ALTSPACE:
1794 if (HIWORD(wParam) == BN_CLICKED ||
1795 HIWORD(wParam) == BN_DOUBLECLICKED)
1796 cfg.alt_space =
1797 IsDlgButtonChecked(hwnd, IDC_ALTSPACE);
1798 break;
1799 case IDC_ALTONLY:
1800 if (HIWORD(wParam) == BN_CLICKED ||
1801 HIWORD(wParam) == BN_DOUBLECLICKED)
1802 cfg.alt_only =
1803 IsDlgButtonChecked(hwnd, IDC_ALTONLY);
1804 break;
1805 case IDC_ECHOBACKEND:
1806 case IDC_ECHOYES:
1807 case IDC_ECHONO:
1808 if (HIWORD(wParam) == BN_CLICKED ||
1809 HIWORD(wParam) == BN_DOUBLECLICKED) {
1810 if (LOWORD(wParam) == IDC_ECHOBACKEND)
1811 cfg.localecho = LD_BACKEND;
1812 if (LOWORD(wParam) == IDC_ECHOYES)
1813 cfg.localecho = LD_YES;
1814 if (LOWORD(wParam) == IDC_ECHONO)
1815 cfg.localecho = LD_NO;
1816 }
1817 break;
1818 case IDC_EDITBACKEND:
1819 case IDC_EDITYES:
1820 case IDC_EDITNO:
1821 if (HIWORD(wParam) == BN_CLICKED ||
1822 HIWORD(wParam) == BN_DOUBLECLICKED) {
1823 if (LOWORD(wParam) == IDC_EDITBACKEND)
1824 cfg.localedit = LD_BACKEND;
1825 if (LOWORD(wParam) == IDC_EDITYES)
1826 cfg.localedit = LD_YES;
1827 if (LOWORD(wParam) == IDC_EDITNO)
1828 cfg.localedit = LD_NO;
1829 }
1830 break;
1831 case IDC_ANSWEREDIT:
1832 if (HIWORD(wParam) == EN_CHANGE)
1833 GetDlgItemText(hwnd, IDC_ANSWEREDIT, cfg.answerback,
1834 sizeof(cfg.answerback) - 1);
1835 break;
1836 case IDC_ALWAYSONTOP:
1837 if (HIWORD(wParam) == BN_CLICKED ||
1838 HIWORD(wParam) == BN_DOUBLECLICKED)
1839 cfg.alwaysontop =
1840 IsDlgButtonChecked(hwnd, IDC_ALWAYSONTOP);
1841 break;
1842 case IDC_SCROLLKEY:
1843 if (HIWORD(wParam) == BN_CLICKED ||
1844 HIWORD(wParam) == BN_DOUBLECLICKED)
1845 cfg.scroll_on_key =
1846 IsDlgButtonChecked(hwnd, IDC_SCROLLKEY);
1847 break;
1848 case IDC_SCROLLDISP:
1849 if (HIWORD(wParam) == BN_CLICKED ||
1850 HIWORD(wParam) == BN_DOUBLECLICKED)
1851 cfg.scroll_on_disp =
1852 IsDlgButtonChecked(hwnd, IDC_SCROLLDISP);
1853 break;
1854 case IDC_COMPOSEKEY:
1855 if (HIWORD(wParam) == BN_CLICKED ||
1856 HIWORD(wParam) == BN_DOUBLECLICKED)
1857 cfg.compose_key =
1858 IsDlgButtonChecked(hwnd, IDC_COMPOSEKEY);
1859 break;
1860 case IDC_CTRLALTKEYS:
1861 if (HIWORD(wParam) == BN_CLICKED ||
1862 HIWORD(wParam) == BN_DOUBLECLICKED)
1863 cfg.ctrlaltkeys =
1864 IsDlgButtonChecked(hwnd, IDC_CTRLALTKEYS);
1865 break;
1866 case IDC_TELNETKEY:
1867 if (HIWORD(wParam) == BN_CLICKED ||
1868 HIWORD(wParam) == BN_DOUBLECLICKED)
1869 cfg.telnet_keyboard =
1870 IsDlgButtonChecked(hwnd, IDC_TELNETKEY);
1871 break;
1872 case IDC_WRAPMODE:
1873 if (HIWORD(wParam) == BN_CLICKED ||
1874 HIWORD(wParam) == BN_DOUBLECLICKED)
1875 cfg.wrap_mode =
1876 IsDlgButtonChecked(hwnd, IDC_WRAPMODE);
1877 break;
1878 case IDC_DECOM:
1879 if (HIWORD(wParam) == BN_CLICKED ||
1880 HIWORD(wParam) == BN_DOUBLECLICKED)
1881 cfg.dec_om = IsDlgButtonChecked(hwnd, IDC_DECOM);
1882 break;
1883 case IDC_LFHASCR:
1884 if (HIWORD(wParam) == BN_CLICKED ||
1885 HIWORD(wParam) == BN_DOUBLECLICKED)
1886 cfg.lfhascr =
1887 IsDlgButtonChecked(hwnd, IDC_LFHASCR);
1888 break;
1889 case IDC_ROWSEDIT:
1890 if (HIWORD(wParam) == EN_CHANGE)
1891 MyGetDlgItemInt(hwnd, IDC_ROWSEDIT, &cfg.height);
1892 break;
1893 case IDC_COLSEDIT:
1894 if (HIWORD(wParam) == EN_CHANGE)
1895 MyGetDlgItemInt(hwnd, IDC_COLSEDIT, &cfg.width);
1896 break;
1897 case IDC_SAVEEDIT:
1898 if (HIWORD(wParam) == EN_CHANGE)
1899 MyGetDlgItemInt(hwnd, IDC_SAVEEDIT, &cfg.savelines);
1900 break;
1901 case IDC_CHOOSEFONT:
1902 {
1903 HDC hdc = GetDC(0);
1904 lf.lfHeight = -MulDiv(cfg.fontheight,
1905 GetDeviceCaps(hdc, LOGPIXELSY),
1906 72);
1907 ReleaseDC(0, hdc);
1908 }
1909 lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0;
1910 lf.lfItalic = lf.lfUnderline = lf.lfStrikeOut = 0;
1911 lf.lfWeight = (cfg.fontisbold ? FW_BOLD : 0);
1912 lf.lfCharSet = cfg.fontcharset;
1913 lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
1914 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1915 lf.lfQuality = DEFAULT_QUALITY;
1916 lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1917 strncpy(lf.lfFaceName, cfg.font,
1918 sizeof(lf.lfFaceName) - 1);
1919 lf.lfFaceName[sizeof(lf.lfFaceName) - 1] = '\0';
1920
1921 cf.lStructSize = sizeof(cf);
1922 cf.hwndOwner = hwnd;
1923 cf.lpLogFont = &lf;
1924 cf.Flags = CF_FIXEDPITCHONLY | CF_FORCEFONTEXIST |
1925 CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
1926
1927 if (ChooseFont(&cf)) {
1928 strncpy(cfg.font, lf.lfFaceName, sizeof(cfg.font) - 1);
1929 cfg.font[sizeof(cfg.font) - 1] = '\0';
1930 cfg.fontisbold = (lf.lfWeight == FW_BOLD);
1931 cfg.fontcharset = lf.lfCharSet;
1932 cfg.fontheight = cf.iPointSize / 10;
1933 fmtfont(fontstatic);
1934 SetDlgItemText(hwnd, IDC_FONTSTATIC, fontstatic);
1935 }
1936 break;
1937 case IDC_BELL_DISABLED:
1938 case IDC_BELL_DEFAULT:
1939 case IDC_BELL_WAVEFILE:
1940 case IDC_BELL_VISUAL:
1941 if (HIWORD(wParam) == BN_CLICKED ||
1942 HIWORD(wParam) == BN_DOUBLECLICKED) {
1943 if (LOWORD(wParam) == IDC_BELL_DISABLED)
1944 cfg.beep = BELL_DISABLED;
1945 if (LOWORD(wParam) == IDC_BELL_DEFAULT)
1946 cfg.beep = BELL_DEFAULT;
1947 if (LOWORD(wParam) == IDC_BELL_WAVEFILE)
1948 cfg.beep = BELL_WAVEFILE;
1949 if (LOWORD(wParam) == IDC_BELL_VISUAL)
1950 cfg.beep = BELL_VISUAL;
1951 }
1952 break;
1953 case IDC_B_IND_DISABLED:
1954 case IDC_B_IND_FLASH:
1955 case IDC_B_IND_STEADY:
1956 if (HIWORD(wParam) == BN_CLICKED ||
1957 HIWORD(wParam) == BN_DOUBLECLICKED) {
1958 if (LOWORD(wParam) == IDC_B_IND_DISABLED)
1959 cfg.beep_ind = B_IND_DISABLED;
1960 if (LOWORD(wParam) == IDC_B_IND_FLASH)
1961 cfg.beep_ind = B_IND_FLASH;
1962 if (LOWORD(wParam) == IDC_B_IND_STEADY)
1963 cfg.beep_ind = B_IND_STEADY;
1964 }
1965 break;
1966 case IDC_BELL_WAVEBROWSE:
1967 memset(&of, 0, sizeof(of));
1968 #ifdef OPENFILENAME_SIZE_VERSION_400
1969 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
1970 #else
1971 of.lStructSize = sizeof(of);
1972 #endif
1973 of.hwndOwner = hwnd;
1974 of.lpstrFilter = "Wave Files\0*.WAV\0AllFiles\0*\0\0\0";
1975 of.lpstrCustomFilter = NULL;
1976 of.nFilterIndex = 1;
1977 of.lpstrFile = filename;
1978 strcpy(filename, cfg.bell_wavefile);
1979 of.nMaxFile = sizeof(filename);
1980 of.lpstrFileTitle = NULL;
1981 of.lpstrInitialDir = NULL;
1982 of.lpstrTitle = "Select Bell Sound File";
1983 of.Flags = 0;
1984 if (GetOpenFileName(&of)) {
1985 strcpy(cfg.bell_wavefile, filename);
1986 SetDlgItemText(hwnd, IDC_BELL_WAVEEDIT,
1987 cfg.bell_wavefile);
1988 }
1989 break;
1990 case IDC_BELL_WAVEEDIT:
1991 if (HIWORD(wParam) == EN_CHANGE)
1992 GetDlgItemText(hwnd, IDC_BELL_WAVEEDIT,
1993 cfg.bell_wavefile,
1994 sizeof(cfg.bell_wavefile) - 1);
1995 break;
1996 case IDC_BELLOVL:
1997 if (HIWORD(wParam) == BN_CLICKED ||
1998 HIWORD(wParam) == BN_DOUBLECLICKED)
1999 cfg.bellovl =
2000 IsDlgButtonChecked(hwnd, IDC_BELLOVL);
2001 break;
2002 case IDC_BELLOVLN:
2003 if (HIWORD(wParam) == EN_CHANGE)
2004 MyGetDlgItemInt(hwnd, IDC_BELLOVLN, &cfg.bellovl_n);
2005 break;
2006 case IDC_BELLOVLT:
2007 if (HIWORD(wParam) == EN_CHANGE)
2008 MyGetDlgItemFlt(hwnd, IDC_BELLOVLT, &cfg.bellovl_t,
2009 1000);
2010 break;
2011 case IDC_BELLOVLS:
2012 if (HIWORD(wParam) == EN_CHANGE)
2013 MyGetDlgItemFlt(hwnd, IDC_BELLOVLS, &cfg.bellovl_s,
2014 1000);
2015 break;
2016 case IDC_BLINKTEXT:
2017 if (HIWORD(wParam) == BN_CLICKED ||
2018 HIWORD(wParam) == BN_DOUBLECLICKED)
2019 cfg.blinktext =
2020 IsDlgButtonChecked(hwnd, IDC_BLINKTEXT);
2021 break;
2022 case IDC_BCE:
2023 if (HIWORD(wParam) == BN_CLICKED ||
2024 HIWORD(wParam) == BN_DOUBLECLICKED)
2025 cfg.bce = IsDlgButtonChecked(hwnd, IDC_BCE);
2026 break;
2027 case IDC_WINNAME:
2028 if (HIWORD(wParam) == BN_CLICKED ||
2029 HIWORD(wParam) == BN_DOUBLECLICKED)
2030 cfg.win_name_always =
2031 IsDlgButtonChecked(hwnd, IDC_WINNAME);
2032 break;
2033 case IDC_HIDEMOUSE:
2034 if (HIWORD(wParam) == BN_CLICKED ||
2035 HIWORD(wParam) == BN_DOUBLECLICKED)
2036 cfg.hide_mouseptr =
2037 IsDlgButtonChecked(hwnd, IDC_HIDEMOUSE);
2038 break;
2039 case IDC_SUNKENEDGE:
2040 if (HIWORD(wParam) == BN_CLICKED ||
2041 HIWORD(wParam) == BN_DOUBLECLICKED)
2042 cfg.sunken_edge =
2043 IsDlgButtonChecked(hwnd, IDC_SUNKENEDGE);
2044 break;
2045 case IDC_CURBLOCK:
2046 if (HIWORD(wParam) == BN_CLICKED ||
2047 HIWORD(wParam) == BN_DOUBLECLICKED)
2048 cfg.cursor_type = 0;
2049 break;
2050 case IDC_CURUNDER:
2051 if (HIWORD(wParam) == BN_CLICKED ||
2052 HIWORD(wParam) == BN_DOUBLECLICKED)
2053 cfg.cursor_type = 1;
2054 break;
2055 case IDC_CURVERT:
2056 if (HIWORD(wParam) == BN_CLICKED ||
2057 HIWORD(wParam) == BN_DOUBLECLICKED)
2058 cfg.cursor_type = 2;
2059 break;
2060 case IDC_BLINKCUR:
2061 if (HIWORD(wParam) == BN_CLICKED ||
2062 HIWORD(wParam) == BN_DOUBLECLICKED)
2063 cfg.blink_cur =
2064 IsDlgButtonChecked(hwnd, IDC_BLINKCUR);
2065 break;
2066 case IDC_SCROLLBAR:
2067 if (HIWORD(wParam) == BN_CLICKED ||
2068 HIWORD(wParam) == BN_DOUBLECLICKED)
2069 cfg.scrollbar =
2070 IsDlgButtonChecked(hwnd, IDC_SCROLLBAR);
2071 break;
2072 case IDC_LOCKSIZE:
2073 if (HIWORD(wParam) == BN_CLICKED ||
2074 HIWORD(wParam) == BN_DOUBLECLICKED)
2075 cfg.locksize =
2076 IsDlgButtonChecked(hwnd, IDC_LOCKSIZE);
2077 break;
2078 case IDC_WINEDIT:
2079 if (HIWORD(wParam) == EN_CHANGE)
2080 GetDlgItemText(hwnd, IDC_WINEDIT, cfg.wintitle,
2081 sizeof(cfg.wintitle) - 1);
2082 break;
2083 case IDC_COEALWAYS:
2084 case IDC_COENEVER:
2085 case IDC_COENORMAL:
2086 if (HIWORD(wParam) == BN_CLICKED ||
2087 HIWORD(wParam) == BN_DOUBLECLICKED) {
2088 cfg.close_on_exit =
2089 IsDlgButtonChecked(hwnd,
2090 IDC_COEALWAYS) ? COE_ALWAYS :
2091 IsDlgButtonChecked(hwnd,
2092 IDC_COENEVER) ? COE_NEVER :
2093 COE_NORMAL;
2094 }
2095 break;
2096 case IDC_CLOSEWARN:
2097 if (HIWORD(wParam) == BN_CLICKED ||
2098 HIWORD(wParam) == BN_DOUBLECLICKED)
2099 cfg.warn_on_close =
2100 IsDlgButtonChecked(hwnd, IDC_CLOSEWARN);
2101 break;
2102 case IDC_TTEDIT:
2103 if (HIWORD(wParam) == EN_CHANGE)
2104 GetDlgItemText(hwnd, IDC_TTEDIT, cfg.termtype,
2105 sizeof(cfg.termtype) - 1);
2106 break;
2107 case IDC_LGFEDIT:
2108 if (HIWORD(wParam) == EN_CHANGE)
2109 GetDlgItemText(hwnd, IDC_LGFEDIT, cfg.logfilename,
2110 sizeof(cfg.logfilename) - 1);
2111 break;
2112 case IDC_LGFBUTTON:
2113 memset(&of, 0, sizeof(of));
2114 #ifdef OPENFILENAME_SIZE_VERSION_400
2115 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
2116 #else
2117 of.lStructSize = sizeof(of);
2118 #endif
2119 of.hwndOwner = hwnd;
2120 of.lpstrFilter = "All Files\0*\0\0\0";
2121 of.lpstrCustomFilter = NULL;
2122 of.nFilterIndex = 1;
2123 of.lpstrFile = filename;
2124 strcpy(filename, cfg.logfilename);
2125 of.nMaxFile = sizeof(filename);
2126 of.lpstrFileTitle = NULL;
2127 of.lpstrInitialDir = NULL;
2128 of.lpstrTitle = "Select session log file";
2129 of.Flags = 0;
2130 if (GetSaveFileName(&of)) {
2131 strcpy(cfg.logfilename, filename);
2132 SetDlgItemText(hwnd, IDC_LGFEDIT, cfg.logfilename);
2133 }
2134 break;
2135 case IDC_LSTATOFF:
2136 case IDC_LSTATASCII:
2137 case IDC_LSTATRAW:
2138 if (HIWORD(wParam) == BN_CLICKED ||
2139 HIWORD(wParam) == BN_DOUBLECLICKED) {
2140 if (IsDlgButtonChecked(hwnd, IDC_LSTATOFF))
2141 cfg.logtype = 0;
2142 if (IsDlgButtonChecked(hwnd, IDC_LSTATASCII))
2143 cfg.logtype = 1;
2144 if (IsDlgButtonChecked(hwnd, IDC_LSTATRAW))
2145 cfg.logtype = 2;
2146 }
2147 break;
2148 case IDC_LSTATXASK:
2149 case IDC_LSTATXAPN:
2150 case IDC_LSTATXOVR:
2151 if (HIWORD(wParam) == BN_CLICKED ||
2152 HIWORD(wParam) == BN_DOUBLECLICKED) {
2153 if (IsDlgButtonChecked(hwnd, IDC_LSTATXASK))
2154 cfg.logxfovr = LGXF_ASK;
2155 if (IsDlgButtonChecked(hwnd, IDC_LSTATXAPN))
2156 cfg.logxfovr = LGXF_APN;
2157 if (IsDlgButtonChecked(hwnd, IDC_LSTATXOVR))
2158 cfg.logxfovr = LGXF_OVR;
2159 }
2160 break;
2161 case IDC_TSEDIT:
2162 case IDC_R_TSEDIT:
2163 if (HIWORD(wParam) == EN_CHANGE)
2164 GetDlgItemText(hwnd, LOWORD(wParam), cfg.termspeed,
2165 sizeof(cfg.termspeed) - 1);
2166 break;
2167 case IDC_LOGEDIT:
2168 if (HIWORD(wParam) == EN_CHANGE)
2169 GetDlgItemText(hwnd, IDC_LOGEDIT, cfg.username,
2170 sizeof(cfg.username) - 1);
2171 break;
2172 case IDC_RLLUSEREDIT:
2173 if (HIWORD(wParam) == EN_CHANGE)
2174 GetDlgItemText(hwnd, IDC_RLLUSEREDIT,
2175 cfg.localusername,
2176 sizeof(cfg.localusername) - 1);
2177 break;
2178 case IDC_EMBSD:
2179 case IDC_EMRFC:
2180 cfg.rfc_environ = IsDlgButtonChecked(hwnd, IDC_EMRFC);
2181 break;
2182 case IDC_TPASSIVE:
2183 case IDC_TACTIVE:
2184 cfg.passive_telnet =
2185 IsDlgButtonChecked(hwnd, IDC_TPASSIVE);
2186 break;
2187 case IDC_ENVADD:
2188 if (HIWORD(wParam) == BN_CLICKED ||
2189 HIWORD(wParam) == BN_DOUBLECLICKED) {
2190 char str[sizeof(cfg.environmt)];
2191 char *p;
2192 GetDlgItemText(hwnd, IDC_VAREDIT, str,
2193 sizeof(str) - 1);
2194 if (!*str) {
2195 MessageBeep(0);
2196 break;
2197 }
2198 p = str + strlen(str);
2199 *p++ = '\t';
2200 GetDlgItemText(hwnd, IDC_VALEDIT, p,
2201 sizeof(str) - 1 - (p - str));
2202 if (!*p) {
2203 MessageBeep(0);
2204 break;
2205 }
2206 p = cfg.environmt;
2207 while (*p) {
2208 while (*p)
2209 p++;
2210 p++;
2211 }
2212 if ((p - cfg.environmt) + strlen(str) + 2 <
2213 sizeof(cfg.environmt)) {
2214 strcpy(p, str);
2215 p[strlen(str) + 1] = '\0';
2216 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_ADDSTRING,
2217 0, (LPARAM) str);
2218 SetDlgItemText(hwnd, IDC_VAREDIT, "");
2219 SetDlgItemText(hwnd, IDC_VALEDIT, "");
2220 } else {
2221 MessageBox(hwnd, "Environment too big",
2222 "PuTTY Error", MB_OK | MB_ICONERROR);
2223 }
2224 }
2225 break;
2226 case IDC_ENVREMOVE:
2227 if (HIWORD(wParam) != BN_CLICKED &&
2228 HIWORD(wParam) != BN_DOUBLECLICKED) break;
2229 i =
2230 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_GETCURSEL, 0,
2231 0);
2232 if (i == LB_ERR)
2233 MessageBeep(0);
2234 else {
2235 char *p, *q;
2236
2237 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_DELETESTRING,
2238 i, 0);
2239 p = cfg.environmt;
2240 while (i > 0) {
2241 if (!*p)
2242 goto disaster;
2243 while (*p)
2244 p++;
2245 p++;
2246 i--;
2247 }
2248 q = p;
2249 if (!*p)
2250 goto disaster;
2251 while (*p)
2252 p++;
2253 p++;
2254 while (*p) {
2255 while (*p)
2256 *q++ = *p++;
2257 *q++ = *p++;
2258 }
2259 *q = '\0';
2260 disaster:;
2261 }
2262 break;
2263 case IDC_NOPTY:
2264 if (HIWORD(wParam) == BN_CLICKED ||
2265 HIWORD(wParam) == BN_DOUBLECLICKED)
2266 cfg.nopty = IsDlgButtonChecked(hwnd, IDC_NOPTY);
2267 break;
2268 case IDC_COMPRESS:
2269 if (HIWORD(wParam) == BN_CLICKED ||
2270 HIWORD(wParam) == BN_DOUBLECLICKED)
2271 cfg.compression =
2272 IsDlgButtonChecked(hwnd, IDC_COMPRESS);
2273 break;
2274 case IDC_BUGGYMAC:
2275 if (HIWORD(wParam) == BN_CLICKED ||
2276 HIWORD(wParam) == BN_DOUBLECLICKED)
2277 cfg.buggymac =
2278 IsDlgButtonChecked(hwnd, IDC_BUGGYMAC);
2279 break;
2280 case IDC_AGENTFWD:
2281 if (HIWORD(wParam) == BN_CLICKED ||
2282 HIWORD(wParam) == BN_DOUBLECLICKED)
2283 cfg.agentfwd =
2284 IsDlgButtonChecked(hwnd, IDC_AGENTFWD);
2285 break;
2286 case IDC_CIPHERLIST:
2287 case IDC_CIPHERUP:
2288 case IDC_CIPHERDN:
2289 handle_prefslist(&cipherlist,
2290 cfg.ssh_cipherlist, CIPHER_MAX,
2291 0, hwnd, wParam, lParam);
2292 break;
2293 case IDC_SSHPROT1:
2294 case IDC_SSHPROT2:
2295 if (HIWORD(wParam) == BN_CLICKED ||
2296 HIWORD(wParam) == BN_DOUBLECLICKED) {
2297 if (IsDlgButtonChecked(hwnd, IDC_SSHPROT1))
2298 cfg.sshprot = 1;
2299 else if (IsDlgButtonChecked(hwnd, IDC_SSHPROT2))
2300 cfg.sshprot = 2;
2301 }
2302 break;
2303 case IDC_AUTHTIS:
2304 if (HIWORD(wParam) == BN_CLICKED ||
2305 HIWORD(wParam) == BN_DOUBLECLICKED)
2306 cfg.try_tis_auth =
2307 IsDlgButtonChecked(hwnd, IDC_AUTHTIS);
2308 break;
2309 case IDC_PKEDIT:
2310 if (HIWORD(wParam) == EN_CHANGE)
2311 GetDlgItemText(hwnd, IDC_PKEDIT, cfg.keyfile,
2312 sizeof(cfg.keyfile) - 1);
2313 break;
2314 case IDC_CMDEDIT:
2315 if (HIWORD(wParam) == EN_CHANGE)
2316 GetDlgItemText(hwnd, IDC_CMDEDIT, cfg.remote_cmd,
2317 sizeof(cfg.remote_cmd) - 1);
2318 break;
2319 case IDC_PKBUTTON:
2320 memset(&of, 0, sizeof(of));
2321 #ifdef OPENFILENAME_SIZE_VERSION_400
2322 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
2323 #else
2324 of.lStructSize = sizeof(of);
2325 #endif
2326 of.hwndOwner = hwnd;
2327 of.lpstrFilter = "All Files\0*\0\0\0";
2328 of.lpstrCustomFilter = NULL;
2329 of.nFilterIndex = 1;
2330 of.lpstrFile = filename;
2331 strcpy(filename, cfg.keyfile);
2332 of.nMaxFile = sizeof(filename);
2333 of.lpstrFileTitle = NULL;
2334 of.lpstrInitialDir = NULL;
2335 of.lpstrTitle = "Select Public Key File";
2336 of.Flags = 0;
2337 if (GetOpenFileName(&of)) {
2338 strcpy(cfg.keyfile, filename);
2339 SetDlgItemText(hwnd, IDC_PKEDIT, cfg.keyfile);
2340 }
2341 break;
2342 case IDC_RAWCNP:
2343 cfg.rawcnp = IsDlgButtonChecked(hwnd, IDC_RAWCNP);
2344 case IDC_MBWINDOWS:
2345 case IDC_MBXTERM:
2346 cfg.mouse_is_xterm = IsDlgButtonChecked(hwnd, IDC_MBXTERM);
2347 break;
2348 case IDC_CCSET:
2349 {
2350 BOOL ok;
2351 int i;
2352 int n = GetDlgItemInt(hwnd, IDC_CCEDIT, &ok, FALSE);
2353
2354 if (!ok)
2355 MessageBeep(0);
2356 else {
2357 for (i = 0; i < 128; i++)
2358 if (SendDlgItemMessage
2359 (hwnd, IDC_CCLIST, LB_GETSEL, i, 0)) {
2360 char str[100];
2361 cfg.wordness[i] = n;
2362 SendDlgItemMessage(hwnd, IDC_CCLIST,
2363 LB_DELETESTRING, i, 0);
2364 sprintf(str, "%d\t(0x%02X)\t%c\t%d", i, i,
2365 (i >= 0x21 && i != 0x7F) ? i : ' ',
2366 cfg.wordness[i]);
2367 SendDlgItemMessage(hwnd, IDC_CCLIST,
2368 LB_INSERTSTRING, i,
2369 (LPARAM) str);
2370 }
2371 }
2372 }
2373 break;
2374 case IDC_BOLDCOLOUR:
2375 if (HIWORD(wParam) == BN_CLICKED ||
2376 HIWORD(wParam) == BN_DOUBLECLICKED) {
2377 int n, i;
2378 cfg.bold_colour =
2379 IsDlgButtonChecked(hwnd, IDC_BOLDCOLOUR);
2380 SendDlgItemMessage(hwnd, IDC_COLOURLIST, WM_SETREDRAW,
2381 FALSE, 0);
2382 n =
2383 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2384 LB_GETCOUNT, 0, 0);
2385 if (n != 12 + 10 * cfg.bold_colour) {
2386 for (i = n; i-- > 0;)
2387 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2388 LB_DELETESTRING, i, 0);
2389 for (i = 0; i < 22; i++)
2390 if (cfg.bold_colour || permcolour[i])
2391 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2392 LB_ADDSTRING, 0,
2393 (LPARAM) colours[i]);
2394 }
2395 SendDlgItemMessage(hwnd, IDC_COLOURLIST, WM_SETREDRAW,
2396 TRUE, 0);
2397 InvalidateRect(GetDlgItem(hwnd, IDC_COLOURLIST), NULL,
2398 TRUE);
2399 }
2400 break;
2401 case IDC_PALETTE:
2402 if (HIWORD(wParam) == BN_CLICKED ||
2403 HIWORD(wParam) == BN_DOUBLECLICKED)
2404 cfg.try_palette =
2405 IsDlgButtonChecked(hwnd, IDC_PALETTE);
2406 break;
2407 case IDC_COLOURLIST:
2408 if (HIWORD(wParam) == LBN_DBLCLK ||
2409 HIWORD(wParam) == LBN_SELCHANGE) {
2410 int i =
2411 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2412 LB_GETCURSEL,
2413 0, 0);
2414 if (!cfg.bold_colour)
2415 i = (i < 3 ? i * 2 : i == 3 ? 5 : i * 2 - 2);
2416 SetDlgItemInt(hwnd, IDC_RVALUE, cfg.colours[i][0],
2417 FALSE);
2418 SetDlgItemInt(hwnd, IDC_GVALUE, cfg.colours[i][1],
2419 FALSE);
2420 SetDlgItemInt(hwnd, IDC_BVALUE, cfg.colours[i][2],
2421 FALSE);
2422 }
2423 break;
2424 case IDC_CHANGE:
2425 if (HIWORD(wParam) == BN_CLICKED ||
2426 HIWORD(wParam) == BN_DOUBLECLICKED) {
2427 static CHOOSECOLOR cc;
2428 static DWORD custom[16] = { 0 }; /* zero initialisers */
2429 int i =
2430 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2431 LB_GETCURSEL,
2432 0, 0);
2433 if (!cfg.bold_colour)
2434 i = (i < 3 ? i * 2 : i == 3 ? 5 : i * 2 - 2);
2435 cc.lStructSize = sizeof(cc);
2436 cc.hwndOwner = hwnd;
2437 cc.hInstance = (HWND) hinst;
2438 cc.lpCustColors = custom;
2439 cc.rgbResult =
2440 RGB(cfg.colours[i][0], cfg.colours[i][1],
2441 cfg.colours[i][2]);
2442 cc.Flags = CC_FULLOPEN | CC_RGBINIT;
2443 if (ChooseColor(&cc)) {
2444 cfg.colours[i][0] =
2445 (unsigned char) (cc.rgbResult & 0xFF);
2446 cfg.colours[i][1] =
2447 (unsigned char) (cc.rgbResult >> 8) & 0xFF;
2448 cfg.colours[i][2] =
2449 (unsigned char) (cc.rgbResult >> 16) & 0xFF;
2450 SetDlgItemInt(hwnd, IDC_RVALUE, cfg.colours[i][0],
2451 FALSE);
2452 SetDlgItemInt(hwnd, IDC_GVALUE, cfg.colours[i][1],
2453 FALSE);
2454 SetDlgItemInt(hwnd, IDC_BVALUE, cfg.colours[i][2],
2455 FALSE);
2456 }
2457 }
2458 break;
2459 case IDC_CODEPAGE:
2460 if (HIWORD(wParam) == CBN_SELCHANGE) {
2461 int index = SendDlgItemMessage(hwnd, IDC_CODEPAGE,
2462 CB_GETCURSEL, 0, 0);
2463 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_GETLBTEXT,
2464 index, (LPARAM)cfg.line_codepage);
2465 }
2466 break;
2467 case IDC_VTXWINDOWS:
2468 case IDC_VTOEMANSI:
2469 case IDC_VTOEMONLY:
2470 case IDC_VTPOORMAN:
2471 case IDC_VTUNICODE:
2472 cfg.vtmode =
2473 (IsDlgButtonChecked(hwnd, IDC_VTXWINDOWS) ? VT_XWINDOWS
2474 : IsDlgButtonChecked(hwnd,
2475 IDC_VTOEMANSI) ? VT_OEMANSI :
2476 IsDlgButtonChecked(hwnd,
2477 IDC_VTOEMONLY) ? VT_OEMONLY :
2478 IsDlgButtonChecked(hwnd,
2479 IDC_VTUNICODE) ? VT_UNICODE :
2480 VT_POORMAN);
2481 break;
2482 case IDC_X11_FORWARD:
2483 if (HIWORD(wParam) == BN_CLICKED ||
2484 HIWORD(wParam) == BN_DOUBLECLICKED)
2485 cfg.x11_forward =
2486 IsDlgButtonChecked(hwnd, IDC_X11_FORWARD);
2487 break;
2488 case IDC_LPORT_ALL:
2489 if (HIWORD(wParam) == BN_CLICKED ||
2490 HIWORD(wParam) == BN_DOUBLECLICKED)
2491 cfg.lport_acceptall =
2492 IsDlgButtonChecked(hwnd, IDC_LPORT_ALL);
2493 break;
2494 case IDC_X11_DISPLAY:
2495 if (HIWORD(wParam) == EN_CHANGE)
2496 GetDlgItemText(hwnd, IDC_X11_DISPLAY, cfg.x11_display,
2497 sizeof(cfg.x11_display) - 1);
2498 break;
2499 case IDC_PFWDADD:
2500 if (HIWORD(wParam) == BN_CLICKED ||
2501 HIWORD(wParam) == BN_DOUBLECLICKED) {
2502 char str[sizeof(cfg.portfwd)];
2503 char *p;
2504 if (IsDlgButtonChecked(hwnd, IDC_PFWDLOCAL))
2505 str[0] = 'L';
2506 else
2507 str[0] = 'R';
2508 GetDlgItemText(hwnd, IDC_SPORTEDIT, str+1,
2509 sizeof(str) - 2);
2510 if (!str[1]) {
2511 MessageBox(hwnd,
2512 "You need to specify a source port number",
2513 "PuTTY Error", MB_OK | MB_ICONERROR);
2514 break;
2515 }
2516 p = str + strlen(str);
2517 *p++ = '\t';
2518 GetDlgItemText(hwnd, IDC_DPORTEDIT, p,
2519 sizeof(str) - 1 - (p - str));
2520 if (!*p || !strchr(p, ':')) {
2521 MessageBox(hwnd,
2522 "You need to specify a destination address\n"
2523 "in the form \"host.name:port\"",
2524 "PuTTY Error", MB_OK | MB_ICONERROR);
2525 break;
2526 }
2527 p = cfg.portfwd;
2528 while (*p) {
2529 while (*p)
2530 p++;
2531 p++;
2532 }
2533 if ((p - cfg.portfwd) + strlen(str) + 2 <
2534 sizeof(cfg.portfwd)) {
2535 strcpy(p, str);
2536 p[strlen(str) + 1] = '\0';
2537 SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_ADDSTRING,
2538 0, (LPARAM) str);
2539 SetDlgItemText(hwnd, IDC_SPORTEDIT, "");
2540 SetDlgItemText(hwnd, IDC_DPORTEDIT, "");
2541 } else {
2542 MessageBox(hwnd, "Too many forwardings",
2543 "PuTTY Error", MB_OK | MB_ICONERROR);
2544 }
2545 }
2546 break;
2547 case IDC_PFWDREMOVE:
2548 if (HIWORD(wParam) != BN_CLICKED &&
2549 HIWORD(wParam) != BN_DOUBLECLICKED) break;
2550 i = SendDlgItemMessage(hwnd, IDC_PFWDLIST,
2551 LB_GETCURSEL, 0, 0);
2552 if (i == LB_ERR)
2553 MessageBeep(0);
2554 else {
2555 char *p, *q;
2556
2557 SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_DELETESTRING,
2558 i, 0);
2559 p = cfg.portfwd;
2560 while (i > 0) {
2561 if (!*p)
2562 goto disaster2;
2563 while (*p)
2564 p++;
2565 p++;
2566 i--;
2567 }
2568 q = p;
2569 if (!*p)
2570 goto disaster2;
2571 while (*p)
2572 p++;
2573 p++;
2574 while (*p) {
2575 while (*p)
2576 *q++ = *p++;
2577 *q++ = *p++;
2578 }
2579 *q = '\0';
2580 disaster2:;
2581 }
2582 break;
2583 }
2584 return 0;
2585 case WM_CLOSE:
2586 EndDialog(hwnd, 0);
2587 return 0;
2588
2589 /* Grrr Explorer will maximize Dialogs! */
2590 case WM_SIZE:
2591 if (wParam == SIZE_MAXIMIZED)
2592 force_normal(hwnd);
2593 return 0;
2594
2595 default:
2596 /*
2597 * Handle application-defined messages eg. DragListBox
2598 */
2599 /* First find out what the number is (once). */
2600 if (draglistmsg == WM_NULL)
2601 draglistmsg = RegisterWindowMessage (DRAGLISTMSGSTRING);
2602
2603 if (msg == draglistmsg) {
2604 /* Only process once dialog is fully formed. */
2605 if (GetWindowLong(hwnd, GWL_USERDATA) == 1) switch (LOWORD(wParam)) {
2606 case IDC_CIPHERLIST:
2607 return handle_prefslist(&cipherlist,
2608 cfg.ssh_cipherlist, CIPHER_MAX,
2609 1, hwnd, wParam, lParam);
2610 }
2611 }
2612 return 0;
2613
2614 }
2615 return 0;
2616 }
2617
2618 static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
2619 WPARAM wParam, LPARAM lParam)
2620 {
2621 if (msg == WM_COMMAND && LOWORD(wParam) == IDOK) {
2622 }
2623 if (msg == WM_COMMAND && LOWORD(wParam) == IDCX_ABOUT) {
2624 EnableWindow(hwnd, 0);
2625 DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
2626 EnableWindow(hwnd, 1);
2627 SetActiveWindow(hwnd);
2628 }
2629 return GenericMainDlgProc(hwnd, msg, wParam, lParam, 0);
2630 }
2631
2632 static int CALLBACK ReconfDlgProc(HWND hwnd, UINT msg,
2633 WPARAM wParam, LPARAM lParam)
2634 {
2635 return GenericMainDlgProc(hwnd, msg, wParam, lParam, 1);
2636 }
2637
2638 void defuse_showwindow(void)
2639 {
2640 /*
2641 * Work around the fact that the app's first call to ShowWindow
2642 * will ignore the default in favour of the shell-provided
2643 * setting.
2644 */
2645 {
2646 HWND hwnd;
2647 hwnd = CreateDialog(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX),
2648 NULL, NullDlgProc);
2649 ShowWindow(hwnd, SW_HIDE);
2650 SetActiveWindow(hwnd);
2651 DestroyWindow(hwnd);
2652 }
2653 }
2654
2655 int do_config(void)
2656 {
2657 int ret;
2658
2659 get_sesslist(TRUE);
2660 savedsession[0] = '\0';
2661 ret =
2662 DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL, MainDlgProc);
2663 get_sesslist(FALSE);
2664
2665 return ret;
2666 }
2667
2668 int do_reconfig(HWND hwnd)
2669 {
2670 Config backup_cfg;
2671 int ret;
2672
2673 backup_cfg = cfg; /* structure copy */
2674 ret =
2675 DialogBox(hinst, MAKEINTRESOURCE(IDD_RECONF), hwnd, ReconfDlgProc);
2676 if (!ret)
2677 cfg = backup_cfg; /* structure copy */
2678
2679 return ret;
2680 }
2681
2682 void logevent(char *string)
2683 {
2684 char timebuf[40];
2685 time_t t;
2686
2687 if (nevents >= negsize) {
2688 negsize += 64;
2689 events = srealloc(events, negsize * sizeof(*events));
2690 }
2691
2692 time(&t);
2693 strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
2694 localtime(&t));
2695
2696 events[nevents] = smalloc(strlen(timebuf) + strlen(string) + 1);
2697 strcpy(events[nevents], timebuf);
2698 strcat(events[nevents], string);
2699 if (logbox) {
2700 int count;
2701 SendDlgItemMessage(logbox, IDN_LIST, LB_ADDSTRING,
2702 0, (LPARAM) events[nevents]);
2703 count = SendDlgItemMessage(logbox, IDN_LIST, LB_GETCOUNT, 0, 0);
2704 SendDlgItemMessage(logbox, IDN_LIST, LB_SETTOPINDEX, count - 1, 0);
2705 }
2706 nevents++;
2707 }
2708
2709 void showeventlog(HWND hwnd)
2710 {
2711 if (!logbox) {
2712 logbox = CreateDialog(hinst, MAKEINTRESOURCE(IDD_LOGBOX),
2713 hwnd, LogProc);
2714 ShowWindow(logbox, SW_SHOWNORMAL);
2715 }
2716 SetActiveWindow(logbox);
2717 }
2718
2719 void showabout(HWND hwnd)
2720 {
2721 DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
2722 }
2723
2724 void verify_ssh_host_key(char *host, int port, char *keytype,
2725 char *keystr, char *fingerprint)
2726 {
2727 int ret;
2728
2729 static const char absentmsg[] =
2730 "The server's host key is not cached in the registry. You\n"
2731 "have no guarantee that the server is the computer you\n"
2732 "think it is.\n"
2733 "The server's key fingerprint is:\n"
2734 "%s\n"
2735 "If you trust this host, hit Yes to add the key to\n"
2736 "PuTTY's cache and carry on connecting.\n"
2737 "If you want to carry on connecting just once, without\n"
2738 "adding the key to the cache, hit No.\n"
2739 "If you do not trust this host, hit Cancel to abandon the\n"
2740 "connection.\n";
2741
2742 static const char wrongmsg[] =
2743 "WARNING - POTENTIAL SECURITY BREACH!\n"
2744 "\n"
2745 "The server's host key does not match the one PuTTY has\n"
2746 "cached in the registry. This means that either the\n"
2747 "server administrator has changed the host key, or you\n"
2748 "have actually connected to another computer pretending\n"
2749 "to be the server.\n"
2750 "The new key fingerprint is:\n"
2751 "%s\n"
2752 "If you were expecting this change and trust the new key,\n"
2753 "hit Yes to update PuTTY's cache and continue connecting.\n"
2754 "If you want to carry on connecting but without updating\n"
2755 "the cache, hit No.\n"
2756 "If you want to abandon the connection completely, hit\n"
2757 "Cancel. Hitting Cancel is the ONLY guaranteed safe\n" "choice.\n";
2758
2759 static const char mbtitle[] = "PuTTY Security Alert";
2760
2761 char message[160 +
2762 /* sensible fingerprint max size */
2763 (sizeof(absentmsg) > sizeof(wrongmsg) ?
2764 sizeof(absentmsg) : sizeof(wrongmsg))];
2765
2766 /*
2767 * Verify the key against the registry.
2768 */
2769 ret = verify_host_key(host, port, keytype, keystr);
2770
2771 if (ret == 0) /* success - key matched OK */
2772 return;
2773 if (ret == 2) { /* key was different */
2774 int mbret;
2775 sprintf(message, wrongmsg, fingerprint);
2776 mbret = MessageBox(NULL, message, mbtitle,
2777 MB_ICONWARNING | MB_YESNOCANCEL);
2778 if (mbret == IDYES)
2779 store_host_key(host, port, keytype, keystr);
2780 if (mbret == IDCANCEL)
2781 exit(0);
2782 }
2783 if (ret == 1) { /* key was absent */
2784 int mbret;
2785 sprintf(message, absentmsg, fingerprint);
2786 mbret = MessageBox(NULL, message, mbtitle,
2787 MB_ICONWARNING | MB_YESNOCANCEL);
2788 if (mbret == IDYES)
2789 store_host_key(host, port, keytype, keystr);
2790 if (mbret == IDCANCEL)
2791 exit(0);
2792 }
2793 }
2794
2795 /*
2796 * Ask whether the selected cipher is acceptable (since it was
2797 * below the configured 'warn' threshold).
2798 * cs: 0 = both ways, 1 = client->server, 2 = server->client
2799 */
2800 void askcipher(char *ciphername, int cs)
2801 {
2802 static const char mbtitle[] = "PuTTY Security Alert";
2803 static const char msg[] =
2804 "The first %.35scipher supported by the server\n"
2805 "is %.64s, which is below the configured\n"
2806 "warning threshold.\n"
2807 "Do you want to continue with this connection?\n";
2808 /* guessed cipher name + type max length */
2809 char message[100 + sizeof(msg)];
2810 int mbret;
2811
2812 sprintf(message, msg,
2813 (cs == 0) ? "" :
2814 (cs == 1) ? "client-to-server " :
2815 "server-to-client ",
2816 ciphername);
2817 mbret = MessageBox(NULL, message, mbtitle,
2818 MB_ICONWARNING | MB_YESNO);
2819 if (mbret == IDYES)
2820 return;
2821 else
2822 exit(0);
2823 }
2824
2825 /*
2826 * Ask whether to wipe a session log file before writing to it.
2827 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
2828 */
2829 int askappend(char *filename)
2830 {
2831 static const char mbtitle[] = "PuTTY Log to File";
2832 static const char msgtemplate[] =
2833 "The session log file \"%.*s\" already exists.\n"
2834 "You can overwrite it with a new session log,\n"
2835 "append your session log to the end of it,\n"
2836 "or disable session logging for this session.\n"
2837 "Hit Yes to wipe the file, No to append to it,\n"
2838 "or Cancel to disable logging.";
2839 char message[sizeof(msgtemplate) + FILENAME_MAX];
2840 int mbret;
2841 if (cfg.logxfovr != LGXF_ASK) {
2842 return ((cfg.logxfovr == LGXF_OVR) ? 2 : 1);
2843 }
2844 sprintf(message, msgtemplate, FILENAME_MAX, filename);
2845
2846 mbret = MessageBox(NULL, message, mbtitle,
2847 MB_ICONQUESTION | MB_YESNOCANCEL);
2848 if (mbret == IDYES)
2849 return 2;
2850 else if (mbret == IDNO)
2851 return 1;
2852 else
2853 return 0;
2854 }