SF.net SVN: geany: [1237] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Jan 31 15:53:12 UTC 2007


Revision: 1237
          http://svn.sourceforge.net/geany/?rev=1237&view=rev
Author:   eht16
Date:     2007-01-31 07:53:11 -0800 (Wed, 31 Jan 2007)

Log Message:
-----------
Improved the auto scrolling of documents (actually done by Nick).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/scintilla/ScintillaGTK.cxx
    trunk/src/document.c
    trunk/src/document.h
    trunk/src/keybindings.c
    trunk/src/sci_cb.c
    trunk/src/sciwrappers.c
    trunk/src/sciwrappers.h
    trunk/src/utils.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/ChangeLog	2007-01-31 15:53:11 UTC (rev 1237)
@@ -1,10 +1,18 @@
+2007-01-31  Enrico Tröger  <enrico.troeger at uvena.de>
+
+ * scintilla/ScintillaGTK.cxx, src/document.c, src/document.h,
+   src/keybindings.c, src/sci_cb.c, src/sciwrappers.c,
+   src/sciwrappers.h, src/utils.c:
+   Improved the auto scrolling of documents (actually done by Nick).
+
+
 2007-01-30  Frank Lanitz  <frank at frank.uvena.de>
 
- * configure.in, src/about.c, po/fi.po: 
+ * configure.in, THANKS, src/about.c, po/fi.po:
    Added Finnish translation (Thanks to Harri Koskinen).
 
 
-2007-01-27  Enrico Troeger  <enrico.troeger at uvena.de>
+2007-01-27  Enrico Tröger  <enrico.troeger at uvena.de>
 
  * src/callbacks.c, src/document.c, src/document.h, src/keyfile.c,
    src/sci_cb.c, src/sciwrappers.c, src/sciwrappers.h:

Modified: trunk/scintilla/ScintillaGTK.cxx
===================================================================
--- trunk/scintilla/ScintillaGTK.cxx	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/scintilla/ScintillaGTK.cxx	2007-01-31 15:53:11 UTC (rev 1237)
@@ -2198,7 +2198,13 @@
 	rcPaint.right = ose->area.x + ose->area.width;
 	rcPaint.bottom = ose->area.y + ose->area.height;
 
-	PLATFORM_ASSERT(rgnUpdate == NULL);
+	/* We can receive an expose-event during an expose-event.
+	 * This can happen when two different scroll messages are sent at different times. */
+	if (rgnUpdate != NULL)
+	{
+		gdk_region_destroy(rgnUpdate);
+		rgnUpdate = NULL;
+	}
 #if GTK_MAJOR_VERSION >= 2
 	rgnUpdate = gdk_region_copy(ose->region);
 #endif

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/document.c	2007-01-31 15:53:11 UTC (rev 1237)
@@ -210,6 +210,7 @@
 	new_doc->sci = NULL;
 	new_doc->undo_actions = NULL;
 	new_doc->redo_actions = NULL;
+	new_doc->scroll_percent = -1.0F;
 }
 
 
@@ -312,7 +313,6 @@
 	this->line_breaking = app->pref_editor_line_breaking;
 	this->use_auto_indention = app->pref_editor_use_auto_indention;
 	this->has_tags = FALSE;
-	this->need_scrolling = FALSE;
 
 	treeviews_openfiles_add(new_idx);	// sets this->iter
 
@@ -353,6 +353,7 @@
 		g_free(doc_list[idx].saved_encoding.encoding);
 		g_free(doc_list[idx].file_name);
 		tm_workspace_remove_object(doc_list[idx].tm_file, TRUE);
+
 		doc_list[idx].is_valid = FALSE;
 		doc_list[idx].sci = NULL;
 		doc_list[idx].file_name = NULL;
@@ -360,6 +361,7 @@
 		doc_list[idx].encoding = NULL;
 		doc_list[idx].has_bom = FALSE;
 		doc_list[idx].tm_file = NULL;
+		doc_list[idx].scroll_percent = -1.0F;
 		document_undo_clear(idx);
 		if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0)
 		{
@@ -741,19 +743,19 @@
 	if (cl_options.goto_line >= 0)
 	{	// goto line which was specified on command line and then undefine the line
 		sci_goto_line(doc_list[idx].sci, cl_options.goto_line - 1, TRUE);
-		doc_list[idx].need_scrolling = TRUE;
+		doc_list[idx].scroll_percent = 0.5F;
 		cl_options.goto_line = -1;
 	}
 	else if (pos >= 0)
 	{
 		sci_set_current_position(doc_list[idx].sci, pos, FALSE);
-		doc_list[idx].need_scrolling = TRUE;
+		doc_list[idx].scroll_percent = 0.5F;
 	}
 	if (cl_options.goto_column >= 0)
 	{	// goto column which was specified on command line and then undefine the column
 		gint cur_pos = sci_get_current_position(doc_list[idx].sci);
 		sci_set_current_position(doc_list[idx].sci, cur_pos + cl_options.goto_column, FALSE);
-		doc_list[idx].need_scrolling = TRUE;
+		doc_list[idx].scroll_percent = 0.5F;
 		cl_options.goto_column = -1;
 	}
 
@@ -1039,7 +1041,7 @@
 	{
 		sci_set_selection_start(doc_list[idx].sci, ttf.chrgText.cpMin);
 		sci_set_selection_end(doc_list[idx].sci, ttf.chrgText.cpMax);
-		sci_scroll_to_line(doc_list[idx].sci, -1, 0.3);
+		doc_list[idx].scroll_percent = 0.3F;
 	}
 	else
 	{
@@ -1087,7 +1089,7 @@
 	if (search_pos != -1)
 	{
 		if (scroll)
-			sci_scroll_to_line(doc_list[idx].sci, -1, 0.3);
+			doc_list[idx].scroll_percent = 0.3F;
 	}
 	else
 	{

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/document.h	2007-01-31 15:53:11 UTC (rev 1237)
@@ -64,8 +64,7 @@
 	gboolean		 changed;
 	gboolean		 line_breaking;
 	gboolean		 use_auto_indention;
-	// whether the current position in the doc needs to be made visible on a tab switch event
-	gboolean		 need_scrolling;
+	gfloat			 scroll_percent;	// % to scroll view by on paint, if positive.
 	time_t			 last_check;	// to remember the last disk check
 	time_t			 mtime;
 	GTrashStack		*undo_actions;

Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/keybindings.c	2007-01-31 15:53:11 UTC (rev 1237)
@@ -788,7 +788,7 @@
 	if (new_pos != -1)
 	{
 		sci_goto_pos(doc_list[idx].sci, new_pos, TRUE); // set the cursor at the brace
-		sci_scroll_to_line(doc_list[idx].sci, -1, 0.5);
+		doc_list[idx].scroll_percent = 0.5F;
 	}
 }
 

Modified: trunk/src/sci_cb.c
===================================================================
--- trunk/src/sci_cb.c	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/sci_cb.c	2007-01-31 15:53:11 UTC (rev 1237)
@@ -54,6 +54,7 @@
 static void get_indent(ScintillaObject *sci, gint pos, gboolean use_this_line);
 static void auto_multiline(ScintillaObject *sci, gint pos);
 static gboolean is_comment(gint lexer, gint style);
+static void scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_view);
 
 
 // calls the edit popup menu in the editor
@@ -164,13 +165,16 @@
 			sci_cb_highlight_braces(sci, pos);
 
 			ui_update_statusbar(idx, pos);
-			
-			if (doc_list[idx].need_scrolling)
-			{	// scroll the document if needed because here it is already realised
-				sci_scroll_to_line(doc_list[idx].sci, -1, 0.5F);
-				doc_list[idx].need_scrolling = FALSE;
-			}		
 
+			/* Visible lines are only laid out accurately once [SCN_UPDATEUI] is sent,
+			 * so we need to only call sci_scroll_to_line here, because the document
+			 * may have line wrapping and folding enabled.
+			 * http://scintilla.sourceforge.net/ScintillaDoc.html#LineWrapping */
+			if (doc_list[idx].scroll_percent > 0.0F)
+			{
+				scroll_to_line(sci, -1, doc_list[idx].scroll_percent);
+				doc_list[idx].scroll_percent = -1.0F;	// disable further scrolling
+			}
 #if 0
 			/// experimental code for inverting selections
 			{
@@ -2078,3 +2082,30 @@
 	// reset the selection
 	sci_set_anchor(doc_list[idx].sci, pos);
 }
+
+
+/* Scroll the view to make line appear at percent_of_view.
+ * line can be -1 to use the current position. */
+static void scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_view)
+{
+	gint vis1, los, delta;
+	GtkWidget *wid = GTK_WIDGET(sci);
+
+	if (! wid->window || ! gdk_window_is_viewable(wid->window))
+		return;
+	//if (GTK_WIDGET(sci)->allocation.height <= 1) return;	// try to prevent gdk_window_scroll warning
+
+	if (line == -1)
+		line = sci_get_current_line(sci, -1);
+
+	// sci 'visible line' != doc line number because of folding and line wrapping
+	/* calling SCI_VISIBLEFROMDOCLINE for line is more accurate than calling
+	 * SCI_DOCLINEFROMVISIBLE for vis1. */
+	line = SSM(sci, SCI_VISIBLEFROMDOCLINE, line, 0);
+	vis1 = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
+	los = SSM(sci, SCI_LINESONSCREEN, 0, 0);
+	delta = (line - vis1) - los * percent_of_view;
+	sci_scroll_lines(sci, delta);
+	//sci_scroll_caret(sci); // ensure visible (maybe not needed now)
+}
+

Modified: trunk/src/sciwrappers.c
===================================================================
--- trunk/src/sciwrappers.c	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/sciwrappers.c	2007-01-31 15:53:11 UTC (rev 1237)
@@ -679,28 +679,6 @@
 }
 
 
-/* Scroll the view to make line appear at percent_of_view.
- * line can be -1 to use the current position. */
-void sci_scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_view)
-{
-	gint vis1, los, delta;
-
-	if (GTK_WIDGET(sci)->allocation.height <= 1) return;	// try to prevent gdk_window_scroll warning
-	if (line == -1)
-		line = sci_get_current_line(sci, -1);
-
-	// sci 'visible line' != doc line number because of folding and line wrapping
-	/* calling SCI_VISIBLEFROMDOCLINE for line is more accurate than calling
-	 * SCI_DOCLINEFROMVISIBLE for vis1. */
-	line = SSM(sci, SCI_VISIBLEFROMDOCLINE, line, 0);
-	vis1 = SSM(sci, SCI_GETFIRSTVISIBLELINE, 0, 0);
-	los = SSM(sci, SCI_LINESONSCREEN, 0, 0);
-	delta = (line - vis1) - los * percent_of_view;
-	sci_scroll_lines(sci, delta);
-	sci_scroll_caret(sci); // ensure visible (maybe not needed now)
-}
-
-
 gint sci_search_next(ScintillaObject *sci, gint flags, const gchar *text)
 {
 	return SSM(sci, SCI_SEARCHNEXT, flags, (sptr_t) text );

Modified: trunk/src/sciwrappers.h
===================================================================
--- trunk/src/sciwrappers.h	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/sciwrappers.h	2007-01-31 15:53:11 UTC (rev 1237)
@@ -125,7 +125,6 @@
 void				sci_set_anchor				(ScintillaObject * sci, gint pos);
 void				sci_scroll_caret			(ScintillaObject * sci);
 void				sci_scroll_lines			(ScintillaObject * sci, gint lines);
-void				sci_scroll_to_line			(ScintillaObject * sci, gint line, gfloat percent_of_view);
 gint				sci_search_next				(ScintillaObject * sci, gint flags, const gchar *text);
 gint				sci_search_prev				(ScintillaObject * sci, gint flags, const gchar *text);
 gint				sci_find_text				(ScintillaObject * sci, gint flags, struct TextToFind *ttf);

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2007-01-30 21:55:45 UTC (rev 1236)
+++ trunk/src/utils.c	2007-01-31 15:53:11 UTC (rev 1237)
@@ -226,7 +226,7 @@
 	sci_set_marker_at_line(doc_list[idx].sci, line, TRUE, 0);
 
 	sci_goto_line(doc_list[idx].sci, line, TRUE);
-	sci_scroll_to_line(doc_list[idx].sci, -1, 0.25);
+	doc_list[idx].scroll_percent = 0.25F;
 
 	// finally switch to the page
 	page_num = gtk_notebook_page_num(GTK_NOTEBOOK(app->notebook), GTK_WIDGET(doc_list[idx].sci));


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list