[patch] Re: bug in gtk_label
- From: a-higuti math sci hokudai ac jp (Akira Higuchi)
- To: gtk-devel-list redhat com
- Subject: [patch] Re: bug in gtk_label
- Date: Thu, 17 Dec 1998 18:19:07 +0900 (JST)
In article <199812161928.UAA20787@loki.gams.co.at>
mla@gams.co.at writes:
>gtk_label_set_text() calls gdk_mbstowcs and uses it's return value as
>an index into label->label_wc.
>
>gdk_mbstowcs can return -1 (it does it on my setup because
>XwcTextPropertyToTextList return a failure code) but this error is not
>checked.
This bug seems to be fixed in gtk+-1.1.9, but I think the following
way is better than checking for glibc2 mb functions. Please apply
the following patch. This patch is against gtk+-1.1.8 (not 1.1.9).
--- gtklabel.c.old Thu Dec 17 16:07:41 1998
+++ gtklabel.c Thu Dec 17 17:24:33 1998
@@ -192,6 +192,7 @@
GTK_WIDGET_SET_FLAGS (label, GTK_NO_WINDOW);
label->label = NULL;
+ label->label_wc = NULL;
label->words = NULL;
label->max_width = 0;
label->jtype = GTK_JUSTIFY_CENTER;
@@ -219,6 +220,7 @@
gtk_label_set_text (GtkLabel *label,
const char *str)
{
+ GtkWidget *widget = GTK_WIDGET (label);
guint len;
guint wc_len;
@@ -231,10 +233,23 @@
label->label = g_strdup (str);
/* Convert text to wide characters */
+ if (label->label_wc)
+ g_free (label->label_wc);
len = strlen (str);
label->label_wc = g_new (GdkWChar, len + 1);
- wc_len = gdk_mbstowcs (label->label_wc, str, len + 1);
- label->label_wc[wc_len] = '\0';
+ gtk_widget_ensure_style (widget);
+ if ((widget->style) && (widget->style->font->type == GDK_FONT_FONTSET))
+ {
+ wc_len = gdk_mbstowcs (label->label_wc, str, len + 1);
+ if (wc_len < 0) wc_len = 0;
+ label->label_wc[wc_len] = '\0';
+ }
+ else
+ {
+ guint i;
+ for (i = 0; i <= len; i++)
+ label->label_wc[i] = label->label[i];
+ }
gtk_label_free_words (label);
@@ -334,6 +349,8 @@
g_free (label->label);
if (label->pattern)
g_free (label->pattern);
+ if (label->label_wc)
+ g_free (label->label_wc);
gtk_label_free_words (label);
(* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
}
@@ -847,15 +864,27 @@
{
GtkWidget *widget = GTK_WIDGET (label);
GtkLabelULine *uline;
- gchar *tmp_str;
+ guchar *tmp_str;
- tmp_str = gdk_wcstombs (word->beginning);
- gtk_paint_string (widget->style, widget->window, widget->state,
- area, widget, "label",
- x + word->x,
- y + word->y,
- tmp_str);
- g_free (tmp_str);
+ if ((widget->style) && (widget->style->font->type == GDK_FONT_FONTSET))
+ tmp_str = gdk_wcstombs (word->beginning);
+ else
+ {
+ guint i, len;
+ for (len = 0; word->beginning[len]; len++);
+ tmp_str = g_new (guchar, len + 1);
+ for (i = 0; i <= len; i++)
+ tmp_str[i] = word->beginning[i];
+ }
+ if (tmp_str)
+ {
+ gtk_paint_string (widget->style, widget->window, widget->state,
+ area, widget, "label",
+ x + word->x,
+ y + word->y,
+ tmp_str);
+ g_free (tmp_str);
+ }
for (uline = word->uline;uline;uline = uline->next)
gtk_paint_hline (widget->style, widget->window,
--- testgtkrc.old Thu Dec 10 11:18:46 1998
+++ testgtkrc Thu Dec 17 16:07:10 1998
@@ -17,8 +17,8 @@
style "defaultfont"
{
- fontset = "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*,*"
-# font = "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*,*"
+# fontset = "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*,*"
+ font = "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*"
}
# common default
--------------------------------------
Akira Higuchi
Dept. of Mathematics, Hokkaido Univ.
Hokkaido, Japan
Email: a-higuti@math.sci.hokudai.ac.jp
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]