[evolution/gnome-3-30] I#182 - Calendar month/year forward/backward arrows overlap



commit b7a5daa951581b88e2d1d61d924accf423b4f4c1
Author: Milan Crha <mcrha redhat com>
Date:   Wed Oct 31 11:26:28 2018 +0100

    I#182 - Calendar month/year forward/backward arrows overlap
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/182

 src/e-util/e-calendar-item.c | 32 ++++++++++++++++++++++++++++----
 src/e-util/e-calendar.c      | 43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 4 deletions(-)
---
diff --git a/src/e-util/e-calendar-item.c b/src/e-util/e-calendar-item.c
index 6708e8be04..71c454855a 100644
--- a/src/e-util/e-calendar-item.c
+++ b/src/e-util/e-calendar-item.c
@@ -245,6 +245,7 @@ enum {
        SELECTION_CHANGED,
        SELECTION_PREVIEW_CHANGED,
        MONTH_WIDTH_CHANGED,
+       CALC_MIN_COLUMN_WIDTH,
        LAST_SIGNAL
 };
 
@@ -577,6 +578,15 @@ e_calendar_item_class_init (ECalendarItemClass *class)
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE, 0);
 
+       e_calendar_item_signals[CALC_MIN_COLUMN_WIDTH] = g_signal_new (
+               "calc-min-column-width",
+               G_TYPE_FROM_CLASS (object_class),
+               G_SIGNAL_ACTION | G_SIGNAL_RUN_LAST,
+               0 /* G_STRUCT_OFFSET (ECalendarItemClass, calc_min_column_width) */,
+               NULL, NULL,
+               NULL,
+               G_TYPE_INT, 0);
+
        e_calendar_item_a11y_init ();
 }
 
@@ -679,6 +689,7 @@ e_calendar_item_get_property (GObject *object,
                               GParamSpec *pspec)
 {
        ECalendarItem *calitem;
+       gint min_column_width;
 
        calitem = E_CALENDAR_ITEM (object);
 
@@ -713,7 +724,14 @@ e_calendar_item_get_property (GObject *object,
                return;
        case PROP_COLUMN_WIDTH:
                e_calendar_item_recalc_sizes (calitem);
-               g_value_set_int (value, calitem->min_month_width);
+
+               min_column_width = 0;
+               g_signal_emit (calitem, e_calendar_item_signals[CALC_MIN_COLUMN_WIDTH], 0, &min_column_width);
+
+               if (min_column_width < calitem->min_month_width)
+                       min_column_width = calitem->min_month_width;
+
+               g_value_set_int (value, min_column_width);
                return;
        case PROP_MINIMUM_ROWS:
                g_value_set_int (value, calitem->min_rows);
@@ -936,7 +954,7 @@ e_calendar_item_update (GnomeCanvasItem *item,
        GnomeCanvasItemClass *item_class;
        ECalendarItem *calitem;
        gint char_height, width, height, space, space_per_cal, space_per_cell;
-       gint rows, cols, xthickness, ythickness, old_month_width;
+       gint rows, cols, xthickness, ythickness, old_month_width, min_column_width;
        PangoContext *pango_context;
        PangoFontMetrics *font_metrics;
        GtkStyleContext *style_context;
@@ -986,10 +1004,16 @@ e_calendar_item_update (GnomeCanvasItem *item,
        if (calitem->max_rows > 0)
                rows = MIN (rows, calitem->max_rows);
 
-       if (calitem->min_month_width == 0)
+       min_column_width = 0;
+       g_signal_emit (calitem, e_calendar_item_signals[CALC_MIN_COLUMN_WIDTH], 0, &min_column_width);
+
+       if (min_column_width < calitem->min_month_width)
+               min_column_width = calitem->min_month_width;
+
+       if (min_column_width == 0)
                cols = 1;
        else
-               cols = width / calitem->min_month_width;
+               cols = width / min_column_width;
        cols = MAX (cols, calitem->min_cols);
        if (calitem->max_cols > 0)
                cols = MIN (cols, calitem->max_cols);
diff --git a/src/e-util/e-calendar.c b/src/e-util/e-calendar.c
index b99d13bf62..6c1a2b8722 100644
--- a/src/e-util/e-calendar.c
+++ b/src/e-util/e-calendar.c
@@ -187,6 +187,46 @@ e_calendar_create_button (GtkArrowType arrow_type)
        return button;
 }
 
+static gint
+e_calendar_calc_min_column_width (ECalendar *cal)
+{
+       GtkWidget *widget;
+       GtkStyleContext *style_context;
+       GtkBorder padding;
+       PangoContext *pango_context;
+       PangoFontMetrics *font_metrics;
+       gdouble xthickness, arrow_button_size;
+
+       g_return_val_if_fail (E_IS_CALENDAR (cal), 0);
+
+       widget = GTK_WIDGET (cal);
+       style_context = gtk_widget_get_style_context (widget);
+       gtk_style_context_get_padding (style_context, gtk_style_context_get_state (style_context), &padding);
+       xthickness = padding.left;
+
+       pango_context = gtk_widget_get_pango_context (widget);
+       font_metrics = pango_context_get_metrics (
+               pango_context, NULL,
+               pango_context_get_language (pango_context));
+
+       arrow_button_size =
+               PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics))
+               + PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics))
+               + E_CALENDAR_ITEM_YPAD_ABOVE_MONTH_NAME
+               + E_CALENDAR_ITEM_YPAD_BELOW_MONTH_NAME
+               - E_CALENDAR_ARROW_BUTTON_Y_PAD * 2 - 2;
+
+       pango_font_metrics_unref (font_metrics);
+
+       return E_CALENDAR_ITEM_MIN_CELL_XPAD +
+               E_CALENDAR_ARROW_BUTTON_X_PAD +
+               (5 * E_CALENDAR_XPAD_BUTTONS) +
+               (4 * arrow_button_size) +
+               (4 * xthickness) +
+               (5 * cal->priv->calitem->max_digit_width) +
+               cal->priv->calitem->max_month_name_width;
+}
+
 static void
 e_calendar_class_init (ECalendarClass *class)
 {
@@ -246,6 +286,9 @@ e_calendar_init (ECalendar *cal)
        g_signal_connect (cal->priv->calitem, "month-width-changed",
                G_CALLBACK (calitem_month_width_changed_cb), cal);
 
+       g_signal_connect_swapped (cal->priv->calitem, "calc-min-column-width",
+               G_CALLBACK (e_calendar_calc_min_column_width), cal);
+
        /* Create the arrow buttons to move to the previous/next month. */
        button = e_calendar_create_button (GTK_ARROW_LEFT);
        g_signal_connect_swapped (


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