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