[balsa: 2/3] balsa-index: add a timeout to verify scrolling




commit 63c777cbef3cc96c52b198d4b3ba95ec95453250
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Sep 2 17:44:53 2020 -0400

    balsa-index: add a timeout to verify scrolling
    
    Add a timeout to verify that the scrolled-to row is actually visible,
    and, if it isn't, to call scroll-to-row again.
    
    * src/balsa-index.c
      (bndx_scroll_to_row_verify_timeout): the timeout handler;
      (bndx_scroll_to_row_idle): if the tree-view is realized, schedule the timeout.

 ChangeLog         | 10 ++++++++++
 src/balsa-index.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)
---
diff --git a/ChangeLog b/ChangeLog
index a34803ac2..d6912a239 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-09-02  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       balsa-index: add a timeout to verify that the scrolled-to row is
+       actually visible, and, if it isn't, to call scroll-to-row again
+
+       * src/balsa-index.c
+         (bndx_scroll_to_row_verify_timeout): the timeout handler;
+         (bndx_scroll_to_row_idle): if the tree-view is realized,
+           schedule the timeout.
+
 2020-08-24  Peter Bloomfield  <pbloomfield bellsouth net>
 
        * libbalsa/libbalsa-gpgme-widgets.c
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 554149df5..903d45d4e 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -861,21 +861,66 @@ balsa_index_new(void)
  */
 
 static gboolean
-bndx_scroll_to_row_idle(gpointer user_data)
+bndx_scroll_to_row_verify_timeout(gpointer user_data)
 {
     BalsaIndex *bindex = user_data;
     GtkTreeView *tree_view = GTK_TREE_VIEW(bindex);
     GtkTreePath *path;
 
     path = gtk_tree_row_reference_get_path(bindex->reference);
+
+    if (path != NULL) {
+        GdkRectangle visible_rect;
+        GdkRectangle row_rect;
+
+        gtk_tree_view_get_cell_area(tree_view, path, NULL, &row_rect);
+
+        gtk_tree_view_get_visible_rect(tree_view, &visible_rect);
+        gtk_tree_view_convert_tree_to_bin_window_coords(tree_view,
+                                                        visible_rect.x, visible_rect.y,
+                                                        &visible_rect.x, &visible_rect.y);
+
+        if (row_rect.y < visible_rect.y ||
+            row_rect.y + row_rect.height > visible_rect.y + visible_rect.height ) {
+            /* row is not completely visible, scroll and reschedule */
+            gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
+            gtk_tree_path_free(path);
+
+            return G_SOURCE_CONTINUE;
+        }
+        gtk_tree_path_free(path);
+    }
+
     gtk_tree_row_reference_free(bindex->reference);
     bindex->reference = NULL;
+    bindex->scroll_to_row_idle_id = 0;
+
+    return G_SOURCE_REMOVE;
+}
+
+static gboolean
+bndx_scroll_to_row_idle(gpointer user_data)
+{
+    BalsaIndex *bindex = user_data;
+    GtkTreeView *tree_view = GTK_TREE_VIEW(bindex);
+    GtkTreePath *path;
+
+    path = gtk_tree_row_reference_get_path(bindex->reference);
 
     if (path != NULL) {
         gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
         gtk_tree_path_free(path);
+
+        if (gtk_widget_get_realized(GTK_WIDGET(tree_view))) {
+            bindex->scroll_to_row_idle_id =
+                g_timeout_add(100, bndx_scroll_to_row_verify_timeout, bindex);
+
+            return G_SOURCE_REMOVE;
+        }
     }
 
+    gtk_tree_row_reference_free(bindex->reference);
+    bindex->reference = NULL;
     bindex->scroll_to_row_idle_id = 0;
 
     return G_SOURCE_REMOVE;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]