gnucash unstable: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Tue Nov 21 12:47:28 EST 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/cdb764fe (commit)
	 via  https://github.com/Gnucash/gnucash/commit/169677a8 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/179d022d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1f4a2e36 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/54b492ee (commit)
	 via  https://github.com/Gnucash/gnucash/commit/45585219 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9c3247d5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9253b502 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ed3de42c (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6228881d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/98d8696b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/7a2c1492 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/45116183 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c5fb0d6d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/55002113 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0c443836 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/2a938425 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a278bcc0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0ba9b768 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/70ad2c3b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/bb16e07d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9f76441d (commit)
	from  https://github.com/Gnucash/gnucash/commit/d44f6bc9 (commit)



commit cdb764fec525642bbe85dd5a0a49ec967c55f089
Merge: 169677a ed3de42
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Nov 21 18:30:09 2017 +0100

    Merge branch 'gtk3-update8' of https://github.com/Bob-IT/gnucash into unstable
    
    More register layout tweaks


commit 169677a8d753ba26a447d22d2b2ec565bfe4798b
Merge: d44f6bc 179d022
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Nov 21 17:04:27 2017 +0100

    Merge branch 'gtk3-update9' of https://github.com/Bob-IT/gnucash into unstable
    
    This branch has several improvements in the dense calendar code. The most
    important of these is to fix a crash on Windows.


commit 179d022d1a74cd77c5a9e1dac156d0fb9b8ffa0f
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Nov 9 11:29:39 2017 +0000

    Prevent the rename popup from appearing in the dense calendar
    
    If you right mouse on the dense calendar, the treeview pops but also
    the rename page popup. So stop the cascade of the button press event
    when on the dense calendar.

diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index 17d1a53..8b57330 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -1311,7 +1311,7 @@ gnc_dense_cal_button_press(GtkWidget *widget,
         dcal->doc = -1;
         gtk_widget_hide(GTK_WIDGET(dcal->transPopup));
     }
-    return FALSE;
+    return TRUE;
 }
 
 static gint

commit 1f4a2e36db04638930f327c0a1783cd58ea2d32f
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Nov 9 11:28:09 2017 +0000

    Dense calendar popup window of screen at bottom
    
    The get_allocation function was in the wrong place for the button press

diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index d268c21..17d1a53 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -1292,12 +1292,12 @@ gnc_dense_cal_button_press(GtkWidget *widget,
         // trick with a bit of flicker.
         gtk_window_move(GTK_WINDOW(dcal->transPopup), evt->x_root + 5, evt->y_root + 5);
 
-        gtk_widget_get_allocation(GTK_WIDGET(dcal->transPopup), &alloc);
-
         populate_hover_window(dcal);
         gtk_widget_queue_resize(GTK_WIDGET(dcal->transPopup));
         gtk_widget_show_all(GTK_WIDGET(dcal->transPopup));
 
+        gtk_widget_get_allocation(GTK_WIDGET(dcal->transPopup), &alloc);
+
         if (evt->x_root + 5 + alloc.width > dcal->screen_width)
             win_xpos = evt->x_root - 2 - alloc.width;
 

commit 54b492ee83affd27896da099bca04994559ddc14
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Nov 9 10:48:59 2017 +0000

    Add a margin to the Date label

diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index 7a99058..d268c21 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -338,6 +338,11 @@ gnc_dense_cal_init(GncDenseCal *dcal)
         gtk_widget_set_name (GTK_WIDGET(dcal->transPopup), "dense-cal-popup");
 
         l = gtk_label_new(_("Date: "));
+#if GTK_CHECK_VERSION(3,12,0)
+        gtk_widget_set_margin_start (l, 5);
+#else
+        gtk_widget_set_margin_left (l, 5);
+#endif
         gtk_container_add(GTK_CONTAINER(hbox), l);
         l = gtk_label_new("YY/MM/DD");
         g_object_set_data(G_OBJECT(dcal->transPopup), "dateLabel", l);

commit 4558521980d7d241c68a9af189fe23feb0d96e7e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Nov 9 10:39:36 2017 +0000

    Don't re-populate dense calendar treeview on every mouse move
    
    The treeview only needs to be re-populated when the mouse moves to a
    different day so test for this.

diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index 9ee8c13..7a99058 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -131,7 +131,7 @@ static gint wheres_this(GncDenseCal *dcal, int x, int y);
 static void recompute_x_y_scales(GncDenseCal *dcal);
 static void recompute_mark_storage(GncDenseCal *dcal);
 static void recompute_extents(GncDenseCal *dcal);
-static void populate_hover_window(GncDenseCal *dcal, gint doc);
+static void populate_hover_window(GncDenseCal *dcal);
 
 static void month_coords(GncDenseCal *dcal, int monthOfCal, GList **outList);
 static void doc_coords(GncDenseCal *dcal, int dayOfCal,
@@ -1197,14 +1197,14 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
 }
 
 static void
-populate_hover_window(GncDenseCal *dcal, gint doc)
+populate_hover_window(GncDenseCal *dcal)
 {
     GtkWidget *w;
     GDate *date;
     static const int MAX_STRFTIME_BUF_LEN = 64;
     gchar strftimeBuf[MAX_STRFTIME_BUF_LEN];
 
-    if (doc >= 0)
+    if (dcal->doc >= 0)
     {
         GObject *o;
         GtkListStore *model;
@@ -1212,7 +1212,7 @@ populate_hover_window(GncDenseCal *dcal, gint doc)
 
         w = GTK_WIDGET(g_object_get_data(G_OBJECT(dcal->transPopup), "dateLabel"));
         date = g_date_new_dmy(1, dcal->month, dcal->year);
-        g_date_add_days(date, doc);
+        g_date_add_days(date, dcal->doc);
         /* Note: the ISO date format (%F or equivalently
          * %Y-%m-%d) is not a good idea here since many
          * locales will want to use a very different date
@@ -1224,7 +1224,7 @@ populate_hover_window(GncDenseCal *dcal, gint doc)
         o = G_OBJECT(dcal->transPopup);
         model = GTK_LIST_STORE(g_object_get_data(o, "model"));
         gtk_list_store_clear(model);
-        for (l = dcal->marks[doc]; l; l = l->next)
+        for (l = dcal->marks[dcal->doc]; l; l = l->next)
         {
             GtkTreeIter iter;
             gdc_mark_data *gdcmd;
@@ -1261,7 +1261,6 @@ gnc_dense_cal_button_press(GtkWidget *widget,
     GdkScreen *screen = gdk_screen_get_default ();
 #endif
     GtkAllocation alloc;
-    gint doc;
     GncDenseCal *dcal = GNC_DENSE_CAL(widget);
     gint win_xpos = evt->x_root + 5;
     gint win_ypos = evt->y_root + 5;
@@ -1276,9 +1275,9 @@ gnc_dense_cal_button_press(GtkWidget *widget,
     dcal->screen_height = gdk_screen_get_height (screen);
 #endif
 
-    doc = wheres_this(dcal, evt->x, evt->y);
+    dcal->doc = wheres_this(dcal, evt->x, evt->y);
     dcal->showPopup = ~(dcal->showPopup);
-    if (dcal->showPopup && doc >= 0)
+    if (dcal->showPopup && dcal->doc >= 0)
     {
         // Do the move twice in case the WM is ignoring the first one
         // because the window hasn't been shown, yet.  The WM is free
@@ -1290,7 +1289,7 @@ gnc_dense_cal_button_press(GtkWidget *widget,
 
         gtk_widget_get_allocation(GTK_WIDGET(dcal->transPopup), &alloc);
 
-        populate_hover_window(dcal, doc);
+        populate_hover_window(dcal);
         gtk_widget_queue_resize(GTK_WIDGET(dcal->transPopup));
         gtk_widget_show_all(GTK_WIDGET(dcal->transPopup));
 
@@ -1303,7 +1302,10 @@ gnc_dense_cal_button_press(GtkWidget *widget,
         gtk_window_move(GTK_WINDOW(dcal->transPopup), win_xpos, win_ypos);
     }
     else
+    {
+        dcal->doc = -1;
         gtk_widget_hide(GTK_WIDGET(dcal->transPopup));
+    }
     return FALSE;
 }
 
@@ -1340,10 +1342,15 @@ gnc_dense_cal_motion_notify(GtkWidget *widget,
     doc = wheres_this(dcal, event->x, event->y);
     if (doc >= 0)
     {
+        if (dcal->doc != doc) // if we are on the same day, no need to reload
+        {
+            dcal->doc = doc;
+            populate_hover_window(dcal);
+            gtk_widget_queue_resize(GTK_WIDGET(dcal->transPopup));
+            gtk_widget_show_all(GTK_WIDGET(dcal->transPopup));
+        }
         gtk_widget_get_allocation(GTK_WIDGET(dcal->transPopup), &alloc);
 
-        gtk_widget_show_all(GTK_WIDGET(dcal->transPopup));
-
         if (event->x_root + 5 + alloc.width > dcal->screen_width)
             win_xpos = event->x_root - 2 - alloc.width;
 
@@ -1353,7 +1360,10 @@ gnc_dense_cal_motion_notify(GtkWidget *widget,
         gtk_window_move(GTK_WINDOW(dcal->transPopup), win_xpos, win_ypos);
     }
     else
+    {
+        dcal->doc = -1;
         gtk_widget_hide(GTK_WIDGET(dcal->transPopup));
+    }
     return TRUE;
 }
 
diff --git a/gnucash/gnome-utils/gnc-dense-cal.h b/gnucash/gnome-utils/gnc-dense-cal.h
index 37ee05c..2a71fcf 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.h
+++ b/gnucash/gnome-utils/gnc-dense-cal.h
@@ -59,6 +59,7 @@ struct _GncDenseCal
     GtkWindow *transPopup;
     gint screen_width;
     gint screen_height;
+    gint doc;
 
     gint min_x_scale;
     gint min_y_scale;

commit 9c3247d5ccfbcab4e360fbb0dc967b7ab800a22e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Nov 9 10:32:10 2017 +0000

    Save the screen dimensions on button click
    
    Instead of getting the dimensions on every mouse move, just save them
    on button click and use the saved values.

diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index 22afcf0..9ee8c13 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -1256,26 +1256,24 @@ gnc_dense_cal_button_press(GtkWidget *widget,
 #if GTK_CHECK_VERSION(3,22,0)
     GdkWindow *win = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
     GdkMonitor *mon = gdk_display_get_monitor_at_window (gtk_widget_get_display (widget), win);
-    GdkRectangle monitor_size;
+    GdkRectangle work_area_size;
 #else
     GdkScreen *screen = gdk_screen_get_default ();
 #endif
     GtkAllocation alloc;
     gint doc;
-    gint screen_width;
-    gint screen_height;
     GncDenseCal *dcal = GNC_DENSE_CAL(widget);
     gint win_xpos = evt->x_root + 5;
     gint win_ypos = evt->y_root + 5;
 
 #if GTK_CHECK_VERSION(3,22,0)
-    gdk_monitor_get_geometry (mon, &monitor_size);
+    gdk_monitor_get_workarea (mon, &work_area_size);
 
-    screen_width = monitor_size.width;
-    screen_height = monitor_size.height;
+    dcal->screen_width = work_area_size.width;
+    dcal->screen_height = work_area_size.height;
 #else
-    screen_width = gdk_screen_get_width (screen);
-    screen_height = gdk_screen_get_height (screen);
+    dcal->screen_width = gdk_screen_get_width (screen);
+    dcal->screen_height = gdk_screen_get_height (screen);
 #endif
 
     doc = wheres_this(dcal, evt->x, evt->y);
@@ -1296,10 +1294,10 @@ gnc_dense_cal_button_press(GtkWidget *widget,
         gtk_widget_queue_resize(GTK_WIDGET(dcal->transPopup));
         gtk_widget_show_all(GTK_WIDGET(dcal->transPopup));
 
-        if (evt->x_root + 5 + alloc.width > screen_width)
+        if (evt->x_root + 5 + alloc.width > dcal->screen_width)
             win_xpos = evt->x_root - 2 - alloc.width;
 
-        if (evt->y_root + 5 + alloc.height > screen_height)
+        if (evt->y_root + 5 + alloc.height > dcal->screen_height)
             win_ypos = evt->y_root - 2 - alloc.height;
 
         gtk_window_move(GTK_WINDOW(dcal->transPopup), win_xpos, win_ypos);
@@ -1313,12 +1311,9 @@ static gint
 gnc_dense_cal_motion_notify(GtkWidget *widget,
                             GdkEventMotion *event)
 {
-    GdkScreen *screen = gdk_screen_get_default ();
     GncDenseCal *dcal;
     GtkAllocation alloc;
     gint doc;
-    gint screen_width;
-    gint screen_height;
     int unused;
     GdkModifierType unused2;
     gint win_xpos = event->x_root + 5;
@@ -1345,30 +1340,14 @@ gnc_dense_cal_motion_notify(GtkWidget *widget,
     doc = wheres_this(dcal, event->x, event->y);
     if (doc >= 0)
     {
-#if GTK_CHECK_VERSION(3,22,0)
-        GdkWindow *win = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
-        GdkMonitor *mon = gdk_display_get_monitor_at_window (gtk_widget_get_display (widget), win);
-        GdkRectangle monitor_size;
-
-        gdk_monitor_get_geometry (mon, &monitor_size);
-
-        screen_width = monitor_size.width;
-        screen_height = monitor_size.height;
-#else
-        screen_width = gdk_screen_get_width (screen);
-        screen_height = gdk_screen_get_height (screen);
-#endif
-        populate_hover_window(dcal, doc);
-        gtk_widget_queue_resize(GTK_WIDGET(dcal->transPopup));
-
         gtk_widget_get_allocation(GTK_WIDGET(dcal->transPopup), &alloc);
 
         gtk_widget_show_all(GTK_WIDGET(dcal->transPopup));
 
-        if (event->x_root + 5 + alloc.width > screen_width)
+        if (event->x_root + 5 + alloc.width > dcal->screen_width)
             win_xpos = event->x_root - 2 - alloc.width;
 
-        if (event->y_root + 5 + alloc.height > screen_height)
+        if (event->y_root + 5 + alloc.height > dcal->screen_height)
             win_ypos = event->y_root - 2 - alloc.height;
 
         gtk_window_move(GTK_WINDOW(dcal->transPopup), win_xpos, win_ypos);
diff --git a/gnucash/gnome-utils/gnc-dense-cal.h b/gnucash/gnome-utils/gnc-dense-cal.h
index 5bedd6e..37ee05c 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.h
+++ b/gnucash/gnome-utils/gnc-dense-cal.h
@@ -57,6 +57,8 @@ struct _GncDenseCal
 
     gboolean showPopup;
     GtkWindow *transPopup;
+    gint screen_width;
+    gint screen_height;
 
     gint min_x_scale;
     gint min_y_scale;

commit 9253b5021016bb2e964dc65c5228020e9ac2c77e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Nov 9 10:12:52 2017 +0000

    If there are no marked days on Windows the dense calendar crashes
    
    If there are no marked days in the dense calendar add a blank one. Also
    make sure all pending events are processed be fore returning as the
    treeview did not always populate correctly.

diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index 90355a4..22afcf0 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -1234,6 +1234,17 @@ populate_hover_window(GncDenseCal *dcal, gint doc)
             gtk_list_store_set(model, &iter, 0, (gdcmd->name ? gdcmd->name : _("(unnamed)")), 1, gdcmd->info, -1);
         }
 
+        // if there are no rows, add one
+        if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL(model), NULL) == 0)
+        {
+            GtkTreeIter iter;
+            gtk_list_store_insert(model, &iter, -1);
+        }
+
+        // make sure all pending events are processed
+        while(gtk_events_pending())
+            gtk_main_iteration();
+
         g_date_free(date);
     }
 }

commit ed3de42c96d4cc0032eb624dc356de05acaa93d0
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:30:03 2017 +0000

    Update the register for the change in RegisterColor enums
    
    Change the map of RegisterColors to CSS style classes to reflect the
    changes and reduce the get colour type to one call per class

diff --git a/gnucash/register/register-gnome/gnucash-header.c b/gnucash/register/register-gnome/gnucash-header.c
index f279971..156ae68 100644
--- a/gnucash/register/register-gnome/gnucash-header.c
+++ b/gnucash/register/register-gnome/gnucash-header.c
@@ -88,8 +88,8 @@ gnc_header_draw_offscreen (GncHeader *header)
 
     gtk_style_context_save (stylectxt);
 
-    // Get the background color type and apply the css class
-    color_type = gnc_table_get_bg_color (table, virt_loc, NULL);
+    // Get the color type and apply the css class
+    color_type = gnc_table_get_color (table, virt_loc, NULL);
     gnucash_get_style_classes (header->sheet, stylectxt, color_type);
 
     if (header->surface)
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c
index acbc323..39641d1 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.c
+++ b/gnucash/register/register-gnome/gnucash-item-edit.c
@@ -487,11 +487,8 @@ draw_background_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data)
 
     gtk_style_context_save (stylectxt);
 
-    // Get the background and foreground color types and apply the css class
-    color_type = gnc_table_get_bg_color (item_edit->sheet->table, item_edit->virt_loc, NULL);
-    gnucash_get_style_classes (item_edit->sheet, stylectxt, color_type);
-
-    color_type = gnc_table_get_fg_color (item_edit->sheet->table, item_edit->virt_loc);
+    // Get the color type and apply the css class
+    color_type = gnc_table_get_color (item_edit->sheet->table, item_edit->virt_loc, NULL);
     gnucash_get_style_classes (item_edit->sheet, stylectxt, color_type);
 
     gtk_render_background (stylectxt, cr, 0, 1, width, height - 2);
diff --git a/gnucash/register/register-gnome/gnucash-sheet-private.c b/gnucash/register/register-gnome/gnucash-sheet-private.c
index 7631caa..e71db31 100644
--- a/gnucash/register/register-gnome/gnucash-sheet-private.c
+++ b/gnucash/register/register-gnome/gnucash-sheet-private.c
@@ -399,11 +399,8 @@ draw_cell (GnucashSheet *sheet,
 
     gtk_style_context_save (stylectxt);
 
-    // Get the background and foreground color types and apply the css class
-    color_type = gnc_table_get_bg_color (table, virt_loc, &hatching);
-    gnucash_get_style_classes (sheet, stylectxt, color_type);
-
-    color_type = gnc_table_get_fg_color (table, virt_loc);
+    // Get the color type and apply the css class
+    color_type = gnc_table_get_color (table, virt_loc, &hatching);
     gnucash_get_style_classes (sheet, stylectxt, color_type);
 
     // Are we in a read-only row? Then make the background color somewhat more grey.
diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index 5a66605..311ab1b 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -2428,52 +2428,46 @@ gnucash_sheet_table_load (GnucashSheet *sheet, gboolean do_scroll)
 
 /*************************************************************/
 
-/** Map a cell type to a css style class. */
+/** Map a cell color type to a css style class. */
 void
 gnucash_get_style_classes (GnucashSheet *sheet, GtkStyleContext *stylectxt,
                            RegisterColor field_type)
 {
     gchar *full_class, *style_class = NULL;
 
+    if (field_type >= COLOR_NEGATIVE) // Require a Negative fg color
+    {
+        gtk_style_context_add_class (stylectxt, "negative-numbers");
+        field_type -= COLOR_NEGATIVE;
+    }
+
     switch (field_type)
     {
     default:
-    case COLOR_UNKNOWN_BG:
-    case COLOR_UNKNOWN_FG:
+    case COLOR_UNDEFINED:
         gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_BACKGROUND);
         return;
 
-    case COLOR_NEGATIVE:
-        gtk_style_context_add_class (stylectxt, "negative-numbers");
-        return;
-
-    case COLOR_HEADER_BG:
-    case COLOR_HEADER_FG:
+    case COLOR_HEADER:
         style_class = "header";
         break;
 
-    case COLOR_PRIMARY_BG:
-    case COLOR_PRIMARY_FG:
+    case COLOR_PRIMARY:
         style_class = "primary";
         break;
 
-    case COLOR_PRIMARY_BG_ACTIVE:
-    case COLOR_PRIMARY_FG_ACTIVE:
-    case COLOR_SECONDARY_BG_ACTIVE:
-    case COLOR_SECONDARY_FG_ACTIVE:
-    case COLOR_SPLIT_BG_ACTIVE:
-    case COLOR_SPLIT_FG_ACTIVE:
+    case COLOR_PRIMARY_ACTIVE:
+    case COLOR_SECONDARY_ACTIVE:
+    case COLOR_SPLIT_ACTIVE:
         gtk_style_context_set_state (stylectxt, GTK_STATE_FLAG_SELECTED);
         style_class = "cursor";
         break;
 
-    case COLOR_SECONDARY_BG:
-    case COLOR_SECONDARY_FG:
+    case COLOR_SECONDARY:
         style_class = "secondary";
         break;
 
-    case COLOR_SPLIT_BG:
-    case COLOR_SPLIT_FG:
+    case COLOR_SPLIT:
         style_class = "split";
         break;
     }

commit 6228881d6a23753ada928eb27fdd2a43963a3fbc
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:25:55 2017 +0000

    Change the split and entry models to reflect the colour changes

diff --git a/gnucash/register/ledger-core/gncEntryLedgerModel.c b/gnucash/register/ledger-core/gncEntryLedgerModel.c
index 8c5207d..a638d06 100644
--- a/gnucash/register/ledger-core/gncEntryLedgerModel.c
+++ b/gnucash/register/ledger-core/gncEntryLedgerModel.c
@@ -915,65 +915,57 @@ static CellIOFlags get_qty_io_flags (VirtualLocation virt_loc, gpointer user_dat
     return flags;
 }
 
-/* GET BG_COLORS */
+/* GET COLORS */
 
 static guint32
-gnc_entry_ledger_get_color_internal (VirtualLocation virt_loc,
-                                     GncEntryLedger *ledger,
-                                     gboolean foreground)
+gnc_entry_ledger_get_cell_color_internal (VirtualLocation virt_loc,
+                                          GncEntryLedger *ledger)
 {
     VirtualCell *vcell;
     gboolean is_current;
-    guint32 colorbase = 0; /* By default return background colors */
+    guint32 colorbase = 0;
 
-    if (foreground)
-        colorbase = COLOR_UNKNOWN_FG; /* a bit of enum arithmetic */
+    /* a bit of enum arithmetic */
+
+    // There are negative numbers
 
     if (!ledger)
-        return (colorbase + COLOR_UNKNOWN_BG);
+        return (colorbase + COLOR_UNDEFINED);
 
     if (gnc_table_virtual_location_in_header (ledger->table, virt_loc))
-        return (colorbase + COLOR_HEADER_BG);
+        return (colorbase + COLOR_HEADER);
 
     vcell = gnc_table_get_virtual_cell (ledger->table, virt_loc.vcell_loc);
     if (!vcell || !vcell->cellblock)
-        return (colorbase + COLOR_UNKNOWN_BG);
+        return (colorbase + COLOR_UNDEFINED);
 
     if ((virt_loc.phys_col_offset < vcell->cellblock->start_col) ||
             (virt_loc.phys_col_offset > vcell->cellblock->stop_col))
-        return (colorbase + COLOR_UNKNOWN_BG);
+        return (colorbase + COLOR_UNDEFINED);
 
     is_current = virt_cell_loc_equal (ledger->table->current_cursor_loc.vcell_loc,
                                       virt_loc.vcell_loc);
 
     if (is_current)
         return vcell->start_primary_color ?
-                (colorbase + COLOR_PRIMARY_BG_ACTIVE) :
-                (colorbase + COLOR_SECONDARY_BG_ACTIVE);
+                (colorbase + COLOR_PRIMARY_ACTIVE) :
+                (colorbase + COLOR_SECONDARY_ACTIVE);
 
     return vcell->start_primary_color ?
-            (colorbase + COLOR_PRIMARY_BG) : (colorbase + COLOR_SECONDARY_BG);
+            (colorbase + COLOR_PRIMARY) : (colorbase + COLOR_SECONDARY);
 
 }
 
 static guint32
-gnc_entry_ledger_get_fg_color (VirtualLocation virt_loc,
-                               gpointer user_data)
-{
-    GncEntryLedger *ledger = user_data;
-    return gnc_entry_ledger_get_color_internal (virt_loc, ledger, TRUE);
-}
-
-static guint32
-gnc_entry_ledger_get_bg_color (VirtualLocation virt_loc,
-                               gboolean *hatching, gpointer user_data)
+gnc_entry_ledger_get_cell_color (VirtualLocation virt_loc,
+                                 gboolean *hatching, gpointer user_data)
 {
     GncEntryLedger *ledger = user_data;
 
     if (hatching)
         *hatching = FALSE;
 
-    return gnc_entry_ledger_get_color_internal (virt_loc, ledger, FALSE);
+    return gnc_entry_ledger_get_cell_color_internal (virt_loc, ledger);
 }
 
 /* SAVE CELLS */
@@ -1225,11 +1217,8 @@ static void gnc_entry_ledger_model_new_handlers (TableModel *model,
     };
     unsigned int i;
 
-    gnc_table_model_set_default_fg_color_handler
-    (model, gnc_entry_ledger_get_fg_color);
-
-    gnc_table_model_set_default_bg_color_handler
-    (model, gnc_entry_ledger_get_bg_color);
+    // Set the cell color handler
+    gnc_table_model_set_default_cell_color_handler (model, gnc_entry_ledger_get_cell_color);
 
     for (i = 0; i < (sizeof(models) / sizeof(*models)); i++)
     {
diff --git a/gnucash/register/ledger-core/split-register-model.c b/gnucash/register/ledger-core/split-register-model.c
index 3a2fac4..f8b6614 100644
--- a/gnucash/register/ledger-core/split-register-model.c
+++ b/gnucash/register/ledger-core/split-register-model.c
@@ -514,33 +514,85 @@ get_trans_total_balance (SplitRegister *reg, Transaction *trans)
     return xaccTransGetAccountBalance(trans, account);
 }
 
+static gboolean
+gnc_split_register_use_negative_color (VirtualLocation virt_loc,
+                                       SplitRegister *reg)
+{
+    const char * cell_name;
+    gnc_numeric value;
+    Split *split;
+
+    if (!use_red_for_negative)
+        return FALSE;
+
+    split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
+    if (!split)
+        return FALSE;
+
+    cell_name = gnc_table_get_cell_name (reg->table, virt_loc);
+
+    if (gnc_cell_name_equal (cell_name, TSHRS_CELL))
+        value = get_trans_total_amount (reg, xaccSplitGetParent (split));
+    else if (gnc_cell_name_equal (cell_name, SHRS_CELL))
+    {
+        if (virt_cell_loc_equal (reg->table->current_cursor_loc.vcell_loc,
+                                      virt_loc.vcell_loc))
+            value = gnc_price_cell_get_value
+                     ((PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
+                             SHRS_CELL));
+        else
+            value = xaccSplitGetAmount (split);
+    }
+    else if (gnc_cell_name_equal (cell_name, BALN_CELL))
+        value = xaccSplitGetBalance (split);
+    else if (gnc_cell_name_equal (cell_name, RBALN_CELL))
+        value = gnc_split_register_get_rbaln (virt_loc, reg, TRUE);
+    else if (gnc_cell_name_equal (cell_name, TBALN_CELL))
+        value = get_trans_total_balance (reg, xaccSplitGetParent (split));
+
+    if ((gnc_cell_name_equal (cell_name, BALN_CELL)) ||
+            (gnc_cell_name_equal (cell_name, RBALN_CELL)) ||
+            (gnc_cell_name_equal (cell_name, TBALN_CELL)))
+        {
+            Account *account = xaccSplitGetAccount (split);
+            if (gnc_reverse_balance (account))
+                value = gnc_numeric_neg (value);
+        }
+
+    if (gnc_numeric_negative_p (value))
+        return TRUE;
+
+    return FALSE;
+}
+
 static guint32
-gnc_split_register_get_color_internal (VirtualLocation virt_loc,
-                                       SplitRegister *reg,
-                                       gboolean foreground)
+gnc_split_register_get_cell_color_internal (VirtualLocation virt_loc,
+                                            SplitRegister *reg)
 {
     const char *cursor_name;
     VirtualCell *vcell;
     gboolean is_current;
     gboolean double_alternate_virt;
-    guint32 colorbase = 0; /* By default return background colors */
+    guint32 colorbase = 0;
 
-    if (foreground)
-        colorbase = COLOR_UNKNOWN_FG; /* a bit of enum arithmetic */
+     /* a bit of enum arithmetic */
+
+    if (gnc_split_register_use_negative_color (virt_loc, reg))
+        colorbase = COLOR_NEGATIVE; // Requires Negative fg color
 
     if (!reg)
-        return (colorbase + COLOR_UNKNOWN_BG);
+        return (colorbase + COLOR_UNDEFINED);
 
     if (gnc_table_virtual_location_in_header (reg->table, virt_loc))
-        return (colorbase + COLOR_HEADER_BG);
+        return (colorbase + COLOR_HEADER);
 
     vcell = gnc_table_get_virtual_cell (reg->table, virt_loc.vcell_loc);
     if (!vcell || !vcell->cellblock)
-        return (colorbase + COLOR_UNKNOWN_BG);
+        return (colorbase + COLOR_UNDEFINED);
 
     if ((virt_loc.phys_col_offset < vcell->cellblock->start_col) ||
             (virt_loc.phys_col_offset > vcell->cellblock->stop_col))
-        return (colorbase + COLOR_UNKNOWN_BG);
+        return (colorbase + COLOR_UNDEFINED);
 
     is_current = virt_cell_loc_equal (reg->table->current_cursor_loc.vcell_loc,
                                       virt_loc.vcell_loc);
@@ -552,11 +604,11 @@ gnc_split_register_get_color_internal (VirtualLocation virt_loc,
     {
         if (is_current)
             return vcell->start_primary_color ?
-                    (colorbase + COLOR_PRIMARY_BG_ACTIVE) :
-                    (colorbase + COLOR_SECONDARY_BG_ACTIVE);
+                    (colorbase + COLOR_PRIMARY_ACTIVE) :
+                    (colorbase + COLOR_SECONDARY_ACTIVE);
 
         return vcell->start_primary_color ?
-                (colorbase + COLOR_PRIMARY_BG) : (colorbase + COLOR_SECONDARY_BG);
+                (colorbase + COLOR_PRIMARY) : (colorbase + COLOR_SECONDARY);
     }
 
     if (g_strcmp0 (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0 ||
@@ -570,101 +622,40 @@ gnc_split_register_get_color_internal (VirtualLocation virt_loc,
         {
             if (double_alternate_virt)
                 return vcell->start_primary_color ?
-                        (colorbase + COLOR_PRIMARY_BG_ACTIVE) :
-                        (colorbase + COLOR_SECONDARY_BG_ACTIVE);
+                        (colorbase + COLOR_PRIMARY_ACTIVE) :
+                        (colorbase + COLOR_SECONDARY_ACTIVE);
 
             return (virt_loc.phys_row_offset % 2 == 0) ?
-                    (colorbase + COLOR_PRIMARY_BG_ACTIVE) :
-                    (colorbase + COLOR_SECONDARY_BG_ACTIVE);
+                    (colorbase + COLOR_PRIMARY_ACTIVE) :
+                    (colorbase + COLOR_SECONDARY_ACTIVE);
         }
 
         if (double_alternate_virt)
             return vcell->start_primary_color ?
-                    (colorbase + COLOR_PRIMARY_BG) :
-                    (colorbase + COLOR_SECONDARY_BG);
+                    (colorbase + COLOR_PRIMARY) :
+                    (colorbase + COLOR_SECONDARY);
 
         return (virt_loc.phys_row_offset % 2 == 0) ?
-                (colorbase + COLOR_PRIMARY_BG) :
-                (colorbase + COLOR_SECONDARY_BG);
+                (colorbase + COLOR_PRIMARY) :
+                (colorbase + COLOR_SECONDARY);
     }
 
     if (g_strcmp0 (cursor_name, CURSOR_SPLIT) == 0)
     {
         if (is_current)
-            return (colorbase + COLOR_SPLIT_BG_ACTIVE);
+            return (colorbase + COLOR_SPLIT_ACTIVE);
 
-        return (colorbase + COLOR_SPLIT_BG);
+        return (colorbase + COLOR_SPLIT);
     }
 
     PWARN ("Unexpected cursor: %s\n", cursor_name);
 
-    return (colorbase + COLOR_UNKNOWN_BG);
+    return (colorbase + COLOR_UNDEFINED);
 }
 
+// Get Color for non numeric cells, no hatching required
 static guint32
-gnc_split_register_get_fg_color_internal (VirtualLocation virt_loc,
-                                          SplitRegister *reg)
-{
-    guint32 fg_color;
-    const char * cell_name;
-    gnc_numeric value;
-    Split *split;
-
-    fg_color = gnc_split_register_get_color_internal (virt_loc, reg, TRUE);
-
-    if (!use_red_for_negative)
-        return fg_color;
-
-    split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
-    if (!split)
-        return fg_color;
-
-    cell_name = gnc_table_get_cell_name (reg->table, virt_loc);
-
-    if (gnc_cell_name_equal (cell_name, TSHRS_CELL))
-        value = get_trans_total_amount (reg, xaccSplitGetParent (split));
-    else if (gnc_cell_name_equal (cell_name, SHRS_CELL))
-    {
-        if (virt_cell_loc_equal (reg->table->current_cursor_loc.vcell_loc,
-                                      virt_loc.vcell_loc))
-            value = gnc_price_cell_get_value
-                     ((PriceCell *) gnc_table_layout_get_cell (reg->table->layout,
-                             SHRS_CELL));
-        else
-            value = xaccSplitGetAmount (split);
-    }
-    else if (gnc_cell_name_equal (cell_name, BALN_CELL))
-        value = xaccSplitGetBalance (split);
-    else if (gnc_cell_name_equal (cell_name, RBALN_CELL))
-        value = gnc_split_register_get_rbaln (virt_loc, reg, TRUE);
-    else if (gnc_cell_name_equal (cell_name, TBALN_CELL))
-        value = get_trans_total_balance (reg, xaccSplitGetParent (split));
-
-    if ((gnc_cell_name_equal (cell_name, BALN_CELL)) ||
-            (gnc_cell_name_equal (cell_name, RBALN_CELL)) ||
-            (gnc_cell_name_equal (cell_name, TBALN_CELL)))
-        {
-            Account *account = xaccSplitGetAccount (split);
-            if (gnc_reverse_balance (account))
-                value = gnc_numeric_neg (value);
-        }
-
-    if (gnc_numeric_negative_p (value))
-        return COLOR_NEGATIVE;
-
-    return fg_color;
-}
-
-static guint32
-gnc_split_register_get_fg_color (VirtualLocation virt_loc,
-                                 gpointer user_data)
-{
-    SplitRegister *reg = user_data;
-    return gnc_split_register_get_fg_color_internal (virt_loc, reg);
-}
-
-static guint32
-gnc_split_register_get_bg_color (VirtualLocation virt_loc,
+gnc_split_register_get_cell_color (VirtualLocation virt_loc,
         gboolean *hatching,
         gpointer user_data)
 {
@@ -673,11 +664,12 @@ gnc_split_register_get_bg_color (VirtualLocation virt_loc,
     if (hatching)
         *hatching = FALSE;
 
-    return gnc_split_register_get_color_internal (virt_loc, reg, FALSE);
+    return gnc_split_register_get_cell_color_internal (virt_loc, reg);
 }
 
+// Get Color for numeric cells, update hatching
 static guint32
-gnc_split_register_get_debcred_bg_color (VirtualLocation virt_loc,
+gnc_split_register_get_debcred_color (VirtualLocation virt_loc,
         gboolean *hatching,
         gpointer user_data)
 {
@@ -694,8 +686,7 @@ gnc_split_register_get_debcred_bg_color (VirtualLocation virt_loc,
         else
             *hatching = FALSE;
     }
-
-    return gnc_split_register_get_bg_color (virt_loc, NULL, user_data);
+    return gnc_split_register_get_cell_color_internal (virt_loc, reg);
 }
 
 static void
@@ -2623,42 +2614,26 @@ gnc_split_register_model_new (void)
         model, gnc_split_register_get_security_io_flags, SHRS_CELL);
 
 
-    gnc_table_model_set_fg_color_handler(
-        model, gnc_split_register_get_fg_color, SHRS_CELL);
-
-    gnc_table_model_set_fg_color_handler(
-        model, gnc_split_register_get_fg_color, TSHRS_CELL);
-
-    gnc_table_model_set_fg_color_handler(
-        model, gnc_split_register_get_fg_color, BALN_CELL);
-
-    gnc_table_model_set_fg_color_handler(
-        model, gnc_split_register_get_fg_color, TBALN_CELL);
-
-    gnc_table_model_set_fg_color_handler(
-        model, gnc_split_register_get_fg_color, RBALN_CELL);
-
-
-    gnc_table_model_set_default_bg_color_handler(
-        model, gnc_split_register_get_bg_color);
+    gnc_table_model_set_default_cell_color_handler(
+        model, gnc_split_register_get_cell_color);
 
-    gnc_table_model_set_bg_color_handler(
-        model, gnc_split_register_get_debcred_bg_color, DEBT_CELL);
+    gnc_table_model_set_cell_color_handler(
+        model, gnc_split_register_get_debcred_color, DEBT_CELL);
 
-    gnc_table_model_set_bg_color_handler(
-        model, gnc_split_register_get_debcred_bg_color, CRED_CELL);
+    gnc_table_model_set_cell_color_handler(
+        model, gnc_split_register_get_debcred_color, CRED_CELL);
 
-    gnc_table_model_set_bg_color_handler(
-        model, gnc_split_register_get_debcred_bg_color, TDEBT_CELL);
+    gnc_table_model_set_cell_color_handler(
+        model, gnc_split_register_get_debcred_color, TDEBT_CELL);
 
-    gnc_table_model_set_bg_color_handler(
-        model, gnc_split_register_get_debcred_bg_color, TCRED_CELL);
+    gnc_table_model_set_cell_color_handler(
+        model, gnc_split_register_get_debcred_color, TCRED_CELL);
 
-    gnc_table_model_set_bg_color_handler(
-        model, gnc_split_register_get_debcred_bg_color, FCRED_CELL);
+    gnc_table_model_set_cell_color_handler(
+        model, gnc_split_register_get_debcred_color, FCRED_CELL);
 
-    gnc_table_model_set_bg_color_handler(
-        model, gnc_split_register_get_debcred_bg_color, FDEBT_CELL);
+    gnc_table_model_set_cell_color_handler(
+        model, gnc_split_register_get_debcred_color, FDEBT_CELL);
 
 
     gnc_table_model_set_default_cell_border_handler(

commit 98d8696b1a223c792dcd029149127c6a17d4e4c6
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:23:17 2017 +0000

    Reduce the RegisterColor enums so there is one for each type
    
    Combine the foreground and background colour enums so there are only
    eight and change the access function to gnc_table_get_color

diff --git a/gnucash/register/register-core/table-allgui.c b/gnucash/register/register-core/table-allgui.c
index 7e407db..038d3b0 100644
--- a/gnucash/register/register-core/table-allgui.c
+++ b/gnucash/register/register-core/table-allgui.c
@@ -345,68 +345,29 @@ gnc_table_get_label (Table *table, VirtualLocation virt_loc)
     return label;
 }
 
-static guint32
-gnc_table_get_fg_color_internal (Table *table, VirtualLocation virt_loc)
-{
-    TableGetFGColorHandler fg_color_handler;
-    const char *handler_name;
-
-    if (!table || !table->model)
-        return COLOR_UNKNOWN_FG;
-
-    handler_name = gnc_table_get_cell_name (table, virt_loc);
-
-    fg_color_handler = gnc_table_model_get_fg_color_handler (table->model,
-                       handler_name);
-    if (!fg_color_handler)
-    {
-        TableGetBGColorHandler bg_color_handler =
-            gnc_table_model_get_bg_color_handler (table->model, handler_name);
-
-        guint32 bg_color =
-            bg_color_handler (virt_loc, NULL, table->model->handler_user_data);
-        return bg_color + COLOR_UNKNOWN_FG;
-    }
-
-    return fg_color_handler (virt_loc, table->model->handler_user_data);
-}
-
 guint32
-gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc)
-{
-    return gnc_table_get_fg_color_internal (table, virt_loc);
-}
-
-static guint32
-gnc_table_get_bg_color_internal (Table *table, VirtualLocation virt_loc,
+gnc_table_get_color (Table *table, VirtualLocation virt_loc,
                                  gboolean *hatching)
 {
-    TableGetBGColorHandler bg_color_handler;
+    TableGetCellColorHandler color_handler;
     const char *handler_name;
 
     if (hatching)
         *hatching = FALSE;
 
     if (!table || !table->model)
-        return COLOR_UNKNOWN_BG;
+        return COLOR_UNDEFINED;
 
     handler_name = gnc_table_get_cell_name (table, virt_loc);
 
-    bg_color_handler = gnc_table_model_get_bg_color_handler (table->model,
-            handler_name);
-
-    if (!bg_color_handler)
-        return COLOR_UNKNOWN_BG;
+    color_handler = gnc_table_model_get_cell_color_handler (table->model,
+                                                            handler_name);
 
-    return bg_color_handler (virt_loc, hatching,
-                             table->model->handler_user_data);
-}
+    if (!color_handler)
+        return COLOR_UNDEFINED;
 
-guint32
-gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc,
-                        gboolean *hatching)
-{
-    return gnc_table_get_bg_color_internal (table, virt_loc, hatching);
+    return color_handler (virt_loc, hatching,
+                          table->model->handler_user_data);
 }
 
 void
diff --git a/gnucash/register/register-core/table-allgui.h b/gnucash/register/register-core/table-allgui.h
index d827fd5..3b4fa26 100644
--- a/gnucash/register/register-core/table-allgui.h
+++ b/gnucash/register/register-core/table-allgui.h
@@ -179,35 +179,19 @@ struct table
 };
 
 /** Color definitions used for table elements */
-typedef enum
-{
-    /* Colors used for background drawing */
-    COLOR_UNKNOWN_BG,          // 0
-    COLOR_HEADER_BG,           // 1
-    COLOR_PRIMARY_BG,          // 2
-    COLOR_PRIMARY_BG_ACTIVE,   // 3
-    COLOR_SECONDARY_BG,        // 4
-    COLOR_SECONDARY_BG_ACTIVE, // 5
-    COLOR_SPLIT_BG,            // 6
-    COLOR_SPLIT_BG_ACTIVE,     // 7
-
-    /* Colors used for foreground drawing (text etc)
-     * ATTENTION: the background and foreground lists should have
-     *            the same types (the same amount of entries) !
-     *            The code relies on this ! */
-    COLOR_UNKNOWN_FG,          // 8
-    COLOR_HEADER_FG,           // 9
-    COLOR_PRIMARY_FG,          // 10
-    COLOR_PRIMARY_FG_ACTIVE,   // 11
-    COLOR_SECONDARY_FG,        // 12
-    COLOR_SECONDARY_FG_ACTIVE, // 13
-    COLOR_SPLIT_FG,            // 14
-    COLOR_SPLIT_FG_ACTIVE,     // 15
-
-    /* Other colors */
-    COLOR_NEGATIVE,            // 16 Color to use for negative numbers
+typedef enum {
+    COLOR_UNDEFINED = 0,      // 0
+    COLOR_HEADER,             // 1
+    COLOR_PRIMARY,            // 2
+    COLOR_PRIMARY_ACTIVE,     // 3
+    COLOR_SECONDARY,          // 4
+    COLOR_SECONDARY_ACTIVE,   // 5
+    COLOR_SPLIT,              // 6
+    COLOR_SPLIT_ACTIVE,       // 7
+    COLOR_NEGATIVE = 16,      // 16
 } RegisterColor;
 
+
 /** Set the default gui handlers used by new tables. */
 void gnc_table_set_default_gui_handlers (TableGUIHandlers *gui_handlers);
 
@@ -258,9 +242,7 @@ const char *   gnc_table_get_label (Table *table, VirtualLocation virt_loc);
 
 CellIOFlags    gnc_table_get_io_flags (Table *table, VirtualLocation virt_loc);
 
-guint32        gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc);
-
-guint32        gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc,
+guint32        gnc_table_get_color (Table *table, VirtualLocation virt_loc,
                                        gboolean *hatching);
 
 void           gnc_table_get_borders (Table *table, VirtualLocation virt_loc,

commit 7a2c1492fd05691db88c7fb0cb10572cf0b786d1
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:20:35 2017 +0000

    Replace the cell foreground and background colour handlers
    
    By using CSS classes, there is no need to have separate handlers for
    the foreground and background colours so replace them with one being of
    a similar format to that of cell_border_handlers.

diff --git a/gnucash/register/register-core/table-model.c b/gnucash/register/register-core/table-model.c
index c76310e..a5baee2 100644
--- a/gnucash/register/register-core/table-model.c
+++ b/gnucash/register/register-core/table-model.c
@@ -134,8 +134,7 @@ gnc_table_model_new (void)
     model->label_handlers = gnc_table_model_handler_hash_new ();
     model->help_handlers = gnc_table_model_handler_hash_new ();
     model->io_flags_handlers = gnc_table_model_handler_hash_new ();
-    model->fg_color_handlers = gnc_table_model_handler_hash_new ();
-    model->bg_color_handlers = gnc_table_model_handler_hash_new ();
+    model->cell_color_handlers = gnc_table_model_handler_hash_new ();
     model->cell_border_handlers = gnc_table_model_handler_hash_new ();
     model->confirm_handlers = gnc_table_model_handler_hash_new ();
     model->save_handlers = gnc_table_model_handler_hash_new ();
@@ -165,11 +164,8 @@ gnc_table_model_destroy (TableModel *model)
     gnc_table_model_handler_hash_destroy (model->io_flags_handlers);
     model->io_flags_handlers = NULL;
 
-    gnc_table_model_handler_hash_destroy (model->fg_color_handlers);
-    model->fg_color_handlers = NULL;
-
-    gnc_table_model_handler_hash_destroy (model->bg_color_handlers);
-    model->bg_color_handlers = NULL;
+    gnc_table_model_handler_hash_destroy (model->cell_color_handlers);
+    model->cell_color_handlers = NULL;
 
     gnc_table_model_handler_hash_destroy (model->cell_border_handlers);
     model->cell_border_handlers = NULL;
@@ -334,75 +330,39 @@ gnc_table_model_get_io_flags_handler (TableModel *model,
 }
 
 void
-gnc_table_model_set_fg_color_handler
+gnc_table_model_set_cell_color_handler
 (TableModel *model,
- TableGetFGColorHandler fg_color_handler,
+ TableGetCellColorHandler color_handler,
  const char * cell_name)
 {
     g_return_if_fail (model != NULL);
     g_return_if_fail (cell_name != NULL);
 
-    gnc_table_model_handler_hash_insert (model->fg_color_handlers,
+    gnc_table_model_handler_hash_insert (model->cell_color_handlers,
                                          cell_name,
-                                         fg_color_handler);
+                                         color_handler);
 }
 
 void
-gnc_table_model_set_default_fg_color_handler
+gnc_table_model_set_default_cell_color_handler
 (TableModel *model,
- TableGetFGColorHandler fg_color_handler)
+ TableGetCellColorHandler color_handler)
 {
     g_return_if_fail (model != NULL);
 
-    gnc_table_model_handler_hash_insert (model->fg_color_handlers,
+    gnc_table_model_handler_hash_insert (model->cell_color_handlers,
                                          DEFAULT_HANDLER,
-                                         fg_color_handler);
-}
-
-TableGetFGColorHandler
-gnc_table_model_get_fg_color_handler (TableModel *model,
-                                      const char * cell_name)
-{
-    g_return_val_if_fail (model != NULL, NULL);
-
-    return gnc_table_model_handler_hash_lookup (model->fg_color_handlers,
-            cell_name);
+                                         color_handler);
 }
 
-void
-gnc_table_model_set_bg_color_handler
-(TableModel *model,
- TableGetBGColorHandler bg_color_handler,
- const char * cell_name)
-{
-    g_return_if_fail (model != NULL);
-    g_return_if_fail (cell_name != NULL);
-
-    gnc_table_model_handler_hash_insert (model->bg_color_handlers,
-                                         cell_name,
-                                         bg_color_handler);
-}
-
-void
-gnc_table_model_set_default_bg_color_handler
-(TableModel *model,
- TableGetBGColorHandler bg_color_handler)
-{
-    g_return_if_fail (model != NULL);
-
-    gnc_table_model_handler_hash_insert (model->bg_color_handlers,
-                                         DEFAULT_HANDLER,
-                                         bg_color_handler);
-}
-
-TableGetBGColorHandler
-gnc_table_model_get_bg_color_handler (TableModel *model,
-                                      const char * cell_name)
+TableGetCellColorHandler
+gnc_table_model_get_cell_color_handler (TableModel *model,
+                                   const char * cell_name)
 {
     g_return_val_if_fail (model != NULL, NULL);
 
-    return gnc_table_model_handler_hash_lookup (model->bg_color_handlers,
-            cell_name);
+    return gnc_table_model_handler_hash_lookup (model->cell_color_handlers,
+                                                cell_name);
 }
 
 void
diff --git a/gnucash/register/register-core/table-model.h b/gnucash/register/register-core/table-model.h
index 268757e..2d489a6 100644
--- a/gnucash/register/register-core/table-model.h
+++ b/gnucash/register/register-core/table-model.h
@@ -76,10 +76,7 @@ typedef char * (*TableGetHelpHandler) (VirtualLocation virt_loc,
 typedef CellIOFlags (*TableGetCellIOFlagsHandler) (VirtualLocation virt_loc,
         gpointer user_data);
 
-typedef guint32 (*TableGetFGColorHandler) (VirtualLocation virt_loc,
-        gpointer user_data);
-
-typedef guint32 (*TableGetBGColorHandler) (VirtualLocation virt_loc,
+typedef guint32 (*TableGetCellColorHandler) (VirtualLocation virt_loc,
         gboolean *hatching,
         gpointer user_data);
 
@@ -107,8 +104,7 @@ typedef struct
     GHashTable *label_handlers;
     GHashTable *help_handlers;
     GHashTable *io_flags_handlers;
-    GHashTable *fg_color_handlers;
-    GHashTable *bg_color_handlers;
+    GHashTable *cell_color_handlers;
     GHashTable *cell_border_handlers;
     GHashTable *confirm_handlers;
 
@@ -189,25 +185,14 @@ TableGetCellIOFlagsHandler gnc_table_model_get_io_flags_handler
 (TableModel *model,
  const char * cell_name);
 
-void gnc_table_model_set_fg_color_handler
-(TableModel *model,
- TableGetFGColorHandler io_flags_handler,
- const char * cell_name);
-void gnc_table_model_set_default_fg_color_handler
-(TableModel *model,
- TableGetFGColorHandler io_flags_handler);
-TableGetFGColorHandler gnc_table_model_get_fg_color_handler
-(TableModel *model,
- const char * cell_name);
-
-void gnc_table_model_set_bg_color_handler
+void gnc_table_model_set_cell_color_handler
 (TableModel *model,
- TableGetBGColorHandler io_flags_handler,
+ TableGetCellColorHandler io_flags_handler,
  const char * cell_name);
-void gnc_table_model_set_default_bg_color_handler
+ void gnc_table_model_set_default_cell_color_handler
 (TableModel *model,
- TableGetBGColorHandler io_flags_handler);
-TableGetBGColorHandler gnc_table_model_get_bg_color_handler
+ TableGetCellColorHandler io_flags_handler);
+TableGetCellColorHandler gnc_table_model_get_cell_color_handler
 (TableModel *model,
  const char * cell_name);
 

commit 451161837d7d6d51a4775298e4a9ea671fc4724f
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:17:19 2017 +0000

    Test the widget state to get the correct background colour.
    
    When the cell borders are not displayed, the border colour is set to
    the background colour so test for the widget being in an insensitive
    state to get the correct background colour.

diff --git a/gnucash/register/register-gnome/gnucash-sheet-private.c b/gnucash/register/register-gnome/gnucash-sheet-private.c
index 2abe7d7..7631caa 100644
--- a/gnucash/register/register-gnome/gnucash-sheet-private.c
+++ b/gnucash/register/register-gnome/gnucash-sheet-private.c
@@ -418,7 +418,10 @@ draw_cell (GnucashSheet *sheet,
     gtk_render_background (stylectxt, cr, x, y, width, height);
 
     gdk_rgba_parse (&color, "black");
-    gnc_style_context_get_background_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
+    if (gtk_style_context_get_state (stylectxt) == GTK_STATE_FLAG_INSENSITIVE)
+        gnc_style_context_get_background_color (stylectxt, GTK_STATE_FLAG_INSENSITIVE, &color);
+    else
+        gnc_style_context_get_background_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
     bg_color = &color;
 
     get_cell_borders (sheet, virt_loc, &borders);

commit c5fb0d6dce7731e040e5c6f8ae811b0a77c2f0cd
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:14:51 2017 +0000

    Change the look of the toggle button
    
    With these changes the button image is removed and you are left with
    the arrow and frame on the yellow background. This can be dropped or
    adjusted if it was deemed a good idea.

diff --git a/gnucash/gnucash-310.css b/gnucash/gnucash-310.css
index e6b218d..76b7232 100644
--- a/gnucash/gnucash-310.css
+++ b/gnucash/gnucash-310.css
@@ -27,7 +27,7 @@
   padding: 2px 2px 2px 2px; /* all work with different values, around the text blue area */
 }
 
-.cursor .button {
+.cursor .toggle-button {
   margin: 1px 1px 1px 1px; /* does not work, not used, here for completeness */
 }
 
diff --git a/gnucash/gnucash-320.css b/gnucash/gnucash-320.css
index 4f4ea09..51f197c 100644
--- a/gnucash/gnucash-320.css
+++ b/gnucash/gnucash-320.css
@@ -18,7 +18,7 @@ cursor entry {
   padding: 0px 2px 0px 2px;
 }
 
-cursor button {
+cursor toggle-button {
   margin: 1px 1px 1px 1px;
 }
 
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c
index 4162532..acbc323 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.c
+++ b/gnucash/register/register-gnome/gnucash-item-edit.c
@@ -138,7 +138,8 @@ gnc_item_edit_tb_class_init (GncItemEditTbClass *gnc_item_edit_tb_class)
     GtkWidgetClass *widget_class;
 
 #if GTK_CHECK_VERSION(3,20,0)
-    gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(gnc_item_edit_tb_class), "button");
+//    gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(gnc_item_edit_tb_class), "button");
+    gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(gnc_item_edit_tb_class), "toggle-button");
 #endif
 
     gnc_item_edit_tb_parent_class = g_type_class_peek_parent (gnc_item_edit_tb_class);
@@ -200,7 +201,8 @@ gnc_item_edit_tb_new (GnucashSheet *sheet)
                            NULL);
 
     // This sets a style class for when Gtk+ version is less than 3.20
-    gnc_widget_set_css_name (GTK_WIDGET(item_edit_tb), "button");
+//    gnc_widget_set_css_name (GTK_WIDGET(item_edit_tb), "button");
+    gnc_widget_set_css_name (GTK_WIDGET(item_edit_tb), "toggle-button");
 
     context = gtk_widget_get_style_context (GTK_WIDGET(item_edit_tb));
     gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
@@ -569,6 +571,9 @@ draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
 
     gtk_render_background (context, cr, 0, 0, width, height);
 
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
+    gtk_render_frame (context, cr, 1, 1, width - 2, height - 2);
+
     gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW);
 
     size = MIN(width / 2, height / 2);

commit 550021130522b2fb4117bc75879e9cdda7d3866f
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:12:01 2017 +0000

    Control the toggle button width
    
    There did not seem to be an easier way to control the toggle button
    width so created a custom one based on the GtkToggleButton. This
    allowed the use of the class function get_preferred_width which is set
    at two thirds the height.

diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c
index 813088f..4162532 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.c
+++ b/gnucash/register/register-gnome/gnucash-item-edit.c
@@ -58,6 +58,155 @@ enum
 
 static GtkBoxClass *gnc_item_edit_parent_class;
 
+static GtkToggleButtonClass *gnc_item_edit_tb_parent_class;
+
+static void
+gnc_item_edit_tb_init (GncItemEditTb *item_edit_tb)
+{
+    item_edit_tb->sheet = NULL;
+}
+
+static void
+gnc_item_edit_tb_get_property (GObject *object,
+                               guint param_id,
+                               GValue *value,
+                               GParamSpec *pspec)
+{
+    GncItemEditTb *item_edit_tb = GNC_ITEM_EDIT_TB (object);
+
+    switch (param_id)
+    {
+    case PROP_SHEET:
+        g_value_take_object (value, item_edit_tb->sheet);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_item_edit_tb_set_property (GObject *object,
+                               guint param_id,
+                               const GValue *value,
+                               GParamSpec *pspec)
+{
+    GncItemEditTb *item_edit_tb = GNC_ITEM_EDIT_TB (object);
+
+    switch (param_id)
+    {
+    case PROP_SHEET:
+        item_edit_tb->sheet = GNUCASH_SHEET (g_value_get_object (value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+        break;
+    }
+}
+
+static void
+gnc_item_edit_tb_get_preferred_width (GtkWidget *widget,
+                                   gint *minimal_width,
+                                   gint *natural_width)
+{
+    GncItemEditTb *tb = GNC_ITEM_EDIT_TB (widget);
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(tb->sheet->item_editor);
+    gint x, y, w, h, width = 0;
+    gnc_item_edit_get_pixel_coords (GNC_ITEM_EDIT (item_edit), &x, &y, &w, &h);
+    width = ((h - 2)*2)/3;
+    if (width < 20) // minimum size for a button
+        width = 20;
+    *minimal_width = *natural_width = width;
+}
+
+static void
+gnc_item_edit_tb_get_preferred_height (GtkWidget *widget,
+                                    gint *minimal_width,
+                                    gint *natural_width)
+{
+    GncItemEditTb *tb = GNC_ITEM_EDIT_TB (widget);
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(tb->sheet->item_editor);
+    gint x, y, w, h;
+    gnc_item_edit_get_pixel_coords (GNC_ITEM_EDIT (item_edit), &x, &y, &w, &h);
+    *minimal_width = *natural_width = (h - 2);
+}
+
+static void
+gnc_item_edit_tb_class_init (GncItemEditTbClass *gnc_item_edit_tb_class)
+{
+    GObjectClass  *object_class;
+    GtkWidgetClass *widget_class;
+
+#if GTK_CHECK_VERSION(3,20,0)
+    gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(gnc_item_edit_tb_class), "button");
+#endif
+
+    gnc_item_edit_tb_parent_class = g_type_class_peek_parent (gnc_item_edit_tb_class);
+
+    object_class = G_OBJECT_CLASS (gnc_item_edit_tb_class);
+    widget_class = GTK_WIDGET_CLASS (gnc_item_edit_tb_class);
+
+    object_class->get_property = gnc_item_edit_tb_get_property;
+    object_class->set_property = gnc_item_edit_tb_set_property;
+
+    g_object_class_install_property (object_class,
+                                     PROP_SHEET,
+                                     g_param_spec_object ("sheet",
+                                             "Sheet Value",
+                                             "Sheet Value",
+                                             GNUCASH_TYPE_SHEET,
+                                             G_PARAM_READWRITE));
+
+    /* GtkWidget method overrides */
+    widget_class->get_preferred_width = gnc_item_edit_tb_get_preferred_width;
+    widget_class->get_preferred_height = gnc_item_edit_tb_get_preferred_height;
+}
+
+GType
+gnc_item_edit_tb_get_type (void)
+{
+    static GType gnc_item_edit_tb_type = 0;
+
+    if (!gnc_item_edit_tb_type)
+    {
+        static const GTypeInfo gnc_item_edit_tb_info =
+        {
+            sizeof (GncItemEditTbClass),
+            NULL,
+            NULL,
+            (GClassInitFunc) gnc_item_edit_tb_class_init,
+            NULL,
+            NULL,
+            sizeof (GncItemEditTb),
+            0, /* n_preallocs */
+            (GInstanceInitFunc) gnc_item_edit_tb_init,
+            NULL,
+        };
+        gnc_item_edit_tb_type =
+            g_type_register_static(GTK_TYPE_TOGGLE_BUTTON,
+                                   "GncItemEditTb",
+                                   &gnc_item_edit_tb_info, 0);
+    }
+    return gnc_item_edit_tb_type;
+}
+
+GtkWidget *
+gnc_item_edit_tb_new (GnucashSheet *sheet)
+{
+    GtkStyleContext *context;
+    GncItemEditTb *item_edit_tb =
+            g_object_new (GNC_TYPE_ITEM_EDIT_TB,
+                          "sheet", sheet,
+                           NULL);
+
+    // This sets a style class for when Gtk+ version is less than 3.20
+    gnc_widget_set_css_name (GTK_WIDGET(item_edit_tb), "button");
+
+    context = gtk_widget_get_style_context (GTK_WIDGET(item_edit_tb));
+    gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
+
+    return GTK_WIDGET(item_edit_tb);
+}
 
 /*
  * Returns the coordinates for the editor bounding box
@@ -722,7 +871,7 @@ gnc_item_edit_new (GnucashSheet *sheet)
     /* Create the popup button
        It will only be displayed when the cell being edited provides
        a popup item (like a calendar or account list) */
-    item_edit->popup_toggle.tbutton = gtk_toggle_button_new();
+    item_edit->popup_toggle.tbutton = gnc_item_edit_tb_new (sheet);
     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (item_edit->popup_toggle.tbutton), FALSE);
 
     /* Wrap the popup button in an event box to give it its own gdkwindow.
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h
index 45d1502..2be4d24 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.h
+++ b/gnucash/register/register-gnome/gnucash-item-edit.h
@@ -37,6 +37,10 @@
 #define GNC_ITEM_EDIT_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_ITEM_EDIT, GncItemEditClass))
 #define GNC_IS_ITEM_EDIT(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), GNC_TYPE_ITEM_EDIT))
 
+#define GNC_TYPE_ITEM_EDIT_TB        (gnc_item_edit_tb_get_type ())
+#define GNC_ITEM_EDIT_TB(o)          (G_TYPE_CHECK_INSTANCE_CAST((o), GNC_TYPE_ITEM_EDIT_TB, GncItemEditTb))
+#define GNC_ITEM_EDIT_TB_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_ITEM_EDIT_TB, GncItemEditTbClass))
+#define GNC_IS_ITEM_EDIT_TB(o)       (G_TYPE_CHECK_INSTANCE_TYPE((o), GNC_TYPE_ITEM_EDIT_TB))
 
 typedef int (*PopupGetHeight) (GtkWidget *item,
                                int space_available,
@@ -102,6 +106,19 @@ typedef struct
     GtkBoxClass parent_class;
 } GncItemEditClass;
 
+typedef struct
+{
+    GtkToggleButton tb;
+    GnucashSheet *sheet;
+} GncItemEditTb;
+
+typedef struct
+{
+    GtkToggleButtonClass parent_class;
+
+    void (* toggled) (GncItemEditTb *item_edit_tb);
+} GncItemEditTbClass;
+
 typedef enum
 {
     left,
@@ -145,5 +162,8 @@ void gnc_item_edit_focus_out (GncItemEdit *item_edit);
 gint gnc_item_edit_get_margin (GncItemEdit *item_edit, Sides side);
 gint gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side);
 
+GType gnc_item_edit_tb_get_type (void);
+GtkWidget *gnc_item_edit_tb_new (GnucashSheet *sheet);
+
 /** @} */
 #endif /* GNUCASH_ITEM_EDIT_H */

commit 0c443836966fa9fcc93c9510d93c7229515e049e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:09:37 2017 +0000

    Move the double line to be inside the cursor cell

diff --git a/gnucash/register/register-gnome/gnucash-sheet-private.c b/gnucash/register/register-gnome/gnucash-sheet-private.c
index 92fbe35..2abe7d7 100644
--- a/gnucash/register/register-gnome/gnucash-sheet-private.c
+++ b/gnucash/register/register-gnome/gnucash-sheet-private.c
@@ -682,7 +682,7 @@ gnucash_sheet_draw_cursor (GnucashCursor *cursor, cairo_t *cr)
     cairo_stroke (cr);
 
     // make the bottom line thicker
-    cairo_move_to (cr, cursor->x - x + 0.5, cursor->y - y + cursor->h - 1.5);
+    cairo_move_to (cr, cursor->x - x + 0.5, cursor->y - y + cursor->h - 3.5);
     cairo_rel_line_to (cr, cursor->w, 0);
     cairo_set_line_width (cr, 1.0);
     cairo_stroke (cr);

commit 2a938425748d73f72aa76849544942869f908fda
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:08:02 2017 +0000

    If a font size is specified for the sheet, popup size may be wrong
    
    When you specify a font size for the sheet, the popup will inherit this
    but when first popped it will use the minimum height value and so may
    be different resulting in not being in the right position. So check on
    allocation and if different remove and pop again.

diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c
index 2293bd2..813088f 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.c
+++ b/gnucash/register/register-gnome/gnucash-item-edit.c
@@ -742,6 +742,25 @@ gnc_item_edit_new (GnucashSheet *sheet)
     return GTK_WIDGET(item_edit);
 }
 
+static void
+check_popup_height_is_true (GtkWidget    *widget,
+                            GdkRectangle *allocation,
+                            gpointer user_data)
+{
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(user_data);
+    GnucashSheet *sheet = item_edit->sheet;
+
+    // if a larger font is specified in css for the sheet, the popup returned height value
+    // on first pop does not reflect the true height but the minimum height so just to be
+    // sure check this value against the allocated one.
+    if (allocation->height != item_edit->popup_returned_height)
+    {
+        gtk_container_remove (GTK_CONTAINER(item_edit->sheet), item_edit->popup_item);
+
+        g_idle_add_full (G_PRIORITY_HIGH_IDLE,
+                        (GSourceFunc) gnc_item_edit_update, item_edit, NULL);
+    }
+}
 
 void
 gnc_item_edit_show_popup (GncItemEdit *item_edit)
@@ -810,6 +829,11 @@ gnc_item_edit_show_popup (GncItemEdit *item_edit)
     if (!gtk_widget_get_parent (item_edit->popup_item))
         gtk_layout_put (GTK_LAYOUT(sheet), item_edit->popup_item, popup_x, popup_y);
 
+    // Lets check popup height is the true height
+    item_edit->popup_returned_height = popup_h;
+    g_signal_connect_after (item_edit->popup_item, "size-allocate",
+                            G_CALLBACK(check_popup_height_is_true), item_edit);
+
     gtk_widget_set_size_request (item_edit->popup_item, popup_w - 1, popup_h);
 
     toggle = GTK_TOGGLE_BUTTON(item_edit->popup_toggle.tbutton);
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h
index 7d37378..45d1502 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.h
+++ b/gnucash/register/register-gnome/gnucash-item-edit.h
@@ -85,6 +85,7 @@ typedef struct
     PopupPostShow    popup_post_show;
     PopupGetWidth    popup_get_width;
     gpointer         popup_user_data;
+    gint             popup_returned_height;
 
     GtkBorder        padding;
     GtkBorder        margin;

commit a278bcc05221e33409248b35e4c0c452f4b1d824
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:05:46 2017 +0000

    Use previously created functions
    
    Use the previously created functions to reduce code and for conformity.
    As part of this some variables were renamed to be common.

diff --git a/gnucash/register/register-gnome/gnucash-header.c b/gnucash/register/register-gnome/gnucash-header.c
index 247d08f..f279971 100644
--- a/gnucash/register/register-gnome/gnucash-header.c
+++ b/gnucash/register/register-gnome/gnucash-header.c
@@ -69,6 +69,7 @@ static void
 gnc_header_draw_offscreen (GncHeader *header)
 {
     SheetBlockStyle *style = header->style;
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(header->sheet->item_editor);
     Table *table = header->sheet->table;
     VirtualLocation virt_loc;
     VirtualCell *vcell;
@@ -125,7 +126,7 @@ gnc_header_draw_offscreen (GncHeader *header)
     for (i = 0; i < style->nrows; i++)
     {
         int col_offset = 0;
-        int h = 0, j;
+        int height = 0, j;
         virt_loc.phys_row_offset = i;
 
         /* TODO: This routine is duplicated in several places.
@@ -139,26 +140,29 @@ gnc_header_draw_offscreen (GncHeader *header)
             double text_x, text_y, text_w, text_h;
             BasicCell *cell;
             const char *text;
-            int w;
+            int width;
             PangoLayout *layout;
+            PangoRectangle logical_rect;
+            GdkRectangle rect;
+            int x_offset;
 
             virt_loc.phys_col_offset = j;
 
             cd = gnucash_style_get_cell_dimensions (style, i, j);
-            h = cd->pixel_height;
+            height = cd->pixel_height;
             if (header->in_resize && (j == header->resize_col))
-                w = header->resize_col_width;
+                width = header->resize_col_width;
             else
-                w = cd->pixel_width;
+                width = cd->pixel_width;
 
             cell = gnc_cellblock_get_cell (cb, i, j);
             if (!cell || !cell->cell_name)
             {
-                col_offset += w;
+                col_offset += width;
                 continue;
             }
 
-            cairo_rectangle (cr, col_offset - 0.5, row_offset + 0.5, w, h);
+            cairo_rectangle (cr, col_offset - 0.5, row_offset + 0.5, width, height);
             cairo_set_line_width (cr, 1.0);
             cairo_stroke (cr);
 
@@ -169,38 +173,28 @@ gnc_header_draw_offscreen (GncHeader *header)
                 text = "";
 
             layout = gtk_widget_create_pango_layout (GTK_WIDGET (header->sheet), text);
-            switch (gnc_table_get_align (table, virt_loc))
-            {
-            default:
-            case CELL_ALIGN_LEFT:
-                pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
-                break;
-
-            case CELL_ALIGN_RIGHT:
-                pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
-                break;
-
-            case CELL_ALIGN_CENTER:
-                pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
-                break;
-            }
 
-            text_x = col_offset + CELL_HPADDING;
-            text_y = row_offset + 1;
-            text_w = MAX (0, w - (2 * CELL_HPADDING));
-            text_h = h - 2;
+            pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+            gnucash_sheet_set_text_bounds (header->sheet, &rect,
+                                           col_offset, row_offset, width, height);
+
             cairo_save (cr);
-            cairo_rectangle (cr, text_x, text_y, text_w, text_h);
+            cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
             cairo_clip (cr);
 
-            gtk_render_layout (stylectxt, cr, text_x, text_y, layout);
+            x_offset = gnucash_sheet_get_text_offset (header->sheet, virt_loc,
+                                                      rect.width, logical_rect.width);
+
+            gtk_render_layout (stylectxt, cr, rect.x + x_offset,
+                               rect.y + gnc_item_edit_get_padding_border (item_edit, top), layout);
 
             cairo_restore (cr);
             g_object_unref (layout);
 
-            col_offset += w;
+            col_offset += width;
         }
-        row_offset += h;
+        row_offset += height;
     }
     gtk_style_context_restore (stylectxt);
 
diff --git a/gnucash/register/register-gnome/gnucash-sheet-private.c b/gnucash/register/register-gnome/gnucash-sheet-private.c
index 955f607..92fbe35 100644
--- a/gnucash/register/register-gnome/gnucash-sheet-private.c
+++ b/gnucash/register/register-gnome/gnucash-sheet-private.c
@@ -381,6 +381,7 @@ draw_cell (GnucashSheet *sheet,
            cairo_t *cr,
            int x, int y, int width, int height)
 {
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
     Table *table = sheet->table;
     PhysicalCellBorders borders;
     const char *text;
@@ -524,39 +525,19 @@ draw_cell (GnucashSheet *sheet,
         goto exit;
     }
 
-    pango_layout_get_pixel_extents(layout,
-                                   NULL,
-                                   &logical_rect);
+    pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
 
-    rect.x      = x + CELL_HPADDING;
-    rect.y      = y + CELL_VPADDING;
-    rect.width  = MAX (0, width - (2 * CELL_HPADDING));
-    rect.height = height - 2;
+    gnucash_sheet_set_text_bounds (sheet, &rect, x, y, width, height);
 
     cairo_save (cr);
     cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
     cairo_clip (cr);
 
-    switch (gnc_table_get_align (table, virt_loc))
-    {
-    default:
-    case CELL_ALIGN_LEFT:
-        x_offset = 0;
-        break;
-
-    case CELL_ALIGN_RIGHT:
-        x_offset = width - 2 * CELL_HPADDING - logical_rect.width - 3;
-        break;
-
-    case CELL_ALIGN_CENTER:
-        if (logical_rect.width > width - 2 * CELL_HPADDING)
-            x_offset = 0;
-        else
-            x_offset = (width - 2 * CELL_HPADDING -
-                        logical_rect.width) / 2;
-        break;
-    }
-    gtk_render_layout (stylectxt, cr, rect.x + x_offset + 1, rect.y, layout);
+    x_offset = gnucash_sheet_get_text_offset (sheet, virt_loc,
+                                              rect.width, logical_rect.width);
+
+    gtk_render_layout (stylectxt, cr, rect.x + x_offset,
+                       rect.y + gnc_item_edit_get_padding_border (item_edit, top), layout);
 
     cairo_restore (cr);
 
diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index 6db5367..5a66605 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -312,7 +312,7 @@ gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocati
     PangoLayout *layout;
     PangoRectangle logical_rect;
     GdkRectangle rect;
-    gint x, y, w, h;
+    gint x, y, width, height;
     gint index, trailing;
     gboolean result;
     gint x_offset = 0;
@@ -321,7 +321,7 @@ gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocati
         return 0;
 
     // Get the item_edit position
-    gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &w, &h);
+    gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &width, &height);
 
     layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
 
@@ -330,35 +330,14 @@ gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocati
 
     pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
 
-    rect.x      = x + CELL_HPADDING;
-    rect.y      = y + CELL_VPADDING;
-    rect.width  = MAX (0, w - (2 * CELL_HPADDING));
-    rect.height = h - 2;
+    gnucash_sheet_set_text_bounds (sheet, &rect, x, y, width, height);
 
-    // Get the alignment of the cell
-    switch (gnc_table_get_align (table, virt_loc))
-    {
-    default:
-    case CELL_ALIGN_LEFT:
-        x_offset = 0;
-        break;
-
-    case CELL_ALIGN_RIGHT:
-        x_offset = w - 2 * CELL_HPADDING - logical_rect.width - 3;
-        break;
-
-    case CELL_ALIGN_CENTER:
-        if (logical_rect.width > w - 2 * CELL_HPADDING)
-            x_offset = 0;
-        else
-            x_offset = (w - 2 * CELL_HPADDING -
-                        logical_rect.width) / 2;
-        break;
-    }
+    x_offset = gnucash_sheet_get_text_offset (sheet, virt_loc,
+                                              rect.width, logical_rect.width);
 
     result = pango_layout_xy_to_index (layout,
                  PANGO_SCALE * (sheet->button_x - rect.x - x_offset),
-                 PANGO_SCALE * (h/2), &index, &trailing);
+                 PANGO_SCALE * (height/2), &index, &trailing);
 
     g_object_unref (layout);
 
@@ -2231,6 +2210,7 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col)
     SheetBlock *block;
     SheetBlockStyle *style;
     PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), "");
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
 
     g_return_val_if_fail (virt_col >= 0, 0);
     g_return_val_if_fail (virt_col < sheet->num_virt_cols, 0);
diff --git a/gnucash/register/register-gnome/gnucash-sheet.h b/gnucash/register/register-gnome/gnucash-sheet.h
index 68b3c70..f729e8f 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.h
+++ b/gnucash/register/register-gnome/gnucash-sheet.h
@@ -33,10 +33,6 @@
  * @brief Public declarations of GnucashSheet class.
  */
 
-#define CELL_VPADDING 2
-#define CELL_HPADDING 5
-
-
 #define GNUCASH_TYPE_SHEET     (gnucash_sheet_get_type ())
 #define GNUCASH_SHEET(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), GNUCASH_TYPE_SHEET, GnucashSheet))
 #define GNUCASH_SHEET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNUCASH_TYPE_SHEET))

commit 0ba9b768996e3214d66d37b8b5a46d71ba4fb74d
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 12:01:54 2017 +0000

    Provide two functions for common code
    
    These two sections of code appear in three separate files in slightly
    different versions so define them hear for conformity

diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index d8a6cea..6db5367 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -261,6 +261,47 @@ gnucash_sheet_deactivate_cursor_cell (GnucashSheet *sheet)
     gnucash_sheet_redraw_block (sheet, virt_loc.vcell_loc);
 }
 
+void
+gnucash_sheet_set_text_bounds (GnucashSheet *sheet, GdkRectangle *rect,
+                               gint x, gint y, gint width, gint height)
+{
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
+
+    rect->x = x + gnc_item_edit_get_margin (item_edit, left);
+    rect->y = y + gnc_item_edit_get_margin (item_edit, top);
+    rect->width = MAX (0, width - gnc_item_edit_get_margin (item_edit, left_right));
+    rect->height = height - gnc_item_edit_get_margin (item_edit, top_bottom);
+}
+
+gint
+gnucash_sheet_get_text_offset (GnucashSheet *sheet, const VirtualLocation virt_loc,
+                                gint rect_width, gint logical_width)
+{
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
+    Table *table = sheet->table;
+    gint x_offset = 0;
+
+    // Get the alignment of the cell
+    switch (gnc_table_get_align (table, virt_loc))
+    {
+    default:
+    case CELL_ALIGN_LEFT:
+        x_offset = gnc_item_edit_get_padding_border (item_edit, left);
+        break;
+
+    case CELL_ALIGN_RIGHT:
+        x_offset = rect_width - gnc_item_edit_get_padding_border (item_edit, right) - logical_width - 1;
+        break;
+
+    case CELL_ALIGN_CENTER:
+        if (logical_width > rect_width)
+            x_offset = 0;
+        else
+            x_offset = (rect_width - logical_width) / 2;
+        break;
+    }
+    return x_offset;
+}
 
 static gint
 gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocation virt_loc)
@@ -2229,7 +2270,7 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col)
                 pango_layout_set_text (layout, text, strlen (text));
                 pango_layout_get_pixel_size (layout, &width, NULL);
 
-                width += 2 * CELL_HPADDING;
+                width += gnc_item_edit_get_margin (item_edit, left_right);
 
                 max = MAX (max, width);
             }
diff --git a/gnucash/register/register-gnome/gnucash-sheet.h b/gnucash/register/register-gnome/gnucash-sheet.h
index b571d03..68b3c70 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.h
+++ b/gnucash/register/register-gnome/gnucash-sheet.h
@@ -108,5 +108,11 @@ void gnucash_sheet_set_window (GnucashSheet *sheet, GtkWidget *window);
 void gnucash_get_style_classes (GnucashSheet *sheet, GtkStyleContext *stylectxt,
                                 RegisterColor field_type);
 
+void gnucash_sheet_set_text_bounds (GnucashSheet *sheet, GdkRectangle *rect,
+                                    gint x, gint y, gint width, gint height);
+
+gint gnucash_sheet_get_text_offset (GnucashSheet *sheet, const VirtualLocation virt_loc,
+                                    gint rect_width, gint logical_width);
+
 /** @} */
 #endif

commit 70ad2c3bc4f035512605154724228c90d90baa75
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 11:57:58 2017 +0000

    This function doesn't do much and is only used for new account registers
    
    This function is used to get the width of the toggle button and add it
    to the sample text length to set the default column width. As it is
    square, just use the row height instead and the user will no doubt set
    there own widths any way.

diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c
index fc44f6a..2293bd2 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.c
+++ b/gnucash/register/register-gnome/gnucash-item-edit.c
@@ -94,14 +94,6 @@ gnc_item_edit_get_pixel_coords (GncItemEdit *item_edit,
     *y += yd;
 }
 
-
-int
-gnc_item_edit_get_toggle_offset (int row_height)
-{
-    /* sync with gnc_item_edit_update */
-    return row_height - (2 * (CELL_VPADDING + 1)) + 3;
-}
-
 static gboolean
 gnc_item_edit_update (GncItemEdit *item_edit)
 {
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h
index a2eae31..7d37378 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.h
+++ b/gnucash/register/register-gnome/gnucash-item-edit.h
@@ -133,8 +133,6 @@ void gnc_item_edit_set_popup (GncItemEdit    *item_edit,
 void gnc_item_edit_show_popup (GncItemEdit *item_edit);
 void gnc_item_edit_hide_popup (GncItemEdit *item_edit);
 
-int gnc_item_edit_get_toggle_offset (int row_height);
-
 void gnc_item_edit_cut_clipboard (GncItemEdit *item_edit);
 void gnc_item_edit_copy_clipboard (GncItemEdit *item_edit);
 void gnc_item_edit_paste_clipboard (GncItemEdit *item_edit);
diff --git a/gnucash/register/register-gnome/gnucash-style.c b/gnucash/register/register-gnome/gnucash-style.c
index 2ef3c8f..e999620 100644
--- a/gnucash/register/register-gnome/gnucash-style.c
+++ b/gnucash/register/register-gnome/gnucash-style.c
@@ -215,9 +215,10 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
             if (cd->pixel_width > 0)
                 continue;
 
+            // This is used on new account popup cells to get the default
+            // width of text plus toggle button.
             if (cell && cell->is_popup)
-                width += gnc_item_edit_get_toggle_offset
-                         (cd->pixel_height);
+                width += cd->pixel_height; // toggle button is square, use cell height
 
             cd->pixel_width = MAX (cd->pixel_width, width);
         }

commit bb16e07d8f41e04f003ff6b18ad57cec907d5dff
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 11:56:12 2017 +0000

    Adjust the sheet to get its spacings from the item_edit CSS

diff --git a/gnucash/register/register-gnome/gnucash-style.c b/gnucash/register/register-gnome/gnucash-style.c
index dcadb7c..2ef3c8f 100644
--- a/gnucash/register/register-gnome/gnucash-style.c
+++ b/gnucash/register/register-gnome/gnucash-style.c
@@ -169,6 +169,7 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
     int row, col;
     gint max_height = -1;
     PangoLayout *layout;
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
 
     /* g_return_if_fail (font != NULL); */
 
@@ -196,13 +197,17 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
                 layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
                 pango_layout_get_pixel_size (layout, &width, &cd->pixel_height);
                 g_object_unref (layout);
-                width += 2 * CELL_HPADDING;
-                cd->pixel_height += 2 * CELL_VPADDING;
+                width += gnc_item_edit_get_margin (item_edit, left_right) +
+                         gnc_item_edit_get_padding_border (item_edit, left_right);
+
+                cd->pixel_height += gnc_item_edit_get_margin (item_edit, top_bottom) +
+                                    gnc_item_edit_get_padding_border (item_edit, top_bottom);
             }
             else
             {
                 width = 0;
-                cd->pixel_height = (2 * CELL_VPADDING);
+                cd->pixel_height = gnc_item_edit_get_margin (item_edit, top_bottom) +
+                                   gnc_item_edit_get_padding_border (item_edit, top_bottom);
             }
 
             max_height = MAX(max_height, cd->pixel_height);
@@ -239,6 +244,7 @@ static void
 set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
 {
     SheetBlockStyle *style;
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
     BlockDimensions *dimensions;
     CellDimensions *cd;
     GTable *cd_table;
@@ -315,7 +321,8 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
                 pango_layout_get_pixel_size (layout, &sample_width, NULL);
                 g_object_unref (layout);
                 /*sample_width = gdk_string_width (font, text);*/
-                sample_width += 2 * CELL_HPADDING;
+                sample_width += gnc_item_edit_get_margin (item_edit, left_right) +
+                                gnc_item_edit_get_padding_border (item_edit, left_right);
             }
             else
                 sample_width = 0;

commit 9f76441d5098b648baad60a5e51c41f571b72d48
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 1 11:54:05 2017 +0000

    Get the item_edit cell padding from CSS instead of defines
    
    This commit sets up getting the vertical and horizontal item_edit cell
    margins, borders and padding from CSS. This increases the option to
    specify individual values for top, right, bottom and left instead of
    just specifying just two values.

diff --git a/gnucash/gnucash-310.css b/gnucash/gnucash-310.css
index e4a37a3..e6b218d 100644
--- a/gnucash/gnucash-310.css
+++ b/gnucash/gnucash-310.css
@@ -21,13 +21,14 @@
   color: mix (currentColor, grey, 0.2);
 }
 
-/* Register Cursor padding settings, make sure entry matches sheet.h */
-cursor entry {
-  padding: 2px 5px 2px 5px;
+/* Register Cursor settings, top, right, bottom, left */
+.cursor .entry {
+  margin: 2px 5px 2px 5px;  /* this only works by doing it in code, yellow area */
+  padding: 2px 2px 2px 2px; /* all work with different values, around the text blue area */
 }
 
-cursor button {
-  padding: 1px 1px 1px 1px;
+.cursor .button {
+  margin: 1px 1px 1px 1px; /* does not work, not used, here for completeness */
 }
 
 /* Register defaults */
@@ -37,7 +38,7 @@ cursor button {
 @define-color register_split_bg_color #EDE7D3;
 @define-color register_cursor_bg_color #FFEF98;
 
-.register-header {
+*.register-header {
   background-color: @register_header_bg_color;
 }
 
diff --git a/gnucash/gnucash-320.css b/gnucash/gnucash-320.css
index d7e0495..4f4ea09 100644
--- a/gnucash/gnucash-320.css
+++ b/gnucash/gnucash-320.css
@@ -12,13 +12,14 @@
   color: @negative-numbers;
 }
 
-/* Register Cursor padding settings, make sure entry matches sheet.h */
+/* Register Cursor settings, top, right, bottom, left */
 cursor entry {
-  padding: 2px 5px 2px 5px;
+  margin: 2px 5px 2px 5px;
+  padding: 0px 2px 0px 2px;
 }
 
 cursor button {
-  padding: 1px 1px 1px 1px;
+  margin: 1px 1px 1px 1px;
 }
 
 /* Register defaults */
@@ -28,7 +29,7 @@ cursor button {
 @define-color register_split_bg_color #EDE7D3;
 @define-color register_cursor_bg_color #FFEF98;
 
-.register-header {
+*.register-header {
   background-color: @register_header_bg_color;
 }
 
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c
index 91aa497..fc44f6a 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.c
+++ b/gnucash/register/register-gnome/gnucash-item-edit.c
@@ -361,6 +361,7 @@ draw_background_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data)
 static gboolean
 draw_text_cursor_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data)
 {
+    GncItemEdit *item_edit = GNC_ITEM_EDIT(user_data);
     GtkEditable *editable = GTK_EDITABLE(widget);
     GtkStyleContext *stylectxt = gtk_widget_get_style_context (GTK_WIDGET(widget));
     gint height = gtk_widget_get_allocated_height (widget);
@@ -401,8 +402,15 @@ draw_text_cursor_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data)
     // Now draw a vertical line
     cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
     cairo_set_line_width (cr, 1.0);
-    cairo_move_to (cr, cursor_x + 0.5, 2);
-    cairo_rel_line_to (cr, 0, height - 4);
+#if GTK_CHECK_VERSION(3,20,0)
+    cairo_move_to (cr, cursor_x + 0.5, gnc_item_edit_get_margin (item_edit, top) +
+                                       gnc_item_edit_get_padding_border (item_edit, top));
+    cairo_rel_line_to (cr, 0, height - gnc_item_edit_get_margin (item_edit, top_bottom) -
+                                       gnc_item_edit_get_padding_border (item_edit, top_bottom));
+#else
+    cairo_move_to (cr, cursor_x + 0.5, gnc_item_edit_get_padding_border (item_edit, top));
+    cairo_rel_line_to (cr, 0, height - gnc_item_edit_get_padding_border (item_edit, top_bottom));
+#endif
     cairo_stroke (cr);
 
     return FALSE;
@@ -608,13 +616,60 @@ gnc_item_edit_get_type (void)
     return gnc_item_edit_type;
 }
 
+gint
+gnc_item_edit_get_margin (GncItemEdit *item_edit, Sides side)
+{
+    switch (side)
+    {
+    case left:
+        return item_edit->margin.left;
+    case right:
+        return item_edit->margin.right;
+    case top:
+        return item_edit->margin.top;
+    case bottom:
+        return item_edit->margin.bottom;
+    case left_right:
+        return item_edit->margin.left + item_edit->margin.right;
+    case top_bottom:
+        return item_edit->margin.top + item_edit->margin.bottom;
+    default:
+        return 2;
+    }
+}
+
+gint
+gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side)
+{
+    switch (side)
+    {
+    case left:
+        return item_edit->padding.left + item_edit->border.left;
+    case right:
+        return item_edit->padding.right + item_edit->border.right;
+    case top:
+        return item_edit->padding.top + item_edit->border.top;
+    case bottom:
+        return item_edit->padding.bottom + item_edit->border.bottom;
+    case left_right:
+        return item_edit->padding.left + item_edit->border.left +
+               item_edit->padding.right + item_edit->border.right;
+    case top_bottom:
+        return item_edit->padding.top + item_edit->border.top +
+               item_edit->padding.bottom + item_edit->border.bottom;
+    default:
+        return 2;
+    }
+}
 
 GtkWidget *
 gnc_item_edit_new (GnucashSheet *sheet)
 {
-    char *hpad_str, *vpad_str, *entry_css;
-    GtkStyleContext *stylecontext;
-    GtkCssProvider *provider;
+    GtkStyleContext *stylectxt;
+    GtkBorder padding;
+    GtkBorder margin;
+    GtkBorder border;
+    GtkWidget *vb = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
     GncItemEdit *item_edit =
             g_object_new (GNC_TYPE_ITEM_EDIT,
                           "sheet", sheet,
@@ -630,32 +685,54 @@ gnc_item_edit_new (GnucashSheet *sheet)
     item_edit->editor = gtk_entry_new();
     sheet->entry = item_edit->editor;
     gtk_entry_set_width_chars (GTK_ENTRY(item_edit->editor), 1);
-    gtk_box_pack_start (GTK_BOX(item_edit), item_edit->editor,  TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX(item_edit), item_edit->editor, TRUE, TRUE, 0);
+
+    // Get the CSS space settings for the entry
+    stylectxt = gtk_widget_get_style_context (GTK_WIDGET(item_edit->editor));
+    gtk_style_context_get_padding (stylectxt, GTK_STATE_FLAG_NORMAL, &padding);
+    gtk_style_context_get_margin (stylectxt, GTK_STATE_FLAG_NORMAL, &margin);
+    gtk_style_context_get_border (stylectxt, GTK_STATE_FLAG_NORMAL, &border);
+
+    item_edit->padding = padding;
+    item_edit->margin = margin;
+    item_edit->border = border;
 
     // Make sure the Entry can not have focus and no frame
     gtk_widget_set_can_focus (GTK_WIDGET(item_edit->editor), FALSE);
     gtk_entry_set_has_frame (GTK_ENTRY(item_edit->editor), FALSE);
 
+#if !GTK_CHECK_VERSION(3,20,0)
+#if GTK_CHECK_VERSION(3,12,0)
+    gtk_widget_set_margin_start (GTK_WIDGET(item_edit->editor),
+                                 gnc_item_edit_get_margin (item_edit, left));
+    gtk_widget_set_margin_end (GTK_WIDGET(item_edit->editor),
+                               gnc_item_edit_get_margin (item_edit, right));
+#else
+    gtk_widget_set_margin_left (GTK_WIDGET(item_edit->editor),
+                                gnc_item_edit_get_margin (item_edit, left));
+    gtk_widget_set_margin_right (GTK_WIDGET(item_edit->editor),
+                                 gnc_item_edit_get_margin (item_edit, right));
+#endif
+    gtk_widget_set_margin_top (GTK_WIDGET(item_edit->editor),
+                               gnc_item_edit_get_margin (item_edit, top));
+    gtk_widget_set_margin_bottom (GTK_WIDGET(item_edit->editor),
+                                  gnc_item_edit_get_margin (item_edit, bottom));
+#endif
+
     // Connect to the draw signal so we can draw a cursor
     g_signal_connect_after (item_edit->editor, "draw",
-                            G_CALLBACK (draw_text_cursor_cb), NULL);
+                            G_CALLBACK (draw_text_cursor_cb), item_edit);
 
     // Fill in the background so the underlying sheet cell can not be seen
     g_signal_connect (item_edit, "draw",
                             G_CALLBACK (draw_background_cb), item_edit);
 
-    /* Force padding on the entry to align with the rest of the register this
-       is done in the gnucash.css file which should be in line with sheet.h */
-
     /* Create the popup button
        It will only be displayed when the cell being edited provides
        a popup item (like a calendar or account list) */
     item_edit->popup_toggle.tbutton = gtk_toggle_button_new();
     gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (item_edit->popup_toggle.tbutton), FALSE);
 
-    /* Force padding on the button to keep it small and display as much as
-       possible of the arrow which is done in the gnucash.css file */
-
     /* Wrap the popup button in an event box to give it its own gdkwindow.
      * Without one the button would disappear behind the grid object. */
     item_edit->popup_toggle.ebox = gtk_event_box_new();
@@ -663,11 +740,13 @@ gnc_item_edit_new (GnucashSheet *sheet)
     gtk_container_add(GTK_CONTAINER(item_edit->popup_toggle.ebox),
                       item_edit->popup_toggle.tbutton);
 
-    gtk_box_pack_start (GTK_BOX(item_edit),
-                        item_edit->popup_toggle.ebox,
-                        FALSE, TRUE, 0);
-    gtk_widget_show_all(GTK_WIDGET(item_edit));
+    /* The button needs to be packed into a vertical box so that the height and position
+     * can be controlled in ealier than Gtk3.20 versions */
+    gtk_box_pack_start (GTK_BOX(vb), item_edit->popup_toggle.ebox,
+                        FALSE, FALSE, 0);
 
+    gtk_box_pack_start (GTK_BOX(item_edit), vb, FALSE, FALSE, 0);
+    gtk_widget_show_all(GTK_WIDGET(item_edit));
     return GTK_WIDGET(item_edit);
 }
 
diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h
index 7b8969a..a2eae31 100644
--- a/gnucash/register/register-gnome/gnucash-item-edit.h
+++ b/gnucash/register/register-gnome/gnucash-item-edit.h
@@ -86,6 +86,10 @@ typedef struct
     PopupGetWidth    popup_get_width;
     gpointer         popup_user_data;
 
+    GtkBorder        padding;
+    GtkBorder        margin;
+    GtkBorder        border;
+
     /* Where are we */
     VirtualLocation virt_loc;
 
@@ -97,6 +101,15 @@ typedef struct
     GtkBoxClass parent_class;
 } GncItemEditClass;
 
+typedef enum
+{
+    left,
+    right,
+    top,
+    bottom,
+    left_right,
+    top_bottom,
+} Sides;
 
 GType gnc_item_edit_get_type (void);
 
@@ -130,5 +143,8 @@ gboolean gnc_item_edit_get_has_selection (GncItemEdit *item_edit);
 void gnc_item_edit_focus_in (GncItemEdit *item_edit);
 void gnc_item_edit_focus_out (GncItemEdit *item_edit);
 
+gint gnc_item_edit_get_margin (GncItemEdit *item_edit, Sides side);
+gint gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side);
+
 /** @} */
 #endif /* GNUCASH_ITEM_EDIT_H */



Summary of changes:
 gnucash/gnome-utils/gnc-dense-cal.c                |  95 ++++---
 gnucash/gnome-utils/gnc-dense-cal.h                |   3 +
 gnucash/gnucash-310.css                            |  13 +-
 gnucash/gnucash-320.css                            |  11 +-
 gnucash/register/ledger-core/gncEntryLedgerModel.c |  49 ++--
 .../register/ledger-core/split-register-model.c    | 217 +++++++--------
 gnucash/register/register-core/table-allgui.c      |  57 +---
 gnucash/register/register-core/table-allgui.h      |  42 +--
 gnucash/register/register-core/table-model.c       |  72 ++---
 gnucash/register/register-core/table-model.h       |  29 +-
 gnucash/register/register-gnome/gnucash-header.c   |  58 ++--
 .../register/register-gnome/gnucash-item-edit.c    | 308 ++++++++++++++++++---
 .../register/register-gnome/gnucash-item-edit.h    |  39 ++-
 .../register-gnome/gnucash-sheet-private.c         |  49 +---
 gnucash/register/register-gnome/gnucash-sheet.c    | 113 ++++----
 gnucash/register/register-gnome/gnucash-sheet.h    |  10 +-
 gnucash/register/register-gnome/gnucash-style.c    |  20 +-
 17 files changed, 664 insertions(+), 521 deletions(-)



More information about the gnucash-changes mailing list