[evolution/wip/webkit2] Bug 692713 - Mini-calendar widget arrows in a wrong position



commit c01615f508db0cd25175917ab9f810042a6d2e14
Author: Milan Crha <mcrha redhat com>
Date:   Tue Nov 10 10:01:10 2015 +0100

    Bug 692713 - Mini-calendar widget arrows in a wrong position

 e-util/e-calendar-item.c             |   17 +++++++++++++-
 e-util/e-calendar.c                  |   12 ++++++++++
 libgnomecanvas/gnome-canvas-widget.c |   40 +++++++++++++++++++++++++++++----
 3 files changed, 63 insertions(+), 6 deletions(-)
---
diff --git a/e-util/e-calendar-item.c b/e-util/e-calendar-item.c
index 57a43dc..fcd9726 100644
--- a/e-util/e-calendar-item.c
+++ b/e-util/e-calendar-item.c
@@ -251,6 +251,7 @@ enum {
        DATE_RANGE_MOVED,
        SELECTION_CHANGED,
        SELECTION_PREVIEW_CHANGED,
+       MONTH_WIDTH_CHANGED,
        LAST_SIGNAL
 };
 
@@ -574,6 +575,15 @@ e_calendar_item_class_init (ECalendarItemClass *class)
                g_cclosure_marshal_VOID__VOID,
                G_TYPE_NONE, 0);
 
+       e_calendar_item_signals[MONTH_WIDTH_CHANGED] = g_signal_new (
+               "month-width-changed",
+               G_TYPE_FROM_CLASS (object_class),
+               G_SIGNAL_RUN_LAST,
+               0 /* G_STRUCT_OFFSET (ECalendarItemClass, month_width_changed) */,
+               NULL, NULL,
+               g_cclosure_marshal_VOID__VOID,
+               G_TYPE_NONE, 0);
+
        e_calendar_item_a11y_init ();
 }
 
@@ -933,7 +943,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;
+       gint rows, cols, xthickness, ythickness, old_month_width;
        PangoContext *pango_context;
        PangoFontMetrics *font_metrics;
        GtkBorder padding;
@@ -1004,6 +1014,7 @@ e_calendar_item_update (GnomeCanvasItem *item,
                PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) +
                PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics));
 
+       old_month_width = calitem->month_width;
        calitem->month_width = calitem->min_month_width;
        calitem->month_height = calitem->min_month_height;
        calitem->cell_width = MAX (calitem->max_day_width, (calitem->max_digit_width * 2))
@@ -1054,6 +1065,10 @@ e_calendar_item_update (GnomeCanvasItem *item,
                item->x2, item->y2);
 
        pango_font_metrics_unref (font_metrics);
+
+       if (old_month_width != calitem->month_width) {
+               g_signal_emit (calitem, e_calendar_item_signals[MONTH_WIDTH_CHANGED], 0, NULL);
+       }
 }
 
 /*
diff --git a/e-util/e-calendar.c b/e-util/e-calendar.c
index ed34bb4..1e4f496 100644
--- a/e-util/e-calendar.c
+++ b/e-util/e-calendar.c
@@ -116,6 +116,15 @@ G_DEFINE_TYPE (
        E_TYPE_CANVAS)
 
 static void
+calitem_month_width_changed_cb (ECalendarItem *item,
+                               ECalendar *cal)
+{
+       g_return_if_fail (E_IS_CALENDAR (cal));
+
+       gtk_widget_queue_resize (GTK_WIDGET (cal));
+}
+
+static void
 e_calendar_class_init (ECalendarClass *class)
 {
        GObjectClass   *object_class;
@@ -168,6 +177,9 @@ e_calendar_init (ECalendar *cal)
        pango_font_description_free (small_font_desc);
        g_object_unref (pango_context);
 
+       g_signal_connect (cal->calitem, "month-width-changed",
+               G_CALLBACK (calitem_month_width_changed_cb), cal);
+
        /* Create the arrow buttons to move to the previous/next month. */
        button = gtk_button_new ();
        gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
diff --git a/libgnomecanvas/gnome-canvas-widget.c b/libgnomecanvas/gnome-canvas-widget.c
index ba7e83b..ea31b3a 100644
--- a/libgnomecanvas/gnome-canvas-widget.c
+++ b/libgnomecanvas/gnome-canvas-widget.c
@@ -182,6 +182,19 @@ gnome_canvas_widget_dispose (GnomeCanvasItem *object)
                dispose (object);
 }
 
+static gboolean
+reposition_widget_cb (gpointer user_data)
+{
+       GnomeCanvasWidget *witem = user_data;
+
+       g_return_val_if_fail (GNOME_IS_CANVAS_WIDGET (witem), FALSE);
+
+       if (witem->widget)
+               gtk_widget_queue_resize (witem->widget);
+
+       return FALSE;
+}
+
 static void
 recalc_bounds (GnomeCanvasWidget *witem)
 {
@@ -207,11 +220,28 @@ recalc_bounds (GnomeCanvasWidget *witem)
        item->x2 = witem->cx + witem->cwidth;
        item->y2 = witem->cy + witem->cheight;
 
-       if (witem->widget)
-               gtk_layout_move (
-                       GTK_LAYOUT (item->canvas), witem->widget,
-                       witem->cx + item->canvas->zoom_xofs,
-                       witem->cy + item->canvas->zoom_yofs);
+       if (witem->widget) {
+               gint current_x = 0, current_y = 0;
+
+               gtk_container_child_get (GTK_CONTAINER (item->canvas), witem->widget,
+                       "x", &current_x,
+                       "y", &current_y,
+                       NULL);
+
+               if (current_x != ((gint) (witem->cx + item->canvas->zoom_xofs)) ||
+                   current_y != ((gint) (witem->cy + item->canvas->zoom_yofs))) {
+                       gtk_layout_move (
+                               GTK_LAYOUT (item->canvas), witem->widget,
+                               witem->cx + item->canvas->zoom_xofs,
+                               witem->cy + item->canvas->zoom_yofs);
+
+                       /* This is needed, because the gtk_layout_move() calls gtk_widget_queue_resize(),
+                          which can be silently ignored when called inside "size-allocate" handler, causing
+                          misposition of the child widget. */
+                       g_idle_add_full (G_PRIORITY_HIGH_IDLE,
+                               reposition_widget_cb, g_object_ref (witem), g_object_unref);
+               }
+       }
 }
 
 static void


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