Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 27800:85d5b6c06a6c
propagate from branch 'im.pidgin.pidgin' (head 33bd2430510196431b931ccb1fa0b55777482dd0)
to branch 'im.pidgin.pidgin.yaz' (head 5426ea7b0587a996037bc668698aea554c01356e)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 17 Mar 2008 06:32:52 +0000 |
parents | e9cf897bd873 |
children | d44a96d49ee5 |
comparison
equal
deleted
inserted
replaced
22483:14c476bcdaee | 27800:85d5b6c06a6c |
---|---|
3457 } | 3457 } |
3458 return FALSE; | 3458 return FALSE; |
3459 #endif | 3459 #endif |
3460 } | 3460 } |
3461 | 3461 |
3462 gchar * | |
3463 pidgin_gtk_ellipsis_text(GtkWidget *widget, const char *text, gint min_width, gchar *ellipsis) | |
3464 { | |
3465 PangoLayout *layout; | |
3466 gint width, height; | |
3467 gint ewidth; | |
3468 glong len0, len1, len2; | |
3469 gchar *buf, *buf_tmp; | |
3470 gboolean with_ellipsis = FALSE; | |
3471 const gchar default_ellipsis[] = "..."; | |
3472 | |
3473 if(!ellipsis) | |
3474 ellipsis = default_ellipsis; | |
3475 | |
3476 /* allocate buf */ | |
3477 buf = g_malloc0(strlen(text) * 2); | |
3478 | |
3479 /* create layout */ | |
3480 layout = gtk_widget_create_pango_layout(widget, ellipsis); | |
3481 pango_layout_get_pixel_size(layout, &width, &height); | |
3482 ewidth = width; /* length of ellipsis text. */ | |
3483 | |
3484 len0 = 0; | |
3485 len1 = g_utf8_strlen(text, -1); | |
3486 len2 = len1; | |
3487 | |
3488 while (1) { | |
3489 | |
3490 if (len2 == len0) | |
3491 break; | |
3492 | |
3493 g_utf8_strncpy(buf, text, len2); | |
3494 pango_layout_set_text(layout, buf, -1); | |
3495 pango_layout_get_pixel_size(layout, &width, &height); | |
3496 | |
3497 if(!with_ellipsis && width <= min_width) | |
3498 break; | |
3499 else | |
3500 with_ellipsis = TRUE; | |
3501 | |
3502 if (width + ewidth > min_width) | |
3503 len1 = len2; | |
3504 else | |
3505 len0 = len2; | |
3506 | |
3507 len2 = (len0 + len1) / 2; | |
3508 } | |
3509 | |
3510 g_object_unref(layout); | |
3511 | |
3512 if (with_ellipsis) { | |
3513 buf_tmp = buf; | |
3514 buf = g_strdup_printf("%s%s", buf_tmp, ellipsis); | |
3515 g_free(buf_tmp); | |
3516 } | |
3517 | |
3518 return buf; | |
3519 } |