X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/1c470c1389113262b90e172811fa4012284dad37..7bfc5fd0ba781cf9ae34393dc4765e4506ee3157:/unix/gtkdlg.c diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index b202d904..b5b75ef3 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -55,6 +55,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 +91,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, @@ -549,7 +551,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); + } } } @@ -564,6 +594,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; @@ -1297,6 +1367,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: @@ -1342,6 +1413,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++) { @@ -1446,6 +1518,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); @@ -1474,6 +1547,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(); @@ -1611,6 +1685,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: @@ -1677,6 +1752,8 @@ static void treeitem_sel(GtkItem *item, gpointer data) panels_switch_to(sp->panels, sp->panel); + dlg_refresh(NULL, sp->dp); + sp->dp->shortcuts = &sp->shortcuts; sp->dp->currtreeitem = sp->treeitem; } @@ -1896,13 +1973,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; @@ -1920,20 +2015,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) @@ -1956,7 +2038,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; @@ -1964,8 +2045,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++) { @@ -1975,8 +2054,8 @@ 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, cfg->protocol, protcfginfo); - unix_setup_config_box(ctrlbox, midsession); + 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); @@ -2161,7 +2240,6 @@ int do_config_box(const char *title, Config *cfg, int midsession, gtk_main(); - get_sesslist(&sl, FALSE); dlg_cleanup(&dp); sfree(selparams); @@ -2424,12 +2502,12 @@ static void licence_clicked(GtkButton *button, gpointer data) char *title; char *licence = - "Copyright 1997-2005 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, Malcolm Smith, Markus Kuhn, " - "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 " @@ -2505,7 +2583,7 @@ void about_box(void *window) w, FALSE, FALSE, 5); gtk_widget_show(w); - w = gtk_label_new("Copyright 1997-2005 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);