[gtk+] GtkLabel: fix mnemonic-keyval when use-markup is true



commit 8e65fa1b43067f5ccebd8ab2070f678651a174d5
Author: Sébastien Wilmet <swilmet src gnome org>
Date:   Tue Apr 24 22:22:22 2012 +0200

    GtkLabel: fix mnemonic-keyval when use-markup is true
    
    To extract the mnemonic key value, the string must contain the
    underscore. But when the "gtk-auto-mnemonics" setting is true and when
    the Alt key is not pressed, the underscore must not be displayed. The
    problem was that the 'new_str' variable was used for both purposes:
    extract the text to display, and extract the accelerator character.
    
    When the underscore must not be visible, the underscores were removed
    from the 'new_str' variable before extracting the accelerator character.
    
    Now there are two strings, one for each purpose.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674759

 gtk/gtklabel.c |   43 +++++++++++++++++++++++++++++++++----------
 1 files changed, 33 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 8d18cf0..587a61f 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -2517,10 +2517,11 @@ gtk_label_set_markup_internal (GtkLabel    *label,
   GError *error = NULL;
   PangoAttrList *attrs = NULL;
   gunichar accel_char = 0;
-  gchar *new_str;
+  gchar *str_for_display = NULL;
+  gchar *str_for_accel = NULL;
   GList *links = NULL;
 
-  if (!parse_uri_markup (label, str, &new_str, &links, &error))
+  if (!parse_uri_markup (label, str, &str_for_display, &links, &error))
     {
       g_warning ("Failed to set text from markup due to error parsing markup: %s",
                  error->message);
@@ -2528,6 +2529,8 @@ gtk_label_set_markup_internal (GtkLabel    *label,
       return;
     }
 
+  str_for_accel = g_strdup (str_for_display);
+
   if (links)
     {
       gtk_label_ensure_select_info (label);
@@ -2555,31 +2558,51 @@ gtk_label_set_markup_internal (GtkLabel    *label,
           gchar *pattern;
           guint key;
 
-          if (separate_uline_pattern (new_str, &key, &tmp, &pattern))
+          if (separate_uline_pattern (str_for_display, &key, &tmp, &pattern))
             {
-              g_free (new_str);
-              new_str = tmp;
+              g_free (str_for_display);
+              str_for_display = tmp;
               g_free (pattern);
             }
         }
     }
 
-  if (!pango_parse_markup (new_str,
+  /* Extract the text to display */
+  if (!pango_parse_markup (str_for_display,
                            -1,
-                           with_uline ? '_' : 0,
+                           0,
                            &attrs,
                            &text,
-                           with_uline ? &accel_char : NULL,
+                           NULL,
                            &error))
     {
       g_warning ("Failed to set text from markup due to error parsing markup: %s",
                  error->message);
-      g_free (new_str);
+      g_free (str_for_display);
+      g_free (str_for_accel);
+      g_error_free (error);
+      return;
+    }
+
+  /* Extract the accelerator character */
+  if (with_uline && !pango_parse_markup (str_for_accel,
+                                        -1,
+                                        '_',
+                                        NULL,
+                                        NULL,
+                                        &accel_char,
+                                        &error))
+    {
+      g_warning ("Failed to set text from markup due to error parsing markup: %s",
+                 error->message);
+      g_free (str_for_display);
+      g_free (str_for_accel);
       g_error_free (error);
       return;
     }
 
-  g_free (new_str);
+  g_free (str_for_display);
+  g_free (str_for_accel);
 
   if (text)
     gtk_label_set_text_internal (label, text);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]