Use Pango's ellipsize functionality instead of doing our own clipping. This properly takes care of the fact that one character isn't necessarily one byte (or, for that matter, one glyph). Replacement of tabs, LFs and CRs is no longer done. Instead, the label is put into single-line mode (so you get [000A] and [000D] instead). Signed-off-by: Darren Salt Index: panel-plugin/clipman.c =================================================================== --- panel-plugin/clipman.c (revision 1850) +++ panel-plugin/clipman.c (working copy) @@ -112,22 +112,12 @@ } static gchar * -clipman_create_title (gchar *txt, - gint chars) +clipman_create_title (gchar *txt) { - guint i; gchar *s, *t, *u; - s = g_strndup (txt, chars); + s = g_strdup (txt); - i = 0; - while (s[i] != '\0') - { - if (s[i] == '\n' || s[i] == '\r' || s[i] == '\t') - s[i] = ' '; - i++; - } - if (!g_utf8_validate (s, -1, NULL)) { DBG ("Title is not utf8 complaint, we're going to convert it"); @@ -189,8 +179,7 @@ clip = g_ptr_array_index (clipman->clips, i); g_free (clip->title); - clip->title = clipman_create_title (clip->text, - clipman->MenuCharacters); + clip->title = clipman_create_title (clip->text); } } @@ -205,7 +194,7 @@ { new_clip = g_new0 (ClipmanClip, 1); - new_clip->title = clipman_create_title (txt, clipman->MenuCharacters); + new_clip->title = clipman_create_title (txt); /* No valid title could be created, drop it... */ if (new_clip->title == NULL) @@ -334,10 +323,12 @@ static GtkWidget * clipman_create_menuitem (ClipmanAction *action, + guint width, guint number, gboolean bold) { GtkWidget *mi; + GtkLabel *label; gchar *title; mi = gtk_menu_item_new_with_label (""); @@ -355,9 +346,13 @@ else title = g_strdup_printf("%d. %s", number ,title); } - - gtk_label_set_markup (GTK_LABEL(GTK_BIN(mi)->child), title); - + + label = GTK_LABEL(GTK_BIN(mi)->child); + gtk_label_set_markup (label, title); + gtk_label_set_single_line_mode (label, TRUE); + gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END); + gtk_label_set_max_width_chars (label, width); + return mi; } @@ -391,13 +386,15 @@ G_LIKELY (clip->text != NULL) && strcmp(clip->text, dtext) == 0) { - mi = clipman_create_menuitem (action, j, TRUE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + j, TRUE); g_free (dtext); dtext = NULL; } else { - mi = clipman_create_menuitem (action, j, FALSE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + j, FALSE); } g_signal_connect (G_OBJECT(mi), "button_release_event", @@ -440,13 +437,15 @@ G_LIKELY (clip->text != NULL) && strcmp(clip->text, ptext) == 0) { - mi = clipman_create_menuitem (action, j, TRUE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + j, TRUE); g_free (ptext); ptext = NULL; } else { - mi = clipman_create_menuitem (action, j, FALSE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + j, FALSE); } g_signal_connect (G_OBJECT(mi), "button_release_event", @@ -501,7 +500,8 @@ G_LIKELY (clip->text != NULL) && strcmp(clip->text, dtext) == 0) { - mi = clipman_create_menuitem (action, clipman->clips->len-i, TRUE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + clipman->clips->len-i, TRUE); g_free (dtext); dtext = NULL; } @@ -509,13 +509,15 @@ G_LIKELY (clip->text != NULL) && strcmp(clip->text, ptext) == 0) { - mi = clipman_create_menuitem (action, clipman->clips->len-i, TRUE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + clipman->clips->len-i, TRUE); g_free (ptext); ptext = NULL; } else { - mi = clipman_create_menuitem (action, clipman->clips->len-i, FALSE); + mi = clipman_create_menuitem (action, clipman->MenuCharacters, + clipman->clips->len-i, FALSE); } g_signal_connect (G_OBJECT(mi), "button_release_event",