From ed3de42c96d4cc0032eb624dc356de05acaa93d0 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 1 Nov 2017 12:30:03 +0000 Subject: [PATCH] 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 --- .../register/register-gnome/gnucash-header.c | 4 +-- .../register-gnome/gnucash-item-edit.c | 7 ++-- .../register-gnome/gnucash-sheet-private.c | 7 ++-- .../register/register-gnome/gnucash-sheet.c | 36 ++++++++----------- 4 files changed, 21 insertions(+), 33 deletions(-) diff --git a/gnucash/register/register-gnome/gnucash-header.c b/gnucash/register/register-gnome/gnucash-header.c index f27997185b..156ae68ab2 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 acbc32325e..39641d12ab 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 7631caa817..e71db31a57 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 5a6660507f..311ab1b2a6 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; }