]> saetta.ns0.it Git - libgtkcalendarex/commitdiff
Passed GooCanvas instead of canvas root to views.
authorAndrea Zagli <azagli@libero.it>
Fri, 3 Dec 2010 08:20:44 +0000 (09:20 +0100)
committerAndrea Zagli <azagli@libero.it>
Fri, 3 Dec 2010 08:20:44 +0000 (09:20 +0100)
src/gtkcalex.c
src/gtkcalexviewday.c
src/gtkcalexviewday.h
src/gtkcalexviewweek.c
src/gtkcalexviewweek.h

index 1bfec6957ffea60f7c97db7b4728d826280f28c0..98a0763d739f18c8dddb970a0b0c9a3b1d39696b 100644 (file)
@@ -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;
 
index f96f3f6c067570da0a4aa32a86b866e474fd5cc9..d6aec83bf7034d07f47e3f1fd651a45d642b95a7 100644 (file)
@@ -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",
index 7ee2be3da27810f3edf88456a1ec9f0e36a44424..a80ad6b31afdc65f54cb631afc12c2ce5da3595a 100644 (file)
@@ -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);
index 59de39b09c59930a3279dd7b9dd913ccd5ef4510..4c4616c5735ed8bd6e3c74e2a9e485e194913a51 100644 (file)
@@ -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);
index 31e86b315fdbc2c636312e87ef3d0e146db301ed..4dce464e8d78427cb61a6d34c99324cd311b1725 100644 (file)
@@ -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