Oh, ok, so you want to move the text from the entry GtkTextView into the display pane while keeping tags. Well, this is a 2 step process. Let us assume we have 2 GtkTextView widgets called view1 and view2. First, to apply the color to the user's entry pane, you use the following (note: I didn't compile this code, so you will have to check for syntax errors...):
Code:
GdkColor color;
GtkTextTag *tag;
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));
gtk_color_button_get_color (colorbutton,&color);
tag = gtk_text_buffer_create_tag (buffer, NULL, "foreground-gdk", color);
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
This code creates a new
foreground-gdk tag on the first text buffer & applies the tag from start to end. If there is selected text, the selection will become that color. If there is no selection (meaning that start == end), then it will be applied to the current cursor position and any text typed from that position will be the color. This works for any tags found in the GtkTextTag API documentation.
Then, you need to move the text to the new buffer:
Code:
GtkTextIter start, end, insert;
GtkTextBuffer buffer1, buffer2;
GtkTextTagTable *table1, *table2;
gchar *text;
buffer1 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));
buffer2 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view2));
table1 = gtk_text_buffer_get_tag_table (buffer1);
table2 = gtK_text_buffer_get_tag_table (buffer2);
gtk_text_tag_table_foreach (table1, (GtkTextTagTableForeach) add_tag, table2);
gtk_text_buffer_get_bounds (buffer1, &start, &end);
gtk_text_buffer_get_end_iter (buffer2, &insert);
text = gtk_text_buffer_get_text (buffer1, &start, &end, TRUE);
gtk_text_buffer_set_text (buffer2, text, -1);
gtk_text_buffer_delete (buffer1, &start, &end);
This will get the tag tables for each buffers, and call a function add_tag(), shown below, which will copy all of the tags over. It will then copy over the text from buffer1 into buffer2 and then remove the text in buffer1.
Code:
static void
add_tag (GtkTextTag *tag, GtkTextTagTable *table2)
{
gtk_text_tag_table_add (table2, tag);
}
That _should_ work, although you may need to alter a thing or two.
I also have to give a small plug ... in March of 2007, my book
Foundations of GTK+ Development will be released. You can find information about it, including preordering it, at
http://book.andrewkrause.net. Good luck! :)