📄 gtkstyle.c
字号:
new_style->engine = style->engine; gtk_theme_engine_ref(new_style->engine); new_style->engine->duplicate_style (new_style, style); } return new_style;}static GtkStyle*gtk_style_duplicate (GtkStyle *style){ GtkStyle *new_style; g_return_val_if_fail (style != NULL, NULL); new_style = gtk_style_copy (style); style->styles = g_slist_append (style->styles, new_style); new_style->styles = style->styles; return new_style;}GtkStyle*gtk_style_new (void){ GtkStyle *style; gint i; style = g_new0 (GtkStyle, 1); if (!default_font) { default_font = gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*"); if (!default_font) default_font = gdk_font_load ("fixed"); if (!default_font) g_error ("Unable to load default font."); } style->font = default_font; gdk_font_ref (style->font); style->ref_count = 1; style->attach_count = 0; style->colormap = NULL; style->depth = -1; style->klass = (GtkStyleClass *)&default_class; style->black.red = 0; style->black.green = 0; style->black.blue = 0; style->white.red = 65535; style->white.green = 65535; style->white.blue = 65535; style->black_gc = NULL; style->white_gc = NULL; style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg; style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg; style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg; style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg; style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg; style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg; style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg; style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg; style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg; style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg; for (i = 0; i < 4; i++) { style->text[i] = style->fg[i]; style->base[i] = style->white; } style->base[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg; style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg; for (i = 0; i < 5; i++) style->bg_pixmap[i] = NULL; style->engine = NULL; style->engine_data = NULL; style->rc_style = NULL; for (i = 0; i < 5; i++) { style->fg_gc[i] = NULL; style->bg_gc[i] = NULL; style->light_gc[i] = NULL; style->dark_gc[i] = NULL; style->mid_gc[i] = NULL; style->text_gc[i] = NULL; style->base_gc[i] = NULL; } return style;}/************************************************************* * gtk_style_attach: * Attach a style to a window; this process allocates the * colors and creates the GC's for the style - it specializes * it to a particular visual and colormap. The process * may involve the creation of a new style if the style * has already been attached to a window with a different * style and colormap. * arguments: * style: * window: * results: * Either the style parameter, or a newly created style. * If the style is newly created, the style parameter * will be dereferenced, and the new style will have * a reference count belonging to the caller. * * FIXME: The sequence - * create a style => s1 * attach s1 to v1, c1 => s1 * attach s1 to v2, c2 => s2 * detach s1 from v1, c1 * attach s1 to v2, c2 => s3 * results in two separate, unlinked styles s2 and s3 which * are identical and could be shared. To fix this, we would * want to never remove a style from the list of linked * styles as long as as it has a reference count. However, the * disadvantage of doing it this way means that we would need two * passes through the linked list when attaching (one to check for * matching styles, one to look for empty unattached styles - but * it will almost never be longer than 2 elements. *************************************************************/GtkStyle*gtk_style_attach (GtkStyle *style, GdkWindow *window){ GSList *styles; GtkStyle *new_style = NULL; GdkColormap *colormap; gint depth; g_return_val_if_fail (style != NULL, NULL); g_return_val_if_fail (window != NULL, NULL); colormap = gdk_window_get_colormap (window); depth = gdk_window_get_visual (window)->depth; if (!style->styles) style->styles = g_slist_append (NULL, style); styles = style->styles; while (styles) { new_style = styles->data; if (new_style->attach_count == 0) { gtk_style_init (new_style, colormap, depth); break; } else if (new_style->colormap == colormap && new_style->depth == depth) break; new_style = NULL; styles = styles->next; } if (!new_style) { new_style = gtk_style_duplicate (style); gtk_style_init (new_style, colormap, depth); } /* A style gets a refcount from being attached */ if (new_style->attach_count == 0) gtk_style_ref (new_style); /* Another refcount belongs to the parent */ if (style != new_style) { gtk_style_unref (style); gtk_style_ref (new_style); } new_style->attach_count++; return new_style;}voidgtk_style_detach (GtkStyle *style){ gint i; g_return_if_fail (style != NULL); style->attach_count -= 1; if (style->attach_count == 0) { if (style->engine) style->engine->unrealize_style (style); gtk_gc_release (style->black_gc); gtk_gc_release (style->white_gc); for (i = 0; i < 5; i++) { gtk_gc_release (style->fg_gc[i]); gtk_gc_release (style->bg_gc[i]); gtk_gc_release (style->light_gc[i]); gtk_gc_release (style->dark_gc[i]); gtk_gc_release (style->mid_gc[i]); gtk_gc_release (style->text_gc[i]); gtk_gc_release (style->base_gc[i]); } gtk_style_unref (style); }}GtkStyle*gtk_style_ref (GtkStyle *style){ g_return_val_if_fail (style != NULL, NULL); g_return_val_if_fail (style->ref_count > 0, NULL); style->ref_count += 1; return style;}voidgtk_style_unref (GtkStyle *style){ g_return_if_fail (style != NULL); g_return_if_fail (style->ref_count > 0); style->ref_count -= 1; if (style->ref_count == 0) gtk_style_destroy (style);}static voidgtk_style_init (GtkStyle *style, GdkColormap *colormap, gint depth){ GdkGCValues gc_values; GdkGCValuesMask gc_values_mask; gint i; g_return_if_fail (style != NULL); style->colormap = colormap; style->depth = depth; for (i = 0; i < 5; i++) { gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT); gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT); style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2; style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2; style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2; } gdk_color_black (colormap, &style->black); gdk_color_white (colormap, &style->white); gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT; if (style->font->type == GDK_FONT_FONT) { gc_values.font = style->font; } else if (style->font->type == GDK_FONT_FONTSET) { gc_values.font = default_font; } gc_values.foreground = style->black; style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->white; style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); for (i = 0; i < 5; i++) { if (style->rc_style && style->rc_style->bg_pixmap_name[i]) style->bg_pixmap[i] = gtk_rc_load_image (style->colormap, &style->bg[i], style->rc_style->bg_pixmap_name[i]); if (!gdk_color_alloc (colormap, &style->fg[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->fg[i].red, style->fg[i].green, style->fg[i].blue); if (!gdk_color_alloc (colormap, &style->bg[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->bg[i].red, style->bg[i].green, style->bg[i].blue); if (!gdk_color_alloc (colormap, &style->light[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->light[i].red, style->light[i].green, style->light[i].blue); if (!gdk_color_alloc (colormap, &style->dark[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->dark[i].red, style->dark[i].green, style->dark[i].blue); if (!gdk_color_alloc (colormap, &style->mid[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->mid[i].red, style->mid[i].green, style->mid[i].blue); if (!gdk_color_alloc (colormap, &style->text[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->text[i].red, style->text[i].green, style->text[i].blue); if (!gdk_color_alloc (colormap, &style->base[i])) g_warning ("unable to allocate color: ( %d %d %d )", style->base[i].red, style->base[i].green, style->base[i].blue); gc_values.foreground = style->fg[i]; style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->bg[i]; style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->light[i]; style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->dark[i]; style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->mid[i]; style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->text[i]; style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->base[i]; style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); } if (style->engine) style->engine->realize_style (style);}static voidgtk_style_destroy (GtkStyle *style){ g_return_if_fail (style->attach_count == 0); if (style->styles) { if (style->styles->data != style) g_slist_remove (style->styles, style); else { GSList *tmp_list = style->styles->next; while (tmp_list) { ((GtkStyle*) tmp_list->data)->styles = style->styles->next; tmp_list = tmp_list->next; } g_slist_free_1 (style->styles); } } if (style->engine) { style->engine->destroy_style (style); gtk_theme_engine_unref (style->engine); } gdk_font_unref (style->font); if (style->rc_style)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -