gtk_text_buffer_apply_tag_by_name slow to take effect



All, I wrote a little function to change some text attributes in a GtkTextBuffer based on the state of some GtkToggleButtons.  When I modify the “weight” attribute to bold, it takes effect immediately.  When I attempt to modify the “foreground” attribute to red I see no effect until I press one of the other toggles (or the same one for that matter).  I can also change the “scale” attribute no problem, but neither the foreground or background colors take effect until I click something else.  Here are the salient parts of the code:

void

change_text_attribute(gint i_attr, GtkToggleButton *i_button)

{

   GtkWidget *top_dog = gtk_widget_get_toplevel(GTK_WIDGET(i_button));

   GtkWidget *msgText = lookup_widget(top_dog, "msgText_entry");

   GtkTextBuffer *msgBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (msgText));

   GtkTextIter msgStart, msgEnd;

   GtkTextTag *tag;

   gboolean l_button_pressed = gtk_toggle_button_get_active(i_button);

   gtk_text_buffer_get_bounds(msgBuffer, &msgStart, &msgEnd);

 

   switch (i_attr)

   {

    case TEXT_BOLD:

       if (l_button_pressed)

       {

          if (gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(msgBuffer), "bold") == NULL)

          {

             tag = gtk_text_buffer_create_tag(msgBuffer, "bold", "weight", PANGO_WEIGHT_BOLD, NULL);

          }

          gtk_text_buffer_apply_tag_by_name(msgBuffer, "bold", &msgStart, &msgEnd);

       }

       else

       {

          gtk_text_buffer_remove_tag_by_name(msgBuffer, "bold", &msgStart, &msgEnd); 

       }

       break;

    case TEXT_RED:

       if (l_button_pressed)

       {

          if (gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(msgBuffer), "red") == NULL)

          {

             tag = gtk_text_buffer_create_tag(msgBuffer, "red", "foreground", "red", NULL); 

          }

          gtk_text_buffer_apply_tag_by_name(msgBuffer, "red", &msgStart, &msgEnd);

       }

       else

       {

          gtk_text_buffer_remove_tag_by_name(msgBuffer, "red", &msgStart, &msgEnd); 

       }

       break;

   }

...

 

 

Any ideas?

 

Thanks – Warren

 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]