[evolution/clutter-calendar-v2] Port month view's basic stuff into Clutter.
- From: Srinivasa Ragavan <sragavan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/clutter-calendar-v2] Port month view's basic stuff into Clutter.
- Date: Mon, 6 Sep 2010 06:40:12 +0000 (UTC)
commit 07766972f6bc2268995b742541846077e220424d
Author: Srinivasa Ragavan <sragavan gnome org>
Date: Mon Sep 6 12:06:41 2010 +0530
Port month view's basic stuff into Clutter.
calendar/gui/Makefile.am | 2 +
calendar/gui/e-month-view.c | 39 ++
calendar/gui/e-week-view-clutter-main-item.c | 492 ++++++++++++++++++++++++++
calendar/gui/e-week-view-clutter-main-item.h | 83 +++++
calendar/gui/e-week-view.c | 251 ++++++++++++-
5 files changed, 851 insertions(+), 16 deletions(-)
---
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index bcaf1b4..72e68c9 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -94,6 +94,8 @@ libevolution_calendar_la_SOURCES = \
e-day-view-clutter-top-item.h \
e-week-view-clutter-titles-item.c \
e-week-view-clutter-titles-item.h \
+ e-week-view-clutter-main-item.c \
+ e-week-view-clutter-main-item.h \
cal-editor-utils.c \
cal-editor-utils.h \
calendar-config.c \
diff --git a/calendar/gui/e-month-view.c b/calendar/gui/e-month-view.c
index 238492c..e5efbca 100644
--- a/calendar/gui/e-month-view.c
+++ b/calendar/gui/e-month-view.c
@@ -21,6 +21,13 @@
#include "e-month-view.h"
+#if HAVE_CLUTTER
+#include "e-week-view-clutter-titles-item.h"
+#include "e-week-view-clutter-main-item.h"
+#endif
+
+#define WITHOUT_CLUTTER (g_getenv("WITHOUT_CLUTTER") != NULL)
+
#include <libecal/e-cal-time-util.h>
#define E_MONTH_VIEW_GET_PRIVATE(obj) \
@@ -59,7 +66,15 @@ month_view_cursor_key_up (EWeekView *week_view)
}
g_signal_emit_by_name (week_view, "selected-time-changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -92,7 +107,15 @@ month_view_cursor_key_down (EWeekView *week_view)
}
g_signal_emit_by_name (week_view, "selected-time-changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -121,7 +144,15 @@ month_view_cursor_key_left (EWeekView *week_view)
}
g_signal_emit_by_name (week_view, "selected-time-changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -154,7 +185,15 @@ month_view_cursor_key_right (EWeekView *week_view)
}
g_signal_emit_by_name (week_view, "selected-time-changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
diff --git a/calendar/gui/e-week-view-clutter-main-item.c b/calendar/gui/e-week-view-clutter-main-item.c
new file mode 100644
index 0000000..e4fff5a
--- /dev/null
+++ b/calendar/gui/e-week-view-clutter-main-item.c
@@ -0,0 +1,492 @@
+/*
+ * EWeekViewClutterMainItem - displays the background grid and dates for the Week and
+ * Month calendar views.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Authors:
+ * Srinivasa Ragavan <sragavan gnome org>
+ *
+ * Copyright (C) 2010 Intel Corporation. (www.intel.com)
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "e-week-view-clutter-main-item.h"
+#include "ea-calendar.h"
+#include "calendar-config.h"
+
+#define E_WEEK_VIEW_CLUTTER_MAIN_ITEM_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM, EWeekViewClutterMainItemPrivate))
+
+struct _EWeekViewClutterMainItemPrivate {
+ EWeekView *week_view;
+};
+
+enum {
+ PROP_0,
+ PROP_WEEK_VIEW
+};
+
+static gpointer parent_class;
+
+static gint
+gdate_to_cal_weekdays (GDateWeekday wd)
+{
+ switch (wd) {
+ case G_DATE_MONDAY: return CAL_MONDAY;
+ case G_DATE_TUESDAY: return CAL_TUESDAY;
+ case G_DATE_WEDNESDAY: return CAL_WEDNESDAY;
+ case G_DATE_THURSDAY: return CAL_THURSDAY;
+ case G_DATE_FRIDAY: return CAL_FRIDAY;
+ case G_DATE_SATURDAY: return CAL_SATURDAY;
+ case G_DATE_SUNDAY: return CAL_SUNDAY;
+ default: break;
+ }
+
+ return 0;
+}
+
+static void
+week_view_clutter_main_item_draw_day (EWeekViewClutterMainItem *main_item,
+ gint day,
+ GDate *date,
+ cairo_t *cr,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ EWeekView *week_view;
+ GtkStyle *style;
+ gint right_edge, bottom_edge, date_width, date_x, line_y;
+ gboolean show_day_name, show_month_name, selected;
+ gchar buffer[128], *format_string;
+ gint day_of_week, month, day_of_month, max_width;
+ GdkColor *bg_color;
+ PangoFontDescription *font_desc;
+ PangoContext *pango_context;
+ PangoFontMetrics *font_metrics;
+ PangoLayout *layout;
+ gboolean today = FALSE;
+ CalWeekdays working_days;
+
+ week_view = e_week_view_clutter_main_item_get_week_view (main_item);
+ style = gtk_widget_get_style (GTK_WIDGET (week_view));
+
+ /* Set up Pango prerequisites */
+ font_desc = pango_font_description_copy (style->font_desc);
+ pango_context = gtk_widget_get_pango_context (GTK_WIDGET (week_view));
+ font_metrics = pango_context_get_metrics (pango_context, font_desc,
+ pango_context_get_language (pango_context));
+
+ day_of_week = gdate_to_cal_weekdays (g_date_get_weekday (date));
+ month = g_date_get_month (date);
+ day_of_month = g_date_get_day (date);
+ line_y = y + E_WEEK_VIEW_DATE_T_PAD +
+ PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) +
+ PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) +
+ E_WEEK_VIEW_DATE_LINE_T_PAD;
+
+ if (!today) {
+ struct icaltimetype tt;
+
+ /* Check if we are drawing today */
+ tt = icaltime_from_timet_with_zone (time (NULL), FALSE,
+ e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
+ today = g_date_get_year (date) == tt.year
+ && g_date_get_month (date) == tt.month
+ && g_date_get_day (date) == tt.day;
+ }
+
+ working_days = calendar_config_get_working_days ();
+
+ /* Draw the background of the day. In the month view odd months are
+ one color and even months another, so you can easily see when each
+ month starts (defaults are white for odd - January, March, ... and
+ light gray for even). In the week view the background is always the
+ same color, the color used for the odd months in the month view. */
+ if (today)
+ bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_TODAY_BACKGROUND];
+ else if ((working_days & day_of_week) == 0)
+ bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_MONTH_NONWORKING_DAY];
+ else if (week_view->multi_week_view && (month % 2 == 0))
+ bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS];
+ else
+ bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS];
+
+ cairo_save (cr);
+ gdk_cairo_set_source_color (cr, bg_color);
+ cairo_rectangle (cr, x, y, width, height);
+ cairo_fill (cr);
+ cairo_restore (cr);
+
+ /* Draw the lines on the right and bottom of the cell. The canvas is
+ sized so that the lines on the right & bottom edges will be off the
+ edge of the canvas, so we don't have to worry about them. */
+ right_edge = x + width - 1;
+ bottom_edge = y + height - 1;
+
+ cairo_save (cr);
+ gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_GRID]);
+ cairo_set_line_width (cr, 0.7);
+ cairo_move_to (cr, right_edge, y);
+ cairo_line_to (cr, right_edge, bottom_edge);
+ cairo_move_to (cr, x, bottom_edge);
+ cairo_line_to (cr, right_edge, bottom_edge);
+ cairo_stroke (cr);
+ cairo_restore (cr);
+
+ /* If the day is selected, draw the blue background. */
+ cairo_save (cr);
+ selected = TRUE;
+ if (week_view->selection_start_day == -1
+ || week_view->selection_start_day > day
+ || week_view->selection_end_day < day)
+ selected = FALSE;
+ if (selected) {
+ if (gtk_widget_has_focus (GTK_WIDGET (week_view))) {
+ gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_SELECTED]);
+ } else {
+ gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_SELECTED]);
+ }
+
+ if (week_view->multi_week_view) {
+ cairo_rectangle (cr, x + 2, y + 1,
+ width - 5,
+ E_WEEK_VIEW_DATE_T_PAD - 1 +
+ PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) +
+ PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)));
+ cairo_fill (cr);
+ } else {
+ cairo_rectangle (cr, x + 2, y + 1,
+ width - 5, line_y - y);
+ cairo_fill (cr);
+ }
+ }
+ cairo_restore (cr);
+
+ /* Display the date in the top of the cell.
+ In the week view, display the long format "10 January" in all cells,
+ or abbreviate it to "10 Jan" or "10" if that doesn't fit.
+ In the month view, only use the long format for the first cell and
+ the 1st of each month, otherwise use "10". */
+ show_day_name = FALSE;
+ show_month_name = FALSE;
+ if (!week_view->multi_week_view) {
+ show_day_name = TRUE;
+ show_month_name = TRUE;
+ } else if (day == 0 || day_of_month == 1) {
+ show_month_name = TRUE;
+ }
+
+ /* Now find the longest form of the date that will fit. */
+ max_width = width - 4;
+ format_string = NULL;
+ if (show_day_name) {
+ if (week_view->max_day_width + week_view->digit_width * 2
+ + week_view->space_width * 2
+ + week_view->month_widths[month - 1] < max_width)
+ /* strftime format %A = full weekday name, %d = day of
+ month, %B = full month name. You can change the
+ order but don't change the specifiers or add
+ anything. */
+ format_string = _("%A %d %B");
+ else if (week_view->max_abbr_day_width
+ + week_view->digit_width * 2
+ + week_view->space_width * 2
+ + week_view->abbr_month_widths[month - 1] < max_width)
+ /* strftime format %a = abbreviated weekday name,
+ %d = day of month, %b = abbreviated month name.
+ You can change the order but don't change the
+ specifiers or add anything. */
+ format_string = _("%a %d %b");
+ }
+ if (!format_string && show_month_name) {
+ if (week_view->digit_width * 2 + week_view->space_width
+ + week_view->month_widths[month - 1] < max_width)
+ /* strftime format %d = day of month, %B = full
+ month name. You can change the order but don't
+ change the specifiers or add anything. */
+ format_string = _("%d %B");
+ else if (week_view->digit_width * 2 + week_view->space_width
+ + week_view->abbr_month_widths[month - 1] < max_width)
+ /* strftime format %d = day of month, %b = abbreviated
+ month name. You can change the order but don't
+ change the specifiers or add anything. */
+ format_string = _("%d %b");
+ }
+
+ cairo_save (cr);
+ if (selected) {
+ gdk_cairo_set_source_color (
+ cr, &week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED]);
+ } else if (week_view->multi_week_view) {
+ if (today) {
+ gdk_cairo_set_source_color (
+ cr, &week_view->colors[E_WEEK_VIEW_COLOR_TODAY]);
+ } else {
+ gdk_cairo_set_source_color (
+ cr, &week_view->colors[E_WEEK_VIEW_COLOR_DATES]);
+ }
+ } else {
+ gdk_cairo_set_source_color (
+ cr, &week_view->colors[E_WEEK_VIEW_COLOR_DATES]);
+ }
+
+ if (today) {
+ g_date_strftime (
+ buffer, sizeof (buffer),
+ format_string ? format_string : "<b>%d</b>", date);
+ pango_cairo_update_context (cr, pango_context);
+ layout = pango_cairo_create_layout (cr);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_set_text (layout, buffer, -1);
+ pango_layout_set_markup (layout, buffer, strlen(buffer));
+ } else {
+ g_date_strftime (buffer, sizeof (buffer),
+ format_string ? format_string : "%d", date);
+ pango_cairo_update_context (cr, pango_context);
+ layout = pango_cairo_create_layout (cr);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_set_text (layout, buffer, -1);
+ }
+
+ pango_layout_get_pixel_size (layout, &date_width, NULL);
+ date_x = x + width - date_width - E_WEEK_VIEW_DATE_R_PAD;
+ date_x = MAX (date_x, x + 1);
+
+ cairo_translate (cr, date_x, y + E_WEEK_VIEW_DATE_T_PAD);
+ pango_cairo_update_layout (cr, layout);
+ pango_cairo_show_layout (cr, layout);
+ cairo_restore (cr);
+ g_object_unref (layout);
+
+ /* Draw the line under the date. */
+ if (!week_view->multi_week_view) {
+ cairo_save (cr);
+ gdk_cairo_set_source_color (
+ cr, &week_view->colors[E_WEEK_VIEW_COLOR_GRID]);
+ cairo_set_line_width (cr, 0.7);
+ cairo_move_to (cr, x + E_WEEK_VIEW_DATE_LINE_L_PAD, line_y);
+ cairo_line_to (cr, right_edge, line_y);
+ cairo_stroke (cr);
+ cairo_restore (cr);
+ }
+ pango_font_metrics_unref (font_metrics);
+ pango_font_description_free (font_desc);
+}
+
+static void
+week_view_clutter_main_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_WEEK_VIEW:
+ e_week_view_clutter_main_item_set_week_view (
+ E_WEEK_VIEW_CLUTTER_MAIN_ITEM (object),
+ g_value_get_object (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+week_view_clutter_main_item_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_WEEK_VIEW:
+ g_value_set_object (
+ value, e_week_view_clutter_main_item_get_week_view (
+ E_WEEK_VIEW_CLUTTER_MAIN_ITEM (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+week_view_clutter_main_item_dispose (GObject *object)
+{
+ EWeekViewClutterMainItemPrivate *priv;
+
+ priv = E_WEEK_VIEW_CLUTTER_MAIN_ITEM_GET_PRIVATE (object);
+
+ if (priv->week_view != NULL) {
+ g_object_unref (priv->week_view);
+ priv->week_view = NULL;
+ }
+
+ /* Chain up to parent's dispose() method. */
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+week_view_clutter_main_item_draw (ClutterCairoTexture *canvas_item)
+{
+ EWeekViewClutterMainItem *main_item;
+ EWeekView *week_view;
+ GDate date;
+ gint num_days, day, day_x, day_y, day_w, day_h;
+ gint x=0, y=0;
+ gint width, height;
+ cairo_t *cr;
+
+ clutter_cairo_texture_clear (canvas_item);
+ clutter_cairo_texture_get_surface_size ((ClutterCairoTexture *)canvas_item, &width, &height);
+ cr = clutter_cairo_texture_create ((ClutterCairoTexture *)canvas_item);
+
+ main_item = E_WEEK_VIEW_CLUTTER_MAIN_ITEM (canvas_item);
+ week_view = e_week_view_clutter_main_item_get_week_view (main_item);
+ g_return_if_fail (week_view != NULL);
+
+ /* Step through each of the days. */
+ date = week_view->first_day_shown;
+
+ /* If no date has been set, we just use Dec 1999/January 2000. */
+ if (!g_date_valid (&date))
+ g_date_set_dmy (&date, 27, 12, 1999);
+
+ num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;
+ for (day = 0; day < num_days; day++) {
+ e_week_view_get_day_position (week_view, day,
+ &day_x, &day_y,
+ &day_w, &day_h);
+ /* Skip any days which are outside the area. */
+ if (day_x < x + width && day_x + day_w >= x
+ && day_y < y + height && day_y + day_h >= y) {
+ week_view_clutter_main_item_draw_day (
+ main_item, day, &date, cr,
+ day_x - x, day_y - y, day_w, day_h);
+ }
+ g_date_add_days (&date, 1);
+ }
+
+ cairo_destroy (cr);
+}
+
+static void
+week_view_clutter_main_item_class_init (EWeekViewClutterMainItemClass *class)
+{
+ GObjectClass *object_class;
+ ClutterCairoTextureClass *item_class;
+
+ parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (EWeekViewClutterMainItemPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = week_view_clutter_main_item_set_property;
+ object_class->get_property = week_view_clutter_main_item_get_property;
+ object_class->dispose = week_view_clutter_main_item_dispose;
+
+ item_class = CLUTTER_CAIRO_TEXTURE_CLASS (class);
+
+ g_object_class_install_property (
+ object_class,
+ PROP_WEEK_VIEW,
+ g_param_spec_object (
+ "week-view",
+ "Week View",
+ NULL,
+ E_TYPE_WEEK_VIEW,
+ G_PARAM_READWRITE));
+
+ /* init the accessibility support for e_week_view_clutter_main_item */
+ e_week_view_main_item_a11y_init ();
+}
+
+static void
+week_view_clutter_main_item_init (EWeekViewClutterMainItem *main_item)
+{
+ main_item->priv = E_WEEK_VIEW_CLUTTER_MAIN_ITEM_GET_PRIVATE (main_item);
+}
+
+GType
+e_week_view_clutter_main_item_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ const GTypeInfo type_info = {
+ sizeof (EWeekViewClutterMainItemClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) week_view_clutter_main_item_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL, /* class_data */
+ sizeof (EWeekViewClutterMainItem),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) week_view_clutter_main_item_init,
+ NULL /* value_table */
+ };
+
+ type = g_type_register_static (
+ CLUTTER_TYPE_CAIRO_TEXTURE, "EWeekViewClutterMainItem",
+ &type_info, 0);
+ }
+
+ return type;
+}
+
+EWeekView *
+e_week_view_clutter_main_item_get_week_view (EWeekViewClutterMainItem *main_item)
+{
+ g_return_val_if_fail (E_IS_WEEK_VIEW_CLUTTER_MAIN_ITEM (main_item), NULL);
+
+ return main_item->priv->week_view;
+}
+
+void
+e_week_view_clutter_main_item_set_week_view (EWeekViewClutterMainItem *main_item,
+ EWeekView *week_view)
+{
+ g_return_if_fail (E_IS_WEEK_VIEW_CLUTTER_MAIN_ITEM (main_item));
+ g_return_if_fail (E_IS_WEEK_VIEW (week_view));
+
+ if (main_item->priv->week_view != NULL)
+ g_object_unref (main_item->priv->week_view);
+
+ main_item->priv->week_view = g_object_ref (week_view);
+
+ g_object_notify (G_OBJECT (main_item), "week-view");
+}
+
+void
+e_week_view_clutter_main_item_redraw (EWeekViewClutterMainItem *item)
+{
+ clutter_cairo_texture_clear ((ClutterCairoTexture *)item);
+ week_view_clutter_main_item_draw ((ClutterActor *)item);
+}
+
+void
+e_week_view_clutter_main_item_set_size (EWeekViewClutterMainItem *item,
+ int width,
+ int height)
+{
+ clutter_cairo_texture_set_surface_size ((ClutterCairoTexture *)item, width, height);
+ week_view_clutter_main_item_draw (item);
+}
diff --git a/calendar/gui/e-week-view-clutter-main-item.h b/calendar/gui/e-week-view-clutter-main-item.h
new file mode 100644
index 0000000..4e751b8
--- /dev/null
+++ b/calendar/gui/e-week-view-clutter-main-item.h
@@ -0,0 +1,83 @@
+/*
+ * e-week-view-clutter-main-item.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Authors:
+ * Srinivasa Ragavan <sragavan gnome org>
+ *
+ * Copyright (C) 2010 Intel Corporation. (www.intel.com)
+ *
+ */
+
+/*
+ * EWeekViewClutterMainItem - displays the background grid and dates for the Week and
+ * Month calendar views.
+ */
+
+#ifndef E_WEEK_VIEW_CLUTTER_MAIN_ITEM_H
+#define E_WEEK_VIEW_CLUTTER_MAIN_ITEM_H
+
+#include "e-week-view.h"
+
+/* Standard GObject macros */
+#define E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM \
+ (e_week_view_clutter_main_item_get_type ())
+#define E_WEEK_VIEW_CLUTTER_MAIN_ITEM(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM, EWeekViewClutterMainItem))
+#define E_WEEK_VIEW_CLUTTER_MAIN_ITEM_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM, EWeekViewClutterMainItemClass))
+#define E_IS_WEEK_VIEW_CLUTTER_MAIN_ITEM(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM))
+#define E_IS_WEEK_VIEW_CLUTTER_MAIN_ITEM_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM))
+#define E_WEEK_VIEW_CLUTTER_MAIN_ITEM_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM, EWeekViewClutterMainItemClass))
+
+G_BEGIN_DECLS
+
+typedef struct _EWeekViewClutterMainItem EWeekViewClutterMainItem;
+typedef struct _EWeekViewClutterMainItemClass EWeekViewClutterMainItemClass;
+typedef struct _EWeekViewClutterMainItemPrivate EWeekViewClutterMainItemPrivate;
+
+struct _EWeekViewClutterMainItem {
+ ClutterCairoTexture parent;
+ EWeekViewClutterMainItemPrivate *priv;
+};
+
+struct _EWeekViewClutterMainItemClass {
+ ClutterCairoTextureClass parent_class;
+};
+
+GType e_week_view_clutter_main_item_get_type (void);
+EWeekView * e_week_view_clutter_main_item_get_week_view
+ (EWeekViewClutterMainItem *main_item);
+void e_week_view_clutter_main_item_set_week_view
+ (EWeekViewClutterMainItem *main_item,
+ EWeekView *week_view);
+void e_week_view_clutter_main_item_redraw
+ (EWeekViewClutterMainItem *item);
+void e_week_view_clutter_main_item_set_size
+ (EWeekViewClutterMainItem *item,
+ int width,
+ int height);
+G_END_DECLS
+
+#endif /* E_WEEK_VIEW_CLUTTER_MAIN_ITEM_H */
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 39e97dd..971d1b7 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -64,6 +64,7 @@
#if HAVE_CLUTTER
#include "e-week-view-clutter-titles-item.h"
+#include "e-week-view-clutter-main-item.h"
#endif
#define WITHOUT_CLUTTER (g_getenv("WITHOUT_CLUTTER") != NULL)
@@ -273,8 +274,15 @@ week_view_update_row (EWeekView *week_view, gint row)
g_free (rid);
week_view_process_component (week_view, comp_data);
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
e_week_view_queue_layout (week_view);
}
@@ -318,8 +326,15 @@ week_view_model_comps_deleted_cb (EWeekView *week_view,
e_week_view_remove_event_cb (week_view, event_num, NULL);
g_free (rid);
}
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
e_week_view_queue_layout (week_view);
}
@@ -356,8 +371,15 @@ week_view_model_rows_inserted_cb (EWeekView *week_view,
}
week_view_process_component (week_view, comp_data);
}
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
e_week_view_queue_layout (week_view);
}
@@ -424,9 +446,15 @@ week_view_time_range_changed_cb (EWeekView *week_view,
e_week_view_free_events (week_view);
return;
}
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
-
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
/* FIXME Preserve selection if possible */
if (week_view->selection_start_day == -1 ||
(week_view->multi_week_view ? week_view->weeks_shown * 7 : 7) <= week_view->selection_start_day)
@@ -478,8 +506,17 @@ week_view_notify_week_start_day_cb (EWeekView *week_view)
if (g_date_valid (first_day_shown))
e_week_view_set_first_day_shown (week_view, first_day_shown);
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->titles_canvas);
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_titles_item_redraw (week_view->titles_canvas_actor);
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -583,7 +620,15 @@ week_view_cursor_key_up (EWeekView *week_view)
week_view->selection_end_day = week_view->selection_start_day;
g_signal_emit_by_name (week_view, "selected_time_changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -601,7 +646,15 @@ week_view_cursor_key_down (EWeekView *week_view)
week_view->selection_end_day = week_view->selection_start_day;
g_signal_emit_by_name (week_view, "selected_time_changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -613,7 +666,15 @@ week_view_cursor_key_left (EWeekView *week_view)
week_view->selection_start_day = map_left[week_view->selection_start_day];
week_view->selection_end_day = week_view->selection_start_day;
g_signal_emit_by_name (week_view, "selected_time_changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -625,7 +686,15 @@ week_view_cursor_key_right (EWeekView *week_view)
week_view->selection_start_day = map_right[week_view->selection_start_day];
week_view->selection_end_day = week_view->selection_start_day;
g_signal_emit_by_name (week_view, "selected_time_changed");
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
static void
@@ -695,6 +764,21 @@ e_week_view_class_init (EWeekViewClass *class)
}
static void
+main_canvas_set_canvas_size (GtkWidget *widget,
+ GtkAllocation *allocation,
+ EWeekView *week_view)
+{
+ ClutterActor *stage = week_view->main_canvas_stage;
+ GtkWidget *embed = week_view->main_canvas_embed;
+ guint w,h;
+
+ gtk_widget_set_size_request (embed, allocation->width, allocation->height);
+ clutter_actor_set_size (stage, allocation->width, allocation->height);
+ clutter_actor_set_size (week_view->main_canvas_actor, allocation->width, allocation->height);
+ e_week_view_clutter_main_item_set_size ((EWeekViewClutterMainItem *)week_view->main_canvas_actor, allocation->width, allocation->height);
+}
+
+static void
titles_canvas_set_canvas_size (GtkWidget *widget,
GtkAllocation *allocation,
EWeekView *week_view)
@@ -712,7 +796,7 @@ titles_canvas_set_canvas_size (GtkWidget *widget,
static void
e_week_view_init (EWeekView *week_view)
{
- GnomeCanvasGroup *canvas_group;
+ GnomeCanvasGroup *canvas_group=NULL;
GtkObject *adjustment;
GdkPixbuf *pixbuf;
gint i;
@@ -821,7 +905,7 @@ e_week_view_init (EWeekView *week_view)
NULL);
clutter_actor_set_reactive (week_view->titles_canvas_actor, FALSE);
abox = mx_box_layout_new ();
- //clutter_actor_set_name (abox, "CalendarTitleBox");
+ clutter_actor_set_name (abox, "CalendarTitleBox");
mx_box_layout_set_orientation ((MxBoxLayout *)abox, MX_ORIENTATION_VERTICAL);
mx_box_layout_add_actor (MX_BOX_LAYOUT (abox),
@@ -841,12 +925,23 @@ e_week_view_init (EWeekView *week_view)
/*
* Main Canvas
*/
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
week_view->main_canvas = e_canvas_new ();
+#if HAVE_CLUTTER
+ } else {
+ week_view->main_canvas = gtk_layout_new (NULL, NULL);
+ }
+#endif
gtk_table_attach (GTK_TABLE (week_view), week_view->main_canvas,
1, 2, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
gtk_widget_show (week_view->main_canvas);
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->main_canvas)->root);
week_view->main_canvas_item =
@@ -854,7 +949,27 @@ e_week_view_init (EWeekView *week_view)
e_week_view_main_item_get_type (),
"EWeekViewMainItem::week_view", week_view,
NULL);
+#if HAVE_CLUTTER
+ } else {
+ week_view->main_canvas_embed = gtk_clutter_embed_new ();
+ gtk_widget_show (week_view->main_canvas_embed);
+ gtk_container_add ((GtkContainer *)week_view->main_canvas , (GtkWidget *)week_view->main_canvas_embed);
+ g_signal_connect (week_view->main_canvas, "size-allocate", G_CALLBACK(main_canvas_set_canvas_size), week_view);
+
+ week_view->main_canvas_stage = gtk_clutter_embed_get_stage ((GtkClutterEmbed *) week_view->main_canvas_embed);
+ week_view->main_canvas_actor = g_object_new (
+ E_TYPE_WEEK_VIEW_CLUTTER_MAIN_ITEM,
+ "EWeekViewClutterMainItem::week_view", week_view,
+ "surface-width", 300,
+ "surface-height", 50,
+ NULL);
+ clutter_actor_set_reactive (week_view->main_canvas_actor, FALSE);
+ clutter_container_add_actor ((ClutterContainer *)week_view->main_canvas_stage, (ClutterActor *)week_view->main_canvas_actor);
+ clutter_actor_show ((ClutterActor *)week_view->main_canvas_actor);
+
+ }
+#endif
g_signal_connect_after (week_view->main_canvas, "button_press_event",
G_CALLBACK (e_week_view_on_button_press), week_view);
g_signal_connect (week_view->main_canvas, "button_release_event",
@@ -1435,9 +1550,15 @@ e_week_view_focus_in (GtkWidget *widget, GdkEventFocus *event)
#if 0
GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
#endif
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
-
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
return FALSE;
}
@@ -1457,9 +1578,15 @@ e_week_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
#if 0
GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
#endif
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
-
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
return FALSE;
}
@@ -1663,8 +1790,15 @@ e_week_view_update_query (EWeekView *week_view)
if (!E_CALENDAR_VIEW (week_view)->in_focus)
return;
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
e_week_view_free_events (week_view);
e_week_view_queue_layout (week_view);
@@ -1764,8 +1898,15 @@ e_week_view_set_selected_time_range (ECalendarView *cal_view,
adjustment = gtk_range_get_adjustment (range);
gtk_adjustment_set_value (adjustment, 0);
}
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
void
@@ -1801,8 +1942,15 @@ e_week_view_set_selected_time_range_visible (EWeekView *week_view,
week_view->selection_end_day = CLAMP (week_view->selection_end_day,
week_view->selection_start_day,
num_days);
-
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
/* Returns the selected time range. */
@@ -1951,7 +2099,15 @@ e_week_view_set_first_day_shown (EWeekView *week_view,
}
e_week_view_update_query (week_view);
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
/* Recalculates the time_t corresponding to the start of each day. */
@@ -2151,9 +2307,17 @@ e_week_view_set_compress_weekend (EWeekView *week_view,
e_week_view_check_layout (week_view);
}
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->titles_canvas);
gtk_widget_queue_draw (week_view->main_canvas);
-
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_titles_item_redraw (week_view->titles_canvas_actor);
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
g_object_notify (G_OBJECT (week_view), "compress-weekend");
}
@@ -2536,7 +2700,15 @@ e_week_view_on_button_press (GtkWidget *widget,
g_signal_emit_by_name (week_view, "selected_time_changed");
/* FIXME: Optimise? */
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
} else if (event->button == 3) {
if (!gtk_widget_has_focus (GTK_WIDGET (week_view)))
@@ -2548,7 +2720,15 @@ e_week_view_on_button_press (GtkWidget *widget,
week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE;
/* FIXME: Optimise? */
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
e_week_view_show_popup_menu (week_view, event, -1);
@@ -2752,7 +2932,15 @@ e_week_view_update_selection (EWeekView *week_view,
/* FIXME: Optimise? */
if (need_redraw) {
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
}
}
@@ -3930,7 +4118,15 @@ e_week_view_change_event_time (EWeekView *week_view, time_t start_dt, time_t end
if (e_cal_component_has_recurrences (comp)) {
if (!recur_component_dialog (client, comp, &mod, NULL, FALSE)) {
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
goto out;
}
@@ -4043,7 +4239,15 @@ e_week_view_on_editing_stopped (EWeekView *week_view,
e_week_view_foreach_event_with_uid (week_view, uid,
e_week_view_remove_event_cb, NULL);
week_view->event_destroyed = TRUE;
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
e_week_view_check_layout (week_view);
goto out;
}
@@ -4374,8 +4578,15 @@ e_week_view_add_new_event_in_selected_range (EWeekView *week_view, const gchar *
add_event_data.comp_data = NULL;
e_week_view_add_event (comp, dtstart, dtend, TRUE, &add_event_data);
e_week_view_check_layout (week_view);
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
-
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
if (!e_week_view_find_event_from_uid (week_view, ecal, uid, NULL, &event_num)) {
g_warning ("Couldn't find event to start editing.\n");
g_object_unref (comp);
@@ -4729,7 +4940,15 @@ e_week_view_layout_timeout_cb (gpointer data)
{
EWeekView *week_view = E_WEEK_VIEW (data);
+#if HAVE_CLUTTER
+ if (WITHOUT_CLUTTER) {
+#endif
gtk_widget_queue_draw (week_view->main_canvas);
+#if HAVE_CLUTTER
+ } else {
+ e_week_view_clutter_main_item_redraw (week_view->main_canvas_actor);
+ }
+#endif
e_week_view_check_layout (week_view);
week_view->layout_timeout_id = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]