Re: Changing the window background for all windows



On Tue, 19 Sep 2000 20:27:28 +0200, Werner Lehmann <wl bwl uni-kiel de> wrote:
Hi,

is there an easy way to change the background color for all
windows of the application? Buttons and other widgets may/should
keep their default light gray but I would like to change
the color of GtkWindow, Frames etc.

Maybe similar to changing the font? acano systec com kindly donated this
code to change the application font globally:

  GtkStyle *default_style, *new_style;
  gchar *fontname;

  fontname = ...
  default_style = gtk_widget_get_default_style ();
  new_style = gtk_style_copy (default_style);
  new_style->font = gdk_font_load (fontname);
  gtk_widget_push_style (new_style);

I figured maybe gtk_style_set_background or gtk_style_apply_default_background
can be used here but both need a GdkWindow reference (so they don't work globally)
and I am not sure about the meaning of their other params. They don't take a color 
so this does not help probably.

to change the background color you can do something like this:
        GdkColor color;
        ...

        default_style = gtk_widget_get_default_style ();
        new_style = gtk_style_copy (default_style);
        color.red = 0x0000;
        color.blue = 0xffff;
        color.green = 0x0000;
        // color.pixel = ???  do you have to do this??
        new_style->bg[GTK_STATE_NORMAL] = color;
        gtk_widget_push_style (new_style);

        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        ...


Since you only want certain classes (GtkWindow, GtkFrame, ...) to
have the new style you could try something like this:

#include <gtk/gtk.h>

gchar *rcstring = "
style 'blue_bg' {
        bg[NORMAL] = { 0.0, 0.0, 1.0 }
}

widget_class 'GtkWindow' style 'blue_bg'
widget_class 'GtkFrame' style 'blue_bg'
# etc ...
";

int main (int argc, char *argv[])
{
        GtkWidget *win, *vbox, *button, *frame;

        gtk_init (&argc, &argv);
        gtk_rc_parse_string (rcstring);

        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (win), vbox);

        button = gtk_button_new_with_label ("default bg");
        gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

        frame = gtk_frame_new ("frame with blue bg");
        gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

        gtk_widget_show_all (win);
        gtk_main ();
        return 0;
}


Regards,
WL

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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