r23202 - gnucash/trunk/src/gnome - Bug #699450

Mike Evans mikee at code.gnucash.org
Tue Oct 1 08:22:04 EDT 2013


Author: mikee
Date: 2013-10-01 08:22:00 -0400 (Tue, 01 Oct 2013)
New Revision: 23202
Trac: http://svn.gnucash.org/trac/changeset/23202

Modified:
   gnucash/trunk/src/gnome/gnc-budget-view.c
Log:
Bug #699450

Reverses previous commit for this bug and applies patches for fix.

This is an amalgum of 7 patches.
Patch comments are reproduced below.  All patches supplied by R Ratcliff.

[PATCH 1/7] Fix budget view resizing issue

The fix here is to change the hardcoded width value from 86 to 60.
* Remove size-allocate signal bound to treeviewcolumn (columns
  don't emit signals)

[PATCH 2/7] Fix the way column width is determined

The budget tree view has a bunch of columns that have visible
set to false. These columns have a width of 0. Change
gbv_tree_view_resized_cb to ignore these columns.

[PATCH 3/7] Change column sizing method.

Not sure if this is crucial to the bug fix.

[PATCH 4/7] Fix regression for window horizontal resizing

This change does two things
* Set expand on totals_title_col to TRUE
* Not set the width of this column in gbv_treeview_resized_cb

Note: The second one is a bit tricky. It relies on the fact that
totals_title_col has a default sizing of GROW_ONLY. It only explicitly
sets the size on columns that have a sizing of FIXED

[PATCH 5/7] Fix horizontal scrolling

* Add a vbox inside the scrolled_window, and add the two treeviews to that.

This fixes horizontal scrolling. If the budget view is too wide for the
window, then a horizontal scrollbar will appear at the bottom, and scroll
both the main budget view and the totals view at the bottom.

However, it breaks vertical scrolling (vertical scrollbar will scroll the
entire view, instead of just the top view). I'll fix this in the next commit.

[PATCH 6/7] Fix vertical scrolling

Vertical scrolling will only apply to the top view (budget values) and not
to the bottom view (budget totals).

Implementation: add an inner scrolled window for the vertical scrollbar.
Set scrolled_window vertical scrollbar policy to NEVER.

Note: This design looks weird when both scrollbars are used because you
have to scroll horizontally to the right in order to see the vertical
scrollbar for the top section.

[PATCH 7/7] Clean up code before submitting patch

* Remove debugging and commented out code

Modified: gnucash/trunk/src/gnome/gnc-budget-view.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-budget-view.c	2013-09-30 19:38:23 UTC (rev 23201)
+++ gnucash/trunk/src/gnome/gnc-budget-view.c	2013-10-01 12:22:00 UTC (rev 23202)
@@ -112,7 +112,6 @@
     GtkTreeSelection *selection, GncBudgetView *view);
 #endif
 static void gbv_treeview_resized_cb(GtkWidget* widget, GtkAllocation* allocation, GncBudgetView* view);
-static void gbv_column_resized_cb(GtkWidget* widget, GtkAllocation* allocation, GtkTreeViewColumn* col);
 static gnc_numeric gbv_get_accumulated_budget_amount(GncBudget* budget,
                                        Account* account, guint period_num);
 
@@ -317,8 +316,10 @@
     GtkTreeSelection *selection;
     GtkTreeView *tree_view;
     GtkWidget *scrolled_window;
+    GtkWidget *inner_scrolled_window;
     const gchar *budget_guid_str;
     GtkVBox* vbox;
+    GtkWidget* inner_vbox;
     GtkListStore* totals_tree_model;
     GtkTreeView* totals_tree_view;
     GtkTreeViewColumn* totals_title_col;
@@ -334,11 +335,21 @@
     scrolled_window = gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
                                    GTK_POLICY_AUTOMATIC,
-                                   GTK_POLICY_AUTOMATIC);
+                                   GTK_POLICY_NEVER);
     gtk_widget_show(scrolled_window);
     gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, /*expand*/TRUE, /*fill*/TRUE, 0);
 
+    inner_vbox = gtk_vbox_new(FALSE, 0);
+    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), GTK_WIDGET(inner_vbox));
+    gtk_widget_show(GTK_WIDGET(inner_vbox));
+
+    inner_scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(inner_scrolled_window),
+                                   GTK_POLICY_NEVER,
+                                   GTK_POLICY_AUTOMATIC);
+    gtk_widget_show(inner_scrolled_window);
     tree_view = gnc_tree_view_account_new(FALSE);
+    gtk_container_add(GTK_CONTAINER(inner_scrolled_window), GTK_WIDGET(tree_view));
 
     g_object_set(G_OBJECT(tree_view), "gconf-section", priv->gconf_section, NULL);
 
@@ -364,7 +375,7 @@
 #endif
     gtk_tree_view_set_headers_visible(tree_view, TRUE);
     gtk_widget_show(GTK_WIDGET(tree_view));
-    gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(tree_view));
+    gtk_box_pack_start(GTK_BOX(inner_vbox), GTK_WIDGET(inner_scrolled_window), /*expand*/TRUE, /*fill*/TRUE, 0);
     priv->fd->tree_view = GNC_TREE_VIEW_ACCOUNT(priv->tree_view);
     gnc_tree_view_account_set_filter(
         GNC_TREE_VIEW_ACCOUNT(tree_view),
@@ -391,13 +402,14 @@
     gtk_tree_view_set_model(totals_tree_view, GTK_TREE_MODEL(totals_tree_model));
 
     totals_title_col = gtk_tree_view_column_new_with_attributes("", gtk_cell_renderer_text_new(), "text", 0, NULL);
+    gtk_tree_view_column_set_expand(totals_title_col, TRUE);
     gtk_tree_view_append_column(totals_tree_view, totals_title_col);
 
-    gtk_box_pack_end(GTK_BOX(vbox), GTK_WIDGET(totals_tree_view), /*expand*/FALSE, /*fill*/TRUE, 0);
+    gtk_box_pack_end(GTK_BOX(inner_vbox), GTK_WIDGET(totals_tree_view), /*expand*/FALSE, /*fill*/TRUE, 0);
 
     h_separator = gtk_hseparator_new();
     gtk_widget_show(h_separator);
-    gtk_box_pack_end(GTK_BOX(vbox), h_separator, /*expand*/FALSE, /*fill*/TRUE, 0);
+    gtk_box_pack_end(GTK_BOX(inner_vbox), h_separator, /*expand*/FALSE, /*fill*/TRUE, 0);
 
     gnc_budget_view_refresh(view);
 }
@@ -555,52 +567,45 @@
 }
 
 static void
-gbv_column_resized_cb(GtkWidget* widget, GtkAllocation* allocation, GtkTreeViewColumn* col)
-{
-    guint period_num;
-
-    period_num = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(col),
-                                  "period_num"));
-    printf("Col %d: x=%d y=%d w=%d h=%d\n", period_num, allocation->x, allocation->y, allocation->width, allocation->height);
-}
-
-static void
 gbv_treeview_resized_cb(GtkWidget* widget, GtkAllocation* allocation, GncBudgetView* view)
 {
-    guint ncols;
+    gint ncols;
     GncBudgetViewPrivate* priv;
-    guint i;
+    gint i;
+    gint j;
+    GList *columns;
 
+    ENTER("");
     priv = GNC_BUDGET_VIEW_GET_PRIVATE(view);
 
-    /* Num cols is number of budget periods + 1 for name.  Ignore totals column.  We
-     * don't want to set the width of the last column so that the user can shrink the
-     * display. */
-    ncols = gnc_budget_get_num_periods(priv->budget) + 1;
-    for (i = 0; i < ncols; ++i)
+    /* There's no easy way to get this number. */
+    columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(priv->tree_view));
+    ncols = g_list_length(columns);
+    g_list_free(columns);
+    /* i is the column we are examining
+     * j is the corresponding column in totals_tree_view */
+    for (i = 0, j = 0; i < ncols; ++i)
     {
         gint col_width;
         GtkTreeViewColumn* tree_view_col;
         GtkTreeViewColumn* totals_view_col;
-        gint fixed_width;
-        gint min_width;
-        gint max_width;
 
-        /* Get the width. */
         tree_view_col = gtk_tree_view_get_column(priv->tree_view, i);
-        col_width = gtk_tree_view_column_get_width(tree_view_col);
-        fixed_width = gtk_tree_view_column_get_fixed_width(tree_view_col);
-        min_width = gtk_tree_view_column_get_min_width(tree_view_col);
-        max_width = gtk_tree_view_column_get_max_width(tree_view_col);
 
-        /* Set total view col's width the same. */
-        if (col_width != 0)
+        if (gtk_tree_view_column_get_visible(tree_view_col))
         {
-            totals_view_col = gtk_tree_view_get_column(priv->totals_tree_view, i);
-            gtk_tree_view_column_set_min_width(totals_view_col, col_width);
-            gtk_tree_view_column_set_max_width(totals_view_col, col_width);
+            col_width = gtk_tree_view_column_get_width(tree_view_col);
+            totals_view_col = gtk_tree_view_get_column(priv->totals_tree_view, j);
+            /* Don't set the width of the first column, which was set up
+             * in gbv_create_widget. It has a sizing of GROW_ONLY. */
+            if (gtk_tree_view_column_get_sizing(totals_view_col) == GTK_TREE_VIEW_COLUMN_FIXED)
+            {
+                gtk_tree_view_column_set_fixed_width(totals_view_col, col_width);
+            }
+            j++;
         }
     }
+    LEAVE("");
 }
 
 static void
@@ -974,12 +979,7 @@
     gtk_tree_view_column_set_cell_data_func(col, renderer, totals_col_source, view, NULL);
     g_object_set_data(G_OBJECT(col), "budget", priv->budget);
     g_object_set_data(G_OBJECT(col), "period_num", GUINT_TO_POINTER(period_num));
-    if (period_num >= 0)
-    {
-        gint col_width = 86;
-        gtk_tree_view_column_set_min_width(col, col_width);
-        gtk_tree_view_column_set_max_width(col, col_width);
-    }
+    gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
 
     return col;
 }
@@ -1044,8 +1044,6 @@
         g_object_set_data(G_OBJECT(col), "budget", priv->budget);
         g_object_set_data(G_OBJECT(col), "period_num",
                           GUINT_TO_POINTER(num_periods_visible));
-        g_signal_connect(G_OBJECT(col), "size-allocate",
-                     G_CALLBACK(gbv_column_resized_cb), col);
         col_list = g_list_append(col_list, col);
 
         renderer_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(col));
@@ -1059,6 +1057,7 @@
         col = gbv_create_totals_column(view, num_periods_visible);
         if (col != NULL)
         {
+            gtk_tree_view_append_column(priv->totals_tree_view, col);
             totals_col_list = g_list_append(totals_col_list, col);
         }
 
@@ -1075,6 +1074,10 @@
         g_object_set_data(G_OBJECT(priv->total_col), "budget", priv->budget);
 
         col = gbv_create_totals_column(view, -1);
+        if (col != NULL)
+        {
+           gtk_tree_view_append_column(priv->totals_tree_view, col);
+        }
     }
 
     gbv_refresh_col_titles(view);



More information about the gnucash-changes mailing list