Added GcalWeekView. Not integrated yet.
Refactoring the code inside GcalMonthView for drawing and for showing child widgets. Fixed ref_sink in GcalEditableRemainder. (Don't need it) Added translation for weekdays abbreviation. (Thxs to ebassi & mclasen) Passed make distcheck.
This commit is contained in:
+178
-71
@@ -25,12 +25,22 @@
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include <libecal/e-cal-time-util.h>
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DATE
|
||||
};
|
||||
|
||||
struct _GcalViewChild
|
||||
{
|
||||
GtkWidget *widget;
|
||||
gboolean hidden_by_me;
|
||||
};
|
||||
|
||||
typedef struct _GcalViewChild GcalViewChild;
|
||||
|
||||
struct _GcalMonthViewPrivate
|
||||
{
|
||||
/**
|
||||
@@ -49,23 +59,12 @@ struct _GcalMonthViewPrivate
|
||||
icaltimetype *date;
|
||||
|
||||
gint days_delay;
|
||||
gint header_size;
|
||||
gint grid_header_size;
|
||||
gdouble vertical_step;
|
||||
gdouble horizontal_step;
|
||||
};
|
||||
|
||||
/* this will need translation */
|
||||
const char* weekdays [] =
|
||||
{
|
||||
"Sun",
|
||||
"Mon",
|
||||
"Tue",
|
||||
"Wed",
|
||||
"Thu",
|
||||
"Fri",
|
||||
"Sat"
|
||||
};
|
||||
|
||||
static void gcal_view_interface_init (GcalViewIface *iface);
|
||||
|
||||
static void gcal_month_view_constructed (GObject *object);
|
||||
@@ -113,10 +112,15 @@ static void gcal_month_view_forall (GtkContainer *con
|
||||
GtkCallback callback,
|
||||
gpointer callback_data);
|
||||
|
||||
static void gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
static void gcal_month_view_draw_header (GcalMonthView *view,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y);
|
||||
GtkAllocation *alloc,
|
||||
GtkBorder *padding);
|
||||
|
||||
static void gcal_month_view_draw_grid (GcalMonthView *view,
|
||||
cairo_t *cr,
|
||||
GtkAllocation *alloc,
|
||||
GtkBorder *padding);
|
||||
|
||||
static gboolean gcal_month_view_is_in_range (GcalView *view,
|
||||
icaltimetype *date);
|
||||
@@ -134,7 +138,8 @@ G_DEFINE_TYPE_WITH_CODE (GcalMonthView,
|
||||
gcal_view_interface_init));
|
||||
|
||||
|
||||
static void gcal_month_view_class_init (GcalMonthViewClass *klass)
|
||||
static void
|
||||
gcal_month_view_class_init (GcalMonthViewClass *klass)
|
||||
{
|
||||
GtkContainerClass *container_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
@@ -175,7 +180,8 @@ static void gcal_month_view_class_init (GcalMonthViewClass *klass)
|
||||
|
||||
|
||||
|
||||
static void gcal_month_view_init (GcalMonthView *self)
|
||||
static void
|
||||
gcal_month_view_init (GcalMonthView *self)
|
||||
{
|
||||
GcalMonthViewPrivate *priv;
|
||||
gint i;
|
||||
@@ -390,48 +396,53 @@ gcal_month_view_size_allocate (GtkWidget *widget,
|
||||
pango_layout_get_pixel_size (layout, NULL, &font_height);
|
||||
|
||||
/* init values */
|
||||
priv->grid_header_size = 12;
|
||||
priv->header_size = font_height + 4;
|
||||
priv->grid_header_size = font_height + 4;
|
||||
priv->horizontal_step =
|
||||
(allocation->width - (allocation->x + padding.left + padding.right)) / 7;
|
||||
priv->vertical_step =
|
||||
(allocation->height - (allocation->y + padding.top + padding.bottom + priv->grid_header_size)) / 5;
|
||||
(allocation->height - (allocation->y + padding.top + padding.bottom + priv->header_size + priv->grid_header_size)) / 5;
|
||||
|
||||
for (i = 0; i < 35; i++)
|
||||
{
|
||||
if (priv->days[i] == NULL)
|
||||
continue;
|
||||
added_height = 0;
|
||||
for (l = priv->days[i]; l != NULL; l = l->next)
|
||||
{
|
||||
GcalViewChild *child;
|
||||
gint pos_x;
|
||||
gint pos_y;
|
||||
gint min_height;
|
||||
gint natural_height;
|
||||
GtkAllocation child_allocation;
|
||||
|
||||
child = (GcalViewChild*) l->data;
|
||||
|
||||
pos_x = ( i % 7 ) * priv->horizontal_step;
|
||||
pos_y = ( i / 7 ) * priv->vertical_step;
|
||||
|
||||
if (! gtk_widget_get_visible (GTK_WIDGET (l->data)))
|
||||
if ((! gtk_widget_get_visible (child->widget)) && (! child->hidden_by_me))
|
||||
continue;
|
||||
gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
|
||||
|
||||
gtk_widget_get_preferred_height (child->widget,
|
||||
&min_height,
|
||||
&natural_height);
|
||||
child_allocation.x = pos_x + allocation->x + padding.top;
|
||||
child_allocation.x = pos_x + allocation->x + padding.left;
|
||||
child_allocation.y = pos_y + font_height + allocation->y
|
||||
+ priv->grid_header_size + padding.left;
|
||||
+ priv->header_size + priv->grid_header_size + padding.top;
|
||||
child_allocation.width = priv->horizontal_step;
|
||||
child_allocation.height = MIN (natural_height, priv->vertical_step);
|
||||
if (added_height + font_height + child_allocation.height
|
||||
> priv->vertical_step)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (l->data));
|
||||
gtk_widget_hide (child->widget);
|
||||
child->hidden_by_me = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_show (GTK_WIDGET (l->data));
|
||||
gtk_widget_show (child->widget);
|
||||
child->hidden_by_me = FALSE;
|
||||
child_allocation.y = child_allocation.y + added_height;
|
||||
gtk_widget_size_allocate (GTK_WIDGET (l->data), &child_allocation);
|
||||
gtk_widget_size_allocate (child->widget, &child_allocation);
|
||||
added_height += child_allocation.height;
|
||||
}
|
||||
}
|
||||
@@ -442,32 +453,19 @@ static gboolean
|
||||
gcal_month_view_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GcalMonthViewPrivate *priv;
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags state;
|
||||
GtkBorder padding;
|
||||
GdkRGBA color;
|
||||
GtkAllocation alloc;
|
||||
|
||||
priv = GCAL_MONTH_VIEW (widget)->priv;
|
||||
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
gtk_style_context_get_padding (context, state, &padding);
|
||||
gtk_style_context_get_color (context, state, &color);
|
||||
|
||||
/* grid_header_size is found through pango_get_size_in_pixels */
|
||||
priv->grid_header_size = 12;
|
||||
|
||||
/* getting allocation, and so on */
|
||||
gtk_widget_get_allocation (widget, &alloc);
|
||||
|
||||
gcal_month_view_draw_month_grid (
|
||||
GCAL_MONTH_VIEW (widget),
|
||||
cr,
|
||||
alloc.x + padding.left,
|
||||
alloc.y + padding.top + priv->grid_header_size);
|
||||
gcal_month_view_draw_header (GCAL_MONTH_VIEW (widget), cr, &alloc, &padding);
|
||||
gcal_month_view_draw_grid (GCAL_MONTH_VIEW (widget), cr, &alloc, &padding);
|
||||
|
||||
if (GTK_WIDGET_CLASS (gcal_month_view_parent_class)->draw != NULL)
|
||||
GTK_WIDGET_CLASS (gcal_month_view_parent_class)->draw (widget, cr);
|
||||
@@ -512,8 +510,9 @@ gcal_month_view_button_press (GtkWidget *widget,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean gcal_month_view_button_release (GtkWidget *widget,
|
||||
GdkEventButton *event)
|
||||
static gboolean
|
||||
gcal_month_view_button_release (GtkWidget *widget,
|
||||
GdkEventButton *event)
|
||||
{
|
||||
GcalMonthViewPrivate *priv;
|
||||
GtkStyleContext *context;
|
||||
@@ -564,6 +563,8 @@ gcal_month_view_add (GtkContainer *container,
|
||||
gint day;
|
||||
icaltimetype *date;
|
||||
|
||||
GcalViewChild *new_child;
|
||||
|
||||
g_return_if_fail (GCAL_IS_MONTH_VIEW (container));
|
||||
g_return_if_fail (GCAL_IS_EVENT_WIDGET (widget));
|
||||
g_return_if_fail (gtk_widget_get_parent (widget) == NULL);
|
||||
@@ -576,15 +577,23 @@ gcal_month_view_add (GtkContainer *container,
|
||||
|
||||
for (l = priv->days[day]; l != NULL; l = l->next)
|
||||
{
|
||||
GcalViewChild *child;
|
||||
|
||||
child = (GcalViewChild*) l->data;
|
||||
if (g_strcmp0 (
|
||||
gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (widget)),
|
||||
gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (l->data))) == 0)
|
||||
gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child->widget))) == 0)
|
||||
{
|
||||
g_warning ("Trying to add an event with the same uuid to the view");
|
||||
return;
|
||||
}
|
||||
}
|
||||
priv->days[day] = g_list_append (priv->days[day], widget);
|
||||
|
||||
new_child = g_new0 (GcalViewChild, 1);
|
||||
new_child->widget = widget;
|
||||
new_child->hidden_by_me = FALSE;
|
||||
|
||||
priv->days[day] = g_list_append (priv->days[day], new_child);
|
||||
gtk_widget_set_parent (widget, GTK_WIDGET (container));
|
||||
}
|
||||
|
||||
@@ -595,6 +604,7 @@ gcal_month_view_remove (GtkContainer *container,
|
||||
GcalMonthViewPrivate *priv;
|
||||
icaltimetype *date;
|
||||
gint day;
|
||||
GList *l;
|
||||
|
||||
g_return_if_fail (GCAL_IS_MONTH_VIEW (container));
|
||||
g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (container));
|
||||
@@ -604,7 +614,18 @@ gcal_month_view_remove (GtkContainer *container,
|
||||
day = date->day + ( - priv->days_delay);
|
||||
g_free (date);
|
||||
|
||||
priv->days[day] = g_list_remove (priv->days[day], widget);
|
||||
for (l = priv->days[day]; l != NULL; l = l->next)
|
||||
{
|
||||
GcalViewChild *child;
|
||||
|
||||
child = (GcalViewChild*) l->data;
|
||||
if (child->widget == widget)
|
||||
{
|
||||
priv->days[day] = g_list_remove (priv->days[day], child);
|
||||
g_free (child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
gtk_widget_unparent (widget);
|
||||
}
|
||||
|
||||
@@ -624,16 +645,83 @@ gcal_month_view_forall (GtkContainer *container,
|
||||
{
|
||||
for (l = priv->days[i]; l != NULL; l = l->next)
|
||||
{
|
||||
(* callback) (l->data, callback_data);
|
||||
GcalViewChild *child;
|
||||
|
||||
child = (GcalViewChild*) l->data;
|
||||
(* callback) (child->widget, callback_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
cairo_t *cr,
|
||||
gint x,
|
||||
gint y)
|
||||
gcal_month_view_draw_header (GcalMonthView *view,
|
||||
cairo_t *cr,
|
||||
GtkAllocation *alloc,
|
||||
GtkBorder *padding)
|
||||
{
|
||||
GcalMonthViewPrivate *priv;
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags state;
|
||||
GdkRGBA color;
|
||||
|
||||
PangoLayout *layout;
|
||||
gint layout_width;
|
||||
|
||||
gchar *left_header;
|
||||
gchar *right_header;
|
||||
gchar str_date[64];
|
||||
|
||||
struct tm tm_date;
|
||||
|
||||
g_return_if_fail (GCAL_IS_MONTH_VIEW (view));
|
||||
priv = view->priv;
|
||||
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (view));
|
||||
state = gtk_widget_get_state_flags (GTK_WIDGET (view));
|
||||
|
||||
gtk_style_context_get_color (context, state, &color);
|
||||
cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
|
||||
|
||||
layout = pango_cairo_create_layout (cr);
|
||||
pango_layout_set_font_description (layout,
|
||||
gtk_style_context_get_font (context,
|
||||
state));
|
||||
|
||||
tm_date = icaltimetype_to_tm (priv->date);
|
||||
e_utf8_strftime_fix_am_pm (str_date, 64, "%B", &tm_date);
|
||||
|
||||
left_header = g_strdup_printf ("%s", str_date);
|
||||
right_header = g_strdup_printf ("%d", priv->date->year);
|
||||
|
||||
pango_layout_set_text (layout, left_header, -1);
|
||||
pango_cairo_update_layout (cr, layout);
|
||||
|
||||
cairo_move_to (cr, alloc->x + padding->left, alloc->y + padding->top);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
state |= GTK_STATE_FLAG_INSENSITIVE;
|
||||
gtk_style_context_get_color (context, state, &color);
|
||||
cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
|
||||
|
||||
pango_layout_set_text (layout, right_header, -1);
|
||||
pango_cairo_update_layout (cr, layout);
|
||||
pango_layout_get_pixel_size (layout, &layout_width, NULL);
|
||||
|
||||
cairo_move_to (cr,
|
||||
alloc->width - padding->right - layout_width,
|
||||
alloc->y + padding->top);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
g_free (left_header);
|
||||
g_free (right_header);
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_month_view_draw_grid (GcalMonthView *view,
|
||||
cairo_t *cr,
|
||||
GtkAllocation *alloc,
|
||||
GtkBorder *padding)
|
||||
{
|
||||
GcalMonthViewPrivate *priv;
|
||||
GtkWidget *widget;
|
||||
@@ -646,6 +734,9 @@ gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
gint font_width;
|
||||
gint font_height;
|
||||
|
||||
gdouble start_grid_x;
|
||||
gdouble start_grid_y;
|
||||
|
||||
guint8 n_days_in_month;
|
||||
|
||||
PangoLayout *layout;
|
||||
@@ -653,6 +744,10 @@ gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
|
||||
priv = view->priv;
|
||||
widget = GTK_WIDGET (view);
|
||||
|
||||
start_grid_x = alloc->x + padding->left;
|
||||
start_grid_y = alloc->y + padding->top + priv->header_size + priv->grid_header_size;
|
||||
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
@@ -660,8 +755,8 @@ gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
gtk_style_context_get_background_color (context, state, &color);
|
||||
cairo_set_source_rgba (cr, color.red, color.green, color.blue, 0.8);
|
||||
cairo_rectangle (cr,
|
||||
x + priv->horizontal_step * ( priv->selected_cell % 7),
|
||||
y + priv->vertical_step * ( priv->selected_cell / 7),
|
||||
start_grid_x + priv->horizontal_step * ( priv->selected_cell % 7),
|
||||
start_grid_y + priv->vertical_step * ( priv->selected_cell / 7),
|
||||
priv->horizontal_step,
|
||||
priv->vertical_step);
|
||||
cairo_fill (cr);
|
||||
@@ -680,12 +775,12 @@ gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
|
||||
for (i = 0; i < 7; i++)
|
||||
{
|
||||
pango_layout_set_text (layout, weekdays[i], -1);
|
||||
pango_layout_set_text (layout, gcal_get_weekday (i), -1);
|
||||
pango_cairo_update_layout (cr, layout);
|
||||
pango_layout_get_pixel_size (layout, &font_width, &font_height);
|
||||
cairo_move_to (cr,
|
||||
x + priv->horizontal_step * i + 1,
|
||||
y - font_height - 1);
|
||||
start_grid_x + priv->horizontal_step * i + 1,
|
||||
start_grid_y - font_height - 1);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
for (j = 0; j < 5; j++)
|
||||
@@ -698,9 +793,10 @@ gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
pango_layout_set_text (layout, day, -1);
|
||||
pango_cairo_update_layout (cr, layout);
|
||||
pango_layout_get_pixel_size (layout, &font_width, &font_height);
|
||||
/* 2: is margin-left and 1: is margin_top for numbers */
|
||||
cairo_move_to (cr,
|
||||
x + priv->horizontal_step * i + 2,
|
||||
y + priv->vertical_step * j + 1);
|
||||
start_grid_x + priv->horizontal_step * i + 2,
|
||||
start_grid_y + priv->vertical_step * j + 1);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
g_free (day);
|
||||
}
|
||||
@@ -710,22 +806,21 @@ gcal_month_view_draw_month_grid (GcalMonthView *view,
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
cairo_move_to (cr, x, y + priv->vertical_step * i);
|
||||
cairo_move_to (cr, start_grid_x, start_grid_y + priv->vertical_step * i);
|
||||
cairo_line_to (cr,
|
||||
x + priv->horizontal_step * 7,
|
||||
y + priv->vertical_step * i);
|
||||
start_grid_x + priv->horizontal_step * 7,
|
||||
start_grid_y + priv->vertical_step * i);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
cairo_move_to (cr, x + priv->horizontal_step * i, y);
|
||||
cairo_move_to (cr, start_grid_x + priv->horizontal_step * i, start_grid_y);
|
||||
cairo_line_to (cr,
|
||||
x + priv->horizontal_step * i,
|
||||
y + priv->vertical_step * 5);
|
||||
start_grid_x + priv->horizontal_step * i,
|
||||
start_grid_y + priv->vertical_step * 5);
|
||||
}
|
||||
|
||||
cairo_stroke (cr);
|
||||
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -752,9 +847,17 @@ gcal_month_view_remove_by_uuid (GcalView *view,
|
||||
{
|
||||
for (l = priv->days[i]; l != NULL; l = l->next)
|
||||
{
|
||||
const gchar* widget_uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (l->data));
|
||||
GcalViewChild *child;
|
||||
const gchar* widget_uuid;
|
||||
|
||||
child = (GcalViewChild*) l->data;
|
||||
widget_uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child->widget));
|
||||
if (g_strcmp0 (uuid, widget_uuid) == 0)
|
||||
gtk_widget_destroy (GTK_WIDGET (l->data));
|
||||
{
|
||||
gtk_widget_destroy (child->widget);
|
||||
i = 36;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -774,9 +877,13 @@ gcal_month_view_get_by_uuid (GcalView *view,
|
||||
{
|
||||
for (l = priv->days[i]; l != NULL; l = l->next)
|
||||
{
|
||||
const gchar* widget_uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (l->data));
|
||||
GcalViewChild *child;
|
||||
const gchar* widget_uuid;
|
||||
|
||||
child = (GcalViewChild*) l->data;
|
||||
widget_uuid = gcal_event_widget_peek_uuid (GCAL_EVENT_WIDGET (child->widget));
|
||||
if (g_strcmp0 (uuid, widget_uuid) == 0)
|
||||
return GTK_WIDGET (l->data);
|
||||
return child->widget;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user