[gtksourceview] Added draw spaces flags for leading, text and trailing spaces
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtksourceview] Added draw spaces flags for leading, text and trailing spaces
- Date: Sun, 11 Oct 2009 14:31:51 +0000 (UTC)
commit c95072aa6b74841cfb9f69abe3e65ffdad146e34
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Sun Oct 11 16:29:43 2009 +0200
Added draw spaces flags for leading, text and trailing spaces
docs/reference/tmpl/view.sgml | 3 +
gtksourceview/gtksourceview.c | 97 +++++++++++++++++++++++++++++++++++++++--
gtksourceview/gtksourceview.h | 8 +++-
3 files changed, 103 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/tmpl/view.sgml b/docs/reference/tmpl/view.sgml
index 2f9cafb..db6c873 100644
--- a/docs/reference/tmpl/view.sgml
+++ b/docs/reference/tmpl/view.sgml
@@ -162,6 +162,9 @@ Function type for setting up a tooltip for #GtkSourceMark.
@GTK_SOURCE_DRAW_SPACES_TAB:
@GTK_SOURCE_DRAW_SPACES_NEWLINE:
@GTK_SOURCE_DRAW_SPACES_NBSP:
+ GTK_SOURCE_DRAW_SPACES_LEADING:
+ GTK_SOURCE_DRAW_SPACES_TEXT:
+ GTK_SOURCE_DRAW_SPACES_TRAILING:
@GTK_SOURCE_DRAW_SPACES_ALL:
<!-- ##### ENUM GtkSourceViewGutterPosition ##### -->
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 7999d88..07584bd 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -2393,6 +2393,76 @@ draw_spaces_at_iter (cairo_t *cr,
}
static void
+get_leading_trailing (GtkTextIter *iter,
+ GtkTextIter *leading,
+ GtkTextIter *trailing)
+{
+ GtkTextIter start = *iter;
+
+ /* Find end of leading */
+ start = *iter;
+ gtk_text_iter_set_line_offset (&start, 0);
+
+ while (TRUE)
+ {
+ gunichar ch = gtk_text_iter_get_char (&start);
+
+ if (!g_unichar_isspace (ch) ||
+ gtk_text_iter_ends_line (&start) ||
+ !gtk_text_iter_forward_char (&start))
+ {
+ *leading = start;
+ break;
+ }
+ }
+
+ /* Find start of trailing */
+ start = *iter;
+ gtk_text_iter_forward_to_line_end (&start);
+
+ while (TRUE)
+ {
+ gunichar ch = gtk_text_iter_get_char (&start);
+
+ if (!g_unichar_isspace (ch) ||
+ gtk_text_iter_starts_line (&start) ||
+ !gtk_text_iter_backward_char (&start))
+ {
+ *trailing = start;
+ break;
+ }
+ }
+}
+
+static gboolean
+check_location (GtkSourceView *view,
+ GtkTextIter *iter,
+ GtkTextIter *leading,
+ GtkTextIter *trailing)
+{
+ gint location = view->priv->draw_spaces & (GTK_SOURCE_DRAW_SPACES_LEADING |
+ GTK_SOURCE_DRAW_SPACES_TEXT |
+ GTK_SOURCE_DRAW_SPACES_TRAILING);
+
+ /* Draw all by default */
+ if (!location)
+ {
+ return TRUE;
+ }
+
+ if (gtk_text_iter_compare (iter, trailing) > 0)
+ {
+ return location & GTK_SOURCE_DRAW_SPACES_TRAILING;
+ }
+
+ if (gtk_text_iter_compare (iter, leading) < 0)
+ {
+ return location & GTK_SOURCE_DRAW_SPACES_LEADING;
+ }
+
+ return location & GTK_SOURCE_DRAW_SPACES_TEXT;
+}
+static void
draw_tabs_and_spaces (GtkSourceView *view,
GdkEventExpose *event)
{
@@ -2400,6 +2470,7 @@ draw_tabs_and_spaces (GtkSourceView *view,
gint x1, y1, x2, y2;
GtkTextIter s, e;
cairo_t *cr;
+ GtkTextIter leading, trailing;
text_view = GTK_TEXT_VIEW (view);
@@ -2437,8 +2508,12 @@ draw_tabs_and_spaces (GtkSourceView *view,
view->priv->spaces_color->blue / 65535.,
1);
cairo_set_line_width (cr, 0.8);
+ cairo_translate (cr, -0.5, -0.5);
+
+ get_leading_trailing (&s, &leading, &trailing);
- do {
+ do
+ {
GdkRectangle rect;
gint ly;
@@ -2448,7 +2523,9 @@ draw_tabs_and_spaces (GtkSourceView *view,
if (rect.x > x2)
{
if (!gtk_text_iter_forward_line (&s))
+ {
break;
+ }
/* move to the first iter in the exposed area of
* the next line */
@@ -2461,20 +2538,32 @@ draw_tabs_and_spaces (GtkSourceView *view,
/* move back one char otherwise tabs may not
* be redrawn */
if (!gtk_text_iter_starts_line (&s))
+ {
gtk_text_iter_backward_char (&s);
-
+ }
+
+ get_leading_trailing (&s, &leading, &trailing);
continue;
}
- draw_spaces_at_iter (cr, view, &s, rect);
+ if (check_location (view, &s, &leading, &trailing))
+ {
+ draw_spaces_at_iter (cr, view, &s, rect);
+ }
if (!gtk_text_iter_forward_char (&s))
+ {
break;
+ }
+
+ if (gtk_text_iter_starts_line (&s))
+ {
+ get_leading_trailing (&s, &leading, &trailing);
+ }
} while (gtk_text_iter_compare (&s, &e) <= 0);
cairo_stroke (cr);
-
cairo_destroy (cr);
}
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 88984c7..0544f32 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -112,10 +112,16 @@ typedef enum
GTK_SOURCE_DRAW_SPACES_TAB = 1 << 1,
GTK_SOURCE_DRAW_SPACES_NEWLINE = 1 << 2,
GTK_SOURCE_DRAW_SPACES_NBSP = 1 << 3,
+ GTK_SOURCE_DRAW_SPACES_LEADING = 1 << 4,
+ GTK_SOURCE_DRAW_SPACES_TEXT = 1 << 5,
+ GTK_SOURCE_DRAW_SPACES_TRAILING = 1 << 6,
GTK_SOURCE_DRAW_SPACES_ALL = (GTK_SOURCE_DRAW_SPACES_SPACE | \
GTK_SOURCE_DRAW_SPACES_TAB | \
GTK_SOURCE_DRAW_SPACES_NEWLINE | \
- GTK_SOURCE_DRAW_SPACES_NBSP)
+ GTK_SOURCE_DRAW_SPACES_NBSP | \
+ GTK_SOURCE_DRAW_SPACES_LEADING | \
+ GTK_SOURCE_DRAW_SPACES_TEXT | \
+ GTK_SOURCE_DRAW_SPACES_TRAILING),
} GtkSourceDrawSpacesFlags;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]