From 98d8696b1a223c792dcd029149127c6a17d4e4c6 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 1 Nov 2017 12:23:17 +0000 Subject: [PATCH] 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 --- gnucash/register/register-core/table-allgui.c | 57 +++---------------- gnucash/register/register-core/table-allgui.h | 42 ++++---------- 2 files changed, 21 insertions(+), 78 deletions(-) diff --git a/gnucash/register/register-core/table-allgui.c b/gnucash/register/register-core/table-allgui.c index 7e407db9c0..038d3b04a8 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); + color_handler = gnc_table_model_get_cell_color_handler (table->model, + handler_name); - if (!bg_color_handler) - return COLOR_UNKNOWN_BG; + if (!color_handler) + return COLOR_UNDEFINED; - return bg_color_handler (virt_loc, hatching, - table->model->handler_user_data); -} - -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 d827fd5fce..3b4fa26d11 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,