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