diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 48f363b3c1..bfa231b9d9 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -2981,8 +2981,18 @@ gtk_label_recalculate (GtkLabel *self) gtk_label_clear_layout (self); gtk_label_clear_select_info (self); - if (self->use_markup || self->use_underline) - gtk_label_set_markup_internal (self, self->label, self->use_underline); + if (self->use_markup) + { + gtk_label_set_markup_internal (self, self->label, self->use_underline); + } + else if (self->use_underline) + { + char *text; + + text = g_markup_escape_text (self->label, -1); + gtk_label_set_markup_internal (self, text, TRUE); + g_free (text); + } else { g_clear_pointer (&self->markup_attrs, pango_attr_list_unref); diff --git a/testsuite/gtk/label.c b/testsuite/gtk/label.c index c075e15139..3b1531a36b 100644 --- a/testsuite/gtk/label.c +++ b/testsuite/gtk/label.c @@ -196,12 +196,35 @@ test_label_markup (void) gtk_window_destroy (GTK_WINDOW (window)); } +static void +test_label_underline (void) +{ + GtkWidget *window; + GtkWidget *label; + + window = gtk_window_new (); + + label = gtk_label_new (""); + + gtk_window_set_child (GTK_WINDOW (window), label); + gtk_window_set_mnemonics_visible (GTK_WINDOW (window), TRUE); + + gtk_label_set_use_markup (GTK_LABEL (label), FALSE); + gtk_label_set_use_underline (GTK_LABEL (label), TRUE); + gtk_label_set_label (GTK_LABEL (label), "tes_t & no markup <<"); + + g_assert_cmpint (gtk_label_get_mnemonic_keyval (GTK_LABEL (label)), ==, GDK_KEY_t); + + gtk_window_destroy (GTK_WINDOW (window)); +} + int main (int argc, char *argv[]) { gtk_test_init (&argc, &argv); g_test_add_func ("/label/markup-parse", test_label_markup); + g_test_add_func ("/label/underline-parse", test_label_underline); return g_test_run (); }