GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Dec 23, 2014 1:34 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: GtkTextView: how to apply format on newly typed text
PostPosted: Thu Jun 12, 2008 10:05 pm 
Offline

Joined: Thu Jun 12, 2008 9:58 pm
Posts: 4
I have been searching the GTK+ documentation and the web for this for several days and can't find a single hint.

Here is the problem:
GtkTextView/Buffer only talks about how to apply tags to a certain region of text by supplying start and end textiter. What I want to do is: one the Bold format button is toggled, all the newly entered text should be in Bold format. But I don't know what to use for the "end" textiter. I have tried to make the end and start the same, but they don't modify the newly entered text at all. I am quite frustrated. Anyone can offer some hint please?

Thanks in advance!

Lianqi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 12:37 am 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
you might be able to use the built-in insert and selection_bound marks, see the bottom of this page:
http://www.bravegnu.org/gtktext/x276.html#AEN366
you can get these marks with this:
http://library.gnome.org/devel/gtk/stab ... r-get-mark
then get an iter using this:
http://library.gnome.org/devel/gtk/stab ... er-at-mark


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 6:12 pm 
Offline

Joined: Thu Jun 12, 2008 9:58 pm
Posts: 4
Thanks. I am aware of these marks. But the problem is, there is no active selection if user just type new inputs.

Lianqi

dreblen wrote:
you might be able to use the built-in insert and selection_bound marks, see the bottom of this page:
http://www.bravegnu.org/gtktext/x276.html#AEN366
you can get these marks with this:
http://library.gnome.org/devel/gtk/stab ... r-get-mark
then get an iter using this:
http://library.gnome.org/devel/gtk/stab ... er-at-mark


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 8:03 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
could you connect the "insert-text" signal
http://library.gnome.org/devel/gtk/stab ... nsert-text
then have your callback be something like this:
Code:
void insert_text_cb(GtkTextBuffer *buf, GtkTextIter *start, gchar *text, gint len, gpointer data)
{
    GtkTextIter end;

    gtk_text_buffer_get_iter_at_line_offset(buf, &end, gtk_text_iter_get_line(start), gtk_text_iter_get_line_offset(start)+len);
    gtk_text_buffer_apply_tag_by_name(buf, "bold_tag", start, &end);
}

I don't know if this will work or not, mostly because I don't know if the 'start' iter is at the end of the text or the beginning.
I wrote this assuming it was at the beginning, if it's at the end, you'll need to change it to end, and change the old end iter to '-len' from '+len'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 13, 2008 8:32 pm 
Offline

Joined: Thu Jun 12, 2008 9:58 pm
Posts: 4
This is worthing trying. My only concern is whether the tag will combine if they are next to each other, otherwise, the textbuffer will be messed up with all the tags.
Thanks a lot

Lianqi

dreblen wrote:
could you connect the "insert-text" signal
http://library.gnome.org/devel/gtk/stab ... nsert-text
then have your callback be something like this:
Code:
void insert_text_cb(GtkTextBuffer *buf, GtkTextIter *start, gchar *text, gint len, gpointer data)
{
    GtkTextIter end;

    gtk_text_buffer_get_iter_at_line_offset(buf, &end, gtk_text_iter_get_line(start), gtk_text_iter_get_line_offset(start)+len);
    gtk_text_buffer_apply_tag_by_name(buf, "bold_tag", start, &end);
}

I don't know if this will work or not, mostly because I don't know if the 'start' iter is at the end of the text or the beginning.
I wrote this assuming it was at the beginning, if it's at the end, you'll need to change it to end, and change the old end iter to '-len' from '+len'


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 15, 2008 5:29 am 
Offline

Joined: Thu Jun 12, 2008 9:58 pm
Posts: 4
This works at expected. Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group