[gtksourceview/wip/gutter-style: 3/3] Apply line-numbers style in GtkSourceGutter (not finished)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/gutter-style: 3/3] Apply line-numbers style in GtkSourceGutter (not finished)
- Date: Wed, 13 Aug 2014 17:19:30 +0000 (UTC)
commit 83835c2553fb368cc30e1534be034628a475126b
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Aug 13 19:08:53 2014 +0200
Apply line-numbers style in GtkSourceGutter (not finished)
The line-numbers style was applied to the whole GtkTextView widget with
gtk_widget_override_color() and gtk_widget_override_background_color().
It worked because the "text" style is also applied to the main
GtkTextView region with CSS, which seems to override the colors set with
gtk_widget_override_color() and gtk_widget_override_background_color().
Now the line-numbers style is applied directly in GtkSourceGutter, which
is more logical.
It permits to provide a "line-numbers" style without providing the
"text" style. The "text" style is not provided by the classic and tango
style schemes, but a different style for "line-numbers" is desirable.
https://bugzilla.gnome.org/show_bug.cgi?id=733606
gtksourceview/gtksourcegutter.c | 46 ++++++++++++++++++++++++++++++++++
gtksourceview/gtksourcestylescheme.c | 33 +-----------------------
2 files changed, 47 insertions(+), 32 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index 1cff5c7..fa52bf4 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -25,6 +25,9 @@
#include "gtksourceview-i18n.h"
#include "gtksourcegutterrenderer.h"
#include "gtksourcegutterrenderer-private.h"
+#include "gtksourcebuffer.h"
+#include "gtksourcestyle.h"
+#include "gtksourcestylescheme.h"
/**
* SECTION:gutter
@@ -929,6 +932,47 @@ get_lines (GtkTextView *text_view,
return total_height;
}
+static void
+draw_background_color (GtkSourceView *view,
+ cairo_t *cr,
+ GdkRectangle *clip)
+{
+ GtkSourceBuffer *buffer;
+ GtkSourceStyleScheme *style_scheme;
+ GtkSourceStyle *style;
+ gboolean bg_set;
+ gchar *bg_color;
+
+ buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ style_scheme = gtk_source_buffer_get_style_scheme (buffer);
+
+ if (style_scheme == NULL)
+ {
+ return;
+ }
+
+ style = gtk_source_style_scheme_get_style (style_scheme, "line-numbers");
+
+ if (style == NULL)
+ {
+ return;
+ }
+
+ g_object_get (style,
+ "background-set", &bg_set,
+ "background", &bg_color,
+ NULL);
+
+ if (!bg_set)
+ {
+ return;
+ }
+
+ g_message ("background: %s", bg_color);
+
+ g_free (bg_color);
+}
+
static gboolean
on_view_draw (GtkSourceView *view,
cairo_t *cr,
@@ -975,6 +1019,8 @@ on_view_draw (GtkSourceView *view,
gutter->priv->is_drawing = TRUE;
+ draw_background_color (view, cr, &clip);
+
text_view = GTK_TEXT_VIEW (view);
buffer = gtk_text_view_get_buffer (text_view);
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 53a5ead..7431c61 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -52,7 +52,7 @@
#define STYLE_CURSOR "cursor"
#define STYLE_SECONDARY_CURSOR "secondary-cursor"
#define STYLE_CURRENT_LINE "current-line"
-#define STYLE_LINE_NUMBERS "line-numbers"
+#define STYLE_LINE_NUMBERS "line-numbers" /* used in GtkSourceGutter */
#define STYLE_RIGHT_MARGIN "right-margin"
#define STYLE_DRAW_SPACES "draw-spaces"
@@ -636,33 +636,6 @@ _gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
}
static void
-set_line_numbers_style (GtkWidget *widget,
- GtkSourceStyle *style)
-{
- GdkRGBA *fg_ptr = NULL;
- GdkRGBA *bg_ptr = NULL;
- GdkRGBA fg;
- GdkRGBA bg;
- GtkStateFlags flags;
-
- if (get_color (style, TRUE, &fg))
- {
- fg_ptr = &fg;
- }
-
- if (get_color (style, FALSE, &bg))
- {
- bg_ptr = &bg;
- }
-
- /* Override the color no matter what the state is */
- flags = GTK_STATE_FLAG_NORMAL;
-
- gtk_widget_override_color (widget, flags, fg_ptr);
- gtk_widget_override_background_color (widget, flags, bg_ptr);
-}
-
-static void
update_cursor_colors (GtkWidget *widget,
GtkSourceStyle *style_primary,
GtkSourceStyle *style_secondary)
@@ -738,9 +711,6 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
gtk_style_context_invalidate (context);
G_GNUC_END_IGNORE_DEPRECATIONS;
- style = gtk_source_style_scheme_get_style (scheme, STYLE_LINE_NUMBERS);
- set_line_numbers_style (widget, style);
-
style = gtk_source_style_scheme_get_style (scheme, STYLE_CURSOR);
style2 = gtk_source_style_scheme_get_style (scheme, STYLE_SECONDARY_CURSOR);
update_cursor_colors (widget, style, style2);
@@ -773,7 +743,6 @@ _gtk_source_style_scheme_unapply (GtkSourceStyleScheme *scheme,
gtk_style_context_invalidate (context);
G_GNUC_END_IGNORE_DEPRECATIONS;
- set_line_numbers_style (widget, NULL);
update_cursor_colors (widget, NULL, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]