Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 27940:b623c1824f29
propagate from branch 'im.pidgin.pidgin' (head 58fbcc161c5eadf3f307cd460a6ce0a209d908df)
to branch 'im.pidgin.pidgin.yaz' (head a378a1d9618c47f5b0e6c67daf613d3c4275f7cf)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 16 Apr 2009 05:51:42 +0000 |
parents | b162300ab1e7 1688f7e15530 |
children | f3ccb5a36fd6 |
comparison
equal
deleted
inserted
replaced
26650:3712d32363dd | 27940:b623c1824f29 |
---|---|
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 } |