20 #define MAIN_NPANELS 9
21 #define RECONF_NPANELS 6
23 static char **events
= NULL
;
24 static int nevents
= 0, negsize
= 0;
26 static HWND logbox
= NULL
, abtbox
= NULL
;
28 static void gpps(void *handle
, char *name
, char *def
, char *val
, int len
) {
29 if (!read_setting_s(handle
, name
, val
, len
)) {
30 strncpy(val
, def
, len
);
35 static void gppi(void *handle
, char *name
, int def
, int *i
) {
36 *i
= read_setting_i(handle
, name
, def
);
39 static HINSTANCE hinst
;
43 static void save_settings (char *section
, int do_host
) {
48 sesskey
= open_settings_w(section
);
52 write_setting_i (sesskey
, "Present", 1);
54 write_setting_s (sesskey
, "HostName", cfg
.host
);
55 write_setting_i (sesskey
, "PortNumber", cfg
.port
);
57 for (i
= 0; backends
[i
].name
!= NULL
; i
++)
58 if (backends
[i
].protocol
== cfg
.protocol
) {
62 write_setting_s (sesskey
, "Protocol", p
);
64 write_setting_i (sesskey
, "CloseOnExit", !!cfg
.close_on_exit
);
65 write_setting_i (sesskey
, "WarnOnClose", !!cfg
.warn_on_close
);
66 write_setting_s (sesskey
, "TerminalType", cfg
.termtype
);
67 write_setting_s (sesskey
, "TerminalSpeed", cfg
.termspeed
);
69 char buf
[2*sizeof(cfg
.environmt
)], *p
, *q
;
75 if (c
== '=' || c
== ',' || c
== '\\')
85 write_setting_s (sesskey
, "Environment", buf
);
87 write_setting_s (sesskey
, "UserName", cfg
.username
);
88 write_setting_i (sesskey
, "NoPTY", cfg
.nopty
);
89 write_setting_i (sesskey
, "AgentFwd", cfg
.agentfwd
);
90 write_setting_s (sesskey
, "RemoteCmd", cfg
.remote_cmd
);
91 write_setting_s (sesskey
, "Cipher", cfg
.cipher
== CIPHER_BLOWFISH ?
"blowfish" :
92 cfg
.cipher
== CIPHER_DES ?
"des" : "3des");
93 write_setting_i (sesskey
, "AuthTIS", cfg
.try_tis_auth
);
94 write_setting_i (sesskey
, "SshProt", cfg
.sshprot
);
95 write_setting_s (sesskey
, "PublicKeyFile", cfg
.keyfile
);
96 write_setting_s (sesskey
, "RemoteCommand", cfg
.remote_cmd
);
97 write_setting_i (sesskey
, "RFCEnviron", cfg
.rfc_environ
);
98 write_setting_i (sesskey
, "BackspaceIsDelete", cfg
.bksp_is_delete
);
99 write_setting_i (sesskey
, "RXVTHomeEnd", cfg
.rxvt_homeend
);
100 write_setting_i (sesskey
, "LinuxFunctionKeys", cfg
.funky_type
);
101 write_setting_i (sesskey
, "ApplicationCursorKeys", cfg
.app_cursor
);
102 write_setting_i (sesskey
, "ApplicationKeypad", cfg
.app_keypad
);
103 write_setting_i (sesskey
, "NetHackKeypad", cfg
.nethack_keypad
);
104 write_setting_i (sesskey
, "AltF4", cfg
.alt_f4
);
105 write_setting_i (sesskey
, "AltSpace", cfg
.alt_space
);
106 write_setting_i (sesskey
, "LdiscTerm", cfg
.ldisc_term
);
107 write_setting_i (sesskey
, "BlinkCur", cfg
.blink_cur
);
108 write_setting_i (sesskey
, "Beep", cfg
.beep
);
109 write_setting_i (sesskey
, "ScrollbackLines", cfg
.savelines
);
110 write_setting_i (sesskey
, "DECOriginMode", cfg
.dec_om
);
111 write_setting_i (sesskey
, "AutoWrapMode", cfg
.wrap_mode
);
112 write_setting_i (sesskey
, "LFImpliesCR", cfg
.lfhascr
);
113 write_setting_i (sesskey
, "WinNameAlways", cfg
.win_name_always
);
114 write_setting_s (sesskey
, "WinTitle", cfg
.wintitle
);
115 write_setting_i (sesskey
, "TermWidth", cfg
.width
);
116 write_setting_i (sesskey
, "TermHeight", cfg
.height
);
117 write_setting_s (sesskey
, "Font", cfg
.font
);
118 write_setting_i (sesskey
, "FontIsBold", cfg
.fontisbold
);
119 write_setting_i (sesskey
, "FontCharSet", cfg
.fontcharset
);
120 write_setting_i (sesskey
, "FontHeight", cfg
.fontheight
);
121 write_setting_i (sesskey
, "FontVTMode", cfg
.vtmode
);
122 write_setting_i (sesskey
, "TryPalette", cfg
.try_palette
);
123 write_setting_i (sesskey
, "BoldAsColour", cfg
.bold_colour
);
124 for (i
=0; i
<22; i
++) {
125 char buf
[20], buf2
[30];
126 sprintf(buf
, "Colour%d", i
);
127 sprintf(buf2
, "%d,%d,%d", cfg
.colours
[i
][0],
128 cfg
.colours
[i
][1], cfg
.colours
[i
][2]);
129 write_setting_s (sesskey
, buf
, buf2
);
131 write_setting_i (sesskey
, "MouseIsXterm", cfg
.mouse_is_xterm
);
132 for (i
=0; i
<256; i
+=32) {
133 char buf
[20], buf2
[256];
135 sprintf(buf
, "Wordness%d", i
);
137 for (j
=i
; j
<i
+32; j
++) {
138 sprintf(buf2
+strlen(buf2
), "%s%d",
139 (*buf2 ?
"," : ""), cfg
.wordness
[j
]);
141 write_setting_s (sesskey
, buf
, buf2
);
143 write_setting_i (sesskey
, "KoiWinXlat", cfg
.xlat_enablekoiwin
);
144 write_setting_i (sesskey
, "88592Xlat", cfg
.xlat_88592w1250
);
145 write_setting_i (sesskey
, "CapsLockCyr", cfg
.xlat_capslockcyr
);
146 write_setting_i (sesskey
, "ScrollBar", cfg
.scrollbar
);
147 write_setting_i (sesskey
, "ScrollOnKey", cfg
.scroll_on_key
);
148 write_setting_i (sesskey
, "LockSize", cfg
.locksize
);
149 write_setting_i (sesskey
, "BCE", cfg
.bce
);
150 write_setting_i (sesskey
, "BlinkText", cfg
.blinktext
);
152 close_settings_w(sesskey
);
155 static void load_settings (char *section
, int do_host
) {
160 sesskey
= open_settings_r(section
);
162 gpps (sesskey
, "HostName", "", cfg
.host
, sizeof(cfg
.host
));
163 gppi (sesskey
, "PortNumber", default_port
, &cfg
.port
);
165 gpps (sesskey
, "Protocol", "default", prot
, 10);
166 cfg
.protocol
= default_protocol
;
167 for (i
= 0; backends
[i
].name
!= NULL
; i
++)
168 if (!strcmp(prot
, backends
[i
].name
)) {
169 cfg
.protocol
= backends
[i
].protocol
;
173 gppi (sesskey
, "CloseOnExit", 1, &cfg
.close_on_exit
);
174 gppi (sesskey
, "WarnOnClose", 1, &cfg
.warn_on_close
);
175 gpps (sesskey
, "TerminalType", "xterm", cfg
.termtype
,
176 sizeof(cfg
.termtype
));
177 gpps (sesskey
, "TerminalSpeed", "38400,38400", cfg
.termspeed
,
178 sizeof(cfg
.termspeed
));
180 char buf
[2*sizeof(cfg
.environmt
)], *p
, *q
;
181 gpps (sesskey
, "Environment", "", buf
, sizeof(buf
));
185 while (*p
&& *p
!= ',') {
198 gpps (sesskey
, "UserName", "", cfg
.username
, sizeof(cfg
.username
));
199 gppi (sesskey
, "NoPTY", 0, &cfg
.nopty
);
200 gppi (sesskey
, "AgentFwd", 0, &cfg
.agentfwd
);
201 gpps (sesskey
, "RemoteCmd", "", cfg
.remote_cmd
, sizeof(cfg
.remote_cmd
));
204 gpps (sesskey
, "Cipher", "3des", cipher
, 10);
205 if (!strcmp(cipher
, "blowfish"))
206 cfg
.cipher
= CIPHER_BLOWFISH
;
207 else if (!strcmp(cipher
, "des"))
208 cfg
.cipher
= CIPHER_DES
;
210 cfg
.cipher
= CIPHER_3DES
;
212 gppi (sesskey
, "SshProt", 1, &cfg
.sshprot
);
213 gppi (sesskey
, "AuthTIS", 0, &cfg
.try_tis_auth
);
214 gpps (sesskey
, "PublicKeyFile", "", cfg
.keyfile
, sizeof(cfg
.keyfile
));
215 gpps (sesskey
, "RemoteCommand", "", cfg
.remote_cmd
,
216 sizeof(cfg
.remote_cmd
));
217 gppi (sesskey
, "RFCEnviron", 0, &cfg
.rfc_environ
);
218 gppi (sesskey
, "BackspaceIsDelete", 1, &cfg
.bksp_is_delete
);
219 gppi (sesskey
, "RXVTHomeEnd", 0, &cfg
.rxvt_homeend
);
220 gppi (sesskey
, "LinuxFunctionKeys", 0, &cfg
.funky_type
);
221 gppi (sesskey
, "ApplicationCursorKeys", 0, &cfg
.app_cursor
);
222 gppi (sesskey
, "ApplicationKeypad", 0, &cfg
.app_keypad
);
223 gppi (sesskey
, "NetHackKeypad", 0, &cfg
.nethack_keypad
);
224 gppi (sesskey
, "AltF4", 1, &cfg
.alt_f4
);
225 gppi (sesskey
, "AltSpace", 0, &cfg
.alt_space
);
226 gppi (sesskey
, "LdiscTerm", 0, &cfg
.ldisc_term
);
227 gppi (sesskey
, "BlinkCur", 0, &cfg
.blink_cur
);
228 gppi (sesskey
, "Beep", 1, &cfg
.beep
);
229 gppi (sesskey
, "ScrollbackLines", 200, &cfg
.savelines
);
230 gppi (sesskey
, "DECOriginMode", 0, &cfg
.dec_om
);
231 gppi (sesskey
, "AutoWrapMode", 1, &cfg
.wrap_mode
);
232 gppi (sesskey
, "LFImpliesCR", 0, &cfg
.lfhascr
);
233 gppi (sesskey
, "WinNameAlways", 0, &cfg
.win_name_always
);
234 gpps (sesskey
, "WinTitle", "", cfg
.wintitle
, sizeof(cfg
.wintitle
));
235 gppi (sesskey
, "TermWidth", 80, &cfg
.width
);
236 gppi (sesskey
, "TermHeight", 24, &cfg
.height
);
237 gpps (sesskey
, "Font", "Courier", cfg
.font
, sizeof(cfg
.font
));
238 gppi (sesskey
, "FontIsBold", 0, &cfg
.fontisbold
);
239 gppi (sesskey
, "FontCharSet", ANSI_CHARSET
, &cfg
.fontcharset
);
240 gppi (sesskey
, "FontHeight", 10, &cfg
.fontheight
);
241 gppi (sesskey
, "FontVTMode", VT_OEMANSI
, (int *)&cfg
.vtmode
);
242 gppi (sesskey
, "TryPalette", 0, &cfg
.try_palette
);
243 gppi (sesskey
, "BoldAsColour", 1, &cfg
.bold_colour
);
244 for (i
=0; i
<22; i
++) {
245 static char *defaults
[] = {
246 "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
247 "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
248 "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
249 "85,85,255", "187,0,187", "255,85,255", "0,187,187",
250 "85,255,255", "187,187,187", "255,255,255"
252 char buf
[20], buf2
[30];
254 sprintf(buf
, "Colour%d", i
);
255 gpps (sesskey
, buf
, defaults
[i
], buf2
, sizeof(buf2
));
256 if(sscanf(buf2
, "%d,%d,%d", &c0
, &c1
, &c2
) == 3) {
257 cfg
.colours
[i
][0] = c0
;
258 cfg
.colours
[i
][1] = c1
;
259 cfg
.colours
[i
][2] = c2
;
262 gppi (sesskey
, "MouseIsXterm", 0, &cfg
.mouse_is_xterm
);
263 for (i
=0; i
<256; i
+=32) {
264 static char *defaults
[] = {
265 "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
266 "0,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1",
267 "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2",
268 "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1",
269 "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",
270 "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",
271 "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2",
272 "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2"
274 char buf
[20], buf2
[256], *p
;
276 sprintf(buf
, "Wordness%d", i
);
277 gpps (sesskey
, buf
, defaults
[i
/32], buf2
, sizeof(buf2
));
279 for (j
=i
; j
<i
+32; j
++) {
281 while (*p
&& *p
!= ',') p
++;
282 if (*p
== ',') *p
++ = '\0';
283 cfg
.wordness
[j
] = atoi(q
);
286 gppi (sesskey
, "KoiWinXlat", 0, &cfg
.xlat_enablekoiwin
);
287 gppi (sesskey
, "88592Xlat", 0, &cfg
.xlat_88592w1250
);
288 gppi (sesskey
, "CapsLockCyr", 0, &cfg
.xlat_capslockcyr
);
289 gppi (sesskey
, "ScrollBar", 1, &cfg
.scrollbar
);
290 gppi (sesskey
, "ScrollOnKey", 0, &cfg
.scroll_on_key
);
291 gppi (sesskey
, "LockSize", 0, &cfg
.locksize
);
292 gppi (sesskey
, "BCE", 0, &cfg
.bce
);
293 gppi (sesskey
, "BlinkText", 0, &cfg
.blinktext
);
295 close_settings_r(sesskey
);
298 static void force_normal(HWND hwnd
)
300 static int recurse
= 0;
307 wp
.length
= sizeof(wp
);
308 if (GetWindowPlacement(hwnd
, &wp
))
310 wp
.showCmd
= SW_SHOWNORMAL
;
311 SetWindowPlacement(hwnd
, &wp
);
316 static void MyGetDlgItemInt (HWND hwnd
, int id
, int *result
) {
319 n
= GetDlgItemInt (hwnd
, id
, &ok
, FALSE
);
324 static int CALLBACK
LogProc (HWND hwnd
, UINT msg
,
325 WPARAM wParam
, LPARAM lParam
) {
330 for (i
=0; i
<nevents
; i
++)
331 SendDlgItemMessage (hwnd
, IDN_LIST
, LB_ADDSTRING
,
332 0, (LPARAM
)events
[i
]);
334 /* case WM_CTLCOLORDLG: */
335 /* return (int) GetStockObject (LTGRAY_BRUSH); */
337 switch (LOWORD(wParam
)) {
340 DestroyWindow (hwnd
);
343 if (HIWORD(wParam
) == BN_CLICKED
||
344 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
347 selcount
= SendDlgItemMessage(hwnd
, IDN_LIST
,
348 LB_GETSELCOUNT
, 0, 0);
349 selitems
= malloc(selcount
* sizeof(int));
351 int count
= SendDlgItemMessage(hwnd
, IDN_LIST
,
353 selcount
, (LPARAM
)selitems
);
357 static unsigned char sel_nl
[] = SEL_NL
;
360 for (i
= 0; i
< count
; i
++)
361 size
+= strlen(events
[selitems
[i
]]) + sizeof(sel_nl
);
363 clipdata
= malloc(size
);
366 for (i
= 0; i
< count
; i
++) {
367 char *q
= events
[selitems
[i
]];
368 int qlen
= strlen(q
);
371 memcpy(p
, sel_nl
, sizeof(sel_nl
));
374 write_clip(clipdata
, size
);
386 DestroyWindow (hwnd
);
392 static int CALLBACK
LicenceProc (HWND hwnd
, UINT msg
,
393 WPARAM wParam
, LPARAM lParam
) {
398 switch (LOWORD(wParam
)) {
411 static int CALLBACK
AboutProc (HWND hwnd
, UINT msg
,
412 WPARAM wParam
, LPARAM lParam
) {
415 SetDlgItemText (hwnd
, IDA_VERSION
, ver
);
417 /* case WM_CTLCOLORDLG: */
418 /* return (int) GetStockObject (LTGRAY_BRUSH); */
419 /* case WM_CTLCOLORSTATIC: */
420 /* SetBkColor ((HDC)wParam, RGB(192,192,192)); */
421 /* return (int) GetStockObject (LTGRAY_BRUSH); */
423 switch (LOWORD(wParam
)) {
426 DestroyWindow (hwnd
);
429 EnableWindow(hwnd
, 0);
430 DialogBox (hinst
, MAKEINTRESOURCE(IDD_LICENCEBOX
),
432 EnableWindow(hwnd
, 1);
433 SetActiveWindow(hwnd
);
439 DestroyWindow (hwnd
);
445 static int GeneralPanelProc (HWND hwnd
, UINT msg
,
446 WPARAM wParam
, LPARAM lParam
) {
449 SetWindowPos (hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
451 /* case WM_CTLCOLORDLG: */
452 /* return (int) GetStockObject (LTGRAY_BRUSH); */
453 /* case WM_CTLCOLORSTATIC: */
454 /* case WM_CTLCOLORBTN: */
455 /* SetBkColor ((HDC)wParam, RGB(192,192,192)); */
456 /* return (int) GetStockObject (LTGRAY_BRUSH); */
458 DestroyWindow (hwnd
);
464 static char savedsession
[2048];
466 static int CALLBACK
ConnectionProc (HWND hwnd
, UINT msg
,
467 WPARAM wParam
, LPARAM lParam
) {
472 SetDlgItemText (hwnd
, IDC0_HOST
, cfg
.host
);
473 SetDlgItemText (hwnd
, IDC0_SESSEDIT
, savedsession
);
474 SetDlgItemInt (hwnd
, IDC0_PORT
, cfg
.port
, FALSE
);
475 for (i
= 0; i
< nsessions
; i
++)
476 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_ADDSTRING
,
477 0, (LPARAM
) (sessions
[i
]));
478 CheckRadioButton (hwnd
, IDC0_PROTRAW
, IDC0_PROTSSH
,
479 cfg
.protocol
==PROT_SSH ? IDC0_PROTSSH
:
480 cfg
.protocol
==PROT_TELNET ? IDC0_PROTTELNET
: IDC0_PROTRAW
);
481 CheckDlgButton (hwnd
, IDC0_CLOSEEXIT
, cfg
.close_on_exit
);
482 CheckDlgButton (hwnd
, IDC0_CLOSEWARN
, cfg
.warn_on_close
);
486 * Button release should trigger WM_OK if there was a
487 * previous double click on the session list.
491 SendMessage (GetParent(hwnd
), WM_COMMAND
, IDOK
, 0);
494 switch (LOWORD(wParam
)) {
495 case IDC0_PROTTELNET
:
498 if (HIWORD(wParam
) == BN_CLICKED
||
499 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
500 int i
= IsDlgButtonChecked (hwnd
, IDC0_PROTSSH
);
501 int j
= IsDlgButtonChecked (hwnd
, IDC0_PROTTELNET
);
502 cfg
.protocol
= i ? PROT_SSH
: j ? PROT_TELNET
: PROT_RAW
;
503 if ((cfg
.protocol
== PROT_SSH
&& cfg
.port
== 23) ||
504 (cfg
.protocol
== PROT_TELNET
&& cfg
.port
== 22)) {
505 cfg
.port
= i ?
22 : 23;
506 SetDlgItemInt (hwnd
, IDC0_PORT
, cfg
.port
, FALSE
);
511 if (HIWORD(wParam
) == EN_CHANGE
)
512 GetDlgItemText (hwnd
, IDC0_HOST
, cfg
.host
,
516 if (HIWORD(wParam
) == EN_CHANGE
)
517 MyGetDlgItemInt (hwnd
, IDC0_PORT
, &cfg
.port
);
520 if (HIWORD(wParam
) == BN_CLICKED
||
521 HIWORD(wParam
) == BN_DOUBLECLICKED
)
522 cfg
.close_on_exit
= IsDlgButtonChecked (hwnd
, IDC0_CLOSEEXIT
);
525 if (HIWORD(wParam
) == BN_CLICKED
||
526 HIWORD(wParam
) == BN_DOUBLECLICKED
)
527 cfg
.warn_on_close
= IsDlgButtonChecked (hwnd
, IDC0_CLOSEWARN
);
530 if (HIWORD(wParam
) == EN_CHANGE
) {
531 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_SETCURSEL
,
533 GetDlgItemText (hwnd
, IDC0_SESSEDIT
,
534 savedsession
, sizeof(savedsession
)-1);
535 savedsession
[sizeof(savedsession
)-1] = '\0';
539 if (HIWORD(wParam
) == BN_CLICKED
||
540 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
545 GetDlgItemText (hwnd
, IDC0_SESSEDIT
, str
, sizeof(str
)-1);
547 int n
= SendDlgItemMessage (hwnd
, IDC0_SESSLIST
,
553 strcpy (str
, sessions
[n
]);
555 save_settings (str
, !!strcmp(str
, "Default Settings"));
556 get_sesslist (FALSE
);
558 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_RESETCONTENT
,
560 for (i
= 0; i
< nsessions
; i
++)
561 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_ADDSTRING
,
562 0, (LPARAM
) (sessions
[i
]));
563 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_SETCURSEL
,
569 if (LOWORD(wParam
) == IDC0_SESSLOAD
&&
570 HIWORD(wParam
) != BN_CLICKED
&&
571 HIWORD(wParam
) != BN_DOUBLECLICKED
)
573 if (LOWORD(wParam
) == IDC0_SESSLIST
&&
574 HIWORD(wParam
) != LBN_DBLCLK
)
577 int n
= SendDlgItemMessage (hwnd
, IDC0_SESSLIST
,
583 load_settings (sessions
[n
],
584 !!strcmp(sessions
[n
], "Default Settings"));
585 SetDlgItemText (hwnd
, IDC0_HOST
, cfg
.host
);
586 SetDlgItemInt (hwnd
, IDC0_PORT
, cfg
.port
, FALSE
);
587 CheckRadioButton (hwnd
, IDC0_PROTRAW
, IDC0_PROTSSH
,
588 (cfg
.protocol
==PROT_SSH ? IDC0_PROTSSH
:
589 cfg
.protocol
==PROT_TELNET ? IDC0_PROTTELNET
: IDC0_PROTRAW
));
590 CheckDlgButton (hwnd
, IDC0_CLOSEEXIT
, cfg
.close_on_exit
);
591 CheckDlgButton (hwnd
, IDC0_CLOSEWARN
, cfg
.warn_on_close
);
592 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_SETCURSEL
,
595 if (LOWORD(wParam
) == IDC0_SESSLIST
) {
597 * A double-click on a saved session should
598 * actually start the session, not just load it.
599 * Unless it's Default Settings or some other
600 * host-less set of saved settings.
609 if (HIWORD(wParam
) == BN_CLICKED
||
610 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
611 int n
= SendDlgItemMessage (hwnd
, IDC0_SESSLIST
,
613 if (n
== LB_ERR
|| n
== 0) {
617 del_settings(sessions
[n
]);
618 get_sesslist (FALSE
);
620 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_RESETCONTENT
,
622 for (i
= 0; i
< nsessions
; i
++)
623 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_ADDSTRING
,
624 0, (LPARAM
) (sessions
[i
]));
625 SendDlgItemMessage (hwnd
, IDC0_SESSLIST
, LB_SETCURSEL
,
630 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
633 static int CALLBACK
KeyboardProc (HWND hwnd
, UINT msg
,
634 WPARAM wParam
, LPARAM lParam
) {
637 CheckRadioButton (hwnd
, IDC1_DEL008
, IDC1_DEL127
,
638 cfg
.bksp_is_delete ? IDC1_DEL127
: IDC1_DEL008
);
639 CheckRadioButton (hwnd
, IDC1_HOMETILDE
, IDC1_HOMERXVT
,
640 cfg
.rxvt_homeend ? IDC1_HOMERXVT
: IDC1_HOMETILDE
);
641 CheckRadioButton (hwnd
, IDC1_FUNCTILDE
, IDC1_FUNCXTERM
,
643 (cfg
.funky_type
==2 ? IDC1_FUNCXTERM
646 CheckRadioButton (hwnd
, IDC1_CURNORMAL
, IDC1_CURAPPLIC
,
647 cfg
.app_cursor ? IDC1_CURAPPLIC
: IDC1_CURNORMAL
);
648 CheckRadioButton (hwnd
, IDC1_KPNORMAL
, IDC1_KPNH
,
649 cfg
.nethack_keypad ? IDC1_KPNH
:
650 cfg
.app_keypad ? IDC1_KPAPPLIC
: IDC1_KPNORMAL
);
651 CheckDlgButton (hwnd
, IDC1_ALTF4
, cfg
.alt_f4
);
652 CheckDlgButton (hwnd
, IDC1_ALTSPACE
, cfg
.alt_space
);
653 CheckDlgButton (hwnd
, IDC1_LDISCTERM
, cfg
.ldisc_term
);
654 CheckDlgButton (hwnd
, IDC1_SCROLLKEY
, cfg
.scroll_on_key
);
657 if (HIWORD(wParam
) == BN_CLICKED
||
658 HIWORD(wParam
) == BN_DOUBLECLICKED
)
659 switch (LOWORD(wParam
)) {
662 cfg
.bksp_is_delete
= IsDlgButtonChecked (hwnd
, IDC1_DEL127
);
666 cfg
.rxvt_homeend
= IsDlgButtonChecked (hwnd
, IDC1_HOMERXVT
);
673 cfg
.funky_type
= IsDlgButtonChecked (hwnd
, IDC1_FUNCLINUX
);
677 cfg
.app_keypad
= IsDlgButtonChecked (hwnd
, IDC1_KPAPPLIC
);
678 cfg
.nethack_keypad
= FALSE
;
681 cfg
.app_keypad
= FALSE
;
682 cfg
.nethack_keypad
= TRUE
;
686 cfg
.app_cursor
= IsDlgButtonChecked (hwnd
, IDC1_CURAPPLIC
);
689 if (HIWORD(wParam
) == BN_CLICKED
||
690 HIWORD(wParam
) == BN_DOUBLECLICKED
)
691 cfg
.alt_f4
= IsDlgButtonChecked (hwnd
, IDC1_ALTF4
);
694 if (HIWORD(wParam
) == BN_CLICKED
||
695 HIWORD(wParam
) == BN_DOUBLECLICKED
)
696 cfg
.alt_space
= IsDlgButtonChecked (hwnd
, IDC1_ALTSPACE
);
699 if (HIWORD(wParam
) == BN_CLICKED
||
700 HIWORD(wParam
) == BN_DOUBLECLICKED
)
701 cfg
.ldisc_term
= IsDlgButtonChecked (hwnd
, IDC1_LDISCTERM
);
704 if (HIWORD(wParam
) == BN_CLICKED
||
705 HIWORD(wParam
) == BN_DOUBLECLICKED
)
706 cfg
.scroll_on_key
= IsDlgButtonChecked (hwnd
, IDC1_SCROLLKEY
);
710 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
713 static void fmtfont (char *buf
) {
714 sprintf (buf
, "Font: %s, ", cfg
.font
);
716 strcat(buf
, "bold, ");
717 if (cfg
.fontheight
== 0)
718 strcat (buf
, "default height");
720 sprintf (buf
+strlen(buf
), "%d-%s",
721 (cfg
.fontheight
< 0 ?
-cfg
.fontheight
: cfg
.fontheight
),
722 (cfg
.fontheight
< 0 ?
"pixel" : "point"));
725 static int CALLBACK
TerminalProc (HWND hwnd
, UINT msg
,
726 WPARAM wParam
, LPARAM lParam
) {
729 char fontstatic
[256];
733 CheckDlgButton (hwnd
, IDC2_WRAPMODE
, cfg
.wrap_mode
);
734 CheckDlgButton (hwnd
, IDC2_DECOM
, cfg
.dec_om
);
735 CheckDlgButton (hwnd
, IDC2_LFHASCR
, cfg
.lfhascr
);
736 SetDlgItemInt (hwnd
, IDC2_ROWSEDIT
, cfg
.height
, FALSE
);
737 SetDlgItemInt (hwnd
, IDC2_COLSEDIT
, cfg
.width
, FALSE
);
738 SetDlgItemInt (hwnd
, IDC2_SAVEEDIT
, cfg
.savelines
, FALSE
);
739 fmtfont (fontstatic
);
740 SetDlgItemText (hwnd
, IDC2_FONTSTATIC
, fontstatic
);
741 CheckDlgButton (hwnd
, IDC1_BEEP
, cfg
.beep
);
742 CheckDlgButton (hwnd
, IDC2_BCE
, cfg
.bce
);
743 CheckDlgButton (hwnd
, IDC2_BLINKTEXT
, cfg
.blinktext
);
746 switch (LOWORD(wParam
)) {
748 if (HIWORD(wParam
) == BN_CLICKED
||
749 HIWORD(wParam
) == BN_DOUBLECLICKED
)
750 cfg
.wrap_mode
= IsDlgButtonChecked (hwnd
, IDC2_WRAPMODE
);
753 if (HIWORD(wParam
) == BN_CLICKED
||
754 HIWORD(wParam
) == BN_DOUBLECLICKED
)
755 cfg
.dec_om
= IsDlgButtonChecked (hwnd
, IDC2_DECOM
);
758 if (HIWORD(wParam
) == BN_CLICKED
||
759 HIWORD(wParam
) == BN_DOUBLECLICKED
)
760 cfg
.lfhascr
= IsDlgButtonChecked (hwnd
, IDC2_LFHASCR
);
763 if (HIWORD(wParam
) == EN_CHANGE
)
764 MyGetDlgItemInt (hwnd
, IDC2_ROWSEDIT
, &cfg
.height
);
767 if (HIWORD(wParam
) == EN_CHANGE
)
768 MyGetDlgItemInt (hwnd
, IDC2_COLSEDIT
, &cfg
.width
);
771 if (HIWORD(wParam
) == EN_CHANGE
)
772 MyGetDlgItemInt (hwnd
, IDC2_SAVEEDIT
, &cfg
.savelines
);
774 case IDC2_CHOOSEFONT
:
775 lf
.lfHeight
= cfg
.fontheight
;
776 lf
.lfWidth
= lf
.lfEscapement
= lf
.lfOrientation
= 0;
777 lf
.lfItalic
= lf
.lfUnderline
= lf
.lfStrikeOut
= 0;
778 lf
.lfWeight
= (cfg
.fontisbold ? FW_BOLD
: 0);
779 lf
.lfCharSet
= cfg
.fontcharset
;
780 lf
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
781 lf
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
782 lf
.lfQuality
= DEFAULT_QUALITY
;
783 lf
.lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
784 strncpy (lf
.lfFaceName
, cfg
.font
, sizeof(lf
.lfFaceName
)-1);
785 lf
.lfFaceName
[sizeof(lf
.lfFaceName
)-1] = '\0';
787 cf
.lStructSize
= sizeof(cf
);
790 cf
.Flags
= CF_FIXEDPITCHONLY
| CF_FORCEFONTEXIST
|
791 CF_INITTOLOGFONTSTRUCT
| CF_SCREENFONTS
;
793 if (ChooseFont (&cf
)) {
794 strncpy (cfg
.font
, lf
.lfFaceName
, sizeof(cfg
.font
)-1);
795 cfg
.font
[sizeof(cfg
.font
)-1] = '\0';
796 cfg
.fontisbold
= (lf
.lfWeight
== FW_BOLD
);
797 cfg
.fontcharset
= lf
.lfCharSet
;
798 cfg
.fontheight
= lf
.lfHeight
;
799 fmtfont (fontstatic
);
800 SetDlgItemText (hwnd
, IDC2_FONTSTATIC
, fontstatic
);
804 if (HIWORD(wParam
) == BN_CLICKED
||
805 HIWORD(wParam
) == BN_DOUBLECLICKED
)
806 cfg
.beep
= IsDlgButtonChecked (hwnd
, IDC1_BEEP
);
809 if (HIWORD(wParam
) == BN_CLICKED
||
810 HIWORD(wParam
) == BN_DOUBLECLICKED
)
811 cfg
.blinktext
= IsDlgButtonChecked (hwnd
, IDC2_BLINKTEXT
);
814 if (HIWORD(wParam
) == BN_CLICKED
||
815 HIWORD(wParam
) == BN_DOUBLECLICKED
)
816 cfg
.bce
= IsDlgButtonChecked (hwnd
, IDC2_BCE
);
821 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
824 static int CALLBACK
WindowProc (HWND hwnd
, UINT msg
,
825 WPARAM wParam
, LPARAM lParam
) {
828 SetDlgItemText (hwnd
, IDCW_WINEDIT
, cfg
.wintitle
);
829 CheckDlgButton (hwnd
, IDCW_WINNAME
, cfg
.win_name_always
);
830 CheckDlgButton (hwnd
, IDCW_BLINKCUR
, cfg
.blink_cur
);
831 CheckDlgButton (hwnd
, IDCW_SCROLLBAR
, cfg
.scrollbar
);
832 CheckDlgButton (hwnd
, IDCW_LOCKSIZE
, cfg
.locksize
);
835 switch (LOWORD(wParam
)) {
837 if (HIWORD(wParam
) == BN_CLICKED
||
838 HIWORD(wParam
) == BN_DOUBLECLICKED
)
839 cfg
.win_name_always
= IsDlgButtonChecked (hwnd
, IDCW_WINNAME
);
842 if (HIWORD(wParam
) == BN_CLICKED
||
843 HIWORD(wParam
) == BN_DOUBLECLICKED
)
844 cfg
.blink_cur
= IsDlgButtonChecked (hwnd
, IDCW_BLINKCUR
);
847 if (HIWORD(wParam
) == BN_CLICKED
||
848 HIWORD(wParam
) == BN_DOUBLECLICKED
)
849 cfg
.scrollbar
= IsDlgButtonChecked (hwnd
, IDCW_SCROLLBAR
);
852 if (HIWORD(wParam
) == BN_CLICKED
||
853 HIWORD(wParam
) == BN_DOUBLECLICKED
)
854 cfg
.locksize
= IsDlgButtonChecked (hwnd
, IDCW_LOCKSIZE
);
857 if (HIWORD(wParam
) == EN_CHANGE
)
858 GetDlgItemText (hwnd
, IDCW_WINEDIT
, cfg
.wintitle
,
859 sizeof(cfg
.wintitle
)-1);
864 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
867 static int CALLBACK
TelnetProc (HWND hwnd
, UINT msg
,
868 WPARAM wParam
, LPARAM lParam
) {
873 SetDlgItemText (hwnd
, IDC3_TTEDIT
, cfg
.termtype
);
874 SetDlgItemText (hwnd
, IDC3_TSEDIT
, cfg
.termspeed
);
875 SetDlgItemText (hwnd
, IDC3_LOGEDIT
, cfg
.username
);
877 char *p
= cfg
.environmt
;
879 SendDlgItemMessage (hwnd
, IDC3_ENVLIST
, LB_ADDSTRING
, 0,
884 CheckRadioButton (hwnd
, IDC3_EMBSD
, IDC3_EMRFC
,
885 cfg
.rfc_environ ? IDC3_EMRFC
: IDC3_EMBSD
);
888 switch (LOWORD(wParam
)) {
890 if (HIWORD(wParam
) == EN_CHANGE
)
891 GetDlgItemText (hwnd
, IDC3_TTEDIT
, cfg
.termtype
,
892 sizeof(cfg
.termtype
)-1);
895 if (HIWORD(wParam
) == EN_CHANGE
)
896 GetDlgItemText (hwnd
, IDC3_TSEDIT
, cfg
.termspeed
,
897 sizeof(cfg
.termspeed
)-1);
900 if (HIWORD(wParam
) == EN_CHANGE
)
901 GetDlgItemText (hwnd
, IDC3_LOGEDIT
, cfg
.username
,
902 sizeof(cfg
.username
)-1);
906 cfg
.rfc_environ
= IsDlgButtonChecked (hwnd
, IDC3_EMRFC
);
909 if (HIWORD(wParam
) == BN_CLICKED
||
910 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
911 char str
[sizeof(cfg
.environmt
)];
913 GetDlgItemText (hwnd
, IDC3_VAREDIT
, str
, sizeof(str
)-1);
918 p
= str
+ strlen(str
);
920 GetDlgItemText (hwnd
, IDC3_VALEDIT
, p
, sizeof(str
)-1-(p
-str
));
930 if ((p
-cfg
.environmt
) + strlen(str
) + 2 < sizeof(cfg
.environmt
)) {
932 p
[strlen(str
)+1] = '\0';
933 SendDlgItemMessage (hwnd
, IDC3_ENVLIST
, LB_ADDSTRING
,
935 SetDlgItemText (hwnd
, IDC3_VAREDIT
, "");
936 SetDlgItemText (hwnd
, IDC3_VALEDIT
, "");
938 MessageBox(hwnd
, "Environment too big", "PuTTY Error",
939 MB_OK
| MB_ICONERROR
);
944 if (HIWORD(wParam
) != BN_CLICKED
&&
945 HIWORD(wParam
) != BN_DOUBLECLICKED
)
947 i
= SendDlgItemMessage (hwnd
, IDC3_ENVLIST
, LB_GETCURSEL
, 0, 0);
953 SendDlgItemMessage (hwnd
, IDC3_ENVLIST
, LB_DELETESTRING
,
980 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
983 static int CALLBACK
SshProc (HWND hwnd
, UINT msg
,
984 WPARAM wParam
, LPARAM lParam
) {
986 char filename
[sizeof(cfg
.keyfile
)];
990 SetDlgItemText (hwnd
, IDC3_TTEDIT
, cfg
.termtype
);
991 SetDlgItemText (hwnd
, IDC3_LOGEDIT
, cfg
.username
);
992 CheckDlgButton (hwnd
, IDC3_NOPTY
, cfg
.nopty
);
993 CheckDlgButton (hwnd
, IDC3_AGENTFWD
, cfg
.agentfwd
);
994 CheckRadioButton (hwnd
, IDC3_CIPHER3DES
, IDC3_CIPHERDES
,
995 cfg
.cipher
== CIPHER_BLOWFISH ? IDC3_CIPHERBLOWF
:
996 cfg
.cipher
== CIPHER_DES ? IDC3_CIPHERDES
:
998 CheckRadioButton (hwnd
, IDC3_SSHPROT1
, IDC3_SSHPROT2
,
999 cfg
.sshprot
== 1 ? IDC3_SSHPROT1
: IDC3_SSHPROT2
);
1000 CheckDlgButton (hwnd
, IDC3_AUTHTIS
, cfg
.try_tis_auth
);
1001 SetDlgItemText (hwnd
, IDC3_PKEDIT
, cfg
.keyfile
);
1002 SetDlgItemText (hwnd
, IDC3_CMDEDIT
, cfg
.remote_cmd
);
1005 switch (LOWORD(wParam
)) {
1007 if (HIWORD(wParam
) == EN_CHANGE
)
1008 GetDlgItemText (hwnd
, IDC3_TTEDIT
, cfg
.termtype
,
1009 sizeof(cfg
.termtype
)-1);
1012 if (HIWORD(wParam
) == EN_CHANGE
)
1013 GetDlgItemText (hwnd
, IDC3_LOGEDIT
, cfg
.username
,
1014 sizeof(cfg
.username
)-1);
1017 if (HIWORD(wParam
) == BN_CLICKED
||
1018 HIWORD(wParam
) == BN_DOUBLECLICKED
)
1019 cfg
.nopty
= IsDlgButtonChecked (hwnd
, IDC3_NOPTY
);
1022 if (HIWORD(wParam
) == BN_CLICKED
||
1023 HIWORD(wParam
) == BN_DOUBLECLICKED
)
1024 cfg
.agentfwd
= IsDlgButtonChecked (hwnd
, IDC3_AGENTFWD
);
1026 case IDC3_CIPHER3DES
:
1027 case IDC3_CIPHERBLOWF
:
1028 case IDC3_CIPHERDES
:
1029 if (HIWORD(wParam
) == BN_CLICKED
||
1030 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
1031 if (IsDlgButtonChecked (hwnd
, IDC3_CIPHER3DES
))
1032 cfg
.cipher
= CIPHER_3DES
;
1033 else if (IsDlgButtonChecked (hwnd
, IDC3_CIPHERBLOWF
))
1034 cfg
.cipher
= CIPHER_BLOWFISH
;
1035 else if (IsDlgButtonChecked (hwnd
, IDC3_CIPHERDES
))
1036 cfg
.cipher
= CIPHER_DES
;
1041 if (HIWORD(wParam
) == BN_CLICKED
||
1042 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
1043 if (IsDlgButtonChecked (hwnd
, IDC3_SSHPROT1
))
1045 else if (IsDlgButtonChecked (hwnd
, IDC3_SSHPROT2
))
1050 if (HIWORD(wParam
) == BN_CLICKED
||
1051 HIWORD(wParam
) == BN_DOUBLECLICKED
)
1052 cfg
.try_tis_auth
= IsDlgButtonChecked (hwnd
, IDC3_AUTHTIS
);
1055 if (HIWORD(wParam
) == EN_CHANGE
)
1056 GetDlgItemText (hwnd
, IDC3_PKEDIT
, cfg
.keyfile
,
1057 sizeof(cfg
.keyfile
)-1);
1060 if (HIWORD(wParam
) == EN_CHANGE
)
1061 GetDlgItemText (hwnd
, IDC3_CMDEDIT
, cfg
.remote_cmd
,
1062 sizeof(cfg
.remote_cmd
)-1);
1066 * FIXME: this crashes. Find out why.
1068 memset(&of
, 0, sizeof(of
));
1069 #ifdef OPENFILENAME_SIZE_VERSION_400
1070 of
.lStructSize
= OPENFILENAME_SIZE_VERSION_400
;
1072 of
.lStructSize
= sizeof(of
);
1074 of
.hwndOwner
= hwnd
;
1075 of
.lpstrFilter
= "All Files\0*\0\0\0";
1076 of
.lpstrCustomFilter
= NULL
;
1077 of
.nFilterIndex
= 1;
1078 of
.lpstrFile
= filename
; strcpy(filename
, cfg
.keyfile
);
1079 of
.nMaxFile
= sizeof(filename
);
1080 of
.lpstrFileTitle
= NULL
;
1081 of
.lpstrInitialDir
= NULL
;
1082 of
.lpstrTitle
= "Select Public Key File";
1084 if (GetOpenFileName(&of
)) {
1085 strcpy(cfg
.keyfile
, filename
);
1086 SetDlgItemText (hwnd
, IDC3_PKEDIT
, cfg
.keyfile
);
1092 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
1095 static int CALLBACK
SelectionProc (HWND hwnd
, UINT msg
,
1096 WPARAM wParam
, LPARAM lParam
) {
1101 CheckRadioButton (hwnd
, IDC4_MBWINDOWS
, IDC4_MBXTERM
,
1102 cfg
.mouse_is_xterm ? IDC4_MBXTERM
: IDC4_MBWINDOWS
);
1104 static int tabs
[4] = {25, 61, 96, 128};
1105 SendDlgItemMessage (hwnd
, IDC4_CCLIST
, LB_SETTABSTOPS
, 4,
1108 for (i
=0; i
<256; i
++) {
1110 sprintf(str
, "%d\t(0x%02X)\t%c\t%d", i
, i
,
1111 (i
>=0x21 && i
!= 0x7F) ? i
: ' ',
1113 SendDlgItemMessage (hwnd
, IDC4_CCLIST
, LB_ADDSTRING
, 0,
1118 switch (LOWORD(wParam
)) {
1119 case IDC4_MBWINDOWS
:
1121 cfg
.mouse_is_xterm
= IsDlgButtonChecked (hwnd
, IDC4_MBXTERM
);
1127 int n
= GetDlgItemInt (hwnd
, IDC4_CCEDIT
, &ok
, FALSE
);
1132 for (i
=0; i
<256; i
++)
1133 if (SendDlgItemMessage (hwnd
, IDC4_CCLIST
, LB_GETSEL
,
1136 cfg
.wordness
[i
] = n
;
1137 SendDlgItemMessage (hwnd
, IDC4_CCLIST
,
1138 LB_DELETESTRING
, i
, 0);
1139 sprintf(str
, "%d\t(0x%02X)\t%c\t%d", i
, i
,
1140 (i
>=0x21 && i
!= 0x7F) ? i
: ' ',
1142 SendDlgItemMessage (hwnd
, IDC4_CCLIST
,
1152 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
1155 static int CALLBACK
ColourProc (HWND hwnd
, UINT msg
,
1156 WPARAM wParam
, LPARAM lParam
) {
1157 static const char *const colours
[] = {
1158 "Default Foreground", "Default Bold Foreground",
1159 "Default Background", "Default Bold Background",
1160 "Cursor Text", "Cursor Colour",
1161 "ANSI Black", "ANSI Black Bold",
1162 "ANSI Red", "ANSI Red Bold",
1163 "ANSI Green", "ANSI Green Bold",
1164 "ANSI Yellow", "ANSI Yellow Bold",
1165 "ANSI Blue", "ANSI Blue Bold",
1166 "ANSI Magenta", "ANSI Magenta Bold",
1167 "ANSI Cyan", "ANSI Cyan Bold",
1168 "ANSI White", "ANSI White Bold"
1170 static const int permanent
[] = {
1171 TRUE
, FALSE
, TRUE
, FALSE
, TRUE
, TRUE
,
1172 TRUE
, FALSE
, TRUE
, FALSE
, TRUE
, FALSE
, TRUE
, FALSE
,
1173 TRUE
, FALSE
, TRUE
, FALSE
, TRUE
, FALSE
, TRUE
, FALSE
1177 CheckDlgButton (hwnd
, IDC5_BOLDCOLOUR
, cfg
.bold_colour
);
1178 CheckDlgButton (hwnd
, IDC5_PALETTE
, cfg
.try_palette
);
1181 for (i
=0; i
<22; i
++)
1182 if (cfg
.bold_colour
|| permanent
[i
])
1183 SendDlgItemMessage (hwnd
, IDC5_LIST
, LB_ADDSTRING
, 0,
1184 (LPARAM
) colours
[i
]);
1186 SendDlgItemMessage (hwnd
, IDC5_LIST
, LB_SETCURSEL
, 0, 0);
1187 SetDlgItemInt (hwnd
, IDC5_RVALUE
, cfg
.colours
[0][0], FALSE
);
1188 SetDlgItemInt (hwnd
, IDC5_GVALUE
, cfg
.colours
[0][1], FALSE
);
1189 SetDlgItemInt (hwnd
, IDC5_BVALUE
, cfg
.colours
[0][2], FALSE
);
1192 switch (LOWORD(wParam
)) {
1193 case IDC5_BOLDCOLOUR
:
1194 if (HIWORD(wParam
) == BN_CLICKED
||
1195 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
1197 cfg
.bold_colour
= IsDlgButtonChecked (hwnd
, IDC5_BOLDCOLOUR
);
1198 n
= SendDlgItemMessage (hwnd
, IDC5_LIST
, LB_GETCOUNT
, 0, 0);
1199 if (cfg
.bold_colour
&& n
!=22) {
1200 for (i
=0; i
<22; i
++)
1202 SendDlgItemMessage (hwnd
, IDC5_LIST
,
1204 (LPARAM
) colours
[i
]);
1205 } else if (!cfg
.bold_colour
&& n
!=12) {
1208 SendDlgItemMessage (hwnd
, IDC5_LIST
,
1209 LB_DELETESTRING
, i
, 0);
1214 if (HIWORD(wParam
) == BN_CLICKED
||
1215 HIWORD(wParam
) == BN_DOUBLECLICKED
)
1216 cfg
.try_palette
= IsDlgButtonChecked (hwnd
, IDC5_PALETTE
);
1219 if (HIWORD(wParam
) == LBN_DBLCLK
||
1220 HIWORD(wParam
) == LBN_SELCHANGE
) {
1221 int i
= SendDlgItemMessage (hwnd
, IDC5_LIST
, LB_GETCURSEL
,
1223 if (!cfg
.bold_colour
)
1224 i
= (i
< 3 ? i
*2 : i
== 3 ?
5 : i
*2-2);
1225 SetDlgItemInt (hwnd
, IDC5_RVALUE
, cfg
.colours
[i
][0], FALSE
);
1226 SetDlgItemInt (hwnd
, IDC5_GVALUE
, cfg
.colours
[i
][1], FALSE
);
1227 SetDlgItemInt (hwnd
, IDC5_BVALUE
, cfg
.colours
[i
][2], FALSE
);
1231 if (HIWORD(wParam
) == BN_CLICKED
||
1232 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
1233 static CHOOSECOLOR cc
;
1234 static DWORD custom
[16] = {0}; /* zero initialisers */
1235 int i
= SendDlgItemMessage (hwnd
, IDC5_LIST
, LB_GETCURSEL
,
1237 if (!cfg
.bold_colour
)
1238 i
= (i
< 3 ? i
*2 : i
== 3 ?
5 : i
*2-2);
1239 cc
.lStructSize
= sizeof(cc
);
1240 cc
.hwndOwner
= hwnd
;
1241 cc
.hInstance
= (HWND
)hinst
;
1242 cc
.lpCustColors
= custom
;
1243 cc
.rgbResult
= RGB (cfg
.colours
[i
][0], cfg
.colours
[i
][1],
1245 cc
.Flags
= CC_FULLOPEN
| CC_RGBINIT
;
1246 if (ChooseColor(&cc
)) {
1248 (unsigned char) (cc
.rgbResult
& 0xFF);
1250 (unsigned char) (cc
.rgbResult
>> 8) & 0xFF;
1252 (unsigned char) (cc
.rgbResult
>> 16) & 0xFF;
1253 SetDlgItemInt (hwnd
, IDC5_RVALUE
, cfg
.colours
[i
][0],
1255 SetDlgItemInt (hwnd
, IDC5_GVALUE
, cfg
.colours
[i
][1],
1257 SetDlgItemInt (hwnd
, IDC5_BVALUE
, cfg
.colours
[i
][2],
1265 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
1268 static int CALLBACK
TranslationProc (HWND hwnd
, UINT msg
,
1269 WPARAM wParam
, LPARAM lParam
) {
1272 CheckRadioButton (hwnd
, IDC6_NOXLAT
, IDC6_88592WIN1250
,
1273 cfg
.xlat_88592w1250 ? IDC6_88592WIN1250
:
1274 cfg
.xlat_enablekoiwin ? IDC6_KOI8WIN1251
:
1276 CheckDlgButton (hwnd
, IDC6_CAPSLOCKCYR
, cfg
.xlat_capslockcyr
);
1277 CheckRadioButton (hwnd
, IDC2_VTXWINDOWS
, IDC2_VTPOORMAN
,
1278 cfg
.vtmode
== VT_XWINDOWS ? IDC2_VTXWINDOWS
:
1279 cfg
.vtmode
== VT_OEMANSI ? IDC2_VTOEMANSI
:
1280 cfg
.vtmode
== VT_OEMONLY ? IDC2_VTOEMONLY
:
1283 switch (LOWORD(wParam
)) {
1285 case IDC6_KOI8WIN1251
:
1286 case IDC6_88592WIN1250
:
1287 cfg
.xlat_enablekoiwin
=
1288 IsDlgButtonChecked (hwnd
, IDC6_KOI8WIN1251
);
1289 cfg
.xlat_88592w1250
=
1290 IsDlgButtonChecked (hwnd
, IDC6_88592WIN1250
);
1292 case IDC6_CAPSLOCKCYR
:
1293 if (HIWORD(wParam
) == BN_CLICKED
||
1294 HIWORD(wParam
) == BN_DOUBLECLICKED
) {
1295 cfg
.xlat_capslockcyr
=
1296 IsDlgButtonChecked (hwnd
, IDC6_CAPSLOCKCYR
);
1299 case IDC2_VTXWINDOWS
:
1300 case IDC2_VTOEMANSI
:
1301 case IDC2_VTOEMONLY
:
1302 case IDC2_VTPOORMAN
:
1304 (IsDlgButtonChecked (hwnd
, IDC2_VTXWINDOWS
) ? VT_XWINDOWS
:
1305 IsDlgButtonChecked (hwnd
, IDC2_VTOEMANSI
) ? VT_OEMANSI
:
1306 IsDlgButtonChecked (hwnd
, IDC2_VTOEMONLY
) ? VT_OEMONLY
:
1311 return GeneralPanelProc (hwnd
, msg
, wParam
, lParam
);
1314 static DLGPROC panelproc
[NPANELS
] = {
1315 ConnectionProc
, KeyboardProc
, TerminalProc
, WindowProc
,
1316 TelnetProc
, SshProc
, SelectionProc
, ColourProc
, TranslationProc
1318 static char *panelids
[NPANELS
] = {
1319 MAKEINTRESOURCE(IDD_PANEL0
),
1320 MAKEINTRESOURCE(IDD_PANEL1
),
1321 MAKEINTRESOURCE(IDD_PANEL2
),
1322 MAKEINTRESOURCE(IDD_PANELW
),
1323 MAKEINTRESOURCE(IDD_PANEL3
),
1324 MAKEINTRESOURCE(IDD_PANEL35
),
1325 MAKEINTRESOURCE(IDD_PANEL4
),
1326 MAKEINTRESOURCE(IDD_PANEL5
),
1327 MAKEINTRESOURCE(IDD_PANEL6
)
1330 static char *names
[NPANELS
] = {
1331 "Connection", "Keyboard", "Terminal", "Window", "Telnet",
1332 "SSH", "Selection", "Colours", "Translation"
1335 static int mainp
[MAIN_NPANELS
] = { 0, 1, 2, 3, 4, 5, 6, 7, 8};
1336 static int reconfp
[RECONF_NPANELS
] = { 1, 2, 3, 6, 7, 8};
1338 static int GenericMainDlgProc (HWND hwnd
, UINT msg
,
1339 WPARAM wParam
, LPARAM lParam
,
1340 int npanels
, int *panelnums
, HWND
*page
) {
1345 { /* centre the window */
1348 hw
= GetDesktopWindow();
1349 if (GetWindowRect (hw
, &rs
) && GetWindowRect (hwnd
, &rd
))
1350 MoveWindow (hwnd
, (rs
.right
+ rs
.left
+ rd
.left
- rd
.right
)/2,
1351 (rs
.bottom
+ rs
.top
+ rd
.top
- rd
.bottom
)/2,
1352 rd
.right
-rd
.left
, rd
.bottom
-rd
.top
, TRUE
);
1355 { /* initialise the tab control */
1359 hw
= GetDlgItem (hwnd
, IDC_TAB
);
1360 for (i
=0; i
<npanels
; i
++) {
1361 tab
.mask
= TCIF_TEXT
;
1362 tab
.pszText
= names
[panelnums
[i
]];
1363 TabCtrl_InsertItem (hw
, i
, &tab
);
1365 /* *page = CreateDialogIndirect (hinst, panels[panelnums[0]].temp,
1366 hwnd, panelproc[panelnums[0]]);*/
1367 *page
= CreateDialog (hinst
, panelids
[panelnums
[0]],
1368 hwnd
, panelproc
[panelnums
[0]]);
1369 SetWindowLong (*page
, GWL_EXSTYLE
,
1370 GetWindowLong (*page
, GWL_EXSTYLE
) |
1371 WS_EX_CONTROLPARENT
);
1376 if (LOWORD(wParam
) == IDC_TAB
&&
1377 ((LPNMHDR
)lParam
)->code
== TCN_SELCHANGE
) {
1378 int i
= TabCtrl_GetCurSel(((LPNMHDR
)lParam
)->hwndFrom
);
1380 DestroyWindow (*page
);
1381 /* *page = CreateDialogIndirect (hinst, panels[panelnums[i]].temp,
1382 hwnd, panelproc[panelnums[i]]);*/
1383 *page
= CreateDialog (hinst
, panelids
[panelnums
[i
]],
1384 hwnd
, panelproc
[panelnums
[i
]]);
1385 SetWindowLong (*page
, GWL_EXSTYLE
,
1386 GetWindowLong (*page
, GWL_EXSTYLE
) |
1387 WS_EX_CONTROLPARENT
);
1388 SetFocus (((LPNMHDR
)lParam
)->hwndFrom
); /* ensure focus stays */
1392 /* case WM_CTLCOLORDLG: */
1393 /* return (int) GetStockObject (LTGRAY_BRUSH); */
1395 switch (LOWORD(wParam
)) {
1398 EndDialog (hwnd
, 1);
1403 EndDialog (hwnd
, 0);
1408 EndDialog (hwnd
, 0);
1411 /* Grrr Explorer will maximize Dialogs! */
1413 if (wParam
== SIZE_MAXIMIZED
)
1420 static int CALLBACK
MainDlgProc (HWND hwnd
, UINT msg
,
1421 WPARAM wParam
, LPARAM lParam
) {
1426 static HWND page
= NULL
;
1428 if (msg
== WM_COMMAND
&& LOWORD(wParam
) == IDOK
) {
1431 * If the Connection panel is active and the Session List
1432 * box is selected, we treat a press of Open to have an
1433 * implicit press of Load preceding it.
1435 hw
= GetDlgItem (hwnd
, IDC_TAB
);
1436 i
= TabCtrl_GetCurSel(hw
);
1437 if (panelproc
[mainp
[i
]] == ConnectionProc
&&
1438 page
&& implicit_load_ok
) {
1439 SendMessage (page
, WM_COMMAND
,
1440 MAKELONG(IDC0_SESSLOAD
, BN_CLICKED
), 0);
1444 if (msg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_ABOUT
) {
1445 EnableWindow(hwnd
, 0);
1446 DialogBox(hinst
, MAKEINTRESOURCE(IDD_ABOUTBOX
),
1447 GetParent(hwnd
), AboutProc
);
1448 EnableWindow(hwnd
, 1);
1449 SetActiveWindow(hwnd
);
1451 return GenericMainDlgProc (hwnd
, msg
, wParam
, lParam
,
1452 MAIN_NPANELS
, mainp
, &page
);
1455 static int CALLBACK
ReconfDlgProc (HWND hwnd
, UINT msg
,
1456 WPARAM wParam
, LPARAM lParam
) {
1458 return GenericMainDlgProc (hwnd
, msg
, wParam
, lParam
,
1459 RECONF_NPANELS
, reconfp
, &page
);
1462 void get_sesslist(int allocate
) {
1463 static char otherbuf
[2048];
1464 static char *buffer
;
1465 int buflen
, bufsize
, i
;
1471 if ((handle
= enum_settings_start()) == NULL
)
1474 buflen
= bufsize
= 0;
1477 ret
= enum_settings_next(handle
, otherbuf
, sizeof(otherbuf
));
1479 int len
= strlen(otherbuf
)+1;
1480 if (bufsize
< buflen
+len
) {
1481 bufsize
= buflen
+ len
+ 2048;
1482 buffer
= srealloc(buffer
, bufsize
);
1484 strcpy(buffer
+buflen
, otherbuf
);
1485 buflen
+= strlen(buffer
+buflen
)+1;
1488 enum_settings_finish(handle
);
1489 buffer
= srealloc(buffer
, buflen
+1);
1490 buffer
[buflen
] = '\0';
1493 nsessions
= 1; /* "Default Settings" counts as one */
1495 if (strcmp(p
, "Default Settings"))
1501 sessions
= smalloc(nsessions
* sizeof(char *));
1502 sessions
[0] = "Default Settings";
1506 if (strcmp(p
, "Default Settings"))
1517 int do_config (void) {
1521 savedsession
[0] = '\0';
1522 ret
= DialogBox (hinst
, MAKEINTRESOURCE(IDD_MAINBOX
), NULL
, MainDlgProc
);
1523 get_sesslist(FALSE
);
1528 int do_reconfig (HWND hwnd
) {
1532 backup_cfg
= cfg
; /* structure copy */
1533 ret
= DialogBox (hinst
, MAKEINTRESOURCE(IDD_RECONF
), hwnd
, ReconfDlgProc
);
1535 cfg
= backup_cfg
; /* structure copy */
1542 void do_defaults (char *session
) {
1544 load_settings (session
, TRUE
);
1546 load_settings ("Default Settings", FALSE
);
1549 void logevent (char *string
) {
1550 if (nevents
>= negsize
) {
1552 events
= srealloc (events
, negsize
* sizeof(*events
));
1554 events
[nevents
] = smalloc(1+strlen(string
));
1555 strcpy (events
[nevents
], string
);
1559 SendDlgItemMessage (logbox
, IDN_LIST
, LB_ADDSTRING
,
1561 count
= SendDlgItemMessage (logbox
, IDN_LIST
, LB_GETCOUNT
, 0, 0);
1562 SendDlgItemMessage (logbox
, IDN_LIST
, LB_SETTOPINDEX
, count
-1, 0);
1566 void showeventlog (HWND hwnd
) {
1568 logbox
= CreateDialog (hinst
, MAKEINTRESOURCE(IDD_LOGBOX
),
1570 ShowWindow (logbox
, SW_SHOWNORMAL
);
1574 void showabout (HWND hwnd
) {
1576 abtbox
= CreateDialog (hinst
, MAKEINTRESOURCE(IDD_ABOUTBOX
),
1578 ShowWindow (abtbox
, SW_SHOWNORMAL
);
1582 void verify_ssh_host_key(char *host
, int port
, char *keytype
,
1583 char *keystr
, char *fingerprint
) {
1586 static const char absentmsg
[] =
1587 "The server's host key is not cached in the registry. You\n"
1588 "have no guarantee that the server is the computer you\n"
1590 "The server's key fingerprint is:\n"
1592 "If you trust this host, hit Yes to add the key to\n"
1593 "PuTTY's cache and carry on connecting.\n"
1594 "If you do not trust this host, hit No to abandon the\n"
1597 static const char wrongmsg
[] =
1598 "WARNING - POTENTIAL SECURITY BREACH!\n"
1600 "The server's host key does not match the one PuTTY has\n"
1601 "cached in the registry. This means that either the\n"
1602 "server administrator has changed the host key, or you\n"
1603 "have actually connected to another computer pretending\n"
1604 "to be the server.\n"
1605 "The new key fingerprint is:\n"
1607 "If you were expecting this change and trust the new key,\n"
1608 "hit Yes to update PuTTY's cache and continue connecting.\n"
1609 "If you want to carry on connecting but without updating\n"
1610 "the cache, hit No.\n"
1611 "If you want to abandon the connection completely, hit\n"
1612 "Cancel. Hitting Cancel is the ONLY guaranteed safe\n"
1615 static const char mbtitle
[] = "PuTTY Security Alert";
1618 char message
[160+ /* sensible fingerprint max size */
1619 (sizeof(absentmsg
) > sizeof(wrongmsg
) ?
1620 sizeof(absentmsg
) : sizeof(wrongmsg
))];
1623 * Verify the key against the registry.
1625 ret
= verify_host_key(host
, port
, keytype
, keystr
);
1627 if (ret
== 0) /* success - key matched OK */
1629 if (ret
== 2) { /* key was different */
1631 sprintf(message
, wrongmsg
, fingerprint
);
1632 mbret
= MessageBox(NULL
, message
, mbtitle
,
1633 MB_ICONWARNING
| MB_YESNOCANCEL
);
1635 store_host_key(host
, port
, keytype
, keystr
);
1636 if (mbret
== IDCANCEL
)
1639 if (ret
== 1) { /* key was absent */
1641 sprintf(message
, absentmsg
, fingerprint
);
1642 mbret
= MessageBox(NULL
, message
, mbtitle
,
1643 MB_ICONWARNING
| MB_YESNO
);
1646 store_host_key(host
, port
, keytype
, keystr
);