]> Pileus Git - ~andy/gtk/commitdiff
New function to reset the RC styles for a heirarchy
authorOwen Taylor <otaylor@gtk.org>
Fri, 1 May 1998 16:15:39 +0000 (16:15 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Fri, 1 May 1998 16:15:39 +0000 (16:15 +0000)
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.

17 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/styles.txt
gdk/gdk.h
gdk/gdkwindow.c
gdk/x11/gdkwindow-x11.c
gtk/gtkrc.c
gtk/gtkrc.h
gtk/gtkwidget.c
gtk/gtkwidget.h
gtk/testgtk.c
tests/testgtk.c

index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (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:
index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (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:
index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (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:
index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (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:
index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (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:
index 4008086af01548e850fb34fd7c930da216a7e039..b331044dafe0c0b1848a1b7d55e00da3e49062dd 100644 (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:
index 051dc4b107544774bad0efbaf763182e82ff22b7..e66cafd19a8bac7fdec5dc6e025e2d6f097cd02d 100644 (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().
index 1cfa3e6082a98255bc5b360ce01a91130fc3674b..6d453c069ef2f13f86bc34f38832780a9cdf2709 100644 (file)
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -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
  */
index d95327ca165d99f5152b13c78f6783d60266dcfc..022baa370b419688435f70c968b32926b103e7fa 100644 (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;
+}
+
index d95327ca165d99f5152b13c78f6783d60266dcfc..022baa370b419688435f70c968b32926b103e7fa 100644 (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;
+}
+
index 26bde5aade7bb60a07d19ef0a9c3691b87b8cad8..c0657d89d2d24763e2d4326e86eaccd45dea9daf 100644 (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)
 {
index 4b43b72a1b3085a0e687508cf12e3314492e59d2..335448668d2809607186ab277cca1abb1bf75f42 100644 (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);
index faf2a41a91be88472b35b9b19f021e697cdeaf9e..9e58abad2f60a8b4967d7b55efbe8747c320f736 100644 (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)
 {
index 0ec99d519381a83c0b78c4e4906381c65c43f4b0..9b43d2cd590d17e0644111b8e52c670b16fda1b6 100644 (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);
index 7dc08bf40e76791cff9f11d89d0b33a822007d7e..d158d8e7a4a568aea0c0debaaf3cb479ecc7f290 100644 (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 },
index 7dc08bf40e76791cff9f11d89d0b33a822007d7e..d158d8e7a4a568aea0c0debaaf3cb479ecc7f290 100644 (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 },