[balsa/wip/gtk4] Lots of ABI breaks



commit 7da775db7a48f5d8c8378bf5fe8c40149e7713a2
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Jun 1 20:24:33 2019 -0400

    Lots of ABI breaks
    
    Major:
    GtkTreeView is no longer derivable; BalsaMBList and BalsaIndex now
    derive directly from GObject, with GtkTreeView members.
    
    Less major:
    GtkNative wass introduced.
    gtk_widget_get_toplevel() is replaced by gtk_widget_get_root().
    gtk_widget_set_has_surface() is a no-op.
    
    Truly minor:
    Use 'bindex' as the identifier for instances of BalsaIndex instead of
    'index'; prolly not yet complete.

 libbalsa/libbalsa-progress.c      |   2 +-
 libbalsa/source-viewer.c          |   2 +-
 src/balsa-cite-bar.c              |   1 -
 src/balsa-index.c                 | 660 ++++++++++++++++++++------------------
 src/balsa-index.h                 |   6 +-
 src/balsa-mblist.c                | 121 +++----
 src/balsa-mblist.h                |  10 +-
 src/balsa-message.c               |  36 +--
 src/balsa-mime-widget-image.c     |   2 +-
 src/balsa-mime-widget-message.c   |  16 +-
 src/balsa-mime-widget-text.c      |  20 +-
 src/balsa-mime-widget-vcalendar.c |  17 +-
 src/compose-window.c              |  45 +--
 src/folder-conf.c                 |   3 +-
 src/main-window.c                 | 272 ++++++++--------
 src/main-window.h                 |   3 +-
 src/message-window.c              |   2 +-
 src/pref-manager.c                |   8 +-
 src/toolbar-factory.c             |   2 +-
 19 files changed, 640 insertions(+), 588 deletions(-)
---
diff --git a/libbalsa/libbalsa-progress.c b/libbalsa/libbalsa-progress.c
index 3e65e1487..11d1a2002 100644
--- a/libbalsa/libbalsa-progress.c
+++ b/libbalsa/libbalsa-progress.c
@@ -327,7 +327,7 @@ remove_progress_widget(progress_widget_data_t *progress_data)
        guint rev_children = 0U;
 
        progress_data->fadeout_id = 0U;
-       parent_dialog = gtk_widget_get_toplevel(progress_data->revealer);
+       parent_dialog = GTK_WIDGET(gtk_widget_get_root(progress_data->revealer));
        gtk_widget_destroy(progress_data->revealer);
 
        /* count the GtkRevealer children left, so we can just destroy the dialogue if there is none */
diff --git a/libbalsa/source-viewer.c b/libbalsa/source-viewer.c
index 469f1b412..bddd61ab3 100644
--- a/libbalsa/source-viewer.c
+++ b/libbalsa/source-viewer.c
@@ -202,7 +202,7 @@ lsv_size_allocate_cb(GtkWidget * window, gint width, gint height,
     GdkSurface *surface;
     gboolean maximized;
 
-    surface = gtk_widget_get_surface(window);
+    surface = gtk_native_get_surface(GTK_NATIVE(window));
     if (surface == NULL)
         return;
 
diff --git a/src/balsa-cite-bar.c b/src/balsa-cite-bar.c
index 6d2f9e8fd..4ae0f5d47 100644
--- a/src/balsa-cite-bar.c
+++ b/src/balsa-cite-bar.c
@@ -57,7 +57,6 @@ balsa_cite_bar_class_init(BalsaCiteBarClass * class)
 static void
 balsa_cite_bar_init(BalsaCiteBar * cite_bar)
 {
-    gtk_widget_set_has_surface(GTK_WIDGET(cite_bar), FALSE);
 }
 
 GtkWidget *
diff --git a/src/balsa-index.c b/src/balsa-index.c
index f0b2e005c..865418f3a 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -66,11 +66,11 @@ static gboolean bndx_popup_menu(GtkWidget *widget);
 /* statics */
 
 /* Manage the tree view */
-static gboolean bndx_row_is_viewable(BalsaIndex  *index,
+static gboolean bndx_row_is_viewable(BalsaIndex  *bindex,
                                      GtkTreePath *path);
-static void     bndx_expand_to_row_and_select(BalsaIndex  *index,
+static void     bndx_expand_to_row_and_select(BalsaIndex  *bindex,
                                               GtkTreeIter *iter);
-static void     bndx_changed_find_row(BalsaIndex *index);
+static void     bndx_changed_find_row(BalsaIndex *bindex);
 
 /* mailbox callbacks */
 static void bndx_mailbox_changed_cb(LibBalsaMailbox *mailbox,
@@ -78,8 +78,8 @@ static void bndx_mailbox_changed_cb(LibBalsaMailbox *mailbox,
 
 /* GtkTree* callbacks */
 static void bndx_selection_changed(GtkTreeSelection *selection,
-                                   BalsaIndex       *index);
-static void bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+                                   BalsaIndex       *bindex);
+static void bndx_gesture_pressed_cb(GtkGestureClick *click,
                                     gint                  n_press,
                                     gdouble               x,
                                     gdouble               y,
@@ -106,12 +106,12 @@ static void bndx_tree_collapse_cb(GtkTreeView *tree_view,
                                   GtkTreePath *path,
                                   gpointer     user_data);
 
-/* formerly balsa-index-page stuff */
+/* formerly balsa-bindex-page stuff */
 enum {
     TARGET_MESSAGES
 };
 
-static const gchar *index_drag_types[] = {
+static const gchar *bindex_drag_types[] = {
     "x-application/x-message-list"
 };
 
@@ -121,8 +121,8 @@ static void bndx_drag_cb(GtkWidget        *widget,
                          gpointer          user_data);
 
 /* Popup menu */
-static GtkWidget *bndx_popup_menu_create(BalsaIndex *index);
-static void       bndx_do_popup(BalsaIndex     *index,
+static GtkWidget *bndx_popup_menu_create(BalsaIndex *bindex);
+static void       bndx_do_popup(BalsaIndex     *bindex,
                                 const GdkEvent *event);
 static GtkWidget *create_stock_menu_item(GtkWidget   *menu,
                                          const gchar *label,
@@ -143,9 +143,9 @@ static gint balsa_index_signals[LAST_SIGNAL] = {
 };
 
 /* General helpers. */
-static void bndx_expand_to_row(BalsaIndex  *index,
+static void bndx_expand_to_row(BalsaIndex  *bindex,
                                GtkTreePath *path);
-static void bndx_select_row(BalsaIndex  *index,
+static void bndx_select_row(BalsaIndex  *bindex,
                             GtkTreePath *path);
 
 /* Other callbacks. */
@@ -154,7 +154,9 @@ static void bndx_store_address(gpointer data);
 /* Class type. */
 
 struct _BalsaIndex {
-    GtkTreeView tree_view;
+    GObject parent_object;
+
+    GtkTreeView *tree_view;
 
     /* the popup menu and some items we need to refer to */
     GtkWidget *popup_menu;
@@ -186,17 +188,15 @@ struct _BalsaIndex {
 };
 
 
-G_DEFINE_TYPE(BalsaIndex, balsa_index, GTK_TYPE_TREE_VIEW)
+G_DEFINE_TYPE(BalsaIndex, balsa_index, G_TYPE_OBJECT)
 
 /* BalsaIndex class init method. */
 static void
 balsa_index_class_init(BalsaIndexClass *klass)
 {
     GObjectClass *object_class;
-    GtkWidgetClass *widget_class;
 
     object_class = (GObjectClass *) klass;
-    widget_class = (GtkWidgetClass *) klass;
 
     balsa_index_signals[INDEX_CHANGED] =
         g_signal_new("index-changed",
@@ -206,7 +206,6 @@ balsa_index_class_init(BalsaIndexClass *klass)
                      G_TYPE_NONE, 0);
 
     object_class->dispose    = bndx_destroy;
-    widget_class->popup_menu = bndx_popup_menu;
 }
 
 
@@ -217,42 +216,42 @@ bndx_mbnode_weak_notify(gpointer data,
 {
     BalsaIndex *bindex = data;
     bindex->mailbox_node = NULL;
-    gtk_widget_destroy(GTK_WIDGET(bindex));
+    gtk_widget_destroy(GTK_WIDGET(bindex->tree_view));
 }
 
 
 static void
 bndx_destroy(GObject *obj)
 {
-    BalsaIndex *index;
+    BalsaIndex *bindex;
 
     g_return_if_fail(obj != NULL);
-    index = BALSA_INDEX(obj);
+    bindex = BALSA_INDEX(obj);
 
-    if (index->mailbox_node) {
+    if (bindex->mailbox_node) {
         LibBalsaMailbox *mailbox;
 
-        mailbox = balsa_index_get_mailbox(index);
+        mailbox = balsa_index_get_mailbox(bindex);
         if (mailbox != NULL) {
             g_signal_handlers_disconnect_matched(mailbox,
                                                  G_SIGNAL_MATCH_DATA,
-                                                 0, 0, NULL, NULL, index);
-            gtk_tree_view_set_model(GTK_TREE_VIEW(index), NULL);
+                                                 0, 0, NULL, NULL, bindex);
+            gtk_tree_view_set_model(bindex->tree_view, NULL);
             libbalsa_mailbox_close(mailbox, balsa_app.expunge_on_close);
         }
 
-        if (index->mailbox_node) {
-            g_object_weak_unref(G_OBJECT(index->mailbox_node),
+        if (bindex->mailbox_node) {
+            g_object_weak_unref(G_OBJECT(bindex->mailbox_node),
                                 (GWeakNotify) bndx_mbnode_weak_notify,
-                                index);
-            index->mailbox_node = NULL;
+                                bindex);
+            bindex->mailbox_node = NULL;
         }
     }
 
-    g_clear_pointer(&index->search_iter, libbalsa_mailbox_search_iter_unref);
-    g_clear_pointer(&index->filter_string, g_free);
+    g_clear_pointer(&bindex->search_iter, libbalsa_mailbox_search_iter_unref);
+    g_clear_pointer(&bindex->filter_string, g_free);
 
-    g_clear_object(&index->popup_menu);
+    g_clear_object(&bindex->popup_menu);
 
     G_OBJECT_CLASS(balsa_index_parent_class)->dispose(obj);
 }
@@ -304,17 +303,22 @@ bndx_string_width(const gchar *text)
 /* BalsaIndex instance init method; no tree store is set on the tree
  * view--that's handled later, when the view is populated. */
 static void
-balsa_index_init(BalsaIndex *index)
+balsa_index_init(BalsaIndex *bindex)
 {
-    GtkWidget *widget           = GTK_WIDGET(index);
-    GtkTreeView *tree_view      = GTK_TREE_VIEW(index);
-    GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
+    GtkWidget *widget;
+    GtkTreeView *tree_view;
+    GtkTreeSelection *selection;
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
     GdkContentFormats *formats;
     GtkGesture *gesture;
     GtkEventController *controller;
 
+    widget = gtk_tree_view_new();
+    bindex->tree_view = tree_view = GTK_TREE_VIEW(widget);
+    g_object_set_data_full(G_OBJECT(tree_view), "balsa-index-object", bindex, g_object_unref);
+    selection = gtk_tree_view_get_selection(tree_view);
+
 #if defined(TREE_VIEW_FIXED_HEIGHT)
     gtk_tree_view_set_fixed_height_mode(tree_view, TRUE);
 #endif
@@ -428,21 +432,21 @@ balsa_index_init(BalsaIndex *index)
     gtk_tree_view_append_column(tree_view, column);
 
     /* Initialize some other members */
-    index->mailbox_node = NULL;
-    index->popup_menu   = bndx_popup_menu_create(index);
-    g_object_ref_sink(index->popup_menu);
+    bindex->mailbox_node = NULL;
+    bindex->popup_menu   = bndx_popup_menu_create(bindex);
+    g_object_ref_sink(bindex->popup_menu);
 
     gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
 
     /* handle select row signals to display message in the window
      * preview pane */
-    index->selection_changed_id =
+    bindex->selection_changed_id =
         g_signal_connect(selection, "changed",
-                         G_CALLBACK(bndx_selection_changed), index);
+                         G_CALLBACK(bndx_selection_changed), bindex);
 
     /* we want to handle button presses to pop up context menus if
      * necessary */
-    gesture = gtk_gesture_multi_press_new();
+    gesture = gtk_gesture_click_new();
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(bndx_gesture_pressed_cb), NULL);
@@ -456,12 +460,12 @@ balsa_index_init(BalsaIndex *index)
                      G_CALLBACK(bndx_row_activated), NULL);
 
     /* catch thread expand events */
-    index->row_expanded_id =
+    bindex->row_expanded_id =
         g_signal_connect_after(tree_view, "row-expanded",
                                G_CALLBACK(bndx_tree_expand_cb), NULL);
     g_signal_connect(tree_view, "test-collapse-row",
                      G_CALLBACK(bndx_test_collapse_row_cb), NULL);
-    index->row_collapsed_id =
+    bindex->row_collapsed_id =
         g_signal_connect_after(tree_view, "row-collapsed",
                                G_CALLBACK(bndx_tree_collapse_cb), NULL);
 
@@ -471,17 +475,20 @@ balsa_index_init(BalsaIndex *index)
                            NULL);
     gtk_tree_view_set_enable_search(tree_view, FALSE);
 
-    formats = gdk_content_formats_new(index_drag_types, G_N_ELEMENTS(index_drag_types));
-    gtk_drag_source_set(GTK_WIDGET (index),
+    formats = gdk_content_formats_new(bindex_drag_types, G_N_ELEMENTS(bindex_drag_types));
+    gtk_drag_source_set(GTK_WIDGET(tree_view),
                         GDK_BUTTON1_MASK | GDK_SHIFT_MASK | GDK_CONTROL_MASK,
                         formats,
                         GDK_ACTION_COPY | GDK_ACTION_MOVE);
     gdk_content_formats_unref(formats);
 
-    g_signal_connect(index, "drag-data-get",
+    g_signal_connect(tree_view, "drag-data-get",
                      G_CALLBACK(bndx_drag_cb), NULL);
 
-    balsa_index_set_column_widths(index);
+    g_signal_connect(tree_view, "popup-menu",
+                     G_CALLBACK(bndx_popup_menu), NULL);
+
+    balsa_index_set_column_widths(bindex);
     gtk_widget_show(widget);
 }
 
@@ -512,38 +519,38 @@ bndx_clear_if_last_ref(gpointer data)
  *
  * Callback for the selection "changed" signal.
  *
- * Do nothing if index->current_msgno is still selected;
+ * Do nothing if bindex->current_msgno is still selected;
  * otherwise, display the last (in tree order) selected message.
  */
 
 /* idle callback: */
 static gboolean
-bndx_selection_changed_idle(BalsaIndex *index)
+bndx_selection_changed_idle(BalsaIndex *bindex)
 {
     LibBalsaMailbox *mailbox;
     guint msgno;
     GtkTreeSelection *selection;
 
-    if (bndx_clear_if_last_ref(&index))
+    if (bndx_clear_if_last_ref(&bindex))
         return FALSE;
 
-    index->has_selection_changed_idle = FALSE;
+    bindex->has_selection_changed_idle = FALSE;
 
-    if (!index->mailbox_node)
+    if (!bindex->mailbox_node)
         return FALSE;
 
-    mailbox   = balsa_index_get_mailbox(index);
-    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(index));
+    mailbox   = balsa_index_get_mailbox(bindex);
+    selection = gtk_tree_view_get_selection(bindex->tree_view);
 
     /* Save next_msgno, because changing flags may zero it. */
-    msgno = index->next_msgno;
-    if (index->current_msgno) {
+    msgno = bindex->next_msgno;
+    if (bindex->current_msgno) {
         /* The current message has been deselected. */
-        g_signal_handler_block(selection, index->selection_changed_id);
-        libbalsa_mailbox_msgno_change_flags(mailbox, index->current_msgno,
+        g_signal_handler_block(selection, bindex->selection_changed_id);
+        libbalsa_mailbox_msgno_change_flags(mailbox, bindex->current_msgno,
                                             0,
                                             LIBBALSA_MESSAGE_FLAG_SELECTED);
-        g_signal_handler_unblock(selection, index->selection_changed_id);
+        g_signal_handler_unblock(selection, bindex->selection_changed_id);
     }
 
     if (msgno) {
@@ -553,12 +560,12 @@ bndx_selection_changed_idle(BalsaIndex *index)
             msgno = 0;
         } else {
             if (!gtk_tree_selection_path_is_selected(selection, path)) {
-                bndx_expand_to_row(index, path);
-                bndx_select_row(index, path);
+                bndx_expand_to_row(bindex, path);
+                bndx_select_row(bindex, path);
             }
             gtk_tree_path_free(path);
 
-            index->current_message_is_deleted =
+            bindex->current_message_is_deleted =
                 libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
                                                  LIBBALSA_MESSAGE_FLAG_DELETED,
                                                  0);
@@ -568,8 +575,8 @@ bndx_selection_changed_idle(BalsaIndex *index)
         }
     }
 
-    index->current_msgno = msgno;
-    bndx_changed_find_row(index);
+    bindex->current_msgno = msgno;
+    bndx_changed_find_row(bindex);
 
     return FALSE;
 }
@@ -590,20 +597,20 @@ bndx_selection_changed_func(GtkTreeModel *model,
 /* the signal handler: */
 static void
 bndx_selection_changed(GtkTreeSelection *selection,
-                       BalsaIndex       *index)
+                       BalsaIndex       *bindex)
 {
-    index->next_msgno = 0;
+    bindex->next_msgno = 0;
     gtk_tree_selection_selected_foreach(selection,
                                         (GtkTreeSelectionForeachFunc)
                                         bndx_selection_changed_func,
-                                        &index->next_msgno);
+                                        &bindex->next_msgno);
 
-    if (index->current_msgno) {
+    if (bindex->current_msgno) {
         LibBalsaMailbox *mailbox;
         GtkTreePath *path;
 
-        mailbox = balsa_index_get_mailbox(index);
-        if (libbalsa_mailbox_msgno_find(mailbox, index->current_msgno,
+        mailbox = balsa_index_get_mailbox(bindex);
+        if (libbalsa_mailbox_msgno_find(mailbox, bindex->current_msgno,
                                         &path, NULL)) {
             gboolean update_preview = TRUE;
 
@@ -611,37 +618,37 @@ bndx_selection_changed(GtkTreeSelection *selection,
                 /* The current message is still selected; we leave the
                  * preview unchanged. */
                 update_preview = FALSE;
-            } else if (index->collapsing
-                       && !bndx_row_is_viewable(index, path)) {
+            } else if (bindex->collapsing
+                       && !bndx_row_is_viewable(bindex, path)) {
                 /* The current message was deselected because its thread
                  * was collapsed; we leave the preview unchanged, and to
                  * avoid confusion, we unselect all messages. */
                 g_signal_handler_block(selection,
-                                       index->selection_changed_id);
+                                       bindex->selection_changed_id);
                 gtk_tree_selection_unselect_all(selection);
                 g_signal_handler_unblock(selection,
-                                         index->selection_changed_id);
+                                         bindex->selection_changed_id);
                 update_preview = FALSE;
             }
             gtk_tree_path_free(path);
 
             if (!update_preview) {
-                g_signal_emit(G_OBJECT(index), balsa_index_signals[INDEX_CHANGED], 0);
+                g_signal_emit(G_OBJECT(bindex), balsa_index_signals[INDEX_CHANGED], 0);
                 return;
             }
         }
     }
 
-    if (!index->has_selection_changed_idle) {
-        index->has_selection_changed_idle = TRUE;
+    if (!bindex->has_selection_changed_idle) {
+        bindex->has_selection_changed_idle = TRUE;
         g_idle_add((GSourceFunc) bndx_selection_changed_idle,
-                   g_object_ref(index));
+                   g_object_ref(bindex));
     }
 }
 
 
 static void
-bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+bndx_gesture_pressed_cb(GtkGestureClick *click,
                         gint                  n_press,
                         gdouble               x,
                         gdouble               y,
@@ -650,14 +657,14 @@ bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
     GtkGesture *gesture;
     GdkEventSequence *sequence;
     const GdkEvent *event;
-    BalsaIndex *index;
+    BalsaIndex *bindex;
     GtkTreeView *tree_view;
     gint bx;
     gint by;
     GtkTreePath *path;
 
-    gesture  = GTK_GESTURE(multi_press);
-    sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(multi_press));
+    gesture  = GTK_GESTURE(click);
+    sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(click));
     event    = gtk_gesture_get_last_event(gesture, sequence);
     g_return_if_fail(event != NULL);
     if (!gdk_event_triggers_context_menu(event))
@@ -665,8 +672,8 @@ bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
 
     gtk_gesture_set_sequence_state(gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
 
-    index     = BALSA_INDEX(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
-    tree_view = GTK_TREE_VIEW(index);
+    bindex     = BALSA_INDEX(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
+    tree_view = bindex->tree_view;
     gtk_tree_view_convert_widget_to_bin_window_coords(tree_view, (gint) x, (gint) y,
                                                       &bx, &by);
 
@@ -680,11 +687,11 @@ bndx_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
             gtk_tree_view_get_selection(tree_view);
 
         if (!gtk_tree_selection_path_is_selected(selection, path))
-            bndx_select_row(index, path);
+            bndx_select_row(bindex, path);
         gtk_tree_path_free(path);
     }
 
-    bndx_do_popup(index, event);
+    bndx_do_popup(bindex, event);
 }
 
 
@@ -709,7 +716,7 @@ bndx_row_activated(GtkTreeView       *tree_view,
      * a compose window */
     if (mailbox == balsa_app.draftbox) {
         /* the simplest way to get a compose window would be:
-         * balsa_message_continue(widget, (gpointer) index);
+         * balsa_message_continue(widget, (gpointer) bindex);
          *
          * instead we'll just use the guts of
          * balsa_message_continue: */
@@ -755,14 +762,14 @@ bndx_tree_expand_cb(GtkTreeView *tree_view,
                     GtkTreePath *path,
                     gpointer     user_data)
 {
-    BalsaIndex *index           = BALSA_INDEX(tree_view);
+    BalsaIndex *bindex           = BALSA_INDEX(tree_view);
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
     GtkTreePath *current_path;
 
     /* If current message has become viewable, reselect it. */
-    if (bndx_find_current_msgno(index, &current_path, NULL)) {
+    if (bndx_find_current_msgno(bindex, &current_path, NULL)) {
         if (!gtk_tree_selection_path_is_selected(selection, current_path)
-            && bndx_row_is_viewable(index, current_path)) {
+            && bndx_row_is_viewable(bindex, current_path)) {
             gtk_tree_selection_select_path(selection, current_path);
             gtk_tree_view_set_cursor(tree_view, current_path, NULL, FALSE);
             gtk_tree_view_scroll_to_cell(tree_view, current_path,
@@ -770,7 +777,7 @@ bndx_tree_expand_cb(GtkTreeView *tree_view,
         }
         gtk_tree_path_free(current_path);
     }
-    bndx_changed_find_row(index);
+    bndx_changed_find_row(bindex);
 }
 
 
@@ -784,8 +791,8 @@ bndx_test_collapse_row_cb(GtkTreeView *tree_view,
                           GtkTreePath *path,
                           gpointer     user_data)
 {
-    BalsaIndex *index = BALSA_INDEX(tree_view);
-    index->collapsing = TRUE;
+    BalsaIndex *bindex = BALSA_INDEX(tree_view);
+    bindex->collapsing = TRUE;
     return FALSE;
 }
 
@@ -800,9 +807,9 @@ bndx_tree_collapse_cb(GtkTreeView *tree_view,
                       GtkTreePath *path,
                       gpointer     user_data)
 {
-    BalsaIndex *index = BALSA_INDEX(tree_view);
-    index->collapsing = FALSE;
-    bndx_changed_find_row(index);
+    BalsaIndex *bindex = BALSA_INDEX(tree_view);
+    bindex->collapsing = FALSE;
+    bndx_changed_find_row(bindex);
 }
 
 
@@ -842,7 +849,7 @@ bndx_column_resize(GtkWidget     *widget,
 
 /* bndx_drag_cb
  *
- * This is the drag_data_get callback for the index widgets.
+ * This is the drag_data_get callback for the bindex widgets.
  * Currently supports DND only within the application.
  */
 static void
@@ -851,34 +858,34 @@ bndx_drag_cb(GtkWidget        *widget,
              GtkSelectionData *data,
              gpointer          user_data)
 {
-    BalsaIndex *index;
+    BalsaIndex *bindex;
 
     g_return_if_fail(widget != NULL);
 
-    index = BALSA_INDEX(widget);
+    bindex = BALSA_INDEX(widget);
 
     if (gtk_tree_selection_count_selected_rows
-            (gtk_tree_view_get_selection(GTK_TREE_VIEW(index))) > 0) {
+            (gtk_tree_view_get_selection(bindex->tree_view)) > 0) {
         gtk_selection_data_set(data, gtk_selection_data_get_target(data),
-                               8, (const guchar *) &index,
+                               8, (const guchar *) &bindex,
                                sizeof(BalsaIndex *));
     }
 }
 
 
 /* Public methods */
-GtkWidget *
+BalsaIndex *
 balsa_index_new(void)
 {
-    BalsaIndex *index = g_object_new(BALSA_TYPE_INDEX, NULL);
+    BalsaIndex *bindex = g_object_new(BALSA_TYPE_INDEX, NULL);
 
-    return GTK_WIDGET(index);
+    return bindex;
 }
 
 
 /**
  * balsa_index_scroll_on_open() moves to the first unread message in
- * the index, or the last message if none is unread, and selects
+ * the bindex, or the last message if none is unread, and selects
  * it. Since this routine is usually called from a thread, we have to
  * take care and and make sure the row is selected from the main
  * thread only. And we also check whether the mailbox hasn't been
@@ -886,19 +893,19 @@ balsa_index_new(void)
  */
 
 static gboolean
-bndx_scroll_on_open_idle(BalsaIndex *index)
+bndx_scroll_on_open_idle(BalsaIndex *bindex)
 {
     LibBalsaMailbox *mailbox;
     guint msgno;
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view = bindex->tree_view;
     GtkTreePath *path;
     gpointer view_on_open;
 
-    if (bndx_clear_if_last_ref(&index))
+    if (bndx_clear_if_last_ref(&bindex))
         return FALSE;
 
-    balsa_index_update_tree(index, balsa_app.expand_tree);
-    mailbox = balsa_index_get_mailbox(index);
+    balsa_index_update_tree(bindex, balsa_app.expand_tree);
+    mailbox = balsa_index_get_mailbox(bindex);
     if ((msgno = libbalsa_mailbox_get_first_unread(mailbox))) {
         libbalsa_mailbox_set_first_unread(mailbox, 0);
         if (!libbalsa_mailbox_msgno_find(mailbox, msgno, &path, NULL))
@@ -916,7 +923,7 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
         path = gtk_tree_path_new_from_indices(total - 1, -1);
     }
 
-    bndx_expand_to_row(index, path);
+    bndx_expand_to_row(bindex, path);
     gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
 
     view_on_open =
@@ -926,10 +933,10 @@ bndx_scroll_on_open_idle(BalsaIndex *index)
     if (gtk_tree_view_get_model(tree_view)) {
         if ((view_on_open && GPOINTER_TO_INT(view_on_open))
             || balsa_app.view_message_on_open) {
-            bndx_select_row(index, path);
+            bndx_select_row(bindex, path);
         } else {
             GtkTreeSelection *selection;
-            gulong changed_id = index->selection_changed_id;
+            gulong changed_id = bindex->selection_changed_id;
 
             selection = gtk_tree_view_get_selection(tree_view);
             g_signal_handler_block(selection, changed_id);
@@ -961,7 +968,7 @@ static LibBalsaCondition *cond_undeleted;
 struct bndx_mailbox_row_inserted_info {
     LibBalsaMailbox *mailbox;
     guint            msgno;
-    BalsaIndex      *index;
+    BalsaIndex      *bindex;
 };
 
 static gboolean
@@ -970,11 +977,11 @@ bndx_mailbox_row_inserted_idle(struct bndx_mailbox_row_inserted_info *info)
     GtkTreePath *path;
     if (libbalsa_mailbox_msgno_find(info->mailbox, info->msgno,
                                     &path, NULL)) {
-        bndx_expand_to_row(info->index, path);
+        bndx_expand_to_row(info->bindex, path);
         gtk_tree_path_free(path);
     }
     g_object_unref(info->mailbox);
-    g_object_unref(info->index);
+    g_object_unref(info->bindex);
     g_free(info);
     return FALSE;
 }
@@ -984,7 +991,7 @@ static void
 bndx_mailbox_row_inserted_cb(LibBalsaMailbox *mailbox,
                              GtkTreePath     *path,
                              GtkTreeIter     *iter,
-                             BalsaIndex      *index)
+                             BalsaIndex      *bindex)
 {
     guint msgno;
 
@@ -1006,8 +1013,8 @@ bndx_mailbox_row_inserted_cb(LibBalsaMailbox *mailbox,
             g_new(struct bndx_mailbox_row_inserted_info, 1);
         info->mailbox = mailbox;
         g_object_ref(mailbox);
-        info->index = index;
-        g_object_ref(index);
+        info->bindex = bindex;
+        g_object_ref(bindex);
         info->msgno = msgno;
         g_idle_add_full(G_PRIORITY_LOW, /* to run after threading */
                         (GSourceFunc) bndx_mailbox_row_inserted_idle,
@@ -1039,14 +1046,14 @@ bndx_mailbox_message_expunged_cb(LibBalsaMailbox *mailbox,
  */
 
 gboolean
-balsa_index_load_mailbox_node(BalsaIndex       *index,
+balsa_index_load_mailbox_node(BalsaIndex       *bindex,
                               BalsaMailboxNode *mbnode)
 {
     GtkTreeView *tree_view;
     LibBalsaMailbox *mailbox;
 
-    g_return_val_if_fail(BALSA_IS_INDEX(index), TRUE);
-    g_return_val_if_fail(index->mailbox_node == NULL, TRUE);
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), TRUE);
+    g_return_val_if_fail(bindex->mailbox_node == NULL, TRUE);
     g_return_val_if_fail(BALSA_IS_MAILBOX_NODE(mbnode), TRUE);
     mailbox = balsa_mailbox_node_get_mailbox(mbnode);
     g_return_val_if_fail(LIBBALSA_IS_MAILBOX(mailbox), TRUE);
@@ -1054,26 +1061,26 @@ balsa_index_load_mailbox_node(BalsaIndex       *index,
     /*
      * set the new mailbox
      */
-    index->mailbox_node = mbnode;
+    bindex->mailbox_node = mbnode;
     g_object_weak_ref(G_OBJECT(mbnode),
-                      (GWeakNotify) bndx_mbnode_weak_notify, index);
+                      (GWeakNotify) bndx_mbnode_weak_notify, bindex);
     /*
      * rename "from" column to "to" for outgoing mail
      */
-    tree_view = GTK_TREE_VIEW(index);
+    tree_view = bindex->tree_view;
     if (libbalsa_mailbox_get_show(mailbox) == LB_MAILBOX_SHOW_TO) {
         GtkTreeViewColumn *column =
             gtk_tree_view_get_column(tree_view, LB_MBOX_FROM_COL);
-        index->filter_no = 1; /* FIXME: this is hack! */
+        bindex->filter_no = 1; /* FIXME: this is hack! */
         gtk_tree_view_column_set_title(column, _("To"));
     }
 
     g_signal_connect(mailbox, "changed",
-                     G_CALLBACK(bndx_mailbox_changed_cb), index);
+                     G_CALLBACK(bndx_mailbox_changed_cb), bindex);
     g_signal_connect(mailbox, "row-inserted",
-                     G_CALLBACK(bndx_mailbox_row_inserted_cb), index);
+                     G_CALLBACK(bndx_mailbox_row_inserted_cb), bindex);
     g_signal_connect(mailbox, "message-expunged",
-                     G_CALLBACK(bndx_mailbox_message_expunged_cb), index);
+                     G_CALLBACK(bndx_mailbox_message_expunged_cb), bindex);
 
     /* Set the tree store */
 #ifndef GTK2_FETCHES_ONLY_VISIBLE_CELLS
@@ -1087,9 +1094,9 @@ balsa_index_load_mailbox_node(BalsaIndex       *index,
             libbalsa_condition_new_flag_enum(TRUE,
                                              LIBBALSA_MESSAGE_FLAG_DELETED);
     }
-    index->search_iter = libbalsa_mailbox_search_iter_new(cond_undeleted);
+    bindex->search_iter = libbalsa_mailbox_search_iter_new(cond_undeleted);
     /* Note when this mailbox was opened, for use in auto-closing. */
-    balsa_index_set_last_use(index);
+    balsa_index_set_last_use(bindex);
 
     return FALSE;
 }
@@ -1115,7 +1122,7 @@ balsa_index_set_width_preference(BalsaIndex               *bindex,
         break;
     }
 
-    tree_view = GTK_TREE_VIEW(bindex);
+    tree_view = bindex->tree_view;
     gtk_tree_view_column_set_visible
         (gtk_tree_view_get_column(tree_view, LB_MBOX_MSGNO_COL), visible);
     gtk_tree_view_column_set_visible
@@ -1183,10 +1190,10 @@ typedef enum {
 } BndxSearchWrap;
 
 static gboolean
-bndx_find_root(BalsaIndex  *index,
+bndx_find_root(BalsaIndex  *bindex,
                GtkTreeIter *iter)
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view = bindex->tree_view;
     GtkTreeModel *model    = gtk_tree_view_get_model(tree_view);
 
     if (!model || !gtk_tree_model_get_iter_first(model, iter))
@@ -1198,7 +1205,7 @@ bndx_find_root(BalsaIndex  *index,
 
 
 static gboolean
-bndx_search_iter(BalsaIndex                *index,
+bndx_search_iter(BalsaIndex                *bindex,
                  LibBalsaMailboxSearchIter *search_iter,
                  GtkTreeIter               *iter,
                  BndxSearchDirection        direction,
@@ -1208,7 +1215,7 @@ bndx_search_iter(BalsaIndex                *index,
     LibBalsaMailbox *mailbox;
     gboolean found;
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
 
     do {
         GtkTreePath *path;
@@ -1224,7 +1231,7 @@ bndx_search_iter(BalsaIndex                *index,
             break;
 
         path  = gtk_tree_model_get_path(GTK_TREE_MODEL(mailbox), iter);
-        found = bndx_row_is_viewable(index, path);
+        found = bndx_row_is_viewable(bindex, path);
         gtk_tree_path_free(path);
     } while (!found);
 
@@ -1233,7 +1240,7 @@ bndx_search_iter(BalsaIndex                *index,
 
 
 static gboolean
-bndx_search_iter_and_select(BalsaIndex                *index,
+bndx_search_iter_and_select(BalsaIndex                *bindex,
                             LibBalsaMailboxSearchIter *search_iter,
                             BndxSearchDirection        direction,
                             BndxSearchViewable         viewable,
@@ -1244,33 +1251,33 @@ bndx_search_iter_and_select(BalsaIndex                *index,
     GtkTreeIter iter;
     guint stop_msgno;
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
 
-    if (!(((index->next_msgno > 0)
-           && libbalsa_mailbox_msgno_find(mailbox, index->next_msgno,
+    if (!(((bindex->next_msgno > 0)
+           && libbalsa_mailbox_msgno_find(mailbox, bindex->next_msgno,
                                           NULL, &iter))
           || ((start == BNDX_SEARCH_START_ANY)
-              && bndx_find_root(index, &iter))))
+              && bndx_find_root(bindex, &iter))))
         return FALSE;
 
     stop_msgno = 0;
-    if ((wrap == BNDX_SEARCH_WRAP_YES) && index->next_msgno)
-        stop_msgno = index->next_msgno;
-    if (!bndx_search_iter(index, search_iter, &iter, direction, viewable,
+    if ((wrap == BNDX_SEARCH_WRAP_YES) && bindex->next_msgno)
+        stop_msgno = bindex->next_msgno;
+    if (!bndx_search_iter(bindex, search_iter, &iter, direction, viewable,
                           stop_msgno))
         return FALSE;
 
-    bndx_expand_to_row_and_select(index, &iter);
+    bndx_expand_to_row_and_select(bindex, &iter);
     return TRUE;
 }
 
 
 void
-balsa_index_select_next(BalsaIndex *index)
+balsa_index_select_next(BalsaIndex *bindex)
 {
-    g_return_if_fail(BALSA_IS_INDEX(index));
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
 
-    bndx_search_iter_and_select(index, index->search_iter,
+    bndx_search_iter_and_select(bindex, bindex->search_iter,
                                 BNDX_SEARCH_DIRECTION_NEXT,
                                 BNDX_SEARCH_VIEWABLE_ONLY,
                                 BNDX_SEARCH_START_CURRENT,
@@ -1279,17 +1286,17 @@ balsa_index_select_next(BalsaIndex *index)
 
 
 static void
-bndx_select_next_threaded(BalsaIndex *index)
+bndx_select_next_threaded(BalsaIndex *bindex)
 {
     /* Make sure we start at the current message: */
-    index->next_msgno = index->current_msgno;
+    bindex->next_msgno = bindex->current_msgno;
 
-    if (!bndx_search_iter_and_select(index, index->search_iter,
+    if (!bndx_search_iter_and_select(bindex, bindex->search_iter,
                                      BNDX_SEARCH_DIRECTION_NEXT,
                                      BNDX_SEARCH_VIEWABLE_ANY,
                                      BNDX_SEARCH_START_CURRENT,
                                      BNDX_SEARCH_WRAP_NO)
-        && !bndx_search_iter_and_select(index, index->search_iter,
+        && !bndx_search_iter_and_select(bindex, bindex->search_iter,
                                         BNDX_SEARCH_DIRECTION_PREV,
                                         BNDX_SEARCH_VIEWABLE_ONLY,
                                         BNDX_SEARCH_START_CURRENT,
@@ -1297,17 +1304,17 @@ bndx_select_next_threaded(BalsaIndex *index)
         /* Nowhere to go--unselect current, so it can be filtered out of
          * the view. */
         gtk_tree_selection_unselect_all(gtk_tree_view_get_selection
-                                            (GTK_TREE_VIEW(index)));
+                                            (bindex->tree_view));
     }
 }
 
 
 void
-balsa_index_select_previous(BalsaIndex *index)
+balsa_index_select_previous(BalsaIndex *bindex)
 {
-    g_return_if_fail(BALSA_IS_INDEX(index));
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
 
-    bndx_search_iter_and_select(index, index->search_iter,
+    bndx_search_iter_and_select(bindex, bindex->search_iter,
                                 BNDX_SEARCH_DIRECTION_PREV,
                                 BNDX_SEARCH_VIEWABLE_ONLY,
                                 BNDX_SEARCH_START_CURRENT,
@@ -1316,14 +1323,14 @@ balsa_index_select_previous(BalsaIndex *index)
 
 
 void
-balsa_index_find(BalsaIndex                *index,
+balsa_index_find(BalsaIndex                *bindex,
                  LibBalsaMailboxSearchIter *search_iter,
                  gboolean                   previous,
                  gboolean                   wrap)
 {
-    g_return_if_fail(BALSA_IS_INDEX(index));
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
 
-    bndx_search_iter_and_select(index, search_iter,
+    bndx_search_iter_and_select(bindex, search_iter,
                                 (previous ?
                                  BNDX_SEARCH_DIRECTION_PREV :
                                  BNDX_SEARCH_DIRECTION_NEXT),
@@ -1336,14 +1343,14 @@ balsa_index_find(BalsaIndex                *index,
 
 
 static gboolean
-bndx_select_next_with_flag(BalsaIndex         *index,
+bndx_select_next_with_flag(BalsaIndex         *bindex,
                            LibBalsaMessageFlag flag)
 {
     LibBalsaCondition *cond_flag, *cond_and;
     LibBalsaMailboxSearchIter *search_iter;
     gboolean retval;
 
-    g_assert(BALSA_IS_INDEX(index));
+    g_assert(BALSA_IS_INDEX(bindex));
 
     cond_flag = libbalsa_condition_new_flag_enum(FALSE, flag);
     cond_and  =
@@ -1354,7 +1361,7 @@ bndx_select_next_with_flag(BalsaIndex         *index,
     search_iter = libbalsa_mailbox_search_iter_new(cond_and);
     libbalsa_condition_unref(cond_and);
 
-    retval = bndx_search_iter_and_select(index, search_iter,
+    retval = bndx_search_iter_and_select(bindex, search_iter,
                                          BNDX_SEARCH_DIRECTION_NEXT,
                                          BNDX_SEARCH_VIEWABLE_ANY,
                                          BNDX_SEARCH_START_ANY,
@@ -1367,20 +1374,20 @@ bndx_select_next_with_flag(BalsaIndex         *index,
 
 
 gboolean
-balsa_index_select_next_unread(BalsaIndex *index)
+balsa_index_select_next_unread(BalsaIndex *bindex)
 {
-    g_return_val_if_fail(BALSA_IS_INDEX(index), FALSE);
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), FALSE);
 
-    return bndx_select_next_with_flag(index, LIBBALSA_MESSAGE_FLAG_NEW);
+    return bndx_select_next_with_flag(bindex, LIBBALSA_MESSAGE_FLAG_NEW);
 }
 
 
 void
-balsa_index_select_next_flagged(BalsaIndex *index)
+balsa_index_select_next_flagged(BalsaIndex *bindex)
 {
-    g_return_if_fail(BALSA_IS_INDEX(index));
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
 
-    bndx_select_next_with_flag(index, LIBBALSA_MESSAGE_FLAG_FLAGGED);
+    bndx_select_next_with_flag(bindex, LIBBALSA_MESSAGE_FLAG_FLAGGED);
 }
 
 
@@ -1406,15 +1413,15 @@ balsa_index_get_next_msgno(BalsaIndex *bindex)
  * Note: iter must be valid; it isn't checked here.
  */
 static void
-bndx_expand_to_row_and_select(BalsaIndex  *index,
+bndx_expand_to_row_and_select(BalsaIndex  *bindex,
                               GtkTreeIter *iter)
 {
-    GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(index));
+    GtkTreeModel *model = gtk_tree_view_get_model(bindex->tree_view);
     GtkTreePath *path;
 
     path = gtk_tree_model_get_path(model, iter);
-    bndx_expand_to_row(index, path);
-    bndx_select_row(index, path);
+    bndx_expand_to_row(bindex, path);
+    bndx_select_row(bindex, path);
     gtk_tree_path_free(path);
 }
 
@@ -1422,9 +1429,9 @@ bndx_expand_to_row_and_select(BalsaIndex  *index,
 /* End of select message interfaces. */
 
 void
-balsa_index_set_column_widths(BalsaIndex *index)
+balsa_index_set_column_widths(BalsaIndex *bindex)
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view = bindex->tree_view;
     gint icon_w            = 16;
 
 #if defined(TREE_VIEW_FIXED_HEIGHT)
@@ -1465,10 +1472,12 @@ balsa_index_set_column_widths(BalsaIndex *index)
  */
 
 static gboolean
-bndx_queue_draw_idle_cb(gpointer bindex)
+bndx_queue_draw_idle_cb(gpointer user_data)
 {
+    BalsaIndex *bindex = user_data;
+
     if (!bndx_clear_if_last_ref(&bindex))
-        gtk_widget_queue_draw(bindex);
+        gtk_widget_queue_draw(GTK_WIDGET(bindex->tree_view));
 
     return FALSE;
 }
@@ -1514,7 +1523,7 @@ static void
 bndx_mailbox_changed_cb(LibBalsaMailbox *mailbox,
                         BalsaIndex      *bindex)
 {
-    if (!gtk_widget_get_realized(GTK_WIDGET(bindex)))
+    if (!gtk_widget_get_realized(GTK_WIDGET(bindex->tree_view)))
         return;
 
     /* Find the next message to be shown now, not later in the idle
@@ -1551,10 +1560,10 @@ bndx_selected_msgnos_func(GtkTreeModel *model,
 
 
 GArray *
-balsa_index_selected_msgnos_new(BalsaIndex *index)
+balsa_index_selected_msgnos_new(BalsaIndex *bindex)
 {
     GArray *msgnos              = g_array_new(FALSE, FALSE, sizeof(guint));
-    GtkTreeView *tree_view      = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view      = bindex->tree_view;
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
     LibBalsaMailbox *mailbox;
 
@@ -1562,7 +1571,7 @@ balsa_index_selected_msgnos_new(BalsaIndex *index)
                                         (GtkTreeSelectionForeachFunc)
                                         bndx_selected_msgnos_func, msgnos);
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
     libbalsa_mailbox_register_msgnos(mailbox, msgnos);
 
     return msgnos;
@@ -1570,12 +1579,12 @@ balsa_index_selected_msgnos_new(BalsaIndex *index)
 
 
 void
-balsa_index_selected_msgnos_free(BalsaIndex *index,
+balsa_index_selected_msgnos_free(BalsaIndex *bindex,
                                  GArray     *msgnos)
 {
     LibBalsaMailbox *mailbox;
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
     libbalsa_mailbox_unregister_msgnos(mailbox, msgnos);
     g_array_unref(msgnos);
 }
@@ -1584,13 +1593,13 @@ balsa_index_selected_msgnos_free(BalsaIndex *index,
 static void
 bndx_view_source(gpointer data)
 {
-    BalsaIndex *index = BALSA_INDEX(data);
+    BalsaIndex *bindex = BALSA_INDEX(data);
     LibBalsaMailbox *mailbox;
     guint i;
     GArray *selected;
 
-    selected = balsa_index_selected_msgnos_new(index);
-    mailbox  = balsa_index_get_mailbox(index);
+    selected = balsa_index_selected_msgnos_new(bindex);
+    mailbox  = balsa_index_get_mailbox(bindex);
 
     for (i = 0; i < selected->len; i++) {
         guint msgno              = g_array_index(selected, guint, i);
@@ -1606,7 +1615,7 @@ bndx_view_source(gpointer data)
                                      &balsa_app.source_height);
         g_object_unref(message);
     }
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
 }
 
 
@@ -1645,12 +1654,12 @@ balsa_index_selected_list_func(GtkTreeModel *model,
  * Free with g_list_foreach(l,g_object_unref)/g_list_free.
  */
 GList *
-balsa_index_selected_list(BalsaIndex *index)
+balsa_index_selected_list(BalsaIndex *bindex)
 {
-    GtkTreeSelection *selection =
-        gtk_tree_view_get_selection(GTK_TREE_VIEW(index));
+    GtkTreeSelection *selection;
     GList *list = NULL;
 
+    selection = gtk_tree_view_get_selection(bindex->tree_view);
     gtk_tree_selection_selected_foreach(selection,
                                         balsa_index_selected_list_func,
                                         &list);
@@ -1664,7 +1673,7 @@ balsa_index_selected_list(BalsaIndex *index)
  * message
  */
 static void
-bndx_compose_foreach(BalsaIndex *index,
+bndx_compose_foreach(BalsaIndex *bindex,
                      SendType    send_type)
 {
     LibBalsaMailbox *mailbox;
@@ -1672,9 +1681,9 @@ bndx_compose_foreach(BalsaIndex *index,
     guint i;
     guint skipped = 0U;
 
-    mailbox  = balsa_index_get_mailbox(index);
+    mailbox  = balsa_index_get_mailbox(bindex);
 
-    selected = balsa_index_selected_msgnos_new(index);
+    selected = balsa_index_selected_msgnos_new(bindex);
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
         BalsaComposeWindow *compose_window;
@@ -1702,7 +1711,7 @@ bndx_compose_foreach(BalsaIndex *index,
             ++skipped;
         }
     }
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
 
     if (skipped != 0U) {
         balsa_information_parented
@@ -1752,19 +1761,19 @@ balsa_message_continue(gpointer user_data)
  * selected messages
  */
 static void
-bndx_compose_from_list(BalsaIndex *index,
+bndx_compose_from_list(BalsaIndex *bindex,
                        SendType    send_type)
 {
     GArray *selected;
     LibBalsaMailbox *mailbox;
     BalsaComposeWindow *compose_window;
 
-    selected = balsa_index_selected_msgnos_new(index);
-    mailbox  = balsa_index_get_mailbox(index);
+    selected = balsa_index_selected_msgnos_new(bindex);
+    mailbox  = balsa_index_get_mailbox(bindex);
 
     compose_window = balsa_compose_window_new_from_list(mailbox, selected, send_type);
 
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
     g_signal_connect(compose_window, "destroy",
                      G_CALLBACK(bndx_compose_window_destroy_cb), NULL);
 }
@@ -1800,7 +1809,7 @@ balsa_message_forward_default(gpointer user_data)
  * bndx_do_delete: helper for message delete methods
  */
 static void
-bndx_do_delete(BalsaIndex *index,
+bndx_do_delete(BalsaIndex *bindex,
                gboolean    move_to_trash)
 {
     BalsaIndex *trash;
@@ -1810,8 +1819,8 @@ bndx_do_delete(BalsaIndex *index,
     guint i;
 
     trash    = balsa_find_index_by_mailbox(balsa_app.trash);
-    selected = balsa_index_selected_msgnos_new(index);
-    mailbox  = balsa_index_get_mailbox(index);
+    selected = balsa_index_selected_msgnos_new(bindex);
+    mailbox  = balsa_index_get_mailbox(bindex);
 
     messages = g_array_new(FALSE, FALSE, sizeof(guint));
     for (i = 0; i < selected->len; i++) {
@@ -1822,7 +1831,7 @@ bndx_do_delete(BalsaIndex *index,
     }
 
     if (messages->len) {
-        if (move_to_trash && (index != trash)) {
+        if (move_to_trash && (bindex != trash)) {
             GError *err = NULL;
             if (!libbalsa_mailbox_messages_move(mailbox, messages,
                                                 balsa_app.trash, &err)) {
@@ -1837,12 +1846,12 @@ bndx_do_delete(BalsaIndex *index,
             libbalsa_mailbox_messages_change_flags
                 (mailbox, messages, LIBBALSA_MESSAGE_FLAG_DELETED,
                 (LibBalsaMessageFlag) 0);
-            if (index == trash)
+            if (bindex == trash)
                 enable_empty_trash(balsa_app.main_window, TRASH_CHECK);
         }
     }
     g_array_unref(messages);
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
 }
 
 
@@ -1852,14 +1861,14 @@ bndx_do_delete(BalsaIndex *index,
 void
 balsa_message_move_to_trash(gpointer user_data)
 {
-    BalsaIndex *index;
+    BalsaIndex *bindex;
 
     g_return_if_fail(user_data != NULL);
-    index = BALSA_INDEX(user_data);
-    bndx_do_delete(index, TRUE);
+    bindex = BALSA_INDEX(user_data);
+    bndx_do_delete(bindex, TRUE);
     /* Note when message was flagged as deleted, for use in
      * auto-expunge. */
-    balsa_index_set_last_use(index);
+    balsa_index_set_last_use(bindex);
 }
 
 
@@ -1876,10 +1885,11 @@ balsa_find_notebook_page_num(LibBalsaMailbox *mailbox)
          (page =
               gtk_notebook_get_nth_page(GTK_NOTEBOOK(balsa_app.notebook), i));
          i++) {
-        GtkWidget *index = gtk_bin_get_child(GTK_BIN(page));
+        GtkTreeView *tree_view = GTK_TREE_VIEW(gtk_bin_get_child(GTK_BIN(page)));
+        BalsaIndex *bindex = balsa_index_get_from_tree_view(tree_view);
 
-        if ((index != NULL) &&
-            (balsa_index_get_mailbox(BALSA_INDEX(index)) == mailbox))
+        if ((bindex != NULL) &&
+            (balsa_index_get_mailbox(bindex) == mailbox))
             return i;
     }
 
@@ -1892,7 +1902,7 @@ balsa_find_notebook_page_num(LibBalsaMailbox *mailbox)
    using given callback.
  */
 void
-balsa_index_toggle_flag(BalsaIndex         *index,
+balsa_index_toggle_flag(BalsaIndex         *bindex,
                         LibBalsaMessageFlag flag)
 {
     LibBalsaMailbox *mailbox;
@@ -1900,8 +1910,8 @@ balsa_index_toggle_flag(BalsaIndex         *index,
     GArray *selected;
     guint i;
 
-    selected = balsa_index_selected_msgnos_new(index);
-    mailbox  = balsa_index_get_mailbox(index);
+    selected = balsa_index_selected_msgnos_new(bindex);
+    mailbox  = balsa_index_get_mailbox(bindex);
 
     /* First see if we should set given flag or unset */
     for (i = 0; i < selected->len; i++) {
@@ -1915,12 +1925,12 @@ balsa_index_toggle_flag(BalsaIndex         *index,
     libbalsa_mailbox_messages_change_flags(mailbox, selected,
                                            is_all_flagged ? 0 : flag,
                                            is_all_flagged ? flag : 0);
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
 
     if (flag == LIBBALSA_MESSAGE_FLAG_DELETED)
         /* Note when deleted flag was changed, for use in
          * auto-expunge. */
-        balsa_index_set_last_use(index);
+        balsa_index_set_last_use(bindex);
 }
 
 
@@ -1928,27 +1938,27 @@ static void
 bi_toggle_deleted_cb(gpointer   user_data,
                      GtkWidget *widget)
 {
-    BalsaIndex *index;
+    BalsaIndex *bindex;
     GArray *selected;
 
     g_return_if_fail(user_data != NULL);
 
-    index = BALSA_INDEX(user_data);
-    balsa_index_toggle_flag(index, LIBBALSA_MESSAGE_FLAG_DELETED);
+    bindex = BALSA_INDEX(user_data);
+    balsa_index_toggle_flag(bindex, LIBBALSA_MESSAGE_FLAG_DELETED);
 
-    selected = balsa_index_selected_msgnos_new(index);
-    if ((widget == index->undelete_item) && (selected->len > 0)) {
+    selected = balsa_index_selected_msgnos_new(bindex);
+    if ((widget == bindex->undelete_item) && (selected->len > 0)) {
         LibBalsaMailbox *mailbox;
         guint msgno = g_array_index(selected, guint, 0);
 
-        mailbox = balsa_index_get_mailbox(index);
+        mailbox = balsa_index_get_mailbox(bindex);
         if (libbalsa_mailbox_msgno_has_flags(mailbox, msgno,
                                              LIBBALSA_MESSAGE_FLAG_DELETED,
                                              0))
             /* Oops! */
-            balsa_index_toggle_flag(index, LIBBALSA_MESSAGE_FLAG_DELETED);
+            balsa_index_toggle_flag(bindex, LIBBALSA_MESSAGE_FLAG_DELETED);
     }
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
 }
 
 
@@ -1976,16 +1986,16 @@ bi_toggle_new_cb(gpointer user_data)
 
 static void
 mru_menu_cb(const gchar *url,
-            BalsaIndex  *index)
+            BalsaIndex  *bindex)
 {
     LibBalsaMailbox *mailbox = balsa_find_mailbox_by_url(url);
 
     g_return_if_fail(mailbox != NULL);
 
-    if (balsa_index_get_mailbox(index) != mailbox) {
-        GArray *selected = balsa_index_selected_msgnos_new(index);
-        balsa_index_transfer(index, selected, mailbox, FALSE);
-        balsa_index_selected_msgnos_free(index, selected);
+    if (balsa_index_get_mailbox(bindex) != mailbox) {
+        GArray *selected = balsa_index_selected_msgnos_new(bindex);
+        balsa_index_transfer(bindex, selected, mailbox, FALSE);
+        balsa_index_selected_msgnos_free(bindex, selected);
     }
 }
 
@@ -1994,7 +2004,7 @@ mru_menu_cb(const gchar *url,
  * bndx_popup_menu_create: create the popup menu at init time
  */
 static GtkWidget *
-bndx_popup_menu_create(BalsaIndex *index)
+bndx_popup_menu_create(BalsaIndex *bindex)
 {
     static const struct {         /* this is a invariable part of */
         const char *icon, *label; /* the context message menu.    */
@@ -2030,40 +2040,40 @@ bndx_popup_menu_create(BalsaIndex *index)
 
     for (i = 0; i < G_N_ELEMENTS(entries); i++) {
         create_stock_menu_item(menu, _(entries[i].label),
-                               entries[i].func, index);
+                               entries[i].func, bindex);
     }
 
     gtk_menu_shell_append(GTK_MENU_SHELL(menu),
                           gtk_separator_menu_item_new());
-    index->delete_item =
+    bindex->delete_item =
         create_stock_menu_item(menu, _("_Delete"),
                                G_CALLBACK(bi_toggle_deleted_cb),
-                               index);
-    index->undelete_item =
+                               bindex);
+    bindex->undelete_item =
         create_stock_menu_item(menu, _("_Undelete"),
                                G_CALLBACK(bi_toggle_deleted_cb),
-                               index);
-    index->move_to_trash_item =
+                               bindex);
+    bindex->move_to_trash_item =
         create_stock_menu_item(menu, _("Move To _Trash"),
                                G_CALLBACK
-                                   (balsa_message_move_to_trash), index);
+                                   (balsa_message_move_to_trash), bindex);
 
     menuitem           = gtk_menu_item_new_with_mnemonic(_("T_oggle"));
-    index->toggle_item = menuitem;
+    bindex->toggle_item = menuitem;
     submenu            = gtk_menu_new();
     create_stock_menu_item(submenu, _("_Flagged"),
                            G_CALLBACK(bi_toggle_flagged_cb),
-                           index);
+                           bindex);
     create_stock_menu_item(submenu, _("_Unread"),
                            G_CALLBACK(bi_toggle_new_cb),
-                           index);
+                           bindex);
 
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
 
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
     menuitem            = gtk_menu_item_new_with_mnemonic(_("_Move to"));
-    index->move_to_item = menuitem;
+    bindex->move_to_item = menuitem;
     gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
 
 
@@ -2071,7 +2081,7 @@ bndx_popup_menu_create(BalsaIndex *index)
                           gtk_separator_menu_item_new());
     create_stock_menu_item(menu, _("_View Source"),
                            G_CALLBACK(bndx_view_source),
-                           index);
+                           bindex);
 
     return menu;
 }
@@ -2095,10 +2105,10 @@ bndx_set_sensitive_func(GtkWidget *item,
 
 
 static void
-bndx_do_popup(BalsaIndex     *index,
+bndx_do_popup(BalsaIndex     *bindex,
               const GdkEvent *event)
 {
-    GtkWidget *menu = index->popup_menu;
+    GtkWidget *menu = bindex->popup_menu;
     GtkWidget *submenu;
     GArray *selected;
     LibBalsaMailbox *mailbox;
@@ -2110,8 +2120,8 @@ bndx_do_popup(BalsaIndex     *index,
 
     BALSA_DEBUG();
 
-    selected = balsa_index_selected_msgnos_new(index);
-    mailbox  = balsa_index_get_mailbox(index);
+    selected = balsa_index_selected_msgnos_new(bindex);
+    mailbox  = balsa_index_get_mailbox(bindex);
 
     for (i = 0; i < selected->len; i++) {
         guint msgno = g_array_index(selected, guint, i);
@@ -2123,36 +2133,36 @@ bndx_do_popup(BalsaIndex     *index,
             any_not_deleted = TRUE;
     }
     any = selected->len > 0;
-    balsa_index_selected_msgnos_free(index, selected);
+    balsa_index_selected_msgnos_free(bindex, selected);
 
     gtk_container_foreach(GTK_CONTAINER(menu), bndx_set_sensitive_func,
                           GINT_TO_POINTER(any));
 
     readonly = libbalsa_mailbox_get_readonly(mailbox);
-    gtk_widget_set_sensitive(index->delete_item,
+    gtk_widget_set_sensitive(bindex->delete_item,
                              any_not_deleted && !readonly);
-    gtk_widget_set_sensitive(index->undelete_item,
+    gtk_widget_set_sensitive(bindex->undelete_item,
                              any_deleted && !readonly);
-    gtk_widget_set_sensitive(index->move_to_trash_item,
+    gtk_widget_set_sensitive(bindex->move_to_trash_item,
                              any && mailbox != balsa_app.trash
                              && !readonly);
-    gtk_widget_set_sensitive(index->toggle_item,
+    gtk_widget_set_sensitive(bindex->toggle_item,
                              any && !readonly);
-    gtk_widget_set_sensitive(index->move_to_item,
+    gtk_widget_set_sensitive(bindex->move_to_item,
                              any && !readonly);
 
     submenu =
         balsa_mblist_mru_menu(GTK_WINDOW
-                                  (gtk_widget_get_toplevel(GTK_WIDGET(index))),
+                                  (gtk_widget_get_root(GTK_WIDGET(bindex))),
                               &balsa_app.folder_mru,
-                              G_CALLBACK(mru_menu_cb), index);
-    gtk_menu_item_set_submenu(GTK_MENU_ITEM(index->move_to_item),
+                              G_CALLBACK(mru_menu_cb), bindex);
+    gtk_menu_item_set_submenu(GTK_MENU_ITEM(bindex->move_to_item),
                               submenu);
 
     if (event != NULL) {
         gtk_menu_popup_at_pointer(GTK_MENU(menu), event);
     } else {
-        gtk_menu_popup_at_widget(GTK_MENU(menu), GTK_WIDGET(index),
+        gtk_menu_popup_at_widget(GTK_MENU(menu), GTK_WIDGET(bindex),
                                  GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
                                  NULL);
     }
@@ -2185,23 +2195,23 @@ bndx_compose_window_destroy_cb(GtkWidget *widget,
 
 
 void
-balsa_index_update_tree(BalsaIndex *index,
+balsa_index_update_tree(BalsaIndex *bindex,
                         gboolean    expand)
 /* Remarks: In the "collapse" case, we still expand current thread to the
             extent where viewed message is visible. An alternative
             approach would be to change preview, e.g. to top of thread. */
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view = bindex->tree_view;
     GtkTreeIter iter;
 
     if (expand) {
-        g_signal_handler_block(index, index->row_expanded_id);
+        g_signal_handler_block(tree_view, bindex->row_expanded_id);
         gtk_tree_view_expand_all(tree_view);
-        g_signal_handler_unblock(index, index->row_expanded_id);
+        g_signal_handler_unblock(tree_view, bindex->row_expanded_id);
     } else {
-        g_signal_handler_block(index, index->row_collapsed_id);
+        g_signal_handler_block(tree_view, bindex->row_collapsed_id);
         gtk_tree_view_collapse_all(tree_view);
-        g_signal_handler_unblock(index, index->row_collapsed_id);
+        g_signal_handler_unblock(tree_view, bindex->row_collapsed_id);
     }
 
     /* Re-expand msg_node's thread; cf. Remarks */
@@ -2209,24 +2219,24 @@ balsa_index_update_tree(BalsaIndex *index,
      * overhead is slight
      * select is needed in both cases, as a previous collapse could have
      * deselected the current message */
-    if (bndx_find_current_msgno(index, NULL, &iter))
-        bndx_expand_to_row_and_select(index, &iter);
+    if (bndx_find_current_msgno(bindex, NULL, &iter))
+        bndx_expand_to_row_and_select(bindex, &iter);
     else
-        balsa_index_ensure_visible(index);
+        balsa_index_ensure_visible(bindex);
 
-    bndx_changed_find_row(index);
+    bndx_changed_find_row(bindex);
 }
 
 
 /* balsa_index_set_threading_type: public method. */
 void
-balsa_index_set_threading_type(BalsaIndex *index,
+balsa_index_set_threading_type(BalsaIndex *bindex,
                                int         thtype)
 {
     LibBalsaMailbox *mailbox;
 
-    g_return_if_fail(index != NULL);
-    mailbox = balsa_index_get_mailbox(index);
+    g_return_if_fail(bindex != NULL);
+    mailbox = balsa_index_get_mailbox(bindex);
     g_return_if_fail(mailbox != NULL);
 
     if ((thtype != LB_MAILBOX_THREADING_FLAT)
@@ -2236,7 +2246,7 @@ balsa_index_set_threading_type(BalsaIndex *index,
     libbalsa_mailbox_set_threading_type(mailbox, thtype);
 
     libbalsa_mailbox_set_threading(mailbox, thtype);
-    balsa_index_update_tree(index, balsa_app.expand_tree);
+    balsa_index_update_tree(bindex, balsa_app.expand_tree);
 }
 
 
@@ -2261,21 +2271,21 @@ balsa_index_set_view_filter(BalsaIndex        *bindex,
 
 /* Public method. */
 void
-balsa_index_refresh_size(BalsaIndex *index)
+balsa_index_refresh_size(BalsaIndex *bindex)
 {
 }
 
 
 /* Public method. */
 void
-balsa_index_refresh_date(BalsaIndex *index)
+balsa_index_refresh_date(BalsaIndex *bindex)
 {
 }
 
 
 /* Transfer messages. */
 void
-balsa_index_transfer(BalsaIndex      *index,
+balsa_index_transfer(BalsaIndex      *bindex,
                      GArray          *msgnos,
                      LibBalsaMailbox *to_mailbox,
                      gboolean         copy)
@@ -2288,7 +2298,7 @@ balsa_index_transfer(BalsaIndex      *index,
     if (msgnos->len == 0)
         return;
 
-    from_mailbox = balsa_index_get_mailbox(index);
+    from_mailbox = balsa_index_get_mailbox(bindex);
     success      = copy ?
         libbalsa_mailbox_messages_copy(from_mailbox, msgnos, to_mailbox, &e) :
         libbalsa_mailbox_messages_move(from_mailbox, msgnos, to_mailbox, &e);
@@ -2314,24 +2324,24 @@ balsa_index_transfer(BalsaIndex      *index,
     if (!copy)
         /* Note when message was flagged as deleted, for use in
          * auto-expunge. */
-        balsa_index_set_last_use(index);
+        balsa_index_set_last_use(bindex);
 }
 
 
 /* General helpers. */
 static void
-bndx_expand_to_row(BalsaIndex  *index,
+bndx_expand_to_row(BalsaIndex  *bindex,
                    GtkTreePath *path)
 {
     GtkTreePath *tmp;
     gint i, j;
 
-    if (!gtk_widget_get_realized(GTK_WIDGET(index)))
+    if (!gtk_widget_get_realized(GTK_WIDGET(bindex->tree_view)))
         return;
 
     tmp = gtk_tree_path_copy(path);
     while (gtk_tree_path_up(tmp) && gtk_tree_path_get_depth(tmp) > 0
-           && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(index), tmp)) {
+           && !gtk_tree_view_row_expanded(bindex->tree_view, tmp)) {
     }
     /* Now we go from the deepest unexpanded ancestor up to full path */
 
@@ -2341,7 +2351,7 @@ bndx_expand_to_row(BalsaIndex  *index,
 
         do {
             gtk_tree_path_append_index(tmp, indices[i]);
-            gtk_tree_view_expand_row(GTK_TREE_VIEW(index), tmp, FALSE);
+            gtk_tree_view_expand_row(bindex->tree_view, tmp, FALSE);
         } while (++i < j);
     }
     gtk_tree_path_free(tmp);
@@ -2349,27 +2359,27 @@ bndx_expand_to_row(BalsaIndex  *index,
 
 
 static void
-bndx_changed_find_row(BalsaIndex *index)
+bndx_changed_find_row(BalsaIndex *bindex)
 {
     GtkTreeIter iter;
 
-    if (bndx_find_current_msgno(index, NULL, &iter)) {
+    if (bndx_find_current_msgno(bindex, NULL, &iter)) {
         gpointer tmp = iter.user_data;
-        index->next_message =
-            bndx_search_iter(index, index->search_iter, &iter,
+        bindex->next_message =
+            bndx_search_iter(bindex, bindex->search_iter, &iter,
                              BNDX_SEARCH_DIRECTION_NEXT,
                              BNDX_SEARCH_VIEWABLE_ONLY, 0);
         iter.user_data      = tmp;
-        index->prev_message =
-            bndx_search_iter(index, index->search_iter, &iter,
+        bindex->prev_message =
+            bndx_search_iter(bindex, bindex->search_iter, &iter,
                              BNDX_SEARCH_DIRECTION_PREV,
                              BNDX_SEARCH_VIEWABLE_ONLY, 0);
     } else {
-        index->next_message = FALSE;
-        index->prev_message = FALSE;
+        bindex->next_message = FALSE;
+        bindex->prev_message = FALSE;
     }
 
-    g_signal_emit(G_OBJECT(index), balsa_index_signals[INDEX_CHANGED], 0);
+    g_signal_emit(G_OBJECT(bindex), balsa_index_signals[INDEX_CHANGED], 0);
 }
 
 
@@ -2377,10 +2387,10 @@ bndx_changed_find_row(BalsaIndex *index)
  * making sure the selected row is within bounds and made visible.
  */
 static void
-bndx_select_row(BalsaIndex  *index,
+bndx_select_row(BalsaIndex  *bindex,
                 GtkTreePath *path)
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view = bindex->tree_view;
 
     gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
     gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);
@@ -2389,7 +2399,7 @@ bndx_select_row(BalsaIndex  *index,
 
 /* Check that all parents are expanded. */
 static gboolean
-bndx_row_is_viewable(BalsaIndex  *index,
+bndx_row_is_viewable(BalsaIndex  *bindex,
                      GtkTreePath *path)
 {
     GtkTreePath *tmp_path = gtk_tree_path_copy(path);
@@ -2398,7 +2408,7 @@ bndx_row_is_viewable(BalsaIndex  *index,
     while (ret_val && gtk_tree_path_up(tmp_path)
            && gtk_tree_path_get_depth(tmp_path) > 0) {
         ret_val =
-            gtk_tree_view_row_expanded(GTK_TREE_VIEW(index), tmp_path);
+            gtk_tree_view_row_expanded(bindex->tree_view, tmp_path);
     }
 
     gtk_tree_path_free(tmp_path);
@@ -2408,14 +2418,14 @@ bndx_row_is_viewable(BalsaIndex  *index,
 
 /* Expunge deleted messages. */
 void
-balsa_index_expunge(BalsaIndex *index)
+balsa_index_expunge(BalsaIndex *bindex)
 {
     LibBalsaMailbox *mailbox;
     gboolean rc;
 
-    g_return_if_fail(index != NULL);
+    g_return_if_fail(bindex != NULL);
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
     if (libbalsa_mailbox_get_readonly(mailbox))
         return;
 
@@ -2430,7 +2440,7 @@ balsa_index_expunge(BalsaIndex *index)
 
 /* Message window */
 static guint
-bndx_next_msgno(BalsaIndex                *index,
+bndx_next_msgno(BalsaIndex                *bindex,
                 guint                      current_msgno,
                 LibBalsaMailboxSearchIter *search_iter,
                 BndxSearchDirection        direction)
@@ -2442,11 +2452,11 @@ bndx_next_msgno(BalsaIndex                *index,
     if (current_msgno == 0)
         return 0;
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
     if (!libbalsa_mailbox_msgno_find(mailbox, current_msgno, NULL, &iter))
         return 0;
 
-    if (bndx_search_iter(index, search_iter, &iter, direction,
+    if (bndx_search_iter(bindex, search_iter, &iter, direction,
                          BNDX_SEARCH_VIEWABLE_ONLY, 0)) {
         GtkTreeModel *model;
 
@@ -2459,19 +2469,19 @@ bndx_next_msgno(BalsaIndex                *index,
 
 
 guint
-balsa_index_next_msgno(BalsaIndex *index,
+balsa_index_next_msgno(BalsaIndex *bindex,
                        guint       current_msgno)
 {
-    return bndx_next_msgno(index, current_msgno, index->search_iter,
+    return bndx_next_msgno(bindex, current_msgno, bindex->search_iter,
                            BNDX_SEARCH_DIRECTION_NEXT);
 }
 
 
 guint
-balsa_index_previous_msgno(BalsaIndex *index,
+balsa_index_previous_msgno(BalsaIndex *bindex,
                            guint       current_msgno)
 {
-    return bndx_next_msgno(index, current_msgno, index->search_iter,
+    return bndx_next_msgno(bindex, current_msgno, bindex->search_iter,
                            BNDX_SEARCH_DIRECTION_PREV);
 }
 
@@ -2798,7 +2808,7 @@ bndx_mailbox_notify(gpointer data)
 }
 
 
-#define BALSA_INDEX_PIPE_INFO "balsa-index-pipe-info"
+#define BALSA_INDEX_PIPE_INFO "balsa-bindex-pipe-info"
 
 static void
 bndx_pipe_response(GtkWidget                *dialog,
@@ -2846,7 +2856,7 @@ bndx_pipe_response(GtkWidget                *dialog,
 #define HIG_PADDING 12
 
 void
-balsa_index_pipe(BalsaIndex *index)
+balsa_index_pipe(BalsaIndex *bindex)
 {
     LibBalsaMailbox *mailbox;
     struct bndx_mailbox_info *info;
@@ -2855,8 +2865,8 @@ balsa_index_pipe(BalsaIndex *index)
     GtkWidget *vbox;
     GList *list;
 
-    g_return_if_fail(BALSA_IS_INDEX(index));
-    mailbox = balsa_index_get_mailbox(index);
+    g_return_if_fail(BALSA_IS_INDEX(bindex));
+    mailbox = balsa_index_get_mailbox(bindex);
     g_return_if_fail(LIBBALSA_IS_MAILBOX(mailbox));
 
     info = g_object_get_data(G_OBJECT(mailbox), BALSA_INDEX_PIPE_INFO);
@@ -2870,12 +2880,12 @@ balsa_index_pipe(BalsaIndex *index)
         return;
 
     info          = g_new(struct bndx_mailbox_info, 1);
-    info->bindex  = index;
+    info->bindex  = bindex;
     info->mailbox = mailbox;
     g_object_set_data_full(G_OBJECT(info->mailbox), BALSA_INDEX_PIPE_INFO,
                            info, bndx_mailbox_notify);
 
-    info->msgnos = balsa_index_selected_msgnos_new(index);
+    info->msgnos = balsa_index_selected_msgnos_new(bindex);
 
     info->dialog = dialog =
             gtk_dialog_new_with_buttons(_("Pipe message through a program"),
@@ -2919,16 +2929,16 @@ balsa_index_pipe(BalsaIndex *index)
  * scroll to either the current message. If this one is unavailable -
  * to the last message in the view, if any. */
 void
-balsa_index_ensure_visible(BalsaIndex *index)
+balsa_index_ensure_visible(BalsaIndex *bindex)
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(index);
+    GtkTreeView *tree_view = bindex->tree_view;
     GdkRectangle rect;
     GtkTreePath *path = NULL;
 
     if (!gtk_widget_get_realized(GTK_WIDGET(tree_view)))
         return;
 
-    if (!bndx_find_current_msgno(index, &path, NULL)) {
+    if (!bndx_find_current_msgno(bindex, &path, NULL)) {
         /* Current message not displayed, make sure that something
            else is... */
         gtk_tree_view_get_visible_rect(tree_view, &rect);
@@ -2967,7 +2977,7 @@ balsa_index_ensure_visible(BalsaIndex *index)
 void
 balsa_index_select_all(BalsaIndex *bindex)
 {
-    GtkTreeView *tree_view      = GTK_TREE_VIEW(bindex);
+    GtkTreeView *tree_view      = bindex->tree_view;
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
 
     gtk_tree_view_expand_all(tree_view);
@@ -2985,7 +2995,7 @@ balsa_index_count_selected_messages(BalsaIndex *bindex)
 
     return
         gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection
-                                                   (GTK_TREE_VIEW(bindex)));
+                                                   (bindex->tree_view));
 }
 
 
@@ -2999,7 +3009,7 @@ balsa_index_select_thread(BalsaIndex *bindex)
     GtkTreeIter next_iter;
     GtkTreePath *path;
     GtkTreeSelection *selection =
-        gtk_tree_view_get_selection(GTK_TREE_VIEW(bindex));
+        gtk_tree_view_get_selection(bindex->tree_view);
     gboolean valid;
 
     if (bindex->current_msgno == 0)
@@ -3016,7 +3026,7 @@ balsa_index_select_thread(BalsaIndex *bindex)
     }
 
     path = gtk_tree_model_get_path(model, &iter);
-    gtk_tree_view_expand_row(GTK_TREE_VIEW(bindex), path, TRUE);
+    gtk_tree_view_expand_row(bindex->tree_view, path, TRUE);
     gtk_tree_path_free(path);
 
     do {
@@ -3112,7 +3122,7 @@ balsa_index_get_filter_no(BalsaIndex *bindex)
 const gchar *
 balsa_index_get_filter_string(BalsaIndex *bindex)
 {
-    g_return_val_if_fail(BALSA_IS_INDEX(bindex), FALSE);
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
 
     return bindex->filter_string;
 }
@@ -3139,7 +3149,25 @@ balsa_index_get_prev_message(BalsaIndex *bindex)
 BalsaMailboxNode *
 balsa_index_get_mailbox_node(BalsaIndex *bindex)
 {
-    g_return_val_if_fail(BALSA_IS_INDEX(bindex), FALSE);
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
 
     return bindex->mailbox_node;
 }
+
+
+GtkTreeView *
+balsa_index_get_tree_view(BalsaIndex *bindex)
+{
+    g_return_val_if_fail(BALSA_IS_INDEX(bindex), NULL);
+
+    return bindex->tree_view;
+}
+
+
+BalsaIndex *
+balsa_index_get_from_tree_view(GtkTreeView *tree_view)
+{
+    g_return_val_if_fail(GTK_IS_TREE_VIEW(tree_view), NULL);
+
+    return g_object_get_data(G_OBJECT(tree_view), "balsa-index-object");
+}
diff --git a/src/balsa-index.h b/src/balsa-index.h
index 1eeb18e2e..a43e60739 100644
--- a/src/balsa-index.h
+++ b/src/balsa-index.h
@@ -32,7 +32,7 @@ G_DECLARE_FINAL_TYPE(BalsaIndex,
                      balsa_index,
                      BALSA,
                      INDEX,
-                     GtkTreeView);
+                     GObject);
 
 
 typedef enum {
@@ -57,7 +57,7 @@ enum {
 
 /* function prototypes */
 
-GtkWidget *balsa_index_new(void);
+BalsaIndex *balsa_index_new(void);
 
 
 /* sets the mail stream; if it's a new stream, then it's
@@ -167,6 +167,8 @@ const gchar      *balsa_index_get_filter_string(BalsaIndex *bindex);
 gboolean          balsa_index_get_next_message(BalsaIndex *bindex);
 gboolean          balsa_index_get_prev_message(BalsaIndex *bindex);
 BalsaMailboxNode *balsa_index_get_mailbox_node(BalsaIndex *bindex);
+GtkTreeView      *balsa_index_get_tree_view(BalsaIndex *bindex);
+BalsaIndex       *balsa_index_get_from_tree_view(GtkTreeView *tree_view);
 
 #define BALSA_INDEX_VIEW_ON_OPEN "balsa-index-view-on-open"
 
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index df86d68ab..d520a99c6 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -84,7 +84,7 @@ static void bmbl_set_property(GObject * object, guint prop_id,
                               const GValue * value, GParamSpec * pspec);
 static void bmbl_get_property(GObject * object, guint prop_id,
                               GValue * value, GParamSpec * pspec);
-static gboolean bmbl_drag_motion(GtkWidget * mblist,
+static gboolean bmbl_drag_motion(GtkWidget * widget,
                                  GdkDrop * drop, gint x, gint y);
 static gboolean bmbl_popup_menu(GtkWidget * widget);
 static gboolean bmbl_selection_func(GtkTreeSelection * selection,
@@ -131,7 +131,9 @@ static void bmbl_expand_to_row(BalsaMBList * mblist, GtkTreePath * path);
 /* class methods */
 
 struct _BalsaMBList {
-    GtkTreeView tree_view;
+    GObject parent_object;
+
+    GtkTreeView *tree_view;
 
     /* Drag destination: */
     LibBalsaMailbox *dest_mailbox;
@@ -146,16 +148,14 @@ struct _BalsaMBList {
     guint sort_idle_id;
 };
 
-G_DEFINE_TYPE(BalsaMBList, balsa_mblist, GTK_TYPE_TREE_VIEW)
+G_DEFINE_TYPE(BalsaMBList, balsa_mblist, G_TYPE_OBJECT)
 
 static void
 balsa_mblist_class_init(BalsaMBListClass * klass)
 {
     GObjectClass *object_class;
-    GtkWidgetClass *widget_class;
 
     object_class = (GObjectClass *) klass;
-    widget_class = (GtkWidgetClass *) klass;
 
     /* HAS_UNREAD_MAILBOX is emitted when the number of mailboxes with
      * unread mail might have changed. */
@@ -171,10 +171,6 @@ balsa_mblist_class_init(BalsaMBListClass * klass)
     object_class->set_property = bmbl_set_property;
     object_class->get_property = bmbl_get_property;
 
-    /* GtkWidget signals */
-    widget_class->drag_motion = bmbl_drag_motion;
-    widget_class->popup_menu = bmbl_popup_menu;
-
     /* Properties */
     g_object_class_install_property(object_class, PROP_SHOW_CONTENT_INFO,
                                     g_param_spec_boolean
@@ -222,7 +218,7 @@ bmbl_set_property(GObject * object, guint prop_id,
                           const GValue * value, GParamSpec * pspec)
 {
     BalsaMBList *mblist = BALSA_MBLIST(object);
-    GtkTreeView *tree_view = GTK_TREE_VIEW(object);
+    GtkTreeView *tree_view = mblist->tree_view;
     GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
     gboolean display_info;
     GtkTreeViewColumn *column;
@@ -271,12 +267,12 @@ bmbl_get_property(GObject * object, guint prop_id, GValue * value,
 }
 
 static gboolean
-bmbl_drag_motion(GtkWidget *mblist,
+bmbl_drag_motion(GtkWidget *widget,
                  GdkDrop   *drop,
                  gint       x,
                  gint       y)
 {
-    GtkTreeView *tree_view = GTK_TREE_VIEW(mblist);
+    GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
     GtkTreePath *path;
     GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
     GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
@@ -284,7 +280,7 @@ bmbl_drag_motion(GtkWidget *mblist,
     gboolean can_drop;
 
     ret_val =
-        GTK_WIDGET_CLASS(balsa_mblist_parent_class)->drag_motion(mblist,
+        GTK_WIDGET_CLASS(balsa_mblist_parent_class)->drag_motion(widget,
                                                                  drop,
                                                                  x, y);
 
@@ -311,11 +307,15 @@ bmbl_drag_motion(GtkWidget *mblist,
 static void
 balsa_mblist_init(BalsaMBList * mblist)
 {
-    GtkTreeStore *store = balsa_mblist_get_store();
-    GtkTreeView *tree_view = GTK_TREE_VIEW(mblist);
+    GtkTreeView *tree_view;
+    GtkTreeStore *store;
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
 
+    mblist->tree_view = tree_view = GTK_TREE_VIEW(gtk_tree_view_new());
+    g_object_set_data_full(G_OBJECT(tree_view), "balsa-mblist-object", mblist, g_object_unref);
+
+    store = balsa_mblist_get_store();
     gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(store));
     g_object_unref(store);
 
@@ -400,10 +400,14 @@ balsa_mblist_init(BalsaMBList * mblist)
                                            bmbl_selection_func, NULL,
                                            NULL);
 
-    g_signal_connect_after(G_OBJECT(tree_view), "row-expanded",
+    g_signal_connect_after(tree_view, "row-expanded",
                            G_CALLBACK(bmbl_tree_expand), NULL);
-    g_signal_connect(G_OBJECT(tree_view), "row-collapsed",
+    g_signal_connect(tree_view, "row-collapsed",
                      G_CALLBACK(bmbl_tree_collapse), NULL);
+    g_signal_connect(tree_view, "popup-menu",
+                     G_CALLBACK(bmbl_popup_menu), NULL);
+    g_signal_connect(tree_view, "drag-motion",
+                     G_CALLBACK(bmbl_drag_motion), NULL);
     gtk_tree_view_set_activate_on_single_click(tree_view, TRUE);
 
     g_object_set(G_OBJECT(mblist),
@@ -492,14 +496,14 @@ bmbl_selection_func(GtkTreeSelection * selection, GtkTreeModel * model,
     return retval;
 }
 
-GtkWidget *
+BalsaMBList *
 balsa_mblist_new()
 {
     BalsaMBList *new;
 
     new = g_object_new(balsa_mblist_get_type(), NULL);
 
-    return GTK_WIDGET(new);
+    return new;
 }
 
 /* callbacks */
@@ -525,12 +529,10 @@ bmbl_tree_expand(GtkTreeView * tree_view, GtkTreeIter * iter,
     g_object_unref(mbnode);
 
     if (gtk_tree_model_iter_children(model, &child_iter, iter)) {
-       GtkWidget *current_index =
+       BalsaIndex *current_index =
            balsa_window_find_current_index(balsa_app.main_window);
        LibBalsaMailbox *current_mailbox =
-           current_index != NULL ?
-           balsa_index_get_mailbox(BALSA_INDEX(current_index)) :
-           NULL;
+           current_index != NULL ? balsa_index_get_mailbox(current_index) : NULL;
        gboolean first_mailbox = TRUE;
 
         do {
@@ -659,7 +661,7 @@ bmbl_row_compare(GtkTreeModel * model, GtkTreeIter * iter1,
    (clicking on folders is passed to GtkTreeView and may trigger expand events
 */
 static void
-bmbl_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+bmbl_gesture_pressed_cb(GtkGestureClick *click,
                         gint                  n_press,
                         gdouble               x,
                         gdouble               y,
@@ -670,7 +672,7 @@ bmbl_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
     GtkTreeView *tree_view;
     GtkTreePath *path;
 
-    gesture = GTK_GESTURE(multi_press);
+    gesture = GTK_GESTURE(click);
     event = gtk_gesture_get_last_event(gesture,
                                        gtk_gesture_get_last_updated_sequence(gesture));
     g_return_if_fail(event != NULL);
@@ -1056,7 +1058,7 @@ static void
 bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
 {
     int i;
-    GtkWidget *index;
+    BalsaIndex *bindex;
     BalsaMailboxNode *mbnode;
 
     mbnode = balsa_mailbox_node_find_from_mailbox(mailbox);
@@ -1065,20 +1067,19 @@ bmbl_open_mailbox(LibBalsaMailbox * mailbox, gboolean set_current)
         return;
     }
 
-    index = balsa_window_find_current_index(balsa_app.main_window);
+    bindex = balsa_window_find_current_index(balsa_app.main_window);
 
     /* If we currently have a page open, update the time last visited */
-    if (index != NULL)
-        balsa_index_set_last_use(BALSA_INDEX(index));
+    if (bindex != NULL)
+        balsa_index_set_last_use(bindex);
 
     i = balsa_find_notebook_page_num(mailbox);
     if (i != -1) {
         if (set_current) {
-            gtk_notebook_set_current_page(GTK_NOTEBOOK(balsa_app.notebook),
-                                          i);
-            index = balsa_window_find_current_index(balsa_app.main_window);
-            balsa_index_set_last_use(BALSA_INDEX(index));
-            balsa_index_set_column_widths(BALSA_INDEX(index));
+            gtk_notebook_set_current_page(GTK_NOTEBOOK(balsa_app.notebook), i);
+            bindex = balsa_window_find_current_index(balsa_app.main_window);
+            balsa_index_set_last_use(bindex);
+            balsa_index_set_column_widths(bindex);
         }
     } else { /* page with mailbox not found, open it */
         balsa_window_open_mbnode(balsa_app.main_window, mbnode,
@@ -1160,7 +1161,7 @@ balsa_mblist_close_lru_peer_mbx(BalsaMBList * mblist,
     struct lru_data dt;
     g_return_val_if_fail(mailbox, FALSE);
 
-    model = gtk_tree_view_get_model(GTK_TREE_VIEW(mblist));
+    model = gtk_tree_view_get_model(mblist->tree_view);
 
     if(!balsa_find_iter_by_data(&iter, mailbox))
         return FALSE;
@@ -1187,28 +1188,28 @@ balsa_mblist_default_signal_bindings(BalsaMBList * mblist)
     GtkGesture *gesture;
     GdkContentFormats *formats;
 
-    gesture = gtk_gesture_multi_press_new();
+    gesture = gtk_gesture_click_new();
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(bmbl_gesture_pressed_cb), NULL);
-    gtk_widget_add_controller(GTK_WIDGET(mblist), GTK_EVENT_CONTROLLER(gesture));
+    gtk_widget_add_controller(GTK_WIDGET(mblist->tree_view), GTK_EVENT_CONTROLLER(gesture));
 
-    g_signal_connect_after(mblist, "size-allocate",
+    g_signal_connect_after(mblist->tree_view, "size-allocate",
                            G_CALLBACK(bmbl_column_resize), NULL);
 
     formats = gdk_content_formats_new(bmbl_drop_types, G_N_ELEMENTS(bmbl_drop_types));
-    gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(mblist),
+    gtk_tree_view_enable_model_drag_dest(mblist->tree_view,
                                          formats,
                                          GDK_ACTION_COPY |
                                          GDK_ACTION_MOVE);
     gdk_content_formats_unref(formats);
 
-    g_signal_connect(mblist, "drag-drop",
+    g_signal_connect(mblist->tree_view, "drag-drop",
                      G_CALLBACK(bmbl_drag_drop_cb), NULL);
-    g_signal_connect(mblist, "drag-data-received",
+    g_signal_connect(mblist->tree_view, "drag-data-received",
                      G_CALLBACK(bmbl_drag_data_received_cb), NULL);
 
-    g_signal_connect(mblist, "row-activated",
+    g_signal_connect(mblist->tree_view, "row-activated",
                      G_CALLBACK(bmbl_row_activated_cb), NULL);
 }
 
@@ -1355,7 +1356,7 @@ bmbl_update_mailbox(GtkTreeStore * store, LibBalsaMailbox * mailbox)
 {
     GtkTreeModel *model = GTK_TREE_MODEL(store);
     GtkTreeIter iter;
-    GtkWidget *bindex;
+    BalsaIndex *bindex;
 
     /* try and find the mailbox */
     if (!balsa_find_iter_by_data(&iter, mailbox))
@@ -1365,7 +1366,7 @@ bmbl_update_mailbox(GtkTreeStore * store, LibBalsaMailbox * mailbox)
 
     bindex = balsa_window_find_current_index(balsa_app.main_window);
     if (bindex == NULL ||
-        mailbox != balsa_index_get_mailbox(BALSA_INDEX(bindex)))
+        mailbox != balsa_index_get_mailbox(bindex))
         return;
 
     balsa_window_set_statusbar(balsa_app.main_window, mailbox);
@@ -1539,8 +1540,8 @@ balsa_mblist_focus_mailbox(BalsaMBList * mblist, LibBalsaMailbox * mailbox)
 
     g_return_val_if_fail(mblist, FALSE);
 
-    model = gtk_tree_view_get_model(GTK_TREE_VIEW(mblist));
-    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mblist));
+    model = gtk_tree_view_get_model(mblist->tree_view);
+    selection = gtk_tree_view_get_selection(mblist->tree_view);
 
     if (mailbox && balsa_find_iter_by_data(&iter, mailbox)) {
         if (!gtk_tree_selection_iter_is_selected(selection, &iter)) {
@@ -1554,7 +1555,7 @@ balsa_mblist_focus_mailbox(BalsaMBList * mblist, LibBalsaMailbox * mailbox)
             path = gtk_tree_model_get_path(model, &iter);
             bmbl_expand_to_row(mblist, path);
             gtk_tree_selection_select_path(selection, path);
-            gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(mblist), path, NULL,
+            gtk_tree_view_scroll_to_cell(mblist->tree_view, path, NULL,
                                          FALSE, 0, 0);
             gtk_tree_path_free(path);
         }
@@ -1772,7 +1773,7 @@ bmbl_mru_size_allocate_cb(GtkWidget * widget, gint width, gint height,
     GdkSurface *surface;
     gboolean maximized;
 
-    surface = gtk_widget_get_surface(widget);
+    surface = gtk_native_get_surface(GTK_NATIVE(widget));
     if (surface == NULL)
         return;
 
@@ -1793,17 +1794,17 @@ bmbl_mru_show_tree(GtkWidget * widget, gpointer data)
     BalsaMBListMRUEntry *mru = data;
     GtkWidget *dialog;
     GtkWidget *scroll;
-    GtkWidget *mblist;
+    BalsaMBList *mblist;
 
     mblist = balsa_mblist_new();
-    g_signal_connect(mblist, "row-activated",
+    g_signal_connect(mblist->tree_view, "row-activated",
                      G_CALLBACK(bmbl_mru_activated_cb), data);
 
     scroll = gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);
-    gtk_container_add(GTK_CONTAINER(scroll), mblist);
+    gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(mblist->tree_view));
 
     dialog =
         gtk_dialog_new_with_buttons(_("Choose destination folder"),
@@ -2092,8 +2093,8 @@ bmbl_expand_to_row(BalsaMBList * mblist, GtkTreePath * path)
     GtkTreePath *tmp = gtk_tree_path_copy(path);
 
     if (gtk_tree_path_up(tmp) && gtk_tree_path_get_depth(tmp) > 0
-        && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(mblist), tmp)) {
-       gtk_tree_view_expand_to_path(GTK_TREE_VIEW(mblist), tmp);
+        && !gtk_tree_view_row_expanded(mblist->tree_view, tmp)) {
+       gtk_tree_view_expand_to_path(mblist->tree_view, tmp);
     }
 
     gtk_tree_path_free(tmp);
@@ -2147,7 +2148,7 @@ balsa_mblist_mailbox_node_append(BalsaMailboxNode * root,
         /* Check whether this node is exposed. */
         GtkTreePath *parent_path =
             gtk_tree_model_get_path(model, parent_iter);
-        if (gtk_tree_view_row_expanded(GTK_TREE_VIEW(balsa_app.mblist),
+        if (gtk_tree_view_row_expanded(balsa_app.mblist->tree_view,
                                        parent_path)) {
             /* Check this node for children. */
             balsa_mailbox_node_append_subtree(mbnode);
@@ -2168,3 +2169,15 @@ balsa_mblist_mailbox_node_redraw(BalsaMailboxNode * mbnode)
        bmbl_store_redraw_mbnode(&iter, mbnode);
     balsa_window_update_tab(mbnode);
 }
+
+/*
+ * Getter
+ */
+
+GtkTreeView *
+balsa_mblist_get_tree_view(BalsaMBList *mblist)
+{
+    g_return_val_if_fail(BALSA_IS_MBLIST(mblist), NULL);
+
+    return mblist->tree_view;
+}
diff --git a/src/balsa-mblist.h b/src/balsa-mblist.h
index e1a537399..122ad2421 100644
--- a/src/balsa-mblist.h
+++ b/src/balsa-mblist.h
@@ -29,9 +29,9 @@ G_DECLARE_FINAL_TYPE(BalsaMBList,
                      balsa_mblist,
                      BALSA,
                      MBLIST,
-                     GtkTreeView);
+                     GObject);
 
-GtkWidget    *balsa_mblist_new(void);
+BalsaMBList  *balsa_mblist_new(void);
 
 GtkTreeStore *balsa_mblist_get_store(void);
 void          balsa_mblist_default_signal_bindings(BalsaMBList *tree);
@@ -75,4 +75,10 @@ void     balsa_mblist_mailbox_node_append(BalsaMailboxNode *root,
 void     balsa_mblist_mailbox_node_redraw(BalsaMailboxNode *mbnode);
 gboolean balsa_mblist_mailbox_node_remove(BalsaMailboxNode *mbnode);
 
+/*
+ * Getter
+ */
+
+GtkTreeView * balsa_mblist_get_tree_view(BalsaMBList *mblist);
+
 #endif
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 1379e9e35..b84343468 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -118,7 +118,7 @@ static void select_part(BalsaMessage * bm, BalsaPartInfo *info);
 static void tree_activate_row_cb(GtkTreeView *treeview, GtkTreePath *arg1,
                                  GtkTreeViewColumn *arg2, gpointer user_data);
 static gboolean tree_menu_popup_key_cb(GtkWidget *widget, gpointer user_data);
-static void bm_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+static void bm_gesture_pressed_cb(GtkGestureClick *click,
                                   gint                  n_press,
                                   gdouble               x,
                                   gdouble               y,
@@ -660,11 +660,11 @@ bm_find_pass_to_entry(GtkEventControllerKey *key_controller,
 static void
 bm_disable_find_entry(BalsaMessage * bm)
 {
-    GtkWidget *toplevel;
+    GtkWidget *root;
 
-    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(bm));
-    if (GTK_IS_APPLICATION_WINDOW(toplevel))
-        libbalsa_window_block_accels((GtkApplicationWindow *) toplevel, FALSE);
+    root = GTK_WIDGET(gtk_widget_get_root(GTK_WIDGET(bm)));
+    if (GTK_IS_APPLICATION_WINDOW(root))
+        libbalsa_window_block_accels((GtkApplicationWindow *) root, FALSE);
 
     if (bm->find_key_controller != NULL &&  bm->key_pressed_id != 0)
         g_signal_handler_disconnect(bm->find_key_controller, bm->key_pressed_id);
@@ -749,7 +749,7 @@ balsa_message_init(BalsaMessage * bm)
     g_signal_connect(bm->treeview, "row-activated",
                      G_CALLBACK(tree_activate_row_cb), bm);
 
-    gesture = gtk_gesture_multi_press_new();
+    gesture = gtk_gesture_click_new();
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(bm_gesture_pressed_cb), NULL);
@@ -996,7 +996,7 @@ tree_menu_popup_key_cb(GtkWidget *widget, gpointer user_data)
 }
 
 static void
-bm_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+bm_gesture_pressed_cb(GtkGestureClick *click,
                       gint                  n_press,
                       gdouble               x,
                       gdouble               y,
@@ -1010,7 +1010,7 @@ bm_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
     BalsaMessage * bm = (BalsaMessage *) user_data;
     GtkTreePath *path;
 
-    gesture = GTK_GESTURE(multi_press);
+    gesture = GTK_GESTURE(click);
     sequence = gtk_gesture_get_last_updated_sequence(gesture);
     event = gtk_gesture_get_last_event(gesture, sequence);
 
@@ -1633,7 +1633,7 @@ part_create_menu (BalsaPartInfo* info)
         gtk_menu_shell_append(GTK_MENU_SHELL(info->popup_menu), menu_item);
 
         submenu =
-            balsa_mblist_mru_menu(GTK_WINDOW(gtk_widget_get_toplevel(info->popup_menu)),
+            balsa_mblist_mru_menu(GTK_WINDOW(gtk_widget_get_root(info->popup_menu)),
                                   &balsa_app.folder_mru,
                                   G_CALLBACK(balsa_message_copy_part),
                                   info->body);
@@ -2267,11 +2267,11 @@ balsa_message_current_part_widget(BalsaMessage * bmessage)
 GtkWindow *
 balsa_get_parent_window(GtkWidget * widget)
 {
-    if (widget) {
-        GtkWidget *toplevel = gtk_widget_get_toplevel(widget);
+    if (widget != NULL) {
+        GtkWidget *root = GTK_WIDGET(gtk_widget_get_root(widget));
 
-        if (gtk_widget_is_toplevel(toplevel) && GTK_IS_WINDOW(toplevel))
-            return GTK_WINDOW(toplevel);
+        if (GTK_IS_WINDOW(root))
+            return GTK_WINDOW(root);
     }
 
     return GTK_WINDOW(balsa_app.main_window);
@@ -3264,7 +3264,7 @@ balsa_message_find_in_message(BalsaMessage * bm)
             || libbalsa_html_can_search(widget)
 #endif                          /* HAVE_HTML_WIDGET */
             )) {
-        GtkWidget *toplevel;
+        GtkWidget *root;
 
         if (GTK_IS_TEXT_VIEW(widget)) {
             GtkTextView *text_view = (GtkTextView *) widget;
@@ -3276,13 +3276,13 @@ balsa_message_find_in_message(BalsaMessage * bm)
         bm->find_forward = TRUE;
         gtk_editable_set_text(GTK_EDITABLE(bm->find_entry), "");
 
-        toplevel = gtk_widget_get_toplevel(GTK_WIDGET(bm));
-        if (GTK_IS_APPLICATION_WINDOW(toplevel))
-            libbalsa_window_block_accels((GtkApplicationWindow *) toplevel, TRUE);
+        root = GTK_WIDGET(gtk_widget_get_root(GTK_WIDGET(bm)));
+        if (GTK_IS_APPLICATION_WINDOW(root))
+            libbalsa_window_block_accels((GtkApplicationWindow *) root, TRUE);
 
         if (bm->find_key_controller == NULL) {
             bm->find_key_controller = gtk_event_controller_key_new();
-            gtk_widget_add_controller(toplevel, bm->find_key_controller);
+            gtk_widget_add_controller(root, bm->find_key_controller);
         }
         if (bm->key_pressed_id == 0) {
             bm->key_pressed_id =
diff --git a/src/balsa-mime-widget-image.c b/src/balsa-mime-widget-image.c
index a6010f067..096d1f62b 100644
--- a/src/balsa-mime-widget-image.c
+++ b/src/balsa-mime-widget-image.c
@@ -191,7 +191,7 @@ balsa_mime_widget_new_image(BalsaMessage * bm,
     g_signal_connect_swapped(picture, "size-allocate",
                              G_CALLBACK(img_size_allocate_cb), mwi);
 
-    gesture = gtk_gesture_multi_press_new();
+    gesture = gtk_gesture_click_new();
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "begin",
                      G_CALLBACK(balsa_mime_widget_image_gesture_pressed_cb), data);
diff --git a/src/balsa-mime-widget-message.c b/src/balsa-mime-widget-message.c
index 67ab22d7e..ce5318b15 100644
--- a/src/balsa-mime-widget-message.c
+++ b/src/balsa-mime-widget-message.c
@@ -313,13 +313,14 @@ static void
 extbody_call_url(GtkWidget * button, gpointer data)
 {
     gchar *url = g_object_get_data(G_OBJECT(button), "call_url");
-    GtkWidget *toplevel;
+    GtkWidget *root;
     GError *err = NULL;
 
-    g_return_if_fail(url);
-    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(button));
-    if (gtk_widget_is_toplevel(toplevel)) {
-        gtk_show_uri_on_window(GTK_WINDOW(toplevel), url,
+    g_return_if_fail(url != NULL);
+
+    root = GTK_WIDGET(gtk_widget_get_root(button));
+    if (GTK_IS_WINDOW(root)) {
+        gtk_show_uri_on_window(GTK_WINDOW(root), url,
                                gtk_get_current_event_time(), &err);
     }
 
@@ -387,8 +388,7 @@ extbody_send_mail(GtkWidget * button, LibBalsaMessageBody * mime_body)
                                   libbalsa_identity_get_smtp_server
                                    (balsa_app.current_ident),
                                   balsa_app.send_progress_dialog,
-                                   GTK_WINDOW(gtk_widget_get_toplevel
-                                              (button)),
+                                   GTK_WINDOW(gtk_widget_get_root(button)),
                                   FALSE, &err);
     if (result != LIBBALSA_MESSAGE_CREATE_OK)
        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
@@ -461,7 +461,7 @@ bm_header_extend_popup(GtkWidget * widget, GtkMenu * menu, gpointer arg)
 
     submenu =
         balsa_mblist_mru_menu(GTK_WINDOW
-                              (gtk_widget_get_toplevel(widget)),
+                              (gtk_widget_get_root(widget)),
                               &balsa_app.folder_mru,
                               G_CALLBACK(balsa_message_copy_part), arg);
     gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item),
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 4ce7ab561..744f02283 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -91,7 +91,7 @@ static GdkCursor *url_cursor_normal = NULL;
 static GdkCursor *url_cursor_over_url = NULL;
 
 
-static void store_button_coords(GtkGestureMultiPress *multi_press,
+static void store_button_coords(GtkGestureClick *click,
                                 gint                  n_press,
                                 gdouble               x,
                                 gdouble               y,
@@ -102,7 +102,7 @@ static void pointer_over_url(GtkWidget * widget, message_url_t * url, gboolean s
 static void prepare_url_offsets(GtkTextBuffer * buffer, GList * url_list);
 static void url_found_cb(GtkTextBuffer * buffer, GtkTextIter * iter,
                          const gchar * buf, guint len, gpointer data);
-static void check_call_url(GtkGestureMultiPress *multi_press,
+static void check_call_url(GtkGestureClick *click,
                            gint                  n_press,
                            gdouble               x,
                            gdouble               y,
@@ -309,7 +309,7 @@ balsa_mime_widget_new_text(BalsaMessage * bm, LibBalsaMessageBody * mime_body,
     if (mwt->url_list != NULL) {
         GtkGesture *gesture;
 
-        gesture = gtk_gesture_multi_press_new();
+        gesture = gtk_gesture_click_new();
         g_signal_connect(gesture, "pressed",
                          G_CALLBACK(store_button_coords), NULL);
         g_signal_connect(gesture, "released",
@@ -615,7 +615,7 @@ text_view_populate_popup(GtkWidget *widget, GtkMenu *menu,
 /* -- URL related stuff -- */
 
 static void
-store_button_coords(GtkGestureMultiPress *multi_press,
+store_button_coords(GtkGestureClick *click,
                     gint                  n_press,
                     gdouble               x,
                     gdouble               y,
@@ -625,7 +625,7 @@ store_button_coords(GtkGestureMultiPress *multi_press,
     const GdkEvent *event;
     GdkModifierType state;
 
-    gesture = GTK_GESTURE(multi_press);
+    gesture = GTK_GESTURE(click);
     event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
     g_return_if_fail(event != NULL);
 
@@ -744,7 +744,7 @@ url_found_cb(GtkTextBuffer * buffer, GtkTextIter * iter,
 /* if the mouse button was released over an URL, and the mouse hasn't
  * moved since the button was pressed, try to call the URL */
 static void
-check_call_url(GtkGestureMultiPress *multi_press,
+check_call_url(GtkGestureClick *click,
                gint                  n_press,
                gdouble               x,
                gdouble               y,
@@ -755,7 +755,7 @@ check_call_url(GtkGestureMultiPress *multi_press,
     const GdkEvent *event;
     GdkModifierType state;
 
-    gesture = GTK_GESTURE(multi_press);
+    gesture = GTK_GESTURE(click);
     event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
 
     if (event == NULL || !gdk_event_get_state(event, &state)) {
@@ -1150,7 +1150,7 @@ balsa_gtk_html_popup(GtkWidget * html, BalsaMessage * bm)
 }
 
 static void
-mwt_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+mwt_gesture_pressed_cb(GtkGestureClick *click,
                        gint                  n_press,
                        gdouble               x,
                        gdouble               y,
@@ -1161,7 +1161,7 @@ mwt_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
     GtkWidget *html;
     BalsaMessage *bm = user_data;
 
-    gesture = GTK_GESTURE(multi_press);
+    gesture = GTK_GESTURE(click);
     event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
     g_return_if_fail(event != NULL);
     html = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
@@ -1209,7 +1209,7 @@ bm_widget_new_html(BalsaMessage * bm, LibBalsaMessageBody * mime_body)
     } else {
         GtkGesture *gesture;
 
-        gesture = gtk_gesture_multi_press_new();
+        gesture = gtk_gesture_click_new();
         gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
         g_signal_connect(gesture, "pressed",
                          G_CALLBACK(mwt_gesture_pressed_cb), bm);
diff --git a/src/balsa-mime-widget-vcalendar.c b/src/balsa-mime-widget-vcalendar.c
index 17bb1a026..4b81e72a1 100644
--- a/src/balsa-mime-widget-vcalendar.c
+++ b/src/balsa-mime-widget-vcalendar.c
@@ -34,7 +34,7 @@
 static GtkWidget *balsa_vevent_widget(LibBalsaVEvent * event,
                                      gboolean may_reply,
                                      InternetAddress * sender);
-static void vevent_reply(GObject * button, GtkWidget * box);
+static void vevent_reply(GtkWidget * button, GtkWidget * box);
 
 
 BalsaMimeWidget *
@@ -249,7 +249,7 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
                                (GDestroyNotify) g_object_unref);
        g_object_set_data(G_OBJECT(button), "mode",
                          GINT_TO_POINTER(VCAL_PSTAT_ACCEPTED));
-       g_signal_connect(G_OBJECT(button), "clicked",
+       g_signal_connect(button, "clicked",
                         G_CALLBACK(vevent_reply), bbox);
        gtk_container_add(GTK_CONTAINER(bbox), button);
 
@@ -257,7 +257,7 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
        g_object_set_data(G_OBJECT(button), "event", event);
        g_object_set_data(G_OBJECT(button), "mode",
                          GINT_TO_POINTER(VCAL_PSTAT_TENTATIVE));
-       g_signal_connect(G_OBJECT(button), "clicked",
+       g_signal_connect(button, "clicked",
                         G_CALLBACK(vevent_reply), bbox);
        gtk_container_add(GTK_CONTAINER(bbox), button);
 
@@ -265,7 +265,7 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
        g_object_set_data(G_OBJECT(button), "event", event);
        g_object_set_data(G_OBJECT(button), "mode",
                          GINT_TO_POINTER(VCAL_PSTAT_DECLINED));
-       g_signal_connect(G_OBJECT(button), "clicked",
+       g_signal_connect(button, "clicked",
                         G_CALLBACK(vevent_reply), bbox);
        gtk_container_add(GTK_CONTAINER(bbox), button);
 
@@ -275,12 +275,12 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
 }
 
 static void
-vevent_reply(GObject * button, GtkWidget * box)
+vevent_reply(GtkWidget * button, GtkWidget * box)
 {
     LibBalsaVEvent *event =
-       LIBBALSA_VEVENT(g_object_get_data(button, "event"));
+       LIBBALSA_VEVENT(g_object_get_data(G_OBJECT(button), "event"));
     LibBalsaVCalPartStat pstat =
-       GPOINTER_TO_INT(g_object_get_data(button, "mode"));
+       GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "mode"));
     gchar *rcpt;
     LibBalsaMessage *message;
     LibBalsaMessageHeaders *headers;
@@ -339,8 +339,7 @@ vevent_reply(GObject * button, GtkWidget * box)
                                   balsa_find_sentbox_by_url,
                                   libbalsa_identity_get_smtp_server(ident),
                                   balsa_app.send_progress_dialog,
-                                   GTK_WINDOW(gtk_widget_get_toplevel
-                                              ((GtkWidget *) button)),
+                                   GTK_WINDOW(gtk_widget_get_root(button)),
                                   FALSE, &error);
     if (result != LIBBALSA_MESSAGE_CREATE_OK)
        libbalsa_information(LIBBALSA_INFORMATION_ERROR,
diff --git a/src/compose-window.c b/src/compose-window.c
index 44591d04b..ce1895cbf 100644
--- a/src/compose-window.c
+++ b/src/compose-window.c
@@ -1500,7 +1500,7 @@ balsa_compose_window_size_allocate(GtkWidget           *widget,
     GTK_WIDGET_CLASS(balsa_compose_window_parent_class)->size_allocate
         (widget, width, height, baseline);
 
-    surface = gtk_widget_get_surface(widget);
+    surface = gtk_native_get_surface(GTK_NATIVE(widget));
     if (surface == NULL)
         return;
 
@@ -1591,7 +1591,7 @@ change_attach_mode(GtkWidget       *menu_item,
         GtkWidget *extbody_dialog, *parent;
         gint result;
 
-        parent         = gtk_widget_get_toplevel(menu_item);
+        parent         = GTK_WIDGET(gtk_widget_get_root(menu_item));
         extbody_dialog =
             gtk_message_dialog_new(GTK_WINDOW(parent),
                                    GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -1656,7 +1656,7 @@ static void
 on_open_url_cb(GtkWidget       *menu_item,
                BalsaAttachInfo *info)
 {
-    GtkWidget *toplevel;
+    GtkWidget *root;
     GError *err = NULL;
     const gchar *uri;
 
@@ -1665,9 +1665,9 @@ on_open_url_cb(GtkWidget       *menu_item,
     g_return_if_fail(uri != NULL);
 
     g_message("open URL %s", uri);
-    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(menu_item));
-    if (gtk_widget_is_toplevel(toplevel)) {
-        gtk_show_uri_on_window(GTK_WINDOW(toplevel), uri,
+    root = GTK_WIDGET(gtk_widget_get_root(menu_item));
+    if (GTK_IS_WINDOW(root)) {
+        gtk_show_uri_on_window((GtkWindow *) root, uri,
                                gtk_get_current_event_time(), &err);
     }
     if (err) {
@@ -2279,20 +2279,23 @@ insert_selected_messages(BalsaComposeWindow *compose_window,
 {
     GtkTextBuffer *buffer =
         gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose_window->text));
-    GtkWidget *index =
+    BalsaIndex *bindex =
         balsa_window_find_current_index(balsa_app.main_window);
-    GList *l;
 
-    if (index && (l = balsa_index_selected_list(BALSA_INDEX(index)))) {
+    if (bindex != NULL) {
+        GList *selected_list = balsa_index_selected_list(bindex);
         GList *node;
 
-        for (node = l; node != NULL; node = node->next) {
+        for (node = selected_list; node != NULL; node = node->next) {
             LibBalsaMessage *message = node->data;
-            GString *body            = quote_message_body(compose_window, message, type);
+            GString *body;
+
+            body = quote_message_body(compose_window, message, type);
             gtk_text_buffer_insert_at_cursor(buffer, body->str, body->len);
             g_string_free(body, TRUE);
         }
-        g_list_free_full(l, g_object_unref);
+
+        g_list_free_full(selected_list, g_object_unref);
     }
 }
 
@@ -2314,13 +2317,13 @@ sw_attach_messages_activated(GSimpleAction *action,
                              gpointer       data)
 {
     BalsaComposeWindow *compose_window = data;
-    GtkWidget *index    =
-        balsa_window_find_current_index(balsa_app.main_window);
+    BalsaIndex *bindex = balsa_window_find_current_index(balsa_app.main_window);
 
-    if (index) {
-        GList *node, *l = balsa_index_selected_list(BALSA_INDEX(index));
+    if (bindex != NULL) {
+        GList *selected_list = balsa_index_selected_list(bindex);
+        GList *node;
 
-        for (node = l; node != NULL; node = node->next) {
+        for (node = selected_list; node != NULL; node = node->next) {
             LibBalsaMessage *message = node->data;
 
             if (!attach_message(compose_window, message)) {
@@ -2331,7 +2334,7 @@ sw_attach_messages_activated(GSimpleAction *action,
                 break;
             }
         }
-        g_list_free_full(l, g_object_unref);
+        g_list_free_full(selected_list, g_object_unref);
     }
 }
 
@@ -2665,7 +2668,7 @@ create_from_entry(GtkWidget    *grid,
 
 
 static void
-sw_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
+sw_gesture_pressed_cb(GtkGestureClick *click,
                       gint                  n_press,
                       gdouble               x,
                       gdouble               y,
@@ -2676,7 +2679,7 @@ sw_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
     GtkTreeView *tree_view;
     GtkTreePath *path;
 
-    gesture = GTK_GESTURE(multi_press);
+    gesture = GTK_GESTURE(click);
     event   =
         gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
     g_return_if_fail(event != NULL);
@@ -2945,7 +2948,7 @@ sw_attachment_list(BalsaComposeWindow *compose_window)
     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(view),
                                 GTK_SELECTION_SINGLE);
 
-    gesture = gtk_gesture_multi_press_new();
+    gesture = gtk_gesture_click_new();
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(sw_gesture_pressed_cb), NULL);
diff --git a/src/folder-conf.c b/src/folder-conf.c
index d8c72a474..eaa3a3c3e 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -581,7 +581,8 @@ browse_button_cb(GtkWidget * widget, SubfolderDialogData * sdd)
     CommonDialogData *cdd = (CommonDialogData *) sdd;
     GtkWidget *scroll, *dialog;
     GtkRequisition req;
-    GtkWidget *tree_view = balsa_mblist_new();
+    BalsaMBList *mblist = balsa_mblist_new();
+    GtkWidget *tree_view = GTK_WIDGET(balsa_mblist_get_tree_view(mblist));
     GtkTreeSelection *selection =
         gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
     BrowseButtonData *bbd;
diff --git a/src/main-window.c b/src/main-window.c
index 29800110c..92d7f7a62 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -111,7 +111,7 @@ static void balsa_window_dispose(GObject * object);
 
 static gboolean bw_close_mailbox_on_timer(BalsaWindow * window);
 
-static void bw_index_changed_cb(GtkWidget * widget, gpointer data);
+static void bw_index_changed_cb(BalsaIndex *bindex, gpointer data);
 static void bw_idle_replace(BalsaWindow * window, BalsaIndex * bindex);
 static void bw_idle_remove(BalsaWindow * window);
 static gboolean bw_idle_cb(BalsaWindow * window);
@@ -198,7 +198,7 @@ struct _BalsaWindowPrivate {
     GtkWidget *preview;                /* message is child */
     GtkWidget *paned_master;
     GtkWidget *paned_slave;
-    GtkWidget *current_index;
+    BalsaIndex *current_index;
     GtkWidget *filter_choice;
     GtkWidget *vbox;
     GtkWidget *content;
@@ -367,14 +367,14 @@ bw_check_filter(GtkWidget *widget, GParamSpec *pspec, gpointer user_data)
 static void
 bw_set_view_filter(BalsaWindow * bw, gint filter_no, GtkWidget * entry)
 {
-    GtkWidget *index = balsa_window_find_current_index(bw);
+    BalsaIndex *index = balsa_window_find_current_index(bw);
     LibBalsaCondition *view_filter;
 
-    if (!index)
+    if (index == NULL)
         return;
 
     view_filter = bw_get_view_filter(bw);
-    balsa_index_set_view_filter(BALSA_INDEX(index), filter_no,
+    balsa_index_set_view_filter(index, filter_no,
                                 gtk_editable_get_text(GTK_EDITABLE(entry)),
                                 view_filter);
     libbalsa_condition_unref(view_filter);
@@ -545,7 +545,7 @@ bw_set_panes(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
     GtkWidget *index_widget = bw_create_index_widget(window);
-    GtkWidget *bindex;
+    BalsaIndex *bindex;
     BalsaIndexWidthPreference width_preference;
 
     switch (balsa_app.layout_type) {
@@ -607,8 +607,8 @@ bw_set_panes(BalsaWindow * window)
                         bw_frame(priv->preview), TRUE, TRUE);
         width_preference = BALSA_INDEX_WIDE;
     }
-    if ( (bindex=balsa_window_find_current_index(window)) != NULL)
-        balsa_index_set_width_preference(BALSA_INDEX(bindex), width_preference);
+    if ((bindex = balsa_window_find_current_index(window)) != NULL)
+        balsa_index_set_width_preference(bindex, width_preference);
 
     gtk_box_reorder_child_after(GTK_BOX(priv->vbox), priv->bottom_bar, priv->content);
 }
@@ -1043,13 +1043,13 @@ continue_activated(GSimpleAction * action,
                    gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
+    bindex = balsa_window_find_current_index(window);
 
-    if (index != NULL
-        && balsa_index_get_mailbox(BALSA_INDEX(index)) == balsa_app.draftbox)
-        balsa_message_continue(BALSA_INDEX(index));
+    if (bindex != NULL
+        && balsa_index_get_mailbox(bindex) == balsa_app.draftbox)
+        balsa_message_continue(bindex);
     else
         balsa_mblist_open_mailbox(balsa_app.draftbox);
 }
@@ -1105,14 +1105,12 @@ print_activated(GSimpleAction * action,
                 gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
     BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    if (!index)
+    bindex = balsa_window_find_current_index(window);
+    if (bindex == NULL)
         return;
 
-    bindex = BALSA_INDEX(index);
     if (balsa_index_get_current_msgno(bindex) != 0) {
         LibBalsaMailbox *mailbox;
         LibBalsaMessage *message;
@@ -1165,10 +1163,10 @@ select_thread_activated(GSimpleAction * action,
                         gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *bindex;
+    BalsaIndex *bindex;
 
-    if ((bindex = balsa_window_find_current_index(window)))
-        balsa_index_select_thread(BALSA_INDEX(bindex));
+    if ((bindex = balsa_window_find_current_index(window)) != NULL)
+        balsa_index_select_thread(bindex);
 }
 
 static void
@@ -1177,10 +1175,10 @@ find_activated(GSimpleAction * action,
                gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *bindex;
+    BalsaIndex *bindex;
 
-    if ((bindex = balsa_window_find_current_index(window)))
-        bw_find_real(window, BALSA_INDEX(bindex), FALSE);
+    if ((bindex = balsa_window_find_current_index(window)) != NULL)
+        bw_find_real(window, bindex, FALSE);
 }
 
 static void
@@ -1189,10 +1187,10 @@ find_next_activated(GSimpleAction * action,
                     gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget * bindex;
+    BalsaIndex *bindex;
 
-    if ((bindex = balsa_window_find_current_index(window)))
-       bw_find_real(window, BALSA_INDEX(bindex), TRUE);
+    if ((bindex = balsa_window_find_current_index(window)) != NULL)
+       bw_find_real(window, bindex, TRUE);
 }
 
 static void
@@ -1229,10 +1227,10 @@ expand_all_activated(GSimpleAction * action,
                      gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_update_tree(BALSA_INDEX(index), TRUE);
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_update_tree(bindex, TRUE);
 }
 
 static void
@@ -1241,10 +1239,10 @@ collapse_all_activated(GSimpleAction * action,
                        gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_update_tree(BALSA_INDEX(index), FALSE);
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_update_tree(bindex, FALSE);
 }
 
 #ifdef HAVE_HTML_WIDGET
@@ -1291,10 +1289,10 @@ next_message_activated(GSimpleAction * action,
                        gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_select_next(BALSA_INDEX(index));
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_select_next(bindex);
 }
 
 static void
@@ -1303,10 +1301,10 @@ previous_message_activated(GSimpleAction * action,
                            gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_select_previous(BALSA_INDEX(index));
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_select_previous(bindex);
 }
 
 static void
@@ -1325,10 +1323,10 @@ next_flagged_activated(GSimpleAction * action,
                        gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_select_next_flagged(BALSA_INDEX(index));
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_select_next_flagged(bindex);
 }
 
 static void
@@ -1338,12 +1336,12 @@ reset_filter_activated(GSimpleAction * action,
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
     /* do it by resetting the sos filder */
     gtk_editable_set_text(GTK_EDITABLE(priv->sos_entry), "");
-    index = balsa_window_find_current_index(window);
-    bw_set_view_filter(window, balsa_index_get_filter_no(BALSA_INDEX(index)),
+    bindex = balsa_window_find_current_index(window);
+    bw_set_view_filter(window, balsa_index_get_filter_no(bindex),
                        priv->sos_entry);
 }
 
@@ -1353,10 +1351,10 @@ mailbox_select_all_activated(GSimpleAction * action,
                              gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    gtk_widget_grab_focus(index);
+    bindex = balsa_window_find_current_index(window);
+    gtk_widget_grab_focus(GTK_WIDGET(balsa_index_get_tree_view(bindex)));
     balsa_window_select_all(GTK_WINDOW(window));
 }
 
@@ -1382,10 +1380,10 @@ mailbox_expunge_activated(GSimpleAction * action,
                           gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_expunge(BALSA_INDEX(index));
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_expunge(bindex);
 }
 
 static void
@@ -1394,13 +1392,13 @@ mailbox_close_activated(GSimpleAction * action,
                         gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    if (index != NULL) {
+    bindex = balsa_window_find_current_index(window);
+    if (bindex != NULL) {
         LibBalsaMailbox *mailbox;
 
-        mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
+        mailbox = balsa_index_get_mailbox(bindex);
         balsa_mblist_close_mailbox(mailbox);
     }
 }
@@ -1421,13 +1419,13 @@ select_filters_activated(GSimpleAction * action,
                       gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    if (index != NULL) {
+    bindex = balsa_window_find_current_index(window);
+    if (bindex != NULL) {
         LibBalsaMailbox *mailbox;
 
-        mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
+        mailbox = balsa_index_get_mailbox(bindex);
         filters_run_dialog(mailbox, GTK_WINDOW(balsa_app.main_window));
     } else {
        /* FIXME : Perhaps should we be able to apply filters on folders (ie recurse on all mailboxes in it),
@@ -1444,15 +1442,15 @@ remove_duplicates_activated(GSimpleAction * action,
                             gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
 
-    index = balsa_window_find_current_index(window);
-    if (index != NULL) {
+    bindex = balsa_window_find_current_index(window);
+    if (bindex != NULL) {
         LibBalsaMailbox *mailbox;
         gint dup_count;
         GError *err = NULL;
 
-        mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
+        mailbox = balsa_index_get_mailbox(bindex);
         dup_count = libbalsa_mailbox_move_duplicates(mailbox, NULL, &err);
         if (err != NULL) {
             balsa_information(LIBBALSA_INFORMATION_WARNING,
@@ -1574,13 +1572,13 @@ view_source_activated(GSimpleAction * action,
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
     GtkApplication *application = gtk_window_get_application(GTK_WINDOW(window));
-    GtkWidget *bindex;
+    BalsaIndex *bindex;
     GList *messages, *list;
 
     bindex = balsa_window_find_current_index(window);
     g_return_if_fail(bindex != NULL);
 
-    messages = balsa_index_selected_list(BALSA_INDEX(bindex));
+    messages = balsa_index_selected_list(bindex);
     for (list = messages; list; list = list->next) {
        LibBalsaMessage *message = list->data;
 
@@ -1634,10 +1632,10 @@ static void
 toggle_flag(LibBalsaMessageFlag flag, gpointer user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *bindex;
+    BalsaIndex *bindex;
 
     bindex = balsa_window_find_current_index(window);
-    balsa_index_toggle_flag(BALSA_INDEX(bindex), flag);
+    balsa_index_toggle_flag(bindex, flag);
 }
 
 static void
@@ -1678,12 +1676,13 @@ store_address_activated(GSimpleAction * action,
                           gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index = balsa_window_find_current_index(window);
+    BalsaIndex *bindex;
     GList *messages;
 
-    g_assert(index != NULL);
+    bindex = balsa_window_find_current_index(window);
+    g_assert(bindex != NULL);
 
-    messages = balsa_index_selected_list(BALSA_INDEX(index));
+    messages = balsa_index_selected_list(bindex);
     balsa_store_address_from_messages(messages);
     g_list_free_full(messages, g_object_unref);
 }
@@ -1922,7 +1921,7 @@ threading_change_state(GSimpleAction * action,
                        gpointer        user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
-    GtkWidget *index;
+    BalsaIndex *bindex;
     const gchar *value;
     LibBalsaMailboxThreadingType type;
     LibBalsaMailbox *mailbox;
@@ -1940,14 +1939,14 @@ threading_change_state(GSimpleAction * action,
         return;
     }
 
-    index = balsa_window_find_current_index(window);
-    balsa_index_set_threading_type(BALSA_INDEX(index), type);
+    bindex = balsa_window_find_current_index(window);
+    balsa_index_set_threading_type(bindex, type);
 
     /* bw->current_index may have been destroyed and cleared during
      * set-threading: */
-    index = balsa_window_find_current_index(window);
-    if (index != NULL &&
-        (mailbox = balsa_index_get_mailbox(BALSA_INDEX(index))) != NULL)
+    bindex = balsa_window_find_current_index(window);
+    if (bindex != NULL &&
+        (mailbox = balsa_index_get_mailbox(bindex)) != NULL)
         bw_enable_expand_collapse(window, mailbox);
 
     g_simple_action_set_state(action, state);
@@ -2226,6 +2225,7 @@ balsa_window_new(GtkApplication *application)
 #if HAVE_MACOSX_DESKTOP
     IgeMacMenuGroup *group;
 #endif
+    GtkTreeView *tree_view;
     GtkAdjustment *hadj, *vadj;
     GAction *action;
     GdkContentFormats *formats;
@@ -2305,14 +2305,15 @@ balsa_window_new(GtkApplication *application)
                      G_CALLBACK(bw_select_part_cb), window);
 
     /* XXX */
-    balsa_app.mblist =  BALSA_MBLIST(balsa_mblist_new());
+    balsa_app.mblist = balsa_mblist_new();
+    tree_view = balsa_mblist_get_tree_view(balsa_app.mblist);
 
-    g_object_get(G_OBJECT(balsa_app.mblist), "hadjustment", &hadj,
+    g_object_get(G_OBJECT(tree_view), "hadjustment", &hadj,
                  "vadjustment", &vadj, NULL);
     priv->mblist = gtk_scrolled_window_new(hadj, vadj);
 
     gtk_container_add(GTK_CONTAINER(priv->mblist),
-                      GTK_WIDGET(balsa_app.mblist));
+                      GTK_WIDGET(tree_view));
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(priv->mblist),
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
     g_signal_connect_swapped(balsa_app.mblist, "has-unread-mailbox",
@@ -2506,7 +2507,7 @@ static void
 bw_enable_message_menus(BalsaWindow * window, guint msgno)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    BalsaIndex *bindex = BALSA_INDEX(priv->current_index);
+    BalsaIndex *bindex = priv->current_index;
     gboolean enable_current_message_actions = FALSE;
     gboolean enable_message_actions = FALSE;
     gboolean enable_modify_message_actions = FALSE;
@@ -2674,14 +2675,14 @@ bw_enable_part_menu_items(BalsaWindow * window)
 static void
 bw_set_threading_menu(BalsaWindow * window, int option)
 {
-    GtkWidget *index;
+    BalsaIndex *bindex;
     LibBalsaMailbox *mailbox;
     const gchar * const threading_types[] = { "flat", "simple", "jwz" };
 
     bw_action_set_string(window, "threading", threading_types[option]);
 
-    if ((index = balsa_window_find_current_index(window)) != NULL &&
-        (mailbox = balsa_index_get_mailbox(BALSA_INDEX(index))) != NULL)
+    if ((bindex = balsa_window_find_current_index(window)) != NULL &&
+        (mailbox = balsa_index_get_mailbox(bindex)) != NULL)
         bw_enable_expand_collapse(window, mailbox);
 }
 
@@ -2893,7 +2894,7 @@ bw_real_open_mbnode_idle_cb(BalsaWindowRealOpenMbnodeInfo * info)
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);
-    gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(index));
+    gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(balsa_index_get_tree_view(index)));
     page_num = gtk_notebook_append_page(GTK_NOTEBOOK(priv->notebook),
                                         scroll, label);
     gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(priv->notebook),
@@ -2996,7 +2997,7 @@ balsa_window_real_open_mbnode(BalsaWindow * window,
     if (bw_is_open_mailbox(mailbox = balsa_mailbox_node_get_mailbox(mbnode)))
         return;
 
-    index = BALSA_INDEX(balsa_index_new());
+    index = balsa_index_new();
     balsa_index_set_width_preference
         (index,
          (balsa_app.layout_type == LAYOUT_WIDE_SCREEN)
@@ -3047,7 +3048,7 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
                                BalsaMailboxNode * mbnode)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    GtkWidget *index = NULL;
+    BalsaIndex *bindex = NULL;
     gint i;
     LibBalsaMailbox *mailbox;
     LibBalsaMailbox **mailbox_p;
@@ -3091,13 +3092,14 @@ balsa_window_real_close_mbnode(BalsaWindow * window,
         }
     }
 
-    index = balsa_window_find_current_index(window);
+    bindex = balsa_window_find_current_index(window);
     mailbox_p = g_new(LibBalsaMailbox *, 1);
-    if (index != NULL) {
-       *mailbox_p = balsa_index_get_mailbox(BALSA_INDEX(index));
+    if (bindex != NULL) {
+       *mailbox_p = balsa_index_get_mailbox(bindex);
        g_object_add_weak_pointer(G_OBJECT(*mailbox_p), (gpointer) mailbox_p);
-    } else
+    } else {
        *mailbox_p = NULL;
+    }
     g_idle_add((GSourceFunc) bw_focus_idle, mailbox_p);
 }
 
@@ -3178,14 +3180,12 @@ void
 balsa_window_refresh(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    GtkWidget *index;
     BalsaIndex *bindex;
 
-    g_return_if_fail(window);
+    g_return_if_fail(window != NULL);
 
-    index = balsa_window_find_current_index(window);
-    bindex = (BalsaIndex *) index;
-    if (bindex) {
+    bindex = balsa_window_find_current_index(window);
+    if (bindex != NULL) {
         /* update the date column, only in the current page */
         balsa_index_refresh_date(bindex);
         /* update the size column, only in the current page */
@@ -3721,7 +3721,7 @@ bw_change_connection_status_idle(gpointer user_data)
     return FALSE;
 }
 
-GtkWidget *
+BalsaIndex *
 balsa_window_find_current_index(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
@@ -3748,7 +3748,7 @@ enum {
 static void
 bw_find_button_clicked(GtkWidget * widget, gpointer data)
 {
-    GtkWidget *dialog = gtk_widget_get_toplevel(widget);
+    GtkWidget *dialog = GTK_WIDGET(gtk_widget_get_root(widget));
     gtk_dialog_response(GTK_DIALOG(dialog), GPOINTER_TO_INT(data));
 }
 
@@ -3996,7 +3996,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
 static void
 bw_mailbox_tab_close_cb(GtkWidget * widget, gpointer data)
 {
-    GtkWidget * window = gtk_widget_get_toplevel(widget);
+    GtkWidget * window = GTK_WIDGET(gtk_widget_get_root(widget));
     balsa_window_real_close_mbnode(BALSA_WINDOW(window),
                                   BALSA_MAILBOX_NODE(data));
 }
@@ -4034,16 +4034,16 @@ bw_get_view_filter(BalsaWindow *window)
 static void
 bw_hide_changed_set_view_filter(BalsaWindow * window)
 {
-    GtkWidget *index;
+    BalsaIndex *bindex;
     LibBalsaMailbox *mailbox;
     gint mask;
     LibBalsaCondition *filter;
 
-    index = balsa_window_find_current_index(window);
-    if(!index)
+    bindex = balsa_window_find_current_index(window);
+    if (bindex == NULL)
         return;
 
-    mailbox = balsa_index_get_mailbox(BALSA_INDEX(index));
+    mailbox = balsa_index_get_mailbox(bindex);
     /* Store the new filter mask in the mailbox view before we set the
      * view filter; rethreading triggers bw_set_filter_menu,
      * which retrieves the mask from the mailbox view, and we want it to
@@ -4070,7 +4070,7 @@ static void
 bw_reset_filter(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    BalsaIndex *bindex = BALSA_INDEX(balsa_window_find_current_index(window));
+    BalsaIndex *bindex = balsa_window_find_current_index(window);
 
     /* do it by resetting the sos filder */
     gtk_editable_set_text(GTK_EDITABLE(priv->sos_entry), "");
@@ -4190,7 +4190,7 @@ balsa_window_size_allocate(GtkWidget           *widget,
     GTK_WIDGET_CLASS(balsa_window_parent_class)->size_allocate
         (widget, width, height, baseline);
 
-    surface = gtk_widget_get_surface(widget);
+    surface = gtk_native_get_surface(GTK_NATIVE(widget));
     if (surface == NULL)
         return;
 
@@ -4216,16 +4216,17 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
     BalsaWindow *window = BALSA_WINDOW(data);
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
     GtkWidget *page;
-    BalsaIndex *index;
+    GtkTreeView *tree_view;
+    BalsaIndex *bindex;
     LibBalsaMailbox *mailbox;
     gchar *title;
     const gchar *filter_string;
 
-    if (priv->current_index) {
+    if (priv->current_index != NULL) {
        g_object_remove_weak_pointer(G_OBJECT(priv->current_index),
                                     (gpointer) &priv->current_index);
        /* Note when this mailbox was hidden, for use in auto-closing. */
-        balsa_index_set_last_use(BALSA_INDEX(priv->current_index));
+        balsa_index_set_last_use(priv->current_index);
         priv->current_index = NULL;
     }
 
@@ -4234,15 +4235,16 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
         return;
 
     page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), page_num);
-    index = BALSA_INDEX(gtk_bin_get_child(GTK_BIN(page)));
+    tree_view = GTK_TREE_VIEW(gtk_bin_get_child(GTK_BIN(page)));
+    bindex = balsa_index_get_from_tree_view(tree_view);
 
-    priv->current_index = GTK_WIDGET(index);
-    g_object_add_weak_pointer(G_OBJECT(index),
+    priv->current_index = bindex;
+    g_object_add_weak_pointer(G_OBJECT(bindex),
                              (gpointer) &priv->current_index);
     /* Note when this mailbox was exposed, for use in auto-expunge. */
-    balsa_index_set_last_use(index);
+    balsa_index_set_last_use(bindex);
 
-    mailbox = balsa_index_get_mailbox(index);
+    mailbox = balsa_index_get_mailbox(bindex);
     if (libbalsa_mailbox_get_name(mailbox)) {
         if (libbalsa_mailbox_get_readonly(mailbox)) {
             title =
@@ -4256,49 +4258,47 @@ bw_notebook_switch_page_cb(GtkWidget * notebook,
         gtk_window_set_title(GTK_WINDOW(window), "Balsa");
     }
 
-    g_object_set_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS, index);
-    bw_idle_replace(window, index);
-    bw_enable_message_menus(window, balsa_index_get_current_msgno(index));
-    bw_enable_mailbox_menus(window, index);
+    g_object_set_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS, bindex);
+    bw_idle_replace(window, bindex);
+    bw_enable_message_menus(window, balsa_index_get_current_msgno(bindex));
+    bw_enable_mailbox_menus(window, bindex);
 
-    filter_string = balsa_index_get_filter_string(index);
+    filter_string = balsa_index_get_filter_string(bindex);
     gtk_editable_set_text(GTK_EDITABLE(priv->sos_entry),
                        filter_string != NULL ? filter_string : "");
     gtk_combo_box_set_active(GTK_COMBO_BOX(priv->filter_choice),
-                             balsa_index_get_filter_no(index));
+                             balsa_index_get_filter_no(bindex));
 
     balsa_mblist_focus_mailbox(balsa_app.mblist, mailbox);
     balsa_window_set_statusbar(window, mailbox);
 
-    balsa_index_refresh_date(index);
-    balsa_index_refresh_size(index);
-    balsa_index_ensure_visible(index);
+    balsa_index_refresh_date(bindex);
+    balsa_index_refresh_size(bindex);
+    balsa_index_ensure_visible(bindex);
 
     g_free(balsa_app.current_mailbox_url);
     balsa_app.current_mailbox_url = g_strdup(libbalsa_mailbox_get_url(mailbox));
 }
 
 static void
-bw_index_changed_cb(GtkWidget * widget, gpointer user_data)
+bw_index_changed_cb(BalsaIndex *bindex, gpointer user_data)
 {
     BalsaWindow *window = BALSA_WINDOW(user_data);
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    BalsaIndex *index;
     LibBalsaMessage *message;
     guint current_msgno;
 
-    if (widget != priv->current_index)
+    if (bindex != priv->current_index)
         return;
 
-    index = BALSA_INDEX(widget);
-    bw_enable_message_menus(window, balsa_index_get_current_msgno(index));
-    bw_enable_mailbox_menus(window, index);
+    bw_enable_message_menus(window, balsa_index_get_current_msgno(bindex));
+    bw_enable_mailbox_menus(window, bindex);
 
     message = balsa_message_get_message(BALSA_MESSAGE(priv->preview));
     current_msgno = message != NULL ? libbalsa_message_get_msgno(message) : 0;
 
-    if (current_msgno != balsa_index_get_current_msgno(index))
-        bw_idle_replace(window, index);
+    if (current_msgno != balsa_index_get_current_msgno(bindex))
+        bw_idle_replace(window, bindex);
 }
 
 static void
@@ -4332,7 +4332,7 @@ static gboolean
 bw_idle_cb(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    BalsaIndex *index;
+    BalsaIndex *bindex;
 
     if (priv->set_message_id == 0) {
         return FALSE;
@@ -4344,17 +4344,17 @@ bw_idle_cb(BalsaWindow * window)
 
     priv->set_message_id = 0;
 
-    index = (BalsaIndex *) priv->current_index;
-    if (index)
+    bindex = priv->current_index;
+    if (bindex != NULL)
         balsa_message_set(BALSA_MESSAGE(priv->preview),
-                          balsa_index_get_mailbox(index),
-                          balsa_index_get_current_msgno(index));
+                          balsa_index_get_mailbox(bindex),
+                          balsa_index_get_current_msgno(bindex));
     else
         balsa_message_set(BALSA_MESSAGE(priv->preview), NULL, 0);
 
-    index = g_object_get_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS);
-    if (index) {
-        gtk_widget_grab_focus(GTK_WIDGET(index));
+    bindex = g_object_get_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS);
+    if (bindex != NULL) {
+        gtk_widget_grab_focus(GTK_WIDGET(balsa_index_get_tree_view(bindex)));
         g_object_set_data(G_OBJECT(window), BALSA_INDEX_GRAB_FOCUS, NULL);
     }
 
diff --git a/src/main-window.h b/src/main-window.h
index 32bbcc02f..ced4ab9df 100644
--- a/src/main-window.h
+++ b/src/main-window.h
@@ -30,6 +30,7 @@
 
 #include <gio/gio.h>
 
+#include "balsa-index.h"
 #include "mailbox-node.h"
 #include "toolbar-factory.h"
 
@@ -75,7 +76,7 @@ enum {
 GType balsa_window_get_type(void);
 GtkWidget *balsa_window_new(GtkApplication *application);
 gboolean balsa_window_fix_paned(BalsaWindow *window);
-GtkWidget *balsa_window_find_current_index(BalsaWindow * window);
+BalsaIndex *balsa_window_find_current_index(BalsaWindow * window);
 void balsa_window_update_book_menus(BalsaWindow *window);
 void balsa_window_refresh(BalsaWindow * window);
 void balsa_window_open_mbnode(BalsaWindow * window,
diff --git a/src/message-window.c b/src/message-window.c
index 9674b5d42..ed9a4db41 100644
--- a/src/message-window.c
+++ b/src/message-window.c
@@ -544,7 +544,7 @@ size_alloc_cb(GtkWidget           *widget,
     GTK_WIDGET_CLASS(balsa_message_window_parent_class)->size_allocate
         (widget, width, height, baseline);
 
-    surface = gtk_widget_get_surface(widget);
+    surface = gtk_native_get_surface(GTK_NATIVE(widget));
 
     if (surface == NULL)
         return;
diff --git a/src/pref-manager.c b/src/pref-manager.c
index 740f6b9db..c5ae04e3c 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -1073,7 +1073,7 @@ balsa_help_pbox_display(void)
     gchar *text, *p;
     GError *err = NULL;
     gchar *uri;
-    GtkWidget *toplevel;
+    GtkWidget *root;
     GString *string;
 
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pui->view));
@@ -1097,9 +1097,9 @@ balsa_help_pbox_display(void)
     g_free(text);
 
     uri = g_string_free(string, FALSE);
-    toplevel = gtk_widget_get_toplevel(GTK_WIDGET(pui->view));
-    if (gtk_widget_is_toplevel(toplevel)) {
-        gtk_show_uri_on_window(GTK_WINDOW(toplevel), uri,
+    root = GTK_WIDGET(gtk_widget_get_root(pui->view));
+    if (GTK_IS_WINDOW(root)) {
+        gtk_show_uri_on_window((GtkWindow *) root, uri,
                                gtk_get_current_event_time(), &err);
     }
     if (err) {
diff --git a/src/toolbar-factory.c b/src/toolbar-factory.c
index 4da886aab..2c9d54e0d 100644
--- a/src/toolbar-factory.c
+++ b/src/toolbar-factory.c
@@ -752,7 +752,7 @@ tm_popup_context_menu_cb(GtkWidget    *toolbar,
         item =
             gtk_menu_item_new_with_mnemonic(_("_Customize Toolbars…"));
         g_signal_connect(item, "activate", G_CALLBACK(customize_dialog_cb),
-                         gtk_widget_get_toplevel(toolbar));
+                         gtk_widget_get_root(toolbar));
         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
         /* Pass the model type to the customize widget, so that it can



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