X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=windows%2Fwindlg.c;h=826876e3cbd30bc713ae02b106187b2d65afe4a4;hb=2eb952ca31aa13d1f6f429305fbb6f43a9a28c56;hp=019f6155c177a87dbe8bea08ebe9cd9f84b15895;hpb=4da1f2b17e816a76685ff91af642b9a0b2b82c98;p=PuTTY.git diff --git a/windows/windlg.c b/windows/windlg.c index 019f6155..826876e3 100644 --- a/windows/windlg.c +++ b/windows/windlg.c @@ -1,3 +1,7 @@ +/* + * windlg.c - dialogs for PuTTY(tel), including the configuration dialog. + */ + #include #include #include @@ -40,7 +44,7 @@ static struct dlgparam dp; static char **events = NULL; static int nevents = 0, negsize = 0; -extern Config cfg; /* defined in window.c */ +extern Conf *conf; /* defined in window.c */ #define PRINTER_DISABLED_STRING "None (printing disabled)" @@ -166,6 +170,37 @@ static int CALLBACK LicenceProc(HWND hwnd, UINT msg, char *str = dupprintf("%s Licence", appname); SetWindowText(hwnd, str); sfree(str); + + SetDlgItemText(hwnd, IDA_TEXT, + "Copyright 1997-2015 Simon Tatham.\r\n\r\n" + + "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " + "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " + "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, " + "Markus Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.\r\n\r\n" + + "Permission is hereby granted, free of charge, to any person " + "obtaining a copy of this software and associated documentation " + "files (the ""Software""), to deal in the Software without restriction, " + "including without limitation the rights to use, copy, modify, merge, " + "publish, distribute, sublicense, and/or sell copies of the Software, " + "and to permit persons to whom the Software is furnished to do so, " + "subject to the following conditions:\r\n\r\n" + + "The above copyright notice and this permission notice shall be " + "included in all copies or substantial portions of the Software.\r\n\r\n" + + "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT " + "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, " + "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " + "MERCHANTABILITY, FITNESS FOR A PARTICULAR " + "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " + "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES " + "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " + "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " + "CONNECTION WITH THE SOFTWARE OR THE USE OR " + "OTHER DEALINGS IN THE SOFTWARE." +); } return 1; case WM_COMMAND: @@ -193,8 +228,14 @@ static int CALLBACK AboutProc(HWND hwnd, UINT msg, str = dupprintf("About %s", appname); SetWindowText(hwnd, str); sfree(str); - SetDlgItemText(hwnd, IDA_TEXT1, appname); - SetDlgItemText(hwnd, IDA_VERSION, ver); + { + char *text = dupprintf + ("%s\r\n\r\n%s\r\n\r\n%s", + appname, ver, + "\251 1997-2015 Simon Tatham. All rights reserved."); + SetDlgItemText(hwnd, IDA_TEXT, text); + sfree(text); + } return 1; case WM_COMMAND: switch (LOWORD(wParam)) { @@ -318,7 +359,7 @@ static HTREEITEM treeview_insert(struct treeview_faff *faff, newitem = TreeView_InsertItem(faff->treeview, &ins); if (level > 0) TreeView_Expand(faff->treeview, faff->lastat[level - 1], - TVE_EXPAND); + (level > 1 ? TVE_COLLAPSE : TVE_EXPAND)); faff->lastat[level] = newitem; for (i = level + 1; i < 4; i++) faff->lastat[i] = NULL; @@ -376,7 +417,7 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, create_controls(hwnd, ""); /* Open and Cancel buttons etc */ SetWindowText(hwnd, dp.wintitle); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); - if (help_path) + if (has_help()) SetWindowLongPtr(hwnd, GWL_EXSTYLE, GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_CONTEXTHELP); @@ -385,7 +426,6 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, if (item) DestroyWindow(item); } - requested_help = FALSE; SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON))); /* @@ -451,6 +491,7 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, HTREEITEM hfirst = NULL; int i; char *path = NULL; + char *firstpath = NULL; for (i = 0; i < ctrlbox->nctrlsets; i++) { struct controlset *s = ctrlbox->ctrlsets[i]; @@ -483,18 +524,27 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, c++; item = treeview_insert(&tvfaff, j, c, s->pathname); - if (!hfirst) + if (!hfirst) { hfirst = item; + firstpath = s->pathname; + } path = s->pathname; } /* - * Put the treeview selection on to the Session panel. - * This should also cause creation of the relevant - * controls. + * Put the treeview selection on to the first panel in the + * ctrlbox. */ TreeView_SelectItem(treeview, hfirst); + + /* + * And create the actual control set for that panel, to + * match the initial treeview selection. + */ + assert(firstpath); /* config.c must have given us _something_ */ + create_controls(hwnd, firstpath); + dlg_refresh(NULL, &dp); /* and set up control values */ } /* @@ -513,6 +563,18 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, } } + /* + * Now we've finished creating our initial set of controls, + * it's safe to actually show the window without risking setup + * flicker. + */ + ShowWindow(hwnd, SW_SHOWNORMAL); + + /* + * Set the flag that activates a couple of the other message + * handlers below, which were disabled until now to avoid + * spurious firing during the above setup procedure. + */ SetWindowLongPtr(hwnd, GWLP_USERDATA, 1); return 0; case WM_LBUTTONUP: @@ -527,10 +589,21 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, case WM_NOTIFY: if (LOWORD(wParam) == IDCX_TREEVIEW && ((LPNMHDR) lParam)->code == TVN_SELCHANGED) { - HTREEITEM i = - TreeView_GetSelection(((LPNMHDR) lParam)->hwndFrom); + /* + * Selection-change events on the treeview cause us to do + * a flurry of control deletion and creation - but only + * after WM_INITDIALOG has finished. The initial + * selection-change event(s) during treeview setup are + * ignored. + */ + HTREEITEM i; TVITEM item; char buffer[64]; + + if (GetWindowLongPtr(hwnd, GWLP_USERDATA) != 1) + return 0; + + i = TreeView_GetSelection(((LPNMHDR) lParam)->hwndFrom); SendMessage (hwnd, WM_SETREDRAW, FALSE, 0); @@ -582,19 +655,12 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg, ret = 0; return ret; case WM_HELP: - if (help_path) { - if (winctrl_context_help(&dp, hwnd, - ((LPHELPINFO)lParam)->iCtrlId)) - requested_help = TRUE; - else - MessageBeep(0); - } + if (!winctrl_context_help(&dp, hwnd, + ((LPHELPINFO)lParam)->iCtrlId)) + MessageBeep(0); break; case WM_CLOSE: - if (requested_help) { - WinHelp(hwnd, help_path, HELP_QUIT, 0); - requested_help = FALSE; - } + quit_help(hwnd); SaneEndDialog(hwnd, 0); return 0; @@ -618,12 +684,7 @@ void modal_about_box(HWND hwnd) void show_help(HWND hwnd) { - if (help_path) { - WinHelp(hwnd, help_path, - help_has_contents ? HELP_FINDER : HELP_CONTENTS, - 0); - requested_help = TRUE; - } + launch_help(hwnd, NULL); } void defuse_showwindow(void) @@ -649,7 +710,7 @@ int do_config(void) ctrlbox = ctrl_new_box(); setup_config_box(ctrlbox, FALSE, 0, 0); - win_setup_config_box(ctrlbox, &dp.hwnd, (help_path != NULL), FALSE); + win_setup_config_box(ctrlbox, &dp.hwnd, has_help(), FALSE, 0); dp_init(&dp); winctrl_init(&ctrls_base); winctrl_init(&ctrls_panel); @@ -657,7 +718,8 @@ int do_config(void) dp_add_tree(&dp, &ctrls_panel); dp.wintitle = dupprintf("%s Configuration", appname); dp.errtitle = dupprintf("%s Error", appname); - dp.data = &cfg; + dp.data = conf; + dlg_auto_set_fixed_pitch_flag(&dp); dp.shortcuts['g'] = TRUE; /* the treeview: `Cate&gory' */ ret = @@ -674,14 +736,15 @@ int do_config(void) int do_reconfig(HWND hwnd, int protcfginfo) { - Config backup_cfg; - int ret; + Conf *backup_conf; + int ret, protocol; - backup_cfg = cfg; /* structure copy */ + backup_conf = conf_copy(conf); ctrlbox = ctrl_new_box(); - setup_config_box(ctrlbox, TRUE, cfg.protocol, protcfginfo); - win_setup_config_box(ctrlbox, &dp.hwnd, (help_path != NULL), TRUE); + protocol = conf_get_int(conf, CONF_protocol); + setup_config_box(ctrlbox, TRUE, protocol, protcfginfo); + win_setup_config_box(ctrlbox, &dp.hwnd, has_help(), TRUE, protocol); dp_init(&dp); winctrl_init(&ctrls_base); winctrl_init(&ctrls_panel); @@ -689,7 +752,8 @@ int do_reconfig(HWND hwnd, int protcfginfo) dp_add_tree(&dp, &ctrls_panel); dp.wintitle = dupprintf("%s Reconfiguration", appname); dp.errtitle = dupprintf("%s Error", appname); - dp.data = &cfg; + dp.data = conf; + dlg_auto_set_fixed_pitch_flag(&dp); dp.shortcuts['g'] = TRUE; /* the treeview: `Cate&gory' */ ret = SaneDialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL, @@ -701,7 +765,9 @@ int do_reconfig(HWND hwnd, int protcfginfo) dp_cleanup(&dp); if (!ret) - cfg = backup_cfg; /* structure copy */ + conf_copy_into(conf, backup_conf); + + conf_free(backup_conf); return ret; } @@ -749,8 +815,8 @@ void showabout(HWND hwnd) DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc); } -int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, - char *keystr, char *fingerprint, +int verify_ssh_host_key(void *frontend, char *host, int port, + const char *keytype, char *keystr, char *fingerprint, void (*callback)(void *ctx, int result), void *ctx) { int ret; @@ -794,7 +860,7 @@ int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, if (ret == 0) /* success - key matched OK */ return 1; - if (ret == 2) { /* key was different */ + else if (ret == 2) { /* key was different */ int mbret; char *text = dupprintf(wrongmsg, appname, keytype, fingerprint, appname); @@ -810,9 +876,7 @@ int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, return 1; } else if (mbret == IDNO) return 1; - return 0; - } - if (ret == 1) { /* key was absent */ + } else if (ret == 1) { /* key was absent */ int mbret; char *text = dupprintf(absentmsg, keytype, fingerprint, appname); char *caption = dupprintf(mbtitle, appname); @@ -827,8 +891,8 @@ int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, return 1; } else if (mbret == IDNO) return 1; - return 0; } + return 0; /* abandon the connection */ } /* @@ -851,6 +915,7 @@ int askalg(void *frontend, const char *algtype, const char *algname, title = dupprintf(mbtitle, appname); mbret = MessageBox(NULL, message, title, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2); + socket_reselect_all(); sfree(message); sfree(title); if (mbret == IDYES) @@ -863,7 +928,7 @@ int askalg(void *frontend, const char *algtype, const char *algname, * Ask whether to wipe a session log file before writing to it. * Returns 2 for wipe, 1 for append, 0 for cancel (don't log). */ -int askappend(void *frontend, Filename filename, +int askappend(void *frontend, Filename *filename, void (*callback)(void *ctx, int result), void *ctx) { static const char msgtemplate[] = @@ -877,12 +942,14 @@ int askappend(void *frontend, Filename filename, char *mbtitle; int mbret; - message = dupprintf(msgtemplate, FILENAME_MAX, filename.path); + message = dupprintf(msgtemplate, FILENAME_MAX, filename->path); mbtitle = dupprintf("%s Log to File", appname); mbret = MessageBox(NULL, message, mbtitle, MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON3); + socket_reselect_all(); + sfree(message); sfree(mbtitle); @@ -924,6 +991,8 @@ void old_keyfile_warning(void) MessageBox(NULL, msg, title, MB_OK); + socket_reselect_all(); + sfree(msg); sfree(title); }