[gnome-calendar] gcal-all-day-grid: allocate event largers than one day
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] gcal-all-day-grid: allocate event largers than one day
- Date: Thu, 4 Dec 2014 22:24:19 +0000 (UTC)
commit 912a5d46e99680cc3b7ecdabfe4893ad7d52be34
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Jun 18 15:59:57 2013 -0400
gcal-all-day-grid: allocate event largers than one day
src/gcal-all-day-grid.c | 85 ++++++++++++++++++++++++++++++++++++++---------
src/gcal-all-day-grid.h | 3 +-
src/gcal-day-view.c | 39 +++++++++++++++------
3 files changed, 99 insertions(+), 28 deletions(-)
---
diff --git a/src/gcal-all-day-grid.c b/src/gcal-all-day-grid.c
index 94f7ca5..e6fbd82 100644
--- a/src/gcal-all-day-grid.c
+++ b/src/gcal-all-day-grid.c
@@ -30,6 +30,15 @@ enum
PROP_SPACING
};
+struct _ChildInfo
+{
+ GtkWidget *widget;
+
+ guint column_span;
+};
+
+typedef struct _ChildInfo ChildInfo;
+
struct _GcalAllDayGridPrivate
{
/* property */
@@ -173,11 +182,20 @@ static void
gcal_all_day_grid_finalize (GObject *object)
{
GcalAllDayGridPrivate *priv;
+ GList *column;
priv = GCAL_ALL_DAY_GRID (object)->priv;
if (priv->children != NULL)
- g_list_free_full (priv->children, (GDestroyNotify) g_list_free);
+ {
+ column = priv->children;
+ while (column)
+ {
+ g_list_free_full (column->data, (GDestroyNotify) g_free);
+ column = column->next;
+ }
+ }
+ g_list_free (priv->children);
if (priv->column_headers != NULL)
g_list_free_full (priv->column_headers, g_free);
@@ -340,10 +358,10 @@ gcal_all_day_grid_get_preferred_height (GtkWidget *widget,
for (;column_children != NULL;
column_children = g_list_next (column_children))
{
- GtkWidget *widget;
- widget = (GtkWidget*) column_children->data;
+ ChildInfo *info;
+ info = (ChildInfo*) column_children->data;
- gtk_widget_get_preferred_height (widget, &min_height, &nat_height);
+ gtk_widget_get_preferred_height (info->widget, &min_height, &nat_height);
/* minimum is calculated as the minimum required
by any child */
@@ -461,8 +479,11 @@ gcal_all_day_grid_size_allocate (GtkWidget *widget,
GList *columns;
gint idx;
+ gint i;
- gint width;
+ gint width_block;
+
+ GArray *last_y;
priv = GCAL_ALL_DAY_GRID (widget)->priv;
gtk_widget_set_allocation (widget, allocation);
@@ -472,7 +493,7 @@ gcal_all_day_grid_size_allocate (GtkWidget *widget,
gtk_widget_get_state_flags (widget),
&padding);
- width = allocation->width - (padding.left + padding.right);
+ width_block = (allocation->width - (padding.left + padding.right)) / priv->columns_nr;
layout = gtk_widget_create_pango_layout (widget, "0");
@@ -492,6 +513,11 @@ gcal_all_day_grid_size_allocate (GtkWidget *widget,
allocation->height - y_gap);
}
+ /* last_y value for each column,
+ will keep the amount of columns as well */
+ last_y = g_array_new (FALSE, TRUE, sizeof (guint));
+ g_array_set_size (last_y, priv->columns_nr);
+
/* Placing children */
for (columns = priv->children, idx = 0;
columns != NULL;
@@ -502,25 +528,39 @@ gcal_all_day_grid_size_allocate (GtkWidget *widget,
column = (GList*) columns->data;
- child_allocation.x = idx * (width / priv->columns_nr) + allocation->x + padding.left;
- child_allocation.width = (width / priv->columns_nr);
+ child_allocation.x = idx * width_block + allocation->x + padding.left;
+
+ y_gap += g_array_index (last_y, guint, idx);
for (; column != NULL; column = g_list_next (column))
{
gint natural_height;
- GtkWidget *item = (GtkWidget*) column->data;
+ ChildInfo *info;
+ GtkWidget *item;
+
+ info = (ChildInfo*) column->data;
+ item = info->widget;
gtk_widget_get_preferred_height (item, NULL, &natural_height);
+ child_allocation.width = width_block * info->column_span;
child_allocation.y = y_gap;
child_allocation.height = natural_height;
y_gap += natural_height;
gtk_widget_size_allocate (item, &child_allocation);
+
+ /* updating y spacings */
+ for (i = 0; i < info->column_span; ++i)
+ {
+ g_array_index (last_y, guint, idx + i) = natural_height;
+ }
}
y_gap = allocation->y + padding.top + logical_rect.height + priv->spacing;
}
+
+ g_array_free (last_y, TRUE);
}
static gboolean
@@ -655,7 +695,7 @@ gcal_all_day_grid_add (GtkContainer *container,
gcal_all_day_grid_place (GCAL_ALL_DAY_GRID (container),
widget,
- 0);
+ 0, 0);
}
static void
@@ -675,11 +715,13 @@ gcal_all_day_grid_remove (GtkContainer *container,
GList* column = (GList*) columns->data;
for (;column != NULL; column = g_list_next (column))
{
- if (widget == (GtkWidget*) column->data)
+ ChildInfo *info = (ChildInfo*) column->data;
+ if (widget == info->widget)
{
GList* orig = (GList*) columns->data;
orig = g_list_delete_link (orig, column);
+ g_free (info);
gtk_widget_unparent (widget);
columns->data = orig;
@@ -713,10 +755,10 @@ gcal_all_day_grid_forall (GtkContainer *container,
while (column)
{
- GtkWidget *child = (GtkWidget*) column->data;
+ ChildInfo *info = (ChildInfo*) column->data;
column = column->next;
- (* callback) (child, callback_data);
+ (* callback) (info->widget, callback_data);
}
}
}
@@ -777,6 +819,7 @@ gcal_all_day_grid_set_column_headers (GcalAllDayGrid *all_day,
* @all_day: A #GcalAllDayGrid widget
* @widget: The child widget to add
* @column_idx: The index of the column, starting with zero
+ * @column_span: The columns the widgets should expand
*
* Adding a widget to a specified column. If the column index
* is bigger than the #GcalAllDayGrid:columns property set,
@@ -785,11 +828,13 @@ gcal_all_day_grid_set_column_headers (GcalAllDayGrid *all_day,
void
gcal_all_day_grid_place (GcalAllDayGrid *all_day,
GtkWidget *widget,
- guint column_idx)
+ guint column_idx,
+ guint column_span)
{
GcalAllDayGridPrivate *priv;
GList* children_link;
GList* column;
+ ChildInfo *info;
priv = all_day->priv;
@@ -797,7 +842,11 @@ gcal_all_day_grid_place (GcalAllDayGrid *all_day,
children_link = g_list_nth (priv->children, column_idx);
column = (GList*) children_link->data;
- children_link->data = g_list_append (column, widget);
+
+ info = g_new0 (ChildInfo, 1);
+ info->widget = widget;
+ info->column_span = column_span;
+ children_link->data = g_list_append (column, info);
gtk_widget_set_parent (widget, GTK_WIDGET (all_day));
}
@@ -822,7 +871,11 @@ gcal_all_day_grid_get_by_uuid (GcalAllDayGrid *all_day,
while (column)
{
- GcalEventWidget *child = GCAL_EVENT_WIDGET ((GtkWidget*) column->data);
+ ChildInfo *info;
+ GcalEventWidget *child;
+
+ info = ((ChildInfo*) column->data);
+ child = GCAL_EVENT_WIDGET (info->widget);
column = column->next;
if (g_strcmp0 (uuid,
diff --git a/src/gcal-all-day-grid.h b/src/gcal-all-day-grid.h
index aac44be..69a586a 100644
--- a/src/gcal-all-day-grid.h
+++ b/src/gcal-all-day-grid.h
@@ -57,7 +57,8 @@ void gcal_all_day_grid_set_column_headers (GcalAllDayGrid *all_day,
void gcal_all_day_grid_place (GcalAllDayGrid *all_day,
GtkWidget *widget,
- guint column_idx);
+ guint column_idx,
+ guint column_span);
GtkWidget* gcal_all_day_grid_get_by_uuid (GcalAllDayGrid *all_day,
const gchar *uuid);
diff --git a/src/gcal-day-view.c b/src/gcal-day-view.c
index e06f252..3372c3c 100644
--- a/src/gcal-day-view.c
+++ b/src/gcal-day-view.c
@@ -285,6 +285,7 @@ gcal_day_view_add (GtkContainer *container,
GtkWidget *widget)
{
GcalDayViewPrivate *priv;
+ icaltimetype *tomorrow;
icaltimetype *dt_start;
icaltimetype *dt_end;
gchar* summ;
@@ -294,33 +295,49 @@ gcal_day_view_add (GtkContainer *container,
priv = GCAL_DAY_VIEW (container)->priv;
summ = gcal_event_widget_get_summary (GCAL_EVENT_WIDGET (widget));
+
+ tomorrow = gcal_day_view_get_final_date (GCAL_VIEW (container));
dt_start = gcal_event_widget_get_date (GCAL_EVENT_WIDGET (widget));
dt_end = gcal_event_widget_get_end_date (GCAL_EVENT_WIDGET (widget));
+
/* FIXME: recheck conditions to add, what, where */
/* Maybe, should be good to add, inside days views only contained events */
- if (gcal_event_widget_get_all_day (GCAL_EVENT_WIDGET (widget)))
- {
- g_debug ("[all-day-grid] %s from %s to %s",
- summ,
- icaltime_as_ical_string (*dt_start),
- icaltime_as_ical_string (*dt_end));
- gcal_all_day_grid_place (GCAL_ALL_DAY_GRID (priv->all_day_grid),
- widget,
- priv->date->day == dt_start->day ? 0 : 1);
- }
- else
+ g_debug ("[processing] %s from %s to %s",
+ summ,
+ icaltime_as_ical_string (*dt_start),
+ icaltime_as_ical_string (*dt_end));
+
+ if (! gcal_event_widget_get_all_day (GCAL_EVENT_WIDGET (widget)) &&
+ (dt_start->day == dt_end->day) &&
+ (dt_start->day == priv->date->day ||
+ dt_start->day == tomorrow->day))
{
g_debug ("[days-grid] %s from %s to %s",
summ,
icaltime_as_ical_string (*dt_start),
icaltime_as_ical_string (*dt_end));
+
gcal_days_grid_place (GCAL_DAYS_GRID (priv->day_grid),
widget,
priv->date->day == dt_start->day ? 0 : 1,
dt_start->hour * 2 + (dt_start->minute / 30),
dt_end->hour * 2 + (dt_end->minute / 30)); /* FIXME Include half hour and length
*/
}
+ else
+ {
+ gboolean start_tomorrow;
+ g_debug ("[all-day-grid] %s from %s to %s",
+ summ,
+ icaltime_as_ical_string (*dt_start),
+ icaltime_as_ical_string (*dt_end));
+ start_tomorrow = icaltime_compare_date_only (*dt_start, *tomorrow) == 0;
+ gcal_all_day_grid_place (GCAL_ALL_DAY_GRID (priv->all_day_grid),
+ widget,
+ start_tomorrow ? 1 : 0,
+ dt_start->day != dt_end->day ? 2 : 1);
+ }
+ g_free (tomorrow);
g_free (dt_start);
g_free (dt_end);
g_free (summ);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]