Mercurial > audlegacy
comparison audacious/playlist_list.c @ 324:fbafca56b6a8 trunk
[svn] playlist window truncation fixes provided by external contributor: Tim Yamin <plasmaroo -at- gentoo.org>.
author | nenolod |
---|---|
date | Mon, 19 Dec 2005 08:45:45 -0800 |
parents | 763afa52f416 |
children | 429b73ffcb18 |
comparison
equal
deleted
inserted
replaced
323:f61c05314118 | 324:fbafca56b6a8 |
---|---|
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 | |
297 gint len; | 296 gint len; |
298 gint len_pixmap; | |
299 guint plist_length_int; | 297 guint plist_length_int; |
298 | |
299 gchar *text_clipped; | |
300 PangoLayout *layout; | 300 PangoLayout *layout; |
301 gchar *text_clipped; | 301 PangoRectangle rect; |
302 | 302 |
303 REQUIRE_STATIC_LOCK(playlist); | 303 REQUIRE_STATIC_LOCK(playlist); |
304 | |
305 len = g_utf8_strlen(text, -1); | |
306 len_pixmap = (width_approx_letters * len); | |
307 | |
308 while (len_pixmap > width && len > 4) { | |
309 len--; | |
310 len_pixmap -= width_approx_letters; | |
311 } | |
312 | |
313 /* FIXME: Is it possible to overflow text_clipped when text is non | |
314 UTF-8? - descender */ | |
315 | |
316 text_clipped = g_new0(gchar, strlen(text)+1); | |
317 g_utf8_strncpy(text_clipped, text, len); | |
318 | 304 |
319 if (cfg.show_numbers_in_pl) { | 305 if (cfg.show_numbers_in_pl) { |
320 gchar *pos_string = g_strdup_printf("%d", ppos); | 306 gchar *pos_string = g_strdup_printf("%d", ppos); |
321 plist_length_int = | 307 plist_length_int = |
322 gint_count_digits(playlist_get_length_nolock()) + 1; | 308 gint_count_digits(playlist_get_length_nolock()) + 1; |
339 g_free(pos_string); | 325 g_free(pos_string); |
340 g_object_unref(layout); | 326 g_object_unref(layout); |
341 } | 327 } |
342 else { | 328 else { |
343 padding = 3; | 329 padding = 3; |
330 } | |
331 | |
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; | |
339 layout = gtk_widget_create_pango_layout(playlistwin, text); | |
340 pango_layout_set_font_description(layout, playlist_list_font); | |
341 pango_layout_get_pixel_extents(layout, &rect, NULL); | |
342 if (rect.width > width) | |
343 { | |
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); | |
344 } | 366 } |
345 | 367 |
346 layout = gtk_widget_create_pango_layout(playlistwin, text_clipped); | 368 layout = gtk_widget_create_pango_layout(playlistwin, text_clipped); |
347 | 369 |
348 pango_layout_set_font_description(layout, playlist_list_font); | 370 pango_layout_set_font_description(layout, playlist_list_font); |
484 max_time_len = MAX(max_time_len, tail_len); | 506 max_time_len = MAX(max_time_len, tail_len); |
485 | 507 |
486 /* FIXME: This is just an approximate alignment, maybe | 508 /* FIXME: This is just an approximate alignment, maybe |
487 something still fast, but exact could be done */ | 509 something still fast, but exact could be done */ |
488 | 510 |
489 tail_width = width - (tail_len * width_approx_digits) + | 511 tail_width = width - (width_approx_digits * 6) - 5; |
490 (width_approx_digits_half) - 3; | |
491 | |
492 if (i == playlist_get_position_nolock()) | 512 if (i == playlist_get_position_nolock()) |
493 gdk_gc_set_foreground(gc, | 513 gdk_gc_set_foreground(gc, |
494 skin_get_color(bmp_active_skin, | 514 skin_get_color(bmp_active_skin, |
495 SKIN_PLEDIT_CURRENT)); | 515 SKIN_PLEDIT_CURRENT)); |
496 else | 516 else |