----- Original Message ----
From: Carlos Pereira <[EMAIL PROTECTED]>
To: gtk-app-devel-list@gnome.org
Sent: Monday, March 17, 2008 8:46:02 AM
Subject: GtkTextView: inserting text with different styles

Hi,
Let's say I have a GtkTextView, with two color tags, red and blue:

text_view = gtk_text_view_new ();
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
gtk_text_buffer_create_tag (buffer, "my_red", "foreground", "#ff0000", 
NULL);
gtk_text_buffer_create_tag (buffer, "my_blue", "foreground", "#00ff00", 
NULL);

Now I want too insert "Hello World":
gtk_text_buffer_insert_at_cursor (buffer, "Hello ", -1);
gtk_text_buffer_insert_at_cursor (buffer, "World", -1);

but I want Hello to be red and World to be blue.

What is the usual procedure to achieve this?
(perhaps get the iterators for the last insertion? it should be quite
easy but apparently I could not find information about this...)

Thanks,
Carlos
-----------------------
I would do this:

GtkTextIter iter;
GtkTextTag *myred,*myblue;
GtkTextTagTable *tb;

/* blah blah blah */
/* start at top */
gtk_text_buffer_get_iter_at_offset(buffer,&iter,0);
tb=gtk_text_buffer_get_tag_table(buffer);
myred=gtk_text_tag_new("my_red");
g_object_set(G_OBJECT(myred),"foreground","#ff0000",NULL);
myblue=gtk_text_tag_new("my_blue");
g_object_set(G_OBJECT(myblue),"foreground","#00ff00",NULL);
gtk_text_tag_table_add(GTK_TEXT_TAG_TABLE(tb),myred);
gtk_text_tag_table_add(GTK_TEXT_TAG_TABLE(tb),myblue);

gtk_text_buffer_insert(buffer,&iter,"random text...",-1);
gtk_text_buffer_insert_with_tags(buffer,&iter,"Hello ",-1,myred,NULL);
gtk_text_buffer_insert_with_tags(buffer,&iter,"World",-1,myblue,NULL);




There may be a little more efficient way to do this (add multiple tags to a tag 
table at the same time, perhaps?), but this is just off the top off my head...





      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to