From 42ff2e76daf3f7f6c055788b9baf9f5838899d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erick=20P=C3=A9rez=20Castellanos?= Date: Tue, 4 Jun 2013 22:34:51 -0400 Subject: [PATCH] ui: added GcalDayView widget Initial approach, it doesn't do anything but painting the background. Still missing to handle chidlren allocation. Integrated GcalAllDayGrid, GcalViewport and GcalDaysGrid. --- src/Makefile.am | 6 +- src/gcal-day-view.c | 257 ++++++++++++++++++++++++++++++++++++++++++++ src/gcal-day-view.h | 57 ++++++++++ 3 files changed, 318 insertions(+), 2 deletions(-) create mode 100644 src/gcal-day-view.c create mode 100644 src/gcal-day-view.h diff --git a/src/Makefile.am b/src/Makefile.am index c292881a..ee303ac4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,12 +36,14 @@ gnome_calendar_SOURCES = \ gcal-window.c \ gcal-view.c \ gcal-view.h \ - gcal-year-view.c \ - gcal-year-view.h \ + gcal-day-view.c \ + gcal-day-view.h \ gcal-month-view.c \ gcal-month-view.h \ gcal-week-view.c \ gcal-week-view.h \ + gcal-year-view.c \ + gcal-year-view.h \ gcal-event-widget.c \ gcal-event-widget.h \ gcal-event-overlay.c \ diff --git a/src/gcal-day-view.c b/src/gcal-day-view.c new file mode 100644 index 00000000..6cb7c08f --- /dev/null +++ b/src/gcal-day-view.c @@ -0,0 +1,257 @@ +/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * gcal-day-view.c + * + * Copyright (C) 2013 - Erick Pérez Castellanos + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gcal-day-view.h" +#include "gcal-view.h" +#include "gcal-all-day-grid.h" +#include "gcal-days-grid.h" +#include "gcal-viewport.h" + +#include + +enum +{ + PROP_0, + PROP_DATE +}; + +struct _GcalDayViewPrivate +{ + /* property */ + icaltimetype *date; + + GtkWidget *fold_button; + + /* events widgets parents */ + GtkWidget *all_day_grid; + GtkWidget *day_grid; +}; + +static void gcal_view_interface_init (GcalViewIface *iface); + +static void gcal_day_view_constructed (GObject *object); + +static void gcal_day_view_finalize (GObject *object); + +static void gcal_day_view_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); + +static void gcal_day_view_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void gcal_day_view_set_date (GcalDayView *view, + icaltimetype *date); + +G_DEFINE_TYPE_WITH_CODE (GcalDayView, + gcal_day_view, + GTK_TYPE_GRID, + G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW, + gcal_view_interface_init)); + +static void +gcal_day_view_class_init (GcalDayViewClass *klass) +{ + /* FIXME: Uncomment stuff here */ + /* GtkContainerClass *container_class; */ + GObjectClass *object_class; + + /* container_class = GTK_CONTAINER_CLASS (klass); */ + /* container_class->add = gcal_day_view_add; */ + /* container_class->remove = gcal_day_view_remove; */ + /* container_class->forall = gcal_day_view_forall; */ + /* gtk_container_class_handle_border_width (container_class); */ + + object_class = G_OBJECT_CLASS (klass); + object_class->constructed = gcal_day_view_constructed; + object_class->finalize = gcal_day_view_finalize; + object_class->set_property = gcal_day_view_set_property; + object_class->get_property = gcal_day_view_get_property; + + g_object_class_override_property (object_class, PROP_DATE, "active-date"); + + g_type_class_add_private ((gpointer)klass, sizeof (GcalDayViewPrivate)); +} + + + +static void +gcal_day_view_init (GcalDayView *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + GCAL_TYPE_DAY_VIEW, + GcalDayViewPrivate); +} + +static void +gcal_view_interface_init (GcalViewIface *iface) +{ + /* FIXME: add new GcalView API */ + /* iface->get_initial_date = gcal_day_view_get_initial_date; */ + /* iface->get_final_date = gcal_day_view_get_final_date; */ + + /* iface->contains = gcal_day_view_contains; */ + /* iface->remove_by_uuid = gcal_day_view_remove_by_uuid; */ + /* iface->get_by_uuid = gcal_day_view_get_by_uuid; */ +} + +static void +gcal_day_view_constructed (GObject *object) +{ + GcalDayViewPrivate *priv; + + /* FIXME: debug code */ + GtkWidget *sw; /* involve overlay in it */ + GdkRGBA color; + + g_return_if_fail (GCAL_IS_DAY_VIEW (object)); + priv = GCAL_DAY_VIEW (object)->priv; + + if (G_OBJECT_CLASS (gcal_day_view_parent_class)->constructed != NULL) + G_OBJECT_CLASS (gcal_day_view_parent_class)->constructed (object); + + priv->fold_button = gtk_button_new_with_label (_("Fold")); + g_object_set (priv->fold_button, + "valign", GTK_ALIGN_END, + "margin", 6, + NULL); + gtk_style_context_add_class ( + gtk_widget_get_style_context (priv->fold_button), + "nav-button"); + gtk_grid_attach (GTK_GRID (object), priv->fold_button, 0, 0, 1, 1); + + /* event widget holders */ + priv->all_day_grid = gcal_all_day_grid_new (2); + gcal_all_day_grid_set_column_headers (GCAL_ALL_DAY_GRID (priv->all_day_grid), + _("Today"), + _("Tomorrow")); + g_object_set (priv->all_day_grid, "spacing", 6, NULL); + gtk_widget_set_size_request (priv->all_day_grid, -1, 64); + gtk_widget_set_hexpand (priv->all_day_grid, TRUE); + + priv->day_grid = gcal_days_grid_new (2); + gcal_days_grid_set_preferred_cell_height (GCAL_DAYS_GRID (priv->day_grid), 60); + g_object_set (priv->day_grid, "spacing", 6, NULL); + + gtk_widget_set_hexpand (priv->day_grid, TRUE); + gtk_widget_set_vexpand (priv->day_grid, TRUE); + + gtk_grid_attach (GTK_GRID (object), priv->all_day_grid, 1, 0, 1, 1); + + sw = gcal_viewport_new (); + gcal_viewport_add (GCAL_VIEWPORT (sw), priv->day_grid); + gtk_grid_attach (GTK_GRID (object), sw, 0, 1, 2, 1); + + /* binding sizes */ + gtk_widget_set_size_request ( + priv->fold_button, + gcal_days_grid_get_scale_width (GCAL_DAYS_GRID (priv->day_grid)) - 12, + -1); + + gtk_widget_show_all (GTK_WIDGET (object)); +} + +static void +gcal_day_view_finalize (GObject *object) +{ + GcalDayViewPrivate *priv = GCAL_DAY_VIEW (object)->priv; + + if (priv->date != NULL) + g_free (priv->date); + + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (gcal_day_view_parent_class)->finalize (object); +} + +static void +gcal_day_view_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail (GCAL_IS_DAY_VIEW (object)); + + switch (property_id) + { + case PROP_DATE: + gcal_day_view_set_date ( + GCAL_DAY_VIEW (object), + g_value_dup_boxed (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gcal_day_view_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GcalDayViewPrivate *priv; + + g_return_if_fail (GCAL_IS_DAY_VIEW (object)); + priv = GCAL_DAY_VIEW (object)->priv; + + switch (property_id) + { + case PROP_DATE: + g_value_set_boxed (value, priv->date); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gcal_day_view_set_date (GcalDayView *view, + icaltimetype *date) + +{ + GcalDayViewPrivate *priv; + + priv = view->priv; + + if (priv->date != NULL) + g_free (priv->date); + + priv->date = date; +} + +/* Public API */ +/** + * gcal_day_view_new: + * @date: + * + * Since: 0.1 + * Return value: A new #GcalDayView + * Returns: (transfer full): + **/ +GtkWidget* +gcal_day_view_new (void) +{ + return g_object_new (GCAL_TYPE_DAY_VIEW, NULL); +} diff --git a/src/gcal-day-view.h b/src/gcal-day-view.h new file mode 100644 index 00000000..418a7d22 --- /dev/null +++ b/src/gcal-day-view.h @@ -0,0 +1,57 @@ +/* + * gcal-day-view.h + * + * Copyright (C) 2013 - Erick Pérez Castellanos + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __GCAL_DAY_VIEW_H__ +#define __GCAL_DAY_VIEW_H__ + +#include + +G_BEGIN_DECLS + +#define GCAL_TYPE_DAY_VIEW (gcal_day_view_get_type ()) +#define GCAL_DAY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_DAY_VIEW, GcalDayView)) +#define GCAL_DAY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_DAY_VIEW, GcalDayViewClass)) +#define GCAL_IS_DAY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_DAY_VIEW)) +#define GCAL_IS_DAY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_DAY_VIEW)) +#define GCAL_DAY_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_DAY_VIEW, GcalDayViewClass)) + +typedef struct _GcalDayView GcalDayView; +typedef struct _GcalDayViewClass GcalDayViewClass; +typedef struct _GcalDayViewPrivate GcalDayViewPrivate; + +struct _GcalDayView +{ + GtkGrid parent; + + /* add your public declarations here */ + GcalDayViewPrivate *priv; +}; + +struct _GcalDayViewClass +{ + GtkGridClass parent_class; +}; + +GType gcal_day_view_get_type (void); + +GtkWidget* gcal_day_view_new (void); + +G_END_DECLS + +#endif /* __GCAL_DAY_VIEW_H__ */