Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 27768:969a2aeae461
propagate from branch 'im.pidgin.pidgin' (head b7875f81b48bb1a776ac4b2473cc7376cb35b0f9)
to branch 'im.pidgin.pidgin.yaz' (head e22890a44520ea1129da935f8ce82ea795081201)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 27 Feb 2008 12:21:29 +0000 |
parents | e9cf897bd873 |
children | d44a96d49ee5 |
comparison
equal
deleted
inserted
replaced
22337:a8c025929245 | 27768:969a2aeae461 |
---|---|
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 } |