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