Changing the background color of a Label



Hello,

I'm imagining simply a label with a background color (usually Grey) and a
foreground color (the color of the writing usually black). But I want to
change this! I've managed to change the foreground color to white but didn't
manage to change the background to green using GtkStyle under Gtk-1.2.
Any help would be greatly appreciate :-)


Here is the code I'm using :

void
on_smnuAbout_activate                  (GtkMenuItem     *menuitem,
                                        ast_pointer         user_data)
{
 GtkWidget    *wndAbout    = NULL;
 GtkWidget    *ABOUT_lblNameVersion = NULL;

 GdkColor  CouleurTitreFond;
 GdkColor  CouleurTitrePolice;
 GdkColormap    *ColorMap    = NULL;

 GtkStyle    *gtkTitleStyle   = NULL;



 /* Creation of the About window (Glade generated function) */
 wndAbout = create_wndAbout();

 ABOUT_lblNameVersion = lookup_widget(wndAbout, "ABOUT_lblNameVersion");


 /* Retrieve the colormap of the widget to alloc new color to it */
 ColorMap = gtk_widget_get_colormap(ABOUT_lblNameVersion);

 /* Make a green color */
 CouleurTitreFond.red  = 29184;
 CouleurTitreFond.green  = 41984;
 CouleurTitreFond.blue  = 33536;
 gdk_colormap_alloc_color(ColorMap, &CouleurTitreFond, FALSE, TRUE);

 gdk_color_parse("white", &CouleurTitrePolice);
 gdk_colormap_alloc_color(ColorMap, &CouleurTitrePolice, FALSE, TRUE);

 /* I don't know if this is needed, but in case... */
 gtk_widget_set_colormap(ABOUT_lblNameVersion, ColorMap);


 gtkTitleStyle = gtk_style_copy(ABOUT_lblNameVersion->style);

 gtkTitleStyle->bg[GTK_STATE_NORMAL]   = CouleurTitreFond;
 gtkTitleStyle->bg[GTK_STATE_ACTIVE]   = CouleurTitreFond;
 gtkTitleStyle->bg[GTK_STATE_PRELIGHT]  = CouleurTitreFond;
 gtkTitleStyle->bg[GTK_STATE_SELECTED]  = CouleurTitreFond;
 gtkTitleStyle->bg[GTK_STATE_INSENSITIVE] = CouleurTitreFond;

 gtkTitleStyle->fg[GTK_STATE_NORMAL]   = CouleurTitrePolice;
 gtkTitleStyle->fg[GTK_STATE_ACTIVE]   = CouleurTitrePolice;
 gtkTitleStyle->fg[GTK_STATE_PRELIGHT]  = CouleurTitrePolice;
 gtkTitleStyle->fg[GTK_STATE_SELECTED]  = CouleurTitrePolice;
 gtkTitleStyle->fg[GTK_STATE_INSENSITIVE] = CouleurTitrePolice;

 gtk_widget_set_style(ABOUT_lblNameVersion, gtkTitleStyle);

 gtk_style_unref(gtkTitleStyle);

 gtk_widget_show_all(wndAbout);

}



Best regards,
---
Jean-Christophe Berthon

Cap Gemini -- Ernst & Young
France
Skill IS -- Image Quality
Email: Jean-Christophe Berthon cgey com
Tel: (+33) 561 31 6639






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