More pager improvements. Pager now determines correctly which text is read by the...
authorrodin <rodin@ddfedd41-794f-dd11-ae45-00112f111e67>
Tue, 11 May 2010 10:30:07 +0000 (10:30 +0000)
committerrodin <rodin@ddfedd41-794f-dd11-ae45-00112f111e67>
Tue, 11 May 2010 10:30:07 +0000 (10:30 +0000)
libchimara/input.c
libchimara/pager.c
libchimara/window.c
libchimara/window.h

index 43ed0453ddcc56a43394809eac0af3e916371884..d59191641ac2d892eb40ddec1e8215eddf09b83d 100644 (file)
@@ -435,6 +435,10 @@ on_char_input_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win
        the shift key when the user tries to type a capital letter */
        if(event->is_modifier)
                return FALSE; /* don't stop the event */
+
+       /* All text up to the input position is now regarded as being read by the user */
+       if(win->type == wintype_TextBuffer)
+               pager_update(win);
        
        glui32 keycode = keyval_to_glk_keycode(event->keyval, win->input_request_type == INPUT_REQUEST_CHARACTER_UNICODE);
 
@@ -456,6 +460,8 @@ on_line_input_key_press_event(GtkWidget *widget, GdkEventKey *event, winid_t win
        switch(win->type)
        {
                case wintype_TextBuffer:
+                       /* All text up to the input position is now regarded as being read by the user */
+                       pager_update(win);
 
                        /* History up/down */
                        if(event->keyval == GDK_Up || event->keyval == GDK_KP_Up
index c88ab63630c3918478e7c1d75027af4a85307175..294a6587aef1f5a84378f23b49772ca0924bffeb 100644 (file)
@@ -68,7 +68,6 @@ pager_check(gpointer data)
        printf("pager check (idle)...\n");
        winid_t win = (winid_t) data;
 
-
        /* Move the pager to the last visible character in the buffer */
        gint view_height, scroll_distance;
        move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance, FALSE );
@@ -79,6 +78,15 @@ pager_check(gpointer data)
                /* Paging is unusable when window is too small */
                return FALSE;
        
+       /* Scroll past text already read by user. This is automatic scrolling, so disable the pager_ajustment_handler
+        * first, that acts on the belief the scolling is performed by the user. */
+       GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(win->frame));
+       g_signal_handler_block(adj, win->pager_adjustment_handler);
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
+       GtkTextMark *pager_position = gtk_text_buffer_get_mark(buffer, "pager_position");
+       gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(win->widget), pager_position, 0.0, TRUE, 0.0, 0.0);
+       g_signal_handler_unblock(adj, win->pager_adjustment_handler);
+       
        if(!win->currently_paging) {
                if(scroll_distance > view_height) {
                        start_paging(win);
@@ -90,14 +98,6 @@ pager_check(gpointer data)
                        gdk_window_invalidate_rect(win->widget->window, NULL, TRUE);
 #endif
                }
-               else if(scroll_distance > 0) {
-                       if(win->input_request_type != INPUT_REQUEST_NONE) {
-                               GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
-                               GtkTextMark *end = gtk_text_buffer_get_mark(buffer, "end_position");
-
-                               gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), end);
-                       }
-               }
        }
        gdk_threads_leave();
 
@@ -179,36 +179,6 @@ pager_after_expose_event(GtkTextView *textview, GdkEventExpose *event, winid_t w
 {
        printf("pager check (expose)...\n");
        g_idle_add(pager_check, win);
-
-//     /* Move the pager to the last visible character in the buffer */
-//     gint view_height, scroll_distance;
-//     move_pager_and_get_scroll_distance( GTK_TEXT_VIEW(win->widget), &view_height, &scroll_distance, FALSE );
-//
-//     if(view_height <= 1)
-//             /* Paging is unusable when window is too small */
-//             return FALSE;
-//     
-//     if(!win->currently_paging) {
-//             if(scroll_distance > view_height) {
-//                     start_paging(win);
-//                     /* Seriously... */
-//                     /* COMPAT: */
-//#if GTK_CHECK_VERSION(2,14,0)
-//                     gdk_window_invalidate_rect(gtk_widget_get_window(win->widget), NULL, TRUE);
-//#else
-//                     gdk_window_invalidate_rect(win->widget->window, NULL, TRUE);
-//#endif
-//             }
-//             else if(scroll_distance > 0) {
-//                     if(win->input_request_type != INPUT_REQUEST_NONE) {
-//                             GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
-//                             GtkTextMark *end = gtk_text_buffer_get_mark(buffer, "end_position");
-//
-//                             gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(win->widget), end);
-//                     }
-//             }
-//     }
-
        return FALSE;
 }
 
@@ -218,3 +188,14 @@ pager_after_size_request(GtkTextView *textview, GtkRequisition *requisition, win
        printf("pager check (size request)...\n");
        g_idle_add(pager_check, win);
 }
+
+void
+pager_update(winid_t win)
+{
+       GtkTextIter input_iter;
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->widget));
+       GtkTextMark *input_position = gtk_text_buffer_get_mark(buffer, "input_position");
+       GtkTextMark *pager_position = gtk_text_buffer_get_mark(buffer, "pager_position");
+       gtk_text_buffer_get_iter_at_mark(buffer, &input_iter, input_position);
+       gtk_text_buffer_move_mark(buffer, pager_position, &input_iter);
+}
index 77c916e97f1cfa7aa4eae6f346719a107d878f6a..94042d1a9aaa901b0d2233453858cecc28518897 100644 (file)
@@ -559,7 +559,7 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        win->pager_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(pager_on_key_press_event), win );
                        g_signal_handler_block(textview, win->pager_keypress_handler);
                        GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolledwindow));
-                       g_signal_connect_after(adj, "value-changed", G_CALLBACK(pager_after_adjustment_changed), win);
+                       win->pager_adjustment_handler = g_signal_connect_after(adj, "value-changed", G_CALLBACK(pager_after_adjustment_changed), win);
 
                        /* Char and line input */
                        win->char_input_keypress_handler = g_signal_connect( textview, "key-press-event", G_CALLBACK(on_char_input_key_press_event), win );
@@ -585,7 +585,8 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
 
                        /* Create the pager position mark; it stands for the last character in the buffer
                         that has been on-screen */
-                       gtk_text_buffer_create_mark(textbuffer, "pager_position", &end, TRUE);
+                       GtkTextMark *pager_position = gtk_text_buffer_create_mark(textbuffer, "pager_position", &end, TRUE);
+                       gtk_text_mark_set_visible(pager_position, TRUE);
                }
                        break;
 
index e13549614351e776e35344f283152043fc46780a..bb9a2f66f945c2b61b4dfc69fadc8432154e9b25 100644 (file)
@@ -79,6 +79,7 @@ struct glk_window_struct
        gulong size_allocate_handler;
        gulong pager_expose_handler;
        gulong pager_keypress_handler;
+       gulong pager_adjustment_handler;
        /* Window buffer */
        GString *buffer;
        /* Hyperlinks */