Re: mnemonics, version 1.3.5



Steve Ramsay <ramsay universal ca> writes:
> 
> I am in the process of porting an app from 1.2.10 to 1.3.5. 

First of all thanks for doing this and sending in questions, now is
the time to catch GTK 2 problems.
 
> My question is how to do this with the new mnemonics of 1.3.5, using 
> gtk_label_new_with_mnemonic() results in the same problem I had before
> when the label has underscores within it, and I only want the first one
> used as a mnemonic.

One way would be, assuming "num" is 1, 2, 3 as you have the files
numbered, and "filename" is the filename:

 gchar *str;
 gchar *escaped; 

 escaped = g_markup_escape_text (filename, -1);

 str = g_strdup_printf ("<span underline='low'>%d</span>. %s",
                        num, escaped);

 gtk_label_set_markup (label, str);
 gtk_object_set (G_OBJECT (label),
                 "mnemonic_keyval",
                 gdk_unicode_to_keyval (digit_to_unichar (num)),
                 NULL);

 g_free (escaped);
 g_free (str);

Where digit_to_unichar() is just something like:

 switch (num)
   {
     case 0: return '0';
     case 1: return '1';
    ...
   }

probably something like "((gint)'0') + num" would work too.

I think just set_pattern ("_") might work instead of playing with
markup, that might be a lot easier.

Another option is that I think you can escape _ with __ in
set_mnemonic(), so you could write a function to go through the
filename and escape any _, that might be a better way too.

Useful docs:
  http://developer.gnome.org/doc/API/2.0/pango/pangomarkupformat.html
  http://developer.gnome.org/doc/API/2.0/glib/glib-simple-xml-subset-parser.html

There are a couple things that are kind of inconvenient here:

 - mnemonic_keyval is only available as a property, there's no 
   corresponding function
 - no digit_to_unichar() to match g_unichar_digit_value()

Havoc




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