From 24b8c553dcd4a1802b583e67f80859daca289ad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erick=20P=C3=A9rez=20Castellanos?= Date: Thu, 15 Jan 2015 00:45:54 -0500 Subject: [PATCH] year-view: initial commit Dropped almost everything. Started using an ui file and using a GtkBox as a parent. --- data/Makefile.am | 1 + data/calendar.gresource.xml | 1 + data/ui/year-view.ui | 41 ++ src/gcal-window.c | 8 +- src/gcal-year-view.c | 1071 +++++------------------------------ src/gcal-year-view.h | 50 +- 6 files changed, 212 insertions(+), 960 deletions(-) create mode 100644 data/ui/year-view.ui diff --git a/data/Makefile.am b/data/Makefile.am index d3240cda..2cd4ceee 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -40,6 +40,7 @@ EXTRA_DIST= \ ui/search-view.ui \ ui/time-selector.ui \ ui/window.ui \ + ui/year-view.ui \ theme/gtk-styles.css \ $(desktop_in_files) \ $(gsettingsschema_in_files) diff --git a/data/calendar.gresource.xml b/data/calendar.gresource.xml index 5b2ba2f8..c6712adc 100644 --- a/data/calendar.gresource.xml +++ b/data/calendar.gresource.xml @@ -8,6 +8,7 @@ ui/search-view.ui ui/time-selector.ui ui/window.ui + ui/year-view.ui theme/gtk-styles.css diff --git a/data/ui/year-view.ui b/data/ui/year-view.ui new file mode 100644 index 00000000..3654386d --- /dev/null +++ b/data/ui/year-view.ui @@ -0,0 +1,41 @@ + + + + + + diff --git a/src/gcal-window.c b/src/gcal-window.c index 54877939..65c8fcdf 100644 --- a/src/gcal-window.c +++ b/src/gcal-window.c @@ -1294,11 +1294,9 @@ gcal_window_constructed (GObject *object) gcal_month_view_set_use_24h_format (GCAL_MONTH_VIEW (priv->views[GCAL_WINDOW_VIEW_MONTH]), use_24h_format); gtk_stack_add_titled (GTK_STACK (priv->views_stack), priv->views[GCAL_WINDOW_VIEW_MONTH], "month", _("Month")); - priv->views[GCAL_WINDOW_VIEW_YEAR] = - gcal_year_view_new (priv->manager); - gtk_stack_add_titled (GTK_STACK (priv->views_stack), - priv->views[GCAL_WINDOW_VIEW_YEAR], - "year", _("Year")); + priv->views[GCAL_WINDOW_VIEW_YEAR] = GTK_WIDGET (gcal_year_view_new ()); + gcal_year_view_set_manager (GCAL_YEAR_VIEW (priv->views[GCAL_WINDOW_VIEW_YEAR]), priv->manager); + gtk_stack_add_titled (GTK_STACK (priv->views_stack), priv->views[GCAL_WINDOW_VIEW_YEAR], "year", _("Year")); /* search view */ gcal_search_view_connect (GCAL_SEARCH_VIEW (priv->search_view), priv->manager); diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c index 1136fd03..9dd66d44 100644 --- a/src/gcal-year-view.c +++ b/src/gcal-year-view.c @@ -1,12 +1,11 @@ /* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * gcal-year-view.c +/* gcal-year-view.c * - * Copyright (C) 2012 - Erick Pérez Castellanos + * Copyright (C) 2015 Erick Pérez Castellanos * - * This program is free software; you can redistribute it and/or modify + * 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 + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -19,978 +18,186 @@ */ #include "gcal-year-view.h" -#include "gcal-subscriber-view-private.h" -#include "gcal-utils.h" #include "gcal-view.h" -#include - -typedef struct +struct _GcalYearViewPrivate { - /* overflow buttons */ - GHashTable *internal_children; + /* composite, GtkBuilder's widgets */ + GtkWidget *year_view_navigator; + GtkWidget *sidebar; + GtkWidget *add_event_button; + GtkWidget *events_listbox; - GdkWindow *event_window; + /* manager singleton */ + GcalManager *manager; - /* input events flags */ - gint clicked_cell; - gint start_mark_cell; - gint end_mark_cell; - - /* text direction factors */ - gint k; - - /* property */ - icaltimetype *date; - GcalManager *manager; /* weak reference */ -} GcalYearViewPrivate; - -enum -{ - PROP_0, - PROP_DATE, //active-date inherited property - PROP_MANAGER //manager inherited property + /* date property */ + icaltimetype *date; }; -static gboolean get_widget_parts (gint first_cell, - gint last_cell, - gint natural_height, - gdouble vertical_cell_space, - gdouble *size_left, - GArray *cells, - GArray *lengths); +enum { + PROP_0, + PROP_DATE, + LAST_PROP +}; -static void gcal_view_interface_init (GcalViewIface *iface); +static void gcal_view_interface_init (GcalViewIface *iface); +static void gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface); -static void gcal_year_view_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); - -static void gcal_year_view_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void gcal_year_view_finalize (GObject *object); - -static void gcal_year_view_realize (GtkWidget *widget); - -static void gcal_year_view_unrealize (GtkWidget *widget); - -static void gcal_year_view_map (GtkWidget *widget); - -static void gcal_year_view_unmap (GtkWidget *widget); - -static void gcal_year_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static gboolean gcal_year_view_draw (GtkWidget *widget, - cairo_t *cr); - -static gboolean gcal_year_view_button_press (GtkWidget *widget, - GdkEventButton *event); - -static gboolean gcal_year_view_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event); - -static gboolean gcal_year_view_button_release (GtkWidget *widget, - GdkEventButton *event); - -static void gcal_year_view_direction_changed (GtkWidget *widget, - GtkTextDirection previous_direction); - -static gboolean gcal_year_view_is_child_multimonth (GcalSubscriberView *subscriber, - GcalEventWidget *child); - -static guint gcal_year_view_get_child_cell (GcalSubscriberView *subscriber, - GcalEventWidget *child); - -static icaltimetype* gcal_year_view_get_initial_date (GcalView *view); - -static icaltimetype* gcal_year_view_get_final_date (GcalView *view); - -static void gcal_year_view_clear_marks (GcalView *view); - -static gchar* gcal_year_view_get_left_header (GcalView *view); - -static gchar* gcal_year_view_get_right_header (GcalView *view); - -G_DEFINE_TYPE_WITH_CODE (GcalYearView, gcal_year_view, GCAL_TYPE_SUBSCRIBER_VIEW, +G_DEFINE_TYPE_WITH_CODE (GcalYearView, gcal_year_view, GTK_TYPE_BOX, G_ADD_PRIVATE (GcalYearView) - G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW,gcal_view_interface_init)); + G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW, gcal_view_interface_init) + G_IMPLEMENT_INTERFACE (E_TYPE_CAL_DATA_MODEL_SUBSCRIBER, + gcal_data_model_subscriber_interface_init)); + +static void +update_date (GcalYearView *year_view, + icaltimetype *new_date) +{ + GcalYearViewPrivate *priv = year_view->priv; + + /* FIXME: add updating subscribe range */ + if (priv->date != NULL) + g_free (priv->date); + priv->date = new_date; +} static gboolean -get_widget_parts (gint first_cell, - gint last_cell, - gint natural_height, - gdouble vertical_cell_space, - gdouble *size_left, - GArray *cells, - GArray *lengths) +draw_navigator (GcalYearView *year_view, + cairo_t *cr, + GtkWidget *widget) { - gint i; - gint current_part_length; - gdouble y, old_y = - 1.0; + /* FIXME: draw navigator */ + guint width, height; + GdkRGBA color; - if (last_cell < first_cell) + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + cairo_arc (cr, width / 2.0, height / 2.0, MIN (width, height) / 2.0, 0, 2 * G_PI); + + gtk_style_context_get_color (gtk_widget_get_style_context (widget), 0, &color); + gdk_cairo_set_source_rgba (cr, &color); + + cairo_fill (cr); + + return FALSE; +} + +static void +add_event_clicked_cb (GcalYearView *year_view, + GtkButton *button) +{ + /* FIXME: implement send detailed signal */ +} + +static void +gcal_year_view_finalize (GObject *object) +{ + GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (object)->priv; + + if (priv->date != NULL) + g_free (priv->date); + + G_OBJECT_CLASS (gcal_year_view_parent_class)->finalize (object); +} + +static void +gcal_year_view_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GcalYearViewPrivate *priv = GCAL_YEAR_VIEW (object)->priv; + + switch (prop_id) { - gint swap = last_cell; - last_cell = first_cell; - first_cell = swap; - } + case PROP_DATE: + g_value_set_boxed (value, priv->date); + break; - for (i = first_cell; i <= last_cell; i++) + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +gcal_year_view_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (prop_id) { - if (size_left[i] < natural_height) - { - return FALSE; - } - else - { - y = vertical_cell_space - size_left[i]; - if (y != old_y) - { - current_part_length = 1; - g_array_append_val (cells, i); - g_array_append_val (lengths, current_part_length); - old_y = y; - } - else - { - current_part_length++; - g_array_index (lengths, gint, lengths->len - 1) = current_part_length; - } - } - } + case PROP_DATE: + update_date (GCAL_YEAR_VIEW (object), g_value_dup_boxed (value)); + break; - return TRUE; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } } static void gcal_year_view_class_init (GcalYearViewClass *klass) { - GcalSubscriberViewClass *subscriber_view_class; - GtkWidgetClass *widget_class; - GObjectClass *object_class; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - subscriber_view_class = GCAL_SUBSCRIBER_VIEW_CLASS (klass); - subscriber_view_class->is_child_multicell = gcal_year_view_is_child_multimonth; - subscriber_view_class->get_child_cell = gcal_year_view_get_child_cell; - - widget_class = GTK_WIDGET_CLASS (klass); - widget_class->realize = gcal_year_view_realize; - widget_class->unrealize = gcal_year_view_unrealize; - widget_class->map = gcal_year_view_map; - widget_class->unmap = gcal_year_view_unmap; - widget_class->size_allocate = gcal_year_view_size_allocate; - widget_class->draw = gcal_year_view_draw; - widget_class->button_press_event = gcal_year_view_button_press; - widget_class->motion_notify_event = gcal_year_view_motion_notify_event; - widget_class->button_release_event = gcal_year_view_button_release; - widget_class->direction_changed = gcal_year_view_direction_changed; - - object_class = G_OBJECT_CLASS (klass); - object_class->set_property = gcal_year_view_set_property; - object_class->get_property = gcal_year_view_get_property; object_class->finalize = gcal_year_view_finalize; + object_class->get_property = gcal_year_view_get_property; + object_class->set_property = gcal_year_view_set_property; g_object_class_override_property (object_class, PROP_DATE, "active-date"); - g_object_class_override_property (object_class, PROP_MANAGER, "manager"); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/year-view.ui"); + + gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, year_view_navigator); + gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, sidebar); + gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, add_event_button); + gtk_widget_class_bind_template_child_private (widget_class, GcalYearView, events_listbox); + + gtk_widget_class_bind_template_callback (widget_class, draw_navigator); + gtk_widget_class_bind_template_callback (widget_class, add_event_clicked_cb); } static void gcal_year_view_init (GcalYearView *self) { - GcalYearViewPrivate *priv; - - gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); - - priv = gcal_year_view_get_instance_private (self); - - priv->clicked_cell = -1; - priv->start_mark_cell = -1; - priv->end_mark_cell = -1; - - if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR) - priv->k = 0; - else if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL) - priv->k = 1; + self->priv = gcal_year_view_get_instance_private (self); + gtk_widget_init_template (GTK_WIDGET (self)); gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "calendar-view"); } static void gcal_view_interface_init (GcalViewIface *iface) { - /* New API */ - iface->get_initial_date = gcal_year_view_get_initial_date; - iface->get_final_date = gcal_year_view_get_final_date; - - iface->clear_marks = gcal_year_view_clear_marks; - - iface->get_left_header = gcal_year_view_get_left_header; - iface->get_right_header = gcal_year_view_get_right_header; + /* FIXME: implement what's needed */ } static void -gcal_year_view_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface) { - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (object)); - - switch (property_id) - { - case PROP_DATE: - { - time_t range_start, range_end; - icaltimetype *date; - icaltimezone* default_zone; - - if (priv->date != NULL) - g_free (priv->date); - - priv->date = g_value_dup_boxed (value); - - default_zone = - gcal_manager_get_system_timezone (priv->manager); - date = gcal_view_get_initial_date (GCAL_VIEW (object)); - range_start = icaltime_as_timet_with_zone (*date, - default_zone); - g_free (date); - date = gcal_view_get_final_date (GCAL_VIEW (object)); - range_end = icaltime_as_timet_with_zone (*date, - default_zone); - g_free (date); - gcal_manager_set_subscriber (priv->manager, - E_CAL_DATA_MODEL_SUBSCRIBER (object), - range_start, - range_end); - gtk_widget_queue_draw (GTK_WIDGET (object)); - break; - } - case PROP_MANAGER: - { - priv->manager = g_value_get_pointer (value); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -gcal_year_view_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (object)); - - 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_year_view_finalize (GObject *object) -{ - GcalYearViewPrivate *priv; - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (object)); - - if (priv->date != NULL) - g_free (priv->date); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (gcal_year_view_parent_class)->finalize (object); -} - -static void -gcal_year_view_realize (GtkWidget *widget) -{ - GcalYearViewPrivate *priv; - GdkWindow *parent_window; - GdkWindowAttr attributes; - gint attributes_mask; - GtkAllocation allocation; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - gtk_widget_set_realized (widget, TRUE); - - parent_window = gtk_widget_get_parent_window (widget); - gtk_widget_set_window (widget, parent_window); - g_object_ref (parent_window); - - gtk_widget_get_allocation (widget, &allocation); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.wclass = GDK_INPUT_ONLY; - attributes.x = allocation.x; - attributes.y = allocation.y; - attributes.width = allocation.width; - attributes.height = allocation.height; - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON1_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK | - GDK_POINTER_MOTION_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK); - attributes_mask = GDK_WA_X | GDK_WA_Y; - - priv->event_window = gdk_window_new (parent_window, - &attributes, - attributes_mask); - gtk_widget_register_window (widget, priv->event_window); -} - -static void -gcal_year_view_unrealize (GtkWidget *widget) -{ - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - if (priv->event_window != NULL) - { - gtk_widget_unregister_window (widget, priv->event_window); - gdk_window_destroy (priv->event_window); - priv->event_window = NULL; - } - - GTK_WIDGET_CLASS (gcal_year_view_parent_class)->unrealize (widget); -} - -static void -gcal_year_view_map (GtkWidget *widget) -{ - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - if (priv->event_window) - gdk_window_show (priv->event_window); - - GTK_WIDGET_CLASS (gcal_year_view_parent_class)->map (widget); -} - -static void -gcal_year_view_unmap (GtkWidget *widget) -{ - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - if (priv->event_window) - gdk_window_hide (priv->event_window); - - GTK_WIDGET_CLASS (gcal_year_view_parent_class)->unmap (widget); -} - -static void -gcal_year_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GcalYearViewPrivate *priv; - GcalSubscriberViewPrivate *ppriv; - gint i, j, sw; - - gint padding_bottom; - PangoLayout *layout; - PangoFontDescription *font_desc; - gint font_height; - - gdouble cell_width, cell_height, vertical_cell_space; - gdouble pos_x, pos_y; - gdouble size_left [12]; - - const gchar *uuid; - GtkWidget *child_widget; - GtkAllocation child_allocation; - gint natural_height; - - GList *widgets, *l, *aux, *l2 = NULL; - GHashTableIter iter; - gpointer key, value; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - ppriv = GCAL_SUBSCRIBER_VIEW (widget)->priv; - - if (!ppriv->children_changed && - allocation->height == gtk_widget_get_allocated_height (widget) && - allocation->width == gtk_widget_get_allocated_width (widget)) - { - return; - } - - /* remove every widget' parts, but the master widget */ - widgets = g_hash_table_get_values (ppriv->children); - for (aux = widgets; aux != NULL; aux = g_list_next (aux)) - { - l = g_list_next ((GList*) aux->data); - for (; l != NULL; l = g_list_next (l)) - l2 = g_list_append (l2, l->data); - } - g_list_free (widgets); - - g_list_foreach (l2, (GFunc) gtk_widget_destroy, NULL); - g_list_free (l2); - - /* clean overflow information */ - g_hash_table_remove_all (ppriv->overflow_cells); - - gtk_widget_set_allocation (widget, allocation); - if (gtk_widget_get_realized (widget)) - gdk_window_move_resize (priv->event_window, allocation->x, allocation->y, allocation->width, allocation->height); - - gtk_style_context_get (gtk_widget_get_style_context (widget), gtk_widget_get_state_flags (widget), - "font", &font_desc, "padding-bottom", &padding_bottom, NULL); - - layout = gtk_widget_create_pango_layout (widget, _("Other events")); - pango_layout_set_font_description (layout, font_desc); - pango_layout_get_pixel_size (layout, NULL, &font_height); - pango_font_description_free (font_desc); - g_object_unref (layout); - - cell_width = allocation->width / 6.0; - cell_height = allocation->height / 2.0; - vertical_cell_space = cell_height - (padding_bottom + font_height); - - for (i = 0; i < 12; i++) - size_left[i] = vertical_cell_space; - - sw = 1 - 2 * priv->k; - - /* allocate multimonth events */ - for (l = ppriv->multi_cell_children; l != NULL; l = g_list_next (l)) - { - gint first_cell, last_cell, first_row, last_row, start, end; - gboolean visible; - - const icaltimetype *date; - GArray *cells, *lengths; - - child_widget = (GtkWidget*) l->data; - uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child_widget)); - if (!gtk_widget_is_visible (child_widget) && !g_hash_table_contains (ppriv->hidden_as_overflow, uuid)) - continue; - - gtk_widget_show (child_widget); - gtk_widget_get_preferred_height (child_widget, NULL, &natural_height); - - j = 1; - date = gcal_event_widget_peek_start_date (GCAL_EVENT_WIDGET (child_widget)); - if (date->year == priv->date->year) - j = date->month; - first_cell = 6 * ((j - 1) / 6) + 6 * priv->k + sw * ((j - 1) % 6) - (1 * priv->k); - - j = 12; - date = gcal_event_widget_peek_end_date (GCAL_EVENT_WIDGET (child_widget)); - if (date->year == priv->date->year) - j = date->month; - last_cell = 6 * ((j - 1) / 6) + 6 * priv->k + sw * ((j - 1) % 6) - (1 * priv->k); - - /* FIXME missing mark widgets with continuos tags */ - - first_row = first_cell / 6; - last_row = last_cell / 6; - visible = TRUE; - cells = g_array_sized_new (TRUE, TRUE, sizeof (gint), 16); - lengths = g_array_sized_new (TRUE, TRUE, sizeof (gint), 16); - for (i = first_row; i <= last_row && visible; i++) - { - start = i * 6 + priv->k * 5; - end = i * 6 + (1 - priv->k) * 5; - - if (i == first_row) - { - start = first_cell; - } - if (i == last_row) - { - end = last_cell; - } - - visible = get_widget_parts (start, end, natural_height, vertical_cell_space, size_left, cells, lengths); - } - - if (visible) - { - for (i = 0; i < cells->len; i++) - { - gint cell_idx = g_array_index (cells, gint, i); - gint row = cell_idx / 6; - gint column = cell_idx % 6; - pos_x = cell_width * column; - pos_y = cell_height * row; - - child_allocation.x = pos_x; - child_allocation.y = pos_y + vertical_cell_space - size_left[cell_idx]; - child_allocation.width = cell_width * g_array_index (lengths, gint, i); - child_allocation.height = natural_height; - - if (i != 0) - { - child_widget = gcal_event_widget_clone (GCAL_EVENT_WIDGET (child_widget)); - - _gcal_subscriber_view_setup_child (GCAL_SUBSCRIBER_VIEW (widget), child_widget); - gtk_widget_show (child_widget); - - aux = g_hash_table_lookup (ppriv->children, uuid); - aux = g_list_append (aux, child_widget); - } - gtk_widget_size_allocate (child_widget, &child_allocation); - g_hash_table_remove (ppriv->hidden_as_overflow, uuid); - - /* update size_left */ - for (j = 0; j < g_array_index (lengths, gint, i); j++) - size_left[cell_idx + j] -= natural_height; - } - } - else - { - gtk_widget_hide (child_widget); - g_hash_table_add (ppriv->hidden_as_overflow, g_strdup (uuid)); - - for (i = first_cell; i <= last_cell; i++) - { - aux = g_hash_table_lookup (ppriv->overflow_cells, GINT_TO_POINTER (i)); - aux = g_list_append (aux, child_widget); - - if (g_list_length (aux) == 1) - g_hash_table_insert (ppriv->overflow_cells, GINT_TO_POINTER (i), aux); - else - g_hash_table_replace (ppriv->overflow_cells, GINT_TO_POINTER (i), g_list_copy (aux)); - } - } - - g_array_free (cells, TRUE); - g_array_free (lengths, TRUE); - } - - g_hash_table_iter_init (&iter, ppriv->single_cell_children); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - j = GPOINTER_TO_INT (key); - i = 6 * ((j - 1) / 6) + 6 * priv->k + sw * ((j - 1) % 6) - (1 * priv->k); - - l = (GList*) value; - for (aux = l; aux != NULL; aux = g_list_next (aux)) - { - child_widget = (GtkWidget*) aux->data; - - uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child_widget)); - if (!gtk_widget_is_visible (child_widget) && !g_hash_table_contains (ppriv->hidden_as_overflow, uuid)) - continue; - - gtk_widget_show (child_widget); - gtk_widget_get_preferred_height (child_widget, NULL, &natural_height); - - if (size_left[i] > natural_height) - { - pos_x = cell_width * (i % 6); - pos_y = cell_height * (i / 6); - - child_allocation.x = pos_x; - child_allocation.y = pos_y + vertical_cell_space - size_left[i]; - child_allocation.width = cell_width; - child_allocation.height = natural_height; - gtk_widget_show (child_widget); - gtk_widget_size_allocate (child_widget, &child_allocation); - g_hash_table_remove (ppriv->hidden_as_overflow, uuid); - - size_left[i] -= natural_height; - } - else - { - gtk_widget_hide (child_widget); - g_hash_table_add (ppriv->hidden_as_overflow, g_strdup (uuid)); - - l = g_hash_table_lookup (ppriv->overflow_cells, GINT_TO_POINTER (i)); - l = g_list_append (l, child_widget); - - if (g_list_length (l) == 1) - g_hash_table_insert (ppriv->overflow_cells, GINT_TO_POINTER (i), l); - else - g_hash_table_replace (ppriv->overflow_cells, GINT_TO_POINTER (i), g_list_copy (l)); - } - } - } - - /* FIXME: remove on Gtk+ 3.15.4 release */ - if (g_hash_table_size (ppriv->overflow_cells) != 0) - gtk_widget_queue_draw_area (widget, allocation->x, allocation->y, allocation->width, allocation->height); - - ppriv->children_changed = FALSE; -} - -static gboolean -gcal_year_view_draw (GtkWidget *widget, - cairo_t *cr) -{ - GcalYearViewPrivate *priv; - - GtkStyleContext *context; - GtkStateFlags state; - - GtkBorder padding; - GtkAllocation alloc; - - /* new declares */ - PangoLayout *layout; - PangoFontDescription *font_desc; - GdkRGBA color; - - gdouble cell_width, cell_height, sw; - gint i, j, pos_x, pos_y; - int font_width, font_height; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - gtk_widget_get_allocation (widget, &alloc); - context = gtk_widget_get_style_context (widget); - state = gtk_widget_get_state_flags (widget); - layout = gtk_widget_create_pango_layout (widget, NULL); - - /* calculations */ - cell_width = alloc.width / 6.0; - cell_height = alloc.height / 2.0; - sw = 1 - 2 * priv->k; - - gtk_style_context_get_padding (context, state, &padding); - gtk_style_context_get (context, state, "font", &font_desc, NULL); - - pango_layout_set_font_description (layout, font_desc); - for (i = 0; i < 12; i++) - { - gint column = i % 6; - gint row = i / 6; - - j = 6 * ((i + 6 * priv->k) / 6) + sw * (i % 6) + (1 - priv->k); - - if (priv->date->month == j) - { - PangoLayout *clayout; - PangoFontDescription *cfont_desc; - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "current"); - - clayout = gtk_widget_create_pango_layout (widget, gcal_get_month_name (j - 1)); - gtk_style_context_get (context, state, "font", &cfont_desc, NULL); - pango_layout_set_font_description (clayout, cfont_desc); - pango_layout_get_pixel_size (clayout, &font_width, &font_height); - - /* FIXME: hardcoded padding of the number background */ - gtk_render_background (context, cr, - cell_width * (column + 1 - priv->k) - sw * padding.right + (priv->k - 1) * font_width - 2.0, - cell_height * (row + 1) - font_height - padding.bottom, - font_width + 4, font_height + 2); - gtk_render_layout (context, cr, - cell_width * (column + 1 - priv->k) - sw * padding.right + (priv->k - 1) * font_width, - cell_height * (row + 1) - font_height - padding.bottom, - clayout); - - gtk_style_context_restore (context); - pango_font_description_free (cfont_desc); - g_object_unref (clayout); - } - else - { - pango_layout_set_text (layout, gcal_get_month_name (j - 1), -1); - pango_layout_get_pixel_size (layout, &font_width, &font_height); - - gtk_render_layout (context, cr, - cell_width * (column + 1 - priv->k) - sw * padding.right + (priv->k - 1) * font_width, - cell_height * (row + 1) - font_height - padding.bottom, - layout); - - } - } - pango_font_description_free (font_desc); - - /* FIXME: missing selected months lines */ - - /* drawing grid skel */ - gtk_style_context_save (context); - gtk_style_context_add_class (context, "lines"); - - gtk_style_context_get_color (context, state, &color); - gdk_cairo_set_source_rgba (cr, &color); - cairo_set_line_width (cr, 0.2); - - /* vertical lines */ - for (i = 0; i < 5; i++) - { - pos_x = cell_width * (i + 1); - cairo_move_to (cr, pos_x + 0.4, 0); - cairo_rel_line_to (cr, 0, alloc.height); - } - - for (i = 0; i < 2; i++) - { - pos_y = (alloc.height / 2) * i; - cairo_move_to (cr, 0, pos_y + 0.4); - cairo_rel_line_to (cr, alloc.width, 0); - } - cairo_stroke (cr); - gtk_style_context_restore (context); - - if (GTK_WIDGET_CLASS (gcal_year_view_parent_class)->draw != NULL) - GTK_WIDGET_CLASS (gcal_year_view_parent_class)->draw (widget, cr); - - return FALSE; -} - -static gboolean -gcal_year_view_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - GcalYearViewPrivate *priv; - - gdouble x, y; - gint width, height; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - - x = event->x; - y = event->y; - - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); - - priv->clicked_cell = 6 * ( (gint ) ( y / (height / 2) )) + ((gint) ( x / (width / 6) )); - priv->start_mark_cell = priv->clicked_cell; - - return TRUE; -} - -static gboolean -gcal_year_view_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event) -{ - GcalYearViewPrivate *priv; - - gint width, height; - gint y; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - - if (priv->clicked_cell == -1) - return FALSE; - - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); - - y = event->y; - - if (y < 0) - return FALSE; - - priv->end_mark_cell = 6 * ( (gint ) ( y / (height / 2) )) + ((gint) ( event->x / (width / 6) )); - - gtk_widget_queue_draw (widget); - - return TRUE; -} - -static gboolean -gcal_year_view_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - GcalYearViewPrivate *priv; - - gdouble x, y; - gint width, height; - - icaltimetype *start_date; - icaltimetype *end_date; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - - if (priv->clicked_cell == -1) - return FALSE; - - x = event->x; - y = event->y; - - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); - - priv->end_mark_cell = 6 * ( (gint ) ( y / (height / 2) )) + ((gint) ( x / (width / 6) )); - - x = (width / 6) * (( priv->end_mark_cell % 6) + 0.5); - y = (height / 2) * (( priv->end_mark_cell / 6) + 0.5); - - start_date = gcal_dup_icaltime (priv->date); - start_date->day = 1; - start_date->month = priv->start_mark_cell + 1; - start_date->is_date = 1; - - end_date = gcal_dup_icaltime (priv->date); - end_date->day = icaltime_days_in_month (priv->end_mark_cell + 1, - end_date->year); - end_date->month = priv->end_mark_cell + 1; - end_date->is_date = 1; - - if (priv->start_mark_cell > priv->end_mark_cell) - { - start_date->month = priv->end_mark_cell + 1; - end_date->day = icaltime_days_in_month (priv->start_mark_cell + 1, - end_date->year); - end_date->month = priv->start_mark_cell + 1; - } - - g_signal_emit_by_name (GCAL_VIEW (widget), - "create-event", - start_date, end_date, - x, y); - g_free (start_date); - g_free (end_date); - - priv->clicked_cell = -1; - return TRUE; -} - -static void -gcal_year_view_direction_changed (GtkWidget *widget, - GtkTextDirection previous_direction) -{ - GcalYearViewPrivate *priv; - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (widget)); - - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) - priv->k = 0; - else if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) - priv->k = 1; -} - -static gboolean -gcal_year_view_is_child_multimonth (GcalSubscriberView *subscriber, - GcalEventWidget *child) -{ - const icaltimetype *dt_start, *dt_end; - - dt_start = gcal_event_widget_peek_start_date (child); - dt_end = gcal_event_widget_peek_end_date (child); - if (dt_end == NULL) - return FALSE; - - return dt_start->month != dt_end->month || dt_start->year != dt_end->year; -} - -static guint -gcal_year_view_get_child_cell (GcalSubscriberView *subscriber, - GcalEventWidget *child) -{ - const icaltimetype *dt_start = gcal_event_widget_peek_start_date (child); - return dt_start->month; -} - -/* GcalView Interface API */ -/** - * gcal_year_view_get_initial_date: - * - * Since: 0.1 - * Return value: the January first of the current year. - * Returns: (transfer full): Release with g_free() - **/ -static icaltimetype* -gcal_year_view_get_initial_date (GcalView *view) -{ - GcalYearViewPrivate *priv; - icaltimetype *new_date; - - g_return_val_if_fail (GCAL_IS_YEAR_VIEW (view), NULL); - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (view)); - - new_date = gcal_dup_icaltime (priv->date); - new_date->day = 1; - new_date->month = 1; - new_date->is_date = 0; - new_date->hour = 0; - new_date->minute = 0; - new_date->second = 0; - - return new_date; -} - -/** - * gcal_year_view_get_final_date: - * - * Since: 0.1 - * Return value: the last day of the month - * Returns: (transfer full): Release with g_free() - **/ -static icaltimetype* -gcal_year_view_get_final_date (GcalView *view) -{ - GcalYearViewPrivate *priv; - icaltimetype *new_date; - - g_return_val_if_fail (GCAL_IS_YEAR_VIEW (view), NULL); - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (view)); - - new_date = gcal_dup_icaltime (priv->date); - new_date->day = 31; - new_date->month = 12; - new_date->is_date = 0; - new_date->hour = 23; - new_date->minute = 59; - new_date->second = 0; - - return new_date; -} - -static void -gcal_year_view_clear_marks (GcalView *view) -{ - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (view)); - - priv->start_mark_cell = -1; - priv->end_mark_cell = -1; - gtk_widget_queue_draw (GTK_WIDGET (view)); -} - -static gchar* -gcal_year_view_get_left_header (GcalView *view) -{ - GcalYearViewPrivate *priv; - - priv = gcal_year_view_get_instance_private (GCAL_YEAR_VIEW (view)); - - return g_strdup_printf ("%d", priv->date->year); -} - -static gchar* -gcal_year_view_get_right_header (GcalView *view) -{ - return g_strdup (""); + /* FIXME: implement this */ + iface->component_added = NULL; + iface->component_modified = NULL; + iface->component_removed = NULL; + iface->freeze = NULL; + iface->thaw = NULL; } /* Public API */ -/** - * gcal_year_view_new: - * @manager: App singleton #GcalManager instance - * - * Create the year view - * - * Returns: (transfer full): - **/ -GtkWidget* -gcal_year_view_new (GcalManager *manager) +GcalYearView * +gcal_year_view_new (void) { - return g_object_new (GCAL_TYPE_YEAR_VIEW, "manager", manager, NULL); + return g_object_new (GCAL_TYPE_YEAR_VIEW, NULL); +} + +void +gcal_year_view_set_manager (GcalYearView *year_view, + GcalManager *manager) +{ + GcalYearViewPrivate *priv = year_view->priv; + + priv->manager = manager; } diff --git a/src/gcal-year-view.h b/src/gcal-year-view.h index 51b73e52..68acf1a5 100644 --- a/src/gcal-year-view.h +++ b/src/gcal-year-view.h @@ -1,11 +1,10 @@ -/* - * gcal-year-view.h +/* gcal-year-view.h * - * Copyright (C) 2012 - Erick Pérez Castellanos + * Copyright (C) 2015 Erick Pérez Castellanos * - * This program is free software; you can redistribute it and/or modify + * 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 + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -17,39 +16,44 @@ * along with this program. If not, see . */ -#ifndef __GCAL_YEAR_VIEW_H__ -#define __GCAL_YEAR_VIEW_H__ +#ifndef GCAL_YEAR_VIEW_H +#define GCAL_YEAR_VIEW_H #include "gcal-manager.h" -#include "gcal-subscriber-view.h" +#include G_BEGIN_DECLS -#define GCAL_TYPE_YEAR_VIEW (gcal_year_view_get_type ()) -#define GCAL_YEAR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_YEAR_VIEW, GcalYearView)) -#define GCAL_YEAR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_YEAR_VIEW, GcalYearViewClass)) -#define GCAL_IS_YEAR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_YEAR_VIEW)) -#define GCAL_IS_YEAR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_YEAR_VIEW)) -#define GCAL_YEAR_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_YEAR_VIEW, GcalYearViewClass)) +#define GCAL_TYPE_YEAR_VIEW (gcal_year_view_get_type()) +#define GCAL_YEAR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCAL_TYPE_YEAR_VIEW, GcalYearView)) +#define GCAL_YEAR_VIEW_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCAL_TYPE_YEAR_VIEW, GcalYearView const)) +#define GCAL_YEAR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCAL_TYPE_YEAR_VIEW, GcalYearViewClass)) +#define GCAL_IS_YEAR_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCAL_TYPE_YEAR_VIEW)) +#define GCAL_IS_YEAR_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCAL_TYPE_YEAR_VIEW)) +#define GCAL_YEAR_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCAL_TYPE_YEAR_VIEW, GcalYearViewClass)) -typedef struct _GcalYearView GcalYearView; -typedef struct _GcalYearViewClass GcalYearViewClass; +typedef struct _GcalYearView GcalYearView; +typedef struct _GcalYearViewClass GcalYearViewClass; +typedef struct _GcalYearViewPrivate GcalYearViewPrivate; struct _GcalYearView { - GcalSubscriberView parent; + GtkBox parent; + + /*< private >*/ + GcalYearViewPrivate *priv; }; struct _GcalYearViewClass { - GcalSubscriberViewClass parent_class; + GtkBoxClass parent; }; -GType gcal_year_view_get_type (void); - -GtkWidget* gcal_year_view_new (GcalManager *manager); - +GType gcal_year_view_get_type (void); +GcalYearView *gcal_year_view_new (void); +void gcal_year_view_set_manager (GcalYearView *year_view, + GcalManager *manager); G_END_DECLS -#endif /* __GCAL_YEAR_VIEW_H__ */ +#endif /* GCAL_YEAR_VIEW_H */