static void update_background_color (GtkSourceMarkAttributes *attrs, GtkSourceBuffer *buffer) { GtkSourceStyleScheme *scheme; GtkSourceStyle *style; scheme = gtk_source_buffer_get_style_scheme (buffer); style = gtk_source_style_scheme_get_style (scheme, "search-match"); if (style) { gboolean bgset; gchar *bg; g_object_get (style, "background-set", &bgset, "background", &bg, NULL); if (bgset) { GdkRGBA color; gdk_rgba_parse (&color, bg); gtk_source_mark_attributes_set_background (attrs, &color); g_free (bg); return; } } gtk_source_mark_attributes_set_background (attrs, NULL); }
static void update_style_scheme (GbpSpellBufferAddin *self, GParamSpec *pspec, IdeBuffer *buffer) { GtkSourceStyleScheme *scheme; g_assert (GBP_IS_SPELL_BUFFER_ADDIN (self)); g_assert (IDE_IS_BUFFER (buffer)); scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer)); if (!ide_source_style_scheme_apply_style (scheme, "misspelled-match", self->misspelled_tag)) g_object_set (self->misspelled_tag, "underline", PANGO_UNDERLINE_SINGLE, NULL); }
static GtkTextTag * create_tag_from_style (IdeHighlightEngine *self, const gchar *style_name) { GtkSourceStyleScheme *style_scheme; GtkTextTag *tag; g_assert (IDE_IS_HIGHLIGHT_ENGINE (self)); g_assert (IDE_IS_BUFFER (self->buffer)); g_assert (style_name != NULL); tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (self->buffer), style_name, NULL); style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (self->buffer)); sync_tag_style (style_scheme, tag); return tag; }
static void ide_highlight_engine__notify_style_scheme_cb (IdeHighlightEngine *self, GParamSpec *pspec, IdeBuffer *buffer) { GtkSourceStyleScheme *style_scheme; GSList *iter; g_assert (IDE_IS_HIGHLIGHT_ENGINE (self)); g_assert (IDE_IS_BUFFER (buffer)); style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer)); for (iter = self->private_tags; iter; iter = iter->next) sync_tag_style (style_scheme, iter->data); for (iter = self->public_tags; iter; iter = iter->next) sync_tag_style (style_scheme, iter->data); }
static void connect_style_scheme (IdeLineChangeGutterRenderer *self) { GtkSourceStyleScheme *scheme; GtkTextBuffer *buffer; GtkTextView *view; if (!(view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (self))) || !(buffer = gtk_text_view_get_buffer (view)) || !GTK_SOURCE_IS_BUFFER (buffer)) return; scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer)); if (!get_style_rgba (scheme, "gutter::added-line", FOREGROUND, &self->changes.add)) gdk_rgba_parse (&self->changes.add, "#8ae234"); if (!get_style_rgba (scheme, "gutter::changed-line", FOREGROUND, &self->changes.change)) gdk_rgba_parse (&self->changes.change, "#fcaf3e"); if (!get_style_rgba (scheme, "gutter::removed-line", FOREGROUND, &self->changes.remove)) gdk_rgba_parse (&self->changes.remove, "#ef2929"); }
static void update_background_color (GeditView *view) { GtkSourceView *source_view = GTK_SOURCE_VIEW (view); GtkSourceStyle *style; GtkSourceStyleScheme *scheme; GtkTextBuffer *buffer; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer)); style = gtk_source_style_scheme_get_style (scheme, "search-match"); if (style) { gboolean bgset; gchar *bg; g_object_get (style, "background-set", &bgset, "background", &bg, NULL); if (bgset) { GdkColor color; gdk_color_parse (bg, &color); gtk_source_view_set_mark_category_background (source_view, BOOKMARK_CATEGORY, &color); g_free (bg); return; } } gtk_source_view_set_mark_category_background (source_view, BOOKMARK_CATEGORY, NULL); }
static void gtk_source_map_rebuild_css (GtkSourceMap *map) { GtkSourceMapPrivate *priv; GtkSourceStyleScheme *style_scheme; GtkSourceStyle *style = NULL; GtkTextBuffer *buffer; GString *gstr; gboolean alter_alpha = TRUE; gchar *background = NULL; priv = gtk_source_map_get_instance_private (map); if (priv->view == NULL) { return; } /* * This is where we calculate the CSS that maps the font for the * minimap as well as the styling for the scrubber. * * The font is calculated from #GtkSourceMap:font-desc. We convert this * to CSS using _gtk_source_pango_font_description_to_css(). It gets * applied to the minimap widget via the CSS style provider which we * attach to the child widget in gtk_source_map_init(). * * The rules for calculating the style for the scrubber are as follows. * * If the current style scheme provides a background color for the * scrubber using the "map-overlay" style name, we use that without * any transformations. * * If the style scheme contains a "selection" style scheme, used for * selected text, we use that with a 0.75 alpha value. * * If none of these are met, we take the background from the * #GtkStyleContext using the deprecated * gtk_style_context_get_background_color(). This is non-ideal, but * currently required since we cannot indicate that we want to * alter the alpha for gtk_render_background(). */ gstr = g_string_new (NULL); /* Calculate the font if one has been set */ if (priv->font_desc != NULL) { gchar *css; css = _gtk_source_pango_font_description_to_css (priv->font_desc); g_string_append_printf (gstr, "GtkSourceView { %s }\n", css != NULL ? css : ""); g_free (css); } buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)); style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer)); if (style_scheme != NULL) { style = gtk_source_style_scheme_get_style (style_scheme, "map-overlay"); if (style != NULL) { /* styling is taking as is only if we found a "map-overlay". */ alter_alpha = FALSE; } else { style = gtk_source_style_scheme_get_style (style_scheme, "selection"); } } if (style != NULL) { g_object_get (style, "background", &background, NULL); } if (background == NULL) { GtkStyleContext *context; GdkRGBA color; /* * We failed to locate a style for both "map-overlay" and for * "selection". That means we need to fallback to using the * selected color for the gtk+ theme. This uses deprecated * API because we have no way to tell gtk_render_background() * to render with an alpha. */ context = gtk_widget_get_style_context (GTK_WIDGET (priv->view)); gtk_style_context_save (context); gtk_style_context_add_class (context, "view"); G_GNUC_BEGIN_IGNORE_DEPRECATIONS; gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color); G_GNUC_END_IGNORE_DEPRECATIONS; gtk_style_context_restore (context); background = gdk_rgba_to_string (&color); /* * Make sure we alter the alpha. It is possible this could be * FALSE here if we found a style for map-overlay but it did * not contain a background color. */ alter_alpha = TRUE; } if (alter_alpha) { GdkRGBA color; gdk_rgba_parse (&color, background); color.alpha = 0.75; g_free (background); background = gdk_rgba_to_string (&color); } if (background != NULL) { g_string_append_printf (gstr, "GtkSourceMap.scrubber {\n" "\tbackground-color: %s;\n" "\tborder-top: 1px solid shade(%s,0.9);\n" "\tborder-bottom: 1px solid shade(%s,0.9);\n" "}\n", background, background, background); } g_free (background); if (gstr->len > 0) { gtk_css_provider_load_from_data (priv->css_provider, gstr->str, gstr->len, NULL); } g_string_free (gstr, TRUE); }