? hline.patch
Index: gtksourceview/gtksourcebuffer.c
===================================================================
RCS file: /cvs/gnome/gtksourceview/gtksourceview/gtksourcebuffer.c,v
retrieving revision 1.39
diff -u -p -r1.39 gtksourcebuffer.c
--- gtksourceview/gtksourcebuffer.c	21 Jun 2005 17:29:28 -0000	1.39
+++ gtksourceview/gtksourcebuffer.c	19 Jul 2005 08:33:52 -0000
@@ -90,6 +90,7 @@ enum {
 	PROP_ESCAPE_CHAR,
 	PROP_CHECK_BRACKETS,
 	PROP_HIGHLIGHT,
+	PROP_HIGHLIGHT_CURRENT_LINE,
 	PROP_MAX_UNDO_LEVELS,
 	PROP_LANGUAGE
 };
@@ -110,6 +111,7 @@ struct _PatternMatch
 struct _GtkSourceBufferPrivate 
 {
 	gint                   highlight:1;
+	gint                   highlight_current_line:1;
 	gint                   check_brackets:1;
 
 	GtkTextTag            *bracket_match_tag;
@@ -301,6 +303,15 @@ gtk_source_buffer_class_init (GtkSourceB
 							       G_PARAM_READWRITE));
 	
 	g_object_class_install_property (object_class,
+					 PROP_HIGHLIGHT_CURRENT_LINE,
+					 g_param_spec_boolean ("highlight_current_line",
+							       _("Highlight Current Line"),
+							       _("Whether to highlight the "
+								 "active line in the buffer"),
+							       FALSE,
+							       G_PARAM_READWRITE));
+	
+	g_object_class_install_property (object_class,
 					 PROP_MAX_UNDO_LEVELS,
 					 g_param_spec_int ("max_undo_levels",
 							   _("Maximum Undo Levels"),
@@ -460,6 +471,8 @@ gtk_source_buffer_constructor (GType    
 	if (g_object) 
 	{
 		GtkSourceTagStyle *tag_style;
+		GtkTextTag *tag;
+		GtkTextIter iter;
 		
 		GtkSourceBuffer *source_buffer = GTK_SOURCE_BUFFER (g_object);
 
@@ -480,6 +493,16 @@ gtk_source_buffer_constructor (GType    
 
 		gtk_source_tag_style_free (tag_style);
 
+		/* Create a mark for the highlighted line. */
+		gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (source_buffer), &iter);
+		gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (source_buffer),
+					     "highlightline", &iter, FALSE);
+
+		/* Create paragraph-background tag for highlighting lines. */
+		tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (source_buffer),
+						  "highlightline", NULL);
+		g_object_set (tag, "paragraph-background", "red", NULL);
+
 		if (GTK_IS_SOURCE_TAG_TABLE (GTK_TEXT_BUFFER (source_buffer)->tag_table))
 		{
 			g_signal_connect (GTK_TEXT_BUFFER (source_buffer)->tag_table ,
@@ -593,6 +616,11 @@ gtk_source_buffer_set_property (GObject 
 							 g_value_get_boolean (value));
 			break;
 			
+		case PROP_HIGHLIGHT_CURRENT_LINE:
+			gtk_source_buffer_set_highlight_current_line (source_buffer,
+								      g_value_get_boolean (value));
+			break;
+			
 		case PROP_MAX_UNDO_LEVELS:
 			gtk_source_buffer_set_max_undo_levels (source_buffer,
 							       g_value_get_int (value));
@@ -635,6 +663,10 @@ gtk_source_buffer_get_property (GObject 
 			g_value_set_boolean (value, source_buffer->priv->highlight);
 			break;
 			
+		case PROP_HIGHLIGHT_CURRENT_LINE:
+			g_value_set_boolean (value, source_buffer->priv->highlight_current_line);
+			break;
+			
 		case PROP_MAX_UNDO_LEVELS:
 			g_value_set_int (value,
 					 gtk_source_buffer_get_max_undo_levels (source_buffer));
@@ -753,6 +785,40 @@ gtk_source_buffer_move_cursor (GtkTextBu
 	if (mark != gtk_text_buffer_get_insert (buffer))
 		return;
 
+	if (GTK_SOURCE_BUFFER (buffer)->priv->highlight_current_line)
+	{
+		GtkTextMark *mark;
+		GtkTextIter hliter;
+		
+		mark = gtk_text_buffer_get_mark (buffer, "highlightline");
+		gtk_text_buffer_get_iter_at_mark (buffer, &hliter, mark);
+
+		/* Only change the highlighted line if the current line has changed. */		
+		if (gtk_text_iter_get_line (&hliter) != gtk_text_iter_get_line (iter))
+		{
+			/* Remove the highlight on the previous line. */ 
+			iter1 = iter2 = hliter;
+			gtk_text_iter_set_line_index (&iter1, 0);
+			if (!gtk_text_iter_ends_line (&iter2))
+				gtk_text_iter_forward_to_line_end (&iter2);
+			else if (gtk_text_iter_starts_line (&iter2))
+				gtk_text_iter_forward_visible_line (&iter2);
+			gtk_text_buffer_remove_tag_by_name (buffer, "highlightline", &iter1, &iter2);
+			
+			/* Highlight the new active line. */
+			iter1 = iter2 = *iter;
+			gtk_text_iter_set_line_index (&iter1, 0);
+			if (!gtk_text_iter_ends_line (&iter2))
+				gtk_text_iter_forward_to_line_end (&iter2);
+			else if (gtk_text_iter_starts_line (&iter2))
+				gtk_text_iter_forward_visible_line (&iter2);
+			gtk_text_buffer_apply_tag_by_name (buffer, "highlightline", &iter1, &iter2);
+			
+			/* Update the position of the mark. */
+			gtk_text_buffer_move_mark (buffer, mark, iter);
+		}
+	}
+
 	if (GTK_SOURCE_BUFFER (buffer)->priv->bracket_found) 
 	{
 		gtk_text_buffer_get_iter_at_mark (buffer,
@@ -1504,6 +1570,61 @@ gtk_source_buffer_set_highlight (GtkSour
 							  &iter2);
 	}
 	g_object_notify (G_OBJECT (buffer), "highlight");
+}
+
+/**
+ * gtk_source_buffer_get_highlight_current_line:
+ * @buffer: a #GtkSourceBuffer
+ *
+ * Returns whether the current line is highlighted
+ *
+ * Return value: TRUE if the current line is highlighted
+ **/
+gboolean 
+gtk_source_buffer_get_highlight_current_line (GtkSourceBuffer *buffer)
+{
+	g_return_val_if_fail (GTK_IS_SOURCE_BUFFER (buffer), FALSE);
+
+	return buffer->priv->highlight_current_line;
+}
+
+/**
+ * gtk_source_buffer_set_highlight_current_line:
+ * @buffer: a #GtkSourceBuffer
+ * @hl: whether to highlight the current line
+ **/
+void 
+gtk_source_buffer_set_highlight_current_line (GtkSourceBuffer *buffer, gboolean hl)
+{
+	g_return_if_fail (GTK_IS_SOURCE_BUFFER (buffer));
+
+	hl = (hl != FALSE);
+
+	if (buffer->priv->highlight_current_line == hl)
+		return;
+
+	buffer->priv->highlight_current_line = hl;
+
+	g_object_notify (G_OBJECT (buffer), "highlight_current_line");
+}
+
+/**
+ * gtk_source_buffer_set_highlight_current_line_color:
+ * @buffer: a #GtkSourceBuffer
+ * @color: the background color to be used for highlighting the current line
+ **/
+void
+gtk_source_buffer_set_highlight_current_line_color (GtkSourceBuffer *buffer, GdkColor *color)
+{
+	GtkTextTagTable *table;
+	GtkTextTag *tag;
+
+	g_return_if_fail (GTK_IS_SOURCE_BUFFER (buffer));
+	g_return_if_fail (color != NULL);
+	
+	table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer));
+	tag = gtk_text_tag_table_lookup (table, "highlightline");
+	g_object_set (tag, "paragraph-background-gdk", color, NULL);
 }
 
 /* Idle worker code ------------ */
Index: gtksourceview/gtksourcebuffer.h
===================================================================
RCS file: /cvs/gnome/gtksourceview/gtksourceview/gtksourcebuffer.h,v
retrieving revision 1.18
diff -u -p -r1.18 gtksourcebuffer.h
--- gtksourceview/gtksourcebuffer.h	6 Jun 2003 08:54:36 -0000	1.18
+++ gtksourceview/gtksourcebuffer.h	19 Jul 2005 08:33:52 -0000
@@ -92,6 +92,15 @@ gboolean		 gtk_source_buffer_get_highlig
 void			 gtk_source_buffer_set_highlight	(GtkSourceBuffer        *buffer,
 								 gboolean                highlight);
 
+void			 gtk_source_buffer_set_highlight_current_line 	
+								(GtkSourceBuffer        *buffer,
+								 gboolean                show);
+gboolean		 gtk_source_buffer_get_highlight_current_line 	
+								(GtkSourceBuffer        *buffer);
+void			 gtk_source_buffer_set_highlight_current_line_color
+								(GtkSourceBuffer        *buffer,
+								 GdkColor               *color);
+
 gint			 gtk_source_buffer_get_max_undo_levels	(GtkSourceBuffer        *buffer);
 void			 gtk_source_buffer_set_max_undo_levels	(GtkSourceBuffer        *buffer,
 							    	 gint                    max_undo_levels);
Index: gtksourceview/gtksourceview.c
===================================================================
RCS file: /cvs/gnome/gtksourceview/gtksourceview/gtksourceview.c,v
retrieving revision 1.37
diff -u -p -r1.37 gtksourceview.c
--- gtksourceview/gtksourceview.c	1 Mar 2005 10:44:01 -0000	1.37
+++ gtksourceview/gtksourceview.c	19 Jul 2005 08:33:53 -0000
@@ -1246,50 +1246,6 @@ gtk_source_view_expose (GtkWidget      *
 				gdk_window_invalidate_rect (w, NULL, FALSE);
 		}
 
-		if (view->priv->highlight_current_line && 
-		    (event->window == gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT)))
-		{
-			GdkRectangle visible_rect;
-			GdkRectangle redraw_rect;
-			GtkTextIter cur;
-			gint y;
-			gint height;
-			gint win_y;
-			
-			gtk_text_buffer_get_iter_at_mark (text_view->buffer, 
-							  &cur, 
-							  gtk_text_buffer_get_insert (text_view->buffer));
-
-			gtk_text_view_get_line_yrange (text_view, &cur, &y, &height);
-							
-			gtk_text_view_get_visible_rect (text_view, &visible_rect);
-			
-			gtk_text_view_buffer_to_window_coords (text_view,
-						       GTK_TEXT_WINDOW_TEXT,
-						       visible_rect.x,
-						       visible_rect.y,
-						       &redraw_rect.x,
-						       &redraw_rect.y);
-
-			gtk_text_view_buffer_to_window_coords (text_view,
-						       GTK_TEXT_WINDOW_TEXT,
-						       0,
-						       y,
-						       NULL,
-						       &win_y);
-
-			redraw_rect.width = visible_rect.width;
-			redraw_rect.height = visible_rect.height;
-
-			gdk_draw_rectangle (event->window,
-					    widget->style->bg_gc[GTK_WIDGET_STATE (widget)],
-					    TRUE,
-					    redraw_rect.x + MAX (0, gtk_text_view_get_left_margin (text_view) - 1),
-					    win_y,
-					    redraw_rect.width,
-					    height);
-		}
-
 		if (view->priv->show_margin && 
 		    (event->window == gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT)))
 		{
Index: tests/test-widget.c
===================================================================
RCS file: /cvs/gnome/gtksourceview/tests/test-widget.c,v
retrieving revision 1.11
diff -u -p -r1.11 test-widget.c
--- tests/test-widget.c	8 Jan 2005 22:02:30 -0000	1.11
+++ tests/test-widget.c	19 Jul 2005 08:33:53 -0000
@@ -431,8 +431,9 @@ static void
 hl_line_toggled_cb (GtkAction *action, gpointer user_data)
 {
 	g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_IS_SOURCE_VIEW (user_data));
-	gtk_source_view_set_highlight_current_line (
-		GTK_SOURCE_VIEW (user_data),
+
+	gtk_source_buffer_set_highlight_current_line (
+		GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (user_data))),
 		gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
 }
 
