New function to reset the RC styles for a heirarchy

Fri May  1 12:06:43 1998  Owen Taylor  <otaylor@gtk.org>

	* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
	function to reset the RC styles for a heirarchy

        Clear the window background if necessary in
	gtk_window_style_set.

	* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
	rereads all previously read RC files.

	* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
	(Should it just be called gdk_get_toplevels?)

	* gtk/testgtk.c: New test to reload RC files.
This commit is contained in:
Owen Taylor 1998-05-01 16:15:39 +00:00 committed by Owen Taylor
parent 61554862e6
commit de210bbdec
17 changed files with 394 additions and 5 deletions

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -1,3 +1,19 @@
Fri May 1 12:06:43 1998 Owen Taylor <otaylor@gtk.org>
* gtk/gtkwindow.[ch] (gtk_widget_reset_rc_styles): New
function to reset the RC styles for a heirarchy
Clear the window background if necessary in
gtk_window_style_set.
* gtk/gtkrc.[ch]: New function gtk_rc_reparse_all() which
rereads all previously read RC files.
* gdk/gdkwindow.c gdk/gdk.h: New function gdk_window_get_toplevels().
(Should it just be called gdk_get_toplevels?)
* gtk/testgtk.c: New test to reload RC files.
Fri May 1 13:57:36 1998 Tim Janik <timj@gtk.org>
* gtk/gtkclist.h:

View File

@ -25,13 +25,17 @@ gtk_widget_set_rc_style ()
restore the default style otherwise.
This will override a previously set user style or rc style.
gtk_widget_reset_rc_styles ()
Descends through a widget heirarchy and sets the rc style
on all widgets that don't have a user style set.
gtk_widget_restore_default_style ()
Reset the widget's style to the default style, this is only usefull if
the widgets default style had been saved by previous calls to
gtk_widget_set_style() or gtk_widget_set_rc_style().
gtk_widget_ensure_style ()
Ensure taht the widget either has a user style set, or an rc lookup
Ensure that the widget either has a user style set, or an rc lookup
has been performed.
gtk_rc_get_style ()
@ -55,7 +59,7 @@ gtk_widget_set_parent ()
that do not have a user style set.
gtk_style_copy ()
This function can be used to copy a widgets style.
This function can be used to copy a widget's style.
The style can subsequntly be changed (e.g., by modifications to the
red/green/blue values of a certain color) and then be applied to the
widget via gtk_widget_set_style().

View File

@ -299,6 +299,8 @@ void gdk_window_set_decorations (GdkWindow *window,
GdkWMDecoration decorations);
void gdk_window_set_functions (GdkWindow *window,
GdkWMFunction functions);
GList * gdk_window_get_toplevels (void);
/* Cursors
*/

View File

@ -233,7 +233,7 @@ gdk_window_new (GdkWindow *parent,
private->parent = parent;
if (parent_private != &gdk_root_parent)
if (parent_private)
parent_private->children = g_list_prepend (parent_private->children, window);
private->xdisplay = parent_display;
@ -1956,3 +1956,20 @@ gdk_window_set_functions (GdkWindow *window,
gdk_window_set_mwm_hints (window, &hints);
}
GList *
gdk_window_get_toplevels (void)
{
GList *new_list = NULL;
GList *tmp_list;
tmp_list = gdk_root_parent.children;
while (tmp_list)
{
new_list = g_list_prepend (new_list, tmp_list->data);
tmp_list = tmp_list->next;
}
return new_list;
}

View File

@ -233,7 +233,7 @@ gdk_window_new (GdkWindow *parent,
private->parent = parent;
if (parent_private != &gdk_root_parent)
if (parent_private)
parent_private->children = g_list_prepend (parent_private->children, window);
private->xdisplay = parent_display;
@ -1956,3 +1956,20 @@ gdk_window_set_functions (GdkWindow *window,
gdk_window_set_mwm_hints (window, &hints);
}
GList *
gdk_window_get_toplevels (void)
{
GList *new_list = NULL;
GList *tmp_list;
tmp_list = gdk_root_parent.children;
while (tmp_list)
{
new_list = g_list_prepend (new_list, tmp_list->data);
tmp_list = tmp_list->next;
}
return new_list;
}

View File

@ -207,6 +207,8 @@ static GSList *widget_class_sets = NULL;
#define GTK_RC_MAX_PIXMAP_PATHS 128
static gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
/* The files we have parsed, to reread later if necessary */
GSList *rc_files;
void
gtk_rc_init ()
@ -230,6 +232,8 @@ gtk_rc_parse (const gchar *filename)
g_return_if_fail (filename != NULL);
rc_files = g_slist_append (rc_files, g_strdup (filename));
fd = open (filename, O_RDONLY);
if (fd < 0)
return;
@ -239,6 +243,93 @@ gtk_rc_parse (const gchar *filename)
close (fd);
}
void
gtk_rc_clear_hash_node (gpointer key,
gpointer data,
gpointer user_data)
{
int i;
GtkRcStyle *rc_style = data;
GList *tmp_list;
g_free (rc_style->name);
g_free (rc_style->font_name);
g_free (rc_style->fontset_name);
for (i=0 ; i<5 ; i++)
g_free (rc_style->bg_pixmap_name[i]);
gtk_style_unref (rc_style->proto_style);
tmp_list = rc_style->styles;
while (tmp_list)
{
GtkRcNode *node = tmp_list->data;
gdk_colormap_unref (node->cmap);
gtk_style_unref (node->style);
g_free (node);
tmp_list = tmp_list->next;
}
g_free (rc_style);
}
void
gtk_rc_reparse_all (void)
{
GSList *tmp_list, *tmp_files;
GtkRcSet *rc_set;
/* Clear out all old rc_styles */
g_hash_table_foreach (rc_style_ht, gtk_rc_clear_hash_node, NULL);
g_hash_table_destroy (rc_style_ht);
rc_style_ht = NULL;
tmp_list = widget_sets;
while (tmp_list)
{
rc_set = (GtkRcSet *)tmp_list->data;
g_free (rc_set->set);
g_free (rc_set);
tmp_list = tmp_list->next;
}
g_slist_free (widget_sets);
widget_sets = NULL;
tmp_list = widget_class_sets;
while (tmp_list)
{
rc_set = (GtkRcSet *)tmp_list->data;
g_free (rc_set->set);
g_free (rc_set);
tmp_list = tmp_list->next;
}
g_slist_free (widget_class_sets);
widget_class_sets = NULL;
/* Now read the RC's again */
gtk_rc_init ();
tmp_files = rc_files;
rc_files = NULL;
tmp_list = tmp_files;
while (tmp_list)
{
gtk_rc_parse ((gchar *)tmp_list->data);
g_free (tmp_list->data);
tmp_list = tmp_list->next;
}
g_slist_free (tmp_files);
}
GtkStyle*
gtk_rc_get_style (GtkWidget *widget)
{

View File

@ -32,6 +32,7 @@ extern "C" {
void gtk_rc_init (void);
void gtk_rc_parse (const gchar *filename);
void gtk_rc_parse_string (const gchar *rc_string);
void gtk_rc_reparse_all (void);
GtkStyle* gtk_rc_get_style (GtkWidget *widget);
void gtk_rc_add_widget_name_style (GtkStyle *style,
const gchar *pattern);

View File

@ -2581,7 +2581,11 @@ gtk_widget_style_set (GtkWidget *widget,
{
if (GTK_WIDGET_REALIZED (widget) &&
!GTK_WIDGET_NO_WINDOW (widget))
gtk_style_set_background (widget->style, widget->window, widget->state);
{
gtk_style_set_background (widget->style, widget->window, widget->state);
if (GTK_WIDGET_DRAWABLE (widget))
gdk_window_clear (widget->window);
}
}
static void
@ -2646,6 +2650,12 @@ gtk_widget_set_style_recurse (GtkWidget *widget,
NULL);
}
void
gtk_widget_reset_rc_styles (GtkWidget *widget)
{
gtk_widget_set_style_recurse (widget, NULL);
}
void
gtk_widget_set_default_style (GtkStyle *style)
{

View File

@ -474,6 +474,9 @@ void gtk_widget_ensure_style (GtkWidget *widget);
GtkStyle* gtk_widget_get_style (GtkWidget *widget);
void gtk_widget_restore_default_style (GtkWidget *widget);
/* Descend recursively and set rc-style on all widgets without user styles */
void gtk_widget_reset_rc_styles (GtkWidget *widget);
/* Tell other Gtk applications to use the same default colors.
*/
void gtk_widget_propagate_default_style (void);

View File

@ -6446,6 +6446,71 @@ create_idle_test ()
gtk_widget_destroy (window);
}
void
reload_rc_file (void)
{
GList *toplevels;
gtk_rc_reparse_all ();
toplevels = gdk_window_get_toplevels();
while (toplevels)
{
GtkWidget *widget;
gdk_window_get_user_data (toplevels->data, (gpointer *)&widget);
if (widget)
gtk_widget_reset_rc_styles (widget);
toplevels = toplevels->next;
}
g_list_free (toplevels);
}
void
create_rc_file ()
{
static GtkWidget *window = NULL;
GtkWidget *button;
if (!window)
{
window = gtk_dialog_new ();
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(destroy_idle_test),
&window);
gtk_window_set_title (GTK_WINDOW (window), "Reload Rc file");
gtk_container_border_width (GTK_CONTAINER (window), 0);
button = gtk_button_new_with_label ("Reload");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(reload_rc_file), NULL);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_grab_default (button);
gtk_widget_show (button);
button = gtk_button_new_with_label ("Close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT (window));
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_show (button);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
}
/*
* Test of recursive mainloop
*/
@ -6550,6 +6615,7 @@ create_main_window ()
{ "progress bar", create_progress_bar },
{ "radio buttons", create_radio_buttons },
{ "range controls", create_range_controls },
{ "rc file", create_rc_file },
{ "reparent", create_reparent },
{ "rulers", create_rulers },
{ "scrolled windows", create_scrolled_windows },

View File

@ -6446,6 +6446,71 @@ create_idle_test ()
gtk_widget_destroy (window);
}
void
reload_rc_file (void)
{
GList *toplevels;
gtk_rc_reparse_all ();
toplevels = gdk_window_get_toplevels();
while (toplevels)
{
GtkWidget *widget;
gdk_window_get_user_data (toplevels->data, (gpointer *)&widget);
if (widget)
gtk_widget_reset_rc_styles (widget);
toplevels = toplevels->next;
}
g_list_free (toplevels);
}
void
create_rc_file ()
{
static GtkWidget *window = NULL;
GtkWidget *button;
if (!window)
{
window = gtk_dialog_new ();
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC(destroy_idle_test),
&window);
gtk_window_set_title (GTK_WINDOW (window), "Reload Rc file");
gtk_container_border_width (GTK_CONTAINER (window), 0);
button = gtk_button_new_with_label ("Reload");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(reload_rc_file), NULL);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_grab_default (button);
gtk_widget_show (button);
button = gtk_button_new_with_label ("Close");
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT (window));
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
button, TRUE, TRUE, 0);
gtk_widget_show (button);
}
if (!GTK_WIDGET_VISIBLE (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
}
/*
* Test of recursive mainloop
*/
@ -6550,6 +6615,7 @@ create_main_window ()
{ "progress bar", create_progress_bar },
{ "radio buttons", create_radio_buttons },
{ "range controls", create_range_controls },
{ "rc file", create_rc_file },
{ "reparent", create_reparent },
{ "rulers", create_rulers },
{ "scrolled windows", create_scrolled_windows },