📄 gtkrc.c
字号:
GtkRcStylePrivate *new_style; new_style = g_new0 (GtkRcStylePrivate, 1); new_style->ref_count = 1; return (GtkRcStyle *)new_style;}void gtk_rc_style_ref (GtkRcStyle *rc_style){ g_return_if_fail (rc_style != NULL); ((GtkRcStylePrivate *)rc_style)->ref_count++;}/* Like g_slist_remove, but remove all copies of data */static GSList*gtk_rc_slist_remove_all (GSList *list, gpointer data){ GSList *tmp; GSList *prev; prev = NULL; tmp = list; while (tmp) { if (tmp->data == data) { if (list == tmp) list = list->next; if (prev) prev->next = tmp->next; g_slist_free_1 (tmp); if (prev) tmp = prev->next; else tmp = list; } else { prev = tmp; tmp = tmp->next; } } return list;}void gtk_rc_style_unref (GtkRcStyle *rc_style){ GtkRcStylePrivate *private = (GtkRcStylePrivate *)rc_style; gint i; g_return_if_fail (rc_style != NULL); g_return_if_fail (private->ref_count > 0); private->ref_count--; if (private->ref_count == 0) { GSList *tmp_list1, *tmp_list2; if (rc_style->engine) { rc_style->engine->destroy_rc_style (rc_style); gtk_theme_engine_unref (rc_style->engine); } if (rc_style->name) g_free (rc_style->name); if (rc_style->fontset_name) g_free (rc_style->fontset_name); if (rc_style->font_name) g_free (rc_style->font_name); for (i=0 ; i<5 ; i++) if (rc_style->bg_pixmap_name[i]) g_free (rc_style->bg_pixmap_name[i]); /* Now remove all references to this rc_style from * realized_style_ht */ tmp_list1 = private->rc_style_lists; while (tmp_list1) { GSList *rc_styles = tmp_list1->data; GtkStyle *style = g_hash_table_lookup (realized_style_ht, rc_styles); gtk_style_unref (style); /* Remove the list of styles from the other rc_styles * in the list */ tmp_list2 = rc_styles; while (tmp_list2) { GtkRcStylePrivate *other_style = tmp_list2->data; if (other_style != private) other_style->rc_style_lists = gtk_rc_slist_remove_all (other_style->rc_style_lists, rc_styles); tmp_list2 = tmp_list2->next; } /* And from the hash table itself */ g_hash_table_remove (realized_style_ht, rc_styles); g_slist_free (rc_styles); tmp_list1 = tmp_list1->next; } g_slist_free (private->rc_style_lists); g_free (private); }}static voidgtk_rc_clear_hash_node (gpointer key, gpointer data, gpointer user_data){ gtk_rc_style_unref (data);}static voidgtk_rc_free_rc_sets (GSList *slist){ while (slist) { GtkRcSet *rc_set; rc_set = slist->data; gtk_pattern_spec_free_segs (&rc_set->pspec); g_free (rc_set); slist = slist->next; }}static voidgtk_rc_clear_styles (void){ /* Clear out all old rc_styles */ if (rc_style_ht) { g_hash_table_foreach (rc_style_ht, gtk_rc_clear_hash_node, NULL); g_hash_table_destroy (rc_style_ht); rc_style_ht = NULL; } gtk_rc_free_rc_sets (gtk_rc_sets_widget); g_slist_free (gtk_rc_sets_widget); gtk_rc_sets_widget = NULL; gtk_rc_free_rc_sets (gtk_rc_sets_widget_class); g_slist_free (gtk_rc_sets_widget_class); gtk_rc_sets_widget_class = NULL; gtk_rc_free_rc_sets (gtk_rc_sets_class); g_slist_free (gtk_rc_sets_class); gtk_rc_sets_class = NULL;}gbooleangtk_rc_reparse_all (void){ GSList *tmp_list; gboolean mtime_modified = FALSE; GtkRcFile *rc_file; struct stat statbuf; /* Check through and see if any of the RC's have had their * mtime modified. If so, reparse everything. */ tmp_list = rc_files; while (tmp_list) { rc_file = tmp_list->data; if (!lstat (rc_file->name, &statbuf) && (statbuf.st_mtime > rc_file->mtime)) { mtime_modified = TRUE; break; } tmp_list = tmp_list->next; } if (mtime_modified) { gtk_rc_clear_styles(); tmp_list = rc_files; while (tmp_list) { rc_file = tmp_list->data; if (rc_file->reload) gtk_rc_parse_file (rc_file->name, FALSE); tmp_list = tmp_list->next; } } return mtime_modified;}static GSList *gtk_rc_styles_match (GSList *rc_styles, GSList *sets, guint path_length, gchar *path, gchar *path_reversed) { GtkRcSet *rc_set; while (sets) { rc_set = sets->data; sets = sets->next; if (gtk_pattern_match (&rc_set->pspec, path_length, path, path_reversed)) rc_styles = g_slist_append (rc_styles, rc_set->rc_style); } return rc_styles;}GtkStyle*gtk_rc_get_style (GtkWidget *widget){ GtkRcStyle *widget_rc_style; GSList *rc_styles = NULL; static guint rc_style_key_id = 0; /* We allow the specification of a single rc style to be bound * tightly to a widget, for application modifications */ if (!rc_style_key_id) rc_style_key_id = g_quark_from_static_string ("gtk-rc-style"); widget_rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), rc_style_key_id); if (widget_rc_style) rc_styles = g_slist_prepend (rc_styles, widget_rc_style); if (gtk_rc_sets_widget) { gchar *path, *path_reversed; guint path_length; gtk_widget_path (widget, &path_length, &path, &path_reversed); rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_widget, path_length, path, path_reversed); g_free (path); g_free (path_reversed); } if (gtk_rc_sets_widget_class) { gchar *path, *path_reversed; guint path_length; gtk_widget_class_path (widget, &path_length, &path, &path_reversed); rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_widget_class, path_length, path, path_reversed); g_free (path); g_free (path_reversed); } if (gtk_rc_sets_class) { GtkType type; type = GTK_OBJECT_TYPE (widget); while (type) { gchar *path, *path_reversed; guint path_length; path = gtk_type_name (type); path_length = strlen (path); path_reversed = g_strdup (path); g_strreverse (path_reversed); rc_styles = gtk_rc_styles_match (rc_styles, gtk_rc_sets_class, path_length, path, path_reversed); g_free (path_reversed); type = gtk_type_parent (type); } } if (rc_styles) return gtk_rc_style_init (rc_styles); return NULL;}static GSList*gtk_rc_add_rc_sets (GSList *slist, GtkRcStyle *rc_style, const char *pattern){ GtkRcStyle *new_style; GtkRcSet *rc_set; guint i; new_style = gtk_rc_style_new (); *new_style = *rc_style; new_style->name = g_strdup (rc_style->name); new_style->font_name = g_strdup (rc_style->font_name); new_style->fontset_name = g_strdup (rc_style->fontset_name); for (i = 0; i < 5; i++) new_style->bg_pixmap_name[i] = g_strdup (rc_style->bg_pixmap_name[i]); rc_set = g_new (GtkRcSet, 1); gtk_pattern_spec_init (&rc_set->pspec, pattern); rc_set->rc_style = rc_style; return g_slist_prepend (slist, rc_set);}voidgtk_rc_add_widget_name_style (GtkRcStyle *rc_style, const gchar *pattern){ g_return_if_fail (rc_style != NULL); g_return_if_fail (pattern != NULL); gtk_rc_sets_widget = gtk_rc_add_rc_sets (gtk_rc_sets_widget, rc_style, pattern);}voidgtk_rc_add_widget_class_style (GtkRcStyle *rc_style, const gchar *pattern){ g_return_if_fail (rc_style != NULL); g_return_if_fail (pattern != NULL); gtk_rc_sets_widget_class = gtk_rc_add_rc_sets (gtk_rc_sets_widget_class, rc_style, pattern);}voidgtk_rc_add_class_style (GtkRcStyle *rc_style, const gchar *pattern){ g_return_if_fail (rc_style != NULL); g_return_if_fail (pattern != NULL); gtk_rc_sets_class = gtk_rc_add_rc_sets (gtk_rc_sets_class, rc_style, pattern);}static voidgtk_rc_parse_any (const gchar *input_name, gint input_fd, const gchar *input_string){ GScanner *scanner; guint i; gboolean done; scanner = g_scanner_new ((GScannerConfig *) >k_rc_scanner_config); if (input_fd >= 0) { g_assert (input_string == NULL); g_scanner_input_file (scanner, input_fd); } else { g_assert (input_string != NULL); g_scanner_input_text (scanner, input_string, strlen (input_string)); } scanner->input_name = input_name; g_scanner_freeze_symbol_table (scanner); for (i = 0; i < n_symbols; i++) g_scanner_add_symbol (scanner, symbols[i].name, GINT_TO_POINTER (symbols[i].token)); g_scanner_thaw_symbol_table (scanner); done = FALSE; while (!done) { if (g_scanner_peek_next_token (scanner) == G_TOKEN_EOF) done = TRUE; else { guint expected_token; expected_token = gtk_rc_parse_statement (scanner); if (expected_token != G_TOKEN_NONE) { gchar *symbol_name; gchar *msg; msg = NULL; symbol_name = NULL; if (scanner->scope_id == 0) { /* if we are in scope 0, we know the symbol names * that are associated with certaintoken values. * so we look them up to make the error messages * more readable. */ if (expected_token > GTK_RC_TOKEN_INVALID && expected_token < GTK_RC_TOKEN_LAST) { for (i = 0; i < n_symbols; i++) if (symbols[i].token == expected_token) msg = symbols[i].name; if (msg) msg = g_strconcat ("e.g. `", msg, "'", NULL); } if (scanner->token > GTK_RC_TOKEN_INVALID && scanner->token < GTK_RC_TOKEN_LAST) { symbol_name = "???"; for (i = 0; i < n_symbols; i++) if (symbols[i].token == scanner->token) symbol_name = symbols[i].name; } } g_scanner_unexp_token (scanner, expected_token, NULL, "keyword", symbol_name, msg, TRUE); g_free (msg); done = TRUE; } } } g_scanner_destroy (scanner);}static guint gtk_rc_styles_hash (const GSList *rc_styles){ guint result; result = 0; while (rc_styles) { result += (result << 9) + GPOINTER_TO_UINT (rc_styles->data); rc_styles = rc_styles->next; } return result;}static gint gtk_rc_styles_compare (const GSList *a, const GSList *b){ while (a && b) { if (a->data != b->data) return FALSE; a = a->next; b = b->next; } return (a == b);}static guintgtk_rc_style_hash (const char *name){ guint result; result = 0; while (*name) result += (result << 3) + *name++; return result;}static gintgtk_rc_style_compare (const char *a, const char *b){ return (strcmp (a, b) == 0);}static GtkRcStyle*gtk_rc_style_find (const char *name){ if (rc_style_ht) return g_hash_table_lookup (rc_style_ht, (gpointer) name); else return NULL;}/* Assumes ownership of rc_style */static GtkStyle *gtk_rc_style_to_style (GtkRcStyle *rc_style){ GtkStyle *style; GdkFont *old_font; gint i; style = gtk_style_new (); style->rc_style = rc_style; if (rc_style->fontset_name) { old_font = style->font; style->font = gdk_fontset_load (rc_style->fontset_name); if (style->font) gdk_font_unref (old_font); else style->font = old_font; } else if (rc_style->font_name) { old_font = style->font; style->font = gdk_font_load (rc_style->font_name); if (style->font) gdk_font_unref (old_font); else style->font = old_font; } for (i = 0; i < 5; i++) { if (rc_style->color_flags[i] & GTK_RC_FG) style->fg[i] = rc_style->fg[i]; if (rc_style->color_flags[i] & GTK_RC_BG) style->bg[i] = rc_style->bg[i]; if (rc_style->color_flags[i] & GTK_RC_TEXT) style->text[i] = rc_style->text[i]; if (rc_style->color_flags[i] & GTK_RC_BASE) style->base[i] = rc_style->base[i]; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -