Fixed GtkTextTag to sync the GdkColors with the new GdkRGBA values for backwards compatability.

This commit is contained in:
Tristan Van Berkom 2011-02-14 14:27:28 +09:00 committed by Matthias Clasen
parent d3c77f0330
commit 2b2d7aa305

View File

@ -775,6 +775,25 @@ gtk_text_tag_finalize (GObject *object)
G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_text_tag_parent_class)->finalize (object);
} }
static void
copy_rgba_to_gdk_color (GdkRGBA *src,
GdkColor *dest)
{
dest->red = CLAMP (src->red, 0.0, 1.0) * 65535.0;
dest->green = CLAMP (src->green, 0.0, 1.0) * 65535.0;
dest->blue = CLAMP (src->blue, 0.0, 1.0) * 65535.0;
}
static void
copy_gdk_color_to_rgba (GdkColor *src,
GdkRGBA *dest)
{
dest->red = src->red / 65535.;
dest->green = src->green / 65535.;
dest->blue = src->blue / 65535.;
dest->alpha = 1;
}
static void static void
set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba) set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
{ {
@ -794,6 +813,8 @@ set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
} }
priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba); priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
copy_rgba_to_gdk_color (rgba, &priv->values->appearance.bg_color);
} }
else else
{ {
@ -824,6 +845,8 @@ set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
} }
priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba); priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
copy_rgba_to_gdk_color (rgba, &priv->values->appearance.fg_color);
} }
else else
{ {
@ -843,10 +866,16 @@ set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
if (priv->values->pg_bg_rgba) if (priv->values->pg_bg_rgba)
gdk_rgba_free (priv->values->pg_bg_rgba); gdk_rgba_free (priv->values->pg_bg_rgba);
if (priv->values->pg_bg_color)
gdk_color_free (priv->values->pg_bg_color);
priv->values->pg_bg_rgba = NULL; priv->values->pg_bg_rgba = NULL;
priv->values->pg_bg_color = NULL;
if (rgba) if (rgba)
{ {
GdkColor color = { 0, };
if (!priv->pg_bg_color_set) if (!priv->pg_bg_color_set)
{ {
priv->pg_bg_color_set = TRUE; priv->pg_bg_color_set = TRUE;
@ -854,6 +883,9 @@ set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
} }
priv->values->pg_bg_rgba = gdk_rgba_copy (rgba); priv->values->pg_bg_rgba = gdk_rgba_copy (rgba);
copy_rgba_to_gdk_color (rgba, &color);
priv->values->pg_bg_color = gdk_color_copy (&color);
} }
else else
{ {
@ -871,13 +903,9 @@ set_bg_color (GtkTextTag *tag, GdkColor *color)
{ {
if (color) if (color)
{ {
gchar *str;
GdkRGBA rgba; GdkRGBA rgba;
str = gdk_color_to_string (color); copy_gdk_color_to_rgba (color, &rgba);
gdk_rgba_parse (&rgba, str);
g_free (str);
set_bg_rgba (tag, &rgba); set_bg_rgba (tag, &rgba);
} }
else else
@ -889,13 +917,9 @@ set_fg_color (GtkTextTag *tag, GdkColor *color)
{ {
if (color) if (color)
{ {
gchar *str;
GdkRGBA rgba; GdkRGBA rgba;
str = gdk_color_to_string (color); copy_gdk_color_to_rgba (color, &rgba);
gdk_rgba_parse (&rgba, str);
g_free (str);
set_fg_rgba (tag, &rgba); set_fg_rgba (tag, &rgba);
} }
else else
@ -907,13 +931,9 @@ set_pg_bg_color (GtkTextTag *tag, GdkColor *color)
{ {
if (color) if (color)
{ {
gchar *str;
GdkRGBA rgba; GdkRGBA rgba;
str = gdk_color_to_string (color); copy_gdk_color_to_rgba (color, &rgba);
gdk_rgba_parse (&rgba, str);
g_free (str);
set_pg_bg_rgba (tag, &rgba); set_pg_bg_rgba (tag, &rgba);
} }
else else
@ -1555,7 +1575,6 @@ gtk_text_tag_get_property (GObject *object,
{ {
GtkTextTag *tag = GTK_TEXT_TAG (object); GtkTextTag *tag = GTK_TEXT_TAG (object);
GtkTextTagPrivate *priv = tag->priv; GtkTextTagPrivate *priv = tag->priv;
GdkColor color = { 0, };
switch (prop_id) switch (prop_id)
{ {
@ -1564,25 +1583,21 @@ gtk_text_tag_get_property (GObject *object,
break; break;
case PROP_BACKGROUND_GDK: case PROP_BACKGROUND_GDK:
if (priv->values->appearance.rgba[0]) g_value_set_boxed (value, &priv->values->appearance.bg_color);
{ break;
color.red = CLAMP (priv->values->appearance.rgba[0]->red, 0.0, 1.0) * 65535.0;
color.green = CLAMP (priv->values->appearance.rgba[0]->green, 0.0, 1.0) * 65535.0; case PROP_BACKGROUND_RGBA:
color.blue = CLAMP (priv->values->appearance.rgba[0]->blue, 0.0, 1.0) * 65535.0; g_value_set_boxed (value, priv->values->appearance.rgba[0]);
}
g_value_set_boxed (value, &color);
break; break;
case PROP_FOREGROUND_GDK: case PROP_FOREGROUND_GDK:
if (priv->values->appearance.rgba[1])
{
color.red = CLAMP (priv->values->appearance.rgba[1]->red, 0.0, 1.0) * 65535.0;
color.green = CLAMP (priv->values->appearance.rgba[1]->green, 0.0, 1.0) * 65535.0;
color.blue = CLAMP (priv->values->appearance.rgba[1]->blue, 0.0, 1.0) * 65535.0;
}
g_value_set_boxed (value, &priv->values->appearance.fg_color); g_value_set_boxed (value, &priv->values->appearance.fg_color);
break; break;
case PROP_FOREGROUND_RGBA:
g_value_set_boxed (value, priv->values->appearance.rgba[1]);
break;
case PROP_FONT: case PROP_FONT:
{ {
gchar *str; gchar *str;
@ -1713,10 +1728,13 @@ gtk_text_tag_get_property (GObject *object,
break; break;
case PROP_PARAGRAPH_BACKGROUND_GDK: case PROP_PARAGRAPH_BACKGROUND_GDK:
/* XXX Transform the GdkRGBA here */
g_value_set_boxed (value, priv->values->pg_bg_color); g_value_set_boxed (value, priv->values->pg_bg_color);
break; break;
case PROP_PARAGRAPH_BACKGROUND_RGBA:
g_value_set_boxed (value, priv->values->pg_bg_rgba);
break;
case PROP_ACCUMULATIVE_MARGIN: case PROP_ACCUMULATIVE_MARGIN:
g_value_set_boolean (value, priv->accumulative_margin); g_value_set_boolean (value, priv->accumulative_margin);
break; break;