comparison audacious/playlist_list.c @ 326:429b73ffcb18 trunk

[svn] playlist_list code cleanups from mikachu.
author nenolod
date Mon, 19 Dec 2005 16:39:12 -0800
parents fbafca56b6a8
children 5c457dac866a
comparison
equal deleted inserted replaced
325:ea321d1dae48 326:429b73ffcb18
291 gint line, 291 gint line,
292 gint width, 292 gint width,
293 const gchar * text, 293 const gchar * text,
294 guint ppos) 294 guint ppos)
295 { 295 {
296 gint len;
297 guint plist_length_int; 296 guint plist_length_int;
298 297
299 gchar *text_clipped;
300 PangoLayout *layout; 298 PangoLayout *layout;
301 PangoRectangle rect;
302 299
303 REQUIRE_STATIC_LOCK(playlist); 300 REQUIRE_STATIC_LOCK(playlist);
304 301
305 if (cfg.show_numbers_in_pl) { 302 if (cfg.show_numbers_in_pl) {
306 gchar *pos_string = g_strdup_printf("%d", ppos); 303 gchar *pos_string = g_strdup_printf("%d", ppos);
327 } 324 }
328 else { 325 else {
329 padding = 3; 326 padding = 3;
330 } 327 }
331 328
332 /* FIXME: Is it possible to overflow text_clipped when text is non
333 UTF-8? - descender */
334 text_clipped = g_new0(gchar, strlen(text)+1);
335 len = g_utf8_strlen(text, -1);
336 g_utf8_strncpy(text_clipped, text, len);
337
338 width -= padding; 329 width -= padding;
330
339 layout = gtk_widget_create_pango_layout(playlistwin, text); 331 layout = gtk_widget_create_pango_layout(playlistwin, text);
332
340 pango_layout_set_font_description(layout, playlist_list_font); 333 pango_layout_set_font_description(layout, playlist_list_font);
341 pango_layout_get_pixel_extents(layout, &rect, NULL); 334 pango_layout_set_width(layout, width * PANGO_SCALE);
342 if (rect.width > width) 335 pango_layout_set_single_paragraph_mode(layout, TRUE);
343 { 336 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
344 while (rect.width > width && len > 4) {
345 len--;
346 g_utf8_strncpy(text_clipped, text_clipped, len);
347
348 layout = gtk_widget_create_pango_layout(playlistwin, text_clipped);
349 pango_layout_set_font_description(layout, playlist_list_font);
350 pango_layout_get_pixel_extents(layout, &rect, NULL);
351 }
352
353 /* Add dots */
354 layout = gtk_widget_create_pango_layout(playlistwin, " ...");
355 pango_layout_set_font_description(layout, playlist_list_font);
356 pango_layout_get_pixel_extents(layout, &rect, NULL);
357
358 g_utf8_strncpy(text_clipped, text, len - (rect.width / width_approx_letters));
359
360 /* If we have whitespace on the end strip off some more... */
361 while (text_clipped[len] == ' ' && len > 4) {
362 len--;
363 g_utf8_strncpy(text_clipped, text_clipped, len);
364 }
365 text_clipped = g_strconcat(text_clipped, "...", NULL);
366 }
367
368 layout = gtk_widget_create_pango_layout(playlistwin, text_clipped);
369
370 pango_layout_set_font_description(layout, playlist_list_font);
371 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc, 337 gdk_draw_layout(pl->pl_widget.parent, pl->pl_widget.gc,
372 pl->pl_widget.x + padding + (width_approx_letters / 4), 338 pl->pl_widget.x + padding + (width_approx_letters / 4),
373 pl->pl_widget.y + (line - 1) * pl->pl_fheight + 339 pl->pl_widget.y + (line - 1) * pl->pl_fheight +
374 ascent + abs(descent), layout); 340 ascent + abs(descent), layout);
375 341
376 g_object_unref(layout); 342 g_object_unref(layout);
377 g_free(text_clipped);
378 } 343 }
379 344
380 void 345 void
381 playlist_list_draw(Widget * w) 346 playlist_list_draw(Widget * w)
382 { 347 {