Merge branch 'gtk3-update5' of https://github.com/Bob-IT/gnucash

This commit is contained in:
Geert Janssens 2017-08-31 09:56:22 +02:00
commit 135055764b
24 changed files with 600 additions and 228 deletions

View File

@ -669,7 +669,7 @@ verify_children_compatible (AccountWindow *aw)
gnc_label_set_alignment (label, 0.0, 0.0); gnc_label_set_alignment (label, 0.0, 0.0);
/* make label large */ /* 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); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

View File

@ -69,9 +69,9 @@ gnc_set_label_color(GtkWidget *label, gnc_numeric value)
deficit = gnc_numeric_negative_p (value); deficit = gnc_numeric_negative_p (value);
if (deficit) if (deficit)
gnc_widget_set_style_context (GTK_WIDGET(label), "css_red_color"); gnc_widget_set_style_context (GTK_WIDGET(label), "negative-numbers");
else else
gnc_widget_set_style_context (GTK_WIDGET(label), "css_default_color"); gnc_widget_set_style_context (GTK_WIDGET(label), "default-color");
} }
@ -293,6 +293,38 @@ gnc_widget_set_style_context (GtkWidget *widget, const char *gnc_class)
gtk_style_context_add_class (context, 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 gboolean
gnc_handle_date_accelerator (GdkEventKey *event, gnc_handle_date_accelerator (GdkEventKey *event,
struct tm *tm, struct tm *tm,

View File

@ -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); 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, gboolean gnc_handle_date_accelerator (GdkEventKey *event,
struct tm *tm, struct tm *tm,
const char *date_str); const char *date_str);

View File

@ -111,6 +111,9 @@ gnc_popup_entry_init (GncPopupEntry *widget)
arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON); arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_BUTTON);
gtk_widget_show (arrow); 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_container_add (GTK_CONTAINER (widget->button), arrow);
gtk_box_pack_start (GTK_BOX (widget->hbox), widget->entry, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (widget->hbox), widget->entry, TRUE, TRUE, 0);

View File

@ -229,6 +229,9 @@ gctt_init (GncCombott *combott)
arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_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));
#if GTK_CHECK_VERSION(3,12,0) #if GTK_CHECK_VERSION(3,12,0)
gtk_widget_set_margin_start (GTK_WIDGET(arrow), 5); gtk_widget_set_margin_start (GTK_WIDGET(arrow), 5);
#else #else

View File

@ -928,6 +928,9 @@ create_children (GNCDateEdit *gde)
/* Graphic for the popup button. */ /* Graphic for the popup button. */
arrow = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_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_box_pack_start (GTK_BOX (hbox), arrow, TRUE, FALSE, 0);
gtk_widget_show (GTK_WIDGET(arrow)); gtk_widget_show (GTK_WIDGET(arrow));

View File

@ -25,6 +25,7 @@
#include "gnc-dense-cal.h" #include "gnc-dense-cal.h"
#include "gnc-dense-cal-model.h" #include "gnc-dense-cal-model.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-gtk-utils.h"
#include <glib.h> #include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -69,11 +70,6 @@ static const int DENSE_CAL_DEFAULT_HEIGHT = 105;
static const int MINOR_BORDER_SIZE = 1; static const int MINOR_BORDER_SIZE = 1;
static const int COL_BORDER_SIZE = 3; 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 #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.gui.dense-cal" #define G_LOG_DOMAIN "gnc.gui.dense-cal"
@ -226,6 +222,10 @@ gnc_dense_cal_class_init(GncDenseCalClass *klass)
object_class = G_OBJECT_CLASS (klass); object_class = G_OBJECT_CLASS (klass);
widget_class = GTK_WIDGET_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); parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_dense_cal_finalize; object_class->finalize = gnc_dense_cal_finalize;
@ -262,13 +262,16 @@ _gdc_get_view_options(void)
static void static void
gnc_dense_cal_init(GncDenseCal *dcal) gnc_dense_cal_init(GncDenseCal *dcal)
{ {
gboolean colorAllocSuccess[MAX_COLORS]; GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET(dcal));
gtk_orientable_set_orientation (GTK_ORIENTABLE(dcal), GTK_ORIENTATION_VERTICAL); 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 // 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; GtkTreeModel *options;
GtkCellRenderer *text_rend; 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); gtk_box_pack_start(GTK_BOX(dcal), GTK_WIDGET(hbox), FALSE, FALSE, 0);
} }
dcal->cal_drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new()); dcal->cal_drawing_area = GTK_DRAWING_AREA(gtk_drawing_area_new());
gtk_widget_add_events(GTK_WIDGET(dcal->cal_drawing_area), (GDK_EXPOSURE_MASK gtk_widget_add_events(GTK_WIDGET(dcal->cal_drawing_area), (GDK_EXPOSURE_MASK
| GDK_BUTTON_PRESS_MASK | GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK
@ -331,6 +335,8 @@ gnc_dense_cal_init(GncDenseCal *dcal)
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE); gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
gtk_widget_set_name (GTK_WIDGET(dcal->transPopup), "dense-cal-popup");
l = gtk_label_new(_("Date: ")); l = gtk_label_new(_("Date: "));
gtk_container_add(GTK_CONTAINER(hbox), l); gtk_container_add(GTK_CONTAINER(hbox), l);
l = gtk_label_new("YY/MM/DD"); 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))); 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, _("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_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); g_object_set_data(G_OBJECT(dcal->transPopup), "model", tree_data);
gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(tree_view)); 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)); 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. */ /* Deal with the various label sizes. */
{ {
PangoLayout *layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL); PangoLayout *layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL);
@ -877,52 +878,16 @@ gnc_dense_cal_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
g_return_val_if_fail(GNC_IS_DENSE_CAL(user_data), FALSE); g_return_val_if_fail(GNC_IS_DENSE_CAL(user_data), FALSE);
dcal = GNC_DENSE_CAL(user_data); dcal = GNC_DENSE_CAL(user_data);
cairo_save (cr);; cairo_save (cr);;
cairo_set_source_surface (cr, dcal->surface, 0, 0); cairo_set_source_surface (cr, dcal->surface, 0, 0);
cairo_paint (cr); cairo_paint (cr);
cairo_restore (cr); cairo_restore (cr);
return TRUE; return TRUE;
} }
#define LOG_AND_RESET(timer, msg) do { g_debug("%s: %f", msg, g_timer_elapsed(timer, NULL) * 1000.); g_timer_reset(timer); } while (0); #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);
}
static void static void
gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal) gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
{ {
@ -930,12 +895,12 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
GtkStyleContext *stylectxt; GtkStyleContext *stylectxt;
GtkStateFlags state_flags; GtkStateFlags state_flags;
GtkAllocation alloc; GtkAllocation alloc;
GdkRGBA color, test_color;
gint i; gint i;
int maxWidth; int maxWidth;
PangoLayout *layout; PangoLayout *layout;
GTimer *timer; GTimer *timer;
cairo_t *cr; cairo_t *cr;
gchar *primary_color_class, *secondary_color_class, *marker_color_class;
timer = g_timer_new(); timer = g_timer_new();
g_debug("drawing"); g_debug("drawing");
@ -949,22 +914,31 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL); layout = gtk_widget_create_pango_layout(GTK_WIDGET(dcal), NULL);
LOG_AND_RESET(timer, "create_pango_layout"); 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); 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); state_flags = gtk_style_context_get_state (stylectxt);
gnc_style_context_get_background_color (stylectxt, state_flags, &color);
// test for no color set gtk_style_context_add_class (stylectxt, GTK_STYLE_CLASS_CALENDAR);
if (gdk_rgba_equal (&color, &test_color))
gdk_rgba_parse (&color, "white");
cairo_set_source_rgb (cr, color.red, color.green, color.blue); gtk_render_background (stylectxt, cr, 0, 0,
cairo_rectangle (cr, 0, 0,
cairo_image_surface_get_width (dcal->surface), cairo_image_surface_get_width (dcal->surface),
cairo_image_surface_get_height (dcal->surface)); cairo_image_surface_get_height (dcal->surface));
cairo_fill (cr);
/* get the colors */
{
GdkRGBA color;
gchar *class_extension = NULL;
gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
if (gnc_is_dark_theme (&color))
class_extension = "-dark";
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);
}
/* Fill in alternating month colors. */ /* Fill in alternating month colors. */
{ {
@ -978,6 +952,8 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
dcal->monthPositions[i].x = dcal->monthPositions[i].y = -1; dcal->monthPositions[i].x = dcal->monthPositions[i].y = -1;
} }
gtk_style_context_save (stylectxt);
/* Paint the weeks for the upcoming N months. */ /* Paint the weeks for the upcoming N months. */
for (i = 0; i < dcal->numMonths; i++) for (i = 0; i < dcal->numMonths; i++)
{ {
@ -990,25 +966,35 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
for (mcListIter = mcList; mcListIter != NULL; mcListIter = mcListIter->next) for (mcListIter = mcList; mcListIter != NULL; mcListIter = mcListIter->next)
{ {
rect = (GdkRectangle*)mcListIter->data; rect = (GdkRectangle*)mcListIter->data;
color = dcal->weekColors[ i % 2 ]; gtk_style_context_save (stylectxt);
cairo_set_source_rgb (cr, color.red, color.green, color.blue);
cairo_rectangle (cr, rect->x, rect->y, if (i % 2 == 0)
rect->width, rect->height); gtk_style_context_add_class (stylectxt, primary_color_class);
cairo_fill (cr); else
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_foreach(mcList, free_rect, NULL);
g_list_free(mcList); g_list_free(mcList);
} }
gtk_style_context_restore (stylectxt);
} }
LOG_AND_RESET(timer, "alternating month colors"); LOG_AND_RESET(timer, "alternating month colors");
/* Highlight the marked days. */ /* Highlight the marked days. */
{ {
int i; int i;
int x1, x2, y1, y2; int x1, x2, y1, y2;
gdk_rgba_parse(&color, MARK_COLOR); gtk_style_context_save (stylectxt);
cairo_set_source_rgb (cr, color.red, color.green, color.blue); 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);
#endif
for (i = 0; i < dcal->numMarks; i++) for (i = 0; i < dcal->numMarks; i++)
{ {
@ -1021,21 +1007,33 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
center_y = (y1 + y2 ) / 2; center_y = (y1 + y2 ) / 2;
radius = MIN((x2 - x1), (y2 - y1)) * .75; radius = MIN((x2 - x1), (y2 - y1)) * .75;
cairo_arc (cr, center_x, center_y, radius, 0.0, 2 * M_PI); // try to compensate for row height being odd or even
cairo_fill (cr); 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);
} }
LOG_AND_RESET(timer, "marked days"); LOG_AND_RESET(timer, "marked days");
for (i = 0; i < num_cols(dcal); i++) for (i = 0; i < num_cols(dcal); i++)
{ {
GdkRGBA color;
gint x, y, w, h; gint x, y, w, h;
gint j; gint j;
cairo_save (cr);
pango_layout_set_text(layout, "S", -1); pango_layout_set_text(layout, "S", -1);
pango_layout_get_pixel_size(layout, NULL, &dcal->dayLabelHeight); pango_layout_get_pixel_size(layout, NULL, &dcal->dayLabelHeight);
gdk_rgba_parse (&color, "black");
x = dcal->leftPadding x = dcal->leftPadding
+ (i * (col_width(dcal) + COL_BORDER_SIZE)) + (i * (col_width(dcal) + COL_BORDER_SIZE))
+ dcal->label_width; + dcal->label_width;
@ -1043,12 +1041,16 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
w = col_width(dcal) - COL_BORDER_SIZE - dcal->label_width; w = col_width(dcal) - COL_BORDER_SIZE - dcal->label_width;
h = col_height(dcal); h = col_height(dcal);
gtk_style_context_save (stylectxt);
/* draw the outside border [inside the month labels] */ /* 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); gnc_style_context_get_border_color (stylectxt, state_flags, &color);
cairo_set_source_rgb (cr, color.red, color.green, color.blue); cairo_set_source_rgb (cr, color.red, color.green, color.blue);
cairo_set_line_width (cr, 1); cairo_set_line_width (cr, 1);
cairo_rectangle (cr, x + 0.5, y + 0.5, w, h);
cairo_stroke (cr);
/* draw the week separations */ /* draw the week separations */
for (j = 0; j < num_weeks_per_col(dcal); j++) for (j = 0; j < num_weeks_per_col(dcal); j++)
@ -1067,20 +1069,27 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
cairo_line_to (cr, dx + 0.5, y + col_height(dcal)); cairo_line_to (cr, dx + 0.5, y + col_height(dcal));
cairo_stroke (cr); cairo_stroke (cr);
} }
cairo_restore (cr);
gtk_style_context_restore (stylectxt);
/* draw the day labels */
/* draw the day of the week labels */
pango_layout_set_text(layout, "88", -1); pango_layout_set_text(layout, "88", -1);
pango_layout_get_pixel_size(layout, &maxWidth, NULL); pango_layout_get_pixel_size(layout, &maxWidth, NULL);
if (dcal->x_scale > maxWidth) 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++) for (j = 0; j < 7; j++)
{ {
int day_label_width; int day_label_width;
gint label_x_offset, label_y_offset; 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]; gchar day_label_str[day_label_str_len+1];
day_label(day_label_str, day_label_str_len, (j + dcal->week_starts_monday) % 7); 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_set_text(layout, day_label_str, -1);
pango_layout_get_pixel_size(layout, &day_label_width, NULL); pango_layout_get_pixel_size(layout, &day_label_width, NULL);
@ -1090,18 +1099,31 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
- (day_label_width / 2); - (day_label_width / 2);
label_y_offset = y - dcal->dayLabelHeight; label_y_offset = y - dcal->dayLabelHeight;
pango_layout_set_text(layout, day_label_str, -1); pango_layout_set_text(layout, day_label_str, -1);
gtk_style_context_get_color (stylectxt, state_flags, &color); gtk_render_layout (stylectxt, cr, label_x_offset, label_y_offset, layout);
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_style_context_restore (stylectxt);
} }
} }
LOG_AND_RESET(timer, "lines and labels"); LOG_AND_RESET(timer, "lines and labels");
/* Month labels. */ /* Month labels. */
{ {
gint i; 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++) for (i = 0; i < 12; i++)
{ {
guint idx; guint idx;
@ -1110,19 +1132,18 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
break; break;
idx = (dcal->month - 1 + i) % 12; idx = (dcal->month - 1 + i) % 12;
pango_layout_set_text(layout, month_name(idx), -1); pango_layout_set_text(layout, month_name(idx), -1);
cairo_save (cr); cairo_save (cr);
cairo_translate (cr, dcal->leftPadding + dcal->monthPositions[i].x, cairo_translate (cr, dcal->monthPositions[i].x + x_offset, dcal->monthPositions[i].y);
dcal->monthPositions[i].y);
cairo_move_to (cr, 0, 0);
cairo_rotate (cr, -G_PI / 2.); cairo_rotate (cr, -G_PI / 2.);
pango_cairo_show_layout (cr, layout); gtk_render_layout (stylectxt, cr, 0, 0, layout);
cairo_restore (cr); cairo_restore (cr);
} }
gtk_style_context_restore (stylectxt);
} }
LOG_AND_RESET(timer, "month labels"); LOG_AND_RESET(timer, "month labels");
/* Try the per-day strings [dates] */
/* Day number strings [dates] */
{ {
GDate d, eoc; GDate d, eoc;
gint doc; gint doc;
@ -1130,6 +1151,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
gint numW, numH; gint numW, numH;
gint x1, y1, x2, y2, w, h; 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); g_date_set_dmy(&d, 1, dcal->month, dcal->year);
eoc = d; eoc = d;
g_date_add_months(&eoc, dcal->numMonths); g_date_add_months(&eoc, dcal->numMonths);
@ -1142,10 +1167,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
pango_layout_get_pixel_size(layout, &numW, &numH); pango_layout_get_pixel_size(layout, &numW, &numH);
w = (x2 - x1) + 1; w = (x2 - x1) + 1;
h = (y2 - y1) + 1; h = (y2 - y1) + 1;
cairo_move_to (cr, x1 + (w / 2) - (numW / 2), gtk_render_layout (stylectxt, cr, x1 + (w / 2) - (numW / 2), y1 + (h / 2) - (numH / 2), layout);
y1 + (h / 2) - (numH / 2));
pango_cairo_show_layout (cr, layout);
} }
cairo_restore (cr);
gtk_style_context_restore (stylectxt);
} }
LOG_AND_RESET(timer, "dates"); LOG_AND_RESET(timer, "dates");
@ -1158,6 +1183,10 @@ gnc_dense_cal_draw_to_buffer(GncDenseCal *dcal)
LOG_AND_RESET(timer, "queue draw"); 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); g_object_unref(layout);
cairo_destroy (cr); cairo_destroy (cr);

View File

@ -44,13 +44,6 @@ typedef struct _gdc_month_coords
gint x, y; gint x, y;
} gdc_month_coords; } gdc_month_coords;
enum GDC_COLORS
{
MONTH_THIS = 0,
MONTH_THAT,
MAX_COLORS
};
struct _GncDenseCal struct _GncDenseCal
{ {
GtkBox widget; GtkBox widget;
@ -84,8 +77,6 @@ struct _GncDenseCal
gdc_month_coords monthPositions[12]; gdc_month_coords monthPositions[12];
GdkRGBA weekColors[MAX_COLORS];
guint label_width; guint label_width;
guint label_height; guint label_height;
gint dayLabelHeight; gint dayLabelHeight;

View File

@ -172,7 +172,7 @@ gnc_configure_date_completion (void)
void void
gnc_add_css_file (void) gnc_add_css_file (void)
{ {
GtkCssProvider *provider_user, *provider_app; GtkCssProvider *provider_user, *provider_app, *provider_fallback;
GdkDisplay *display; GdkDisplay *display;
GdkScreen *screen; GdkScreen *screen;
const gchar *var; const gchar *var;
@ -182,13 +182,20 @@ gnc_add_css_file (void)
provider_user = gtk_css_provider_new (); provider_user = gtk_css_provider_new ();
provider_app = gtk_css_provider_new (); provider_app = gtk_css_provider_new ();
provider_fallback = gtk_css_provider_new ();
display = gdk_display_get_default (); display = gdk_display_get_default ();
screen = gdk_display_get_default_screen (display); screen = gdk_display_get_default_screen (display);
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_app), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_user), GTK_STYLE_PROVIDER_PRIORITY_USER); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider_user), GTK_STYLE_PROVIDER_PRIORITY_USER);
if (pkgdatadir) 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); str = g_build_filename (pkgdatadir, "ui", "gnucash.css", (char *)NULL);
gtk_css_provider_load_from_path (provider_app, str, &error); gtk_css_provider_load_from_path (provider_app, str, &error);
g_free (str); g_free (str);
@ -204,6 +211,7 @@ gnc_add_css_file (void)
} }
g_object_unref (provider_user); g_object_unref (provider_user);
g_object_unref (provider_app); g_object_unref (provider_app);
g_object_unref (provider_fallback);
} }
#ifdef MAC_INTEGRATION #ifdef MAC_INTEGRATION

View File

@ -223,3 +223,74 @@ gnc_cbwe_require_list_item (GtkComboBox *cbwe)
g_object_set_data(G_OBJECT(cbwe), CHANGED_ID, GINT_TO_POINTER(id)); 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;
}
/** 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);
}

View File

@ -45,6 +45,14 @@ void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text);
void gnc_cbwe_add_completion (GtkComboBox *cbwe); void gnc_cbwe_add_completion (GtkComboBox *cbwe);
void gnc_cbwe_require_list_item (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 */ #endif /* GNC_GTK_UTILS_H */

View File

@ -106,6 +106,17 @@ typedef struct GncTreeModelAccountPrivate
/************************************************************/ /************************************************************/
/* Account Tree Model - Misc Functions */ /* 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-numbers");
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 /** Tell the GncTreeModelAccount code to update the color that it will
* use for negative numbers. This function will iterate over all * 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; model = user_data;
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED); 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 */ /* g_object required functions */
@ -205,7 +216,7 @@ gnc_tree_model_account_init (GncTreeModelAccount *model)
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
priv->book = NULL; priv->book = NULL;
priv->root = 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_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
gnc_tree_model_account_update_color, gnc_tree_model_account_update_color,

View File

@ -1017,7 +1017,7 @@ gnc_tree_view_split_reg_new_with_model (GncTreeModelSplitReg *model)
view->help_text = g_strdup ("Help Text"); view->help_text = g_strdup ("Help Text");
/* Set the grid lines to be solid */ /* 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 */ /* TreeView Grid lines */
if (view->priv->use_horizontal_lines) if (view->priv->use_horizontal_lines)

View File

@ -247,9 +247,6 @@ gnc_tree_view_init (GncTreeView *view, GncTreeViewClass *klass)
priv->sort_column_changed_cb_id = 0; priv->sort_column_changed_cb_id = 0;
priv->size_allocate_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 // Set the style context for this page so it can be easily manipulated with css
gnc_widget_set_style_context (GTK_WIDGET(view), "GncTreeView"); gnc_widget_set_style_context (GTK_WIDGET(view), "GncTreeView");
@ -276,9 +273,12 @@ gnc_tree_view_init (GncTreeView *view, GncTreeViewClass *klass)
/* Create the last column which contains the column selection /* Create the last column which contains the column selection
* widget. gnc_tree_view_add_text_column will do most of the * widget. gnc_tree_view_add_text_column will do most of the
* work. */ * work. */
icon = gtk_image_new_from_icon_name ("go-down", icon = gtk_image_new_from_icon_name ("go-down", GTK_ICON_SIZE_SMALL_TOOLBAR);
GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_widget_show(icon); 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); gtk_widget_get_preferred_size(icon, &requisition, NULL);
column = gnc_tree_view_add_text_column (view, NULL, NULL, NULL, NULL, column = gnc_tree_view_add_text_column (view, NULL, NULL, NULL, NULL,
-1, -1, NULL); -1, -1, NULL);

View File

@ -16,6 +16,7 @@ SET(gnome_utils_ui_DIST_local
Makefile.am Makefile.am
osx_accel_map osx_accel_map
gnucash.css gnucash.css
gnucash-fallback.css
) )
SET_DIST_LIST(gnome_utils_ui_DIST ${gnome_utils_ui_DIST_local}) SET_DIST_LIST(gnome_utils_ui_DIST ${gnome_utils_ui_DIST_local})

View File

@ -4,6 +4,7 @@ ui_DATA = \
gnc-windows-menu-ui.xml \ gnc-windows-menu-ui.xml \
gnc-windows-menu-ui-quartz.xml \ gnc-windows-menu-ui-quartz.xml \
osx_accel_map \ osx_accel_map \
gnucash.css gnucash.css \
gnucash-fallback.css
EXTRA_DIST = $(ui_DATA) CMakeLists.txt EXTRA_DIST = $(ui_DATA) CMakeLists.txt

View File

@ -0,0 +1,83 @@
/* Note: Widgets obtained from Glade files will not be addressable
unless they have been named or have style classes added. Only
the widget type can be configured unless they are named in code */
/* 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: @intervention-required_bg_color;
}
.intervention-probably-required {
background-color: @intervention-probably-required_bg_color;
}
.intervention-not-required {
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 */
.default-color {
color: currentColor;
}
.negative-numbers {
color: rgb(75%, 0%, 0%);
}
/* Register2 grid lines color */
.register2_grid_lines {
border-color: black;
}
/* Make label more important */
.emphasize-label {
font-size: large;
font-weight: bold;
}
/* 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: @primary_bg_color;
}
*.primary-dark {
background-color: shade (@primary_bg_color, 0.7);
}
*.secondary {
background-color: @secondary_bg_color;
}
*.secondary-dark {
background-color: shade (@secondary_bg_color, 0.7);
}
*.markers {
background-color: @marker_bg_color;
}
*.markers-dark {
background-color: shade (@marker_bg_color, 0.8);
}

View File

@ -1,37 +1,4 @@
/* Note: Widgets obtained from Glade files will not be addressable /* 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 */ 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;
}
/* 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;
}
/* Increase label size # dialog-account.c */
.primary_label_size {
font-size: large;
font-weight: bold;
}

View File

@ -47,6 +47,8 @@ typedef struct
int component_id; int component_id;
int cnxn_id; int cnxn_id;
gboolean combo_popped; gboolean combo_popped;
gboolean show_negative_color;
gchar *negative_color;
} GNCMainSummary; } GNCMainSummary;
#define WINDOW_SUMMARYBAR_CM_CLASS "summary-bar" #define WINDOW_SUMMARYBAR_CM_CLASS "summary-bar"
@ -327,6 +329,8 @@ enum
COLUMN_ASSETS_VALUE, COLUMN_ASSETS_VALUE,
COLUMN_PROFITS, COLUMN_PROFITS,
COLUMN_PROFITS_VALUE, COLUMN_PROFITS_VALUE,
COLUMN_ASSETS_NEG,
COLUMN_PROFITS_NEG,
N_COLUMNS N_COLUMNS
}; };
@ -417,8 +421,10 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
COLUMN_MNEMONIC_TYPE, total_mode_label, COLUMN_MNEMONIC_TYPE, total_mode_label,
COLUMN_ASSETS, _("Net Assets:"), COLUMN_ASSETS, _("Net Assets:"),
COLUMN_ASSETS_VALUE, asset_amount_string, COLUMN_ASSETS_VALUE, asset_amount_string,
COLUMN_ASSETS_NEG, gnc_numeric_negative_p(currency_accum->assets),
COLUMN_PROFITS, _("Profits:"), COLUMN_PROFITS, _("Profits:"),
COLUMN_PROFITS_VALUE, profit_amount_string, COLUMN_PROFITS_VALUE, profit_amount_string,
COLUMN_PROFITS_NEG, gnc_numeric_negative_p(currency_accum->profits),
-1); -1);
g_free(total_mode_label); g_free(total_mode_label);
} }
@ -439,11 +445,47 @@ gnc_main_window_summary_refresh (GNCMainSummary * summary)
g_list_free(currency_list); 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-numbers");
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 static void
gnc_main_window_summary_destroy_cb(GNCMainSummary *summary, gpointer data) gnc_main_window_summary_destroy_cb(GNCMainSummary *summary, gpointer data)
{ {
gnc_prefs_remove_cb_by_id (GNC_PREFS_GROUP, summary->cnxn_id); gnc_prefs_remove_cb_by_id (GNC_PREFS_GROUP, summary->cnxn_id);
gnc_unregister_gui_component(summary->component_id); gnc_unregister_gui_component(summary->component_id);
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); g_free (summary);
} }
@ -461,12 +503,57 @@ prefs_changed_cb (gpointer prefs, gchar *pref, gpointer user_data)
gnc_main_window_summary_refresh(summary); 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 ("&amp;", strings);
g_strfreev (strings);
}
if (g_strrstr (ret_string, "<") != NULL)
{
strings = g_strsplit (ret_string, "<", -1);
g_free (ret_string);
ret_string = g_strjoinv ("&lt;", strings);
g_strfreev (strings);
}
if (g_strrstr (ret_string, ">") != NULL)
{
strings = g_strsplit (ret_string, ">", -1);
g_free (ret_string);
ret_string = g_strjoinv ("&gt;", strings);
g_strfreev (strings);
}
if (g_strrstr (ret_string, "\"") != NULL)
{
strings = g_strsplit (ret_string, "\"", -1);
g_free (ret_string);
ret_string = g_strjoinv ("&quot;", strings);
g_strfreev (strings);
}
if (g_strrstr (ret_string, "'") != NULL)
{
strings = g_strsplit (ret_string, "'", -1);
g_free (ret_string);
ret_string = g_strjoinv ("&apos;", strings);
g_strfreev (strings);
}
return ret_string;
}
static void static void
cdf (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, cdf (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter,
gpointer user_data) gpointer user_data)
{ {
GNCMainSummary * summary = user_data; GNCMainSummary * summary = user_data;
gchar *type, *assets, *assets_val, *profits, *profits_val; gchar *type, *assets, *assets_val, *profits, *profits_val;
gboolean assets_neg, profits_neg;
gint viewcol; gint viewcol;
viewcol = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "view_column")); 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, &assets,
COLUMN_ASSETS_VALUE, &assets_val, COLUMN_ASSETS_VALUE, &assets_val,
COLUMN_PROFITS, &profits, 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) if (viewcol == 0)
g_object_set (cell, "text", type, NULL); g_object_set (cell, "text", type, NULL);
if (viewcol == 2) if (viewcol == 2)
{ {
gchar *a_string = g_strconcat (assets, " ", assets_val, NULL); gchar *a_string, *checked_string = check_string_for_markup (assets_val);
g_object_set (cell, "text", a_string, NULL); if ((summary->show_negative_color == TRUE) && (assets_neg == TRUE))
a_string = g_strconcat (assets, " <span foreground='", summary->negative_color, "'>", checked_string, "</span>", NULL);
else
a_string = g_strconcat (assets, " ", checked_string, NULL);
g_object_set (cell, "markup", a_string, NULL);
g_free (a_string); g_free (a_string);
g_free (checked_string);
} }
if (viewcol == 4) if (viewcol == 4)
{ {
gchar *p_string = g_strconcat (profits, " ", profits_val, NULL); gchar *p_string, *checked_string = check_string_for_markup (profits_val);
g_object_set (cell, "text", p_string, NULL); if ((summary->show_negative_color == TRUE) && (profits_neg == TRUE))
p_string = g_strconcat (profits, " <span foreground='", summary->negative_color, "'>", checked_string, "</span>", NULL);
else
p_string = g_strconcat (profits, " ", checked_string, NULL);
g_object_set (cell, "markup", p_string, NULL);
g_free (p_string); g_free (p_string);
g_free (checked_string);
} }
g_free (type); 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_STRING,
G_TYPE_STRING); G_TYPE_STRING,
G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
retval->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); retval->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_set_homogeneous (GTK_BOX (retval->hbox), FALSE); gtk_box_set_homogeneous (GTK_BOX (retval->hbox), FALSE);
// Set the style context for this widget so it can be easily manipulated with css // 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)); retval->totals_combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (retval->datamodel));
g_object_unref (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, retval->component_id = gnc_register_gui_component (WINDOW_SUMMARYBAR_CM_CLASS,
summarybar_refresh_handler, summarybar_refresh_handler,
NULL, retval); NULL, retval);
@ -553,7 +661,7 @@ gnc_main_window_summary_new (void)
retval->combo_popped = FALSE; 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()); textRenderer = GTK_CELL_RENDERER(gtk_cell_renderer_text_new());

View File

@ -1004,7 +1004,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkEventBox" id="red"> <object class="GtkEventBox" id="intervention_required_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
@ -1021,7 +1021,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkEventBox" id="yellow"> <object class="GtkEventBox" id="intervention_probably_required_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
@ -1038,7 +1038,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkEventBox" id="green"> <object class="GtkEventBox" id="intervention_not_required_box">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>

View File

@ -43,6 +43,7 @@
#include "gnc-ui.h" #include "gnc-ui.h"
#include "gnc-ui-util.h" #include "gnc-ui-util.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-gtk-utils.h"
#include "import-settings.h" #include "import-settings.h"
#include "import-match-picker.h" #include "import-match-picker.h"
#include "import-backend.h" #include "import-backend.h"
@ -60,6 +61,7 @@ struct _main_matcher_info
GtkTreeView *view; GtkTreeView *view;
GNCImportSettings *user_settings; GNCImportSettings *user_settings;
int selected_row; int selected_row;
gboolean dark_theme;
GNCTransactionProcessedCB transaction_processed_cb; GNCTransactionProcessedCB transaction_processed_cb;
gpointer user_data; gpointer user_data;
GNCImportPendingMatches *pending_matches; GNCImportPendingMatches *pending_matches;
@ -82,9 +84,9 @@ enum downloaded_cols
NUM_DOWNLOADED_COLS NUM_DOWNLOADED_COLS
}; };
#define COLOR_RED "brown1" #define CSS_INT_REQUIRED_CLASS "intervention-required"
#define COLOR_YELLOW "gold" #define CSS_INT_PROB_REQUIRED_CLASS "intervention-probably-required"
#define COLOR_GREEN "DarkSeaGreen1" #define CSS_INT_NOT_REQUIRED_CLASS "intervention-not-required"
static QofLogModule log_module = GNC_MOD_IMPORT; static QofLogModule log_module = GNC_MOD_IMPORT;
@ -206,6 +208,8 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data)
GNCImportMainMatcher *info = user_data; GNCImportMainMatcher *info = user_data;
GtkBuilder *builder; GtkBuilder *builder;
GtkWidget *help_dialog, *box; GtkWidget *help_dialog, *box;
gchar *int_required_class, *int_prob_required_class, *int_not_required_class;
gchar *class_extension = NULL;
builder = gtk_builder_new(); builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer2"); gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer2");
@ -214,14 +218,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", "textbuffer5");
gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog"); gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog");
box = GTK_WIDGET(gtk_builder_get_object (builder, "red")); if (info->dark_theme == TRUE)
gnc_widget_set_style_context (GTK_WIDGET(box), "color_back_red"); class_extension = "-dark";
box = GTK_WIDGET(gtk_builder_get_object (builder, "yellow")); int_required_class = g_strconcat (CSS_INT_REQUIRED_CLASS, class_extension, NULL);
gnc_widget_set_style_context (GTK_WIDGET(box), "color_back_yellow"); 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, "green")); box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_required_box"));
gnc_widget_set_style_context (GTK_WIDGET(box), "color_back_green"); 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), int_prob_required_class);
box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_not_required_box"));
gnc_widget_set_style_context (GTK_WIDGET(box), int_not_required_class);
help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog")); help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog"));
gtk_window_set_transient_for(GTK_WINDOW(help_dialog), gtk_window_set_transient_for(GTK_WINDOW(help_dialog),
@ -232,6 +243,10 @@ on_matcher_help_clicked (GtkButton *button, gpointer user_data)
g_object_unref(G_OBJECT(builder)); 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); gtk_widget_show(help_dialog);
} }
@ -398,10 +413,6 @@ add_text_column(GtkTreeView *view, const gchar *title, int col_num)
GtkTreeViewColumn *column; GtkTreeViewColumn *column;
renderer = gtk_cell_renderer_text_new(); 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 column = gtk_tree_view_column_new_with_attributes
(title, renderer, (title, renderer,
"text", col_num, "text", col_num,
@ -481,10 +492,6 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info,
"cell-background", DOWNLOADED_COL_COLOR, "cell-background", DOWNLOADED_COL_COLOR,
NULL); NULL);
renderer = gtk_cell_renderer_text_new(); 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_pack_start(column, renderer, TRUE);
gtk_tree_view_column_set_attributes(column, renderer, gtk_tree_view_column_set_attributes(column, renderer,
"text", DOWNLOADED_COL_ACTION_INFO, "text", DOWNLOADED_COL_ACTION_INFO,
@ -505,6 +512,8 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info,
G_CALLBACK(gnc_gen_trans_row_changed_cb), info); G_CALLBACK(gnc_gen_trans_row_changed_cb), info);
} }
GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent, GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
const gchar* heading, const gchar* heading,
gboolean all_from_same_account, gboolean all_from_same_account,
@ -515,6 +524,8 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
GtkWidget *heading_label; GtkWidget *heading_label;
GtkWidget *box, *pbox; GtkWidget *box, *pbox;
gboolean show_update; gboolean show_update;
GtkStyleContext *stylectxt;
GdkRGBA color;
info = g_new0 (GNCImportMainMatcher, 1); info = g_new0 (GNCImportMainMatcher, 1);
info->pending_matches = gnc_import_PendingMatches_new(); info->pending_matches = gnc_import_PendingMatches_new();
@ -523,6 +534,10 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
info->user_settings = gnc_import_Settings_new (); info->user_settings = gnc_import_Settings_new ();
gnc_import_Settings_set_match_date_hardlimit (info->user_settings, match_date_hardlimit); 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 = gnc_is_dark_theme (&color);
/* Initialize the GtkDialog. */ /* Initialize the GtkDialog. */
builder = gtk_builder_new(); builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_dialog"); gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_dialog");
@ -578,6 +593,8 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent,
GtkWidget *heading_label; GtkWidget *heading_label;
GtkWidget *box; GtkWidget *box;
gboolean show_update; gboolean show_update;
GtkStyleContext *stylectxt;
GdkRGBA color;
info = g_new0 (GNCImportMainMatcher, 1); info = g_new0 (GNCImportMainMatcher, 1);
info->pending_matches = gnc_import_PendingMatches_new(); info->pending_matches = gnc_import_PendingMatches_new();
@ -586,6 +603,10 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent,
info->user_settings = gnc_import_Settings_new (); info->user_settings = gnc_import_Settings_new ();
gnc_import_Settings_set_match_date_hardlimit (info->user_settings, match_date_hardlimit); 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 = gnc_is_dark_theme (&color);
/* load the interface */ /* load the interface */
builder = gtk_builder_new(); builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_content"); gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_content");
@ -650,6 +671,17 @@ gboolean gnc_gen_trans_list_run (GNCImportMainMatcher *info)
return result; return result;
} }
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 static void
refresh_model_row (GNCImportMainMatcher *gui, refresh_model_row (GNCImportMainMatcher *gui,
GtkTreeModel *model, GtkTreeModel *model,
@ -660,6 +692,8 @@ refresh_model_row (GNCImportMainMatcher *gui,
GtkTreeSelection *selection; GtkTreeSelection *selection;
gchar *tmp, *imbalance, *text, *color; gchar *tmp, *imbalance, *text, *color;
const gchar *ro_text; const gchar *ro_text;
gchar *int_required_class, *int_prob_required_class, *int_not_required_class;
gchar *class_extension = NULL;
Split *split; Split *split;
g_assert (gui); g_assert (gui);
g_assert (model); g_assert (model);
@ -669,6 +703,13 @@ refresh_model_row (GNCImportMainMatcher *gui,
store = GTK_LIST_STORE(model); store = GTK_LIST_STORE(model);
gtk_list_store_set(store, iter, DOWNLOADED_COL_DATA, info, -1); 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:*/ /*Account:*/
split = gnc_import_TransInfo_get_fsplit (info); split = gnc_import_TransInfo_get_fsplit (info);
g_assert(split); // Must not be NULL g_assert(split); // Must not be NULL
@ -705,7 +746,7 @@ refresh_model_row (GNCImportMainMatcher *gui,
if (gnc_import_TransInfo_is_balanced(info) == TRUE) if (gnc_import_TransInfo_is_balanced(info) == TRUE)
{ {
ro_text = _("New, already balanced"); ro_text = _("New, already balanced");
color = COLOR_GREEN; color = get_required_color (int_not_required_class);
} }
else else
{ {
@ -721,7 +762,7 @@ refresh_model_row (GNCImportMainMatcher *gui,
TRUE) )); TRUE) ));
if (gnc_import_TransInfo_get_destacc (info) != NULL) if (gnc_import_TransInfo_get_destacc (info) != NULL)
{ {
color = COLOR_GREEN; color = get_required_color (int_not_required_class);
tmp = gnc_account_get_full_name tmp = gnc_account_get_full_name
(gnc_import_TransInfo_get_destacc (info)); (gnc_import_TransInfo_get_destacc (info));
if (gnc_import_TransInfo_get_destacc_selected_manually(info) if (gnc_import_TransInfo_get_destacc_selected_manually(info)
@ -746,7 +787,7 @@ refresh_model_row (GNCImportMainMatcher *gui,
} }
else else
{ {
color = COLOR_YELLOW; color = get_required_color (int_prob_required_class);
text = text =
/* Translators: %s is the amount to be transferred. */ /* Translators: %s is the amount to be transferred. */
g_strdup_printf(_("New, UNBALANCED (need acct to transfer %s)!"), g_strdup_printf(_("New, UNBALANCED (need acct to transfer %s)!"),
@ -758,7 +799,7 @@ refresh_model_row (GNCImportMainMatcher *gui,
case GNCImport_CLEAR: case GNCImport_CLEAR:
if (gnc_import_TransInfo_get_selected_match(info)) if (gnc_import_TransInfo_get_selected_match(info))
{ {
color = COLOR_GREEN; color = get_required_color (int_not_required_class);
if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE)
{ {
ro_text = _("Reconcile (manual) match"); ro_text = _("Reconcile (manual) match");
@ -770,14 +811,14 @@ refresh_model_row (GNCImportMainMatcher *gui,
} }
else else
{ {
color = COLOR_RED; color = get_required_color (int_required_class);
ro_text = _("Match missing!"); ro_text = _("Match missing!");
} }
break; break;
case GNCImport_UPDATE: case GNCImport_UPDATE:
if (gnc_import_TransInfo_get_selected_match(info)) if (gnc_import_TransInfo_get_selected_match(info))
{ {
color = COLOR_GREEN; color = get_required_color (int_not_required_class);
if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE)
{ {
ro_text = _("Update and reconcile (manual) match"); ro_text = _("Update and reconcile (manual) match");
@ -789,12 +830,12 @@ refresh_model_row (GNCImportMainMatcher *gui,
} }
else else
{ {
color = COLOR_RED; color = get_required_color (int_required_class);
ro_text = _("Match missing!"); ro_text = _("Match missing!");
} }
break; break;
case GNCImport_SKIP: case GNCImport_SKIP:
color = COLOR_RED; color = get_required_color (int_required_class);
ro_text = _("Do not import (no action selected)"); ro_text = _("Do not import (no action selected)");
break; break;
default: default:
@ -810,6 +851,10 @@ refresh_model_row (GNCImportMainMatcher *gui,
if (text) if (text)
g_free(text); g_free(text);
g_free (int_required_class);
g_free (int_prob_required_class);
g_free (int_not_required_class);
/* Set the pixmaps */ /* Set the pixmaps */
gtk_list_store_set(store, iter, gtk_list_store_set(store, iter,
DOWNLOADED_COL_ACTION_ADD, DOWNLOADED_COL_ACTION_ADD,

View File

@ -167,8 +167,7 @@ gnc_item_edit_init (GncItemEdit *item_edit)
item_edit->popup_toggle.ebox = NULL; item_edit->popup_toggle.ebox = NULL;
item_edit->popup_toggle.tbutton = NULL; item_edit->popup_toggle.tbutton = NULL;
item_edit->popup_toggle.arrow_up = NULL; item_edit->popup_toggle.arrow_down = TRUE;
item_edit->popup_toggle.arrow_down = NULL;
item_edit->popup_toggle.signals_connected = FALSE; item_edit->popup_toggle.signals_connected = FALSE;
item_edit->popup_item = NULL; 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.arrow_down == 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 static void
connect_popup_toggle_signals (GncItemEdit *item_edit) connect_popup_toggle_signals (GncItemEdit *item_edit)
{ {
@ -353,6 +378,10 @@ connect_popup_toggle_signals (GncItemEdit *item_edit)
G_CALLBACK(key_press_popup_cb), G_CALLBACK(key_press_popup_cb),
item_edit); item_edit);
g_signal_connect_after (object, "draw",
G_CALLBACK (draw_arrow_cb),
item_edit);
item_edit->popup_toggle.signals_connected = TRUE; item_edit->popup_toggle.signals_connected = TRUE;
} }
@ -507,7 +536,6 @@ GtkWidget *
gnc_item_edit_new (GnucashSheet *sheet) gnc_item_edit_new (GnucashSheet *sheet)
{ {
char *hpad_str, *vpad_str, *entry_css; char *hpad_str, *vpad_str, *entry_css;
GtkWidget *box;
GtkStyleContext *stylecontext; GtkStyleContext *stylecontext;
GtkCssProvider *provider; GtkCssProvider *provider;
GncItemEdit *item_edit = GncItemEdit *item_edit =
@ -543,17 +571,8 @@ gnc_item_edit_new (GnucashSheet *sheet)
/* Create the popup button /* Create the popup button
It will only be displayed when the cell being edited provides It will only be displayed when the cell being edited provides
a popup item (like a calendar or account list) */ 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(); item_edit->popup_toggle.tbutton = gtk_toggle_button_new();
gtk_toggle_button_set_mode ( gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (item_edit->popup_toggle.tbutton), FALSE);
GTK_TOGGLE_BUTTON (item_edit->popup_toggle.tbutton), FALSE);
gtk_container_add(GTK_CONTAINER(item_edit->popup_toggle.tbutton), GTK_WIDGET(box));
/* Force padding on the button to /* Force padding on the button to
1. keep it small 1. keep it small
@ -576,8 +595,6 @@ gnc_item_edit_new (GnucashSheet *sheet)
FALSE, TRUE, 0); FALSE, TRUE, 0);
gtk_widget_show_all(GTK_WIDGET(item_edit)); gtk_widget_show_all(GTK_WIDGET(item_edit));
gtk_widget_hide (GTK_WIDGET(item_edit->popup_toggle.arrow_up));
return GTK_WIDGET(item_edit); return GTK_WIDGET(item_edit);
} }
@ -667,8 +684,8 @@ gnc_item_edit_show_popup (GncItemEdit *item_edit)
unblock_toggle_signals (item_edit); unblock_toggle_signals (item_edit);
} }
gtk_widget_hide (item_edit->popup_toggle.arrow_down); // set the popup arrow direction up
gtk_widget_show (item_edit->popup_toggle.arrow_up); item_edit->popup_toggle.arrow_down = FALSE;
if (item_edit->popup_set_focus) if (item_edit->popup_set_focus)
item_edit->popup_set_focus (item_edit->popup_item, 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_container_remove (GTK_CONTAINER(item_edit->sheet), item_edit->popup_item);
gtk_widget_hide (item_edit->popup_toggle.arrow_up); // set the popup arrow direction down
gtk_widget_show (item_edit->popup_toggle.arrow_down); item_edit->popup_toggle.arrow_down = TRUE;
gtk_toggle_button_set_active gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON(item_edit->popup_toggle.tbutton), FALSE); (GTK_TOGGLE_BUTTON(item_edit->popup_toggle.tbutton), FALSE);

View File

@ -61,8 +61,7 @@ struct _PopupToggle
{ {
GtkWidget *ebox; GtkWidget *ebox;
GtkWidget *tbutton; GtkWidget *tbutton;
GtkWidget *arrow_up; gboolean arrow_down;
GtkWidget *arrow_down;
gboolean signals_connected; gboolean signals_connected;
}; };

View File

@ -37,6 +37,7 @@
#include "gnucash-sheetP.h" #include "gnucash-sheetP.h"
#include "dialog-utils.h" #include "dialog-utils.h"
#include "gnc-gtk-utils.h"
#include "gnc-prefs.h" #include "gnc-prefs.h"
#include "gnucash-color.h" #include "gnucash-color.h"
#include "gnucash-cursor.h" #include "gnucash-cursor.h"
@ -2330,25 +2331,6 @@ gnucash_sheet_realize_entry (GnucashSheet *sheet, GtkWidget *entry)
* the register is rewritten. * 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. */ /** Map a cell type to a gtkrc specified color. */
GdkRGBA * GdkRGBA *
get_gtkrc_color (GnucashSheet *sheet, get_gtkrc_color (GnucashSheet *sheet,