[planner: 17/32] Preliminary port to GtkStyleContext




commit 6c4107012a7cee3e6fedbde69cabbe74574668ac
Author: Mart Raudsepp <leio gentoo org>
Date:   Mon May 31 12:13:43 2021 +0300

    Preliminary port to GtkStyleContext
    
    Mostly one to one port from GtkStyle. In the long-run all drawing should
    be reworked to honor themes better, including work well with dark themes.
    However this makes sense to go together with various UI redesign steps,
    so just getting rid of deprecation warnings for now.
    In the sidebar case it wasn't worth porting it over, so that code is
    wrapped inside disabling of deprecation warnings until reworked.

 src/planner-gantt-background.c |  5 ++++-
 src/planner-gantt-header.c     | 43 +++++++++++++++++++++---------------------
 src/planner-gantt-row.c        |  8 ++++++--
 src/planner-sidebar.c          |  3 +++
 src/planner-usage-row.c        | 20 +++++++-------------
 5 files changed, 41 insertions(+), 38 deletions(-)
---
diff --git a/src/planner-gantt-background.c b/src/planner-gantt-background.c
index b7b9bb72..2ce4134c 100644
--- a/src/planner-gantt-background.c
+++ b/src/planner-gantt-background.c
@@ -571,6 +571,7 @@ gantt_background_draw (GnomeCanvasItem *item,
        if (priv->project_start >= t0) {
                gchar *str, *tmp;
                gint   label_width;
+               GdkRGBA text_color = { 0.0, 0.0, 0.0, 1.0 }; /* Fallback to black */
 
                /* i18n: project start, the date format is described in
                 * libmrproject/docs/DateFormat. */
@@ -585,7 +586,9 @@ gantt_background_draw (GnomeCanvasItem *item,
 
                pango_layout_get_pixel_size (priv->layout, &label_width, NULL);
 
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (GTK_WIDGET 
(item->canvas))->text[GTK_STATE_NORMAL]);
+               gtk_style_context_lookup_color (gtk_widget_get_style_context (GTK_WIDGET (item->canvas)),
+                                               "theme_text_color", &text_color);
+               gdk_cairo_set_source_rgba (cr, &text_color);
                cairo_move_to (cr, cx1 - label_width - 5 - x, 5 - y);
                pango_cairo_show_layout (cr, priv->layout);
        }
diff --git a/src/planner-gantt-header.c b/src/planner-gantt-header.c
index 19607b2e..2f776e4a 100644
--- a/src/planner-gantt-header.c
+++ b/src/planner-gantt-header.c
@@ -479,13 +479,6 @@ gantt_header_realize (GtkWidget *widget)
                                                   &attributes,
                                                   attributes_mask);
        gdk_window_set_user_data (header->priv->bin_window, widget);
-
-       /* TODO-GTK3: gtk_widget_set_style is a no-op in GTK3 */
-       gtk_widget_set_style (widget, gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window 
(widget)));
-       gdk_window_set_background (gtk_widget_get_window (widget),
-                                  &gtk_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
-       gdk_window_set_background (header->priv->bin_window,
-                                  &gtk_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
 }
 
 static void
@@ -543,6 +536,8 @@ gantt_header_draw (GtkWidget *widget,
        gchar                  *str;
        gint                    minor_width;
        gint                    major_width;
+       GdkRGBA text_color = { 0.0, 0.0, 0.0, 1.0 }; /* Fallback to black */
+       GdkRGBA insensitive_fg_color = { 0.980392, 0.976471, 0.972549, 1.000000 }; /* Fallback to #faf9f8 */
 
        header = PLANNER_GANTT_HEADER (widget);
        priv = header->priv;
@@ -560,6 +555,12 @@ gantt_header_draw (GtkWidget *widget,
        cairo_set_line_width (cr, 1.0);
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
 
+       gtk_style_context_lookup_color (gtk_widget_get_style_context (widget),
+                                       "theme_text_color", &text_color);
+       /* TODO: Use same theming methods as GtkTreeView column headers do (they end up different shade of 
grey) */
+       gtk_style_context_lookup_color (gtk_widget_get_style_context (widget),
+                                       "insensitive_fg_color", &insensitive_fg_color);
+
        t0 = floor ((priv->x1 + clip.x) / hscale + 0.5);
        t1 = floor ((priv->x1 + clip.x + clip.width) / hscale + 0.5);
 
@@ -568,19 +569,16 @@ gantt_header_draw (GtkWidget *widget,
        /* Draw background. We only draw over the exposed area, padding with +/-
         * 5 so we don't mess up the header with button edges all over.
         */
-       gtk_paint_box (gtk_widget_get_style (widget),
-                      cr,
-                      GTK_STATE_NORMAL,
-                      GTK_SHADOW_OUT,
-                      widget,
-                      "button",
-                      clip.x - 5,
-                      0,
-                      clip.width + 10,
-                      height);
+       /* TODO: Just leaving out this step seems to render OK result too - investigate */
+       gtk_render_background (gtk_widget_get_style_context (widget),
+                              cr,
+                              clip.x - 5,
+                              0,
+                              clip.width + 10,
+                              height);
 
        // Horizontal full width line between week number and date rows
-       gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->fg[GTK_STATE_INSENSITIVE]);
+       gdk_cairo_set_source_rgba (cr, &insensitive_fg_color);
        cairo_move_to (cr, clip.x + 0.5, height / 2 + 0.5);
        cairo_line_to (cr, clip.x + clip.width + 0.5, height / 2 + 0.5);
        cairo_stroke (cr);
@@ -606,7 +604,7 @@ gantt_header_draw (GtkWidget *widget,
                x = floor (t * hscale - priv->x1 + 0.5);
 
                // Vertical lines between different weeks
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->fg[GTK_STATE_INSENSITIVE]);
+               gdk_cairo_set_source_rgba (cr, &insensitive_fg_color);
                cairo_move_to (cr, x + 0.5, 0.5);
                cairo_line_to (cr, x + 0.5, height / 2 + 1);
                cairo_stroke (cr);
@@ -622,7 +620,8 @@ gantt_header_draw (GtkWidget *widget,
                cairo_save (cr);
                cairo_rectangle (cr, x, 0, major_width, height);
                cairo_clip (cr);
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->text[GTK_STATE_NORMAL]);
+
+               gdk_cairo_set_source_rgba (cr, &text_color);
                cairo_move_to (cr, x + 3, 2);
                pango_cairo_show_layout (cr, priv->layout);
                cairo_restore (cr);
@@ -644,7 +643,7 @@ gantt_header_draw (GtkWidget *widget,
                x = floor (t * hscale - priv->x1 + 0.5);
 
                // NOTE: Vertical lines between dates
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->fg[GTK_STATE_INSENSITIVE]);
+               gdk_cairo_set_source_rgba (cr, &insensitive_fg_color);
                cairo_move_to (cr, x + 0.5, height / 2 + 0.5);
                cairo_line_to (cr, x + 0.5, height + 0.5);
                cairo_stroke (cr);
@@ -660,7 +659,7 @@ gantt_header_draw (GtkWidget *widget,
                cairo_save (cr);
                cairo_rectangle (cr, x, 0, minor_width, height);
                cairo_clip (cr);
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (widget)->text[GTK_STATE_NORMAL]);
+               gdk_cairo_set_source_rgba (cr, &text_color);
                cairo_move_to (cr, x + 3, height / 2 + 2);
                pango_cairo_show_layout (cr, priv->layout);
                cairo_restore (cr);
diff --git a/src/planner-gantt-row.c b/src/planner-gantt-row.c
index 109fce95..9f16fcba 100644
--- a/src/planner-gantt-row.c
+++ b/src/planner-gantt-row.c
@@ -1734,12 +1734,16 @@ gantt_row_draw (GnomeCanvasItem *item,
        rx2 = MIN (cx2 + TEXT_PADDING + priv->text_width, width);
 
        if (priv->layout != NULL && rx1 < rx2) {
+               GdkRGBA text_color = { 0.0, 0.0, 0.0, 1.0 }; /* Fallback to black */
+
+               gtk_style_context_lookup_color (gtk_widget_get_style_context (GTK_WIDGET (item->canvas)),
+                                               "theme_text_color", &text_color);
                /* NOTE: cy1 is the pixel coordinate of the top of the bar.
                         subtract round(priv->bar_top) to bring us to the top of the row
                         add priv->height / 2 to get to the center of the row
                         subtract priv->text_height / 2 to get to the top of the text */
 
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (GTK_WIDGET 
(item->canvas))->text[GTK_STATE_NORMAL]);
+               gdk_cairo_set_source_rgba (cr, &text_color);
                cairo_move_to (cr,
                               cx2 + TEXT_PADDING,
                               cy1 - (gint)(priv->bar_top + 0.5) + (priv->height - priv->text_height) / 2);
@@ -1758,7 +1762,7 @@ gantt_row_draw (GnomeCanvasItem *item,
                        x1 += cx2 + TEXT_PADDING;
                        x2 += cx2 + TEXT_PADDING;
 
-                       gdk_cairo_set_source_color (cr, &gtk_widget_get_style (GTK_WIDGET 
(item->canvas))->text[GTK_STATE_NORMAL]);
+                       gdk_cairo_set_source_rgba (cr, &text_color);
                        cairo_move_to (cr, x1 + 0.5, cy2 + 2 + 0.5);
                        cairo_line_to (cr, x2 + 0.5, cy2 + 2 + 0.5);
                        cairo_stroke (cr);
diff --git a/src/planner-sidebar.c b/src/planner-sidebar.c
index 15d423f5..b9a1dddb 100644
--- a/src/planner-sidebar.c
+++ b/src/planner-sidebar.c
@@ -343,6 +343,8 @@ sidebar_darken_color (GdkColor *color,
 static void
 sidebar_modify_bg (PlannerSidebar *bar)
 {
+/* TODO: Handle colors without deprecated GtkStyle, while rewriting to GtkStack and co */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
        GList       *l;
        GdkColor     normal_color;
        GdkColor     prelight_color;
@@ -371,6 +373,7 @@ sidebar_modify_bg (PlannerSidebar *bar)
 
                gtk_widget_modify_fg (entry->label, GTK_STATE_NORMAL, &style->white);
        }
+G_GNUC_END_IGNORE_DEPRECATIONS
 }
 
 static void
diff --git a/src/planner-usage-row.c b/src/planner-usage-row.c
index 648e6b7b..a7001af7 100644
--- a/src/planner-usage-row.c
+++ b/src/planner-usage-row.c
@@ -949,7 +949,7 @@ usage_row_draw_resource_ival (mrptime          start,
 
        /* Interval separator. */
        if (!(chunk & ROW_START)) {
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (GTK_WIDGET (item->canvas))->white);
+               cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */
                cairo_move_to (cr, c_xstart + 0.5, rs_ystart + 0.5);
                cairo_line_to (cr, c_xstart + 0.5, rr_yend + 0.5);
                cairo_stroke (cr);
@@ -1222,18 +1222,12 @@ usage_row_draw_assignment (PlannerUsageRow *row,
         rx2 = MIN (cx2 + TEXT_PADDING + priv->text_width, width);
 
        if (priv->layout != NULL && rx1 < rx2) {
-               /* TODO-GTK3: Use the below code for color (double-check about state)
-               GtkStyleContext *context;
-               GtkStateFlags    flags;
-               GdkRGBA rgba;
-
-               context = gtk_widget_get_style_context (GTK_WIDGET (item->canvas))
-               state = gtk_widget_get_state_flags (GTK_WIDGET (item->canvas));
-               gtk_style_context_get_color (context, state, &rgba);
-               gdk_cairo_set_source_rgba (cr, &rgba);
-               */
-               /* Until then, use GtkStyle */
-               gdk_cairo_set_source_color (cr, &gtk_widget_get_style (GTK_WIDGET 
(item->canvas))->text[GTK_STATE_NORMAL]);
+               GdkRGBA text_color = { 0.0, 0.0, 0.0, 1.0 }; /* Fallback to black */
+
+               gtk_style_context_lookup_color (gtk_widget_get_style_context (GTK_WIDGET (item->canvas)),
+                                               "theme_text_color", &text_color);
+               gdk_cairo_set_source_rgba (cr, &text_color);
+
                /* FIXME: Center the text vertically? */
                cairo_move_to (cr, cx2 + TEXT_PADDING, cy1);
                pango_cairo_show_layout (cr, priv->layout);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]