From ae802c16d8feb31f3c3600b3e2176b5d20d64da9 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 29 Mar 2008 14:21:25 +0000 Subject: [PATCH] Deal with the possibility of no valid font being selected at all during an entire run of unifontsel (because unifontsel_set_name was either not called at all, or called with a name that didn't correspond to any known font). In this situation we grey out the OK button until a valid font is selected, and we have unifontsel_get_name return NULL rather than failing an assertion if it should be called in that state. The current client code in gtkdlg.c should never encounter a NULL return, since it only calls it after the OK button is clicked, but I've stuck an assertion in there too on general principles. [originally from svn r7953] --- unix/gtkdlg.c | 1 + unix/gtkfont.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 73d734e6..7b50ac19 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -1226,6 +1226,7 @@ static void fontsel_ok(GtkButton *button, gpointer data) (GTK_OBJECT(button), "user-data"); struct uctrl *uc = (struct uctrl *)fontsel->user_data; char *name = unifontsel_get_name(fontsel); + assert(name); /* should always be ok after OK pressed */ gtk_entry_set_text(GTK_ENTRY(uc->entry), name); sfree(name); } diff --git a/unix/gtkfont.c b/unix/gtkfont.c index b5c31cfa..cc655622 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -1564,6 +1564,8 @@ static void unifontsel_select_font(unifontsel_internal *fs, if (size_is_explicit) fs->intendedsize = size; + gtk_widget_set_sensitive(fs->u.ok_button, TRUE); + /* * Find the index of this fontinfo in the selorder list. */ @@ -2270,6 +2272,8 @@ unifontsel *unifontsel_new(const char *wintitle) unifontsel_setup_familylist(fs); fs->selected = NULL; + fs->selsize = fs->intendedsize = 13; /* random default */ + gtk_widget_set_sensitive(fs->u.ok_button, FALSE); return (unifontsel *)fs; } @@ -2349,7 +2353,8 @@ char *unifontsel_get_name(unifontsel *fontsel) unifontsel_internal *fs = (unifontsel_internal *)fontsel; char *name; - assert(fs->selected); + if (!fs->selected) + return NULL; if (fs->selected->size == 0) { name = fs->selected->fontclass->scale_fontname