]> saetta.ns0.it Git - libgtkcalendarex/commitdiff
Changed view from GObject to GtkBin.
authorAndrea Zagli <azagli@libero.it>
Fri, 3 Dec 2010 09:49:30 +0000 (10:49 +0100)
committerAndrea Zagli <azagli@libero.it>
Fri, 3 Dec 2010 09:49:30 +0000 (10:49 +0100)
src/gtkcalex.c
src/gtkcalex.h
src/gtkcalexviewday.c
src/gtkcalexviewday.h
tests/test.c
tests/test.ui

index 98a0763d739f18c8dddb970a0b0c9a3b1d39696b..de6171932cfb12ae625e83d8deba63002345bc21 100644 (file)
@@ -20,8 +20,6 @@
        #include <config.h>
 #endif
 
-#include <goocanvas.h>
-
 #include "gtkcalex.h"
 #include "gtkcalexviewday.h"
 #include "gtkcalexviewweek.h"
@@ -72,14 +70,10 @@ struct _GtkCalExPrivate
        {
                GdkWindow *event_window;
 
-               GtkWidget *scrolledw; 
-               GtkWidget *goo_canvas;
-               GooCanvasItem *goo_canvas_root;
-
                GtkCalExViewType view_type;
                GDate *date;
 
-               GObject *view;
+               GtkWidget *view;
 
                GList *calendars;
                GList *categories;
@@ -117,21 +111,6 @@ gtk_calex_init (GtkCalEx *gtk_calex)
 
        GtkCalExPrivate *priv = GTK_CALEX_GET_PRIVATE (gtk_calex);
 
-       GTK_WIDGET_SET_FLAGS (gtk_calex, GTK_CAN_FOCUS);
-       GTK_WIDGET_UNSET_FLAGS (gtk_calex, GTK_NO_WINDOW);
-
-       priv->scrolledw = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolledw),
-                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-       gtk_container_add (GTK_CONTAINER (gtk_calex), priv->scrolledw);
-
-       priv->goo_canvas = goo_canvas_new ();
-       gtk_widget_set_size_request (priv->goo_canvas, 600, 450);
-       goo_canvas_set_bounds (GOO_CANVAS (priv->goo_canvas), 0, 0, 1000, 1000);
-       gtk_container_add (GTK_CONTAINER (priv->scrolledw), priv->goo_canvas);
-
-       priv->goo_canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->goo_canvas));
-
        priv->date = g_date_new ();
        g_get_current_time (&tval);
        g_date_set_time_val (priv->date, &tval);
@@ -224,51 +203,55 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type)
                        case GTK_CALEX_VIEW_TYPE_DAY:
                                if (priv->view != NULL)
                                        {
-                                               g_object_unref (priv->view);
+                                               gtk_widget_destroy (priv->view);
                                                priv->view = NULL;
                                        }
-                               GtkCalExViewDay *vd = gtk_calex_view_day_new (priv->goo_canvas, priv->date, FALSE);
-                               priv->view = G_OBJECT (vd);
+                               GtkWidget *vd = gtk_calex_view_day_new (priv->date, FALSE);
+                               priv->view = vd;
+                               gtk_container_add (GTK_CONTAINER (calex), vd);
                                break;
 
                        case GTK_CALEX_VIEW_TYPE_WORKING_WEEK:
                                if (priv->view != NULL)
                                        {
-                                               g_object_unref (priv->view);
+                                               gtk_widget_destroy (priv->view);
                                                priv->view = NULL;
                                        }
-                               GtkCalExViewDay *vww = gtk_calex_view_day_new (priv->goo_canvas, priv->date, TRUE);
-                               priv->view = G_OBJECT (vww);
+                               GtkWidget *vww = gtk_calex_view_day_new (priv->date, TRUE);
+                               priv->view = vww;
+                               gtk_container_add (GTK_CONTAINER (calex), vww);
                                break;
 
                        case GTK_CALEX_VIEW_TYPE_WEEK:
-                               if (priv->view != NULL)
+                               /*if (priv->view != NULL)
                                        {
                                                g_object_unref (priv->view);
                                                priv->view = NULL;
                                        }
                                GtkCalExViewWeek *vw = gtk_calex_view_week_new (priv->goo_canvas, priv->date);
-                               priv->view = G_OBJECT (vw);
+                               priv->view = vw;*/
                                break;
 
                        case GTK_CALEX_VIEW_TYPE_MONTH:
                                if (priv->view != NULL)
                                        {
-                                               g_object_unref (priv->view);
+                                               gtk_widget_destroy (priv->view);
                                                priv->view = NULL;
                                        }
-                               GtkCalExViewDay *vm = gtk_calex_view_day_new (priv->goo_canvas, priv->date, FALSE);
-                               priv->view = G_OBJECT (vm);
+                               GtkWidget *vm = gtk_calex_view_day_new (priv->date, FALSE);
+                               priv->view = vm;
+                               gtk_container_add (GTK_CONTAINER (calex), vm);
                                break;
 
                        case GTK_CALEX_VIEW_TYPE_LIST:
                                if (priv->view != NULL)
                                        {
-                                               g_object_unref (priv->view);
+                                               gtk_widget_destroy (priv->view);
                                                priv->view = NULL;
                                        }
-                               GtkCalExViewDay *vl = gtk_calex_view_day_new (priv->goo_canvas, priv->date, FALSE);
-                               priv->view = G_OBJECT (vl);
+                               GtkWidget *vl = gtk_calex_view_day_new (priv->date, FALSE);
+                               priv->view = vl;
+                               gtk_container_add (GTK_CONTAINER (calex), vl);
                                break;
 
                        default:
@@ -280,7 +263,7 @@ gtk_calex_set_view_type (GtkCalEx *calex, GtkCalExViewType type)
 GDate
 *gtk_calex_get_date (GtkCalEx *calex)
 {
-       g_return_val_if_fail (IS_GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_DAY);
+       g_return_val_if_fail (IS_GTK_CALEX (calex), NULL);
 
        GtkCalExPrivate *priv = GTK_CALEX_GET_PRIVATE (calex);
 
@@ -294,7 +277,13 @@ gtk_calex_set_date (GtkCalEx *calex, GDate *date)
 
        GtkCalExPrivate *priv = GTK_CALEX_GET_PRIVATE (calex);
 
-       priv->date = g_memdup (date, sizeof (GDate));
+       if (priv->date != NULL)
+               {
+                       g_date_free (priv->date);
+                       priv->date = NULL;
+               }
+       priv->date = g_date_new_dmy ((GDateDay)date->day, (GDateMonth)date->month, (GDateYear)date->year);
+       gtk_calex_view_day_set_date (GTK_CALEX_VIEW_DAY (priv->view), priv->date);
 }
 
 static void
@@ -486,9 +475,9 @@ gtk_calex_clean_canvas (GtkCalEx *gtk_calex)
 
        GtkCalExPrivate *priv = GTK_CALEX_GET_PRIVATE (gtk_calex);
 
-       children = goo_canvas_item_get_n_children (priv->goo_canvas_root);
+       /*children = goo_canvas_item_get_n_children (priv->goo_canvas_root);
        for (i = children - 1; i >= 0; i--)
                {
                        goo_canvas_item_remove (goo_canvas_item_get_child (priv->goo_canvas_root, i));
-               }
+               }*/
 }
index ba6e3f70b908fbae1f2b514fda70bb34f77ac138..e9b351dd947f323e5fd346dc26e21fad9b7952c7 100644 (file)
 #ifndef __GTK_CALEX_H__
 #define __GTK_CALEX_H__
 
-#include <glib.h>
-#include <glib-object.h>
+#include <gtk/gtk.h>
 
 #include "gtkcalexcalendar.h"
 #include "gtkcalexcategory.h"
 #include "gtkcalexevent.h"
 
+
 G_BEGIN_DECLS
 
 
index d6aec83bf7034d07f47e3f1fd651a45d642b95a7..939ee31697f1cd4166722fa4769f9406aa7d6901 100644 (file)
@@ -20,6 +20,8 @@
        #include <config.h>
 #endif
 
+#include <goocanvas.h>
+
 #include "gtkcalexviewday.h"
 
 enum
@@ -30,6 +32,22 @@ enum
 static void gtk_calex_view_day_class_init (GtkCalExViewDayClass *klass);
 static void gtk_calex_view_day_init (GtkCalExViewDay *gtk_calex_view_day);
 
+static void gtk_calex_view_day_add (GtkContainer *container,
+                           GtkWidget *widget);
+
+static void gtk_calex_view_day_forall (GtkContainer *container,
+                              gboolean include_internals,
+                              GtkCallback callback,
+                              gpointer callback_data);
+
+static void gtk_calex_view_day_realize (GtkWidget *widget);
+static void gtk_calex_view_day_unrealize (GtkWidget *widget);
+static void gtk_calex_view_day_map (GtkWidget *widget);
+static void gtk_calex_view_day_size_request (GtkWidget *widget,
+                                    GtkRequisition *requisition);
+static void gtk_calex_view_day_size_allocate (GtkWidget *widget,
+                                     GtkAllocation *allocation);
+
 static void gtk_calex_view_day_set_property (GObject *object,
                                     guint property_id,
                                     const GValue *value,
@@ -39,6 +57,8 @@ static void gtk_calex_view_day_get_property (GObject *object,
                                     GValue *value,
                                     GParamSpec *pspec);
 
+static void gtk_calex_view_day_clean_canvas (GtkCalExViewDay *view_day);
+
 static void gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day);
 
 
@@ -47,25 +67,40 @@ static void gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day);
 typedef struct _GtkCalExViewDayPrivate GtkCalExViewDayPrivate;
 struct _GtkCalExViewDayPrivate
        {
-               GtkWidget *canvas;
-               GooCanvasItem *canvas_root;
+               GdkWindow *event_window;
+
+               GtkWidget *scrolledw;
+               GtkWidget *goo_canvas;
+               GooCanvasItem *goo_canvas_root;
+
                GDate *date;
                gboolean working_week;
 
                guint division;
        };
 
-G_DEFINE_TYPE (GtkCalExViewDay, gtk_calex_view_day, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GtkCalExViewDay, gtk_calex_view_day, GTK_TYPE_BIN)
 
 static void
 gtk_calex_view_day_class_init (GtkCalExViewDayClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
+       GtkContainerClass *container_class = (GtkContainerClass*) klass;
 
        g_type_class_add_private (object_class, sizeof (GtkCalExViewDayPrivate));
 
        object_class->set_property = gtk_calex_view_day_set_property;
        object_class->get_property = gtk_calex_view_day_get_property;
+
+       widget_class->realize = gtk_calex_view_day_realize;
+       widget_class->unrealize = gtk_calex_view_day_unrealize;
+       widget_class->map = gtk_calex_view_day_map;
+       widget_class->size_request = gtk_calex_view_day_size_request;
+       widget_class->size_allocate = gtk_calex_view_day_size_allocate;
+
+       container_class->add = gtk_calex_view_day_add;
+       container_class->forall = gtk_calex_view_day_forall;
 }
 
 static void
@@ -73,6 +108,21 @@ gtk_calex_view_day_init (GtkCalExViewDay *gtk_calex_view_day)
 {
        GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtk_calex_view_day);
 
+       GTK_WIDGET_SET_FLAGS (gtk_calex_view_day, GTK_CAN_FOCUS);
+       GTK_WIDGET_UNSET_FLAGS (gtk_calex_view_day, GTK_NO_WINDOW);
+
+       priv->scrolledw = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolledw),
+                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+       gtk_container_add (GTK_CONTAINER (gtk_calex_view_day), priv->scrolledw);
+
+       priv->goo_canvas = goo_canvas_new ();
+       gtk_widget_set_size_request (priv->goo_canvas, 600, 450);
+       goo_canvas_set_bounds (GOO_CANVAS (priv->goo_canvas), 0, 0, 1000, 1000);
+       gtk_container_add (GTK_CONTAINER (priv->scrolledw), priv->goo_canvas);
+
+       priv->goo_canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->goo_canvas));
+
        priv->division = 30;
 }
 
@@ -108,27 +158,46 @@ gtk_calex_view_day_get_property (GObject *object, guint property_id, GValue *val
 
 /**
  * gtk_calex_view_day_new:
- * @canvas:
  * @date:
  * @working_week:
  *
  * Returns: the newly created #GtkCalExViewDay object.
  */
-GtkCalExViewDay
-*gtk_calex_view_day_new (GtkWidget *canvas, GDate *date, gboolean working_week)
+GtkWidget
+*gtk_calex_view_day_new (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->canvas = canvas;
-       priv->canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas));
        priv->date = date;
        priv->working_week = working_week;
 
        gtk_calex_view_day_draw (gtk_calex_view_day);
 
-       return gtk_calex_view_day;
+       return GTK_WIDGET (gtk_calex_view_day);
+}
+
+GDate
+*gtk_calex_view_day_get_date (GtkCalExViewDay *view_day)
+{
+       g_return_val_if_fail (IS_GTK_CALEX_VIEW_DAY (view_day), NULL);
+
+       GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (view_day);
+
+       return g_memdup (priv->date, sizeof (GDate));
+}
+
+void
+gtk_calex_view_day_set_date (GtkCalExViewDay *view_day, GDate *date)
+{
+       g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (view_day));
+
+       GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (view_day);
+
+       priv->date = g_memdup (date, sizeof (GDate));
+
+       gtk_calex_view_day_draw (view_day);
 }
 
 void
@@ -171,38 +240,41 @@ 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);
+       gtk_calex_view_day_clean_canvas (gtk_calex_view_day);
+
+       gtk_widget_get_allocation (priv->goo_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,
+       goo_canvas_text_new (priv->goo_canvas_root, str_day,
                             0, 0, allocation.width,
                             GTK_ANCHOR_NORTH_WEST,
                             "font", "Sans 10",
                             NULL);
+       g_free (str_day);
 
        divisions = 60 / priv->division;
        y = 0;
        for (hour = 0; hour < 24; hour++)
                {
                        y += 20;
-                       goo_canvas_polyline_new_line (priv->canvas_root,
+                       goo_canvas_polyline_new_line (priv->goo_canvas_root,
                                             0, y, 50, y,
                                             "stroke-color", "black",
                                             NULL);
-                       goo_canvas_rect_new (priv->canvas_root,
+                       goo_canvas_rect_new (priv->goo_canvas_root,
                                             55, y, allocation.width - 55, 20,
                                             "line-width", 1.0,
                                             "stroke-color", "black",
                                             "fill-color", "yellow",
                                             NULL);
-                       goo_canvas_text_new (priv->canvas_root, g_strdup_printf ("%d", hour),
+                       goo_canvas_text_new (priv->goo_canvas_root, g_strdup_printf ("%d", hour),
                                             0, y, 50,
                                             GTK_ANCHOR_NORTH_WEST,
                                             "font", "Sans 24",
                                             NULL);
-                       goo_canvas_text_new (priv->canvas_root, "00",
+                       goo_canvas_text_new (priv->goo_canvas_root, "00",
                                             25, y, 25,
                                             GTK_ANCHOR_NORTH_WEST,
                                             "font", "Sans 12",
@@ -211,16 +283,16 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day)
                        for (division = 1; division < divisions; division++)
                                {
                                        y += 20;
-                                       goo_canvas_polyline_new_line (priv->canvas_root,
+                                       goo_canvas_polyline_new_line (priv->goo_canvas_root,
                                                                      25, y, 50, y,
                                                                      "stroke-color", "black",
                                                                      NULL);
-                                       goo_canvas_text_new (priv->canvas_root, g_strdup_printf ("%02d", 60 / divisions * division),
+                                       goo_canvas_text_new (priv->goo_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->canvas_root,
+                                       goo_canvas_rect_new (priv->goo_canvas_root,
                                                             55, y, allocation.width - 55, 20,
                                                             "line-width", 1.0,
                                                             "stroke-color", "black",
@@ -229,3 +301,199 @@ gtk_calex_view_day_draw (GtkCalExViewDay *gtk_calex_view_day)
                                }
                }
 }
+
+static void
+gtk_calex_view_day_add (GtkContainer *container,
+               GtkWidget *child)
+{
+       GtkCalExViewDay *gtkcalexvd;
+       GtkBin *bin;
+
+       bin = GTK_BIN (container);
+       g_return_if_fail (bin->child == NULL);
+
+       gtkcalexvd = GTK_CALEX_VIEW_DAY (container);
+
+       bin->child = child;
+       gtk_widget_set_parent (child, GTK_WIDGET (bin));
+}
+
+static void
+gtk_calex_view_day_forall (GtkContainer *container,
+                gboolean include_internals,
+                GtkCallback callback,
+                gpointer callback_data)
+{
+       g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (container));
+       g_return_if_fail (callback != NULL);
+
+       GTK_CONTAINER_CLASS (gtk_calex_view_day_parent_class)->forall (container,
+                            include_internals,
+                            callback,
+                            callback_data);
+}
+
+static void
+gtk_calex_view_day_realize (GtkWidget *widget)
+{
+       GdkWindowAttr attributes;
+       gint attributes_mask;
+
+       GtkCalExViewDayPrivate *priv;
+
+       GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+
+       priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (GTK_CALEX_VIEW_DAY (widget));
+
+       attributes.x = widget->allocation.x;
+       attributes.y = widget->allocation.y;
+       attributes.width = widget->allocation.width;
+       attributes.height = widget->allocation.height;
+       attributes.window_type = GDK_WINDOW_CHILD;
+       attributes.wclass = GDK_INPUT_OUTPUT;
+       attributes.visual = gtk_widget_get_visual (widget);
+       attributes.colormap = gtk_widget_get_colormap (widget);
+       attributes.event_mask = gtk_widget_get_events (widget)
+                               | GDK_BUTTON_MOTION_MASK
+                               | GDK_BUTTON_PRESS_MASK
+                               | GDK_BUTTON_RELEASE_MASK
+                               | GDK_POINTER_MOTION_MASK
+                               | GDK_POINTER_MOTION_HINT_MASK;
+
+       attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+       widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
+                                        &attributes, attributes_mask);
+       gdk_window_set_user_data (widget->window, widget);
+
+       attributes.wclass = GDK_INPUT_ONLY;
+       attributes_mask = 0;
+
+       priv->event_window = gdk_window_new (widget->window,
+                                            &attributes, attributes_mask);
+       gdk_window_set_user_data (priv->event_window, widget);
+
+       widget->style = gtk_style_attach (widget->style, widget->window);
+
+       gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
+}
+
+static void
+gtk_calex_view_day_unrealize (GtkWidget *widget)
+{
+       GtkCalExViewDayPrivate *priv;
+
+       priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (widget);
+
+       if (priv->event_window != NULL)
+               {
+                       gdk_window_set_user_data (priv->event_window, NULL);
+                       gdk_window_destroy (priv->event_window);
+                       priv->event_window = NULL;
+               }
+
+       GTK_WIDGET_CLASS (gtk_calex_view_day_parent_class)->unrealize (widget);
+}
+
+static void 
+gtk_calex_view_day_map (GtkWidget *widget)
+{
+       GtkCalExViewDayPrivate *priv;
+
+       g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (widget));
+
+       priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (GTK_CALEX_VIEW_DAY (widget));
+
+       GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
+
+       GTK_WIDGET_CLASS (gtk_calex_view_day_parent_class)->map (widget);
+
+       gdk_window_show (priv->event_window);
+       gdk_window_show (widget->window);
+}
+
+static void
+gtk_calex_view_day_size_request (GtkWidget *widget,
+                        GtkRequisition *requisition)
+{
+       GtkCalExViewDay *gtkcalexvd;
+       GtkBin *bin;
+       GtkRequisition child_requisition;
+
+       guint border_width;
+
+       g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (widget));
+       g_return_if_fail (requisition != NULL);
+
+       gtkcalexvd = GTK_CALEX_VIEW_DAY (widget);
+       bin = GTK_BIN (gtkcalexvd);
+
+       requisition->width = 0;
+       requisition->height = 0;
+
+       if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+               {
+                       gtk_widget_size_request (bin->child, &child_requisition);
+                       requisition->width += child_requisition.width;
+                       requisition->height += child_requisition.height;
+               }
+
+       border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+       requisition->width += border_width * 2;
+       requisition->height += border_width * 2;
+}
+
+static void
+gtk_calex_view_day_size_allocate (GtkWidget *widget,
+                         GtkAllocation *allocation)
+{
+       GtkCalExViewDay *gtkcalex;
+       GtkCalExViewDayPrivate *priv;
+       GtkBin *bin;
+       GtkAllocation relative_allocation;
+       GtkAllocation child_allocation;
+
+       guint border_width;
+
+       g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (widget));
+       g_return_if_fail (allocation != NULL);
+
+       gtkcalex = GTK_CALEX_VIEW_DAY (widget);
+       bin = GTK_BIN (gtkcalex);
+
+       priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (gtkcalex);
+
+       gtk_widget_set_allocation (widget, allocation);
+
+       border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+       relative_allocation.x = border_width;
+       relative_allocation.y = border_width;
+       relative_allocation.width = MAX (1, (gint)widget->allocation.width - relative_allocation.x * 2);
+       relative_allocation.height = MAX (1, (gint)widget->allocation.height - relative_allocation.y * 2);
+
+       if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+               {
+                       child_allocation.x = relative_allocation.x + allocation->x;
+                       child_allocation.y = relative_allocation.y + allocation->y;
+                       child_allocation.width = relative_allocation.width;
+                       child_allocation.height = relative_allocation.height;
+                       gtk_widget_size_allocate (bin->child, &child_allocation);
+               }
+}
+
+static void
+gtk_calex_view_day_clean_canvas (GtkCalExViewDay *view_day)
+{
+       gint children;
+       gint i;
+
+       g_return_if_fail (IS_GTK_CALEX_VIEW_DAY (view_day));
+
+       GtkCalExViewDayPrivate *priv = GTK_CALEX_VIEW_DAY_GET_PRIVATE (view_day);
+
+       children = goo_canvas_item_get_n_children (priv->goo_canvas_root);
+       for (i = children - 1; i >= 0; i--)
+               {
+                       goo_canvas_item_remove (goo_canvas_item_get_child (priv->goo_canvas_root, i));
+               }
+}
index a80ad6b31afdc65f54cb631afc12c2ce5da3595a..224a9eaa1e0556a6b5ce3e8ae3df6b301afd84a8 100644 (file)
 #ifndef __GTK_CALEX_VIEW_DAY_H__
 #define __GTK_CALEX_VIEW_DAY_H__
 
-#include <glib.h>
-#include <glib-object.h>
+#include <gtk/gtk.h>
 
-#include <goocanvas.h>
 
 G_BEGIN_DECLS
 
@@ -41,18 +39,21 @@ typedef struct _GtkCalExViewDayClass GtkCalExViewDayClass;
 
 struct _GtkCalExViewDay
        {
-               GObject parent;
+               GtkBin parent;
        };
 
 struct _GtkCalExViewDayClass
        {
-               GObjectClass parent_class;
+               GtkBinClass parent_class;
        };
 
 GType gtk_calex_view_day_get_type (void) G_GNUC_CONST;
 
 
-GtkCalExViewDay *gtk_calex_view_day_new (GtkWidget *canvas, GDate *date, gboolean working_week);
+GtkWidget *gtk_calex_view_day_new (GDate *date, gboolean working_week);
+
+GDate *gtk_calex_view_day_get_date (GtkCalExViewDay *view_day);
+void gtk_calex_view_day_set_date (GtkCalExViewDay *view_day, GDate *date);
 
 void gtk_calex_view_day_set_division (GtkCalExViewDay *view_day, guint division);
 guint gtk_calex_view_day_get_division (GtkCalExViewDay *view_day);
index c76a1edbfbb91e40eae61b7e7faf08eecfb0a922..3f95a7005fedbc182f5338dd8b166418e45e53b8 100644 (file)
@@ -57,6 +57,26 @@ on_tbtn_view_type_list_toggled (GtkToggleToolButton *toggle_tool_button,
        gtk_calex_set_view_type (GTK_CALEX (calex), GTK_CALEX_VIEW_TYPE_LIST);
 }
 
+G_MODULE_EXPORT void
+on_calendar_day_selected (GtkCalendar *calendar,
+                          gpointer user_data)
+{
+       GDate date;
+
+       guint year;
+       guint month;
+       guint day;
+
+       gtk_calendar_get_date (calendar, &year, &month, &day);
+       date.year = year;
+       date.month = month + 1;
+       date.day = day;
+
+       gtk_calex_set_date (GTK_CALEX (calex), &date);
+
+       g_message ("Date %d-%d-%d", date.year, date.month, date.day);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -64,6 +84,10 @@ main (int argc, char **argv)
        GError *error;
        GtkWidget *w;
        GtkWidget *vbox;
+       GtkWidget *calendar;
+
+       GTimeVal tval;
+       GDate *date;
 
        gtk_init (&argc, &argv);
 
@@ -78,10 +102,18 @@ main (int argc, char **argv)
 
        w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "window1"));
        vbox = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "vbox2"));
+       calendar = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "calendar1"));
 
        calex = gtk_calex_new ();
        gtk_box_pack_start (GTK_BOX (vbox), calex, TRUE, TRUE, 0);
 
+       date = g_date_new ();
+       g_get_current_time (&tval);
+       g_date_set_time_val (date, &tval);
+
+       gtk_calendar_select_month (GTK_CALENDAR (calendar), date->month - 1, date->year);
+       gtk_calendar_select_day (GTK_CALENDAR (calendar), date->day);
+
        gtk_builder_connect_signals (gtkbuilder, NULL);
 
        gtk_widget_show_all (w);
index d070330c73c863678ed72670d67ef9e8f63f3eb7..912436b1b5aa499ba2ed6406ca99b83f5ce67f29 100644 (file)
@@ -93,9 +93,7 @@
               <object class="GtkCalendar" id="calendar1">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="year">2010</property>
-                <property name="month">10</property>
-                <property name="day">7</property>
+                <signal name="day_selected" handler="on_calendar_day_selected"/>
               </object>
               <packing>
                 <property name="expand">False</property>