----- Original Message ----
From: Samuel Lidén Borell <[EMAIL PROTECTED]>
To: gtk-app-devel-list@gnome.org
Sent: Tuesday, October 24, 2006 1:49:54 PM
Subject: GtkTextView: Applying tags at the cursor

Hi,

I'm working on a web site creation software that uses Gtk, Glade and
Python for the UI. I'm using the GtkTextView widget to let the user edit
text with basic formatting but I have a question:

How do I apply a tag at the cursor so that inserted text gets it's
formatting? Right now I surround the cursor with two zero-width spaces
(an invisible Unicode character) and then I apply the tag to the spaces.
This gives new text the right formatting, but it's an ugly solution that
has some bugs...

-----------------
I'm not sure there you can just add a tag at the current cursor position.  I'm 
creating the GTK2 bindings for the language Pike, and in my tests I created an 
array of tags that I need to apply at a certain position, then I added the text 
for that position, then applied that tags for that text range.  Something like 
this:

void insert_text(char *text) {
  GtkTextIter *start,*end,*iter;
  GtkTextMark *mark;

  mark=gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(buffer));
  gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(buffer),start,mark);
  *start=*iter;
  gtk_text_buffer_insert(GTK_TEXT_BUFFER(buffer),text,-1);
  mark=gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(buffer));
  gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(buffer),end,mark);
  /* foreach tag */
    gtk_text_buffer_apply_tag(GTK_TEXT_BUFFER(buffer),tag,start,end);
  /* end */
}

I fudged on the foreach array iteration.  I have it simpler in pike, but 
basically the same thing.






_______________________________________________
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