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 May 21, 2013 4:15 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: gtk_text_buffer_insert_with_tags_by_name questions
PostPosted: Sat Nov 21, 2009 10:51 pm 
Offline
GTK+ Geek

Joined: Mon Jan 05, 2009 9:37 am
Posts: 68
Location: Austria
Dear All,

I want to implement a primitive console with some very rudimentary highlighting, and I would like to ask two questions about the usage of gtk_text_buffer_insert_with_tags_by_name. Here is a segment of my code
Code:
   case GDK_parenleft:
         // Paranthesis should be closed
         gtk_text_buffer_insert_with_tags_by_name (gnuwid->buffer,&iter_current, "()", 2, "fg_red", NULL);
         gtk_text_iter_backward_char(&iter_current);
         gtk_text_buffer_place_cursor (gnuwid->buffer, &iter_current);


and what it is supposed to do is to put a ( ) pair on the text box, whenever ( is entered, and then step the cursor back by one, so that the user can continue typing inside the () pair. My problem is that the input between will be red, even if I enter the next character with
Code:
         gtk_text_buffer_insert_with_tags_by_name (gnuwid->buffer,&iter_current, event->string, 1, "fg_blue", NULL);

Is there a way to make the text in the brackets blue? (I used
Code:
gtk_text_buffer_create_tag (gnuwidget->buffer, "fg_red","foreground", "red", NULL); 
gtk_text_buffer_create_tag (gnuwidget->buffer, "fg_blue","foreground", "blue", NULL); 

to define tags for the buffer.)

The second problem is related to this. What I would like to do is to implement a function for the GDK_Up code such that it places previously entered lines on the prompt. However, I would like to keep the highlighting (e.g., that brackets are red, as above). If I use this code
Code:
      case GDK_Up:
         if(gnuwid->line_no > 0) gnuwid->line_no--;
         gtk_text_buffer_get_iter_at_line(gnuwid->bufferRaw, &iterRaw_start, gnuwid->line_no);
         iterRaw_end = iterRaw_start;
         gtk_text_iter_forward_to_line_end (&iterRaw_end);
         text_command = gtk_text_buffer_get_text(gnuwid->bufferRaw, &iterRaw_start, &iterRaw_end, FALSE);
         gtk_text_iter_set_line_offset (&iter_current, SHIFT-1);
         iter_end = iter_current;
         gtk_text_iter_forward_to_line_end (&iter_end);
         gtk_text_buffer_delete(gnuwid->buffer, &iter_current, &iter_end);
         gtk_text_buffer_insert (gnuwid->buffer, &iter_current, text_command, -1);

then I obviously lose the colours. So, my question is whether it is possible to add lines to the buffer in such a way that it keeps all formatting (only colour, in this case) information, and then retrieve that information from the buffer.
Thanks,
Zoltán


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 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