16 #define TVINSERTSTRUCT TV_INSERTSTRUCT
17 #define TVITEM TV_ITEM
21 static char **events = NULL;
22 static int nevents = 0, negsize = 0;
25 static int sesslist_has_focus;
26 static int requested_help;
28 static struct prefslist cipherlist;
30 void force_normal(HWND hwnd)
32 static int recurse = 0;
40 wp.length = sizeof(wp);
41 if (GetWindowPlacement(hwnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) {
42 wp.showCmd = SW_SHOWNORMAL;
43 SetWindowPlacement(hwnd, &wp);
48 static void MyGetDlgItemInt(HWND hwnd, int id, int *result)
52 n = GetDlgItemInt(hwnd, id, &ok, FALSE);
57 static void MyGetDlgItemFlt(HWND hwnd, int id, int *result, int scale)
61 ok = GetDlgItemText(hwnd, id, text, sizeof(text) - 1);
63 *result = (int) (scale * atof(text));
66 static void MySetDlgItemFlt(HWND hwnd, int id, double value)
69 sprintf(text, "%g", value);
70 SetDlgItemText(hwnd, id, text);
73 static int CALLBACK LogProc(HWND hwnd, UINT msg,
74 WPARAM wParam, LPARAM lParam)
81 static int tabs[4] = { 78, 108 };
82 SendDlgItemMessage(hwnd, IDN_LIST, LB_SETTABSTOPS, 2,
85 for (i = 0; i < nevents; i++)
86 SendDlgItemMessage(hwnd, IDN_LIST, LB_ADDSTRING,
87 0, (LPARAM) events[i]);
90 switch (LOWORD(wParam)) {
94 SetActiveWindow(GetParent(hwnd));
98 if (HIWORD(wParam) == BN_CLICKED ||
99 HIWORD(wParam) == BN_DOUBLECLICKED) {
102 selcount = SendDlgItemMessage(hwnd, IDN_LIST,
103 LB_GETSELCOUNT, 0, 0);
104 if (selcount == 0) { /* don't even try to copy zero items */
109 selitems = smalloc(selcount * sizeof(int));
111 int count = SendDlgItemMessage(hwnd, IDN_LIST,
118 static unsigned char sel_nl[] = SEL_NL;
120 if (count == 0) { /* can't copy zero stuff */
126 for (i = 0; i < count; i++)
128 strlen(events[selitems[i]]) + sizeof(sel_nl);
130 clipdata = smalloc(size);
133 for (i = 0; i < count; i++) {
134 char *q = events[selitems[i]];
135 int qlen = strlen(q);
138 memcpy(p, sel_nl, sizeof(sel_nl));
141 write_aclip(clipdata, size, TRUE);
146 for (i = 0; i < nevents; i++)
147 SendDlgItemMessage(hwnd, IDN_LIST, LB_SETSEL,
156 SetActiveWindow(GetParent(hwnd));
163 static int CALLBACK LicenceProc(HWND hwnd, UINT msg,
164 WPARAM wParam, LPARAM lParam)
170 switch (LOWORD(wParam)) {
183 static int CALLBACK AboutProc(HWND hwnd, UINT msg,
184 WPARAM wParam, LPARAM lParam)
188 SetDlgItemText(hwnd, IDA_VERSION, ver);
191 switch (LOWORD(wParam)) {
194 EndDialog(hwnd, TRUE);
197 EnableWindow(hwnd, 0);
198 DialogBox(hinst, MAKEINTRESOURCE(IDD_LICENCEBOX),
200 EnableWindow(hwnd, 1);
201 SetActiveWindow(hwnd);
205 /* Load web browser */
206 ShellExecute(hwnd, "open",
207 "http://www.chiark.greenend.org.uk/~sgtatham/putty/",
208 0, 0, SW_SHOWDEFAULT);
213 EndDialog(hwnd, TRUE);
220 * Null dialog procedure.
222 static int CALLBACK NullDlgProc(HWND hwnd, UINT msg,
223 WPARAM wParam, LPARAM lParam)
228 static char savedsession[2048];
231 IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
370 IDC_SCROLLBARFULLSCREEN,
385 IDC_FULLSCREENONALTENTER,
388 appearancepanelstart,
389 IDC_TITLE_APPEARANCE,
411 connectionpanelstart,
412 IDC_TITLE_CONNECTION,
531 translationpanelstart,
532 IDC_TITLE_TRANSLATION,
533 IDC_BOX_TRANSLATION1,
534 IDC_BOX_TRANSLATION2,
535 IDC_BOX_TRANSLATION3,
573 static const char *const colours[] = {
574 "Default Foreground", "Default Bold Foreground",
575 "Default Background", "Default Bold Background",
576 "Cursor Text", "Cursor Colour",
577 "ANSI Black", "ANSI Black Bold",
578 "ANSI Red", "ANSI Red Bold",
579 "ANSI Green", "ANSI Green Bold",
580 "ANSI Yellow", "ANSI Yellow Bold",
581 "ANSI Blue", "ANSI Blue Bold",
582 "ANSI Magenta", "ANSI Magenta Bold",
583 "ANSI Cyan", "ANSI Cyan Bold",
584 "ANSI White", "ANSI White Bold"
586 static const int permcolour[] = {
587 TRUE, FALSE, TRUE, FALSE, TRUE, TRUE,
588 TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE,
589 TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE
592 static void fmtfont(char *buf)
594 sprintf(buf, "Font: %s, ", cfg.font);
596 strcat(buf, "bold, ");
597 if (cfg.fontheight == 0)
598 strcat(buf, "default height");
600 sprintf(buf + strlen(buf), "%d-point",
601 (cfg.fontheight < 0 ? -cfg.fontheight : cfg.fontheight));
604 char *help_context_cmd(int id)
616 return "JI(`',`session.hostname')";
623 return "JI(`',`session.saved')";
628 return "JI(`',`session.coe')";
629 case IDC_LSTATSTATIC:
633 case IDC_LSTATPACKET:
634 return "JI(`',`logging.main')";
639 return "JI(`',`logging.filename')";
644 return "JI(`',`logging.exists')";
649 return "JI(`',`keyboard.backspace')";
653 return "JI(`',`keyboard.homeend')";
661 return "JI(`',`keyboard.funkeys')";
666 return "JI(`',`keyboard.appkeypad')";
671 return "JI(`',`keyboard.appcursor')";
673 return "JI(`',`keyboard.nethack')";
675 return "JI(`',`keyboard.compose')";
676 case IDC_CTRLALTKEYS:
677 return "JI(`',`keyboard.ctrlalt')";
680 return "JI(`',`terminal.autowrap')";
682 return "JI(`',`terminal.decom')";
684 return "JI(`',`terminal.lfhascr')";
686 return "JI(`',`terminal.bce')";
688 return "JI(`',`terminal.blink')";
691 return "JI(`',`terminal.answerback')";
693 case IDC_ECHOBACKEND:
696 return "JI(`',`terminal.localecho')";
698 case IDC_EDITBACKEND:
701 return "JI(`',`terminal.localedit')";
704 case IDC_BELL_DISABLED:
705 case IDC_BELL_DEFAULT:
706 case IDC_BELL_WAVEFILE:
707 case IDC_BELL_VISUAL:
708 case IDC_BELL_WAVESTATIC:
709 case IDC_BELL_WAVEEDIT:
710 case IDC_BELL_WAVEBROWSE:
711 return "JI(`',`bell.style')";
712 case IDC_B_IND_STATIC:
713 case IDC_B_IND_DISABLED:
714 case IDC_B_IND_FLASH:
715 case IDC_B_IND_STEADY:
716 return "JI(`',`bell.taskbar')";
718 case IDC_BELLOVLNSTATIC:
720 case IDC_BELLOVLTSTATIC:
722 case IDC_BELLOVLEXPLAIN:
723 case IDC_BELLOVLSSTATIC:
725 return "JI(`',`bell.overload')";
731 return "JI(`',`window.size')";
732 case IDC_RESIZESTATIC:
736 case IDC_RESIZEEITHER:
737 return "JI(`',`window.resize')";
739 case IDC_SCROLLBARFULLSCREEN:
744 return "JI(`',`window.scrollback')";
747 return "JI(`',`behaviour.closewarn')";
749 return "JI(`',`behaviour.altf4')";
751 return "JI(`',`behaviour.altspace')";
753 return "JI(`',`behaviour.altonly')";
754 case IDC_ALWAYSONTOP:
755 return "JI(`',`behaviour.alwaysontop')";
756 case IDC_FULLSCREENONALTENTER:
757 return "JI(`',`behaviour.altenter')";
759 case IDC_CURSORSTATIC:
764 return "JI(`',`appearance.cursor')";
767 return "JI(`',`appearance.font')";
771 return "JI(`',`appearance.title')";
773 return "JI(`',`appearance.hidemouse')";
777 return "JI(`',`appearance.border')";
781 return "JI(`',`connection.termtype')";
784 return "JI(`',`connection.username')";
787 return "JI(`',`connection.keepalive')";
789 return "JI(`',`connection.nodelay')";
793 return "JI(`',`telnet.termspeed')";
802 return "JI(`',`telnet.environ')";
806 return "JI(`',`telnet.oldenviron')";
810 return "JI(`',`telnet.passive')";
812 return "JI(`',`telnet.specialkeys')";
814 return "JI(`',`telnet.newline')";
818 return "JI(`',`rlogin.termspeed')";
819 case IDC_RLLUSERSTATIC:
820 case IDC_RLLUSEREDIT:
821 return "JI(`',`rlogin.localuser')";
824 return "JI(`',`ssh.nopty')";
825 case IDC_CIPHERSTATIC2:
830 return "JI(`',`ssh.ciphers')";
832 return "JI(`',`ssh.buggymac')";
833 case IDC_SSHPROTSTATIC:
836 return "JI(`',`ssh.protocol')";
839 return "JI(`',`ssh.command')";
841 return "JI(`',`ssh.compress')";
846 return "JI(`',`ssh.auth.privkey')";
848 return "JI(`',`ssh.auth.agentfwd')";
850 return "JI(`',`ssh.auth.changeuser')";
852 return "JI(`',`ssh.auth.tis')";
854 return "JI(`',`ssh.auth.ki')";
859 return "JI(`',`selection.buttons')";
860 case IDC_MOUSEOVERRIDE:
861 return "JI(`',`selection.shiftdrag')";
862 case IDC_SELTYPESTATIC:
864 case IDC_SELTYPERECT:
865 return "JI(`',`selection.rect')";
871 return "JI(`',`selection.charclasses')";
873 return "JI(`',`selection.linedraw')";
875 return "JI(`',`selection.rtf')";
878 return "JI(`',`colours.bold')";
880 return "JI(`',`colours.logpal')";
881 case IDC_COLOURSTATIC:
890 return "JI(`',`colours.config')";
892 case IDC_CODEPAGESTATIC:
894 return "JI(`',`translation.codepage')";
895 case IDC_CAPSLOCKCYR:
896 return "JI(`',`translation.cyrillic')";
903 return "JI(`',`translation.linedraw')";
905 case IDC_X11_FORWARD:
906 case IDC_X11_DISPSTATIC:
907 case IDC_X11_DISPLAY:
908 return "JI(`',`ssh.tunnels.x11')";
910 case IDC_PFWDSTATIC2:
914 case IDC_SPORTSTATIC:
916 case IDC_DPORTSTATIC:
920 return "JI(`',`ssh.tunnels.portfwd')";
923 return "JI(`',`ssh.tunnels.portfwd.localhost')";
930 /* 2nd arg: NZ => don't redraw session list (use when loading
932 static void init_dlg_ctrls(HWND hwnd, int keepsess)
935 char fontstatic[256];
937 SetDlgItemText(hwnd, IDC_HOST, cfg.host);
938 SetDlgItemText(hwnd, IDC_SESSEDIT, savedsession);
941 n = SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_GETCOUNT, 0, 0);
942 for (i = n; i-- > 0;)
943 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_DELETESTRING, i, 0);
944 for (i = 0; i < nsessions; i++)
945 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_ADDSTRING,
946 0, (LPARAM) (sessions[i]));
948 SetDlgItemInt(hwnd, IDC_PORT, cfg.port, FALSE);
949 CheckRadioButton(hwnd, IDC_PROTRAW, IDC_PROTSSH,
950 cfg.protocol == PROT_SSH ? IDC_PROTSSH :
951 cfg.protocol == PROT_TELNET ? IDC_PROTTELNET :
953 PROT_RLOGIN ? IDC_PROTRLOGIN : IDC_PROTRAW);
954 SetDlgItemInt(hwnd, IDC_PINGEDIT, cfg.ping_interval, FALSE);
955 CheckDlgButton(hwnd, IDC_NODELAY, cfg.tcp_nodelay);
957 CheckRadioButton(hwnd, IDC_DEL008, IDC_DEL127,
958 cfg.bksp_is_delete ? IDC_DEL127 : IDC_DEL008);
959 CheckRadioButton(hwnd, IDC_HOMETILDE, IDC_HOMERXVT,
960 cfg.rxvt_homeend ? IDC_HOMERXVT : IDC_HOMETILDE);
961 CheckRadioButton(hwnd, IDC_FUNCTILDE, IDC_FUNCSCO,
962 cfg.funky_type == 0 ? IDC_FUNCTILDE :
963 cfg.funky_type == 1 ? IDC_FUNCLINUX :
964 cfg.funky_type == 2 ? IDC_FUNCXTERM :
965 cfg.funky_type == 3 ? IDC_FUNCVT400 :
966 cfg.funky_type == 4 ? IDC_FUNCVT100P :
967 cfg.funky_type == 5 ? IDC_FUNCSCO : IDC_FUNCTILDE);
968 CheckDlgButton(hwnd, IDC_NOAPPLICC, cfg.no_applic_c);
969 CheckDlgButton(hwnd, IDC_NOAPPLICK, cfg.no_applic_k);
970 CheckRadioButton(hwnd, IDC_CURNORMAL, IDC_CURAPPLIC,
971 cfg.app_cursor ? IDC_CURAPPLIC : IDC_CURNORMAL);
972 CheckRadioButton(hwnd, IDC_KPNORMAL, IDC_KPNH,
973 cfg.nethack_keypad ? IDC_KPNH :
974 cfg.app_keypad ? IDC_KPAPPLIC : IDC_KPNORMAL);
975 CheckDlgButton(hwnd, IDC_ALTF4, cfg.alt_f4);
976 CheckDlgButton(hwnd, IDC_ALTSPACE, cfg.alt_space);
977 CheckDlgButton(hwnd, IDC_ALTONLY, cfg.alt_only);
978 CheckDlgButton(hwnd, IDC_COMPOSEKEY, cfg.compose_key);
979 CheckDlgButton(hwnd, IDC_CTRLALTKEYS, cfg.ctrlaltkeys);
980 CheckDlgButton(hwnd, IDC_TELNETKEY, cfg.telnet_keyboard);
981 CheckDlgButton(hwnd, IDC_TELNETRET, cfg.telnet_newline);
982 CheckRadioButton(hwnd, IDC_ECHOBACKEND, IDC_ECHONO,
983 cfg.localecho == LD_BACKEND ? IDC_ECHOBACKEND :
984 cfg.localecho == LD_YES ? IDC_ECHOYES : IDC_ECHONO);
985 CheckRadioButton(hwnd, IDC_EDITBACKEND, IDC_EDITNO,
986 cfg.localedit == LD_BACKEND ? IDC_EDITBACKEND :
987 cfg.localedit == LD_YES ? IDC_EDITYES : IDC_EDITNO);
988 SetDlgItemText(hwnd, IDC_ANSWEREDIT, cfg.answerback);
989 CheckDlgButton(hwnd, IDC_ALWAYSONTOP, cfg.alwaysontop);
990 CheckDlgButton(hwnd, IDC_FULLSCREENONALTENTER, cfg.fullscreenonaltenter);
991 CheckDlgButton(hwnd, IDC_SCROLLKEY, cfg.scroll_on_key);
992 CheckDlgButton(hwnd, IDC_SCROLLDISP, cfg.scroll_on_disp);
994 CheckDlgButton(hwnd, IDC_WRAPMODE, cfg.wrap_mode);
995 CheckDlgButton(hwnd, IDC_DECOM, cfg.dec_om);
996 CheckDlgButton(hwnd, IDC_LFHASCR, cfg.lfhascr);
997 SetDlgItemInt(hwnd, IDC_ROWSEDIT, cfg.height, FALSE);
998 SetDlgItemInt(hwnd, IDC_COLSEDIT, cfg.width, FALSE);
999 SetDlgItemInt(hwnd, IDC_SAVEEDIT, cfg.savelines, FALSE);
1000 fmtfont(fontstatic);
1001 SetDlgItemText(hwnd, IDC_FONTSTATIC, fontstatic);
1002 CheckRadioButton(hwnd, IDC_BELL_DISABLED, IDC_BELL_VISUAL,
1003 cfg.beep == BELL_DISABLED ? IDC_BELL_DISABLED :
1004 cfg.beep == BELL_DEFAULT ? IDC_BELL_DEFAULT :
1005 cfg.beep == BELL_WAVEFILE ? IDC_BELL_WAVEFILE :
1007 BELL_VISUAL ? IDC_BELL_VISUAL : IDC_BELL_DEFAULT);
1008 CheckRadioButton(hwnd, IDC_B_IND_DISABLED, IDC_B_IND_STEADY,
1010 B_IND_DISABLED ? IDC_B_IND_DISABLED : cfg.beep_ind ==
1011 B_IND_FLASH ? IDC_B_IND_FLASH : cfg.beep_ind ==
1012 B_IND_STEADY ? IDC_B_IND_STEADY : IDC_B_IND_DISABLED);
1013 SetDlgItemText(hwnd, IDC_BELL_WAVEEDIT, cfg.bell_wavefile);
1014 CheckDlgButton(hwnd, IDC_BELLOVL, cfg.bellovl);
1015 SetDlgItemInt(hwnd, IDC_BELLOVLN, cfg.bellovl_n, FALSE);
1016 MySetDlgItemFlt(hwnd, IDC_BELLOVLT, cfg.bellovl_t / 1000.0);
1017 MySetDlgItemFlt(hwnd, IDC_BELLOVLS, cfg.bellovl_s / 1000.0);
1019 CheckDlgButton(hwnd, IDC_BCE, cfg.bce);
1020 CheckDlgButton(hwnd, IDC_BLINKTEXT, cfg.blinktext);
1022 SetDlgItemText(hwnd, IDC_WINEDIT, cfg.wintitle);
1023 CheckDlgButton(hwnd, IDC_WINNAME, cfg.win_name_always);
1024 CheckDlgButton(hwnd, IDC_HIDEMOUSE, cfg.hide_mouseptr);
1025 CheckDlgButton(hwnd, IDC_SUNKENEDGE, cfg.sunken_edge);
1026 SetDlgItemInt(hwnd, IDC_WINBEDIT, cfg.window_border, FALSE);
1027 CheckRadioButton(hwnd, IDC_CURBLOCK, IDC_CURVERT,
1028 cfg.cursor_type == 0 ? IDC_CURBLOCK :
1029 cfg.cursor_type == 1 ? IDC_CURUNDER : IDC_CURVERT);
1030 CheckDlgButton(hwnd, IDC_BLINKCUR, cfg.blink_cur);
1031 CheckDlgButton(hwnd, IDC_SCROLLBAR, cfg.scrollbar);
1032 CheckDlgButton(hwnd, IDC_SCROLLBARFULLSCREEN, cfg.scrollbar_in_fullscreen);
1033 CheckRadioButton(hwnd, IDC_RESIZETERM, IDC_RESIZEEITHER,
1034 cfg.resize_action == RESIZE_TERM ? IDC_RESIZETERM :
1035 cfg.resize_action == RESIZE_FONT ? IDC_RESIZEFONT :
1036 cfg.resize_action == RESIZE_EITHER ? IDC_RESIZEEITHER :
1038 CheckRadioButton(hwnd, IDC_COEALWAYS, IDC_COENORMAL,
1039 cfg.close_on_exit == COE_NORMAL ? IDC_COENORMAL :
1040 cfg.close_on_exit ==
1041 COE_NEVER ? IDC_COENEVER : IDC_COEALWAYS);
1042 CheckDlgButton(hwnd, IDC_CLOSEWARN, cfg.warn_on_close);
1044 SetDlgItemText(hwnd, IDC_TTEDIT, cfg.termtype);
1045 SetDlgItemText(hwnd, IDC_TSEDIT, cfg.termspeed);
1046 SetDlgItemText(hwnd, IDC_R_TSEDIT, cfg.termspeed);
1047 SetDlgItemText(hwnd, IDC_RLLUSEREDIT, cfg.localusername);
1048 SetDlgItemText(hwnd, IDC_LOGEDIT, cfg.username);
1049 SetDlgItemText(hwnd, IDC_LGFEDIT, cfg.logfilename);
1050 CheckRadioButton(hwnd, IDC_LSTATOFF, IDC_LSTATPACKET,
1051 cfg.logtype == LGTYP_NONE ? IDC_LSTATOFF :
1052 cfg.logtype == LGTYP_ASCII ? IDC_LSTATASCII :
1053 cfg.logtype == LGTYP_DEBUG ? IDC_LSTATRAW :
1055 CheckRadioButton(hwnd, IDC_LSTATXOVR, IDC_LSTATXASK,
1056 cfg.logxfovr == LGXF_OVR ? IDC_LSTATXOVR :
1057 cfg.logxfovr == LGXF_ASK ? IDC_LSTATXASK :
1060 char *p = cfg.environmt;
1061 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_RESETCONTENT, 0, 0);
1063 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_ADDSTRING, 0,
1069 SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_ADDSTRING, 0,
1074 CheckRadioButton(hwnd, IDC_EMBSD, IDC_EMRFC,
1075 cfg.rfc_environ ? IDC_EMRFC : IDC_EMBSD);
1076 CheckRadioButton(hwnd, IDC_TPASSIVE, IDC_TACTIVE,
1077 cfg.passive_telnet ? IDC_TPASSIVE : IDC_TACTIVE);
1079 SetDlgItemText(hwnd, IDC_TTEDIT, cfg.termtype);
1080 SetDlgItemText(hwnd, IDC_LOGEDIT, cfg.username);
1081 CheckDlgButton(hwnd, IDC_NOPTY, cfg.nopty);
1082 CheckDlgButton(hwnd, IDC_COMPRESS, cfg.compression);
1083 CheckDlgButton(hwnd, IDC_BUGGYMAC, cfg.buggymac);
1084 CheckDlgButton(hwnd, IDC_SSH2DES, cfg.ssh2_des_cbc);
1085 CheckDlgButton(hwnd, IDC_AGENTFWD, cfg.agentfwd);
1086 CheckDlgButton(hwnd, IDC_CHANGEUSER, cfg.change_username);
1087 CheckRadioButton(hwnd, IDC_SSHPROT1, IDC_SSHPROT2,
1088 cfg.sshprot == 1 ? IDC_SSHPROT1 : IDC_SSHPROT2);
1089 CheckDlgButton(hwnd, IDC_AUTHTIS, cfg.try_tis_auth);
1090 CheckDlgButton(hwnd, IDC_AUTHKI, cfg.try_ki_auth);
1091 SetDlgItemText(hwnd, IDC_PKEDIT, cfg.keyfile);
1092 SetDlgItemText(hwnd, IDC_CMDEDIT, cfg.remote_cmd);
1096 static const struct { char *s; int c; } ciphers[] = {
1097 { "3DES", CIPHER_3DES },
1098 { "Blowfish", CIPHER_BLOWFISH },
1099 { "DES", CIPHER_DES },
1100 { "AES (SSH 2 only)", CIPHER_AES },
1101 { "-- warn below here --", CIPHER_WARN }
1104 /* Set up the "selected ciphers" box. */
1105 /* (cipherlist assumed to contain all ciphers) */
1106 SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_RESETCONTENT, 0, 0);
1107 for (i = 0; i < CIPHER_MAX; i++) {
1108 int c = cfg.ssh_cipherlist[i];
1111 for (j = 0; j < (sizeof ciphers) / (sizeof ciphers[0]); j++) {
1112 if (ciphers[j].c == c) {
1113 cstr = ciphers[j].s;
1117 pos = SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_ADDSTRING,
1119 SendDlgItemMessage(hwnd, IDC_CIPHERLIST, LB_SETITEMDATA,
1125 CheckRadioButton(hwnd, IDC_MBWINDOWS, IDC_MBXTERM,
1126 cfg.mouse_is_xterm ? IDC_MBXTERM : IDC_MBWINDOWS);
1127 CheckRadioButton(hwnd, IDC_SELTYPELEX, IDC_SELTYPERECT,
1128 cfg.rect_select == 0 ? IDC_SELTYPELEX : IDC_SELTYPERECT);
1129 CheckDlgButton(hwnd, IDC_MOUSEOVERRIDE, cfg.mouse_override);
1130 CheckDlgButton(hwnd, IDC_RAWCNP, cfg.rawcnp);
1131 CheckDlgButton(hwnd, IDC_RTFPASTE, cfg.rtf_paste);
1133 static int tabs[4] = { 25, 61, 96, 128 };
1134 SendDlgItemMessage(hwnd, IDC_CCLIST, LB_SETTABSTOPS, 4,
1137 for (i = 0; i < 128; i++) {
1139 sprintf(str, "%d\t(0x%02X)\t%c\t%d", i, i,
1140 (i >= 0x21 && i != 0x7F) ? i : ' ', cfg.wordness[i]);
1141 SendDlgItemMessage(hwnd, IDC_CCLIST, LB_ADDSTRING, 0,
1145 CheckDlgButton(hwnd, IDC_BOLDCOLOUR, cfg.bold_colour);
1146 CheckDlgButton(hwnd, IDC_PALETTE, cfg.try_palette);
1149 n = SendDlgItemMessage(hwnd, IDC_COLOURLIST, LB_GETCOUNT, 0, 0);
1150 for (i = n; i-- > 0;)
1151 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
1152 LB_DELETESTRING, i, 0);
1153 for (i = 0; i < 22; i++)
1154 if (cfg.bold_colour || permcolour[i])
1155 SendDlgItemMessage(hwnd, IDC_COLOURLIST, LB_ADDSTRING, 0,
1156 (LPARAM) colours[i]);
1158 SendDlgItemMessage(hwnd, IDC_COLOURLIST, LB_SETCURSEL, 0, 0);
1159 SetDlgItemInt(hwnd, IDC_RVALUE, cfg.colours[0][0], FALSE);
1160 SetDlgItemInt(hwnd, IDC_GVALUE, cfg.colours[0][1], FALSE);
1161 SetDlgItemInt(hwnd, IDC_BVALUE, cfg.colours[0][2], FALSE);
1166 strcpy(cfg.line_codepage, cp_name(decode_codepage(cfg.line_codepage)));
1167 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_RESETCONTENT, 0, 0);
1168 CheckDlgButton (hwnd, IDC_CAPSLOCKCYR, cfg.xlat_capslockcyr);
1169 for (i = 0; (cp = cp_enumerate(i)) != NULL; i++) {
1170 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_ADDSTRING,
1173 SetDlgItemText(hwnd, IDC_CODEPAGE, cfg.line_codepage);
1176 CheckRadioButton(hwnd, IDC_VTXWINDOWS, IDC_VTUNICODE,
1177 cfg.vtmode == VT_XWINDOWS ? IDC_VTXWINDOWS :
1178 cfg.vtmode == VT_OEMANSI ? IDC_VTOEMANSI :
1179 cfg.vtmode == VT_OEMONLY ? IDC_VTOEMONLY :
1180 cfg.vtmode == VT_UNICODE ? IDC_VTUNICODE :
1183 CheckDlgButton(hwnd, IDC_X11_FORWARD, cfg.x11_forward);
1184 SetDlgItemText(hwnd, IDC_X11_DISPLAY, cfg.x11_display);
1186 CheckDlgButton(hwnd, IDC_LPORT_ALL, cfg.lport_acceptall);
1187 CheckDlgButton(hwnd, IDC_RPORT_ALL, cfg.rport_acceptall);
1188 CheckRadioButton(hwnd, IDC_PFWDLOCAL, IDC_PFWDREMOTE, IDC_PFWDLOCAL);
1191 struct treeview_faff {
1193 HTREEITEM lastat[4];
1196 static HTREEITEM treeview_insert(struct treeview_faff *faff,
1197 int level, char *text)
1202 ins.hParent = (level > 0 ? faff->lastat[level - 1] : TVI_ROOT);
1203 ins.hInsertAfter = faff->lastat[level];
1204 #if _WIN32_IE >= 0x0400 && defined NONAMELESSUNION
1205 #define INSITEM DUMMYUNIONNAME.item
1207 #define INSITEM item
1209 ins.INSITEM.mask = TVIF_TEXT;
1210 ins.INSITEM.pszText = text;
1211 newitem = TreeView_InsertItem(faff->treeview, &ins);
1213 TreeView_Expand(faff->treeview, faff->lastat[level - 1],
1215 faff->lastat[level] = newitem;
1216 for (i = level + 1; i < 4; i++)
1217 faff->lastat[i] = NULL;
1222 * Create the panelfuls of controls in the configuration box.
1224 static void create_controls(HWND hwnd, int dlgtype, int panel)
1226 if (panel == sessionpanelstart) {
1227 /* The Session panel. Accelerators used: [acgoh] nprtis elvd w */
1229 ctlposinit(&cp, hwnd, 80, 3, 13);
1230 bartitle(&cp, "Basic options for your PuTTY session",
1233 beginbox(&cp, "Specify your connection by host name or IP address",
1236 "Host &Name (or IP address)",
1237 IDC_HOSTSTATIC, IDC_HOST, 75,
1238 "&Port", IDC_PORTSTATIC, IDC_PORT, 25, NULL);
1239 if (backends[3].backend == NULL) {
1240 /* this is PuTTYtel, so only three protocols available */
1241 radioline(&cp, "Protocol:", IDC_PROTSTATIC, 3,
1242 "&Raw", IDC_PROTRAW,
1243 "&Telnet", IDC_PROTTELNET,
1244 "Rlog&in", IDC_PROTRLOGIN, NULL);
1246 radioline(&cp, "Protocol:", IDC_PROTSTATIC, 4,
1247 "&Raw", IDC_PROTRAW,
1248 "&Telnet", IDC_PROTTELNET,
1249 "Rlog&in", IDC_PROTRLOGIN,
1258 beginbox(&cp, "Load, save or delete a stored session",
1260 sesssaver(&cp, "Sav&ed Sessions",
1261 IDC_SESSSTATIC, IDC_SESSEDIT, IDC_SESSLIST,
1262 "&Load", IDC_SESSLOAD,
1263 "Sa&ve", IDC_SESSSAVE, "&Delete", IDC_SESSDEL, NULL);
1266 beginbox(&cp, NULL, IDC_BOX_SESSION3);
1267 radioline(&cp, "Close &window on exit:", IDC_CLOSEEXIT, 4,
1268 "Always", IDC_COEALWAYS,
1269 "Never", IDC_COENEVER,
1270 "Only on clean exit", IDC_COENORMAL, NULL);
1274 if (panel == loggingpanelstart) {
1275 /* The Logging panel. Accelerators used: [acgoh] tplsfwe */
1277 ctlposinit(&cp, hwnd, 80, 3, 13);
1278 bartitle(&cp, "Options controlling session logging",
1280 beginbox(&cp, NULL, IDC_BOX_LOGGING1);
1282 "Session logging:", IDC_LSTATSTATIC,
1283 "Logging &turned off completely", IDC_LSTATOFF,
1284 "Log &printable output only", IDC_LSTATASCII,
1285 "&Log all session output", IDC_LSTATRAW,
1286 "Log &SSH packet data", IDC_LSTATPACKET,
1288 editbutton(&cp, "Log &file name:",
1289 IDC_LGFSTATIC, IDC_LGFEDIT, "Bro&wse...",
1291 statictext(&cp, "(Log file name can contain &&Y, &&M, &&D for date,"
1292 " &&T for time, and &&H for host name)", 2, IDC_LGFEXPLAIN);
1294 "What to do if the log file already &exists:",
1295 IDC_LSTATXIST, "Always overwrite it", IDC_LSTATXOVR,
1296 "Always append to the end of it", IDC_LSTATXAPN,
1297 "Ask the user every time", IDC_LSTATXASK, NULL);
1301 if (panel == terminalpanelstart) {
1302 /* The Terminal panel. Accelerators used: [acgoh] wdren lts */
1304 ctlposinit(&cp, hwnd, 80, 3, 13);
1305 bartitle(&cp, "Options controlling the terminal emulation",
1306 IDC_TITLE_TERMINAL);
1307 beginbox(&cp, "Set various terminal options", IDC_BOX_TERMINAL1);
1308 checkbox(&cp, "Auto &wrap mode initially on", IDC_WRAPMODE);
1309 checkbox(&cp, "&DEC Origin Mode initially on", IDC_DECOM);
1310 checkbox(&cp, "Implicit C&R in every LF", IDC_LFHASCR);
1311 checkbox(&cp, "Use background colour to &erase screen", IDC_BCE);
1312 checkbox(&cp, "Enable bli&nking text", IDC_BLINKTEXT);
1314 "An&swerback to ^E:", IDC_ANSWERBACK,
1315 IDC_ANSWEREDIT, 100, NULL);
1318 beginbox(&cp, "Line discipline options", IDC_BOX_TERMINAL2);
1319 radioline(&cp, "&Local echo:", IDC_ECHOSTATIC, 3,
1320 "Auto", IDC_ECHOBACKEND,
1321 "Force on", IDC_ECHOYES, "Force off", IDC_ECHONO, NULL);
1322 radioline(&cp, "Local line edi&ting:", IDC_EDITSTATIC, 3,
1323 "Auto", IDC_EDITBACKEND,
1324 "Force on", IDC_EDITYES, "Force off", IDC_EDITNO, NULL);
1328 if (panel == bellpanelstart) {
1329 /* The Bell panel. Accelerators used: [acgoh] bdsm wit */
1331 ctlposinit(&cp, hwnd, 80, 3, 13);
1332 bartitle(&cp, "Options controlling the terminal bell",
1334 beginbox(&cp, "Set the style of bell", IDC_BOX_BELL1);
1336 "Action to happen when a &bell occurs:", IDC_BELLSTATIC,
1337 "None (bell disabled)", IDC_BELL_DISABLED,
1338 "Play Windows Default Sound", IDC_BELL_DEFAULT,
1339 "Play a custom sound file", IDC_BELL_WAVEFILE,
1340 "Visual bell (flash window)", IDC_BELL_VISUAL, NULL);
1341 editbutton(&cp, "Custom sound file to play as a bell:",
1342 IDC_BELL_WAVESTATIC, IDC_BELL_WAVEEDIT,
1343 "Bro&wse...", IDC_BELL_WAVEBROWSE);
1344 radioline(&cp, "Taskbar/caption &indication on bell:",
1345 IDC_B_IND_STATIC, 3, "Disabled", IDC_B_IND_DISABLED,
1346 "Flashing", IDC_B_IND_FLASH, "Steady", IDC_B_IND_STEADY,
1349 beginbox(&cp, "Control the bell overload behaviour",
1351 checkbox(&cp, "Bell is temporarily &disabled when over-used",
1353 staticedit(&cp, "Over-use means this &many bells...",
1354 IDC_BELLOVLNSTATIC, IDC_BELLOVLN, 20);
1355 staticedit(&cp, "... in &this many seconds",
1356 IDC_BELLOVLTSTATIC, IDC_BELLOVLT, 20);
1358 "The bell is re-enabled after a few seconds of silence.",
1359 1, IDC_BELLOVLEXPLAIN);
1360 staticedit(&cp, "Seconds of &silence required", IDC_BELLOVLSSTATIC,
1365 if (panel == keyboardpanelstart) {
1366 /* The Keyboard panel. Accelerators used: [acgoh] bef ruyntd */
1368 ctlposinit(&cp, hwnd, 80, 3, 13);
1369 bartitle(&cp, "Options controlling the effects of keys",
1370 IDC_TITLE_KEYBOARD);
1371 beginbox(&cp, "Change the sequences sent by:", IDC_BOX_KEYBOARD1);
1372 radioline(&cp, "The &Backspace key", IDC_DELSTATIC, 2,
1373 "Control-H", IDC_DEL008,
1374 "Control-? (127)", IDC_DEL127, NULL);
1375 radioline(&cp, "The Home and &End keys", IDC_HOMESTATIC, 2,
1376 "Standard", IDC_HOMETILDE, "rxvt", IDC_HOMERXVT, NULL);
1377 radioline(&cp, "The &Function keys and keypad", IDC_FUNCSTATIC, 3,
1378 "ESC[n~", IDC_FUNCTILDE,
1379 "Linux", IDC_FUNCLINUX,
1380 "Xterm R6", IDC_FUNCXTERM,
1381 "VT400", IDC_FUNCVT400,
1382 "VT100+", IDC_FUNCVT100P, "SCO", IDC_FUNCSCO, NULL);
1384 beginbox(&cp, "Application keypad settings:", IDC_BOX_KEYBOARD2);
1386 "Application c&ursor keys totally disabled",
1388 radioline(&cp, "Initial state of cu&rsor keys:", IDC_CURSTATIC, 2,
1389 "Normal", IDC_CURNORMAL,
1390 "Application", IDC_CURAPPLIC, NULL);
1392 "Application ke&ypad keys totally disabled",
1394 radioline(&cp, "Initial state of &numeric keypad:", IDC_KPSTATIC,
1395 3, "Normal", IDC_KPNORMAL, "Application", IDC_KPAPPLIC,
1396 "NetHack", IDC_KPNH, NULL);
1398 beginbox(&cp, "Enable extra keyboard features:",
1400 checkbox(&cp, "AltGr ac&ts as Compose key", IDC_COMPOSEKEY);
1401 checkbox(&cp, "Control-Alt is &different from AltGr",
1406 if (panel == windowpanelstart) {
1407 /* The Window panel. Accelerators used: [acgoh] rmz sdikp */
1409 ctlposinit(&cp, hwnd, 80, 3, 13);
1410 bartitle(&cp, "Options controlling PuTTY's window",
1412 beginbox(&cp, "Set the size of the window", IDC_BOX_WINDOW1);
1414 "&Rows", IDC_ROWSSTATIC, IDC_ROWSEDIT, 50,
1415 "Colu&mns", IDC_COLSSTATIC, IDC_COLSEDIT, 50, NULL);
1416 radiobig(&cp, "When window is resi&zed:", IDC_RESIZESTATIC,
1417 "Change the number of rows and columns", IDC_RESIZETERM,
1418 "Change the size of the font", IDC_RESIZEFONT,
1419 "Change font size only when maximised", IDC_RESIZEEITHER,
1420 "Forbid resizing completely", IDC_RESIZENONE, NULL);
1422 beginbox(&cp, "Control the scrollback in the window",
1424 staticedit(&cp, "Lines of &scrollback",
1425 IDC_SAVESTATIC, IDC_SAVEEDIT, 50);
1426 checkbox(&cp, "&Display scrollbar", IDC_SCROLLBAR);
1427 checkbox(&cp, "D&isplay scrollbar in full screen mode", IDC_SCROLLBARFULLSCREEN);
1428 checkbox(&cp, "Reset scrollback on &keypress", IDC_SCROLLKEY);
1429 checkbox(&cp, "Reset scrollback on dis&play activity",
1434 if (panel == appearancepanelstart) {
1435 /* The Appearance panel. Accelerators used: [acgoh] luvb n ti p s */
1437 ctlposinit(&cp, hwnd, 80, 3, 13);
1438 bartitle(&cp, "Configure the appearance of PuTTY's window",
1439 IDC_TITLE_APPEARANCE);
1440 beginbox(&cp, "Adjust the use of the cursor", IDC_BOX_APPEARANCE1);
1441 radioline(&cp, "Cursor appearance:", IDC_CURSORSTATIC, 3,
1442 "B&lock", IDC_CURBLOCK,
1443 "&Underline", IDC_CURUNDER,
1444 "&Vertical line", IDC_CURVERT, NULL);
1445 checkbox(&cp, "Cursor &blinks", IDC_BLINKCUR);
1447 beginbox(&cp, "Set the font used in the terminal window",
1448 IDC_BOX_APPEARANCE2);
1449 staticbtn(&cp, "", IDC_FONTSTATIC, "Cha&nge...", IDC_CHOOSEFONT);
1451 beginbox(&cp, "Adjust the use of the window title",
1452 IDC_BOX_APPEARANCE3);
1454 "Window &title:", IDC_WINTITLE, IDC_WINEDIT, 100, NULL);
1455 checkbox(&cp, "Avoid ever using &icon title", IDC_WINNAME);
1457 beginbox(&cp, "Adjust the use of the mouse pointer",
1458 IDC_BOX_APPEARANCE4);
1459 checkbox(&cp, "Hide mouse &pointer when typing in window",
1462 beginbox(&cp, "Adjust the window border", IDC_BOX_APPEARANCE5);
1463 checkbox(&cp, "&Sunken-edge border (slightly thicker)",
1465 staticedit(&cp, "Gap between text and window edge",
1466 IDC_WINBSTATIC, IDC_WINBEDIT, 20);
1470 if (panel == behaviourpanelstart) {
1471 /* The Behaviour panel. Accelerators used: [acgoh] w4yltf */
1473 ctlposinit(&cp, hwnd, 80, 3, 13);
1474 bartitle(&cp, "Configure the behaviour of PuTTY's window",
1476 beginbox(&cp, NULL, IDC_BOX_BEHAVIOUR1);
1477 checkbox(&cp, "&Warn before closing window", IDC_CLOSEWARN);
1478 checkbox(&cp, "Window closes on ALT-F&4", IDC_ALTF4);
1479 checkbox(&cp, "S&ystem menu appears on ALT-Space", IDC_ALTSPACE);
1480 checkbox(&cp, "System menu appears on A< alone", IDC_ALTONLY);
1481 checkbox(&cp, "Ensure window is always on &top", IDC_ALWAYSONTOP);
1482 checkbox(&cp, "&Full screen on Alt-Enter", IDC_FULLSCREENONALTENTER);
1486 if (panel == translationpanelstart) {
1487 /* The Translation panel. Accelerators used: [acgoh] rxbepus */
1489 ctlposinit(&cp, hwnd, 80, 3, 13);
1490 bartitle(&cp, "Options controlling character set translation",
1491 IDC_TITLE_TRANSLATION);
1492 beginbox(&cp, "Character set translation on received data",
1493 IDC_BOX_TRANSLATION1);
1494 combobox(&cp, "&Received data assumed to be in which character set:",
1495 IDC_CODEPAGESTATIC, IDC_CODEPAGE);
1497 beginbox(&cp, "Enable character set translation on input data",
1498 IDC_BOX_TRANSLATION2);
1499 checkbox(&cp, "Cap&s Lock acts as Cyrillic switch",
1502 beginbox(&cp, "Adjust how PuTTY displays line drawing characters",
1503 IDC_BOX_TRANSLATION3);
1505 "Handling of line drawing characters:", IDC_VTSTATIC,
1506 "Font has &XWindows encoding", IDC_VTXWINDOWS,
1507 "Use font in &both ANSI and OEM modes", IDC_VTOEMANSI,
1508 "Use font in O&EM mode only", IDC_VTOEMONLY,
1509 "&Poor man's line drawing (" "+" ", " "-" " and " "|" ")",
1510 IDC_VTPOORMAN, "&Unicode mode", IDC_VTUNICODE, NULL);
1514 if (panel == selectionpanelstart) {
1515 /* The Selection panel. Accelerators used: [acgoh] df wxp est nr */
1517 ctlposinit(&cp, hwnd, 80, 3, 13);
1518 bartitle(&cp, "Options controlling copy and paste",
1519 IDC_TITLE_SELECTION);
1520 beginbox(&cp, "Translation of pasted characters",
1521 IDC_BOX_SELECTION1);
1523 "&Don't translate line drawing chars into +, - and |",
1526 "Paste to clipboard in RT&F as well as plain text",
1529 beginbox(&cp, "Control which mouse button does which thing",
1530 IDC_BOX_SELECTION2);
1531 radiobig(&cp, "Action of mouse buttons:", IDC_MBSTATIC,
1532 "&Windows (Right pastes, Middle extends)", IDC_MBWINDOWS,
1533 "&xterm (Right extends, Middle pastes)", IDC_MBXTERM,
1536 "Shift overrides a&pplication's use of mouse",
1539 "Default selection mode (Alt+drag does the other one):",
1540 IDC_SELTYPESTATIC, 2,
1541 "&Normal", IDC_SELTYPELEX,
1542 "&Rectangular block", IDC_SELTYPERECT, NULL);
1544 beginbox(&cp, "Control the select-one-word-at-a-time mode",
1545 IDC_BOX_SELECTION3);
1546 charclass(&cp, "Charact&er classes:", IDC_CCSTATIC, IDC_CCLIST,
1547 "&Set", IDC_CCSET, IDC_CCEDIT,
1548 "&to class", IDC_CCSTATIC2);
1552 if (panel == colourspanelstart) {
1553 /* The Colours panel. Accelerators used: [acgoh] blum */
1555 ctlposinit(&cp, hwnd, 80, 3, 13);
1556 bartitle(&cp, "Options controlling use of colours",
1558 beginbox(&cp, "General options for colour usage",
1560 checkbox(&cp, "&Bolded text is a different colour",
1562 checkbox(&cp, "Attempt to use &logical palettes", IDC_PALETTE);
1564 beginbox(&cp, "Adjust the precise colours PuTTY displays",
1566 colouredit(&cp, "Select a colo&ur and then click to modify it:",
1567 IDC_COLOURSTATIC, IDC_COLOURLIST,
1568 "&Modify...", IDC_CHANGE,
1569 "Red:", IDC_RSTATIC, IDC_RVALUE,
1570 "Green:", IDC_GSTATIC, IDC_GVALUE,
1571 "Blue:", IDC_BSTATIC, IDC_BVALUE, NULL);
1575 if (panel == connectionpanelstart) {
1576 /* The Connection panel. Accelerators used: [acgoh] tukn */
1578 ctlposinit(&cp, hwnd, 80, 3, 13);
1579 bartitle(&cp, "Options controlling the connection",
1580 IDC_TITLE_CONNECTION);
1582 beginbox(&cp, "Data to send to the server",
1583 IDC_BOX_CONNECTION1);
1584 staticedit(&cp, "Terminal-&type string", IDC_TTSTATIC,
1586 staticedit(&cp, "Auto-login &username", IDC_LOGSTATIC,
1590 beginbox(&cp, "Adjust telnet session.", IDC_BOX_CONNECTION1);
1591 checkbox(&cp, "Keyboard sends telnet Backspace and Interrupt",
1593 checkbox(&cp, "Return key sends telnet New Line instead of ^M",
1597 beginbox(&cp, "Sending of null packets to keep session active",
1598 IDC_BOX_CONNECTION2);
1599 staticedit(&cp, "Seconds between &keepalives (0 to turn off)",
1600 IDC_PINGSTATIC, IDC_PINGEDIT, 20);
1603 beginbox(&cp, "Low-level TCP connection options",
1604 IDC_BOX_CONNECTION3);
1605 checkbox(&cp, "Disable &Nagle's algorithm (TCP_NODELAY option)",
1611 if (panel == telnetpanelstart) {
1612 /* The Telnet panel. Accelerators used: [acgoh] svldr bftk */
1614 ctlposinit(&cp, hwnd, 80, 3, 13);
1616 bartitle(&cp, "Options controlling Telnet connections",
1618 beginbox(&cp, "Data to send to the server", IDC_BOX_TELNET1);
1619 staticedit(&cp, "Terminal-&speed string", IDC_TSSTATIC,
1621 envsetter(&cp, "Environment variables:", IDC_ENVSTATIC,
1622 "&Variable", IDC_VARSTATIC, IDC_VAREDIT, "Va&lue",
1623 IDC_VALSTATIC, IDC_VALEDIT, IDC_ENVLIST, "A&dd",
1624 IDC_ENVADD, "&Remove", IDC_ENVREMOVE);
1626 beginbox(&cp, "Telnet protocol adjustments", IDC_BOX_TELNET2);
1627 radioline(&cp, "Handling of OLD_ENVIRON ambiguity:",
1628 IDC_EMSTATIC, 2, "&BSD (commonplace)", IDC_EMBSD,
1629 "R&FC 1408 (unusual)", IDC_EMRFC, NULL);
1630 radioline(&cp, "&Telnet negotiation mode:", IDC_ACTSTATIC, 2,
1631 "Passive", IDC_TPASSIVE, "Active",
1633 checkbox(&cp, "&Keyboard sends telnet Backspace and Interrupt",
1635 checkbox(&cp, "Return key sends telnet New Line instead of ^M",
1641 if (panel == rloginpanelstart) {
1642 /* The Rlogin panel. Accelerators used: [acgoh] sl */
1644 ctlposinit(&cp, hwnd, 80, 3, 13);
1646 bartitle(&cp, "Options controlling Rlogin connections",
1648 beginbox(&cp, "Data to send to the server", IDC_BOX_RLOGIN1);
1649 staticedit(&cp, "Terminal-&speed string", IDC_R_TSSTATIC,
1651 staticedit(&cp, "&Local username:", IDC_RLLUSERSTATIC,
1652 IDC_RLLUSEREDIT, 50);
1657 if (panel == sshpanelstart) {
1658 /* The SSH panel. Accelerators used: [acgoh] r pe12i sd */
1660 ctlposinit(&cp, hwnd, 80, 3, 13);
1662 bartitle(&cp, "Options controlling SSH connections",
1664 beginbox(&cp, "Data to send to the server", IDC_BOX_SSH1);
1666 "&Remote command:", IDC_CMDSTATIC, IDC_CMDEDIT, 100,
1669 beginbox(&cp, "Protocol options", IDC_BOX_SSH2);
1670 checkbox(&cp, "Don't allocate a &pseudo-terminal", IDC_NOPTY);
1671 checkbox(&cp, "Enable compr&ession", IDC_COMPRESS);
1672 radioline(&cp, "Preferred SSH protocol version:",
1673 IDC_SSHPROTSTATIC, 2,
1674 "&1", IDC_SSHPROT1, "&2", IDC_SSHPROT2, NULL);
1675 checkbox(&cp, "&Imitate SSH 2 MAC bug in commercial <= v2.3.x",
1678 beginbox(&cp, "Encryption options", IDC_BOX_SSH3);
1679 prefslist(&cipherlist, &cp, "Encryption cipher &selection policy:",
1680 IDC_CIPHERSTATIC2, IDC_CIPHERLIST, IDC_CIPHERUP,
1682 checkbox(&cp, "Enable non-standard use of single-&DES in SSH 2",
1688 if (panel == sshauthpanelstart) {
1689 /* The SSH authentication panel. Accelerators used: [acgoh] m fkiuw */
1691 ctlposinit(&cp, hwnd, 80, 3, 13);
1693 bartitle(&cp, "Options controlling SSH authentication",
1695 beginbox(&cp, "Authentication methods",
1697 checkbox(&cp, "Atte&mpt TIS or CryptoCard authentication (SSH1)",
1699 checkbox(&cp, "Attempt \"keyboard-&interactive\" authentication"
1700 " (SSH2)", IDC_AUTHKI);
1702 beginbox(&cp, "Authentication parameters",
1704 checkbox(&cp, "Allow agent &forwarding", IDC_AGENTFWD);
1705 checkbox(&cp, "Allow attempted changes of &username in SSH2",
1707 editbutton(&cp, "Private &key file for authentication:",
1708 IDC_PKSTATIC, IDC_PKEDIT, "Bro&wse...",
1714 if (panel == tunnelspanelstart) {
1715 /* The Tunnels panel. Accelerators used: [acgoh] deilmrstxp */
1717 ctlposinit(&cp, hwnd, 80, 3, 13);
1719 bartitle(&cp, "Options controlling SSH tunnelling",
1721 beginbox(&cp, "X11 forwarding", IDC_BOX_TUNNELS1);
1722 checkbox(&cp, "&Enable X11 forwarding", IDC_X11_FORWARD);
1723 multiedit(&cp, "&X display location", IDC_X11_DISPSTATIC,
1724 IDC_X11_DISPLAY, 50, NULL);
1726 beginbox(&cp, "Port forwarding", IDC_BOX_TUNNELS2);
1727 checkbox(&cp, "Local ports accept connections from o&ther hosts",
1729 checkbox(&cp, "Remote &ports do the same (SSH v2 only)",
1731 staticbtn(&cp, "Forwarded ports:", IDC_PFWDSTATIC,
1732 "&Remove", IDC_PFWDREMOVE);
1733 fwdsetter(&cp, IDC_PFWDLIST,
1734 "Add new forwarded port:", IDC_PFWDSTATIC2,
1735 "&Source port", IDC_SPORTSTATIC, IDC_SPORTEDIT,
1736 "Dest&ination", IDC_DPORTSTATIC, IDC_DPORTEDIT,
1737 "A&dd", IDC_PFWDADD);
1738 bareradioline(&cp, 2,
1739 "&Local", IDC_PFWDLOCAL,
1740 "Re&mote", IDC_PFWDREMOTE, NULL);
1748 * Helper function to load the session selected in SESSLIST
1749 * if any, as this is done in more than one place in
1750 * GenericMainDlgProc(). 0 => failure.
1752 static int load_selected_session(HWND hwnd)
1754 int n = SendDlgItemMessage(hwnd, IDC_SESSLIST,
1755 LB_GETCURSEL, 0, 0);
1761 isdef = !strcmp(sessions[n], "Default Settings");
1762 load_settings(sessions[n], !isdef, &cfg);
1763 init_dlg_ctrls(hwnd, TRUE);
1765 SetDlgItemText(hwnd, IDC_SESSEDIT, sessions[n]);
1767 SetDlgItemText(hwnd, IDC_SESSEDIT, "");
1768 /* Restore the selection, which will have been clobbered by
1769 * SESSEDIT handling. */
1770 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL, n, 0);
1775 * This function is the configuration box.
1777 static int GenericMainDlgProc(HWND hwnd, UINT msg,
1778 WPARAM wParam, LPARAM lParam, int dlgtype)
1781 struct treeview_faff tvfaff;
1784 char filename[sizeof(cfg.keyfile)];
1787 char fontstatic[256];
1789 struct servent *service;
1791 static UINT draglistmsg = WM_NULL;
1796 SetWindowLong(hwnd, GWL_USERDATA, 0);
1798 SetWindowLong(hwnd, GWL_EXSTYLE,
1799 GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
1801 HWND item = GetDlgItem(hwnd, IDC_HELPBTN);
1803 DestroyWindow(item);
1805 requested_help = FALSE;
1806 SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
1807 (LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON)));
1809 * Centre the window.
1811 { /* centre the window */
1814 hw = GetDesktopWindow();
1815 if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
1817 (rs.right + rs.left + rd.left - rd.right) / 2,
1818 (rs.bottom + rs.top + rd.top - rd.bottom) / 2,
1819 rd.right - rd.left, rd.bottom - rd.top, TRUE);
1823 * Create the tree view.
1831 r.right = r.left + 75;
1833 r.bottom = r.top + 10;
1834 MapDialogRect(hwnd, &r);
1835 tvstatic = CreateWindowEx(0, "STATIC", "Cate&gory:",
1836 WS_CHILD | WS_VISIBLE,
1838 r.right - r.left, r.bottom - r.top,
1839 hwnd, (HMENU) IDCX_TVSTATIC, hinst,
1841 font = SendMessage(hwnd, WM_GETFONT, 0, 0);
1842 SendMessage(tvstatic, WM_SETFONT, font, MAKELPARAM(TRUE, 0));
1845 r.right = r.left + 75;
1847 r.bottom = r.top + 219;
1848 MapDialogRect(hwnd, &r);
1849 treeview = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "",
1850 WS_CHILD | WS_VISIBLE |
1851 WS_TABSTOP | TVS_HASLINES |
1852 TVS_DISABLEDRAGDROP | TVS_HASBUTTONS
1854 TVS_SHOWSELALWAYS, r.left, r.top,
1855 r.right - r.left, r.bottom - r.top,
1856 hwnd, (HMENU) IDCX_TREEVIEW, hinst,
1858 font = SendMessage(hwnd, WM_GETFONT, 0, 0);
1859 SendMessage(treeview, WM_SETFONT, font, MAKELPARAM(TRUE, 0));
1860 tvfaff.treeview = treeview;
1861 memset(tvfaff.lastat, 0, sizeof(tvfaff.lastat));
1865 * Set up the tree view contents.
1867 hsession = treeview_insert(&tvfaff, 0, "Session");
1868 treeview_insert(&tvfaff, 1, "Logging");
1869 treeview_insert(&tvfaff, 0, "Terminal");
1870 treeview_insert(&tvfaff, 1, "Keyboard");
1871 treeview_insert(&tvfaff, 1, "Bell");
1872 treeview_insert(&tvfaff, 0, "Window");
1873 treeview_insert(&tvfaff, 1, "Appearance");
1874 treeview_insert(&tvfaff, 1, "Behaviour");
1875 treeview_insert(&tvfaff, 1, "Translation");
1876 treeview_insert(&tvfaff, 1, "Selection");
1877 treeview_insert(&tvfaff, 1, "Colours");
1878 treeview_insert(&tvfaff, 0, "Connection");
1880 treeview_insert(&tvfaff, 1, "Telnet");
1881 treeview_insert(&tvfaff, 1, "Rlogin");
1882 if (backends[3].backend != NULL) {
1883 treeview_insert(&tvfaff, 1, "SSH");
1884 /* XXX long name is ugly */
1885 /* XXX make it closed by default? */
1886 treeview_insert(&tvfaff, 2, "Auth");
1887 treeview_insert(&tvfaff, 2, "Tunnels");
1892 * Put the treeview selection on to the Session panel. This
1893 * should also cause creation of the relevant controls.
1895 TreeView_SelectItem(treeview, hsession);
1898 * Set focus into the first available control.
1902 ctl = GetDlgItem(hwnd, IDC_HOST);
1904 ctl = GetDlgItem(hwnd, IDC_CLOSEEXIT);
1908 SetWindowLong(hwnd, GWL_USERDATA, 1);
1909 sesslist_has_focus = 0;
1913 * Button release should trigger WM_OK if there was a
1914 * previous double click on the session list.
1918 SendMessage(hwnd, WM_COMMAND, IDOK, 0);
1921 if (LOWORD(wParam) == IDCX_TREEVIEW &&
1922 ((LPNMHDR) lParam)->code == TVN_SELCHANGED) {
1924 TreeView_GetSelection(((LPNMHDR) lParam)->hwndFrom);
1929 SendMessage (hwnd, WM_SETREDRAW, FALSE, 0);
1932 item.pszText = buffer;
1933 item.cchTextMax = sizeof(buffer);
1934 item.mask = TVIF_TEXT;
1935 TreeView_GetItem(((LPNMHDR) lParam)->hwndFrom, &item);
1936 for (j = controlstartvalue; j < controlendvalue; j++) {
1937 HWND item = GetDlgItem(hwnd, j);
1939 DestroyWindow(item);
1941 if (!strcmp(buffer, "Session"))
1942 create_controls(hwnd, dlgtype, sessionpanelstart);
1943 if (!strcmp(buffer, "Logging"))
1944 create_controls(hwnd, dlgtype, loggingpanelstart);
1945 if (!strcmp(buffer, "Keyboard"))
1946 create_controls(hwnd, dlgtype, keyboardpanelstart);
1947 if (!strcmp(buffer, "Terminal"))
1948 create_controls(hwnd, dlgtype, terminalpanelstart);
1949 if (!strcmp(buffer, "Bell"))
1950 create_controls(hwnd, dlgtype, bellpanelstart);
1951 if (!strcmp(buffer, "Window"))
1952 create_controls(hwnd, dlgtype, windowpanelstart);
1953 if (!strcmp(buffer, "Appearance"))
1954 create_controls(hwnd, dlgtype, appearancepanelstart);
1955 if (!strcmp(buffer, "Behaviour"))
1956 create_controls(hwnd, dlgtype, behaviourpanelstart);
1957 if (!strcmp(buffer, "Tunnels"))
1958 create_controls(hwnd, dlgtype, tunnelspanelstart);
1959 if (!strcmp(buffer, "Connection"))
1960 create_controls(hwnd, dlgtype, connectionpanelstart);
1961 if (!strcmp(buffer, "Telnet"))
1962 create_controls(hwnd, dlgtype, telnetpanelstart);
1963 if (!strcmp(buffer, "Rlogin"))
1964 create_controls(hwnd, dlgtype, rloginpanelstart);
1965 if (!strcmp(buffer, "SSH"))
1966 create_controls(hwnd, dlgtype, sshpanelstart);
1967 if (!strcmp(buffer, "Auth"))
1968 create_controls(hwnd, dlgtype, sshauthpanelstart);
1969 if (!strcmp(buffer, "Selection"))
1970 create_controls(hwnd, dlgtype, selectionpanelstart);
1971 if (!strcmp(buffer, "Colours"))
1972 create_controls(hwnd, dlgtype, colourspanelstart);
1973 if (!strcmp(buffer, "Translation"))
1974 create_controls(hwnd, dlgtype, translationpanelstart);
1976 init_dlg_ctrls(hwnd, FALSE);
1978 SendMessage (hwnd, WM_SETREDRAW, TRUE, 0);
1979 InvalidateRect (hwnd, NULL, TRUE);
1981 SetFocus(((LPNMHDR) lParam)->hwndFrom); /* ensure focus stays */
1987 * Only process WM_COMMAND once the dialog is fully formed.
1989 if (GetWindowLong(hwnd, GWL_USERDATA) == 1)
1990 switch (LOWORD(wParam)) {
1992 /* Behaviour of the "Open" button is different if the
1993 * session list has focus, *unless* the user just
1994 * double-clicked... */
1995 if (sesslist_has_focus && !readytogo) {
1996 if (!load_selected_session(hwnd)) {
2001 /* If at this point we have a valid session, go! */
2003 if (requested_help) {
2004 WinHelp(hwnd, help_path, HELP_QUIT, 0);
2005 requested_help = FALSE;
2012 if (HIWORD(wParam) == BN_CLICKED ||
2013 HIWORD(wParam) == BN_DOUBLECLICKED) {
2015 WinHelp(hwnd, help_path,
2016 help_has_contents ? HELP_FINDER : HELP_CONTENTS,
2018 requested_help = TRUE;
2023 if (requested_help) {
2024 WinHelp(hwnd, help_path, HELP_QUIT, 0);
2025 requested_help = FALSE;
2029 case IDC_PROTTELNET:
2030 case IDC_PROTRLOGIN:
2033 if (HIWORD(wParam) == BN_CLICKED ||
2034 HIWORD(wParam) == BN_DOUBLECLICKED) {
2035 int i = IsDlgButtonChecked(hwnd, IDC_PROTSSH);
2036 int j = IsDlgButtonChecked(hwnd, IDC_PROTTELNET);
2037 int k = IsDlgButtonChecked(hwnd, IDC_PROTRLOGIN);
2039 i ? PROT_SSH : j ? PROT_TELNET : k ? PROT_RLOGIN :
2042 * When switching using the arrow keys, we
2043 * appear to get two of these messages, both
2044 * mentioning the target button in
2045 * LOWORD(wParam), but one of them called while
2046 * the previous button is still checked. This
2047 * causes an unnecessary reset of the port
2048 * number field, which we fix by ensuring here
2049 * that the button selected is indeed the one
2052 if (IsDlgButtonChecked(hwnd, LOWORD(wParam)) &&
2053 ((cfg.protocol == PROT_SSH && cfg.port != 22)
2054 || (cfg.protocol == PROT_TELNET && cfg.port != 23)
2055 || (cfg.protocol == PROT_RLOGIN
2056 && cfg.port != 513))) {
2057 cfg.port = i ? 22 : j ? 23 : 513;
2058 SetDlgItemInt(hwnd, IDC_PORT, cfg.port, FALSE);
2063 if (HIWORD(wParam) == EN_CHANGE)
2064 GetDlgItemText(hwnd, IDC_HOST, cfg.host,
2065 sizeof(cfg.host) - 1);
2068 if (HIWORD(wParam) == EN_CHANGE) {
2069 GetDlgItemText(hwnd, IDC_PORT, portname, 31);
2070 if (isdigit(portname[0]))
2071 MyGetDlgItemInt(hwnd, IDC_PORT, &cfg.port);
2073 service = getservbyname(portname, NULL);
2075 cfg.port = ntohs(service->s_port);
2082 if (HIWORD(wParam) == EN_CHANGE) {
2083 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
2085 GetDlgItemText(hwnd, IDC_SESSEDIT,
2086 savedsession, sizeof(savedsession) - 1);
2087 savedsession[sizeof(savedsession) - 1] = '\0';
2091 if (HIWORD(wParam) == BN_CLICKED ||
2092 HIWORD(wParam) == BN_DOUBLECLICKED) {
2097 GetDlgItemText(hwnd, IDC_SESSEDIT, str,
2100 int n = SendDlgItemMessage(hwnd, IDC_SESSLIST,
2101 LB_GETCURSEL, 0, 0);
2106 strcpy(str, sessions[n]);
2108 save_settings(str, !!strcmp(str, "Default Settings"),
2110 get_sesslist(FALSE);
2112 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
2114 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT,
2116 for (i = 0; i < nsessions; i++)
2117 SendDlgItemMessage(hwnd, IDC_SESSLIST,
2119 (LPARAM) (sessions[i]));
2120 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
2122 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
2124 InvalidateRect(GetDlgItem(hwnd, IDC_SESSLIST), NULL,
2130 if (LOWORD(wParam) == IDC_SESSLIST) {
2131 if (HIWORD(wParam) == LBN_SETFOCUS)
2132 sesslist_has_focus = 1;
2133 else if (HIWORD(wParam) == LBN_KILLFOCUS)
2134 sesslist_has_focus = 0;
2136 if (LOWORD(wParam) == IDC_SESSLOAD &&
2137 HIWORD(wParam) != BN_CLICKED &&
2138 HIWORD(wParam) != BN_DOUBLECLICKED) break;
2139 if (LOWORD(wParam) == IDC_SESSLIST &&
2140 HIWORD(wParam) != LBN_DBLCLK) break;
2141 /* Load the session selected in SESSLIST. */
2142 if (load_selected_session(hwnd) &&
2143 LOWORD(wParam) == IDC_SESSLIST) {
2145 * A double-click on a saved session should
2146 * actually start the session, not just load it.
2147 * Unless it's Default Settings or some other
2148 * host-less set of saved settings.
2157 if (HIWORD(wParam) == BN_CLICKED ||
2158 HIWORD(wParam) == BN_DOUBLECLICKED) {
2159 int n = SendDlgItemMessage(hwnd, IDC_SESSLIST,
2160 LB_GETCURSEL, 0, 0);
2161 if (n == LB_ERR || n == 0) {
2165 del_settings(sessions[n]);
2166 get_sesslist(FALSE);
2168 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
2170 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_RESETCONTENT,
2172 for (i = 0; i < nsessions; i++)
2173 SendDlgItemMessage(hwnd, IDC_SESSLIST,
2175 (LPARAM) (sessions[i]));
2176 SendDlgItemMessage(hwnd, IDC_SESSLIST, LB_SETCURSEL,
2178 SendDlgItemMessage(hwnd, IDC_SESSLIST, WM_SETREDRAW,
2180 InvalidateRect(GetDlgItem(hwnd, IDC_SESSLIST), NULL,
2184 if (HIWORD(wParam) == EN_CHANGE)
2185 MyGetDlgItemInt(hwnd, IDC_PINGEDIT,
2186 &cfg.ping_interval);
2189 if (HIWORD(wParam) == BN_CLICKED ||
2190 HIWORD(wParam) == BN_DOUBLECLICKED)
2192 IsDlgButtonChecked(hwnd, IDC_NODELAY);
2196 if (HIWORD(wParam) == BN_CLICKED ||
2197 HIWORD(wParam) == BN_DOUBLECLICKED)
2198 cfg.bksp_is_delete =
2199 IsDlgButtonChecked(hwnd, IDC_DEL127);
2203 if (HIWORD(wParam) == BN_CLICKED ||
2204 HIWORD(wParam) == BN_DOUBLECLICKED)
2206 IsDlgButtonChecked(hwnd, IDC_HOMERXVT);
2212 case IDC_FUNCVT100P:
2214 if (HIWORD(wParam) == BN_CLICKED ||
2215 HIWORD(wParam) == BN_DOUBLECLICKED)
2216 switch (LOWORD(wParam)) {
2229 case IDC_FUNCVT100P:
2239 if (HIWORD(wParam) == BN_CLICKED ||
2240 HIWORD(wParam) == BN_DOUBLECLICKED) {
2242 IsDlgButtonChecked(hwnd, IDC_KPAPPLIC);
2243 cfg.nethack_keypad = FALSE;
2247 if (HIWORD(wParam) == BN_CLICKED ||
2248 HIWORD(wParam) == BN_DOUBLECLICKED) {
2249 cfg.app_keypad = FALSE;
2250 cfg.nethack_keypad = TRUE;
2255 if (HIWORD(wParam) == BN_CLICKED ||
2256 HIWORD(wParam) == BN_DOUBLECLICKED)
2258 IsDlgButtonChecked(hwnd, IDC_CURAPPLIC);
2261 if (HIWORD(wParam) == BN_CLICKED ||
2262 HIWORD(wParam) == BN_DOUBLECLICKED)
2264 IsDlgButtonChecked(hwnd, IDC_NOAPPLICC);
2267 if (HIWORD(wParam) == BN_CLICKED ||
2268 HIWORD(wParam) == BN_DOUBLECLICKED)
2270 IsDlgButtonChecked(hwnd, IDC_NOAPPLICK);
2273 if (HIWORD(wParam) == BN_CLICKED ||
2274 HIWORD(wParam) == BN_DOUBLECLICKED)
2275 cfg.alt_f4 = IsDlgButtonChecked(hwnd, IDC_ALTF4);
2278 if (HIWORD(wParam) == BN_CLICKED ||
2279 HIWORD(wParam) == BN_DOUBLECLICKED)
2281 IsDlgButtonChecked(hwnd, IDC_ALTSPACE);
2284 if (HIWORD(wParam) == BN_CLICKED ||
2285 HIWORD(wParam) == BN_DOUBLECLICKED)
2287 IsDlgButtonChecked(hwnd, IDC_ALTONLY);
2289 case IDC_ECHOBACKEND:
2292 if (HIWORD(wParam) == BN_CLICKED ||
2293 HIWORD(wParam) == BN_DOUBLECLICKED) {
2294 if (LOWORD(wParam) == IDC_ECHOBACKEND)
2295 cfg.localecho = LD_BACKEND;
2296 if (LOWORD(wParam) == IDC_ECHOYES)
2297 cfg.localecho = LD_YES;
2298 if (LOWORD(wParam) == IDC_ECHONO)
2299 cfg.localecho = LD_NO;
2302 case IDC_EDITBACKEND:
2305 if (HIWORD(wParam) == BN_CLICKED ||
2306 HIWORD(wParam) == BN_DOUBLECLICKED) {
2307 if (LOWORD(wParam) == IDC_EDITBACKEND)
2308 cfg.localedit = LD_BACKEND;
2309 if (LOWORD(wParam) == IDC_EDITYES)
2310 cfg.localedit = LD_YES;
2311 if (LOWORD(wParam) == IDC_EDITNO)
2312 cfg.localedit = LD_NO;
2315 case IDC_ANSWEREDIT:
2316 if (HIWORD(wParam) == EN_CHANGE)
2317 GetDlgItemText(hwnd, IDC_ANSWEREDIT, cfg.answerback,
2318 sizeof(cfg.answerback) - 1);
2320 case IDC_ALWAYSONTOP:
2321 if (HIWORD(wParam) == BN_CLICKED ||
2322 HIWORD(wParam) == BN_DOUBLECLICKED)
2324 IsDlgButtonChecked(hwnd, IDC_ALWAYSONTOP);
2326 case IDC_FULLSCREENONALTENTER:
2327 if (HIWORD(wParam) == BN_CLICKED ||
2328 HIWORD(wParam) == BN_DOUBLECLICKED)
2329 cfg.fullscreenonaltenter =
2330 IsDlgButtonChecked(hwnd, IDC_FULLSCREENONALTENTER);
2333 if (HIWORD(wParam) == BN_CLICKED ||
2334 HIWORD(wParam) == BN_DOUBLECLICKED)
2336 IsDlgButtonChecked(hwnd, IDC_SCROLLKEY);
2338 case IDC_SCROLLDISP:
2339 if (HIWORD(wParam) == BN_CLICKED ||
2340 HIWORD(wParam) == BN_DOUBLECLICKED)
2341 cfg.scroll_on_disp =
2342 IsDlgButtonChecked(hwnd, IDC_SCROLLDISP);
2344 case IDC_COMPOSEKEY:
2345 if (HIWORD(wParam) == BN_CLICKED ||
2346 HIWORD(wParam) == BN_DOUBLECLICKED)
2348 IsDlgButtonChecked(hwnd, IDC_COMPOSEKEY);
2350 case IDC_CTRLALTKEYS:
2351 if (HIWORD(wParam) == BN_CLICKED ||
2352 HIWORD(wParam) == BN_DOUBLECLICKED)
2354 IsDlgButtonChecked(hwnd, IDC_CTRLALTKEYS);
2357 if (HIWORD(wParam) == BN_CLICKED ||
2358 HIWORD(wParam) == BN_DOUBLECLICKED)
2359 cfg.telnet_keyboard =
2360 IsDlgButtonChecked(hwnd, IDC_TELNETKEY);
2363 if (HIWORD(wParam) == BN_CLICKED ||
2364 HIWORD(wParam) == BN_DOUBLECLICKED)
2365 cfg.telnet_newline =
2366 IsDlgButtonChecked(hwnd, IDC_TELNETRET);
2369 if (HIWORD(wParam) == BN_CLICKED ||
2370 HIWORD(wParam) == BN_DOUBLECLICKED)
2372 IsDlgButtonChecked(hwnd, IDC_WRAPMODE);
2375 if (HIWORD(wParam) == BN_CLICKED ||
2376 HIWORD(wParam) == BN_DOUBLECLICKED)
2377 cfg.dec_om = IsDlgButtonChecked(hwnd, IDC_DECOM);
2380 if (HIWORD(wParam) == BN_CLICKED ||
2381 HIWORD(wParam) == BN_DOUBLECLICKED)
2383 IsDlgButtonChecked(hwnd, IDC_LFHASCR);
2386 if (HIWORD(wParam) == EN_CHANGE)
2387 MyGetDlgItemInt(hwnd, IDC_ROWSEDIT, &cfg.height);
2390 if (HIWORD(wParam) == EN_CHANGE)
2391 MyGetDlgItemInt(hwnd, IDC_COLSEDIT, &cfg.width);
2394 if (HIWORD(wParam) == EN_CHANGE)
2395 MyGetDlgItemInt(hwnd, IDC_SAVEEDIT, &cfg.savelines);
2397 case IDC_CHOOSEFONT:
2400 lf.lfHeight = -MulDiv(cfg.fontheight,
2401 GetDeviceCaps(hdc, LOGPIXELSY),
2405 lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0;
2406 lf.lfItalic = lf.lfUnderline = lf.lfStrikeOut = 0;
2407 lf.lfWeight = (cfg.fontisbold ? FW_BOLD : 0);
2408 lf.lfCharSet = cfg.fontcharset;
2409 lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
2410 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
2411 lf.lfQuality = DEFAULT_QUALITY;
2412 lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
2413 strncpy(lf.lfFaceName, cfg.font,
2414 sizeof(lf.lfFaceName) - 1);
2415 lf.lfFaceName[sizeof(lf.lfFaceName) - 1] = '\0';
2417 cf.lStructSize = sizeof(cf);
2418 cf.hwndOwner = hwnd;
2420 cf.Flags = CF_FIXEDPITCHONLY | CF_FORCEFONTEXIST |
2421 CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
2423 if (ChooseFont(&cf)) {
2424 strncpy(cfg.font, lf.lfFaceName, sizeof(cfg.font) - 1);
2425 cfg.font[sizeof(cfg.font) - 1] = '\0';
2426 cfg.fontisbold = (lf.lfWeight == FW_BOLD);
2427 cfg.fontcharset = lf.lfCharSet;
2428 cfg.fontheight = cf.iPointSize / 10;
2429 fmtfont(fontstatic);
2430 SetDlgItemText(hwnd, IDC_FONTSTATIC, fontstatic);
2433 case IDC_BELL_DISABLED:
2434 case IDC_BELL_DEFAULT:
2435 case IDC_BELL_WAVEFILE:
2436 case IDC_BELL_VISUAL:
2437 if (HIWORD(wParam) == BN_CLICKED ||
2438 HIWORD(wParam) == BN_DOUBLECLICKED) {
2439 if (LOWORD(wParam) == IDC_BELL_DISABLED)
2440 cfg.beep = BELL_DISABLED;
2441 if (LOWORD(wParam) == IDC_BELL_DEFAULT)
2442 cfg.beep = BELL_DEFAULT;
2443 if (LOWORD(wParam) == IDC_BELL_WAVEFILE)
2444 cfg.beep = BELL_WAVEFILE;
2445 if (LOWORD(wParam) == IDC_BELL_VISUAL)
2446 cfg.beep = BELL_VISUAL;
2449 case IDC_B_IND_DISABLED:
2450 case IDC_B_IND_FLASH:
2451 case IDC_B_IND_STEADY:
2452 if (HIWORD(wParam) == BN_CLICKED ||
2453 HIWORD(wParam) == BN_DOUBLECLICKED) {
2454 if (LOWORD(wParam) == IDC_B_IND_DISABLED)
2455 cfg.beep_ind = B_IND_DISABLED;
2456 if (LOWORD(wParam) == IDC_B_IND_FLASH)
2457 cfg.beep_ind = B_IND_FLASH;
2458 if (LOWORD(wParam) == IDC_B_IND_STEADY)
2459 cfg.beep_ind = B_IND_STEADY;
2462 case IDC_BELL_WAVEBROWSE:
2463 memset(&of, 0, sizeof(of));
2464 #ifdef OPENFILENAME_SIZE_VERSION_400
2465 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
2467 of.lStructSize = sizeof(of);
2469 of.hwndOwner = hwnd;
2470 of.lpstrFilter = "Wave Files\0*.WAV\0AllFiles\0*\0\0\0";
2471 of.lpstrCustomFilter = NULL;
2472 of.nFilterIndex = 1;
2473 of.lpstrFile = filename;
2474 strcpy(filename, cfg.bell_wavefile);
2475 of.nMaxFile = sizeof(filename);
2476 of.lpstrFileTitle = NULL;
2477 of.lpstrInitialDir = NULL;
2478 of.lpstrTitle = "Select Bell Sound File";
2480 if (GetOpenFileName(&of)) {
2481 strcpy(cfg.bell_wavefile, filename);
2482 SetDlgItemText(hwnd, IDC_BELL_WAVEEDIT,
2486 case IDC_BELL_WAVEEDIT:
2487 if (HIWORD(wParam) == EN_CHANGE)
2488 GetDlgItemText(hwnd, IDC_BELL_WAVEEDIT,
2490 sizeof(cfg.bell_wavefile) - 1);
2493 if (HIWORD(wParam) == BN_CLICKED ||
2494 HIWORD(wParam) == BN_DOUBLECLICKED)
2496 IsDlgButtonChecked(hwnd, IDC_BELLOVL);
2499 if (HIWORD(wParam) == EN_CHANGE)
2500 MyGetDlgItemInt(hwnd, IDC_BELLOVLN, &cfg.bellovl_n);
2503 if (HIWORD(wParam) == EN_CHANGE)
2504 MyGetDlgItemFlt(hwnd, IDC_BELLOVLT, &cfg.bellovl_t,
2508 if (HIWORD(wParam) == EN_CHANGE)
2509 MyGetDlgItemFlt(hwnd, IDC_BELLOVLS, &cfg.bellovl_s,
2513 if (HIWORD(wParam) == BN_CLICKED ||
2514 HIWORD(wParam) == BN_DOUBLECLICKED)
2516 IsDlgButtonChecked(hwnd, IDC_BLINKTEXT);
2519 if (HIWORD(wParam) == BN_CLICKED ||
2520 HIWORD(wParam) == BN_DOUBLECLICKED)
2521 cfg.bce = IsDlgButtonChecked(hwnd, IDC_BCE);
2524 if (HIWORD(wParam) == BN_CLICKED ||
2525 HIWORD(wParam) == BN_DOUBLECLICKED)
2526 cfg.win_name_always =
2527 IsDlgButtonChecked(hwnd, IDC_WINNAME);
2530 if (HIWORD(wParam) == BN_CLICKED ||
2531 HIWORD(wParam) == BN_DOUBLECLICKED)
2533 IsDlgButtonChecked(hwnd, IDC_HIDEMOUSE);
2535 case IDC_SUNKENEDGE:
2536 if (HIWORD(wParam) == BN_CLICKED ||
2537 HIWORD(wParam) == BN_DOUBLECLICKED)
2539 IsDlgButtonChecked(hwnd, IDC_SUNKENEDGE);
2542 if (HIWORD(wParam) == EN_CHANGE)
2543 MyGetDlgItemInt(hwnd, IDC_WINBEDIT,
2544 &cfg.window_border);
2545 if (cfg.window_border > 32)
2546 cfg.window_border = 32;
2549 if (HIWORD(wParam) == BN_CLICKED ||
2550 HIWORD(wParam) == BN_DOUBLECLICKED)
2551 cfg.cursor_type = 0;
2554 if (HIWORD(wParam) == BN_CLICKED ||
2555 HIWORD(wParam) == BN_DOUBLECLICKED)
2556 cfg.cursor_type = 1;
2559 if (HIWORD(wParam) == BN_CLICKED ||
2560 HIWORD(wParam) == BN_DOUBLECLICKED)
2561 cfg.cursor_type = 2;
2564 if (HIWORD(wParam) == BN_CLICKED ||
2565 HIWORD(wParam) == BN_DOUBLECLICKED)
2567 IsDlgButtonChecked(hwnd, IDC_BLINKCUR);
2570 if (HIWORD(wParam) == BN_CLICKED ||
2571 HIWORD(wParam) == BN_DOUBLECLICKED)
2573 IsDlgButtonChecked(hwnd, IDC_SCROLLBAR);
2575 case IDC_SCROLLBARFULLSCREEN:
2576 if (HIWORD(wParam) == BN_CLICKED ||
2577 HIWORD(wParam) == BN_DOUBLECLICKED)
2578 cfg.scrollbar_in_fullscreen =
2579 IsDlgButtonChecked(hwnd, IDC_SCROLLBARFULLSCREEN);
2581 case IDC_RESIZETERM:
2582 case IDC_RESIZEFONT:
2583 case IDC_RESIZENONE:
2584 case IDC_RESIZEEITHER:
2585 if (HIWORD(wParam) == BN_CLICKED ||
2586 HIWORD(wParam) == BN_DOUBLECLICKED) {
2588 IsDlgButtonChecked(hwnd,
2589 IDC_RESIZETERM) ? RESIZE_TERM :
2590 IsDlgButtonChecked(hwnd,
2591 IDC_RESIZEFONT) ? RESIZE_FONT :
2592 IsDlgButtonChecked(hwnd,
2593 IDC_RESIZEEITHER) ? RESIZE_EITHER :
2598 if (HIWORD(wParam) == EN_CHANGE)
2599 GetDlgItemText(hwnd, IDC_WINEDIT, cfg.wintitle,
2600 sizeof(cfg.wintitle) - 1);
2605 if (HIWORD(wParam) == BN_CLICKED ||
2606 HIWORD(wParam) == BN_DOUBLECLICKED) {
2608 IsDlgButtonChecked(hwnd,
2609 IDC_COEALWAYS) ? COE_ALWAYS :
2610 IsDlgButtonChecked(hwnd,
2611 IDC_COENEVER) ? COE_NEVER :
2616 if (HIWORD(wParam) == BN_CLICKED ||
2617 HIWORD(wParam) == BN_DOUBLECLICKED)
2619 IsDlgButtonChecked(hwnd, IDC_CLOSEWARN);
2622 if (HIWORD(wParam) == EN_CHANGE)
2623 GetDlgItemText(hwnd, IDC_TTEDIT, cfg.termtype,
2624 sizeof(cfg.termtype) - 1);
2627 if (HIWORD(wParam) == EN_CHANGE)
2628 GetDlgItemText(hwnd, IDC_LGFEDIT, cfg.logfilename,
2629 sizeof(cfg.logfilename) - 1);
2632 memset(&of, 0, sizeof(of));
2633 #ifdef OPENFILENAME_SIZE_VERSION_400
2634 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
2636 of.lStructSize = sizeof(of);
2638 of.hwndOwner = hwnd;
2639 of.lpstrFilter = "All Files\0*\0\0\0";
2640 of.lpstrCustomFilter = NULL;
2641 of.nFilterIndex = 1;
2642 of.lpstrFile = filename;
2643 strcpy(filename, cfg.logfilename);
2644 of.nMaxFile = sizeof(filename);
2645 of.lpstrFileTitle = NULL;
2646 of.lpstrInitialDir = NULL;
2647 of.lpstrTitle = "Select session log file";
2649 if (GetSaveFileName(&of)) {
2650 strcpy(cfg.logfilename, filename);
2651 SetDlgItemText(hwnd, IDC_LGFEDIT, cfg.logfilename);
2655 case IDC_LSTATASCII:
2657 case IDC_LSTATPACKET:
2658 if (HIWORD(wParam) == BN_CLICKED ||
2659 HIWORD(wParam) == BN_DOUBLECLICKED) {
2660 if (IsDlgButtonChecked(hwnd, IDC_LSTATOFF))
2661 cfg.logtype = LGTYP_NONE;
2662 if (IsDlgButtonChecked(hwnd, IDC_LSTATASCII))
2663 cfg.logtype = LGTYP_ASCII;
2664 if (IsDlgButtonChecked(hwnd, IDC_LSTATRAW))
2665 cfg.logtype = LGTYP_DEBUG;
2666 if (IsDlgButtonChecked(hwnd, IDC_LSTATPACKET))
2667 cfg.logtype = LGTYP_PACKETS;
2673 if (HIWORD(wParam) == BN_CLICKED ||
2674 HIWORD(wParam) == BN_DOUBLECLICKED) {
2675 if (IsDlgButtonChecked(hwnd, IDC_LSTATXASK))
2676 cfg.logxfovr = LGXF_ASK;
2677 if (IsDlgButtonChecked(hwnd, IDC_LSTATXAPN))
2678 cfg.logxfovr = LGXF_APN;
2679 if (IsDlgButtonChecked(hwnd, IDC_LSTATXOVR))
2680 cfg.logxfovr = LGXF_OVR;
2685 if (HIWORD(wParam) == EN_CHANGE)
2686 GetDlgItemText(hwnd, LOWORD(wParam), cfg.termspeed,
2687 sizeof(cfg.termspeed) - 1);
2690 if (HIWORD(wParam) == EN_CHANGE)
2691 GetDlgItemText(hwnd, IDC_LOGEDIT, cfg.username,
2692 sizeof(cfg.username) - 1);
2694 case IDC_RLLUSEREDIT:
2695 if (HIWORD(wParam) == EN_CHANGE)
2696 GetDlgItemText(hwnd, IDC_RLLUSEREDIT,
2698 sizeof(cfg.localusername) - 1);
2702 cfg.rfc_environ = IsDlgButtonChecked(hwnd, IDC_EMRFC);
2706 cfg.passive_telnet =
2707 IsDlgButtonChecked(hwnd, IDC_TPASSIVE);
2710 if (HIWORD(wParam) == BN_CLICKED ||
2711 HIWORD(wParam) == BN_DOUBLECLICKED) {
2712 char str[sizeof(cfg.environmt)];
2714 GetDlgItemText(hwnd, IDC_VAREDIT, str,
2720 p = str + strlen(str);
2722 GetDlgItemText(hwnd, IDC_VALEDIT, p,
2723 sizeof(str) - 1 - (p - str));
2734 if ((p - cfg.environmt) + strlen(str) + 2 <
2735 sizeof(cfg.environmt)) {
2737 p[strlen(str) + 1] = '\0';
2738 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_ADDSTRING,
2740 SetDlgItemText(hwnd, IDC_VAREDIT, "");
2741 SetDlgItemText(hwnd, IDC_VALEDIT, "");
2743 MessageBox(hwnd, "Environment too big",
2744 "PuTTY Error", MB_OK | MB_ICONERROR);
2749 if (HIWORD(wParam) != BN_CLICKED &&
2750 HIWORD(wParam) != BN_DOUBLECLICKED) break;
2752 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_GETCURSEL, 0,
2759 SendDlgItemMessage(hwnd, IDC_ENVLIST, LB_DELETESTRING,
2786 if (HIWORD(wParam) == BN_CLICKED ||
2787 HIWORD(wParam) == BN_DOUBLECLICKED)
2788 cfg.nopty = IsDlgButtonChecked(hwnd, IDC_NOPTY);
2791 if (HIWORD(wParam) == BN_CLICKED ||
2792 HIWORD(wParam) == BN_DOUBLECLICKED)
2794 IsDlgButtonChecked(hwnd, IDC_COMPRESS);
2797 if (HIWORD(wParam) == BN_CLICKED ||
2798 HIWORD(wParam) == BN_DOUBLECLICKED)
2800 IsDlgButtonChecked(hwnd, IDC_BUGGYMAC);
2803 if (HIWORD(wParam) == BN_CLICKED ||
2804 HIWORD(wParam) == BN_DOUBLECLICKED)
2806 IsDlgButtonChecked(hwnd, IDC_SSH2DES);
2809 if (HIWORD(wParam) == BN_CLICKED ||
2810 HIWORD(wParam) == BN_DOUBLECLICKED)
2812 IsDlgButtonChecked(hwnd, IDC_AGENTFWD);
2814 case IDC_CHANGEUSER:
2815 if (HIWORD(wParam) == BN_CLICKED ||
2816 HIWORD(wParam) == BN_DOUBLECLICKED)
2817 cfg.change_username =
2818 IsDlgButtonChecked(hwnd, IDC_CHANGEUSER);
2820 case IDC_CIPHERLIST:
2823 handle_prefslist(&cipherlist,
2824 cfg.ssh_cipherlist, CIPHER_MAX,
2825 0, hwnd, wParam, lParam);
2829 if (HIWORD(wParam) == BN_CLICKED ||
2830 HIWORD(wParam) == BN_DOUBLECLICKED) {
2831 if (IsDlgButtonChecked(hwnd, IDC_SSHPROT1))
2833 else if (IsDlgButtonChecked(hwnd, IDC_SSHPROT2))
2838 if (HIWORD(wParam) == BN_CLICKED ||
2839 HIWORD(wParam) == BN_DOUBLECLICKED)
2841 IsDlgButtonChecked(hwnd, IDC_AUTHTIS);
2844 if (HIWORD(wParam) == BN_CLICKED ||
2845 HIWORD(wParam) == BN_DOUBLECLICKED)
2847 IsDlgButtonChecked(hwnd, IDC_AUTHKI);
2850 if (HIWORD(wParam) == EN_CHANGE)
2851 GetDlgItemText(hwnd, IDC_PKEDIT, cfg.keyfile,
2852 sizeof(cfg.keyfile) - 1);
2855 if (HIWORD(wParam) == EN_CHANGE)
2856 GetDlgItemText(hwnd, IDC_CMDEDIT, cfg.remote_cmd,
2857 sizeof(cfg.remote_cmd) - 1);
2860 memset(&of, 0, sizeof(of));
2861 #ifdef OPENFILENAME_SIZE_VERSION_400
2862 of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
2864 of.lStructSize = sizeof(of);
2866 of.hwndOwner = hwnd;
2867 of.lpstrFilter = "All Files\0*\0\0\0";
2868 of.lpstrCustomFilter = NULL;
2869 of.nFilterIndex = 1;
2870 of.lpstrFile = filename;
2871 strcpy(filename, cfg.keyfile);
2872 of.nMaxFile = sizeof(filename);
2873 of.lpstrFileTitle = NULL;
2874 of.lpstrInitialDir = NULL;
2875 of.lpstrTitle = "Select Private Key File";
2877 if (GetOpenFileName(&of)) {
2878 strcpy(cfg.keyfile, filename);
2879 SetDlgItemText(hwnd, IDC_PKEDIT, cfg.keyfile);
2883 cfg.rawcnp = IsDlgButtonChecked(hwnd, IDC_RAWCNP);
2886 cfg.rtf_paste = IsDlgButtonChecked(hwnd, IDC_RTFPASTE);
2890 cfg.mouse_is_xterm = IsDlgButtonChecked(hwnd, IDC_MBXTERM);
2892 case IDC_SELTYPELEX:
2893 case IDC_SELTYPERECT:
2894 cfg.rect_select = IsDlgButtonChecked(hwnd, IDC_SELTYPERECT);
2896 case IDC_MOUSEOVERRIDE:
2897 cfg.mouse_override = IsDlgButtonChecked(hwnd, IDC_MOUSEOVERRIDE);
2903 int n = GetDlgItemInt(hwnd, IDC_CCEDIT, &ok, FALSE);
2908 for (i = 0; i < 128; i++)
2909 if (SendDlgItemMessage
2910 (hwnd, IDC_CCLIST, LB_GETSEL, i, 0)) {
2912 cfg.wordness[i] = n;
2913 SendDlgItemMessage(hwnd, IDC_CCLIST,
2914 LB_DELETESTRING, i, 0);
2915 sprintf(str, "%d\t(0x%02X)\t%c\t%d", i, i,
2916 (i >= 0x21 && i != 0x7F) ? i : ' ',
2918 SendDlgItemMessage(hwnd, IDC_CCLIST,
2925 case IDC_BOLDCOLOUR:
2926 if (HIWORD(wParam) == BN_CLICKED ||
2927 HIWORD(wParam) == BN_DOUBLECLICKED) {
2930 IsDlgButtonChecked(hwnd, IDC_BOLDCOLOUR);
2931 SendDlgItemMessage(hwnd, IDC_COLOURLIST, WM_SETREDRAW,
2934 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2936 if (n != 12 + 10 * cfg.bold_colour) {
2937 for (i = n; i-- > 0;)
2938 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2939 LB_DELETESTRING, i, 0);
2940 for (i = 0; i < 22; i++)
2941 if (cfg.bold_colour || permcolour[i])
2942 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2944 (LPARAM) colours[i]);
2946 SendDlgItemMessage(hwnd, IDC_COLOURLIST, WM_SETREDRAW,
2948 InvalidateRect(GetDlgItem(hwnd, IDC_COLOURLIST), NULL,
2953 if (HIWORD(wParam) == BN_CLICKED ||
2954 HIWORD(wParam) == BN_DOUBLECLICKED)
2956 IsDlgButtonChecked(hwnd, IDC_PALETTE);
2958 case IDC_COLOURLIST:
2959 if (HIWORD(wParam) == LBN_DBLCLK ||
2960 HIWORD(wParam) == LBN_SELCHANGE) {
2962 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2965 if (!cfg.bold_colour)
2966 i = (i < 3 ? i * 2 : i == 3 ? 5 : i * 2 - 2);
2967 SetDlgItemInt(hwnd, IDC_RVALUE, cfg.colours[i][0],
2969 SetDlgItemInt(hwnd, IDC_GVALUE, cfg.colours[i][1],
2971 SetDlgItemInt(hwnd, IDC_BVALUE, cfg.colours[i][2],
2976 if (HIWORD(wParam) == BN_CLICKED ||
2977 HIWORD(wParam) == BN_DOUBLECLICKED) {
2978 static CHOOSECOLOR cc;
2979 static DWORD custom[16] = { 0 }; /* zero initialisers */
2981 SendDlgItemMessage(hwnd, IDC_COLOURLIST,
2984 if (!cfg.bold_colour)
2985 i = (i < 3 ? i * 2 : i == 3 ? 5 : i * 2 - 2);
2986 cc.lStructSize = sizeof(cc);
2987 cc.hwndOwner = hwnd;
2988 cc.hInstance = (HWND) hinst;
2989 cc.lpCustColors = custom;
2991 RGB(cfg.colours[i][0], cfg.colours[i][1],
2993 cc.Flags = CC_FULLOPEN | CC_RGBINIT;
2994 if (ChooseColor(&cc)) {
2996 (unsigned char) (cc.rgbResult & 0xFF);
2998 (unsigned char) (cc.rgbResult >> 8) & 0xFF;
3000 (unsigned char) (cc.rgbResult >> 16) & 0xFF;
3001 SetDlgItemInt(hwnd, IDC_RVALUE, cfg.colours[i][0],
3003 SetDlgItemInt(hwnd, IDC_GVALUE, cfg.colours[i][1],
3005 SetDlgItemInt(hwnd, IDC_BVALUE, cfg.colours[i][2],
3011 if (HIWORD(wParam) == CBN_SELCHANGE) {
3012 int index = SendDlgItemMessage(hwnd, IDC_CODEPAGE,
3013 CB_GETCURSEL, 0, 0);
3014 SendDlgItemMessage(hwnd, IDC_CODEPAGE, CB_GETLBTEXT,
3015 index, (LPARAM)cfg.line_codepage);
3016 } else if (HIWORD(wParam) == CBN_EDITCHANGE) {
3017 GetDlgItemText(hwnd, IDC_CODEPAGE, cfg.line_codepage,
3018 sizeof(cfg.line_codepage) - 1);
3019 } else if (HIWORD(wParam) == CBN_KILLFOCUS) {
3020 strcpy(cfg.line_codepage,
3021 cp_name(decode_codepage(cfg.line_codepage)));
3022 SetDlgItemText(hwnd, IDC_CODEPAGE, cfg.line_codepage);
3025 case IDC_CAPSLOCKCYR:
3026 if (HIWORD(wParam) == BN_CLICKED ||
3027 HIWORD(wParam) == BN_DOUBLECLICKED) {
3028 cfg.xlat_capslockcyr =
3029 IsDlgButtonChecked (hwnd, IDC_CAPSLOCKCYR);
3032 case IDC_VTXWINDOWS:
3038 (IsDlgButtonChecked(hwnd, IDC_VTXWINDOWS) ? VT_XWINDOWS
3039 : IsDlgButtonChecked(hwnd,
3040 IDC_VTOEMANSI) ? VT_OEMANSI :
3041 IsDlgButtonChecked(hwnd,
3042 IDC_VTOEMONLY) ? VT_OEMONLY :
3043 IsDlgButtonChecked(hwnd,
3044 IDC_VTUNICODE) ? VT_UNICODE :
3047 case IDC_X11_FORWARD:
3048 if (HIWORD(wParam) == BN_CLICKED ||
3049 HIWORD(wParam) == BN_DOUBLECLICKED)
3051 IsDlgButtonChecked(hwnd, IDC_X11_FORWARD);
3054 if (HIWORD(wParam) == BN_CLICKED ||
3055 HIWORD(wParam) == BN_DOUBLECLICKED)
3056 cfg.lport_acceptall =
3057 IsDlgButtonChecked(hwnd, IDC_LPORT_ALL);
3060 if (HIWORD(wParam) == BN_CLICKED ||
3061 HIWORD(wParam) == BN_DOUBLECLICKED)
3062 cfg.rport_acceptall =
3063 IsDlgButtonChecked(hwnd, IDC_RPORT_ALL);
3065 case IDC_X11_DISPLAY:
3066 if (HIWORD(wParam) == EN_CHANGE)
3067 GetDlgItemText(hwnd, IDC_X11_DISPLAY, cfg.x11_display,
3068 sizeof(cfg.x11_display) - 1);
3071 if (HIWORD(wParam) == BN_CLICKED ||
3072 HIWORD(wParam) == BN_DOUBLECLICKED) {
3073 char str[sizeof(cfg.portfwd)];
3075 if (IsDlgButtonChecked(hwnd, IDC_PFWDLOCAL))
3079 GetDlgItemText(hwnd, IDC_SPORTEDIT, str+1,
3083 "You need to specify a source port number",
3084 "PuTTY Error", MB_OK | MB_ICONERROR);
3087 p = str + strlen(str);
3089 GetDlgItemText(hwnd, IDC_DPORTEDIT, p,
3090 sizeof(str) - 1 - (p - str));
3091 if (!*p || !strchr(p, ':')) {
3093 "You need to specify a destination address\n"
3094 "in the form \"host.name:port\"",
3095 "PuTTY Error", MB_OK | MB_ICONERROR);
3104 if ((p - cfg.portfwd) + strlen(str) + 2 <
3105 sizeof(cfg.portfwd)) {
3107 p[strlen(str) + 1] = '\0';
3108 SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_ADDSTRING,
3110 SetDlgItemText(hwnd, IDC_SPORTEDIT, "");
3111 SetDlgItemText(hwnd, IDC_DPORTEDIT, "");
3113 MessageBox(hwnd, "Too many forwardings",
3114 "PuTTY Error", MB_OK | MB_ICONERROR);
3118 case IDC_PFWDREMOVE:
3119 if (HIWORD(wParam) != BN_CLICKED &&
3120 HIWORD(wParam) != BN_DOUBLECLICKED) break;
3121 i = SendDlgItemMessage(hwnd, IDC_PFWDLIST,
3122 LB_GETCURSEL, 0, 0);
3128 SendDlgItemMessage(hwnd, IDC_PFWDLIST, LB_DELETESTRING,
3158 int id = ((LPHELPINFO)lParam)->iCtrlId;
3159 char *cmd = help_context_cmd(id);
3161 WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
3162 requested_help = TRUE;
3169 if (requested_help) {
3170 WinHelp(hwnd, help_path, HELP_QUIT, 0);
3171 requested_help = FALSE;
3176 /* Grrr Explorer will maximize Dialogs! */
3178 if (wParam == SIZE_MAXIMIZED)
3184 * Handle application-defined messages eg. DragListBox
3186 /* First find out what the number is (once). */
3187 if (draglistmsg == WM_NULL)
3188 draglistmsg = RegisterWindowMessage (DRAGLISTMSGSTRING);
3190 if (msg == draglistmsg) {
3191 /* Only process once dialog is fully formed. */
3192 if (GetWindowLong(hwnd, GWL_USERDATA) == 1) switch (LOWORD(wParam)) {
3193 case IDC_CIPHERLIST:
3194 return handle_prefslist(&cipherlist,
3195 cfg.ssh_cipherlist, CIPHER_MAX,
3196 1, hwnd, wParam, lParam);
3205 static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
3206 WPARAM wParam, LPARAM lParam)
3208 if (msg == WM_COMMAND && LOWORD(wParam) == IDOK) {
3210 if (msg == WM_COMMAND && LOWORD(wParam) == IDCX_ABOUT) {
3211 EnableWindow(hwnd, 0);
3212 DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
3213 EnableWindow(hwnd, 1);
3214 SetActiveWindow(hwnd);
3216 return GenericMainDlgProc(hwnd, msg, wParam, lParam, 0);
3219 static int CALLBACK ReconfDlgProc(HWND hwnd, UINT msg,
3220 WPARAM wParam, LPARAM lParam)
3222 return GenericMainDlgProc(hwnd, msg, wParam, lParam, 1);
3225 void defuse_showwindow(void)
3228 * Work around the fact that the app's first call to ShowWindow
3229 * will ignore the default in favour of the shell-provided
3234 hwnd = CreateDialog(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX),
3236 ShowWindow(hwnd, SW_HIDE);
3237 SetActiveWindow(hwnd);
3238 DestroyWindow(hwnd);
3247 savedsession[0] = '\0';
3249 DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL, MainDlgProc);
3250 get_sesslist(FALSE);
3255 int do_reconfig(HWND hwnd)
3260 backup_cfg = cfg; /* structure copy */
3262 DialogBox(hinst, MAKEINTRESOURCE(IDD_RECONF), hwnd, ReconfDlgProc);
3264 cfg = backup_cfg; /* structure copy */
3269 void logevent(char *string)
3274 if (nevents >= negsize) {
3276 events = srealloc(events, negsize * sizeof(*events));
3280 strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
3283 events[nevents] = smalloc(strlen(timebuf) + strlen(string) + 1);
3284 strcpy(events[nevents], timebuf);
3285 strcat(events[nevents], string);
3288 SendDlgItemMessage(logbox, IDN_LIST, LB_ADDSTRING,
3289 0, (LPARAM) events[nevents]);
3290 count = SendDlgItemMessage(logbox, IDN_LIST, LB_GETCOUNT, 0, 0);
3291 SendDlgItemMessage(logbox, IDN_LIST, LB_SETTOPINDEX, count - 1, 0);
3296 void showeventlog(HWND hwnd)
3299 logbox = CreateDialog(hinst, MAKEINTRESOURCE(IDD_LOGBOX),
3301 ShowWindow(logbox, SW_SHOWNORMAL);
3303 SetActiveWindow(logbox);
3306 void showabout(HWND hwnd)
3308 DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
3311 void verify_ssh_host_key(char *host, int port, char *keytype,
3312 char *keystr, char *fingerprint)
3316 static const char absentmsg[] =
3317 "The server's host key is not cached in the registry. You\n"
3318 "have no guarantee that the server is the computer you\n"
3320 "The server's key fingerprint is:\n"
3322 "If you trust this host, hit Yes to add the key to\n"
3323 "PuTTY's cache and carry on connecting.\n"
3324 "If you want to carry on connecting just once, without\n"
3325 "adding the key to the cache, hit No.\n"
3326 "If you do not trust this host, hit Cancel to abandon the\n"
3329 static const char wrongmsg[] =
3330 "WARNING - POTENTIAL SECURITY BREACH!\n"
3332 "The server's host key does not match the one PuTTY has\n"
3333 "cached in the registry. This means that either the\n"
3334 "server administrator has changed the host key, or you\n"
3335 "have actually connected to another computer pretending\n"
3336 "to be the server.\n"
3337 "The new key fingerprint is:\n"
3339 "If you were expecting this change and trust the new key,\n"
3340 "hit Yes to update PuTTY's cache and continue connecting.\n"
3341 "If you want to carry on connecting but without updating\n"
3342 "the cache, hit No.\n"
3343 "If you want to abandon the connection completely, hit\n"
3344 "Cancel. Hitting Cancel is the ONLY guaranteed safe\n" "choice.\n";
3346 static const char mbtitle[] = "PuTTY Security Alert";
3349 /* sensible fingerprint max size */
3350 (sizeof(absentmsg) > sizeof(wrongmsg) ?
3351 sizeof(absentmsg) : sizeof(wrongmsg))];
3354 * Verify the key against the registry.
3356 ret = verify_host_key(host, port, keytype, keystr);
3358 if (ret == 0) /* success - key matched OK */
3360 if (ret == 2) { /* key was different */
3362 sprintf(message, wrongmsg, fingerprint);
3363 mbret = MessageBox(NULL, message, mbtitle,
3364 MB_ICONWARNING | MB_YESNOCANCEL);
3366 store_host_key(host, port, keytype, keystr);
3367 if (mbret == IDCANCEL)
3370 if (ret == 1) { /* key was absent */
3372 sprintf(message, absentmsg, fingerprint);
3373 mbret = MessageBox(NULL, message, mbtitle,
3374 MB_ICONWARNING | MB_YESNOCANCEL);
3376 store_host_key(host, port, keytype, keystr);
3377 if (mbret == IDCANCEL)
3383 * Ask whether the selected cipher is acceptable (since it was
3384 * below the configured 'warn' threshold).
3385 * cs: 0 = both ways, 1 = client->server, 2 = server->client
3387 void askcipher(char *ciphername, int cs)
3389 static const char mbtitle[] = "PuTTY Security Alert";
3390 static const char msg[] =
3391 "The first %.35scipher supported by the server\n"
3392 "is %.64s, which is below the configured\n"
3393 "warning threshold.\n"
3394 "Do you want to continue with this connection?\n";
3395 /* guessed cipher name + type max length */
3396 char message[100 + sizeof(msg)];
3399 sprintf(message, msg,
3401 (cs == 1) ? "client-to-server " :
3402 "server-to-client ",
3404 mbret = MessageBox(NULL, message, mbtitle,
3405 MB_ICONWARNING | MB_YESNO);
3413 * Ask whether to wipe a session log file before writing to it.
3414 * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
3416 int askappend(char *filename)
3418 static const char mbtitle[] = "PuTTY Log to File";
3419 static const char msgtemplate[] =
3420 "The session log file \"%.*s\" already exists.\n"
3421 "You can overwrite it with a new session log,\n"
3422 "append your session log to the end of it,\n"
3423 "or disable session logging for this session.\n"
3424 "Hit Yes to wipe the file, No to append to it,\n"
3425 "or Cancel to disable logging.";
3426 char message[sizeof(msgtemplate) + FILENAME_MAX];
3428 if (cfg.logxfovr != LGXF_ASK) {
3429 return ((cfg.logxfovr == LGXF_OVR) ? 2 : 1);
3431 sprintf(message, msgtemplate, FILENAME_MAX, filename);
3433 mbret = MessageBox(NULL, message, mbtitle,
3434 MB_ICONQUESTION | MB_YESNOCANCEL);
3437 else if (mbret == IDNO)
3444 * Warn about the obsolescent key file format.
3446 void old_keyfile_warning(void)
3448 static const char mbtitle[] = "PuTTY Key File Warning";
3449 static const char message[] =
3450 "You are loading an SSH 2 private key which has an\n"
3451 "old version of the file format. This means your key\n"
3452 "file is not fully tamperproof. Future versions of\n"
3453 "PuTTY may stop supporting this private key format,\n"
3454 "so we recommend you convert your key to the new\n"
3457 "You can perform this conversion by loading the key\n"
3458 "into PuTTYgen and then saving it again.";
3460 MessageBox(NULL, message, mbtitle, MB_OK);