Skip to content

Commit

Permalink
Change CSS class and names used for the Register
Browse files Browse the repository at this point in the history
Change the CSS classes and widget names to a standard naming for all of
Gnucash. This should make it easier to adjust Gnucash appearance if
required. CSS classes all begin with 'gnc-class-' and widget names
begin with 'gnc-id-'
  • Loading branch information
Bob-IT committed Apr 5, 2020
1 parent 7ccba84 commit 0546dd5
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gnucash/gnome-utils/gnc-tree-view-split-reg.c
Expand Up @@ -989,7 +989,7 @@ gnc_tree_view_split_reg_new_with_model (GncTreeModelSplitReg *model)
view->help_text = g_strdup ("Help Text");

/* Set the grid lines to be solid */
gnc_widget_set_style_context (GTK_WIDGET(view), "register2_grid_lines");
gnc_widget_style_context_add_class (GTK_WIDGET(view), "gnc-class-register2-grid-lines");

/* TreeView Grid lines */
if (view->priv->use_horizontal_lines)
Expand Down
28 changes: 14 additions & 14 deletions gnucash/gnucash-310.css
Expand Up @@ -13,12 +13,12 @@
}

/* Register Cursor settings, top, right, bottom, left */
.cursor .entry {
.gnc-class-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 {
.gnc-class-cursor .button {
margin: 1px 1px 1px 1px; /* does not work, not used, here for completeness */
}

Expand All @@ -30,52 +30,52 @@
@define-color register_cursor_bg_color #FFEF98;
@define-color register_fg_color black;

*.register-foreground {
*.gnc-class-register-foreground {
color: @register_fg_color;
}

*.register-header {
*.gnc-class-register-header {
background-color: @register_header_bg_color;
}

*.register-primary {
*.gnc-class-register-primary {
background-color: @register_primary_bg_color;
}

*.register-primary:insensitive {
*.gnc-class-register-primary:insensitive {
background-color: mix (@register_primary_bg_color, grey, 0.2);
}

*.register-secondary {
*.gnc-class-register-secondary {
background-color: @register_secondary_bg_color;
}

*.register-secondary:insensitive {
*.gnc-class-register-secondary:insensitive {
background-color: mix (@register_secondary_bg_color, grey, 0.2);
}

*.register-split {
*.gnc-class-register-split {
background-color: @register_split_bg_color;
}

*.register-split:insensitive {
*.gnc-class-register-split:insensitive {
background-color: mix (@register_split_bg_color, grey, 0.2);
}

*.register-cursor {
*.gnc-class-register-cursor {
background-color: @register_cursor_bg_color;
}

*.register-cursor:insensitive {
*.gnc-class-register-cursor:insensitive {
background-color: mix (@register_cursor_bg_color, grey, 0.2);
}

/* Change font color by mixing with grey */
.lighter-grey-mix {
.gnc-class-lighter-grey-mix {
color: mix (currentColor, grey, 0.8);
}

.darker-grey-mix {
.gnc-class-darker-grey-mix {
color: mix (currentColor, grey, 0.2);
}

Expand Down
28 changes: 14 additions & 14 deletions gnucash/gnucash-320.css
Expand Up @@ -13,12 +13,12 @@
}

/* Register Cursor settings, top, right, bottom, left */
cursor entry {
gnc-id-cursor entry {
margin: 2px 5px 2px 5px;
padding: 0px 2px 0px 2px;
}

cursor button {
gnc-id-cursor button {
margin: 1px 1px 1px 1px;
}

Expand All @@ -30,52 +30,52 @@ cursor button {
@define-color register_cursor_bg_color #FFEF98;
@define-color register_fg_color black;

*.register-foreground {
*.gnc-class-register-foreground {
color: @register_fg_color;
}

*.register-header {
*.gnc-class-register-header {
background-color: @register_header_bg_color;
}

*.register-primary {
*.gnc-class-register-primary {
background-color: @register_primary_bg_color;
}

*.register-primary:disabled {
*.gnc-class-register-primary:disabled {
background-color: mix (@register_primary_bg_color, grey, 0.2);
}

*.register-secondary {
*.gnc-class-register-secondary {
background-color: @register_secondary_bg_color;
}

*.register-secondary:disabled {
*.gnc-class-register-secondary:disabled {
background-color: mix (@register_secondary_bg_color, grey, 0.2);
}

*.register-split {
*.gnc-class-register-split {
background-color: @register_split_bg_color;
}

*.register-split:disabled {
*.gnc-class-register-split:disabled {
background-color: mix (@register_split_bg_color, grey, 0.2);
}

*.register-cursor {
*.gnc-class-register-cursor {
background-color: @register_cursor_bg_color;
}

*.register-cursor:disabled {
*.gnc-class-register-cursor:disabled {
background-color: mix (@register_cursor_bg_color, grey, 0.2);
}

/* Change font color by mixing with grey */
.lighter-grey-mix {
.gnc-class-lighter-grey-mix {
color: mix (currentColor, grey, 0.8);
}

.darker-grey-mix {
.gnc-class-darker-grey-mix {
color: mix (currentColor, grey, 0.2);
}

Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnucash-fallback-310.css
Expand Up @@ -37,7 +37,7 @@
@define-color negative-numbers rgb(75%, 0%, 0%);

/* Register2 grid lines color */
.register2_grid_lines {
.gnc-class-register2-grid-lines {
border-color: black;
}

Expand Down
6 changes: 3 additions & 3 deletions gnucash/register/register-gnome/gnucash-header.c
Expand Up @@ -74,7 +74,7 @@ gnc_header_draw_offscreen (GncHeader *header)

// 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);
gnucash_get_style_classes (header->sheet, stylectxt, color_type, FALSE);

if (header->surface)
cairo_surface_destroy (header->surface);
Expand Down Expand Up @@ -596,7 +596,7 @@ gnc_header_init (GncHeader *header)
header->style = NULL;

// This sets a style class for when Gtk+ version is less than 3.20
gnc_widget_set_css_name (GTK_WIDGET(header), "header");
gnc_widget_add_style_class (GTK_WIDGET(header), "gnc-class-header");

gtk_widget_add_events(GTK_WIDGET(header), (GDK_EXPOSURE_MASK
| GDK_BUTTON_PRESS_MASK
Expand All @@ -617,7 +617,7 @@ gnc_header_class_init (GncHeaderClass *header_class)
GtkWidgetClass *item_class = GTK_WIDGET_CLASS (header_class);

#if GTK_CHECK_VERSION(3,20,0)
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(header_class), "header");
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(header_class), "gnc-id-header");
#endif

parent_class = g_type_class_peek_parent (header_class);
Expand Down
10 changes: 5 additions & 5 deletions gnucash/register/register-gnome/gnucash-item-edit.c
Expand Up @@ -209,7 +209,7 @@ 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_add_style_class (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);
Expand Down Expand Up @@ -498,7 +498,7 @@ draw_background_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data)

// 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);
gnucash_get_style_classes (item_edit->sheet, stylectxt, color_type, FALSE);

gtk_render_background (stylectxt, cr, 0, 1, width, height - 2);

Expand Down Expand Up @@ -711,7 +711,7 @@ gnc_item_edit_class_init (GncItemEditClass *gnc_item_edit_class)
GtkWidgetClass *widget_class;

#if GTK_CHECK_VERSION(3,20,0)
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(gnc_item_edit_class), "cursor");
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(gnc_item_edit_class), "gnc-id-cursor");
#endif

gnc_item_edit_parent_class = g_type_class_peek_parent (gnc_item_edit_class);
Expand Down Expand Up @@ -866,7 +866,7 @@ gnc_item_edit_new (GnucashSheet *sheet)
gtk_layout_put (GTK_LAYOUT(sheet), GTK_WIDGET(item_edit), 0, 0);

// This sets a style class for when Gtk+ version is less than 3.20
gnc_widget_set_css_name (GTK_WIDGET(item_edit), "cursor");
gnc_widget_add_style_class (GTK_WIDGET(item_edit), "gnc-class-cursor");

/* Create the text entry */
item_edit->editor = gtk_entry_new();
Expand All @@ -876,7 +876,7 @@ gnc_item_edit_new (GnucashSheet *sheet)

// Get the CSS space settings for the entry
stylectxt = gtk_widget_get_style_context (GTK_WIDGET(item_edit->editor));
gtk_style_context_add_class (stylectxt, "register-foreground");
gtk_style_context_add_class (stylectxt, "gnc-class-register-foreground");
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);
Expand Down
4 changes: 2 additions & 2 deletions gnucash/register/register-gnome/gnucash-register.c
Expand Up @@ -318,7 +318,7 @@ gnucash_register_class_init (GnucashRegisterClass *klass)
gobject_class = G_OBJECT_CLASS (klass);

#if GTK_CHECK_VERSION(3,20,0)
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(klass), "register");
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(klass), "gnc-id-register");
#endif

register_parent_class = g_type_class_peek_parent (klass);
Expand Down Expand Up @@ -379,7 +379,7 @@ gnucash_register_init (GnucashRegister *g_reg)
gtk_widget_set_can_default (GTK_WIDGET(table), FALSE);

// This sets a style class for when Gtk+ version is less than 3.20
gnc_widget_set_css_name (GTK_WIDGET(g_reg), "register");
gnc_widget_add_style_class (GTK_WIDGET(g_reg), "gnc-class-register");

gtk_grid_set_row_homogeneous (GTK_GRID(table), FALSE);
gtk_grid_set_column_homogeneous (GTK_GRID(table), FALSE);
Expand Down
17 changes: 11 additions & 6 deletions gnucash/register/register-gnome/gnucash-sheet-private.c
Expand Up @@ -396,12 +396,19 @@ draw_cell (GnucashSheet *sheet,
int x_offset;
GtkStyleContext *stylectxt = gtk_widget_get_style_context (GTK_WIDGET(sheet));
GdkRGBA color;
gboolean use_neg_class = TRUE;

gtk_style_context_save (stylectxt);

text = gnc_table_get_entry (table, virt_loc);

// test for any text, if no text we do not want to add gnc-class-negative-numbers
if (!text || *text == '\0')
use_neg_class = FALSE;

// 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);
gnucash_get_style_classes (sheet, stylectxt, color_type, use_neg_class);

// Are we in a read-only row? Then make the background color somewhat more grey.
if ((virt_loc.phys_row_offset < block->style->nrows)
Expand Down Expand Up @@ -477,8 +484,6 @@ draw_cell (GnucashSheet *sheet,
table->model->dividing_row_lower, block->style->nrows,
fg_color, x, y, width, height);

text = gnc_table_get_entry (table, virt_loc);

layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);

if (gtk_style_context_has_class (stylectxt, GTK_STYLE_CLASS_VIEW))
Expand All @@ -496,7 +501,7 @@ draw_cell (GnucashSheet *sheet,
&& (virt_loc.vcell_loc.virt_row < table->model->dividing_row_upper))
{
// Make text color greyed
gtk_style_context_add_class (stylectxt, "lighter-grey-mix");
gtk_style_context_add_class (stylectxt, "gnc-class-lighter-grey-mix");
}
#endif

Expand All @@ -511,7 +516,7 @@ draw_cell (GnucashSheet *sheet,
goto exit;

// Make text color greyed
gtk_style_context_add_class (stylectxt, "lighter-grey-mix");
gtk_style_context_add_class (stylectxt, "gnc-class-lighter-grey-mix");

pango_layout_set_text (layout, text, strlen (text));
pango_font_description_set_style (font, PANGO_STYLE_ITALIC);
Expand Down Expand Up @@ -699,7 +704,7 @@ gnucash_sheet_draw_cursor (GnucashCursor *cursor, cairo_t *cr)
}

void
gnc_widget_set_css_name (GtkWidget *widget, const char *name)
gnc_widget_add_style_class (GtkWidget *widget, const char *name)
{
#if !GTK_CHECK_VERSION(3,20,0)
GtkStyleContext *context = gtk_widget_get_style_context (widget);
Expand Down
15 changes: 8 additions & 7 deletions gnucash/register/register-gnome/gnucash-sheet.c
Expand Up @@ -2519,19 +2519,20 @@ gnucash_sheet_table_load (GnucashSheet *sheet, gboolean do_scroll)
/** Map a cell color type to a css style class. */
void
gnucash_get_style_classes (GnucashSheet *sheet, GtkStyleContext *stylectxt,
RegisterColor field_type)
RegisterColor field_type, gboolean use_neg_class)
{
gchar *full_class, *style_class = NULL;

if (field_type >= COLOR_NEGATIVE) // Require a Negative fg color
{
gtk_style_context_add_class (stylectxt, "gnc-class-negative-numbers");
if (use_neg_class)
gtk_style_context_add_class (stylectxt, "gnc-class-negative-numbers");
field_type -= COLOR_NEGATIVE;
}
else
{
if (sheet->use_gnc_color_theme) // only add this class if builtin colors used
gtk_style_context_add_class (stylectxt, "register-foreground");
gtk_style_context_add_class (stylectxt, "gnc-class-register-foreground");
}

switch (field_type)
Expand Down Expand Up @@ -2566,11 +2567,11 @@ gnucash_get_style_classes (GnucashSheet *sheet, GtkStyleContext *stylectxt,
}

if (sheet->use_gnc_color_theme)
full_class = g_strconcat ("register-", style_class, NULL);
full_class = g_strconcat ("gnc-class-register-", style_class, NULL);
else
{
gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_VIEW);
full_class = g_strconcat (style_class, "-color", NULL);
full_class = g_strconcat ("gnc-class-user-register-", style_class, NULL);
}

gtk_style_context_add_class (stylectxt, full_class);
Expand All @@ -2590,7 +2591,7 @@ gnucash_sheet_class_init (GnucashSheetClass *klass)
widget_class = GTK_WIDGET_CLASS (klass);

#if GTK_CHECK_VERSION(3,20,0)
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(klass), "sheet");
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(klass), "gnc-id-sheet");
#endif

sheet_parent_class = g_type_class_peek_parent (klass);
Expand Down Expand Up @@ -2620,7 +2621,7 @@ gnucash_sheet_init (GnucashSheet *sheet)
gtk_widget_set_can_default (GTK_WIDGET(sheet), TRUE);

// This sets a style class for when Gtk+ version is less than 3.20
gnc_widget_set_css_name (GTK_WIDGET(sheet), "sheet");
gnc_widget_add_style_class (GTK_WIDGET(sheet), "gnc-class-sheet");

sheet->num_visible_blocks = 1;
sheet->num_visible_phys_rows = 1;
Expand Down
2 changes: 1 addition & 1 deletion gnucash/register/register-gnome/gnucash-sheet.h
Expand Up @@ -102,7 +102,7 @@ void gnucash_sheet_update_adjustments (GnucashSheet *sheet);
void gnucash_sheet_set_window (GnucashSheet *sheet, GtkWidget *window);

void gnucash_get_style_classes (GnucashSheet *sheet, GtkStyleContext *stylectxt,
RegisterColor field_type);
RegisterColor field_type, gboolean use_neg_class);

void gnucash_sheet_set_text_bounds (GnucashSheet *sheet, GdkRectangle *rect,
gint x, gint y, gint width, gint height);
Expand Down
2 changes: 1 addition & 1 deletion gnucash/register/register-gnome/gnucash-sheetP.h
Expand Up @@ -139,7 +139,7 @@ gboolean gnucash_sheet_draw_internal (GnucashSheet *sheet, cairo_t *cr,
GtkAllocation *alloc);
void gnucash_sheet_draw_cursor (GnucashCursor *cursor, cairo_t *cr);

void gnc_widget_set_css_name (GtkWidget *widget, const char *name);
void gnc_widget_add_style_class (GtkWidget *widget, const char *name);

/** @} */
#endif

0 comments on commit 0546dd5

Please sign in to comment.