From 8d8073aafa75b1492fe5f171d83539d16b98fa05 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Tue, 8 Aug 2017 17:10:21 +0100 Subject: [PATCH 01/29] Remove the rules hint from gnc-tree-view to align with current setting --- gnucash/gnome-utils/gnc-tree-view.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/gnucash/gnome-utils/gnc-tree-view.c b/gnucash/gnome-utils/gnc-tree-view.c index 3028c9984c..6e903f9b2d 100644 --- a/gnucash/gnome-utils/gnc-tree-view.c +++ b/gnucash/gnome-utils/gnc-tree-view.c @@ -247,9 +247,6 @@ gnc_tree_view_init (GncTreeView *view, GncTreeViewClass *klass) priv->sort_column_changed_cb_id = 0; priv->size_allocate_cb_id = 0; - /* Ask gtk to help the user keep track of rows. */ - g_object_set(view, "rules-hint", TRUE, NULL); - // Set the style context for this page so it can be easily manipulated with css gnc_widget_set_style_context (GTK_WIDGET(view), "GncTreeView"); From 404214b7937b7baac0b2a663c4ace4e01b067304 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Tue, 8 Aug 2017 17:17:31 +0100 Subject: [PATCH 02/29] Add CSS provider of a lesser priority than themes Add a css provider that has a lesser priority than themes so that it can be over-ridden by the theme. This may turn out to be the only one required but for now keep the application one also. --- gnucash/gnome-utils/gnc-gnome-utils.c | 10 +++++++++- gnucash/gnome-utils/ui/CMakeLists.txt | 1 + gnucash/gnome-utils/ui/Makefile.am | 3 ++- gnucash/gnome-utils/ui/gnucash-fallback.css | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gnucash/gnome-utils/ui/gnucash-fallback.css diff --git a/gnucash/gnome-utils/gnc-gnome-utils.c b/gnucash/gnome-utils/gnc-gnome-utils.c index 845f63e0d1..12fa9c250c 100644 --- a/gnucash/gnome-utils/gnc-gnome-utils.c +++ b/gnucash/gnome-utils/gnc-gnome-utils.c @@ -172,7 +172,7 @@ gnc_configure_date_completion (void) void gnc_add_css_file (void) { - GtkCssProvider *provider_user, *provider_app; + GtkCssProvider *provider_user, *provider_app, *provider_fallback; GdkDisplay *display; GdkScreen *screen; const gchar *var; @@ -182,13 +182,20 @@ gnc_add_css_file (void) provider_user = gtk_css_provider_new (); provider_app = gtk_css_provider_new (); + provider_fallback = gtk_css_provider_new (); display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); + + gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_fallback), GTK_STYLE_PROVIDER_PRIORITY_THEME - 50); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_app), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_user), GTK_STYLE_PROVIDER_PRIORITY_USER); if (pkgdatadir) { + str = g_build_filename (pkgdatadir, "ui", "gnucash-fallback.css", (char *)NULL); + gtk_css_provider_load_from_path (provider_fallback, str, &error); + g_free (str); + str = g_build_filename (pkgdatadir, "ui", "gnucash.css", (char *)NULL); gtk_css_provider_load_from_path (provider_app, str, &error); g_free (str); @@ -204,6 +211,7 @@ gnc_add_css_file (void) } g_object_unref (provider_user); g_object_unref (provider_app); + g_object_unref (provider_fallback); } #ifdef MAC_INTEGRATION diff --git a/gnucash/gnome-utils/ui/CMakeLists.txt b/gnucash/gnome-utils/ui/CMakeLists.txt index a014a1aa67..d0bfa4ab3a 100644 --- a/gnucash/gnome-utils/ui/CMakeLists.txt +++ b/gnucash/gnome-utils/ui/CMakeLists.txt @@ -16,6 +16,7 @@ SET(gnome_utils_ui_DIST_local Makefile.am osx_accel_map gnucash.css + gnucash-fallback.css ) SET_DIST_LIST(gnome_utils_ui_DIST ${gnome_utils_ui_DIST_local}) diff --git a/gnucash/gnome-utils/ui/Makefile.am b/gnucash/gnome-utils/ui/Makefile.am index 7acda83ee6..4eeeec0fa3 100644 --- a/gnucash/gnome-utils/ui/Makefile.am +++ b/gnucash/gnome-utils/ui/Makefile.am @@ -4,6 +4,7 @@ ui_DATA = \ gnc-windows-menu-ui.xml \ gnc-windows-menu-ui-quartz.xml \ osx_accel_map \ - gnucash.css + gnucash.css \ + gnucash-fallback.css EXTRA_DIST = $(ui_DATA) CMakeLists.txt diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css new file mode 100644 index 0000000000..c6d1bad746 --- /dev/null +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -0,0 +1,4 @@ +/* Note: Widgets obtained from Glade files will not be addressable + directly by name as these are not brought in when loaded, only + the widget type can be configured unless they are named in code */ + From 16a42799c02cf2e829b54e68d5b9c8bee83973bb Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Tue, 8 Aug 2017 17:22:14 +0100 Subject: [PATCH 03/29] Change the dense calender to use css so that it can be themed Change the dense calender so that it is based on css and can be made similar to the basic calender. --- gnucash/gnome-utils/gnc-dense-cal.c | 138 ++++++++++++-------- gnucash/gnome-utils/ui/gnucash-fallback.css | 13 ++ 2 files changed, 100 insertions(+), 51 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 8d2bc326df..261b44f041 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -69,11 +69,6 @@ static const int DENSE_CAL_DEFAULT_HEIGHT = 105; static const int MINOR_BORDER_SIZE = 1; static const int COL_BORDER_SIZE = 3; -static const gchar* MONTH_THIS_COLOR = "lavender"; -static const gchar* MONTH_THAT_COLOR = "SlateGray1"; - -static const gchar* MARK_COLOR = "Yellow"; - #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "gnc.gui.dense-cal" @@ -226,6 +221,10 @@ gnc_dense_cal_class_init(GncDenseCalClass *klass) object_class = G_OBJECT_CLASS (klass); widget_class = GTK_WIDGET_CLASS (klass); +#if GTK_CHECK_VERSION(3,20,0) + gtk_widget_class_set_css_name (GTK_WIDGET_CLASS(klass), "calendar"); +#endif + parent_class = g_type_class_peek_parent (klass); object_class->finalize = gnc_dense_cal_finalize; @@ -262,13 +261,17 @@ _gdc_get_view_options(void) static void gnc_dense_cal_init(GncDenseCal *dcal) { + GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(dcal)); gboolean colorAllocSuccess[MAX_COLORS]; gtk_orientable_set_orientation (GTK_ORIENTABLE(dcal), GTK_ORIENTATION_VERTICAL); // Set the style context for this widget so it can be easily manipulated with css - gnc_widget_set_style_context (GTK_WIDGET(dcal), "GncDenseCal"); + gnc_widget_set_style_context (GTK_WIDGET(dcal), "calendar"); + gtk_widget_set_name (GTK_WIDGET(dcal), "dense-cal"); + + gtk_style_context_add_class (context, GTK_STYLE_CLASS_CALENDAR); { GtkTreeModel *options; GtkCellRenderer *text_rend; @@ -300,6 +303,7 @@ gnc_dense_cal_init(GncDenseCal *dcal) gtk_box_pack_start(GTK_BOX(dcal), GTK_WIDGET(hbox), FALSE, FALSE, 0); } dcal->cal_drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new()); + gtk_widget_add_events(GTK_WIDGET(dcal->cal_drawing_area), (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -331,6 +335,8 @@ gnc_dense_cal_init(GncDenseCal *dcal) hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE); + gtk_widget_set_name (GTK_WIDGET(dcal->transPopup), "dense-cal-popup"); + l = gtk_label_new(_("Date: ")); gtk_container_add(GTK_CONTAINER(hbox), l); l = gtk_label_new("YY/MM/DD"); @@ -344,6 +350,7 @@ gnc_dense_cal_init(GncDenseCal *dcal) tree_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_data))); gtk_tree_view_insert_column_with_attributes(tree_view, -1, _("Name"), gtk_cell_renderer_text_new(), "text", 0, NULL); gtk_tree_view_insert_column_with_attributes(tree_view, -1, _("Frequency"), gtk_cell_renderer_text_new(), "text", 1, NULL); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW(tree_view)), GTK_SELECTION_NONE); g_object_set_data(G_OBJECT(dcal->transPopup), "model", tree_data); gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(tree_view)); @@ -354,12 +361,6 @@ gnc_dense_cal_init(GncDenseCal *dcal) gtk_widget_realize(GTK_WIDGET(dcal->transPopup)); } - gdk_rgba_parse(&dcal->weekColors[MONTH_THIS], MONTH_THIS_COLOR); - gdk_rgba_parse(&dcal->weekColors[MONTH_THAT], MONTH_THAT_COLOR); - - /* success array must be as big as number of colors */ - g_assert(MAX_COLORS == (sizeof(colorAllocSuccess)/sizeof(gboolean))); - /* Deal with the various label sizes. */ { PangoLayout *layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL); @@ -877,11 +878,11 @@ gnc_dense_cal_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data) g_return_val_if_fail(GNC_IS_DENSE_CAL(user_data), FALSE); dcal = GNC_DENSE_CAL(user_data); + cairo_save (cr);; cairo_set_source_surface (cr, dcal->surface, 0, 0); cairo_paint (cr); cairo_restore (cr); - return TRUE; } @@ -930,7 +931,6 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) GtkStyleContext *stylectxt; GtkStateFlags state_flags; GtkAllocation alloc; - GdkRGBA color, test_color; gint i; int maxWidth; PangoLayout *layout; @@ -949,22 +949,15 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL); LOG_AND_RESET(timer, "create_pango_layout"); - gdk_rgba_parse (&test_color, "rgba(0, 0, 0, 0)"); - gtk_widget_get_allocation (GTK_WIDGET(dcal->cal_drawing_area), &alloc); - stylectxt = gtk_widget_get_style_context (widget); + stylectxt = gtk_widget_get_style_context (GTK_WIDGET(dcal->cal_drawing_area)); state_flags = gtk_style_context_get_state (stylectxt); - gnc_style_context_get_background_color (stylectxt, state_flags, &color); - // test for no color set - if (gdk_rgba_equal (&color, &test_color)) - gdk_rgba_parse (&color, "white"); + gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_CALENDAR); - cairo_set_source_rgb (cr, color.red, color.green, color.blue); - cairo_rectangle (cr, 0, 0, - cairo_image_surface_get_width (dcal->surface), - cairo_image_surface_get_height (dcal->surface)); - cairo_fill (cr); + gtk_render_background (stylectxt, cr, 0, 0, + cairo_image_surface_get_width (dcal->surface), + cairo_image_surface_get_height (dcal->surface)); /* Fill in alternating month colors. */ { @@ -978,6 +971,8 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) dcal->monthPositions[i].x = dcal->monthPositions[i].y = -1; } + gtk_style_context_save (stylectxt); + /* Paint the weeks for the upcoming N months. */ for (i = 0; i < dcal->numMonths; i++) { @@ -990,25 +985,40 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) for (mcListIter = mcList; mcListIter != NULL; mcListIter = mcListIter->next) { rect = (GdkRectangle*)mcListIter->data; - color = dcal->weekColors[ i % 2 ]; - cairo_set_source_rgb (cr, color.red, color.green, color.blue); - cairo_rectangle (cr, rect->x, rect->y, - rect->width, rect->height); - cairo_fill (cr); + + if (i % 2 == 0) + { + gtk_style_context_add_class (stylectxt, "primary"); + if (gtk_style_context_has_class (stylectxt, "secondary")) + gtk_style_context_remove_class (stylectxt, "secondary"); + } + else + { + if (gtk_style_context_has_class (stylectxt, "primary")) + gtk_style_context_remove_class (stylectxt, "primary"); + gtk_style_context_add_class (stylectxt, "secondary"); + } + gtk_render_background (stylectxt, cr, rect->x, rect->y, rect->width, rect->height); } g_list_foreach(mcList, free_rect, NULL); g_list_free(mcList); } + gtk_style_context_restore (stylectxt); } LOG_AND_RESET(timer, "alternating month colors"); + /* Highlight the marked days. */ { int i; int x1, x2, y1, y2; - gdk_rgba_parse(&color, MARK_COLOR); - cairo_set_source_rgb (cr, color.red, color.green, color.blue); + gtk_style_context_save (stylectxt); + gtk_style_context_add_class (stylectxt, "markers"); +#if GTK_CHECK_VERSION(3,22,0) + gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_VIEW); + gtk_style_context_set_state (stylectxt, GTK_STATE_FLAG_SELECTED); +#endif for (i = 0; i < dcal->numMarks; i++) { @@ -1021,21 +1031,25 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) center_y = (y1 + y2 ) / 2; radius = MIN((x2 - x1), (y2 - y1)) * .75; - cairo_arc (cr, center_x, center_y, radius, 0.0, 2 * M_PI); - cairo_fill (cr); + gtk_render_background (stylectxt, cr, center_x - radius - 2, center_y - radius, (radius * 2) + 4, radius * 2); } } + gtk_style_context_restore (stylectxt); } LOG_AND_RESET(timer, "marked days"); for (i = 0; i < num_cols(dcal); i++) { + GdkRGBA color; gint x, y, w, h; gint j; + cairo_save (cr); pango_layout_set_text(layout, "S", -1); pango_layout_get_pixel_size(layout, NULL, &dcal->dayLabelHeight); + gdk_rgba_parse (&color, "black"); + x = dcal->leftPadding + (i * (col_width(dcal) + COL_BORDER_SIZE)) + dcal->label_width; @@ -1067,20 +1081,26 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) cairo_line_to (cr, dx + 0.5, y + col_height(dcal)); cairo_stroke (cr); } + cairo_restore (cr); - /* draw the day labels */ + + /* draw the day of the week labels */ pango_layout_set_text(layout, "88", -1); pango_layout_get_pixel_size(layout, &maxWidth, NULL); if (dcal->x_scale > maxWidth) { + gtk_style_context_save (stylectxt); + gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_HEADER); + + gtk_render_background (stylectxt, cr, x, y - dcal->dayLabelHeight, (day_width(dcal) * 7) + 1, dcal->dayLabelHeight); + for (j = 0; j < 7; j++) { int day_label_width; gint label_x_offset, label_y_offset; - gint day_label_str_len = 3; + gint day_label_str_len = 4; gchar day_label_str[day_label_str_len+1]; - day_label(day_label_str, day_label_str_len, (j + dcal->week_starts_monday) % 7); pango_layout_set_text(layout, day_label_str, -1); pango_layout_get_pixel_size(layout, &day_label_width, NULL); @@ -1090,18 +1110,31 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) - (day_label_width / 2); label_y_offset = y - dcal->dayLabelHeight; pango_layout_set_text(layout, day_label_str, -1); - gtk_style_context_get_color (stylectxt, state_flags, &color); - cairo_set_source_rgb (cr, color.red, color.green, color.blue); - cairo_move_to (cr, label_x_offset, label_y_offset); - pango_cairo_show_layout (cr, layout); + gtk_render_layout (stylectxt, cr, label_x_offset, label_y_offset, layout); } + gtk_style_context_restore (stylectxt); } } LOG_AND_RESET(timer, "lines and labels"); + /* Month labels. */ { gint i; + gint x_offset = dcal->label_height - (dcal->leftPadding * 2); + + gtk_style_context_save (stylectxt); + gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_HEADER); + + for (i = 0; i < 12; i++) + { + if (dcal->monthPositions[i].x == -1) + break; + + gtk_render_background (stylectxt, cr, dcal->monthPositions[i].x + x_offset + 1, dcal->topPadding, + dcal->dayLabelHeight, col_height(dcal) + dcal->dayLabelHeight + 1); + } + for (i = 0; i < 12; i++) { guint idx; @@ -1110,19 +1143,18 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) break; idx = (dcal->month - 1 + i) % 12; pango_layout_set_text(layout, month_name(idx), -1); - cairo_save (cr); - cairo_translate (cr, dcal->leftPadding + dcal->monthPositions[i].x, - dcal->monthPositions[i].y); - cairo_move_to (cr, 0, 0); + cairo_translate (cr, dcal->monthPositions[i].x + x_offset, dcal->monthPositions[i].y); cairo_rotate (cr, -G_PI / 2.); - pango_cairo_show_layout (cr, layout); + gtk_render_layout (stylectxt, cr, 0, 0, layout); cairo_restore (cr); } + gtk_style_context_restore (stylectxt); } LOG_AND_RESET(timer, "month labels"); - /* Try the per-day strings [dates] */ + + /* Day number strings [dates] */ { GDate d, eoc; gint doc; @@ -1130,6 +1162,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) gint numW, numH; gint x1, y1, x2, y2, w, h; + gtk_style_context_save (stylectxt); + gtk_style_context_add_class (stylectxt, "day-number"); + + cairo_save (cr); g_date_set_dmy(&d, 1, dcal->month, dcal->year); eoc = d; g_date_add_months(&eoc, dcal->numMonths); @@ -1142,10 +1178,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) pango_layout_get_pixel_size(layout, &numW, &numH); w = (x2 - x1) + 1; h = (y2 - y1) + 1; - cairo_move_to (cr, x1 + (w / 2) - (numW / 2), - y1 + (h / 2) - (numH / 2)); - pango_cairo_show_layout (cr, layout); + gtk_render_layout (stylectxt, cr, x1 + (w / 2) - (numW / 2), y1 + (h / 2) - (numH / 2), layout); } + cairo_restore (cr); + gtk_style_context_restore (stylectxt); } LOG_AND_RESET(timer, "dates"); diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index c6d1bad746..df0d6fe948 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -2,3 +2,16 @@ directly by name as these are not brought in when loaded, only the widget type can be configured unless they are named in code */ + +/* These are the defaults used in the dense-cal */ +*.primary { + background-color: lavender; +} + +*.secondary { + background-color: SlateGray1; +} + +*.markers { + background-color: yellow; +} From ec8e52e87e6977d1dfba58c662bd1dd228eaa141 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 9 Aug 2017 11:29:21 +0100 Subject: [PATCH 04/29] Add a draw callback to draw a theme based up/down arrow --- gnucash/gnome-utils/dialog-utils.c | 32 ++++++++++++++++++++++++++++++ gnucash/gnome-utils/dialog-utils.h | 10 ++++++++++ 2 files changed, 42 insertions(+) diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c index 247b5d3c2c..27ef5b111d 100644 --- a/gnucash/gnome-utils/dialog-utils.c +++ b/gnucash/gnome-utils/dialog-utils.c @@ -293,6 +293,38 @@ gnc_widget_set_style_context (GtkWidget *widget, const char *gnc_class) gtk_style_context_add_class (context, gnc_class); } +/********************************************************************\ + * Draw an arrow on a Widget so it can be altered with css * + * * + * Args: widget - widget to add arrow to in the draw callback * + * cr - cairo context for the draw callback * + * direction - 0 for up, 1 for down * + * Returns: TRUE, stop other handlers being invoked for the event * +\********************************************************************/ +gboolean +gnc_draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer direction) +{ + GtkStyleContext *context = gtk_widget_get_style_context (widget); + gint width = gtk_widget_get_allocated_width (widget); + gint height = gtk_widget_get_allocated_height (widget); + gint size; + + gtk_render_background (context, cr, 0, 0, width, height); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW); + + size = MIN(width / 2, height / 2); + + if (GPOINTER_TO_INT(direction) == 0) + gtk_render_arrow (context, cr, 0, + (width - size)/2, (height - size)/2, size); + else + gtk_render_arrow (context, cr, G_PI, + (width - size)/2, (height - size)/2, size); + + return TRUE; +} + + gboolean gnc_handle_date_accelerator (GdkEventKey *event, struct tm *tm, diff --git a/gnucash/gnome-utils/dialog-utils.h b/gnucash/gnome-utils/dialog-utils.h index f311efa87a..06d7ff8a7a 100644 --- a/gnucash/gnome-utils/dialog-utils.h +++ b/gnucash/gnome-utils/dialog-utils.h @@ -88,6 +88,16 @@ GtkTreeViewGridLines gnc_tree_view_get_grid_lines_pref (void); \********************************************************************/ void gnc_widget_set_style_context (GtkWidget *widget, const char *gnc_class); +/********************************************************************\ + * Draw an arrow on a Widget so it can be altered with css * + * * + * Args: widget - widget to add arrow to in the draw callback * + * cr - cairo context for the draw callback * + * direction - 0 for up, 1 for down * + * Returns: TRUE, stop other handlers being invoked for the event * +\********************************************************************/ +gboolean gnc_draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer direction); + gboolean gnc_handle_date_accelerator (GdkEventKey *event, struct tm *tm, const char *date_str); From f7556b6094d2dcc122e24b1c5ea361a32bfee6e9 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 9 Aug 2017 11:30:10 +0100 Subject: [PATCH 05/29] Add draw arrow call back to various widgets --- gnucash/gnome-utils/gnc-cell-renderer-popup-entry.c | 3 +++ gnucash/gnome-utils/gnc-combott.c | 3 +++ gnucash/gnome-utils/gnc-date-edit.c | 3 +++ gnucash/gnome-utils/gnc-tree-view.c | 7 +++++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gnucash/gnome-utils/gnc-cell-renderer-popup-entry.c b/gnucash/gnome-utils/gnc-cell-renderer-popup-entry.c index e1e0da57fd..e9945b5b5b 100644 --- a/gnucash/gnome-utils/gnc-cell-renderer-popup-entry.c +++ b/gnucash/gnome-utils/gnc-cell-renderer-popup-entry.c @@ -111,6 +111,9 @@ gnc_popup_entry_init (GncPopupEntry *widget) arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON); gtk_widget_show (arrow); + g_signal_connect (G_OBJECT (arrow), "draw", + G_CALLBACK (gnc_draw_arrow_cb), GINT_TO_POINTER(1)); + gtk_container_add (GTK_CONTAINER (widget->button), arrow); gtk_box_pack_start (GTK_BOX (widget->hbox), widget->entry, TRUE, TRUE, 0); diff --git a/gnucash/gnome-utils/gnc-combott.c b/gnucash/gnome-utils/gnc-combott.c index ea5bfd13be..d68dfacca5 100644 --- a/gnucash/gnome-utils/gnc-combott.c +++ b/gnucash/gnome-utils/gnc-combott.c @@ -229,6 +229,9 @@ gctt_init (GncCombott *combott) arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON); + g_signal_connect (G_OBJECT (arrow), "draw", + G_CALLBACK (gnc_draw_arrow_cb), GINT_TO_POINTER(1)); + #if GTK_CHECK_VERSION(3,12,0) gtk_widget_set_margin_start (GTK_WIDGET(arrow), 5); #else diff --git a/gnucash/gnome-utils/gnc-date-edit.c b/gnucash/gnome-utils/gnc-date-edit.c index 1c9dcbee11..583043dbf0 100644 --- a/gnucash/gnome-utils/gnc-date-edit.c +++ b/gnucash/gnome-utils/gnc-date-edit.c @@ -929,6 +929,9 @@ create_children (GNCDateEdit *gde) /* Graphic for the popup button. */ arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON); + g_signal_connect (G_OBJECT (arrow), "draw", + G_CALLBACK (gnc_draw_arrow_cb), GINT_TO_POINTER(1)); + gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, FALSE, 0); gtk_widget_show (GTK_WIDGET(arrow)); diff --git a/gnucash/gnome-utils/gnc-tree-view.c b/gnucash/gnome-utils/gnc-tree-view.c index 6e903f9b2d..5999cd9e84 100644 --- a/gnucash/gnome-utils/gnc-tree-view.c +++ b/gnucash/gnome-utils/gnc-tree-view.c @@ -273,9 +273,12 @@ gnc_tree_view_init (GncTreeView *view, GncTreeViewClass *klass) /* Create the last column which contains the column selection * widget. gnc_tree_view_add_text_column will do most of the * work. */ - icon = gtk_image_new_from_icon_name ("go-down", - GTK_ICON_SIZE_SMALL_TOOLBAR); + icon = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show(icon); + + g_signal_connect (G_OBJECT (icon), "draw", + G_CALLBACK (gnc_draw_arrow_cb), GINT_TO_POINTER(1)); + gtk_widget_get_preferred_size(icon, &requisition, NULL); column = gnc_tree_view_add_text_column (view, NULL, NULL, NULL, NULL, -1, -1, NULL); From 501671dca77b05ed4136b2ae8be3c50e5889f86f Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 9 Aug 2017 11:31:04 +0100 Subject: [PATCH 06/29] Replace toggle arrow with a theme drawn one --- .../register-gnome/gnucash-item-edit.c | 55 ++++++++++++------- .../register-gnome/gnucash-item-edit.h | 3 +- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c index ac08ed3c61..236150ca9c 100644 --- a/gnucash/register/register-gnome/gnucash-item-edit.c +++ b/gnucash/register/register-gnome/gnucash-item-edit.c @@ -167,8 +167,7 @@ gnc_item_edit_init (GncItemEdit *item_edit) item_edit->popup_toggle.ebox = NULL; item_edit->popup_toggle.tbutton = NULL; - item_edit->popup_toggle.arrow_up = NULL; - item_edit->popup_toggle.arrow_down = NULL; + item_edit->popup_toggle.direction = TRUE; item_edit->popup_toggle.signals_connected = FALSE; item_edit->popup_item = NULL; @@ -333,6 +332,32 @@ unblock_toggle_signals(GncItemEdit *item_edit) } +static gboolean +draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer data) +{ + GncItemEdit *item_edit = GNC_ITEM_EDIT (data); + GtkStyleContext *context = gtk_widget_get_style_context (widget); + gint width = gtk_widget_get_allocated_width (widget); + gint height = gtk_widget_get_allocated_height (widget); + gint size; + + gtk_render_background (context, cr, 0, 0, width, height); + + gtk_style_context_add_class (context, GTK_STYLE_CLASS_ARROW); + + size = MIN(width / 2, height / 2); + + if (item_edit->popup_toggle.direction == 0) + gtk_render_arrow (context, cr, 0, + (width - size)/2, (height - size)/2, size); + else + gtk_render_arrow (context, cr, G_PI, + (width - size)/2, (height - size)/2, size); + + return FALSE; +} + + static void connect_popup_toggle_signals (GncItemEdit *item_edit) { @@ -353,6 +378,10 @@ connect_popup_toggle_signals (GncItemEdit *item_edit) G_CALLBACK(key_press_popup_cb), item_edit); + g_signal_connect_after (object, "draw", + G_CALLBACK (draw_arrow_cb), + item_edit); + item_edit->popup_toggle.signals_connected = TRUE; } @@ -507,7 +536,6 @@ GtkWidget * gnc_item_edit_new (GnucashSheet *sheet) { char *hpad_str, *vpad_str, *entry_css; - GtkWidget *box; GtkStyleContext *stylecontext; GtkCssProvider *provider; GncItemEdit *item_edit = @@ -543,17 +571,8 @@ 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.arrow_down = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON); - item_edit->popup_toggle.arrow_up = gtk_image_new_from_icon_name ("go-up", GTK_ICON_SIZE_BUTTON); - - box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_pack_start (GTK_BOX(box), GTK_WIDGET(item_edit->popup_toggle.arrow_down), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(box), GTK_WIDGET(item_edit->popup_toggle.arrow_up),FALSE, FALSE, 0); - item_edit->popup_toggle.tbutton = gtk_toggle_button_new(); - gtk_toggle_button_set_mode ( - GTK_TOGGLE_BUTTON (item_edit->popup_toggle.tbutton), FALSE); - gtk_container_add(GTK_CONTAINER(item_edit->popup_toggle.tbutton), GTK_WIDGET(box)); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (item_edit->popup_toggle.tbutton), FALSE); /* Force padding on the button to 1. keep it small @@ -576,8 +595,6 @@ gnc_item_edit_new (GnucashSheet *sheet) FALSE, TRUE, 0); gtk_widget_show_all(GTK_WIDGET(item_edit)); - gtk_widget_hide (GTK_WIDGET(item_edit->popup_toggle.arrow_up)); - return GTK_WIDGET(item_edit); } @@ -667,8 +684,8 @@ gnc_item_edit_show_popup (GncItemEdit *item_edit) unblock_toggle_signals (item_edit); } - gtk_widget_hide (item_edit->popup_toggle.arrow_down); - gtk_widget_show (item_edit->popup_toggle.arrow_up); + // set the popup arrow direction up + item_edit->popup_toggle.direction = FALSE; if (item_edit->popup_set_focus) item_edit->popup_set_focus (item_edit->popup_item, @@ -713,8 +730,8 @@ gnc_item_edit_hide_popup (GncItemEdit *item_edit) gtk_container_remove (GTK_CONTAINER(item_edit->sheet), item_edit->popup_item); - gtk_widget_hide (item_edit->popup_toggle.arrow_up); - gtk_widget_show (item_edit->popup_toggle.arrow_down); + // set the popup arrow direction down + item_edit->popup_toggle.direction = TRUE; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item_edit->popup_toggle.tbutton), FALSE); diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h index 07ded69ed9..0c394e59d0 100644 --- a/gnucash/register/register-gnome/gnucash-item-edit.h +++ b/gnucash/register/register-gnome/gnucash-item-edit.h @@ -61,8 +61,7 @@ struct _PopupToggle { GtkWidget *ebox; GtkWidget *tbutton; - GtkWidget *arrow_up; - GtkWidget *arrow_down; + gboolean direction; gboolean signals_connected; }; From 2475193120cd7e14716127850a221cb4f9b017dd Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 12 Aug 2017 13:04:55 +0100 Subject: [PATCH 07/29] Rework the negative label colour Changed the class name to negative-color and moved the default to the fallback css file. --- gnucash/gnome-utils/dialog-utils.c | 4 ++-- gnucash/gnome-utils/ui/gnucash-fallback.css | 10 +++++++++- gnucash/gnome-utils/ui/gnucash.css | 9 --------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c index 27ef5b111d..cd0d2331b1 100644 --- a/gnucash/gnome-utils/dialog-utils.c +++ b/gnucash/gnome-utils/dialog-utils.c @@ -69,9 +69,9 @@ gnc_set_label_color(GtkWidget *label, gnc_numeric value) deficit = gnc_numeric_negative_p (value); if (deficit) - gnc_widget_set_style_context (GTK_WIDGET(label), "css_red_color"); + gnc_widget_set_style_context (GTK_WIDGET(label), "negative-color"); else - gnc_widget_set_style_context (GTK_WIDGET(label), "css_default_color"); + gnc_widget_set_style_context (GTK_WIDGET(label), "default-color"); } diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index df0d6fe948..6192594bfb 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -2,8 +2,16 @@ directly by name as these are not brought in when loaded, only the widget type can be configured unless they are named in code */ +/* negative value label colors # dialog-utils.c */ +.default-color { + color: currentColor; +} -/* These are the defaults used in the dense-cal */ +.negative-color { + color: rgb(75%, 0%, 0%); +} + +/* These are the defaults used in # gnc-dense-cal.c */ *.primary { background-color: lavender; } diff --git a/gnucash/gnome-utils/ui/gnucash.css b/gnucash/gnome-utils/ui/gnucash.css index 8abcb59000..0b23218235 100644 --- a/gnucash/gnome-utils/ui/gnucash.css +++ b/gnucash/gnome-utils/ui/gnucash.css @@ -15,15 +15,6 @@ background-color: DarkSeaGreen1; } -/* label colors # dialog-utils.c */ -.css_default_color { - color: currentColor; -} - -.css_red_color { - color: rgb(75%, 0%, 0%); -} - /* Set the grid lines to be solid # gnc-tree-view-split-reg.c */ .treeview_grid_lines { border-color: black; From f034fd6467534ce042d770ef61f1c962f4392f29 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 12 Aug 2017 13:06:25 +0100 Subject: [PATCH 08/29] Change the account treeview to use the css negative color --- gnucash/gnome-utils/gnc-tree-model-account.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c index ded9207bb2..d78f45c6f0 100644 --- a/gnucash/gnome-utils/gnc-tree-model-account.c +++ b/gnucash/gnome-utils/gnc-tree-model-account.c @@ -106,6 +106,17 @@ typedef struct GncTreeModelAccountPrivate /************************************************************/ /* Account Tree Model - Misc Functions */ /************************************************************/ +static gchar* +get_negative_color (void) +{ + GdkRGBA color; + GtkWidget *label = gtk_label_new ("Color"); + GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(label)); + gtk_style_context_add_class (context, "negative-color"); + gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); + + return gdk_rgba_to_string (&color);; +} /** Tell the GncTreeModelAccount code to update the color that it will * use for negative numbers. This function will iterate over all @@ -124,7 +135,7 @@ gnc_tree_model_account_update_color (gpointer gsettings, gchar *key, gpointer us model = user_data; priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED); - priv->negative_color = use_red ? "red" : NULL; + priv->negative_color = use_red ? get_negative_color () : NULL; } /************************************************************/ /* g_object required functions */ @@ -205,7 +216,7 @@ gnc_tree_model_account_init (GncTreeModelAccount *model) priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); priv->book = NULL; priv->root = NULL; - priv->negative_color = red ? "red" : NULL; + priv->negative_color = red ? get_negative_color () : NULL; gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED, gnc_tree_model_account_update_color, From 94841d9e6492f8141adfadfd5bf94a968c8febde Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sat, 12 Aug 2017 13:07:28 +0100 Subject: [PATCH 09/29] The summary bar never respected the use of a negative colour Changed the summary bar to use the css negative colour if required. This involved adding a boolean columns to the model for the result of checking values for being negative and changing to use the 'markup' property to display the negative values in the negative colour. --- gnucash/gnome-utils/window-main-summarybar.c | 126 +++++++++++++++++-- 1 file changed, 117 insertions(+), 9 deletions(-) diff --git a/gnucash/gnome-utils/window-main-summarybar.c b/gnucash/gnome-utils/window-main-summarybar.c index 10a5dbd7c7..a809d7c6ab 100644 --- a/gnucash/gnome-utils/window-main-summarybar.c +++ b/gnucash/gnome-utils/window-main-summarybar.c @@ -47,6 +47,8 @@ typedef struct int component_id; int cnxn_id; gboolean combo_popped; + gboolean show_negative_color; + gchar *negative_color; } GNCMainSummary; #define WINDOW_SUMMARYBAR_CM_CLASS "summary-bar" @@ -327,6 +329,8 @@ enum COLUMN_ASSETS_VALUE, COLUMN_PROFITS, COLUMN_PROFITS_VALUE, + COLUMN_ASSETS_NEG, + COLUMN_PROFITS_NEG, N_COLUMNS }; @@ -417,8 +421,10 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary) COLUMN_MNEMONIC_TYPE, total_mode_label, COLUMN_ASSETS, _("Net Assets:"), COLUMN_ASSETS_VALUE, asset_amount_string, + COLUMN_ASSETS_NEG, gnc_numeric_negative_p(currency_accum->assets), COLUMN_PROFITS, _("Profits:"), COLUMN_PROFITS_VALUE, profit_amount_string, + COLUMN_PROFITS_NEG, gnc_numeric_negative_p(currency_accum->profits), -1); g_free(total_mode_label); } @@ -439,12 +445,48 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary) g_list_free(currency_list); } +static gchar* +get_negative_color (void) +{ + GdkRGBA color; + GdkRGBA *rgba; + gchar *color_str; + GtkWidget *label = gtk_label_new ("Color"); + GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(label)); + gtk_style_context_add_class (context, "negative-color"); + gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); + rgba = gdk_rgba_copy (&color); + + color_str = g_strdup_printf ("#%02X%02X%02X", + (int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.), + (int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.), + (int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.)); + gdk_rgba_free (rgba); + return color_str; +} + +static void +summarybar_update_color (gpointer gsettings, gchar *key, gpointer user_data) +{ + GNCMainSummary *summary = user_data; + + summary->negative_color = get_negative_color(); + summary->show_negative_color = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED); + + gnc_main_window_summary_refresh (summary); +} + static void gnc_main_window_summary_destroy_cb(GNCMainSummary *summary, gpointer data) { gnc_prefs_remove_cb_by_id (GNC_PREFS_GROUP, summary->cnxn_id); gnc_unregister_gui_component(summary->component_id); - g_free(summary); + + gnc_prefs_remove_cb_by_func(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED, + summarybar_update_color, summary); + + g_free (summary->negative_color); + g_free (summary); } static void @@ -461,12 +503,57 @@ prefs_changed_cb (gpointer prefs, gchar *pref, gpointer user_data) gnc_main_window_summary_refresh(summary); } +static gchar* +check_string_for_markup (gchar *string) +{ + gchar **strings; + gchar *ret_string = g_strdup (string); + + if (g_strrstr (ret_string, "&") != NULL) + { + strings = g_strsplit (ret_string, "&", -1); + g_free (ret_string); + ret_string = g_strjoinv ("&", strings); + g_strfreev (strings); + } + if (g_strrstr (ret_string, "<") != NULL) + { + strings = g_strsplit (ret_string, "<", -1); + g_free (ret_string); + ret_string = g_strjoinv ("<", strings); + g_strfreev (strings); + } + if (g_strrstr (ret_string, ">") != NULL) + { + strings = g_strsplit (ret_string, ">", -1); + g_free (ret_string); + ret_string = g_strjoinv (">", strings); + g_strfreev (strings); + } + if (g_strrstr (ret_string, "\"") != NULL) + { + strings = g_strsplit (ret_string, "\"", -1); + g_free (ret_string); + ret_string = g_strjoinv (""", strings); + g_strfreev (strings); + } + if (g_strrstr (ret_string, "'") != NULL) + { + strings = g_strsplit (ret_string, "'", -1); + g_free (ret_string); + ret_string = g_strjoinv ("'", strings); + g_strfreev (strings); + } + return ret_string; +} + static void cdf (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data) { GNCMainSummary * summary = user_data; gchar *type, *assets, *assets_val, *profits, *profits_val; + gboolean assets_neg, profits_neg; gint viewcol; viewcol = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "view_column")); @@ -481,23 +568,37 @@ cdf (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model COLUMN_ASSETS, &assets, COLUMN_ASSETS_VALUE, &assets_val, COLUMN_PROFITS, &profits, - COLUMN_PROFITS_VALUE, &profits_val, -1); + COLUMN_PROFITS_VALUE, &profits_val, + COLUMN_ASSETS_NEG, &assets_neg, + COLUMN_PROFITS_NEG, &profits_neg, -1); if (viewcol == 0) g_object_set (cell, "text", type, NULL); if (viewcol == 2) { - gchar *a_string = g_strconcat (assets, " ", assets_val, NULL); - g_object_set (cell, "text", a_string, NULL); + gchar *a_string, *checked_string = check_string_for_markup (assets_val); + if ((summary->show_negative_color == TRUE) && (assets_neg == TRUE)) + a_string = g_strconcat (assets, " ", checked_string, "", NULL); + else + a_string = g_strconcat (assets, " ", checked_string, NULL); + + g_object_set (cell, "markup", a_string, NULL); g_free (a_string); + g_free (checked_string); } if (viewcol == 4) { - gchar *p_string = g_strconcat (profits, " ", profits_val, NULL); - g_object_set (cell, "text", p_string, NULL); + gchar *p_string, *checked_string = check_string_for_markup (profits_val); + if ((summary->show_negative_color == TRUE) && (profits_neg == TRUE)) + p_string = g_strconcat (profits, " ", checked_string, "", NULL); + else + p_string = g_strconcat (profits, " ", checked_string, NULL); + + g_object_set (cell, "markup", p_string, NULL); g_free (p_string); + g_free (checked_string); } g_free (type); @@ -529,17 +630,24 @@ gnc_main_window_summary_new (void) G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING); + G_TYPE_STRING, + G_TYPE_BOOLEAN, + G_TYPE_BOOLEAN); retval->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_set_homogeneous (GTK_BOX (retval->hbox), FALSE); // Set the style context for this widget so it can be easily manipulated with css - gnc_widget_set_style_context (GTK_WIDGET(retval->hbox), "GncSummaryBar"); + gnc_widget_set_style_context (GTK_WIDGET(retval->hbox), "summary-bar"); retval->totals_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (retval->datamodel)); g_object_unref (retval->datamodel); + retval->negative_color = get_negative_color(); + retval->show_negative_color = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED); + gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED, + summarybar_update_color, retval); + retval->component_id = gnc_register_gui_component (WINDOW_SUMMARYBAR_CM_CLASS, summarybar_refresh_handler, NULL, retval); @@ -553,7 +661,7 @@ gnc_main_window_summary_new (void) retval->combo_popped = FALSE; - for (i = 0; i <= N_COLUMNS; i += 2) + for (i = 0; i <= N_COLUMNS - 2; i += 2) { textRenderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new()); From 3be453649da7e8c9ae901680f0ff07cde6c4d181 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 09:18:08 +0100 Subject: [PATCH 10/29] Rename css class negative-color to negative-numbers --- gnucash/gnome-utils/dialog-utils.c | 2 +- gnucash/gnome-utils/gnc-tree-model-account.c | 2 +- gnucash/gnome-utils/ui/gnucash-fallback.css | 2 +- gnucash/gnome-utils/window-main-summarybar.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c index cd0d2331b1..108a83f9fd 100644 --- a/gnucash/gnome-utils/dialog-utils.c +++ b/gnucash/gnome-utils/dialog-utils.c @@ -69,7 +69,7 @@ gnc_set_label_color(GtkWidget *label, gnc_numeric value) deficit = gnc_numeric_negative_p (value); if (deficit) - gnc_widget_set_style_context (GTK_WIDGET(label), "negative-color"); + gnc_widget_set_style_context (GTK_WIDGET(label), "negative-numbers"); else gnc_widget_set_style_context (GTK_WIDGET(label), "default-color"); } diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c index d78f45c6f0..2b8558c07f 100644 --- a/gnucash/gnome-utils/gnc-tree-model-account.c +++ b/gnucash/gnome-utils/gnc-tree-model-account.c @@ -112,7 +112,7 @@ get_negative_color (void) GdkRGBA color; GtkWidget *label = gtk_label_new ("Color"); GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(label)); - gtk_style_context_add_class (context, "negative-color"); + gtk_style_context_add_class (context, "negative-numbers"); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); return gdk_rgba_to_string (&color);; diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 6192594bfb..865f833380 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -7,7 +7,7 @@ color: currentColor; } -.negative-color { +.negative-numbers { color: rgb(75%, 0%, 0%); } diff --git a/gnucash/gnome-utils/window-main-summarybar.c b/gnucash/gnome-utils/window-main-summarybar.c index a809d7c6ab..f26c3ed1c2 100644 --- a/gnucash/gnome-utils/window-main-summarybar.c +++ b/gnucash/gnome-utils/window-main-summarybar.c @@ -453,7 +453,7 @@ get_negative_color (void) gchar *color_str; GtkWidget *label = gtk_label_new ("Color"); GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(label)); - gtk_style_context_add_class (context, "negative-color"); + gtk_style_context_add_class (context, "negative-numbers"); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); rgba = gdk_rgba_copy (&color); From e18d56dfc4a9ac63fcbcaae7f1b586056cabc5c4 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 17:03:20 +0100 Subject: [PATCH 11/29] Rework the Import Matcher colours to be from the fallback css file Rename the css classes used and make sure the import matcher used them. --- gnucash/gnome-utils/ui/gnucash-fallback.css | 16 +++++- gnucash/gnome-utils/ui/gnucash.css | 13 ----- gnucash/import-export/import-main-matcher.c | 57 ++++++++++++++++----- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 865f833380..81957f1a93 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -2,7 +2,21 @@ directly by name as these are not brought in when loaded, only the widget type can be configured unless they are named in code */ -/* negative value label colors # dialog-utils.c */ + +/* Import Matcher, amount of intervention required */ +.intervention-required { + background-color: brown1; +} + +.intervention-probably-required { + background-color: gold; +} + +.intervention-not-required { + background-color: DarkSeaGreen1; +} + +/* Negative value label colors */ .default-color { color: currentColor; } diff --git a/gnucash/gnome-utils/ui/gnucash.css b/gnucash/gnome-utils/ui/gnucash.css index 0b23218235..e54838a25a 100644 --- a/gnucash/gnome-utils/ui/gnucash.css +++ b/gnucash/gnome-utils/ui/gnucash.css @@ -2,19 +2,6 @@ directly by name as these are not brought in when loaded, only the widget type can be configured unless they are named in code */ -/* Import Matcher # import-main-matcher.*/ -.color_back_red { - background-color: brown1; -} - -.color_back_yellow { - background-color: gold; -} - -.color_back_green { - background-color: DarkSeaGreen1; -} - /* Set the grid lines to be solid # gnc-tree-view-split-reg.c */ .treeview_grid_lines { border-color: black; diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index cfbaa5afaa..1293b7e971 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -82,9 +82,9 @@ enum downloaded_cols NUM_DOWNLOADED_COLS }; -#define COLOR_RED "brown1" -#define COLOR_YELLOW "gold" -#define COLOR_GREEN "DarkSeaGreen1" +#define COLOR_RED_CLASS "intervention-required" +#define COLOR_YELLOW_CLASS "intervention-probably-required" +#define COLOR_GREEN_CLASS "intervention-not-required" static QofLogModule log_module = GNC_MOD_IMPORT; @@ -215,13 +215,13 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data) gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog"); box = GTK_WIDGET(gtk_builder_get_object (builder, "red")); - gnc_widget_set_style_context (GTK_WIDGET(box), "color_back_red"); + gnc_widget_set_style_context (GTK_WIDGET(box), "intervention-required"); box = GTK_WIDGET(gtk_builder_get_object (builder, "yellow")); - gnc_widget_set_style_context (GTK_WIDGET(box), "color_back_yellow"); + gnc_widget_set_style_context (GTK_WIDGET(box), "intervention-probably-required"); box = GTK_WIDGET(gtk_builder_get_object (builder, "green")); - gnc_widget_set_style_context (GTK_WIDGET(box), "color_back_green"); + gnc_widget_set_style_context (GTK_WIDGET(box), "intervention-not-required"); help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog")); gtk_window_set_transient_for(GTK_WINDOW(help_dialog), @@ -650,6 +650,35 @@ gboolean gnc_gen_trans_list_run (GNCImportMainMatcher *info) return result; } +static void +gnc_style_context_get_background_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA *c; + + g_return_if_fail (color != NULL); + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + + gtk_style_context_get (context, + state, + GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, + NULL); + *color = *c; + gdk_rgba_free (c); +} + +static gchar* +get_required_color (const gchar *class_name) +{ + GdkRGBA color; + GtkWidget *label = gtk_label_new ("Color"); + GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(label)); + gtk_style_context_add_class (context, class_name); + gnc_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &color); + return gdk_rgba_to_string (&color); +} + static void refresh_model_row (GNCImportMainMatcher *gui, GtkTreeModel *model, @@ -705,7 +734,7 @@ refresh_model_row (GNCImportMainMatcher *gui, if (gnc_import_TransInfo_is_balanced(info) == TRUE) { ro_text = _("New, already balanced"); - color = COLOR_GREEN; + color = get_required_color (COLOR_GREEN_CLASS); } else { @@ -721,7 +750,7 @@ refresh_model_row (GNCImportMainMatcher *gui, TRUE) )); if (gnc_import_TransInfo_get_destacc (info) != NULL) { - color = COLOR_GREEN; + color = get_required_color (COLOR_GREEN_CLASS); tmp = gnc_account_get_full_name (gnc_import_TransInfo_get_destacc (info)); if (gnc_import_TransInfo_get_destacc_selected_manually(info) @@ -746,7 +775,7 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = COLOR_YELLOW; + color = get_required_color (COLOR_YELLOW_CLASS); text = /* Translators: %s is the amount to be transferred. */ g_strdup_printf(_("New, UNBALANCED (need acct to transfer %s)!"), @@ -758,7 +787,7 @@ refresh_model_row (GNCImportMainMatcher *gui, case GNCImport_CLEAR: if (gnc_import_TransInfo_get_selected_match(info)) { - color = COLOR_GREEN; + color = get_required_color (COLOR_GREEN_CLASS); if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Reconcile (manual) match"); @@ -770,14 +799,14 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = COLOR_RED; + color = get_required_color (COLOR_RED_CLASS); ro_text = _("Match missing!"); } break; case GNCImport_UPDATE: if (gnc_import_TransInfo_get_selected_match(info)) { - color = COLOR_GREEN; + color = get_required_color (COLOR_GREEN_CLASS); if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Update and reconcile (manual) match"); @@ -789,12 +818,12 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = COLOR_RED; + color = get_required_color (COLOR_RED_CLASS); ro_text = _("Match missing!"); } break; case GNCImport_SKIP: - color = COLOR_RED; + color = get_required_color (COLOR_RED_CLASS); ro_text = _("Do not import (no action selected)"); break; default: From 908e3f3fc0a091569fe96401addf0a969c78b125 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 17:04:55 +0100 Subject: [PATCH 12/29] Do not set the foreground colour in Import Matcher Let the theme set the foreground colour which is more relevant on dark themes --- gnucash/import-export/import-main-matcher.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 1293b7e971..3617fd803f 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -398,10 +398,6 @@ add_text_column(GtkTreeView *view, const gchar *title, int col_num) GtkTreeViewColumn *column; renderer = gtk_cell_renderer_text_new(); - g_object_set(G_OBJECT(renderer), - "foreground", "black", - "foreground-set", TRUE, - NULL); column = gtk_tree_view_column_new_with_attributes (title, renderer, "text", col_num, @@ -481,10 +477,6 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info, "cell-background", DOWNLOADED_COL_COLOR, NULL); renderer = gtk_cell_renderer_text_new(); - g_object_set(G_OBJECT(renderer), - "foreground", "black", - "foreground-set", TRUE, - NULL); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_set_attributes(column, renderer, "text", DOWNLOADED_COL_ACTION_INFO, From ffe9a23ca5109ec9f9e0c5f39dfdfacd2d763545 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 17:05:45 +0100 Subject: [PATCH 13/29] Change the Register2 css to be from the fallback file --- gnucash/gnome-utils/gnc-tree-view-split-reg.c | 2 +- gnucash/gnome-utils/ui/gnucash-fallback.css | 6 +++++- gnucash/gnome-utils/ui/gnucash.css | 5 ----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/gnucash/gnome-utils/gnc-tree-view-split-reg.c b/gnucash/gnome-utils/gnc-tree-view-split-reg.c index ab387a98e0..91dcae221f 100644 --- a/gnucash/gnome-utils/gnc-tree-view-split-reg.c +++ b/gnucash/gnome-utils/gnc-tree-view-split-reg.c @@ -1017,7 +1017,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), "treeview_grid_lines"); + gnc_widget_set_style_context (GTK_WIDGET(view), "register2_grid_lines"); /* TreeView Grid lines */ if (view->priv->use_horizontal_lines) diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 81957f1a93..75f162d690 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -25,7 +25,11 @@ color: rgb(75%, 0%, 0%); } -/* These are the defaults used in # gnc-dense-cal.c */ +/* Register2 grid lines color */ +.register2_grid_lines { + border-color: black; +} + *.primary { background-color: lavender; } diff --git a/gnucash/gnome-utils/ui/gnucash.css b/gnucash/gnome-utils/ui/gnucash.css index e54838a25a..7d1915988f 100644 --- a/gnucash/gnome-utils/ui/gnucash.css +++ b/gnucash/gnome-utils/ui/gnucash.css @@ -2,11 +2,6 @@ directly by name as these are not brought in when loaded, only the widget type can be configured unless they are named in code */ -/* Set the grid lines to be solid # gnc-tree-view-split-reg.c */ -.treeview_grid_lines { - border-color: black; -} - /* Increase label size # dialog-account.c */ .primary_label_size { font-size: large; From cdfdfb48c15032781ecf4ad812068b2414a991c4 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 17:07:58 +0100 Subject: [PATCH 14/29] Change the css for the primary label in dialog account Renamed the css class used and moved to the fallback css file. --- gnucash/gnome-utils/dialog-account.c | 2 +- gnucash/gnome-utils/ui/gnucash-fallback.css | 7 +++++++ gnucash/gnome-utils/ui/gnucash.css | 6 ------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c index 565472c122..8cb11a557d 100644 --- a/gnucash/gnome-utils/dialog-account.c +++ b/gnucash/gnome-utils/dialog-account.c @@ -669,7 +669,7 @@ verify_children_compatible (AccountWindow *aw) gnc_label_set_alignment (label, 0.0, 0.0); /* make label large */ - gnc_widget_set_style_context (GTK_WIDGET(label), "primary_label_size"); + gnc_widget_set_style_context (GTK_WIDGET(label), "emphasize-label"); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 75f162d690..548b7ea4f7 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -30,6 +30,13 @@ border-color: black; } +/* Make Label bold and larger */ +.emphasize-label { + font-size: large; + font-weight: bold; +} + +/* The Dense Calendar defaults */ *.primary { background-color: lavender; } diff --git a/gnucash/gnome-utils/ui/gnucash.css b/gnucash/gnome-utils/ui/gnucash.css index 7d1915988f..c6d1bad746 100644 --- a/gnucash/gnome-utils/ui/gnucash.css +++ b/gnucash/gnome-utils/ui/gnucash.css @@ -2,9 +2,3 @@ directly by name as these are not brought in when loaded, only the widget type can be configured unless they are named in code */ -/* Increase label size # dialog-account.c */ -.primary_label_size { - font-size: large; - font-weight: bold; -} - From 2c5e2f7ade4e7ed85be0bcdbb20c73cb8e981409 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 17:09:29 +0100 Subject: [PATCH 15/29] These variables are not required any more in gnc-dense-cal --- gnucash/gnome-utils/gnc-dense-cal.c | 1 - gnucash/gnome-utils/gnc-dense-cal.h | 9 --------- 2 files changed, 10 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 261b44f041..a154594caf 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -262,7 +262,6 @@ static void gnc_dense_cal_init(GncDenseCal *dcal) { GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(dcal)); - gboolean colorAllocSuccess[MAX_COLORS]; gtk_orientable_set_orientation (GTK_ORIENTABLE(dcal), GTK_ORIENTATION_VERTICAL); diff --git a/gnucash/gnome-utils/gnc-dense-cal.h b/gnucash/gnome-utils/gnc-dense-cal.h index cb9f148b83..f4e0f78504 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.h +++ b/gnucash/gnome-utils/gnc-dense-cal.h @@ -44,13 +44,6 @@ typedef struct _gdc_month_coords gint x, y; } gdc_month_coords; -enum GDC_COLORS -{ - MONTH_THIS = 0, - MONTH_THAT, - MAX_COLORS -}; - struct _GncDenseCal { GtkBox widget; @@ -84,8 +77,6 @@ struct _GncDenseCal gdc_month_coords monthPositions[12]; - GdkRGBA weekColors[MAX_COLORS]; - guint label_width; guint label_height; gint dayLabelHeight; From d4a248a244083c04f6d0320a41439e4303270d7b Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Sun, 13 Aug 2017 17:10:30 +0100 Subject: [PATCH 16/29] Minor fix to gnc-tree-model-account, removal of double ; --- gnucash/gnome-utils/gnc-tree-model-account.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c index 2b8558c07f..e19ace3876 100644 --- a/gnucash/gnome-utils/gnc-tree-model-account.c +++ b/gnucash/gnome-utils/gnc-tree-model-account.c @@ -115,7 +115,7 @@ get_negative_color (void) gtk_style_context_add_class (context, "negative-numbers"); gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &color); - return gdk_rgba_to_string (&color);; + return gdk_rgba_to_string (&color); } /** Tell the GncTreeModelAccount code to update the color that it will From e8f8e561279681655c6b820e55f090c590da8c13 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 14 Aug 2017 09:27:33 +0100 Subject: [PATCH 17/29] Use the css class defines in the import matcher help dialog --- gnucash/import-export/import-main-matcher.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 3617fd803f..7ef178b113 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -215,13 +215,13 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data) gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog"); box = GTK_WIDGET(gtk_builder_get_object (builder, "red")); - gnc_widget_set_style_context (GTK_WIDGET(box), "intervention-required"); + gnc_widget_set_style_context (GTK_WIDGET(box), COLOR_RED_CLASS); box = GTK_WIDGET(gtk_builder_get_object (builder, "yellow")); - gnc_widget_set_style_context (GTK_WIDGET(box), "intervention-probably-required"); + gnc_widget_set_style_context (GTK_WIDGET(box), COLOR_YELLOW_CLASS); box = GTK_WIDGET(gtk_builder_get_object (builder, "green")); - gnc_widget_set_style_context (GTK_WIDGET(box), "intervention-not-required"); + gnc_widget_set_style_context (GTK_WIDGET(box), COLOR_GREEN_CLASS); help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog")); gtk_window_set_transient_for(GTK_WINDOW(help_dialog), From 1051847e2b03ba05e31b984e9a6089f6518f2480 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Tue, 22 Aug 2017 14:22:11 +0100 Subject: [PATCH 18/29] Use GTK_STYLE_PROVIDER_PRIORITY_FALLBACK for fallback css file --- gnucash/gnome-utils/gnc-gnome-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gnucash/gnome-utils/gnc-gnome-utils.c b/gnucash/gnome-utils/gnc-gnome-utils.c index 12fa9c250c..eefcadc971 100644 --- a/gnucash/gnome-utils/gnc-gnome-utils.c +++ b/gnucash/gnome-utils/gnc-gnome-utils.c @@ -186,7 +186,7 @@ gnc_add_css_file (void) display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); - gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_fallback), GTK_STYLE_PROVIDER_PRIORITY_THEME - 50); + gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_fallback), GTK_STYLE_PROVIDER_PRIORITY_FALLBACK); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_app), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_user), GTK_STYLE_PROVIDER_PRIORITY_USER); @@ -195,7 +195,7 @@ gnc_add_css_file (void) str = g_build_filename (pkgdatadir, "ui", "gnucash-fallback.css", (char *)NULL); gtk_css_provider_load_from_path (provider_fallback, str, &error); g_free (str); - + str = g_build_filename (pkgdatadir, "ui", "gnucash.css", (char *)NULL); gtk_css_provider_load_from_path (provider_app, str, &error); g_free (str); From 94d538d233dfd0ed447fd44c83e2bd46df69c564 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 23 Aug 2017 15:47:12 +0100 Subject: [PATCH 19/29] Change glade comment in css file --- gnucash/gnome-utils/ui/gnucash-fallback.css | 2 +- gnucash/gnome-utils/ui/gnucash.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 548b7ea4f7..0cf3cc554c 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -1,5 +1,5 @@ /* Note: Widgets obtained from Glade files will not be addressable - directly by name as these are not brought in when loaded, only + unless they have been named or have style classes added. Only the widget type can be configured unless they are named in code */ diff --git a/gnucash/gnome-utils/ui/gnucash.css b/gnucash/gnome-utils/ui/gnucash.css index c6d1bad746..c8cc0936aa 100644 --- a/gnucash/gnome-utils/ui/gnucash.css +++ b/gnucash/gnome-utils/ui/gnucash.css @@ -1,4 +1,4 @@ /* Note: Widgets obtained from Glade files will not be addressable - directly by name as these are not brought in when loaded, only + unless they have been named or have style classes added. Only the widget type can be configured unless they are named in code */ From 3a04e8b937afe1f4f72a66aaa78adaddb882c38c Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 23 Aug 2017 16:50:38 +0100 Subject: [PATCH 20/29] Fix some lines with spaces on them --- gnucash/gnome-utils/gnc-dense-cal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index a154594caf..3442e27f58 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -419,8 +419,8 @@ gnc_dense_cal_init(GncDenseCal *dcal) dcal->topPadding = 2; { - GDate now; - g_date_clear (&now, 1); + GDate now; + g_date_clear (&now, 1); gnc_gdate_set_today (&now); _gnc_dense_cal_set_month(dcal, g_date_get_month(&now), FALSE); _gnc_dense_cal_set_year(dcal, g_date_get_year(&now), FALSE); @@ -1341,7 +1341,7 @@ gnc_dense_cal_motion_notify(GtkWidget *widget, 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; @@ -1355,7 +1355,7 @@ gnc_dense_cal_motion_notify(GtkWidget *widget, gtk_widget_get_allocation(GTK_WIDGET(dcal->transPopup), &alloc); - gtk_widget_show_all(GTK_WIDGET(dcal->transPopup)); + gtk_widget_show_all(GTK_WIDGET(dcal->transPopup)); if (event->x_root + 5 + alloc.width > screen_width) win_xpos = event->x_root - 2 - alloc.width; From 4cdae2481e3c0c35d095b52dccb69b4c13a233f7 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 23 Aug 2017 16:51:59 +0100 Subject: [PATCH 21/29] Improve marker alignment depending on row height being odd or even --- gnucash/gnome-utils/gnc-dense-cal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 3442e27f58..705cd17861 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -1030,7 +1030,15 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) center_y = (y1 + y2 ) / 2; radius = MIN((x2 - x1), (y2 - y1)) * .75; - gtk_render_background (stylectxt, cr, center_x - radius - 2, center_y - radius, (radius * 2) + 4, radius * 2); + // try to compensate for row height being odd or even + if (((y2 -y1) % 2) == 0) + gtk_render_background (stylectxt, cr, + center_x - radius - 2, center_y - radius - 1, + (radius * 2) + 4, radius * 2); + else + gtk_render_background (stylectxt, cr, + center_x - radius - 2, center_y - radius, + (radius * 2) + 4, (radius * 2) + 1); } } gtk_style_context_restore (stylectxt); From efaa7dbb1a65470136f883116316e7883ea6e961 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 23 Aug 2017 16:53:34 +0100 Subject: [PATCH 22/29] Change the way dense calendar background colours are sourced Defined the three colours and function to decide if the foreground colour is light and make the colours darker. Also changed the colour of the grid to based on border colour. --- gnucash/gnome-utils/gnc-dense-cal.c | 57 ++++++++++++++++----- gnucash/gnome-utils/ui/gnucash-fallback.css | 23 +++++++-- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 705cd17861..903e98508c 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -923,6 +923,20 @@ gnc_style_context_get_border_color (GtkStyleContext *context, gdk_rgba_free (c); } +static gboolean +is_color_dark (GdkRGBA *color) +{ + gboolean is_dark = FALSE; + + // Counting the perceptive luminance - human eye favors green color... + double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue); + + if (a > 0.5) + is_dark = TRUE; + + return is_dark; +} + static void gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) { @@ -935,6 +949,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) PangoLayout *layout; GTimer *timer; cairo_t *cr; + const gchar *primary_color_class, *secondary_color_class, *marker_color_class; timer = g_timer_new(); g_debug("drawing"); @@ -958,6 +973,22 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) cairo_image_surface_get_width (dcal->surface), cairo_image_surface_get_height (dcal->surface)); + /* get the colors */ + { + GdkRGBA color; + gchar *color_extension = NULL; + + gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); + + if (is_color_dark (&color)) + color_extension = "-dark"; + + primary_color_class = g_strconcat ("primary", color_extension, NULL); + secondary_color_class = g_strconcat ("secondary", color_extension, NULL); + marker_color_class = g_strconcat ("markers", color_extension, NULL); + } + + /* Fill in alternating month colors. */ { gint i; @@ -984,20 +1015,15 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) for (mcListIter = mcList; mcListIter != NULL; mcListIter = mcListIter->next) { rect = (GdkRectangle*)mcListIter->data; + gtk_style_context_save (stylectxt); if (i % 2 == 0) - { - gtk_style_context_add_class (stylectxt, "primary"); - if (gtk_style_context_has_class (stylectxt, "secondary")) - gtk_style_context_remove_class (stylectxt, "secondary"); - } + gtk_style_context_add_class (stylectxt, primary_color_class); else - { - if (gtk_style_context_has_class (stylectxt, "primary")) - gtk_style_context_remove_class (stylectxt, "primary"); - gtk_style_context_add_class (stylectxt, "secondary"); - } + gtk_style_context_add_class (stylectxt, secondary_color_class); + gtk_render_background (stylectxt, cr, rect->x, rect->y, rect->width, rect->height); + gtk_style_context_restore (stylectxt); } g_list_foreach(mcList, free_rect, NULL); g_list_free(mcList); @@ -1013,7 +1039,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) int x1, x2, y1, y2; gtk_style_context_save (stylectxt); - gtk_style_context_add_class (stylectxt, "markers"); + gtk_style_context_add_class (stylectxt, marker_color_class); #if GTK_CHECK_VERSION(3,22,0) gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_VIEW); gtk_style_context_set_state (stylectxt, GTK_STATE_FLAG_SELECTED); @@ -1064,12 +1090,16 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) w = col_width(dcal) - COL_BORDER_SIZE - dcal->label_width; h = col_height(dcal); + gtk_style_context_save (stylectxt); + /* draw the outside border [inside the month labels] */ + gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_FRAME); + + gtk_render_frame (stylectxt, cr, x, y, w + 1, h + 1); + gnc_style_context_get_border_color (stylectxt, state_flags, &color); cairo_set_source_rgb (cr, color.red, color.green, color.blue); cairo_set_line_width (cr, 1); - cairo_rectangle (cr, x + 0.5, y + 0.5, w, h); - cairo_stroke (cr); /* draw the week separations */ for (j = 0; j < num_weeks_per_col(dcal); j++) @@ -1089,6 +1119,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) cairo_stroke (cr); } cairo_restore (cr); + gtk_style_context_restore (stylectxt); /* draw the day of the week labels */ diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 0cf3cc554c..60c69b36ec 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -37,14 +37,31 @@ } /* The Dense Calendar defaults */ +@define-color primary_bg_color lavender; +@define-color secondary_bg_color SlateGray1; +@define-color marker_bg_color yellow; + *.primary { - background-color: lavender; + background-color: @primary_bg_color; +} + +*.primary-dark { + background-color: shade (@primary_bg_color, 0.7); } *.secondary { - background-color: SlateGray1; + background-color: @secondary_bg_color; +} + +*.secondary-dark { + background-color: shade (@secondary_bg_color, 0.7); } *.markers { - background-color: yellow; + background-color: @marker_bg_color; } + +*.markers-dark { + background-color: shade (@marker_bg_color, 0.8); +} + From f7a4fa6fb03a2a3b202a409713970af33f82ac12 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 23 Aug 2017 16:58:28 +0100 Subject: [PATCH 23/29] Rename direction boolean to arrow_down --- gnucash/register/register-gnome/gnucash-item-edit.c | 8 ++++---- gnucash/register/register-gnome/gnucash-item-edit.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c index 236150ca9c..ba249dd265 100644 --- a/gnucash/register/register-gnome/gnucash-item-edit.c +++ b/gnucash/register/register-gnome/gnucash-item-edit.c @@ -167,7 +167,7 @@ gnc_item_edit_init (GncItemEdit *item_edit) item_edit->popup_toggle.ebox = NULL; item_edit->popup_toggle.tbutton = NULL; - item_edit->popup_toggle.direction = TRUE; + item_edit->popup_toggle.arrow_down = TRUE; item_edit->popup_toggle.signals_connected = FALSE; item_edit->popup_item = NULL; @@ -347,7 +347,7 @@ draw_arrow_cb (GtkWidget *widget, cairo_t *cr, gpointer data) size = MIN(width / 2, height / 2); - if (item_edit->popup_toggle.direction == 0) + if (item_edit->popup_toggle.arrow_down == 0) gtk_render_arrow (context, cr, 0, (width - size)/2, (height - size)/2, size); else @@ -685,7 +685,7 @@ gnc_item_edit_show_popup (GncItemEdit *item_edit) } // set the popup arrow direction up - item_edit->popup_toggle.direction = FALSE; + item_edit->popup_toggle.arrow_down = FALSE; if (item_edit->popup_set_focus) item_edit->popup_set_focus (item_edit->popup_item, @@ -731,7 +731,7 @@ gnc_item_edit_hide_popup (GncItemEdit *item_edit) gtk_container_remove (GTK_CONTAINER(item_edit->sheet), item_edit->popup_item); // set the popup arrow direction down - item_edit->popup_toggle.direction = TRUE; + item_edit->popup_toggle.arrow_down = TRUE; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(item_edit->popup_toggle.tbutton), FALSE); diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h index 0c394e59d0..d6b7e73369 100644 --- a/gnucash/register/register-gnome/gnucash-item-edit.h +++ b/gnucash/register/register-gnome/gnucash-item-edit.h @@ -61,7 +61,7 @@ struct _PopupToggle { GtkWidget *ebox; GtkWidget *tbutton; - gboolean direction; + gboolean arrow_down; gboolean signals_connected; }; From da9a57eef3c6a8c963237e921d533532739bb4f8 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 23 Aug 2017 17:31:42 +0100 Subject: [PATCH 24/29] Rename the colour defines to closely match the text in import matcher --- gnucash/import-export/dialog-import.glade | 6 ++-- gnucash/import-export/import-main-matcher.c | 34 ++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/gnucash/import-export/dialog-import.glade b/gnucash/import-export/dialog-import.glade index 8224c727ce..05a03da99f 100644 --- a/gnucash/import-export/dialog-import.glade +++ b/gnucash/import-export/dialog-import.glade @@ -1004,7 +1004,7 @@ - + True False @@ -1021,7 +1021,7 @@ - + True False @@ -1038,7 +1038,7 @@ - + True False diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 7ef178b113..6117c3077c 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -82,9 +82,9 @@ enum downloaded_cols NUM_DOWNLOADED_COLS }; -#define COLOR_RED_CLASS "intervention-required" -#define COLOR_YELLOW_CLASS "intervention-probably-required" -#define COLOR_GREEN_CLASS "intervention-not-required" +#define CSS_INT_REQUIRED_CLASS "intervention-required" +#define CSS_INT_PROB_REQUIRED_CLASS "intervention-probably-required" +#define CSS_INT_NOT_REQUIRED_CLASS "intervention-not-required" static QofLogModule log_module = GNC_MOD_IMPORT; @@ -214,14 +214,14 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data) gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer5"); gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog"); - box = GTK_WIDGET(gtk_builder_get_object (builder, "red")); - gnc_widget_set_style_context (GTK_WIDGET(box), COLOR_RED_CLASS); + box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_required_box")); + gnc_widget_set_style_context (GTK_WIDGET(box), CSS_INT_REQUIRED_CLASS); - box = GTK_WIDGET(gtk_builder_get_object (builder, "yellow")); - gnc_widget_set_style_context (GTK_WIDGET(box), COLOR_YELLOW_CLASS); + box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_probably_required_box")); + gnc_widget_set_style_context (GTK_WIDGET(box), CSS_INT_PROB_REQUIRED_CLASS); - box = GTK_WIDGET(gtk_builder_get_object (builder, "green")); - gnc_widget_set_style_context (GTK_WIDGET(box), COLOR_GREEN_CLASS); + box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_not_required_box")); + gnc_widget_set_style_context (GTK_WIDGET(box), CSS_INT_NOT_REQUIRED_CLASS); help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog")); gtk_window_set_transient_for(GTK_WINDOW(help_dialog), @@ -726,7 +726,7 @@ refresh_model_row (GNCImportMainMatcher *gui, if (gnc_import_TransInfo_is_balanced(info) == TRUE) { ro_text = _("New, already balanced"); - color = get_required_color (COLOR_GREEN_CLASS); + color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); } else { @@ -742,7 +742,7 @@ refresh_model_row (GNCImportMainMatcher *gui, TRUE) )); if (gnc_import_TransInfo_get_destacc (info) != NULL) { - color = get_required_color (COLOR_GREEN_CLASS); + color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); tmp = gnc_account_get_full_name (gnc_import_TransInfo_get_destacc (info)); if (gnc_import_TransInfo_get_destacc_selected_manually(info) @@ -767,7 +767,7 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = get_required_color (COLOR_YELLOW_CLASS); + color = get_required_color (CSS_INT_PROB_REQUIRED_CLASS); text = /* Translators: %s is the amount to be transferred. */ g_strdup_printf(_("New, UNBALANCED (need acct to transfer %s)!"), @@ -779,7 +779,7 @@ refresh_model_row (GNCImportMainMatcher *gui, case GNCImport_CLEAR: if (gnc_import_TransInfo_get_selected_match(info)) { - color = get_required_color (COLOR_GREEN_CLASS); + color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Reconcile (manual) match"); @@ -791,14 +791,14 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = get_required_color (COLOR_RED_CLASS); + color = get_required_color (CSS_INT_REQUIRED_CLASS); ro_text = _("Match missing!"); } break; case GNCImport_UPDATE: if (gnc_import_TransInfo_get_selected_match(info)) { - color = get_required_color (COLOR_GREEN_CLASS); + color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Update and reconcile (manual) match"); @@ -810,12 +810,12 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = get_required_color (COLOR_RED_CLASS); + color = get_required_color (CSS_INT_REQUIRED_CLASS); ro_text = _("Match missing!"); } break; case GNCImport_SKIP: - color = get_required_color (COLOR_RED_CLASS); + color = get_required_color (CSS_INT_REQUIRED_CLASS); ro_text = _("Do not import (no action selected)"); break; default: From d3e6a9c53b02d5be41ef8a9b57ac89843125161e Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Thu, 24 Aug 2017 09:02:18 +0100 Subject: [PATCH 25/29] Change comment in fallback css file for emphasize-label --- gnucash/gnome-utils/ui/gnucash-fallback.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 60c69b36ec..079c66d531 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -30,7 +30,7 @@ border-color: black; } -/* Make Label bold and larger */ +/* Make label more important */ .emphasize-label { font-size: large; font-weight: bold; From 659d3b95825d548db22c670a927c430ef6214eb3 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 28 Aug 2017 10:21:44 +0100 Subject: [PATCH 26/29] Change colour function to is_color_light in gnc-dense-cal Change colour function to is_color_light and correct syntax and also change some character strings. --- gnucash/gnome-utils/gnc-dense-cal.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 903e98508c..330eb04667 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -924,17 +924,17 @@ gnc_style_context_get_border_color (GtkStyleContext *context, } static gboolean -is_color_dark (GdkRGBA *color) +is_color_light (GdkRGBA *color) { - gboolean is_dark = FALSE; + gboolean is_light = FALSE; // Counting the perceptive luminance - human eye favors green color... double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue); if (a > 0.5) - is_dark = TRUE; + is_light = TRUE; - return is_dark; + return is_light; } static void @@ -949,7 +949,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) PangoLayout *layout; GTimer *timer; cairo_t *cr; - const gchar *primary_color_class, *secondary_color_class, *marker_color_class; + gchar *primary_color_class, *secondary_color_class, *marker_color_class; timer = g_timer_new(); g_debug("drawing"); @@ -976,16 +976,16 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) /* get the colors */ { GdkRGBA color; - gchar *color_extension = NULL; + gchar *class_extension = NULL; gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); - if (is_color_dark (&color)) - color_extension = "-dark"; + if (is_color_light (&color)) + class_extension = "-dark"; - primary_color_class = g_strconcat ("primary", color_extension, NULL); - secondary_color_class = g_strconcat ("secondary", color_extension, NULL); - marker_color_class = g_strconcat ("markers", color_extension, NULL); + primary_color_class = g_strconcat ("primary", class_extension, NULL); + secondary_color_class = g_strconcat ("secondary", class_extension, NULL); + marker_color_class = g_strconcat ("markers", class_extension, NULL); } @@ -1232,6 +1232,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) LOG_AND_RESET(timer, "queue draw"); + g_free (primary_color_class); + g_free (secondary_color_class); + g_free (marker_color_class); + g_object_unref(layout); cairo_destroy (cr); From b81a4a559d04177ba79ea4f1446dd6d8c4ac5f5a Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 28 Aug 2017 10:25:34 +0100 Subject: [PATCH 27/29] Change the background colours of the import-main-matcher Use the same procedure as that used in the dense calendar to change the background colours in the import main matcher to be based on the brightness of the foreground colour. --- gnucash/gnome-utils/ui/gnucash-fallback.css | 22 +++++- gnucash/import-export/import-main-matcher.c | 77 +++++++++++++++++---- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/gnucash/gnome-utils/ui/gnucash-fallback.css b/gnucash/gnome-utils/ui/gnucash-fallback.css index 079c66d531..21cb6164a8 100644 --- a/gnucash/gnome-utils/ui/gnucash-fallback.css +++ b/gnucash/gnome-utils/ui/gnucash-fallback.css @@ -4,16 +4,32 @@ /* Import Matcher, amount of intervention required */ +@define-color intervention-required_bg_color brown1; +@define-color intervention-probably-required_bg_color gold; +@define-color intervention-not-required_bg_color DarkSeaGreen1; + .intervention-required { - background-color: brown1; + background-color: @intervention-required_bg_color; } .intervention-probably-required { - background-color: gold; + background-color: @intervention-probably-required_bg_color; } .intervention-not-required { - background-color: DarkSeaGreen1; + background-color: @intervention-not-required_bg_color; +} + +.intervention-required-dark { + background-color: shade (@intervention-required_bg_color, 0.7); +} + +.intervention-probably-required-dark { + background-color: shade (@intervention-probably-required_bg_color, 0.8); +} + +.intervention-not-required-dark { + background-color: shade (@intervention-not-required_bg_color, 0.3); } /* Negative value label colors */ diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 6117c3077c..3157242eef 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -60,6 +60,7 @@ struct _main_matcher_info GtkTreeView *view; GNCImportSettings *user_settings; int selected_row; + gboolean dark_theme; GNCTransactionProcessedCB transaction_processed_cb; gpointer user_data; GNCImportPendingMatches *pending_matches; @@ -206,6 +207,8 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data) GNCImportMainMatcher *info = user_data; GtkBuilder *builder; GtkWidget *help_dialog, *box; + gchar *int_required_class, *int_prob_required_class, *int_not_required_class; + gchar *class_extension = NULL; builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer2"); @@ -214,14 +217,21 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data) gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer5"); gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog"); + if (info->dark_theme == TRUE) + class_extension = "-dark"; + + int_required_class = g_strconcat (CSS_INT_REQUIRED_CLASS, class_extension, NULL); + int_prob_required_class = g_strconcat (CSS_INT_PROB_REQUIRED_CLASS, class_extension, NULL); + int_not_required_class = g_strconcat (CSS_INT_NOT_REQUIRED_CLASS, class_extension, NULL); + box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_required_box")); - gnc_widget_set_style_context (GTK_WIDGET(box), CSS_INT_REQUIRED_CLASS); + gnc_widget_set_style_context (GTK_WIDGET(box), int_required_class); box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_probably_required_box")); - gnc_widget_set_style_context (GTK_WIDGET(box), CSS_INT_PROB_REQUIRED_CLASS); + gnc_widget_set_style_context (GTK_WIDGET(box), int_prob_required_class); box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_not_required_box")); - gnc_widget_set_style_context (GTK_WIDGET(box), CSS_INT_NOT_REQUIRED_CLASS); + gnc_widget_set_style_context (GTK_WIDGET(box), int_not_required_class); help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog")); gtk_window_set_transient_for(GTK_WINDOW(help_dialog), @@ -232,6 +242,10 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data) g_object_unref(G_OBJECT(builder)); + g_free (int_required_class); + g_free (int_prob_required_class); + g_free (int_not_required_class); + gtk_widget_show(help_dialog); } @@ -497,6 +511,20 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info, G_CALLBACK(gnc_gen_trans_row_changed_cb), info); } +static gboolean +is_color_light (GdkRGBA *color) +{ + gboolean is_light = FALSE; + + // Counting the perceptive luminance - human eye favors green color... + double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue); + + if (a > 0.5) + is_light = TRUE; + + return is_light; +} + GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, const gchar* heading, gboolean all_from_same_account, @@ -507,6 +535,8 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, GtkWidget *heading_label; GtkWidget *box, *pbox; gboolean show_update; + GtkStyleContext *stylectxt; + GdkRGBA color; info = g_new0 (GNCImportMainMatcher, 1); info->pending_matches = gnc_import_PendingMatches_new(); @@ -515,6 +545,10 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, info->user_settings = gnc_import_Settings_new (); gnc_import_Settings_set_match_date_hardlimit (info->user_settings, match_date_hardlimit); + stylectxt = gtk_widget_get_style_context (GTK_WIDGET(parent)); + gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); + info->dark_theme = is_color_light (&color); + /* Initialize the GtkDialog. */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_dialog"); @@ -538,7 +572,7 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, /* if (parent) gtk_window_set_transient_for (GTK_WINDOW (info->dialog), - GTK_WINDOW (parent));*/ + GTK_WINDOW (parent));*/ if (heading) gtk_label_set_text (GTK_LABEL (heading_label), heading); @@ -570,6 +604,8 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent, GtkWidget *heading_label; GtkWidget *box; gboolean show_update; + GtkStyleContext *stylectxt; + GdkRGBA color; info = g_new0 (GNCImportMainMatcher, 1); info->pending_matches = gnc_import_PendingMatches_new(); @@ -578,6 +614,10 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent, info->user_settings = gnc_import_Settings_new (); gnc_import_Settings_set_match_date_hardlimit (info->user_settings, match_date_hardlimit); + stylectxt = gtk_widget_get_style_context (GTK_WIDGET(parent)); + gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); + info->dark_theme = is_color_light (&color); + /* load the interface */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_content"); @@ -681,6 +721,8 @@ refresh_model_row (GNCImportMainMatcher *gui, GtkTreeSelection *selection; gchar *tmp, *imbalance, *text, *color; const gchar *ro_text; + gchar *int_required_class, *int_prob_required_class, *int_not_required_class; + gchar *class_extension = NULL; Split *split; g_assert (gui); g_assert (model); @@ -690,6 +732,13 @@ refresh_model_row (GNCImportMainMatcher *gui, store = GTK_LIST_STORE(model); gtk_list_store_set(store, iter, DOWNLOADED_COL_DATA, info, -1); + if (gui->dark_theme == TRUE) + class_extension = "-dark"; + + int_required_class = g_strconcat (CSS_INT_REQUIRED_CLASS, class_extension, NULL); + int_prob_required_class = g_strconcat (CSS_INT_PROB_REQUIRED_CLASS, class_extension, NULL); + int_not_required_class = g_strconcat (CSS_INT_NOT_REQUIRED_CLASS, class_extension, NULL); + /*Account:*/ split = gnc_import_TransInfo_get_fsplit (info); g_assert(split); // Must not be NULL @@ -726,7 +775,7 @@ refresh_model_row (GNCImportMainMatcher *gui, if (gnc_import_TransInfo_is_balanced(info) == TRUE) { ro_text = _("New, already balanced"); - color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); + color = get_required_color (int_not_required_class); } else { @@ -742,7 +791,7 @@ refresh_model_row (GNCImportMainMatcher *gui, TRUE) )); if (gnc_import_TransInfo_get_destacc (info) != NULL) { - color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); + color = get_required_color (int_not_required_class); tmp = gnc_account_get_full_name (gnc_import_TransInfo_get_destacc (info)); if (gnc_import_TransInfo_get_destacc_selected_manually(info) @@ -767,7 +816,7 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = get_required_color (CSS_INT_PROB_REQUIRED_CLASS); + color = get_required_color (int_prob_required_class); text = /* Translators: %s is the amount to be transferred. */ g_strdup_printf(_("New, UNBALANCED (need acct to transfer %s)!"), @@ -779,7 +828,7 @@ refresh_model_row (GNCImportMainMatcher *gui, case GNCImport_CLEAR: if (gnc_import_TransInfo_get_selected_match(info)) { - color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); + color = get_required_color (int_not_required_class); if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Reconcile (manual) match"); @@ -791,14 +840,14 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = get_required_color (CSS_INT_REQUIRED_CLASS); + color = get_required_color (int_required_class); ro_text = _("Match missing!"); } break; case GNCImport_UPDATE: if (gnc_import_TransInfo_get_selected_match(info)) { - color = get_required_color (CSS_INT_NOT_REQUIRED_CLASS); + color = get_required_color (int_not_required_class); if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Update and reconcile (manual) match"); @@ -810,12 +859,12 @@ refresh_model_row (GNCImportMainMatcher *gui, } else { - color = get_required_color (CSS_INT_REQUIRED_CLASS); + color = get_required_color (int_required_class); ro_text = _("Match missing!"); } break; case GNCImport_SKIP: - color = get_required_color (CSS_INT_REQUIRED_CLASS); + color = get_required_color (int_required_class); ro_text = _("Do not import (no action selected)"); break; default: @@ -831,6 +880,10 @@ refresh_model_row (GNCImportMainMatcher *gui, if (text) g_free(text); + g_free (int_required_class); + g_free (int_prob_required_class); + g_free (int_not_required_class); + /* Set the pixmaps */ gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_ADD, From 08d7830f7b51ffeea7513adeae6aecf66c381847 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 30 Aug 2017 11:13:26 +0100 Subject: [PATCH 28/29] Move function is_color_light to gnc-gtk-utils and rename Move is_color_light and rename to gnc_is_dark_theme and update required files where used. --- gnucash/gnome-utils/gnc-dense-cal.c | 18 ++---------------- gnucash/gnome-utils/gnc-gtk-utils.c | 19 +++++++++++++++++++ gnucash/gnome-utils/gnc-gtk-utils.h | 1 + gnucash/import-export/import-main-matcher.c | 17 +++-------------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 330eb04667..f0cd3c2376 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -25,6 +25,7 @@ #include "gnc-dense-cal.h" #include "gnc-dense-cal-model.h" #include "gnc-engine.h" +#include "gnc-gtk-utils.h" #include #include #include @@ -923,21 +924,6 @@ gnc_style_context_get_border_color (GtkStyleContext *context, gdk_rgba_free (c); } -static gboolean -is_color_light (GdkRGBA *color) -{ - gboolean is_light = FALSE; - - // Counting the perceptive luminance - human eye favors green color... - double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue); - - if (a > 0.5) - is_light = TRUE; - - return is_light; -} - -static void gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) { GtkWidget *widget; @@ -980,7 +966,7 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); - if (is_color_light (&color)) + if (gnc_is_dark_theme (&color)) class_extension = "-dark"; primary_color_class = g_strconcat ("primary", class_extension, NULL); diff --git a/gnucash/gnome-utils/gnc-gtk-utils.c b/gnucash/gnome-utils/gnc-gtk-utils.c index 4dc971e022..4db6e79d70 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.c +++ b/gnucash/gnome-utils/gnc-gtk-utils.c @@ -223,3 +223,22 @@ gnc_cbwe_require_list_item (GtkComboBox *cbwe) g_object_set_data(G_OBJECT(cbwe), CHANGED_ID, GINT_TO_POINTER(id)); } + +/** Test to see if fg_color is a light one which should be a foreground + * one and hence would be on a dark background + * + * @param fg_color The foreground color to test. + */ +gboolean +gnc_is_dark_theme (GdkRGBA *fg_color) +{ + gboolean is_dark = FALSE; + + // Counting the perceptive luminance - human eye favors green color... + double lightness = (0.299 * fg_color->red + 0.587 * fg_color->green + 0.114 * fg_color->blue); + + if (lightness > 0.5) + is_dark = TRUE; + + return is_dark; +} diff --git a/gnucash/gnome-utils/gnc-gtk-utils.h b/gnucash/gnome-utils/gnc-gtk-utils.h index d2b0a1a557..d75b9cbab7 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.h +++ b/gnucash/gnome-utils/gnc-gtk-utils.h @@ -45,6 +45,7 @@ void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text); void gnc_cbwe_add_completion (GtkComboBox *cbwe); void gnc_cbwe_require_list_item (GtkComboBox *cbwe); +gboolean gnc_is_dark_theme (GdkRGBA *fg_color); /** @} */ #endif /* GNC_GTK_UTILS_H */ diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 3157242eef..6bed9ccfda 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -43,6 +43,7 @@ #include "gnc-ui.h" #include "gnc-ui-util.h" #include "gnc-engine.h" +#include "gnc-gtk-utils.h" #include "import-settings.h" #include "import-match-picker.h" #include "import-backend.h" @@ -511,19 +512,7 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info, G_CALLBACK(gnc_gen_trans_row_changed_cb), info); } -static gboolean -is_color_light (GdkRGBA *color) -{ - gboolean is_light = FALSE; - // Counting the perceptive luminance - human eye favors green color... - double a = (0.299 * color->red + 0.587 * color->green + 0.114 * color->blue); - - if (a > 0.5) - is_light = TRUE; - - return is_light; -} GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, const gchar* heading, @@ -547,7 +536,7 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, stylectxt = gtk_widget_get_style_context (GTK_WIDGET(parent)); gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); - info->dark_theme = is_color_light (&color); + info->dark_theme = gnc_is_dark_theme (&color); /* Initialize the GtkDialog. */ builder = gtk_builder_new(); @@ -616,7 +605,7 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent, stylectxt = gtk_widget_get_style_context (GTK_WIDGET(parent)); gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color); - info->dark_theme = is_color_light (&color); + info->dark_theme = gnc_is_dark_theme (&color); /* load the interface */ builder = gtk_builder_new(); From 64563cae5070df7ec4056b08b17bd50362290c85 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Wed, 30 Aug 2017 11:20:47 +0100 Subject: [PATCH 29/29] Move another couple of functions used more than once to gnc-gtk-utils --- gnucash/gnome-utils/gnc-dense-cal.c | 35 ------------- gnucash/gnome-utils/gnc-gtk-utils.c | 52 +++++++++++++++++++ gnucash/gnome-utils/gnc-gtk-utils.h | 7 +++ gnucash/import-export/import-main-matcher.c | 18 ------- .../register/register-gnome/gnucash-sheet.c | 20 +------ 5 files changed, 60 insertions(+), 72 deletions(-) diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index f0cd3c2376..befb37df48 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -889,41 +889,6 @@ gnc_dense_cal_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data) #define LOG_AND_RESET(timer, msg) do { g_debug("%s: %f", msg, g_timer_elapsed(timer, NULL) * 1000.); g_timer_reset(timer); } while (0); static void -gnc_style_context_get_background_color (GtkStyleContext *context, - GtkStateFlags state, - GdkRGBA *color) -{ - GdkRGBA *c; - - g_return_if_fail (color != NULL); - g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); - - gtk_style_context_get (context, - state, - GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, - NULL); - *color = *c; - gdk_rgba_free (c); -} - -static void -gnc_style_context_get_border_color (GtkStyleContext *context, - GtkStateFlags state, - GdkRGBA *color) -{ - GdkRGBA *c; - - g_return_if_fail (color != NULL); - g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); - - gtk_style_context_get (context, - state, - GTK_STYLE_PROPERTY_BORDER_COLOR, &c, - NULL); - *color = *c; - gdk_rgba_free (c); -} - gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) { GtkWidget *widget; diff --git a/gnucash/gnome-utils/gnc-gtk-utils.c b/gnucash/gnome-utils/gnc-gtk-utils.c index 4db6e79d70..4b188b0add 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.c +++ b/gnucash/gnome-utils/gnc-gtk-utils.c @@ -242,3 +242,55 @@ gnc_is_dark_theme (GdkRGBA *fg_color) return is_dark; } + +/** Wrapper to get the background color of a widget for a given state + * + * @param context Style context of widget. + * + * @param state The stateflag of the widget. + * + * @param color The returned background color of the widget. + */ +void +gnc_style_context_get_background_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA *c; + + g_return_if_fail (color != NULL); + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + + gtk_style_context_get (context, + state, + GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, + NULL); + *color = *c; + gdk_rgba_free (c); +} + +/** Wrapper to get the border color of a widget for a given state + * + * @param context Style context of widget. + * + * @param state The stateflag of the widget. + * + * @param color The returned border color of the widget. + */ +void +gnc_style_context_get_border_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA *c; + + g_return_if_fail (color != NULL); + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + + gtk_style_context_get (context, + state, + GTK_STYLE_PROPERTY_BORDER_COLOR, &c, + NULL); + *color = *c; + gdk_rgba_free (c); +} diff --git a/gnucash/gnome-utils/gnc-gtk-utils.h b/gnucash/gnome-utils/gnc-gtk-utils.h index d75b9cbab7..6651f76f0c 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.h +++ b/gnucash/gnome-utils/gnc-gtk-utils.h @@ -46,6 +46,13 @@ void gnc_cbwe_add_completion (GtkComboBox *cbwe); void gnc_cbwe_require_list_item (GtkComboBox *cbwe); gboolean gnc_is_dark_theme (GdkRGBA *fg_color); +void gnc_style_context_get_background_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color); +void gnc_style_context_get_border_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color); + /** @} */ #endif /* GNC_GTK_UTILS_H */ diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c index 6bed9ccfda..f0908eaa01 100644 --- a/gnucash/import-export/import-main-matcher.c +++ b/gnucash/import-export/import-main-matcher.c @@ -671,24 +671,6 @@ gboolean gnc_gen_trans_list_run (GNCImportMainMatcher *info) return result; } -static void -gnc_style_context_get_background_color (GtkStyleContext *context, - GtkStateFlags state, - GdkRGBA *color) -{ - GdkRGBA *c; - - g_return_if_fail (color != NULL); - g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); - - gtk_style_context_get (context, - state, - GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, - NULL); - *color = *c; - gdk_rgba_free (c); -} - static gchar* get_required_color (const gchar *class_name) { diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c index d0cdb464fd..258e88cdec 100644 --- a/gnucash/register/register-gnome/gnucash-sheet.c +++ b/gnucash/register/register-gnome/gnucash-sheet.c @@ -37,6 +37,7 @@ #include "gnucash-sheetP.h" #include "dialog-utils.h" +#include "gnc-gtk-utils.h" #include "gnc-prefs.h" #include "gnucash-color.h" #include "gnucash-cursor.h" @@ -2330,25 +2331,6 @@ gnucash_sheet_realize_entry (GnucashSheet *sheet, GtkWidget *entry) * the register is rewritten. */ -static void -gnc_style_context_get_background_color (GtkStyleContext *context, - GtkStateFlags state, - GdkRGBA *color) -{ - GdkRGBA *c; - - g_return_if_fail (color != NULL); - g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); - - gtk_style_context_get (context, - state, - GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &c, - NULL); - *color = *c; - gdk_rgba_free (c); -} - - /** Map a cell type to a gtkrc specified color. */ GdkRGBA * get_gtkrc_color (GnucashSheet *sheet,