Re: Entry and Text Widgets with color



Hi Carlos

nice example I think that is like I want do .
The color of my text is fix the user should not change.
Do yo have an example to set the Gtk_Style I think this job
is done at the subroutine
  gamgi_gtk_dialog_text_insert

See below 

Do you know is this also works with clist text I think the basic
structures
behind will be the same as in text or entry widget.

Best Regards
Günther Rapp

I don't remember, you must see if you need to change style->base 
(as in GtkText), style->bg (as in GtkButton), or something else. 

There are a couple of issues like this to 
check, but eventually it should work ;-)

Carlos

-----------example---------
GtkWidget *text;
GtkStyle *style;
GdkColor color;

/* set text */
text = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT (text), FALSE);
gtk_text_set_line_wrap (GTK_TEXT (text), TRUE);
gtk_text_set_word_wrap (GTK_TEXT (text), TRUE);

/* set background color, which is constant, between 0 and 65535 */
color.pixel = 0;
color.red = my_red;
color.green = my_green;
color.blue = my_blue;

style = gtk_style_copy (gtk_widget_get_style (text));
style->base[GTK_STATE_NORMAL] = color;
style->base[GTK_STATE_ACTIVE] = color;
style->base[GTK_STATE_PRELIGHT] = color;
style->base[GTK_STATE_SELECTED] = color;
style->base[GTK_STATE_INSENSITIVE] = color;
gtk_widget_set_style (text, style);
gtk_style_unref (style);

/* set multiple foreground colors and then choose which one to use */
color.pixel = 0;
color.red = my_red;
color.green = my_green;
color.blue = my_blue;

To insert text:
gtk_text_insert (GTK_TEXT (text), font, &color, NULL, "Hello World", -1);



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