# HG changeset patch # User nenolod # Date 1135039152 28800 # Node ID 429b73ffcb18662db3cf8fc072b4f3c131cbc98f # Parent ea321d1dae485fb8dd6c59500779cb98e308530f [svn] playlist_list code cleanups from mikachu. diff -r ea321d1dae48 -r 429b73ffcb18 audacious/playlist_list.c --- a/audacious/playlist_list.c Mon Dec 19 08:58:27 2005 -0800 +++ b/audacious/playlist_list.c Mon Dec 19 16:39:12 2005 -0800 @@ -293,12 +293,9 @@ const gchar * text, guint ppos) { - gint len; guint plist_length_int; - gchar *text_clipped; PangoLayout *layout; - PangoRectangle rect; REQUIRE_STATIC_LOCK(playlist); @@ -329,52 +326,20 @@ padding = 3; } - /* FIXME: Is it possible to overflow text_clipped when text is non - UTF-8? - descender */ - text_clipped = g_new0(gchar, strlen(text)+1); - len = g_utf8_strlen(text, -1); - g_utf8_strncpy(text_clipped, text, len); - width -= padding; - layout = gtk_widget_create_pango_layout(playlistwin, text); - pango_layout_set_font_description(layout, playlist_list_font); - pango_layout_get_pixel_extents(layout, &rect, NULL); - if (rect.width > width) - { - while (rect.width > width && len > 4) { - len--; - g_utf8_strncpy(text_clipped, text_clipped, len); - layout = gtk_widget_create_pango_layout(playlistwin, text_clipped); - pango_layout_set_font_description(layout, playlist_list_font); - pango_layout_get_pixel_extents(layout, &rect, NULL); - } - - /* Add dots */ - layout = gtk_widget_create_pango_layout(playlistwin, " ..."); - pango_layout_set_font_description(layout, playlist_list_font); - pango_layout_get_pixel_extents(layout, &rect, NULL); - - g_utf8_strncpy(text_clipped, text, len - (rect.width / width_approx_letters)); - - /* If we have whitespace on the end strip off some more... */ - while (text_clipped[len] == ' ' && len > 4) { - len--; - g_utf8_strncpy(text_clipped, text_clipped, len); - } - text_clipped = g_strconcat(text_clipped, "...", NULL); - } - - layout = gtk_widget_create_pango_layout(playlistwin, text_clipped); + layout = gtk_widget_create_pango_layout(playlistwin, text); pango_layout_set_font_description(layout, playlist_list_font); + pango_layout_set_width(layout, width * PANGO_SCALE); + pango_layout_set_single_paragraph_mode(layout, TRUE); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, pl->pl_widget.x + padding + (width_approx_letters / 4), pl->pl_widget.y + (line - 1) * pl->pl_fheight + ascent + abs(descent), layout); g_object_unref(layout); - g_free(text_clipped); } void