Fixing some pager bugs
authorrodin <rodin@ddfedd41-794f-dd11-ae45-00112f111e67>
Tue, 18 May 2010 14:41:29 +0000 (14:41 +0000)
committerrodin <rodin@ddfedd41-794f-dd11-ae45-00112f111e67>
Tue, 18 May 2010 14:41:29 +0000 (14:41 +0000)
libchimara/pager.c
libchimara/pager.h
libchimara/style.c
libchimara/window.c

index 2ab27554c955518fcce4ba89a9631f2482709b3a..c51dbd75e0c43574fd52d35a3a4af9125b0767b2 100644 (file)
@@ -59,51 +59,6 @@ stop_paging(winid_t win)
        g_signal_handler_block(win->widget, win->pager_keypress_handler);
 }
 
-/* Check whether paging should be done. This function is called inside the 
- * idle handler, after the textview has finished updating. */
-gboolean
-pager_check(gpointer data)
-{
-
-       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 );
-
-       gdk_threads_enter();
-
-       if(view_height <= 1)
-               /* 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);
-                       /* 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
-               }
-       }
-       gdk_threads_leave();
-
-       /* Returning FALSE to prevent this function from being called multiple times */
-       return FALSE;
-}
-
 /* When the user scrolls up in a textbuffer, start paging. */
 void
 pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win)
@@ -173,17 +128,40 @@ pager_on_expose(GtkTextView *textview, GdkEventExpose *event, winid_t win)
        return FALSE; /* Propagate event further */
 }
 
-gboolean
-pager_after_expose_event(GtkTextView *textview, GdkEventExpose *event, winid_t win)
-{
-       g_idle_add(pager_check, win);
-       return FALSE;
-}
+/* Check whether paging should be done. This function is called after the
+ * textview has finished validating text positions. */
+void pager_after_size_request(GtkTextView *textview, GtkRequisition
+               *requisition, winid_t 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
+                       );
 
-void
-pager_after_size_request(GtkTextView *textview, GtkRequisition *requisition, winid_t win)
-{
-       g_idle_add(pager_check, win);
+       if(view_height <= 1)
+               /* Paging is unusable when window is too small */
+               return;
+       
+       /* 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);
+                       /* 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
+               }
+       }
 }
 
 void
index 04c92ec4cebf74994f885a5d41c4858bf7dfa3c8..59188732dc9afdec306acd620619d0c389949ef7 100644 (file)
@@ -8,8 +8,6 @@
 G_GNUC_INTERNAL gboolean pager_on_expose(GtkTextView *textview, GdkEventExpose *event, winid_t win);
 G_GNUC_INTERNAL gboolean pager_on_key_press_event(GtkTextView *textview, GdkEventKey *event, winid_t win);
 G_GNUC_INTERNAL void pager_after_adjustment_changed(GtkAdjustment *adj, winid_t win);
-G_GNUC_INTERNAL gboolean pager_check(gpointer data);
-G_GNUC_INTERNAL gboolean pager_after_expose_event(GtkTextView *textview, GdkEventExpose *event, winid_t win);
 G_GNUC_INTERNAL void pager_after_size_request(GtkTextView *textview, GtkRequisition *requisition, winid_t win);
 G_GNUC_INTERNAL void pager_update(winid_t win);
 
index f31f2d660943d0d04b455e0e8b38cce8ea7b33c5..14ca359d00f887860016c68ad6d319bc93a1f91d 100644 (file)
@@ -907,12 +907,16 @@ glk_stylehint_clear(glui32 wintype, glui32 styl, glui32 hint)
 
        switch(wintype) {
        case wintype_TextBuffer:
-               tag = g_hash_table_lookup( glk_data->styles->text_buffer, get_glk_tag_name(styl) );
-               glk_stylehint_set( wintype, styl, hint, query_tag(tag, wintype, hint) );
+               tag = g_hash_table_lookup( glk_data->glk_styles->text_buffer, get_glk_tag_name(styl) );
+               if(tag) {
+                       glk_stylehint_set( wintype, styl, hint, query_tag(tag, wintype, hint) );
+               }
                break;
        case wintype_TextGrid:
-               tag = g_hash_table_lookup( glk_data->styles->text_grid, get_glk_tag_name(styl) );
-               glk_stylehint_set( wintype, styl, hint, query_tag(tag, wintype, hint) );
+               tag = g_hash_table_lookup( glk_data->glk_styles->text_grid, get_glk_tag_name(styl) );
+               if(tag) {
+                       glk_stylehint_set( wintype, styl, hint, query_tag(tag, wintype, hint) );
+               }
        default:
                return;
        }
index 224db4808cf789c5b4f72b9f4e35c8bb2db982b0..5b970f5be4bedd4d2e2990189b7ba434cd131bb4 100644 (file)
@@ -553,7 +553,6 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype,
                        /* Connect signal handlers */
                        
                        /* Pager */
-                       //g_signal_connect_after( textview, "expose-event", G_CALLBACK(pager_after_expose_event), win );
                        g_signal_connect_after( textview, "size-request", G_CALLBACK(pager_after_size_request), win );
                        win->pager_expose_handler = g_signal_connect_after( textview, "expose-event", G_CALLBACK(pager_on_expose), win );
                        g_signal_handler_block(textview, win->pager_expose_handler);