From fee9accbd15097a392d8ce615741f5d4481003ec Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 21 Jul 2006 16:12:44 +0000 Subject: [PATCH] New function to destroy an rc context. 2006-07-21 Matthias Clasen * gtk/gtkrc.h: * gtk/gtkrc.c (_gtk_rc_context_destroy): New function to destroy an rc context. * gtk/gtksettings.c (gtk_settings_finalize): Destroy the rc context. (gtk_settings_get_for_screen): Unref the settings when the screen goes away. (#348096, Chris Wilson) --- ChangeLog | 15 ++++++--- ChangeLog.pre-2-10 | 15 ++++++--- gtk/gtkrc.c | 82 ++++++++++++++++++++++++++++++++++++---------- gtk/gtkrc.h | 1 + gtk/gtksettings.c | 5 ++- 5 files changed, 90 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c2248871f..c703eb51e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-07-21 Matthias Clasen + + * gtk/gtkrc.h: + * gtk/gtkrc.c (_gtk_rc_context_destroy): New function to + destroy an rc context. + + * gtk/gtksettings.c (gtk_settings_finalize): Destroy the rc context. + (gtk_settings_get_for_screen): Unref the settings when the screen + goes away. (#348096, Chris Wilson) + 2006-07-21 Richard Hult * gdk/quartz/gdkgc-quartz.c: (gdk_quartz_gc_get_values), @@ -9,11 +19,6 @@ 2006-07-21 Matthias Clasen - * gtk/gtkstyle.c: - * gtk/gtkrc.c: - * gtk/gtkwidget.c: Replace gtk_rc_style_ref/unref by - g_object_ref/unref. - * gtk/gtkimcontextsimple.c (gtk_im_context_simple_get_preedit_string): 0-terminate outbuf in all cases. (#348227, Nguyen Thái Ngoc Duy) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 0c2248871f..c703eb51e6 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +2006-07-21 Matthias Clasen + + * gtk/gtkrc.h: + * gtk/gtkrc.c (_gtk_rc_context_destroy): New function to + destroy an rc context. + + * gtk/gtksettings.c (gtk_settings_finalize): Destroy the rc context. + (gtk_settings_get_for_screen): Unref the settings when the screen + goes away. (#348096, Chris Wilson) + 2006-07-21 Richard Hult * gdk/quartz/gdkgc-quartz.c: (gdk_quartz_gc_get_values), @@ -9,11 +19,6 @@ 2006-07-21 Matthias Clasen - * gtk/gtkstyle.c: - * gtk/gtkrc.c: - * gtk/gtkwidget.c: Replace gtk_rc_style_ref/unref by - g_object_ref/unref. - * gtk/gtkimcontextsimple.c (gtk_im_context_simple_get_preedit_string): 0-terminate outbuf in all cases. (#348227, Nguyen Thái Ngoc Duy) diff --git a/gtk/gtkrc.c b/gtk/gtkrc.c index 0b5280b001..e94592d86f 100644 --- a/gtk/gtkrc.c +++ b/gtk/gtkrc.c @@ -720,6 +720,70 @@ gtk_rc_context_get (GtkSettings *settings) return settings->rc_context; } +static void +gtk_rc_clear_rc_files (GtkRcContext *context) +{ + GSList *list; + + list = context->rc_files; + while (list) + { + GtkRcFile *rc_file = list->data; + + if (rc_file->canonical_name != rc_file->name) + g_free (rc_file->canonical_name); + g_free (rc_file->directory); + g_free (rc_file->name); + g_free (rc_file); + + list = list->next; + } + + g_slist_free (context->rc_files); + context->rc_files = NULL; +} + +void +_gtk_rc_context_destroy (GtkSettings *settings) +{ + GtkRcContext *context; + + g_return_if_fail (GTK_IS_SETTINGS (settings)); + + context = settings->rc_context; + if (!context) + return; + + _gtk_settings_reset_rc_values (context->settings); + gtk_rc_clear_styles (context); + gtk_rc_clear_rc_files (context); + + if (context->default_style) + g_object_unref (context->default_style); + + g_strfreev (context->pixmap_path); + + g_free (context->theme_name); + g_free (context->key_theme_name); + g_free (context->font_name); + + if (context->color_hash) + g_hash_table_unref (context->color_hash); + + g_signal_handlers_disconnect_by_func (settings, + gtk_rc_settings_changed, context); + g_signal_handlers_disconnect_by_func (settings, + gtk_rc_font_name_changed, context); + g_signal_handlers_disconnect_by_func (settings, + gtk_rc_color_hash_changed, context); + + rc_contexts = g_slist_remove (rc_contexts, context); + + g_free (context); + + settings->rc_context = NULL; +} + static void gtk_rc_parse_named (GtkRcContext *context, const gchar *name, @@ -1646,7 +1710,6 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings, GtkRcFile *rc_file; GSList *tmp_list; GtkRcContext *context; - struct stat statbuf; g_return_val_if_fail (GTK_IS_SETTINGS (settings), FALSE); @@ -1684,22 +1747,7 @@ gtk_rc_reparse_all_for_settings (GtkSettings *settings, context->reloading = TRUE; _gtk_settings_reset_rc_values (context->settings); - tmp_list = context->rc_files; - while (tmp_list) - { - rc_file = tmp_list->data; - - if (rc_file->canonical_name != rc_file->name) - g_free (rc_file->canonical_name); - g_free (rc_file->directory); - g_free (rc_file->name); - g_free (rc_file); - - tmp_list = tmp_list->next; - } - - g_slist_free (context->rc_files); - context->rc_files = NULL; + gtk_rc_clear_rc_files (context); gtk_rc_parse_default_files (context); diff --git a/gtk/gtkrc.h b/gtk/gtkrc.h index 3b8e67e6c0..2fd8f3e440 100644 --- a/gtk/gtkrc.h +++ b/gtk/gtkrc.h @@ -248,6 +248,7 @@ const GtkRcProperty* _gtk_rc_style_lookup_rc_property (GtkRcStyle *rc_style, GSList * _gtk_rc_style_get_color_hashes (GtkRcStyle *rc_style); const gchar* _gtk_rc_context_get_default_font_name (GtkSettings *settings); +void _gtk_rc_context_destroy (GtkSettings *settings); G_END_DECLS diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index 2b038f9c20..80e3102f11 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -524,6 +524,8 @@ gtk_settings_finalize (GObject *object) g_value_unset (&settings->property_values[i].value); g_free (settings->property_values); + _gtk_rc_context_destroy (settings); + g_datalist_clear (&settings->queued_settings); G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object); @@ -551,7 +553,8 @@ gtk_settings_get_for_screen (GdkScreen *screen) { settings = g_object_new (GTK_TYPE_SETTINGS, NULL); settings->screen = screen; - g_object_set_data (G_OBJECT (screen), I_("gtk-settings"), settings); + g_object_set_data_full (G_OBJECT (screen), I_("gtk-settings"), + settings, g_object_unref); gtk_rc_reparse_all_for_settings (settings, TRUE); settings_update_double_click (settings);