From: Andrea Zagli Date: Fri, 3 Dec 2010 08:20:44 +0000 (+0100) Subject: Passed GooCanvas instead of canvas root to views. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=13d9b68e2e4dffcdf6fd84077d607ef9617ff2cb;p=libgtkcalendarex Passed GooCanvas instead of canvas root to views. --- diff --git a/src/gtkcalex.c b/src/gtkcalex.c index 1bfec69..98a0763 100644 --- a/src/gtkcalex.c +++ b/src/gtkcalex.c @@ -227,7 +227,7 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type) g_object_unref (priv->view); priv->view = NULL; } - GtkCalExViewDay *vd = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date, FALSE); + GtkCalExViewDay *vd = gtk_calex_view_day_new (priv->goo_canvas, priv->date, FALSE); priv->view = G_OBJECT (vd); break; @@ -237,7 +237,7 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type) g_object_unref (priv->view); priv->view = NULL; } - GtkCalExViewDay *vww = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date, TRUE); + GtkCalExViewDay *vww = gtk_calex_view_day_new (priv->goo_canvas, priv->date, TRUE); priv->view = G_OBJECT (vww); break; @@ -247,7 +247,7 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type) g_object_unref (priv->view); priv->view = NULL; } - GtkCalExViewWeek *vw = gtk_calex_view_week_new (priv->goo_canvas_root, priv->date); + GtkCalExViewWeek *vw = gtk_calex_view_week_new (priv->goo_canvas, priv->date); priv->view = G_OBJECT (vw); break; @@ -257,7 +257,7 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type) g_object_unref (priv->view); priv->view = NULL; } - GtkCalExViewDay *vm = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date, FALSE); + GtkCalExViewDay *vm = gtk_calex_view_day_new (priv->goo_canvas, priv->date, FALSE); priv->view = G_OBJECT (vm); break; @@ -267,7 +267,7 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type) g_object_unref (priv->view); priv->view = NULL; } - GtkCalExViewDay *vl = gtk_calex_view_day_new (priv->goo_canvas_root, priv->date, FALSE); + GtkCalExViewDay *vl = gtk_calex_view_day_new (priv->goo_canvas, priv->date, FALSE); priv->view = G_OBJECT (vl); break; diff --git a/src/gtkcalexviewday.c b/src/gtkcalexviewday.c index f96f3f6..d6aec83 100644 --- a/src/gtkcalexviewday.c +++ b/src/gtkcalexviewday.c @@ -47,7 +47,8 @@ static void gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day); typedef struct _GtkCalExViewDayPrivate GtkCalExViewDayPrivate; struct _GtkCalExViewDayPrivate { - GooCanvasItem *goo_canvas_root; + GtkWidget *canvas; + GooCanvasItem *canvas_root; GDate *date; gboolean working_week; @@ -107,20 +108,21 @@ gtk_calex_view_day_get_property (GObject *object, guint property_id, GValue *val /** * gtk_calex_view_day_new: - * @root: + * @canvas: * @date: * @working_week: * * Returns: the newly created #GtkCalExViewDay object. */ GtkCalExViewDay -*gtk_calex_view_day_new (GooCanvasItem *root, GDate *date, gboolean working_week) +*gtk_calex_view_day_new (GtkWidget *canvas, GDate *date, gboolean working_week) { GtkCalExViewDay *gtk_calex_view_day = GTK_CALEX_VIEW_DAY (g_object_new (gtk_calex_view_day_get_type (), NULL)); GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day); - priv->goo_canvas_root = root; + priv->canvas = canvas; + priv->canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas)); priv->date = date; priv->working_week = working_week; @@ -154,6 +156,10 @@ gtk_calex_view_day_get_division (GtkCalExViewDay *view_day) static void gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) { + GtkAllocation allocation; + + gchar *str_day; + guint hour; guint division; @@ -165,27 +171,38 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day); + gtk_widget_get_allocation (priv->canvas, &allocation); + + str_day = g_malloc0 (100); + g_date_strftime (str_day, 100, "%A %d %B", priv->date); + + goo_canvas_text_new (priv->canvas_root, str_day, + 0, 0, allocation.width, + GTK_ANCHOR_NORTH_WEST, + "font", "Sans 10", + NULL); + divisions = 60 / priv->division; - y = -20; + y = 0; for (hour = 0; hour < 24; hour++) { y += 20; - goo_canvas_polyline_new_line (priv->goo_canvas_root, + goo_canvas_polyline_new_line (priv->canvas_root, 0, y, 50, y, "stroke-color", "black", NULL); - goo_canvas_rect_new (priv->goo_canvas_root, - 55, y, 400, 20, + goo_canvas_rect_new (priv->canvas_root, + 55, y, allocation.width - 55, 20, "line-width", 1.0, "stroke-color", "black", "fill-color", "yellow", NULL); - goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour), + goo_canvas_text_new (priv->canvas_root, g_strdup_printf ("%d", hour), 0, y, 50, GTK_ANCHOR_NORTH_WEST, "font", "Sans 24", NULL); - goo_canvas_text_new (priv->goo_canvas_root, "00", + goo_canvas_text_new (priv->canvas_root, "00", 25, y, 25, GTK_ANCHOR_NORTH_WEST, "font", "Sans 12", @@ -194,17 +211,17 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day) for (division = 1; division < divisions; division++) { y += 20; - goo_canvas_polyline_new_line (priv->goo_canvas_root, + goo_canvas_polyline_new_line (priv->canvas_root, 25, y, 50, y, "stroke-color", "black", NULL); - goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%02d", 60 / divisions * division), + goo_canvas_text_new (priv->canvas_root, g_strdup_printf ("%02d", 60 / divisions * division), 25, y, 25, GTK_ANCHOR_NORTH_WEST, "font", "Sans 12", NULL); - goo_canvas_rect_new (priv->goo_canvas_root, - 55, y, 400, 20, + goo_canvas_rect_new (priv->canvas_root, + 55, y, allocation.width - 55, 20, "line-width", 1.0, "stroke-color", "black", "fill-color", "yellow", diff --git a/src/gtkcalexviewday.h b/src/gtkcalexviewday.h index 7ee2be3..a80ad6b 100644 --- a/src/gtkcalexviewday.h +++ b/src/gtkcalexviewday.h @@ -52,7 +52,7 @@ struct _GtkCalExViewDayClass GType gtk_calex_view_day_get_type (void) G_GNUC_CONST; -GtkCalExViewDay *gtk_calex_view_day_new (GooCanvasItem *root, GDate *date, gboolean working_week); +GtkCalExViewDay *gtk_calex_view_day_new (GtkWidget *canvas, GDate *date, gboolean working_week); void gtk_calex_view_day_set_division (GtkCalExViewDay *view_day, guint division); guint gtk_calex_view_day_get_division (GtkCalExViewDay *view_day); diff --git a/src/gtkcalexviewweek.c b/src/gtkcalexviewweek.c index 59de39b..4c4616c 100644 --- a/src/gtkcalexviewweek.c +++ b/src/gtkcalexviewweek.c @@ -49,7 +49,8 @@ static void gtk_calex_view_week_draw (GtkCalExViewWeek *gtk_calex_view_week); typedef struct _GtkCalExViewWeekPrivate GtkCalExViewWeekPrivate; struct _GtkCalExViewWeekPrivate { - GooCanvasItem *goo_canvas_root; + GtkWidget *canvas; + GooCanvasItem *canvas_root; GDate *date; }; @@ -104,19 +105,20 @@ gtk_calex_view_week_get_property (GObject *object, guint property_id, GValue *va /** * gtk_calex_view_week_new: - * @root: + * @canvas: * @date: * * Returns: the newly created #GtkCalExViewWeek object. */ GtkCalExViewWeek -*gtk_calex_view_week_new (GooCanvasItem *root, GDate *date) +*gtk_calex_view_week_new (GtkWidget *canvas, GDate *date) { GtkCalExViewWeek *gtk_calex_view_week = GTK_CALEX_VIEW_WEEK (g_object_new (gtk_calex_view_week_get_type (), NULL)); GtkCalExViewWeekPrivate *priv = GTK_CALEX_VIEW_WEEK_GET_PRIVATE (gtk_calex_view_week); - priv->goo_canvas_root = root; + priv->canvas = canvas; + priv->canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas)); priv->date = date; gtk_calex_view_week_draw (gtk_calex_view_week); diff --git a/src/gtkcalexviewweek.h b/src/gtkcalexviewweek.h index 31e86b3..4dce464 100644 --- a/src/gtkcalexviewweek.h +++ b/src/gtkcalexviewweek.h @@ -50,7 +50,7 @@ struct _GtkCalExViewWeekClass GType gtk_calex_view_week_get_type (void) G_GNUC_CONST; -GtkCalExViewWeek *gtk_calex_view_week_new (GooCanvasItem *root, GDate *date); +GtkCalExViewWeek *gtk_calex_view_week_new (GtkWidget *canvas, GDate *date); G_END_DECLS