X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/b4c61ce2c6c9c8e1cf02260ac993676013c12c73..8a9977e54db756281cf0d9f4a8322ce24b001a61:/unix/gtkdlg.c diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index a961ba50..b7947b52 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -22,7 +22,6 @@ #include #include "gtkcols.h" -#include "gtkpanel.h" #ifdef TESTMODE #define PUTTY_DO_GLOBALS /* actually _define_ globals */ @@ -55,6 +54,7 @@ struct uctrl { GtkWidget *menu; /* for optionmenu (==droplist) */ GtkWidget *optmenu; /* also for optionmenu */ GtkWidget *text; /* for text */ + GtkWidget *label; /* for dlg_label_change */ GtkAdjustment *adj; /* for the scrollbar in a list box */ guint textsig; }; @@ -90,6 +90,7 @@ static gboolean widget_focus(GtkWidget *widget, GdkEventFocus *event, gpointer data); static void shortcut_add(struct Shortcuts *scs, GtkWidget *labelw, int chr, int action, void *ptr); +static void shortcut_highlight(GtkWidget *label, int chr); static int listitem_single_key(GtkWidget *item, GdkEventKey *event, gpointer data); static int listitem_multi_key(GtkWidget *item, GdkEventKey *event, @@ -152,6 +153,8 @@ static void dlg_init(struct dlgparam *dp) dp->coloursel_result.ok = FALSE; dp->treeitems = NULL; dp->window = dp->cancelbutton = dp->currtreeitem = NULL; + dp->flags = 0; + dp->currfocus = NULL; } static void dlg_cleanup(struct dlgparam *dp) @@ -374,7 +377,8 @@ void dlg_listbox_addwithid(union control *ctrl, void *dlg, gtk_container_add(GTK_CONTAINER(uc->menu), menuitem); gtk_widget_show(menuitem); - gtk_object_set_data(GTK_OBJECT(menuitem), "user-data", (gpointer)id); + gtk_object_set_data(GTK_OBJECT(menuitem), "user-data", + GINT_TO_POINTER(id)); gtk_signal_connect(GTK_OBJECT(menuitem), "activate", GTK_SIGNAL_FUNC(menuitem_activate), dp); } else if (!uc->entry) { @@ -436,7 +440,8 @@ void dlg_listbox_addwithid(union control *ctrl, void *dlg, GTK_SIGNAL_FUNC(widget_focus), dp); gtk_signal_connect(GTK_OBJECT(listitem), "button_press_event", GTK_SIGNAL_FUNC(listitem_button), dp); - gtk_object_set_data(GTK_OBJECT(listitem), "user-data", (gpointer)id); + gtk_object_set_data(GTK_OBJECT(listitem), "user-data", + GINT_TO_POINTER(id)); } else { /* * List item in a combo-box list, which means the sensible @@ -448,7 +453,8 @@ void dlg_listbox_addwithid(union control *ctrl, void *dlg, gtk_container_add(GTK_CONTAINER(uc->list), listitem); gtk_widget_show(listitem); - gtk_object_set_data(GTK_OBJECT(listitem), "user-data", (gpointer)id); + gtk_object_set_data(GTK_OBJECT(listitem), "user-data", + GINT_TO_POINTER(id)); } dp->flags &= ~FLAG_UPDATING_COMBO_LIST; @@ -470,7 +476,7 @@ int dlg_listbox_getid(union control *ctrl, void *dlg, int index) item = GTK_OBJECT(g_list_nth_data(children, index)); g_list_free(children); - return (int)gtk_object_get_data(GTK_OBJECT(item), "user-data"); + return GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(item), "user-data")); } /* dlg_listbox_index returns <0 if no single element is selected. */ @@ -489,6 +495,8 @@ int dlg_listbox_index(union control *ctrl, void *dlg) if (uc->menu) activeitem = gtk_menu_get_active(GTK_MENU(uc->menu)); + else + activeitem = NULL; /* unnecessarily placate gcc */ children = gtk_container_children(GTK_CONTAINER(uc->menu ? uc->menu : uc->list)); @@ -542,7 +550,35 @@ void dlg_listbox_select(union control *ctrl, void *dlg, int index) if (uc->optmenu) { gtk_option_menu_set_history(GTK_OPTION_MENU(uc->optmenu), index); } else { + int nitems; + GList *items; + gdouble newtop, newbot; + gtk_list_select_item(GTK_LIST(uc->list), index); + + /* + * Scroll the list box if necessary to ensure the newly + * selected item is visible. + */ + items = gtk_container_children(GTK_CONTAINER(uc->list)); + nitems = g_list_length(items); + if (nitems > 0) { + int modified = FALSE; + g_list_free(items); + newtop = uc->adj->lower + + (uc->adj->upper - uc->adj->lower) * index / nitems; + newbot = uc->adj->lower + + (uc->adj->upper - uc->adj->lower) * (index+1) / nitems; + if (uc->adj->value > newtop) { + modified = TRUE; + uc->adj->value = newtop; + } else if (uc->adj->value < newbot - uc->adj->page_size) { + modified = TRUE; + uc->adj->value = newbot - uc->adj->page_size; + } + if (modified) + gtk_adjustment_value_changed(uc->adj); + } } } @@ -557,6 +593,46 @@ void dlg_text_set(union control *ctrl, void *dlg, char const *text) gtk_label_set_text(GTK_LABEL(uc->text), text); } +void dlg_label_change(union control *ctrl, void *dlg, char const *text) +{ + struct dlgparam *dp = (struct dlgparam *)dlg; + struct uctrl *uc = dlg_find_byctrl(dp, ctrl); + + switch (uc->ctrl->generic.type) { + case CTRL_BUTTON: + gtk_label_set_text(GTK_LABEL(uc->toplevel), text); + shortcut_highlight(uc->toplevel, ctrl->button.shortcut); + break; + case CTRL_CHECKBOX: + gtk_label_set_text(GTK_LABEL(uc->toplevel), text); + shortcut_highlight(uc->toplevel, ctrl->checkbox.shortcut); + break; + case CTRL_RADIO: + gtk_label_set_text(GTK_LABEL(uc->label), text); + shortcut_highlight(uc->label, ctrl->radio.shortcut); + break; + case CTRL_EDITBOX: + gtk_label_set_text(GTK_LABEL(uc->label), text); + shortcut_highlight(uc->label, ctrl->editbox.shortcut); + break; + case CTRL_FILESELECT: + gtk_label_set_text(GTK_LABEL(uc->label), text); + shortcut_highlight(uc->label, ctrl->fileselect.shortcut); + break; + case CTRL_FONTSELECT: + gtk_label_set_text(GTK_LABEL(uc->label), text); + shortcut_highlight(uc->label, ctrl->fontselect.shortcut); + break; + case CTRL_LISTBOX: + gtk_label_set_text(GTK_LABEL(uc->label), text); + shortcut_highlight(uc->label, ctrl->listbox.shortcut); + break; + default: + assert(!"This shouldn't happen"); + break; + } +} + void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn) { struct dlgparam *dp = (struct dlgparam *)dlg; @@ -1290,6 +1366,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, uc->buttons = NULL; uc->entry = uc->list = uc->menu = NULL; uc->button = uc->optmenu = uc->text = NULL; + uc->label = NULL; switch (ctrl->generic.type) { case CTRL_BUTTON: @@ -1335,6 +1412,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, gtk_widget_show(label); shortcut_add(scs, label, ctrl->radio.shortcut, SHORTCUT_UCTRL, uc); + uc->label = label; } percentages = g_new(gint, ctrl->radio.ncolumns); for (i = 0; i < ctrl->radio.ncolumns; i++) { @@ -1439,6 +1517,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, gtk_widget_show(w); w = container; + uc->label = label; } gtk_signal_connect(GTK_OBJECT(uc->entry), "focus_out_event", GTK_SIGNAL_FUNC(editbox_lostfocus), dp); @@ -1467,6 +1546,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, ctrl->fileselect.shortcut : ctrl->fontselect.shortcut), SHORTCUT_UCTRL, uc); + uc->label = ww; } uc->entry = ww = gtk_entry_new(); @@ -1604,6 +1684,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, shortcut_add(scs, label, ctrl->listbox.shortcut, SHORTCUT_UCTRL, uc); w = container; + uc->label = label; } break; case CTRL_TEXT: @@ -1659,7 +1740,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, struct selparam { struct dlgparam *dp; - Panels *panels; + GtkNotebook *panels; GtkWidget *panel, *treeitem; struct Shortcuts shortcuts; }; @@ -1667,8 +1748,12 @@ struct selparam { static void treeitem_sel(GtkItem *item, gpointer data) { struct selparam *sp = (struct selparam *)data; + gint page_num; + + page_num = gtk_notebook_page_num(sp->panels, sp->panel); + gtk_notebook_set_page(sp->panels, page_num); - panels_switch_to(sp->panels, sp->panel); + dlg_refresh(NULL, sp->dp); sp->dp->shortcuts = &sp->shortcuts; sp->dp->currtreeitem = sp->treeitem; @@ -1889,13 +1974,31 @@ int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data) return FALSE; } -void shortcut_add(struct Shortcuts *scs, GtkWidget *labelw, - int chr, int action, void *ptr) +static void shortcut_highlight(GtkWidget *labelw, int chr) { GtkLabel *label = GTK_LABEL(labelw); gchar *currstr, *pattern; int i; + gtk_label_get(label, &currstr); + for (i = 0; currstr[i]; i++) + if (tolower((unsigned char)currstr[i]) == chr) { + GtkRequisition req; + + pattern = dupprintf("%*s_", i, ""); + + gtk_widget_size_request(GTK_WIDGET(label), &req); + gtk_label_set_pattern(label, pattern); + gtk_widget_set_usize(GTK_WIDGET(label), -1, req.height); + + sfree(pattern); + break; + } +} + +void shortcut_add(struct Shortcuts *scs, GtkWidget *labelw, + int chr, int action, void *ptr) +{ if (chr == NO_SHORTCUT) return; @@ -1913,20 +2016,7 @@ void shortcut_add(struct Shortcuts *scs, GtkWidget *labelw, scs->sc[chr].uc = (struct uctrl *)ptr; } - gtk_label_get(label, &currstr); - for (i = 0; currstr[i]; i++) - if (tolower((unsigned char)currstr[i]) == chr) { - GtkRequisition req; - - pattern = dupprintf("%*s_", i, ""); - - gtk_widget_size_request(GTK_WIDGET(label), &req); - gtk_label_set_pattern(label, pattern); - gtk_widget_set_usize(GTK_WIDGET(label), -1, req.height); - - sfree(pattern); - break; - } + shortcut_highlight(labelw, chr); } int get_listitemheight(void) @@ -1938,7 +2028,8 @@ int get_listitemheight(void) return req.height; } -int do_config_box(const char *title, Config *cfg, int midsession) +int do_config_box(const char *title, Config *cfg, int midsession, + int protcfginfo) { GtkWidget *window, *hbox, *vbox, *cols, *label, *tree, *treescroll, *panels, *panelvbox; @@ -1948,7 +2039,6 @@ int do_config_box(const char *title, Config *cfg, int midsession) GtkTreeItem *treeitemlevels[8]; GtkTree *treelevels[8]; struct dlgparam dp; - struct sesslist sl; struct Shortcuts scs; struct selparam *selparams = NULL; @@ -1956,8 +2046,6 @@ int do_config_box(const char *title, Config *cfg, int midsession) dlg_init(&dp); - get_sesslist(&sl, TRUE); - listitemheight = get_listitemheight(); for (index = 0; index < lenof(scs.sc); index++) { @@ -1967,8 +2055,9 @@ int do_config_box(const char *title, Config *cfg, int midsession) window = gtk_dialog_new(); ctrlbox = ctrl_new_box(); - setup_config_box(ctrlbox, &sl, midsession, 0); - unix_setup_config_box(ctrlbox, midsession, window); + setup_config_box(ctrlbox, midsession, cfg->protocol, protcfginfo); + unix_setup_config_box(ctrlbox, midsession, cfg->protocol); + gtk_setup_config_box(ctrlbox, midsession, window); gtk_window_set_title(GTK_WINDOW(window), title); hbox = gtk_hbox_new(FALSE, 4); @@ -2002,7 +2091,9 @@ int do_config_box(const char *title, Config *cfg, int midsession) gtk_widget_show(tree); gtk_widget_show(treescroll); gtk_box_pack_start(GTK_BOX(vbox), treescroll, TRUE, TRUE, 0); - panels = panels_new(); + panels = gtk_notebook_new(); + gtk_notebook_set_show_tabs(GTK_NOTEBOOK(panels), FALSE); + gtk_notebook_set_show_border(GTK_NOTEBOOK(panels), FALSE); gtk_box_pack_start(GTK_BOX(hbox), panels, TRUE, TRUE, 0); gtk_widget_show(panels); @@ -2072,9 +2163,15 @@ int do_config_box(const char *title, Config *cfg, int midsession) first = (panelvbox == NULL); panelvbox = gtk_vbox_new(FALSE, 4); - gtk_container_add(GTK_CONTAINER(panels), panelvbox); + gtk_widget_show(panelvbox); + gtk_notebook_append_page(GTK_NOTEBOOK(panels), panelvbox, + NULL); if (first) { - panels_switch_to(PANELS(panels), panelvbox); + gint page_num; + + page_num = gtk_notebook_page_num(GTK_NOTEBOOK(panels), + panelvbox); + gtk_notebook_set_page(GTK_NOTEBOOK(panels), page_num); gtk_tree_select_child(GTK_TREE(tree), treeitem); } @@ -2084,7 +2181,7 @@ int do_config_box(const char *title, Config *cfg, int midsession) struct selparam); } selparams[nselparams].dp = &dp; - selparams[nselparams].panels = PANELS(panels); + selparams[nselparams].panels = GTK_NOTEBOOK(panels); selparams[nselparams].panel = panelvbox; selparams[nselparams].shortcuts = scs; /* structure copy */ selparams[nselparams].treeitem = treeitem; @@ -2152,7 +2249,6 @@ int do_config_box(const char *title, Config *cfg, int midsession) gtk_main(); - get_sesslist(&sl, FALSE); dlg_cleanup(&dp); sfree(selparams); @@ -2285,13 +2381,14 @@ int reallyclose(void *frontend) return ret; } -void 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, char *keytype, + char *keystr, char *fingerprint, + void (*callback)(void *ctx, int result), void *ctx) { static const char absenttxt[] = "The server's host key is not cached. You have no guarantee " "that the server is the computer you think it is.\n" - "The server's key fingerprint is:\n" + "The server's %s key fingerprint is:\n" "%s\n" "If you trust this host, press \"Accept\" to add the key to " "PuTTY's cache and carry on connecting.\n" @@ -2305,7 +2402,7 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, "cached. This means that either the server administrator " "has changed the host key, or you have actually connected " "to another computer pretending to be the server.\n" - "The new key fingerprint is:\n" + "The new %s key fingerprint is:\n" "%s\n" "If you were expecting this change and trust the new key, " "press \"Accept\" to update PuTTY's cache and continue connecting.\n" @@ -2323,9 +2420,9 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, ret = verify_host_key(host, port, keytype, keystr); if (ret == 0) /* success - key matched OK */ - return; + return 1; - text = dupprintf((ret == 2 ? wrongtxt : absenttxt), fingerprint); + text = dupprintf((ret == 2 ? wrongtxt : absenttxt), keytype, fingerprint); ret = messagebox(GTK_WIDGET(get_window(frontend)), "PuTTY Security Alert", text, @@ -2337,29 +2434,29 @@ void verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, sfree(text); - if (ret == 0) - cleanup_exit(0); - else if (ret == 2) + if (ret == 2) { store_host_key(host, port, keytype, keystr); + return 1; /* continue with connection */ + } else if (ret == 1) + return 1; /* continue with connection */ + return 0; /* do not continue with connection */ } /* - * Ask whether the selected cipher is acceptable (since it was + * Ask whether the selected algorithm is acceptable (since it was * below the configured 'warn' threshold). - * cs: 0 = both ways, 1 = client->server, 2 = server->client */ -void askcipher(void *frontend, char *ciphername, int cs) +int askalg(void *frontend, const char *algtype, const char *algname, + void (*callback)(void *ctx, int result), void *ctx) { static const char msg[] = - "The first %scipher supported by the server is " + "The first %s supported by the server is " "%s, which is below the configured warning threshold.\n" "Continue with connection?"; char *text; int ret; - text = dupprintf(msg, (cs == 0) ? "" : - (cs == 1) ? "client-to-server " : "server-to-client ", - ciphername); + text = dupprintf(msg, algtype, algname); ret = messagebox(GTK_WIDGET(get_window(frontend)), "PuTTY Security Alert", text, string_width("Continue with connection?"), @@ -2369,9 +2466,9 @@ void askcipher(void *frontend, char *ciphername, int cs) sfree(text); if (ret) { - return; + return 1; } else { - cleanup_exit(0); + return 0; } } @@ -2414,11 +2511,12 @@ static void licence_clicked(GtkButton *button, gpointer data) char *title; char *licence = - "Copyright 1997-2003 Simon Tatham.\n\n" + "Copyright 1997-2006 Simon Tatham.\n\n" "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " - "Barry, Justin Bradford, Ben Harris, and CORE SDI S.A.\n\n" + "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, " + "Markus Kuhn, and CORE SDI S.A.\n\n" "Permission is hereby granted, free of charge, to any person " "obtaining a copy of this software and associated documentation " @@ -2494,7 +2592,7 @@ void about_box(void *window) w, FALSE, FALSE, 5); gtk_widget_show(w); - w = gtk_label_new("Copyright 1997-2003 Simon Tatham. All rights reserved"); + w = gtk_label_new("Copyright 1997-2006 Simon Tatham. All rights reserved"); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox), w, FALSE, FALSE, 5); gtk_widget_show(w); @@ -2598,7 +2696,7 @@ void eventlog_selection_get(GtkWidget *widget, GtkSelectionData *seldata, struct eventlog_stuff *es = (struct eventlog_stuff *)data; gtk_selection_data_set(seldata, seldata->target, 8, - es->seldata, es->sellen); + (unsigned char *)es->seldata, es->sellen); } gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata, @@ -2718,21 +2816,20 @@ void *eventlogstuff_new(void) return es; } -void logevent_dlg(void *estuff, char *string) +void logevent_dlg(void *estuff, const char *string) { struct eventlog_stuff *es = (struct eventlog_stuff *)estuff; char timebuf[40]; - time_t t; + struct tm tm; if (es->nevents >= es->negsize) { es->negsize += 64; es->events = sresize(es->events, es->negsize, char *); } - time(&t); - strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", - localtime(&t)); + tm=ltime(); + strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", &tm); es->events[es->nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char); strcpy(es->events[es->nevents], timebuf); @@ -2743,7 +2840,8 @@ void logevent_dlg(void *estuff, char *string) es->nevents++; } -int askappend(void *frontend, Filename filename) +int askappend(void *frontend, Filename filename, + void (*callback)(void *ctx, int result), void *ctx) { static const char msgtemplate[] = "The session log file \"%.*s\" already exists. "