GTK+ 2.0 Tutorial
<<< Previous |  | Next >>>

# GTK's rc Files

GTK has its own way of dealing with application defaults, by using rc files. These can be used to set the colors of just about any widget, and can also be used to tile pixmaps onto the background of some widgets.

# Functions For rc Files

When your application starts, you should include a call to:

    void gtk_rc_parse( char *filename );

Passing in the filename of your rc file. This will cause GTK to parse this file, and use the style settings for the widget types defined there.

If you wish to have a special set of widgets that can take on a different style from others, or any other logical division of widgets, use a call to:

    void gtk_widget_set_name( GtkWidget *widget,
                              gchar     *name );

Passing your newly created widget as the first argument, and the name you wish to give it as the second. This will allow you to change the attributes of this widget by name through the rc file.

If we use a call something like this:

    button = gtk_button_new_with_label ("Special Button");
    gtk_widget_set_name (button, "special button");

Then this button is given the name "special button" and may be addressed by name in the rc file as "special button.GtkButton". [<--- Verify ME!]

The example rc file below, sets the properties of the main window, and lets all children of that main window inherit the style described by the "main button" style. The code used in the application is:

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_name (window, "main window");

And then the style is defined in the rc file using:

    widget "main window.*GtkButton*" style "main_button"

Which sets all the Button widgets in the "main window" to the "main_buttons" style as defined in the rc file.

As you can see, this is a fairly powerful and flexible system. Use your imagination as to how best to take advantage of this.

<<< Previous | Home | Next >>>
Utility and Error Functions |  | GTK's rc File Format