[balsa] main-window: Fix some geometry



commit eca4f7b5e4c5a222cc4efd576d416c41ee3eb6d8
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sun Nov 1 14:42:02 2020 -0500

    main-window: Fix some geometry
    
    Use the correct GtkPaned's position to detect changes in the
    width of BalsaMBList and the height of BalsaIndex
    
    * src/main-window.c
      (Private structure): add mblist_parent and notebook_parent widgets;
      (bw_mblist_parent_position_cb): callback for the mblist's horizontal GtkPaned parent;
      (bw_notebook_parent_position_cb): callback for the notebook's vertical GtkPaned parent;
      (bw_set_panes): set priv->mblist_parent and priv->notebook_parent according to the layout;
      (balsa_window_new),
      (balsa_window_fix_paned),
      (balsa_window_refresh),
      (bw_show_mbtree),
      (balsa_change_window_layout): use the appropriate parent GtkPaneds,
        instead of paned_parent and paned_child.

 ChangeLog         |  23 ++++++++
 src/main-window.c | 174 ++++++++++++++++++++++++++++++------------------------
 2 files changed, 119 insertions(+), 78 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index eeb423c44..7de73686f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2020-11-01  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       main-window: Fix some geometry
+
+       Use the correct GtkPaned's position to detect changes in the
+       width of BalsaMBList and the height of BalsaIndex
+
+       * src/main-window.c
+         (Private structure): add mblist_parent and notebook_parent
+           widgets;
+         (bw_mblist_parent_position_cb): callback for the mblist's
+           horizontal GtkPaned parent;
+         (bw_notebook_parent_position_cb): callback for the notebook's
+           vertical GtkPaned parent;
+         (bw_set_panes): set priv->mblist_parent and
+           priv->notebook_parent according to the layout;
+         (balsa_window_new),
+         (balsa_window_fix_paned),
+         (balsa_window_refresh),
+         (bw_show_mbtree),
+         (balsa_change_window_layout): use the appropriate parent
+         GtkPaneds, instead of paned_parent and paned_child.
+
 2020-10-17  Peter Bloomfield  <pbloomfield bellsouth net>
 
        balsa-icons: rename balsa_register_pixbufs()
diff --git a/src/main-window.c b/src/main-window.c
index 795ee85af..0b01b7590 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -147,10 +147,6 @@ static void bw_select_part_cb(BalsaMessage * bm, gpointer data);
 static void bw_find_real(BalsaWindow * window, BalsaIndex * bindex,
                          gboolean again);
 
-static void bw_paned_child_position_cb(GtkPaned   * paned_child,
-                                       GParamSpec * pspec,
-                                       gpointer     user_data);
-
 static void bw_notebook_switch_page_cb(GtkWidget * notebook,
                                        void * page,
                                        guint page_num,
@@ -202,10 +198,11 @@ struct _BalsaWindowPrivate {
     GtkWidget *preview;                /* message is child */
     GtkWidget *paned_parent;
     GtkWidget *paned_child;
+    GtkWidget *mblist_parent;    /* the horizontal GtkPaned parent of BalsaWindow:mblist */
+    GtkWidget *notebook_parent;  /* the vertical GtkPaned parent of BalsaWindow:notebook */
     GtkWidget *current_index;
     GtkWidget *filter_choice;
     GtkWidget *vbox;
-    GtkWidget *content;
 
     guint set_message_id;
 
@@ -338,13 +335,21 @@ bw_delete_cb(GtkWidget* main_window)
 }
 
 static void
-bw_paned_parent_position_cb(GtkPaned   * paned_parent,
-                            GParamSpec * pspec,
-                            gpointer     user_data)
+bw_mblist_parent_position_cb(GtkPaned   * mblist_parent,
+                             GParamSpec * pspec,
+                             gpointer     user_data)
 {
     if (balsa_app.show_mblist)
-        balsa_app.mblist_width = /* FIXME: this makes some assumptions... */
-            gtk_paned_get_position(paned_parent);
+        balsa_app.mblist_width = gtk_paned_get_position(mblist_parent);
+}
+
+static void
+bw_notebook_parent_position_cb(GtkPaned   * notebook_parent,
+                               GParamSpec * pspec,
+                               gpointer     user_data)
+{
+    if (balsa_app.previewpane)
+        balsa_app.notebook_height = gtk_paned_get_position(notebook_parent);
 }
 
 static GtkWidget *
@@ -578,20 +583,22 @@ static void
 bw_set_panes(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    GtkWidget *index_widget = bw_create_index_widget(window);
+    GtkWidget *index_widget;
     GtkWidget *bindex;
     BalsaIndexWidthPreference width_preference;
 
+    if (priv->paned_parent != NULL)
+        gtk_container_remove(GTK_CONTAINER(priv->vbox), priv->paned_parent);
+    index_widget = bw_create_index_widget(window);
+
     switch (balsa_app.layout_type) {
     case LAYOUT_WIDE_MSG:
        priv->paned_parent = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
        priv->paned_child  = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
-        if (priv->content)
-            gtk_container_remove(GTK_CONTAINER(priv->vbox),
-                                 priv->content);
-        priv->content = priv->paned_parent;
-        gtk_box_pack_start(GTK_BOX(priv->vbox), priv->content,
-                           TRUE, TRUE, 0);
+
+        priv->mblist_parent = priv->paned_child;
+        priv->notebook_parent = priv->paned_parent;
+
        gtk_paned_pack1(GTK_PANED(priv->paned_child),
                        bw_frame(priv->mblist), TRUE, TRUE);
         gtk_paned_pack2(GTK_PANED(priv->paned_child),
@@ -600,17 +607,18 @@ bw_set_panes(BalsaWindow * window)
                        priv->paned_child, TRUE, TRUE);
        gtk_paned_pack2(GTK_PANED(priv->paned_parent),
                        bw_frame(priv->preview), TRUE, TRUE);
+
         width_preference = BALSA_INDEX_WIDE;
+
        break;
+
     case LAYOUT_WIDE_SCREEN:
        priv->paned_parent = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
        priv->paned_child  = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
-        if (priv->content)
-            gtk_container_remove(GTK_CONTAINER(priv->vbox),
-                                 priv->content);
-        priv->content = priv->paned_parent;
-        gtk_box_pack_start(GTK_BOX(priv->vbox), priv->content,
-                           TRUE, TRUE, 0);
+
+        priv->mblist_parent = priv->paned_parent;
+        priv->notebook_parent = NULL;
+
        gtk_paned_pack1(GTK_PANED(priv->paned_parent),
                         bw_frame(priv->mblist), TRUE, TRUE);
         gtk_paned_pack2(GTK_PANED(priv->paned_parent), priv->paned_child,
@@ -619,18 +627,19 @@ bw_set_panes(BalsaWindow * window)
                         bw_frame(index_widget), TRUE, FALSE);
        gtk_paned_pack2(GTK_PANED(priv->paned_child),
                         bw_frame(priv->preview), TRUE, TRUE);
+
         width_preference = BALSA_INDEX_NARROW;
+
        break;
+
     case LAYOUT_DEFAULT:
     default:
        priv->paned_parent = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
        priv->paned_child  = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
-        if (priv->content)
-            gtk_container_remove(GTK_CONTAINER(priv->vbox),
-                                 priv->content);
-        priv->content = priv->paned_parent;
-        gtk_box_pack_start(GTK_BOX(priv->vbox), priv->content,
-                           TRUE, TRUE, 0);
+
+        priv->mblist_parent = priv->paned_parent;
+        priv->notebook_parent = priv->paned_child;
+
        gtk_paned_pack1(GTK_PANED(priv->paned_parent),
                         bw_frame(priv->mblist), TRUE, TRUE);
         gtk_paned_pack2(GTK_PANED(priv->paned_parent), priv->paned_child,
@@ -639,9 +648,15 @@ bw_set_panes(BalsaWindow * window)
                         bw_frame(index_widget), TRUE, TRUE);
        gtk_paned_pack2(GTK_PANED(priv->paned_child),
                         bw_frame(priv->preview), TRUE, TRUE);
+
         width_preference = BALSA_INDEX_WIDE;
     }
-    if ( (bindex=balsa_window_find_current_index(window)) != NULL)
+
+    gtk_widget_show(priv->paned_child);
+    gtk_widget_show(priv->paned_parent);
+    gtk_box_pack_start(GTK_BOX(priv->vbox), priv->paned_parent, TRUE, TRUE, 0);
+
+    if ((bindex = balsa_window_find_current_index(window)) != NULL)
         balsa_index_set_width_preference(BALSA_INDEX(bindex), width_preference);
 }
 
@@ -2303,28 +2318,27 @@ balsa_window_new(GtkApplication *application)
 
     bw_set_panes(window);
 
-    /*PKGW: do it this way, without the usizes. */
     bw_action_set_boolean(window, "show-mailbox-tree",
                           balsa_app.show_mblist);
 
     if (balsa_app.show_mblist) {
         gtk_widget_show(priv->mblist);
-        gtk_paned_set_position(GTK_PANED(priv->paned_parent),
+        gtk_paned_set_position(GTK_PANED(priv->mblist_parent),
                                balsa_app.mblist_width);
     } else {
-        gtk_paned_set_position(GTK_PANED(priv->paned_parent), 0);
+        gtk_paned_set_position(GTK_PANED(priv->mblist_parent), 0);
     }
 
-    /*PKGW: do it this way, without the usizes. */
-    if (balsa_app.previewpane)
-        gtk_paned_set_position(GTK_PANED(priv->paned_child),
-                               balsa_app.notebook_height);
-    else
-        /* Set it to something really high */
-        gtk_paned_set_position(GTK_PANED(priv->paned_child), G_MAXINT);
+    if (priv->notebook_parent != NULL) {
+        if (balsa_app.previewpane) {
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent),
+                                   balsa_app.notebook_height);
+        } else {
+            /* Set it to something really high */
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent), G_MAXINT);
+        }
+    }
 
-    gtk_widget_show(priv->paned_child);
-    gtk_widget_show(priv->paned_parent);
     gtk_widget_show(priv->notebook);
 
     /* set the toolbar style */
@@ -2379,24 +2393,34 @@ balsa_window_new(GtkApplication *application)
     return GTK_WIDGET(window);
 }
 
+/*
+ * balsa_window_fix_paned
+ *
+ * Called as either an idle handler or a timeout handler, after the
+ * BalsaWindow has been created
+ */
+
 gboolean
 balsa_window_fix_paned(BalsaWindow *window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
 
     if (balsa_app.show_mblist) {
-        gtk_paned_set_position(GTK_PANED(priv->paned_parent),
+        gtk_paned_set_position(GTK_PANED(priv->mblist_parent),
                                balsa_app.mblist_width);
     }
-    if (balsa_app.previewpane) {
-        gtk_paned_set_position(GTK_PANED(priv->paned_child),
-                               balsa_app.notebook_height);
-    }
 
-    g_signal_connect(priv->paned_parent, "notify::position",
-                     G_CALLBACK(bw_paned_parent_position_cb), NULL);
-    g_signal_connect(priv->paned_child, "notify::position",
-                     G_CALLBACK(bw_paned_child_position_cb), NULL);
+    g_signal_connect(priv->mblist_parent, "notify::position",
+                     G_CALLBACK(bw_mblist_parent_position_cb), NULL);
+
+    if (priv->notebook_parent != NULL) {
+        if (balsa_app.previewpane) {
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent),
+                                   balsa_app.notebook_height);
+        }
+        g_signal_connect(priv->notebook_parent, "notify::position",
+                         G_CALLBACK(bw_notebook_parent_position_cb), NULL);
+    }
 
     return FALSE;
 }
@@ -3183,12 +3207,16 @@ balsa_window_refresh(BalsaWindow * window)
     }
     if (balsa_app.previewpane) {
         bw_idle_replace(window, bindex);
-       gtk_paned_set_position(GTK_PANED(priv->paned_child),
-                                balsa_app.notebook_height);
+        if (priv->notebook_parent != NULL) {
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent),
+                                   balsa_app.notebook_height);
+        }
     } else {
-       /* Set the height to something really big (those new hi-res
-          screens and all :) */
-       gtk_paned_set_position(GTK_PANED(priv->paned_child), G_MAXINT);
+        if (priv->notebook_parent != NULL) {
+            /* Set the height to something really big (those new hi-res
+             * screens and all :) */
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent), G_MAXINT);
+        }
     }
 }
 
@@ -4122,20 +4150,13 @@ static void
 bw_show_mbtree(BalsaWindow * window)
 {
     BalsaWindowPrivate *priv = balsa_window_get_instance_private(window);
-    GtkWidget *parent;
-
-    parent = gtk_widget_get_ancestor(priv->mblist, GTK_TYPE_PANED);
-    while (gtk_orientable_get_orientation(GTK_ORIENTABLE(parent)) !=
-           GTK_ORIENTATION_HORIZONTAL) {
-        parent = gtk_widget_get_ancestor(parent, GTK_TYPE_PANED);
-    }
 
     if (balsa_app.show_mblist) {
         gtk_widget_show(priv->mblist);
-        gtk_paned_set_position(GTK_PANED(parent), balsa_app.mblist_width);
+        gtk_paned_set_position(GTK_PANED(priv->mblist_parent), balsa_app.mblist_width);
     } else {
         gtk_widget_hide(priv->mblist);
-        gtk_paned_set_position(GTK_PANED(parent), 0);
+        gtk_paned_set_position(GTK_PANED(priv->mblist_parent), 0);
     }
 }
 
@@ -4164,22 +4185,19 @@ balsa_change_window_layout(BalsaWindow *window)
     g_object_unref(priv->mblist);
     g_object_unref(priv->preview);
 
-    gtk_paned_set_position(GTK_PANED(priv->paned_parent),
+    gtk_paned_set_position(GTK_PANED(priv->mblist_parent),
                            balsa_app.show_mblist ?
                            balsa_app.mblist_width : 0);
-    gtk_widget_show(priv->paned_child);
-    gtk_widget_show(priv->paned_parent);
-
-}
 
-/* PKGW: remember when they change the position of the vpaned. */
-static void
-bw_paned_child_position_cb(GtkPaned   * paned_child,
-                           GParamSpec * pspec,
-                           gpointer     user_data)
-{
-    if (balsa_app.previewpane)
-        balsa_app.notebook_height = gtk_paned_get_position(paned_child);
+    if (priv->notebook_parent != NULL) {
+        if (balsa_app.previewpane) {
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent),
+                                   balsa_app.notebook_height);
+        } else {
+            /* Set it to something really high */
+            gtk_paned_set_position(GTK_PANED(priv->notebook_parent), G_MAXINT);
+        }
+    }
 }
 
 /* When page is switched we change the preview window and the selected


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