Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 27937:1337d2813b2d
propagate from branch 'im.pidgin.pidgin' (head 5ab68ddb0251205f7ef97f4c280e65696cbd5ff2)
to branch 'im.pidgin.pidgin.yaz' (head 7a5d48783707dd377fd754961d3b009c3e492827)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 07 Apr 2009 14:32:50 +0000 |
parents | 1688f7e15530 |
children | b623c1824f29 |
comparison
equal
deleted
inserted
replaced
26588:1a94a964bddf | 27937:1337d2813b2d |
---|---|
3675 gtk_imhtml_class_register_protocol("ftp://", NULL, NULL); | 3675 gtk_imhtml_class_register_protocol("ftp://", NULL, NULL); |
3676 gtk_imhtml_class_register_protocol("mailto:", NULL, NULL); | 3676 gtk_imhtml_class_register_protocol("mailto:", NULL, NULL); |
3677 gtk_imhtml_class_register_protocol("gopher://", NULL, NULL); | 3677 gtk_imhtml_class_register_protocol("gopher://", NULL, NULL); |
3678 } | 3678 } |
3679 | 3679 |
3680 gchar * | |
3681 pidgin_gtk_ellipsis_text(GtkWidget *widget, const char *text, gint min_width, gchar *ellipsis) | |
3682 { | |
3683 PangoLayout *layout; | |
3684 gint width, height; | |
3685 gint ewidth; | |
3686 glong len0, len1, len2; | |
3687 gchar *buf, *buf_tmp; | |
3688 gboolean with_ellipsis = FALSE; | |
3689 const gchar default_ellipsis[] = "..."; | |
3690 | |
3691 if(!ellipsis) | |
3692 ellipsis = default_ellipsis; | |
3693 | |
3694 /* allocate buf */ | |
3695 buf = g_malloc0(strlen(text) * 2); | |
3696 | |
3697 /* create layout */ | |
3698 layout = gtk_widget_create_pango_layout(widget, ellipsis); | |
3699 pango_layout_get_pixel_size(layout, &width, &height); | |
3700 ewidth = width; /* length of ellipsis text. */ | |
3701 | |
3702 len0 = 0; | |
3703 len1 = g_utf8_strlen(text, -1); | |
3704 len2 = len1; | |
3705 | |
3706 while (1) { | |
3707 | |
3708 if (len2 == len0) | |
3709 break; | |
3710 | |
3711 g_utf8_strncpy(buf, text, len2); | |
3712 pango_layout_set_text(layout, buf, -1); | |
3713 pango_layout_get_pixel_size(layout, &width, &height); | |
3714 | |
3715 if(!with_ellipsis && width <= min_width) | |
3716 break; | |
3717 else | |
3718 with_ellipsis = TRUE; | |
3719 | |
3720 if (width + ewidth > min_width) | |
3721 len1 = len2; | |
3722 else | |
3723 len0 = len2; | |
3724 | |
3725 len2 = (len0 + len1) / 2; | |
3726 } | |
3727 | |
3728 g_object_unref(layout); | |
3729 | |
3730 if (with_ellipsis) { | |
3731 buf_tmp = buf; | |
3732 buf = g_strdup_printf("%s%s", buf_tmp, ellipsis); | |
3733 g_free(buf_tmp); | |
3734 } | |
3735 | |
3736 return buf; | |
3737 } |