mirror of https://github.com/GNOME/gimp.git
app: create separate tag lists for IME preedit colors.
In particular, I don't want the preedit foreground colors to be displayed in the text style editor UI. They are only temporary hints and should not be taken into account as user-chosen style.
This commit is contained in:
parent
a86b0cf0a2
commit
cd641fa14f
|
@ -1465,15 +1465,15 @@ gimp_text_tool_im_preedit_changed (GtkIMContext *context,
|
|||
|
||||
if (attr->klass->type == PANGO_ATTR_BACKGROUND)
|
||||
{
|
||||
gimp_text_buffer_set_bg_color (text_tool->buffer,
|
||||
&start, &end,
|
||||
&color);
|
||||
gimp_text_buffer_set_preedit_bg_color (text_tool->buffer,
|
||||
&start, &end,
|
||||
&color);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_text_buffer_set_color (text_tool->buffer,
|
||||
&start, &end,
|
||||
&color);
|
||||
gimp_text_buffer_set_preedit_color (text_tool->buffer,
|
||||
&start, &end,
|
||||
&color);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -160,10 +160,16 @@ gimp_text_buffer_finalize (GObject *object)
|
|||
buffer->color_tags = NULL;
|
||||
}
|
||||
|
||||
if (buffer->bg_color_tags)
|
||||
if (buffer->preedit_color_tags)
|
||||
{
|
||||
g_list_free (buffer->bg_color_tags);
|
||||
buffer->bg_color_tags = NULL;
|
||||
g_list_free (buffer->preedit_color_tags);
|
||||
buffer->preedit_color_tags = NULL;
|
||||
}
|
||||
|
||||
if (buffer->preedit_bg_color_tags)
|
||||
{
|
||||
g_list_free (buffer->preedit_bg_color_tags);
|
||||
buffer->preedit_bg_color_tags = NULL;
|
||||
}
|
||||
|
||||
gimp_text_buffer_clear_insert_tags (buffer);
|
||||
|
@ -1013,8 +1019,8 @@ gimp_text_buffer_set_color (GimpTextBuffer *buffer,
|
|||
}
|
||||
|
||||
GtkTextTag *
|
||||
gimp_text_buffer_get_bg_color_tag (GimpTextBuffer *buffer,
|
||||
const GimpRGB *color)
|
||||
gimp_text_buffer_get_preedit_color_tag (GimpTextBuffer *buffer,
|
||||
const GimpRGB *color)
|
||||
{
|
||||
GList *list;
|
||||
GtkTextTag *tag;
|
||||
|
@ -1024,7 +1030,89 @@ gimp_text_buffer_get_bg_color_tag (GimpTextBuffer *buffer,
|
|||
|
||||
gimp_rgb_get_uchar (color, &r, &g, &b);
|
||||
|
||||
for (list = buffer->bg_color_tags; list; list = g_list_next (list))
|
||||
for (list = buffer->preedit_color_tags; list; list = g_list_next (list))
|
||||
{
|
||||
GimpRGB tag_color;
|
||||
guchar tag_r, tag_g, tag_b;
|
||||
|
||||
tag = list->data;
|
||||
|
||||
gimp_text_tag_get_color (tag, &tag_color);
|
||||
|
||||
gimp_rgb_get_uchar (&tag_color, &tag_r, &tag_g, &tag_b);
|
||||
|
||||
/* Do not compare the alpha channel, since it's unused */
|
||||
if (tag_r == r &&
|
||||
tag_g == g &&
|
||||
tag_b == b)
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
g_snprintf (name, sizeof (name), "preedit-color-#%02x%02x%02x",
|
||||
r, g, b);
|
||||
|
||||
gimp_rgb_get_gdk_color (color, &gdk_color);
|
||||
|
||||
tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
|
||||
name,
|
||||
"foreground-gdk", &gdk_color,
|
||||
"foreground-set", TRUE,
|
||||
NULL);
|
||||
|
||||
buffer->preedit_color_tags = g_list_prepend (buffer->preedit_color_tags, tag);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_text_buffer_set_preedit_color (GimpTextBuffer *buffer,
|
||||
const GtkTextIter *start,
|
||||
const GtkTextIter *end,
|
||||
const GimpRGB *color)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
g_return_if_fail (GIMP_IS_TEXT_BUFFER (buffer));
|
||||
g_return_if_fail (start != NULL);
|
||||
g_return_if_fail (end != NULL);
|
||||
|
||||
if (gtk_text_iter_equal (start, end))
|
||||
return;
|
||||
|
||||
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
|
||||
|
||||
for (list = buffer->preedit_color_tags; list; list = g_list_next (list))
|
||||
{
|
||||
gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (buffer), list->data,
|
||||
start, end);
|
||||
}
|
||||
|
||||
if (color)
|
||||
{
|
||||
GtkTextTag *tag = gimp_text_buffer_get_preedit_color_tag (buffer, color);
|
||||
|
||||
gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
|
||||
start, end);
|
||||
}
|
||||
|
||||
gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (buffer));
|
||||
}
|
||||
|
||||
GtkTextTag *
|
||||
gimp_text_buffer_get_preedit_bg_color_tag (GimpTextBuffer *buffer,
|
||||
const GimpRGB *color)
|
||||
{
|
||||
GList *list;
|
||||
GtkTextTag *tag;
|
||||
gchar name[256];
|
||||
GdkColor gdk_color;
|
||||
guchar r, g, b;
|
||||
|
||||
gimp_rgb_get_uchar (color, &r, &g, &b);
|
||||
|
||||
for (list = buffer->preedit_bg_color_tags; list; list = g_list_next (list))
|
||||
{
|
||||
GimpRGB tag_color;
|
||||
guchar tag_r, tag_g, tag_b;
|
||||
|
@ -1055,16 +1143,16 @@ gimp_text_buffer_get_bg_color_tag (GimpTextBuffer *buffer,
|
|||
"background-set", TRUE,
|
||||
NULL);
|
||||
|
||||
buffer->bg_color_tags = g_list_prepend (buffer->bg_color_tags, tag);
|
||||
buffer->preedit_bg_color_tags = g_list_prepend (buffer->preedit_bg_color_tags, tag);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_text_buffer_set_bg_color (GimpTextBuffer *buffer,
|
||||
const GtkTextIter *start,
|
||||
const GtkTextIter *end,
|
||||
const GimpRGB *color)
|
||||
gimp_text_buffer_set_preedit_bg_color (GimpTextBuffer *buffer,
|
||||
const GtkTextIter *start,
|
||||
const GtkTextIter *end,
|
||||
const GimpRGB *color)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
|
@ -1077,7 +1165,7 @@ gimp_text_buffer_set_bg_color (GimpTextBuffer *buffer,
|
|||
|
||||
gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (buffer));
|
||||
|
||||
for (list = buffer->bg_color_tags; list; list = g_list_next (list))
|
||||
for (list = buffer->preedit_bg_color_tags; list; list = g_list_next (list))
|
||||
{
|
||||
gtk_text_buffer_remove_tag (GTK_TEXT_BUFFER (buffer), list->data,
|
||||
start, end);
|
||||
|
@ -1085,7 +1173,7 @@ gimp_text_buffer_set_bg_color (GimpTextBuffer *buffer,
|
|||
|
||||
if (color)
|
||||
{
|
||||
GtkTextTag *tag = gimp_text_buffer_get_bg_color_tag (buffer, color);
|
||||
GtkTextTag *tag = gimp_text_buffer_get_preedit_bg_color_tag (buffer, color);
|
||||
|
||||
gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer), tag,
|
||||
start, end);
|
||||
|
@ -1102,6 +1190,7 @@ gimp_text_buffer_set_bg_color (GimpTextBuffer *buffer,
|
|||
#define GIMP_TEXT_ATTR_NAME_FONT "font"
|
||||
#define GIMP_TEXT_ATTR_NAME_STYLE "style"
|
||||
#define GIMP_TEXT_ATTR_NAME_COLOR "foreground"
|
||||
#define GIMP_TEXT_ATTR_NAME_FG_COLOR "fgcolor"
|
||||
#define GIMP_TEXT_ATTR_NAME_BG_COLOR "background"
|
||||
#define GIMP_TEXT_ATTR_NAME_UNDERLINE "underline"
|
||||
|
||||
|
@ -1194,7 +1283,28 @@ gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer,
|
|||
|
||||
return "span";
|
||||
}
|
||||
else if (g_list_find (buffer->bg_color_tags, tag))
|
||||
else if (g_list_find (buffer->preedit_color_tags, tag))
|
||||
{
|
||||
/* "foreground" and "fgcolor" attributes are similar, but I use
|
||||
* one or the other as a trick to differentiate the color chosen
|
||||
* from the user and a display color for preedit. */
|
||||
if (attribute)
|
||||
*attribute = GIMP_TEXT_ATTR_NAME_FG_COLOR;
|
||||
|
||||
if (value)
|
||||
{
|
||||
GimpRGB color;
|
||||
guchar r, g, b;
|
||||
|
||||
gimp_text_tag_get_color (tag, &color);
|
||||
gimp_rgb_get_uchar (&color, &r, &g, &b);
|
||||
|
||||
*value = g_strdup_printf ("#%02x%02x%02x", r, g, b);
|
||||
}
|
||||
|
||||
return "span";
|
||||
}
|
||||
else if (g_list_find (buffer->preedit_bg_color_tags, tag))
|
||||
{
|
||||
if (attribute)
|
||||
*attribute = GIMP_TEXT_ATTR_NAME_BG_COLOR;
|
||||
|
|
|
@ -45,9 +45,10 @@ struct _GimpTextBuffer
|
|||
GList *kerning_tags;
|
||||
GList *font_tags;
|
||||
GList *color_tags;
|
||||
GList *bg_color_tags;
|
||||
|
||||
GtkTextTag *preedit_underline_tag;
|
||||
GList *preedit_color_tags;
|
||||
GList *preedit_bg_color_tags;
|
||||
|
||||
gboolean insert_tags_set;
|
||||
GList *insert_tags;
|
||||
|
@ -134,12 +135,18 @@ void gimp_text_buffer_set_color (GimpTextBuffer *buffer,
|
|||
const GtkTextIter *end,
|
||||
const GimpRGB *color);
|
||||
|
||||
GtkTextTag * gimp_text_buffer_get_bg_color_tag (GimpTextBuffer *buffer,
|
||||
const GimpRGB *color);
|
||||
void gimp_text_buffer_set_bg_color (GimpTextBuffer *buffer,
|
||||
const GtkTextIter *start,
|
||||
const GtkTextIter *end,
|
||||
const GimpRGB *color);
|
||||
GtkTextTag * gimp_text_buffer_get_preedit_color_tag (GimpTextBuffer *buffer,
|
||||
const GimpRGB *color);
|
||||
void gimp_text_buffer_set_preedit_color (GimpTextBuffer *buffer,
|
||||
const GtkTextIter *start,
|
||||
const GtkTextIter *end,
|
||||
const GimpRGB *color);
|
||||
GtkTextTag * gimp_text_buffer_get_preedit_bg_color_tag (GimpTextBuffer *buffer,
|
||||
const GimpRGB *color);
|
||||
void gimp_text_buffer_set_preedit_bg_color (GimpTextBuffer *buffer,
|
||||
const GtkTextIter *start,
|
||||
const GtkTextIter *end,
|
||||
const GimpRGB *color);
|
||||
|
||||
const gchar * gimp_text_buffer_tag_to_name (GimpTextBuffer *buffer,
|
||||
GtkTextTag *tag,
|
||||
|
|
Loading…
Reference in New Issue