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
This commit is contained in:
Robert Fewell 2017-11-01 12:23:17 +00:00
parent 7a2c1492fd
commit 98d8696b1a
2 changed files with 21 additions and 78 deletions

View File

@ -345,70 +345,31 @@ 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,
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,
return 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);
}
void
gnc_table_get_borders (Table *table, VirtualLocation virt_loc,
PhysicalCellBorders *borders)

View File

@ -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,